Title: [275076] trunk
Revision
275076
Author
[email protected]
Date
2021-03-25 20:27:16 -0700 (Thu, 25 Mar 2021)

Log Message

Don't add `-webkit-user-select: none;` on image elements with `draggable=true`
https://bugs.webkit.org/show_bug.cgi?id=223774
<rdar://problem/75860124>

Reviewed by Tim Horton.

Source/WebCore:

Avoid adding this presentational CSS style property for image elements marked with `draggable=true`. Since
image elements are already draggable by default and mouse drags over image elements do not trigger text
selection, it's not necessary for the user agent to add this style property. See below for more details.

Test: fast/images/image-extraction/mac/select-word-in-draggable-image-overlay.html

* html/HTMLElement.cpp:
(WebCore::HTMLElement::collectStyleForPresentationAttribute):

If the element is already draggable (barring HTML attributes), don't additionally disable text selection inside
the element when we additionally have `draggable=true` set on the element.

(WebCore::HTMLElement::draggable const):

Refactor this to consult `isDraggableIgnoringAttributes()` when determining whether to check if the `draggable`
attribute value is not `"false"` vs. equal to `"true"`. In the case where the element is already draggable, we
only return `false` here if `draggable=false` is explicitly set.

* html/HTMLElement.h:
(WebCore::HTMLElement::isDraggableIgnoringAttributes const):
* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::draggable const): Deleted.
* html/HTMLImageElement.h:

Override `isDraggableIgnoringAttributes` and return `true`.

LayoutTests:

* fast/images/image-extraction/mac/select-word-in-draggable-image-overlay-expected-mismatch.html: Added.
* fast/images/image-extraction/mac/select-word-in-draggable-image-overlay.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (275075 => 275076)


--- trunk/LayoutTests/ChangeLog	2021-03-26 03:20:14 UTC (rev 275075)
+++ trunk/LayoutTests/ChangeLog	2021-03-26 03:27:16 UTC (rev 275076)
@@ -1,3 +1,14 @@
+2021-03-25  Wenson Hsieh  <[email protected]>
+
+        Don't add `-webkit-user-select: none;` on image elements with `draggable=true`
+        https://bugs.webkit.org/show_bug.cgi?id=223774
+        <rdar://problem/75860124>
+
+        Reviewed by Tim Horton.
+
+        * fast/images/image-extraction/mac/select-word-in-draggable-image-overlay-expected-mismatch.html: Added.
+        * fast/images/image-extraction/mac/select-word-in-draggable-image-overlay.html: Added.
+
 2021-03-25  Kyle Piddington  <[email protected]>
 
         [Metal ANGLE] fast/canvas/webgl/out-of-bounds-simulated-vertexAttrib0-drawArrays.html causes GPURestarts on some machines

Added: trunk/LayoutTests/fast/images/image-extraction/mac/select-word-in-draggable-image-overlay-expected-mismatch.html (0 => 275076)


--- trunk/LayoutTests/fast/images/image-extraction/mac/select-word-in-draggable-image-overlay-expected-mismatch.html	                        (rev 0)
+++ trunk/LayoutTests/fast/images/image-extraction/mac/select-word-in-draggable-image-overlay-expected-mismatch.html	2021-03-26 03:27:16 UTC (rev 275076)
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+img {
+    position: absolute;
+    top: 0;
+    left: 0;
+}
+</style>
+</head>
+<body>
+<img src=""
+</body>
+</html>
\ No newline at end of file

Added: trunk/LayoutTests/fast/images/image-extraction/mac/select-word-in-draggable-image-overlay.html (0 => 275076)


--- trunk/LayoutTests/fast/images/image-extraction/mac/select-word-in-draggable-image-overlay.html	                        (rev 0)
+++ trunk/LayoutTests/fast/images/image-extraction/mac/select-word-in-draggable-image-overlay.html	2021-03-26 03:27:16 UTC (rev 275076)
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+<style>
+img {
+    position: absolute;
+    top: 0;
+    left: 0;
+}
+</style>
+</head>
+<body>
+<img draggable="true" src=""
+<script>
+addEventListener("load", () => {
+    internals.installImageOverlay(document.querySelector("img"), [
+        {
+            text : "hello",
+            topLeft : new DOMPointReadOnly(0, 0),
+            topRight : new DOMPointReadOnly(1, 0),
+            bottomRight : new DOMPointReadOnly(1, 0.5),
+            bottomLeft : new DOMPointReadOnly(0, 0.5),
+        }
+    ]);
+    eventSender.mouseMoveTo(50, 300);
+    eventSender.mouseDown();
+    eventSender.mouseMoveTo(350, 300);
+    eventSender.mouseUp();
+});
+</script>
+</body>
+</html>
\ No newline at end of file

Modified: trunk/Source/WebCore/ChangeLog (275075 => 275076)


--- trunk/Source/WebCore/ChangeLog	2021-03-26 03:20:14 UTC (rev 275075)
+++ trunk/Source/WebCore/ChangeLog	2021-03-26 03:27:16 UTC (rev 275076)
@@ -1,5 +1,39 @@
 2021-03-25  Wenson Hsieh  <[email protected]>
 
+        Don't add `-webkit-user-select: none;` on image elements with `draggable=true`
+        https://bugs.webkit.org/show_bug.cgi?id=223774
+        <rdar://problem/75860124>
+
+        Reviewed by Tim Horton.
+
+        Avoid adding this presentational CSS style property for image elements marked with `draggable=true`. Since
+        image elements are already draggable by default and mouse drags over image elements do not trigger text
+        selection, it's not necessary for the user agent to add this style property. See below for more details.
+
+        Test: fast/images/image-extraction/mac/select-word-in-draggable-image-overlay.html
+
+        * html/HTMLElement.cpp:
+        (WebCore::HTMLElement::collectStyleForPresentationAttribute):
+
+        If the element is already draggable (barring HTML attributes), don't additionally disable text selection inside
+        the element when we additionally have `draggable=true` set on the element.
+
+        (WebCore::HTMLElement::draggable const):
+
+        Refactor this to consult `isDraggableIgnoringAttributes()` when determining whether to check if the `draggable`
+        attribute value is not `"false"` vs. equal to `"true"`. In the case where the element is already draggable, we
+        only return `false` here if `draggable=false` is explicitly set.
+
+        * html/HTMLElement.h:
+        (WebCore::HTMLElement::isDraggableIgnoringAttributes const):
+        * html/HTMLImageElement.cpp:
+        (WebCore::HTMLImageElement::draggable const): Deleted.
+        * html/HTMLImageElement.h:
+
+        Override `isDraggableIgnoringAttributes` and return `true`.
+
+2021-03-25  Wenson Hsieh  <[email protected]>
+
         It should be possible to drag images with overlay content
         https://bugs.webkit.org/show_bug.cgi?id=223766
         <rdar://problem/75856030>

Modified: trunk/Source/WebCore/html/HTMLElement.cpp (275075 => 275076)


--- trunk/Source/WebCore/html/HTMLElement.cpp	2021-03-26 03:20:14 UTC (rev 275075)
+++ trunk/Source/WebCore/html/HTMLElement.cpp	2021-03-26 03:27:16 UTC (rev 275076)
@@ -210,7 +210,8 @@
     } else if (name == draggableAttr) {
         if (equalLettersIgnoringASCIICase(value, "true")) {
             addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitUserDrag, CSSValueElement);
-            addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitUserSelect, CSSValueNone);
+            if (!isDraggableIgnoringAttributes())
+                addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitUserSelect, CSSValueNone);
         } else if (equalLettersIgnoringASCIICase(value, "false"))
             addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitUserDrag, CSSValueNone);
     } else if (name == dirAttr) {
@@ -709,7 +710,11 @@
 
 bool HTMLElement::draggable() const
 {
-    return equalLettersIgnoringASCIICase(attributeWithoutSynchronization(draggableAttr), "true");
+    auto& value = attributeWithoutSynchronization(draggableAttr);
+    if (isDraggableIgnoringAttributes())
+        return !equalLettersIgnoringASCIICase(value, "false");
+
+    return equalLettersIgnoringASCIICase(value, "true");
 }
 
 void HTMLElement::setDraggable(bool value)

Modified: trunk/Source/WebCore/html/HTMLElement.h (275075 => 275076)


--- trunk/Source/WebCore/html/HTMLElement.h	2021-03-26 03:20:14 UTC (rev 275075)
+++ trunk/Source/WebCore/html/HTMLElement.h	2021-03-26 03:27:16 UTC (rev 275076)
@@ -63,6 +63,7 @@
 
     virtual bool draggable() const;
     WEBCORE_EXPORT void setDraggable(bool);
+    virtual bool isDraggableIgnoringAttributes() const { return false; }
 
     WEBCORE_EXPORT bool spellcheck() const;
     WEBCORE_EXPORT void setSpellcheck(bool);

Modified: trunk/Source/WebCore/html/HTMLImageElement.cpp (275075 => 275076)


--- trunk/Source/WebCore/html/HTMLImageElement.cpp	2021-03-26 03:20:14 UTC (rev 275075)
+++ trunk/Source/WebCore/html/HTMLImageElement.cpp	2021-03-26 03:27:16 UTC (rev 275076)
@@ -558,12 +558,6 @@
     return attributeWithoutSynchronization(altAttr);
 }
 
-bool HTMLImageElement::draggable() const
-{
-    // Image elements are draggable by default.
-    return !equalLettersIgnoringASCIICase(attributeWithoutSynchronization(draggableAttr), "false");
-}
-
 void HTMLImageElement::setHeight(unsigned value)
 {
     setUnsignedIntegralAttribute(heightAttr, value);

Modified: trunk/Source/WebCore/html/HTMLImageElement.h (275075 => 275076)


--- trunk/Source/WebCore/html/HTMLImageElement.h	2021-03-26 03:20:14 UTC (rev 275075)
+++ trunk/Source/WebCore/html/HTMLImageElement.h	2021-03-26 03:27:16 UTC (rev 275076)
@@ -161,7 +161,7 @@
     bool attributeContainsURL(const Attribute&) const override;
     String completeURLsInAttributeValue(const URL& base, const Attribute&) const override;
 
-    bool draggable() const override;
+    bool isDraggableIgnoringAttributes() const final { return true; }
 
     void addSubresourceAttributeURLs(ListHashSet<URL>&) const override;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to