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. */
|
|
|
|
|
2014-02-27 14:51:15 +04:00
|
|
|
#include "mozilla/dom/PointerEvent.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;
|
|
|
|
mEvent->time = PR_Now();
|
|
|
|
mEvent->refPoint.x = mEvent->refPoint.y = 0;
|
|
|
|
mouseEvent->inputSource = nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint16_t
|
|
|
|
ConvertStringToPointerType(const nsAString& aPointerTypeArg)
|
|
|
|
{
|
|
|
|
if (aPointerTypeArg.EqualsLiteral("mouse")) {
|
|
|
|
return nsIDOMMouseEvent::MOZ_SOURCE_MOUSE;
|
|
|
|
}
|
|
|
|
if (aPointerTypeArg.EqualsLiteral("pen")) {
|
|
|
|
return nsIDOMMouseEvent::MOZ_SOURCE_PEN;
|
|
|
|
}
|
|
|
|
if (aPointerTypeArg.EqualsLiteral("touch")) {
|
|
|
|
return nsIDOMMouseEvent::MOZ_SOURCE_TOUCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2014-11-11 10:29:00 +03:00
|
|
|
void
|
|
|
|
ConvertPointerTypeToString(uint16_t aPointerTypeSrc, nsAString& aPointerTypeDest)
|
|
|
|
{
|
|
|
|
switch (aPointerTypeSrc) {
|
|
|
|
case nsIDOMMouseEvent::MOZ_SOURCE_MOUSE:
|
|
|
|
aPointerTypeDest.AssignLiteral("mouse");
|
|
|
|
break;
|
|
|
|
case nsIDOMMouseEvent::MOZ_SOURCE_PEN:
|
|
|
|
aPointerTypeDest.AssignLiteral("pen");
|
|
|
|
break;
|
|
|
|
case nsIDOMMouseEvent::MOZ_SOURCE_TOUCH:
|
|
|
|
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
|
|
|
{
|
2014-04-04 21:09:10 +04:00
|
|
|
nsRefPtr<PointerEvent> e = new PointerEvent(aOwner, nullptr, nullptr);
|
|
|
|
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;
|
|
|
|
widgetEvent->width = aParam.mWidth;
|
|
|
|
widgetEvent->height = aParam.mHeight;
|
|
|
|
widgetEvent->pressure = aParam.mPressure;
|
|
|
|
widgetEvent->tiltX = aParam.mTiltX;
|
|
|
|
widgetEvent->tiltY = aParam.mTiltY;
|
|
|
|
widgetEvent->inputSource = ConvertStringToPointerType(aParam.mPointerType);
|
|
|
|
widgetEvent->isPrimary = aParam.mIsPrimary;
|
|
|
|
widgetEvent->buttons = aParam.mButtons;
|
|
|
|
|
|
|
|
e->SetTrusted(trusted);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
return mEvent->AsPointerEvent()->width;
|
|
|
|
}
|
|
|
|
|
2014-02-27 14:51:15 +04:00
|
|
|
int32_t
|
|
|
|
PointerEvent::Height()
|
2013-11-21 09:44:22 +04:00
|
|
|
{
|
|
|
|
return mEvent->AsPointerEvent()->height;
|
|
|
|
}
|
|
|
|
|
2014-02-27 14:51:15 +04:00
|
|
|
float
|
|
|
|
PointerEvent::Pressure()
|
2013-11-21 09:44:22 +04:00
|
|
|
{
|
|
|
|
return mEvent->AsPointerEvent()->pressure;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-02-27 14:51:15 +04:00
|
|
|
bool
|
|
|
|
PointerEvent::IsPrimary()
|
2013-11-21 09:44:22 +04:00
|
|
|
{
|
|
|
|
return mEvent->AsPointerEvent()->isPrimary;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // 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-08-12 14:39:31 +03:00
|
|
|
nsRefPtr<PointerEvent> it = new PointerEvent(aOwner, aPresContext, aEvent);
|
|
|
|
return it.forget();
|
2013-11-21 09:44:22 +04:00
|
|
|
}
|