⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 251632 in webkit


Ignore:
Timestamp:
Oct 26, 2019, 5:47:05 AM (7 years ago)
Author:
Antti Koivisto
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:
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r251630 r251632  
     12019-10-26  Antti Koivisto  <antti@apple.com>
     2
     3        Build cascade in PropertyCascade constructor
     4        https://bugs.webkit.org/show_bug.cgi?id=203455
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        Instead of calling addNormalMatches/addImportantMatches several times, clients now simply
     9        pass the desired cascade levels to the constructor.
     10
     11        * css/StyleResolver.cpp:
     12        (WebCore::StyleResolver::styleForKeyframe):
     13        (WebCore::StyleResolver::styleForPage):
     14        (WebCore::StyleResolver::applyMatchedProperties):
     15        (WebCore::StyleResolver::applyPropertyToCurrentStyle):
     16        * style/PropertyCascade.cpp:
     17        (WebCore::Style::PropertyCascade::PropertyCascade):
     18        (WebCore::Style::PropertyCascade::addMatch):
     19        (WebCore::Style::PropertyCascade::addNormalMatches):
     20
     21        Return if there were any important matches so we may skip the step later.
     22
     23        (WebCore::Style::PropertyCascade::addImportantMatches):
     24        (WebCore::Style::PropertyCascade::applyDeferredProperties):
     25        (WebCore::Style::PropertyCascade::applyPropertiesImpl):
     26        (WebCore::Style::PropertyCascade::propertyCascadeForRollback):
     27        (WebCore::Style::PropertyCascade::applyProperty):
     28        (WebCore::Style::PropertyCascade::Property::apply): Deleted.
     29
     30        Also make this PropertyCascade::applyProperty
     31
     32        * style/PropertyCascade.h:
     33
    1342019-10-26  Chris Lord  <clord@igalia.com>
    235
  • trunk/Source/WebCore/css/StyleResolver.cpp

    r251611 r251632  
    373373    extractDirectionAndWritingMode(*state.style(), result, direction, writingMode);
    374374
    375     // We don't need to bother with !important. Since there is only ever one
    376     // decl, there's nothing to override. So just add the first properties.
    377     Style::PropertyCascade cascade(*this, result, direction, writingMode);
    378     cascade.addNormalMatches(Style::CascadeLevel::Author);
     375    Style::PropertyCascade cascade(*this, result, { Style::CascadeLevel::Author }, direction, writingMode);
    379376
    380377    cascade.applyProperties(firstCSSProperty, lastHighPriorityProperty);
     
    580577    extractDirectionAndWritingMode(*m_state.style(), result, direction, writingMode);
    581578
    582     Style::PropertyCascade cascade(*this, result, direction, writingMode);
    583     cascade.addNormalMatches(Style::CascadeLevel::Author);
     579    Style::PropertyCascade cascade(*this, result, { Style::CascadeLevel::Author }, direction, writingMode);
    584580
    585581    cascade.applyProperties(firstCSSProperty, lastHighPriorityProperty);
     
    13501346    State& state = m_state;
    13511347    unsigned cacheHash = shouldUseMatchedPropertiesCache && matchResult.isCacheable ? computeMatchedPropertiesHash(matchResult) : 0;
    1352     bool applyInheritedOnly = false;
     1348    auto includedProperties = Style::PropertyCascade::IncludedProperties::All;
     1349
    13531350    const MatchedPropertiesCacheItem* cacheItem = nullptr;
    13541351    if (cacheHash && (cacheItem = findFromMatchedPropertiesCache(cacheHash, matchResult))
     
    13681365            return;
    13691366        }
    1370         applyInheritedOnly = true;
     1367        includedProperties = Style::PropertyCascade::IncludedProperties::InheritedOnly;
    13711368    }
    13721369
     
    13821379        // If so, we cache the border and background styles so that RenderTheme::adjustStyle()
    13831380        // can look at them later to figure out if this is a styled form control or not.
    1384         Style::PropertyCascade cascade(*this, matchResult, direction, writingMode);
    1385         cascade.addNormalMatches(Style::CascadeLevel::UserAgent, applyInheritedOnly);
    1386         cascade.addImportantMatches(Style::CascadeLevel::UserAgent, applyInheritedOnly);
     1381        Style::PropertyCascade cascade(*this, matchResult, { Style::CascadeLevel::UserAgent }, direction, writingMode, includedProperties);
    13871382
    13881383        cascade.applyProperties(CSSPropertyWebkitRubyPosition, CSSPropertyWebkitRubyPosition);
     
    14071402    }
    14081403
    1409     Style::PropertyCascade cascade(*this, matchResult, direction, writingMode);
    1410     cascade.addNormalMatches(Style::CascadeLevel::UserAgent, applyInheritedOnly);
    1411     cascade.addNormalMatches(Style::CascadeLevel::User, applyInheritedOnly);
    1412     cascade.addNormalMatches(Style::CascadeLevel::Author, applyInheritedOnly);
    1413     cascade.addImportantMatches(Style::CascadeLevel::Author, applyInheritedOnly);
    1414     cascade.addImportantMatches(Style::CascadeLevel::User, applyInheritedOnly);
    1415     cascade.addImportantMatches(Style::CascadeLevel::UserAgent, applyInheritedOnly);
     1404    Style::PropertyCascade cascade(*this, matchResult, Style::allCascadeLevels(), direction, writingMode, includedProperties);
    14161405
    14171406    cascade.applyProperties(CSSPropertyWebkitRubyPosition, CSSPropertyWebkitRubyPosition);
     
    14661455{
    14671456    MatchResult matchResult;
    1468     Style::PropertyCascade cascade(*this, matchResult, { }, { });
     1457    Style::PropertyCascade cascade(*this, matchResult, { }, { }, { });
    14691458    if (value)
    14701459        applyProperty(id, value, cascade);
  • trunk/Source/WebCore/style/PropertyCascade.cpp

    r251611 r251632  
    141141#endif
    142142
    143 PropertyCascade::PropertyCascade(StyleResolver& styleResolver, const MatchResult& matchResult, TextDirection direction, WritingMode writingMode)
     143PropertyCascade::PropertyCascade(StyleResolver& styleResolver, const MatchResult& matchResult, OptionSet<CascadeLevel> cascadeLevels, TextDirection direction, WritingMode writingMode, IncludedProperties includedProperties)
    144144    : m_styleResolver(styleResolver)
    145145    , m_matchResult(matchResult)
     146    , m_includedProperties(includedProperties)
    146147    , m_direction(direction)
    147148    , m_writingMode(writingMode)
    148149{
     150    OptionSet<CascadeLevel> cascadeLevelsWithImportant;
     151
     152    for (auto cascadeLevel : cascadeLevels) {
     153        bool hasImportant = addNormalMatches(cascadeLevel);
     154        if (hasImportant)
     155            cascadeLevelsWithImportant.add(cascadeLevel);
     156    }
     157
     158    for (auto cascadeLevel : { CascadeLevel::Author, CascadeLevel::User, CascadeLevel::UserAgent }) {
     159        if (!cascadeLevelsWithImportant.contains(cascadeLevel))
     160            continue;
     161        addImportantMatches(cascadeLevel);
     162    }
    149163}
    150164
     
    210224
    211225
    212 void PropertyCascade::addMatch(const MatchedProperties& matchedProperties, CascadeLevel cascadeLevel, bool isImportant, bool inheritedOnly)
     226bool PropertyCascade::addMatch(const MatchedProperties& matchedProperties, CascadeLevel cascadeLevel, bool important)
    213227{
    214228    auto& styleProperties = *matchedProperties.properties;
    215229    auto propertyWhitelistType = static_cast<PropertyWhitelistType>(matchedProperties.whitelistType);
     230    bool hasImportantProperties = false;
    216231
    217232    for (unsigned i = 0, count = styleProperties.propertyCount(); i < count; ++i) {
    218233        auto current = styleProperties.propertyAt(i);
    219         if (isImportant != current.isImportant())
    220             continue;
    221         if (inheritedOnly && !current.isInherited()) {
     234
     235        if (current.isImportant())
     236            hasImportantProperties = true;
     237        if (important != current.isImportant())
     238            continue;
     239
     240        if (m_includedProperties == IncludedProperties::InheritedOnly && !current.isInherited()) {
    222241            // Inherited only mode is used after matched properties cache hit.
    223242            // A match with a value that is explicitly inherited should never have been cached.
     
    239258            set(propertyID, *current.value(), matchedProperties.linkMatchType, cascadeLevel, matchedProperties.styleScopeOrdinal);
    240259    }
     260
     261    return hasImportantProperties;
    241262}
    242263
     
    252273}
    253274
    254 void PropertyCascade::addNormalMatches(CascadeLevel cascadeLevel, bool inheritedOnly)
    255 {
     275bool PropertyCascade::addNormalMatches(CascadeLevel cascadeLevel)
     276{
     277    bool hasImportant = false;
    256278    for (auto& matchedDeclarations : declarationsForCascadeLevel(m_matchResult, cascadeLevel))
    257         addMatch(matchedDeclarations, cascadeLevel, false, inheritedOnly);
     279        hasImportant |= addMatch(matchedDeclarations, cascadeLevel, false);
     280
     281    return hasImportant;
    258282}
    259283
     
    267291}
    268292
    269 void PropertyCascade::addImportantMatches(CascadeLevel cascadeLevel, bool inheritedOnly)
     293void PropertyCascade::addImportantMatches(CascadeLevel cascadeLevel)
    270294{
    271295    struct IndexAndOrdinal {
     
    302326
    303327    for (auto& match : importantMatches)
    304         addMatch(matchedDeclarations[match.index], cascadeLevel, true, inheritedOnly);
     328        addMatch(matchedDeclarations[match.index], cascadeLevel, true);
    305329}
    306330
     
    308332{
    309333    for (auto& property : m_deferredProperties)
    310         property.apply(*this);
     334        applyProperty(property);
    311335}
    312336
     
    340364
    341365            m_applyState.inProgressProperties.set(propertyID);
    342             property.apply(*this);
     366            applyProperty(property);
    343367            m_applyState.appliedProperties.set(propertyID);
    344368            m_applyState.inProgressProperties.set(propertyID, false);
     
    347371
    348372        // If we don't have any custom properties, then there can't be any cycles.
    349         property.apply(*this);
     373        applyProperty(property);
    350374    }
    351375}
     
    434458    case CascadeLevel::Author:
    435459        if (!m_authorRollbackCascade) {
    436             m_authorRollbackCascade = makeUnique<PropertyCascade>(m_styleResolver, m_matchResult, m_direction, m_writingMode);
    437 
    438             // This special rollback cascade contains UA rules and user rules but no author rules.
    439             m_authorRollbackCascade->addNormalMatches(CascadeLevel::UserAgent, false);
    440             m_authorRollbackCascade->addNormalMatches(CascadeLevel::User, false);
    441             m_authorRollbackCascade->addImportantMatches(CascadeLevel::User, false);
    442             m_authorRollbackCascade->addImportantMatches(CascadeLevel::UserAgent, false);
     460            auto cascadeLevels = OptionSet<CascadeLevel> { CascadeLevel::UserAgent, CascadeLevel::User };
     461            m_authorRollbackCascade = makeUnique<PropertyCascade>(m_styleResolver, m_matchResult, cascadeLevels, m_direction, m_writingMode, m_includedProperties);
    443462        }
    444463        return m_authorRollbackCascade.get();
     
    446465    case CascadeLevel::User:
    447466        if (!m_userRollbackCascade) {
    448             m_userRollbackCascade = makeUnique<PropertyCascade>(m_styleResolver, m_matchResult, m_direction, m_writingMode);
    449 
    450             // This special rollback cascade contains only UA rules.
    451             m_userRollbackCascade->addNormalMatches(CascadeLevel::UserAgent, false);
    452             m_userRollbackCascade->addImportantMatches(CascadeLevel::UserAgent, false);
     467            auto cascadeLevels = OptionSet<CascadeLevel> { CascadeLevel::UserAgent };
     468            m_userRollbackCascade = makeUnique<PropertyCascade>(m_styleResolver, m_matchResult, cascadeLevels, m_direction, m_writingMode, m_includedProperties);
    453469        }
    454470        return m_userRollbackCascade.get();
     
    461477}
    462478
    463 void PropertyCascade::Property::apply(PropertyCascade& cascade)
    464 {
    465     auto& resolver = cascade.styleResolver();
    466     StyleResolver::State& state = resolver.state();
    467     state.setCascadeLevel(level);
    468     state.setStyleScopeOrdinal(styleScopeOrdinal);
    469 
    470     if (cssValue[SelectorChecker::MatchDefault]) {
     479inline void PropertyCascade::applyProperty(const Property& property)
     480{
     481    StyleResolver::State& state = m_styleResolver.state();
     482    state.setCascadeLevel(property.level);
     483    state.setStyleScopeOrdinal(property.styleScopeOrdinal);
     484
     485    if (property.cssValue[SelectorChecker::MatchDefault]) {
    471486        state.setApplyPropertyToRegularStyle(true);
    472487        state.setApplyPropertyToVisitedLinkStyle(false);
    473         resolver.applyProperty(id, cssValue[SelectorChecker::MatchDefault], cascade, SelectorChecker::MatchDefault);
     488        m_styleResolver.applyProperty(property.id, property.cssValue[SelectorChecker::MatchDefault], *this, SelectorChecker::MatchDefault);
    474489    }
    475490
     
    477492        return;
    478493
    479     if (cssValue[SelectorChecker::MatchLink]) {
     494    if (property.cssValue[SelectorChecker::MatchLink]) {
    480495        state.setApplyPropertyToRegularStyle(true);
    481496        state.setApplyPropertyToVisitedLinkStyle(false);
    482         resolver.applyProperty(id, cssValue[SelectorChecker::MatchLink], cascade, SelectorChecker::MatchLink);
    483     }
    484 
    485     if (cssValue[SelectorChecker::MatchVisited]) {
     497        m_styleResolver.applyProperty(property.id, property.cssValue[SelectorChecker::MatchLink], *this, SelectorChecker::MatchLink);
     498    }
     499
     500    if (property.cssValue[SelectorChecker::MatchVisited]) {
    486501        state.setApplyPropertyToRegularStyle(false);
    487502        state.setApplyPropertyToVisitedLinkStyle(true);
    488         resolver.applyProperty(id, cssValue[SelectorChecker::MatchVisited], cascade, SelectorChecker::MatchVisited);
     503        m_styleResolver.applyProperty(property.id, property.cssValue[SelectorChecker::MatchVisited], *this, SelectorChecker::MatchVisited);
    489504    }
    490505
  • trunk/Source/WebCore/style/PropertyCascade.h

    r251611 r251632  
    3737
    3838enum class CascadeLevel : uint8_t {
    39     UserAgent,
    40     User,
    41     Author
     39    UserAgent   = 1 << 0,
     40    User        = 1 << 1,
     41    Author      = 1 << 2
    4242};
     43
     44static constexpr OptionSet<CascadeLevel> allCascadeLevels() { return { Style::CascadeLevel::UserAgent, Style::CascadeLevel::User, Style::CascadeLevel::Author }; }
    4345
    4446class PropertyCascade {
    4547    WTF_MAKE_FAST_ALLOCATED;
    4648public:
    47     PropertyCascade(StyleResolver&, const MatchResult&, TextDirection, WritingMode);
     49    enum IncludedProperties { All, InheritedOnly };
     50    PropertyCascade(StyleResolver&, const MatchResult&, OptionSet<CascadeLevel>, TextDirection, WritingMode, IncludedProperties = IncludedProperties::All);
    4851    ~PropertyCascade();
    4952
     
    5154
    5255    struct Property {
    53         void apply(PropertyCascade&);
    54 
    5556        CSSPropertyID id;
    5657        CascadeLevel level;
     
    6566    Property customProperty(const String&) const;
    6667
    67     void addNormalMatches(CascadeLevel, bool inheritedOnly = false);
    68     void addImportantMatches(CascadeLevel, bool inheritedOnly = false);
    69 
    7068    bool hasAppliedProperty(CSSPropertyID) const;
    7169
     
    7977
    8078private:
    81     void addMatch(const MatchedProperties&, CascadeLevel, bool isImportant, bool inheritedOnly);
     79    bool addNormalMatches(CascadeLevel);
     80    void addImportantMatches(CascadeLevel);
     81    bool addMatch(const MatchedProperties&, CascadeLevel, bool important);
     82
    8283    void set(CSSPropertyID, CSSValue&, unsigned linkMatchType, CascadeLevel, ScopeOrdinal);
    8384    void setDeferred(CSSPropertyID, CSSValue&, unsigned linkMatchType, CascadeLevel, ScopeOrdinal);
     
    8788    template<CustomPropertyCycleTracking trackCycles>
    8889    void applyPropertiesImpl(int firstProperty, int lastProperty);
     90    void applyProperty(const Property&);
    8991
    9092    StyleResolver& m_styleResolver;
    9193    const MatchResult& m_matchResult;
     94    IncludedProperties m_includedProperties;
    9295
    9396    TextDirection m_direction;
Note: See TracChangeset for help on using the changeset viewer.