Title: [286900] trunk/Source/WebKit
Revision
286900
Author
timothy_hor...@apple.com
Date
2021-12-10 19:43:48 -0800 (Fri, 10 Dec 2021)

Log Message

Momentum Event Dispatcher: Magic Mouse doesn't use momentum event dispatcher
https://bugs.webkit.org/show_bug.cgi?id=234189
<rdar://problem/86344954>

Reviewed by Simon Fraser.

* Shared/mac/ScrollingAccelerationCurveMac.mm:
(WebKit::fromIOHIDDevice):
Fix the FIXME here about the additional fallback values; it turns out
Magic Mouse is one device that does not have a value for
kIOHIDScrollAccelerationTypeKey, so we need the full fallback chain to support it.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::sendWheelEvent):
Un-wrapping this optional results in losing the engaged state, and sending
a garbage ScrollingAccelerationCurve across the wire.
The message argument is also an optional, so just pass it along.

The result of this bug was that if you had ever used a device with a curve
for a given page, and then used a device with no curve, MomentumEventDispatcher
would have a garbage curve (from this message trying to "unset" the optional),
and a garbage curve results in chaotic scrolling.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (286899 => 286900)


--- trunk/Source/WebKit/ChangeLog	2021-12-11 03:24:50 UTC (rev 286899)
+++ trunk/Source/WebKit/ChangeLog	2021-12-11 03:43:48 UTC (rev 286900)
@@ -1,3 +1,28 @@
+2021-12-10  Tim Horton  <timothy_hor...@apple.com>
+
+        Momentum Event Dispatcher: Magic Mouse doesn't use momentum event dispatcher
+        https://bugs.webkit.org/show_bug.cgi?id=234189
+        <rdar://problem/86344954>
+
+        Reviewed by Simon Fraser.
+
+        * Shared/mac/ScrollingAccelerationCurveMac.mm:
+        (WebKit::fromIOHIDDevice):
+        Fix the FIXME here about the additional fallback values; it turns out
+        Magic Mouse is one device that does not have a value for
+        kIOHIDScrollAccelerationTypeKey, so we need the full fallback chain to support it.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::sendWheelEvent):
+        Un-wrapping this optional results in losing the engaged state, and sending
+        a garbage ScrollingAccelerationCurve across the wire.
+        The message argument is also an optional, so just pass it along.
+
+        The result of this bug was that if you had ever used a device with a curve
+        for a given page, and then used a device with no curve, MomentumEventDispatcher
+        would have a garbage curve (from this message trying to "unset" the optional),
+        and a garbage curve results in chaotic scrolling.
+
 2021-12-10  Michael Saboff  <msab...@apple.com>
 
         https://bugs.webkit.org/show_bug.cgi?id=234173

Modified: trunk/Source/WebKit/Shared/mac/ScrollingAccelerationCurveMac.mm (286899 => 286900)


--- trunk/Source/WebKit/Shared/mac/ScrollingAccelerationCurveMac.mm	2021-12-11 03:24:50 UTC (rev 286899)
+++ trunk/Source/WebKit/Shared/mac/ScrollingAccelerationCurveMac.mm	2021-12-11 03:43:48 UTC (rev 286900)
@@ -116,26 +116,37 @@
         return std::nullopt;
     }
 
-    // FIXME: There is some additional fallback to implement here, though this seems usually sufficient.
-    auto scrollAccelerationType = adoptCF(dynamic_cf_cast<CFStringRef>(IOHIDServiceClientCopyProperty(ioHIDService.get(), CFSTR("HIDScrollAccelerationType"))));
-    if (!scrollAccelerationType) {
-        RELEASE_LOG(ScrollAnimations, "ScrollingAccelerationCurve::fromIOHIDDevice failed to look up acceleration type");
-        return std::nullopt;
-    }
+    auto readFixedPointServiceKey = [&] (CFStringRef key) -> std::optional<float> {
+        auto valueCF = adoptCF(dynamic_cf_cast<CFNumberRef>(IOHIDServiceClientCopyProperty(ioHIDService.get(), key)));
+        if (!valueCF)
+            return std::nullopt;
+        return fromFixedPoint([(NSNumber *)valueCF.get() floatValue]);
+    };
 
-    auto scrollAccelerationCF = adoptCF(dynamic_cf_cast<CFNumberRef>(IOHIDServiceClientCopyProperty(ioHIDService.get(), scrollAccelerationType.get())));
-    if (!scrollAccelerationCF) {
-        RELEASE_LOG(ScrollAnimations, "ScrollingAccelerationCurve::fromIOHIDDevice failed to look up acceleration value");
+    auto scrollAcceleration = [&] () -> std::optional<float> {
+        if (auto scrollAccelerationType = adoptCF(dynamic_cf_cast<CFStringRef>(IOHIDServiceClientCopyProperty(ioHIDService.get(), CFSTR("HIDScrollAccelerationType"))))) {
+            if (auto acceleration = readFixedPointServiceKey(scrollAccelerationType.get()))
+                return acceleration;
+        }
+
+        if (auto acceleration = readFixedPointServiceKey(CFSTR(kIOHIDMouseScrollAccelerationKey)))
+            return acceleration;
+
+        if (auto acceleration = readFixedPointServiceKey(CFSTR(kIOHIDScrollAccelerationKey)))
+            return acceleration;
+
         return std::nullopt;
+    }();
+    if (!scrollAcceleration) {
+        RELEASE_LOG(ScrollAnimations, "ScrollingAccelerationCurve::fromIOHIDDevice failed to look up acceleration");
+        return std::nullopt;
     }
-    auto scrollAcceleration = fromFixedPoint(fromCFNumber(scrollAccelerationCF.get()));
 
-    auto resolutionCF = adoptCF(dynamic_cf_cast<CFNumberRef>(IOHIDServiceClientCopyProperty(ioHIDService.get(), CFSTR(kIOHIDScrollResolutionKey))));
-    if (!resolutionCF) {
+    auto resolution = readFixedPointServiceKey(CFSTR(kIOHIDScrollResolutionKey));
+    if (!resolution) {
         RELEASE_LOG(ScrollAnimations, "ScrollingAccelerationCurve::fromIOHIDDevice failed to look up resolution");
         return std::nullopt;
     }
-    auto resolution = fromFixedPoint([(NSNumber *)resolutionCF.get() floatValue]);
 
     static CFStringRef dispatchFrameRateKey = CFSTR("ScrollMomentumDispatchRate");
     static constexpr float defaultDispatchFrameRate = 60;
@@ -142,7 +153,7 @@
     auto frameRateCF = adoptCF(dynamic_cf_cast<CFNumberRef>(IOHIDServiceClientCopyProperty(ioHIDService.get(), dispatchFrameRateKey)));
     float frameRate = frameRateCF ? fromCFNumber(frameRateCF.get()) : defaultDispatchFrameRate;
 
-    return fromIOHIDCurveArrayWithAcceleration((NSArray *)curves.get(), scrollAcceleration, resolution, frameRate);
+    return fromIOHIDCurveArrayWithAcceleration((NSArray *)curves.get(), *scrollAcceleration, *resolution, frameRate);
 }
 
 std::optional<ScrollingAccelerationCurve> ScrollingAccelerationCurve::fromNativeWheelEvent(const NativeWebWheelEvent& nativeWebWheelEvent)

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (286899 => 286900)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-12-11 03:24:50 UTC (rev 286899)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-12-11 03:43:48 UTC (rev 286900)
@@ -2962,7 +2962,7 @@
 
 #if ENABLE(MOMENTUM_EVENT_DISPATCHER)
     if (event.momentumPhase() == WebWheelEvent::PhaseBegan && m_scrollingAccelerationCurve != m_lastSentScrollingAccelerationCurve) {
-        connection->send(Messages::EventDispatcher::SetScrollingAccelerationCurve(m_webPageID, *m_scrollingAccelerationCurve), 0, { }, Thread::QOS::UserInteractive);
+        connection->send(Messages::EventDispatcher::SetScrollingAccelerationCurve(m_webPageID, m_scrollingAccelerationCurve), 0, { }, Thread::QOS::UserInteractive);
         m_lastSentScrollingAccelerationCurve = m_scrollingAccelerationCurve;
     }
 #endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to