Title: [285790] trunk/Source
Revision
285790
Author
[email protected]
Date
2021-11-14 10:38:45 -0800 (Sun, 14 Nov 2021)

Log Message

Attach IOHIDEvent timestamps to wheel events
https://bugs.webkit.org/show_bug.cgi?id=233051

Reviewed by Wenson Hsieh.
Source/WebCore:

On some macOS devices, there can be significant deltas between NSEvent timestamps,
and the timestamps on underlying IOHIDEvents (rdar://85309639). This makes momentum
velocity computation unpredictable; we can get better results by using IOHIDEvent
timestamps.

* platform/PlatformWheelEvent.cpp:
(WebCore::PlatformWheelEvent::createFromGesture):
* platform/PlatformWheelEvent.h:
(WebCore::PlatformWheelEvent::ioHIDEventTimestamp const):
* platform/mac/PlatformEventFactoryMac.h:
* platform/mac/PlatformEventFactoryMac.mm:
(WebCore::eventTimeStampSince1970):
(WebCore::PlatformMouseEventBuilder::PlatformMouseEventBuilder):
(WebCore::PlatformWheelEventBuilder::PlatformWheelEventBuilder):
(WebCore::PlatformKeyboardEventBuilder::PlatformKeyboardEventBuilder):

Source/WebCore/PAL:

Expose a few bits of SPI needed.

* pal/spi/cg/CoreGraphicsSPI.h:
* pal/spi/cocoa/IOKitSPI.h:

Source/WebKit:

On some macOS devices, there can be significant deltas between NSEvent timestamps,
and the timestamps on underlying IOHIDEvents (rdar://85309639). This makes momentum
velocity computation unpredictable; we can get better results by using IOHIDEvent
timestamps.

* Shared/WebEventConversion.cpp:
(WebKit::WebKit2PlatformWheelEvent::WebKit2PlatformWheelEvent):
* Shared/WebWheelEvent.cpp:
(WebKit::WebWheelEvent::WebWheelEvent):
(WebKit::WebWheelEvent::encode const):
(WebKit::WebWheelEvent::decode):
* Shared/WebWheelEvent.h:
(WebKit::WebWheelEvent::ioHIDEventTimestamp const):
* Shared/WebWheelEventCoalescer.cpp:
(WebKit::WebWheelEventCoalescer::coalesce):
* Shared/ios/WebIOSEventFactory.mm:
(WebIOSEventFactory::createWebWheelEvent):
* Shared/mac/NativeWebGestureEventMac.mm:
* Shared/mac/WebEventFactory.mm:
(WebKit::WebEventFactory::createWebMouseEvent):
(WebKit::WebEventFactory::createWebWheelEvent):
(WebKit::WebEventFactory::createWebKeyboardEvent):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (285789 => 285790)


--- trunk/Source/WebCore/ChangeLog	2021-11-14 18:33:29 UTC (rev 285789)
+++ trunk/Source/WebCore/ChangeLog	2021-11-14 18:38:45 UTC (rev 285790)
@@ -1,3 +1,26 @@
+2021-11-14  Simon Fraser  <[email protected]>
+
+        Attach IOHIDEvent timestamps to wheel events
+        https://bugs.webkit.org/show_bug.cgi?id=233051
+
+        Reviewed by Wenson Hsieh.
+
+        On some macOS devices, there can be significant deltas between NSEvent timestamps,
+        and the timestamps on underlying IOHIDEvents (rdar://85309639). This makes momentum
+        velocity computation unpredictable; we can get better results by using IOHIDEvent
+        timestamps.
+
+        * platform/PlatformWheelEvent.cpp:
+        (WebCore::PlatformWheelEvent::createFromGesture):
+        * platform/PlatformWheelEvent.h:
+        (WebCore::PlatformWheelEvent::ioHIDEventTimestamp const):
+        * platform/mac/PlatformEventFactoryMac.h:
+        * platform/mac/PlatformEventFactoryMac.mm:
+        (WebCore::eventTimeStampSince1970):
+        (WebCore::PlatformMouseEventBuilder::PlatformMouseEventBuilder):
+        (WebCore::PlatformWheelEventBuilder::PlatformWheelEventBuilder):
+        (WebCore::PlatformKeyboardEventBuilder::PlatformKeyboardEventBuilder):
+
 2021-11-13  Simon Fraser  <[email protected]>
 
         Run a ScrollAnimationMomentum for the momentum phase of a scroll

Modified: trunk/Source/WebCore/PAL/ChangeLog (285789 => 285790)


--- trunk/Source/WebCore/PAL/ChangeLog	2021-11-14 18:33:29 UTC (rev 285789)
+++ trunk/Source/WebCore/PAL/ChangeLog	2021-11-14 18:38:45 UTC (rev 285790)
@@ -1,3 +1,15 @@
+2021-11-14  Simon Fraser  <[email protected]>
+
+        Attach IOHIDEvent timestamps to wheel events
+        https://bugs.webkit.org/show_bug.cgi?id=233051
+
+        Reviewed by Wenson Hsieh.
+        
+        Expose a few bits of SPI needed.
+
+        * pal/spi/cg/CoreGraphicsSPI.h:
+        * pal/spi/cocoa/IOKitSPI.h:
+
 2021-11-13  Tim Horton  <[email protected]>
 
         Clean up IOKit SPI headers

Modified: trunk/Source/WebCore/PAL/pal/spi/cg/CoreGraphicsSPI.h (285789 => 285790)


--- trunk/Source/WebCore/PAL/pal/spi/cg/CoreGraphicsSPI.h	2021-11-14 18:33:29 UTC (rev 285789)
+++ trunk/Source/WebCore/PAL/pal/spi/cg/CoreGraphicsSPI.h	2021-11-14 18:38:45 UTC (rev 285790)
@@ -32,6 +32,10 @@
 #include <pal/spi/cocoa/IOSurfaceSPI.h>
 #endif
 
+#if PLATFORM(MAC)
+#include <pal/spi/cocoa/IOKitSPI.h>
+#endif
+
 #if USE(APPLE_INTERNAL_SDK)
 
 #include <CoreGraphics/CGContextDelegatePrivate.h>
@@ -42,6 +46,7 @@
 
 #if PLATFORM(MAC)
 #include <CoreGraphics/CGAccessibility.h>
+#include <CoreGraphics/CGEventPrivate.h>
 #endif
 
 #else
@@ -351,6 +356,7 @@
 typedef int32_t CGSDisplayID;
 CGSDisplayID CGSMainDisplayID(void);
 
+IOHIDEventRef CGEventCopyIOHIDEvent(CGEventRef);
 #endif // PLATFORM(MAC)
 
 #if ENABLE(PDFKIT_PLUGIN) && !USE(APPLE_INTERNAL_SDK)

Modified: trunk/Source/WebCore/PAL/pal/spi/mac/IOKitSPIMac.h (285789 => 285790)


--- trunk/Source/WebCore/PAL/pal/spi/mac/IOKitSPIMac.h	2021-11-14 18:33:29 UTC (rev 285789)
+++ trunk/Source/WebCore/PAL/pal/spi/mac/IOKitSPIMac.h	2021-11-14 18:38:45 UTC (rev 285790)
@@ -43,6 +43,8 @@
 #define kIOHIDProductIDKey "ProductID"
 
 WTF_EXTERN_C_BEGIN
+
+typedef struct __IOHIDEvent * IOHIDEventRef;
 typedef struct CF_BRIDGED_TYPE(id) __IOHIDServiceClient * IOHIDServiceClientRef;
 typedef struct CF_BRIDGED_TYPE(id) __IOHIDEventSystemClient * IOHIDEventSystemClientRef;
 typedef void (^IOHIDServiceClientBlock)(void *, void *, IOHIDServiceClientRef);
@@ -81,6 +83,8 @@
 };
 typedef uint32_t IOHIDEventType;
 
+uint64_t IOHIDEventGetTimeStamp(IOHIDEventRef);
+
 WTF_EXTERN_C_END
 
 #endif // USE(APPLE_INTERNAL_SDK)

Modified: trunk/Source/WebCore/platform/PlatformWheelEvent.cpp (285789 => 285790)


--- trunk/Source/WebCore/platform/PlatformWheelEvent.cpp	2021-11-14 18:33:29 UTC (rev 285789)
+++ trunk/Source/WebCore/platform/PlatformWheelEvent.cpp	2021-11-14 18:38:45 UTC (rev 285790)
@@ -75,6 +75,7 @@
 #endif // ENABLE(KINETIC_SCROLLING)
 
 #if PLATFORM(COCOA)
+    platformWheelEvent.m_ioHIDEventTimestamp = platformWheelEvent.m_timestamp;
     platformWheelEvent.m_unacceleratedScrollingDeltaY = deltaY;
 #endif // PLATFORM(COCOA)
 

Modified: trunk/Source/WebCore/platform/PlatformWheelEvent.h (285789 => 285790)


--- trunk/Source/WebCore/platform/PlatformWheelEvent.h	2021-11-14 18:33:29 UTC (rev 285789)
+++ trunk/Source/WebCore/platform/PlatformWheelEvent.h	2021-11-14 18:38:45 UTC (rev 285790)
@@ -151,6 +151,8 @@
 #if PLATFORM(COCOA)
     unsigned scrollCount() const { return m_scrollCount; }
     FloatSize unacceleratedScrollingDelta() const { return { m_unacceleratedScrollingDeltaX, m_unacceleratedScrollingDeltaY }; }
+    
+    WallTime ioHIDEventTimestamp() const { return m_ioHIDEventTimestamp; }
 #endif
 
 #if ENABLE(ASYNC_SCROLLING)
@@ -199,6 +201,7 @@
     PlatformWheelEventPhase m_momentumPhase { PlatformWheelEventPhase::None };
 #endif
 #if PLATFORM(COCOA)
+    WallTime m_ioHIDEventTimestamp;
     unsigned m_scrollCount { 0 };
     float m_unacceleratedScrollingDeltaX { 0 };
     float m_unacceleratedScrollingDeltaY { 0 };

Modified: trunk/Source/WebCore/platform/mac/PlatformEventFactoryMac.h (285789 => 285790)


--- trunk/Source/WebCore/platform/mac/PlatformEventFactoryMac.h	2021-11-14 18:33:29 UTC (rev 285789)
+++ trunk/Source/WebCore/platform/mac/PlatformEventFactoryMac.h	2021-11-14 18:38:45 UTC (rev 285790)
@@ -50,7 +50,7 @@
 WEBCORE_EXPORT String keyIdentifierForKeyEvent(NSEvent *);
 WEBCORE_EXPORT String keyForKeyEvent(NSEvent *);
 WEBCORE_EXPORT String codeForKeyEvent(NSEvent *);
-WEBCORE_EXPORT WallTime eventTimeStampSince1970(NSEvent *);
+WEBCORE_EXPORT WallTime eventTimeStampSince1970(NSTimeInterval);
 
 WEBCORE_EXPORT OptionSet<PlatformEvent::Modifier> modifiersForEvent(NSEvent *);
 WEBCORE_EXPORT void getWheelEventDeltas(NSEvent *, float& deltaX, float& deltaY, BOOL& continuous);

Modified: trunk/Source/WebCore/platform/mac/PlatformEventFactoryMac.mm (285789 => 285790)


--- trunk/Source/WebCore/platform/mac/PlatformEventFactoryMac.mm	2021-11-14 18:33:29 UTC (rev 285789)
+++ trunk/Source/WebCore/platform/mac/PlatformEventFactoryMac.mm	2021-11-14 18:38:45 UTC (rev 285790)
@@ -607,9 +607,9 @@
     return systemStartupTime;
 }
 
-WallTime eventTimeStampSince1970(NSEvent* event)
+WallTime eventTimeStampSince1970(NSTimeInterval timestamp)
 {
-    return WallTime::fromRawSeconds(static_cast<double>(cachedStartupTimeIntervalSince1970() + [event timestamp]));
+    return WallTime::fromRawSeconds(static_cast<double>(cachedStartupTimeIntervalSince1970() + timestamp));
 }
 
 static inline bool isKeyUpEvent(NSEvent *event)
@@ -720,7 +720,7 @@
         }
 
         m_modifiers = modifiersForEvent(event);
-        m_timestamp = eventTimeStampSince1970(event);
+        m_timestamp = eventTimeStampSince1970(event.timestamp);
 
         // PlatformMouseEvent
         m_position = pointForEvent(event, windowView);
@@ -755,7 +755,7 @@
         // PlatformEvent
         m_type = PlatformEvent::Wheel;
         m_modifiers = modifiersForEvent(event);
-        m_timestamp = eventTimeStampSince1970(event);
+        m_timestamp = eventTimeStampSince1970(event.timestamp);
 
         // PlatformWheelEvent
         m_position = pointForEvent(event, windowView);
@@ -794,7 +794,7 @@
         // PlatformEvent
         m_type = isKeyUpEvent(event) ? PlatformEvent::KeyUp : PlatformEvent::KeyDown;
         m_modifiers = modifiersForEvent(event);
-        m_timestamp = eventTimeStampSince1970(event);
+        m_timestamp = eventTimeStampSince1970(event.timestamp);
 
         // PlatformKeyboardEvent
         m_text = textFromEvent(event);

Modified: trunk/Source/WebKit/ChangeLog (285789 => 285790)


--- trunk/Source/WebKit/ChangeLog	2021-11-14 18:33:29 UTC (rev 285789)
+++ trunk/Source/WebKit/ChangeLog	2021-11-14 18:38:45 UTC (rev 285790)
@@ -1,3 +1,33 @@
+2021-11-14  Simon Fraser  <[email protected]>
+
+        Attach IOHIDEvent timestamps to wheel events
+        https://bugs.webkit.org/show_bug.cgi?id=233051
+
+        Reviewed by Wenson Hsieh.
+        
+        On some macOS devices, there can be significant deltas between NSEvent timestamps,
+        and the timestamps on underlying IOHIDEvents (rdar://85309639). This makes momentum
+        velocity computation unpredictable; we can get better results by using IOHIDEvent
+        timestamps.
+
+        * Shared/WebEventConversion.cpp:
+        (WebKit::WebKit2PlatformWheelEvent::WebKit2PlatformWheelEvent):
+        * Shared/WebWheelEvent.cpp:
+        (WebKit::WebWheelEvent::WebWheelEvent):
+        (WebKit::WebWheelEvent::encode const):
+        (WebKit::WebWheelEvent::decode):
+        * Shared/WebWheelEvent.h:
+        (WebKit::WebWheelEvent::ioHIDEventTimestamp const):
+        * Shared/WebWheelEventCoalescer.cpp:
+        (WebKit::WebWheelEventCoalescer::coalesce):
+        * Shared/ios/WebIOSEventFactory.mm:
+        (WebIOSEventFactory::createWebWheelEvent):
+        * Shared/mac/NativeWebGestureEventMac.mm:
+        * Shared/mac/WebEventFactory.mm:
+        (WebKit::WebEventFactory::createWebMouseEvent):
+        (WebKit::WebEventFactory::createWebWheelEvent):
+        (WebKit::WebEventFactory::createWebKeyboardEvent):
+
 2021-11-13  Per Arne Vollan <[email protected]>
 
         [macOS][GPUP] Remove logging of used syscalls

Modified: trunk/Source/WebKit/Shared/WebEventConversion.cpp (285789 => 285790)


--- trunk/Source/WebKit/Shared/WebEventConversion.cpp	2021-11-14 18:33:29 UTC (rev 285789)
+++ trunk/Source/WebKit/Shared/WebEventConversion.cpp	2021-11-14 18:38:45 UTC (rev 285790)
@@ -169,6 +169,7 @@
         m_hasPreciseScrollingDeltas = webEvent.hasPreciseScrollingDeltas();
 #endif
 #if PLATFORM(COCOA)
+        m_ioHIDEventTimestamp = webEvent.ioHIDEventTimestamp();
         m_scrollCount = webEvent.scrollCount();
         m_unacceleratedScrollingDeltaX = webEvent.unacceleratedScrollingDelta().width();
         m_unacceleratedScrollingDeltaY = webEvent.unacceleratedScrollingDelta().height();

Modified: trunk/Source/WebKit/Shared/WebWheelEvent.cpp (285789 => 285790)


--- trunk/Source/WebKit/Shared/WebWheelEvent.cpp	2021-11-14 18:33:29 UTC (rev 285789)
+++ trunk/Source/WebKit/Shared/WebWheelEvent.cpp	2021-11-14 18:38:45 UTC (rev 285790)
@@ -44,7 +44,7 @@
 }
 
 #if PLATFORM(COCOA)
-WebWheelEvent::WebWheelEvent(Type type, const IntPoint& position, const IntPoint& globalPosition, const FloatSize& delta, const FloatSize& wheelTicks, Granularity granularity, bool directionInvertedFromDevice, Phase phase, Phase momentumPhase, bool hasPreciseScrollingDeltas, uint32_t scrollCount, const WebCore::FloatSize& unacceleratedScrollingDelta, OptionSet<Modifier> modifiers, WallTime timestamp)
+WebWheelEvent::WebWheelEvent(Type type, const IntPoint& position, const IntPoint& globalPosition, const FloatSize& delta, const FloatSize& wheelTicks, Granularity granularity, bool directionInvertedFromDevice, Phase phase, Phase momentumPhase, bool hasPreciseScrollingDeltas, uint32_t scrollCount, const WebCore::FloatSize& unacceleratedScrollingDelta, OptionSet<Modifier> modifiers, WallTime timestamp, WallTime ioHIDEventTimestamp)
     : WebEvent(type, modifiers, timestamp)
     , m_position(position)
     , m_globalPosition(globalPosition)
@@ -55,6 +55,7 @@
     , m_momentumPhase(momentumPhase)
     , m_directionInvertedFromDevice(directionInvertedFromDevice)
     , m_hasPreciseScrollingDeltas(hasPreciseScrollingDeltas)
+    , m_ioHIDEventTimestamp(ioHIDEventTimestamp)
     , m_scrollCount(scrollCount)
     , m_unacceleratedScrollingDelta(unacceleratedScrollingDelta)
 {
@@ -92,6 +93,7 @@
     encoder << m_hasPreciseScrollingDeltas;
 #endif
 #if PLATFORM(COCOA)
+    encoder << m_ioHIDEventTimestamp;
     encoder << m_scrollCount;
     encoder << m_unacceleratedScrollingDelta;
 #endif
@@ -122,6 +124,8 @@
         return false;
 #endif
 #if PLATFORM(COCOA)
+    if (!decoder.decode(t.m_ioHIDEventTimestamp))
+        return false;
     if (!decoder.decode(t.m_scrollCount))
         return false;
     if (!decoder.decode(t.m_unacceleratedScrollingDelta))

Modified: trunk/Source/WebKit/Shared/WebWheelEvent.h (285789 => 285790)


--- trunk/Source/WebKit/Shared/WebWheelEvent.h	2021-11-14 18:33:29 UTC (rev 285789)
+++ trunk/Source/WebKit/Shared/WebWheelEvent.h	2021-11-14 18:38:45 UTC (rev 285790)
@@ -53,7 +53,7 @@
 
     WebWheelEvent(Type, const WebCore::IntPoint& position, const WebCore::IntPoint& globalPosition, const WebCore::FloatSize& delta, const WebCore::FloatSize& wheelTicks, Granularity, OptionSet<Modifier>, WallTime timestamp);
 #if PLATFORM(COCOA)
-    WebWheelEvent(Type, const WebCore::IntPoint& position, const WebCore::IntPoint& globalPosition, const WebCore::FloatSize& delta, const WebCore::FloatSize& wheelTicks, Granularity, bool directionInvertedFromDevice, Phase, Phase momentumPhase, bool hasPreciseScrollingDeltas, uint32_t scrollCount, const WebCore::FloatSize& unacceleratedScrollingDelta, OptionSet<Modifier>, WallTime timestamp);
+    WebWheelEvent(Type, const WebCore::IntPoint& position, const WebCore::IntPoint& globalPosition, const WebCore::FloatSize& delta, const WebCore::FloatSize& wheelTicks, Granularity, bool directionInvertedFromDevice, Phase, Phase momentumPhase, bool hasPreciseScrollingDeltas, uint32_t scrollCount, const WebCore::FloatSize& unacceleratedScrollingDelta, OptionSet<Modifier>, WallTime timestamp, WallTime ioHIDEventTimestamp);
 #elif PLATFORM(GTK) || USE(LIBWPE)
     WebWheelEvent(Type, const WebCore::IntPoint& position, const WebCore::IntPoint& globalPosition, const WebCore::FloatSize& delta, const WebCore::FloatSize& wheelTicks, Phase, Phase momentumPhase, Granularity, bool hasPreciseScrollingDeltas, OptionSet<Modifier>, WallTime timestamp);
 #endif
@@ -70,6 +70,7 @@
     bool hasPreciseScrollingDeltas() const { return m_hasPreciseScrollingDeltas; }
 #endif
 #if PLATFORM(COCOA)
+    WallTime ioHIDEventTimestamp() const { return m_ioHIDEventTimestamp; }
     uint32_t scrollCount() const { return m_scrollCount; }
     const WebCore::FloatSize& unacceleratedScrollingDelta() const { return m_unacceleratedScrollingDelta; }
 #endif
@@ -87,11 +88,13 @@
     uint32_t m_granularity { ScrollByPageWheelEvent };
     uint32_t m_phase { Phase::PhaseNone };
     uint32_t m_momentumPhase { Phase::PhaseNone };
+
     bool m_directionInvertedFromDevice { false };
 #if PLATFORM(COCOA) || PLATFORM(GTK) || USE(LIBWPE)
     bool m_hasPreciseScrollingDeltas { false };
 #endif
 #if PLATFORM(COCOA)
+    WallTime m_ioHIDEventTimestamp;
     uint32_t m_scrollCount { 0 };
     WebCore::FloatSize m_unacceleratedScrollingDelta;
 #endif

Modified: trunk/Source/WebKit/Shared/WebWheelEventCoalescer.cpp (285789 => 285790)


--- trunk/Source/WebKit/Shared/WebWheelEventCoalescer.cpp	2021-11-14 18:33:29 UTC (rev 285789)
+++ trunk/Source/WebKit/Shared/WebWheelEventCoalescer.cpp	2021-11-14 18:38:45 UTC (rev 285790)
@@ -78,7 +78,7 @@
 #if PLATFORM(COCOA)
     auto mergedUnacceleratedScrollingDelta = a.unacceleratedScrollingDelta() + b.unacceleratedScrollingDelta();
 
-    return WebWheelEvent(WebEvent::Wheel, b.position(), b.globalPosition(), mergedDelta, mergedWheelTicks, b.granularity(), b.directionInvertedFromDevice(), b.phase(), b.momentumPhase(), b.hasPreciseScrollingDeltas(), b.scrollCount(), mergedUnacceleratedScrollingDelta, b.modifiers(), b.timestamp());
+    return WebWheelEvent(WebEvent::Wheel, b.position(), b.globalPosition(), mergedDelta, mergedWheelTicks, b.granularity(), b.directionInvertedFromDevice(), b.phase(), b.momentumPhase(), b.hasPreciseScrollingDeltas(), b.scrollCount(), mergedUnacceleratedScrollingDelta, b.modifiers(), b.timestamp(), b.ioHIDEventTimestamp());
 #elif PLATFORM(GTK) || USE(LIBWPE)
     return WebWheelEvent(WebEvent::Wheel, b.position(), b.globalPosition(), mergedDelta, mergedWheelTicks, b.phase(), b.momentumPhase(), b.granularity(), b.hasPreciseScrollingDeltas(), b.modifiers(), b.timestamp());
 #else

Modified: trunk/Source/WebKit/Shared/ios/WebIOSEventFactory.mm (285789 => 285790)


--- trunk/Source/WebKit/Shared/ios/WebIOSEventFactory.mm	2021-11-14 18:33:29 UTC (rev 285789)
+++ trunk/Source/WebKit/Shared/ios/WebIOSEventFactory.mm	2021-11-14 18:38:45 UTC (rev 285790)
@@ -161,7 +161,7 @@
     WebCore::FloatSize delta(deltaVector.dx, deltaVector.dy);
     WebCore::FloatSize wheelTicks = delta;
     wheelTicks.scale(1. / static_cast<float>(WebCore::Scrollbar::pixelsPerLineStep()));
-
+    auto timestamp = MonotonicTime::fromRawSeconds(event.timestamp).approximateWallTime();
     return {
         WebKit::WebEvent::Wheel,
         scrollLocation,
@@ -176,7 +176,8 @@
         1,
         delta,
         { },
-        MonotonicTime::fromRawSeconds(event.timestamp).approximateWallTime()
+        timestamp,
+        timestamp
     };
 }
 #endif

Modified: trunk/Source/WebKit/Shared/mac/NativeWebGestureEventMac.mm (285789 => 285790)


--- trunk/Source/WebKit/Shared/mac/NativeWebGestureEventMac.mm	2021-11-14 18:33:29 UTC (rev 285789)
+++ trunk/Source/WebKit/Shared/mac/NativeWebGestureEventMac.mm	2021-11-14 18:38:45 UTC (rev 285790)
@@ -62,7 +62,7 @@
     : WebGestureEvent(
         webEventTypeForNSEvent(event),
         OptionSet<WebEvent::Modifier> { },
-        WebCore::eventTimeStampSince1970(event),
+        WebCore::eventTimeStampSince1970(event.timestamp),
         WebCore::IntPoint(pointForEvent(event, view)),
         event.type == NSEventTypeMagnify ? event.magnification : 0,
         event.type == NSEventTypeRotate ? event.rotation : 0)

Modified: trunk/Source/WebKit/Shared/mac/WebEventFactory.mm (285789 => 285790)


--- trunk/Source/WebKit/Shared/mac/WebEventFactory.mm	2021-11-14 18:33:29 UTC (rev 285789)
+++ trunk/Source/WebKit/Shared/mac/WebEventFactory.mm	2021-11-14 18:38:45 UTC (rev 285790)
@@ -32,6 +32,7 @@
 #import <WebCore/PlatformEventFactoryMac.h>
 #import <WebCore/Scrollbar.h>
 #import <WebCore/WindowsKeyboardCodes.h>
+#import <pal/spi/cg/CoreGraphicsSPI.h>
 #import <pal/spi/mac/NSMenuSPI.h>
 #import <wtf/ASCIICType.h>
 
@@ -353,7 +354,7 @@
     float deltaZ = [event deltaZ];
     int clickCount = clickCountForEvent(event);
     auto modifiers = modifiersForEvent(event);
-    auto timestamp = WebCore::eventTimeStampSince1970(event);
+    auto timestamp = WebCore::eventTimeStampSince1970(event.timestamp);
     int eventNumber = [event eventNumber];
     int menuTypeForEvent = typeForEvent(event);
 
@@ -408,9 +409,26 @@
     }
 
     auto modifiers = modifiersForEvent(event);
-    auto timestamp = WebCore::eventTimeStampSince1970(event);
+    auto timestamp = WebCore::eventTimeStampSince1970(event.timestamp);
 
-    return WebWheelEvent(WebEvent::Wheel, WebCore::IntPoint(position), WebCore::IntPoint(globalPosition), WebCore::FloatSize(deltaX, deltaY), WebCore::FloatSize(wheelTicksX, wheelTicksY), granularity, directionInvertedFromDevice, phase, momentumPhase, hasPreciseScrollingDeltas, scrollCount, unacceleratedScrollingDelta, modifiers, timestamp);
+    auto ioHIDEventTimestamp = [](NSEvent *event) {
+        auto cgEvent = event.CGEvent;
+        if (!cgEvent)
+            return event.timestamp;
+
+        auto iohidEvent = adoptCF(CGEventCopyIOHIDEvent(cgEvent));
+        if (!iohidEvent)
+            return event.timestamp;
+
+        auto ioHIDEventTimestamp = IOHIDEventGetTimeStamp(iohidEvent.get()); // IOEventRef timestamp is mach_absolute_time units.
+        return MonotonicTime::fromMachAbsoluteTime(ioHIDEventTimestamp).secondsSinceEpoch().seconds();
+    }(event);
+
+    auto ioHIDEventWallTime = WebCore::eventTimeStampSince1970(ioHIDEventTimestamp);
+
+    return WebWheelEvent(WebEvent::Wheel, WebCore::IntPoint(position), WebCore::IntPoint(globalPosition), WebCore::FloatSize(deltaX, deltaY), WebCore::FloatSize(wheelTicksX, wheelTicksY),
+        granularity, directionInvertedFromDevice, phase, momentumPhase, hasPreciseScrollingDeltas,
+        scrollCount, unacceleratedScrollingDelta, modifiers, timestamp, ioHIDEventWallTime);
 }
 
 WebKeyboardEvent WebEventFactory::createWebKeyboardEvent(NSEvent *event, bool handledByInputMethod, bool replacesSoftSpace, const Vector<WebCore::KeypressCommand>& commands)
@@ -428,7 +446,7 @@
     bool isKeypad                   = isKeypadEvent(event);
     bool isSystemKey                = false; // SystemKey is always false on the Mac.
     auto modifiers = modifiersForEvent(event);
-    auto timestamp                  = WebCore::eventTimeStampSince1970(event);
+    auto timestamp                  = WebCore::eventTimeStampSince1970(event.timestamp);
 
     // Always use 13 for Enter/Return -- we don't want to use AppKit's different character for Enter.
     if (windowsVirtualKeyCode == VK_RETURN) {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to