Title: [237932] trunk
Revision
237932
Author
m...@apple.com
Date
2018-11-07 11:33:54 -0800 (Wed, 07 Nov 2018)

Log Message

Add a pseudoclass that matches img elements that are backed by an attachment
https://bugs.webkit.org/show_bug.cgi?id=191286
<rdar://problem/45823554>

Reviewed by Dean Jackson.

Source/WebCore:

Test: fast/css/has-attachment.html

Added a :has-attachment pseudoclass, enabled only when the attachment element is enabled at
runtime, that matches elements (currently only img elements qualify) that have an attachment
element in their shadow DOM.

* css/CSSSelector.cpp:
(WebCore::CSSSelector::selectorText const): Handle the new PseudoClassHasAttachment value.
* css/CSSSelector.h: Added a new value to the PseudoClassType enum.

* css/SelectorChecker.cpp:
(WebCore::SelectorChecker::checkOne const): Check the new PseudoClassHasAttachment value
  using the new hasAttachment test function.

* css/SelectorCheckerTestFunctions.h:
(WebCore::hasAttachment): Added. Tests if the element is an img element that has an
  attachment.

* css/SelectorPseudoClassAndCompatibilityElementMap.in: Added has-attachment.

* css/parser/CSSParserContext.cpp:
(WebCore::CSSParserContext::CSSParserContext): Initialize new attachmentEnabled member based
  on RuntimeEnabledFeatures.
(WebCore::operator==): Compare new attachmentEnabled member.
* css/parser/CSSParserContext.h:
(WebCore::CSSParserContextHash::hash): Include new attachmentEnabled member.

* css/parser/CSSSelectorParser.cpp:
(WebCore::CSSSelectorParser::consumePseudo): Reject :has-attachment if the attachment
  element is not enabled.

* cssjit/SelectorCompiler.cpp:
(WebCore::SelectorCompiler::addPseudoClassType): Handle PseudoClassHasAttachment.

LayoutTests:

* fast/css/has-attachment-expected.txt: Added.
* fast/css/has-attachment.html: Added.
* platform/win/TestExpectations:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (237931 => 237932)


--- trunk/LayoutTests/ChangeLog	2018-11-07 19:25:39 UTC (rev 237931)
+++ trunk/LayoutTests/ChangeLog	2018-11-07 19:33:54 UTC (rev 237932)
@@ -1,3 +1,15 @@
+2018-11-07  Dan Bernstein  <m...@apple.com>
+
+        Add a pseudoclass that matches img elements that are backed by an attachment
+        https://bugs.webkit.org/show_bug.cgi?id=191286
+        <rdar://problem/45823554>
+
+        Reviewed by Dean Jackson.
+
+        * fast/css/has-attachment-expected.txt: Added.
+        * fast/css/has-attachment.html: Added.
+        * platform/win/TestExpectations:
+
 2018-11-07  Ali Juma  <aj...@chromium.org>
 
         IntersectionObserverEntry doesn't keep JS wrappers of rects alive

Added: trunk/LayoutTests/fast/css/has-attachment-expected.txt (0 => 237932)


--- trunk/LayoutTests/fast/css/has-attachment-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/css/has-attachment-expected.txt	2018-11-07 19:33:54 UTC (rev 237932)
@@ -0,0 +1,11 @@
+This tests the :has-attachment pseudoclass.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS getComputedStyle(target).clear is "both"
+PASS getComputedStyle(target).clear is "none"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/css/has-attachment.html (0 => 237932)


--- trunk/LayoutTests/fast/css/has-attachment.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css/has-attachment.html	2018-11-07 19:33:54 UTC (rev 237932)
@@ -0,0 +1,19 @@
+<!DOCTYPE html><!-- webkit-test-runner [ enableAttachmentElement=true ] -->
+<head>
+    <script src=""
+    <style>
+        img { clear: both; }
+        img:has-attachment { clear: none; }
+    </style>
+</head>
+<body>
+    <img id=target>
+    <script>
+        description("This tests the :has-attachment pseudoclass.");
+        var target = document.getElementById("target");
+        shouldBeEqualToString("getComputedStyle(target).clear", "both");
+        HTMLAttachmentElement.getAttachmentIdentifier(target);
+        shouldBeEqualToString("getComputedStyle(target).clear", "none");
+    </script>
+    <script src=""
+</body>

Modified: trunk/LayoutTests/platform/win/TestExpectations (237931 => 237932)


--- trunk/LayoutTests/platform/win/TestExpectations	2018-11-07 19:25:39 UTC (rev 237931)
+++ trunk/LayoutTests/platform/win/TestExpectations	2018-11-07 19:33:54 UTC (rev 237932)
@@ -625,6 +625,7 @@
 
 # TODO Attachment elements do not provide a custom renderer
 webkit.org/b/142260 fast/attachment [ Skip ]
+webkit.org/b/142260 fast/css/has-attachment.html [ Skip ]
 
 # TODO APNG is not supported
 webkit.org/b/142731 fast/images/animated-png.html [ Skip ]

Modified: trunk/Source/WebCore/ChangeLog (237931 => 237932)


--- trunk/Source/WebCore/ChangeLog	2018-11-07 19:25:39 UTC (rev 237931)
+++ trunk/Source/WebCore/ChangeLog	2018-11-07 19:33:54 UTC (rev 237932)
@@ -1,3 +1,45 @@
+2018-11-07  Dan Bernstein  <m...@apple.com>
+
+        Add a pseudoclass that matches img elements that are backed by an attachment
+        https://bugs.webkit.org/show_bug.cgi?id=191286
+        <rdar://problem/45823554>
+
+        Reviewed by Dean Jackson.
+
+        Test: fast/css/has-attachment.html
+
+        Added a :has-attachment pseudoclass, enabled only when the attachment element is enabled at
+        runtime, that matches elements (currently only img elements qualify) that have an attachment
+        element in their shadow DOM.
+
+        * css/CSSSelector.cpp:
+        (WebCore::CSSSelector::selectorText const): Handle the new PseudoClassHasAttachment value.
+        * css/CSSSelector.h: Added a new value to the PseudoClassType enum.
+
+        * css/SelectorChecker.cpp:
+        (WebCore::SelectorChecker::checkOne const): Check the new PseudoClassHasAttachment value
+          using the new hasAttachment test function.
+
+        * css/SelectorCheckerTestFunctions.h:
+        (WebCore::hasAttachment): Added. Tests if the element is an img element that has an
+          attachment.
+
+        * css/SelectorPseudoClassAndCompatibilityElementMap.in: Added has-attachment.
+
+        * css/parser/CSSParserContext.cpp:
+        (WebCore::CSSParserContext::CSSParserContext): Initialize new attachmentEnabled member based
+          on RuntimeEnabledFeatures.
+        (WebCore::operator==): Compare new attachmentEnabled member.
+        * css/parser/CSSParserContext.h:
+        (WebCore::CSSParserContextHash::hash): Include new attachmentEnabled member.
+
+        * css/parser/CSSSelectorParser.cpp:
+        (WebCore::CSSSelectorParser::consumePseudo): Reject :has-attachment if the attachment
+          element is not enabled.
+
+        * cssjit/SelectorCompiler.cpp:
+        (WebCore::SelectorCompiler::addPseudoClassType): Handle PseudoClassHasAttachment.
+
 2018-11-07  Don Olmstead  <don.olmst...@sony.com>
 
         Make generic MainThreadSharedTimer implementation

Modified: trunk/Source/WebCore/css/CSSSelector.cpp (237931 => 237932)


--- trunk/Source/WebCore/css/CSSSelector.cpp	2018-11-07 19:25:39 UTC (rev 237931)
+++ trunk/Source/WebCore/css/CSSSelector.cpp	2018-11-07 19:33:54 UTC (rev 237932)
@@ -505,6 +505,11 @@
                 str.appendLiteral(":future");
                 break;
 #endif
+#if ENABLE(ATTACHMENT_ELEMENT)
+            case CSSSelector::PseudoClassHasAttachment:
+                str.appendLiteral(":has-attachment");
+                break;
+#endif
             case CSSSelector::PseudoClassHorizontal:
                 str.appendLiteral(":horizontal");
                 break;

Modified: trunk/Source/WebCore/css/CSSSelector.h (237931 => 237932)


--- trunk/Source/WebCore/css/CSSSelector.h	2018-11-07 19:25:39 UTC (rev 237931)
+++ trunk/Source/WebCore/css/CSSSelector.h	2018-11-07 19:33:54 UTC (rev 237932)
@@ -162,6 +162,9 @@
 #endif
             PseudoClassHost,
             PseudoClassDefined,
+#if ENABLE(ATTACHMENT_ELEMENT)
+            PseudoClassHasAttachment,
+#endif
         };
 
         enum PseudoElementType {

Modified: trunk/Source/WebCore/css/SelectorChecker.cpp (237931 => 237932)


--- trunk/Source/WebCore/css/SelectorChecker.cpp	2018-11-07 19:25:39 UTC (rev 237931)
+++ trunk/Source/WebCore/css/SelectorChecker.cpp	2018-11-07 19:33:54 UTC (rev 237932)
@@ -1111,6 +1111,11 @@
             return false;
 #endif
 
+#if ENABLE(ATTACHMENT_ELEMENT)
+        case CSSSelector::PseudoClassHasAttachment:
+            return hasAttachment(element);
+#endif
+
         case CSSSelector::PseudoClassUnknown:
             ASSERT_NOT_REACHED();
             break;

Modified: trunk/Source/WebCore/css/SelectorCheckerTestFunctions.h (237931 => 237932)


--- trunk/Source/WebCore/css/SelectorCheckerTestFunctions.h	2018-11-07 19:25:39 UTC (rev 237931)
+++ trunk/Source/WebCore/css/SelectorCheckerTestFunctions.h	2018-11-07 19:33:54 UTC (rev 237932)
@@ -34,6 +34,10 @@
 #include "ScrollbarTheme.h"
 #include <wtf/Compiler.h>
 
+#if ENABLE(ATTACHMENT_ELEMENT)
+#include "HTMLAttachmentElement.h"
+#endif
+
 #if ENABLE(VIDEO_TRACK)
 #include "WebVTTElement.h"
 #endif
@@ -130,6 +134,13 @@
     return !page->focusController().isActive();
 }
 
+#if ENABLE(ATTACHMENT_ELEMENT)
+ALWAYS_INLINE bool hasAttachment(const Element& element)
+{
+    return is<HTMLImageElement>(element) && downcast<HTMLImageElement>(element).attachmentElement();
+}
+#endif
+
 ALWAYS_INLINE bool containslanguageSubtagMatchingRange(StringView language, StringView range, unsigned languageLength, unsigned& position)
 {
     unsigned languageSubtagsStartIndex = position;

Modified: trunk/Source/WebCore/css/SelectorPseudoClassAndCompatibilityElementMap.in (237931 => 237932)


--- trunk/Source/WebCore/css/SelectorPseudoClassAndCompatibilityElementMap.in	2018-11-07 19:25:39 UTC (rev 237931)
+++ trunk/Source/WebCore/css/SelectorPseudoClassAndCompatibilityElementMap.in	2018-11-07 19:33:54 UTC (rev 237932)
@@ -28,6 +28,9 @@
 first-of-type
 focus
 focus-within
+#if ENABLE(ATTACHMENT_ELEMENT)
+has-attachment
+#endif
 horizontal
 host, PseudoClassHost, PseudoElementUnknown
 hover

Modified: trunk/Source/WebCore/css/parser/CSSParserContext.cpp (237931 => 237932)


--- trunk/Source/WebCore/css/parser/CSSParserContext.cpp	2018-11-07 19:25:39 UTC (rev 237931)
+++ trunk/Source/WebCore/css/parser/CSSParserContext.cpp	2018-11-07 19:33:54 UTC (rev 237932)
@@ -28,6 +28,7 @@
 
 #include "Document.h"
 #include "Page.h"
+#include "RuntimeEnabledFeatures.h"
 #include "Settings.h"
 #include <wtf/NeverDestroyed.h>
 
@@ -68,6 +69,9 @@
     springTimingFunctionEnabled = document.settings().springTimingFunctionEnabled();
     constantPropertiesEnabled = document.settings().constantPropertiesEnabled();
     colorFilterEnabled = document.settings().colorFilterEnabled();
+#if ENABLE(ATTACHMENT_ELEMENT)
+    attachmentEnabled = RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled();
+#endif
     deferredCSSParserEnabled = document.settings().deferredCSSParserEnabled();
     useSystemAppearance = document.page() ? document.page()->useSystemAppearance() : false;
 
@@ -94,6 +98,9 @@
         && a.springTimingFunctionEnabled == b.springTimingFunctionEnabled
         && a.constantPropertiesEnabled == b.constantPropertiesEnabled
         && a.colorFilterEnabled == b.colorFilterEnabled
+#if ENABLE(ATTACHMENT_ELEMENT)
+        && a.attachmentEnabled == b.attachmentEnabled
+#endif
         && a.deferredCSSParserEnabled == b.deferredCSSParserEnabled
         && a.hasDocumentSecurityOrigin == b.hasDocumentSecurityOrigin
         && a.useSystemAppearance == b.useSystemAppearance;

Modified: trunk/Source/WebCore/css/parser/CSSParserContext.h (237931 => 237932)


--- trunk/Source/WebCore/css/parser/CSSParserContext.h	2018-11-07 19:25:39 UTC (rev 237931)
+++ trunk/Source/WebCore/css/parser/CSSParserContext.h	2018-11-07 19:33:54 UTC (rev 237932)
@@ -55,6 +55,9 @@
     bool springTimingFunctionEnabled { false };
     bool constantPropertiesEnabled { false };
     bool colorFilterEnabled { false };
+#if ENABLE(ATTACHMENT_ELEMENT)
+    bool attachmentEnabled { false };
+#endif
     bool deferredCSSParserEnabled { false };
     
     // This is only needed to support getMatchedCSSRules.
@@ -98,7 +101,10 @@
             & key.deferredCSSParserEnabled                  << 8
             & key.hasDocumentSecurityOrigin                 << 9
             & key.useSystemAppearance                       << 10
-            & key.mode                                      << 11; // Keep this last.
+#if ENABLE(ATTACHMENT_ELEMENT)
+            & key.attachmentEnabled                         << 11
+#endif
+            & key.mode                                      << 12; // Keep this last.
         hash ^= WTF::intHash(bits);
         return hash;
     }

Modified: trunk/Source/WebCore/css/parser/CSSSelectorParser.cpp (237931 => 237932)


--- trunk/Source/WebCore/css/parser/CSSSelectorParser.cpp	2018-11-07 19:25:39 UTC (rev 237931)
+++ trunk/Source/WebCore/css/parser/CSSSelectorParser.cpp	2018-11-07 19:33:54 UTC (rev 237932)
@@ -493,9 +493,13 @@
     auto lowercasedValue = token.value().convertToASCIILowercase();
     auto value = StringView { lowercasedValue };
 
-    if (colons == 1)
+    if (colons == 1) {
         selector = std::unique_ptr<CSSParserSelector>(CSSParserSelector::parsePseudoClassSelectorFromStringView(value));
-    else {
+#if ENABLE(ATTACHMENT_ELEMENT)
+        if (!m_context.attachmentEnabled && selector && selector->match() == CSSSelector::PseudoClass && selector->pseudoClassType() == CSSSelector::PseudoClassHasAttachment)
+            return nullptr;
+#endif
+    } else {
         selector = std::unique_ptr<CSSParserSelector>(CSSParserSelector::parsePseudoElementSelectorFromStringView(value));
 #if ENABLE(VIDEO_TRACK)
         // Treat the ident version of cue as PseudoElementWebkitCustom.

Modified: trunk/Source/WebCore/cssjit/SelectorCompiler.cpp (237931 => 237932)


--- trunk/Source/WebCore/cssjit/SelectorCompiler.cpp	2018-11-07 19:25:39 UTC (rev 237931)
+++ trunk/Source/WebCore/cssjit/SelectorCompiler.cpp	2018-11-07 19:33:54 UTC (rev 237932)
@@ -619,6 +619,12 @@
         return FunctionType::SimpleSelectorChecker;
 #endif
 
+#if ENABLE(ATTACHMENT_ELEMENT)
+    case CSSSelector::PseudoClassHasAttachment:
+        fragment.unoptimizedPseudoClasses.append(JSC::FunctionPtr<CSSOperationPtrTag>(hasAttachment));
+        return FunctionType::SimpleSelectorChecker;
+#endif
+
     // These pseudo-classes only have meaning with scrollbars.
     case CSSSelector::PseudoClassHorizontal:
     case CSSSelector::PseudoClassVertical:
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to