OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 15 matching lines...) Expand all Loading... |
26 | 26 |
27 #ifndef ShadowRoot_h | 27 #ifndef ShadowRoot_h |
28 #define ShadowRoot_h | 28 #define ShadowRoot_h |
29 | 29 |
30 #include "core/CoreExport.h" | 30 #include "core/CoreExport.h" |
31 #include "core/dom/ContainerNode.h" | 31 #include "core/dom/ContainerNode.h" |
32 #include "core/dom/DocumentFragment.h" | 32 #include "core/dom/DocumentFragment.h" |
33 #include "core/dom/Element.h" | 33 #include "core/dom/Element.h" |
34 #include "core/dom/TreeScope.h" | 34 #include "core/dom/TreeScope.h" |
35 #include "core/dom/shadow/SlotAssignment.h" | 35 #include "core/dom/shadow/SlotAssignment.h" |
36 #include "wtf/DoublyLinkedList.h" | |
37 #include <iosfwd> | |
38 | 36 |
39 namespace blink { | 37 namespace blink { |
40 | 38 |
41 class Document; | 39 class Document; |
42 class ElementShadow; | 40 class ElementShadow; |
43 class ExceptionState; | 41 class ExceptionState; |
44 class HTMLShadowElement; | 42 class HTMLShadowElement; |
45 class InsertionPoint; | 43 class InsertionPoint; |
46 class ShadowRootRareData; | 44 class ShadowRootRareData; |
47 class ShadowRootRareDataV0; | 45 class ShadowRootRareDataV0; |
48 class StyleSheetList; | 46 class StyleSheetList; |
49 | 47 |
50 enum class ShadowRootType { | 48 enum class ShadowRootType { |
51 UserAgent, | 49 UserAgent, |
52 V0, | 50 V0, |
53 Open, | 51 Open, |
54 Closed | 52 Closed |
55 }; | 53 }; |
56 | 54 |
57 class CORE_EXPORT ShadowRoot final : public DocumentFragment, public TreeScope,
public DoublyLinkedListNode<ShadowRoot> { | 55 class CORE_EXPORT ShadowRoot final : public DocumentFragment, public TreeScope { |
58 DEFINE_WRAPPERTYPEINFO(); | 56 DEFINE_WRAPPERTYPEINFO(); |
59 USING_GARBAGE_COLLECTED_MIXIN(ShadowRoot); | 57 USING_GARBAGE_COLLECTED_MIXIN(ShadowRoot); |
60 friend class WTF::DoublyLinkedListNode<ShadowRoot>; | |
61 public: | 58 public: |
62 // FIXME: Current implementation does not work well if a shadow root is dyna
mically created. | 59 // FIXME: Current implementation does not work well if a shadow root is dyna
mically created. |
63 // So multiple shadow subtrees in several elements are prohibited. | 60 // So multiple shadow subtrees in several elements are prohibited. |
64 // See https://github.com/w3c/webcomponents/issues/102 and http://crbug.com/
234020 | 61 // See https://github.com/w3c/webcomponents/issues/102 and http://crbug.com/
234020 |
65 static ShadowRoot* create(Document& document, ShadowRootType type) | 62 static ShadowRoot* create(Document& document, ShadowRootType type) |
66 { | 63 { |
67 return new ShadowRoot(document, type); | 64 return new ShadowRoot(document, type); |
68 } | 65 } |
69 | 66 |
70 void recalcStyle(StyleRecalcChange); | 67 void recalcStyle(StyleRecalcChange); |
71 | 68 |
72 // Disambiguate between Node and TreeScope hierarchies; TreeScope's implemen
tation is simpler. | 69 // Disambiguate between Node and TreeScope hierarchies; TreeScope's implemen
tation is simpler. |
73 using TreeScope::document; | 70 using TreeScope::document; |
74 using TreeScope::getElementById; | 71 using TreeScope::getElementById; |
75 | 72 |
76 // TODO(kochi): crbug.com/507413 In non-Oilpan, host() may return null durin
g queued | 73 // TODO(kochi): crbug.com/507413 In non-Oilpan, host() may return null durin
g queued |
77 // event handling (e.g. during execCommand()). | 74 // event handling (e.g. during execCommand()). |
78 Element* host() const { return toElement(parentOrShadowHostNode()); } | 75 Element* host() const { return toElement(parentOrShadowHostNode()); } |
79 ElementShadow* owner() const { return host() ? host()->shadow() : 0; } | 76 ElementShadow* owner() const { return host() ? host()->shadow() : 0; } |
80 | 77 |
81 ShadowRoot* youngerShadowRoot() const { return prev(); } | 78 ShadowRoot* youngerShadowRoot() const; |
| 79 ShadowRoot* olderShadowRoot() const; |
| 80 ShadowRoot* olderShadowRootForBindings() const; |
82 | 81 |
83 ShadowRoot* olderShadowRootForBindings() const; | 82 void setYoungerShadowRoot(ShadowRoot&); |
| 83 void setOlderShadowRoot(ShadowRoot&); |
84 | 84 |
85 String mode() const { return (type() == ShadowRootType::V0 || type() == Shad
owRootType::Open) ? "open" : "closed"; }; | 85 String mode() const { return (type() == ShadowRootType::V0 || type() == Shad
owRootType::Open) ? "open" : "closed"; }; |
86 | 86 |
87 bool isOpenOrV0() const { return type() == ShadowRootType::V0 || type() == S
hadowRootType::Open; } | 87 bool isOpenOrV0() const { return type() == ShadowRootType::V0 || type() == S
hadowRootType::Open; } |
88 | 88 |
89 bool isV1() const { return type() == ShadowRootType::Open || type() == Shado
wRootType::Closed; } | 89 bool isV1() const { return type() == ShadowRootType::Open || type() == Shado
wRootType::Closed; } |
90 | 90 |
91 bool isYoungest() const { return !youngerShadowRoot(); } | 91 bool isYoungest() const { return !youngerShadowRoot(); } |
92 bool isOldest() const { return !olderShadowRoot(); } | 92 bool isOldest() const { return !olderShadowRoot(); } |
93 | 93 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 HTMLSlotElement* assignedSlotFor(const Node& node) const | 128 HTMLSlotElement* assignedSlotFor(const Node& node) const |
129 { | 129 { |
130 DCHECK(m_slotAssignment); | 130 DCHECK(m_slotAssignment); |
131 return m_slotAssignment->assignedSlotFor(node); | 131 return m_slotAssignment->assignedSlotFor(node); |
132 } | 132 } |
133 | 133 |
134 // Make protected methods from base class public here. | 134 // Make protected methods from base class public here. |
135 using TreeScope::setDocument; | 135 using TreeScope::setDocument; |
136 using TreeScope::setParentTreeScope; | 136 using TreeScope::setParentTreeScope; |
137 | 137 |
138 public: | |
139 Element* activeElement() const; | 138 Element* activeElement() const; |
140 | 139 |
141 ShadowRoot* olderShadowRoot() const { return next(); } | |
142 | |
143 String innerHTML() const; | 140 String innerHTML() const; |
144 void setInnerHTML(const String&, ExceptionState&); | 141 void setInnerHTML(const String&, ExceptionState&); |
145 | 142 |
146 Node* cloneNode(bool, ExceptionState&); | 143 Node* cloneNode(bool, ExceptionState&); |
147 | 144 |
148 StyleSheetList* styleSheets(); | 145 StyleSheetList* styleSheets(); |
149 | 146 |
150 void setDelegatesFocus(bool flag) { m_delegatesFocus = flag; } | 147 void setDelegatesFocus(bool flag) { m_delegatesFocus = flag; } |
151 bool delegatesFocus() const { return m_delegatesFocus; } | 148 bool delegatesFocus() const { return m_delegatesFocus; } |
152 | 149 |
153 DECLARE_VIRTUAL_TRACE(); | 150 DECLARE_VIRTUAL_TRACE(); |
154 | 151 |
155 private: | 152 private: |
156 ShadowRoot(Document&, ShadowRootType); | 153 ShadowRoot(Document&, ShadowRootType); |
157 ~ShadowRoot() override; | 154 ~ShadowRoot() override; |
158 | 155 |
159 void childrenChanged(const ChildrenChange&) override; | 156 void childrenChanged(const ChildrenChange&) override; |
160 | 157 |
161 ShadowRootRareData* ensureShadowRootRareData(); | 158 ShadowRootRareData& ensureShadowRootRareData(); |
162 ShadowRootRareDataV0* ensureShadowRootRareDataV0(); | 159 ShadowRootRareDataV0& ensureShadowRootRareDataV0(); |
163 | 160 |
164 void addChildShadowRoot(); | 161 void addChildShadowRoot(); |
165 void removeChildShadowRoot(); | 162 void removeChildShadowRoot(); |
166 void invalidateDescendantInsertionPoints(); | 163 void invalidateDescendantInsertionPoints(); |
167 | 164 |
168 // ShadowRoots should never be cloned. | 165 // ShadowRoots should never be cloned. |
169 Node* cloneNode(bool) override { return nullptr; } | 166 Node* cloneNode(bool) override { return nullptr; } |
170 | 167 |
171 // FIXME: This shouldn't happen. https://bugs.webkit.org/show_bug.cgi?id=888
34 | 168 // FIXME: This shouldn't happen. https://bugs.webkit.org/show_bug.cgi?id=888
34 |
172 bool isOrphan() const { return !host(); } | 169 bool isOrphan() const { return !host(); } |
173 | 170 |
174 void invalidateDescendantSlots(); | 171 void invalidateDescendantSlots(); |
175 unsigned descendantSlotCount() const; | 172 unsigned descendantSlotCount() const; |
176 | 173 |
177 Member<ShadowRoot> m_prev; | |
178 Member<ShadowRoot> m_next; | |
179 Member<ShadowRootRareData> m_shadowRootRareData; | 174 Member<ShadowRootRareData> m_shadowRootRareData; |
180 Member<ShadowRootRareDataV0> m_shadowRootRareDataV0; | 175 Member<ShadowRootRareDataV0> m_shadowRootRareDataV0; |
181 | |
182 Member<SlotAssignment> m_slotAssignment; | 176 Member<SlotAssignment> m_slotAssignment; |
183 unsigned m_numberOfStyles : 26; | 177 unsigned m_numberOfStyles : 26; |
184 unsigned m_type : 2; | 178 unsigned m_type : 2; |
185 unsigned m_registeredWithParentShadowRoot : 1; | 179 unsigned m_registeredWithParentShadowRoot : 1; |
186 unsigned m_descendantInsertionPointsIsValid : 1; | 180 unsigned m_descendantInsertionPointsIsValid : 1; |
187 unsigned m_delegatesFocus : 1; | 181 unsigned m_delegatesFocus : 1; |
188 unsigned m_descendantSlotsIsValid : 1; | 182 unsigned m_descendantSlotsIsValid : 1; |
189 }; | 183 }; |
190 | 184 |
191 inline Element* ShadowRoot::activeElement() const | 185 inline Element* ShadowRoot::activeElement() const |
(...skipping 11 matching lines...) Expand all Loading... |
203 | 197 |
204 DEFINE_NODE_TYPE_CASTS(ShadowRoot, isShadowRoot()); | 198 DEFINE_NODE_TYPE_CASTS(ShadowRoot, isShadowRoot()); |
205 DEFINE_TYPE_CASTS(ShadowRoot, TreeScope, treeScope, treeScope->rootNode().isShad
owRoot(), treeScope.rootNode().isShadowRoot()); | 199 DEFINE_TYPE_CASTS(ShadowRoot, TreeScope, treeScope, treeScope->rootNode().isShad
owRoot(), treeScope.rootNode().isShadowRoot()); |
206 DEFINE_TYPE_CASTS(TreeScope, ShadowRoot, shadowRoot, true, true); | 200 DEFINE_TYPE_CASTS(TreeScope, ShadowRoot, shadowRoot, true, true); |
207 | 201 |
208 CORE_EXPORT std::ostream& operator<<(std::ostream&, const ShadowRootType&); | 202 CORE_EXPORT std::ostream& operator<<(std::ostream&, const ShadowRootType&); |
209 | 203 |
210 } // namespace blink | 204 } // namespace blink |
211 | 205 |
212 #endif // ShadowRoot_h | 206 #endif // ShadowRoot_h |
OLD | NEW |