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

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

Issue 2323953003: Clarify a role of Shadow DOM related functions (Closed)
Patch Set: rebased Created 4 years, 3 months 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
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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 for (ShadowRoot* root = &youngestShadowRoot(); root; root = root->olderShado wRoot()) 216 for (ShadowRoot* root = &youngestShadowRoot(); root; root = root->olderShado wRoot())
217 root->detachLayoutTree(childrenContext); 217 root->detachLayoutTree(childrenContext);
218 } 218 }
219 219
220 void ElementShadow::setNeedsDistributionRecalc() 220 void ElementShadow::setNeedsDistributionRecalc()
221 { 221 {
222 if (m_needsDistributionRecalc) 222 if (m_needsDistributionRecalc)
223 return; 223 return;
224 m_needsDistributionRecalc = true; 224 m_needsDistributionRecalc = true;
225 host().markAncestorsWithChildNeedsDistributionRecalc(); 225 host().markAncestorsWithChildNeedsDistributionRecalc();
226 clearDistribution(); 226 if (!isV1())
227 clearDistributionV0();
227 } 228 }
228 229
229 bool ElementShadow::hasSameStyles(const ElementShadow* other) const 230 bool ElementShadow::hasSameStyles(const ElementShadow* other) const
230 { 231 {
231 ShadowRoot* root = &youngestShadowRoot(); 232 ShadowRoot* root = &youngestShadowRoot();
232 ShadowRoot* otherRoot = &other->youngestShadowRoot(); 233 ShadowRoot* otherRoot = &other->youngestShadowRoot();
233 while (root || otherRoot) { 234 while (root || otherRoot) {
234 if (!root || !otherRoot) 235 if (!root || !otherRoot)
235 return false; 236 return false;
236 237
237 StyleSheetList& list = root->styleSheets(); 238 StyleSheetList& list = root->styleSheets();
238 StyleSheetList& otherList = otherRoot->styleSheets(); 239 StyleSheetList& otherList = otherRoot->styleSheets();
239 240
240 if (list.length() != otherList.length()) 241 if (list.length() != otherList.length())
241 return false; 242 return false;
242 243
243 for (size_t i = 0; i < list.length(); i++) { 244 for (size_t i = 0; i < list.length(); i++) {
244 if (toCSSStyleSheet(list.item(i))->contents() != toCSSStyleSheet(oth erList.item(i))->contents()) 245 if (toCSSStyleSheet(list.item(i))->contents() != toCSSStyleSheet(oth erList.item(i))->contents())
245 return false; 246 return false;
246 } 247 }
247 root = root->olderShadowRoot(); 248 root = root->olderShadowRoot();
248 otherRoot = otherRoot->olderShadowRoot(); 249 otherRoot = otherRoot->olderShadowRoot();
249 } 250 }
250 251
251 return true; 252 return true;
252 } 253 }
253 254
254 const InsertionPoint* ElementShadow::finalDestinationInsertionPointFor(const Nod e* key) const 255 const InsertionPoint* ElementShadow::finalDestinationInsertionPointFor(const Nod e* key) const
255 { 256 {
257 DCHECK(!isV1());
256 DCHECK(key); 258 DCHECK(key);
257 DCHECK(!key->needsDistributionRecalc()); 259 DCHECK(!key->needsDistributionRecalc());
258 NodeToDestinationInsertionPoints::const_iterator it = m_nodeToInsertionPoint s.find(key); 260 NodeToDestinationInsertionPoints::const_iterator it = m_nodeToInsertionPoint s.find(key);
259 return it == m_nodeToInsertionPoints.end() ? nullptr : it->value->last(); 261 return it == m_nodeToInsertionPoints.end() ? nullptr : it->value->last();
260 } 262 }
261 263
262 const DestinationInsertionPoints* ElementShadow::destinationInsertionPointsFor(c onst Node* key) const 264 const DestinationInsertionPoints* ElementShadow::destinationInsertionPointsFor(c onst Node* key) const
263 { 265 {
266 DCHECK(!isV1());
264 DCHECK(key); 267 DCHECK(key);
265 DCHECK(!key->needsDistributionRecalc()); 268 DCHECK(!key->needsDistributionRecalc());
266 NodeToDestinationInsertionPoints::const_iterator it = m_nodeToInsertionPoint s.find(key); 269 NodeToDestinationInsertionPoints::const_iterator it = m_nodeToInsertionPoint s.find(key);
267 return it == m_nodeToInsertionPoints.end() ? nullptr : it->value; 270 return it == m_nodeToInsertionPoints.end() ? nullptr : it->value;
268 } 271 }
269 272
270 void ElementShadow::distribute() 273 void ElementShadow::distribute()
271 { 274 {
272 if (isV1()) 275 if (isV1())
273 youngestShadowRoot().distributeV1(); 276 youngestShadowRoot().distributeV1();
274 else 277 else
275 distributeV0(); 278 distributeV0();
276 } 279 }
277 280
278 void ElementShadow::distributeV0() 281 void ElementShadow::distributeV0()
279 { 282 {
283 DCHECK(!isV1());
280 HeapVector<Member<HTMLShadowElement>, 32> shadowInsertionPoints; 284 HeapVector<Member<HTMLShadowElement>, 32> shadowInsertionPoints;
281 DistributionPool pool(host()); 285 DistributionPool pool(host());
282 286
283 for (ShadowRoot* root = &youngestShadowRoot(); root; root = root->olderShado wRoot()) { 287 for (ShadowRoot* root = &youngestShadowRoot(); root; root = root->olderShado wRoot()) {
284 HTMLShadowElement* shadowInsertionPoint = 0; 288 HTMLShadowElement* shadowInsertionPoint = 0;
285 const HeapVector<Member<InsertionPoint>>& insertionPoints = root->descen dantInsertionPoints(); 289 const HeapVector<Member<InsertionPoint>>& insertionPoints = root->descen dantInsertionPoints();
286 for (size_t i = 0; i < insertionPoints.size(); ++i) { 290 for (size_t i = 0; i < insertionPoints.size(); ++i) {
287 InsertionPoint* point = insertionPoints[i]; 291 InsertionPoint* point = insertionPoints[i];
288 if (!point->isActive()) 292 if (!point->isActive())
289 continue; 293 continue;
290 if (isHTMLShadowElement(*point)) { 294 if (isHTMLShadowElement(*point)) {
291 DCHECK(!shadowInsertionPoint); 295 DCHECK(!shadowInsertionPoint);
292 shadowInsertionPoint = toHTMLShadowElement(point); 296 shadowInsertionPoint = toHTMLShadowElement(point);
293 shadowInsertionPoints.append(shadowInsertionPoint); 297 shadowInsertionPoints.append(shadowInsertionPoint);
294 } else { 298 } else {
295 pool.distributeTo(point, this); 299 pool.distributeTo(point, this);
296 if (ElementShadow* shadow = shadowWhereNodeCanBeDistributed(*poi nt)) 300 if (ElementShadow* shadow = shadowWhereNodeCanBeDistributedForV0 (*point))
297 shadow->setNeedsDistributionRecalc(); 301 shadow->setNeedsDistributionRecalc();
298 } 302 }
299 } 303 }
300 } 304 }
301 305
302 for (size_t i = shadowInsertionPoints.size(); i > 0; --i) { 306 for (size_t i = shadowInsertionPoints.size(); i > 0; --i) {
303 HTMLShadowElement* shadowInsertionPoint = shadowInsertionPoints[i - 1]; 307 HTMLShadowElement* shadowInsertionPoint = shadowInsertionPoints[i - 1];
304 ShadowRoot* root = shadowInsertionPoint->containingShadowRoot(); 308 ShadowRoot* root = shadowInsertionPoint->containingShadowRoot();
305 DCHECK(root); 309 DCHECK(root);
306 if (root->isOldest()) { 310 if (root->isOldest()) {
307 pool.distributeTo(shadowInsertionPoint, this); 311 pool.distributeTo(shadowInsertionPoint, this);
308 } else if (root->olderShadowRoot()->type() == root->type()) { 312 } else if (root->olderShadowRoot()->type() == root->type()) {
309 // Only allow reprojecting older shadow roots between the same type to 313 // Only allow reprojecting older shadow roots between the same type to
310 // disallow reprojecting UA elements into author shadows. 314 // disallow reprojecting UA elements into author shadows.
311 DistributionPool olderShadowRootPool(*root->olderShadowRoot()); 315 DistributionPool olderShadowRootPool(*root->olderShadowRoot());
312 olderShadowRootPool.distributeTo(shadowInsertionPoint, this); 316 olderShadowRootPool.distributeTo(shadowInsertionPoint, this);
313 root->olderShadowRoot()->setShadowInsertionPointOfYoungerShadowRoot( shadowInsertionPoint); 317 root->olderShadowRoot()->setShadowInsertionPointOfYoungerShadowRoot( shadowInsertionPoint);
314 } 318 }
315 if (ElementShadow* shadow = shadowWhereNodeCanBeDistributed(*shadowInser tionPoint)) 319 if (ElementShadow* shadow = shadowWhereNodeCanBeDistributedForV0(*shadow InsertionPoint))
316 shadow->setNeedsDistributionRecalc(); 320 shadow->setNeedsDistributionRecalc();
317 } 321 }
318 InspectorInstrumentation::didPerformElementShadowDistribution(&host()); 322 InspectorInstrumentation::didPerformElementShadowDistribution(&host());
319 } 323 }
320 324
321 void ElementShadow::didDistributeNode(const Node* node, InsertionPoint* insertio nPoint) 325 void ElementShadow::didDistributeNode(const Node* node, InsertionPoint* insertio nPoint)
322 { 326 {
327 DCHECK(!isV1());
323 NodeToDestinationInsertionPoints::AddResult result = m_nodeToInsertionPoints .add(node, nullptr); 328 NodeToDestinationInsertionPoints::AddResult result = m_nodeToInsertionPoints .add(node, nullptr);
324 if (result.isNewEntry) 329 if (result.isNewEntry)
325 result.storedValue->value = new DestinationInsertionPoints; 330 result.storedValue->value = new DestinationInsertionPoints;
326 result.storedValue->value->append(insertionPoint); 331 result.storedValue->value->append(insertionPoint);
327 } 332 }
328 333
329 const SelectRuleFeatureSet& ElementShadow::ensureSelectFeatureSet() 334 const SelectRuleFeatureSet& ElementShadow::ensureSelectFeatureSet()
330 { 335 {
336 DCHECK(!isV1());
331 if (!m_needsSelectFeatureSet) 337 if (!m_needsSelectFeatureSet)
332 return m_selectFeatures; 338 return m_selectFeatures;
333 339
334 m_selectFeatures.clear(); 340 m_selectFeatures.clear();
335 for (ShadowRoot* root = &oldestShadowRoot(); root; root = root->youngerShado wRoot()) 341 for (ShadowRoot* root = &oldestShadowRoot(); root; root = root->youngerShado wRoot())
336 collectSelectFeatureSetFrom(*root); 342 collectSelectFeatureSetFrom(*root);
337 m_needsSelectFeatureSet = false; 343 m_needsSelectFeatureSet = false;
338 return m_selectFeatures; 344 return m_selectFeatures;
339 } 345 }
340 346
341 void ElementShadow::collectSelectFeatureSetFrom(ShadowRoot& root) 347 void ElementShadow::collectSelectFeatureSetFrom(ShadowRoot& root)
342 { 348 {
349 DCHECK(!isV1());
343 if (!root.containsShadowRoots() && !root.containsContentElements()) 350 if (!root.containsShadowRoots() && !root.containsContentElements())
344 return; 351 return;
345 352
346 for (Element& element : ElementTraversal::descendantsOf(root)) { 353 for (Element& element : ElementTraversal::descendantsOf(root)) {
347 if (ElementShadow* shadow = element.shadow()) 354 if (ElementShadow* shadow = element.shadow())
348 m_selectFeatures.add(shadow->ensureSelectFeatureSet()); 355 m_selectFeatures.add(shadow->ensureSelectFeatureSet());
349 if (!isHTMLContentElement(element)) 356 if (!isHTMLContentElement(element))
350 continue; 357 continue;
351 const CSSSelectorList& list = toHTMLContentElement(element).selectorList (); 358 const CSSSelectorList& list = toHTMLContentElement(element).selectorList ();
352 m_selectFeatures.collectFeaturesFromSelectorList(list); 359 m_selectFeatures.collectFeaturesFromSelectorList(list);
353 } 360 }
354 } 361 }
355 362
356 void ElementShadow::willAffectSelector() 363 void ElementShadow::willAffectSelector()
357 { 364 {
365 DCHECK(!isV1());
358 for (ElementShadow* shadow = this; shadow; shadow = shadow->containingShadow ()) { 366 for (ElementShadow* shadow = this; shadow; shadow = shadow->containingShadow ()) {
359 if (shadow->needsSelectFeatureSet()) 367 if (shadow->needsSelectFeatureSet())
360 break; 368 break;
361 shadow->setNeedsSelectFeatureSet(); 369 shadow->setNeedsSelectFeatureSet();
362 } 370 }
363 setNeedsDistributionRecalc(); 371 setNeedsDistributionRecalc();
364 } 372 }
365 373
366 void ElementShadow::clearDistribution() 374 void ElementShadow::clearDistributionV0()
367 { 375 {
376 DCHECK(!isV1());
368 m_nodeToInsertionPoints.clear(); 377 m_nodeToInsertionPoints.clear();
369 378
370 for (ShadowRoot* root = &youngestShadowRoot(); root; root = root->olderShado wRoot()) 379 for (ShadowRoot* root = &youngestShadowRoot(); root; root = root->olderShado wRoot())
371 root->setShadowInsertionPointOfYoungerShadowRoot(nullptr); 380 root->setShadowInsertionPointOfYoungerShadowRoot(nullptr);
372 } 381 }
373 382
374 DEFINE_TRACE(ElementShadow) 383 DEFINE_TRACE(ElementShadow)
375 { 384 {
376 visitor->trace(m_nodeToInsertionPoints); 385 visitor->trace(m_nodeToInsertionPoints);
377 visitor->trace(m_selectFeatures); 386 visitor->trace(m_selectFeatures);
378 visitor->trace(m_shadowRoot); 387 visitor->trace(m_shadowRoot);
379 } 388 }
380 389
381 DEFINE_TRACE_WRAPPERS(ElementShadow) 390 DEFINE_TRACE_WRAPPERS(ElementShadow)
382 { 391 {
383 visitor->traceWrappers(m_shadowRoot); 392 visitor->traceWrappers(m_shadowRoot);
384 } 393 }
385 394
386 } // namespace blink 395 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698