Title: [282927] branches/safari-612-branch
Revision
282927
Author
repst...@apple.com
Date
2021-09-22 22:13:27 -0700 (Wed, 22 Sep 2021)

Log Message

Cherry-pick r281354. rdar://problem/83429677

    Web Inspector: Style rules declared after a rule whose selector has over 8192 components are not shown correctly
    https://bugs.webkit.org/show_bug.cgi?id=229218

    Reviewed by Devin Rousso.

    Source/WebCore:

    Test: inspector/css/getMatchedStylesForNodeLargeSelectors.html

    CSS rules are limited to 8192 selector components in WebCore, and when more components are present the rule is
    split into multiple `StyleRule` instances. This meant Web Inspector could not reliably resolve a `StyleRule`
    back to its source data, which we do to enable things like editing, as well as to make sure we show the un-split
    selector in the Styles sidebar of the Elements tab. Previously, the presences of multiple `StyleRule`s for a
    single source data declaration was not accounted for, which meant that rules after the split rules would show a
    mix of style information from the actual rule as well as a rule some number of declarations later in the same
    style sheet. This is resolved by marking `StyleRule`s that have been split and marking the last of the split
    rules. This allows us to then forgo incrementing the index for looking up raw declarations until we encounter
    the last rule from a split `StyleRule`.

     * css/StyleRule.cpp:
    (WebCore::StyleRule::StyleRule):
    (WebCore::StyleRule::createForSplitting):
    (WebCore::StyleRule::splitIntoMultipleRulesWithMaximumSelectorComponentCount const):

    * css/StyleRule.h:
    - Added two members to track rules that are split into multiple rules due to exceeding the 8192 component limit
    for selectors in order to determine later which rules are effectively duplicates of each other. We use two
    members here, one to track that the rule was split from a larger authored rule (`m_isSplitRule`), and one to
    mark the last rule split from a given rule (`m_isLastRuleInSplitRule`). The second member prevents situations
    where we might otherwise accidentally continue iterating into a list of `StyleRule` where two large authored
    rules that had to be split are present next to each other in an ordered collection of `StyleRule`.

    * inspector/InspectorStyleSheet.cpp:
    (WebCore::selectorsFromSource):
    - Use a vector of `CSSSelector`s for specificity information since we now collect selectors from potentially
    multiple `CSSStyleRule`s.

    (WebCore::InspectorStyleSheet::cssStyleRulesSplitFromSameRule):
    - Find any neighboring CSSStyleRules that were split from the same original rule based on the order of rules as
    well as the new flags in `StyleRule`

    (WebCore::InspectorStyleSheet::selectorsForCSSStyleRule):
    - Find all selectors for a given CSSStyleRule, including other `CSSStyleRule`s split from the same rule in a
    style sheet.

    (WebCore::InspectorStyleSheet::buildObjectForSelectorList):
    - Use all CSSSelectors from for the CSSStyleRule and other rules that were split from the same rule in a style
    sheet.

    (WebCore::InspectorStyleSheet::ruleSourceDataFor const):
    (WebCore::InspectorStyleSheet::ruleIndexByStyle const):
    - When looking up an index to get rule source data, make sure we don't overcount split rules.

    * inspector/InspectorStyleSheet.h:

    LayoutTests:

    Test very large (8192 individual component) selectors to ensure surrounding styles are correctly resolved.

    * inspector/css/getMatchedStylesForNodeLargeSelectors-expected.txt: Added.
    * inspector/css/getMatchedStylesForNodeLargeSelectors.html: Added.

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@281354 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Added Paths

Diff

Modified: branches/safari-612-branch/LayoutTests/ChangeLog (282926 => 282927)


--- branches/safari-612-branch/LayoutTests/ChangeLog	2021-09-23 05:13:21 UTC (rev 282926)
+++ branches/safari-612-branch/LayoutTests/ChangeLog	2021-09-23 05:13:27 UTC (rev 282927)
@@ -1,5 +1,86 @@
 2021-09-22  Alan Coon  <alanc...@apple.com>
 
+        Cherry-pick r281354. rdar://problem/83429677
+
+    Web Inspector: Style rules declared after a rule whose selector has over 8192 components are not shown correctly
+    https://bugs.webkit.org/show_bug.cgi?id=229218
+    
+    Reviewed by Devin Rousso.
+    
+    Source/WebCore:
+    
+    Test: inspector/css/getMatchedStylesForNodeLargeSelectors.html
+    
+    CSS rules are limited to 8192 selector components in WebCore, and when more components are present the rule is
+    split into multiple `StyleRule` instances. This meant Web Inspector could not reliably resolve a `StyleRule`
+    back to its source data, which we do to enable things like editing, as well as to make sure we show the un-split
+    selector in the Styles sidebar of the Elements tab. Previously, the presences of multiple `StyleRule`s for a
+    single source data declaration was not accounted for, which meant that rules after the split rules would show a
+    mix of style information from the actual rule as well as a rule some number of declarations later in the same
+    style sheet. This is resolved by marking `StyleRule`s that have been split and marking the last of the split
+    rules. This allows us to then forgo incrementing the index for looking up raw declarations until we encounter
+    the last rule from a split `StyleRule`.
+    
+     * css/StyleRule.cpp:
+    (WebCore::StyleRule::StyleRule):
+    (WebCore::StyleRule::createForSplitting):
+    (WebCore::StyleRule::splitIntoMultipleRulesWithMaximumSelectorComponentCount const):
+    
+    * css/StyleRule.h:
+    - Added two members to track rules that are split into multiple rules due to exceeding the 8192 component limit
+    for selectors in order to determine later which rules are effectively duplicates of each other. We use two
+    members here, one to track that the rule was split from a larger authored rule (`m_isSplitRule`), and one to
+    mark the last rule split from a given rule (`m_isLastRuleInSplitRule`). The second member prevents situations
+    where we might otherwise accidentally continue iterating into a list of `StyleRule` where two large authored
+    rules that had to be split are present next to each other in an ordered collection of `StyleRule`.
+    
+    * inspector/InspectorStyleSheet.cpp:
+    (WebCore::selectorsFromSource):
+    - Use a vector of `CSSSelector`s for specificity information since we now collect selectors from potentially
+    multiple `CSSStyleRule`s.
+    
+    (WebCore::InspectorStyleSheet::cssStyleRulesSplitFromSameRule):
+    - Find any neighboring CSSStyleRules that were split from the same original rule based on the order of rules as
+    well as the new flags in `StyleRule`
+    
+    (WebCore::InspectorStyleSheet::selectorsForCSSStyleRule):
+    - Find all selectors for a given CSSStyleRule, including other `CSSStyleRule`s split from the same rule in a
+    style sheet.
+    
+    (WebCore::InspectorStyleSheet::buildObjectForSelectorList):
+    - Use all CSSSelectors from for the CSSStyleRule and other rules that were split from the same rule in a style
+    sheet.
+    
+    (WebCore::InspectorStyleSheet::ruleSourceDataFor const):
+    (WebCore::InspectorStyleSheet::ruleIndexByStyle const):
+    - When looking up an index to get rule source data, make sure we don't overcount split rules.
+    
+    * inspector/InspectorStyleSheet.h:
+    
+    LayoutTests:
+    
+    Test very large (8192 individual component) selectors to ensure surrounding styles are correctly resolved.
+    
+    * inspector/css/getMatchedStylesForNodeLargeSelectors-expected.txt: Added.
+    * inspector/css/getMatchedStylesForNodeLargeSelectors.html: Added.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@281354 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-08-20  Patrick Angle  <pan...@apple.com>
+
+            Web Inspector: Style rules declared after a rule whose selector has over 8192 components are not shown correctly
+            https://bugs.webkit.org/show_bug.cgi?id=229218
+
+            Reviewed by Devin Rousso.
+
+            Test very large (8192 individual component) selectors to ensure surrounding styles are correctly resolved.
+
+            * inspector/css/getMatchedStylesForNodeLargeSelectors-expected.txt: Added.
+            * inspector/css/getMatchedStylesForNodeLargeSelectors.html: Added.
+
+2021-09-22  Alan Coon  <alanc...@apple.com>
+
         Cherry-pick r281323. rdar://problem/83430037
 
     Release assert in ScriptController::canExecuteScripts via WebCore::WebSocket::didReceiveMessage

Added: branches/safari-612-branch/LayoutTests/inspector/css/getMatchedStylesForNodeLargeSelectors-expected.txt (0 => 282927)


--- branches/safari-612-branch/LayoutTests/inspector/css/getMatchedStylesForNodeLargeSelectors-expected.txt	                        (rev 0)
+++ branches/safari-612-branch/LayoutTests/inspector/css/getMatchedStylesForNodeLargeSelectors-expected.txt	2021-09-23 05:13:27 UTC (rev 282927)
@@ -0,0 +1,34 @@
+Tests for the CSS.getMatchedStylesForNode command and very large selectors.
+
+
+== Running test suite: CSS.getMatchedStylesForNode.LargeSelectors
+-- Running test case: CSS.getMatchedStylesForNode.LargeSelectors.StylePreceedingLargeSelector
+PASS: Should have one matching authored rule.
+PASS: Should have `1` parsed selector.
+PASS: First parsed selector should be `#test1`.
+PASS: Raw selector should be `#test1`.
+PASS: Rule should have a source code line number of `97`.
+PASS: Should have one CSS property.
+PASS: Parsed property and raw style text should be the same.
+PASS: Property value should be `rebeccapurple`.
+
+-- Running test case: CSS.getMatchedStylesForNode.LargeSelectors.StyleWithLargeSelector
+PASS: Should have one matching authored rule.
+PASS: Should have `165` parsed selectors.
+PASS: First parsed selector should be `#test2`.
+PASS: Raw selector should start with `#test2`.
+PASS: Rule should have a source code line number of `101`.
+PASS: Should have one CSS property.
+PASS: Parsed property and raw style text should be the same.
+PASS: Property value should be `aliceblue`.
+
+-- Running test case: CSS.getMatchedStylesForNode.LargeSelectors.StyleFollowingLargeSelector
+PASS: Should have one matching authored rule.
+PASS: Should have `1` parsed selector.
+PASS: First parsed selector should be `#test3`.
+PASS: Raw selector should be `#test3`.
+PASS: Rule should have a source code line number of `437`.
+PASS: Should have one CSS property.
+PASS: Parsed property and raw style text should be the same.
+PASS: Property value should be `papayawhip`.
+

Added: branches/safari-612-branch/LayoutTests/inspector/css/getMatchedStylesForNodeLargeSelectors.html (0 => 282927)


--- branches/safari-612-branch/LayoutTests/inspector/css/getMatchedStylesForNodeLargeSelectors.html	                        (rev 0)
+++ branches/safari-612-branch/LayoutTests/inspector/css/getMatchedStylesForNodeLargeSelectors.html	2021-09-23 05:13:27 UTC (rev 282927)
@@ -0,0 +1,449 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script>
+function test()
+{
+    let suite = InspectorTest.createAsyncSuite("CSS.getMatchedStylesForNode.LargeSelectors");
+
+    function addTestCase({name, description, selector, authoredRuleHandler})
+    {
+        suite.addTestCase({
+            name,
+            description,
+            async test() {
+                let documentNode = await WI.domManager.requestDocument();
+                let nodeId = await documentNode.querySelector(selector);
+                let domNode = WI.domManager.nodeForId(nodeId);
+                InspectorTest.assert(domNode, `Should find DOM Node for selector '${selector}'.`);
+
+                let domNodeStyles = WI.cssManager.stylesForNode(domNode);
+                InspectorTest.assert(domNodeStyles, `Should find CSS Styles for DOM Node.`);
+                await domNodeStyles.refreshIfNeeded();
+
+                let authoredRules = domNodeStyles.matchedRules.filter((rule) => rule.type === WI.CSSStyleSheet.Type.Author);
+                InspectorTest.expectEqual(authoredRules.length, 1, "Should have one matching authored rule.");
+
+                let authoredRule = authoredRules[0];
+
+                await authoredRuleHandler(authoredRule);
+            },
+        });
+    }
+
+    addTestCase({
+        name: "CSS.getMatchedStylesForNode.LargeSelectors.StylePreceedingLargeSelector",
+        description: "Ensure that for rules declared before a large selector that both the parsed and raw selector and style properties are in agreement.",
+        selector: "#test1",
+        async authoredRuleHandler(rule) {
+            InspectorTest.expectEqual(rule.selectors.length, 1, "Should have `1` parsed selector.");
+            InspectorTest.expectEqual(rule.selectors[0].text, "#test1", "First parsed selector should be `#test1`.");
+            InspectorTest.expectEqual(rule.selectorText, "#test1", "Raw selector should be `#test1`.");
+
+            InspectorTest.expectEqual(rule.sourceCodeLocation?.lineNumber, 97, "Rule should have a source code line number of `97`.");
+
+            InspectorTest.expectEqual(rule.style.properties.length, 1, "Should have one CSS property.");
+            let property = rule.style.properties[0];
+
+            InspectorTest.expectEqual(property.text.trim(), rule.style.text.trim(), "Parsed property and raw style text should be the same.");
+            InspectorTest.expectEqual(property.value, "rebeccapurple", "Property value should be `rebeccapurple`.");
+        }
+    });
+
+    addTestCase({
+        name: "CSS.getMatchedStylesForNode.LargeSelectors.StyleWithLargeSelector",
+        description: "Ensure that for rules with a large selector that both the parsed and raw selector and style properties are in agreement.",
+        selector: "#test2",
+        async authoredRuleHandler(rule) {
+            InspectorTest.expectEqual(rule.selectors.length, 165, "Should have `165` parsed selectors.");
+            InspectorTest.expectEqual(rule.selectors[0].text, "#test2", "First parsed selector should be `#test2`.");
+            for (let i = 1; i < rule.selectors.length; ++i)
+                InspectorTest.assert(rule.selectors[i].text === `a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y`);
+            InspectorTest.expectTrue(rule.selectorText.startsWith("#test2,"), "Raw selector should start with `#test2`.");
+
+            InspectorTest.expectEqual(rule.sourceCodeLocation?.lineNumber, 101, "Rule should have a source code line number of `101`.");
+
+            InspectorTest.expectEqual(rule.style.properties.length, 1, "Should have one CSS property.");
+            let property = rule.style.properties[0];
+
+            InspectorTest.expectEqual(property.text.trim(), rule.style.text.trim(), "Parsed property and raw style text should be the same.");
+            InspectorTest.expectEqual(property.value, "aliceblue", "Property value should be `aliceblue`.");
+        }
+    });
+
+    addTestCase({
+        name: "CSS.getMatchedStylesForNode.LargeSelectors.StyleFollowingLargeSelector",
+        description: "Ensure that for rules declared after a large selector that both the parsed and raw selector and style properties are in agreement.",
+        selector: "#test3",
+        async authoredRuleHandler(rule) {
+            InspectorTest.expectEqual(rule.selectors.length, 1, "Should have `1` parsed selector.");
+            InspectorTest.expectEqual(rule.selectors[0].text, "#test3", "First parsed selector should be `#test3`.");
+            InspectorTest.expectEqual(rule.selectorText, "#test3", "Raw selector should be `#test3`.");
+
+            InspectorTest.expectEqual(rule.sourceCodeLocation?.lineNumber, 437, "Rule should have a source code line number of `437`.");
+
+            InspectorTest.expectEqual(rule.style.properties.length, 1, "Should have one CSS property.");
+            let property = rule.style.properties[0];
+
+            InspectorTest.expectEqual(property.text.trim(), rule.style.text.trim(), "Parsed property and raw style text should be the same.");
+            InspectorTest.expectEqual(property.value, "papayawhip", "Property value should be `papayawhip`.");
+        }
+    });
+
+    suite.runTestCasesAndFinish();
+}
+</script>
+<style>
+    #test1 {
+        background-color: rebeccapurple;
+    }
+
+    #test2,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y,
+    a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y {
+        background-color: aliceblue;
+    }
+
+    /* Test that two rules with large selectors don't run together into a single set of parsed selectors for the first rule. */
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B,
+    z y x w v u t s r q p o n m l k j i h g f e d c b Z Y X W V U T S R Q P O N M L K J I H G F E D C B {
+        /* This rule intentionally left blank. */
+    }
+
+    #test3 {
+        background-color: papayawhip;
+    }
+</style>
+</head>
+<body _onload_="runTest()">
+    <p>Tests for the CSS.getMatchedStylesForNode command and very large selectors.</p>
+    <div id="test1"></div>
+    <div id="test2"></div>
+    <div id="test3"></div>
+</body>
+</html>

Modified: branches/safari-612-branch/Source/WebCore/ChangeLog (282926 => 282927)


--- branches/safari-612-branch/Source/WebCore/ChangeLog	2021-09-23 05:13:21 UTC (rev 282926)
+++ branches/safari-612-branch/Source/WebCore/ChangeLog	2021-09-23 05:13:27 UTC (rev 282927)
@@ -1,5 +1,129 @@
 2021-09-22  Alan Coon  <alanc...@apple.com>
 
+        Cherry-pick r281354. rdar://problem/83429677
+
+    Web Inspector: Style rules declared after a rule whose selector has over 8192 components are not shown correctly
+    https://bugs.webkit.org/show_bug.cgi?id=229218
+    
+    Reviewed by Devin Rousso.
+    
+    Source/WebCore:
+    
+    Test: inspector/css/getMatchedStylesForNodeLargeSelectors.html
+    
+    CSS rules are limited to 8192 selector components in WebCore, and when more components are present the rule is
+    split into multiple `StyleRule` instances. This meant Web Inspector could not reliably resolve a `StyleRule`
+    back to its source data, which we do to enable things like editing, as well as to make sure we show the un-split
+    selector in the Styles sidebar of the Elements tab. Previously, the presences of multiple `StyleRule`s for a
+    single source data declaration was not accounted for, which meant that rules after the split rules would show a
+    mix of style information from the actual rule as well as a rule some number of declarations later in the same
+    style sheet. This is resolved by marking `StyleRule`s that have been split and marking the last of the split
+    rules. This allows us to then forgo incrementing the index for looking up raw declarations until we encounter
+    the last rule from a split `StyleRule`.
+    
+     * css/StyleRule.cpp:
+    (WebCore::StyleRule::StyleRule):
+    (WebCore::StyleRule::createForSplitting):
+    (WebCore::StyleRule::splitIntoMultipleRulesWithMaximumSelectorComponentCount const):
+    
+    * css/StyleRule.h:
+    - Added two members to track rules that are split into multiple rules due to exceeding the 8192 component limit
+    for selectors in order to determine later which rules are effectively duplicates of each other. We use two
+    members here, one to track that the rule was split from a larger authored rule (`m_isSplitRule`), and one to
+    mark the last rule split from a given rule (`m_isLastRuleInSplitRule`). The second member prevents situations
+    where we might otherwise accidentally continue iterating into a list of `StyleRule` where two large authored
+    rules that had to be split are present next to each other in an ordered collection of `StyleRule`.
+    
+    * inspector/InspectorStyleSheet.cpp:
+    (WebCore::selectorsFromSource):
+    - Use a vector of `CSSSelector`s for specificity information since we now collect selectors from potentially
+    multiple `CSSStyleRule`s.
+    
+    (WebCore::InspectorStyleSheet::cssStyleRulesSplitFromSameRule):
+    - Find any neighboring CSSStyleRules that were split from the same original rule based on the order of rules as
+    well as the new flags in `StyleRule`
+    
+    (WebCore::InspectorStyleSheet::selectorsForCSSStyleRule):
+    - Find all selectors for a given CSSStyleRule, including other `CSSStyleRule`s split from the same rule in a
+    style sheet.
+    
+    (WebCore::InspectorStyleSheet::buildObjectForSelectorList):
+    - Use all CSSSelectors from for the CSSStyleRule and other rules that were split from the same rule in a style
+    sheet.
+    
+    (WebCore::InspectorStyleSheet::ruleSourceDataFor const):
+    (WebCore::InspectorStyleSheet::ruleIndexByStyle const):
+    - When looking up an index to get rule source data, make sure we don't overcount split rules.
+    
+    * inspector/InspectorStyleSheet.h:
+    
+    LayoutTests:
+    
+    Test very large (8192 individual component) selectors to ensure surrounding styles are correctly resolved.
+    
+    * inspector/css/getMatchedStylesForNodeLargeSelectors-expected.txt: Added.
+    * inspector/css/getMatchedStylesForNodeLargeSelectors.html: Added.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@281354 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-08-20  Patrick Angle  <pan...@apple.com>
+
+            Web Inspector: Style rules declared after a rule whose selector has over 8192 components are not shown correctly
+            https://bugs.webkit.org/show_bug.cgi?id=229218
+
+            Reviewed by Devin Rousso.
+
+            Test: inspector/css/getMatchedStylesForNodeLargeSelectors.html
+
+            CSS rules are limited to 8192 selector components in WebCore, and when more components are present the rule is
+            split into multiple `StyleRule` instances. This meant Web Inspector could not reliably resolve a `StyleRule`
+            back to its source data, which we do to enable things like editing, as well as to make sure we show the un-split
+            selector in the Styles sidebar of the Elements tab. Previously, the presences of multiple `StyleRule`s for a
+            single source data declaration was not accounted for, which meant that rules after the split rules would show a
+            mix of style information from the actual rule as well as a rule some number of declarations later in the same
+            style sheet. This is resolved by marking `StyleRule`s that have been split and marking the last of the split
+            rules. This allows us to then forgo incrementing the index for looking up raw declarations until we encounter
+            the last rule from a split `StyleRule`.
+
+             * css/StyleRule.cpp:
+            (WebCore::StyleRule::StyleRule):
+            (WebCore::StyleRule::createForSplitting):
+            (WebCore::StyleRule::splitIntoMultipleRulesWithMaximumSelectorComponentCount const):
+
+            * css/StyleRule.h:
+            - Added two members to track rules that are split into multiple rules due to exceeding the 8192 component limit
+            for selectors in order to determine later which rules are effectively duplicates of each other. We use two
+            members here, one to track that the rule was split from a larger authored rule (`m_isSplitRule`), and one to
+            mark the last rule split from a given rule (`m_isLastRuleInSplitRule`). The second member prevents situations
+            where we might otherwise accidentally continue iterating into a list of `StyleRule` where two large authored
+            rules that had to be split are present next to each other in an ordered collection of `StyleRule`.
+
+            * inspector/InspectorStyleSheet.cpp:
+            (WebCore::selectorsFromSource):
+            - Use a vector of `CSSSelector`s for specificity information since we now collect selectors from potentially
+            multiple `CSSStyleRule`s.
+
+            (WebCore::InspectorStyleSheet::cssStyleRulesSplitFromSameRule):
+            - Find any neighboring CSSStyleRules that were split from the same original rule based on the order of rules as
+            well as the new flags in `StyleRule`
+
+            (WebCore::InspectorStyleSheet::selectorsForCSSStyleRule):
+            - Find all selectors for a given CSSStyleRule, including other `CSSStyleRule`s split from the same rule in a
+            style sheet.
+
+            (WebCore::InspectorStyleSheet::buildObjectForSelectorList):
+            - Use all CSSSelectors from for the CSSStyleRule and other rules that were split from the same rule in a style
+            sheet.
+
+            (WebCore::InspectorStyleSheet::ruleSourceDataFor const):
+            (WebCore::InspectorStyleSheet::ruleIndexByStyle const):
+            - When looking up an index to get rule source data, make sure we don't overcount split rules.
+
+            * inspector/InspectorStyleSheet.h:
+
+2021-09-22  Alan Coon  <alanc...@apple.com>
+
         Cherry-pick r281323. rdar://problem/83430037
 
     Release assert in ScriptController::canExecuteScripts via WebCore::WebSocket::didReceiveMessage

Modified: branches/safari-612-branch/Source/WebCore/css/StyleRule.cpp (282926 => 282927)


--- branches/safari-612-branch/Source/WebCore/css/StyleRule.cpp	2021-09-23 05:13:21 UTC (rev 282926)
+++ branches/safari-612-branch/Source/WebCore/css/StyleRule.cpp	2021-09-23 05:13:27 UTC (rev 282927)
@@ -191,6 +191,8 @@
     : StyleRuleBase(o)
     , m_properties(o.properties().mutableCopy())
     , m_selectorList(o.m_selectorList)
+    , m_isSplitRule(o.m_isSplitRule)
+    , m_isLastRuleInSplitRule(o.m_isLastRuleInSplitRule)
 {
 }
 
@@ -227,7 +229,9 @@
     for (unsigned i = 0; i < selectors.size(); ++i)
         new (NotNull, &selectorListArray[i]) CSSSelector(*selectors.at(i));
     selectorListArray[selectors.size() - 1].setLastInSelectorList();
-    return StyleRule::create(WTFMove(properties), hasDocumentSecurityOrigin, CSSSelectorList(WTFMove(selectorListArray)));
+    auto styleRule = StyleRule::create(WTFMove(properties), hasDocumentSecurityOrigin, CSSSelectorList(WTFMove(selectorListArray)));
+    styleRule->markAsSplitRule();
+    return styleRule;
 }
 
 Vector<RefPtr<StyleRule>> StyleRule::splitIntoMultipleRulesWithMaximumSelectorComponentCount(unsigned maxCount) const
@@ -253,6 +257,9 @@
     if (!componentsSinceLastSplit.isEmpty())
         rules.append(createForSplitting(componentsSinceLastSplit, const_cast<StyleProperties&>(properties()), hasDocumentSecurityOrigin()));
 
+    if (!rules.isEmpty())
+        rules.last()->markAsLastRuleInSplitRule();
+
     return rules;
 }
 

Modified: branches/safari-612-branch/Source/WebCore/css/StyleRule.h (282926 => 282927)


--- branches/safari-612-branch/Source/WebCore/css/StyleRule.h	2021-09-23 05:13:21 UTC (rev 282926)
+++ branches/safari-612-branch/Source/WebCore/css/StyleRule.h	2021-09-23 05:13:27 UTC (rev 282927)
@@ -97,6 +97,11 @@
     MutableStyleProperties& mutableProperties();
     const StyleProperties* propertiesWithoutDeferredParsing() const;
 
+    bool isSplitRule() const { return m_isSplitRule; }
+    void markAsSplitRule() { m_isSplitRule = true; }
+    bool isLastRuleInSplitRule() const { return m_isLastRuleInSplitRule; }
+    void markAsLastRuleInSplitRule() { m_isLastRuleInSplitRule = true; }
+
     using StyleRuleBase::hasDocumentSecurityOrigin;
 
     void wrapperAdoptSelectorList(CSSSelectorList&&);
@@ -122,6 +127,9 @@
 #if ENABLE(CSS_SELECTOR_JIT)
     mutable UniqueArray<CompiledSelector> m_compiledSelectors;
 #endif
+
+    bool m_isSplitRule { false };
+    bool m_isLastRuleInSplitRule { false };
 };
 
 class StyleRuleFontFace final : public StyleRuleBase {

Modified: branches/safari-612-branch/Source/WebCore/inspector/InspectorStyleSheet.cpp (282926 => 282927)


--- branches/safari-612-branch/Source/WebCore/inspector/InspectorStyleSheet.cpp	2021-09-23 05:13:21 UTC (rev 282926)
+++ branches/safari-612-branch/Source/WebCore/inspector/InspectorStyleSheet.cpp	2021-09-23 05:13:27 UTC (rev 282927)
@@ -61,6 +61,7 @@
 #include "StyleSheetList.h"
 #include <_javascript_Core/ContentSearchUtilities.h>
 #include <_javascript_Core/RegularExpression.h>
+#include <wtf/NotFound.h>
 #include <wtf/text/StringBuilder.h>
 
 using JSON::ArrayOf;
@@ -1069,17 +1070,17 @@
     return inspectorSelector;
 }
 
-static Ref<JSON::ArrayOf<Protocol::CSS::CSSSelector>> selectorsFromSource(const CSSRuleSourceData* sourceData, const String& sheetText, const CSSSelectorList& selectorList)
+static Ref<JSON::ArrayOf<Protocol::CSS::CSSSelector>> selectorsFromSource(const CSSRuleSourceData* sourceData, const String& sheetText, const Vector<const CSSSelector*> selectors)
 {
     static NeverDestroyed<JSC::Yarr::RegularExpression> comment("/\\*[^]*?\\*/", JSC::Yarr::TextCaseSensitive, JSC::Yarr::MultilineEnabled);
 
     auto result = JSON::ArrayOf<Protocol::CSS::CSSSelector>::create();
-    const CSSSelector* selector = selectorList.first();
+    unsigned selectorIndex = 0;
     for (auto& range : sourceData->selectorRanges) {
         // If we don't have a selector, that means the SourceData for this CSSStyleSheet
         // no longer matches up with the actual rules in the CSSStyleSheet.
-        ASSERT(selector);
-        if (!selector)
+        ASSERT(selectorIndex < selectors.size());
+        if (selectorIndex >= selectors.size())
             break;
 
         String selectorText = sheetText.substring(range.start, range.length());
@@ -1086,13 +1087,67 @@
 
         // We don't want to see any comments in the selector components, only the meaningful parts.
         replace(selectorText, comment, String());
-        result->addItem(buildObjectForSelectorHelper(selectorText.stripWhiteSpace(), *selector));
+        result->addItem(buildObjectForSelectorHelper(selectorText.stripWhiteSpace(), *selectors.at(selectorIndex)));
 
-        selector = CSSSelectorList::next(selector);
+        ++selectorIndex;
     }
     return result;
 }
 
+Vector<Ref<CSSStyleRule>> InspectorStyleSheet::cssStyleRulesSplitFromSameRule(CSSStyleRule& rule)
+{
+    if (!rule.styleRule().isSplitRule())
+        return { rule };
+
+    Vector<Ref<CSSStyleRule>> rules;
+
+    ensureFlatRules();
+    auto firstIndexOfSplitRule = m_flatRules.find(&rule);
+    if (firstIndexOfSplitRule == notFound)
+        return { rule };
+
+    for (; firstIndexOfSplitRule > 0; --firstIndexOfSplitRule) {
+        auto ruleAtPreviousIndex = m_flatRules.at(firstIndexOfSplitRule - 1);
+
+        ASSERT(ruleAtPreviousIndex);
+        if (!ruleAtPreviousIndex)
+            return { rule };
+
+        if (!ruleAtPreviousIndex->styleRule().isSplitRule() || ruleAtPreviousIndex->styleRule().isLastRuleInSplitRule())
+            break;
+    }
+
+    for (auto i = firstIndexOfSplitRule; i < m_flatRules.size(); ++i) {
+        auto rule = m_flatRules.at(i);
+
+        ASSERT(rule);
+        if (!rule)
+            return rules;
+
+        if (!rule->styleRule().isSplitRule())
+            break;
+
+        rules.append(*rule);
+
+        if (rule->styleRule().isLastRuleInSplitRule())
+            break;
+    }
+
+    return rules;
+}
+
+Vector<const CSSSelector*> InspectorStyleSheet::selectorsForCSSStyleRule(CSSStyleRule& rule)
+{
+    auto rules = cssStyleRulesSplitFromSameRule(rule);
+
+    Vector<const CSSSelector*> selectors;
+    for (auto& rule : cssStyleRulesSplitFromSameRule(rule)) {
+        for (const CSSSelector* selector = rule->styleRule().selectorList().first(); selector; selector = CSSSelectorList::next(selector))
+            selectors.append(selector);
+    }
+    return selectors;
+}
+
 Ref<Protocol::CSS::CSSSelector> InspectorStyleSheet::buildObjectForSelector(const CSSSelector* selector)
 {
     return buildObjectForSelectorHelper(selector->selectorText(), *selector);
@@ -1109,11 +1164,10 @@
     String selectorText = rule->selectorText();
 
     if (sourceData)
-        selectors = selectorsFromSource(sourceData.get(), m_parsedStyleSheet->text(), rule->styleRule().selectorList());
+        selectors = selectorsFromSource(sourceData.get(), m_parsedStyleSheet->text(), selectorsForCSSStyleRule(*rule));
     else {
         selectors = JSON::ArrayOf<Protocol::CSS::CSSSelector>::create();
-        const CSSSelectorList& selectorList = rule->styleRule().selectorList();
-        for (const CSSSelector* selector = selectorList.first(); selector; selector = CSSSelectorList::next(selector))
+        for (const CSSSelector* selector : selectorsForCSSStyleRule(*rule))
             selectors->addItem(buildObjectForSelector(selector));
     }
     auto result = Protocol::CSS::SelectorList::create()
@@ -1251,7 +1305,8 @@
 
 RefPtr<CSSRuleSourceData> InspectorStyleSheet::ruleSourceDataFor(CSSStyleDeclaration* style) const
 {
-    return m_parsedStyleSheet->ruleSourceDataAt(ruleIndexByStyle(style));
+    constexpr auto combineSplitRules = true;
+    return m_parsedStyleSheet->ruleSourceDataAt(ruleIndexByStyle(style, combineSplitRules));
 }
 
 Vector<size_t> InspectorStyleSheet::lineEndings() const
@@ -1261,7 +1316,7 @@
     return ContentSearchUtilities::lineEndings(m_parsedStyleSheet->text());
 }
 
-unsigned InspectorStyleSheet::ruleIndexByStyle(CSSStyleDeclaration* pageStyle) const
+unsigned InspectorStyleSheet::ruleIndexByStyle(CSSStyleDeclaration* pageStyle, bool combineSplitRules) const
 {
     ensureFlatRules();
     unsigned index = 0;
@@ -1269,7 +1324,8 @@
         if (&rule->style() == pageStyle)
             return index;
 
-        ++index;
+        if (!combineSplitRules || !rule->styleRule().isSplitRule() || rule->styleRule().isLastRuleInSplitRule())
+            ++index;
     }
     return UINT_MAX;
 }

Modified: branches/safari-612-branch/Source/WebCore/inspector/InspectorStyleSheet.h (282926 => 282927)


--- branches/safari-612-branch/Source/WebCore/inspector/InspectorStyleSheet.h	2021-09-23 05:13:21 UTC (rev 282926)
+++ branches/safari-612-branch/Source/WebCore/inspector/InspectorStyleSheet.h	2021-09-23 05:13:27 UTC (rev 282927)
@@ -193,7 +193,7 @@
     InspectorCSSId ruleOrStyleId(CSSStyleDeclaration*) const;
     virtual Document* ownerDocument() const;
     virtual RefPtr<CSSRuleSourceData> ruleSourceDataFor(CSSStyleDeclaration*) const;
-    virtual unsigned ruleIndexByStyle(CSSStyleDeclaration*) const;
+    virtual unsigned ruleIndexByStyle(CSSStyleDeclaration*, bool combineSplitRules = false) const;
     virtual bool ensureParsedDataReady();
     virtual RefPtr<InspectorStyle> inspectorStyleForId(const InspectorCSSId&);
 
@@ -219,6 +219,9 @@
     Ref<Inspector::Protocol::CSS::CSSSelector> buildObjectForSelector(const CSSSelector*);
     Ref<Inspector::Protocol::CSS::SelectorList> buildObjectForSelectorList(CSSStyleRule*, int& endingLine);
 
+    Vector<Ref<CSSStyleRule>> cssStyleRulesSplitFromSameRule(CSSStyleRule&);
+    Vector<const CSSSelector*> selectorsForCSSStyleRule(CSSStyleRule&);
+
     InspectorPageAgent* m_pageAgent;
     String m_id;
     RefPtr<CSSStyleSheet> m_pageStyleSheet;
@@ -242,7 +245,7 @@
 
     Document* ownerDocument() const final;
     RefPtr<CSSRuleSourceData> ruleSourceDataFor(CSSStyleDeclaration* style) const final { ASSERT_UNUSED(style, style == &inlineStyle()); return m_ruleSourceData; }
-    unsigned ruleIndexByStyle(CSSStyleDeclaration*) const final { return 0; }
+    unsigned ruleIndexByStyle(CSSStyleDeclaration*, bool) const final { return 0; }
     bool ensureParsedDataReady() final;
     RefPtr<InspectorStyle> inspectorStyleForId(const InspectorCSSId&) final;
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to