Bug 1369072 - part2: PresShell::HandleEvent() should retarget KeyboardEvent if focused document is invisible r?smaug
When focused document is invisible, PresShell::HandleEvent() won't dispatch
any events. However, if it's KeyboardEvent, user cannot do anything only with
keyboard. So, in this case, PresShell should retarget keyboard events to
first visible ancestor.
MozReview-Commit-ID: CvCBcYwvfbe
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -7316,18 +7316,31 @@ PresShell::HandleEvent(nsIFrame* aFrame,
(aEvent->mClass == eMouseEventClass) ||
(aEvent->mClass == eWheelEventClass)) {
retargetEventDoc = GetPrimaryContentDocument();
#endif
}
if (retargetEventDoc) {
nsCOMPtr<nsIPresShell> presShell = retargetEventDoc->GetShell();
- if (!presShell)
- return NS_OK;
+ // Even if the document doesn't have PresShell, i.e., it's invisible, we
+ // need to dispatch only KeyboardEvent in its nearest visible document
+ // because key focus shouldn't be caught by invisible document.
+ if (!presShell) {
+ if (!aEvent->HasKeyEventMessage()) {
+ return NS_OK;
+ }
+ while (!presShell) {
+ retargetEventDoc = retargetEventDoc->GetParentDocument();
+ if (!retargetEventDoc) {
+ return NS_OK;
+ }
+ presShell = retargetEventDoc->GetShell();
+ }
+ }
if (presShell != this) {
nsIFrame* frame = presShell->GetRootFrame();
if (!frame) {
if (aEvent->mMessage == eQueryTextContent ||
aEvent->IsContentCommandEvent()) {
return NS_OK;
}