2015-05-03 19:32:37 +00: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: */
|
2012-05-21 11:12:37 +00: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/. */
|
2004-08-20 18:09:19 +00:00
|
|
|
|
2009-11-17 14:22:23 +00:00
|
|
|
#include "base/basictypes.h"
|
2012-08-28 12:41:04 +00:00
|
|
|
#include "ipc/IPCMessageUtils.h"
|
2014-02-28 14:58:43 +00:00
|
|
|
#include "mozilla/dom/UIEvent.h"
|
|
|
|
#include "mozilla/ArrayUtils.h"
|
|
|
|
#include "mozilla/Assertions.h"
|
|
|
|
#include "mozilla/ContentEvents.h"
|
2014-04-01 04:09:23 +00:00
|
|
|
#include "mozilla/EventStateManager.h"
|
2014-02-28 14:58:43 +00:00
|
|
|
#include "mozilla/TextEvents.h"
|
2004-08-20 18:09:19 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2014-02-28 14:58:43 +00:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsIContent.h"
|
2004-08-20 18:09:19 +00:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2014-01-10 02:03:47 +00:00
|
|
|
#include "nsIDocShell.h"
|
2011-07-15 10:31:34 +00:00
|
|
|
#include "nsIDOMWindow.h"
|
2004-08-20 18:09:19 +00:00
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsIFrame.h"
|
2013-07-03 15:56:26 +00:00
|
|
|
#include "prtime.h"
|
2012-04-25 03:00:01 +00:00
|
|
|
|
2014-02-28 14:58:43 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2004-08-20 18:09:19 +00:00
|
|
|
|
2014-02-28 14:58:43 +00:00
|
|
|
UIEvent::UIEvent(EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* aEvent)
|
2014-03-05 00:37:43 +00:00
|
|
|
: Event(aOwner, aPresContext,
|
2015-08-28 23:58:26 +00:00
|
|
|
aEvent ? aEvent : new InternalUIEvent(false, eVoidEvent, nullptr))
|
2014-02-28 14:58:43 +00:00
|
|
|
, mClientPoint(0, 0)
|
|
|
|
, mLayerPoint(0, 0)
|
|
|
|
, mPagePoint(0, 0)
|
|
|
|
, mMovementPoint(0, 0)
|
2014-04-01 04:09:23 +00:00
|
|
|
, mIsPointerLocked(EventStateManager::sIsPointerLocked)
|
|
|
|
, mLastClientPoint(EventStateManager::sLastClientPoint)
|
2004-08-20 18:09:19 +00:00
|
|
|
{
|
|
|
|
if (aEvent) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mEventIsInternal = false;
|
2004-08-20 18:09:19 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-10-17 14:59:28 +00:00
|
|
|
mEventIsInternal = true;
|
2016-03-28 04:29:42 +00:00
|
|
|
mEvent->mTime = PR_Now();
|
2004-08-20 18:09:19 +00:00
|
|
|
}
|
|
|
|
|
2005-04-28 23:48:28 +00:00
|
|
|
// Fill mDetail and mView according to the mEvent (widget-generated
|
|
|
|
// event) we've got
|
2014-08-04 05:28:46 +00:00
|
|
|
switch(mEvent->mClass) {
|
2014-08-04 05:28:47 +00:00
|
|
|
case eUIEventClass:
|
2004-08-20 18:09:19 +00:00
|
|
|
{
|
2016-03-26 07:22:27 +00:00
|
|
|
mDetail = mEvent->AsUIEvent()->mDetail;
|
2004-08-20 18:09:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-08-04 05:28:53 +00:00
|
|
|
case eScrollPortEventClass:
|
2004-08-20 18:09:19 +00:00
|
|
|
{
|
2013-10-18 06:10:21 +00:00
|
|
|
InternalScrollPortEvent* scrollEvent = mEvent->AsScrollPortEvent();
|
2016-03-30 08:48:23 +00:00
|
|
|
mDetail = static_cast<int32_t>(scrollEvent->mOrient);
|
2004-08-20 18:09:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
mDetail = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
mView = nullptr;
|
2004-08-20 18:09:19 +00:00
|
|
|
if (mPresContext)
|
|
|
|
{
|
2014-01-10 02:03:47 +00:00
|
|
|
nsIDocShell* docShell = mPresContext->GetDocShell();
|
|
|
|
if (docShell)
|
2004-08-20 18:09:19 +00:00
|
|
|
{
|
2014-01-10 02:03:47 +00:00
|
|
|
mView = docShell->GetWindow();
|
2004-08-20 18:09:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-28 14:58:43 +00:00
|
|
|
// static
|
|
|
|
already_AddRefed<UIEvent>
|
|
|
|
UIEvent::Constructor(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aType,
|
|
|
|
const UIEventInit& aParam,
|
|
|
|
ErrorResult& aRv)
|
2013-03-13 20:02:32 +00:00
|
|
|
{
|
2014-02-28 14:58:43 +00:00
|
|
|
nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports());
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<UIEvent> e = new UIEvent(t, nullptr, nullptr);
|
2013-03-13 20:02:32 +00:00
|
|
|
bool trusted = e->Init(t);
|
2016-01-30 17:05:36 +00:00
|
|
|
e->InitUIEvent(aType, aParam.mBubbles, aParam.mCancelable, aParam.mView,
|
|
|
|
aParam.mDetail);
|
2013-03-13 20:02:32 +00:00
|
|
|
e->SetTrusted(trusted);
|
2016-08-31 03:16:11 +00:00
|
|
|
e->SetComposed(aParam.mComposed);
|
2013-03-13 20:02:32 +00:00
|
|
|
return e.forget();
|
|
|
|
}
|
|
|
|
|
2014-04-25 16:49:00 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(UIEvent, Event,
|
|
|
|
mView)
|
2007-06-26 08:21:42 +00:00
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
NS_IMPL_ADDREF_INHERITED(UIEvent, Event)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(UIEvent, Event)
|
2004-08-20 18:09:19 +00:00
|
|
|
|
2014-02-28 14:58:43 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(UIEvent)
|
2004-08-20 18:09:19 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMUIEvent)
|
2014-03-05 00:37:43 +00:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(Event)
|
2004-08-20 18:09:19 +00:00
|
|
|
|
2012-06-20 23:38:11 +00:00
|
|
|
static nsIntPoint
|
2013-08-02 07:05:16 +00:00
|
|
|
DevPixelsToCSSPixels(const LayoutDeviceIntPoint& aPoint,
|
|
|
|
nsPresContext* aContext)
|
2012-06-20 23:38:11 +00:00
|
|
|
{
|
|
|
|
return nsIntPoint(aContext->DevPixelsToIntCSSPixels(aPoint.x),
|
|
|
|
aContext->DevPixelsToIntCSSPixels(aPoint.y));
|
|
|
|
}
|
|
|
|
|
2009-01-15 03:27:09 +00:00
|
|
|
nsIntPoint
|
2014-02-28 14:58:43 +00:00
|
|
|
UIEvent::GetMovementPoint()
|
2009-01-15 03:27:09 +00:00
|
|
|
{
|
2015-05-19 20:26:02 +00:00
|
|
|
if (mPrivateDataDuplicated || mEventIsInternal) {
|
2012-05-09 22:54:18 +00:00
|
|
|
return mMovementPoint;
|
|
|
|
}
|
|
|
|
|
2012-04-11 21:55:21 +00:00
|
|
|
if (!mEvent ||
|
2014-08-04 05:28:50 +00:00
|
|
|
(mEvent->mClass != eMouseEventClass &&
|
2014-08-04 05:28:51 +00:00
|
|
|
mEvent->mClass != eMouseScrollEventClass &&
|
2014-08-04 05:28:51 +00:00
|
|
|
mEvent->mClass != eWheelEventClass &&
|
2014-08-04 05:28:50 +00:00
|
|
|
mEvent->mClass != eDragEventClass &&
|
2014-08-04 05:28:52 +00:00
|
|
|
mEvent->mClass != ePointerEventClass &&
|
2014-08-04 05:28:53 +00:00
|
|
|
mEvent->mClass != eSimpleGestureEventClass) ||
|
2016-04-14 08:03:14 +00:00
|
|
|
!mEvent->AsGUIEvent()->mWidget) {
|
2009-01-15 03:27:09 +00:00
|
|
|
return nsIntPoint(0, 0);
|
2004-08-20 18:09:19 +00:00
|
|
|
}
|
|
|
|
|
2012-06-20 23:38:11 +00:00
|
|
|
// Calculate the delta between the last screen point and the current one.
|
2016-04-18 14:09:02 +00:00
|
|
|
nsIntPoint current = DevPixelsToCSSPixels(mEvent->mRefPoint, mPresContext);
|
2016-04-18 14:28:22 +00:00
|
|
|
nsIntPoint last = DevPixelsToCSSPixels(mEvent->mLastRefPoint, mPresContext);
|
2012-06-20 23:38:11 +00:00
|
|
|
return current - last;
|
2012-04-11 21:55:21 +00:00
|
|
|
}
|
|
|
|
|
2004-08-20 18:09:19 +00:00
|
|
|
NS_IMETHODIMP
|
2016-01-30 17:05:36 +00:00
|
|
|
UIEvent::GetView(mozIDOMWindowProxy** aView)
|
2004-08-20 18:09:19 +00:00
|
|
|
{
|
|
|
|
*aView = mView;
|
|
|
|
NS_IF_ADDREF(*aView);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-28 14:58:43 +00:00
|
|
|
UIEvent::GetDetail(int32_t* aDetail)
|
2004-08-20 18:09:19 +00:00
|
|
|
{
|
|
|
|
*aDetail = mDetail;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
void
|
|
|
|
UIEvent::InitUIEvent(const nsAString& typeArg,
|
|
|
|
bool canBubbleArg,
|
|
|
|
bool cancelableArg,
|
|
|
|
nsGlobalWindow* viewArg,
|
|
|
|
int32_t detailArg)
|
|
|
|
{
|
|
|
|
auto* view = viewArg ? viewArg->AsInner() : nullptr;
|
|
|
|
InitUIEvent(typeArg, canBubbleArg, cancelableArg, view, detailArg);
|
|
|
|
}
|
|
|
|
|
2004-08-20 18:09:19 +00:00
|
|
|
NS_IMETHODIMP
|
2014-02-28 14:58:43 +00:00
|
|
|
UIEvent::InitUIEvent(const nsAString& typeArg,
|
|
|
|
bool canBubbleArg,
|
|
|
|
bool cancelableArg,
|
2016-01-30 17:05:36 +00:00
|
|
|
mozIDOMWindow* viewArg,
|
2014-02-28 14:58:43 +00:00
|
|
|
int32_t detailArg)
|
2004-08-20 18:09:19 +00:00
|
|
|
{
|
2015-11-13 00:09:42 +00:00
|
|
|
Event::InitEvent(typeArg, canBubbleArg, cancelableArg);
|
2016-01-30 17:05:36 +00:00
|
|
|
|
2004-08-20 18:09:19 +00:00
|
|
|
mDetail = detailArg;
|
2016-01-30 17:05:36 +00:00
|
|
|
mView = viewArg ? nsPIDOMWindowInner::From(viewArg)->GetOuterWindow() :
|
|
|
|
nullptr;
|
2004-08-20 18:09:19 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-28 14:58:43 +00:00
|
|
|
UIEvent::GetPageX(int32_t* aPageX)
|
2004-08-20 18:09:19 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aPageX);
|
2013-05-10 07:13:45 +00:00
|
|
|
*aPageX = PageX();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
2014-02-28 14:58:43 +00:00
|
|
|
UIEvent::PageX() const
|
2013-05-10 07:13:45 +00:00
|
|
|
{
|
2011-12-17 00:24:11 +00:00
|
|
|
if (mPrivateDataDuplicated) {
|
2013-05-10 07:13:45 +00:00
|
|
|
return mPagePoint.x;
|
2011-12-17 00:24:11 +00:00
|
|
|
}
|
2013-05-10 07:13:45 +00:00
|
|
|
|
2016-04-18 14:09:02 +00:00
|
|
|
return Event::GetPageCoords(mPresContext, mEvent, mEvent->mRefPoint,
|
2014-03-05 00:37:43 +00:00
|
|
|
mClientPoint).x;
|
2004-08-20 18:09:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-28 14:58:43 +00:00
|
|
|
UIEvent::GetPageY(int32_t* aPageY)
|
2004-08-20 18:09:19 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aPageY);
|
2013-05-10 07:13:45 +00:00
|
|
|
*aPageY = PageY();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
2014-02-28 14:58:43 +00:00
|
|
|
UIEvent::PageY() const
|
2013-05-10 07:13:45 +00:00
|
|
|
{
|
2011-12-17 00:24:11 +00:00
|
|
|
if (mPrivateDataDuplicated) {
|
2013-05-10 07:13:45 +00:00
|
|
|
return mPagePoint.y;
|
2011-12-17 00:24:11 +00:00
|
|
|
}
|
2013-05-10 07:13:45 +00:00
|
|
|
|
2016-04-18 14:09:02 +00:00
|
|
|
return Event::GetPageCoords(mPresContext, mEvent, mEvent->mRefPoint,
|
2014-03-05 00:37:43 +00:00
|
|
|
mClientPoint).y;
|
2004-08-20 18:09:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-28 14:58:43 +00:00
|
|
|
UIEvent::GetWhich(uint32_t* aWhich)
|
2004-08-20 18:09:19 +00:00
|
|
|
{
|
2013-05-05 07:03:16 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aWhich);
|
|
|
|
*aWhich = Which();
|
|
|
|
return NS_OK;
|
2004-08-20 18:09:19 +00:00
|
|
|
}
|
|
|
|
|
2013-03-13 20:02:32 +00:00
|
|
|
already_AddRefed<nsINode>
|
2014-02-28 14:58:43 +00:00
|
|
|
UIEvent::GetRangeParent()
|
2004-08-20 18:09:19 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
nsIFrame* targetFrame = nullptr;
|
2004-08-20 18:09:19 +00:00
|
|
|
|
|
|
|
if (mPresContext) {
|
2011-04-21 17:35:52 +00:00
|
|
|
targetFrame = mPresContext->EventStateManager()->GetEventTarget();
|
2004-08-20 18:09:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (targetFrame) {
|
2005-09-04 20:04:23 +00:00
|
|
|
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(mEvent,
|
2006-02-27 05:57:37 +00:00
|
|
|
targetFrame);
|
|
|
|
nsCOMPtr<nsIContent> parent = targetFrame->GetContentOffsetsFromPoint(pt).content;
|
|
|
|
if (parent) {
|
2012-10-10 19:04:42 +00:00
|
|
|
if (parent->ChromeOnlyAccess() &&
|
2011-01-29 11:32:19 +00:00
|
|
|
!nsContentUtils::CanAccessNativeAnon()) {
|
2013-03-13 20:02:32 +00:00
|
|
|
return nullptr;
|
2011-01-29 11:32:19 +00:00
|
|
|
}
|
2013-04-22 11:15:59 +00:00
|
|
|
return parent.forget();
|
2004-08-20 18:09:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-13 20:02:32 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-28 14:58:43 +00:00
|
|
|
UIEvent::GetRangeParent(nsIDOMNode** aRangeParent)
|
2013-03-13 20:02:32 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aRangeParent);
|
|
|
|
*aRangeParent = nullptr;
|
|
|
|
nsCOMPtr<nsINode> n = GetRangeParent();
|
|
|
|
if (n) {
|
|
|
|
CallQueryInterface(n, aRangeParent);
|
|
|
|
}
|
2004-08-20 18:09:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-28 14:58:43 +00:00
|
|
|
UIEvent::GetRangeOffset(int32_t* aRangeOffset)
|
2004-08-20 18:09:19 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aRangeOffset);
|
2013-05-10 07:13:45 +00:00
|
|
|
*aRangeOffset = RangeOffset();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2004-08-20 18:09:19 +00:00
|
|
|
|
2013-05-10 07:13:45 +00:00
|
|
|
int32_t
|
2014-02-28 14:58:43 +00:00
|
|
|
UIEvent::RangeOffset() const
|
2013-05-10 07:13:45 +00:00
|
|
|
{
|
|
|
|
if (!mPresContext) {
|
|
|
|
return 0;
|
2004-08-20 18:09:19 +00:00
|
|
|
}
|
|
|
|
|
2013-05-10 07:13:45 +00:00
|
|
|
nsIFrame* targetFrame = mPresContext->EventStateManager()->GetEventTarget();
|
|
|
|
if (!targetFrame) {
|
|
|
|
return 0;
|
2004-08-20 18:09:19 +00:00
|
|
|
}
|
2013-05-10 07:13:45 +00:00
|
|
|
|
|
|
|
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(mEvent,
|
|
|
|
targetFrame);
|
|
|
|
return targetFrame->GetContentOffsetsFromPoint(pt).offset;
|
2004-08-20 18:09:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-28 14:58:43 +00:00
|
|
|
UIEvent::GetCancelBubble(bool* aCancelBubble)
|
2004-08-20 18:09:19 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCancelBubble);
|
2013-03-13 20:02:32 +00:00
|
|
|
*aCancelBubble = CancelBubble();
|
2004-08-20 18:09:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-28 14:58:43 +00:00
|
|
|
UIEvent::SetCancelBubble(bool aCancelBubble)
|
2004-08-20 18:09:19 +00:00
|
|
|
{
|
2012-12-16 01:26:03 +00:00
|
|
|
mEvent->mFlags.mPropagationStopped = aCancelBubble;
|
2004-08-20 18:09:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-01-15 03:27:09 +00:00
|
|
|
nsIntPoint
|
2014-02-28 14:58:43 +00:00
|
|
|
UIEvent::GetLayerPoint() const
|
2009-01-15 03:27:09 +00:00
|
|
|
{
|
2007-02-20 14:57:52 +00:00
|
|
|
if (!mEvent ||
|
2014-08-04 05:28:50 +00:00
|
|
|
(mEvent->mClass != eMouseEventClass &&
|
2014-08-04 05:28:51 +00:00
|
|
|
mEvent->mClass != eMouseScrollEventClass &&
|
2014-08-04 05:28:51 +00:00
|
|
|
mEvent->mClass != eWheelEventClass &&
|
2014-08-04 05:28:52 +00:00
|
|
|
mEvent->mClass != ePointerEventClass &&
|
2014-08-04 05:28:53 +00:00
|
|
|
mEvent->mClass != eTouchEventClass &&
|
2014-08-04 05:28:50 +00:00
|
|
|
mEvent->mClass != eDragEventClass &&
|
2014-08-04 05:28:53 +00:00
|
|
|
mEvent->mClass != eSimpleGestureEventClass) ||
|
2007-11-12 12:53:06 +00:00
|
|
|
!mPresContext ||
|
|
|
|
mEventIsInternal) {
|
|
|
|
return mLayerPoint;
|
2004-08-20 18:09:19 +00:00
|
|
|
}
|
2007-02-18 10:43:12 +00:00
|
|
|
// XXX I'm not really sure this is correct; it's my best shot, though
|
2011-04-21 17:35:52 +00:00
|
|
|
nsIFrame* targetFrame = mPresContext->EventStateManager()->GetEventTarget();
|
2007-02-18 10:43:12 +00:00
|
|
|
if (!targetFrame)
|
2007-11-12 12:53:06 +00:00
|
|
|
return mLayerPoint;
|
2007-02-18 10:43:12 +00:00
|
|
|
nsIFrame* layer = nsLayoutUtils::GetClosestLayer(targetFrame);
|
|
|
|
nsPoint pt(nsLayoutUtils::GetEventCoordinatesRelativeTo(mEvent, layer));
|
2009-01-15 03:27:09 +00:00
|
|
|
return nsIntPoint(nsPresContext::AppUnitsToIntCSSPixels(pt.x),
|
|
|
|
nsPresContext::AppUnitsToIntCSSPixels(pt.y));
|
2005-08-23 03:57:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-28 14:58:43 +00:00
|
|
|
UIEvent::GetLayerX(int32_t* aLayerX)
|
2005-08-23 03:57:07 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aLayerX);
|
|
|
|
*aLayerX = GetLayerPoint().x;
|
2004-08-20 18:09:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-28 14:58:43 +00:00
|
|
|
UIEvent::GetLayerY(int32_t* aLayerY)
|
2004-08-20 18:09:19 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aLayerY);
|
2005-08-23 03:57:07 +00:00
|
|
|
*aLayerY = GetLayerPoint().y;
|
2004-08-20 18:09:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-28 14:58:43 +00:00
|
|
|
UIEvent::GetIsChar(bool* aIsChar)
|
2004-08-20 18:09:19 +00:00
|
|
|
{
|
2013-05-10 07:13:45 +00:00
|
|
|
*aIsChar = IsChar();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-02-28 14:58:43 +00:00
|
|
|
UIEvent::IsChar() const
|
2013-05-10 07:13:45 +00:00
|
|
|
{
|
2013-10-18 06:10:24 +00:00
|
|
|
WidgetKeyboardEvent* keyEvent = mEvent->AsKeyboardEvent();
|
2016-05-12 09:31:05 +00:00
|
|
|
return keyEvent ? keyEvent->mIsChar : false;
|
2004-08-20 18:09:19 +00:00
|
|
|
}
|
|
|
|
|
2016-01-12 04:19:08 +00:00
|
|
|
mozilla::dom::Event*
|
|
|
|
UIEvent::AsEvent(void)
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2012-06-10 23:44:50 +00:00
|
|
|
NS_IMETHODIMP
|
2014-02-28 14:58:43 +00:00
|
|
|
UIEvent::DuplicatePrivateData()
|
2007-11-12 12:53:06 +00:00
|
|
|
{
|
2014-03-05 00:37:43 +00:00
|
|
|
mClientPoint =
|
2016-04-18 14:09:02 +00:00
|
|
|
Event::GetClientCoords(mPresContext, mEvent, mEvent->mRefPoint,
|
2014-03-05 00:37:43 +00:00
|
|
|
mClientPoint);
|
2012-05-09 22:54:18 +00:00
|
|
|
mMovementPoint = GetMovementPoint();
|
2011-12-17 00:24:11 +00:00
|
|
|
mLayerPoint = GetLayerPoint();
|
2014-03-05 00:37:43 +00:00
|
|
|
mPagePoint =
|
2016-04-18 14:09:02 +00:00
|
|
|
Event::GetPageCoords(mPresContext, mEvent, mEvent->mRefPoint, mClientPoint);
|
|
|
|
// GetScreenPoint converts mEvent->mRefPoint to right coordinates.
|
2015-11-10 16:32:40 +00:00
|
|
|
CSSIntPoint screenPoint =
|
2016-04-18 14:09:02 +00:00
|
|
|
Event::GetScreenCoords(mPresContext, mEvent, mEvent->mRefPoint);
|
2014-03-05 00:37:43 +00:00
|
|
|
nsresult rv = Event::DuplicatePrivateData();
|
2007-11-12 12:53:06 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2015-11-10 16:32:40 +00:00
|
|
|
CSSToLayoutDeviceScale scale = mPresContext ? mPresContext->CSSToDevPixelScale()
|
|
|
|
: CSSToLayoutDeviceScale(1);
|
2016-04-18 14:09:02 +00:00
|
|
|
mEvent->mRefPoint = RoundedToInt(screenPoint * scale);
|
2007-11-12 12:53:06 +00:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-06-10 23:44:50 +00:00
|
|
|
NS_IMETHODIMP_(void)
|
2014-02-28 14:58:43 +00:00
|
|
|
UIEvent::Serialize(IPC::Message* aMsg, bool aSerializeInterfaceType)
|
2009-11-17 14:22:23 +00:00
|
|
|
{
|
|
|
|
if (aSerializeInterfaceType) {
|
|
|
|
IPC::WriteParam(aMsg, NS_LITERAL_STRING("uievent"));
|
|
|
|
}
|
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
Event::Serialize(aMsg, false);
|
2009-11-17 14:22:23 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t detail = 0;
|
2009-11-17 14:22:23 +00:00
|
|
|
GetDetail(&detail);
|
|
|
|
IPC::WriteParam(aMsg, detail);
|
|
|
|
}
|
|
|
|
|
2012-06-10 23:44:50 +00:00
|
|
|
NS_IMETHODIMP_(bool)
|
2016-04-21 04:09:15 +00:00
|
|
|
UIEvent::Deserialize(const IPC::Message* aMsg, PickleIterator* aIter)
|
2009-11-17 14:22:23 +00:00
|
|
|
{
|
2014-03-05 00:37:43 +00:00
|
|
|
NS_ENSURE_TRUE(Event::Deserialize(aMsg, aIter), false);
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &mDetail), false);
|
|
|
|
return true;
|
2009-11-17 14:22:23 +00:00
|
|
|
}
|
|
|
|
|
2012-04-25 03:00:01 +00:00
|
|
|
// XXX Following struct and array are used only in
|
2014-02-28 14:58:43 +00:00
|
|
|
// UIEvent::ComputeModifierState(), but if we define them in it,
|
2012-04-25 03:00:01 +00:00
|
|
|
// we fail to build on Mac at calling mozilla::ArrayLength().
|
2014-02-28 14:58:43 +00:00
|
|
|
struct ModifierPair
|
2012-04-25 03:00:01 +00:00
|
|
|
{
|
2014-02-28 14:58:43 +00:00
|
|
|
Modifier modifier;
|
2012-04-25 03:00:01 +00:00
|
|
|
const char* name;
|
|
|
|
};
|
2014-02-28 14:58:43 +00:00
|
|
|
static const ModifierPair kPairs[] = {
|
2013-09-14 02:39:41 +00:00
|
|
|
{ MODIFIER_ALT, NS_DOM_KEYNAME_ALT },
|
|
|
|
{ MODIFIER_ALTGRAPH, NS_DOM_KEYNAME_ALTGRAPH },
|
|
|
|
{ MODIFIER_CAPSLOCK, NS_DOM_KEYNAME_CAPSLOCK },
|
|
|
|
{ MODIFIER_CONTROL, NS_DOM_KEYNAME_CONTROL },
|
|
|
|
{ MODIFIER_FN, NS_DOM_KEYNAME_FN },
|
2015-02-19 06:50:19 +00:00
|
|
|
{ MODIFIER_FNLOCK, NS_DOM_KEYNAME_FNLOCK },
|
2013-09-14 02:39:41 +00:00
|
|
|
{ MODIFIER_META, NS_DOM_KEYNAME_META },
|
|
|
|
{ MODIFIER_NUMLOCK, NS_DOM_KEYNAME_NUMLOCK },
|
|
|
|
{ MODIFIER_SCROLLLOCK, NS_DOM_KEYNAME_SCROLLLOCK },
|
|
|
|
{ MODIFIER_SHIFT, NS_DOM_KEYNAME_SHIFT },
|
2015-02-19 06:50:19 +00:00
|
|
|
{ MODIFIER_SYMBOL, NS_DOM_KEYNAME_SYMBOL },
|
2013-09-14 02:39:41 +00:00
|
|
|
{ MODIFIER_SYMBOLLOCK, NS_DOM_KEYNAME_SYMBOLLOCK },
|
|
|
|
{ MODIFIER_OS, NS_DOM_KEYNAME_OS }
|
2012-04-25 03:00:01 +00:00
|
|
|
};
|
|
|
|
|
2014-02-28 14:58:43 +00:00
|
|
|
// static
|
|
|
|
Modifiers
|
|
|
|
UIEvent::ComputeModifierState(const nsAString& aModifiersList)
|
2012-04-25 03:00:01 +00:00
|
|
|
{
|
|
|
|
if (aModifiersList.IsEmpty()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Be careful about the performance. If aModifiersList is too long,
|
|
|
|
// parsing it needs too long time.
|
|
|
|
// XXX Should we abort if aModifiersList is too long?
|
|
|
|
|
|
|
|
Modifiers modifiers = 0;
|
|
|
|
|
|
|
|
nsAString::const_iterator listStart, listEnd;
|
|
|
|
aModifiersList.BeginReading(listStart);
|
|
|
|
aModifiersList.EndReading(listEnd);
|
|
|
|
|
2014-02-28 14:58:43 +00:00
|
|
|
for (uint32_t i = 0; i < ArrayLength(kPairs); i++) {
|
2012-04-25 03:00:01 +00:00
|
|
|
nsAString::const_iterator start(listStart), end(listEnd);
|
|
|
|
if (!FindInReadable(NS_ConvertASCIItoUTF16(kPairs[i].name), start, end)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((start != listStart && !NS_IsAsciiWhitespace(*(--start))) ||
|
|
|
|
(end != listEnd && !NS_IsAsciiWhitespace(*(end)))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
modifiers |= kPairs[i].modifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
return modifiers;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-02-28 14:58:43 +00:00
|
|
|
UIEvent::GetModifierStateInternal(const nsAString& aKey)
|
2012-04-25 03:00:01 +00:00
|
|
|
{
|
2013-10-18 06:10:26 +00:00
|
|
|
WidgetInputEvent* inputEvent = mEvent->AsInputEvent();
|
|
|
|
MOZ_ASSERT(inputEvent, "mEvent must be WidgetInputEvent or derived class");
|
2016-03-31 08:03:00 +00:00
|
|
|
return ((inputEvent->mModifiers & WidgetInputEvent::GetModifier(aKey)) != 0);
|
2012-04-25 03:00:01 +00:00
|
|
|
}
|
|
|
|
|
2015-04-13 07:16:13 +00:00
|
|
|
void
|
|
|
|
UIEvent::InitModifiers(const EventModifierInit& aParam)
|
|
|
|
{
|
|
|
|
if (NS_WARN_IF(!mEvent)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
WidgetInputEvent* inputEvent = mEvent->AsInputEvent();
|
|
|
|
MOZ_ASSERT(inputEvent,
|
|
|
|
"This method shouldn't be called if it doesn't have modifiers");
|
|
|
|
if (NS_WARN_IF(!inputEvent)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-31 08:03:00 +00:00
|
|
|
inputEvent->mModifiers = MODIFIER_NONE;
|
2015-04-13 07:16:13 +00:00
|
|
|
|
|
|
|
#define SET_MODIFIER(aName, aValue) \
|
|
|
|
if (aParam.m##aName) { \
|
2016-03-31 08:03:00 +00:00
|
|
|
inputEvent->mModifiers |= aValue; \
|
2015-04-13 07:16:13 +00:00
|
|
|
} \
|
|
|
|
|
|
|
|
SET_MODIFIER(CtrlKey, MODIFIER_CONTROL)
|
|
|
|
SET_MODIFIER(ShiftKey, MODIFIER_SHIFT)
|
|
|
|
SET_MODIFIER(AltKey, MODIFIER_ALT)
|
|
|
|
SET_MODIFIER(MetaKey, MODIFIER_META)
|
|
|
|
SET_MODIFIER(ModifierAltGraph, MODIFIER_ALTGRAPH)
|
|
|
|
SET_MODIFIER(ModifierCapsLock, MODIFIER_CAPSLOCK)
|
|
|
|
SET_MODIFIER(ModifierFn, MODIFIER_FN)
|
|
|
|
SET_MODIFIER(ModifierFnLock, MODIFIER_FNLOCK)
|
|
|
|
SET_MODIFIER(ModifierNumLock, MODIFIER_NUMLOCK)
|
|
|
|
SET_MODIFIER(ModifierOS, MODIFIER_OS)
|
|
|
|
SET_MODIFIER(ModifierScrollLock, MODIFIER_SCROLLLOCK)
|
|
|
|
SET_MODIFIER(ModifierSymbol, MODIFIER_SYMBOL)
|
|
|
|
SET_MODIFIER(ModifierSymbolLock, MODIFIER_SYMBOLLOCK)
|
|
|
|
|
|
|
|
#undef SET_MODIFIER
|
|
|
|
}
|
|
|
|
|
2014-02-28 14:58:43 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
2012-04-25 03:00:01 +00:00
|
|
|
|
2015-08-12 11:39:31 +00:00
|
|
|
already_AddRefed<UIEvent>
|
|
|
|
NS_NewDOMUIEvent(EventTarget* aOwner,
|
2014-02-28 14:58:43 +00:00
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* aEvent)
|
2004-08-20 18:09:19 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<UIEvent> it = new UIEvent(aOwner, aPresContext, aEvent);
|
2015-08-12 11:39:31 +00:00
|
|
|
return it.forget();
|
2004-08-20 18:09:19 +00:00
|
|
|
}
|