зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1536353 - part 2: Merge PresShell::EventHandler::PrepareToDispatchEvent() and PresShell::EventHandler::PrepareToDispatchContextMenuEvent() r=smaug
`PresShell::EventHandler::PrepareToDispatchEvent()` checked whether the given event is a trusted event or an untrusted event, but `PresShell::EventHandler::PrepareToDispatchOntextMenuEvent()` didn't so. However, now, both of them don't need to check it. Therefore, we can merge them. Differential Revision: https://phabricator.services.mozilla.com/D24132 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
f371fabc1b
Коммит
dbf37b7d62
|
@ -7666,12 +7666,8 @@ nsresult PresShell::EventHandler::HandleEventWithCurrentEventInfo(
|
|||
}
|
||||
}
|
||||
|
||||
bool isHandlingUserInput = PrepareToDispatchEvent(aEvent);
|
||||
|
||||
// If we cannot open context menu even though eContextMenu is fired, we
|
||||
// should stop dispatching it into the DOM.
|
||||
if (aEvent->mMessage == eContextMenu &&
|
||||
!PrepareToDispatchContextMenuEvent(aEvent)) {
|
||||
bool isHandlingUserInput = false;
|
||||
if (!PrepareToDispatchEvent(aEvent, &isHandlingUserInput)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -7797,8 +7793,10 @@ nsresult PresShell::EventHandler::DispatchEvent(
|
|||
aOverrideClickTarget);
|
||||
}
|
||||
|
||||
bool PresShell::EventHandler::PrepareToDispatchEvent(WidgetEvent* aEvent) {
|
||||
bool PresShell::EventHandler::PrepareToDispatchEvent(WidgetEvent* aEvent,
|
||||
bool* aIsUserInteraction) {
|
||||
MOZ_ASSERT(aEvent->IsTrusted());
|
||||
MOZ_ASSERT(aIsUserInteraction);
|
||||
|
||||
if (aEvent->IsUserAction()) {
|
||||
mPresShell->mHasHandledUserInput = true;
|
||||
|
@ -7813,12 +7811,14 @@ bool PresShell::EventHandler::PrepareToDispatchEvent(WidgetEvent* aEvent) {
|
|||
// Not all keyboard events are treated as user input, so that popups
|
||||
// can't be opened, fullscreen mode can't be started, etc at unexpected
|
||||
// time.
|
||||
return keyboardEvent->CanTreatAsUserInput();
|
||||
*aIsUserInteraction = keyboardEvent->CanTreatAsUserInput();
|
||||
return true;
|
||||
}
|
||||
case eMouseDown:
|
||||
case eMouseUp:
|
||||
case ePointerDown:
|
||||
case ePointerUp:
|
||||
*aIsUserInteraction = true;
|
||||
return true;
|
||||
|
||||
case eMouseMove: {
|
||||
|
@ -7827,7 +7827,8 @@ bool PresShell::EventHandler::PrepareToDispatchEvent(WidgetEvent* aEvent) {
|
|||
GetPresContext()->EventStateManager() ==
|
||||
EventStateManager::GetActiveEventStateManager();
|
||||
nsIPresShell::AllowMouseCapture(allowCapture);
|
||||
return false;
|
||||
*aIsUserInteraction = false;
|
||||
return true;
|
||||
}
|
||||
case eDrop: {
|
||||
nsCOMPtr<nsIDragSession> session = nsContentUtils::GetDragSession();
|
||||
|
@ -7838,11 +7839,33 @@ bool PresShell::EventHandler::PrepareToDispatchEvent(WidgetEvent* aEvent) {
|
|||
aEvent->mFlags.mOnlyChromeDispatch = true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
*aIsUserInteraction = false;
|
||||
return true;
|
||||
}
|
||||
case eContextMenu: {
|
||||
*aIsUserInteraction = false;
|
||||
|
||||
// If we cannot open context menu even though eContextMenu is fired, we
|
||||
// should stop dispatching it into the DOM.
|
||||
WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent();
|
||||
if (mouseEvent->IsContextMenuKeyEvent() &&
|
||||
!AdjustContextMenuKeyEvent(mouseEvent)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If "Shift" state is active, context menu should be forcibly opened even
|
||||
// if web apps want to prevent it since we respect our users' intention.
|
||||
// In this case, we don't fire "contextmenu" event on web content because
|
||||
// of not cancelable.
|
||||
if (mouseEvent->IsShift()) {
|
||||
aEvent->mFlags.mOnlyChromeDispatch = true;
|
||||
aEvent->mFlags.mRetargetToNonNativeAnonymous = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
*aIsUserInteraction = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7895,29 +7918,6 @@ void PresShell::EventHandler::FinalizeHandlingEvent(WidgetEvent* aEvent) {
|
|||
}
|
||||
}
|
||||
|
||||
bool PresShell::EventHandler::PrepareToDispatchContextMenuEvent(
|
||||
WidgetEvent* aEvent) {
|
||||
MOZ_ASSERT(aEvent);
|
||||
MOZ_ASSERT(aEvent->mMessage == eContextMenu);
|
||||
MOZ_ASSERT(aEvent->IsTrusted());
|
||||
|
||||
WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent();
|
||||
if (mouseEvent->IsContextMenuKeyEvent() &&
|
||||
!AdjustContextMenuKeyEvent(mouseEvent)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If "Shift" state is active, context menu should be forcibly opened even
|
||||
// if web apps want to prevent it since we respect our users' intention.
|
||||
// In this case, we don't fire "contextmenu" event on web content because
|
||||
// of not cancelable.
|
||||
if (mouseEvent->IsShift()) {
|
||||
aEvent->mFlags.mOnlyChromeDispatch = true;
|
||||
aEvent->mFlags.mRetargetToNonNativeAnonymous = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void PresShell::EventHandler::MaybeHandleKeyboardEventBeforeDispatch(
|
||||
WidgetKeyboardEvent* aKeyboardEvent) {
|
||||
MOZ_ASSERT(aKeyboardEvent);
|
||||
|
|
|
@ -1104,13 +1104,16 @@ class PresShell final : public nsIPresShell,
|
|||
/**
|
||||
* PrepareToDispatchEvent() prepares to dispatch aEvent.
|
||||
*
|
||||
* @param aEvent The handling event.
|
||||
* @return true if the event is user interaction. I.e.,
|
||||
* enough obvious input to allow to open popup,
|
||||
* etc. false, otherwise.
|
||||
* @param aEvent The handling event.
|
||||
* @param aIsUserInteraction [out] Set to true if the event is user
|
||||
* interaction. I.e., enough obvious input
|
||||
* to allow to open popup, etc. Otherwise,
|
||||
* set to false.
|
||||
* @return true if the caller can dispatch the
|
||||
* event into the DOM.
|
||||
*/
|
||||
MOZ_CAN_RUN_SCRIPT
|
||||
bool PrepareToDispatchEvent(WidgetEvent* aEvent);
|
||||
bool PrepareToDispatchEvent(WidgetEvent* aEvent, bool* aIsUserInteraction);
|
||||
|
||||
/**
|
||||
* MaybeHandleKeyboardEventBeforeDispatch() may handle aKeyboardEvent
|
||||
|
@ -1122,16 +1125,6 @@ class PresShell final : public nsIPresShell,
|
|||
void MaybeHandleKeyboardEventBeforeDispatch(
|
||||
WidgetKeyboardEvent* aKeyboardEvent);
|
||||
|
||||
/**
|
||||
* PrepareToDispatchContextMenuEvent() prepares to dispatch aEvent into
|
||||
* the DOM.
|
||||
*
|
||||
* @param aEvent Must be eContextMenu event.
|
||||
* @return true if it can be dispatched into the DOM.
|
||||
* Otherwise, false.
|
||||
*/
|
||||
bool PrepareToDispatchContextMenuEvent(WidgetEvent* aEvent);
|
||||
|
||||
/**
|
||||
* This and the next two helper methods are used to target and position the
|
||||
* context menu when the keyboard shortcut is used to open it.
|
||||
|
|
Загрузка…
Ссылка в новой задаче