Bug 471883 - Gesture events should be dispatched to the element under mouse, not to document. r+sr=roc

This commit is contained in:
Olli Pettay 2009-01-03 14:40:26 +02:00
Родитель c083ed85b1
Коммит 89b7cee249
5 изменённых файлов: 43 добавлений и 25 удалений

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

@ -83,6 +83,8 @@ function test_gestureListener(evt)
{
is(evt.type, test_expectedType,
"evt.type (" + evt.type + ") does not match expected value");
is(evt.target, test_utils.elementFromPoint(20, 20, false, false),
"evt.target (" + evt.target + ") does not match expected value");
is(evt.direction, test_expectedDirection,
"evt.direction (" + evt.direction + ") does not match expected value");
is(evt.delta, test_expectedDelta,
@ -111,7 +113,7 @@ function test_helper1(type, direction, delta, modifiers)
let expectedEventCount = test_eventCount + 1;
document.addEventListener(type, test_gestureListener, true);
test_utils.sendSimpleGestureEvent(type, direction, delta, modifiers);
test_utils.sendSimpleGestureEvent(type, 20, 20, direction, delta, modifiers);
document.removeEventListener(type, test_gestureListener, true);
is(expectedEventCount, test_eventCount, "Event (" + type + ") was never received by event listener");
@ -256,7 +258,7 @@ function test_emitLatchedEvents(eventPrefix, initialDelta, cmd)
};
// Send the "Start" event.
test_utils.sendSimpleGestureEvent(eventPrefix + "Start", 0, initialDelta, 0);
test_utils.sendSimpleGestureEvent(eventPrefix + "Start", 0, 0, 0, initialDelta, 0);
cumulativeDelta += initialDelta;
if (isIncreasing) {
expect.inc++;
@ -270,13 +272,13 @@ function test_emitLatchedEvents(eventPrefix, initialDelta, cmd)
// command triggers.
for (let i = 0; i < 5; i++) {
let delta = Math.random() * (isIncreasing ? 100 : -100);
test_utils.sendSimpleGestureEvent(eventPrefix + "Update", 0, delta, 0);
test_utils.sendSimpleGestureEvent(eventPrefix + "Update", 0, 0, 0, delta, 0);
cumulativeDelta += delta;
checkBoth(2, "Increasing command was triggered", "Decreasing command was triggered");
}
// Now go back in the opposite direction.
test_utils.sendSimpleGestureEvent(eventPrefix + "Update", 0,
test_utils.sendSimpleGestureEvent(eventPrefix + "Update", 0, 0, 0,
- initialDelta, 0);
cumulativeDelta += - initialDelta;
if (isIncreasing) {
@ -291,13 +293,13 @@ function test_emitLatchedEvents(eventPrefix, initialDelta, cmd)
// command triggers.
for (let i = 0; i < 5; i++) {
let delta = Math.random() * (isIncreasing ? -100 : 100);
test_utils.sendSimpleGestureEvent(eventPrefix + "Update", 0, delta, 0);
test_utils.sendSimpleGestureEvent(eventPrefix + "Update", 0, 0, 0, delta, 0);
cumulativeDelta += delta;
checkBoth(4, "Increasing command was triggered", "Decreasing command was triggered");
}
// Go back to the original direction. The original command should trigger.
test_utils.sendSimpleGestureEvent(eventPrefix + "Update", 0,
test_utils.sendSimpleGestureEvent(eventPrefix + "Update", 0, 0, 0,
initialDelta, 0);
cumulativeDelta += initialDelta;
if (isIncreasing) {
@ -309,7 +311,7 @@ function test_emitLatchedEvents(eventPrefix, initialDelta, cmd)
}
// Send the wrap-up event. No commands should be triggered.
test_utils.sendSimpleGestureEvent(eventPrefix, 0, cumulativeDelta, 0);
test_utils.sendSimpleGestureEvent(eventPrefix, 0, 0, 0, cumulativeDelta, 0);
checkBoth(6, "Increasing command was triggered", "Decreasing command was triggered");
}
@ -376,32 +378,32 @@ function test_thresholdGesture(gesture, inc, dec, eventPrefix)
// Send the start event but stop short of triggering threshold.
cmdInc.callCount = cmdDec.callCount = 0;
test_utils.sendSimpleGestureEvent(eventPrefix + "Start", 0, 49.5, 0);
test_utils.sendSimpleGestureEvent(eventPrefix + "Start", 0, 0, 0, 49.5, 0);
ok(cmdInc.callCount == 0, "Increasing command was triggered");
ok(cmdDec.callCount == 0, "Decreasing command was triggered");
// Now trigger the threshold.
cmdInc.callCount = cmdDec.callCount = 0;
test_utils.sendSimpleGestureEvent(eventPrefix + "Update", 0, 1, 0);
test_utils.sendSimpleGestureEvent(eventPrefix + "Update", 0, 0, 0, 1, 0);
ok(cmdInc.callCount == 1, "Increasing command was not triggered");
ok(cmdDec.callCount == 0, "Decreasing command was triggered");
// The tracking counter should go to zero. Go back the other way and
// stop short of triggering the threshold.
cmdInc.callCount = cmdDec.callCount = 0;
test_utils.sendSimpleGestureEvent(eventPrefix + "Update", 0, -49.5, 0);
test_utils.sendSimpleGestureEvent(eventPrefix + "Update", 0, 0, 0, -49.5, 0);
ok(cmdInc.callCount == 0, "Increasing command was triggered");
ok(cmdDec.callCount == 0, "Decreasing command was triggered");
// Now cross the threshold and trigger the decreasing command.
cmdInc.callCount = cmdDec.callCount = 0;
test_utils.sendSimpleGestureEvent(eventPrefix + "Update", 0, -1.5, 0);
test_utils.sendSimpleGestureEvent(eventPrefix + "Update", 0, 0, 0, -1.5, 0);
ok(cmdInc.callCount == 0, "Increasing command was triggered");
ok(cmdDec.callCount == 1, "Decreasing command was not triggered");
// Send the wrap-up event. No commands should trigger.
cmdInc.callCount = cmdDec.callCount = 0;
test_utils.sendSimpleGestureEvent(eventPrefix, 0, -0.5, 0);
test_utils.sendSimpleGestureEvent(eventPrefix, 0, 0, 0, -0.5, 0);
ok(cmdInc.callCount == 0, "Increasing command was triggered");
ok(cmdDec.callCount == 0, "Decreasing command was triggered");
@ -437,7 +439,7 @@ function test_swipeGestures()
// UP
resetCounts();
test_utils.sendSimpleGestureEvent("MozSwipeGesture", up, 0, 0);
test_utils.sendSimpleGestureEvent("MozSwipeGesture", 0, 0, up, 0, 0);
ok(cmdUp.callCount == 1, "Step 1: Up command was not triggered");
ok(cmdDown.callCount == 0, "Step 1: Down command was triggered");
ok(cmdLeft.callCount == 0, "Step 1: Left command was triggered");
@ -445,7 +447,7 @@ function test_swipeGestures()
// DOWN
resetCounts();
test_utils.sendSimpleGestureEvent("MozSwipeGesture", down, 0, 0);
test_utils.sendSimpleGestureEvent("MozSwipeGesture", 0, 0, down, 0, 0);
ok(cmdUp.callCount == 0, "Step 2: Up command was triggered");
ok(cmdDown.callCount == 1, "Step 2: Down command was not triggered");
ok(cmdLeft.callCount == 0, "Step 2: Left command was triggered");
@ -453,7 +455,7 @@ function test_swipeGestures()
// LEFT
resetCounts();
test_utils.sendSimpleGestureEvent("MozSwipeGesture", left, 0, 0);
test_utils.sendSimpleGestureEvent("MozSwipeGesture", 0, 0, left, 0, 0);
ok(cmdUp.callCount == 0, "Step 3: Up command was triggered");
ok(cmdDown.callCount == 0, "Step 3: Down command was triggered");
ok(cmdLeft.callCount == 1, "Step 3: Left command was not triggered");
@ -461,7 +463,7 @@ function test_swipeGestures()
// RIGHT
resetCounts();
test_utils.sendSimpleGestureEvent("MozSwipeGesture", right, 0, 0);
test_utils.sendSimpleGestureEvent("MozSwipeGesture", 0, 0, right, 0, 0);
ok(cmdUp.callCount == 0, "Step 4: Up command was triggered");
ok(cmdDown.callCount == 0, "Step 4: Down command was triggered");
ok(cmdLeft.callCount == 0, "Step 4: Left command was triggered");
@ -471,7 +473,7 @@ function test_swipeGestures()
let combos = [ up | left, up | right, down | left, down | right];
for (let i = 0; i < combos.length; i++) {
resetCounts();
test_utils.sendSimpleGestureEvent("MozSwipeGesture", combos[i], 0, 0);
test_utils.sendSimpleGestureEvent("MozSwipeGesture", 0, 0, combos[i], 0, 0);
ok(cmdUp.callCount == 0, "Step 5-"+i+": Up command was triggered");
ok(cmdDown.callCount == 0, "Step 5-"+i+": Down command was triggered");
ok(cmdLeft.callCount == 0, "Step 5-"+i+": Left command was triggered");

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

@ -48,7 +48,7 @@
interface nsIDOMElement;
interface nsIDOMHTMLCanvasElement;
[scriptable, uuid(440D036F-0879-4497-9364-35DE49F6849F)]
[scriptable, uuid(e3833da2-8fad-4662-9b61-908cf58a7e03)]
interface nsIDOMWindowUtils : nsISupports {
/**
@ -255,11 +255,15 @@ interface nsIDOMWindowUtils : nsISupports {
* without UniversalXPConnect privileges.
*
* @param aType event type
* @param aX x offset in CSS pixels
* @param aY y offset in CSS pixels
* @param aDirection direction, using constants defined in nsIDOMSimpleGestureEvent
* @param aDelta amount of magnification or rotation for magnify and rotation events
* @param aModifiers modifiers pressed, using constants defined in nsIDOMNSEvent
*/
void sendSimpleGestureEvent(in AString aType,
in float aX,
in float aY,
in unsigned long aDirection,
in double aDelta,
in long aModifiers);

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

@ -515,6 +515,8 @@ nsDOMWindowUtils::ProcessUpdates()
NS_IMETHODIMP
nsDOMWindowUtils::SendSimpleGestureEvent(const nsAString& aType,
float aX,
float aY,
PRUint32 aDirection,
PRFloat64 aDelta,
PRInt32 aModifiers)
@ -525,7 +527,8 @@ nsDOMWindowUtils::SendSimpleGestureEvent(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;
@ -554,6 +557,14 @@ nsDOMWindowUtils::SendSimpleGestureEvent(const nsAString& aType,
event.isMeta = (aModifiers & nsIDOMNSEvent::META_MASK) ? PR_TRUE : PR_FALSE;
event.time = PR_IntervalNow();
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);
}

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

@ -632,7 +632,8 @@ nsLayoutUtils::GetEventCoordinatesRelativeTo(const nsEvent* aEvent, nsIFrame* aF
{
if (!aEvent || (aEvent->eventStructType != NS_MOUSE_EVENT &&
aEvent->eventStructType != NS_MOUSE_SCROLL_EVENT &&
aEvent->eventStructType != NS_DRAG_EVENT))
aEvent->eventStructType != NS_DRAG_EVENT &&
aEvent->eventStructType != NS_SIMPLE_GESTURE_EVENT))
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
const nsGUIEvent* GUIEvent = static_cast<const nsGUIEvent*>(aEvent);

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

@ -3327,7 +3327,7 @@ static const PRInt32 sShadowInvalidationInterval = 100;
// Setup the "swipe" event.
nsSimpleGestureEvent geckoEvent(PR_TRUE, NS_SIMPLE_GESTURE_SWIPE, mGeckoChild, 0, 0.0);
[self convertGenericCocoaEvent:anEvent toGeckoEvent:&geckoEvent];
[self convertCocoaMouseEvent:anEvent toGeckoEvent:&geckoEvent];
// Record the left/right direction.
if (deltaX > 0.0)
@ -3391,7 +3391,7 @@ static const PRInt32 sShadowInvalidationInterval = 100;
// Setup the event.
nsSimpleGestureEvent geckoEvent(PR_TRUE, msg, mGeckoChild, 0, deltaZ);
[self convertGenericCocoaEvent:anEvent toGeckoEvent:&geckoEvent];
[self convertCocoaMouseEvent:anEvent toGeckoEvent:&geckoEvent];
// Send the event.
mGeckoChild->DispatchWindowEvent(geckoEvent);
@ -3433,7 +3433,7 @@ static const PRInt32 sShadowInvalidationInterval = 100;
// Setup the event.
nsSimpleGestureEvent geckoEvent(PR_TRUE, msg, mGeckoChild, 0, 0.0);
[self convertGenericCocoaEvent:anEvent toGeckoEvent:&geckoEvent];
[self convertCocoaMouseEvent:anEvent toGeckoEvent:&geckoEvent];
geckoEvent.delta = -rotation;
if (rotation > 0.0) {
geckoEvent.direction = nsIDOMSimpleGestureEvent::DIRECTION_LEFT;
@ -3471,7 +3471,7 @@ static const PRInt32 sShadowInvalidationInterval = 100;
// Setup the "magnify" event.
nsSimpleGestureEvent geckoEvent(PR_TRUE, NS_SIMPLE_GESTURE_MAGNIFY,
mGeckoChild, 0, mCumulativeMagnification);
[self convertGenericCocoaEvent:anEvent toGeckoEvent:&geckoEvent];
[self convertCocoaMouseEvent:anEvent toGeckoEvent:&geckoEvent];
// Send the event.
mGeckoChild->DispatchWindowEvent(geckoEvent);
@ -3482,7 +3482,7 @@ static const PRInt32 sShadowInvalidationInterval = 100;
{
// Setup the "rotate" event.
nsSimpleGestureEvent geckoEvent(PR_TRUE, NS_SIMPLE_GESTURE_ROTATE, mGeckoChild, 0, 0.0);
[self convertGenericCocoaEvent:anEvent toGeckoEvent:&geckoEvent];
[self convertCocoaMouseEvent:anEvent toGeckoEvent:&geckoEvent];
geckoEvent.delta = -mCumulativeRotation;
if (mCumulativeRotation > 0.0) {
geckoEvent.direction = nsIDOMSimpleGestureEvent::DIRECTION_LEFT;