Bug 1161206 - Implement native mousewheel event synthesization on OS X. r=mstange

This commit is contained in:
Kartikaya Gupta 2015-05-05 14:45:11 -04:00
Родитель 29b4070568
Коммит 83a95ac8fd
3 изменённых файлов: 51 добавлений и 1 удалений

Просмотреть файл

@ -51,7 +51,7 @@ interface nsIJSRAIIHelper;
interface nsIContentPermissionRequest;
interface nsIObserver;
[scriptable, uuid(9bb4a34f-de8f-43d3-a58c-10757cac95a0)]
[scriptable, uuid(1a75c351-d115-4d51-94df-731dd1723a1f)]
interface nsIDOMWindowUtils : nsISupports {
/**
@ -613,6 +613,11 @@ interface nsIDOMWindowUtils : nsISupports {
*/
const unsigned long MOUSESCROLL_PREFER_WIDGET_AT_POINT = 0x00000001;
/**
* Interpret the scroll delta values as lines rather than pixels.
*/
const unsigned long MOUSESCROLL_SCROLL_LINES = 0x00000002;
/**
* The platform specific values of aAdditionalFlags. Must be over 0x00010000.
*/

Просмотреть файл

@ -466,6 +466,14 @@ public:
virtual nsresult SynthesizeNativeMouseMove(mozilla::LayoutDeviceIntPoint aPoint,
nsIObserver* aObserver) override
{ return SynthesizeNativeMouseEvent(aPoint, NSMouseMoved, 0, aObserver); }
virtual nsresult SynthesizeNativeMouseScrollEvent(mozilla::LayoutDeviceIntPoint aPoint,
uint32_t aNativeMessage,
double aDeltaX,
double aDeltaY,
double aDeltaZ,
uint32_t aModifierFlags,
uint32_t aAdditionalFlags,
nsIObserver* aObserver) override;
// Mac specific methods

Просмотреть файл

@ -91,6 +91,7 @@
#include "InputData.h"
#include "VibrancyManager.h"
#include "nsNativeThemeCocoa.h"
#include "nsIDOMWindowUtils.h"
using namespace mozilla;
using namespace mozilla::layers;
@ -1185,6 +1186,42 @@ nsresult nsChildView::SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint,
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
nsresult nsChildView::SynthesizeNativeMouseScrollEvent(mozilla::LayoutDeviceIntPoint aPoint,
uint32_t aNativeMessage,
double aDeltaX,
double aDeltaY,
double aDeltaZ,
uint32_t aModifierFlags,
uint32_t aAdditionalFlags,
nsIObserver* aObserver)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
AutoObserverNotifier notifier(aObserver, "mousescrollevent");
NSPoint pt =
nsCocoaUtils::DevPixelsToCocoaPoints(aPoint, BackingScaleFactor());
// Move the mouse cursor to the requested position and reconnect it to the mouse.
CGWarpMouseCursorPosition(NSPointToCGPoint(pt));
CGAssociateMouseAndMouseCursorPosition(true);
// Mostly copied from http://stackoverflow.com/a/6130349
CGScrollEventUnit units =
(aAdditionalFlags & nsIDOMWindowUtils::MOUSESCROLL_SCROLL_LINES)
? kCGScrollEventUnitLine : kCGScrollEventUnitPixel;
CGEventRef cgEvent = CGEventCreateScrollWheelEvent(NULL, units, 3, aDeltaY, aDeltaX, aDeltaZ);
if (!cgEvent) {
return NS_ERROR_FAILURE;
}
CGEventPost(kCGHIDEventTap, cgEvent);
CFRelease(cgEvent);
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)