Bug 1466208 - part 11: Create PresShell::EventHandler::MaybeDiscardOrDelayKeyboardEvent() r=smaug

PresShell::EventHandler::HandleEvent() discards or puts off to dispatch
the handling event if it's a keyboard event and event dispatching is
suppressed by the document.

This patch moves the block into the new method for making HandleEvent() simpler.

Differential Revision: https://phabricator.services.mozilla.com/D18520

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Masayuki Nakano 2019-02-07 01:49:31 +00:00
Родитель f619616521
Коммит 3ebe8914da
2 изменённых файлов: 37 добавлений и 9 удалений

Просмотреть файл

@ -6517,15 +6517,8 @@ nsresult PresShell::EventHandler::HandleEvent(nsIFrame* aFrame,
}
}
if (aGUIEvent->mClass == eKeyboardEventClass && GetDocument() &&
GetDocument()->EventHandlingSuppressed()) {
if (aGUIEvent->mMessage == eKeyDown) {
mPresShell->mNoDelayedKeyEvents = true;
} else if (!mPresShell->mNoDelayedKeyEvents) {
auto event = MakeUnique<DelayedKeyEvent>(aGUIEvent->AsKeyboardEvent());
PushDelayedEventIntoQueue(std::move(event));
}
aGUIEvent->mFlags.mIsSuppressedOrDelayed = true;
if (MaybeDiscardOrDelayKeyboardEvent(aGUIEvent)) {
// The event is discarded or put into the delayed event queue.
return NS_OK;
}
@ -7273,6 +7266,30 @@ bool PresShell::EventHandler::MaybeHandleEventWithAnotherPresShell(
return true;
}
bool PresShell::EventHandler::MaybeDiscardOrDelayKeyboardEvent(
WidgetGUIEvent* aGUIEvent) {
MOZ_ASSERT(aGUIEvent);
if (aGUIEvent->mClass != eKeyboardEventClass) {
return false;
}
Document* document = GetDocument();
if (!document || !document->EventHandlingSuppressed()) {
return false;
}
if (aGUIEvent->mMessage == eKeyDown) {
mPresShell->mNoDelayedKeyEvents = true;
} else if (!mPresShell->mNoDelayedKeyEvents) {
UniquePtr<DelayedKeyEvent> delayedKeyEvent =
MakeUnique<DelayedKeyEvent>(aGUIEvent->AsKeyboardEvent());
PushDelayedEventIntoQueue(std::move(delayedKeyEvent));
}
aGUIEvent->mFlags.mIsSuppressedOrDelayed = true;
return true;
}
Document* PresShell::GetPrimaryContentDocument() {
nsPresContext* context = GetPresContext();
if (!context || !context->IsRoot()) {

Просмотреть файл

@ -672,6 +672,17 @@ class PresShell final : public nsIPresShell,
bool MaybeHandleEventWithAccessibleCaret(WidgetGUIEvent* aGUIEvent,
nsEventStatus* aEventStatus);
/**
* MaybeDiscardOrDelayKeyboardEvent() may discared or put aGUIEvent into
* the delayed event queue if it's a keyboard event and if we should do so.
* If aGUIEvent is not a keyboard event, this does nothing.
*
* @param aGUIEvent The handling event.
* @return true if this method discard the event or
* put it into the delayed event queue.
*/
bool MaybeDiscardOrDelayKeyboardEvent(WidgetGUIEvent* aGUIEvent);
/**
* XXX Needs better name.
* HandleEventInternal() dispatches aEvent into the DOM tree and