Changeset 287018 in webkit


Ignore:
Timestamp:
Dec 14, 2021 2:13:54 AM (7 months ago)
Author:
Antti Koivisto
Message:

[CSS Cascade Layers] revert-layer should revert style attribute to regular author style
https://bugs.webkit.org/show_bug.cgi?id=234082

Reviewed by Simon Fraser.

Source/WebCore:

If 'revert-layer' keyword is used in style attribute it should revert to regular author style
on the default cascade level.

  • style/PropertyCascade.cpp:

(WebCore::Style::PropertyCascade::PropertyCascade):

Make the maximum level (used for revert cascades) an std::optional.

(WebCore::Style::PropertyCascade::setPropertyInternal):
(WebCore::Style::PropertyCascade::addMatch):

Factor the revert test into a lambda.
We can never revert to an attribute style so always skip them.

  • style/PropertyCascade.h:

(WebCore::Style::PropertyCascade::PropertyCascade):
(WebCore::Style::PropertyCascade::maximumCascadeLevel const): Deleted.
(WebCore::Style::PropertyCascade::maximumCascadeLayerPriority const): Deleted.

  • style/RuleSet.h:
  • style/StyleBuilder.cpp:

(WebCore::Style::Builder::applyCustomProperty):
(WebCore::Style::Builder::applyCascadeProperty):
(WebCore::Style::Builder::applyRollbackCascadeProperty):

Keep a pointer to the current property being applied in state instead of individual priority values.

(WebCore::Style::Builder::applyProperty):
(WebCore::Style::Builder::ensureRollbackCascadeForRevert):
(WebCore::Style::Builder::ensureRollbackCascadeForRevertLayer):

If the current property is from attribute style it reverts to the same layer.

  • style/StyleBuilder.h:
  • style/StyleBuilderState.h:

(WebCore::Style::BuilderState::styleScopeOrdinal const):

LayoutTests:

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r287013 r287018  
     12021-12-14  Antti Koivisto  <antti@apple.com>
     2
     3        [CSS Cascade Layers] revert-layer should revert style attribute to regular author style
     4        https://bugs.webkit.org/show_bug.cgi?id=234082
     5
     6        Reviewed by Simon Fraser.
     7
     8        * TestExpectations:
     9
    1102021-12-13  John Wilander  <wilander@apple.com>
    211
  • trunk/LayoutTests/TestExpectations

    r286955 r287018  
    21822182imported/w3c/web-platform-tests/css/css-cascade/important-prop.html [ ImageOnlyFailure ]
    21832183webkit.org/b/187093 [ Debug ] imported/w3c/web-platform-tests/css/css-cascade/all-prop-initial-xml.html [ Skip ]
    2184 webkit.org/b/233937 imported/w3c/web-platform-tests/css/css-cascade/revert-layer-009.html [ ImageOnlyFailure ]
    21852184webkit.org/b/233937 imported/w3c/web-platform-tests/css/css-cascade/revert-layer-010.html [ ImageOnlyFailure ]
    21862185webkit.org/b/233937 imported/w3c/web-platform-tests/css/css-cascade/revert-layer-011.html [ ImageOnlyFailure ]
    2187 webkit.org/b/233937 imported/w3c/web-platform-tests/css/css-cascade/revert-layer-012.html [ ImageOnlyFailure ]
    21882186
    21892187webkit.org/b/148801 imported/w3c/web-platform-tests/css/css-color/t422-rgba-onscreen-b.xht [ ImageOnlyFailure ]
  • trunk/Source/WebCore/ChangeLog

    r287017 r287018  
     12021-12-14  Antti Koivisto  <antti@apple.com>
     2
     3        [CSS Cascade Layers] revert-layer should revert style attribute to regular author style
     4        https://bugs.webkit.org/show_bug.cgi?id=234082
     5
     6        Reviewed by Simon Fraser.
     7
     8        If 'revert-layer' keyword is used in style attribute it should revert to regular author style
     9        on the default cascade level.
     10
     11        * style/PropertyCascade.cpp:
     12        (WebCore::Style::PropertyCascade::PropertyCascade):
     13
     14        Make the maximum level (used for revert cascades) an std::optional.
     15
     16        (WebCore::Style::PropertyCascade::setPropertyInternal):
     17        (WebCore::Style::PropertyCascade::addMatch):
     18
     19        Factor the revert test into a lambda.
     20        We can never revert to an attribute style so always skip them.
     21
     22        * style/PropertyCascade.h:
     23        (WebCore::Style::PropertyCascade::PropertyCascade):
     24        (WebCore::Style::PropertyCascade::maximumCascadeLevel const): Deleted.
     25        (WebCore::Style::PropertyCascade::maximumCascadeLayerPriority const): Deleted.
     26        * style/RuleSet.h:
     27        * style/StyleBuilder.cpp:
     28        (WebCore::Style::Builder::applyCustomProperty):
     29        (WebCore::Style::Builder::applyCascadeProperty):
     30        (WebCore::Style::Builder::applyRollbackCascadeProperty):
     31
     32        Keep a pointer to the current property being applied in state instead of individual priority values.
     33
     34        (WebCore::Style::Builder::applyProperty):
     35        (WebCore::Style::Builder::ensureRollbackCascadeForRevert):
     36        (WebCore::Style::Builder::ensureRollbackCascadeForRevertLayer):
     37
     38        If the current property is from attribute style it reverts to the same layer.
     39
     40        * style/StyleBuilder.h:
     41        * style/StyleBuilderState.h:
     42        (WebCore::Style::BuilderState::styleScopeOrdinal const):
     43
    1442021-12-14  Youenn Fablet  <youenn@apple.com>
    245
  • trunk/Source/WebCore/style/PropertyCascade.cpp

    r285624 r287018  
    2727#include "PropertyCascade.h"
    2828
     29#include "CSSCustomPropertyValue.h"
    2930#include "CSSPaintImageValue.h"
    3031#include "CSSPrimitiveValueMappings.h"
     
    8182}
    8283
    83 PropertyCascade::PropertyCascade(const PropertyCascade& parent, CascadeLevel maximumCascadeLevel, CascadeLayerPriority maximumCascadeLayerPriority)
     84PropertyCascade::PropertyCascade(const PropertyCascade& parent, CascadeLevel maximumCascadeLevel, std::optional<CascadeLayerPriority> maximumCascadeLayerPriorityForRollback)
    8485    : m_matchResult(parent.m_matchResult)
    8586    , m_includedProperties(parent.m_includedProperties)
    8687    , m_maximumCascadeLevel(maximumCascadeLevel)
    87     , m_maximumCascadeLayerPriority(maximumCascadeLayerPriority)
     88    , m_maximumCascadeLayerPriorityForRollback(maximumCascadeLayerPriorityForRollback)
    8889    , m_direction(parent.direction())
    8990    , m_directionIsUnresolved(false)
     
    117118    ASSERT(matchedProperties.linkMatchType <= SelectorChecker::MatchAll);
    118119    property.id = id;
    119     property.level = cascadeLevel;
     120    property.cascadeLevel = cascadeLevel;
    120121    property.styleScopeOrdinal = matchedProperties.styleScopeOrdinal;
    121122    property.cascadeLayerPriority = matchedProperties.cascadeLayerPriority;
     123    property.fromStyleAttribute = matchedProperties.fromStyleAttribute;
    122124
    123125    if (matchedProperties.linkMatchType == SelectorChecker::MatchAll) {
     
    178180bool PropertyCascade::addMatch(const MatchedProperties& matchedProperties, CascadeLevel cascadeLevel, bool important)
    179181{
    180     if (matchedProperties.cascadeLayerPriority > m_maximumCascadeLayerPriority && cascadeLevel == m_maximumCascadeLevel && matchedProperties.styleScopeOrdinal == ScopeOrdinal::Element)
     182    auto skipForRollback = [&] {
     183        if (!m_maximumCascadeLayerPriorityForRollback)
     184            return false;
     185        if (matchedProperties.styleScopeOrdinal != ScopeOrdinal::Element)
     186            return false;
     187        if (cascadeLevel < m_maximumCascadeLevel)
     188            return false;
     189        if (matchedProperties.fromStyleAttribute == FromStyleAttribute::Yes)
     190            return true;
     191        return matchedProperties.cascadeLayerPriority > *m_maximumCascadeLayerPriorityForRollback;
     192    };
     193    if (skipForRollback())
    181194        return false;
    182195
  • trunk/Source/WebCore/style/PropertyCascade.h

    r285624 r287018  
    2828#include "CascadeLevel.h"
    2929#include "MatchResult.h"
    30 #include "StyleBuilderState.h"
    3130#include <bitset>
    3231
     
    4847
    4948    PropertyCascade(const MatchResult&, CascadeLevel, IncludedProperties, Direction);
    50     PropertyCascade(const PropertyCascade&, CascadeLevel, CascadeLayerPriority maximumCascadeLayerPriority = RuleSet::cascadeLayerPriorityForUnlayered);
     49    PropertyCascade(const PropertyCascade&, CascadeLevel, std::optional<CascadeLayerPriority> maximumCascadeLayerPriorityForRollback = { });
    5150
    5251    ~PropertyCascade();
     
    5453    struct Property {
    5554        CSSPropertyID id;
    56         CascadeLevel level;
     55        CascadeLevel cascadeLevel;
    5756        ScopeOrdinal styleScopeOrdinal;
    5857        CascadeLayerPriority cascadeLayerPriority;
     58        FromStyleAttribute fromStyleAttribute;
    5959        CSSValue* cssValue[3]; // Values for link match states MatchDefault, MatchLink and MatchVisited
    6060    };
     
    7070
    7171    Direction direction() const;
    72 
    73     auto maximumCascadeLevel() const { return m_maximumCascadeLevel; }
    74     auto maximumCascadeLayerPriority() const { return m_maximumCascadeLayerPriority; }
    7572
    7673private:
     
    8986    const IncludedProperties m_includedProperties;
    9087    const CascadeLevel m_maximumCascadeLevel;
    91     const CascadeLayerPriority m_maximumCascadeLayerPriority { RuleSet::cascadeLayerPriorityForUnlayered };
     88    const std::optional<CascadeLayerPriority> m_maximumCascadeLayerPriorityForRollback;
    9289    mutable Direction m_direction;
    9390    mutable bool m_directionIsUnresolved { true };
  • trunk/Source/WebCore/style/RuleSet.h

    r285622 r287018  
    107107
    108108    static constexpr auto cascadeLayerPriorityForUnlayered = std::numeric_limits<CascadeLayerPriority>::max();
     109
    109110    CascadeLayerPriority cascadeLayerPriorityFor(const RuleData&) const;
    110111
  • trunk/Source/WebCore/style/StyleBuilder.cpp

    r285801 r287018  
    181181    bool inCycle = m_state.m_inProgressPropertiesCustom.contains(name);
    182182
     183    SetForScope levelScope(m_state.m_currentProperty, &property);
     184
    183185    for (auto index : { SelectorChecker::MatchDefault, SelectorChecker::MatchLink, SelectorChecker::MatchVisited }) {
    184186        if (!property.cssValue[index])
     
    234236inline void Builder::applyCascadeProperty(const PropertyCascade::Property& property)
    235237{
    236     m_state.m_cascadeLevel = property.level;
    237     m_state.m_styleScopeOrdinal = property.styleScopeOrdinal;
    238     m_state.m_cascadeLayerPriority = property.cascadeLayerPriority;
     238    SetForScope levelScope(m_state.m_currentProperty, &property);
    239239
    240240    auto applyWithLinkMatch = [&](SelectorChecker::LinkMatchMask linkMatch) {
     
    262262        return;
    263263
    264     SetForScope levelScope(m_state.m_cascadeLevel, property.level);
    265     SetForScope scopeScope(m_state.m_styleScopeOrdinal, property.styleScopeOrdinal);
    266     SetForScope layerScope(m_state.m_cascadeLayerPriority, property.cascadeLayerPriority);
     264    SetForScope levelScope(m_state.m_currentProperty, &property);
    267265
    268266    applyProperty(property.id, *value, linkMatchMask);
     
    303301
    304302    if (isRevert || isRevertLayer) {
    305         auto* rollbackCascade = isRevert
    306             ? ensureRollbackCascadeForRevert(m_state.m_cascadeLevel)
    307             : ensureRollbackCascadeForRevertLayer(m_state.m_cascadeLevel, m_state.m_cascadeLayerPriority);
     303        auto* rollbackCascade = isRevert ? ensureRollbackCascadeForRevert() : ensureRollbackCascadeForRevertLayer();
    308304
    309305        if (rollbackCascade) {
     
    380376}
    381377
    382 const PropertyCascade* Builder::ensureRollbackCascadeForRevert(CascadeLevel rollbackCascadeLevel)
    383 {
     378const PropertyCascade* Builder::ensureRollbackCascadeForRevert()
     379{
     380    auto rollbackCascadeLevel = m_state.m_currentProperty->cascadeLevel;
    384381    if (rollbackCascadeLevel == CascadeLevel::UserAgent)
    385382        return nullptr;
     
    387384    --rollbackCascadeLevel;
    388385
    389     auto key = makeRollbackCascadeKey(rollbackCascadeLevel, RuleSet::cascadeLayerPriorityForUnlayered);
     386    auto key = makeRollbackCascadeKey(rollbackCascadeLevel, 0);
    390387    return m_rollbackCascades.ensure(key, [&] {
    391         return makeUnique<const PropertyCascade>(m_cascade, rollbackCascadeLevel, RuleSet::cascadeLayerPriorityForUnlayered);
     388        return makeUnique<const PropertyCascade>(m_cascade, rollbackCascadeLevel);
    392389    }).iterator->value.get();
    393390}
    394391
    395 const PropertyCascade* Builder::ensureRollbackCascadeForRevertLayer(CascadeLevel cascadeLevel, CascadeLayerPriority rollbackLayerPriority)
    396 {
     392const PropertyCascade* Builder::ensureRollbackCascadeForRevertLayer()
     393{
     394    auto& property = *m_state.m_currentProperty;
     395    auto rollbackLayerPriority = property.cascadeLayerPriority;
    397396    if (!rollbackLayerPriority)
    398397        return nullptr;
    399398
    400     --rollbackLayerPriority;
    401 
    402     auto key = makeRollbackCascadeKey(cascadeLevel, rollbackLayerPriority);
     399    ASSERT(property.fromStyleAttribute == FromStyleAttribute::No || property.cascadeLayerPriority == RuleSet::cascadeLayerPriorityForUnlayered);
     400
     401    // Style attribute reverts to the regular author style.
     402    if (property.fromStyleAttribute == FromStyleAttribute::No)
     403        --rollbackLayerPriority;
     404
     405    auto key = makeRollbackCascadeKey(property.cascadeLevel, rollbackLayerPriority);
    403406    return m_rollbackCascades.ensure(key, [&] {
    404         return makeUnique<const PropertyCascade>(m_cascade, cascadeLevel, rollbackLayerPriority);
     407        return makeUnique<const PropertyCascade>(m_cascade, property.cascadeLevel, rollbackLayerPriority);
    405408    }).iterator->value.get();
    406409}
  • trunk/Source/WebCore/style/StyleBuilder.h

    r285801 r287018  
    6363    RefPtr<CSSValue> resolvedVariableValue(CSSPropertyID, const CSSValue&);
    6464
    65     const PropertyCascade* ensureRollbackCascadeForRevert(CascadeLevel);
    66     const PropertyCascade* ensureRollbackCascadeForRevertLayer(CascadeLevel, CascadeLayerPriority);
     65    const PropertyCascade* ensureRollbackCascadeForRevert();
     66    const PropertyCascade* ensureRollbackCascadeForRevertLayer();
    6767
    6868    using RollbackCascadeKey = std::pair<unsigned, unsigned>;
  • trunk/Source/WebCore/style/StyleBuilderState.h

    r285710 r287018  
    2929#include "CSSToStyleMap.h"
    3030#include "CascadeLevel.h"
     31#include "PropertyCascade.h"
    3132#include "RenderStyle.h"
    3233#include "RuleSet.h"
     
    9091    bool useSVGZoomRules() const;
    9192    bool useSVGZoomRulesForLength() const;
    92     ScopeOrdinal styleScopeOrdinal() const { return m_styleScopeOrdinal; }
     93    ScopeOrdinal styleScopeOrdinal() const { return m_currentProperty->styleScopeOrdinal; }
    9394
    9495    Ref<CSSValue> resolveImageStyles(CSSValue&);
     
    136137    HashSet<String> m_inProgressPropertiesCustom;
    137138
    138     CascadeLevel m_cascadeLevel { CascadeLevel::Author };
    139     ScopeOrdinal m_styleScopeOrdinal { };
    140     CascadeLayerPriority m_cascadeLayerPriority { };
     139    const PropertyCascade::Property* m_currentProperty { nullptr };
    141140    SelectorChecker::LinkMatchMask m_linkMatch { };
    142141
Note: See TracChangeset for help on using the changeset viewer.