| Index: Source/core/css/resolver/StyleResolver.cpp
|
| diff --git a/Source/core/css/resolver/StyleResolver.cpp b/Source/core/css/resolver/StyleResolver.cpp
|
| index 6126f704eb577fe785d9340ae24832bb01b0149d..d66178a0cb26805dd6e80ccc2fa75a5359bb1007 100644
|
| --- a/Source/core/css/resolver/StyleResolver.cpp
|
| +++ b/Source/core/css/resolver/StyleResolver.cpp
|
| @@ -124,21 +124,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))
|
| @@ -232,14 +217,8 @@ void StyleResolver::resetRuleFeatures()
|
| m_needCollectFeatures = true;
|
| }
|
|
|
| -void StyleResolver::addTreeBoundaryCrossingScope(ContainerNode& scope)
|
| -{
|
| - m_treeBoundaryCrossingRules.addScope(scope);
|
| -}
|
| -
|
| void StyleResolver::resetAuthorStyle(TreeScope& treeScope)
|
| {
|
| - m_treeBoundaryCrossingRules.removeScope(treeScope.rootNode());
|
| resetRuleFeatures();
|
|
|
| ScopedStyleResolver* resolver = treeScope.scopedStyleResolver();
|
| @@ -339,11 +318,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 treeBoundaryCrossingRules.
|
| // 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
|
| @@ -352,40 +331,76 @@ 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;
|
|
|
| - CascadeOrder cascadeOrder = 0;
|
| - WillBeHeapVector<RawPtrWillBeMember<ScopedStyleResolver>, 8> resolversInShadowTree;
|
| - collectScopedResolversForHostedShadowTrees(element, resolversInShadowTree);
|
| + // Adding scoped resolvers for active shadow roots for shadow host styling.
|
| + 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();
|
| + }
|
| + }
|
| +}
|
|
|
| - // 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);
|
| +void StyleResolver::matchScopedRules(const Element& element, ElementRuleCollector& collector, bool includeEmptyRules)
|
| +{
|
| + // TODO(rune@opera.com): TreeScope::treeScopeInComposedTree can potentially be expensive as its doing
|
| + // composed tree traversal to find the closest tree-scope for the element in the composed tree. Getting the
|
| + // ancestor tree-scopes are much cheaper as we do the composed tree traversal for each TreeScope once and then cache
|
| + // its composed tree parent scope as a member.
|
|
|
| - // Apply normal rules from element scope.
|
| - if (ScopedStyleResolver* resolver = scopedResolverFor(element))
|
| - resolver->collectMatchingAuthorRules(collector, includeEmptyRules, ++cascadeOrder);
|
| + // TODO(rune@opera.com): The current implementation does not handle cascading order as
|
| + // spec'ed for !important rules.
|
|
|
| - // Apply /deep/ and ::shadow rules from outer scopes, and ::content from inner.
|
| - m_treeBoundaryCrossingRules.collectTreeBoundaryCrossingRules(element, collector, includeEmptyRules);
|
| - collector.sortAndTransferMatchedRules();
|
| + ScopedStyleResolver* resolverForElementScope = scopedResolverFor(element);
|
| +
|
| + if (!document().styleEngine().hasTreeBoundaryCrossingRules()) {
|
| + if (!resolverForElementScope)
|
| + return;
|
| + collector.clearMatchedRules();
|
| + resolverForElementScope->collectMatchingAuthorRules(collector, includeEmptyRules);
|
| + collector.sortAndTransferMatchedRules();
|
| + return;
|
| + }
|
| +
|
| + for (TreeScope* scope = TreeScope::treeScopeInComposedTree(element); scope; scope = scope->composedParent()) {
|
| + if (ScopedStyleResolver* resolver = scope->scopedStyleResolver()) {
|
| + collector.clearMatchedRules();
|
| + if (resolver == resolverForElementScope)
|
| + resolver->collectMatchingAuthorRules(collector, includeEmptyRules);
|
| + if (resolver->hasTreeBoundaryCrossingRules())
|
| + resolver->collectMatchingTreeBoundaryCrossingRules(collector, includeEmptyRules);
|
| + collector.sortAndTransferMatchedRules();
|
| + }
|
| + }
|
| +}
|
| +
|
| +void StyleResolver::matchAuthorRules(const Element& element, ElementRuleCollector& collector, bool includeEmptyRules)
|
| +{
|
| + matchHostRules(element, collector, includeEmptyRules);
|
| + matchScopedRules(element, collector, includeEmptyRules);
|
| }
|
|
|
| void StyleResolver::matchUARules(ElementRuleCollector& collector)
|
| @@ -437,7 +452,7 @@ void StyleResolver::matchAllRules(StyleResolverState& state, ElementRuleCollecto
|
| }
|
| }
|
|
|
| - matchAuthorRules(state.element(), collector, false);
|
| + matchAuthorRules(*state.element(), collector, false);
|
|
|
| if (state.element()->isStyledElement()) {
|
| if (state.element()->inlineStyle()) {
|
| @@ -449,6 +464,8 @@ void StyleResolver::matchAllRules(StyleResolverState& state, ElementRuleCollecto
|
| // Now check SMIL animation override style.
|
| if (includeSMILProperties && state.element()->isSVGElement())
|
| collector.addElementStyleProperties(toSVGElement(state.element())->animatedSMILStyleProperties(), false /* isCacheable */);
|
| +
|
| + collector.finishAddInlineStyle();
|
| }
|
| }
|
|
|
| @@ -654,13 +671,13 @@ PassRefPtr<ComputedStyle> StyleResolver::styleForKeyframe(Element& element, cons
|
| // relevant one is animation-timing-function and we special-case that in
|
| // CSSAnimations.cpp
|
| bool inheritedOnly = false;
|
| - applyMatchedProperties<HighPropertyPriority>(state, result, false, result.begin(), result.end(), inheritedOnly);
|
| + applyMatchedProperties<HighPropertyPriority>(state, result.allRules(), false, inheritedOnly);
|
|
|
| // If our font got dirtied, go ahead and update it now.
|
| updateFont(state);
|
|
|
| // Now do rest of the properties.
|
| - applyMatchedProperties<LowPropertyPriority>(state, result, false, result.begin(), result.end(), inheritedOnly);
|
| + applyMatchedProperties<LowPropertyPriority>(state, result.allRules(), false, inheritedOnly);
|
|
|
| loadPendingResources(state);
|
|
|
| @@ -775,9 +792,9 @@ bool StyleResolver::pseudoStyleForElementInternal(Element& element, const Pseudo
|
| collector.setPseudoStyleRequest(pseudoStyleRequest);
|
|
|
| matchUARules(collector);
|
| - matchAuthorRules(state.element(), collector, false);
|
| + matchAuthorRules(*state.element(), collector, false);
|
|
|
| - if (collector.matchedResult().matchedProperties.isEmpty())
|
| + if (!collector.matchedResult().hasMatchedProperties())
|
| return false;
|
|
|
| applyMatchedProperties(state, collector.matchedResult());
|
| @@ -849,12 +866,12 @@ PassRefPtr<ComputedStyle> StyleResolver::styleForPage(int pageIndex)
|
| bool inheritedOnly = false;
|
|
|
| const MatchResult& result = collector.matchedResult();
|
| - applyMatchedProperties<HighPropertyPriority>(state, result, false, result.begin(), result.end(), inheritedOnly);
|
| + applyMatchedProperties<HighPropertyPriority>(state, result.allRules(), false, inheritedOnly);
|
|
|
| // If our font got dirtied, go ahead and update it now.
|
| updateFont(state);
|
|
|
| - applyMatchedProperties<LowPropertyPriority>(state, result, false, result.begin(), result.end(), inheritedOnly);
|
| + applyMatchedProperties<LowPropertyPriority>(state, result.allRules(), false, inheritedOnly);
|
|
|
| loadPendingResources(state);
|
|
|
| @@ -924,7 +941,7 @@ void StyleResolver::collectPseudoRulesForElement(Element* element, ElementRuleCo
|
|
|
| if (rulesToInclude & AuthorCSSRules) {
|
| collector.setSameOriginOnly(!(rulesToInclude & CrossOriginCSSRules));
|
| - matchAuthorRules(element, collector, rulesToInclude & EmptyCSSRules);
|
| + matchAuthorRules(*element, collector, rulesToInclude & EmptyCSSRules);
|
| }
|
| }
|
|
|
| @@ -967,10 +984,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);
|
|
|
| @@ -1252,16 +1284,13 @@ void StyleResolver::applyProperties(StyleResolverState& state, const StyleProper
|
| }
|
|
|
| template <CSSPropertyPriority priority>
|
| -void StyleResolver::applyMatchedProperties(StyleResolverState& state, const MatchResult& matchResult, bool isImportant, unsigned startIndex, unsigned endIndex, bool inheritedOnly)
|
| +void StyleResolver::applyMatchedProperties(StyleResolverState& state, const MatchedPropertiesRange& range, bool isImportant, bool inheritedOnly)
|
| {
|
| - if (startIndex == endIndex)
|
| + if (range.begin() == range.end())
|
| return;
|
|
|
| - ASSERT_WITH_SECURITY_IMPLICATION(endIndex <= matchResult.matchedProperties.size());
|
| -
|
| if (state.style()->insideLink() != NotInsideLink) {
|
| - for (unsigned i = startIndex; i < endIndex; ++i) {
|
| - const MatchedProperties& matchedProperties = matchResult.matchedProperties[i];
|
| + for (const auto& matchedProperties : range) {
|
| unsigned linkMatchType = matchedProperties.m_types.linkMatchType;
|
| // FIXME: It would be nicer to pass these as arguments but that requires changes in many places.
|
| state.setApplyPropertyToRegularStyle(linkMatchType & CSSSelector::MatchLink);
|
| @@ -1273,10 +1302,8 @@ void StyleResolver::applyMatchedProperties(StyleResolverState& state, const Matc
|
| state.setApplyPropertyToVisitedLinkStyle(false);
|
| return;
|
| }
|
| - for (unsigned i = startIndex; i < endIndex; ++i) {
|
| - const MatchedProperties& matchedProperties = matchResult.matchedProperties[i];
|
| + for (const auto& matchedProperties : range)
|
| applyProperties<priority>(state, matchedProperties.properties.get(), isImportant, inheritedOnly, static_cast<PropertyWhitelistType>(matchedProperties.m_types.whitelistType));
|
| - }
|
| }
|
|
|
| static unsigned computeMatchedPropertiesHash(const MatchedProperties* properties, unsigned size)
|
| @@ -1302,9 +1329,9 @@ void StyleResolver::applyMatchedProperties(StyleResolverState& state, const Matc
|
|
|
| INCREMENT_STYLE_STATS_COUNTER(*this, matchedPropertyApply, 1);
|
|
|
| - unsigned cacheHash = matchResult.isCacheable ? computeMatchedPropertiesHash(matchResult.matchedProperties.data(), matchResult.matchedProperties.size()) : 0;
|
| + unsigned cacheHash = matchResult.isCacheable() ? computeMatchedPropertiesHash(matchResult.matchedProperties().data(), matchResult.matchedProperties().size()) : 0;
|
| bool applyInheritedOnly = false;
|
| - const CachedMatchedProperties* cachedMatchedProperties = cacheHash ? m_matchedPropertiesCache.find(cacheHash, state, matchResult) : 0;
|
| + const CachedMatchedProperties* cachedMatchedProperties = cacheHash ? m_matchedPropertiesCache.find(cacheHash, state, matchResult.matchedProperties()) : 0;
|
|
|
| if (cachedMatchedProperties && MatchedPropertiesCache::isCacheable(element, *state.style(), *state.parentStyle())) {
|
| INCREMENT_STYLE_STATS_COUNTER(*this, matchedPropertyCacheHit, 1);
|
| @@ -1335,9 +1362,10 @@ void StyleResolver::applyMatchedProperties(StyleResolverState& state, const Matc
|
| // high-priority properties first, i.e., those properties that other properties depend on.
|
| // The order is (1) high-priority not important, (2) high-priority important, (3) normal not important
|
| // and (4) normal important.
|
| - applyMatchedProperties<HighPropertyPriority>(state, matchResult, false, matchResult.begin(), matchResult.end(), applyInheritedOnly);
|
| - applyMatchedProperties<HighPropertyPriority>(state, matchResult, true, matchResult.beginAuthor(), matchResult.endAuthor(), applyInheritedOnly);
|
| - applyMatchedProperties<HighPropertyPriority>(state, matchResult, true, matchResult.beginUA(), matchResult.endUA(), applyInheritedOnly);
|
| + applyMatchedProperties<HighPropertyPriority>(state, matchResult.allRules(), false, applyInheritedOnly);
|
| + for (auto range : ImportantAuthorRanges(matchResult))
|
| + applyMatchedProperties<HighPropertyPriority>(state, range, true, applyInheritedOnly);
|
| + applyMatchedProperties<HighPropertyPriority>(state, matchResult.uaRules(), true, applyInheritedOnly);
|
|
|
| if (UNLIKELY(isSVGForeignObjectElement(element))) {
|
| // LayoutSVGRoot handles zooming for the whole SVG subtree, so foreignObject content should not be scaled again.
|
| @@ -1363,21 +1391,22 @@ void StyleResolver::applyMatchedProperties(StyleResolverState& state, const Matc
|
| applyInheritedOnly = false;
|
|
|
| // Now do the normal priority UA properties.
|
| - applyMatchedProperties<LowPropertyPriority>(state, matchResult, false, matchResult.beginUA(), matchResult.endUA(), applyInheritedOnly);
|
| + applyMatchedProperties<LowPropertyPriority>(state, matchResult.uaRules(), false, applyInheritedOnly);
|
|
|
| // Cache the UA properties to pass them to LayoutTheme in adjustComputedStyle.
|
| state.cacheUserAgentBorderAndBackground();
|
|
|
| // Now do the author and user normal priority properties and all the !important properties.
|
| - applyMatchedProperties<LowPropertyPriority>(state, matchResult, false, matchResult.beginAuthor(), matchResult.endAuthor(), applyInheritedOnly);
|
| - applyMatchedProperties<LowPropertyPriority>(state, matchResult, true, matchResult.beginAuthor(), matchResult.endAuthor(), applyInheritedOnly);
|
| - applyMatchedProperties<LowPropertyPriority>(state, matchResult, true, matchResult.beginUA(), matchResult.endUA(), applyInheritedOnly);
|
| + applyMatchedProperties<LowPropertyPriority>(state, matchResult.authorRules(), false, applyInheritedOnly);
|
| + for (auto range : ImportantAuthorRanges(matchResult))
|
| + applyMatchedProperties<LowPropertyPriority>(state, range, true, applyInheritedOnly);
|
| + applyMatchedProperties<LowPropertyPriority>(state, matchResult.uaRules(), true, applyInheritedOnly);
|
|
|
| loadPendingResources(state);
|
|
|
| if (!cachedMatchedProperties && cacheHash && MatchedPropertiesCache::isCacheable(element, *state.style(), *state.parentStyle())) {
|
| INCREMENT_STYLE_STATS_COUNTER(*this, matchedPropertyCacheAdded, 1);
|
| - m_matchedPropertiesCache.add(*state.style(), *state.parentStyle(), cacheHash, matchResult);
|
| + m_matchedPropertiesCache.add(*state.style(), *state.parentStyle(), cacheHash, matchResult.matchedProperties());
|
| }
|
|
|
| ASSERT(!state.fontBuilder().fontDirty());
|
| @@ -1464,7 +1493,6 @@ DEFINE_TRACE(StyleResolver)
|
| visitor->trace(m_siblingRuleSet);
|
| visitor->trace(m_uncommonAttributeRuleSet);
|
| visitor->trace(m_watchedSelectorsRules);
|
| - visitor->trace(m_treeBoundaryCrossingRules);
|
| visitor->trace(m_styleResourceLoader);
|
| visitor->trace(m_styleSharingLists);
|
| visitor->trace(m_pendingStyleSheets);
|
|
|