2013-11-20 21:44:22 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* 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 02:51:15 -08:00
|
|
|
#include "mozilla/dom/PointerEvent.h"
|
2013-11-20 21:44:22 -08:00
|
|
|
#include "mozilla/MouseEvents.h"
|
|
|
|
#include "prtime.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
PointerEvent::PointerEvent(EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetPointerEvent* aEvent)
|
2014-02-27 02:51:15 -08:00
|
|
|
: MouseEvent(aOwner, aPresContext,
|
|
|
|
aEvent ? aEvent : new WidgetPointerEvent(false, 0, nullptr))
|
2013-11-20 21:44:22 -08:00
|
|
|
{
|
2014-02-27 02:51:15 -08:00
|
|
|
NS_ASSERTION(mEvent->eventStructType == NS_POINTER_EVENT,
|
|
|
|
"event type mismatch NS_POINTER_EVENT");
|
2013-11-20 21:44:22 -08: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
//static
|
|
|
|
already_AddRefed<PointerEvent>
|
2014-02-27 02:51:15 -08:00
|
|
|
PointerEvent::Constructor(const GlobalObject& aGlobal,
|
2013-11-20 21:44:22 -08:00
|
|
|
const nsAString& aType,
|
2014-02-27 02:51:15 -08:00
|
|
|
const PointerEventInit& aParam,
|
|
|
|
ErrorResult& aRv)
|
2013-11-20 21:44:22 -08:00
|
|
|
{
|
2014-02-27 02:51:15 -08:00
|
|
|
nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports());
|
2013-11-20 21:44:22 -08:00
|
|
|
nsRefPtr<PointerEvent> e = new PointerEvent(t, nullptr, nullptr);
|
|
|
|
bool trusted = e->Init(t);
|
|
|
|
|
|
|
|
aRv = e->InitMouseEvent(aType, aParam.mBubbles, aParam.mCancelable,
|
|
|
|
aParam.mView, aParam.mDetail, aParam.mScreenX,
|
|
|
|
aParam.mScreenY, aParam.mClientX, aParam.mClientY,
|
|
|
|
aParam.mCtrlKey, aParam.mAltKey, aParam.mShiftKey,
|
2014-02-27 02:51:15 -08:00
|
|
|
aParam.mMetaKey, aParam.mButton,
|
|
|
|
aParam.mRelatedTarget);
|
2013-11-20 21:44:22 -08:00
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PointerEvent::GetPointerType(nsAString& aPointerType)
|
|
|
|
{
|
|
|
|
switch (mEvent->AsPointerEvent()->inputSource) {
|
|
|
|
case nsIDOMMouseEvent::MOZ_SOURCE_MOUSE:
|
|
|
|
aPointerType.AssignLiteral("mouse");
|
|
|
|
break;
|
|
|
|
case nsIDOMMouseEvent::MOZ_SOURCE_PEN:
|
|
|
|
aPointerType.AssignLiteral("pen");
|
|
|
|
break;
|
|
|
|
case nsIDOMMouseEvent::MOZ_SOURCE_TOUCH:
|
|
|
|
aPointerType.AssignLiteral("touch");
|
|
|
|
break;
|
|
|
|
case nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN:
|
|
|
|
aPointerType.AssignLiteral("");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-27 02:51:15 -08:00
|
|
|
int32_t
|
|
|
|
PointerEvent::PointerId()
|
2013-11-20 21:44:22 -08:00
|
|
|
{
|
|
|
|
return mEvent->AsPointerEvent()->pointerId;
|
|
|
|
}
|
|
|
|
|
2014-02-27 02:51:15 -08:00
|
|
|
int32_t
|
|
|
|
PointerEvent::Width()
|
2013-11-20 21:44:22 -08:00
|
|
|
{
|
|
|
|
return mEvent->AsPointerEvent()->width;
|
|
|
|
}
|
|
|
|
|
2014-02-27 02:51:15 -08:00
|
|
|
int32_t
|
|
|
|
PointerEvent::Height()
|
2013-11-20 21:44:22 -08:00
|
|
|
{
|
|
|
|
return mEvent->AsPointerEvent()->height;
|
|
|
|
}
|
|
|
|
|
2014-02-27 02:51:15 -08:00
|
|
|
float
|
|
|
|
PointerEvent::Pressure()
|
2013-11-20 21:44:22 -08:00
|
|
|
{
|
|
|
|
return mEvent->AsPointerEvent()->pressure;
|
|
|
|
}
|
|
|
|
|
2014-02-27 02:51:15 -08:00
|
|
|
int32_t
|
|
|
|
PointerEvent::TiltX()
|
2013-11-20 21:44:22 -08:00
|
|
|
{
|
|
|
|
return mEvent->AsPointerEvent()->tiltX;
|
|
|
|
}
|
|
|
|
|
2014-02-27 02:51:15 -08:00
|
|
|
int32_t
|
|
|
|
PointerEvent::TiltY()
|
2013-11-20 21:44:22 -08:00
|
|
|
{
|
|
|
|
return mEvent->AsPointerEvent()->tiltY;
|
|
|
|
}
|
|
|
|
|
2014-02-27 02:51:15 -08:00
|
|
|
bool
|
|
|
|
PointerEvent::IsPrimary()
|
2013-11-20 21:44:22 -08:00
|
|
|
{
|
|
|
|
return mEvent->AsPointerEvent()->isPrimary;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
using namespace mozilla;
|
2014-02-27 02:51:15 -08:00
|
|
|
using namespace mozilla::dom;
|
2013-11-20 21:44:22 -08:00
|
|
|
|
2014-02-27 02:51:15 -08:00
|
|
|
nsresult
|
|
|
|
NS_NewDOMPointerEvent(nsIDOMEvent** aInstancePtrResult,
|
|
|
|
EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetPointerEvent *aEvent)
|
2013-11-20 21:44:22 -08:00
|
|
|
{
|
2014-02-27 02:51:15 -08:00
|
|
|
PointerEvent *it = new PointerEvent(aOwner, aPresContext, aEvent);
|
2014-03-17 13:00:11 -07:00
|
|
|
NS_ADDREF(it);
|
|
|
|
*aInstancePtrResult = static_cast<Event*>(it);
|
|
|
|
return NS_OK;
|
2013-11-20 21:44:22 -08:00
|
|
|
}
|