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

Changeset 275076 in webkit


Ignore:
Timestamp:
Mar 25, 2021, 8:27:16 PM (5 years ago)
Author:
Wenson Hsieh
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.
Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r275075 r275076  
     12021-03-25  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Don't add `-webkit-user-select: none;` on image elements with `draggable=true`
     4        https://bugs.webkit.org/show_bug.cgi?id=223774
     5        <rdar://problem/75860124>
     6
     7        Reviewed by Tim Horton.
     8
     9        * fast/images/image-extraction/mac/select-word-in-draggable-image-overlay-expected-mismatch.html: Added.
     10        * fast/images/image-extraction/mac/select-word-in-draggable-image-overlay.html: Added.
     11
    1122021-03-25  Kyle Piddington  <kpiddington@apple.com>
    213
  • trunk/Source/WebCore/ChangeLog

    r275072 r275076  
     12021-03-25  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Don't add `-webkit-user-select: none;` on image elements with `draggable=true`
     4        https://bugs.webkit.org/show_bug.cgi?id=223774
     5        <rdar://problem/75860124>
     6
     7        Reviewed by Tim Horton.
     8
     9        Avoid adding this presentational CSS style property for image elements marked with `draggable=true`. Since
     10        image elements are already draggable by default and mouse drags over image elements do not trigger text
     11        selection, it's not necessary for the user agent to add this style property. See below for more details.
     12
     13        Test: fast/images/image-extraction/mac/select-word-in-draggable-image-overlay.html
     14
     15        * html/HTMLElement.cpp:
     16        (WebCore::HTMLElement::collectStyleForPresentationAttribute):
     17
     18        If the element is already draggable (barring HTML attributes), don't additionally disable text selection inside
     19        the element when we additionally have `draggable=true` set on the element.
     20
     21        (WebCore::HTMLElement::draggable const):
     22
     23        Refactor this to consult `isDraggableIgnoringAttributes()` when determining whether to check if the `draggable`
     24        attribute value is not `"false"` vs. equal to `"true"`. In the case where the element is already draggable, we
     25        only return `false` here if `draggable=false` is explicitly set.
     26
     27        * html/HTMLElement.h:
     28        (WebCore::HTMLElement::isDraggableIgnoringAttributes const):
     29        * html/HTMLImageElement.cpp:
     30        (WebCore::HTMLImageElement::draggable const): Deleted.
     31        * html/HTMLImageElement.h:
     32
     33        Override `isDraggableIgnoringAttributes` and return `true`.
     34
    1352021-03-25  Wenson Hsieh  <wenson_hsieh@apple.com>
    236
  • trunk/Source/WebCore/html/HTMLElement.cpp

    r275072 r275076  
    211211        if (equalLettersIgnoringASCIICase(value, "true")) {
    212212            addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitUserDrag, CSSValueElement);
    213             addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitUserSelect, CSSValueNone);
     213            if (!isDraggableIgnoringAttributes())
     214                addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitUserSelect, CSSValueNone);
    214215        } else if (equalLettersIgnoringASCIICase(value, "false"))
    215216            addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitUserDrag, CSSValueNone);
     
    710711bool HTMLElement::draggable() const
    711712{
    712     return equalLettersIgnoringASCIICase(attributeWithoutSynchronization(draggableAttr), "true");
     713    auto& value = attributeWithoutSynchronization(draggableAttr);
     714    if (isDraggableIgnoringAttributes())
     715        return !equalLettersIgnoringASCIICase(value, "false");
     716
     717    return equalLettersIgnoringASCIICase(value, "true");
    713718}
    714719
  • trunk/Source/WebCore/html/HTMLElement.h

    r275072 r275076  
    6464    virtual bool draggable() const;
    6565    WEBCORE_EXPORT void setDraggable(bool);
     66    virtual bool isDraggableIgnoringAttributes() const { return false; }
    6667
    6768    WEBCORE_EXPORT bool spellcheck() const;
  • trunk/Source/WebCore/html/HTMLImageElement.cpp

    r273622 r275076  
    559559}
    560560
    561 bool HTMLImageElement::draggable() const
    562 {
    563     // Image elements are draggable by default.
    564     return !equalLettersIgnoringASCIICase(attributeWithoutSynchronization(draggableAttr), "false");
    565 }
    566 
    567561void HTMLImageElement::setHeight(unsigned value)
    568562{
  • trunk/Source/WebCore/html/HTMLImageElement.h

    r272117 r275076  
    162162    String completeURLsInAttributeValue(const URL& base, const Attribute&) const override;
    163163
    164     bool draggable() const override;
     164    bool isDraggableIgnoringAttributes() const final { return true; }
    165165
    166166    void addSubresourceAttributeURLs(ListHashSet<URL>&) const override;
Note: See TracChangeset for help on using the changeset viewer.