Skip to content

Commit c02ba0f

Browse files
author
Oleg Romashin
committed
Bug 822898 - Implement pointer events. Interface. r=smaug
1 parent 5d9d885 commit c02ba0f

16 files changed

+439
-1
lines changed

content/base/src/nsGkAtomList.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,18 @@ GK_ATOM(onMozEdgeUIStarted, "onMozEdgeUIStarted")
17581758
GK_ATOM(onMozEdgeUICanceled, "onMozEdgeUICanceled")
17591759
GK_ATOM(onMozEdgeUICompleted, "onMozEdgeUICompleted")
17601760

1761+
// Pointer events
1762+
GK_ATOM(onpointerdown, "onpointerdown")
1763+
GK_ATOM(onpointermove, "onpointermove")
1764+
GK_ATOM(onpointerup, "onpointerup")
1765+
GK_ATOM(onpointercancel, "onpointercancel")
1766+
GK_ATOM(onpointerover, "onpointerover")
1767+
GK_ATOM(onpointerout, "onpointerout")
1768+
GK_ATOM(onpointerenter, "onpointerenter")
1769+
GK_ATOM(onpointerleave, "onpointerleave")
1770+
GK_ATOM(ongotpointercapture, "ongotpointercapture")
1771+
GK_ATOM(onlostpointercapture, "onlostpointercapture")
1772+
17611773
// orientation support
17621774
GK_ATOM(ondevicemotion, "ondevicemotion")
17631775
GK_ATOM(ondeviceorientation, "ondeviceorientation")

content/events/public/nsEventNameList.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,48 @@ EVENT(mozpointerlockerror,
293293
NS_POINTERLOCKERROR,
294294
EventNameType_HTML,
295295
NS_EVENT)
296+
297+
EVENT(pointerdown,
298+
NS_POINTER_DOWN,
299+
EventNameType_All,
300+
NS_POINTER_EVENT)
301+
EVENT(pointermove,
302+
NS_POINTER_MOVE,
303+
EventNameType_All,
304+
NS_POINTER_EVENT)
305+
EVENT(pointerup,
306+
NS_POINTER_UP,
307+
EventNameType_All,
308+
NS_POINTER_EVENT)
309+
EVENT(pointercancel,
310+
NS_POINTER_CANCEL,
311+
EventNameType_All,
312+
NS_POINTER_EVENT)
313+
EVENT(pointerover,
314+
NS_POINTER_OVER,
315+
EventNameType_All,
316+
NS_POINTER_EVENT)
317+
EVENT(pointerout,
318+
NS_POINTER_OUT,
319+
EventNameType_All,
320+
NS_POINTER_EVENT)
321+
EVENT(pointerenter,
322+
NS_POINTER_ENTER,
323+
EventNameType_All,
324+
NS_POINTER_EVENT)
325+
EVENT(pointerleave,
326+
NS_POINTER_LEAVE,
327+
EventNameType_All,
328+
NS_POINTER_EVENT)
329+
EVENT(gotpointercapture,
330+
NS_POINTER_GOT_CAPTURE,
331+
EventNameType_All,
332+
NS_POINTER_EVENT)
333+
EVENT(lostpointercapture,
334+
NS_POINTER_LOST_CAPTURE,
335+
EventNameType_All,
336+
NS_POINTER_EVENT)
337+
296338
// Not supported yet; probably never because "wheel" is a better idea.
297339
// EVENT(mousewheel)
298340
EVENT(pause,

content/events/src/PointerEvent.cpp

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2+
/* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
5+
*
6+
* Portions Copyright 2013 Microsoft Open Technologies, Inc. */
7+
8+
#include "PointerEvent.h"
9+
#include "mozilla/MouseEvents.h"
10+
#include "prtime.h"
11+
12+
namespace mozilla {
13+
namespace dom {
14+
15+
PointerEvent::PointerEvent(EventTarget* aOwner,
16+
nsPresContext* aPresContext,
17+
WidgetPointerEvent* aEvent)
18+
: nsDOMMouseEvent(aOwner, aPresContext, aEvent ? aEvent : new WidgetPointerEvent(false, 0, nullptr))
19+
{
20+
NS_ASSERTION(mEvent->eventStructType == NS_POINTER_EVENT, "event type mismatch NS_POINTER_EVENT");
21+
22+
WidgetMouseEvent* mouseEvent = mEvent->AsMouseEvent();
23+
if (aEvent) {
24+
mEventIsInternal = false;
25+
} else {
26+
mEventIsInternal = true;
27+
mEvent->time = PR_Now();
28+
mEvent->refPoint.x = mEvent->refPoint.y = 0;
29+
mouseEvent->inputSource = nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN;
30+
}
31+
}
32+
33+
static uint16_t
34+
ConvertStringToPointerType(const nsAString& aPointerTypeArg)
35+
{
36+
if (aPointerTypeArg.EqualsLiteral("mouse")) {
37+
return nsIDOMMouseEvent::MOZ_SOURCE_MOUSE;
38+
}
39+
if (aPointerTypeArg.EqualsLiteral("pen")) {
40+
return nsIDOMMouseEvent::MOZ_SOURCE_PEN;
41+
}
42+
if (aPointerTypeArg.EqualsLiteral("touch")) {
43+
return nsIDOMMouseEvent::MOZ_SOURCE_TOUCH;
44+
}
45+
46+
return nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN;
47+
}
48+
49+
//static
50+
already_AddRefed<PointerEvent>
51+
PointerEvent::Constructor(const mozilla::dom::GlobalObject& aGlobal,
52+
const nsAString& aType,
53+
const mozilla::dom::PointerEventInit& aParam,
54+
mozilla::ErrorResult& aRv)
55+
{
56+
nsCOMPtr<mozilla::dom::EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports());
57+
nsRefPtr<PointerEvent> e = new PointerEvent(t, nullptr, nullptr);
58+
bool trusted = e->Init(t);
59+
60+
aRv = e->InitMouseEvent(aType, aParam.mBubbles, aParam.mCancelable,
61+
aParam.mView, aParam.mDetail, aParam.mScreenX,
62+
aParam.mScreenY, aParam.mClientX, aParam.mClientY,
63+
aParam.mCtrlKey, aParam.mAltKey, aParam.mShiftKey,
64+
aParam.mMetaKey, aParam.mButton, aParam.mRelatedTarget);
65+
if (aRv.Failed()) {
66+
return nullptr;
67+
}
68+
69+
WidgetPointerEvent* widgetEvent = e->mEvent->AsPointerEvent();
70+
widgetEvent->pointerId = aParam.mPointerId;
71+
widgetEvent->width = aParam.mWidth;
72+
widgetEvent->height = aParam.mHeight;
73+
widgetEvent->pressure = aParam.mPressure;
74+
widgetEvent->tiltX = aParam.mTiltX;
75+
widgetEvent->tiltY = aParam.mTiltY;
76+
widgetEvent->inputSource = ConvertStringToPointerType(aParam.mPointerType);
77+
widgetEvent->isPrimary = aParam.mIsPrimary;
78+
widgetEvent->buttons = aParam.mButtons;
79+
80+
e->SetTrusted(trusted);
81+
return e.forget();
82+
}
83+
84+
void
85+
PointerEvent::GetPointerType(nsAString& aPointerType)
86+
{
87+
switch (mEvent->AsPointerEvent()->inputSource) {
88+
case nsIDOMMouseEvent::MOZ_SOURCE_MOUSE:
89+
aPointerType.AssignLiteral("mouse");
90+
break;
91+
case nsIDOMMouseEvent::MOZ_SOURCE_PEN:
92+
aPointerType.AssignLiteral("pen");
93+
break;
94+
case nsIDOMMouseEvent::MOZ_SOURCE_TOUCH:
95+
aPointerType.AssignLiteral("touch");
96+
break;
97+
case nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN:
98+
aPointerType.AssignLiteral("");
99+
break;
100+
}
101+
}
102+
103+
int32_t PointerEvent::PointerId()
104+
{
105+
return mEvent->AsPointerEvent()->pointerId;
106+
}
107+
108+
int32_t PointerEvent::Width()
109+
{
110+
return mEvent->AsPointerEvent()->width;
111+
}
112+
113+
int32_t PointerEvent::Height()
114+
{
115+
return mEvent->AsPointerEvent()->height;
116+
}
117+
118+
int32_t PointerEvent::Pressure()
119+
{
120+
return mEvent->AsPointerEvent()->pressure;
121+
}
122+
123+
int32_t PointerEvent::TiltX()
124+
{
125+
return mEvent->AsPointerEvent()->tiltX;
126+
}
127+
128+
int32_t PointerEvent::TiltY()
129+
{
130+
return mEvent->AsPointerEvent()->tiltY;
131+
}
132+
133+
bool PointerEvent::IsPrimary()
134+
{
135+
return mEvent->AsPointerEvent()->isPrimary;
136+
}
137+
138+
} // namespace dom
139+
} // namespace mozilla
140+
141+
using namespace mozilla;
142+
143+
nsresult NS_NewDOMPointerEvent(nsIDOMEvent** aInstancePtrResult,
144+
dom::EventTarget* aOwner,
145+
nsPresContext* aPresContext,
146+
WidgetPointerEvent *aEvent)
147+
{
148+
dom::PointerEvent *it = new dom::PointerEvent(aOwner, aPresContext, aEvent);
149+
return CallQueryInterface(it, aInstancePtrResult);
150+
}

content/events/src/PointerEvent.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
*
5+
* Portions Copyright 2013 Microsoft Open Technologies, Inc. */
6+
7+
#ifndef PointerEvent_h__
8+
#define PointerEvent_h__
9+
10+
#include "nsDOMMouseEvent.h"
11+
#include "mozilla/dom/PointerEventBinding.h"
12+
13+
class nsPresContext;
14+
15+
namespace mozilla {
16+
namespace dom {
17+
18+
class PointerEvent : public nsDOMMouseEvent
19+
{
20+
public:
21+
PointerEvent(EventTarget* aOwner,
22+
nsPresContext* aPresContext,
23+
WidgetPointerEvent* aEvent);
24+
25+
virtual JSObject* WrapObject(JSContext* aCx,
26+
JS::Handle<JSObject*> aScope) MOZ_OVERRIDE
27+
{
28+
return mozilla::dom::PointerEventBinding::Wrap(aCx, aScope, this);
29+
}
30+
31+
static already_AddRefed<PointerEvent>
32+
Constructor(const GlobalObject& aGlobal,
33+
const nsAString& aType,
34+
const PointerEventInit& aParam,
35+
mozilla::ErrorResult& aRv);
36+
37+
int32_t PointerId();
38+
int32_t Width();
39+
int32_t Height();
40+
int32_t Pressure();
41+
int32_t TiltX();
42+
int32_t TiltY();
43+
bool IsPrimary();
44+
void GetPointerType(nsAString& aPointerType);
45+
};
46+
47+
} // namespace dom
48+
} // namespace mozilla
49+
50+
#endif

content/events/src/moz.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ EXPORTS += [
1414
]
1515

1616
EXPORTS.mozilla.dom += [
17+
'PointerEvent.h',
1718
'Touch.h',
1819
]
1920

@@ -57,6 +58,7 @@ UNIFIED_SOURCES += [
5758
'nsIMEStateManager.cpp',
5859
'nsPaintRequest.cpp',
5960
'nsPrivateTextRange.cpp',
61+
'PointerEvent.cpp',
6062
'TextComposition.cpp',
6163
'Touch.cpp',
6264
]

content/events/src/nsEventDispatcher.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,9 @@ nsEventDispatcher::CreateEvent(mozilla::dom::EventTarget* aOwner,
739739
case NS_SIMPLE_GESTURE_EVENT:
740740
return NS_NewDOMSimpleGestureEvent(aDOMEvent, aOwner, aPresContext,
741741
aEvent->AsSimpleGestureEvent());
742+
case NS_POINTER_EVENT:
743+
return NS_NewDOMPointerEvent(aDOMEvent, aOwner, aPresContext,
744+
aEvent->AsPointerEvent());
742745
case NS_TOUCH_EVENT:
743746
return NS_NewDOMTouchEvent(aDOMEvent, aOwner, aPresContext,
744747
aEvent->AsTouchEvent());

dom/interfaces/core/nsIInlineEventHandlers.idl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "jspubtd.h"
88
%}
99

10-
[scriptable, uuid(22df6ed6-d094-4e45-97fc-a8eca11c390c)]
10+
[scriptable, uuid(6c1fcf3d-119b-4cf4-9437-b9357508976a)]
1111
interface nsIInlineEventHandlers : nsISupports
1212
{
1313
[implicit_jscontext] attribute jsval onabort;
@@ -71,6 +71,17 @@ interface nsIInlineEventHandlers : nsISupports
7171
[implicit_jscontext] attribute jsval onwaiting;
7272
[implicit_jscontext] attribute jsval onwheel;
7373

74+
[implicit_jscontext] attribute jsval onpointerdown;
75+
[implicit_jscontext] attribute jsval onpointermove;
76+
[implicit_jscontext] attribute jsval onpointerout;
77+
[implicit_jscontext] attribute jsval onpointerover;
78+
[implicit_jscontext] attribute jsval onpointerup;
79+
[implicit_jscontext] attribute jsval onpointerenter;
80+
[implicit_jscontext] attribute jsval onpointerleave;
81+
[implicit_jscontext] attribute jsval ongotpointercapture;
82+
[implicit_jscontext] attribute jsval onlostpointercapture;
83+
[implicit_jscontext] attribute jsval onpointercancel;
84+
7485
/**
7586
* Non-HTML5 event attributes
7687
*/

dom/interfaces/events/nsIDOMEvent.idl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,11 @@ NS_NewDOMAnimationEvent(nsIDOMEvent** aInstancePtrResult,
372372
nsPresContext* aPresContext,
373373
mozilla::InternalAnimationEvent* aEvent);
374374
nsresult
375+
NS_NewDOMPointerEvent(nsIDOMEvent** aInstancePtrResult,
376+
mozilla::dom::EventTarget* aOwner,
377+
nsPresContext* aPresContext,
378+
mozilla::WidgetPointerEvent* aEvent);
379+
nsresult
375380
NS_NewDOMTouchEvent(nsIDOMEvent** aInstancePtrResult,
376381
mozilla::dom::EventTarget* aOwner,
377382
nsPresContext* aPresContext,

dom/webidl/EventHandler.webidl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,22 @@ interface GlobalEventHandlers {
8888
attribute EventHandler onvolumechange;
8989
attribute EventHandler onwaiting;
9090

91+
// Pointer events handlers
92+
[Pref="dom.w3c_pointer_events.enabled"]
93+
attribute EventHandler onpointerdown;
94+
[Pref="dom.w3c_pointer_events.enabled"]
95+
attribute EventHandler onpointerup;
96+
[Pref="dom.w3c_pointer_events.enabled"]
97+
attribute EventHandler onpointermove;
98+
[Pref="dom.w3c_pointer_events.enabled"]
99+
attribute EventHandler onpointerout;
100+
[Pref="dom.w3c_pointer_events.enabled"]
101+
attribute EventHandler onpointerover;
102+
[Pref="dom.w3c_pointer_events.enabled"]
103+
attribute EventHandler onpointerenter;
104+
[Pref="dom.w3c_pointer_events.enabled"]
105+
attribute EventHandler onpointerleave;
106+
91107
// Mozilla-specific handlers
92108
attribute EventHandler onmozfullscreenchange;
93109
attribute EventHandler onmozfullscreenerror;

dom/webidl/PointerEvent.webidl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2+
/* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
5+
*
6+
* For more information see nsIPointerEvent.idl.
7+
*
8+
* Portions Copyright 2013 Microsoft Open Technologies, Inc. */
9+
10+
interface WindowProxy;
11+
12+
[Pref="dom.w3c_pointer_events.enabled",
13+
Constructor(DOMString type, optional PointerEventInit eventInitDict)]
14+
interface PointerEvent : MouseEvent
15+
{
16+
readonly attribute long pointerId;
17+
readonly attribute long width;
18+
readonly attribute long height;
19+
readonly attribute float pressure;
20+
readonly attribute long tiltX;
21+
readonly attribute long tiltY;
22+
readonly attribute DOMString pointerType;
23+
readonly attribute boolean isPrimary;
24+
};
25+
26+
dictionary PointerEventInit : MouseEventInit
27+
{
28+
long pointerId = 0;
29+
long width = 0;
30+
long height = 0;
31+
float pressure = 0;
32+
long tiltX = 0;
33+
long tiltY = 0;
34+
DOMString pointerType = "";
35+
boolean isPrimary = false;
36+
};
37+

0 commit comments

Comments
 (0)