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

Unified Diff: Source/core/css/resolver/StyleResolver.cpp

Issue 1298173004: Implement proposed shadow tree cascade order. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/css/resolver/StyleResolver.h ('k') | Source/core/dom/DocumentOrderedList.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/resolver/StyleResolver.cpp
diff --git a/Source/core/css/resolver/StyleResolver.cpp b/Source/core/css/resolver/StyleResolver.cpp
index bcda31acd3fdf757f5cdbb017045186c6d43f88b..963690e65aa8bd64c9627a1fe5ec3aebb56c014d 100644
--- a/Source/core/css/resolver/StyleResolver.cpp
+++ b/Source/core/css/resolver/StyleResolver.cpp
@@ -123,21 +123,6 @@ static StylePropertySet* rightToLeftDeclaration()
return rightToLeftDecl;
}
-static void collectScopedResolversForHostedShadowTrees(const Element* element, WillBeHeapVector<RawPtrWillBeMember<ScopedStyleResolver>, 8>& resolvers)
-{
- ElementShadow* shadow = element->shadow();
- if (!shadow)
- return;
-
- // Adding scoped resolver for active shadow roots for shadow host styling.
- for (ShadowRoot* shadowRoot = shadow->youngestShadowRoot(); shadowRoot; shadowRoot = shadowRoot->olderShadowRoot()) {
- if (shadowRoot->numberOfStyles() > 0) {
- if (ScopedStyleResolver* resolver = shadowRoot->scopedStyleResolver())
- resolvers.append(resolver);
- }
- }
-}
-
StyleResolver::StyleResolver(Document& document)
: m_document(document)
, m_viewportStyleResolver(ViewportStyleResolver::create(&document))
@@ -242,12 +227,12 @@ void StyleResolver::resetRuleFeatures()
void StyleResolver::addTreeBoundaryCrossingScope(ContainerNode& scope)
{
- m_treeBoundaryCrossingRules.addScope(scope);
+ m_treeBoundaryCrossingScopes.add(&scope);
}
void StyleResolver::resetAuthorStyle(TreeScope& treeScope)
{
- m_treeBoundaryCrossingRules.removeScope(treeScope.rootNode());
+ m_treeBoundaryCrossingScopes.remove(&treeScope.rootNode());
ScopedStyleResolver* resolver = treeScope.scopedStyleResolver();
if (!resolver)
@@ -348,11 +333,11 @@ StyleResolver::~StyleResolver()
{
}
-static inline ScopedStyleResolver* scopedResolverFor(const Element* element)
+static inline ScopedStyleResolver* scopedResolverFor(const Element& element)
{
// Ideally, returning element->treeScope().scopedStyleResolver() should be
// enough, but ::cue and custom pseudo elements like ::-webkit-meter-bar pierce
- // through a shadow dom boundary, yet they are not part of m_treeBoundaryCrossingRules.
+ // through a shadow dom boundary, yet they are not part of m_treeBoundaryCrossingScopes.
// The assumption here is that these rules only pierce through one boundary and
// that the scope of these elements do not have a style resolver due to the fact
// that VTT scopes and UA shadow trees don't have <style> elements. This is
@@ -361,40 +346,82 @@ static inline ScopedStyleResolver* scopedResolverFor(const Element* element)
// FIXME: Make ::cue and custom pseudo elements part of boundary crossing rules
// when moving those rules to ScopedStyleResolver as part of issue 401359.
- TreeScope* treeScope = &element->treeScope();
+ TreeScope* treeScope = &element.treeScope();
if (ScopedStyleResolver* resolver = treeScope->scopedStyleResolver()) {
- ASSERT(element->shadowPseudoId().isEmpty());
- ASSERT(!element->isVTTElement());
+ ASSERT(element.shadowPseudoId().isEmpty());
+ ASSERT(!element.isVTTElement());
return resolver;
}
treeScope = treeScope->parentTreeScope();
if (!treeScope)
return nullptr;
- if (element->shadowPseudoId().isEmpty() && !element->isVTTElement())
+ if (element.shadowPseudoId().isEmpty() && !element.isVTTElement())
return nullptr;
return treeScope->scopedStyleResolver();
}
-void StyleResolver::matchAuthorRules(Element* element, ElementRuleCollector& collector, bool includeEmptyRules)
+void StyleResolver::matchHostRules(const Element& element, ElementRuleCollector& collector, bool includeEmptyRules)
{
- collector.clearMatchedRules();
+ ElementShadow* shadow = element.shadow();
+ if (!shadow)
+ return;
+
+ // Adding scoped resolvers for active shadow roots for shadow host styling.
kochi 2015/08/19 10:29:24 Nit: This comment seems copied from collectScopedR
rune 2015/08/19 16:37:22 I've just dropped the comment.
+ for (ShadowRoot* shadowRoot = shadow->oldestShadowRoot(); shadowRoot; shadowRoot = shadowRoot->youngerShadowRoot()) {
+ if (!shadowRoot->numberOfStyles())
+ continue;
+ if (ScopedStyleResolver* resolver = shadowRoot->scopedStyleResolver()) {
+ collector.clearMatchedRules();
+ resolver->collectMatchingShadowHostRules(collector, includeEmptyRules);
+ collector.sortAndTransferMatchedRules();
+ collector.finishAddingAuthorRulesForTreeScope();
+ }
+ }
+}
+
+ScopedStyleResolver* StyleResolver::matchElementScopeRules(const Element& element, ElementRuleCollector& collector, bool includeEmptyRules)
+{
+ ScopedStyleResolver* resolver = scopedResolverFor(element);
+ if (resolver) {
+ collector.clearMatchedRules();
+ resolver->collectMatchingAuthorRules(collector, includeEmptyRules);
+ resolver->collectMatchingTreeBoundaryCrossingRules(collector, includeEmptyRules);
+ collector.sortAndTransferMatchedRules();
+ }
+ collector.finishAddingAuthorRulesForTreeScope();
kochi 2015/08/19 10:29:24 Why this line can't be in the if() {} above?
rune 2015/08/19 16:37:22 Yes it could. I've restructured the code in patch
+ return resolver;
+}
- CascadeOrder cascadeOrder = 0;
- WillBeHeapVector<RawPtrWillBeMember<ScopedStyleResolver>, 8> resolversInShadowTree;
- collectScopedResolversForHostedShadowTrees(element, resolversInShadowTree);
+void StyleResolver::matchScopedRules(const Element& element, ElementRuleCollector& collector, bool includeEmptyRules)
+{
+ bool matchElementScope = true;
kochi 2015/08/19 10:29:24 nit: how about bool matchElementScopeDone = false;
rune 2015/08/19 16:37:22 Done.
- // Apply :host and :host-context rules from inner scopes.
- for (int j = resolversInShadowTree.size() - 1; j >= 0; --j)
- resolversInShadowTree.at(j)->collectMatchingShadowHostRules(collector, includeEmptyRules, ++cascadeOrder);
+ for (auto it = m_treeBoundaryCrossingScopes.rbegin(); it != m_treeBoundaryCrossingScopes.rend(); ++it) {
+ const TreeScope& scope = (*it)->treeScope();
+ ScopedStyleResolver* resolver = scope.scopedStyleResolver();
+ ASSERT(resolver);
- // Apply normal rules from element scope.
- if (ScopedStyleResolver* resolver = scopedResolverFor(element))
- resolver->collectMatchingAuthorRules(collector, includeEmptyRules, ++cascadeOrder);
+ if (matchElementScope && scope.isInclusiveAncestorOf(element.treeScope())) {
+ matchElementScope = false;
+ if (matchElementScopeRules(element, collector, includeEmptyRules) == resolver)
kochi 2015/08/19 10:29:24 This looks tricky. Could you add comment why the s
rune 2015/08/19 16:37:22 I've restructured the code a bit, and added docume
+ continue;
+ }
- // Apply /deep/ and ::shadow rules from outer scopes, and ::content from inner.
- m_treeBoundaryCrossingRules.collectTreeBoundaryCrossingRules(element, collector, includeEmptyRules);
- collector.sortAndTransferMatchedRules();
+ collector.clearMatchedRules();
+ resolver->collectMatchingTreeBoundaryCrossingRules(collector, includeEmptyRules);
+ collector.sortAndTransferMatchedRules();
+ collector.finishAddingAuthorRulesForTreeScope();
+ }
+
+ if (matchElementScope)
+ matchElementScopeRules(element, collector, includeEmptyRules);
+}
+
+void StyleResolver::matchAuthorRules(const Element& element, ElementRuleCollector& collector, bool includeEmptyRules)
+{
+ matchHostRules(element, collector, includeEmptyRules);
+ matchScopedRules(element, collector, includeEmptyRules);
}
void StyleResolver::matchUARules(ElementRuleCollector& collector)
@@ -447,9 +474,15 @@ void StyleResolver::matchAllRules(StyleResolverState& state, ElementRuleCollecto
}
}
- matchAuthorRules(state.element(), collector, false);
+ matchAuthorRules(*state.element(), collector, false);
if (state.element()->isStyledElement()) {
+ // TODO(rune@opera.com): Adding style attribute rules here is probably too late
+ // when you have shadow piercing combinators. When we don't have piercing combinators,
+ // the style attribute always belong to the outermost scope whose rules apply to
+ // the element. Thus, applying inline style here is correct. Fixing this for piercing
+ // combinators means moving the code below into matchElementScopeRules and _not_
+ // invoking it for pseudo style requests.
if (state.element()->inlineStyle()) {
// Inline style is immutable as long as there is no CSSOM wrapper.
bool isInlineStyleCacheable = !state.element()->inlineStyle()->isMutable();
@@ -758,7 +791,7 @@ bool StyleResolver::pseudoStyleForElementInternal(Element& element, const Pseudo
collector.setPseudoStyleRequest(pseudoStyleRequest);
matchUARules(collector);
- matchAuthorRules(state.element(), collector, false);
+ matchAuthorRules(*state.element(), collector, false);
collector.finishAddingAuthorRulesForTreeScope();
if (!collector.matchedResult().hasMatchedProperties())
@@ -909,7 +942,7 @@ void StyleResolver::collectPseudoRulesForElement(Element* element, ElementRuleCo
if (rulesToInclude & AuthorCSSRules) {
collector.setSameOriginOnly(!(rulesToInclude & CrossOriginCSSRules));
- matchAuthorRules(element, collector, rulesToInclude & EmptyCSSRules);
+ matchAuthorRules(*element, collector, rulesToInclude & EmptyCSSRules);
}
}
@@ -952,10 +985,25 @@ bool StyleResolver::applyAnimatedProperties(StyleResolverState& state, const Ele
return true;
}
+static void collectScopedResolversForHostedShadowTrees(const Element& element, WillBeHeapVector<RawPtrWillBeMember<ScopedStyleResolver>, 8>& resolvers)
+{
+ ElementShadow* shadow = element.shadow();
+ if (!shadow)
+ return;
+
+ // Adding scoped resolver for active shadow roots for shadow host styling.
+ for (ShadowRoot* shadowRoot = shadow->youngestShadowRoot(); shadowRoot; shadowRoot = shadowRoot->olderShadowRoot()) {
+ if (shadowRoot->numberOfStyles() > 0) {
+ if (ScopedStyleResolver* resolver = shadowRoot->scopedStyleResolver())
+ resolvers.append(resolver);
+ }
+ }
+}
+
StyleRuleKeyframes* StyleResolver::findKeyframesRule(const Element* element, const AtomicString& animationName)
{
WillBeHeapVector<RawPtrWillBeMember<ScopedStyleResolver>, 8> resolvers;
- collectScopedResolversForHostedShadowTrees(element, resolvers);
+ collectScopedResolversForHostedShadowTrees(*element, resolvers);
if (ScopedStyleResolver* scopedResolver = element->treeScope().scopedStyleResolver())
resolvers.append(scopedResolver);
@@ -1446,7 +1494,7 @@ DEFINE_TRACE(StyleResolver)
visitor->trace(m_siblingRuleSet);
visitor->trace(m_uncommonAttributeRuleSet);
visitor->trace(m_watchedSelectorsRules);
- visitor->trace(m_treeBoundaryCrossingRules);
+ visitor->trace(m_treeBoundaryCrossingScopes);
visitor->trace(m_styleResourceLoader);
visitor->trace(m_styleSharingLists);
visitor->trace(m_pendingStyleSheets);
« no previous file with comments | « Source/core/css/resolver/StyleResolver.h ('k') | Source/core/dom/DocumentOrderedList.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698