Title: [279059] trunk/Source
Revision
279059
Author
[email protected]
Date
2021-06-20 14:31:34 -0700 (Sun, 20 Jun 2021)

Log 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:]):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (279058 => 279059)


--- trunk/Source/WebCore/ChangeLog	2021-06-20 20:33:15 UTC (rev 279058)
+++ trunk/Source/WebCore/ChangeLog	2021-06-20 21:31:34 UTC (rev 279059)
@@ -1,3 +1,36 @@
+2021-06-20  Wenson Hsieh  <[email protected]>
+
+        [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.
+
+        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):
+
 2021-06-20  Alan Bujtas  <[email protected]>
 
         Move rectForPoint() static function out from the HitTestLocation class

Modified: trunk/Source/WebCore/page/EventHandler.cpp (279058 => 279059)


--- trunk/Source/WebCore/page/EventHandler.cpp	2021-06-20 20:33:15 UTC (rev 279058)
+++ trunk/Source/WebCore/page/EventHandler.cpp	2021-06-20 21:31:34 UTC (rev 279059)
@@ -2540,12 +2540,10 @@
     m_elementUnderMouse = targetElement;
 
 #if ENABLE(IMAGE_ANALYSIS)
-    if (platformMouseEvent.syntheticClickType() == NoTap) {
-        if (m_elementUnderMouse && is<RenderImage>(m_elementUnderMouse->renderer()))
-            m_textRecognitionHoverTimer.restart();
-        else
-            m_textRecognitionHoverTimer.stop();
-    }
+    if (!m_elementUnderMouse || !is<RenderImage>(m_elementUnderMouse->renderer()))
+        m_textRecognitionHoverTimer.stop();
+    else if (!platformMouseEvent.movementDelta().isZero())
+        m_textRecognitionHoverTimer.restart();
 #endif // ENABLE(IMAGE_ANALYSIS)
 
     if (auto* page = m_frame.page())

Modified: trunk/Source/WebCore/platform/PlatformMouseEvent.h (279058 => 279059)


--- trunk/Source/WebCore/platform/PlatformMouseEvent.h	2021-06-20 20:33:15 UTC (rev 279058)
+++ trunk/Source/WebCore/platform/PlatformMouseEvent.h	2021-06-20 21:31:34 UTC (rev 279059)
@@ -65,9 +65,7 @@
         // Use ScrollView::windowToContents() to convert it to into the contents of a given view.
         const IntPoint& position() const { return m_position; }
         const IntPoint& globalPosition() const { return m_globalPosition; }
-#if ENABLE(POINTER_LOCK)
         const IntPoint& movementDelta() const { return m_movementDelta; }
-#endif
 
         MouseButton button() const { return m_button; }
         unsigned short buttons() const { return m_buttons; }
@@ -95,9 +93,7 @@
 
         IntPoint m_position;
         IntPoint m_globalPosition;
-#if ENABLE(POINTER_LOCK)
         IntPoint m_movementDelta;
-#endif
         double m_force { 0 };
         PointerID m_pointerId { mousePointerID };
         String m_pointerType { "mouse"_s };

Modified: trunk/Source/WebCore/platform/mac/PlatformEventFactoryMac.mm (279058 => 279059)


--- trunk/Source/WebCore/platform/mac/PlatformEventFactoryMac.mm	2021-06-20 20:33:15 UTC (rev 279058)
+++ trunk/Source/WebCore/platform/mac/PlatformEventFactoryMac.mm	2021-06-20 21:31:34 UTC (rev 279059)
@@ -728,9 +728,7 @@
         m_button = mouseButtonForEvent(event);
         m_buttons = currentlyPressedMouseButtons();
         m_clickCount = clickCountForEvent(event);
-#if ENABLE(POINTER_LOCK)
         m_movementDelta = IntPoint(event.deltaX, event.deltaY);
-#endif
 
         m_force = 0;
         int stage = eventIsPressureEvent ? event.stage : correspondingPressureEvent.stage;

Modified: trunk/Source/WebKit/ChangeLog (279058 => 279059)


--- trunk/Source/WebKit/ChangeLog	2021-06-20 20:33:15 UTC (rev 279058)
+++ trunk/Source/WebKit/ChangeLog	2021-06-20 21:31:34 UTC (rev 279059)
@@ -1,3 +1,20 @@
+2021-06-20  Wenson Hsieh  <[email protected]>
+
+        [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.
+
+        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:]):
+
 2021-06-18  Brent Fulgham  <[email protected]>
 
         Clear state after process crash so that we know to re-issue sandbox extensions

Modified: trunk/Source/WebKit/Shared/WebEventConversion.cpp (279058 => 279059)


--- trunk/Source/WebKit/Shared/WebEventConversion.cpp	2021-06-20 20:33:15 UTC (rev 279058)
+++ trunk/Source/WebKit/Shared/WebEventConversion.cpp	2021-06-20 21:31:34 UTC (rev 279059)
@@ -105,9 +105,7 @@
         m_buttons = webEvent.buttons();
 
         m_position = webEvent.position();
-#if ENABLE(POINTER_LOCK)
         m_movementDelta = WebCore::IntPoint(webEvent.deltaX(), webEvent.deltaY());
-#endif
         m_globalPosition = webEvent.globalPosition();
         m_clickCount = webEvent.clickCount();
 #if PLATFORM(MAC)

Modified: trunk/Source/WebKit/UIProcess/ios/WKMouseGestureRecognizer.mm (279058 => 279059)


--- trunk/Source/WebKit/UIProcess/ios/WKMouseGestureRecognizer.mm	2021-06-20 20:33:15 UTC (rev 279058)
+++ trunk/Source/WebKit/UIProcess/ios/WKMouseGestureRecognizer.mm	2021-06-20 21:31:34 UTC (rev 279059)
@@ -120,10 +120,10 @@
     }();
 
     WebCore::IntPoint point { [self locationInView:self.view] };
-
+    auto delta = point - WebCore::IntPoint { [_currentTouch previousLocationInView:self.view] };
     // UITouch's timestamp uses mach_absolute_time as its timebase, same as MonotonicTime.
     auto timestamp = MonotonicTime::fromRawSeconds([_currentTouch timestamp]).approximateWallTime();
-    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);
+    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);
 }
 
 - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to