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 20 matching lines...) Expand all Loading... | |
| 31 #include "core/css/StyleSheetList.h" | 31 #include "core/css/StyleSheetList.h" |
| 32 #include "core/dom/ContainerNodeAlgorithms.h" | 32 #include "core/dom/ContainerNodeAlgorithms.h" |
| 33 #include "core/dom/ElementTraversal.h" | 33 #include "core/dom/ElementTraversal.h" |
| 34 #include "core/dom/NodeTraversal.h" | 34 #include "core/dom/NodeTraversal.h" |
| 35 #include "core/dom/shadow/ContentDistribution.h" | 35 #include "core/dom/shadow/ContentDistribution.h" |
| 36 #include "core/html/HTMLContentElement.h" | 36 #include "core/html/HTMLContentElement.h" |
| 37 #include "core/html/HTMLShadowElement.h" | 37 #include "core/html/HTMLShadowElement.h" |
| 38 | 38 |
| 39 namespace WebCore { | 39 namespace WebCore { |
| 40 | 40 |
| 41 class DistributionPool { | 41 class DistributionPool FINAL { |
| 42 STACK_ALLOCATED(); | |
| 42 public: | 43 public: |
| 43 explicit DistributionPool(const ContainerNode&); | 44 explicit DistributionPool(const ContainerNode&); |
| 44 void clear(); | 45 void clear(); |
| 45 ~DistributionPool(); | 46 ~DistributionPool(); |
| 46 void distributeTo(InsertionPoint*, ElementShadow*); | 47 void distributeTo(InsertionPoint*, ElementShadow*); |
| 47 void populateChildren(const ContainerNode&); | 48 void populateChildren(const ContainerNode&); |
| 48 | 49 |
| 49 private: | 50 private: |
| 50 void detachNonDistributedNodes(); | 51 void detachNonDistributedNodes(); |
| 51 Vector<Node*, 32> m_nodes; | 52 WillBeHeapVector<RawPtrWillBeMember<Node>, 32> m_nodes; |
| 52 Vector<bool, 32> m_distributed; | 53 Vector<bool, 32> m_distributed; |
| 53 }; | 54 }; |
| 54 | 55 |
| 55 inline DistributionPool::DistributionPool(const ContainerNode& parent) | 56 inline DistributionPool::DistributionPool(const ContainerNode& parent) |
| 56 { | 57 { |
| 57 populateChildren(parent); | 58 populateChildren(parent); |
| 58 } | 59 } |
| 59 | 60 |
| 60 inline void DistributionPool::clear() | 61 inline void DistributionPool::clear() |
| 61 { | 62 { |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 root = root->olderShadowRoot(); | 233 root = root->olderShadowRoot(); |
| 233 otherRoot = otherRoot->olderShadowRoot(); | 234 otherRoot = otherRoot->olderShadowRoot(); |
| 234 } | 235 } |
| 235 | 236 |
| 236 return true; | 237 return true; |
| 237 } | 238 } |
| 238 | 239 |
| 239 const InsertionPoint* ElementShadow::finalDestinationInsertionPointFor(const Nod e* key) const | 240 const InsertionPoint* ElementShadow::finalDestinationInsertionPointFor(const Nod e* key) const |
| 240 { | 241 { |
| 241 ASSERT(key && !key->document().childNeedsDistributionRecalc()); | 242 ASSERT(key && !key->document().childNeedsDistributionRecalc()); |
| 242 NodeToDestinationInsertionPoints::const_iterator it = m_nodeToInsertionPoint s.find(key); | 243 NodeToDestinationInsertionPoints::const_iterator it = m_nodeToInsertionPoint s.find(const_cast<Node*>(key)); |
|
haraken
2014/05/12 13:38:35
Remove const_cast.
sof
2014/05/12 21:57:19
It was added for a reason. i.e., you run into reso
haraken
2014/05/13 05:49:50
Probably I'm misunderstanding, but won't the follo
| |
| 243 return it == m_nodeToInsertionPoints.end() ? 0: it->value.last().get(); | 244 return it == m_nodeToInsertionPoints.end() ? 0: it->value.last().get(); |
| 244 } | 245 } |
| 245 | 246 |
| 246 const DestinationInsertionPoints* ElementShadow::destinationInsertionPointsFor(c onst Node* key) const | 247 const DestinationInsertionPoints* ElementShadow::destinationInsertionPointsFor(c onst Node* key) const |
| 247 { | 248 { |
| 248 ASSERT(key && !key->document().childNeedsDistributionRecalc()); | 249 ASSERT(key && !key->document().childNeedsDistributionRecalc()); |
| 249 NodeToDestinationInsertionPoints::const_iterator it = m_nodeToInsertionPoint s.find(key); | 250 NodeToDestinationInsertionPoints::const_iterator it = m_nodeToInsertionPoint s.find(const_cast<Node*>(key)); |
| 250 return it == m_nodeToInsertionPoints.end() ? 0: &it->value; | 251 return it == m_nodeToInsertionPoints.end() ? 0: &it->value; |
| 251 } | 252 } |
| 252 | 253 |
| 253 void ElementShadow::distribute() | 254 void ElementShadow::distribute() |
| 254 { | 255 { |
| 255 host()->setNeedsStyleRecalc(SubtreeStyleChange); | 256 host()->setNeedsStyleRecalc(SubtreeStyleChange); |
| 256 Vector<HTMLShadowElement*, 32> shadowInsertionPoints; | 257 Vector<HTMLShadowElement*, 32> shadowInsertionPoints; |
| 257 DistributionPool pool(*host()); | 258 DistributionPool pool(*host()); |
| 258 | 259 |
| 259 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow Root()) { | 260 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow Root()) { |
| 260 HTMLShadowElement* shadowInsertionPoint = 0; | 261 HTMLShadowElement* shadowInsertionPoint = 0; |
| 261 const Vector<RefPtr<InsertionPoint> >& insertionPoints = root->descendan tInsertionPoints(); | 262 const WillBeHeapVector<RefPtrWillBeMember<InsertionPoint> >& insertionPo ints = root->descendantInsertionPoints(); |
| 262 for (size_t i = 0; i < insertionPoints.size(); ++i) { | 263 for (size_t i = 0; i < insertionPoints.size(); ++i) { |
| 263 InsertionPoint* point = insertionPoints[i].get(); | 264 InsertionPoint* point = insertionPoints[i].get(); |
| 264 if (!point->isActive()) | 265 if (!point->isActive()) |
| 265 continue; | 266 continue; |
| 266 if (isHTMLShadowElement(*point)) { | 267 if (isHTMLShadowElement(*point)) { |
| 267 ASSERT(!shadowInsertionPoint); | 268 ASSERT(!shadowInsertionPoint); |
| 268 shadowInsertionPoint = toHTMLShadowElement(point); | 269 shadowInsertionPoint = toHTMLShadowElement(point); |
| 269 shadowInsertionPoints.append(shadowInsertionPoint); | 270 shadowInsertionPoints.append(shadowInsertionPoint); |
| 270 } else { | 271 } else { |
| 271 pool.distributeTo(point, this); | 272 pool.distributeTo(point, this); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 288 olderShadowRootPool.distributeTo(shadowInsertionPoint, this); | 289 olderShadowRootPool.distributeTo(shadowInsertionPoint, this); |
| 289 root->olderShadowRoot()->setShadowInsertionPointOfYoungerShadowRoot( shadowInsertionPoint); | 290 root->olderShadowRoot()->setShadowInsertionPointOfYoungerShadowRoot( shadowInsertionPoint); |
| 290 } | 291 } |
| 291 if (ElementShadow* shadow = shadowWhereNodeCanBeDistributed(*shadowInser tionPoint)) | 292 if (ElementShadow* shadow = shadowWhereNodeCanBeDistributed(*shadowInser tionPoint)) |
| 292 shadow->setNeedsDistributionRecalc(); | 293 shadow->setNeedsDistributionRecalc(); |
| 293 } | 294 } |
| 294 } | 295 } |
| 295 | 296 |
| 296 void ElementShadow::didDistributeNode(const Node* node, InsertionPoint* insertio nPoint) | 297 void ElementShadow::didDistributeNode(const Node* node, InsertionPoint* insertio nPoint) |
| 297 { | 298 { |
| 298 NodeToDestinationInsertionPoints::AddResult result = m_nodeToInsertionPoints .add(node, DestinationInsertionPoints()); | 299 NodeToDestinationInsertionPoints::AddResult result = m_nodeToInsertionPoints .add(const_cast<Node*>(node), DestinationInsertionPoints()); |
| 299 result.storedValue->value.append(insertionPoint); | 300 result.storedValue->value.append(insertionPoint); |
| 300 } | 301 } |
| 301 | 302 |
| 302 const SelectRuleFeatureSet& ElementShadow::ensureSelectFeatureSet() | 303 const SelectRuleFeatureSet& ElementShadow::ensureSelectFeatureSet() |
| 303 { | 304 { |
| 304 if (!m_needsSelectFeatureSet) | 305 if (!m_needsSelectFeatureSet) |
| 305 return m_selectFeatures; | 306 return m_selectFeatures; |
| 306 | 307 |
| 307 m_selectFeatures.clear(); | 308 m_selectFeatures.clear(); |
| 308 for (ShadowRoot* root = oldestShadowRoot(); root; root = root->youngerShadow Root()) | 309 for (ShadowRoot* root = oldestShadowRoot(); root; root = root->youngerShadow Root()) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 void ElementShadow::clearDistribution() | 349 void ElementShadow::clearDistribution() |
| 349 { | 350 { |
| 350 m_nodeToInsertionPoints.clear(); | 351 m_nodeToInsertionPoints.clear(); |
| 351 | 352 |
| 352 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow Root()) | 353 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow Root()) |
| 353 root->setShadowInsertionPointOfYoungerShadowRoot(nullptr); | 354 root->setShadowInsertionPointOfYoungerShadowRoot(nullptr); |
| 354 } | 355 } |
| 355 | 356 |
| 356 void ElementShadow::trace(Visitor* visitor) | 357 void ElementShadow::trace(Visitor* visitor) |
| 357 { | 358 { |
| 359 visitor->trace(m_nodeToInsertionPoints); | |
| 358 // Shadow roots are linked with previous and next pointers which are traced. | 360 // Shadow roots are linked with previous and next pointers which are traced. |
| 359 // It is therefore enough to trace one of the shadow roots here and the | 361 // It is therefore enough to trace one of the shadow roots here and the |
| 360 // rest will be traced from there. | 362 // rest will be traced from there. |
| 361 visitor->trace(m_shadowRoots.head()); | 363 visitor->trace(m_shadowRoots.head()); |
| 362 } | 364 } |
| 363 | 365 |
| 364 } // namespace | 366 } // namespace |
| OLD | NEW |