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 61d3478f4a
commit 6f4b15e60d
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 // The event listeners in chrome can prevent this ESC behavior by
// calling prevent default on the preceding keydown/press events. // calling prevent default on the preceding keydown/press events.
if (!mPresShell->mIsLastChromeOnlyEscapeKeyConsumed && if (aKeyboardEvent->mMessage == eKeyUp) {
aKeyboardEvent->mMessage == eKeyUp) { bool shouldExitFullscreen =
// ESC key released while in DOM fullscreen mode. !mPresShell->mIsLastChromeOnlyEscapeKeyConsumed;
// Fully exit all browser windows and documents from if (!shouldExitFullscreen) {
// fullscreen mode. if (mPresShell->mLastConsumedEscapeKeyUpForFullscreen &&
Document::AsyncExitFullscreen(nullptr); (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);
}
} }
} }

View file

@ -3221,6 +3221,10 @@ class PresShell final : public nsStubDocumentObserver,
bool mProcessingReflowCommands : 1; bool mProcessingReflowCommands : 1;
bool mPendingDidDoReflow : 1; bool mPendingDidDoReflow : 1;
// The last TimeStamp when the keyup event did not exit fullscreen because it
// was consumed.
TimeStamp mLastConsumedEscapeKeyUpForFullscreen;
struct CapturingContentInfo final { struct CapturingContentInfo final {
CapturingContentInfo() CapturingContentInfo()
: mRemoteTarget(nullptr), : mRemoteTarget(nullptr),

View file

@ -2703,6 +2703,13 @@
value: false value: false
mirror: always mirror: always
# The interval in milliseconds between two Escape key events where the second
# key event will exit fullscreen, even if it is consumed.
- name: dom.fullscreen.force_exit_on_multiple_escape_interval
type: uint32_t
value: 500
mirror: always
# Whether the Gamepad API is enabled # Whether the Gamepad API is enabled
- name: dom.gamepad.enabled - name: dom.gamepad.enabled
type: bool type: bool