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

Changeset 292181 in webkit


Ignore:
Timestamp:
Mar 31, 2022, 2:50:47 PM (5 years ago)
Author:
Patrick Angle
Message:

Web Inspector: Support Container Queries in the Styles sidebar
​https://bugs.webkit.org/show_bug.cgi?id=238346

Reviewed by Devin Rousso.

Source/JavaScriptCore:

Add new container-rule type for CSS::Grouping::Type.

  • inspector/protocol/CSS.json:

Source/WebCore:

Test: inspector/css/getMatchedStylesForNodeContainerGrouping.html

Add basic support to Web Inspector for viewing styles in @container rules.

  • css/CSSContainerRule.cpp:

(WebCore::CSSContainerRule::nameFilterText const):

  • css/CSSContainerRule.h:
  • Provide a way to get the name that is used to filter the rule to specific containers.
  • inspector/InspectorStyleSheet.cpp:

(flattenSourceData):

  • In order to prevent future rule types from being added without some consideration for how they are inspected,

use an exhaustive switch-case statement here. This will at minimum allow us to make sure we have opened a bug
and put a FIXME here for new values in the future.

(WebCore::asCSSRuleList):
(WebCore::buildArrayForGroupings):

  • style/InspectorCSSOMWrappers.cpp:

(WebCore::Style::InspectorCSSOMWrappers::collect):

Source/WebInspectorUI:

  • UserInterface/Models/CSSGrouping.js:

(WI.CSSGrouping.prototype.get isContainer):
(WI.CSSGrouping.prototype.get prefix):
(WI.CSSGrouping):

LayoutTests:

  • inspector/css/getMatchedStylesForNodeContainerGrouping-expected.txt: Added.
  • inspector/css/getMatchedStylesForNodeContainerGrouping.html: Added.
Location:
trunk
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r292180 r292181  
     12022-03-31  Patrick Angle  <pangle@apple.com>
     2
     3        Web Inspector: Support Container Queries in the Styles sidebar
     4        https://bugs.webkit.org/show_bug.cgi?id=238346
     5
     6        Reviewed by Devin Rousso.
     7
     8        * inspector/css/getMatchedStylesForNodeContainerGrouping-expected.txt: Added.
     9        * inspector/css/getMatchedStylesForNodeContainerGrouping.html: Added.
     10
    1112022-03-31  Robert Jenner  <Jenner@apple.com>
    212
  • trunk/Source/JavaScriptCore/ChangeLog

    r292118 r292181  
     12022-03-31  Patrick Angle  <pangle@apple.com>
     2
     3        Web Inspector: Support Container Queries in the Styles sidebar
     4        https://bugs.webkit.org/show_bug.cgi?id=238346
     5
     6        Reviewed by Devin Rousso.
     7
     8        Add new `container-rule` type for `CSS::Grouping::Type`.
     9
     10        * inspector/protocol/CSS.json:
     11
    1122022-03-30  Chris Dumez  <cdumez@apple.com>
    213
  • trunk/Source/JavaScriptCore/inspector/protocol/CSS.json

    r288492 r292181  
    229229            "description": "CSS @media (as well as other users of media queries, like @import, <style>, <link>, etc.), @supports, and @layer descriptor.",
    230230            "properties": [
    231                 { "name": "type", "type": "string", "enum": ["media-rule", "media-import-rule", "media-link-node", "media-style-node", "supports-rule", "layer-rule", "layer-import-rule"], "description": "Source of the media query: \"media-rule\" if specified by a @media rule, \"media-import-rule\" if specified by an @import rule, \"media-link-node\" if specified by a \"media\" attribute in a linked style sheet's LINK tag, \"media-style-node\" if specified by a \"media\" attribute in an inline style sheet's STYLE tag, \"supports-rule\" if specified by an @supports rule, \"layer-rule\" if specified by an @layer rule." },
    232                 { "name": "text", "type": "string", "optional": true, "description": "Query text if specified by a @media or @supports rule. Layer name (or not present for anonymous layers) for @layer rules." },
     231                { "name": "type", "type": "string", "enum": ["media-rule", "media-import-rule", "media-link-node", "media-style-node", "supports-rule", "layer-rule", "layer-import-rule", "container-rule"], "description": "Source of the media query: \"media-rule\" if specified by a @media rule, \"media-import-rule\" if specified by an @import rule, \"media-link-node\" if specified by a \"media\" attribute in a linked style sheet's LINK tag, \"media-style-node\" if specified by a \"media\" attribute in an inline style sheet's STYLE tag, \"supports-rule\" if specified by an @supports rule, \"layer-rule\" if specified by an @layer rule, \"container-rule\" if specified by an @container rule." },
     232                { "name": "text", "type": "string", "optional": true, "description": "Query text if specified by a @media, @supports, or @container rule. Layer name (or not present for anonymous layers) for @layer rules." },
    233233                { "name": "sourceURL", "type": "string", "optional": true, "description": "URL of the document containing the CSS grouping." }
    234234            ]
  • trunk/Source/WebCore/ChangeLog

    r292160 r292181  
     12022-03-31  Patrick Angle  <pangle@apple.com>
     2
     3        Web Inspector: Support Container Queries in the Styles sidebar
     4        https://bugs.webkit.org/show_bug.cgi?id=238346
     5
     6        Reviewed by Devin Rousso.
     7
     8        Test: inspector/css/getMatchedStylesForNodeContainerGrouping.html
     9
     10        Add basic support to Web Inspector for viewing styles in `@container` rules.
     11
     12        * css/CSSContainerRule.cpp:
     13        (WebCore::CSSContainerRule::nameFilterText const):
     14        * css/CSSContainerRule.h:
     15        - Provide a way to get the name that is used to filter the rule to specific containers.
     16
     17        * inspector/InspectorStyleSheet.cpp:
     18        (flattenSourceData):
     19        - In order to prevent future rule types from being added without some consideration for how they are inspected,
     20        use an exhaustive switch-case statement here. This will at minimum allow us to make sure we have opened a bug
     21        and put a FIXME here for new values in the future.
     22
     23        (WebCore::asCSSRuleList):
     24        (WebCore::buildArrayForGroupings):
     25       
     26        * style/InspectorCSSOMWrappers.cpp:
     27        (WebCore::Style::InspectorCSSOMWrappers::collect):
     28
    1292022-03-31  Diego Pino Garcia  <dpino@igalia.com>
    230
  • trunk/Source/WebCore/css/CSSContainerRule.cpp

    r292045 r292181  
    7777}
    7878
     79String CSSContainerRule::nameFilterText() const
     80{
     81    StringBuilder builder;
     82   
     83    auto name = styleRuleContainer().filteredQuery().nameFilter;
     84    if (!name.isEmpty())
     85        serializeIdentifier(name, builder);
     86
     87    return builder.toString();
     88}
     89
    7990} // namespace WebCore
    8091
  • trunk/Source/WebCore/css/CSSContainerRule.h

    r292045 r292181  
    3838    String cssText() const final;
    3939    String conditionText() const final;
     40    String nameFilterText() const;
    4041
    4142private:
  • trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp

    r291992 r292181  
    2727#include "InspectorStyleSheet.h"
    2828
     29#include "CSSContainerRule.h"
    2930#include "CSSImportRule.h"
    3031#include "CSSKeyframesRule.h"
    … …  
    107108{
    108109    for (auto& data : dataList) {
    109         if (data->type == WebCore::StyleRuleType::Style)
     110        switch (data->type) {
     111        case WebCore::StyleRuleType::Style:
    110112            target.append(data.copyRef());
    111         else if (data->type == WebCore::StyleRuleType::Media || data->type == WebCore::StyleRuleType::Supports || data->type == WebCore::StyleRuleType::LayerBlock)
     113            break;
     114
     115        case WebCore::StyleRuleType::Media:
     116        case WebCore::StyleRuleType::Supports:
     117        case WebCore::StyleRuleType::LayerBlock:
     118        case WebCore::StyleRuleType::Container:
    112119            flattenSourceData(data->childRules, target);
     120            break;
     121
     122        case WebCore::StyleRuleType::Unknown:
     123        case WebCore::StyleRuleType::Charset:
     124        case WebCore::StyleRuleType::Import:
     125        case WebCore::StyleRuleType::FontFace:
     126        case WebCore::StyleRuleType::Page:
     127        case WebCore::StyleRuleType::Keyframes:
     128        case WebCore::StyleRuleType::Keyframe:
     129        case WebCore::StyleRuleType::Margin:
     130        case WebCore::StyleRuleType::Namespace:
     131        case WebCore::StyleRuleType::CounterStyle:
     132        case WebCore::StyleRuleType::LayerStatement:
     133        case WebCore::StyleRuleType::FontPaletteValues:
     134            // These rule types do not contain child rules, and therefore have nothing to display in the Styles panel in
     135            // the details sidebar of the Elements Tab in Web Inspector.
     136            break;
     137        }
    113138    }
    114139}
    … …  
    431456        return &downcast<CSSLayerBlockRule>(*rule).cssRules();
    432457
     458    if (auto* containerRule = dynamicDowncast<CSSContainerRule>(rule))
     459        return &containerRule->cssRules();
     460
    433461    return nullptr;
    434462}
    … …  
    483511                layerRulePayload->setText(layerName);
    484512            ruleGroupingPayloads.append(WTFMove(layerRulePayload));
     513        } else if (auto* containerRule = dynamicDowncast<CSSContainerRule>(parentRule)) {
     514            auto containerRulePayload = Protocol::CSS::Grouping::create()
     515                .setType(Protocol::CSS::Grouping::Type::ContainerRule)
     516                .release();
     517
     518            StringBuilder builder;
     519            auto nameFilter = containerRule->nameFilterText();
     520            if (!nameFilter.isEmpty())
     521                builder.append(nameFilter, ' ');
     522            builder.append(containerRule->conditionText());
     523            containerRulePayload->setText(builder.toString());
     524
     525            ruleGroupingPayloads.append(WTFMove(containerRulePayload));
    485526        }
    486527
  • trunk/Source/WebCore/style/InspectorCSSOMWrappers.cpp

    r291824 r292181  
    3030#include "InspectorCSSOMWrappers.h"
    3131
     32#include "CSSContainerRule.h"
    3233#include "CSSImportRule.h"
    3334#include "CSSLayerBlockRule.h"
    … …  
    6465       
    6566        switch (cssRule->styleRuleType()) {
     67        case StyleRuleType::Container:
     68            collect(downcast<CSSContainerRule>(cssRule));
     69            break;
    6670        case StyleRuleType::Import:
    6771            collect(downcast<CSSImportRule>(*cssRule).styleSheet());
  • trunk/Source/WebInspectorUI/ChangeLog

    r292172 r292181  
     12022-03-31  Patrick Angle  <pangle@apple.com>
     2
     3        Web Inspector: Support Container Queries in the Styles sidebar
     4        https://bugs.webkit.org/show_bug.cgi?id=238346
     5
     6        Reviewed by Devin Rousso.
     7
     8        * UserInterface/Models/CSSGrouping.js:
     9        (WI.CSSGrouping.prototype.get isContainer):
     10        (WI.CSSGrouping.prototype.get prefix):
     11        (WI.CSSGrouping):
     12
    1132022-03-31  Devin Rousso  <drousso@apple.com>
    214
  • trunk/Source/WebInspectorUI/UserInterface/Models/CSSGrouping.js

    r286558 r292181  
    6262    }
    6363
     64    get isContainer()
     65    {
     66        return this._type === WI.CSSGrouping.Type.ContainerRule;
     67    }
     68
    6469    get prefix()
    6570    {
    … …  
    6974        if (this.isLayer)
    7075            return "@layer";
     76
     77        if (this.isContainer)
     78            return "@container";
    7179
    7280        console.assert(this.isMedia);
    … …  
    8391    LayerRule: "layer-rule",
    8492    LayerImportRule: "layer-import-rule",
     93    ContainerRule: "container-rule",
    8594};
Note: See TracChangeset for help on using the changeset viewer.