Chromium Code Reviews| 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 removeDetachedShadowRoots(); | 142 removeDetachedShadowRoots(); |
| 143 #endif | 143 #endif |
| 144 } | 144 } |
| 145 | 145 |
| 146 ShadowRoot& ElementShadow::addShadowRoot(Element& shadowHost, ShadowRootType typ e) | 146 ShadowRoot& ElementShadow::addShadowRoot(Element& shadowHost, ShadowRootType typ e) |
| 147 { | 147 { |
| 148 EventDispatchForbiddenScope assertNoEventDispatch; | 148 EventDispatchForbiddenScope assertNoEventDispatch; |
| 149 ScriptForbiddenScope forbidScript; | 149 ScriptForbiddenScope forbidScript; |
| 150 | 150 |
| 151 if (type == ShadowRootType::V0) { | 151 if (type == ShadowRootType::V0) { |
| 152 if (!youngestShadowRoot()) { | 152 if (m_shadowRoots.isEmpty()) { |
|
hayato
2015/10/19 06:58:19
Updated: Use m_shadowRoots.isEmpty() here because
kochi
2015/10/19 07:02:03
Acknowledged.
| |
| 153 shadowHost.willAddFirstAuthorShadowRoot(); | 153 shadowHost.willAddFirstAuthorShadowRoot(); |
| 154 } else if (youngestShadowRoot()->type() == ShadowRootType::UserAgent) { | 154 } else if (m_shadowRoots.tail()->type() == ShadowRootType::UserAgent) { |
| 155 shadowHost.willAddFirstAuthorShadowRoot(); | 155 shadowHost.willAddFirstAuthorShadowRoot(); |
| 156 UseCounter::countDeprecation(shadowHost.document(), UseCounter::Elem entCreateShadowRootMultipleWithUserAgentShadowRoot); | 156 UseCounter::countDeprecation(shadowHost.document(), UseCounter::Elem entCreateShadowRootMultipleWithUserAgentShadowRoot); |
| 157 } else { | 157 } else { |
| 158 UseCounter::countDeprecation(shadowHost.document(), UseCounter::Elem entCreateShadowRootMultiple); | 158 UseCounter::countDeprecation(shadowHost.document(), UseCounter::Elem entCreateShadowRootMultiple); |
| 159 } | 159 } |
| 160 } else if (type == ShadowRootType::Open || type == ShadowRootType::Closed) { | 160 } else if (type == ShadowRootType::Open || type == ShadowRootType::Closed) { |
| 161 shadowHost.willAddFirstAuthorShadowRoot(); | 161 shadowHost.willAddFirstAuthorShadowRoot(); |
| 162 } | 162 } |
| 163 | 163 |
| 164 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow Root()) | 164 for (ShadowRoot* root = m_shadowRoots.tail(); root; root = root->olderShadow Root()) |
|
kochi
2015/10/19 07:02:03
Should this be m_shadowRoots.head() instead of m_s
hayato
2015/10/19 07:12:11
Done. Nice catch!
| |
| 165 root->lazyReattachIfAttached(); | 165 root->lazyReattachIfAttached(); |
| 166 | 166 |
| 167 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = ShadowRoot::create(shadowHost.do cument(), type); | 167 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = ShadowRoot::create(shadowHost.do cument(), type); |
| 168 shadowRoot->setParentOrShadowHostNode(&shadowHost); | 168 shadowRoot->setParentOrShadowHostNode(&shadowHost); |
| 169 shadowRoot->setParentTreeScope(shadowHost.treeScope()); | 169 shadowRoot->setParentTreeScope(shadowHost.treeScope()); |
| 170 m_shadowRoots.push(shadowRoot.get()); | 170 m_shadowRoots.push(shadowRoot.get()); |
| 171 setNeedsDistributionRecalc(); | 171 setNeedsDistributionRecalc(); |
| 172 | 172 |
| 173 shadowRoot->insertedInto(&shadowHost); | 173 shadowRoot->insertedInto(&shadowHost); |
| 174 shadowHost.setChildNeedsStyleRecalc(); | 174 shadowHost.setChildNeedsStyleRecalc(); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 196 oldRoot->setNext(0); | 196 oldRoot->setNext(0); |
| 197 } | 197 } |
| 198 } | 198 } |
| 199 #endif | 199 #endif |
| 200 | 200 |
| 201 void ElementShadow::attach(const Node::AttachContext& context) | 201 void ElementShadow::attach(const Node::AttachContext& context) |
| 202 { | 202 { |
| 203 Node::AttachContext childrenContext(context); | 203 Node::AttachContext childrenContext(context); |
| 204 childrenContext.resolvedStyle = 0; | 204 childrenContext.resolvedStyle = 0; |
| 205 | 205 |
| 206 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow Root()) { | 206 for (ShadowRoot* root = &youngestShadowRoot(); root; root = root->olderShado wRoot()) { |
| 207 if (root->needsAttach()) | 207 if (root->needsAttach()) |
| 208 root->attach(childrenContext); | 208 root->attach(childrenContext); |
| 209 } | 209 } |
| 210 } | 210 } |
| 211 | 211 |
| 212 void ElementShadow::detach(const Node::AttachContext& context) | 212 void ElementShadow::detach(const Node::AttachContext& context) |
| 213 { | 213 { |
| 214 Node::AttachContext childrenContext(context); | 214 Node::AttachContext childrenContext(context); |
| 215 childrenContext.resolvedStyle = 0; | 215 childrenContext.resolvedStyle = 0; |
| 216 | 216 |
| 217 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow Root()) | 217 for (ShadowRoot* root = &youngestShadowRoot(); root; root = root->olderShado wRoot()) |
| 218 root->detach(childrenContext); | 218 root->detach(childrenContext); |
| 219 } | 219 } |
| 220 | 220 |
| 221 void ElementShadow::setNeedsDistributionRecalc() | 221 void ElementShadow::setNeedsDistributionRecalc() |
| 222 { | 222 { |
| 223 if (m_needsDistributionRecalc) | 223 if (m_needsDistributionRecalc) |
| 224 return; | 224 return; |
| 225 m_needsDistributionRecalc = true; | 225 m_needsDistributionRecalc = true; |
| 226 host()->markAncestorsWithChildNeedsDistributionRecalc(); | 226 host()->markAncestorsWithChildNeedsDistributionRecalc(); |
| 227 clearDistribution(); | 227 clearDistribution(); |
| 228 } | 228 } |
| 229 | 229 |
| 230 bool ElementShadow::hasSameStyles(const ElementShadow* other) const | 230 bool ElementShadow::hasSameStyles(const ElementShadow* other) const |
| 231 { | 231 { |
| 232 ShadowRoot* root = youngestShadowRoot(); | 232 ShadowRoot* root = &youngestShadowRoot(); |
| 233 ShadowRoot* otherRoot = other->youngestShadowRoot(); | 233 ShadowRoot* otherRoot = &other->youngestShadowRoot(); |
| 234 while (root || otherRoot) { | 234 while (root || otherRoot) { |
| 235 if (!root || !otherRoot) | 235 if (!root || !otherRoot) |
| 236 return false; | 236 return false; |
| 237 | 237 |
| 238 StyleSheetList* list = root->styleSheets(); | 238 StyleSheetList* list = root->styleSheets(); |
| 239 StyleSheetList* otherList = otherRoot->styleSheets(); | 239 StyleSheetList* otherList = otherRoot->styleSheets(); |
| 240 | 240 |
| 241 if (list->length() != otherList->length()) | 241 if (list->length() != otherList->length()) |
| 242 return false; | 242 return false; |
| 243 | 243 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 273 return it == m_nodeToInsertionPoints.end() ? nullptr : &it->value; | 273 return it == m_nodeToInsertionPoints.end() ? nullptr : &it->value; |
| 274 #endif | 274 #endif |
| 275 } | 275 } |
| 276 | 276 |
| 277 void ElementShadow::distribute() | 277 void ElementShadow::distribute() |
| 278 { | 278 { |
| 279 host()->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing: :create(StyleChangeReason::Shadow)); | 279 host()->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing: :create(StyleChangeReason::Shadow)); |
| 280 WillBeHeapVector<RawPtrWillBeMember<HTMLShadowElement>, 32> shadowInsertionP oints; | 280 WillBeHeapVector<RawPtrWillBeMember<HTMLShadowElement>, 32> shadowInsertionP oints; |
| 281 DistributionPool pool(*host()); | 281 DistributionPool pool(*host()); |
| 282 | 282 |
| 283 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow Root()) { | 283 for (ShadowRoot* root = &youngestShadowRoot(); root; root = root->olderShado wRoot()) { |
| 284 HTMLShadowElement* shadowInsertionPoint = 0; | 284 HTMLShadowElement* shadowInsertionPoint = 0; |
| 285 const WillBeHeapVector<RefPtrWillBeMember<InsertionPoint>>& insertionPoi nts = root->descendantInsertionPoints(); | 285 const WillBeHeapVector<RefPtrWillBeMember<InsertionPoint>>& insertionPoi nts = root->descendantInsertionPoints(); |
| 286 for (size_t i = 0; i < insertionPoints.size(); ++i) { | 286 for (size_t i = 0; i < insertionPoints.size(); ++i) { |
| 287 InsertionPoint* point = insertionPoints[i].get(); | 287 InsertionPoint* point = insertionPoints[i].get(); |
| 288 if (!point->isActive()) | 288 if (!point->isActive()) |
| 289 continue; | 289 continue; |
| 290 if (isHTMLShadowElement(*point)) { | 290 if (isHTMLShadowElement(*point)) { |
| 291 ASSERT(!shadowInsertionPoint); | 291 ASSERT(!shadowInsertionPoint); |
| 292 shadowInsertionPoint = toHTMLShadowElement(point); | 292 shadowInsertionPoint = toHTMLShadowElement(point); |
| 293 shadowInsertionPoints.append(shadowInsertionPoint); | 293 shadowInsertionPoints.append(shadowInsertionPoint); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 break; | 365 break; |
| 366 shadow->setNeedsSelectFeatureSet(); | 366 shadow->setNeedsSelectFeatureSet(); |
| 367 } | 367 } |
| 368 setNeedsDistributionRecalc(); | 368 setNeedsDistributionRecalc(); |
| 369 } | 369 } |
| 370 | 370 |
| 371 void ElementShadow::clearDistribution() | 371 void ElementShadow::clearDistribution() |
| 372 { | 372 { |
| 373 m_nodeToInsertionPoints.clear(); | 373 m_nodeToInsertionPoints.clear(); |
| 374 | 374 |
| 375 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow Root()) | 375 for (ShadowRoot* root = &youngestShadowRoot(); root; root = root->olderShado wRoot()) |
| 376 root->setShadowInsertionPointOfYoungerShadowRoot(nullptr); | 376 root->setShadowInsertionPointOfYoungerShadowRoot(nullptr); |
| 377 } | 377 } |
| 378 | 378 |
| 379 DEFINE_TRACE(ElementShadow) | 379 DEFINE_TRACE(ElementShadow) |
| 380 { | 380 { |
| 381 #if ENABLE(OILPAN) | 381 #if ENABLE(OILPAN) |
| 382 visitor->trace(m_nodeToInsertionPoints); | 382 visitor->trace(m_nodeToInsertionPoints); |
| 383 visitor->trace(m_selectFeatures); | 383 visitor->trace(m_selectFeatures); |
| 384 // Shadow roots are linked with previous and next pointers which are traced. | 384 // Shadow roots are linked with previous and next pointers which are traced. |
| 385 // It is therefore enough to trace one of the shadow roots here and the | 385 // It is therefore enough to trace one of the shadow roots here and the |
| 386 // rest will be traced from there. | 386 // rest will be traced from there. |
| 387 visitor->trace(m_shadowRoots.head()); | 387 visitor->trace(m_shadowRoots.head()); |
| 388 #endif | 388 #endif |
| 389 } | 389 } |
| 390 | 390 |
| 391 } // namespace | 391 } // namespace |
| OLD | NEW |