Changeset 279059 in webkit


Ignore:
Timestamp:
Jun 20, 2021 2:31:34 PM (13 months ago)
Author:
Wenson Hsieh
Message:

[Live Text] Mouse events should only trigger text recognition if the cursor is moving
https://bugs.webkit.org/show_bug.cgi?id=227181
rdar://79469827

Reviewed by Tim Horton.

Source/WebCore:

Make a slight adjustment to how we trigger the text recognition timer when hovering over images; instead of
allowing any non-synthetic mouse event to kick off the timer, limit it to only mouse events with horizontal or
vertical movement deltas.

To implement this, we remove some ENABLE(POINTER_LOCK) guards around PlatformMouseEvent's movement delta, and
check whether the movement delta is nonzero in EventHandler when determining whether to start the text
recognition timer.

  • page/EventHandler.cpp:

(WebCore::EventHandler::updateMouseEventTargetNode):

Check for a nonzero movement delta in place of the synthetic click type; since all synthetic mouse events are
created with no horizontal or vertical delta, since new movement delta check obviates the need for checking the
synthetic click type.

Additionally, we invert the conditional here so that if any mouse events are detected over content that is not
an image, we'll immediately stop the timer; however, if the mouse event is over an image, we'll only kick off
the timer if the movement delta is additionally nonzero.

  • platform/PlatformMouseEvent.h:

(WebCore::PlatformMouseEvent::globalPosition const):
(WebCore::PlatformMouseEvent::movementDelta const):

  • platform/mac/PlatformEventFactoryMac.mm:

(WebCore::PlatformMouseEventBuilder::PlatformMouseEventBuilder):

Source/WebKit:

Populate the deltaX and deltaY members of the platform mouse event on iOS, when using a trackpad. This
allows the adjusted logic in EventHandler to apply to iPadOS when using a trackpad as well (see WebCore
ChangeLog for more information).

  • Shared/WebEventConversion.cpp:

(WebKit::WebKit2PlatformMouseEvent::WebKit2PlatformMouseEvent):

  • UIProcess/ios/WKMouseGestureRecognizer.mm:

(-[WKMouseGestureRecognizer createMouseEventWithType:wasCancelled:]):

Location:
trunk/Source
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r279057 r279059  
     12021-06-20  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [Live Text] Mouse events should only trigger text recognition if the cursor is moving
     4        https://bugs.webkit.org/show_bug.cgi?id=227181
     5        rdar://79469827
     6
     7        Reviewed by Tim Horton.
     8
     9        Make a slight adjustment to how we trigger the text recognition timer when hovering over images; instead of
     10        allowing any non-synthetic mouse event to kick off the timer, limit it to only mouse events with horizontal or
     11        vertical movement deltas.
     12
     13        To implement this, we remove some `ENABLE(POINTER_LOCK)` guards around PlatformMouseEvent's movement delta, and
     14        check whether the movement delta is nonzero in EventHandler when determining whether to start the text
     15        recognition timer.
     16
     17        * page/EventHandler.cpp:
     18        (WebCore::EventHandler::updateMouseEventTargetNode):
     19
     20        Check for a nonzero movement delta in place of the synthetic click type; since all synthetic mouse events are
     21        created with no horizontal or vertical delta, since new movement delta check obviates the need for checking the
     22        synthetic click type.
     23
     24        Additionally, we invert the conditional here so that if any mouse events are detected over content that is not
     25        an image, we'll immediately stop the timer; however, if the mouse event is over an image, we'll only kick off
     26        the timer if the movement delta is additionally nonzero.
     27
     28        * platform/PlatformMouseEvent.h:
     29        (WebCore::PlatformMouseEvent::globalPosition const):
     30        (WebCore::PlatformMouseEvent::movementDelta const):
     31        * platform/mac/PlatformEventFactoryMac.mm:
     32        (WebCore::PlatformMouseEventBuilder::PlatformMouseEventBuilder):
     33
    1342021-06-20  Alan Bujtas  <zalan@apple.com>
    235
  • trunk/Source/WebCore/page/EventHandler.cpp

    r278964 r279059  
    25412541
    25422542#if ENABLE(IMAGE_ANALYSIS)
    2543     if (platformMouseEvent.syntheticClickType() == NoTap) {
    2544         if (m_elementUnderMouse && is<RenderImage>(m_elementUnderMouse->renderer()))
    2545             m_textRecognitionHoverTimer.restart();
    2546         else
    2547             m_textRecognitionHoverTimer.stop();
    2548     }
     2543    if (!m_elementUnderMouse || !is<RenderImage>(m_elementUnderMouse->renderer()))
     2544        m_textRecognitionHoverTimer.stop();
     2545    else if (!platformMouseEvent.movementDelta().isZero())
     2546        m_textRecognitionHoverTimer.restart();
    25492547#endif // ENABLE(IMAGE_ANALYSIS)
    25502548
  • trunk/Source/WebCore/platform/PlatformMouseEvent.h

    r270582 r279059  
    6666        const IntPoint& position() const { return m_position; }
    6767        const IntPoint& globalPosition() const { return m_globalPosition; }
    68 #if ENABLE(POINTER_LOCK)
    6968        const IntPoint& movementDelta() const { return m_movementDelta; }
    70 #endif
    7169
    7270        MouseButton button() const { return m_button; }
     
    9694        IntPoint m_position;
    9795        IntPoint m_globalPosition;
    98 #if ENABLE(POINTER_LOCK)
    9996        IntPoint m_movementDelta;
    100 #endif
    10197        double m_force { 0 };
    10298        PointerID m_pointerId { mousePointerID };
  • trunk/Source/WebCore/platform/mac/PlatformEventFactoryMac.mm

    r269659 r279059  
    729729        m_buttons = currentlyPressedMouseButtons();
    730730        m_clickCount = clickCountForEvent(event);
    731 #if ENABLE(POINTER_LOCK)
    732731        m_movementDelta = IntPoint(event.deltaX, event.deltaY);
    733 #endif
    734732
    735733        m_force = 0;
  • trunk/Source/WebKit/ChangeLog

    r279045 r279059  
     12021-06-20  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [Live Text] Mouse events should only trigger text recognition if the cursor is moving
     4        https://bugs.webkit.org/show_bug.cgi?id=227181
     5        rdar://79469827
     6
     7        Reviewed by Tim Horton.
     8
     9        Populate the `deltaX` and `deltaY` members of the platform mouse event on iOS, when using a trackpad. This
     10        allows the adjusted logic in EventHandler to apply to iPadOS when using a trackpad as well (see WebCore
     11        ChangeLog for more information).
     12
     13        * Shared/WebEventConversion.cpp:
     14        (WebKit::WebKit2PlatformMouseEvent::WebKit2PlatformMouseEvent):
     15        * UIProcess/ios/WKMouseGestureRecognizer.mm:
     16        (-[WKMouseGestureRecognizer createMouseEventWithType:wasCancelled:]):
     17
    1182021-06-18  Brent Fulgham  <bfulgham@apple.com>
    219
  • trunk/Source/WebKit/Shared/WebEventConversion.cpp

    r270582 r279059  
    106106
    107107        m_position = webEvent.position();
    108 #if ENABLE(POINTER_LOCK)
    109108        m_movementDelta = WebCore::IntPoint(webEvent.deltaX(), webEvent.deltaY());
    110 #endif
    111109        m_globalPosition = webEvent.globalPosition();
    112110        m_clickCount = webEvent.clickCount();
  • trunk/Source/WebKit/UIProcess/ios/WKMouseGestureRecognizer.mm

    r278727 r279059  
    121121
    122122    WebCore::IntPoint point { [self locationInView:self.view] };
    123 
     123    auto delta = point - WebCore::IntPoint { [_currentTouch previousLocationInView:self.view] };
    124124    // UITouch's timestamp uses mach_absolute_time as its timebase, same as MonotonicTime.
    125125    auto timestamp = MonotonicTime::fromRawSeconds([_currentTouch timestamp]).approximateWallTime();
    126     return WTF::makeUnique<WebKit::NativeWebMouseEvent>(type, button, buttons, point, point, 0, 0, 0, [_currentTouch tapCount], modifiers, timestamp, 0, cancelled ? WebKit::GestureWasCancelled::Yes : WebKit::GestureWasCancelled::No);
     126    return WTF::makeUnique<WebKit::NativeWebMouseEvent>(type, button, buttons, point, point, delta.width(), delta.height(), 0, [_currentTouch tapCount], modifiers, timestamp, 0, cancelled ? WebKit::GestureWasCancelled::Yes : WebKit::GestureWasCancelled::No);
    127127}
    128128
Note: See TracChangeset for help on using the changeset viewer.