Bug 1883396 - Exit fullscreen when two Escape keyup events occur in a short time; r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D209667
This commit is contained in:
Edgar Chen
2024-06-04 23:38:45 +00:00
parent e6dff4fa84
commit 0b7dde807f
3 changed files with 35 additions and 6 deletions

View File

@@ -8669,12 +8669,30 @@ void PresShell::EventHandler::MaybeHandleKeyboardEventBeforeDispatch(
// The event listeners in chrome can prevent this ESC behavior by
// calling prevent default on the preceding keydown/press events.
if (!mPresShell->mIsLastChromeOnlyEscapeKeyConsumed &&
aKeyboardEvent->mMessage == eKeyUp) {
// ESC key released while in DOM fullscreen mode.
// Fully exit all browser windows and documents from
// fullscreen mode.
Document::AsyncExitFullscreen(nullptr);
if (aKeyboardEvent->mMessage == eKeyUp) {
bool shouldExitFullscreen =
!mPresShell->mIsLastChromeOnlyEscapeKeyConsumed;
if (!shouldExitFullscreen) {
if (mPresShell->mLastConsumedEscapeKeyUpForFullscreen &&
(aKeyboardEvent->mTimeStamp -
mPresShell->mLastConsumedEscapeKeyUpForFullscreen) <=
TimeDuration::FromMilliseconds(
StaticPrefs::
dom_fullscreen_force_exit_on_multiple_escape_interval())) {
shouldExitFullscreen = true;
mPresShell->mLastConsumedEscapeKeyUpForFullscreen = TimeStamp();
} else {
mPresShell->mLastConsumedEscapeKeyUpForFullscreen =
aKeyboardEvent->mTimeStamp;
}
}
if (shouldExitFullscreen) {
// ESC key released while in DOM fullscreen mode.
// Fully exit all browser windows and documents from
// fullscreen mode.
Document::AsyncExitFullscreen(nullptr);
}
}
}