Title: [190680] trunk
Revision
190680
Author
an...@apple.com
Date
2015-10-07 12:59:32 -0700 (Wed, 07 Oct 2015)

Log Message

Implement :host pseudo class
https://bugs.webkit.org/show_bug.cgi?id=149440
Source/WebCore:

rdar://problem/22731953

Reviewed by Ryosuke Niwa.

This implements the basic non-function :host syntax.

* css/CSSSelector.cpp:
(WebCore::CSSSelector::selectorText):
* css/CSSSelector.h:
* css/ElementRuleCollector.cpp:
(WebCore::ElementRuleCollector::matchAuthorRules):
(WebCore::ElementRuleCollector::matchHostPseudoClassRules):
(WebCore::ElementRuleCollector::matchUserRules):
* css/ElementRuleCollector.h:
* css/RuleSet.cpp:
(WebCore::computeMatchBasedOnRuleHash):
(WebCore::RuleSet::addRule):
* css/RuleSet.h:
(WebCore::RuleSet::cuePseudoRules):
(WebCore::RuleSet::hostPseudoClassRules):
(WebCore::RuleSet::focusPseudoClassRules):
(WebCore::RuleSet::universalRules):
* css/SelectorChecker.cpp:
(WebCore::SelectorChecker::checkOne):
* css/SelectorPseudoClassAndCompatibilityElementMap.in:
* cssjit/SelectorCompiler.cpp:
(WebCore::SelectorCompiler::addPseudoClassType):

LayoutTests:


Reviewed by Ryosuke Niwa.

* fast/shadow-dom/css-scoping-shadow-host-rule.html:

    Fix and expand the test case.

* platform/mac/TestExpectations:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (190679 => 190680)


--- trunk/LayoutTests/ChangeLog	2015-10-07 19:41:28 UTC (rev 190679)
+++ trunk/LayoutTests/ChangeLog	2015-10-07 19:59:32 UTC (rev 190680)
@@ -1,3 +1,16 @@
+2015-10-07  Antti Koivisto  <an...@apple.com>
+
+        Implement :host pseudo class
+        https://bugs.webkit.org/show_bug.cgi?id=149440
+
+        Reviewed by Ryosuke Niwa.
+
+        * fast/shadow-dom/css-scoping-shadow-host-rule.html:
+
+            Fix and expand the test case.
+
+        * platform/mac/TestExpectations:
+
 2015-10-07  Brian Burg  <bb...@apple.com>
 
         Unreviewed, more Mac test gardening after r190629.

Modified: trunk/LayoutTests/fast/shadow-dom/css-scoping-shadow-host-rule.html (190679 => 190680)


--- trunk/LayoutTests/fast/shadow-dom/css-scoping-shadow-host-rule.html	2015-10-07 19:41:28 UTC (rev 190679)
+++ trunk/LayoutTests/fast/shadow-dom/css-scoping-shadow-host-rule.html	2015-10-07 19:59:32 UTC (rev 190680)
@@ -8,41 +8,56 @@
 </head>
 <body>
     <style>
-        my-host, good-host, other-host, other-good-host {
+        my-host, my-host2, my-host3, my-host4 {
             display: block;
             width: 100px;
-            height: 50px;
+            height: 25px;
+        }
+        my-host2 {
+            background: green;
+        }
+        my-host3 {
             background: red;
+            color: green;
         }
-        good-host, other-good-host {
+        my-host4 {
             background: green;
+            color: green;
         }
     </style>
     <p>Test passes if you see a single 100px by 100px green box below.</p> 
     <my-host>
         <div>FAIL</div>
     </my-host>
+    <my-host2>
+        <div>FAIL</div>
+    </my-host2>
+    <my-host3>
+        <div>FAIL</div>
+    </my-host3>
     <div class="container">
-        <good-host>
+        <my-host4>
             <div>FAIL</div>
-        </good-host>
+        </my-host4>
     </div>
-    <other-host id="bar" class="foo" name="baz">
-        <div>FAIL</div>
-    </other-host>
-    <other-good-host>
-        <div class="child">FAIL</div>
-    </other-good-host>
     <script>
 
         try {
             var shadowHost = document.querySelector('my-host');
+            var shadowRoot = shadowHost.attachShadow({mode: 'open'});
+            shadowRoot.innerHTML = '<style> :host { color: green; background: green; } </style><div>FAIL</div>';
+
+            shadowHost = document.querySelector('my-host2');
             shadowRoot = shadowHost.attachShadow({mode: 'open'});
-            shadowRoot.innerHTML = '<style> :host { background: green; } </style>';
+            shadowRoot.innerHTML = '<style> :host { color: red; background: red; } div { color: green }</style><div>FAIL</div>';
 
-            shadowHost = document.querySelector('good-host');
+            shadowHost = document.querySelector('my-host3');
             shadowRoot = shadowHost.attachShadow({mode: 'open'});
-            shadowRoot.innerHTML = '<style> .container :host { background: red; } </style>';
+            shadowRoot.innerHTML = '<style> :host { background: green !important; color: green !important; } </style><div>FAIL</div>';
+
+            shadowHost = document.querySelector('my-host4');
+            shadowRoot = shadowHost.attachShadow({mode: 'open'});
+            shadowRoot.innerHTML = '<style> .container :host { background: red !important; } </style><div>FAIL</div>';
         } catch (exception) {
             document.body.appendChild(document.createTextNode(exception));
         }

Modified: trunk/LayoutTests/platform/mac/TestExpectations (190679 => 190680)


--- trunk/LayoutTests/platform/mac/TestExpectations	2015-10-07 19:41:28 UTC (rev 190679)
+++ trunk/LayoutTests/platform/mac/TestExpectations	2015-10-07 19:59:32 UTC (rev 190680)
@@ -1325,7 +1325,6 @@
 webkit.org/b/149128 fast/text/control-characters [ ImageOnlyFailure ]
 
 webkit.org/b/148695 fast/shadow-dom [ Pass ]
-webkit.org/b/149440 fast/shadow-dom/css-scoping-shadow-host-rule.html [ ImageOnlyFailure ]
 webkit.org/b/149440 fast/shadow-dom/css-scoping-shadow-host-functional-rule.html [ ImageOnlyFailure ]
 webkit.org/b/149441 fast/shadow-dom/css-scoping-shadow-slotted-rule.html [ ImageOnlyFailure ]
 webkit.org/b/149441 fast/shadow-dom/css-scoping-shadow-slot-display-override.html [ ImageOnlyFailure ]

Modified: trunk/Source/WebCore/ChangeLog (190679 => 190680)


--- trunk/Source/WebCore/ChangeLog	2015-10-07 19:41:28 UTC (rev 190679)
+++ trunk/Source/WebCore/ChangeLog	2015-10-07 19:59:32 UTC (rev 190680)
@@ -1,3 +1,35 @@
+2015-10-07  Antti Koivisto  <an...@apple.com>
+
+        Implement :host pseudo class
+        https://bugs.webkit.org/show_bug.cgi?id=149440
+        rdar://problem/22731953
+
+        Reviewed by Ryosuke Niwa.
+
+        This implements the basic non-function :host syntax.
+
+        * css/CSSSelector.cpp:
+        (WebCore::CSSSelector::selectorText):
+        * css/CSSSelector.h:
+        * css/ElementRuleCollector.cpp:
+        (WebCore::ElementRuleCollector::matchAuthorRules):
+        (WebCore::ElementRuleCollector::matchHostPseudoClassRules):
+        (WebCore::ElementRuleCollector::matchUserRules):
+        * css/ElementRuleCollector.h:
+        * css/RuleSet.cpp:
+        (WebCore::computeMatchBasedOnRuleHash):
+        (WebCore::RuleSet::addRule):
+        * css/RuleSet.h:
+        (WebCore::RuleSet::cuePseudoRules):
+        (WebCore::RuleSet::hostPseudoClassRules):
+        (WebCore::RuleSet::focusPseudoClassRules):
+        (WebCore::RuleSet::universalRules):
+        * css/SelectorChecker.cpp:
+        (WebCore::SelectorChecker::checkOne):
+        * css/SelectorPseudoClassAndCompatibilityElementMap.in:
+        * cssjit/SelectorCompiler.cpp:
+        (WebCore::SelectorCompiler::addPseudoClassType):
+
 2015-10-07  Nan Wang  <n_w...@apple.com>
 
         AX: ARIA 1.1 @aria-placeholder

Modified: trunk/Source/WebCore/css/CSSSelector.cpp (190679 => 190680)


--- trunk/Source/WebCore/css/CSSSelector.cpp	2015-10-07 19:41:28 UTC (rev 190679)
+++ trunk/Source/WebCore/css/CSSSelector.cpp	2015-10-07 19:59:32 UTC (rev 190680)
@@ -632,6 +632,11 @@
             case CSSSelector::PseudoClassWindowInactive:
                 str.appendLiteral(":window-inactive");
                 break;
+#if ENABLE(SHADOW_DOM)
+            case CSSSelector::PseudoClassHost:
+                str.appendLiteral(":host");
+                break;
+#endif
             case CSSSelector::PseudoClassUnknown:
                 ASSERT_NOT_REACHED();
             }

Modified: trunk/Source/WebCore/css/CSSSelector.h (190679 => 190680)


--- trunk/Source/WebCore/css/CSSSelector.h	2015-10-07 19:41:28 UTC (rev 190679)
+++ trunk/Source/WebCore/css/CSSSelector.h	2015-10-07 19:59:32 UTC (rev 190680)
@@ -159,6 +159,9 @@
             PseudoClassDir,
             PseudoClassRole,
 #endif
+#if ENABLE(SHADOW_DOM)
+            PseudoClassHost,
+#endif
         };
 
         enum PseudoElementType {

Modified: trunk/Source/WebCore/css/ElementRuleCollector.cpp (190679 => 190680)


--- trunk/Source/WebCore/css/ElementRuleCollector.cpp	2015-10-07 19:41:28 UTC (rev 190679)
+++ trunk/Source/WebCore/css/ElementRuleCollector.cpp	2015-10-07 19:59:32 UTC (rev 190680)
@@ -188,6 +188,11 @@
 
 void ElementRuleCollector::matchAuthorRules(bool includeEmptyRules)
 {
+#if ENABLE(SHADOW_DOM)
+    if (m_element.shadowRoot())
+        matchHostPseudoClassRules(includeEmptyRules);
+#endif
+
     clearMatchedRules();
     m_result.ranges.lastAuthorRule = m_result.matchedProperties().size() - 1;
 
@@ -200,6 +205,29 @@
     sortAndTransferMatchedRules();
 }
 
+#if ENABLE(SHADOW_DOM)
+void ElementRuleCollector::matchHostPseudoClassRules(bool includeEmptyRules)
+{
+    ASSERT(m_element.shadowRoot());
+    auto& shadowAuthorStyle = *m_element.shadowRoot()->styleResolver().ruleSets().authorStyle();
+    auto& shadowHostRules = shadowAuthorStyle.hostPseudoClassRules();
+    if (shadowHostRules.isEmpty())
+        return;
+
+    clearMatchedRules();
+    m_result.ranges.lastAuthorRule = m_result.matchedProperties().size() - 1;
+
+    auto ruleRange = m_result.ranges.authorRuleRange();
+    MatchRequest matchRequest(&shadowAuthorStyle, includeEmptyRules);
+    collectMatchingRulesForList(&shadowHostRules, matchRequest, ruleRange);
+
+    // We just sort the host rules before other author rules. This matches the current vague spec language
+    // but is not necessarily exactly what is needed.
+    // FIXME: Match the spec when it is finalized.
+    sortAndTransferMatchedRules();
+}
+#endif
+
 void ElementRuleCollector::matchUserRules(bool includeEmptyRules)
 {
     if (!m_ruleSets.userStyle())

Modified: trunk/Source/WebCore/css/ElementRuleCollector.h (190679 => 190680)


--- trunk/Source/WebCore/css/ElementRuleCollector.h	2015-10-07 19:41:28 UTC (rev 190679)
+++ trunk/Source/WebCore/css/ElementRuleCollector.h	2015-10-07 19:59:32 UTC (rev 190680)
@@ -77,6 +77,9 @@
     void addElementStyleProperties(const StyleProperties*, bool isCacheable = true);
 
     void matchUARules(RuleSet*);
+#if ENABLE(SHADOW_DOM)
+    void matchHostPseudoClassRules(bool includeEmptyRules);
+#endif
 
     void collectMatchingRules(const MatchRequest&, StyleResolver::RuleRange&);
     void collectMatchingRulesForRegion(const MatchRequest&, StyleResolver::RuleRange&);

Modified: trunk/Source/WebCore/css/RuleSet.cpp (190679 => 190680)


--- trunk/Source/WebCore/css/RuleSet.cpp	2015-10-07 19:41:28 UTC (rev 190679)
+++ trunk/Source/WebCore/css/RuleSet.cpp	2015-10-07 19:59:32 UTC (rev 190680)
@@ -70,6 +70,10 @@
     }
     if (SelectorChecker::isCommonPseudoClassSelector(&selector))
         return MatchBasedOnRuleHash::ClassB;
+#if ENABLE(SHADOW_DOM)
+    if (selector.match() == CSSSelector::PseudoClass && selector.pseudoClassType() == CSSSelector::PseudoClassHost)
+        return MatchBasedOnRuleHash::ClassB;
+#endif
     if (selector.match() == CSSSelector::Id)
         return MatchBasedOnRuleHash::ClassA;
     if (selector.match() == CSSSelector::Class)
@@ -258,6 +262,12 @@
             }
         }
 
+#if ENABLE(SHADOW_DOM)
+        if (selector->match() == CSSSelector::PseudoClass && selector->pseudoClassType() == CSSSelector::PseudoClassHost) {
+            m_hostPseudoClassRules.append(ruleData);
+            return;
+        }
+#endif
         if (selector->relation() != CSSSelector::SubSelector)
             break;
         selector = selector->tagHistory();

Modified: trunk/Source/WebCore/css/RuleSet.h (190679 => 190680)


--- trunk/Source/WebCore/css/RuleSet.h	2015-10-07 19:41:28 UTC (rev 190679)
+++ trunk/Source/WebCore/css/RuleSet.h	2015-10-07 19:59:32 UTC (rev 190680)
@@ -179,6 +179,9 @@
 #if ENABLE(VIDEO_TRACK)
     const RuleDataVector* cuePseudoRules() const { return &m_cuePseudoRules; }
 #endif
+#if ENABLE(SHADOW_DOM)
+    const RuleDataVector& hostPseudoClassRules() const { return m_hostPseudoClassRules; }
+#endif
     const RuleDataVector* focusPseudoClassRules() const { return &m_focusPseudoClassRules; }
     const RuleDataVector* universalRules() const { return &m_universalRules; }
 
@@ -202,6 +205,9 @@
 #if ENABLE(VIDEO_TRACK)
     RuleDataVector m_cuePseudoRules;
 #endif
+#if ENABLE(SHADOW_DOM)
+    RuleDataVector m_hostPseudoClassRules;
+#endif
     RuleDataVector m_focusPseudoClassRules;
     RuleDataVector m_universalRules;
     Vector<StyleRulePage*> m_pageRules;

Modified: trunk/Source/WebCore/css/SelectorChecker.cpp (190679 => 190680)


--- trunk/Source/WebCore/css/SelectorChecker.cpp	2015-10-07 19:41:28 UTC (rev 190679)
+++ trunk/Source/WebCore/css/SelectorChecker.cpp	2015-10-07 19:59:32 UTC (rev 190680)
@@ -1013,7 +1013,11 @@
                     return true;
                 break;
             }
-
+#if ENABLE(SHADOW_DOM)
+        case CSSSelector::PseudoClassHost:
+            // :host matches based on context. Cases that reach selector checker don't match.
+            return false;
+#endif
         case CSSSelector::PseudoClassWindowInactive:
             return isWindowInactive(element);
 

Modified: trunk/Source/WebCore/css/SelectorPseudoClassAndCompatibilityElementMap.in (190679 => 190680)


--- trunk/Source/WebCore/css/SelectorPseudoClassAndCompatibilityElementMap.in	2015-10-07 19:41:28 UTC (rev 190679)
+++ trunk/Source/WebCore/css/SelectorPseudoClassAndCompatibilityElementMap.in	2015-10-07 19:59:32 UTC (rev 190680)
@@ -74,3 +74,7 @@
 future
 past
 #endif
+
+#if ENABLE(SHADOW_DOM)
+host
+#endif

Modified: trunk/Source/WebCore/cssjit/SelectorCompiler.cpp (190679 => 190680)


--- trunk/Source/WebCore/cssjit/SelectorCompiler.cpp	2015-10-07 19:41:28 UTC (rev 190679)
+++ trunk/Source/WebCore/cssjit/SelectorCompiler.cpp	2015-10-07 19:59:32 UTC (rev 190680)
@@ -819,7 +819,11 @@
 
             return functionType;
         }
-
+#if ENABLE(SHADOW_DOM)
+    case CSSSelector::PseudoClassHost:
+        // :host matches based on context. Cases that reach selector checker don't match.
+        return FunctionType::CannotMatchAnything;
+#endif
     case CSSSelector::PseudoClassUnknown:
         ASSERT_NOT_REACHED();
         return FunctionType::CannotMatchAnything;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to