Changeset 285790 in webkit
- Timestamp:
- Nov 14, 2021, 10:38:45 AM (5 years ago)
- Location:
- trunk/Source
- Files:
-
- 16 edited
-
WebCore/ChangeLog (modified) (1 diff)
-
WebCore/PAL/ChangeLog (modified) (1 diff)
-
WebCore/PAL/pal/spi/cg/CoreGraphicsSPI.h (modified) (3 diffs)
-
WebCore/PAL/pal/spi/mac/IOKitSPIMac.h (modified) (2 diffs)
-
WebCore/platform/PlatformWheelEvent.cpp (modified) (1 diff)
-
WebCore/platform/PlatformWheelEvent.h (modified) (2 diffs)
-
WebCore/platform/mac/PlatformEventFactoryMac.h (modified) (1 diff)
-
WebCore/platform/mac/PlatformEventFactoryMac.mm (modified) (4 diffs)
-
WebKit/ChangeLog (modified) (1 diff)
-
WebKit/Shared/WebEventConversion.cpp (modified) (1 diff)
-
WebKit/Shared/WebWheelEvent.cpp (modified) (4 diffs)
-
WebKit/Shared/WebWheelEvent.h (modified) (4 diffs)
-
WebKit/Shared/WebWheelEventCoalescer.cpp (modified) (1 diff)
-
WebKit/Shared/ios/WebIOSEventFactory.mm (modified) (2 diffs)
-
WebKit/Shared/mac/NativeWebGestureEventMac.mm (modified) (1 diff)
-
WebKit/Shared/mac/WebEventFactory.mm (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r285787 r285790 1 2021-11-14 Simon Fraser <simon.fraser@apple.com> 2 3 Attach IOHIDEvent timestamps to wheel events 4 https://bugs.webkit.org/show_bug.cgi?id=233051 5 6 Reviewed by Wenson Hsieh. 7 8 On some macOS devices, there can be significant deltas between NSEvent timestamps, 9 and the timestamps on underlying IOHIDEvents (rdar://85309639). This makes momentum 10 velocity computation unpredictable; we can get better results by using IOHIDEvent 11 timestamps. 12 13 * platform/PlatformWheelEvent.cpp: 14 (WebCore::PlatformWheelEvent::createFromGesture): 15 * platform/PlatformWheelEvent.h: 16 (WebCore::PlatformWheelEvent::ioHIDEventTimestamp const): 17 * platform/mac/PlatformEventFactoryMac.h: 18 * platform/mac/PlatformEventFactoryMac.mm: 19 (WebCore::eventTimeStampSince1970): 20 (WebCore::PlatformMouseEventBuilder::PlatformMouseEventBuilder): 21 (WebCore::PlatformWheelEventBuilder::PlatformWheelEventBuilder): 22 (WebCore::PlatformKeyboardEventBuilder::PlatformKeyboardEventBuilder): 23 1 24 2021-11-13 Simon Fraser <simon.fraser@apple.com> 2 25 -
trunk/Source/WebCore/PAL/ChangeLog
r285786 r285790 1 2021-11-14 Simon Fraser <simon.fraser@apple.com> 2 3 Attach IOHIDEvent timestamps to wheel events 4 https://bugs.webkit.org/show_bug.cgi?id=233051 5 6 Reviewed by Wenson Hsieh. 7 8 Expose a few bits of SPI needed. 9 10 * pal/spi/cg/CoreGraphicsSPI.h: 11 * pal/spi/cocoa/IOKitSPI.h: 12 1 13 2021-11-13 Tim Horton <timothy_horton@apple.com> 2 14 -
trunk/Source/WebCore/PAL/pal/spi/cg/CoreGraphicsSPI.h
r283863 r285790 33 33 #endif 34 34 35 #if PLATFORM(MAC) 36 #include <pal/spi/cocoa/IOKitSPI.h> 37 #endif 38 35 39 #if USE(APPLE_INTERNAL_SDK) 36 40 … … 43 47 #if PLATFORM(MAC) 44 48 #include <CoreGraphics/CGAccessibility.h> 49 #include <CoreGraphics/CGEventPrivate.h> 45 50 #endif 46 51 … … 352 357 CGSDisplayID CGSMainDisplayID(void); 353 358 359 IOHIDEventRef CGEventCopyIOHIDEvent(CGEventRef); 354 360 #endif // PLATFORM(MAC) 355 361 -
trunk/Source/WebCore/PAL/pal/spi/mac/IOKitSPIMac.h
r285786 r285790 44 44 45 45 WTF_EXTERN_C_BEGIN 46 47 typedef struct __IOHIDEvent * IOHIDEventRef; 46 48 typedef struct CF_BRIDGED_TYPE(id) __IOHIDServiceClient * IOHIDServiceClientRef; 47 49 typedef struct CF_BRIDGED_TYPE(id) __IOHIDEventSystemClient * IOHIDEventSystemClientRef; … … 82 84 typedef uint32_t IOHIDEventType; 83 85 86 uint64_t IOHIDEventGetTimeStamp(IOHIDEventRef); 87 84 88 WTF_EXTERN_C_END 85 89 -
trunk/Source/WebCore/platform/PlatformWheelEvent.cpp
r285787 r285790 76 76 77 77 #if PLATFORM(COCOA) 78 platformWheelEvent.m_ioHIDEventTimestamp = platformWheelEvent.m_timestamp; 78 79 platformWheelEvent.m_unacceleratedScrollingDeltaY = deltaY; 79 80 #endif // PLATFORM(COCOA) -
trunk/Source/WebCore/platform/PlatformWheelEvent.h
r285367 r285790 152 152 unsigned scrollCount() const { return m_scrollCount; } 153 153 FloatSize unacceleratedScrollingDelta() const { return { m_unacceleratedScrollingDeltaX, m_unacceleratedScrollingDeltaY }; } 154 155 WallTime ioHIDEventTimestamp() const { return m_ioHIDEventTimestamp; } 154 156 #endif 155 157 … … 200 202 #endif 201 203 #if PLATFORM(COCOA) 204 WallTime m_ioHIDEventTimestamp; 202 205 unsigned m_scrollCount { 0 }; 203 206 float m_unacceleratedScrollingDeltaX { 0 }; -
trunk/Source/WebCore/platform/mac/PlatformEventFactoryMac.h
r235158 r285790 51 51 WEBCORE_EXPORT String keyForKeyEvent(NSEvent *); 52 52 WEBCORE_EXPORT String codeForKeyEvent(NSEvent *); 53 WEBCORE_EXPORT WallTime eventTimeStampSince1970(NS Event *);53 WEBCORE_EXPORT WallTime eventTimeStampSince1970(NSTimeInterval); 54 54 55 55 WEBCORE_EXPORT OptionSet<PlatformEvent::Modifier> modifiersForEvent(NSEvent *); -
trunk/Source/WebCore/platform/mac/PlatformEventFactoryMac.mm
r279059 r285790 608 608 } 609 609 610 WallTime eventTimeStampSince1970(NS Event* event)611 { 612 return WallTime::fromRawSeconds(static_cast<double>(cachedStartupTimeIntervalSince1970() + [event timestamp]));610 WallTime eventTimeStampSince1970(NSTimeInterval timestamp) 611 { 612 return WallTime::fromRawSeconds(static_cast<double>(cachedStartupTimeIntervalSince1970() + timestamp)); 613 613 } 614 614 … … 721 721 722 722 m_modifiers = modifiersForEvent(event); 723 m_timestamp = eventTimeStampSince1970(event );723 m_timestamp = eventTimeStampSince1970(event.timestamp); 724 724 725 725 // PlatformMouseEvent … … 756 756 m_type = PlatformEvent::Wheel; 757 757 m_modifiers = modifiersForEvent(event); 758 m_timestamp = eventTimeStampSince1970(event );758 m_timestamp = eventTimeStampSince1970(event.timestamp); 759 759 760 760 // PlatformWheelEvent … … 795 795 m_type = isKeyUpEvent(event) ? PlatformEvent::KeyUp : PlatformEvent::KeyDown; 796 796 m_modifiers = modifiersForEvent(event); 797 m_timestamp = eventTimeStampSince1970(event );797 m_timestamp = eventTimeStampSince1970(event.timestamp); 798 798 799 799 // PlatformKeyboardEvent -
trunk/Source/WebKit/ChangeLog
r285775 r285790 1 2021-11-14 Simon Fraser <simon.fraser@apple.com> 2 3 Attach IOHIDEvent timestamps to wheel events 4 https://bugs.webkit.org/show_bug.cgi?id=233051 5 6 Reviewed by Wenson Hsieh. 7 8 On some macOS devices, there can be significant deltas between NSEvent timestamps, 9 and the timestamps on underlying IOHIDEvents (rdar://85309639). This makes momentum 10 velocity computation unpredictable; we can get better results by using IOHIDEvent 11 timestamps. 12 13 * Shared/WebEventConversion.cpp: 14 (WebKit::WebKit2PlatformWheelEvent::WebKit2PlatformWheelEvent): 15 * Shared/WebWheelEvent.cpp: 16 (WebKit::WebWheelEvent::WebWheelEvent): 17 (WebKit::WebWheelEvent::encode const): 18 (WebKit::WebWheelEvent::decode): 19 * Shared/WebWheelEvent.h: 20 (WebKit::WebWheelEvent::ioHIDEventTimestamp const): 21 * Shared/WebWheelEventCoalescer.cpp: 22 (WebKit::WebWheelEventCoalescer::coalesce): 23 * Shared/ios/WebIOSEventFactory.mm: 24 (WebIOSEventFactory::createWebWheelEvent): 25 * Shared/mac/NativeWebGestureEventMac.mm: 26 * Shared/mac/WebEventFactory.mm: 27 (WebKit::WebEventFactory::createWebMouseEvent): 28 (WebKit::WebEventFactory::createWebWheelEvent): 29 (WebKit::WebEventFactory::createWebKeyboardEvent): 30 1 31 2021-11-13 Per Arne Vollan <pvollan@apple.com> 2 32 -
trunk/Source/WebKit/Shared/WebEventConversion.cpp
r281610 r285790 170 170 #endif 171 171 #if PLATFORM(COCOA) 172 m_ioHIDEventTimestamp = webEvent.ioHIDEventTimestamp(); 172 173 m_scrollCount = webEvent.scrollCount(); 173 174 m_unacceleratedScrollingDeltaX = webEvent.unacceleratedScrollingDelta().width(); -
trunk/Source/WebKit/Shared/WebWheelEvent.cpp
r268522 r285790 45 45 46 46 #if PLATFORM(COCOA) 47 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 )47 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) 48 48 : WebEvent(type, modifiers, timestamp) 49 49 , m_position(position) … … 56 56 , m_directionInvertedFromDevice(directionInvertedFromDevice) 57 57 , m_hasPreciseScrollingDeltas(hasPreciseScrollingDeltas) 58 , m_ioHIDEventTimestamp(ioHIDEventTimestamp) 58 59 , m_scrollCount(scrollCount) 59 60 , m_unacceleratedScrollingDelta(unacceleratedScrollingDelta) … … 93 94 #endif 94 95 #if PLATFORM(COCOA) 96 encoder << m_ioHIDEventTimestamp; 95 97 encoder << m_scrollCount; 96 98 encoder << m_unacceleratedScrollingDelta; … … 123 125 #endif 124 126 #if PLATFORM(COCOA) 127 if (!decoder.decode(t.m_ioHIDEventTimestamp)) 128 return false; 125 129 if (!decoder.decode(t.m_scrollCount)) 126 130 return false; -
trunk/Source/WebKit/Shared/WebWheelEvent.h
r268522 r285790 54 54 WebWheelEvent(Type, const WebCore::IntPoint& position, const WebCore::IntPoint& globalPosition, const WebCore::FloatSize& delta, const WebCore::FloatSize& wheelTicks, Granularity, OptionSet<Modifier>, WallTime timestamp); 55 55 #if PLATFORM(COCOA) 56 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 );56 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); 57 57 #elif PLATFORM(GTK) || USE(LIBWPE) 58 58 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); … … 71 71 #endif 72 72 #if PLATFORM(COCOA) 73 WallTime ioHIDEventTimestamp() const { return m_ioHIDEventTimestamp; } 73 74 uint32_t scrollCount() const { return m_scrollCount; } 74 75 const WebCore::FloatSize& unacceleratedScrollingDelta() const { return m_unacceleratedScrollingDelta; } … … 88 89 uint32_t m_phase { Phase::PhaseNone }; 89 90 uint32_t m_momentumPhase { Phase::PhaseNone }; 91 90 92 bool m_directionInvertedFromDevice { false }; 91 93 #if PLATFORM(COCOA) || PLATFORM(GTK) || USE(LIBWPE) … … 93 95 #endif 94 96 #if PLATFORM(COCOA) 97 WallTime m_ioHIDEventTimestamp; 95 98 uint32_t m_scrollCount { 0 }; 96 99 WebCore::FloatSize m_unacceleratedScrollingDelta; -
trunk/Source/WebKit/Shared/WebWheelEventCoalescer.cpp
r285165 r285790 79 79 auto mergedUnacceleratedScrollingDelta = a.unacceleratedScrollingDelta() + b.unacceleratedScrollingDelta(); 80 80 81 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() );81 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()); 82 82 #elif PLATFORM(GTK) || USE(LIBWPE) 83 83 return WebWheelEvent(WebEvent::Wheel, b.position(), b.globalPosition(), mergedDelta, mergedWheelTicks, b.phase(), b.momentumPhase(), b.granularity(), b.hasPreciseScrollingDeltas(), b.modifiers(), b.timestamp()); -
trunk/Source/WebKit/Shared/ios/WebIOSEventFactory.mm
r278253 r285790 162 162 WebCore::FloatSize wheelTicks = delta; 163 163 wheelTicks.scale(1. / static_cast<float>(WebCore::Scrollbar::pixelsPerLineStep())); 164 164 auto timestamp = MonotonicTime::fromRawSeconds(event.timestamp).approximateWallTime(); 165 165 return { 166 166 WebKit::WebEvent::Wheel, … … 177 177 delta, 178 178 { }, 179 MonotonicTime::fromRawSeconds(event.timestamp).approximateWallTime() 179 timestamp, 180 timestamp 180 181 }; 181 182 } -
trunk/Source/WebKit/Shared/mac/NativeWebGestureEventMac.mm
r267916 r285790 63 63 webEventTypeForNSEvent(event), 64 64 OptionSet<WebEvent::Modifier> { }, 65 WebCore::eventTimeStampSince1970(event ),65 WebCore::eventTimeStampSince1970(event.timestamp), 66 66 WebCore::IntPoint(pointForEvent(event, view)), 67 67 event.type == NSEventTypeMagnify ? event.magnification : 0, -
trunk/Source/WebKit/Shared/mac/WebEventFactory.mm
r242325 r285790 33 33 #import <WebCore/Scrollbar.h> 34 34 #import <WebCore/WindowsKeyboardCodes.h> 35 #import <pal/spi/cg/CoreGraphicsSPI.h> 35 36 #import <pal/spi/mac/NSMenuSPI.h> 36 37 #import <wtf/ASCIICType.h> … … 354 355 int clickCount = clickCountForEvent(event); 355 356 auto modifiers = modifiersForEvent(event); 356 auto timestamp = WebCore::eventTimeStampSince1970(event );357 auto timestamp = WebCore::eventTimeStampSince1970(event.timestamp); 357 358 int eventNumber = [event eventNumber]; 358 359 int menuTypeForEvent = typeForEvent(event); … … 409 410 410 411 auto modifiers = modifiersForEvent(event); 411 auto timestamp = WebCore::eventTimeStampSince1970(event); 412 413 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); 412 auto timestamp = WebCore::eventTimeStampSince1970(event.timestamp); 413 414 auto ioHIDEventTimestamp = [](NSEvent *event) { 415 auto cgEvent = event.CGEvent; 416 if (!cgEvent) 417 return event.timestamp; 418 419 auto iohidEvent = adoptCF(CGEventCopyIOHIDEvent(cgEvent)); 420 if (!iohidEvent) 421 return event.timestamp; 422 423 auto ioHIDEventTimestamp = IOHIDEventGetTimeStamp(iohidEvent.get()); // IOEventRef timestamp is mach_absolute_time units. 424 return MonotonicTime::fromMachAbsoluteTime(ioHIDEventTimestamp).secondsSinceEpoch().seconds(); 425 }(event); 426 427 auto ioHIDEventWallTime = WebCore::eventTimeStampSince1970(ioHIDEventTimestamp); 428 429 return WebWheelEvent(WebEvent::Wheel, WebCore::IntPoint(position), WebCore::IntPoint(globalPosition), WebCore::FloatSize(deltaX, deltaY), WebCore::FloatSize(wheelTicksX, wheelTicksY), 430 granularity, directionInvertedFromDevice, phase, momentumPhase, hasPreciseScrollingDeltas, 431 scrollCount, unacceleratedScrollingDelta, modifiers, timestamp, ioHIDEventWallTime); 414 432 } 415 433 … … 429 447 bool isSystemKey = false; // SystemKey is always false on the Mac. 430 448 auto modifiers = modifiersForEvent(event); 431 auto timestamp = WebCore::eventTimeStampSince1970(event );449 auto timestamp = WebCore::eventTimeStampSince1970(event.timestamp); 432 450 433 451 // Always use 13 for Enter/Return -- we don't want to use AppKit's different character for Enter.
Note:
See TracChangeset
for help on using the changeset viewer.