1 | /* |
2 | * Copyright (C) 2016 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #include "Node.h" |
29 | #include "StyleChange.h" |
30 | #include <wtf/HashMap.h> |
31 | #include <wtf/HashSet.h> |
32 | #include <wtf/ListHashSet.h> |
33 | |
34 | namespace WebCore { |
35 | |
36 | class ContainerNode; |
37 | class Document; |
38 | class Element; |
39 | class Node; |
40 | class RenderStyle; |
41 | class Text; |
42 | |
43 | namespace Style { |
44 | |
45 | struct ElementUpdate { |
46 | std::unique_ptr<RenderStyle> style; |
47 | Change change { NoChange }; |
48 | bool recompositeLayer { false }; |
49 | }; |
50 | |
51 | enum class DescendantsToResolve { None, ChildrenWithExplicitInherit, Children, All }; |
52 | |
53 | struct ElementUpdates { |
54 | ElementUpdate update; |
55 | DescendantsToResolve descendantsToResolve { DescendantsToResolve::None }; |
56 | Optional<ElementUpdate> beforePseudoElementUpdate; |
57 | Optional<ElementUpdate> afterPseudoElementUpdate; |
58 | }; |
59 | |
60 | struct TextUpdate { |
61 | unsigned offset { 0 }; |
62 | unsigned length { std::numeric_limits<unsigned>::max() }; |
63 | Optional<std::unique_ptr<RenderStyle>> inheritedDisplayContentsStyle; |
64 | }; |
65 | |
66 | class Update { |
67 | WTF_MAKE_FAST_ALLOCATED; |
68 | public: |
69 | Update(Document&); |
70 | |
71 | const ListHashSet<ContainerNode*>& roots() const { return m_roots; } |
72 | |
73 | const ElementUpdates* elementUpdates(const Element&) const; |
74 | ElementUpdates* elementUpdates(const Element&); |
75 | |
76 | const TextUpdate* textUpdate(const Text&) const; |
77 | |
78 | const RenderStyle* elementStyle(const Element&) const; |
79 | RenderStyle* elementStyle(const Element&); |
80 | |
81 | const Document& document() const { return m_document; } |
82 | |
83 | unsigned size() const { return m_elements.size() + m_texts.size(); } |
84 | |
85 | void addElement(Element&, Element* parent, ElementUpdates&&); |
86 | void addText(Text&, Element* parent, TextUpdate&&); |
87 | void addText(Text&, TextUpdate&&); |
88 | |
89 | private: |
90 | void addPossibleRoot(Element*); |
91 | |
92 | Document& m_document; |
93 | ListHashSet<ContainerNode*> m_roots; |
94 | HashMap<const Element*, ElementUpdates> m_elements; |
95 | HashMap<const Text*, TextUpdate> m_texts; |
96 | }; |
97 | |
98 | } |
99 | } |
100 | |