Bug 1164981 - Add MouseEvent.movementX/Y, r=masayuki,ehsan

--HG--
extra : rebase_source : 2119f9849223ec49075737ca8fb4356d8f0765b5
This commit is contained in:
Olli Pettay 2015-05-19 19:57:24 +03:00
Родитель 1d31da42fd
Коммит 46d974943b
11 изменённых файлов: 50 добавлений и 49 удалений

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

@ -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();
}

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

@ -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,
@ -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();
}
@ -305,7 +311,7 @@ NS_IMETHODIMP
MouseEvent::GetMozMovementX(int32_t* aMovementX)
{
NS_ENSURE_ARG_POINTER(aMovementX);
*aMovementX = MozMovementX();
*aMovementX = MovementX();
return NS_OK;
}
@ -314,7 +320,7 @@ NS_IMETHODIMP
MouseEvent::GetMozMovementY(int32_t* aMovementY)
{
NS_ENSURE_ARG_POINTER(aMovementY);
*aMovementY = MozMovementY();
*aMovementY = MovementY();
return NS_OK;
}

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

@ -69,6 +69,9 @@ public:
aShiftKey, aMetaKey, aButton,
aRelatedTarget);
}
void InitializeExtraMouseEventDictionaryMembers(const MouseEventInit& aParam);
bool GetModifierState(const nsAString& aKeyArg)
{
return GetModifierStateInternal(aKeyArg);
@ -77,11 +80,11 @@ public:
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;
}

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

@ -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;

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

@ -114,7 +114,7 @@ DevPixelsToCSSPixels(const LayoutDeviceIntPoint& aPoint,
nsIntPoint
UIEvent::GetMovementPoint()
{
if (mPrivateDataDuplicated) {
if (mPrivateDataDuplicated || mEventIsInternal) {
return mMovementPoint;
}

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

@ -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();
}

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

@ -107,6 +107,10 @@ function testInitializingUntrustedEvent()
}
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,

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

@ -696,11 +696,14 @@ try {
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!");
@ -724,7 +727,7 @@ var mouseEventProps =
{ modifierSymbolLock: false },
{ button: 0 },
{ buttons: 0 },
{ relatedTarget: null }
{ relatedTarget: null },
];
var testProps =
@ -811,8 +814,11 @@ try {
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!");
@ -907,8 +913,11 @@ try {
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!");

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

@ -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;
@ -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,
@ -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:
@ -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

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

@ -1,8 +0,0 @@
[constructor.html]
type: testharness
[Default event values for mouse event interface and its pointer lock extensions.]
expected: FAIL
[Default event values for pointerlockerror using a dictionary]
expected: FAIL

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

@ -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