Files
palemoon27/dom/events/MouseEvent.cpp
T
roytam1 b91a6a24cc import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1001637 - Make math tables implement the nsIAccessibleTable interface. r=surkov (ebbb4325d6)
- Bug 1149118 - Expose radio group with the correct role on OS X, r=surkov (4d4a95735c)
- Bug 1113153 - use 'paragraph' role for paragraphs only, introduce 'text' role for small text containers, r=marcoz (14c4fa5881)
- Bug 1175164 - Do not expose MathML semantics element in the accessibility tree. r=surkov (3945ae0367)
- Bug 930843 part.1 Add test for checking isTrust attribute value of DOMActivate event r=smaug (14a49dd447)
- Bug 930843 part.2 NS_UI_ACTIVATE event should be trusted event even if it's caused by an untrusted event r=smaug (e0af6165b5)
- Bug 1156315 - Call DispatchInputEvent in more places on OS X. r=dvander (e24f42c09f)
- Bug 1186015 part.1 Rename nsIMEContext to mozilla::widget::IMEContext r=jimm (077bf6e772)
- Bug 1186015 part.2 Rename nsIMM32Handler to mozilla::widget::IMMHandler r=jimm+m_kato (a2098e33b5)
- Bug 1184533 Rewrite range check in aOffset of nsIMM32Handler::GetCharacterRectOfSelectedTextAt() r=emk (fb68bc3c56)
- Bug 555642 part.1 nsCaret should have a way to override the caret visible state for hiding caret temporarily and nsEditor should hide caret if composition string doesn't have caret information r=roc (9de4aa366c)
- Bug 1171847 Remove unnecessary ',' in logging code in nsTextStore::Initialize() r=m_kato (78d0d43625)
- Bug 1181714 nsTextStore should store previous focused document manager until new document manager actually gets focus r=m_kato (fd7e820af2)
- Bug 1176950 nsTextStore should keep storing locked content until NOTIFY_IME_OF_COMPOSITION_UPDATE is notified r=emk (0a12349575)
- Bug 1137539 part.1 Implement TSFStaticSink::IsGoogleJapaneseInputActive() r=emk (68d1f9a0ec)
- Bug 1137539 part.2 Implement TSFStaticSink::IsATOKActive() r=emk (51a4208bfa)
- Bug 1137539 part.3 Implement TSFStaticSink::IsFreeChangJieActive() r=emk (affbb81b96)
- Bug 1137539 part.4 Implement TSFStaticSink::IsEasyChangjeiActive() r=emk (abd3e674b6)
- Bug 1186014 Rename nsTextStore to mozilla::widget::TSFTextStore r=jimm+m_kato (ca63351f94)
- Bug 1187351 TSFTextStore should forget modified range at notifying TSF of layout change since GetTextExt() shouldn't return TS_E_NOLAYOUT after that r=emk (48878793e0)
-  Bg 1187367 TSFTextStore shouldn't destroy native caret for ATOK until notifying TSF of layout change r=emk (a2a4022d15)
- Bug 1187566 TSFTextStore::Content should compute mMinTextModified Offset only with the latest composition string and original composition string, and also the hack should be enabled on Win10 r=emk (1368885efe)
- Bug 1050644 part.1 Add methods to check whether the active TIP is Chinese TIP which deosn't show candidate window in e10s mode r=emk (1b783e682e)
- Bug 1050644 part.2 Hack ITextStoreACP::GetTextExt()'s offset for some Chinese TIPs of MS r=emk (c05cec10ce)
- Bug 1187579 Enable TSF in e10s mode r=m_kato (1ae106231a)
- Bug 555642 part.2 IME handlers on Windows shouldn't append caret range if the caret is in the target clause which doesn't have specific style r=m_kato (88bae2c8da)
- Bug 1196124 Fix mismatch of printf style string and following arguments of MOZ_LOG() in IMMHandler::GetCharacterRectOfSelectedTextAt() r=m_kato (0f6debd0d3)
- Bug 90712 Cancel composition when Enter key message isn't consumed by IME r=m_kato (0febdb1fd9)
- pointer style (6c984274cd)
- Bug 1177268 - implement aria-rowcount/index and aria-colcount/index, r=marcoz (92ac300374)
- Bug 1153135 - Return possibility PEN working while APZC is enabled. r=jimm (8bc77ff84f)
- Bug 1171073 - Suppress content scrolling issue on 64-bit platforms. r=kats (62db0dead3)
- Bug 1121946, Implement e10 cursor drag feedback on Windows, r=jmathies (6e8218d202)
- Bug 1144650 - Don't dispatch touch-based mouse events when APZ is handling touch. r=jimm (53ebea0d90)
- Bug 1163056 - InkCollector activation at first PEN event. r=jimm (b28e0ee58b)
- Bug 895274 part.3 Make the enum of event messages a named enum IGNORE IDL r=smaug (32e04a4e90)
- spacing (b9249221dc)
- Bug 1182966 - Part 3: Add some final annotations to DomainSet. r=mrbkap (3455822e89)
- Bug 1050122 - Part 1: Enable Nuwa on debug builds, and kill it if the preference is false. r=khuey (46685a7bf3)
- Bug 1146229: Remove calling convention modifier from local variable. r=surkov (e5f4b6e5d5)
- bug 1168932 - Implement ProxyCreated and ProxyDestroyed to update mozAccessibles r=tbsaunde (77a007fa21)
- Bug 1169701 - Fire native OS X accessibility events for proxied accessibles r=tbsaunde (c4847135a8)
- bug 1172523 - fire useful text change events for proxies r=lsock (85b7f995b8)
- remove spurious file (229c787360)
- bug 1171117 - Fix cairo to build on iOS. r=jrmuizel (45709c8fe3)
- Bug 963738 - Annotate XPCNativeMember, r=terrence (d1afdde52b)
- Bug 1148383 - Add testcase for previously fixed object metadata issue r=terrence (2c1b762cba)
- Bug 1149797 - Update browser jstests to treat ecma_6/extensions tests as 1.8, so that let is interpreted as a statement and not as an expression. r=bustage in a CLOSED TREE (ac6127d6bc)
- Bug 1150858 - Unwrap the correct object in ArrayBuffer.transfer (r=sfink) (cf67906802)
- Bug 1150380 - IonMonkey: MIPS: Fix JitRuntime::generateProfilerExitFrameTailStub. r=rankov (eeac49ddce)
- use RootedValue for POW as in 1135708 (34c1c3d191)
- Bug 1196648: IonMonkey - Don't run the lazy link stub for asmjs to jit fastpath, r=nbp (686d495371)
- Bug 1121947, Implement e10 cursor drag feedback on Mac, r=smaug (f48df2d1)
- and sync widget/TextEvents.h and TextRange.h with AF.
2022-01-19 09:57:42 +08:00

519 lines
13 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#include "mozilla/dom/MouseEvent.h"
#include "mozilla/MouseEvents.h"
#include "nsContentUtils.h"
#include "nsIContent.h"
#include "prtime.h"
namespace mozilla {
namespace dom {
MouseEvent::MouseEvent(EventTarget* aOwner,
nsPresContext* aPresContext,
WidgetMouseEventBase* aEvent)
: UIEvent(aOwner, aPresContext,
aEvent ? aEvent :
new WidgetMouseEvent(false, NS_EVENT_NULL, nullptr,
WidgetMouseEvent::eReal))
{
// There's no way to make this class' ctor allocate an WidgetMouseScrollEvent.
// It's not that important, though, since a scroll event is not a real
// DOM event.
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;
}
if (mouseEvent) {
MOZ_ASSERT(mouseEvent->reason != WidgetMouseEvent::eSynthesized,
"Don't dispatch DOM events from synthesized mouse events");
mDetail = mouseEvent->clickCount;
}
}
NS_IMPL_ADDREF_INHERITED(MouseEvent, UIEvent)
NS_IMPL_RELEASE_INHERITED(MouseEvent, UIEvent)
NS_INTERFACE_MAP_BEGIN(MouseEvent)
NS_INTERFACE_MAP_ENTRY(nsIDOMMouseEvent)
NS_INTERFACE_MAP_END_INHERITING(UIEvent)
NS_IMETHODIMP
MouseEvent::InitMouseEvent(const nsAString& aType,
bool aCanBubble,
bool aCancelable,
nsIDOMWindow* aView,
int32_t aDetail,
int32_t aScreenX,
int32_t aScreenY,
int32_t aClientX,
int32_t aClientY,
bool aCtrlKey,
bool aAltKey,
bool aShiftKey,
bool aMetaKey,
uint16_t aButton,
nsIDOMEventTarget* aRelatedTarget)
{
nsresult rv =
UIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, aDetail);
NS_ENSURE_SUCCESS(rv, rv);
switch(mEvent->mClass) {
case eMouseEventClass:
case eMouseScrollEventClass:
case eWheelEventClass:
case eDragEventClass:
case ePointerEventClass:
case eSimpleGestureEventClass: {
WidgetMouseEventBase* mouseEventBase = mEvent->AsMouseEventBase();
mouseEventBase->relatedTarget = aRelatedTarget;
mouseEventBase->button = aButton;
mouseEventBase->InitBasicModifiers(aCtrlKey, aAltKey, aShiftKey, aMetaKey);
mClientPoint.x = aClientX;
mClientPoint.y = aClientY;
mouseEventBase->refPoint.x = aScreenX;
mouseEventBase->refPoint.y = aScreenY;
WidgetMouseEvent* mouseEvent = mEvent->AsMouseEvent();
if (mouseEvent) {
mouseEvent->clickCount = aDetail;
}
break;
}
default:
break;
}
return NS_OK;
}
nsresult
MouseEvent::InitMouseEvent(const nsAString& aType,
bool aCanBubble,
bool aCancelable,
nsIDOMWindow* aView,
int32_t aDetail,
int32_t aScreenX,
int32_t aScreenY,
int32_t aClientX,
int32_t aClientY,
int16_t aButton,
nsIDOMEventTarget* aRelatedTarget,
const nsAString& aModifiersList)
{
Modifiers modifiers = ComputeModifierState(aModifiersList);
nsresult rv = InitMouseEvent(aType, aCanBubble, aCancelable, aView,
aDetail, aScreenX, aScreenY, aClientX, aClientY,
(modifiers & MODIFIER_CONTROL) != 0,
(modifiers & MODIFIER_ALT) != 0,
(modifiers & MODIFIER_SHIFT) != 0,
(modifiers & MODIFIER_META) != 0,
aButton, aRelatedTarget);
NS_ENSURE_SUCCESS(rv, rv);
switch(mEvent->mClass) {
case eMouseEventClass:
case eMouseScrollEventClass:
case eWheelEventClass:
case eDragEventClass:
case ePointerEventClass:
case eSimpleGestureEventClass:
mEvent->AsInputEvent()->modifiers = modifiers;
return NS_OK;
default:
MOZ_CRASH("There is no space to store the modifiers");
}
}
already_AddRefed<MouseEvent>
MouseEvent::Constructor(const GlobalObject& aGlobal,
const nsAString& aType,
const MouseEventInit& aParam,
ErrorResult& aRv)
{
nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports());
nsRefPtr<MouseEvent> e = new MouseEvent(t, nullptr, nullptr);
bool trusted = e->Init(t);
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,
aParam.mMetaKey, aParam.mButton, aParam.mRelatedTarget,
aRv);
e->SetTrusted(trusted);
switch (e->mEvent->mClass) {
case eMouseEventClass:
case eMouseScrollEventClass:
case eWheelEventClass:
case eDragEventClass:
case ePointerEventClass:
case eSimpleGestureEventClass:
e->mEvent->AsMouseEventBase()->buttons = aParam.mButtons;
break;
default:
break;
}
return e.forget();
}
NS_IMETHODIMP
MouseEvent::InitNSMouseEvent(const nsAString& aType,
bool aCanBubble,
bool aCancelable,
nsIDOMWindow* aView,
int32_t aDetail,
int32_t aScreenX,
int32_t aScreenY,
int32_t aClientX,
int32_t aClientY,
bool aCtrlKey,
bool aAltKey,
bool aShiftKey,
bool aMetaKey,
uint16_t aButton,
nsIDOMEventTarget* aRelatedTarget,
float aPressure,
uint16_t aInputSource)
{
nsresult rv = MouseEvent::InitMouseEvent(aType, aCanBubble, aCancelable,
aView, aDetail, aScreenX, aScreenY,
aClientX, aClientY,
aCtrlKey, aAltKey, aShiftKey,
aMetaKey, aButton, aRelatedTarget);
NS_ENSURE_SUCCESS(rv, rv);
WidgetMouseEventBase* mouseEventBase = mEvent->AsMouseEventBase();
mouseEventBase->pressure = aPressure;
mouseEventBase->inputSource = aInputSource;
return NS_OK;
}
NS_IMETHODIMP
MouseEvent::GetButton(int16_t* aButton)
{
NS_ENSURE_ARG_POINTER(aButton);
*aButton = Button();
return NS_OK;
}
int16_t
MouseEvent::Button()
{
switch(mEvent->mClass) {
case eMouseEventClass:
case eMouseScrollEventClass:
case eWheelEventClass:
case eDragEventClass:
case ePointerEventClass:
case eSimpleGestureEventClass:
return mEvent->AsMouseEventBase()->button;
default:
NS_WARNING("Tried to get mouse button for non-mouse event!");
return WidgetMouseEvent::eLeftButton;
}
}
NS_IMETHODIMP
MouseEvent::GetButtons(uint16_t* aButtons)
{
NS_ENSURE_ARG_POINTER(aButtons);
*aButtons = Buttons();
return NS_OK;
}
uint16_t
MouseEvent::Buttons()
{
switch(mEvent->mClass) {
case eMouseEventClass:
case eMouseScrollEventClass:
case eWheelEventClass:
case eDragEventClass:
case ePointerEventClass:
case eSimpleGestureEventClass:
return mEvent->AsMouseEventBase()->buttons;
default:
MOZ_CRASH("Tried to get mouse buttons for non-mouse event!");
}
}
NS_IMETHODIMP
MouseEvent::GetRelatedTarget(nsIDOMEventTarget** aRelatedTarget)
{
NS_ENSURE_ARG_POINTER(aRelatedTarget);
*aRelatedTarget = GetRelatedTarget().take();
return NS_OK;
}
already_AddRefed<EventTarget>
MouseEvent::GetRelatedTarget()
{
nsCOMPtr<EventTarget> relatedTarget;
switch(mEvent->mClass) {
case eMouseEventClass:
case eMouseScrollEventClass:
case eWheelEventClass:
case eDragEventClass:
case ePointerEventClass:
case eSimpleGestureEventClass:
relatedTarget =
do_QueryInterface(mEvent->AsMouseEventBase()->relatedTarget);
break;
default:
break;
}
if (relatedTarget) {
nsCOMPtr<nsIContent> content = do_QueryInterface(relatedTarget);
nsCOMPtr<nsIContent> currentTarget = do_QueryInterface(mEvent->currentTarget);
nsIContent* shadowRelatedTarget = GetShadowRelatedTarget(currentTarget, content);
if (shadowRelatedTarget) {
relatedTarget = shadowRelatedTarget;
}
if (content && content->ChromeOnlyAccess() &&
!nsContentUtils::CanAccessNativeAnon()) {
relatedTarget = do_QueryInterface(content->FindFirstNonChromeOnlyAccessContent());
}
if (relatedTarget) {
relatedTarget = relatedTarget->GetTargetForDOMEvent();
}
return relatedTarget.forget();
}
return nullptr;
}
void
MouseEvent::GetRegion(nsAString& aRegion)
{
SetDOMStringToNull(aRegion);
WidgetMouseEventBase* mouseEventBase = mEvent->AsMouseEventBase();
if (mouseEventBase) {
aRegion = mouseEventBase->region;
}
}
NS_IMETHODIMP
MouseEvent::GetMozMovementX(int32_t* aMovementX)
{
NS_ENSURE_ARG_POINTER(aMovementX);
*aMovementX = MozMovementX();
return NS_OK;
}
NS_IMETHODIMP
MouseEvent::GetMozMovementY(int32_t* aMovementY)
{
NS_ENSURE_ARG_POINTER(aMovementY);
*aMovementY = MozMovementY();
return NS_OK;
}
NS_IMETHODIMP
MouseEvent::GetScreenX(int32_t* aScreenX)
{
NS_ENSURE_ARG_POINTER(aScreenX);
*aScreenX = ScreenX();
return NS_OK;
}
int32_t
MouseEvent::ScreenX()
{
return Event::GetScreenCoords(mPresContext, mEvent, mEvent->refPoint).x;
}
NS_IMETHODIMP
MouseEvent::GetScreenY(int32_t* aScreenY)
{
NS_ENSURE_ARG_POINTER(aScreenY);
*aScreenY = ScreenY();
return NS_OK;
}
int32_t
MouseEvent::ScreenY()
{
return Event::GetScreenCoords(mPresContext, mEvent, mEvent->refPoint).y;
}
NS_IMETHODIMP
MouseEvent::GetClientX(int32_t* aClientX)
{
NS_ENSURE_ARG_POINTER(aClientX);
*aClientX = ClientX();
return NS_OK;
}
int32_t
MouseEvent::ClientX()
{
return Event::GetClientCoords(mPresContext, mEvent, mEvent->refPoint,
mClientPoint).x;
}
NS_IMETHODIMP
MouseEvent::GetClientY(int32_t* aClientY)
{
NS_ENSURE_ARG_POINTER(aClientY);
*aClientY = ClientY();
return NS_OK;
}
int32_t
MouseEvent::ClientY()
{
return Event::GetClientCoords(mPresContext, mEvent, mEvent->refPoint,
mClientPoint).y;
}
int32_t
MouseEvent::OffsetX()
{
return Event::GetOffsetCoords(mPresContext, mEvent, mEvent->refPoint,
mClientPoint).x;
}
int32_t
MouseEvent::OffsetY()
{
return Event::GetOffsetCoords(mPresContext, mEvent, mEvent->refPoint,
mClientPoint).y;
}
bool
MouseEvent::AltKey()
{
return mEvent->AsInputEvent()->IsAlt();
}
NS_IMETHODIMP
MouseEvent::GetAltKey(bool* aIsDown)
{
NS_ENSURE_ARG_POINTER(aIsDown);
*aIsDown = AltKey();
return NS_OK;
}
bool
MouseEvent::CtrlKey()
{
return mEvent->AsInputEvent()->IsControl();
}
NS_IMETHODIMP
MouseEvent::GetCtrlKey(bool* aIsDown)
{
NS_ENSURE_ARG_POINTER(aIsDown);
*aIsDown = CtrlKey();
return NS_OK;
}
bool
MouseEvent::ShiftKey()
{
return mEvent->AsInputEvent()->IsShift();
}
NS_IMETHODIMP
MouseEvent::GetShiftKey(bool* aIsDown)
{
NS_ENSURE_ARG_POINTER(aIsDown);
*aIsDown = ShiftKey();
return NS_OK;
}
bool
MouseEvent::MetaKey()
{
return mEvent->AsInputEvent()->IsMeta();
}
NS_IMETHODIMP
MouseEvent::GetMetaKey(bool* aIsDown)
{
NS_ENSURE_ARG_POINTER(aIsDown);
*aIsDown = MetaKey();
return NS_OK;
}
NS_IMETHODIMP
MouseEvent::GetModifierState(const nsAString& aKey,
bool* aState)
{
NS_ENSURE_ARG_POINTER(aState);
*aState = GetModifierState(aKey);
return NS_OK;
}
float
MouseEvent::MozPressure() const
{
return mEvent->AsMouseEventBase()->pressure;
}
NS_IMETHODIMP
MouseEvent::GetMozPressure(float* aPressure)
{
NS_ENSURE_ARG_POINTER(aPressure);
*aPressure = MozPressure();
return NS_OK;
}
bool
MouseEvent::HitCluster() const
{
return mEvent->AsMouseEventBase()->hitCluster;
}
uint16_t
MouseEvent::MozInputSource() const
{
return mEvent->AsMouseEventBase()->inputSource;
}
NS_IMETHODIMP
MouseEvent::GetMozInputSource(uint16_t* aInputSource)
{
NS_ENSURE_ARG_POINTER(aInputSource);
*aInputSource = MozInputSource();
return NS_OK;
}
} // namespace dom
} // namespace mozilla
using namespace mozilla;
using namespace mozilla::dom;
already_AddRefed<MouseEvent>
NS_NewDOMMouseEvent(EventTarget* aOwner,
nsPresContext* aPresContext,
WidgetMouseEvent* aEvent)
{
nsRefPtr<MouseEvent> it = new MouseEvent(aOwner, aPresContext, aEvent);
return it.forget();
}