diff --git a/layout/base/PresShell.cpp b/layout/base/PresShell.cpp index 2fd0c87f026a..7aff3527c3fa 100644 --- a/layout/base/PresShell.cpp +++ b/layout/base/PresShell.cpp @@ -7114,32 +7114,46 @@ bool PresShell::EventHandler::MaybeHandleEventWithAccessibleCaret( MOZ_ASSERT(aGUIEvent); MOZ_ASSERT(aEventStatus); - if (AccessibleCaretEnabled(GetDocument()->GetDocShell())) { - // We have to target the focus window because regardless of where the - // touch goes, we want to access the copy paste manager. - nsCOMPtr window = GetFocusedDOMWindowInOurWindow(); - RefPtr retargetEventDoc = - window ? window->GetExtantDoc() : nullptr; - nsCOMPtr presShell = - retargetEventDoc ? retargetEventDoc->GetShell() : nullptr; - - RefPtr eventHub = - presShell ? presShell->GetAccessibleCaretEventHub() : nullptr; - if (eventHub && *aEventStatus != nsEventStatus_eConsumeNoDefault) { - // Don't dispatch event to AccessibleCaretEventHub when the event status - // is nsEventStatus_eConsumeNoDefault. This might be happened when content - // preventDefault on the pointer events. In such case, we also call - // preventDefault on mouse events to stop default behaviors. - *aEventStatus = eventHub->HandleEvent(aGUIEvent); - if (*aEventStatus == nsEventStatus_eConsumeNoDefault) { - // If the event is consumed, cancel APZC panning by setting - // mMultipleActionsPrevented. - aGUIEvent->mFlags.mMultipleActionsPrevented = true; - return true; - } - } + // Don't dispatch event to AccessibleCaretEventHub when the event status + // is nsEventStatus_eConsumeNoDefault. This might be happened when content + // preventDefault on the pointer events. In such case, we also call + // preventDefault on mouse events to stop default behaviors. + if (*aEventStatus == nsEventStatus_eConsumeNoDefault) { + return false; } - return false; + + if (!AccessibleCaretEnabled(GetDocument()->GetDocShell())) { + return false; + } + + // We have to target the focus window because regardless of where the + // touch goes, we want to access the copy paste manager. + nsCOMPtr window = GetFocusedDOMWindowInOurWindow(); + if (!window) { + return false; + } + RefPtr retargetEventDoc = window->GetExtantDoc(); + if (!retargetEventDoc) { + return false; + } + nsCOMPtr presShell = retargetEventDoc->GetShell(); + if (!presShell) { + return false; + } + + RefPtr eventHub = + presShell->GetAccessibleCaretEventHub(); + if (!eventHub) { + return false; + } + *aEventStatus = eventHub->HandleEvent(aGUIEvent); + if (*aEventStatus != nsEventStatus_eConsumeNoDefault) { + return false; + } + // If the event is consumed, cancel APZC panning by setting + // mMultipleActionsPrevented. + aGUIEvent->mFlags.mMultipleActionsPrevented = true; + return true; } Document* PresShell::GetPrimaryContentDocument() {