Skip to content

Commit

Permalink
Bug 1164981 - Add MouseEvent.movementX/Y. r=masayuki, r=ehsan
Browse files Browse the repository at this point in the history
CLOSED TREE
  • Loading branch information
Olli Pettay authored and Olli Pettay committed May 19, 2015
1 parent e1ee0d7 commit d6a44b8
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 49 deletions.
1 change: 1 addition & 0 deletions dom/events/DragEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ DragEvent::Constructor(const GlobalObject& aGlobal,
aParam.mCtrlKey, aParam.mAltKey, aParam.mShiftKey,
aParam.mMetaKey, aParam.mButton, aParam.mRelatedTarget,
aParam.mDataTransfer);
e->InitializeExtraMouseEventDictionaryMembers(aParam);
e->SetTrusted(trusted);
return e.forget();
}
Expand Down
18 changes: 12 additions & 6 deletions dom/events/MouseEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ MouseEvent::InitMouseEvent(const nsAString& aType,
}
}

void
MouseEvent::InitializeExtraMouseEventDictionaryMembers(const MouseEventInit& aParam)
{
InitModifiers(aParam);
mEvent->AsMouseEventBase()->buttons = aParam.mButtons;
mMovementPoint.x = aParam.mMovementX;
mMovementPoint.y = aParam.mMovementY;
}

already_AddRefed<MouseEvent>
MouseEvent::Constructor(const GlobalObject& aGlobal,
const nsAString& aType,
Expand All @@ -153,11 +162,8 @@ MouseEvent::Constructor(const GlobalObject& aGlobal,
aParam.mCtrlKey, aParam.mAltKey, aParam.mShiftKey,
aParam.mMetaKey, aParam.mButton, aParam.mRelatedTarget,
aRv);
e->InitModifiers(aParam);
e->InitializeExtraMouseEventDictionaryMembers(aParam);
e->SetTrusted(trusted);
MOZ_RELEASE_ASSERT(e->mEvent->AsMouseEventBase(),
"mEvent of MouseEvent must inherit WidgetMouseEventBase");
e->mEvent->AsMouseEventBase()->buttons = aParam.mButtons;

return e.forget();
}
Expand Down Expand Up @@ -305,7 +311,7 @@ NS_IMETHODIMP
MouseEvent::GetMozMovementX(int32_t* aMovementX)
{
NS_ENSURE_ARG_POINTER(aMovementX);
*aMovementX = MozMovementX();
*aMovementX = MovementX();

return NS_OK;
}
Expand All @@ -314,7 +320,7 @@ NS_IMETHODIMP
MouseEvent::GetMozMovementY(int32_t* aMovementY)
{
NS_ENSURE_ARG_POINTER(aMovementY);
*aMovementY = MozMovementY();
*aMovementY = MovementY();

return NS_OK;
}
Expand Down
7 changes: 5 additions & 2 deletions dom/events/MouseEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class MouseEvent : public UIEvent,
aShiftKey, aMetaKey, aButton,
aRelatedTarget);
}

void InitializeExtraMouseEventDictionaryMembers(const MouseEventInit& aParam);

bool GetModifierState(const nsAString& aKeyArg)
{
return GetModifierStateInternal(aKeyArg);
Expand All @@ -77,11 +80,11 @@ class MouseEvent : public UIEvent,
const nsAString& aType,
const MouseEventInit& aParam,
ErrorResult& aRv);
int32_t MozMovementX()
int32_t MovementX()
{
return GetMovementPoint().x;
}
int32_t MozMovementY()
int32_t MovementY()
{
return GetMovementPoint().y;
}
Expand Down
2 changes: 1 addition & 1 deletion dom/events/PointerEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ PointerEvent::Constructor(EventTarget* aOwner,
aParam.mScreenY, aParam.mClientX, aParam.mClientY,
false, false, false, false, aParam.mButton,
aParam.mRelatedTarget);
e->InitModifiers(aParam);
e->InitializeExtraMouseEventDictionaryMembers(aParam);

WidgetPointerEvent* widgetEvent = e->mEvent->AsPointerEvent();
widgetEvent->pointerId = aParam.mPointerId;
Expand Down
2 changes: 1 addition & 1 deletion dom/events/UIEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ DevPixelsToCSSPixels(const LayoutDeviceIntPoint& aPoint,
nsIntPoint
UIEvent::GetMovementPoint()
{
if (mPrivateDataDuplicated) {
if (mPrivateDataDuplicated || mEventIsInternal) {
return mMovementPoint;
}

Expand Down
3 changes: 1 addition & 2 deletions dom/events/WheelEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ WheelEvent::Constructor(const GlobalObject& aGlobal,
aParam.mButton, aParam.mRelatedTarget,
EmptyString(), aParam.mDeltaX,
aParam.mDeltaY, aParam.mDeltaZ, aParam.mDeltaMode);
e->InitModifiers(aParam);
e->mEvent->AsWheelEvent()->buttons = aParam.mButtons;
e->InitializeExtraMouseEventDictionaryMembers(aParam);
e->SetTrusted(trusted);
return e.forget();
}
Expand Down
4 changes: 4 additions & 0 deletions dom/events/test/test_dom_mouse_event.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@
}
is(e.isTrusted, false, description + "isTrusted returns wrong value");
is(e.buttons, 0, description + "buttons returns wrong value");
is(e.movementX, 0, description + "movementX returns wrong value");
is(e.movementY, 0, description + "movementY returns wrong value");
is(e.movementX, e.mozMovementX);
is(e.movementY, e.mozMovementY);

// getModifierState() tests
is(e.getModifierState("Shift"), kTest.shiftKey,
Expand Down
17 changes: 13 additions & 4 deletions dom/events/test/test_eventctors.html
Original file line number Diff line number Diff line change
Expand Up @@ -696,11 +696,14 @@
ok(ex, "MouseEvent: First parameter is required!");
ex = false;

e = new MouseEvent("hello");
e = new MouseEvent("hello", { buttons: 1, movementX: 2, movementY: 3});
is(e.type, "hello", "MouseEvent: Wrong event type!");
ok(!e.isTrusted, "MouseEvent: Event shouldn't be trusted!");
ok(!e.bubbles, "MouseEvent: Event shouldn't bubble!");
ok(!e.cancelable, "MouseEvent: Event shouldn't be cancelable!");
is(e.buttons, 1);
is(e.movementX, 2);
is(e.movementY, 3);
document.dispatchEvent(e);
is(receivedEvent, e, "MouseEvent: Wrong event!");

Expand All @@ -724,7 +727,7 @@
{ modifierSymbolLock: false },
{ button: 0 },
{ buttons: 0 },
{ relatedTarget: null }
{ relatedTarget: null },
];

var testProps =
Expand Down Expand Up @@ -811,8 +814,11 @@
ok(ex, "WheelEvent: First parameter is required!");
ex = false;

e = new WheelEvent("hello");
e = new WheelEvent("hello", { buttons: 1, movementX: 2, movementY: 3});
is(e.type, "hello", "WheelEvent: Wrong event type!");
is(e.buttons, 1);
is(e.movementX, 2);
is(e.movementY, 3);
ok(!e.isTrusted, "WheelEvent: Event shouldn't be trusted!");
ok(!e.bubbles, "WheelEvent: Event shouldn't bubble!");
ok(!e.cancelable, "WheelEvent: Event shouldn't be cancelable!");
Expand Down Expand Up @@ -907,8 +913,11 @@
ok(ex, "DragEvent: First parameter is required!");
ex = false;

e = new DragEvent("hello");
e = new DragEvent("hello", { buttons: 1, movementX: 2, movementY: 3});
is(e.type, "hello", "DragEvent: Wrong event type!");
is(e.buttons, 1);
is(e.movementX, 2);
is(e.movementY, 3);
document.dispatchEvent(e);
is(receivedEvent, e, "DragEvent: Wrong event!");

Expand Down
19 changes: 12 additions & 7 deletions dom/webidl/MouseEvent.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* liability, trademark and document use rules apply.
*/

[Constructor(DOMString typeArg, optional MouseEventInit mouseEventInitDict)]
interface MouseEvent : UIEvent {
readonly attribute long screenX;
readonly attribute long screenY;
Expand All @@ -25,6 +26,11 @@ interface MouseEvent : UIEvent {
readonly attribute unsigned short buttons;
readonly attribute EventTarget? relatedTarget;
readonly attribute DOMString? region;

// Pointer Lock
readonly attribute long movementX;
readonly attribute long movementY;

// Deprecated in DOM Level 3:
[Throws]
void initMouseEvent(DOMString typeArg,
Expand All @@ -46,13 +52,6 @@ interface MouseEvent : UIEvent {
boolean getModifierState(DOMString keyArg);
};


// Event Constructor Syntax:
[Constructor(DOMString typeArg, optional MouseEventInit mouseEventInitDict)]
partial interface MouseEvent
{
};

// Suggested initMouseEvent replacement initializer:
dictionary MouseEventInit : EventModifierInit {
// Attributes for MouseEvent:
Expand All @@ -64,12 +63,18 @@ dictionary MouseEventInit : EventModifierInit {
// Note: "buttons" was not previously initializable through initMouseEvent!
unsigned short buttons = 0;
EventTarget? relatedTarget = null;

// Pointer Lock
long movementX = 0;
long movementY = 0;
};

// Mozilla extensions
partial interface MouseEvent
{
[BinaryName="movementX"]
readonly attribute long mozMovementX;
[BinaryName="movementY"]
readonly attribute long mozMovementY;

// Finger or touch pressure event value
Expand Down
8 changes: 0 additions & 8 deletions testing/web-platform/meta/pointerlock/constructor.html.ini

This file was deleted.

18 changes: 0 additions & 18 deletions testing/web-platform/meta/pointerlock/idlharness.html.ini
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,3 @@
[Document interface: window.document must inherit property "exitPointerLock" with the proper type (3)]
expected: FAIL

[MouseEvent interface: attribute movementX]
expected: FAIL

[MouseEvent interface: attribute movementY]
expected: FAIL

[MouseEvent interface: new MouseEvent('mousemove') must inherit property "movementX" with the proper type (0)]
expected: FAIL

[MouseEvent interface: new MouseEvent('mousemove') must inherit property "movementY" with the proper type (1)]
expected: FAIL

[MouseEvent interface: new MouseEvent('pointerlockchange') must inherit property "movementX" with the proper type (0)]
expected: FAIL

[MouseEvent interface: new MouseEvent('pointerlockchange') must inherit property "movementY" with the proper type (1)]
expected: FAIL

0 comments on commit d6a44b8

Please sign in to comment.