2013-09-24 10:04:14 +00: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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_BasicEvents_h__
|
|
|
|
#define mozilla_BasicEvents_h__
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2020-03-28 13:57:14 +00:00
|
|
|
#include <type_traits>
|
2013-09-24 10:04:14 +00:00
|
|
|
|
2020-01-14 02:41:15 +00:00
|
|
|
#include "mozilla/EventForwards.h"
|
|
|
|
#include "mozilla/TimeStamp.h"
|
2020-01-14 07:15:45 +00:00
|
|
|
#include "mozilla/dom/EventTarget.h"
|
|
|
|
#include "mozilla/layers/LayersTypes.h"
|
2013-09-24 10:04:14 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2017-10-02 22:05:19 +00:00
|
|
|
#include "nsAtom.h"
|
2014-02-26 21:36:35 +00:00
|
|
|
#include "nsISupportsImpl.h"
|
2013-09-24 10:04:14 +00:00
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "Units.h"
|
|
|
|
|
2017-07-05 04:58:41 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
# include "nsXULAppAPI.h"
|
|
|
|
#endif // #ifdef DEBUG
|
|
|
|
|
2020-11-23 16:21:38 +00:00
|
|
|
class nsIPrincipal;
|
|
|
|
|
2014-07-23 19:55:51 +00:00
|
|
|
namespace IPC {
|
|
|
|
template <typename T>
|
|
|
|
struct ParamTraits;
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace IPC
|
2014-07-23 19:55:51 +00:00
|
|
|
|
2013-09-24 10:04:14 +00:00
|
|
|
namespace mozilla {
|
|
|
|
|
2017-12-18 16:07:36 +00:00
|
|
|
class EventTargetChainItem;
|
|
|
|
|
Bug 1435717 - Make calling WidgetEvent::PreventDefault*() stop cross process forwarding too r=smaug
Currently, if an event is consumed in the main process, EventStateManager
does not send it to remote process. However, this is unexpected behavior
for some WidgetKeyboardEvent dispatchers. OS sometimes has consumed native
key events before sending applications. For example, Alt key on Windows
should activate menu bar of focused window but Alt key may be consumed before
focused window receives the event. In such case, we mark Alt keyboard event
as "consumed before dispatch", and chrome treat it like as its preventDefault()
is called in web content. (Note that for compatibility with other browsers,
the consumed state is not exposed to web content. So, Event.defaultPrevented
returns false in web content.)
Therefore, we need to treat "consumed" state and "cross process forwarding"
state separately. This patch makes calling WidgetEvent::PreventDefault()
always stops cross process forwarding for backward compatibility. Additionally,
for the special case mentioned above, this patch makes
WidgetEvent::PreventDefaultBeforeDispatch() take additional argument,
|aIfStopCrossProcessForwarding|. If this is CrossProcessForwarding::eStop,
the event won't be sent to remote process as same as calling PreventDefault().
Otherwise, CrossProcessForwarding::eHold, PreventDefaultBeforeDispatch() call
does not change "cross process forwarding" state. I.e., if the event's
StopCrossProcessForwarding() and PreventDefault() are not called until
EventStateManager::PostHandleEvent(), the event will be sent to remote process
as usual.
MozReview-Commit-ID: IQGWJvXetxV
--HG--
extra : rebase_source : 4ccdd500e80b8fe29e469ac3b85578e1c07c8358
2018-06-25 09:17:18 +00:00
|
|
|
enum class CrossProcessForwarding {
|
|
|
|
// eStop prevents the event to be sent to remote process.
|
|
|
|
eStop,
|
|
|
|
// eAllow keeps current state of the event whether it's sent to remote
|
|
|
|
// process. In other words, eAllow does NOT mean that making the event
|
|
|
|
// sent to remote process when IsCrossProcessForwardingStopped() returns
|
|
|
|
// true.
|
|
|
|
eAllow,
|
|
|
|
};
|
|
|
|
|
2013-09-24 10:04:14 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::BaseEventFlags
|
|
|
|
*
|
|
|
|
* BaseEventFlags must be a POD struct for safe to use memcpy (including
|
|
|
|
* in ParamTraits<BaseEventFlags>). So don't make virtual methods, constructor,
|
|
|
|
* destructor and operators.
|
|
|
|
* This is necessary for VC which is NOT C++0x compiler.
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
struct BaseEventFlags {
|
|
|
|
public:
|
|
|
|
// If mIsTrusted is true, the event is a trusted event. Otherwise, it's
|
|
|
|
// an untrusted event.
|
|
|
|
bool mIsTrusted : 1;
|
|
|
|
// If mInBubblingPhase is true, the event is in bubbling phase or target
|
|
|
|
// phase.
|
|
|
|
bool mInBubblingPhase : 1;
|
|
|
|
// If mInCapturePhase is true, the event is in capture phase or target phase.
|
|
|
|
bool mInCapturePhase : 1;
|
2023-06-06 09:08:14 +00:00
|
|
|
// If mInTargetPhase is true, the event is in target phase.
|
|
|
|
bool mInTargetPhase : 1;
|
2013-09-24 10:04:14 +00:00
|
|
|
// If mInSystemGroup is true, the event is being dispatched in system group.
|
|
|
|
bool mInSystemGroup : 1;
|
|
|
|
// If mCancelable is true, the event can be consumed. I.e., calling
|
2014-03-05 00:37:43 +00:00
|
|
|
// dom::Event::PreventDefault() can prevent the default action.
|
2013-09-24 10:04:14 +00:00
|
|
|
bool mCancelable : 1;
|
|
|
|
// If mBubbles is true, the event can bubble. Otherwise, cannot be handled
|
|
|
|
// in bubbling phase.
|
|
|
|
bool mBubbles : 1;
|
2014-03-05 00:37:43 +00:00
|
|
|
// If mPropagationStopped is true, dom::Event::StopPropagation() or
|
|
|
|
// dom::Event::StopImmediatePropagation() has been called.
|
2013-09-24 10:04:14 +00:00
|
|
|
bool mPropagationStopped : 1;
|
|
|
|
// If mImmediatePropagationStopped is true,
|
2014-03-05 00:37:43 +00:00
|
|
|
// dom::Event::StopImmediatePropagation() has been called.
|
2013-09-24 10:04:14 +00:00
|
|
|
// Note that mPropagationStopped must be true when this is true.
|
|
|
|
bool mImmediatePropagationStopped : 1;
|
|
|
|
// If mDefaultPrevented is true, the event has been consumed.
|
2014-03-05 00:37:43 +00:00
|
|
|
// E.g., dom::Event::PreventDefault() has been called or
|
2013-09-24 10:04:14 +00:00
|
|
|
// the default action has been performed.
|
|
|
|
bool mDefaultPrevented : 1;
|
|
|
|
// If mDefaultPreventedByContent is true, the event has been
|
|
|
|
// consumed by content.
|
|
|
|
// Note that mDefaultPrevented must be true when this is true.
|
|
|
|
bool mDefaultPreventedByContent : 1;
|
2015-01-21 01:16:04 +00:00
|
|
|
// If mDefaultPreventedByChrome is true, the event has been
|
|
|
|
// consumed by chrome.
|
|
|
|
// Note that mDefaultPrevented must be true when this is true.
|
|
|
|
bool mDefaultPreventedByChrome : 1;
|
2013-09-24 10:04:14 +00:00
|
|
|
// mMultipleActionsPrevented may be used when default handling don't want to
|
|
|
|
// be prevented, but only one of the event targets should handle the event.
|
|
|
|
// For example, when a <label> element is in another <label> element and
|
|
|
|
// the first <label> element is clicked, that one may set this true.
|
|
|
|
// Then, the second <label> element won't handle the event.
|
|
|
|
bool mMultipleActionsPrevented : 1;
|
|
|
|
// If mIsBeingDispatched is true, the DOM event created from the event is
|
|
|
|
// dispatching into the DOM tree and not completed.
|
|
|
|
bool mIsBeingDispatched : 1;
|
|
|
|
// If mDispatchedAtLeastOnce is true, the event has been dispatched
|
Bug 1581192 - `WidgetEvent::mFlags::mDispatchedAtLeastOnce` needs to be reset before dispatching in content process again r=smaug
The crash occurs when dispatching a user input event which is a default action
of a raw user input event like `click` event caused by `mouseup` event if
the raw event's `isTrusted` is set to `false` accidentally during dispatch.
User input events are fired in the main process first. Then,
`EventStateManager` sends it to remote process from `PostHandleEvent()` if
necessary. However, at this time, `WidgetEvent::mFlags::mDispatchedAtLeastOnce`
is never rest, but its only referrer, `EventDispatcher::DispatchDOMEvent()`
assumes that when it's `true`, `WidgetEvent::mFlags:mIsBeingDispatched` is
`false`. Therefore, only in content process, `mouseup` event's `isTrusted` is
set to `false` by `EventTarget.dispatchEvent()` even while it's being dispatch.
And also the trusted state will be used for creating next event which is part
of the default action.
https://searchfox.org/mozilla-central/rev/6566d92dd46417a2f57e75c515135ebe84c9cef5/dom/events/EventDispatcher.cpp#1121,1126,1130-1131,1135,1138,1143
Therefore, this patch makes `WidgetEvent::mFlags` reset `mDispatchedAtLeastOnce`
when it's copied across process boundary and make
`EventDispatcher::DispatchDOMEvent()` won't modify being dispatched events for
avoiding any odd issues.
Unfortunately, this patch adds "expected: FAIL" to the new WPT test only on
Windows. The failure reason is still unclear. I cannot reproduce the failure
on my Windows environment, but on Try Server, it fails permanently since
the driver succeeds to send the mouse click, but the button never receives
`mouseup` nor `click` event.
Differential Revision: https://phabricator.services.mozilla.com/D52988
--HG--
extra : moz-landing-system : lando
2019-11-26 09:08:38 +00:00
|
|
|
// as a DOM event and the dispatch has been completed in the process.
|
|
|
|
// So, this is false even if the event has already been dispatched
|
|
|
|
// in another process.
|
2013-09-24 10:04:14 +00:00
|
|
|
bool mDispatchedAtLeastOnce : 1;
|
|
|
|
// If mIsSynthesizedForTests is true, the event has been synthesized for
|
|
|
|
// automated tests or something hacky approach of an add-on.
|
|
|
|
bool mIsSynthesizedForTests : 1;
|
2016-05-09 05:16:42 +00:00
|
|
|
// If mExceptionWasRaised is true, one of the event handlers has raised an
|
2013-09-24 10:04:14 +00:00
|
|
|
// exception.
|
2016-05-09 05:16:42 +00:00
|
|
|
bool mExceptionWasRaised : 1;
|
2013-09-24 10:04:14 +00:00
|
|
|
// If mRetargetToNonNativeAnonymous is true and the target is in a non-native
|
2016-04-18 16:33:23 +00:00
|
|
|
// native anonymous subtree, the event target is set to mOriginalTarget.
|
2013-09-24 10:04:14 +00:00
|
|
|
bool mRetargetToNonNativeAnonymous : 1;
|
|
|
|
// If mNoContentDispatch is true, the event is never dispatched to the
|
|
|
|
// event handlers which are added to the contents, onfoo attributes and
|
|
|
|
// properties. Note that this flag is ignored when
|
2014-03-18 04:48:19 +00:00
|
|
|
// EventChainPreVisitor::mForceContentDispatch is set true. For exapmle,
|
2013-09-24 10:04:14 +00:00
|
|
|
// window and document object sets it true. Therefore, web applications
|
|
|
|
// can handle the event if they add event listeners to the window or the
|
|
|
|
// document.
|
2016-03-16 01:58:28 +00:00
|
|
|
// XXX This is an ancient and broken feature, don't use this for new bug
|
|
|
|
// as far as possible.
|
2013-09-24 10:04:14 +00:00
|
|
|
bool mNoContentDispatch : 1;
|
|
|
|
// If mOnlyChromeDispatch is true, the event is dispatched to only chrome.
|
|
|
|
bool mOnlyChromeDispatch : 1;
|
2017-07-05 04:58:41 +00:00
|
|
|
// Indicates if the key combination is reserved by chrome. This is set by
|
|
|
|
// MarkAsReservedByChrome().
|
|
|
|
bool mIsReservedByChrome : 1;
|
2016-03-16 01:58:28 +00:00
|
|
|
// If mOnlySystemGroupDispatchInContent is true, event listeners added to
|
|
|
|
// the default group for non-chrome EventTarget won't be called.
|
2016-03-16 01:58:28 +00:00
|
|
|
// Be aware, if this is true, EventDispatcher needs to check if each event
|
|
|
|
// listener is added to chrome node, so, don't set this to true for the
|
|
|
|
// events which are fired a lot of times like eMouseMove.
|
2016-03-16 01:58:28 +00:00
|
|
|
bool mOnlySystemGroupDispatchInContent : 1;
|
2018-12-20 21:35:39 +00:00
|
|
|
// If mOnlySystemGroupDispatch is true, the event will be dispatched only to
|
|
|
|
// event listeners added in the system group.
|
|
|
|
bool mOnlySystemGroupDispatch : 1;
|
2015-04-15 16:28:47 +00:00
|
|
|
// The event's action will be handled by APZ. The main thread should not
|
2018-11-05 23:36:14 +00:00
|
|
|
// perform its associated action.
|
2015-04-15 16:28:47 +00:00
|
|
|
bool mHandledByAPZ : 1;
|
2016-05-12 18:50:22 +00:00
|
|
|
// True if the event is currently being handled by an event listener that
|
|
|
|
// was registered as a passive listener.
|
|
|
|
bool mInPassiveListener : 1;
|
2016-08-31 03:16:11 +00:00
|
|
|
// If mComposed is true, the event fired by nodes in shadow DOM can cross the
|
|
|
|
// boundary of shadow DOM and light DOM.
|
|
|
|
bool mComposed : 1;
|
2016-09-12 10:15:16 +00:00
|
|
|
// Similar to mComposed. Set it to true to allow events cross the boundary
|
|
|
|
// between native non-anonymous content and native anonymouse content
|
|
|
|
bool mComposedInNativeAnonymousContent : 1;
|
2016-12-02 05:41:00 +00:00
|
|
|
// Set to true for events which are suppressed or delayed so that later a
|
|
|
|
// DelayedEvent of it is dispatched. This is used when parent side process
|
|
|
|
// the key event after content side, and may drop the event if the event
|
|
|
|
// was suppressed or delayed in contents side.
|
|
|
|
// It is also set to true for the events (in a DelayedInputEvent), which will
|
|
|
|
// be dispatched afterwards.
|
2016-11-21 11:55:00 +00:00
|
|
|
bool mIsSuppressedOrDelayed : 1;
|
2017-03-23 10:57:44 +00:00
|
|
|
// Certain mouse events can be marked as positionless to return 0 from
|
|
|
|
// coordinate related getters.
|
|
|
|
bool mIsPositionless : 1;
|
2013-09-24 10:04:14 +00:00
|
|
|
|
2017-07-05 04:58:41 +00:00
|
|
|
// Flags managing state of propagation between processes.
|
|
|
|
// Note the the following flags shouldn't be referred directly. Use utility
|
|
|
|
// methods instead.
|
|
|
|
|
|
|
|
// If mNoRemoteProcessDispatch is true, the event is not allowed to be sent
|
|
|
|
// to remote process.
|
|
|
|
bool mNoRemoteProcessDispatch : 1;
|
|
|
|
// If mWantReplyFromContentProcess is true, the event will be redispatched
|
|
|
|
// in the parent process after the content process has handled it. Useful
|
|
|
|
// for when the parent process need the know first how the event was used
|
|
|
|
// by content before handling it itself.
|
|
|
|
bool mWantReplyFromContentProcess : 1;
|
2017-07-05 09:59:44 +00:00
|
|
|
// If mPostedToRemoteProcess is true, the event has been posted to the
|
|
|
|
// remote process (but it's not handled yet if it's not a duplicated event
|
|
|
|
// instance).
|
|
|
|
bool mPostedToRemoteProcess : 1;
|
2020-03-05 21:34:28 +00:00
|
|
|
// If mCameFromAnotherProcess is true, the event came from another process.
|
|
|
|
bool mCameFromAnotherProcess : 1;
|
2017-07-05 04:58:41 +00:00
|
|
|
|
2016-03-17 02:17:42 +00:00
|
|
|
/**
|
|
|
|
* Helper methods for methods of DOM Event.
|
|
|
|
*/
|
|
|
|
inline void StopPropagation() { mPropagationStopped = true; }
|
2016-03-17 02:57:42 +00:00
|
|
|
inline void StopImmediatePropagation() {
|
|
|
|
StopPropagation();
|
|
|
|
mImmediatePropagationStopped = true;
|
|
|
|
}
|
2016-03-22 07:26:27 +00:00
|
|
|
inline void PreventDefault(bool aCalledByDefaultHandler = true) {
|
2017-01-12 12:14:43 +00:00
|
|
|
if (!mCancelable) {
|
|
|
|
return;
|
|
|
|
}
|
2016-03-22 07:26:27 +00:00
|
|
|
mDefaultPrevented = true;
|
|
|
|
// Note that even if preventDefault() has already been called by chrome,
|
|
|
|
// a call of preventDefault() by content needs to overwrite
|
|
|
|
// mDefaultPreventedByContent to true because in such case, defaultPrevented
|
|
|
|
// must be true when web apps check it after they call preventDefault().
|
|
|
|
if (aCalledByDefaultHandler) {
|
Bug 1435717 - Make calling WidgetEvent::PreventDefault*() stop cross process forwarding too r=smaug
Currently, if an event is consumed in the main process, EventStateManager
does not send it to remote process. However, this is unexpected behavior
for some WidgetKeyboardEvent dispatchers. OS sometimes has consumed native
key events before sending applications. For example, Alt key on Windows
should activate menu bar of focused window but Alt key may be consumed before
focused window receives the event. In such case, we mark Alt keyboard event
as "consumed before dispatch", and chrome treat it like as its preventDefault()
is called in web content. (Note that for compatibility with other browsers,
the consumed state is not exposed to web content. So, Event.defaultPrevented
returns false in web content.)
Therefore, we need to treat "consumed" state and "cross process forwarding"
state separately. This patch makes calling WidgetEvent::PreventDefault()
always stops cross process forwarding for backward compatibility. Additionally,
for the special case mentioned above, this patch makes
WidgetEvent::PreventDefaultBeforeDispatch() take additional argument,
|aIfStopCrossProcessForwarding|. If this is CrossProcessForwarding::eStop,
the event won't be sent to remote process as same as calling PreventDefault().
Otherwise, CrossProcessForwarding::eHold, PreventDefaultBeforeDispatch() call
does not change "cross process forwarding" state. I.e., if the event's
StopCrossProcessForwarding() and PreventDefault() are not called until
EventStateManager::PostHandleEvent(), the event will be sent to remote process
as usual.
MozReview-Commit-ID: IQGWJvXetxV
--HG--
extra : rebase_source : 4ccdd500e80b8fe29e469ac3b85578e1c07c8358
2018-06-25 09:17:18 +00:00
|
|
|
StopCrossProcessForwarding();
|
2016-03-22 07:26:27 +00:00
|
|
|
mDefaultPreventedByChrome = true;
|
|
|
|
} else {
|
|
|
|
mDefaultPreventedByContent = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// This should be used only before dispatching events into the DOM tree.
|
Bug 1435717 - Make calling WidgetEvent::PreventDefault*() stop cross process forwarding too r=smaug
Currently, if an event is consumed in the main process, EventStateManager
does not send it to remote process. However, this is unexpected behavior
for some WidgetKeyboardEvent dispatchers. OS sometimes has consumed native
key events before sending applications. For example, Alt key on Windows
should activate menu bar of focused window but Alt key may be consumed before
focused window receives the event. In such case, we mark Alt keyboard event
as "consumed before dispatch", and chrome treat it like as its preventDefault()
is called in web content. (Note that for compatibility with other browsers,
the consumed state is not exposed to web content. So, Event.defaultPrevented
returns false in web content.)
Therefore, we need to treat "consumed" state and "cross process forwarding"
state separately. This patch makes calling WidgetEvent::PreventDefault()
always stops cross process forwarding for backward compatibility. Additionally,
for the special case mentioned above, this patch makes
WidgetEvent::PreventDefaultBeforeDispatch() take additional argument,
|aIfStopCrossProcessForwarding|. If this is CrossProcessForwarding::eStop,
the event won't be sent to remote process as same as calling PreventDefault().
Otherwise, CrossProcessForwarding::eHold, PreventDefaultBeforeDispatch() call
does not change "cross process forwarding" state. I.e., if the event's
StopCrossProcessForwarding() and PreventDefault() are not called until
EventStateManager::PostHandleEvent(), the event will be sent to remote process
as usual.
MozReview-Commit-ID: IQGWJvXetxV
--HG--
extra : rebase_source : 4ccdd500e80b8fe29e469ac3b85578e1c07c8358
2018-06-25 09:17:18 +00:00
|
|
|
inline void PreventDefaultBeforeDispatch(
|
|
|
|
CrossProcessForwarding aCrossProcessForwarding) {
|
2017-01-12 12:14:43 +00:00
|
|
|
if (!mCancelable) {
|
|
|
|
return;
|
|
|
|
}
|
2016-03-22 07:26:27 +00:00
|
|
|
mDefaultPrevented = true;
|
Bug 1435717 - Make calling WidgetEvent::PreventDefault*() stop cross process forwarding too r=smaug
Currently, if an event is consumed in the main process, EventStateManager
does not send it to remote process. However, this is unexpected behavior
for some WidgetKeyboardEvent dispatchers. OS sometimes has consumed native
key events before sending applications. For example, Alt key on Windows
should activate menu bar of focused window but Alt key may be consumed before
focused window receives the event. In such case, we mark Alt keyboard event
as "consumed before dispatch", and chrome treat it like as its preventDefault()
is called in web content. (Note that for compatibility with other browsers,
the consumed state is not exposed to web content. So, Event.defaultPrevented
returns false in web content.)
Therefore, we need to treat "consumed" state and "cross process forwarding"
state separately. This patch makes calling WidgetEvent::PreventDefault()
always stops cross process forwarding for backward compatibility. Additionally,
for the special case mentioned above, this patch makes
WidgetEvent::PreventDefaultBeforeDispatch() take additional argument,
|aIfStopCrossProcessForwarding|. If this is CrossProcessForwarding::eStop,
the event won't be sent to remote process as same as calling PreventDefault().
Otherwise, CrossProcessForwarding::eHold, PreventDefaultBeforeDispatch() call
does not change "cross process forwarding" state. I.e., if the event's
StopCrossProcessForwarding() and PreventDefault() are not called until
EventStateManager::PostHandleEvent(), the event will be sent to remote process
as usual.
MozReview-Commit-ID: IQGWJvXetxV
--HG--
extra : rebase_source : 4ccdd500e80b8fe29e469ac3b85578e1c07c8358
2018-06-25 09:17:18 +00:00
|
|
|
if (aCrossProcessForwarding == CrossProcessForwarding::eStop) {
|
|
|
|
StopCrossProcessForwarding();
|
|
|
|
}
|
2016-03-22 07:26:27 +00:00
|
|
|
}
|
2016-03-22 07:47:52 +00:00
|
|
|
inline bool DefaultPrevented() const { return mDefaultPrevented; }
|
|
|
|
inline bool DefaultPreventedByContent() const {
|
|
|
|
MOZ_ASSERT(!mDefaultPreventedByContent || DefaultPrevented());
|
|
|
|
return mDefaultPreventedByContent;
|
|
|
|
}
|
2016-03-17 07:01:30 +00:00
|
|
|
inline bool IsTrusted() const { return mIsTrusted; }
|
2016-03-17 07:21:57 +00:00
|
|
|
inline bool PropagationStopped() const { return mPropagationStopped; }
|
2016-03-17 02:17:42 +00:00
|
|
|
|
2017-07-05 04:58:41 +00:00
|
|
|
// Helper methods to access flags managing state of propagation between
|
|
|
|
// processes.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prevent to be dispatched to remote process.
|
|
|
|
*/
|
|
|
|
inline void StopCrossProcessForwarding() {
|
2017-07-05 09:59:44 +00:00
|
|
|
MOZ_ASSERT(!mPostedToRemoteProcess);
|
2017-07-05 04:58:41 +00:00
|
|
|
mNoRemoteProcessDispatch = true;
|
|
|
|
mWantReplyFromContentProcess = false;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Return true if the event shouldn't be dispatched to remote process.
|
|
|
|
*/
|
|
|
|
inline bool IsCrossProcessForwardingStopped() const {
|
|
|
|
return mNoRemoteProcessDispatch;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Mark the event as waiting reply from remote process.
|
2017-07-21 08:22:08 +00:00
|
|
|
* If the caller needs to win other keyboard event handlers in chrome,
|
|
|
|
* the caller should call StopPropagation() too.
|
|
|
|
* Otherwise, if the caller just needs to know if the event is consumed by
|
|
|
|
* either content or chrome, it should just call this because the event
|
|
|
|
* may be reserved by chrome and it needs to be dispatched into the DOM
|
|
|
|
* tree in chrome for checking if it's reserved before being sent to any
|
|
|
|
* remote processes.
|
2017-07-05 04:58:41 +00:00
|
|
|
*/
|
|
|
|
inline void MarkAsWaitingReplyFromRemoteProcess() {
|
2017-07-05 09:59:44 +00:00
|
|
|
MOZ_ASSERT(!mPostedToRemoteProcess);
|
2017-07-05 04:58:41 +00:00
|
|
|
mNoRemoteProcessDispatch = false;
|
|
|
|
mWantReplyFromContentProcess = true;
|
|
|
|
}
|
Bug 1333459 - part2-2: EventStateManager should check if it needs to wait reply from remote content before handling access keys r=smaug
Currently, access key is handled in EventStateManager::PreHandleEvent() with eKeyPress event, i.e., before dispatching it into the DOM tree, if the access key is registered in EventStateManager. So, the main process does not check if the preceding eKeyDown event is consumed in focused remote process.
When preceding eKeyDown event is consumed in the main process, eKeyPress event won't be dispatched by widget. However, if remote process has focus, it's impossible widget to stop dispatching eKeyPress event because preceding eKeyDown event hasn't been handled in the focused remote process yet. Therefore, main process needs to post eKeyPress event to check if preceding eKeyDown event was consumed. When eKeyPress event is marked as "waiting reply from remote process", TabChild sends it back to the main process only when preceding eKeyDown event wasn't consumed. So, only when eKeyPress event is back to the main process, main process should handle accesskey with it.
This patch makes EventStateManager::PreHandleEvent() check if a remote target has focus before handling accesskey. If a remote process has accesskey and there is an accesskey matching with eKeyPress event, it marks the event as "waiting reply from remote content" and stop propagation in the process.
Finally, when eKeyPress event is sent back to TabParent, TabParent::RecvReplyKeyEvent() calls EventStateManager::HandleAccessKey() before dispatching the reply event into the DOM tree.
MozReview-Commit-ID: KsOkakaIVzb
--HG--
extra : rebase_source : 7e0c6966a1bde085e34d45bca4b0166b9fc2f3f1
2017-07-22 01:50:41 +00:00
|
|
|
/**
|
|
|
|
* Reset "waiting reply from remote process" state. This is useful when
|
|
|
|
* you dispatch a copy of an event coming from different process.
|
|
|
|
*/
|
|
|
|
inline void ResetWaitingReplyFromRemoteProcessState() {
|
|
|
|
if (IsWaitingReplyFromRemoteProcess()) {
|
|
|
|
// FYI: mWantReplyFromContentProcess is also used for indicating
|
|
|
|
// "handled in remote process" state. Therefore, only when
|
|
|
|
// IsWaitingReplyFromRemoteProcess() returns true, this should
|
|
|
|
// reset the flag.
|
|
|
|
mWantReplyFromContentProcess = false;
|
|
|
|
}
|
|
|
|
}
|
2017-07-05 04:58:41 +00:00
|
|
|
/**
|
|
|
|
* Return true if the event handler should wait reply event. I.e., if this
|
|
|
|
* returns true, any event handler should do nothing with the event.
|
|
|
|
*/
|
|
|
|
inline bool IsWaitingReplyFromRemoteProcess() const {
|
|
|
|
return !mNoRemoteProcessDispatch && mWantReplyFromContentProcess;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Mark the event as already handled in the remote process. This should be
|
|
|
|
* called when initializing reply events.
|
|
|
|
*/
|
|
|
|
inline void MarkAsHandledInRemoteProcess() {
|
|
|
|
mNoRemoteProcessDispatch = true;
|
|
|
|
mWantReplyFromContentProcess = true;
|
2017-07-05 09:59:44 +00:00
|
|
|
mPostedToRemoteProcess = false;
|
2017-07-05 04:58:41 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Return true if the event has already been handled in the remote process.
|
|
|
|
*/
|
|
|
|
inline bool IsHandledInRemoteProcess() const {
|
|
|
|
return mNoRemoteProcessDispatch && mWantReplyFromContentProcess;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Return true if the event should be sent back to its parent process.
|
|
|
|
*/
|
|
|
|
inline bool WantReplyFromContentProcess() const {
|
|
|
|
MOZ_ASSERT(!XRE_IsParentProcess());
|
|
|
|
return IsWaitingReplyFromRemoteProcess();
|
|
|
|
}
|
2017-07-05 09:59:44 +00:00
|
|
|
/**
|
|
|
|
* Mark the event has already posted to a remote process.
|
|
|
|
*/
|
|
|
|
inline void MarkAsPostedToRemoteProcess() {
|
|
|
|
MOZ_ASSERT(!IsCrossProcessForwardingStopped());
|
|
|
|
mPostedToRemoteProcess = true;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Reset the cross process dispatching state. This should be used when a
|
|
|
|
* process receives the event because the state is in the sender.
|
|
|
|
*/
|
|
|
|
inline void ResetCrossProcessDispatchingState() {
|
|
|
|
MOZ_ASSERT(!IsCrossProcessForwardingStopped());
|
|
|
|
mPostedToRemoteProcess = false;
|
2022-06-02 23:50:44 +00:00
|
|
|
// Ignore propagation state in the remote process if it's marked as
|
Bug 1333459 - part2-2: EventStateManager should check if it needs to wait reply from remote content before handling access keys r=smaug
Currently, access key is handled in EventStateManager::PreHandleEvent() with eKeyPress event, i.e., before dispatching it into the DOM tree, if the access key is registered in EventStateManager. So, the main process does not check if the preceding eKeyDown event is consumed in focused remote process.
When preceding eKeyDown event is consumed in the main process, eKeyPress event won't be dispatched by widget. However, if remote process has focus, it's impossible widget to stop dispatching eKeyPress event because preceding eKeyDown event hasn't been handled in the focused remote process yet. Therefore, main process needs to post eKeyPress event to check if preceding eKeyDown event was consumed. When eKeyPress event is marked as "waiting reply from remote process", TabChild sends it back to the main process only when preceding eKeyDown event wasn't consumed. So, only when eKeyPress event is back to the main process, main process should handle accesskey with it.
This patch makes EventStateManager::PreHandleEvent() check if a remote target has focus before handling accesskey. If a remote process has accesskey and there is an accesskey matching with eKeyPress event, it marks the event as "waiting reply from remote content" and stop propagation in the process.
Finally, when eKeyPress event is sent back to TabParent, TabParent::RecvReplyKeyEvent() calls EventStateManager::HandleAccessKey() before dispatching the reply event into the DOM tree.
MozReview-Commit-ID: KsOkakaIVzb
--HG--
extra : rebase_source : 7e0c6966a1bde085e34d45bca4b0166b9fc2f3f1
2017-07-22 01:50:41 +00:00
|
|
|
// "waiting reply from remote process" because the process needs to
|
|
|
|
// stop propagation in the process until receiving a reply event.
|
2022-06-02 23:50:44 +00:00
|
|
|
// Note that the propagation stopped flag is important for the reply event
|
|
|
|
// handler in the main process because it's used for making whether it's
|
|
|
|
// ignored by the remote process or not.
|
|
|
|
if (!XRE_IsParentProcess() && IsWaitingReplyFromRemoteProcess()) {
|
Bug 1333459 - part2-2: EventStateManager should check if it needs to wait reply from remote content before handling access keys r=smaug
Currently, access key is handled in EventStateManager::PreHandleEvent() with eKeyPress event, i.e., before dispatching it into the DOM tree, if the access key is registered in EventStateManager. So, the main process does not check if the preceding eKeyDown event is consumed in focused remote process.
When preceding eKeyDown event is consumed in the main process, eKeyPress event won't be dispatched by widget. However, if remote process has focus, it's impossible widget to stop dispatching eKeyPress event because preceding eKeyDown event hasn't been handled in the focused remote process yet. Therefore, main process needs to post eKeyPress event to check if preceding eKeyDown event was consumed. When eKeyPress event is marked as "waiting reply from remote process", TabChild sends it back to the main process only when preceding eKeyDown event wasn't consumed. So, only when eKeyPress event is back to the main process, main process should handle accesskey with it.
This patch makes EventStateManager::PreHandleEvent() check if a remote target has focus before handling accesskey. If a remote process has accesskey and there is an accesskey matching with eKeyPress event, it marks the event as "waiting reply from remote content" and stop propagation in the process.
Finally, when eKeyPress event is sent back to TabParent, TabParent::RecvReplyKeyEvent() calls EventStateManager::HandleAccessKey() before dispatching the reply event into the DOM tree.
MozReview-Commit-ID: KsOkakaIVzb
--HG--
extra : rebase_source : 7e0c6966a1bde085e34d45bca4b0166b9fc2f3f1
2017-07-22 01:50:41 +00:00
|
|
|
mPropagationStopped = mImmediatePropagationStopped = false;
|
|
|
|
}
|
Bug 1581192 - `WidgetEvent::mFlags::mDispatchedAtLeastOnce` needs to be reset before dispatching in content process again r=smaug
The crash occurs when dispatching a user input event which is a default action
of a raw user input event like `click` event caused by `mouseup` event if
the raw event's `isTrusted` is set to `false` accidentally during dispatch.
User input events are fired in the main process first. Then,
`EventStateManager` sends it to remote process from `PostHandleEvent()` if
necessary. However, at this time, `WidgetEvent::mFlags::mDispatchedAtLeastOnce`
is never rest, but its only referrer, `EventDispatcher::DispatchDOMEvent()`
assumes that when it's `true`, `WidgetEvent::mFlags:mIsBeingDispatched` is
`false`. Therefore, only in content process, `mouseup` event's `isTrusted` is
set to `false` by `EventTarget.dispatchEvent()` even while it's being dispatch.
And also the trusted state will be used for creating next event which is part
of the default action.
https://searchfox.org/mozilla-central/rev/6566d92dd46417a2f57e75c515135ebe84c9cef5/dom/events/EventDispatcher.cpp#1121,1126,1130-1131,1135,1138,1143
Therefore, this patch makes `WidgetEvent::mFlags` reset `mDispatchedAtLeastOnce`
when it's copied across process boundary and make
`EventDispatcher::DispatchDOMEvent()` won't modify being dispatched events for
avoiding any odd issues.
Unfortunately, this patch adds "expected: FAIL" to the new WPT test only on
Windows. The failure reason is still unclear. I cannot reproduce the failure
on my Windows environment, but on Try Server, it fails permanently since
the driver succeeds to send the mouse click, but the button never receives
`mouseup` nor `click` event.
Differential Revision: https://phabricator.services.mozilla.com/D52988
--HG--
extra : moz-landing-system : lando
2019-11-26 09:08:38 +00:00
|
|
|
// mDispatchedAtLeastOnce indicates the state in current process.
|
|
|
|
mDispatchedAtLeastOnce = false;
|
2017-07-05 09:59:44 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Return true if the event has been posted to a remote process.
|
|
|
|
* Note that MarkAsPostedToRemoteProcess() is called by
|
|
|
|
* ParamTraits<mozilla::WidgetEvent>. Therefore, it *might* be possible
|
|
|
|
* that posting the event failed even if this returns true. But that must
|
|
|
|
* really rare. If that'd be problem for you, you should unmark this in
|
2019-04-09 21:38:15 +00:00
|
|
|
* BrowserParent or somewhere.
|
2017-07-05 09:59:44 +00:00
|
|
|
*/
|
|
|
|
inline bool HasBeenPostedToRemoteProcess() const {
|
|
|
|
return mPostedToRemoteProcess;
|
|
|
|
}
|
2020-03-05 21:34:28 +00:00
|
|
|
/**
|
|
|
|
* Return true if the event came from another process.
|
|
|
|
*/
|
|
|
|
inline bool CameFromAnotherProcess() const { return mCameFromAnotherProcess; }
|
|
|
|
/**
|
|
|
|
* Mark the event as coming from another process.
|
|
|
|
*/
|
|
|
|
inline void MarkAsComingFromAnotherProcess() {
|
|
|
|
mCameFromAnotherProcess = true;
|
|
|
|
}
|
2017-07-05 04:58:41 +00:00
|
|
|
/**
|
|
|
|
* Mark the event is reserved by chrome. I.e., shouldn't be dispatched to
|
|
|
|
* content because it shouldn't be cancelable.
|
|
|
|
*/
|
|
|
|
inline void MarkAsReservedByChrome() {
|
2017-07-05 09:59:44 +00:00
|
|
|
MOZ_ASSERT(!mPostedToRemoteProcess);
|
2017-07-05 04:58:41 +00:00
|
|
|
mIsReservedByChrome = true;
|
|
|
|
// For reserved commands (such as Open New Tab), we don't need to wait for
|
|
|
|
// the content to answer, neither to give a chance for content to override
|
|
|
|
// its behavior.
|
|
|
|
StopCrossProcessForwarding();
|
|
|
|
// If the event is reserved by chrome, we shouldn't expose the event to
|
|
|
|
// web contents because such events shouldn't be cancelable. So, it's not
|
|
|
|
// good behavior to fire such events but to ignore the defaultPrevented
|
|
|
|
// attribute value in chrome.
|
|
|
|
mOnlySystemGroupDispatchInContent = true;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Return true if the event is reserved by chrome.
|
|
|
|
*/
|
|
|
|
inline bool IsReservedByChrome() const {
|
|
|
|
MOZ_ASSERT(!mIsReservedByChrome || (IsCrossProcessForwardingStopped() &&
|
|
|
|
mOnlySystemGroupDispatchInContent));
|
|
|
|
return mIsReservedByChrome;
|
|
|
|
}
|
|
|
|
|
2013-09-24 10:04:14 +00:00
|
|
|
inline void Clear() { SetRawFlags(0); }
|
|
|
|
// Get if either the instance's bit or the aOther's bit is true, the
|
|
|
|
// instance's bit becomes true. In other words, this works like:
|
|
|
|
// eventFlags |= aOther;
|
|
|
|
inline void Union(const BaseEventFlags& aOther) {
|
|
|
|
RawFlags rawFlags = GetRawFlags() | aOther.GetRawFlags();
|
|
|
|
SetRawFlags(rawFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-11-13 18:12:02 +00:00
|
|
|
typedef uint64_t RawFlags;
|
2013-09-24 10:04:14 +00:00
|
|
|
|
|
|
|
inline void SetRawFlags(RawFlags aRawFlags) {
|
|
|
|
static_assert(sizeof(BaseEventFlags) <= sizeof(RawFlags),
|
|
|
|
"mozilla::EventFlags must not be bigger than the RawFlags");
|
|
|
|
memcpy(this, &aRawFlags, sizeof(BaseEventFlags));
|
|
|
|
}
|
|
|
|
inline RawFlags GetRawFlags() const {
|
|
|
|
RawFlags result = 0;
|
|
|
|
memcpy(&result, this, sizeof(BaseEventFlags));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::EventFlags
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
struct EventFlags : public BaseEventFlags {
|
|
|
|
EventFlags() { Clear(); }
|
|
|
|
};
|
|
|
|
|
2016-03-16 04:47:48 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::WidgetEventTime
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
class WidgetEventTime {
|
|
|
|
public:
|
2023-01-02 12:31:40 +00:00
|
|
|
// Timestamp when the message was created.
|
2016-03-28 04:49:02 +00:00
|
|
|
TimeStamp mTimeStamp;
|
2016-03-16 04:47:48 +00:00
|
|
|
|
2023-01-02 12:31:40 +00:00
|
|
|
WidgetEventTime() : mTimeStamp(TimeStamp::Now()) {}
|
2016-03-16 04:47:48 +00:00
|
|
|
|
2023-08-09 10:29:39 +00:00
|
|
|
explicit WidgetEventTime(const WidgetEventTime* aTime)
|
|
|
|
: mTimeStamp(aTime ? aTime->mTimeStamp : TimeStamp::Now()) {
|
|
|
|
MOZ_ASSERT(aTime != this);
|
|
|
|
MOZ_ASSERT_IF(aTime, !aTime->mTimeStamp.IsNull());
|
|
|
|
}
|
|
|
|
|
2023-01-02 12:31:40 +00:00
|
|
|
explicit WidgetEventTime(TimeStamp aTimeStamp) : mTimeStamp(aTimeStamp) {}
|
2016-03-16 04:47:48 +00:00
|
|
|
|
|
|
|
void AssignEventTime(const WidgetEventTime& aOther) {
|
2016-03-28 04:49:02 +00:00
|
|
|
mTimeStamp = aOther.mTimeStamp;
|
2016-03-16 04:47:48 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-09-24 10:04:14 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::WidgetEvent
|
|
|
|
******************************************************************************/
|
|
|
|
|
2016-03-16 04:47:48 +00:00
|
|
|
class WidgetEvent : public WidgetEventTime {
|
2016-04-13 06:16:42 +00:00
|
|
|
private:
|
|
|
|
void SetDefaultCancelableAndBubbles() {
|
|
|
|
switch (mClass) {
|
|
|
|
case eEditorInputEventClass:
|
|
|
|
mFlags.mCancelable = false;
|
|
|
|
mFlags.mBubbles = mFlags.mIsTrusted;
|
|
|
|
break;
|
2024-04-08 12:29:59 +00:00
|
|
|
case eLegacyTextEventClass:
|
|
|
|
mFlags.mCancelable = mFlags.mIsTrusted && mMessage == eLegacyTextInput;
|
|
|
|
mFlags.mBubbles = mFlags.mIsTrusted && mMessage == eLegacyTextInput;
|
|
|
|
break;
|
2016-04-13 06:16:42 +00:00
|
|
|
case eMouseEventClass:
|
|
|
|
mFlags.mCancelable =
|
|
|
|
(mMessage != eMouseEnter && mMessage != eMouseLeave);
|
|
|
|
mFlags.mBubbles = (mMessage != eMouseEnter && mMessage != eMouseLeave);
|
|
|
|
break;
|
|
|
|
case ePointerEventClass:
|
|
|
|
mFlags.mCancelable =
|
|
|
|
(mMessage != ePointerEnter && mMessage != ePointerLeave &&
|
|
|
|
mMessage != ePointerCancel && mMessage != ePointerGotCapture &&
|
|
|
|
mMessage != ePointerLostCapture);
|
|
|
|
mFlags.mBubbles =
|
|
|
|
(mMessage != ePointerEnter && mMessage != ePointerLeave);
|
|
|
|
break;
|
|
|
|
case eDragEventClass:
|
|
|
|
mFlags.mCancelable = (mMessage != eDragExit && mMessage != eDragLeave &&
|
|
|
|
mMessage != eDragEnd);
|
|
|
|
mFlags.mBubbles = true;
|
|
|
|
break;
|
|
|
|
case eSMILTimeEventClass:
|
|
|
|
mFlags.mCancelable = false;
|
|
|
|
mFlags.mBubbles = false;
|
|
|
|
break;
|
|
|
|
case eTransitionEventClass:
|
|
|
|
case eAnimationEventClass:
|
|
|
|
mFlags.mCancelable = false;
|
|
|
|
mFlags.mBubbles = true;
|
|
|
|
break;
|
|
|
|
case eCompositionEventClass:
|
|
|
|
// XXX compositionstart is cancelable in draft of DOM3 Events.
|
|
|
|
// However, it doesn't make sense for us, we cannot cancel
|
|
|
|
// composition when we send compositionstart event.
|
|
|
|
mFlags.mCancelable = false;
|
|
|
|
mFlags.mBubbles = true;
|
|
|
|
break;
|
|
|
|
default:
|
Bug 1478776 - Part 10: Add internal VisualViewport resize/scroll events. r=botond,nika
The VisualViewport events are all nice and shiny, but unfortunately not quite
what is needed for the session store.
Firstly, the spec wants the "scroll" event to be fired only when the *relative*
offset between visual and layout viewport changes. The session store however
records the absolute offset and as such is interested in when *that* changes.
Secondly, again as per the spec the events don't bubble, and with the default
DOMEventTargetHelper implementation they don't escape the VisualViewport during
capturing, either. This means that any event listener must be added directly on
the VisualViewport itself in order to capture any events.
This might have been intended because the events use the same names as the
normal "scroll"/"resize" events, and as such you cannot specify separate event
listeners for VisualViewport and non-VisualViewport "scroll" events if both
events end up being dispatched to the same element (you can only try to filter
after the fact by looking at the originalTarget of the event).
At the same time, the VisualViewport is attached to the inner Window, and so
each time you navigate, you also get a different VisualViewport object.
All of this might be totally fine from the perspective of a page script, because
in that case you won't care anyway about what happens when the current page goes
away.
From the session store perspective on the other hand (especially Fennec's non-
e10s session store design), this is rather unfortunate because we don't want to
have to keep registering event listeners
a) manually for each subframe
b) each time the page navigates
The event target chain problem could be solved by letting the scroll events
escape the VisualViewport during the capturing phase (which the spec doesn't say
anything about), but this would mean that any scroll listener attached to a
window/browser/... that uses capturing will now catch both layout and visual
viewport scroll events.
In some cases this might even be beneficial, but in others (e.g. bug 1498812
comment 21) I'd like to specifically decide which kind of scroll event to
capture. Having to look at event.originalTarget to distinguish the two kinds
might be defensible in test code, but in case this distinction would be needed
in production code as well, given the existence of a C++-based filtering helper
in nsSessionStoreUtils for another use case where (scroll) events need to be
filtered, JS-based scroll event filtering might be a bad idea.
Additionally, in any case this wouldn't solve the fundamental conflict between
the spec and the session store about *when* the "scroll" event should be fired
in the first place.
Hence I'd like to introduce a separate set of events with distinct event names,
which will be dispatched according to the requirements of our internal users
(i.e. currently the session store). To avoid potential web compatibility issues
down the road, for now these events will be dispatched only to event listeners
registered in the system group (allowing *all* Chrome event listeners cannot be
done because checking the Chrome status of each event target might be too
expensive for frequently dispatched events).
Differential Revision: https://phabricator.services.mozilla.com/D14046
--HG--
extra : moz-landing-system : lando
2018-12-20 22:14:42 +00:00
|
|
|
if (mMessage == eResize || mMessage == eMozVisualResize ||
|
2020-11-15 02:32:22 +00:00
|
|
|
mMessage == eMozVisualScroll || mMessage == eEditorInput ||
|
|
|
|
mMessage == eFormSelect) {
|
2016-05-26 22:35:48 +00:00
|
|
|
mFlags.mCancelable = false;
|
|
|
|
} else {
|
|
|
|
mFlags.mCancelable = true;
|
|
|
|
}
|
2016-04-13 06:16:42 +00:00
|
|
|
mFlags.mBubbles = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-24 10:04:14 +00:00
|
|
|
protected:
|
2015-08-26 12:56:59 +00:00
|
|
|
WidgetEvent(bool aIsTrusted, EventMessage aMessage,
|
2023-08-09 10:29:39 +00:00
|
|
|
EventClassID aEventClassID,
|
|
|
|
const WidgetEventTime* aTime = nullptr)
|
|
|
|
: WidgetEventTime(aTime),
|
2016-03-16 04:47:48 +00:00
|
|
|
mClass(aEventClassID),
|
2015-08-22 01:34:51 +00:00
|
|
|
mMessage(aMessage),
|
2016-04-18 14:09:02 +00:00
|
|
|
mRefPoint(0, 0),
|
2016-04-18 14:28:22 +00:00
|
|
|
mLastRefPoint(0, 0),
|
2017-06-06 00:45:31 +00:00
|
|
|
mFocusSequenceNumber(0),
|
2016-04-18 14:53:03 +00:00
|
|
|
mSpecifiedEventType(nullptr),
|
2019-02-26 07:15:43 +00:00
|
|
|
mPath(nullptr),
|
|
|
|
mLayersId(layers::LayersId{0}) {
|
2013-09-24 10:04:14 +00:00
|
|
|
MOZ_COUNT_CTOR(WidgetEvent);
|
|
|
|
mFlags.Clear();
|
|
|
|
mFlags.mIsTrusted = aIsTrusted;
|
2016-04-13 06:16:42 +00:00
|
|
|
SetDefaultCancelableAndBubbles();
|
2016-08-31 03:16:11 +00:00
|
|
|
SetDefaultComposed();
|
2016-09-12 10:15:16 +00:00
|
|
|
SetDefaultComposedInNativeAnonymousContent();
|
2013-09-24 10:04:14 +00:00
|
|
|
}
|
|
|
|
|
2023-10-15 15:29:02 +00:00
|
|
|
WidgetEvent() : mPath(nullptr) { MOZ_COUNT_CTOR(WidgetEvent); }
|
2013-09-24 10:04:14 +00:00
|
|
|
|
|
|
|
public:
|
2023-08-09 10:29:39 +00:00
|
|
|
WidgetEvent(bool aIsTrusted, EventMessage aMessage,
|
|
|
|
const WidgetEventTime* aTime = nullptr)
|
|
|
|
: WidgetEvent(aIsTrusted, aMessage, eBasicEventClass, aTime) {}
|
2013-09-24 10:04:14 +00:00
|
|
|
|
2020-02-20 11:40:14 +00:00
|
|
|
MOZ_COUNTED_DTOR_VIRTUAL(WidgetEvent)
|
2013-09-24 10:04:14 +00:00
|
|
|
|
2023-10-15 15:29:02 +00:00
|
|
|
WidgetEvent(const WidgetEvent& aOther) : WidgetEventTime(aOther) {
|
2013-09-24 10:04:14 +00:00
|
|
|
MOZ_COUNT_CTOR(WidgetEvent);
|
|
|
|
*this = aOther;
|
|
|
|
}
|
2018-01-30 00:26:48 +00:00
|
|
|
WidgetEvent& operator=(const WidgetEvent& aOther) = default;
|
|
|
|
|
|
|
|
WidgetEvent(WidgetEvent&& aOther)
|
2018-05-30 19:15:35 +00:00
|
|
|
: WidgetEventTime(std::move(aOther)),
|
2018-01-30 00:26:48 +00:00
|
|
|
mClass(aOther.mClass),
|
|
|
|
mMessage(aOther.mMessage),
|
2018-05-30 19:15:35 +00:00
|
|
|
mRefPoint(std::move(aOther.mRefPoint)),
|
|
|
|
mLastRefPoint(std::move(aOther.mLastRefPoint)),
|
2018-01-30 00:26:48 +00:00
|
|
|
mFocusSequenceNumber(aOther.mFocusSequenceNumber),
|
2018-05-30 19:15:35 +00:00
|
|
|
mFlags(std::move(aOther.mFlags)),
|
|
|
|
mSpecifiedEventType(std::move(aOther.mSpecifiedEventType)),
|
|
|
|
mSpecifiedEventTypeString(std::move(aOther.mSpecifiedEventTypeString)),
|
|
|
|
mTarget(std::move(aOther.mTarget)),
|
|
|
|
mCurrentTarget(std::move(aOther.mCurrentTarget)),
|
|
|
|
mOriginalTarget(std::move(aOther.mOriginalTarget)),
|
|
|
|
mRelatedTarget(std::move(aOther.mRelatedTarget)),
|
|
|
|
mOriginalRelatedTarget(std::move(aOther.mOriginalRelatedTarget)),
|
|
|
|
mPath(std::move(aOther.mPath)) {
|
2018-01-30 00:26:48 +00:00
|
|
|
MOZ_COUNT_CTOR(WidgetEvent);
|
|
|
|
}
|
|
|
|
WidgetEvent& operator=(WidgetEvent&& aOther) = default;
|
2013-09-24 10:04:14 +00:00
|
|
|
|
2014-01-27 06:10:44 +00:00
|
|
|
virtual WidgetEvent* Duplicate() const {
|
2014-08-04 05:28:58 +00:00
|
|
|
MOZ_ASSERT(mClass == eBasicEventClass,
|
2014-01-27 06:10:44 +00:00
|
|
|
"Duplicate() must be overridden by sub class");
|
2023-08-09 10:29:39 +00:00
|
|
|
WidgetEvent* result = new WidgetEvent(false, mMessage, this);
|
2014-01-27 06:10:44 +00:00
|
|
|
result->AssignEventData(*this, true);
|
|
|
|
result->mFlags = mFlags;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-08-04 05:28:46 +00:00
|
|
|
EventClassID mClass;
|
2015-08-26 12:56:59 +00:00
|
|
|
EventMessage mMessage;
|
2013-09-24 10:04:14 +00:00
|
|
|
// Relative to the widget of the event, or if there is no widget then it is
|
|
|
|
// in screen coordinates. Not modified by layout code.
|
2020-05-05 19:24:41 +00:00
|
|
|
// This is in visual coordinates, i.e. the correct RelativeTo value that
|
|
|
|
// expresses what this is relative to is `{viewportFrame, Visual}`, where
|
|
|
|
// `viewportFrame` is the viewport frame of the widget's root document.
|
2016-04-18 14:09:02 +00:00
|
|
|
LayoutDeviceIntPoint mRefPoint;
|
|
|
|
// The previous mRefPoint, if known, used to calculate mouse movement deltas.
|
2016-04-18 14:28:22 +00:00
|
|
|
LayoutDeviceIntPoint mLastRefPoint;
|
2017-06-06 00:45:31 +00:00
|
|
|
// The sequence number of the last potentially focus changing event handled
|
|
|
|
// by APZ. This is used to track when that event has been processed by
|
|
|
|
// content, and focus can be reconfirmed for async keyboard scrolling.
|
|
|
|
uint64_t mFocusSequenceNumber;
|
2013-09-24 10:04:14 +00:00
|
|
|
// See BaseEventFlags definition for the detail.
|
|
|
|
BaseEventFlags mFlags;
|
|
|
|
|
2016-04-18 14:53:03 +00:00
|
|
|
// If JS creates an event with unknown event type or known event type but
|
|
|
|
// for different event interface, the event type is stored to this.
|
2018-11-21 03:59:02 +00:00
|
|
|
// NOTE: This is always used if the instance is a WidgetCommandEvent instance
|
|
|
|
// or "input" event is dispatched with dom::Event class.
|
2017-10-02 22:05:19 +00:00
|
|
|
RefPtr<nsAtom> mSpecifiedEventType;
|
2013-09-24 10:04:14 +00:00
|
|
|
|
2017-10-02 22:05:19 +00:00
|
|
|
// nsAtom isn't available on non-main thread due to unsafe. Therefore,
|
2016-04-18 15:10:17 +00:00
|
|
|
// mSpecifiedEventTypeString is used instead of mSpecifiedEventType if
|
|
|
|
// the event is created in non-main thread.
|
|
|
|
nsString mSpecifiedEventTypeString;
|
2013-09-24 10:04:14 +00:00
|
|
|
|
|
|
|
// Event targets, needed by DOM Events
|
2017-01-17 08:17:06 +00:00
|
|
|
// Note that when you need event target for DOM event, you should use
|
|
|
|
// Get*DOMEventTarget() instead of accessing these members directly.
|
2016-04-18 15:46:00 +00:00
|
|
|
nsCOMPtr<dom::EventTarget> mTarget;
|
2016-04-18 16:15:16 +00:00
|
|
|
nsCOMPtr<dom::EventTarget> mCurrentTarget;
|
2016-04-18 16:33:23 +00:00
|
|
|
nsCOMPtr<dom::EventTarget> mOriginalTarget;
|
2013-09-24 10:04:14 +00:00
|
|
|
|
2017-12-18 17:08:11 +00:00
|
|
|
/// The possible related target
|
|
|
|
nsCOMPtr<dom::EventTarget> mRelatedTarget;
|
2018-02-15 10:08:42 +00:00
|
|
|
nsCOMPtr<dom::EventTarget> mOriginalRelatedTarget;
|
2017-12-18 17:08:11 +00:00
|
|
|
|
2017-12-18 16:07:36 +00:00
|
|
|
nsTArray<EventTargetChainItem>* mPath;
|
|
|
|
|
2019-02-26 07:15:43 +00:00
|
|
|
// The LayersId of the content process that this event should be
|
|
|
|
// dispatched to. This field is only used in the chrome process
|
|
|
|
// and doesn't get remoted to child processes.
|
|
|
|
layers::LayersId mLayersId;
|
|
|
|
|
2017-01-17 08:17:06 +00:00
|
|
|
dom::EventTarget* GetDOMEventTarget() const;
|
|
|
|
dom::EventTarget* GetCurrentDOMEventTarget() const;
|
|
|
|
dom::EventTarget* GetOriginalDOMEventTarget() const;
|
|
|
|
|
2013-09-24 10:04:14 +00:00
|
|
|
void AssignEventData(const WidgetEvent& aEvent, bool aCopyTargets) {
|
2014-08-04 05:28:46 +00:00
|
|
|
// mClass should be initialized with the constructor.
|
2015-08-22 01:34:51 +00:00
|
|
|
// mMessage should be initialized with the constructor.
|
2016-04-18 14:09:02 +00:00
|
|
|
mRefPoint = aEvent.mRefPoint;
|
2016-04-18 14:28:22 +00:00
|
|
|
// mLastRefPoint doesn't need to be copied.
|
2017-06-06 00:45:31 +00:00
|
|
|
mFocusSequenceNumber = aEvent.mFocusSequenceNumber;
|
2019-02-26 07:15:43 +00:00
|
|
|
// mLayersId intentionally not copied, since it's not used within content
|
2016-03-16 04:47:48 +00:00
|
|
|
AssignEventTime(aEvent);
|
2013-09-24 10:04:14 +00:00
|
|
|
// mFlags should be copied manually if it's necessary.
|
2016-04-18 14:53:03 +00:00
|
|
|
mSpecifiedEventType = aEvent.mSpecifiedEventType;
|
2016-04-18 15:10:17 +00:00
|
|
|
// mSpecifiedEventTypeString should be copied manually if it's necessary.
|
2016-04-18 15:46:00 +00:00
|
|
|
mTarget = aCopyTargets ? aEvent.mTarget : nullptr;
|
2016-04-18 16:15:16 +00:00
|
|
|
mCurrentTarget = aCopyTargets ? aEvent.mCurrentTarget : nullptr;
|
2016-04-18 16:33:23 +00:00
|
|
|
mOriginalTarget = aCopyTargets ? aEvent.mOriginalTarget : nullptr;
|
2017-12-18 17:08:11 +00:00
|
|
|
mRelatedTarget = aCopyTargets ? aEvent.mRelatedTarget : nullptr;
|
2018-02-15 10:08:42 +00:00
|
|
|
mOriginalRelatedTarget =
|
|
|
|
aCopyTargets ? aEvent.mOriginalRelatedTarget : nullptr;
|
2013-09-24 10:04:14 +00:00
|
|
|
}
|
2013-09-24 10:04:16 +00:00
|
|
|
|
2016-03-17 02:17:42 +00:00
|
|
|
/**
|
|
|
|
* Helper methods for methods of DOM Event.
|
|
|
|
*/
|
|
|
|
void StopPropagation() { mFlags.StopPropagation(); }
|
2016-03-17 02:57:42 +00:00
|
|
|
void StopImmediatePropagation() { mFlags.StopImmediatePropagation(); }
|
2017-07-10 08:42:01 +00:00
|
|
|
void PreventDefault(bool aCalledByDefaultHandler = true,
|
|
|
|
nsIPrincipal* aPrincipal = nullptr);
|
|
|
|
|
Bug 1435717 - Make calling WidgetEvent::PreventDefault*() stop cross process forwarding too r=smaug
Currently, if an event is consumed in the main process, EventStateManager
does not send it to remote process. However, this is unexpected behavior
for some WidgetKeyboardEvent dispatchers. OS sometimes has consumed native
key events before sending applications. For example, Alt key on Windows
should activate menu bar of focused window but Alt key may be consumed before
focused window receives the event. In such case, we mark Alt keyboard event
as "consumed before dispatch", and chrome treat it like as its preventDefault()
is called in web content. (Note that for compatibility with other browsers,
the consumed state is not exposed to web content. So, Event.defaultPrevented
returns false in web content.)
Therefore, we need to treat "consumed" state and "cross process forwarding"
state separately. This patch makes calling WidgetEvent::PreventDefault()
always stops cross process forwarding for backward compatibility. Additionally,
for the special case mentioned above, this patch makes
WidgetEvent::PreventDefaultBeforeDispatch() take additional argument,
|aIfStopCrossProcessForwarding|. If this is CrossProcessForwarding::eStop,
the event won't be sent to remote process as same as calling PreventDefault().
Otherwise, CrossProcessForwarding::eHold, PreventDefaultBeforeDispatch() call
does not change "cross process forwarding" state. I.e., if the event's
StopCrossProcessForwarding() and PreventDefault() are not called until
EventStateManager::PostHandleEvent(), the event will be sent to remote process
as usual.
MozReview-Commit-ID: IQGWJvXetxV
--HG--
extra : rebase_source : 4ccdd500e80b8fe29e469ac3b85578e1c07c8358
2018-06-25 09:17:18 +00:00
|
|
|
void PreventDefaultBeforeDispatch(
|
|
|
|
CrossProcessForwarding aCrossProcessForwarding) {
|
|
|
|
mFlags.PreventDefaultBeforeDispatch(aCrossProcessForwarding);
|
|
|
|
}
|
2016-03-22 07:47:52 +00:00
|
|
|
bool DefaultPrevented() const { return mFlags.DefaultPrevented(); }
|
|
|
|
bool DefaultPreventedByContent() const {
|
|
|
|
return mFlags.DefaultPreventedByContent();
|
|
|
|
}
|
2016-03-17 07:01:30 +00:00
|
|
|
bool IsTrusted() const { return mFlags.IsTrusted(); }
|
2016-03-17 07:21:57 +00:00
|
|
|
bool PropagationStopped() const { return mFlags.PropagationStopped(); }
|
2015-10-17 06:50:09 +00:00
|
|
|
|
2017-07-05 04:58:41 +00:00
|
|
|
/**
|
|
|
|
* Prevent to be dispatched to remote process.
|
|
|
|
*/
|
|
|
|
inline void StopCrossProcessForwarding() {
|
|
|
|
mFlags.StopCrossProcessForwarding();
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Return true if the event shouldn't be dispatched to remote process.
|
|
|
|
*/
|
|
|
|
inline bool IsCrossProcessForwardingStopped() const {
|
|
|
|
return mFlags.IsCrossProcessForwardingStopped();
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Mark the event as waiting reply from remote process.
|
|
|
|
* Note that this also stops immediate propagation in current process.
|
|
|
|
*/
|
|
|
|
inline void MarkAsWaitingReplyFromRemoteProcess() {
|
|
|
|
mFlags.MarkAsWaitingReplyFromRemoteProcess();
|
|
|
|
}
|
Bug 1333459 - part2-2: EventStateManager should check if it needs to wait reply from remote content before handling access keys r=smaug
Currently, access key is handled in EventStateManager::PreHandleEvent() with eKeyPress event, i.e., before dispatching it into the DOM tree, if the access key is registered in EventStateManager. So, the main process does not check if the preceding eKeyDown event is consumed in focused remote process.
When preceding eKeyDown event is consumed in the main process, eKeyPress event won't be dispatched by widget. However, if remote process has focus, it's impossible widget to stop dispatching eKeyPress event because preceding eKeyDown event hasn't been handled in the focused remote process yet. Therefore, main process needs to post eKeyPress event to check if preceding eKeyDown event was consumed. When eKeyPress event is marked as "waiting reply from remote process", TabChild sends it back to the main process only when preceding eKeyDown event wasn't consumed. So, only when eKeyPress event is back to the main process, main process should handle accesskey with it.
This patch makes EventStateManager::PreHandleEvent() check if a remote target has focus before handling accesskey. If a remote process has accesskey and there is an accesskey matching with eKeyPress event, it marks the event as "waiting reply from remote content" and stop propagation in the process.
Finally, when eKeyPress event is sent back to TabParent, TabParent::RecvReplyKeyEvent() calls EventStateManager::HandleAccessKey() before dispatching the reply event into the DOM tree.
MozReview-Commit-ID: KsOkakaIVzb
--HG--
extra : rebase_source : 7e0c6966a1bde085e34d45bca4b0166b9fc2f3f1
2017-07-22 01:50:41 +00:00
|
|
|
/**
|
|
|
|
* Reset "waiting reply from remote process" state. This is useful when
|
|
|
|
* you dispatch a copy of an event coming from different process.
|
|
|
|
*/
|
|
|
|
inline void ResetWaitingReplyFromRemoteProcessState() {
|
|
|
|
mFlags.ResetWaitingReplyFromRemoteProcessState();
|
|
|
|
}
|
2017-07-05 04:58:41 +00:00
|
|
|
/**
|
|
|
|
* Return true if the event handler should wait reply event. I.e., if this
|
|
|
|
* returns true, any event handler should do nothing with the event.
|
|
|
|
*/
|
|
|
|
inline bool IsWaitingReplyFromRemoteProcess() const {
|
|
|
|
return mFlags.IsWaitingReplyFromRemoteProcess();
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Mark the event as already handled in the remote process. This should be
|
|
|
|
* called when initializing reply events.
|
|
|
|
*/
|
|
|
|
inline void MarkAsHandledInRemoteProcess() {
|
|
|
|
mFlags.MarkAsHandledInRemoteProcess();
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Return true if the event has already been handled in the remote process.
|
|
|
|
* I.e., if this returns true, the event is a reply event.
|
|
|
|
*/
|
|
|
|
inline bool IsHandledInRemoteProcess() const {
|
|
|
|
return mFlags.IsHandledInRemoteProcess();
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Return true if the event should be sent back to its parent process.
|
|
|
|
* So, usual event handlers shouldn't call this.
|
|
|
|
*/
|
|
|
|
inline bool WantReplyFromContentProcess() const {
|
|
|
|
return mFlags.WantReplyFromContentProcess();
|
|
|
|
}
|
2017-07-05 09:59:44 +00:00
|
|
|
/**
|
|
|
|
* Mark the event has already posted to a remote process.
|
|
|
|
*/
|
|
|
|
inline void MarkAsPostedToRemoteProcess() {
|
|
|
|
mFlags.MarkAsPostedToRemoteProcess();
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Reset the cross process dispatching state. This should be used when a
|
|
|
|
* process receives the event because the state is in the sender.
|
|
|
|
*/
|
|
|
|
inline void ResetCrossProcessDispatchingState() {
|
|
|
|
mFlags.ResetCrossProcessDispatchingState();
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Return true if the event has been posted to a remote process.
|
|
|
|
*/
|
|
|
|
inline bool HasBeenPostedToRemoteProcess() const {
|
|
|
|
return mFlags.HasBeenPostedToRemoteProcess();
|
|
|
|
}
|
2020-03-05 21:34:28 +00:00
|
|
|
/**
|
|
|
|
* Return true if the event came from another process.
|
|
|
|
*/
|
|
|
|
inline bool CameFromAnotherProcess() const {
|
|
|
|
return mFlags.CameFromAnotherProcess();
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Mark the event as coming from another process.
|
|
|
|
*/
|
|
|
|
inline void MarkAsComingFromAnotherProcess() {
|
|
|
|
mFlags.MarkAsComingFromAnotherProcess();
|
|
|
|
}
|
2017-07-05 04:58:41 +00:00
|
|
|
/**
|
|
|
|
* Mark the event is reserved by chrome. I.e., shouldn't be dispatched to
|
|
|
|
* content because it shouldn't be cancelable.
|
|
|
|
*/
|
|
|
|
inline void MarkAsReservedByChrome() { mFlags.MarkAsReservedByChrome(); }
|
|
|
|
/**
|
|
|
|
* Return true if the event is reserved by chrome.
|
|
|
|
*/
|
|
|
|
inline bool IsReservedByChrome() const { return mFlags.IsReservedByChrome(); }
|
|
|
|
|
2013-09-24 10:04:16 +00:00
|
|
|
/**
|
|
|
|
* Utils for checking event types
|
|
|
|
*/
|
|
|
|
|
2013-10-18 06:10:20 +00:00
|
|
|
/**
|
|
|
|
* As*Event() returns the pointer of the instance only when the instance is
|
|
|
|
* the class or one of its derived class.
|
|
|
|
*/
|
|
|
|
#define NS_ROOT_EVENT_CLASS(aPrefix, aName)
|
|
|
|
#define NS_EVENT_CLASS(aPrefix, aName) \
|
|
|
|
virtual aPrefix##aName* As##aName(); \
|
|
|
|
const aPrefix##aName* As##aName() const;
|
|
|
|
|
|
|
|
#include "mozilla/EventClassList.h"
|
|
|
|
|
|
|
|
#undef NS_EVENT_CLASS
|
|
|
|
#undef NS_ROOT_EVENT_CLASS
|
|
|
|
|
2013-09-24 10:04:16 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the event is a query content event.
|
|
|
|
*/
|
|
|
|
bool IsQueryContentEvent() const;
|
|
|
|
/**
|
|
|
|
* Returns true if the event is a selection event.
|
|
|
|
*/
|
|
|
|
bool IsSelectionEvent() const;
|
|
|
|
/**
|
|
|
|
* Returns true if the event is a content command event.
|
|
|
|
*/
|
|
|
|
bool IsContentCommandEvent() const;
|
|
|
|
|
|
|
|
/**
|
2015-08-22 01:34:51 +00:00
|
|
|
* Returns true if the event mMessage is one of mouse events.
|
2013-09-24 10:04:16 +00:00
|
|
|
*/
|
|
|
|
bool HasMouseEventMessage() const;
|
|
|
|
/**
|
2015-08-22 01:34:51 +00:00
|
|
|
* Returns true if the event mMessage is one of drag events.
|
2013-09-24 10:04:16 +00:00
|
|
|
*/
|
|
|
|
bool HasDragEventMessage() const;
|
|
|
|
/**
|
Bug 1406446 - part 1: InputContextAction should treat focus change during handling a user input as caused by user input even if it's caused by JS r=smaug
Currently, widget doesn't show VKB when input context change is caused by JS.
However, if it's caused by an event handler of a user input, user may expect
to open VKB. For example, if a touch event in fake editor causes moving
focus to actual editable node, user expect to show VKB.
Therefore, InputContextAction should declare two causes. One is unknown but
occurred during handling non-keyboard event. The other is unknown but occurred
during handling keyboard event.
However, EventStateManager doesn't have an API to check if it's being handling
a keyboard event. Therefore, this patch adds it first.
AutoHandlingUserInputStatePusher sends event type to StartHandlingUserInput()
and StopHandlingUserInput() of EventStateManager and sUserKeyboardEventDepth
manages the number of nested keyboard event handling. Therefore,
EventStateManager::IsHandlingKeyboardInput() can return if it's handling a
keyboard event.
IMEStateManager uses this new API to adjust the cause of changes of input
context.
Finally, InputContextAction::IsUserInput() is renamed to IsHandlingUserInput()
for consistency with EventStateManager and starts to return true when the
input context change is caused by script while it's handling a user input.
MozReview-Commit-ID: 5JsLqdqeGah
--HG--
extra : rebase_source : 9fcf7687d1bf90eeebbf6eac62d4488ff64b083c
2017-10-23 17:46:15 +00:00
|
|
|
* Returns true if aMessage or mMessage is one of key events.
|
2013-09-24 10:04:16 +00:00
|
|
|
*/
|
Bug 1406446 - part 1: InputContextAction should treat focus change during handling a user input as caused by user input even if it's caused by JS r=smaug
Currently, widget doesn't show VKB when input context change is caused by JS.
However, if it's caused by an event handler of a user input, user may expect
to open VKB. For example, if a touch event in fake editor causes moving
focus to actual editable node, user expect to show VKB.
Therefore, InputContextAction should declare two causes. One is unknown but
occurred during handling non-keyboard event. The other is unknown but occurred
during handling keyboard event.
However, EventStateManager doesn't have an API to check if it's being handling
a keyboard event. Therefore, this patch adds it first.
AutoHandlingUserInputStatePusher sends event type to StartHandlingUserInput()
and StopHandlingUserInput() of EventStateManager and sUserKeyboardEventDepth
manages the number of nested keyboard event handling. Therefore,
EventStateManager::IsHandlingKeyboardInput() can return if it's handling a
keyboard event.
IMEStateManager uses this new API to adjust the cause of changes of input
context.
Finally, InputContextAction::IsUserInput() is renamed to IsHandlingUserInput()
for consistency with EventStateManager and starts to return true when the
input context change is caused by script while it's handling a user input.
MozReview-Commit-ID: 5JsLqdqeGah
--HG--
extra : rebase_source : 9fcf7687d1bf90eeebbf6eac62d4488ff64b083c
2017-10-23 17:46:15 +00:00
|
|
|
static bool IsKeyEventMessage(EventMessage aMessage);
|
|
|
|
bool HasKeyEventMessage() const { return IsKeyEventMessage(mMessage); }
|
2013-09-24 10:04:16 +00:00
|
|
|
/**
|
2015-08-22 01:34:51 +00:00
|
|
|
* Returns true if the event mMessage is one of composition events or text
|
2013-09-24 10:04:16 +00:00
|
|
|
* event.
|
|
|
|
*/
|
|
|
|
bool HasIMEEventMessage() const;
|
|
|
|
|
2017-01-19 07:46:59 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the event can be sent to remote process.
|
|
|
|
*/
|
|
|
|
bool CanBeSentToRemoteProcess() const;
|
2017-07-19 09:39:34 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the original target is a remote process and the event
|
|
|
|
* will be posted to the remote process later.
|
|
|
|
*/
|
|
|
|
bool WillBeSentToRemoteProcess() const;
|
2013-09-24 10:04:16 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the event is related to IME handling. It includes
|
|
|
|
* IME events, query content events and selection events.
|
|
|
|
* Be careful when you use this.
|
|
|
|
*/
|
|
|
|
bool IsIMERelatedEvent() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the event should be handled by the frame of the mouse cursor
|
|
|
|
* position or not. When it should be handled there (e.g., the mouse events),
|
|
|
|
* this returns true.
|
|
|
|
*/
|
|
|
|
bool IsUsingCoordinates() const;
|
|
|
|
/**
|
|
|
|
* Whether the event should be handled by the focused DOM window in the
|
|
|
|
* same top level window's or not. E.g., key events, IME related events
|
|
|
|
* (including the query content events, they are used in IME transaction)
|
|
|
|
* should be handled by the (last) focused window rather than the dispatched
|
|
|
|
* window.
|
|
|
|
*
|
|
|
|
* NOTE: Even if this returns true, the event isn't going to be handled by the
|
|
|
|
* application level active DOM window which is on another top level window.
|
|
|
|
* So, when the event is fired on a deactive window, the event is going to be
|
|
|
|
* handled by the last focused DOM window in the last focused window.
|
|
|
|
*/
|
|
|
|
bool IsTargetedAtFocusedWindow() const;
|
|
|
|
/**
|
|
|
|
* Whether the event should be handled by the focused content or not. E.g.,
|
|
|
|
* key events, IME related events and other input events which are not handled
|
|
|
|
* by the frame of the mouse cursor position.
|
|
|
|
*
|
|
|
|
* NOTE: Even if this returns true, the event isn't going to be handled by the
|
|
|
|
* application level active DOM window which is on another top level window.
|
|
|
|
* So, when the event is fired on a deactive window, the event is going to be
|
|
|
|
* handled by the last focused DOM element of the last focused DOM window in
|
|
|
|
* the last focused window.
|
|
|
|
*/
|
|
|
|
bool IsTargetedAtFocusedContent() const;
|
|
|
|
/**
|
|
|
|
* Whether the event should cause a DOM event.
|
|
|
|
*/
|
|
|
|
bool IsAllowedToDispatchDOMEvent() const;
|
2016-11-11 10:02:37 +00:00
|
|
|
/**
|
|
|
|
* Whether the event should be dispatched in system group.
|
|
|
|
*/
|
|
|
|
bool IsAllowedToDispatchInSystemGroup() const;
|
2017-08-31 03:14:14 +00:00
|
|
|
/**
|
|
|
|
* Whether the event should be blocked for fingerprinting resistance.
|
|
|
|
*/
|
|
|
|
bool IsBlockedForFingerprintingResistance() const;
|
2023-08-07 05:24:20 +00:00
|
|
|
/**
|
|
|
|
* Whether the event handler can flush pending notifications or not.
|
|
|
|
*/
|
|
|
|
bool AllowFlushingPendingNotifications() const;
|
2016-08-31 03:16:11 +00:00
|
|
|
/**
|
|
|
|
* Initialize mComposed
|
|
|
|
*/
|
|
|
|
void SetDefaultComposed() {
|
|
|
|
switch (mClass) {
|
2021-01-29 13:30:40 +00:00
|
|
|
case eClipboardEventClass:
|
|
|
|
mFlags.mComposed = true;
|
|
|
|
break;
|
2016-08-31 03:16:11 +00:00
|
|
|
case eCompositionEventClass:
|
2019-06-03 09:18:47 +00:00
|
|
|
mFlags.mComposed =
|
|
|
|
mMessage == eCompositionStart || mMessage == eCompositionUpdate ||
|
|
|
|
mMessage == eCompositionChange || mMessage == eCompositionEnd;
|
2016-08-31 03:16:11 +00:00
|
|
|
break;
|
|
|
|
case eDragEventClass:
|
|
|
|
// All drag & drop events are composed
|
|
|
|
mFlags.mComposed = mMessage == eDrag || mMessage == eDragEnd ||
|
|
|
|
mMessage == eDragEnter || mMessage == eDragExit ||
|
|
|
|
mMessage == eDragLeave || mMessage == eDragOver ||
|
|
|
|
mMessage == eDragStart || mMessage == eDrop;
|
|
|
|
break;
|
|
|
|
case eEditorInputEventClass:
|
2020-01-14 07:15:45 +00:00
|
|
|
mFlags.mComposed =
|
|
|
|
mMessage == eEditorInput || mMessage == eEditorBeforeInput;
|
2016-08-31 03:16:11 +00:00
|
|
|
break;
|
|
|
|
case eFocusEventClass:
|
2018-07-09 14:40:01 +00:00
|
|
|
mFlags.mComposed = mMessage == eBlur || mMessage == eFocus ||
|
|
|
|
mMessage == eFocusOut || mMessage == eFocusIn;
|
2016-08-31 03:16:11 +00:00
|
|
|
break;
|
|
|
|
case eKeyboardEventClass:
|
|
|
|
mFlags.mComposed =
|
|
|
|
mMessage == eKeyDown || mMessage == eKeyUp || mMessage == eKeyPress;
|
|
|
|
break;
|
|
|
|
case eMouseEventClass:
|
2019-05-16 20:56:45 +00:00
|
|
|
mFlags.mComposed =
|
|
|
|
mMessage == eMouseClick || mMessage == eMouseDoubleClick ||
|
|
|
|
mMessage == eMouseAuxClick || mMessage == eMouseDown ||
|
|
|
|
mMessage == eMouseUp || mMessage == eMouseOver ||
|
|
|
|
mMessage == eMouseOut || mMessage == eMouseMove ||
|
|
|
|
mMessage == eContextMenu || mMessage == eXULPopupShowing ||
|
|
|
|
mMessage == eXULPopupHiding || mMessage == eXULPopupShown ||
|
2020-10-06 16:28:41 +00:00
|
|
|
mMessage == eXULPopupHidden;
|
2016-08-31 03:16:11 +00:00
|
|
|
break;
|
|
|
|
case ePointerEventClass:
|
|
|
|
// All pointer events are composed
|
|
|
|
mFlags.mComposed =
|
|
|
|
mMessage == ePointerDown || mMessage == ePointerMove ||
|
|
|
|
mMessage == ePointerUp || mMessage == ePointerCancel ||
|
|
|
|
mMessage == ePointerOver || mMessage == ePointerOut ||
|
|
|
|
mMessage == ePointerGotCapture || mMessage == ePointerLostCapture;
|
|
|
|
break;
|
|
|
|
case eTouchEventClass:
|
|
|
|
// All touch events are composed
|
|
|
|
mFlags.mComposed = mMessage == eTouchStart || mMessage == eTouchEnd ||
|
|
|
|
mMessage == eTouchMove || mMessage == eTouchCancel;
|
|
|
|
break;
|
|
|
|
case eUIEventClass:
|
|
|
|
mFlags.mComposed = mMessage == eLegacyDOMFocusIn ||
|
|
|
|
mMessage == eLegacyDOMFocusOut ||
|
|
|
|
mMessage == eLegacyDOMActivate;
|
|
|
|
break;
|
|
|
|
case eWheelEventClass:
|
|
|
|
// All wheel events are composed
|
|
|
|
mFlags.mComposed = mMessage == eWheel;
|
|
|
|
break;
|
2019-12-08 21:43:11 +00:00
|
|
|
case eMouseScrollEventClass:
|
|
|
|
// Legacy mouse scroll events are composed too, for consistency with
|
|
|
|
// wheel.
|
|
|
|
mFlags.mComposed = mMessage == eLegacyMouseLineOrPageScroll ||
|
|
|
|
mMessage == eLegacyMousePixelScroll;
|
|
|
|
break;
|
2016-08-31 03:16:11 +00:00
|
|
|
default:
|
|
|
|
mFlags.mComposed = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetComposed(const nsAString& aEventTypeArg) {
|
|
|
|
mFlags.mComposed = // composition events
|
|
|
|
aEventTypeArg.EqualsLiteral("compositionstart") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("compositionupdate") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("compositionend") ||
|
2019-06-03 09:18:47 +00:00
|
|
|
aEventTypeArg.EqualsLiteral("text") ||
|
2016-08-31 03:16:11 +00:00
|
|
|
// drag and drop events
|
|
|
|
aEventTypeArg.EqualsLiteral("dragstart") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("drag") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("dragenter") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("dragexit") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("dragleave") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("dragover") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("drop") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("dropend") ||
|
|
|
|
// editor input events
|
|
|
|
aEventTypeArg.EqualsLiteral("input") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("beforeinput") ||
|
|
|
|
// focus events
|
|
|
|
aEventTypeArg.EqualsLiteral("blur") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("focus") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("focusin") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("focusout") ||
|
|
|
|
// keyboard events
|
|
|
|
aEventTypeArg.EqualsLiteral("keydown") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("keyup") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("keypress") ||
|
|
|
|
// mouse events
|
|
|
|
aEventTypeArg.EqualsLiteral("click") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("dblclick") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("mousedown") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("mouseup") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("mouseenter") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("mouseleave") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("mouseover") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("mouseout") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("mousemove") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("contextmenu") ||
|
|
|
|
// pointer events
|
|
|
|
aEventTypeArg.EqualsLiteral("pointerdown") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("pointermove") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("pointerup") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("pointercancel") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("pointerover") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("pointerout") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("pointerenter") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("pointerleave") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("gotpointercapture") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("lostpointercapture") ||
|
|
|
|
// touch events
|
|
|
|
aEventTypeArg.EqualsLiteral("touchstart") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("touchend") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("touchmove") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("touchcancel") ||
|
|
|
|
// UI legacy events
|
|
|
|
aEventTypeArg.EqualsLiteral("DOMFocusIn") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("DOMFocusOut") ||
|
|
|
|
aEventTypeArg.EqualsLiteral("DOMActivate") ||
|
|
|
|
// wheel events
|
|
|
|
aEventTypeArg.EqualsLiteral("wheel");
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-08-31 03:16:11 +00:00
|
|
|
void SetComposed(bool aComposed) { mFlags.mComposed = aComposed; }
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-09-12 10:15:16 +00:00
|
|
|
void SetDefaultComposedInNativeAnonymousContent() {
|
|
|
|
// For compatibility concerns, we set mComposedInNativeAnonymousContent to
|
|
|
|
// false for those events we want to stop propagation.
|
|
|
|
//
|
|
|
|
// nsVideoFrame may create anonymous image element which fires eLoad,
|
|
|
|
// eLoadStart, eLoadEnd, eLoadError. We don't want these events cross
|
|
|
|
// the boundary of NAC
|
|
|
|
mFlags.mComposedInNativeAnonymousContent =
|
|
|
|
mMessage != eLoad && mMessage != eLoadStart && mMessage != eLoadEnd &&
|
|
|
|
mMessage != eLoadError;
|
|
|
|
}
|
2017-11-21 22:25:09 +00:00
|
|
|
|
|
|
|
bool IsUserAction() const;
|
2013-09-24 10:04:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::WidgetGUIEvent
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
class WidgetGUIEvent : public WidgetEvent {
|
|
|
|
protected:
|
2015-08-26 12:56:59 +00:00
|
|
|
WidgetGUIEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget,
|
2023-08-09 10:29:39 +00:00
|
|
|
EventClassID aEventClassID,
|
|
|
|
const WidgetEventTime* aTime = nullptr)
|
|
|
|
: WidgetEvent(aIsTrusted, aMessage, aEventClassID, aTime),
|
|
|
|
mWidget(aWidget) {}
|
2013-09-24 10:04:14 +00:00
|
|
|
|
2020-03-16 10:56:57 +00:00
|
|
|
WidgetGUIEvent() = default;
|
2013-09-24 10:04:14 +00:00
|
|
|
|
|
|
|
public:
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual WidgetGUIEvent* AsGUIEvent() override { return this; }
|
2013-10-18 06:10:20 +00:00
|
|
|
|
2023-08-09 10:29:39 +00:00
|
|
|
WidgetGUIEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget,
|
|
|
|
const WidgetEventTime* aTime = nullptr)
|
|
|
|
: WidgetEvent(aIsTrusted, aMessage, eGUIEventClass, aTime),
|
|
|
|
mWidget(aWidget) {}
|
2013-09-24 10:04:14 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual WidgetEvent* Duplicate() const override {
|
2014-08-04 05:28:46 +00:00
|
|
|
MOZ_ASSERT(mClass == eGUIEventClass,
|
2014-01-27 06:10:44 +00:00
|
|
|
"Duplicate() must be overridden by sub class");
|
|
|
|
// Not copying widget, it is a weak reference.
|
2023-08-09 10:29:39 +00:00
|
|
|
WidgetGUIEvent* result = new WidgetGUIEvent(false, mMessage, nullptr, this);
|
2014-01-27 06:10:44 +00:00
|
|
|
result->AssignGUIEventData(*this, true);
|
|
|
|
result->mFlags = mFlags;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-04-14 08:03:14 +00:00
|
|
|
// Originator of the event
|
|
|
|
nsCOMPtr<nsIWidget> mWidget;
|
2013-09-24 10:04:14 +00:00
|
|
|
|
|
|
|
void AssignGUIEventData(const WidgetGUIEvent& aEvent, bool aCopyTargets) {
|
|
|
|
AssignEventData(aEvent, aCopyTargets);
|
|
|
|
// widget should be initialized with the constructor.
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::Modifier
|
|
|
|
*
|
|
|
|
* All modifier keys should be defined here. This is used for managing
|
|
|
|
* modifier states for DOM Level 3 or later.
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
enum Modifier {
|
2014-05-22 04:06:05 +00:00
|
|
|
MODIFIER_NONE = 0x0000,
|
2013-09-24 10:04:14 +00:00
|
|
|
MODIFIER_ALT = 0x0001,
|
|
|
|
MODIFIER_ALTGRAPH = 0x0002,
|
|
|
|
MODIFIER_CAPSLOCK = 0x0004,
|
|
|
|
MODIFIER_CONTROL = 0x0008,
|
|
|
|
MODIFIER_FN = 0x0010,
|
2015-02-19 06:50:19 +00:00
|
|
|
MODIFIER_FNLOCK = 0x0020,
|
|
|
|
MODIFIER_META = 0x0040,
|
|
|
|
MODIFIER_NUMLOCK = 0x0080,
|
|
|
|
MODIFIER_SCROLLLOCK = 0x0100,
|
|
|
|
MODIFIER_SHIFT = 0x0200,
|
|
|
|
MODIFIER_SYMBOL = 0x0400,
|
|
|
|
MODIFIER_SYMBOLLOCK = 0x0800,
|
2013-09-24 10:04:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Modifier key names.
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#define NS_DOM_KEYNAME_ALT "Alt"
|
|
|
|
#define NS_DOM_KEYNAME_ALTGRAPH "AltGraph"
|
|
|
|
#define NS_DOM_KEYNAME_CAPSLOCK "CapsLock"
|
|
|
|
#define NS_DOM_KEYNAME_CONTROL "Control"
|
|
|
|
#define NS_DOM_KEYNAME_FN "Fn"
|
2015-02-19 06:50:19 +00:00
|
|
|
#define NS_DOM_KEYNAME_FNLOCK "FnLock"
|
2013-09-24 10:04:14 +00:00
|
|
|
#define NS_DOM_KEYNAME_META "Meta"
|
|
|
|
#define NS_DOM_KEYNAME_NUMLOCK "NumLock"
|
|
|
|
#define NS_DOM_KEYNAME_SCROLLLOCK "ScrollLock"
|
|
|
|
#define NS_DOM_KEYNAME_SHIFT "Shift"
|
2015-02-19 06:50:19 +00:00
|
|
|
#define NS_DOM_KEYNAME_SYMBOL "Symbol"
|
2013-09-24 10:04:14 +00:00
|
|
|
#define NS_DOM_KEYNAME_SYMBOLLOCK "SymbolLock"
|
|
|
|
#define NS_DOM_KEYNAME_OS "OS"
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::Modifiers
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
typedef uint16_t Modifiers;
|
|
|
|
|
Bug 1297013 part.2 Implement some helper methods to log constants related to event handling r=smaug
This patch implements some helper methods to log constants related to event handling.
ToString(KeyNameIndex) and ToString(CodeNameIndex) converts the enum itmes to human readable string. They use WidgetKeyboardEvent's helper class which returns Unicode text. Therefore, this need to convert from UTF16 to UTF8. That's the reason why these methods don't return |const char*|.
GetDOMKeyCodeName(uint32_t) returns DOM keycode name if it's defined. Otherwise, returns hexadecimal value. For generating switch-case statement, VirtualKeyCodeList.h shouldn't include ",". Therefore, this patch removes "," from VirtualKeyCodeList.h and append it at defining NS_DEFINE_VK. Additionally, the last item of enum and array should not end with ",". Therefore, this adds dummy last item at each of them. Finally, some of the keyCode values are shared between 2 keys. Therefore, it needs to support NS_DISALLOW_SAME_KEYCODE for switch-case generator. See the comment in the file for more detail.
GetModifiersName(Modifiers) returns all modifier names included in the given value.
MozReview-Commit-ID: 9i2ftFOTpDn
--HG--
extra : rebase_source : 458a4d28624dc10dd4454f2e7708d746d1fcb045
2016-09-14 15:48:47 +00:00
|
|
|
class MOZ_STACK_CLASS GetModifiersName final : public nsAutoCString {
|
|
|
|
public:
|
|
|
|
explicit GetModifiersName(Modifiers aModifiers) {
|
|
|
|
if (aModifiers & MODIFIER_ALT) {
|
|
|
|
AssignLiteral(NS_DOM_KEYNAME_ALT);
|
|
|
|
}
|
|
|
|
if (aModifiers & MODIFIER_ALTGRAPH) {
|
|
|
|
MaybeAppendSeparator();
|
|
|
|
AppendLiteral(NS_DOM_KEYNAME_ALTGRAPH);
|
|
|
|
}
|
|
|
|
if (aModifiers & MODIFIER_CAPSLOCK) {
|
|
|
|
MaybeAppendSeparator();
|
|
|
|
AppendLiteral(NS_DOM_KEYNAME_CAPSLOCK);
|
|
|
|
}
|
|
|
|
if (aModifiers & MODIFIER_CONTROL) {
|
|
|
|
MaybeAppendSeparator();
|
|
|
|
AppendLiteral(NS_DOM_KEYNAME_CONTROL);
|
|
|
|
}
|
|
|
|
if (aModifiers & MODIFIER_FN) {
|
|
|
|
MaybeAppendSeparator();
|
|
|
|
AppendLiteral(NS_DOM_KEYNAME_FN);
|
|
|
|
}
|
|
|
|
if (aModifiers & MODIFIER_FNLOCK) {
|
|
|
|
MaybeAppendSeparator();
|
|
|
|
AppendLiteral(NS_DOM_KEYNAME_FNLOCK);
|
|
|
|
}
|
|
|
|
if (aModifiers & MODIFIER_META) {
|
|
|
|
MaybeAppendSeparator();
|
|
|
|
AppendLiteral(NS_DOM_KEYNAME_META);
|
|
|
|
}
|
|
|
|
if (aModifiers & MODIFIER_NUMLOCK) {
|
|
|
|
MaybeAppendSeparator();
|
|
|
|
AppendLiteral(NS_DOM_KEYNAME_NUMLOCK);
|
|
|
|
}
|
|
|
|
if (aModifiers & MODIFIER_SCROLLLOCK) {
|
|
|
|
MaybeAppendSeparator();
|
|
|
|
AppendLiteral(NS_DOM_KEYNAME_SCROLLLOCK);
|
|
|
|
}
|
|
|
|
if (aModifiers & MODIFIER_SHIFT) {
|
|
|
|
MaybeAppendSeparator();
|
|
|
|
AppendLiteral(NS_DOM_KEYNAME_SHIFT);
|
|
|
|
}
|
|
|
|
if (aModifiers & MODIFIER_SYMBOL) {
|
|
|
|
MaybeAppendSeparator();
|
|
|
|
AppendLiteral(NS_DOM_KEYNAME_SYMBOL);
|
|
|
|
}
|
|
|
|
if (aModifiers & MODIFIER_SYMBOLLOCK) {
|
|
|
|
MaybeAppendSeparator();
|
|
|
|
AppendLiteral(NS_DOM_KEYNAME_SYMBOLLOCK);
|
|
|
|
}
|
|
|
|
if (IsEmpty()) {
|
|
|
|
AssignLiteral("none");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void MaybeAppendSeparator() {
|
|
|
|
if (!IsEmpty()) {
|
|
|
|
AppendLiteral(" | ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-09-24 10:04:14 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::WidgetInputEvent
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
class WidgetInputEvent : public WidgetGUIEvent {
|
|
|
|
protected:
|
2015-08-26 12:56:59 +00:00
|
|
|
WidgetInputEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget,
|
2023-08-09 10:29:39 +00:00
|
|
|
EventClassID aEventClassID,
|
|
|
|
const WidgetEventTime* aTime = nullptr)
|
|
|
|
: WidgetGUIEvent(aIsTrusted, aMessage, aWidget, aEventClassID, aTime),
|
2016-03-31 08:03:00 +00:00
|
|
|
mModifiers(0) {}
|
2013-09-24 10:04:14 +00:00
|
|
|
|
|
|
|
WidgetInputEvent() : mModifiers(0) {}
|
|
|
|
|
|
|
|
public:
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual WidgetInputEvent* AsInputEvent() override { return this; }
|
2013-10-18 06:10:20 +00:00
|
|
|
|
2023-08-09 10:29:39 +00:00
|
|
|
WidgetInputEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget,
|
|
|
|
const WidgetEventTime* aTime = nullptr)
|
|
|
|
: WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eInputEventClass, aTime),
|
2016-03-31 08:03:00 +00:00
|
|
|
mModifiers(0) {}
|
2013-09-24 10:04:14 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual WidgetEvent* Duplicate() const override {
|
2014-08-04 05:28:47 +00:00
|
|
|
MOZ_ASSERT(mClass == eInputEventClass,
|
2014-01-27 06:10:44 +00:00
|
|
|
"Duplicate() must be overridden by sub class");
|
|
|
|
// Not copying widget, it is a weak reference.
|
2023-08-09 10:29:39 +00:00
|
|
|
WidgetInputEvent* result =
|
|
|
|
new WidgetInputEvent(false, mMessage, nullptr, this);
|
2014-01-27 06:10:44 +00:00
|
|
|
result->AssignInputEventData(*this, true);
|
|
|
|
result->mFlags = mFlags;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-05-22 04:06:05 +00:00
|
|
|
/**
|
|
|
|
* Returns a modifier of "Accel" virtual modifier which is used for shortcut
|
|
|
|
* key.
|
|
|
|
*/
|
|
|
|
static Modifier AccelModifier();
|
|
|
|
|
2015-02-19 06:50:19 +00:00
|
|
|
/**
|
|
|
|
* GetModifier() returns a modifier flag which is activated by aDOMKeyName.
|
|
|
|
*/
|
|
|
|
static Modifier GetModifier(const nsAString& aDOMKeyName);
|
|
|
|
|
2014-05-22 04:06:05 +00:00
|
|
|
// true indicates the accel key on the environment is down
|
2016-03-31 08:03:00 +00:00
|
|
|
bool IsAccel() const { return ((mModifiers & AccelModifier()) != 0); }
|
2014-05-22 04:06:05 +00:00
|
|
|
|
2013-09-24 10:04:14 +00:00
|
|
|
// true indicates the shift key is down
|
2016-03-31 08:03:00 +00:00
|
|
|
bool IsShift() const { return ((mModifiers & MODIFIER_SHIFT) != 0); }
|
2013-09-24 10:04:14 +00:00
|
|
|
// true indicates the control key is down
|
2016-03-31 08:03:00 +00:00
|
|
|
bool IsControl() const { return ((mModifiers & MODIFIER_CONTROL) != 0); }
|
2013-09-24 10:04:14 +00:00
|
|
|
// true indicates the alt key is down
|
2016-03-31 08:03:00 +00:00
|
|
|
bool IsAlt() const { return ((mModifiers & MODIFIER_ALT) != 0); }
|
Bug 1266437 - Drop "OS" modifier r=smaug,m_kato,karlt,Gijs
On Windows, Windows logo key was mapped to "OS" modifier, and on Linux,
it's same and the key is called "Super" and "Hyper". That conformed to the
older UI Events spec.
However, UI Events declares that they should be mapped to "Meta" now and Chrome
handles it as the spec in Windows and Linux. Therefore, we should align the
behavior to them.
Note that we've treated the legacy "Meta" modifier on Linux as DOM "Meta"
modifier state, and we'll keep this as-is because in Sun/Solaris keyboard
layout, they keys are mapped to the legacy "Meta".
Finally, the following check only `IsMeta()` but not `IsOS()`. I think that
they should've checked `IsOS()` too. Therefore, they will behave differently
in Windows and Linux.
* https://searchfox.org/mozilla-central/rev/9a4666e63199bd1bcfc9095f6efec3488c358458/dom/base/Element.cpp#3287-3288
* https://searchfox.org/mozilla-central/rev/9a4666e63199bd1bcfc9095f6efec3488c358458/dom/html/HTMLInputElement.cpp#3762-3764
* https://searchfox.org/mozilla-central/rev/9a4666e63199bd1bcfc9095f6efec3488c358458/dom/html/HTMLInputElement.cpp#3796-3806
* https://searchfox.org/mozilla-central/rev/9a4666e63199bd1bcfc9095f6efec3488c358458/dom/html/HTMLLabelElement.cpp#127-128
* https://searchfox.org/mozilla-central/rev/9a4666e63199bd1bcfc9095f6efec3488c358458/widget/gtk/nsGtkKeyUtils.cpp#1461-1462
Note that `KEY_NAME_INDEX_OS` will be removed in the patch for bug 1232918.
Differential Revision: https://phabricator.services.mozilla.com/D183480
2023-08-07 01:03:58 +00:00
|
|
|
// true indicates the meta key is down (Command key on macOS, Windows logo key
|
|
|
|
// on Windows, Super/Hyper key on Linux, Meta key on Android).
|
2016-03-31 08:03:00 +00:00
|
|
|
bool IsMeta() const { return ((mModifiers & MODIFIER_META) != 0); }
|
2013-09-24 10:04:14 +00:00
|
|
|
// true indicates the alt graph key is down
|
|
|
|
// NOTE: on Mac, the option key press causes both IsAlt() and IsAltGrpah()
|
|
|
|
// return true.
|
2016-03-31 08:03:00 +00:00
|
|
|
bool IsAltGraph() const { return ((mModifiers & MODIFIER_ALTGRAPH) != 0); }
|
2015-02-19 06:50:19 +00:00
|
|
|
// true indicates the CapLock LED is turn on.
|
2016-03-31 08:03:00 +00:00
|
|
|
bool IsCapsLocked() const { return ((mModifiers & MODIFIER_CAPSLOCK) != 0); }
|
2015-02-19 06:50:19 +00:00
|
|
|
// true indicates the NumLock LED is turn on.
|
2016-03-31 08:03:00 +00:00
|
|
|
bool IsNumLocked() const { return ((mModifiers & MODIFIER_NUMLOCK) != 0); }
|
2015-02-19 06:50:19 +00:00
|
|
|
// true indicates the ScrollLock LED is turn on.
|
2013-09-24 10:04:14 +00:00
|
|
|
bool IsScrollLocked() const {
|
2016-03-31 08:03:00 +00:00
|
|
|
return ((mModifiers & MODIFIER_SCROLLLOCK) != 0);
|
2013-09-24 10:04:14 +00:00
|
|
|
}
|
|
|
|
|
2015-02-19 06:50:19 +00:00
|
|
|
// true indicates the Fn key is down, but this is not supported by native
|
2013-09-24 10:04:14 +00:00
|
|
|
// key event on any platform.
|
2016-03-31 08:03:00 +00:00
|
|
|
bool IsFn() const { return ((mModifiers & MODIFIER_FN) != 0); }
|
2015-02-19 06:50:19 +00:00
|
|
|
// true indicates the FnLock LED is turn on, but we don't know such
|
|
|
|
// keyboards nor platforms.
|
2016-03-31 08:03:00 +00:00
|
|
|
bool IsFnLocked() const { return ((mModifiers & MODIFIER_FNLOCK) != 0); }
|
2015-02-19 06:50:19 +00:00
|
|
|
// true indicates the Symbol is down, but this is not supported by native
|
|
|
|
// key event on any platforms.
|
2016-03-31 08:03:00 +00:00
|
|
|
bool IsSymbol() const { return ((mModifiers & MODIFIER_SYMBOL) != 0); }
|
2015-02-19 06:50:19 +00:00
|
|
|
// true indicates the SymbolLock LED is turn on, but we don't know such
|
|
|
|
// keyboards nor platforms.
|
2013-09-24 10:04:14 +00:00
|
|
|
bool IsSymbolLocked() const {
|
2016-03-31 08:03:00 +00:00
|
|
|
return ((mModifiers & MODIFIER_SYMBOLLOCK) != 0);
|
2013-09-24 10:04:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InitBasicModifiers(bool aCtrlKey, bool aAltKey, bool aShiftKey,
|
|
|
|
bool aMetaKey) {
|
2016-03-31 08:03:00 +00:00
|
|
|
mModifiers = 0;
|
2013-09-24 10:04:14 +00:00
|
|
|
if (aCtrlKey) {
|
2016-03-31 08:03:00 +00:00
|
|
|
mModifiers |= MODIFIER_CONTROL;
|
2013-09-24 10:04:14 +00:00
|
|
|
}
|
|
|
|
if (aAltKey) {
|
2016-03-31 08:03:00 +00:00
|
|
|
mModifiers |= MODIFIER_ALT;
|
2013-09-24 10:04:14 +00:00
|
|
|
}
|
|
|
|
if (aShiftKey) {
|
2016-03-31 08:03:00 +00:00
|
|
|
mModifiers |= MODIFIER_SHIFT;
|
2013-09-24 10:04:14 +00:00
|
|
|
}
|
|
|
|
if (aMetaKey) {
|
2016-03-31 08:03:00 +00:00
|
|
|
mModifiers |= MODIFIER_META;
|
2013-09-24 10:04:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-31 08:03:00 +00:00
|
|
|
Modifiers mModifiers;
|
2013-09-24 10:04:14 +00:00
|
|
|
|
|
|
|
void AssignInputEventData(const WidgetInputEvent& aEvent, bool aCopyTargets) {
|
|
|
|
AssignGUIEventData(aEvent, aCopyTargets);
|
|
|
|
|
2016-03-31 08:03:00 +00:00
|
|
|
mModifiers = aEvent.mModifiers;
|
2013-09-24 10:04:14 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::InternalUIEvent
|
|
|
|
*
|
|
|
|
* XXX Why this inherits WidgetGUIEvent rather than WidgetEvent?
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
class InternalUIEvent : public WidgetGUIEvent {
|
2013-09-24 10:04:15 +00:00
|
|
|
protected:
|
2015-08-22 04:02:39 +00:00
|
|
|
InternalUIEvent() : mDetail(0), mCausedByUntrustedEvent(false) {}
|
2014-04-10 07:11:37 +00:00
|
|
|
|
2015-08-26 12:56:59 +00:00
|
|
|
InternalUIEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget,
|
2023-08-09 10:29:39 +00:00
|
|
|
EventClassID aEventClassID,
|
|
|
|
const WidgetEventTime* aTime = nullptr)
|
|
|
|
: WidgetGUIEvent(aIsTrusted, aMessage, aWidget, aEventClassID, aTime),
|
2016-03-26 07:22:27 +00:00
|
|
|
mDetail(0),
|
2015-08-22 04:02:39 +00:00
|
|
|
mCausedByUntrustedEvent(false) {}
|
2014-04-10 07:11:37 +00:00
|
|
|
|
2015-08-26 12:56:59 +00:00
|
|
|
InternalUIEvent(bool aIsTrusted, EventMessage aMessage,
|
2023-08-09 10:29:39 +00:00
|
|
|
EventClassID aEventClassID,
|
|
|
|
const WidgetEventTime* aTime = nullptr)
|
|
|
|
: WidgetGUIEvent(aIsTrusted, aMessage, nullptr, aEventClassID, aTime),
|
2016-03-26 07:22:27 +00:00
|
|
|
mDetail(0),
|
2015-08-22 04:02:39 +00:00
|
|
|
mCausedByUntrustedEvent(false) {}
|
2013-09-24 10:04:15 +00:00
|
|
|
|
2013-09-24 10:04:14 +00:00
|
|
|
public:
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual InternalUIEvent* AsUIEvent() override { return this; }
|
2013-10-18 06:10:20 +00:00
|
|
|
|
2015-08-22 04:02:39 +00:00
|
|
|
/**
|
|
|
|
* If the UIEvent is caused by another event (e.g., click event),
|
|
|
|
* aEventCausesThisEvent should be the event. If there is no such event,
|
|
|
|
* this should be nullptr.
|
|
|
|
*/
|
2015-08-26 12:56:59 +00:00
|
|
|
InternalUIEvent(bool aIsTrusted, EventMessage aMessage,
|
2023-08-09 10:29:39 +00:00
|
|
|
const WidgetEvent* aEventCausesThisEvent,
|
|
|
|
const WidgetEventTime* aTime = nullptr)
|
|
|
|
: WidgetGUIEvent(aIsTrusted, aMessage, nullptr, eUIEventClass, aTime),
|
2016-03-26 07:22:27 +00:00
|
|
|
mDetail(0),
|
2016-03-17 07:01:30 +00:00
|
|
|
mCausedByUntrustedEvent(aEventCausesThisEvent &&
|
|
|
|
!aEventCausesThisEvent->IsTrusted()) {}
|
2013-09-24 10:04:14 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual WidgetEvent* Duplicate() const override {
|
2014-08-04 05:28:47 +00:00
|
|
|
MOZ_ASSERT(mClass == eUIEventClass,
|
2014-01-27 06:10:44 +00:00
|
|
|
"Duplicate() must be overridden by sub class");
|
2023-08-09 10:29:39 +00:00
|
|
|
InternalUIEvent* result =
|
|
|
|
new InternalUIEvent(false, mMessage, nullptr, this);
|
2014-01-27 06:10:44 +00:00
|
|
|
result->AssignUIEventData(*this, true);
|
|
|
|
result->mFlags = mFlags;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-26 07:22:27 +00:00
|
|
|
int32_t mDetail;
|
2015-08-22 04:02:39 +00:00
|
|
|
// mCausedByUntrustedEvent is true if the event is caused by untrusted event.
|
|
|
|
bool mCausedByUntrustedEvent;
|
|
|
|
|
|
|
|
// If you check the event is a trusted event and NOT caused by an untrusted
|
|
|
|
// event, IsTrustable() returns what you expected.
|
2016-03-17 07:01:30 +00:00
|
|
|
bool IsTrustable() const { return IsTrusted() && !mCausedByUntrustedEvent; }
|
2013-09-24 10:04:14 +00:00
|
|
|
|
|
|
|
void AssignUIEventData(const InternalUIEvent& aEvent, bool aCopyTargets) {
|
|
|
|
AssignGUIEventData(aEvent, aCopyTargets);
|
|
|
|
|
2016-03-26 07:22:27 +00:00
|
|
|
mDetail = aEvent.mDetail;
|
2015-08-22 04:02:39 +00:00
|
|
|
mCausedByUntrustedEvent = aEvent.mCausedByUntrustedEvent;
|
2013-09-24 10:04:14 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_BasicEvents_h__
|