| 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 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 #include "config.h" | 27 #include "config.h" |
| 28 #include "core/dom/shadow/ElementShadow.h" | 28 #include "core/dom/shadow/ElementShadow.h" |
| 29 | 29 |
| 30 #include "core/css/StyleSheetList.h" | 30 #include "core/css/StyleSheetList.h" |
| 31 #include "core/dom/Document.h" | 31 #include "core/dom/Document.h" |
| 32 #include "core/dom/ElementTraversal.h" | 32 #include "core/dom/ElementTraversal.h" |
| 33 #include "core/dom/NodeTraversal.h" | 33 #include "core/dom/NodeTraversal.h" |
| 34 #include "core/dom/shadow/ContentDistribution.h" | 34 #include "core/dom/shadow/ContentDistribution.h" |
| 35 #include "core/html/HTMLContentElement.h" | 35 #include "core/html/HTMLContentElement.h" |
| 36 #include "core/html/HTMLShadowElement.h" | |
| 37 #include "platform/EventDispatchForbiddenScope.h" | 36 #include "platform/EventDispatchForbiddenScope.h" |
| 38 #include "platform/ScriptForbiddenScope.h" | 37 #include "platform/ScriptForbiddenScope.h" |
| 39 | 38 |
| 40 namespace blink { | 39 namespace blink { |
| 41 | 40 |
| 42 class DistributionPool final { | 41 class DistributionPool final { |
| 43 STACK_ALLOCATED(); | 42 STACK_ALLOCATED(); |
| 44 public: | 43 public: |
| 45 explicit DistributionPool(const ContainerNode&); | 44 explicit DistributionPool(const ContainerNode&); |
| 46 void clear(); | 45 void clear(); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 const DestinationInsertionPoints* ElementShadow::destinationInsertionPointsFor(c
onst Node* key) const | 242 const DestinationInsertionPoints* ElementShadow::destinationInsertionPointsFor(c
onst Node* key) const |
| 244 { | 243 { |
| 245 ASSERT(key && !key->document().childNeedsDistributionRecalc()); | 244 ASSERT(key && !key->document().childNeedsDistributionRecalc()); |
| 246 NodeToDestinationInsertionPoints::const_iterator it = m_nodeToInsertionPoint
s.find(key); | 245 NodeToDestinationInsertionPoints::const_iterator it = m_nodeToInsertionPoint
s.find(key); |
| 247 return it == m_nodeToInsertionPoints.end() ? 0: &it->value; | 246 return it == m_nodeToInsertionPoints.end() ? 0: &it->value; |
| 248 } | 247 } |
| 249 | 248 |
| 250 void ElementShadow::distribute() | 249 void ElementShadow::distribute() |
| 251 { | 250 { |
| 252 host()->setNeedsStyleRecalc(SubtreeStyleChange); | 251 host()->setNeedsStyleRecalc(SubtreeStyleChange); |
| 253 Vector<RawPtr<HTMLShadowElement>, 32> shadowInsertionPoints; | |
| 254 DistributionPool pool(*host()); | 252 DistributionPool pool(*host()); |
| 255 | 253 |
| 256 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow
Root()) { | 254 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow
Root()) { |
| 257 HTMLShadowElement* shadowInsertionPoint = 0; | |
| 258 const Vector<RefPtr<InsertionPoint> >& insertionPoints = root->descendan
tInsertionPoints(); | 255 const Vector<RefPtr<InsertionPoint> >& insertionPoints = root->descendan
tInsertionPoints(); |
| 259 for (size_t i = 0; i < insertionPoints.size(); ++i) { | 256 for (size_t i = 0; i < insertionPoints.size(); ++i) { |
| 260 InsertionPoint* point = insertionPoints[i].get(); | 257 InsertionPoint* point = insertionPoints[i].get(); |
| 261 if (!point->isActive()) | 258 if (!point->isActive()) |
| 262 continue; | 259 continue; |
| 263 if (isHTMLShadowElement(*point)) { | 260 pool.distributeTo(point, this); |
| 264 ASSERT(!shadowInsertionPoint); | 261 if (ElementShadow* shadow = shadowWhereNodeCanBeDistributed(*point)) |
| 265 shadowInsertionPoint = toHTMLShadowElement(point); | 262 shadow->setNeedsDistributionRecalc(); |
| 266 shadowInsertionPoints.append(shadowInsertionPoint); | |
| 267 } else { | |
| 268 pool.distributeTo(point, this); | |
| 269 if (ElementShadow* shadow = shadowWhereNodeCanBeDistributed(*poi
nt)) | |
| 270 shadow->setNeedsDistributionRecalc(); | |
| 271 } | |
| 272 } | 263 } |
| 273 } | 264 } |
| 274 | |
| 275 for (size_t i = shadowInsertionPoints.size(); i > 0; --i) { | |
| 276 HTMLShadowElement* shadowInsertionPoint = shadowInsertionPoints[i - 1]; | |
| 277 ShadowRoot* root = shadowInsertionPoint->containingShadowRoot(); | |
| 278 ASSERT(root); | |
| 279 if (root->isOldest()) { | |
| 280 pool.distributeTo(shadowInsertionPoint, this); | |
| 281 } else { | |
| 282 DistributionPool olderShadowRootPool(*root->olderShadowRoot()); | |
| 283 olderShadowRootPool.distributeTo(shadowInsertionPoint, this); | |
| 284 root->olderShadowRoot()->setShadowInsertionPointOfYoungerShadowRoot(
shadowInsertionPoint); | |
| 285 } | |
| 286 if (ElementShadow* shadow = shadowWhereNodeCanBeDistributed(*shadowInser
tionPoint)) | |
| 287 shadow->setNeedsDistributionRecalc(); | |
| 288 } | |
| 289 } | 265 } |
| 290 | 266 |
| 291 void ElementShadow::didDistributeNode(const Node* node, InsertionPoint* insertio
nPoint) | 267 void ElementShadow::didDistributeNode(const Node* node, InsertionPoint* insertio
nPoint) |
| 292 { | 268 { |
| 293 NodeToDestinationInsertionPoints::AddResult result = m_nodeToInsertionPoints
.add(node, DestinationInsertionPoints()); | 269 NodeToDestinationInsertionPoints::AddResult result = m_nodeToInsertionPoints
.add(node, DestinationInsertionPoints()); |
| 294 result.storedValue->value.append(insertionPoint); | 270 result.storedValue->value.append(insertionPoint); |
| 295 } | 271 } |
| 296 | 272 |
| 297 const SelectRuleFeatureSet& ElementShadow::ensureSelectFeatureSet() | 273 const SelectRuleFeatureSet& ElementShadow::ensureSelectFeatureSet() |
| 298 { | 274 { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 if (shadow->needsSelectFeatureSet()) | 306 if (shadow->needsSelectFeatureSet()) |
| 331 break; | 307 break; |
| 332 shadow->setNeedsSelectFeatureSet(); | 308 shadow->setNeedsSelectFeatureSet(); |
| 333 } | 309 } |
| 334 setNeedsDistributionRecalc(); | 310 setNeedsDistributionRecalc(); |
| 335 } | 311 } |
| 336 | 312 |
| 337 void ElementShadow::clearDistribution() | 313 void ElementShadow::clearDistribution() |
| 338 { | 314 { |
| 339 m_nodeToInsertionPoints.clear(); | 315 m_nodeToInsertionPoints.clear(); |
| 340 | |
| 341 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow
Root()) | |
| 342 root->setShadowInsertionPointOfYoungerShadowRoot(nullptr); | |
| 343 } | 316 } |
| 344 | 317 |
| 345 void ElementShadow::trace(Visitor* visitor) | 318 void ElementShadow::trace(Visitor* visitor) |
| 346 { | 319 { |
| 347 #if ENABLE(OILPAN) | 320 #if ENABLE(OILPAN) |
| 348 visitor->trace(m_nodeToInsertionPoints); | 321 visitor->trace(m_nodeToInsertionPoints); |
| 349 visitor->trace(m_selectFeatures); | 322 visitor->trace(m_selectFeatures); |
| 350 // Shadow roots are linked with previous and next pointers which are traced. | 323 // Shadow roots are linked with previous and next pointers which are traced. |
| 351 // It is therefore enough to trace one of the shadow roots here and the | 324 // It is therefore enough to trace one of the shadow roots here and the |
| 352 // rest will be traced from there. | 325 // rest will be traced from there. |
| 353 visitor->trace(m_shadowRoots.head()); | 326 visitor->trace(m_shadowRoots.head()); |
| 354 #endif | 327 #endif |
| 355 } | 328 } |
| 356 | 329 |
| 357 } // namespace | 330 } // namespace |
| OLD | NEW |