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

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

Issue 843773002: Only match style from element's TreeScope for normal rules. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed custom pseudo and ::cue regressions 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') | no next file » | 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 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 // Note that we may get invoked for some random elements in some wacky cases during style resolve. 379 // Note that we may get invoked for some random elements in some wacky cases during style resolve.
380 // Pause maintaining the stack in this case. 380 // Pause maintaining the stack in this case.
381 if (m_selectorFilter.parentStackIsConsistent(&parent)) 381 if (m_selectorFilter.parentStackIsConsistent(&parent))
382 m_selectorFilter.popParent(); 382 m_selectorFilter.popParent();
383 } 383 }
384 384
385 StyleResolver::~StyleResolver() 385 StyleResolver::~StyleResolver()
386 { 386 {
387 } 387 }
388 388
389 void StyleResolver::matchAuthorRulesForShadowHost(Element* element, ElementRuleC ollector& collector, bool includeEmptyRules, WillBeHeapVector<RawPtrWillBeMember <ScopedStyleResolver>, 8>& resolvers, WillBeHeapVector<RawPtrWillBeMember<Scoped StyleResolver>, 8>& resolversInShadowTree) 389 static inline ScopedStyleResolver* scopedResolverFor(const Element* element)
390 { 390 {
391 collector.clearMatchedRules(); 391 // Ideally, returning element->treeScope().scopedStyleResolver() should be
392 collector.matchedResult().ranges.lastAuthorRule = collector.matchedResult(). matchedProperties.size() - 1; 392 // enough, but ::cue and custom pseudo elements like ::-webkit-meter-bar pie rce
393 // through a shadow dom boundary, yet they are not part of m_treeBoundaryCro ssingRules.
394 // The assumption here is that these rules only pierce through one boundary and
395 // that the scope of these elements do not have a style resolver due to the fact
396 // that VTT scopes and UA shadow trees don't have <style> elements. This is
397 // backed up by the ASSERTs below.
398 //
399 // FIXME: Make ::cue and custom pseudo elements part of boundary crossing ru les
400 // when moving those rules to ScopedStyleResolver as part of issue 401359.
393 401
394 CascadeScope cascadeScope = 0; 402 TreeScope* treeScope = &element->treeScope();
403 if (ScopedStyleResolver* resolver = treeScope->scopedStyleResolver()) {
404 ASSERT(element->shadowPseudoId().isEmpty());
405 ASSERT(!element->isVTTElement());
406 return resolver;
407 }
408
409 treeScope = treeScope->parentTreeScope();
410 if (!treeScope)
411 return nullptr;
412 if (element->shadowPseudoId().isEmpty() && !element->isVTTElement())
413 return nullptr;
414 return treeScope->scopedStyleResolver();
415 }
416
417 void StyleResolver::matchAuthorRulesForShadowHost(Element* element, ElementRuleC ollector& collector, bool includeEmptyRules, WillBeHeapVector<RawPtrWillBeMember <ScopedStyleResolver>, 8>& resolversInShadowTree)
418 {
395 CascadeOrder cascadeOrder = 0; 419 CascadeOrder cascadeOrder = 0;
420 for (int j = resolversInShadowTree.size() - 1; j >= 0; --j)
421 resolversInShadowTree.at(j)->collectMatchingShadowHostRules(collector, i ncludeEmptyRules, cascadeOrder++);
396 422
397 for (int j = resolversInShadowTree.size() - 1; j >= 0; --j) 423 if (ScopedStyleResolver* resolver = scopedResolverFor(element))
398 resolversInShadowTree.at(j)->collectMatchingShadowHostRules(collector, i ncludeEmptyRules, cascadeScope, cascadeOrder++); 424 resolver->collectMatchingAuthorRules(collector, includeEmptyRules, casca deOrder);
399
400 if (resolvers.isEmpty() || resolvers.first()->treeScope() != element->treeSc ope())
401 ++cascadeScope;
402 cascadeOrder += resolvers.size();
403 for (unsigned i = 0; i < resolvers.size(); ++i)
404 resolvers.at(i)->collectMatchingAuthorRules(collector, includeEmptyRules , cascadeScope++, --cascadeOrder);
405
406 m_treeBoundaryCrossingRules.collectTreeBoundaryCrossingRules(element, collec tor, includeEmptyRules);
407 collector.sortAndTransferMatchedRules();
408 } 425 }
409 426
410 void StyleResolver::matchAuthorRules(Element* element, ElementRuleCollector& col lector, bool includeEmptyRules) 427 void StyleResolver::matchAuthorRules(Element* element, ElementRuleCollector& col lector, bool includeEmptyRules)
411 { 428 {
412 collector.clearMatchedRules(); 429 collector.clearMatchedRules();
413 collector.matchedResult().ranges.lastAuthorRule = collector.matchedResult(). matchedProperties.size() - 1; 430 collector.matchedResult().ranges.lastAuthorRule = collector.matchedResult(). matchedProperties.size() - 1;
414 431
415 if (document().styleEngine()->onlyDocumentHasStyles()) { 432 if (document().styleEngine()->onlyDocumentHasStyles()) {
416 ScopedStyleResolver* resolver = document().scopedStyleResolver(); 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) .
417 if (!resolver) 436 if (!resolver)
418 return; 437 return;
419 // If we have no resolver for a document, the document has no styles. 438 resolver->collectMatchingAuthorRules(collector, includeEmptyRules);
420 // We don't need to see any rules (including treeboundary crossing ones) .
421 resolver->collectMatchingAuthorRules(collector, includeEmptyRules, ignor eCascadeScope);
422 m_treeBoundaryCrossingRules.collectTreeBoundaryCrossingRules(element, co llector, includeEmptyRules); 439 m_treeBoundaryCrossingRules.collectTreeBoundaryCrossingRules(element, co llector, includeEmptyRules);
423 collector.sortAndTransferMatchedRules(); 440 collector.sortAndTransferMatchedRules();
424 return; 441 return;
425 } 442 }
426 443
427 WillBeHeapVector<RawPtrWillBeMember<ScopedStyleResolver>, 8> resolvers;
428 resolveScopedStyles(element, resolvers);
429
430 WillBeHeapVector<RawPtrWillBeMember<ScopedStyleResolver>, 8> resolversInShad owTree; 444 WillBeHeapVector<RawPtrWillBeMember<ScopedStyleResolver>, 8> resolversInShad owTree;
431 collectScopedResolversForHostedShadowTrees(element, resolversInShadowTree); 445 collectScopedResolversForHostedShadowTrees(element, resolversInShadowTree);
432 if (!resolversInShadowTree.isEmpty()) { 446 if (!resolversInShadowTree.isEmpty())
433 matchAuthorRulesForShadowHost(element, collector, includeEmptyRules, res olvers, resolversInShadowTree); 447 matchAuthorRulesForShadowHost(element, collector, includeEmptyRules, res olversInShadowTree);
434 return; 448 else if (ScopedStyleResolver* resolver = scopedResolverFor(element))
435 } 449 resolver->collectMatchingAuthorRules(collector, includeEmptyRules, resol ver->treeScope().rootNode().isShadowRoot() ? 0 : 1);
436
437 if (!resolvers.isEmpty()) {
438 CascadeScope cascadeScope = 0;
439 CascadeOrder cascadeOrder = resolvers.size();
440 for (unsigned i = 0; i < resolvers.size(); ++i, --cascadeOrder) {
441 ScopedStyleResolver* resolver = resolvers.at(i);
442 // FIXME: Need to clarify how to treat style scoped.
443 resolver->collectMatchingAuthorRules(collector, includeEmptyRules, c ascadeScope++, resolver->treeScope() == element->treeScope() && resolver->treeSc ope().rootNode().isShadowRoot() ? 0 : cascadeOrder);
444 }
445 }
446 450
447 m_treeBoundaryCrossingRules.collectTreeBoundaryCrossingRules(element, collec tor, includeEmptyRules); 451 m_treeBoundaryCrossingRules.collectTreeBoundaryCrossingRules(element, collec tor, includeEmptyRules);
448 collector.sortAndTransferMatchedRules(); 452 collector.sortAndTransferMatchedRules();
449 } 453 }
450 454
451 void StyleResolver::matchUARules(ElementRuleCollector& collector) 455 void StyleResolver::matchUARules(ElementRuleCollector& collector)
452 { 456 {
453 collector.setMatchingUARules(true); 457 collector.setMatchingUARules(true);
454 458
455 CSSDefaultStyleSheets& defaultStyleSheets = CSSDefaultStyleSheets::instance( ); 459 CSSDefaultStyleSheets& defaultStyleSheets = CSSDefaultStyleSheets::instance( );
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 applyAnimatedProperties<LowPriorityProperties>(state, activeInterpolationsFo rTransitions); 1020 applyAnimatedProperties<LowPriorityProperties>(state, activeInterpolationsFo rTransitions);
1017 1021
1018 // Start loading resources used by animations. 1022 // Start loading resources used by animations.
1019 loadPendingResources(state); 1023 loadPendingResources(state);
1020 1024
1021 ASSERT(!state.fontBuilder().fontDirty()); 1025 ASSERT(!state.fontBuilder().fontDirty());
1022 1026
1023 return true; 1027 return true;
1024 } 1028 }
1025 1029
1026 static inline ScopedStyleResolver* scopedResolverFor(const Element* element)
1027 {
1028 for (TreeScope* treeScope = &element->treeScope(); treeScope; treeScope = tr eeScope->parentTreeScope()) {
1029 if (ScopedStyleResolver* scopedStyleResolver = treeScope->scopedStyleRes olver())
1030 return scopedStyleResolver;
1031 }
1032 return 0;
1033 }
1034
1035 void StyleResolver::resolveScopedStyles(const Element* element, WillBeHeapVector <RawPtrWillBeMember<ScopedStyleResolver>, 8>& resolvers)
1036 {
1037 for (ScopedStyleResolver* scopedResolver = scopedResolverFor(element); scope dResolver; scopedResolver = scopedResolver->parent())
1038 resolvers.append(scopedResolver);
1039 }
1040
1041 const StyleRuleKeyframes* StyleResolver::findKeyframesRule(const Element* elemen t, const AtomicString& animationName) 1030 const StyleRuleKeyframes* StyleResolver::findKeyframesRule(const Element* elemen t, const AtomicString& animationName)
1042 { 1031 {
1043 WillBeHeapVector<RawPtrWillBeMember<ScopedStyleResolver>, 8> resolvers; 1032 WillBeHeapVector<RawPtrWillBeMember<ScopedStyleResolver>, 8> resolvers;
1044 collectScopedResolversForHostedShadowTrees(element, resolvers); 1033 collectScopedResolversForHostedShadowTrees(element, resolvers);
1045 if (ScopedStyleResolver* scopedResolver = element->treeScope().scopedStyleRe solver()) 1034 if (ScopedStyleResolver* scopedResolver = element->treeScope().scopedStyleRe solver())
1046 resolvers.append(scopedResolver); 1035 resolvers.append(scopedResolver);
1047 1036
1048 for (size_t i = 0; i < resolvers.size(); ++i) { 1037 for (size_t i = 0; i < resolvers.size(); ++i) {
1049 if (const StyleRuleKeyframes* keyframesRule = resolvers[i]->keyframeStyl esForAnimation(animationName.impl())) 1038 if (const StyleRuleKeyframes* keyframesRule = resolvers[i]->keyframeStyl esForAnimation(animationName.impl()))
1050 return keyframesRule; 1039 return keyframesRule;
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
1604 visitor->trace(m_uncommonAttributeRuleSet); 1593 visitor->trace(m_uncommonAttributeRuleSet);
1605 visitor->trace(m_watchedSelectorsRules); 1594 visitor->trace(m_watchedSelectorsRules);
1606 visitor->trace(m_treeBoundaryCrossingRules); 1595 visitor->trace(m_treeBoundaryCrossingRules);
1607 visitor->trace(m_styleSharingLists); 1596 visitor->trace(m_styleSharingLists);
1608 visitor->trace(m_pendingStyleSheets); 1597 visitor->trace(m_pendingStyleSheets);
1609 visitor->trace(m_document); 1598 visitor->trace(m_document);
1610 #endif 1599 #endif
1611 } 1600 }
1612 1601
1613 } // namespace blink 1602 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/css/resolver/StyleResolver.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698