Title: [251632] trunk/Source/WebCore
Revision
251632
Author
[email protected]
Date
2019-10-26 05:47:05 -0700 (Sat, 26 Oct 2019)

Log Message

Build cascade in PropertyCascade constructor
https://bugs.webkit.org/show_bug.cgi?id=203455

Reviewed by Zalan Bujtas.

Instead of calling addNormalMatches/addImportantMatches several times, clients now simply
pass the desired cascade levels to the constructor.

* css/StyleResolver.cpp:
(WebCore::StyleResolver::styleForKeyframe):
(WebCore::StyleResolver::styleForPage):
(WebCore::StyleResolver::applyMatchedProperties):
(WebCore::StyleResolver::applyPropertyToCurrentStyle):
* style/PropertyCascade.cpp:
(WebCore::Style::PropertyCascade::PropertyCascade):
(WebCore::Style::PropertyCascade::addMatch):
(WebCore::Style::PropertyCascade::addNormalMatches):

Return if there were any important matches so we may skip the step later.

(WebCore::Style::PropertyCascade::addImportantMatches):
(WebCore::Style::PropertyCascade::applyDeferredProperties):
(WebCore::Style::PropertyCascade::applyPropertiesImpl):
(WebCore::Style::PropertyCascade::propertyCascadeForRollback):
(WebCore::Style::PropertyCascade::applyProperty):
(WebCore::Style::PropertyCascade::Property::apply): Deleted.

Also make this PropertyCascade::applyProperty

* style/PropertyCascade.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (251631 => 251632)


--- trunk/Source/WebCore/ChangeLog	2019-10-26 07:31:25 UTC (rev 251631)
+++ trunk/Source/WebCore/ChangeLog	2019-10-26 12:47:05 UTC (rev 251632)
@@ -1,3 +1,36 @@
+2019-10-26  Antti Koivisto  <[email protected]>
+
+        Build cascade in PropertyCascade constructor
+        https://bugs.webkit.org/show_bug.cgi?id=203455
+
+        Reviewed by Zalan Bujtas.
+
+        Instead of calling addNormalMatches/addImportantMatches several times, clients now simply
+        pass the desired cascade levels to the constructor.
+
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::styleForKeyframe):
+        (WebCore::StyleResolver::styleForPage):
+        (WebCore::StyleResolver::applyMatchedProperties):
+        (WebCore::StyleResolver::applyPropertyToCurrentStyle):
+        * style/PropertyCascade.cpp:
+        (WebCore::Style::PropertyCascade::PropertyCascade):
+        (WebCore::Style::PropertyCascade::addMatch):
+        (WebCore::Style::PropertyCascade::addNormalMatches):
+
+        Return if there were any important matches so we may skip the step later.
+
+        (WebCore::Style::PropertyCascade::addImportantMatches):
+        (WebCore::Style::PropertyCascade::applyDeferredProperties):
+        (WebCore::Style::PropertyCascade::applyPropertiesImpl):
+        (WebCore::Style::PropertyCascade::propertyCascadeForRollback):
+        (WebCore::Style::PropertyCascade::applyProperty):
+        (WebCore::Style::PropertyCascade::Property::apply): Deleted.
+
+        Also make this PropertyCascade::applyProperty
+
+        * style/PropertyCascade.h:
+
 2019-10-26  Chris Lord  <[email protected]>
 
         Put OffscreenCanvas behind a build flag

Modified: trunk/Source/WebCore/css/StyleResolver.cpp (251631 => 251632)


--- trunk/Source/WebCore/css/StyleResolver.cpp	2019-10-26 07:31:25 UTC (rev 251631)
+++ trunk/Source/WebCore/css/StyleResolver.cpp	2019-10-26 12:47:05 UTC (rev 251632)
@@ -372,10 +372,7 @@
     WritingMode writingMode;
     extractDirectionAndWritingMode(*state.style(), result, direction, writingMode);
 
-    // We don't need to bother with !important. Since there is only ever one
-    // decl, there's nothing to override. So just add the first properties.
-    Style::PropertyCascade cascade(*this, result, direction, writingMode);
-    cascade.addNormalMatches(Style::CascadeLevel::Author);
+    Style::PropertyCascade cascade(*this, result, { Style::CascadeLevel::Author }, direction, writingMode);
 
     cascade.applyProperties(firstCSSProperty, lastHighPriorityProperty);
 
@@ -579,8 +576,7 @@
     WritingMode writingMode;
     extractDirectionAndWritingMode(*m_state.style(), result, direction, writingMode);
 
-    Style::PropertyCascade cascade(*this, result, direction, writingMode);
-    cascade.addNormalMatches(Style::CascadeLevel::Author);
+    Style::PropertyCascade cascade(*this, result, { Style::CascadeLevel::Author }, direction, writingMode);
 
     cascade.applyProperties(firstCSSProperty, lastHighPriorityProperty);
 
@@ -1349,7 +1345,8 @@
 {
     State& state = m_state;
     unsigned cacheHash = shouldUseMatchedPropertiesCache && matchResult.isCacheable ? computeMatchedPropertiesHash(matchResult) : 0;
-    bool applyInheritedOnly = false;
+    auto includedProperties = Style::PropertyCascade::IncludedProperties::All;
+
     const MatchedPropertiesCacheItem* cacheItem = nullptr;
     if (cacheHash && (cacheItem = findFromMatchedPropertiesCache(cacheHash, matchResult))
         && isCacheableInMatchedPropertiesCache(element, state.style(), state.parentStyle())) {
@@ -1367,7 +1364,7 @@
             state.style()->setInsideLink(linkStatus);
             return;
         }
-        applyInheritedOnly = true; 
+        includedProperties = Style::PropertyCascade::IncludedProperties::InheritedOnly;
     }
 
     // Directional properties (*-before/after) are aliases that depend on the TextDirection and WritingMode.
@@ -1381,9 +1378,7 @@
         // Find out if there's a -webkit-appearance property in effect from the UA sheet.
         // If so, we cache the border and background styles so that RenderTheme::adjustStyle()
         // can look at them later to figure out if this is a styled form control or not.
-        Style::PropertyCascade cascade(*this, matchResult, direction, writingMode);
-        cascade.addNormalMatches(Style::CascadeLevel::UserAgent, applyInheritedOnly);
-        cascade.addImportantMatches(Style::CascadeLevel::UserAgent, applyInheritedOnly);
+        Style::PropertyCascade cascade(*this, matchResult, { Style::CascadeLevel::UserAgent }, direction, writingMode, includedProperties);
 
         cascade.applyProperties(CSSPropertyWebkitRubyPosition, CSSPropertyWebkitRubyPosition);
         adjustStyleForInterCharacterRuby();
@@ -1406,13 +1401,7 @@
         state.cacheBorderAndBackground();
     }
 
-    Style::PropertyCascade cascade(*this, matchResult, direction, writingMode);
-    cascade.addNormalMatches(Style::CascadeLevel::UserAgent, applyInheritedOnly);
-    cascade.addNormalMatches(Style::CascadeLevel::User, applyInheritedOnly);
-    cascade.addNormalMatches(Style::CascadeLevel::Author, applyInheritedOnly);
-    cascade.addImportantMatches(Style::CascadeLevel::Author, applyInheritedOnly);
-    cascade.addImportantMatches(Style::CascadeLevel::User, applyInheritedOnly);
-    cascade.addImportantMatches(Style::CascadeLevel::UserAgent, applyInheritedOnly);
+    Style::PropertyCascade cascade(*this, matchResult, Style::allCascadeLevels(), direction, writingMode, includedProperties);
 
     cascade.applyProperties(CSSPropertyWebkitRubyPosition, CSSPropertyWebkitRubyPosition);
     adjustStyleForInterCharacterRuby();
@@ -1465,7 +1454,7 @@
 void StyleResolver::applyPropertyToCurrentStyle(CSSPropertyID id, CSSValue* value)
 {
     MatchResult matchResult;
-    Style::PropertyCascade cascade(*this, matchResult, { }, { });
+    Style::PropertyCascade cascade(*this, matchResult, { }, { }, { });
     if (value)
         applyProperty(id, value, cascade);
 }

Modified: trunk/Source/WebCore/style/PropertyCascade.cpp (251631 => 251632)


--- trunk/Source/WebCore/style/PropertyCascade.cpp	2019-10-26 07:31:25 UTC (rev 251631)
+++ trunk/Source/WebCore/style/PropertyCascade.cpp	2019-10-26 12:47:05 UTC (rev 251632)
@@ -140,12 +140,26 @@
 }
 #endif
 
-PropertyCascade::PropertyCascade(StyleResolver& styleResolver, const MatchResult& matchResult, TextDirection direction, WritingMode writingMode)
+PropertyCascade::PropertyCascade(StyleResolver& styleResolver, const MatchResult& matchResult, OptionSet<CascadeLevel> cascadeLevels, TextDirection direction, WritingMode writingMode, IncludedProperties includedProperties)
     : m_styleResolver(styleResolver)
     , m_matchResult(matchResult)
+    , m_includedProperties(includedProperties)
     , m_direction(direction)
     , m_writingMode(writingMode)
 {
+    OptionSet<CascadeLevel> cascadeLevelsWithImportant;
+
+    for (auto cascadeLevel : cascadeLevels) {
+        bool hasImportant = addNormalMatches(cascadeLevel);
+        if (hasImportant)
+            cascadeLevelsWithImportant.add(cascadeLevel);
+    }
+
+    for (auto cascadeLevel : { CascadeLevel::Author, CascadeLevel::User, CascadeLevel::UserAgent }) {
+        if (!cascadeLevelsWithImportant.contains(cascadeLevel))
+            continue;
+        addImportantMatches(cascadeLevel);
+    }
 }
 
 PropertyCascade::~PropertyCascade() = default;
@@ -209,16 +223,21 @@
 }
 
 
-void PropertyCascade::addMatch(const MatchedProperties& matchedProperties, CascadeLevel cascadeLevel, bool isImportant, bool inheritedOnly)
+bool PropertyCascade::addMatch(const MatchedProperties& matchedProperties, CascadeLevel cascadeLevel, bool important)
 {
     auto& styleProperties = *matchedProperties.properties;
     auto propertyWhitelistType = static_cast<PropertyWhitelistType>(matchedProperties.whitelistType);
+    bool hasImportantProperties = false;
 
     for (unsigned i = 0, count = styleProperties.propertyCount(); i < count; ++i) {
         auto current = styleProperties.propertyAt(i);
-        if (isImportant != current.isImportant())
+
+        if (current.isImportant())
+            hasImportantProperties = true;
+        if (important != current.isImportant())
             continue;
-        if (inheritedOnly && !current.isInherited()) {
+
+        if (m_includedProperties == IncludedProperties::InheritedOnly && !current.isInherited()) {
             // Inherited only mode is used after matched properties cache hit.
             // A match with a value that is explicitly inherited should never have been cached.
             ASSERT(!current.value()->isInheritedValue());
@@ -238,6 +257,8 @@
         else
             set(propertyID, *current.value(), matchedProperties.linkMatchType, cascadeLevel, matchedProperties.styleScopeOrdinal);
     }
+
+    return hasImportantProperties;
 }
 
 static auto& declarationsForCascadeLevel(const MatchResult& matchResult, CascadeLevel cascadeLevel)
@@ -251,10 +272,13 @@
     return matchResult.authorDeclarations;
 }
 
-void PropertyCascade::addNormalMatches(CascadeLevel cascadeLevel, bool inheritedOnly)
+bool PropertyCascade::addNormalMatches(CascadeLevel cascadeLevel)
 {
+    bool hasImportant = false;
     for (auto& matchedDeclarations : declarationsForCascadeLevel(m_matchResult, cascadeLevel))
-        addMatch(matchedDeclarations, cascadeLevel, false, inheritedOnly);
+        hasImportant |= addMatch(matchedDeclarations, cascadeLevel, false);
+
+    return hasImportant;
 }
 
 static bool hasImportantProperties(const StyleProperties& properties)
@@ -266,7 +290,7 @@
     return false;
 }
 
-void PropertyCascade::addImportantMatches(CascadeLevel cascadeLevel, bool inheritedOnly)
+void PropertyCascade::addImportantMatches(CascadeLevel cascadeLevel)
 {
     struct IndexAndOrdinal {
         unsigned index;
@@ -301,13 +325,13 @@
     }
 
     for (auto& match : importantMatches)
-        addMatch(matchedDeclarations[match.index], cascadeLevel, true, inheritedOnly);
+        addMatch(matchedDeclarations[match.index], cascadeLevel, true);
 }
 
 void PropertyCascade::applyDeferredProperties()
 {
     for (auto& property : m_deferredProperties)
-        property.apply(*this);
+        applyProperty(property);
 }
 
 void PropertyCascade::applyProperties(int firstProperty, int lastProperty)
@@ -339,7 +363,7 @@
             }
 
             m_applyState.inProgressProperties.set(propertyID);
-            property.apply(*this);
+            applyProperty(property);
             m_applyState.appliedProperties.set(propertyID);
             m_applyState.inProgressProperties.set(propertyID, false);
             continue;
@@ -346,7 +370,7 @@
         }
 
         // If we don't have any custom properties, then there can't be any cycles.
-        property.apply(*this);
+        applyProperty(property);
     }
 }
 
@@ -433,23 +457,15 @@
     switch (cascadeLevel) {
     case CascadeLevel::Author:
         if (!m_authorRollbackCascade) {
-            m_authorRollbackCascade = makeUnique<PropertyCascade>(m_styleResolver, m_matchResult, m_direction, m_writingMode);
-
-            // This special rollback cascade contains UA rules and user rules but no author rules.
-            m_authorRollbackCascade->addNormalMatches(CascadeLevel::UserAgent, false);
-            m_authorRollbackCascade->addNormalMatches(CascadeLevel::User, false);
-            m_authorRollbackCascade->addImportantMatches(CascadeLevel::User, false);
-            m_authorRollbackCascade->addImportantMatches(CascadeLevel::UserAgent, false);
+            auto cascadeLevels = OptionSet<CascadeLevel> { CascadeLevel::UserAgent, CascadeLevel::User };
+            m_authorRollbackCascade = makeUnique<PropertyCascade>(m_styleResolver, m_matchResult, cascadeLevels, m_direction, m_writingMode, m_includedProperties);
         }
         return m_authorRollbackCascade.get();
 
     case CascadeLevel::User:
         if (!m_userRollbackCascade) {
-            m_userRollbackCascade = makeUnique<PropertyCascade>(m_styleResolver, m_matchResult, m_direction, m_writingMode);
-
-            // This special rollback cascade contains only UA rules.
-            m_userRollbackCascade->addNormalMatches(CascadeLevel::UserAgent, false);
-            m_userRollbackCascade->addImportantMatches(CascadeLevel::UserAgent, false);
+            auto cascadeLevels = OptionSet<CascadeLevel> { CascadeLevel::UserAgent };
+            m_userRollbackCascade = makeUnique<PropertyCascade>(m_styleResolver, m_matchResult, cascadeLevels, m_direction, m_writingMode, m_includedProperties);
         }
         return m_userRollbackCascade.get();
 
@@ -460,32 +476,31 @@
     return nullptr;
 }
 
-void PropertyCascade::Property::apply(PropertyCascade& cascade)
+inline void PropertyCascade::applyProperty(const Property& property)
 {
-    auto& resolver = cascade.styleResolver();
-    StyleResolver::State& state = resolver.state();
-    state.setCascadeLevel(level);
-    state.setStyleScopeOrdinal(styleScopeOrdinal);
+    StyleResolver::State& state = m_styleResolver.state();
+    state.setCascadeLevel(property.level);
+    state.setStyleScopeOrdinal(property.styleScopeOrdinal);
 
-    if (cssValue[SelectorChecker::MatchDefault]) {
+    if (property.cssValue[SelectorChecker::MatchDefault]) {
         state.setApplyPropertyToRegularStyle(true);
         state.setApplyPropertyToVisitedLinkStyle(false);
-        resolver.applyProperty(id, cssValue[SelectorChecker::MatchDefault], cascade, SelectorChecker::MatchDefault);
+        m_styleResolver.applyProperty(property.id, property.cssValue[SelectorChecker::MatchDefault], *this, SelectorChecker::MatchDefault);
     }
 
     if (state.style()->insideLink() == InsideLink::NotInside)
         return;
 
-    if (cssValue[SelectorChecker::MatchLink]) {
+    if (property.cssValue[SelectorChecker::MatchLink]) {
         state.setApplyPropertyToRegularStyle(true);
         state.setApplyPropertyToVisitedLinkStyle(false);
-        resolver.applyProperty(id, cssValue[SelectorChecker::MatchLink], cascade, SelectorChecker::MatchLink);
+        m_styleResolver.applyProperty(property.id, property.cssValue[SelectorChecker::MatchLink], *this, SelectorChecker::MatchLink);
     }
 
-    if (cssValue[SelectorChecker::MatchVisited]) {
+    if (property.cssValue[SelectorChecker::MatchVisited]) {
         state.setApplyPropertyToRegularStyle(false);
         state.setApplyPropertyToVisitedLinkStyle(true);
-        resolver.applyProperty(id, cssValue[SelectorChecker::MatchVisited], cascade, SelectorChecker::MatchVisited);
+        m_styleResolver.applyProperty(property.id, property.cssValue[SelectorChecker::MatchVisited], *this, SelectorChecker::MatchVisited);
     }
 
     state.setApplyPropertyToRegularStyle(true);

Modified: trunk/Source/WebCore/style/PropertyCascade.h (251631 => 251632)


--- trunk/Source/WebCore/style/PropertyCascade.h	2019-10-26 07:31:25 UTC (rev 251631)
+++ trunk/Source/WebCore/style/PropertyCascade.h	2019-10-26 12:47:05 UTC (rev 251632)
@@ -36,22 +36,23 @@
 namespace Style {
 
 enum class CascadeLevel : uint8_t {
-    UserAgent,
-    User,
-    Author
+    UserAgent   = 1 << 0,
+    User        = 1 << 1,
+    Author      = 1 << 2
 };
 
+static constexpr OptionSet<CascadeLevel> allCascadeLevels() { return { Style::CascadeLevel::UserAgent, Style::CascadeLevel::User, Style::CascadeLevel::Author }; }
+
 class PropertyCascade {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    PropertyCascade(StyleResolver&, const MatchResult&, TextDirection, WritingMode);
+    enum IncludedProperties { All, InheritedOnly };
+    PropertyCascade(StyleResolver&, const MatchResult&, OptionSet<CascadeLevel>, TextDirection, WritingMode, IncludedProperties = IncludedProperties::All);
     ~PropertyCascade();
 
     StyleResolver& styleResolver() { return m_styleResolver; }
 
     struct Property {
-        void apply(PropertyCascade&);
-
         CSSPropertyID id;
         CascadeLevel level;
         ScopeOrdinal styleScopeOrdinal;
@@ -64,9 +65,6 @@
     bool hasCustomProperty(const String&) const;
     Property customProperty(const String&) const;
 
-    void addNormalMatches(CascadeLevel, bool inheritedOnly = false);
-    void addImportantMatches(CascadeLevel, bool inheritedOnly = false);
-
     bool hasAppliedProperty(CSSPropertyID) const;
 
     void applyProperties(int firstProperty, int lastProperty);
@@ -78,7 +76,10 @@
     PropertyCascade* propertyCascadeForRollback(CascadeLevel);
 
 private:
-    void addMatch(const MatchedProperties&, CascadeLevel, bool isImportant, bool inheritedOnly);
+    bool addNormalMatches(CascadeLevel);
+    void addImportantMatches(CascadeLevel);
+    bool addMatch(const MatchedProperties&, CascadeLevel, bool important);
+
     void set(CSSPropertyID, CSSValue&, unsigned linkMatchType, CascadeLevel, ScopeOrdinal);
     void setDeferred(CSSPropertyID, CSSValue&, unsigned linkMatchType, CascadeLevel, ScopeOrdinal);
     static void setPropertyInternal(Property&, CSSPropertyID, CSSValue&, unsigned linkMatchType, CascadeLevel, ScopeOrdinal);
@@ -86,9 +87,11 @@
     enum CustomPropertyCycleTracking { Enabled = 0, Disabled };
     template<CustomPropertyCycleTracking trackCycles>
     void applyPropertiesImpl(int firstProperty, int lastProperty);
+    void applyProperty(const Property&);
 
     StyleResolver& m_styleResolver;
     const MatchResult& m_matchResult;
+    IncludedProperties m_includedProperties;
 
     TextDirection m_direction;
     WritingMode m_writingMode;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to