зеркало из https://github.com/mozilla/gecko-dev.git
Bug 647216: Allow testing of MozMouseHittest window dragging. r=enndeakin
This commit is contained in:
Родитель
37b7d7dbc2
Коммит
69c7d8ae0b
|
@ -494,11 +494,12 @@ nsDOMWindowUtils::SendMouseEvent(const nsAString& aType,
|
|||
int32_t aModifiers,
|
||||
bool aIgnoreRootScrollFrame,
|
||||
float aPressure,
|
||||
unsigned short aInputSourceArg)
|
||||
unsigned short aInputSourceArg,
|
||||
bool *aPreventDefault)
|
||||
{
|
||||
return SendMouseEventCommon(aType, aX, aY, aButton, aClickCount, aModifiers,
|
||||
aIgnoreRootScrollFrame, aPressure,
|
||||
aInputSourceArg, false);
|
||||
aInputSourceArg, false, aPreventDefault);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -515,7 +516,7 @@ nsDOMWindowUtils::SendMouseEventToWindow(const nsAString& aType,
|
|||
SAMPLE_LABEL("nsDOMWindowUtils", "SendMouseEventToWindow");
|
||||
return SendMouseEventCommon(aType, aX, aY, aButton, aClickCount, aModifiers,
|
||||
aIgnoreRootScrollFrame, aPressure,
|
||||
aInputSourceArg, true);
|
||||
aInputSourceArg, true, nullptr);
|
||||
}
|
||||
|
||||
static nsIntPoint
|
||||
|
@ -538,7 +539,8 @@ nsDOMWindowUtils::SendMouseEventCommon(const nsAString& aType,
|
|||
bool aIgnoreRootScrollFrame,
|
||||
float aPressure,
|
||||
unsigned short aInputSourceArg,
|
||||
bool aToWindow)
|
||||
bool aToWindow,
|
||||
bool *aPreventDefault)
|
||||
{
|
||||
if (!nsContentUtils::IsCallerChrome()) {
|
||||
return NS_ERROR_DOM_SECURITY_ERR;
|
||||
|
@ -565,7 +567,9 @@ nsDOMWindowUtils::SendMouseEventCommon(const nsAString& aType,
|
|||
else if (aType.EqualsLiteral("contextmenu")) {
|
||||
msg = NS_CONTEXTMENU;
|
||||
contextMenuKey = (aButton == 0);
|
||||
} else
|
||||
} else if (aType.EqualsLiteral("MozMouseHittest"))
|
||||
msg = NS_MOUSE_MOZHITTEST;
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if (aInputSourceArg == nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN) {
|
||||
|
@ -606,7 +610,10 @@ nsDOMWindowUtils::SendMouseEventCommon(const nsAString& aType,
|
|||
status = nsEventStatus_eIgnore;
|
||||
return presShell->HandleEvent(view->GetFrame(), &event, false, &status);
|
||||
}
|
||||
return widget->DispatchEvent(&event, status);
|
||||
nsresult rv = widget->DispatchEvent(&event, status);
|
||||
*aPreventDefault = (status == nsEventStatus_eConsumeNoDefault);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -44,7 +44,8 @@ protected:
|
|||
bool aIgnoreRootScrollFrame,
|
||||
float aPressure,
|
||||
unsigned short aInputSourceArg,
|
||||
bool aToWindow);
|
||||
bool aToWindow,
|
||||
bool *aPreventDefault);
|
||||
|
||||
static mozilla::widget::Modifiers GetWidgetModifiers(int32_t aModifiers);
|
||||
};
|
||||
|
|
|
@ -40,7 +40,7 @@ interface nsIDOMTouch;
|
|||
interface nsIDOMClientRect;
|
||||
interface nsIURI;
|
||||
|
||||
[scriptable, uuid(d0b58b1b-58fa-49a0-8e4d-a3693bc65ebd)]
|
||||
[scriptable, uuid(020deb5a-cba6-41dd-8551-72a880d01970)]
|
||||
interface nsIDOMWindowUtils : nsISupports {
|
||||
|
||||
/**
|
||||
|
@ -202,7 +202,8 @@ interface nsIDOMWindowUtils : nsISupports {
|
|||
const long MODIFIER_OS = 0x0400;
|
||||
|
||||
/** Synthesize a mouse event. The event types supported are:
|
||||
* mousedown, mouseup, mousemove, mouseover, mouseout, contextmenu
|
||||
* mousedown, mouseup, mousemove, mouseover, mouseout, contextmenu,
|
||||
* MozMouseHitTest
|
||||
*
|
||||
* Events are sent in coordinates offset by aX and aY from the window.
|
||||
*
|
||||
|
@ -234,16 +235,18 @@ interface nsIDOMWindowUtils : nsISupports {
|
|||
* @param aPressure touch input pressure: 0.0 -> 1.0
|
||||
* @param aInputSourceArg input source, see nsIDOMMouseEvent for values,
|
||||
* defaults to mouse input.
|
||||
*
|
||||
* returns true if the page called prevent default on this event
|
||||
*/
|
||||
void sendMouseEvent(in AString aType,
|
||||
in float aX,
|
||||
in float aY,
|
||||
in long aButton,
|
||||
in long aClickCount,
|
||||
in long aModifiers,
|
||||
[optional] in boolean aIgnoreRootScrollFrame,
|
||||
[optional] in float aPressure,
|
||||
[optional] in unsigned short aInputSourceArg);
|
||||
boolean sendMouseEvent(in AString aType,
|
||||
in float aX,
|
||||
in float aY,
|
||||
in long aButton,
|
||||
in long aClickCount,
|
||||
in long aModifiers,
|
||||
[optional] in boolean aIgnoreRootScrollFrame,
|
||||
[optional] in float aPressure,
|
||||
[optional] in unsigned short aInputSourceArg);
|
||||
|
||||
/** Synthesize a touch event. The event types supported are:
|
||||
* touchstart, touchend, touchmove, and touchcancel
|
||||
|
|
|
@ -1276,8 +1276,9 @@ TabChild::RecvMouseEvent(const nsString& aType,
|
|||
{
|
||||
nsCOMPtr<nsIDOMWindowUtils> utils(GetDOMWindowUtils());
|
||||
NS_ENSURE_TRUE(utils, true);
|
||||
bool ignored = false;
|
||||
utils->SendMouseEvent(aType, aX, aY, aButton, aClickCount, aModifiers,
|
||||
aIgnoreRootScrollFrame, 0, 0);
|
||||
aIgnoreRootScrollFrame, 0, 0, &ignored);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -206,11 +206,13 @@ function _parseModifiers(aEvent)
|
|||
* a mousedown followed by a mouse up is performed.
|
||||
*
|
||||
* aWindow is optional, and defaults to the current window object.
|
||||
*
|
||||
* Returns whether the event had preventDefault() called on it.
|
||||
*/
|
||||
function synthesizeMouse(aTarget, aOffsetX, aOffsetY, aEvent, aWindow)
|
||||
{
|
||||
var rect = aTarget.getBoundingClientRect();
|
||||
synthesizeMouseAtPoint(rect.left + aOffsetX, rect.top + aOffsetY,
|
||||
return synthesizeMouseAtPoint(rect.left + aOffsetX, rect.top + aOffsetY,
|
||||
aEvent, aWindow);
|
||||
}
|
||||
function synthesizeTouch(aTarget, aOffsetX, aOffsetY, aEvent, aWindow)
|
||||
|
@ -234,6 +236,7 @@ function synthesizeTouch(aTarget, aOffsetX, aOffsetY, aEvent, aWindow)
|
|||
function synthesizeMouseAtPoint(left, top, aEvent, aWindow)
|
||||
{
|
||||
var utils = _getDOMWindowUtils(aWindow);
|
||||
var defaultPrevented = false;
|
||||
|
||||
if (utils) {
|
||||
var button = aEvent.button || 0;
|
||||
|
@ -241,13 +244,15 @@ function synthesizeMouseAtPoint(left, top, aEvent, aWindow)
|
|||
var modifiers = _parseModifiers(aEvent);
|
||||
|
||||
if (("type" in aEvent) && aEvent.type) {
|
||||
utils.sendMouseEvent(aEvent.type, left, top, button, clickCount, modifiers);
|
||||
defaultPrevented = utils.sendMouseEvent(aEvent.type, left, top, button, clickCount, modifiers);
|
||||
}
|
||||
else {
|
||||
utils.sendMouseEvent("mousedown", left, top, button, clickCount, modifiers);
|
||||
utils.sendMouseEvent("mouseup", left, top, button, clickCount, modifiers);
|
||||
}
|
||||
}
|
||||
|
||||
return defaultPrevented;
|
||||
}
|
||||
function synthesizeTouchAtPoint(left, top, aEvent, aWindow)
|
||||
{
|
||||
|
|
|
@ -52,7 +52,6 @@
|
|||
<statusbar id="statusbar">
|
||||
<statusbarpanel>
|
||||
<label id="statuslabel" value="Status"/>
|
||||
<label id="statuslabelnodrag" value="No Drag" onmousedown="event.preventDefault()"/>
|
||||
</statusbarpanel>
|
||||
</statusbar>
|
||||
|
||||
|
@ -106,26 +105,18 @@ function test_titlebar()
|
|||
var titlebar = document.getElementById("titlebar");
|
||||
var label = document.getElementById("label");
|
||||
|
||||
// on Mac, the window can also be moved with the statusbar
|
||||
// On Mac, the window can also be moved with the statusbar, but this works
|
||||
// via the MozMouseHittest event, not via mouse events.
|
||||
if (navigator.platform.indexOf("Mac") >= 0) {
|
||||
var preventDefaulted;
|
||||
|
||||
var statuslabel = document.getElementById("statuslabel");
|
||||
var statuslabelnodrag = document.getElementById("statuslabelnodrag");
|
||||
preventDefaulted = synthesizeMouse(statuslabel, 2, 2, { type: "MozMouseHittest" });
|
||||
SimpleTest.ok(preventDefaulted, "MozMouseHittest should have been defaultPrevented over statusbar");
|
||||
|
||||
origoldx = window.screenX;
|
||||
origoldy = window.screenY;
|
||||
|
||||
synthesizeMouse(statuslabel, 2, 2, { type: "mousedown" });
|
||||
synthesizeMouse(statuslabel, 22, 22, { type: "mousemove" });
|
||||
SimpleTest.is(window.screenX, origoldx + 20, "move window with statusbar horizontal");
|
||||
SimpleTest.is(window.screenY, origoldy + 20, "move window with statusbar vertical");
|
||||
synthesizeMouse(statuslabel, 22, 22, { type: "mouseup" });
|
||||
|
||||
// event was cancelled so the drag should not have occurred
|
||||
synthesizeMouse(statuslabelnodrag, 2, 2, { type: "mousedown" });
|
||||
synthesizeMouse(statuslabelnodrag, 22, 22, { type: "mousemove" });
|
||||
SimpleTest.is(window.screenX, origoldx + 20, "move window with statusbar cancelled mousedown horizontal");
|
||||
SimpleTest.is(window.screenY, origoldy + 20, "move window with statusbar cancelled mousedown vertical");
|
||||
synthesizeMouse(statuslabelnodrag, 22, 22, { type: "mouseup" });
|
||||
var button = document.getElementById("button");
|
||||
preventDefaulted = synthesizeMouse(button, 2, 2, { type: "MozMouseHittest" });
|
||||
SimpleTest.ok(!preventDefaulted, "MozMouseHittest should NOT have been defaultPrevented over button");
|
||||
}
|
||||
|
||||
origoldx = window.screenX;
|
||||
|
|
Загрузка…
Ссылка в новой задаче