OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Neither the name of Google Inc. nor the names of its | 10 * * Neither the name of Google Inc. nor the names of its |
(...skipping 13 matching lines...) Expand all Loading... |
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 */ | 25 */ |
26 | 26 |
27 #ifndef ElementShadow_h | 27 #ifndef ElementShadow_h |
28 #define ElementShadow_h | 28 #define ElementShadow_h |
29 | 29 |
30 #include "core/CoreExport.h" | 30 #include "core/CoreExport.h" |
31 #include "core/dom/shadow/InsertionPoint.h" | 31 #include "core/dom/shadow/InsertionPoint.h" |
32 #include "core/dom/shadow/SelectRuleFeatureSet.h" | 32 #include "core/dom/shadow/SelectRuleFeatureSet.h" |
33 #include "core/dom/shadow/ShadowRoot.h" | 33 #include "core/dom/shadow/ShadowRoot.h" |
| 34 #include "core/dom/shadow/SlotAssignment.h" |
34 #include "platform/heap/Handle.h" | 35 #include "platform/heap/Handle.h" |
35 #include "wtf/DoublyLinkedList.h" | 36 #include "wtf/DoublyLinkedList.h" |
36 #include "wtf/HashMap.h" | 37 #include "wtf/HashMap.h" |
37 #include "wtf/Noncopyable.h" | 38 #include "wtf/Noncopyable.h" |
38 #include "wtf/PassOwnPtr.h" | 39 #include "wtf/PassOwnPtr.h" |
39 | 40 |
40 namespace blink { | 41 namespace blink { |
41 | 42 |
42 class CORE_EXPORT ElementShadow final : public NoBaseWillBeGarbageCollectedFinal
ized<ElementShadow> { | 43 class CORE_EXPORT ElementShadow final : public NoBaseWillBeGarbageCollectedFinal
ized<ElementShadow> { |
43 WTF_MAKE_NONCOPYABLE(ElementShadow); | 44 WTF_MAKE_NONCOPYABLE(ElementShadow); |
44 USING_FAST_MALLOC_WILL_BE_REMOVED(ElementShadow); | 45 USING_FAST_MALLOC_WILL_BE_REMOVED(ElementShadow); |
45 public: | 46 public: |
46 static PassOwnPtrWillBeRawPtr<ElementShadow> create(); | 47 static PassOwnPtrWillBeRawPtr<ElementShadow> create(); |
47 ~ElementShadow(); | 48 ~ElementShadow(); |
48 | 49 |
49 Element* host() const; | 50 Element* host() const; |
50 ShadowRoot& youngestShadowRoot() const { ASSERT(m_shadowRoots.head()); retur
n *m_shadowRoots.head(); } | 51 ShadowRoot& youngestShadowRoot() const { ASSERT(m_shadowRoots.head()); retur
n *m_shadowRoots.head(); } |
51 ShadowRoot* oldestShadowRoot() const { return m_shadowRoots.tail(); } | 52 ShadowRoot* oldestShadowRoot() const { return m_shadowRoots.tail(); } |
52 ElementShadow* containingShadow() const; | 53 ElementShadow* containingShadow() const; |
53 | 54 |
| 55 ShadowRoot* shadowRootIfV1() const |
| 56 { |
| 57 if (isV1()) |
| 58 return &youngestShadowRoot(); |
| 59 return nullptr; |
| 60 } |
| 61 |
| 62 HTMLSlotElement* assignedSlotFor(const Node& node) const |
| 63 { |
| 64 ASSERT(m_slotAssignment); |
| 65 return m_slotAssignment->assignedSlotFor(node); |
| 66 } |
| 67 |
54 ShadowRoot& addShadowRoot(Element& shadowHost, ShadowRootType); | 68 ShadowRoot& addShadowRoot(Element& shadowHost, ShadowRootType); |
55 | 69 |
56 bool hasSameStyles(const ElementShadow*) const; | 70 bool hasSameStyles(const ElementShadow*) const; |
57 | 71 |
58 void attach(const Node::AttachContext&); | 72 void attach(const Node::AttachContext&); |
59 void detach(const Node::AttachContext&); | 73 void detach(const Node::AttachContext&); |
60 | 74 |
61 void willAffectSelector(); | 75 void willAffectSelector(); |
62 const SelectRuleFeatureSet& ensureSelectFeatureSet(); | 76 const SelectRuleFeatureSet& ensureSelectFeatureSet(); |
63 | 77 |
64 void distributeIfNeeded(); | 78 void distributeIfNeeded(); |
65 void setNeedsDistributionRecalc(); | 79 void setNeedsDistributionRecalc(); |
66 | 80 |
67 const InsertionPoint* finalDestinationInsertionPointFor(const Node*) const; | 81 const InsertionPoint* finalDestinationInsertionPointFor(const Node*) const; |
68 const DestinationInsertionPoints* destinationInsertionPointsFor(const Node*)
const; | 82 const DestinationInsertionPoints* destinationInsertionPointsFor(const Node*)
const; |
69 | 83 |
70 void didDistributeNode(const Node*, InsertionPoint*); | 84 void didDistributeNode(const Node*, InsertionPoint*); |
71 | 85 |
| 86 bool isV1() const { return youngestShadowRoot().isV1(); }; |
| 87 |
72 DECLARE_TRACE(); | 88 DECLARE_TRACE(); |
73 | 89 |
74 private: | 90 private: |
75 ElementShadow(); | 91 ElementShadow(); |
76 | 92 |
77 #if !ENABLE(OILPAN) | 93 #if !ENABLE(OILPAN) |
78 void removeDetachedShadowRoots(); | 94 void removeDetachedShadowRoots(); |
79 #endif | 95 #endif |
80 | 96 |
81 void distribute(); | 97 void distribute(); |
82 void clearDistribution(); | 98 void clearDistribution(); |
83 | 99 |
84 void distributeV0(); | 100 void distributeV0(); |
85 void distributeV1(); | 101 void distributeV1(); |
86 | 102 |
87 void collectSelectFeatureSetFrom(ShadowRoot&); | 103 void collectSelectFeatureSetFrom(ShadowRoot&); |
88 void distributeNodeChildrenTo(InsertionPoint*, ContainerNode*); | 104 void distributeNodeChildrenTo(InsertionPoint*, ContainerNode*); |
89 | 105 |
90 bool needsSelectFeatureSet() const { return m_needsSelectFeatureSet; } | 106 bool needsSelectFeatureSet() const { return m_needsSelectFeatureSet; } |
91 void setNeedsSelectFeatureSet() { m_needsSelectFeatureSet = true; } | 107 void setNeedsSelectFeatureSet() { m_needsSelectFeatureSet = true; } |
92 | 108 |
93 bool isV1() const { return youngestShadowRoot().type() == ShadowRootType::Op
en || youngestShadowRoot().type() == ShadowRootType::Closed; }; | |
94 | |
95 #if ENABLE(OILPAN) | 109 #if ENABLE(OILPAN) |
96 // The cost of |new| in Oilpan is lower than non-Oilpan. We should reduce | 110 // The cost of |new| in Oilpan is lower than non-Oilpan. We should reduce |
97 // the size of HashMap entry. | 111 // the size of HashMap entry. |
98 typedef HeapHashMap<Member<const Node>, Member<DestinationInsertionPoints>>
NodeToDestinationInsertionPoints; | 112 typedef HeapHashMap<Member<const Node>, Member<DestinationInsertionPoints>>
NodeToDestinationInsertionPoints; |
99 #else | 113 #else |
100 typedef HashMap<const Node*, DestinationInsertionPoints> NodeToDestinationIn
sertionPoints; | 114 typedef HashMap<const Node*, DestinationInsertionPoints> NodeToDestinationIn
sertionPoints; |
101 #endif | 115 #endif |
102 NodeToDestinationInsertionPoints m_nodeToInsertionPoints; | 116 NodeToDestinationInsertionPoints m_nodeToInsertionPoints; |
103 | 117 |
104 SelectRuleFeatureSet m_selectFeatures; | 118 SelectRuleFeatureSet m_selectFeatures; |
105 // FIXME: Oilpan: add a heap-based version of DoublyLinkedList<>. | 119 // FIXME: Oilpan: add a heap-based version of DoublyLinkedList<>. |
106 DoublyLinkedList<ShadowRoot> m_shadowRoots; | 120 DoublyLinkedList<ShadowRoot> m_shadowRoots; |
107 bool m_needsDistributionRecalc; | 121 bool m_needsDistributionRecalc; |
108 bool m_needsSelectFeatureSet; | 122 bool m_needsSelectFeatureSet; |
| 123 |
| 124 // TODO(hayato): ShadowRoot should be an owner of SlotAssigment |
| 125 OwnPtr<SlotAssignment> m_slotAssignment; |
109 }; | 126 }; |
110 | 127 |
111 inline Element* ElementShadow::host() const | 128 inline Element* ElementShadow::host() const |
112 { | 129 { |
113 ASSERT(!m_shadowRoots.isEmpty()); | 130 ASSERT(!m_shadowRoots.isEmpty()); |
114 return youngestShadowRoot().host(); | 131 return youngestShadowRoot().host(); |
115 } | 132 } |
116 | 133 |
117 inline ShadowRoot* Node::youngestShadowRoot() const | 134 inline ShadowRoot* Node::youngestShadowRoot() const |
118 { | 135 { |
119 if (!isElementNode()) | 136 if (!isElementNode()) |
120 return 0; | 137 return 0; |
121 return toElement(this)->youngestShadowRoot(); | 138 return toElement(this)->youngestShadowRoot(); |
122 } | 139 } |
123 | 140 |
124 inline ShadowRoot* Element::youngestShadowRoot() const | 141 inline ShadowRoot* Element::youngestShadowRoot() const |
125 { | 142 { |
126 if (ElementShadow* shadow = this->shadow()) | 143 if (ElementShadow* shadow = this->shadow()) |
127 return &shadow->youngestShadowRoot(); | 144 return &shadow->youngestShadowRoot(); |
128 return 0; | 145 return 0; |
129 } | 146 } |
130 | 147 |
| 148 inline ShadowRoot* Element::shadowRootIfV1() const |
| 149 { |
| 150 if (ElementShadow* shadow = this->shadow()) |
| 151 return shadow->shadowRootIfV1(); |
| 152 return nullptr; |
| 153 } |
| 154 |
131 inline ElementShadow* ElementShadow::containingShadow() const | 155 inline ElementShadow* ElementShadow::containingShadow() const |
132 { | 156 { |
133 if (ShadowRoot* parentRoot = host()->containingShadowRoot()) | 157 if (ShadowRoot* parentRoot = host()->containingShadowRoot()) |
134 return parentRoot->owner(); | 158 return parentRoot->owner(); |
135 return 0; | 159 return 0; |
136 } | 160 } |
137 | 161 |
138 inline void ElementShadow::distributeIfNeeded() | 162 inline void ElementShadow::distributeIfNeeded() |
139 { | 163 { |
140 if (m_needsDistributionRecalc) | 164 if (m_needsDistributionRecalc) |
141 distribute(); | 165 distribute(); |
142 m_needsDistributionRecalc = false; | 166 m_needsDistributionRecalc = false; |
143 } | 167 } |
144 | 168 |
145 } // namespace | 169 } // namespace |
146 | 170 |
147 #endif | 171 #endif |
OLD | NEW |