2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-11-21 09:44:22 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* Portions Copyright 2013 Microsoft Open Technologies, Inc. */
|
|
|
|
|
2018-03-20 07:16:06 +03:00
|
|
|
#include "mozilla/dom/MouseEventBinding.h"
|
2014-02-27 14:51:15 +04:00
|
|
|
#include "mozilla/dom/PointerEvent.h"
|
2017-09-20 08:00:57 +03:00
|
|
|
#include "mozilla/dom/PointerEventBinding.h"
|
2013-11-21 09:44:22 +04:00
|
|
|
#include "mozilla/MouseEvents.h"
|
|
|
|
#include "prtime.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
PointerEvent::PointerEvent(EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetPointerEvent* aEvent)
|
2014-02-27 14:51:15 +04:00
|
|
|
: MouseEvent(aOwner, aPresContext,
|
2015-08-26 15:56:59 +03:00
|
|
|
aEvent ? aEvent :
|
2015-08-29 02:58:26 +03:00
|
|
|
new WidgetPointerEvent(false, eVoidEvent, nullptr))
|
2013-11-21 09:44:22 +04:00
|
|
|
{
|
2014-08-04 09:28:52 +04:00
|
|
|
NS_ASSERTION(mEvent->mClass == ePointerEventClass,
|
|
|
|
"event type mismatch ePointerEventClass");
|
2013-11-21 09:44:22 +04:00
|
|
|
|
|
|
|
WidgetMouseEvent* mouseEvent = mEvent->AsMouseEvent();
|
|
|
|
if (aEvent) {
|
|
|
|
mEventIsInternal = false;
|
|
|
|
} else {
|
|
|
|
mEventIsInternal = true;
|
2016-03-28 07:29:42 +03:00
|
|
|
mEvent->mTime = PR_Now();
|
2016-04-18 17:09:02 +03:00
|
|
|
mEvent->mRefPoint = LayoutDeviceIntPoint(0, 0);
|
2018-03-20 07:16:06 +03:00
|
|
|
mouseEvent->inputSource = MouseEventBinding::MOZ_SOURCE_UNKNOWN;
|
2013-11-21 09:44:22 +04:00
|
|
|
}
|
2016-09-02 06:10:48 +03:00
|
|
|
// 5.2 Pointer Event types, for all pointer events, |detail| attribute SHOULD
|
|
|
|
// be 0.
|
|
|
|
mDetail = 0;
|
2013-11-21 09:44:22 +04:00
|
|
|
}
|
|
|
|
|
2017-09-20 08:00:57 +03:00
|
|
|
JSObject*
|
|
|
|
PointerEvent::WrapObjectInternal(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto)
|
|
|
|
{
|
|
|
|
return PointerEventBinding::Wrap(aCx, this, aGivenProto);
|
|
|
|
}
|
|
|
|
|
2013-11-21 09:44:22 +04:00
|
|
|
static uint16_t
|
|
|
|
ConvertStringToPointerType(const nsAString& aPointerTypeArg)
|
|
|
|
{
|
|
|
|
if (aPointerTypeArg.EqualsLiteral("mouse")) {
|
2018-03-20 07:16:06 +03:00
|
|
|
return MouseEventBinding::MOZ_SOURCE_MOUSE;
|
2013-11-21 09:44:22 +04:00
|
|
|
}
|
|
|
|
if (aPointerTypeArg.EqualsLiteral("pen")) {
|
2018-03-20 07:16:06 +03:00
|
|
|
return MouseEventBinding::MOZ_SOURCE_PEN;
|
2013-11-21 09:44:22 +04:00
|
|
|
}
|
|
|
|
if (aPointerTypeArg.EqualsLiteral("touch")) {
|
2018-03-20 07:16:06 +03:00
|
|
|
return MouseEventBinding::MOZ_SOURCE_TOUCH;
|
2013-11-21 09:44:22 +04:00
|
|
|
}
|
|
|
|
|
2018-03-20 07:16:06 +03:00
|
|
|
return MouseEventBinding::MOZ_SOURCE_UNKNOWN;
|
2013-11-21 09:44:22 +04:00
|
|
|
}
|
|
|
|
|
2014-11-11 10:29:00 +03:00
|
|
|
void
|
|
|
|
ConvertPointerTypeToString(uint16_t aPointerTypeSrc, nsAString& aPointerTypeDest)
|
|
|
|
{
|
|
|
|
switch (aPointerTypeSrc) {
|
2018-03-20 07:16:06 +03:00
|
|
|
case MouseEventBinding::MOZ_SOURCE_MOUSE:
|
2014-11-11 10:29:00 +03:00
|
|
|
aPointerTypeDest.AssignLiteral("mouse");
|
|
|
|
break;
|
2018-03-20 07:16:06 +03:00
|
|
|
case MouseEventBinding::MOZ_SOURCE_PEN:
|
2014-11-11 10:29:00 +03:00
|
|
|
aPointerTypeDest.AssignLiteral("pen");
|
|
|
|
break;
|
2018-03-20 07:16:06 +03:00
|
|
|
case MouseEventBinding::MOZ_SOURCE_TOUCH:
|
2014-11-11 10:29:00 +03:00
|
|
|
aPointerTypeDest.AssignLiteral("touch");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
aPointerTypeDest.Truncate();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-04 21:09:10 +04:00
|
|
|
// static
|
2013-11-21 09:44:22 +04:00
|
|
|
already_AddRefed<PointerEvent>
|
2014-04-04 21:09:10 +04:00
|
|
|
PointerEvent::Constructor(EventTarget* aOwner,
|
2013-11-21 09:44:22 +04:00
|
|
|
const nsAString& aType,
|
2014-04-04 21:09:10 +04:00
|
|
|
const PointerEventInit& aParam)
|
2013-11-21 09:44:22 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<PointerEvent> e = new PointerEvent(aOwner, nullptr, nullptr);
|
2014-04-04 21:09:10 +04:00
|
|
|
bool trusted = e->Init(aOwner);
|
2013-11-21 09:44:22 +04:00
|
|
|
|
2014-04-04 21:09:10 +04:00
|
|
|
e->InitMouseEvent(aType, aParam.mBubbles, aParam.mCancelable,
|
|
|
|
aParam.mView, aParam.mDetail, aParam.mScreenX,
|
|
|
|
aParam.mScreenY, aParam.mClientX, aParam.mClientY,
|
2015-04-13 10:16:13 +03:00
|
|
|
false, false, false, false, aParam.mButton,
|
2014-04-04 21:09:10 +04:00
|
|
|
aParam.mRelatedTarget);
|
2015-05-19 23:26:02 +03:00
|
|
|
e->InitializeExtraMouseEventDictionaryMembers(aParam);
|
2013-11-21 09:44:22 +04:00
|
|
|
|
|
|
|
WidgetPointerEvent* widgetEvent = e->mEvent->AsPointerEvent();
|
|
|
|
widgetEvent->pointerId = aParam.mPointerId;
|
2016-08-03 11:18:04 +03:00
|
|
|
widgetEvent->mWidth = aParam.mWidth;
|
2016-08-03 11:23:56 +03:00
|
|
|
widgetEvent->mHeight = aParam.mHeight;
|
2013-11-21 09:44:22 +04:00
|
|
|
widgetEvent->pressure = aParam.mPressure;
|
2017-02-09 05:49:00 +03:00
|
|
|
widgetEvent->tangentialPressure = aParam.mTangentialPressure;
|
2013-11-21 09:44:22 +04:00
|
|
|
widgetEvent->tiltX = aParam.mTiltX;
|
|
|
|
widgetEvent->tiltY = aParam.mTiltY;
|
2017-02-09 05:49:00 +03:00
|
|
|
widgetEvent->twist = aParam.mTwist;
|
2013-11-21 09:44:22 +04:00
|
|
|
widgetEvent->inputSource = ConvertStringToPointerType(aParam.mPointerType);
|
2016-08-03 11:34:53 +03:00
|
|
|
widgetEvent->mIsPrimary = aParam.mIsPrimary;
|
2013-11-21 09:44:22 +04:00
|
|
|
widgetEvent->buttons = aParam.mButtons;
|
|
|
|
|
2017-09-20 08:00:57 +03:00
|
|
|
if (!aParam.mCoalescedEvents.IsEmpty()) {
|
|
|
|
e->mCoalescedEvents.AppendElements(aParam.mCoalescedEvents);
|
|
|
|
}
|
2013-11-21 09:44:22 +04:00
|
|
|
e->SetTrusted(trusted);
|
2016-08-31 06:16:11 +03:00
|
|
|
e->SetComposed(aParam.mComposed);
|
2013-11-21 09:44:22 +04:00
|
|
|
return e.forget();
|
|
|
|
}
|
|
|
|
|
2014-04-04 21:09:10 +04:00
|
|
|
// static
|
|
|
|
already_AddRefed<PointerEvent>
|
|
|
|
PointerEvent::Constructor(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aType,
|
|
|
|
const PointerEventInit& aParam,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
nsCOMPtr<EventTarget> owner = do_QueryInterface(aGlobal.GetAsSupports());
|
|
|
|
return Constructor(owner, aType, aParam);
|
|
|
|
}
|
|
|
|
|
2017-09-20 08:00:57 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(PointerEvent)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(PointerEvent, MouseEvent)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCoalescedEvents)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(PointerEvent, MouseEvent)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCoalescedEvents)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PointerEvent)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(MouseEvent)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(PointerEvent, MouseEvent)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(PointerEvent, MouseEvent)
|
|
|
|
|
2013-11-21 09:44:22 +04:00
|
|
|
void
|
|
|
|
PointerEvent::GetPointerType(nsAString& aPointerType)
|
|
|
|
{
|
2014-11-11 10:29:00 +03:00
|
|
|
ConvertPointerTypeToString(mEvent->AsPointerEvent()->inputSource, aPointerType);
|
2013-11-21 09:44:22 +04:00
|
|
|
}
|
|
|
|
|
2014-02-27 14:51:15 +04:00
|
|
|
int32_t
|
|
|
|
PointerEvent::PointerId()
|
2013-11-21 09:44:22 +04:00
|
|
|
{
|
|
|
|
return mEvent->AsPointerEvent()->pointerId;
|
|
|
|
}
|
|
|
|
|
2014-02-27 14:51:15 +04:00
|
|
|
int32_t
|
|
|
|
PointerEvent::Width()
|
2013-11-21 09:44:22 +04:00
|
|
|
{
|
2016-08-03 11:18:04 +03:00
|
|
|
return mEvent->AsPointerEvent()->mWidth;
|
2013-11-21 09:44:22 +04:00
|
|
|
}
|
|
|
|
|
2014-02-27 14:51:15 +04:00
|
|
|
int32_t
|
|
|
|
PointerEvent::Height()
|
2013-11-21 09:44:22 +04:00
|
|
|
{
|
2016-08-03 11:23:56 +03:00
|
|
|
return mEvent->AsPointerEvent()->mHeight;
|
2013-11-21 09:44:22 +04:00
|
|
|
}
|
|
|
|
|
2014-02-27 14:51:15 +04:00
|
|
|
float
|
|
|
|
PointerEvent::Pressure()
|
2013-11-21 09:44:22 +04:00
|
|
|
{
|
|
|
|
return mEvent->AsPointerEvent()->pressure;
|
|
|
|
}
|
|
|
|
|
2017-02-09 05:49:00 +03:00
|
|
|
float
|
|
|
|
PointerEvent::TangentialPressure()
|
|
|
|
{
|
|
|
|
return mEvent->AsPointerEvent()->tangentialPressure;
|
|
|
|
}
|
|
|
|
|
2014-02-27 14:51:15 +04:00
|
|
|
int32_t
|
|
|
|
PointerEvent::TiltX()
|
2013-11-21 09:44:22 +04:00
|
|
|
{
|
|
|
|
return mEvent->AsPointerEvent()->tiltX;
|
|
|
|
}
|
|
|
|
|
2014-02-27 14:51:15 +04:00
|
|
|
int32_t
|
|
|
|
PointerEvent::TiltY()
|
2013-11-21 09:44:22 +04:00
|
|
|
{
|
|
|
|
return mEvent->AsPointerEvent()->tiltY;
|
|
|
|
}
|
|
|
|
|
2017-02-09 05:49:00 +03:00
|
|
|
int32_t
|
|
|
|
PointerEvent::Twist()
|
|
|
|
{
|
|
|
|
return mEvent->AsPointerEvent()->twist;
|
|
|
|
}
|
|
|
|
|
2014-02-27 14:51:15 +04:00
|
|
|
bool
|
|
|
|
PointerEvent::IsPrimary()
|
2013-11-21 09:44:22 +04:00
|
|
|
{
|
2016-08-03 11:34:53 +03:00
|
|
|
return mEvent->AsPointerEvent()->mIsPrimary;
|
2013-11-21 09:44:22 +04:00
|
|
|
}
|
|
|
|
|
2017-09-20 08:00:57 +03:00
|
|
|
void
|
|
|
|
PointerEvent::GetCoalescedEvents(nsTArray<RefPtr<PointerEvent>>& aPointerEvents)
|
|
|
|
{
|
|
|
|
WidgetPointerEvent* widgetEvent = mEvent->AsPointerEvent();
|
|
|
|
if (mCoalescedEvents.IsEmpty() && widgetEvent &&
|
|
|
|
widgetEvent->mCoalescedWidgetEvents &&
|
|
|
|
!widgetEvent->mCoalescedWidgetEvents->mEvents.IsEmpty()) {
|
|
|
|
for (WidgetPointerEvent& event :
|
|
|
|
widgetEvent->mCoalescedWidgetEvents->mEvents) {
|
|
|
|
RefPtr<PointerEvent> domEvent =
|
|
|
|
NS_NewDOMPointerEvent(nullptr, nullptr, &event);
|
|
|
|
|
2017-11-08 06:42:04 +03:00
|
|
|
// The dom event is derived from an OS generated widget event. Setup
|
|
|
|
// mWidget and mPresContext since they are necessary to calculate
|
|
|
|
// offsetX / offsetY.
|
|
|
|
domEvent->mEvent->AsGUIEvent()->mWidget = widgetEvent->mWidget;
|
|
|
|
domEvent->mPresContext = mPresContext;
|
|
|
|
|
2017-09-20 08:00:57 +03:00
|
|
|
// The coalesced widget mouse events shouldn't have been dispatched.
|
|
|
|
MOZ_ASSERT(!domEvent->mEvent->mTarget);
|
|
|
|
// The event target should be the same as the dispatched event's target.
|
|
|
|
domEvent->mEvent->mTarget = mEvent->mTarget;
|
|
|
|
|
|
|
|
// JS could hold reference to dom events. We have to ask dom event to
|
|
|
|
// duplicate its private data to avoid the widget event is destroyed.
|
|
|
|
domEvent->DuplicatePrivateData();
|
2017-11-08 06:42:04 +03:00
|
|
|
|
|
|
|
// Setup mPresContext again after DuplicatePrivateData since it clears
|
|
|
|
// mPresContext.
|
|
|
|
domEvent->mPresContext = mPresContext;
|
2017-09-20 08:00:57 +03:00
|
|
|
mCoalescedEvents.AppendElement(domEvent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mEvent->mTarget) {
|
|
|
|
for (RefPtr<PointerEvent>& pointerEvent : mCoalescedEvents) {
|
|
|
|
// Only set event target when it's null.
|
|
|
|
if (!pointerEvent->mEvent->mTarget) {
|
|
|
|
pointerEvent->mEvent->mTarget = mEvent->mTarget;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aPointerEvents.AppendElements(mCoalescedEvents);
|
|
|
|
}
|
|
|
|
|
2013-11-21 09:44:22 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
using namespace mozilla;
|
2014-02-27 14:51:15 +04:00
|
|
|
using namespace mozilla::dom;
|
2013-11-21 09:44:22 +04:00
|
|
|
|
2015-08-12 14:39:31 +03:00
|
|
|
already_AddRefed<PointerEvent>
|
|
|
|
NS_NewDOMPointerEvent(EventTarget* aOwner,
|
2014-02-27 14:51:15 +04:00
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetPointerEvent *aEvent)
|
2013-11-21 09:44:22 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<PointerEvent> it = new PointerEvent(aOwner, aPresContext, aEvent);
|
2015-08-12 14:39:31 +03:00
|
|
|
return it.forget();
|
2013-11-21 09:44:22 +04:00
|
|
|
}
|