Bug 1174323 part 1 - Add nsDOMWindowUtils::SendNativeMouseMove and EventUtils.sendNativeMouseMove.
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -1026,16 +1026,34 @@ nsDOMWindowUtils::SendNativeMouseEvent(i
<LayoutDeviceIntPoint, int32_t, int32_t, nsIObserver*>
(widget, &nsIWidget::SynthesizeNativeMouseEvent,
LayoutDeviceIntPoint(aScreenX, aScreenY), aNativeMessage, aModifierFlags,
aObserver));
return NS_OK;
}
NS_IMETHODIMP
+nsDOMWindowUtils::SendNativeMouseMove(int32_t aScreenX,
+ int32_t aScreenY,
+ nsIDOMElement* aElement,
+ nsIObserver* aObserver)
+{
+ // get the widget to send the event to
+ nsCOMPtr<nsIWidget> widget = GetWidgetForElement(aElement);
+ if (!widget)
+ return NS_ERROR_FAILURE;
+
+ NS_DispatchToMainThread(NS_NewRunnableMethodWithArgs
+ <LayoutDeviceIntPoint, nsIObserver*>
+ (widget, &nsIWidget::SynthesizeNativeMouseMove,
+ LayoutDeviceIntPoint(aScreenX, aScreenY), aObserver));
+ return NS_OK;
+}
+
+NS_IMETHODIMP
nsDOMWindowUtils::SendNativeMouseScrollEvent(int32_t aScreenX,
int32_t aScreenY,
uint32_t aNativeMessage,
double aDeltaX,
double aDeltaY,
double aDeltaZ,
uint32_t aModifierFlags,
uint32_t aAdditionalFlags,
--- a/dom/interfaces/base/nsIDOMWindowUtils.idl
+++ b/dom/interfaces/base/nsIDOMWindowUtils.idl
@@ -44,17 +44,17 @@ interface nsIDOMClientRect;
interface nsIURI;
interface nsIDOMEventTarget;
interface nsIRunnable;
interface nsITranslationNodeList;
interface nsIJSRAIIHelper;
interface nsIContentPermissionRequest;
interface nsIObserver;
-[scriptable, uuid(3f3f2bf4-d411-44b2-b2f7-dee5948c4763)]
+[scriptable, uuid(7846c43d-e131-40a6-8417-3be2c7e11df1)]
interface nsIDOMWindowUtils : nsISupports {
/**
* Image animation mode of the window. When this attribute's value
* is changed, the implementation should set all images in the window
* to the given value. That is, when set to kDontAnimMode, all images
* will stop animating. The attribute's value must be one of the
* animationMode values from imgIContainer.
@@ -585,16 +585,23 @@ interface nsIDOMWindowUtils : nsISupport
* topic.
*/
void sendNativeMouseEvent(in long aScreenX,
in long aScreenY,
in long aNativeMessage,
in long aModifierFlags,
in nsIDOMElement aElement,
[optional] in nsIObserver aObserver);
+ /**
+ * See nsIWidget::SynthesizeNativeMouseMove and sendNativeMouseEvent
+ */
+ void sendNativeMouseMove(in long aScreenX,
+ in long aScreenY,
+ in nsIDOMElement aElement,
+ [optional] in nsIObserver aObserver);
/**
* The values for sendNativeMouseScrollEvent's aAdditionalFlags.
*/
/**
* If MOUSESCROLL_PREFER_WIDGET_AT_POINT is set, widget will dispatch
* the event to a widget which is under the cursor. Otherwise, dispatch to
--- a/testing/mochitest/tests/SimpleTest/EventUtils.js
+++ b/testing/mochitest/tests/SimpleTest/EventUtils.js
@@ -545,16 +545,40 @@ function sendWheelAndPaint(aTarget, aOff
}
}, 0);
};
aWindow.addEventListener("wheel", onwheel);
synthesizeWheel(aTarget, aOffsetX, aOffsetY, aEvent, aWindow);
}
+function synthesizeNativeMouseMove(aTarget, aOffsetX, aOffsetY, aWindow) {
+ aWindow = aWindow || window;
+
+ var utils = _getDOMWindowUtils(aWindow);
+ if (!utils)
+ return;
+
+ var rect = aTarget.getBoundingClientRect();
+ var x = aOffsetX + window.mozInnerScreenX + rect.left;
+ var y = aOffsetY + window.mozInnerScreenY + rect.top;
+ var scale = utils.screenPixelsPerCSSPixel;
+
+ return new Promise(resolve => {
+ let observer = {
+ observe: (subject, topic, data) => {
+ if (topic == "mouseevent") {
+ resolve();
+ }
+ }
+ };
+ utils.sendNativeMouseMove(x * scale, y * scale, null, observer);
+ });
+}
+
function _computeKeyCodeFromChar(aChar)
{
if (aChar.length != 1) {
return 0;
}
const nsIDOMKeyEvent = _EU_Ci.nsIDOMKeyEvent;
if (aChar >= 'a' && aChar <= 'z') {
return nsIDOMKeyEvent.DOM_VK_A + aChar.charCodeAt(0) - 'a'.charCodeAt(0);