| 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 17 matching lines...) Expand all Loading... |
| 28 #include "sky/engine/core/dom/shadow/ShadowRoot.h" | 28 #include "sky/engine/core/dom/shadow/ShadowRoot.h" |
| 29 | 29 |
| 30 #include "sky/engine/bindings/core/v8/ExceptionState.h" | 30 #include "sky/engine/bindings/core/v8/ExceptionState.h" |
| 31 #include "sky/engine/core/css/resolver/StyleResolver.h" | 31 #include "sky/engine/core/css/resolver/StyleResolver.h" |
| 32 #include "sky/engine/core/dom/Document.h" | 32 #include "sky/engine/core/dom/Document.h" |
| 33 #include "sky/engine/core/dom/ElementTraversal.h" | 33 #include "sky/engine/core/dom/ElementTraversal.h" |
| 34 #include "sky/engine/core/dom/StyleEngine.h" | 34 #include "sky/engine/core/dom/StyleEngine.h" |
| 35 #include "sky/engine/core/dom/Text.h" | 35 #include "sky/engine/core/dom/Text.h" |
| 36 #include "sky/engine/core/dom/shadow/ElementShadow.h" | 36 #include "sky/engine/core/dom/shadow/ElementShadow.h" |
| 37 #include "sky/engine/core/dom/shadow/InsertionPoint.h" | 37 #include "sky/engine/core/dom/shadow/InsertionPoint.h" |
| 38 #include "sky/engine/core/dom/shadow/ShadowRootRareData.h" | |
| 39 #include "sky/engine/public/platform/Platform.h" | 38 #include "sky/engine/public/platform/Platform.h" |
| 40 | 39 |
| 41 namespace blink { | 40 namespace blink { |
| 42 | 41 |
| 43 struct SameSizeAsShadowRoot : public DocumentFragment, public TreeScope { | 42 struct SameSizeAsShadowRoot : public DocumentFragment, public TreeScope { |
| 44 void* pointers[1]; | 43 Vector<RefPtr<InsertionPoint>> vector; |
| 45 unsigned countersAndFlags[1]; | 44 unsigned countersAndFlags[3]; |
| 46 }; | 45 }; |
| 47 | 46 |
| 48 COMPILE_ASSERT(sizeof(ShadowRoot) == sizeof(SameSizeAsShadowRoot), shadowroot_sh
ould_stay_small); | 47 COMPILE_ASSERT(sizeof(ShadowRoot) == sizeof(SameSizeAsShadowRoot), shadowroot_sh
ould_stay_small); |
| 49 | 48 |
| 50 ShadowRoot::ShadowRoot(Document& document) | 49 ShadowRoot::ShadowRoot(Document& document) |
| 51 : DocumentFragment(0, CreateShadowRoot) | 50 : DocumentFragment(0, CreateShadowRoot) |
| 52 , TreeScope(*this, document) | 51 , TreeScope(*this, document) |
| 52 , m_descendantContentElementCount(0) |
| 53 , m_childShadowRootCount(0) |
| 53 , m_descendantInsertionPointsIsValid(false) | 54 , m_descendantInsertionPointsIsValid(false) |
| 54 { | 55 { |
| 55 } | 56 } |
| 56 | 57 |
| 57 ShadowRoot::~ShadowRoot() | 58 ShadowRoot::~ShadowRoot() |
| 58 { | 59 { |
| 59 // We cannot let ContainerNode destructor call willBeDeletedFromDocument() | 60 // We cannot let ContainerNode destructor call willBeDeletedFromDocument() |
| 60 // for this ShadowRoot instance because TreeScope destructor | 61 // for this ShadowRoot instance because TreeScope destructor |
| 61 // clears Node::m_treeScope thus ContainerNode is no longer able | 62 // clears Node::m_treeScope thus ContainerNode is no longer able |
| 62 // to access it Document reference after that. | 63 // to access it Document reference after that. |
| 63 willBeDeletedFromDocument(); | 64 willBeDeletedFromDocument(); |
| 64 | 65 |
| 65 // We must remove all of our children first before the TreeScope destructor | 66 // We must remove all of our children first before the TreeScope destructor |
| 66 // runs so we don't go through TreeScopeAdopter for each child with a | 67 // runs so we don't go through TreeScopeAdopter for each child with a |
| 67 // destructed tree scope in each descendant. | 68 // destructed tree scope in each descendant. |
| 68 removeDetachedChildren(); | 69 removeDetachedChildren(); |
| 69 | 70 |
| 70 // We must call clearRareData() here since a ShadowRoot class inherits TreeS
cope | 71 // We must call clearRareData() here since a ShadowRoot class inherits TreeS
cope |
| 71 // as well as Node. See a comment on TreeScope.h for the reason. | 72 // as well as Node. See a comment on TreeScope.h for the reason. |
| 72 if (hasRareData()) | 73 if (hasRareData()) |
| 73 clearRareData(); | 74 clearRareData(); |
| 74 } | 75 } |
| 75 | 76 |
| 76 void ShadowRoot::dispose() | 77 void ShadowRoot::dispose() |
| 77 { | 78 { |
| 79 invalidateDescendantInsertionPoints(); |
| 78 removeDetachedChildren(); | 80 removeDetachedChildren(); |
| 79 } | 81 } |
| 80 | 82 |
| 81 PassRefPtr<Node> ShadowRoot::cloneNode(bool, ExceptionState& exceptionState) | 83 PassRefPtr<Node> ShadowRoot::cloneNode(bool, ExceptionState& exceptionState) |
| 82 { | 84 { |
| 83 exceptionState.throwDOMException(DataCloneError, "ShadowRoot nodes are not c
lonable."); | 85 exceptionState.throwDOMException(DataCloneError, "ShadowRoot nodes are not c
lonable."); |
| 84 return nullptr; | 86 return nullptr; |
| 85 } | 87 } |
| 86 | 88 |
| 89 PassRefPtr<Node> ShadowRoot::cloneNode(ExceptionState& exceptionState) |
| 90 { |
| 91 return cloneNode(exceptionState); |
| 92 } |
| 93 |
| 94 PassRefPtr<Node> ShadowRoot::cloneNode(bool deep) |
| 95 { |
| 96 return nullptr; |
| 97 } |
| 98 |
| 87 void ShadowRoot::recalcStyle(StyleRecalcChange change) | 99 void ShadowRoot::recalcStyle(StyleRecalcChange change) |
| 88 { | 100 { |
| 89 if (styleChangeType() >= SubtreeStyleChange) | 101 if (styleChangeType() >= SubtreeStyleChange) |
| 90 change = Force; | 102 change = Force; |
| 91 | 103 |
| 92 // There's no style to update so just calling recalcStyle means we're update
d. | 104 // There's no style to update so just calling recalcStyle means we're update
d. |
| 93 clearNeedsStyleRecalc(); | 105 clearNeedsStyleRecalc(); |
| 94 | 106 |
| 95 // FIXME: This doesn't handle :hover + div properly like Element::recalcStyl
e does. | 107 // FIXME: This doesn't handle :hover + div properly like Element::recalcStyl
e does. |
| 96 Text* lastTextNode = 0; | 108 Text* lastTextNode = 0; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 127 root = insertionPoint->containingShadowRoot(); | 139 root = insertionPoint->containingShadowRoot(); |
| 128 if (root) | 140 if (root) |
| 129 root->removeChildShadowRoot(); | 141 root->removeChildShadowRoot(); |
| 130 | 142 |
| 131 if (inActiveDocument()) | 143 if (inActiveDocument()) |
| 132 document().styleEngine()->removeTreeScope(*this); | 144 document().styleEngine()->removeTreeScope(*this); |
| 133 | 145 |
| 134 DocumentFragment::removedFrom(insertionPoint); | 146 DocumentFragment::removedFrom(insertionPoint); |
| 135 } | 147 } |
| 136 | 148 |
| 137 ShadowRootRareData* ShadowRoot::ensureShadowRootRareData() | 149 void ShadowRoot::didAddInsertionPoint() |
| 138 { | 150 { |
| 139 if (m_shadowRootRareData) | 151 ++m_descendantContentElementCount; |
| 140 return m_shadowRootRareData.get(); | |
| 141 | |
| 142 m_shadowRootRareData = adoptPtr(new ShadowRootRareData); | |
| 143 return m_shadowRootRareData.get(); | |
| 144 } | |
| 145 | |
| 146 bool ShadowRoot::containsContentElements() const | |
| 147 { | |
| 148 return m_shadowRootRareData ? m_shadowRootRareData->containsContentElements(
) : 0; | |
| 149 } | |
| 150 | |
| 151 bool ShadowRoot::containsShadowRoots() const | |
| 152 { | |
| 153 return m_shadowRootRareData ? m_shadowRootRareData->containsShadowRoots() :
0; | |
| 154 } | |
| 155 | |
| 156 void ShadowRoot::didAddInsertionPoint(InsertionPoint* insertionPoint) | |
| 157 { | |
| 158 ensureShadowRootRareData()->didAddInsertionPoint(insertionPoint); | |
| 159 invalidateDescendantInsertionPoints(); | 152 invalidateDescendantInsertionPoints(); |
| 160 } | 153 } |
| 161 | 154 |
| 162 void ShadowRoot::didRemoveInsertionPoint(InsertionPoint* insertionPoint) | 155 void ShadowRoot::didRemoveInsertionPoint() |
| 163 { | 156 { |
| 164 m_shadowRootRareData->didRemoveInsertionPoint(insertionPoint); | 157 ASSERT(m_descendantContentElementCount); |
| 158 --m_descendantContentElementCount; |
| 165 invalidateDescendantInsertionPoints(); | 159 invalidateDescendantInsertionPoints(); |
| 166 } | 160 } |
| 167 | 161 |
| 168 void ShadowRoot::addChildShadowRoot() | 162 void ShadowRoot::addChildShadowRoot() |
| 169 { | 163 { |
| 170 ensureShadowRootRareData()->didAddChildShadowRoot(); | 164 ++m_childShadowRootCount; |
| 171 } | 165 } |
| 172 | 166 |
| 173 void ShadowRoot::removeChildShadowRoot() | 167 void ShadowRoot::removeChildShadowRoot() |
| 174 { | 168 { |
| 175 // FIXME: Why isn't this an ASSERT? | 169 ASSERT(m_childShadowRootCount); |
| 176 if (!m_shadowRootRareData) | 170 --m_childShadowRootCount; |
| 177 return; | |
| 178 m_shadowRootRareData->didRemoveChildShadowRoot(); | |
| 179 } | |
| 180 | |
| 181 unsigned ShadowRoot::childShadowRootCount() const | |
| 182 { | |
| 183 return m_shadowRootRareData ? m_shadowRootRareData->childShadowRootCount() :
0; | |
| 184 } | 171 } |
| 185 | 172 |
| 186 void ShadowRoot::invalidateDescendantInsertionPoints() | 173 void ShadowRoot::invalidateDescendantInsertionPoints() |
| 187 { | 174 { |
| 188 m_descendantInsertionPointsIsValid = false; | 175 m_descendantInsertionPointsIsValid = false; |
| 189 m_shadowRootRareData->clearDescendantInsertionPoints(); | 176 m_descendantInsertionPoints.clear(); |
| 177 } |
| 178 |
| 179 bool ShadowRoot::containsContentElements() const |
| 180 { |
| 181 return m_descendantContentElementCount; |
| 182 } |
| 183 |
| 184 bool ShadowRoot::containsShadowRoots() const |
| 185 { |
| 186 return m_childShadowRootCount; |
| 190 } | 187 } |
| 191 | 188 |
| 192 const Vector<RefPtr<InsertionPoint> >& ShadowRoot::descendantInsertionPoints() | 189 const Vector<RefPtr<InsertionPoint> >& ShadowRoot::descendantInsertionPoints() |
| 193 { | 190 { |
| 194 DEFINE_STATIC_LOCAL(Vector<RefPtr<InsertionPoint> >, emptyList, ()); | 191 DEFINE_STATIC_LOCAL(Vector<RefPtr<InsertionPoint> >, emptyList, ()); |
| 195 if (m_shadowRootRareData && m_descendantInsertionPointsIsValid) | 192 if (m_descendantInsertionPointsIsValid) |
| 196 return m_shadowRootRareData->descendantInsertionPoints(); | 193 return m_descendantInsertionPoints; |
| 197 | 194 |
| 198 m_descendantInsertionPointsIsValid = true; | 195 m_descendantInsertionPointsIsValid = true; |
| 199 | 196 |
| 200 if (!containsInsertionPoints()) | 197 if (!containsContentElements()) |
| 201 return emptyList; | 198 return emptyList; |
| 202 | 199 |
| 203 Vector<RefPtr<InsertionPoint> > insertionPoints; | 200 Vector<RefPtr<InsertionPoint> > insertionPoints; |
| 204 for (InsertionPoint* insertionPoint = Traversal<InsertionPoint>::firstWithin
(*this); insertionPoint; insertionPoint = Traversal<InsertionPoint>::next(*inser
tionPoint, this)) | 201 for (InsertionPoint* insertionPoint = Traversal<InsertionPoint>::firstWithin
(*this); insertionPoint; insertionPoint = Traversal<InsertionPoint>::next(*inser
tionPoint, this)) |
| 205 insertionPoints.append(insertionPoint); | 202 insertionPoints.append(insertionPoint); |
| 206 | 203 |
| 207 ensureShadowRootRareData()->setDescendantInsertionPoints(insertionPoints); | 204 m_descendantInsertionPoints.swap(insertionPoints); |
| 208 | 205 |
| 209 return m_shadowRootRareData->descendantInsertionPoints(); | 206 return m_descendantInsertionPoints; |
| 210 } | 207 } |
| 211 | 208 |
| 212 } | 209 } |
| OLD | NEW |