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

Changeset 286021 in webkit


Ignore:
Timestamp:
Nov 18, 2021, 12:48:15 PM (5 years ago)
Author:
Wenson Hsieh
Message:

[macOS] [Live Text] Avoid analyzing images in editable content
https://bugs.webkit.org/show_bug.cgi?id=233317

Reviewed by Megan Gardner.

Source/WebCore:

Make macOS Live Text behavior consistent with iOS, and avoid automatically triggering text recognition (Live
Text) when hovering over images in editable content. In addition to platform consistency, this also allows us to
avoid handling both image service controls and image overlay content inside editable image elements in Mail
compose.

Test: fast/images/text-recognition/mac/text-recognition-candidates.html

  • page/EventHandler.cpp:

(WebCore::EventHandler::textRecognitionCandidateElement const):

Add the editability check here and return null.

  • page/EventHandler.h:

Drive-by code cleanup -- move textRecognitionCandidateElement behind the ENABLE(IMAGE_ANALYSIS) compile-time
flag, since it's only used from image analysis code.

  • testing/Internals.cpp:

(WebCore::Internals::textRecognitionCandidate const):

Add an internal testing hook to query the current text recognition candidate element (i.e. a suitable image that
is being hovered, or otherwise null).

  • testing/Internals.h:
  • testing/Internals.idl:

LayoutTests:

Add a layout test to exercise the change.

  • fast/images/text-recognition/mac/text-recognition-candidates-expected.txt: Added.
  • fast/images/text-recognition/mac/text-recognition-candidates.html: Added.
Location:
trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r286011 r286021  
     12021-11-18  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [macOS] [Live Text] Avoid analyzing images in editable content
     4        https://bugs.webkit.org/show_bug.cgi?id=233317
     5
     6        Reviewed by Megan Gardner.
     7
     8        Add a layout test to exercise the change.
     9
     10        * fast/images/text-recognition/mac/text-recognition-candidates-expected.txt: Added.
     11        * fast/images/text-recognition/mac/text-recognition-candidates.html: Added.
     12
    1132021-11-18  Yoshiaki Jitsukawa  <yoshiaki.jitsukawa@sony.com>
    214
  • trunk/Source/WebCore/ChangeLog

    r286019 r286021  
     12021-11-18  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [macOS] [Live Text] Avoid analyzing images in editable content
     4        https://bugs.webkit.org/show_bug.cgi?id=233317
     5
     6        Reviewed by Megan Gardner.
     7
     8        Make macOS Live Text behavior consistent with iOS, and avoid automatically triggering text recognition (Live
     9        Text) when hovering over images in editable content. In addition to platform consistency, this also allows us to
     10        avoid handling both image service controls and image overlay content inside editable image elements in Mail
     11        compose.
     12
     13        Test: fast/images/text-recognition/mac/text-recognition-candidates.html
     14
     15        * page/EventHandler.cpp:
     16        (WebCore::EventHandler::textRecognitionCandidateElement const):
     17
     18        Add the editability check here and return null.
     19
     20        * page/EventHandler.h:
     21
     22        Drive-by code cleanup -- move `textRecognitionCandidateElement` behind the `ENABLE(IMAGE_ANALYSIS)` compile-time
     23        flag, since it's only used from image analysis code.
     24
     25        * testing/Internals.cpp:
     26        (WebCore::Internals::textRecognitionCandidate const):
     27
     28        Add an internal testing hook to query the current text recognition candidate element (i.e. a suitable image that
     29        is being hovered, or otherwise null).
     30
     31        * testing/Internals.h:
     32        * testing/Internals.idl:
     33
    1342021-11-18  Antoine Quint  <graouts@webkit.org>
    235
  • trunk/Source/WebCore/page/EventHandler.cpp

    r285655 r286021  
    25252525}
    25262526
     2527#if ENABLE(IMAGE_ANALYSIS)
     2528
    25272529RefPtr<Element> EventHandler::textRecognitionCandidateElement() const
    25282530{
     
    25362538        return nullptr;
    25372539
     2540    if (candidateElement->hasEditableStyle())
     2541        return nullptr;
     2542
    25382543    auto renderer = candidateElement->renderer();
    25392544    if (!is<RenderImage>(renderer))
     
    25522557    return candidateElement;
    25532558}
     2559
     2560#endif // ENABLE(IMAGE_ANALYSIS)
    25542561
    25552562void EventHandler::updateMouseEventTargetNode(const AtomString& eventType, Node* targetNode, const PlatformMouseEvent& platformMouseEvent, FireMouseOverOut fireMouseOverOut)
  • trunk/Source/WebCore/page/EventHandler.h

    r285367 r286021  
    355355    WEBCORE_EXPORT void invalidateClick();
    356356
     357#if ENABLE(IMAGE_ANALYSIS)
     358    WEBCORE_EXPORT RefPtr<Element> textRecognitionCandidateElement() const;
     359#endif
     360
    357361    static bool scrollableAreaCanHandleEvent(const PlatformWheelEvent&, ScrollableArea&);
    358362
     
    362366    static const Seconds TextDragDelay;
    363367#endif
    364 
    365     RefPtr<Element> textRecognitionCandidateElement() const;
    366368
    367369    bool eventActivatedView(const PlatformMouseEvent&) const;
  • trunk/Source/WebCore/testing/Internals.cpp

    r286012 r286021  
    57765776}
    57775777
    5778 #endif // ENABLE(IMAGE_ANALYSIS)
    5779 
    57805778void Internals::requestTextRecognition(Element& element, RefPtr<VoidCallback>&& callback)
    57815779{
     
    57865784    }
    57875785
    5788 #if ENABLE(IMAGE_ANALYSIS)
    57895786    page->chrome().client().requestTextRecognition(element, { }, [callback = WTFMove(callback)] (auto&&) {
    57905787        if (callback)
    57915788            callback->handleEvent();
    57925789    });
    5793 #else
    5794     UNUSED_PARAM(element);
    5795     if (callback)
    5796         callback->handleEvent();
    5797 #endif
    5798 }
     5790}
     5791
     5792RefPtr<Element> Internals::textRecognitionCandidate() const
     5793{
     5794    if (RefPtr frame = contextDocument()->frame())
     5795        return frame->eventHandler().textRecognitionCandidateElement();
     5796
     5797    return nullptr;
     5798}
     5799
     5800#endif // ENABLE(IMAGE_ANALYSIS)
    57995801
    58005802void Internals::installImageOverlay(Element& element, Vector<ImageOverlayLine>&& lines)
  • trunk/Source/WebCore/testing/Internals.h

    r285984 r286021  
    920920    };
    921921    void installImageOverlay(Element&, Vector<ImageOverlayLine>&&);
     922
     923#if ENABLE(IMAGE_ANALYSIS)
    922924    void requestTextRecognition(Element&, RefPtr<VoidCallback>&&);
     925    RefPtr<Element> textRecognitionCandidate() const;
     926#endif
    923927
    924928    bool isSystemPreviewLink(Element&) const;
  • trunk/Source/WebCore/testing/Internals.idl

    r285610 r286021  
    940940    boolean isSystemPreviewImage(Element element);
    941941
    942     undefined requestTextRecognition(Element element, VoidCallback callback);
     942    [Conditional=IMAGE_ANALYSIS] readonly attribute Element? textRecognitionCandidate;
     943    [Conditional=IMAGE_ANALYSIS] undefined requestTextRecognition(Element element, VoidCallback callback);
    943944    undefined installImageOverlay(Element element, sequence<ImageOverlayLine> lines);
    944945
Note: See TracChangeset for help on using the changeset viewer.