From f27c48490f244f1f930c0c396d68799fb6633042 Mon Sep 17 00:00:00 2001 From: Kartikaya Gupta Date: Mon, 25 Jul 2016 17:33:09 -0700 Subject: [PATCH] Bug 1288187 - Allow synthesizing widget touch events on OS X. r=mstange MozReview-Commit-ID: AGvZQZtbPh --- widget/cocoa/nsChildView.h | 10 ++++++++ widget/cocoa/nsChildView.mm | 48 +++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/widget/cocoa/nsChildView.h b/widget/cocoa/nsChildView.h index 2e62f4251a33..c814fc00d58a 100644 --- a/widget/cocoa/nsChildView.h +++ b/widget/cocoa/nsChildView.h @@ -419,6 +419,12 @@ public: uint32_t aModifierFlags, uint32_t aAdditionalFlags, nsIObserver* aObserver) override; + virtual nsresult SynthesizeNativeTouchPoint(uint32_t aPointerId, + TouchPointerState aPointerState, + LayoutDeviceIntPoint aPoint, + double aPointerPressure, + uint32_t aPointerOrientation, + nsIObserver* aObserver) override; // Mac specific methods @@ -646,6 +652,10 @@ protected: static uint32_t sLastInputEventCount; void ReleaseTitlebarCGContext(); + + // This is used by SynthesizeNativeTouchPoint to maintain state between + // multiple synthesized points + mozilla::UniquePtr mSynthesizedTouchInput; }; #endif // nsChildView_h_ diff --git a/widget/cocoa/nsChildView.mm b/widget/cocoa/nsChildView.mm index 9f12a334f586..83c162392778 100644 --- a/widget/cocoa/nsChildView.mm +++ b/widget/cocoa/nsChildView.mm @@ -1184,6 +1184,54 @@ nsresult nsChildView::SynthesizeNativeMouseScrollEvent(mozilla::LayoutDeviceIntP NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; } +nsresult nsChildView::SynthesizeNativeTouchPoint(uint32_t aPointerId, + TouchPointerState aPointerState, + mozilla::LayoutDeviceIntPoint aPoint, + double aPointerPressure, + uint32_t aPointerOrientation, + nsIObserver* aObserver) +{ + NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; + + AutoObserverNotifier notifier(aObserver, "touchpoint"); + + MOZ_ASSERT(NS_IsMainThread()); + if (aPointerState == TOUCH_HOVER) { + return NS_ERROR_UNEXPECTED; + } + + if (!mSynthesizedTouchInput) { + mSynthesizedTouchInput = MakeUnique(); + } + + LayoutDeviceIntPoint pointInWindow = aPoint - WidgetToScreenOffset(); + MultiTouchInput inputToDispatch = UpdateSynthesizedTouchState( + mSynthesizedTouchInput.get(), aPointerId, aPointerState, + pointInWindow, aPointerPressure, aPointerOrientation); + + if (mAPZC) { + uint64_t inputBlockId = 0; + ScrollableLayerGuid guid; + + nsEventStatus result = mAPZC->ReceiveInputEvent(inputToDispatch, &guid, &inputBlockId); + if (result == nsEventStatus_eConsumeNoDefault) { + return NS_OK; + } + + WidgetTouchEvent event = inputToDispatch.ToWidgetTouchEvent(this); + ProcessUntransformedAPZEvent(&event, guid, inputBlockId, result); + } else { + WidgetTouchEvent event = inputToDispatch.ToWidgetTouchEvent(this); + + nsEventStatus status; + DispatchEvent(&event, status); + } + + return NS_OK;; + + NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; +} + // First argument has to be an NSMenu representing the application's top-level // menu bar. The returned item is *not* retained. static NSMenuItem* NativeMenuItemWithLocation(NSMenu* menubar, NSString* locationString)