Bug 1264017 - Add an APZ test API to synthesize a mouse click. r=botond

MozReview-Commit-ID: 1zeoPTGrrLh
This commit is contained in:
Kartikaya Gupta 2016-05-16 12:17:17 -04:00
parent 91695742a1
commit 392f87445d
2 changed files with 39 additions and 7 deletions

View File

@ -44,6 +44,14 @@ function nativeScrollUnits(aElement, aDimen) {
return aDimen;
}
function nativeMouseDownEventMsg() {
switch (getPlatform()) {
case "windows": return 2; // MOUSEEVENTF_LEFTDOWN
case "mac": return 1; // NSLeftMouseDown
case "linux": return 4; // GDK_BUTTON_PRESS
}
}
function nativeMouseMoveEventMsg() {
switch (getPlatform()) {
case "windows": return 1; // MOUSEEVENTF_MOVE
@ -53,6 +61,14 @@ function nativeMouseMoveEventMsg() {
throw "Native wheel events not supported on platform " + getPlatform();
}
function nativeMouseUpEventMsg() {
switch (getPlatform()) {
case "windows": return 4; // MOUSEEVENTF_LEFTUP
case "mac": return 2; // NSLeftMouseUp
case "linux": return 7; // GDK_BUTTON_RELEASE
}
}
// Convert (aX, aY), in CSS pixels relative to aElement's bounding rect,
// to device pixels relative to aElement's containing window.
function coordinatesRelativeToWindow(aX, aY, aElement) {
@ -177,3 +193,12 @@ function synthesizeNativeTap(aElement, aX, aY, aObserver = null) {
utils.sendNativeTouchTap(pt.x, pt.y, false, aObserver);
return true;
}
function synthesizeNativeClick(aElement, aX, aY, aObserver = null) {
var pt = coordinatesRelativeToWindow(aX, aY, aElement);
var utils = SpecialPowers.getDOMWindowUtils(aElement.ownerDocument.defaultView);
utils.sendNativeMouseEvent(pt.x, pt.y, nativeMouseDownEventMsg(), 0, aElement, function() {
utils.sendNativeMouseEvent(pt.x, pt.y, nativeMouseUpEventMsg(), 0, aElement, aObserver);
});
return true;
}

View File

@ -6810,12 +6810,12 @@ nsWindow::SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint,
GdkDisplay* display = gdk_window_get_display(mGdkWindow);
// When a button-release event is requested, create it here and put it in the
// When a button-press/release event is requested, create it here and put it in the
// event queue. This will not emit a motion event - this needs to be done
// explicitly *before* requesting a button-release. You will also need to wait
// for the motion event to be dispatched before requesting a button-release
// explicitly *before* requesting a button-press/release. You will also need to wait
// for the motion event to be dispatched before requesting a button-press/release
// event to maintain the desired event order.
if (aNativeMessage == GDK_BUTTON_RELEASE) {
if (aNativeMessage == GDK_BUTTON_PRESS || aNativeMessage == GDK_BUTTON_RELEASE) {
GdkEvent event;
memset(&event, 0, sizeof(GdkEvent));
event.type = (GdkEventType)aNativeMessage;
@ -6829,11 +6829,18 @@ nsWindow::SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint,
event.button.device = gdk_device_manager_get_client_pointer(device_manager);
#endif
event.button.x_root = DevicePixelsToGdkCoordRoundDown(aPoint.x);
event.button.y_root = DevicePixelsToGdkCoordRoundDown(aPoint.y);
LayoutDeviceIntPoint pointInWindow = aPoint - WidgetToScreenOffset();
event.button.x = DevicePixelsToGdkCoordRoundDown(pointInWindow.x);
event.button.y = DevicePixelsToGdkCoordRoundDown(pointInWindow.y);
gdk_event_put(&event);
} else {
// We don't support specific events other than button-release. In case
// aNativeMessage != GDK_BUTTON_RELEASE we'll synthesize a motion event
// that will be emitted by gdk_display_warp_pointer().
// We don't support specific events other than button-press/release. In all
// other cases we'll synthesize a motion event that will be emitted by
// gdk_display_warp_pointer().
GdkScreen* screen = gdk_window_get_screen(mGdkWindow);
GdkPoint point = DevicePixelsToGdkPointRoundDown(aPoint);
gdk_display_warp_pointer(display, screen, point.x, point.y);