Bug 910532 part 2 - Prevent exiting fullscreen if escape is consumed by chrome. r=smaug

--HG--
extra : source : b18129bfc6a864ee580c54bd317a01d12ee62e33
This commit is contained in:
Xidorn Quan 2015-01-21 12:16:04 +11:00
parent ef4f779722
commit 9317e1bbe3
2 changed files with 30 additions and 4 deletions

View File

@ -801,6 +801,7 @@ PresShell::PresShell()
mPaintingIsFrozen = false;
mHasCSSBackgroundColor = true;
mIsLastChromeOnlyEscapeKeyConsumed = false;
}
NS_IMPL_ISUPPORTS(PresShell, nsIPresShell, nsIDocumentObserver,
@ -8005,7 +8006,10 @@ PresShell::HandleEventInternal(WidgetEvent* aEvent, nsEventStatus* aStatus)
aEvent->mFlags.mDefaultPrevented = true;
aEvent->mFlags.mOnlyChromeDispatch = true;
if (aEvent->message == NS_KEY_UP) {
// The event listeners in chrome can prevent this ESC behavior by
// calling prevent default on the preceding keydown/press events.
if (!mIsLastChromeOnlyEscapeKeyConsumed &&
aEvent->message == NS_KEY_UP) {
// ESC key released while in DOM fullscreen mode.
// If fullscreen is running in content-only mode, exit the target
// doctree branch from fullscreen, otherwise fully exit all
@ -8021,7 +8025,7 @@ PresShell::HandleEventInternal(WidgetEvent* aEvent, nsEventStatus* aStatus)
}
nsCOMPtr<nsIDocument> pointerLockedDoc =
do_QueryReferent(EventStateManager::sPointerLockedDoc);
if (pointerLockedDoc) {
if (!mIsLastChromeOnlyEscapeKeyConsumed && pointerLockedDoc) {
aEvent->mFlags.mDefaultPrevented = true;
aEvent->mFlags.mOnlyChromeDispatch = true;
if (aEvent->message == NS_KEY_UP) {
@ -8256,11 +8260,30 @@ PresShell::HandleEventInternal(WidgetEvent* aEvent, nsEventStatus* aStatus)
}
}
if (aEvent->message == NS_MOUSE_BUTTON_UP) {
switch (aEvent->message) {
case NS_KEY_PRESS:
case NS_KEY_DOWN:
case NS_KEY_UP: {
if (aEvent->AsKeyboardEvent()->keyCode == NS_VK_ESCAPE) {
if (aEvent->message == NS_KEY_UP) {
// Reset this flag after key up is handled.
mIsLastChromeOnlyEscapeKeyConsumed = false;
} else {
if (aEvent->mFlags.mOnlyChromeDispatch &&
aEvent->mFlags.mDefaultPreventedByChrome) {
mIsLastChromeOnlyEscapeKeyConsumed = true;
}
}
}
break;
}
case NS_MOUSE_BUTTON_UP:
// reset the capturing content now that the mouse button is up
SetCapturingContent(nullptr, 0);
} else if (aEvent->message == NS_MOUSE_MOVE) {
break;
case NS_MOUSE_MOVE:
nsIPresShell::AllowMouseCapture(false);
break;
}
}
return rv;

View File

@ -868,6 +868,9 @@ protected:
// applied to rendered layers.
bool mScaleToResolution : 1;
// Whether the last chrome-only escape key event is consumed.
bool mIsLastChromeOnlyEscapeKeyConsumed : 1;
static bool sDisableNonTestMouseEvents;
};