Verified Commit fc69dc79 authored by Edgar Chen's avatar Edgar Chen Committed by ma1
Browse files

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

parent d25fbed6
Loading
Loading
Loading
Loading
+24 −6
Original line number Diff line number Diff line
@@ -8463,14 +8463,32 @@ 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) {
    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);
      }
    }
  }

  if (XRE_IsParentProcess() &&
      !mPresShell->mIsLastChromeOnlyEscapeKeyConsumed) {
+4 −0
Original line number Diff line number Diff line
@@ -3209,6 +3209,10 @@ class PresShell final : public nsStubDocumentObserver,
  bool mProcessingReflowCommands : 1;
  bool mPendingDidDoReflow : 1;

  // The last TimeStamp when the keyup event did not exit fullscreen because it
  // was consumed.
  TimeStamp mLastConsumedEscapeKeyUpForFullscreen;

  struct CapturingContentInfo final {
    CapturingContentInfo()
        : mRemoteTarget(nullptr),
+7 −0
Original line number Diff line number Diff line
@@ -2701,6 +2701,13 @@
  value: false
  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 fullscreen should make the rest of the document inert.
# This matches other browsers but historically not Gecko.
- name: dom.fullscreen.modal