Changeset 292819 in webkit


Ignore:
Timestamp:
Apr 13, 2022 12:12:47 PM (3 months ago)
Author:
Antti Koivisto
Message:

[CSS Container Queries] Correct container selection for pseudo-elements
https://bugs.webkit.org/show_bug.cgi?id=239279

Reviewed by Simon Fraser.

Source/WebCore:

The element itself may be the container for its pseudo-elements.

  • css/CSSPrimitiveValue.cpp:

(WebCore::CSSPrimitiveValue::computeNonCalcLengthDouble):

  • style/ContainerQueryEvaluator.cpp:

(WebCore::Style::ContainerQueryEvaluator::ContainerQueryEvaluator):
(WebCore::Style::ContainerQueryEvaluator::selectContainer const):
(WebCore::Style::ContainerQueryEvaluator::selectContainer):

  • style/ContainerQueryEvaluator.h:

Instead of passing the pseudo-element being matched, pass a container selection mode flag. The exact pseudo-element type
doesn't matter.

  • style/ElementRuleCollector.cpp:

(WebCore::Style::ElementRuleCollector::containerQueriesMatch):

We need to use the pseudo-element mode when matching a rule that matches a pseudo-element, even when we are not actually resolving
the pseudo element. This is because regular element rule matching sets the style bits that indicate what pseudo-elements the
element has.

LayoutTests:

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r292817 r292819  
     12022-04-13  Antti Koivisto  <antti@apple.com>
     2
     3        [CSS Container Queries] Correct container selection for pseudo-elements
     4        https://bugs.webkit.org/show_bug.cgi?id=239279
     5
     6        Reviewed by Simon Fraser.
     7
     8        * TestExpectations:
     9
    1102022-04-13  Alan Bujtas  <zalan@apple.com>
    211
  • trunk/LayoutTests/TestExpectations

    r292720 r292819  
    47024702# Container queries
    47034703webkit.org/b/229659 imported/w3c/web-platform-tests/css/css-contain/container-queries/custom-layout-container-001.https.html [ ImageOnlyFailure ]
    4704 webkit.org/b/229659 imported/w3c/web-platform-tests/css/css-contain/container-queries/pseudo-elements-002.html [ ImageOnlyFailure ]
    47054704webkit.org/b/229659 imported/w3c/web-platform-tests/css/css-contain/container-queries/svg-foreignobject-no-size-container.html [ Skip ]
    47064705webkit.org/b/229659 imported/w3c/web-platform-tests/css/css-contain/container-queries/inline-size-bfc-floats.html [ ImageOnlyFailure ]
  • trunk/Source/WebCore/ChangeLog

    r292817 r292819  
     12022-04-13  Antti Koivisto  <antti@apple.com>
     2
     3        [CSS Container Queries] Correct container selection for pseudo-elements
     4        https://bugs.webkit.org/show_bug.cgi?id=239279
     5
     6        Reviewed by Simon Fraser.
     7
     8        The element itself may be the container for its pseudo-elements.
     9
     10        * css/CSSPrimitiveValue.cpp:
     11        (WebCore::CSSPrimitiveValue::computeNonCalcLengthDouble):
     12        * style/ContainerQueryEvaluator.cpp:
     13        (WebCore::Style::ContainerQueryEvaluator::ContainerQueryEvaluator):
     14        (WebCore::Style::ContainerQueryEvaluator::selectContainer const):
     15        (WebCore::Style::ContainerQueryEvaluator::selectContainer):
     16        * style/ContainerQueryEvaluator.h:
     17
     18        Instead of passing the pseudo-element being matched, pass a container selection mode flag. The exact pseudo-element type
     19        doesn't matter.
     20
     21        * style/ElementRuleCollector.cpp:
     22        (WebCore::Style::ElementRuleCollector::containerQueriesMatch):
     23
     24        We need to use the pseudo-element mode when matching a rule that matches a pseudo-element, even when we are not actually resolving
     25        the pseudo element. This is because regular element rule matching sets the style bits that indicate what pseudo-elements the
     26        element has.
     27
    1282022-04-13  Alan Bujtas  <zalan@apple.com>
    229
  • trunk/Source/WebCore/css/CSSPrimitiveValue.cpp

    r291863 r292819  
    827827            return nullptr;
    828828        // FIXME: Use cached query containers when available.
    829         auto* container = Style::ContainerQueryEvaluator::selectContainer(axis, nullString(), *conversionData.element(), nullptr);
     829        auto* container = Style::ContainerQueryEvaluator::selectContainer(axis, nullString(), *conversionData.element());
    830830        if (!container)
    831831            return nullptr;
  • trunk/Source/WebCore/style/ContainerQueryEvaluator.cpp

    r292635 r292819  
    4545};
    4646
    47 ContainerQueryEvaluator::ContainerQueryEvaluator(const Element& element, PseudoId pseudoId, ScopeOrdinal scopeOrdinal, SelectorMatchingState* selectorMatchingState)
     47ContainerQueryEvaluator::ContainerQueryEvaluator(const Element& element, SelectionMode selectionMode, ScopeOrdinal scopeOrdinal, SelectorMatchingState* selectorMatchingState)
    4848    : m_element(element)
    49     , m_pseudoId(pseudoId)
     49    , m_selectionMode(selectionMode)
    5050    , m_scopeOrdinal(scopeOrdinal)
    5151    , m_selectorMatchingState(selectorMatchingState)
     
    8383    auto* cachedQueryContainers = m_selectorMatchingState ? &m_selectorMatchingState->queryContainers : nullptr;
    8484
    85     auto* container = selectContainer(filteredContainerQuery.axisFilter, filteredContainerQuery.nameFilter, m_element.get(), cachedQueryContainers, m_pseudoId, m_scopeOrdinal);
     85    auto* container = selectContainer(filteredContainerQuery.axisFilter, filteredContainerQuery.nameFilter, m_element.get(), m_selectionMode, m_scopeOrdinal, cachedQueryContainers);
    8686    if (!container)
    8787        return { };
     
    9090}
    9191
    92 const Element* ContainerQueryEvaluator::selectContainer(OptionSet<CQ::Axis> axes, const String& name, const Element& element, const CachedQueryContainers* cachedQueryContainers, PseudoId pseudoId, ScopeOrdinal scopeOrdinal)
     92const Element* ContainerQueryEvaluator::selectContainer(OptionSet<CQ::Axis> axes, const String& name, const Element& element, SelectionMode selectionMode, ScopeOrdinal scopeOrdinal, const CachedQueryContainers* cachedQueryContainers)
    9393{
    9494    // "For each element, the query container to be queried is selected from among the element’s
     
    145145    }
    146146
     147    if (selectionMode == SelectionMode::PseudoElement) {
     148        if (isContainerForQuery(element))
     149            return &element;
     150    }
     151
    147152    if (cachedQueryContainers) {
    148153        for (auto& container : makeReversedRange(*cachedQueryContainers)) {
     
    151156        }
    152157        return { };
    153     }
    154 
    155     if (pseudoId != PseudoId::None) {
    156         if (isContainerForQuery(element))
    157             return &element;
    158158    }
    159159
  • trunk/Source/WebCore/style/ContainerQueryEvaluator.h

    r292635 r292819  
    4040class ContainerQueryEvaluator {
    4141public:
    42     ContainerQueryEvaluator(const Element&, PseudoId, ScopeOrdinal, SelectorMatchingState*);
     42    enum class SelectionMode : bool { Element, PseudoElement };
     43    ContainerQueryEvaluator(const Element&, SelectionMode, ScopeOrdinal, SelectorMatchingState*);
    4344
    4445    bool evaluate(const FilteredContainerQuery&) const;
    4546
    46     static const Element* selectContainer(OptionSet<CQ::Axis>, const String& name, const Element&, const CachedQueryContainers*, PseudoId = PseudoId::None, ScopeOrdinal = ScopeOrdinal::Element);
     47    static const Element* selectContainer(OptionSet<CQ::Axis>, const String& name, const Element&, SelectionMode = SelectionMode::Element, ScopeOrdinal = ScopeOrdinal::Element, const CachedQueryContainers* = nullptr);
    4748
    4849private:
     
    5556
    5657    const Ref<const Element> m_element;
    57     const PseudoId m_pseudoId;
    58     ScopeOrdinal m_scopeOrdinal;
     58    const SelectionMode m_selectionMode;
     59    const ScopeOrdinal m_scopeOrdinal;
    5960    SelectorMatchingState* m_selectorMatchingState;
    6061};
  • trunk/Source/WebCore/style/ElementRuleCollector.cpp

    r292635 r292819  
    513513        return true;
    514514
     515    // Style bits indicating which pseudo-elements match are set during regular element matching. Container queries need to be evaluate in the right mode.
     516    auto selectionMode = ruleData.canMatchPseudoElement() ? ContainerQueryEvaluator::SelectionMode::PseudoElement : ContainerQueryEvaluator::SelectionMode::Element;
     517
    515518    // "Style rules defined on an element inside multiple nested container queries apply when all of the wrapping container queries are true for that element."
    516     ContainerQueryEvaluator evaluator(element(), m_pseudoElementRequest.pseudoId, matchRequest.styleScopeOrdinal, m_selectorMatchingState);
     519    ContainerQueryEvaluator evaluator(element(), selectionMode, matchRequest.styleScopeOrdinal, m_selectorMatchingState);
    517520    for (auto* query : queries) {
    518521        if (!evaluator.evaluate(*query))
Note: See TracChangeset for help on using the changeset viewer.