mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-27 21:00:50 +00:00
Bug 462979. Fix synthesizeMouse to send events to the right place. r=enn, sr=roc, a=beltzner
This commit is contained in:
parent
da02b6f204
commit
8b028084c0
@ -78,8 +78,8 @@ addLoadEvent(function() {
|
||||
submitForm(++pendingLoads);
|
||||
submitForm(++pendingLoads);
|
||||
submitForm(++pendingLoads);
|
||||
/* submitFormMouse(++pendingLoads);
|
||||
submitFormMouse(++pendingLoads);*/
|
||||
submitFormMouse(++pendingLoads);
|
||||
submitFormMouse(++pendingLoads);
|
||||
}, 0);
|
||||
});
|
||||
|
||||
|
@ -114,8 +114,8 @@ interface nsIDOMWindowUtils : nsISupports {
|
||||
* privileges.
|
||||
*
|
||||
* @param aType event type
|
||||
* @param aX x offset
|
||||
* @param aY y offset
|
||||
* @param aX x offset in CSS pixels
|
||||
* @param aY y offset in CSS pixels
|
||||
* @param aButton button to synthesize
|
||||
* @param aClickCount number of clicks that have been performed
|
||||
* @param aModifiers modifiers pressed, using constants defined in nsIDOMNSEvent
|
||||
@ -123,8 +123,8 @@ interface nsIDOMWindowUtils : nsISupports {
|
||||
* during dispatch
|
||||
*/
|
||||
void sendMouseEvent(in AString aType,
|
||||
in long aX,
|
||||
in long aY,
|
||||
in float aX,
|
||||
in float aY,
|
||||
in long aButton,
|
||||
in long aClickCount,
|
||||
in long aModifiers,
|
||||
@ -142,8 +142,8 @@ interface nsIDOMWindowUtils : nsISupports {
|
||||
* privileges.
|
||||
*
|
||||
* @param aType event type
|
||||
* @param aX x offset
|
||||
* @param aY y offset
|
||||
* @param aX x offset in CSS pixels
|
||||
* @param aY y offset in CSS pixels
|
||||
* @param aButton button to synthesize
|
||||
* @param aScrollFlags flag bits --- see nsMouseScrollFlags in nsGUIEvent.h
|
||||
* @param aDelta the direction and amount to scroll (in lines or pixels,
|
||||
@ -151,8 +151,8 @@ interface nsIDOMWindowUtils : nsISupports {
|
||||
* @param aModifiers modifiers pressed, using constants defined in nsIDOMNSEvent
|
||||
*/
|
||||
void sendMouseScrollEvent(in AString aType,
|
||||
in long aX,
|
||||
in long aY,
|
||||
in float aX,
|
||||
in float aY,
|
||||
in long aButton,
|
||||
in long aScrollFlags,
|
||||
in long aDelta,
|
||||
|
@ -195,8 +195,8 @@ nsDOMWindowUtils::Redraw(PRUint32 aCount, PRUint32 *aDurationOut)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMWindowUtils::SendMouseEvent(const nsAString& aType,
|
||||
PRInt32 aX,
|
||||
PRInt32 aY,
|
||||
float aX,
|
||||
float aY,
|
||||
PRInt32 aButton,
|
||||
PRInt32 aClickCount,
|
||||
PRInt32 aModifiers,
|
||||
@ -208,7 +208,8 @@ nsDOMWindowUtils::SendMouseEvent(const nsAString& aType,
|
||||
return NS_ERROR_DOM_SECURITY_ERR;
|
||||
|
||||
// get the widget to send the event to
|
||||
nsCOMPtr<nsIWidget> widget = GetWidget();
|
||||
nsPoint offset;
|
||||
nsCOMPtr<nsIWidget> widget = GetWidget(&offset);
|
||||
if (!widget)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
@ -242,8 +243,14 @@ nsDOMWindowUtils::SendMouseEvent(const nsAString& aType,
|
||||
|
||||
event.clickCount = aClickCount;
|
||||
event.time = PR_IntervalNow();
|
||||
event.refPoint.x = aX;
|
||||
event.refPoint.y = aY;
|
||||
|
||||
float appPerDev = float(widget->GetDeviceContext()->AppUnitsPerDevPixel());
|
||||
event.refPoint.x =
|
||||
NSAppUnitsToIntPixels(nsPresContext::CSSPixelsToAppUnits(aX) + offset.x,
|
||||
appPerDev);
|
||||
event.refPoint.y =
|
||||
NSAppUnitsToIntPixels(nsPresContext::CSSPixelsToAppUnits(aY) + offset.y,
|
||||
appPerDev);
|
||||
event.ignoreScrollFrame = aIgnoreScrollFrame;
|
||||
|
||||
nsEventStatus status;
|
||||
@ -252,8 +259,8 @@ nsDOMWindowUtils::SendMouseEvent(const nsAString& aType,
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMWindowUtils::SendMouseScrollEvent(const nsAString& aType,
|
||||
PRInt32 aX,
|
||||
PRInt32 aY,
|
||||
float aX,
|
||||
float aY,
|
||||
PRInt32 aButton,
|
||||
PRInt32 aScrollFlags,
|
||||
PRInt32 aDelta,
|
||||
@ -265,7 +272,8 @@ nsDOMWindowUtils::SendMouseScrollEvent(const nsAString& aType,
|
||||
return NS_ERROR_DOM_SECURITY_ERR;
|
||||
|
||||
// get the widget to send the event to
|
||||
nsCOMPtr<nsIWidget> widget = GetWidget();
|
||||
nsPoint offset;
|
||||
nsCOMPtr<nsIWidget> widget = GetWidget(&offset);
|
||||
if (!widget)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
@ -288,8 +296,14 @@ nsDOMWindowUtils::SendMouseScrollEvent(const nsAString& aType,
|
||||
event.scrollFlags = aScrollFlags;
|
||||
|
||||
event.time = PR_IntervalNow();
|
||||
event.refPoint.x = aX;
|
||||
event.refPoint.y = aY;
|
||||
|
||||
float appPerDev = float(widget->GetDeviceContext()->AppUnitsPerDevPixel());
|
||||
event.refPoint.x =
|
||||
NSAppUnitsToIntPixels(nsPresContext::CSSPixelsToAppUnits(aX) + offset.x,
|
||||
appPerDev);
|
||||
event.refPoint.y =
|
||||
NSAppUnitsToIntPixels(nsPresContext::CSSPixelsToAppUnits(aY) + offset.y,
|
||||
appPerDev);
|
||||
|
||||
nsEventStatus status;
|
||||
return widget->DispatchEvent(&event, status);
|
||||
@ -401,7 +415,7 @@ nsDOMWindowUtils::ForceUpdateNativeMenuAt(const nsAString& indexString)
|
||||
}
|
||||
|
||||
nsIWidget*
|
||||
nsDOMWindowUtils::GetWidget()
|
||||
nsDOMWindowUtils::GetWidget(nsPoint* aOffset)
|
||||
{
|
||||
if (mWindow) {
|
||||
nsIDocShell *docShell = mWindow->GetDocShell();
|
||||
@ -411,7 +425,7 @@ nsDOMWindowUtils::GetWidget()
|
||||
if (presShell) {
|
||||
nsIFrame* frame = presShell->GetRootFrame();
|
||||
if (frame)
|
||||
return frame->GetWindow();
|
||||
return frame->GetView()->GetNearestWidget(aOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -54,5 +54,7 @@ public:
|
||||
protected:
|
||||
nsRefPtr<nsGlobalWindow> mWindow;
|
||||
|
||||
nsIWidget* GetWidget();
|
||||
// If aOffset is non-null, it gets filled in with an offset, in app
|
||||
// units, that should be added to any event offset we're given.
|
||||
nsIWidget* GetWidget(nsPoint* aOffset = nsnull);
|
||||
};
|
||||
|
@ -211,15 +211,16 @@ function synthesizeMouse(aTarget, aOffsetX, aOffsetY, aEvent, aWindow)
|
||||
var modifiers = _parseModifiers(aEvent);
|
||||
|
||||
var rect = aTarget.getBoundingClientRect();
|
||||
var left = rect.left;
|
||||
var top = rect.top;
|
||||
|
||||
var left = rect.left + aOffsetX;
|
||||
var top = rect.top + aOffsetY;
|
||||
|
||||
if (aEvent.type) {
|
||||
utils.sendMouseEvent(aEvent.type, left + aOffsetX, top + aOffsetY, button, clickCount, modifiers);
|
||||
utils.sendMouseEvent(aEvent.type, left, top, button, clickCount, modifiers);
|
||||
}
|
||||
else {
|
||||
utils.sendMouseEvent("mousedown", left + aOffsetX, top + aOffsetY, button, clickCount, modifiers);
|
||||
utils.sendMouseEvent("mouseup", left + aOffsetX, top + aOffsetY, button, clickCount, modifiers);
|
||||
utils.sendMouseEvent("mousedown", left, top, button, clickCount, modifiers);
|
||||
utils.sendMouseEvent("mouseup", left, top, button, clickCount, modifiers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -66,8 +66,8 @@ function popupShowingEventOccured(event)
|
||||
|
||||
var trigger = document.getElementById(event.target.id == "outerpopup" ? "outer" : "inner");
|
||||
var rect = trigger.getBoundingClientRect();
|
||||
is(event.clientX, Math.floor(rect.left) + 4, testname + "clientX");
|
||||
is(event.clientY, Math.floor(rect.top) + 5, testname + "clientY");
|
||||
is(event.clientX, Math.round(rect.left + 4), testname + "clientX");
|
||||
is(event.clientY, Math.round(rect.top + 5), testname + "clientY");
|
||||
// rangeOffset should be just after the trigger element. As rangeOffset
|
||||
// considers the zeroth position to be before the first element, the value
|
||||
// should be one higher than its index within its parent.
|
||||
|
@ -44,9 +44,9 @@ function checkCoords(event)
|
||||
|
||||
var rect = gButton.getBoundingClientRect();
|
||||
var popupstyle = window.getComputedStyle(gButton, "");
|
||||
is(event.clientX, Math.floor(rect.left) + mod,
|
||||
is(event.clientX, Math.round(rect.left + mod),
|
||||
"step " + (gTestIndex + 1) + " clientX");
|
||||
is(event.clientY, Math.floor(rect.top) + mod,
|
||||
is(event.clientY, Math.round(rect.top + mod),
|
||||
"step " + (gTestIndex + 1) + " clientY");
|
||||
ok(event.screenX > 0, "step " + (gTestIndex + 1) + " screenX");
|
||||
ok(event.screenY > 0, "step " + (gTestIndex + 1) + " screenY");
|
||||
@ -97,11 +97,11 @@ var popupTests = [
|
||||
var rect = document.getElementById("thetooltip").getBoundingClientRect();
|
||||
var popupstyle = window.getComputedStyle(document.getElementById("thetooltip"), "");
|
||||
|
||||
is(Math.floor(rect.left), Math.floor(buttonrect.left) +
|
||||
parseInt(popupstyle.marginLeft) + 6,
|
||||
is(Math.round(rect.left),
|
||||
Math.round(buttonrect.left + parseFloat(popupstyle.marginLeft) + 6),
|
||||
testname + " top position of tooltip");
|
||||
is(Math.floor(rect.top), Math.floor(buttonrect.top) +
|
||||
parseInt(popupstyle.marginTop) + 6,
|
||||
is(Math.round(rect.top),
|
||||
Math.round(buttonrect.top + parseFloat(popupstyle.marginTop) + 6),
|
||||
testname + " top position of tooltip");
|
||||
|
||||
var labelrect = document.getElementById("label").getBoundingClientRect();
|
||||
@ -139,11 +139,11 @@ var popupTests = [
|
||||
var popupstyle = window.getComputedStyle(document.getElementById("thetooltip"), "");
|
||||
var buttonstyle = window.getComputedStyle(document.getElementById("withtooltip"), "");
|
||||
|
||||
is(Math.floor(rect.left), Math.floor(buttonrect.left) +
|
||||
parseInt(popupstyle.marginLeft) + 4,
|
||||
is(Math.round(rect.left),
|
||||
Math.round(buttonrect.left + parseFloat(popupstyle.marginLeft) + 4),
|
||||
testname + " top position of tooltip");
|
||||
is(Math.floor(rect.top), Math.floor(buttonrect.top) +
|
||||
parseInt(popupstyle.marginTop) + 4,
|
||||
is(Math.round(rect.top),
|
||||
Math.round(buttonrect.top + parseFloat(popupstyle.marginTop) + 4),
|
||||
testname + " top position of tooltip");
|
||||
|
||||
var labelrect = document.getElementById("label").getBoundingClientRect();
|
||||
@ -182,11 +182,11 @@ var popupTests = [
|
||||
var popupstyle = window.getComputedStyle(document.getElementById("thetooltip"), "");
|
||||
var buttonstyle = window.getComputedStyle(document.getElementById("withtooltip"), "");
|
||||
|
||||
is(Math.floor(rect.left), Math.floor(buttonrect.left) +
|
||||
parseInt(popupstyle.marginLeft) + 6,
|
||||
is(Math.round(rect.left),
|
||||
Math.round(buttonrect.left + parseFloat(popupstyle.marginLeft) + 6),
|
||||
testname + " top position of tooltip");
|
||||
is(Math.floor(rect.top), Math.floor(buttonrect.top) +
|
||||
parseInt(popupstyle.marginTop) + 6,
|
||||
is(Math.round(rect.top),
|
||||
Math.round(buttonrect.top + parseFloat(popupstyle.marginTop) + 6),
|
||||
testname + " top position of tooltip");
|
||||
|
||||
var labelrect = document.getElementById("label").getBoundingClientRect();
|
||||
|
Loading…
x
Reference in New Issue
Block a user