| 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 ElementShadow::ElementShadow() | 137 ElementShadow::ElementShadow() |
| 138 : m_needsDistributionRecalc(false) | 138 : m_needsDistributionRecalc(false) |
| 139 , m_needsSelectFeatureSet(false) | 139 , m_needsSelectFeatureSet(false) |
| 140 { | 140 { |
| 141 } | 141 } |
| 142 | 142 |
| 143 ElementShadow::~ElementShadow() | 143 ElementShadow::~ElementShadow() |
| 144 { | 144 { |
| 145 } | 145 } |
| 146 | 146 |
| 147 ShadowRoot& ElementShadow::youngestShadowRoot() const |
| 148 { |
| 149 ShadowRoot* current = m_shadowRoot; |
| 150 DCHECK(current); |
| 151 while (current->youngerShadowRoot()) |
| 152 current = current->youngerShadowRoot(); |
| 153 return *current; |
| 154 } |
| 155 |
| 147 ShadowRoot& ElementShadow::addShadowRoot(Element& shadowHost, ShadowRootType typ
e) | 156 ShadowRoot& ElementShadow::addShadowRoot(Element& shadowHost, ShadowRootType typ
e) |
| 148 { | 157 { |
| 149 EventDispatchForbiddenScope assertNoEventDispatch; | 158 EventDispatchForbiddenScope assertNoEventDispatch; |
| 150 ScriptForbiddenScope forbidScript; | 159 ScriptForbiddenScope forbidScript; |
| 151 | 160 |
| 152 if (type == ShadowRootType::V0 && !m_shadowRoots.isEmpty()) { | 161 if (type == ShadowRootType::V0 && m_shadowRoot) { |
| 153 DCHECK_NE(ShadowRootType::UserAgent, m_shadowRoots.head()->type()); | 162 DCHECK_EQ(m_shadowRoot->type(), ShadowRootType::V0); |
| 154 Deprecation::countDeprecation(shadowHost.document(), UseCounter::Element
CreateShadowRootMultiple); | 163 Deprecation::countDeprecation(shadowHost.document(), UseCounter::Element
CreateShadowRootMultiple); |
| 155 } | 164 } |
| 156 | 165 |
| 157 for (ShadowRoot* root = m_shadowRoots.head(); root; root = root->olderShadow
Root()) | 166 if (m_shadowRoot) { |
| 158 root->lazyReattachIfAttached(); | 167 // TODO(hayato): Is the order, from the youngest to the oldest, importan
t? |
| 168 for (ShadowRoot* root = &youngestShadowRoot(); root; root = root->olderS
hadowRoot()) |
| 169 root->lazyReattachIfAttached(); |
| 170 } |
| 159 | 171 |
| 160 ShadowRoot* shadowRoot = ShadowRoot::create(shadowHost.document(), type); | 172 ShadowRoot* shadowRoot = ShadowRoot::create(shadowHost.document(), type); |
| 161 shadowRoot->setParentOrShadowHostNode(&shadowHost); | 173 shadowRoot->setParentOrShadowHostNode(&shadowHost); |
| 162 shadowRoot->setParentTreeScope(shadowHost.treeScope()); | 174 shadowRoot->setParentTreeScope(shadowHost.treeScope()); |
| 163 m_shadowRoots.push(shadowRoot); | 175 appendShadowRoot(*shadowRoot); |
| 164 setNeedsDistributionRecalc(); | 176 setNeedsDistributionRecalc(); |
| 165 | 177 |
| 166 shadowRoot->insertedInto(&shadowHost); | 178 shadowRoot->insertedInto(&shadowHost); |
| 167 shadowHost.setChildNeedsStyleRecalc(); | 179 shadowHost.setChildNeedsStyleRecalc(); |
| 168 shadowHost.setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTraci
ng::create(StyleChangeReason::Shadow)); | 180 shadowHost.setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTraci
ng::create(StyleChangeReason::Shadow)); |
| 169 | 181 |
| 170 InspectorInstrumentation::didPushShadowRoot(&shadowHost, shadowRoot); | 182 InspectorInstrumentation::didPushShadowRoot(&shadowHost, shadowRoot); |
| 171 | 183 |
| 172 return *shadowRoot; | 184 return *shadowRoot; |
| 173 } | 185 } |
| 174 | 186 |
| 187 void ElementShadow::appendShadowRoot(ShadowRoot& shadowRoot) |
| 188 { |
| 189 if (!m_shadowRoot) { |
| 190 m_shadowRoot = &shadowRoot; |
| 191 return; |
| 192 } |
| 193 ShadowRoot& youngest = youngestShadowRoot(); |
| 194 DCHECK(shadowRoot.type() == ShadowRootType::V0); |
| 195 DCHECK(youngest.type() == ShadowRootType::V0); |
| 196 youngest.setYoungerShadowRoot(shadowRoot); |
| 197 shadowRoot.setOlderShadowRoot(youngest); |
| 198 } |
| 199 |
| 175 void ElementShadow::attach(const Node::AttachContext& context) | 200 void ElementShadow::attach(const Node::AttachContext& context) |
| 176 { | 201 { |
| 177 Node::AttachContext childrenContext(context); | 202 Node::AttachContext childrenContext(context); |
| 178 childrenContext.resolvedStyle = 0; | 203 childrenContext.resolvedStyle = 0; |
| 179 | 204 |
| 180 for (ShadowRoot* root = &youngestShadowRoot(); root; root = root->olderShado
wRoot()) { | 205 for (ShadowRoot* root = &youngestShadowRoot(); root; root = root->olderShado
wRoot()) { |
| 181 if (root->needsAttach()) | 206 if (root->needsAttach()) |
| 182 root->attach(childrenContext); | 207 root->attach(childrenContext); |
| 183 } | 208 } |
| 184 } | 209 } |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 m_nodeToInsertionPoints.clear(); | 372 m_nodeToInsertionPoints.clear(); |
| 348 | 373 |
| 349 for (ShadowRoot* root = &youngestShadowRoot(); root; root = root->olderShado
wRoot()) | 374 for (ShadowRoot* root = &youngestShadowRoot(); root; root = root->olderShado
wRoot()) |
| 350 root->setShadowInsertionPointOfYoungerShadowRoot(nullptr); | 375 root->setShadowInsertionPointOfYoungerShadowRoot(nullptr); |
| 351 } | 376 } |
| 352 | 377 |
| 353 DEFINE_TRACE(ElementShadow) | 378 DEFINE_TRACE(ElementShadow) |
| 354 { | 379 { |
| 355 visitor->trace(m_nodeToInsertionPoints); | 380 visitor->trace(m_nodeToInsertionPoints); |
| 356 visitor->trace(m_selectFeatures); | 381 visitor->trace(m_selectFeatures); |
| 357 // Shadow roots are linked with previous and next pointers which are traced. | 382 visitor->trace(m_shadowRoot); |
| 358 // It is therefore enough to trace one of the shadow roots here and the | |
| 359 // rest will be traced from there. | |
| 360 visitor->trace(m_shadowRoots.head()); | |
| 361 } | 383 } |
| 362 | 384 |
| 363 } // namespace blink | 385 } // namespace blink |
| OLD | NEW |