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