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

Side by Side Diff: Source/core/css/resolver/StyleResolver.cpp

Issue 844963002: Refactor StyleResolver::matchAuthorRules. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@style-scoped-20150109
Patch Set: Rebased Created 5 years, 11 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
« no previous file with comments | « Source/core/css/resolver/StyleResolver.h ('k') | Source/core/dom/StyleEngine.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 } 407 }
408 408
409 treeScope = treeScope->parentTreeScope(); 409 treeScope = treeScope->parentTreeScope();
410 if (!treeScope) 410 if (!treeScope)
411 return nullptr; 411 return nullptr;
412 if (element->shadowPseudoId().isEmpty() && !element->isVTTElement()) 412 if (element->shadowPseudoId().isEmpty() && !element->isVTTElement())
413 return nullptr; 413 return nullptr;
414 return treeScope->scopedStyleResolver(); 414 return treeScope->scopedStyleResolver();
415 } 415 }
416 416
417 void StyleResolver::matchAuthorRulesForShadowHost(Element* element, ElementRuleC ollector& collector, bool includeEmptyRules, WillBeHeapVector<RawPtrWillBeMember <ScopedStyleResolver>, 8>& resolversInShadowTree)
418 {
419 CascadeOrder cascadeOrder = 0;
420 for (int j = resolversInShadowTree.size() - 1; j >= 0; --j)
421 resolversInShadowTree.at(j)->collectMatchingShadowHostRules(collector, i ncludeEmptyRules, cascadeOrder++);
422
423 if (ScopedStyleResolver* resolver = scopedResolverFor(element))
424 resolver->collectMatchingAuthorRules(collector, includeEmptyRules, casca deOrder);
425 }
426
427 void StyleResolver::matchAuthorRules(Element* element, ElementRuleCollector& col lector, bool includeEmptyRules) 417 void StyleResolver::matchAuthorRules(Element* element, ElementRuleCollector& col lector, bool includeEmptyRules)
428 { 418 {
429 collector.clearMatchedRules(); 419 collector.clearMatchedRules();
430 collector.matchedResult().ranges.lastAuthorRule = collector.matchedResult(). matchedProperties.size() - 1; 420 collector.matchedResult().ranges.lastAuthorRule = collector.matchedResult(). matchedProperties.size() - 1;
431 421
432 if (document().styleEngine()->onlyDocumentHasStyles()) { 422 CascadeOrder cascadeOrder = 0;
433 ScopedStyleResolver* resolver = document().scopedStyleResolver();
434 // If we have no resolver for a document, the document has no styles.
435 // We don't need to see any rules (including treeboundary crossing ones) .
436 if (!resolver)
437 return;
438 resolver->collectMatchingAuthorRules(collector, includeEmptyRules);
439 m_treeBoundaryCrossingRules.collectTreeBoundaryCrossingRules(element, co llector, includeEmptyRules);
440 collector.sortAndTransferMatchedRules();
441 return;
442 }
443
444 WillBeHeapVector<RawPtrWillBeMember<ScopedStyleResolver>, 8> resolversInShad owTree; 423 WillBeHeapVector<RawPtrWillBeMember<ScopedStyleResolver>, 8> resolversInShad owTree;
445 collectScopedResolversForHostedShadowTrees(element, resolversInShadowTree); 424 collectScopedResolversForHostedShadowTrees(element, resolversInShadowTree);
446 if (!resolversInShadowTree.isEmpty())
447 matchAuthorRulesForShadowHost(element, collector, includeEmptyRules, res olversInShadowTree);
448 else if (ScopedStyleResolver* resolver = scopedResolverFor(element))
449 resolver->collectMatchingAuthorRules(collector, includeEmptyRules, resol ver->treeScope().rootNode().isShadowRoot() ? 0 : 1);
450 425
426 // Apply :host and :host-context rules from inner scopes.
427 for (int j = resolversInShadowTree.size() - 1; j >= 0; --j)
428 resolversInShadowTree.at(j)->collectMatchingShadowHostRules(collector, i ncludeEmptyRules, ++cascadeOrder);
429
430 // Apply normal rules from element scope.
431 if (ScopedStyleResolver* resolver = scopedResolverFor(element))
432 resolver->collectMatchingAuthorRules(collector, includeEmptyRules, ++cas cadeOrder);
433
434 // Apply /deep/ and ::shadow rules from outer scopes, and ::content from inn er.
451 m_treeBoundaryCrossingRules.collectTreeBoundaryCrossingRules(element, collec tor, includeEmptyRules); 435 m_treeBoundaryCrossingRules.collectTreeBoundaryCrossingRules(element, collec tor, includeEmptyRules);
452 collector.sortAndTransferMatchedRules(); 436 collector.sortAndTransferMatchedRules();
453 } 437 }
454 438
455 void StyleResolver::matchUARules(ElementRuleCollector& collector) 439 void StyleResolver::matchUARules(ElementRuleCollector& collector)
456 { 440 {
457 collector.setMatchingUARules(true); 441 collector.setMatchingUARules(true);
458 442
459 CSSDefaultStyleSheets& defaultStyleSheets = CSSDefaultStyleSheets::instance( ); 443 CSSDefaultStyleSheets& defaultStyleSheets = CSSDefaultStyleSheets::instance( );
460 RuleSet* userAgentStyleSheet = m_printMediaType ? defaultStyleSheets.default PrintStyle() : defaultStyleSheets.defaultStyle(); 444 RuleSet* userAgentStyleSheet = m_printMediaType ? defaultStyleSheets.default PrintStyle() : defaultStyleSheets.defaultStyle();
(...skipping 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1589 visitor->trace(m_uncommonAttributeRuleSet); 1573 visitor->trace(m_uncommonAttributeRuleSet);
1590 visitor->trace(m_watchedSelectorsRules); 1574 visitor->trace(m_watchedSelectorsRules);
1591 visitor->trace(m_treeBoundaryCrossingRules); 1575 visitor->trace(m_treeBoundaryCrossingRules);
1592 visitor->trace(m_styleSharingLists); 1576 visitor->trace(m_styleSharingLists);
1593 visitor->trace(m_pendingStyleSheets); 1577 visitor->trace(m_pendingStyleSheets);
1594 visitor->trace(m_document); 1578 visitor->trace(m_document);
1595 #endif 1579 #endif
1596 } 1580 }
1597 1581
1598 } // namespace blink 1582 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/css/resolver/StyleResolver.h ('k') | Source/core/dom/StyleEngine.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698