Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: Source/core/dom/shadow/ElementShadow.cpp

Issue 59903015: [Shadow DOM]: Empty shadow insertion points should behave like <shadow><content *leftover*></conten… (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 22 matching lines...) Expand all
33 #include "core/dom/shadow/ContentDistribution.h" 33 #include "core/dom/shadow/ContentDistribution.h"
34 #include "core/dom/shadow/InsertionPoint.h" 34 #include "core/dom/shadow/InsertionPoint.h"
35 #include "core/dom/shadow/ShadowRoot.h" 35 #include "core/dom/shadow/ShadowRoot.h"
36 #include "core/html/shadow/HTMLContentElement.h" 36 #include "core/html/shadow/HTMLContentElement.h"
37 #include "core/html/shadow/HTMLShadowElement.h" 37 #include "core/html/shadow/HTMLShadowElement.h"
38 38
39 namespace WebCore { 39 namespace WebCore {
40 40
41 class DistributionPool { 41 class DistributionPool {
42 public: 42 public:
43 explicit DistributionPool(const ContainerNode*); 43 explicit DistributionPool(const ContainerNode&);
44 void clear();
44 ~DistributionPool(); 45 ~DistributionPool();
45 void distributeTo(InsertionPoint*, ElementShadow*); 46 void distributeTo(InsertionPoint*, ElementShadow*);
47 void populateChildren(const ContainerNode&);
46 48
47 private: 49 private:
48 void populateChildren(const ContainerNode*);
49 void detachNonDistributedNodes(); 50 void detachNonDistributedNodes();
50 Vector<Node*, 32> m_nodes; 51 Vector<Node*, 32> m_nodes;
51 Vector<bool, 32> m_distributed; 52 Vector<bool, 32> m_distributed;
52 }; 53 };
53 54
54 inline DistributionPool::DistributionPool(const ContainerNode* parent) 55 inline DistributionPool::DistributionPool(const ContainerNode& parent)
55 { 56 {
56 if (parent) 57 populateChildren(parent);
57 populateChildren(parent);
58 } 58 }
59 59
60 inline void DistributionPool::populateChildren(const ContainerNode* parent) 60 inline void DistributionPool::clear()
61 { 61 {
62 for (Node* child = parent->firstChild(); child; child = child->nextSibling() ) { 62 detachNonDistributedNodes();
63 m_nodes.clear();
64 m_distributed.clear();
65 }
66
67 inline void DistributionPool::populateChildren(const ContainerNode& parent)
68 {
69 clear();
70 for (Node* child = parent.firstChild(); child; child = child->nextSibling()) {
63 if (isActiveInsertionPoint(*child)) { 71 if (isActiveInsertionPoint(*child)) {
64 InsertionPoint* insertionPoint = toInsertionPoint(child); 72 InsertionPoint* insertionPoint = toInsertionPoint(child);
65 for (size_t i = 0; i < insertionPoint->size(); ++i) 73 for (size_t i = 0; i < insertionPoint->size(); ++i)
66 m_nodes.append(insertionPoint->at(i)); 74 m_nodes.append(insertionPoint->at(i));
67 } else { 75 } else {
68 m_nodes.append(child); 76 m_nodes.append(child);
69 } 77 }
70 } 78 }
71 m_distributed.resize(m_nodes.size()); 79 m_distributed.resize(m_nodes.size());
72 m_distributed.fill(false); 80 m_distributed.fill(false);
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 256
249 const DestinationInsertionPoints* ElementShadow::destinationInsertionPointsFor(c onst Node* key) const 257 const DestinationInsertionPoints* ElementShadow::destinationInsertionPointsFor(c onst Node* key) const
250 { 258 {
251 NodeToDestinationInsertionPoints::const_iterator it = m_nodeToInsertionPoint s.find(key); 259 NodeToDestinationInsertionPoints::const_iterator it = m_nodeToInsertionPoint s.find(key);
252 return it == m_nodeToInsertionPoints.end() ? 0: &it->value; 260 return it == m_nodeToInsertionPoints.end() ? 0: &it->value;
253 } 261 }
254 262
255 void ElementShadow::distribute() 263 void ElementShadow::distribute()
256 { 264 {
257 host()->setNeedsStyleRecalc(); 265 host()->setNeedsStyleRecalc();
266 Vector<HTMLShadowElement*, 32> shadowInsertionPoints;
267 DistributionPool pool(*host());
258 268
259 const ContainerNode* poolContainer = host();
260
261 Vector<HTMLShadowElement*, 32> shadowInsertionPoints;
262 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow Root()) { 269 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow Root()) {
263 DistributionPool pool(poolContainer);
264
265 HTMLShadowElement* shadowInsertionPoint = 0; 270 HTMLShadowElement* shadowInsertionPoint = 0;
266 const Vector<RefPtr<InsertionPoint> >& insertionPoints = root->descendan tInsertionPoints(); 271 const Vector<RefPtr<InsertionPoint> >& insertionPoints = root->descendan tInsertionPoints();
267 for (size_t i = 0; i < insertionPoints.size(); ++i) { 272 for (size_t i = 0; i < insertionPoints.size(); ++i) {
268 InsertionPoint* point = insertionPoints[i].get(); 273 InsertionPoint* point = insertionPoints[i].get();
269 if (!point->isActive()) 274 if (!point->isActive())
270 continue; 275 continue;
271 if (isHTMLShadowElement(point)) { 276 if (isHTMLShadowElement(point)) {
272 if (!shadowInsertionPoint) 277 if (!shadowInsertionPoint)
273 shadowInsertionPoint = toHTMLShadowElement(point); 278 shadowInsertionPoint = toHTMLShadowElement(point);
274 } else { 279 } else {
275 pool.distributeTo(point, this); 280 pool.distributeTo(point, this);
276 if (ElementShadow* shadow = shadowWhereNodeCanBeDistributed(*poi nt)) 281 if (ElementShadow* shadow = shadowWhereNodeCanBeDistributed(*poi nt))
277 shadow->setNeedsDistributionRecalc(); 282 shadow->setNeedsDistributionRecalc();
278 } 283 }
279 } 284 }
280 if (shadowInsertionPoint) 285 if (shadowInsertionPoint) {
281 shadowInsertionPoints.append(shadowInsertionPoint); 286 shadowInsertionPoints.append(shadowInsertionPoint);
282 poolContainer = shadowInsertionPoint; 287 if (shadowInsertionPoint->hasChildNodes())
288 pool.populateChildren(*shadowInsertionPoint);
289 } else if (!root->isOldest()) {
290 pool.clear();
291 }
283 } 292 }
284 293
285 for (size_t i = shadowInsertionPoints.size(); i > 0; --i) { 294 for (size_t i = shadowInsertionPoints.size(); i > 0; --i) {
286 HTMLShadowElement* shadowInsertionPoint = shadowInsertionPoints[i - 1]; 295 HTMLShadowElement* shadowInsertionPoint = shadowInsertionPoints[i - 1];
287 ShadowRoot* root = shadowInsertionPoint->containingShadowRoot(); 296 ShadowRoot* root = shadowInsertionPoint->containingShadowRoot();
288 ASSERT(root); 297 ASSERT(root);
289 if (root->olderShadowRoot() && root->olderShadowRoot()->type() == root-> type()) { 298 if (root->olderShadowRoot() && root->olderShadowRoot()->type() == root-> type()) {
290 // Only allow reprojecting older shadow roots between the same type to 299 // Only allow reprojecting older shadow roots between the same type to
291 // disallow reprojecting UA elements into author shadows. 300 // disallow reprojecting UA elements into author shadows.
292 distributeNodeChildrenTo(shadowInsertionPoint, root->olderShadowRoot ()); 301 distributeNodeChildrenTo(shadowInsertionPoint, root->olderShadowRoot ());
293 root->olderShadowRoot()->setShadowInsertionPointOfYoungerShadowRoot( shadowInsertionPoint); 302 root->olderShadowRoot()->setShadowInsertionPointOfYoungerShadowRoot( shadowInsertionPoint);
294 } else if (root->isOldest()) { 303 } else if (root->isOldest()) {
295 DistributionPool pool(shadowInsertionPoint); 304 if (shadowInsertionPoint->hasChildNodes())
305 pool.populateChildren(*shadowInsertionPoint);
296 pool.distributeTo(shadowInsertionPoint, this); 306 pool.distributeTo(shadowInsertionPoint, this);
297 } 307 }
298 if (ElementShadow* shadow = shadowWhereNodeCanBeDistributed(*shadowInser tionPoint)) 308 if (ElementShadow* shadow = shadowWhereNodeCanBeDistributed(*shadowInser tionPoint))
299 shadow->setNeedsDistributionRecalc(); 309 shadow->setNeedsDistributionRecalc();
300 } 310 }
301 } 311 }
302 312
303 void ElementShadow::didDistributeNode(const Node* node, InsertionPoint* insertio nPoint) 313 void ElementShadow::didDistributeNode(const Node* node, InsertionPoint* insertio nPoint)
304 { 314 {
305 NodeToDestinationInsertionPoints::AddResult result = m_nodeToInsertionPoints .add(node, DestinationInsertionPoints()); 315 NodeToDestinationInsertionPoints::AddResult result = m_nodeToInsertionPoints .add(node, DestinationInsertionPoints());
306 result.iterator->value.append(insertionPoint); 316 result.iterator->value.append(insertionPoint);
307 } 317 }
308 318
309 void ElementShadow::distributeNodeChildrenTo(InsertionPoint* insertionPoint, Con tainerNode* containerNode) 319 void ElementShadow::distributeNodeChildrenTo(InsertionPoint* insertionPoint, Con tainerNode* containerNode)
310 { 320 {
311 DistributionPool pool(containerNode); 321 DistributionPool pool(*containerNode);
312 pool.distributeTo(insertionPoint, this); 322 pool.distributeTo(insertionPoint, this);
313 } 323 }
314 324
315 const SelectRuleFeatureSet& ElementShadow::ensureSelectFeatureSet() 325 const SelectRuleFeatureSet& ElementShadow::ensureSelectFeatureSet()
316 { 326 {
317 if (!m_needsSelectFeatureSet) 327 if (!m_needsSelectFeatureSet)
318 return m_selectFeatures; 328 return m_selectFeatures;
319 329
320 m_selectFeatures.clear(); 330 m_selectFeatures.clear();
321 for (ShadowRoot* root = oldestShadowRoot(); root; root = root->youngerShadow Root()) 331 for (ShadowRoot* root = oldestShadowRoot(); root; root = root->youngerShadow Root())
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 370
361 void ElementShadow::clearDistribution() 371 void ElementShadow::clearDistribution()
362 { 372 {
363 m_nodeToInsertionPoints.clear(); 373 m_nodeToInsertionPoints.clear();
364 374
365 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow Root()) 375 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow Root())
366 root->setShadowInsertionPointOfYoungerShadowRoot(0); 376 root->setShadowInsertionPointOfYoungerShadowRoot(0);
367 } 377 }
368 378
369 } // namespace 379 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698