Bug 694204 - Prevent default action on ESC key press to exit full-screen mode, prevents <video> loads being cancelled on full-screen exit. r=smaug

This commit is contained in:
Chris Pearce 2011-11-01 18:11:29 +13:00
parent 427807cc7c
commit 9c5634653e
2 changed files with 21 additions and 4 deletions

View File

@ -43,7 +43,7 @@ var keyList = [
{ code: "VK_FINAL", allowed: false},
{ code: "VK_HANJA", allowed: false},
{ code: "VK_KANJI", allowed: false},
{ code: "VK_ESCAPE", allowed: false},
{ code: "VK_ESCAPE", allowed: false, suppressed: true},
{ code: "VK_CONVERT", allowed: false},
{ code: "VK_NONCONVERT", allowed: false},
{ code: "VK_ACCEPT", allowed: false},
@ -176,14 +176,16 @@ var gKeyTestIndex = 0;
var gKeyName;
var gKeyCode;
var gKeyAllowed;
var gKeySuppressed;
var gKeyReceived = false;
function keyHandler(event) {
event.preventDefault()
event.preventDefault();
gKeyReceived = true;
}
function checkKeyEffect() {
is(gKeySuppressed, !gKeyReceived, "Should not receive suppressed key events");
is(document.mozFullScreen, gKeyAllowed,
(gKeyAllowed ? ("Should remain in full-screen mode for allowed key press " + gKeyName)
: ("Should drop out of full-screen mode for restricted key press " + gKeyName)));
@ -239,6 +241,8 @@ function testNextKey() {
gKeyName = keyList[gKeyTestIndex].code;
gKeyCode = KeyEvent["DOM_" + gKeyName];
gKeyAllowed = keyList[gKeyTestIndex].allowed;
gKeySuppressed = (keyList[gKeyTestIndex].suppressed != undefined) ?
keyList[gKeyTestIndex].suppressed : false;
gKeyTestIndex++;
testScriptInitiatedKeyEvents();

View File

@ -6344,17 +6344,30 @@ PresShell::HandleEventInternal(nsEvent* aEvent, nsIView *aView,
switch (aEvent->message) {
case NS_KEY_PRESS:
case NS_KEY_DOWN:
case NS_KEY_UP:
case NS_KEY_UP: {
if (IsFullScreenAndRestrictedKeyEvent(mCurrentEventContent, aEvent) &&
aEvent->message == NS_KEY_DOWN) {
aEvent->message == NS_KEY_UP) {
// We're in DOM full-screen mode, and a key with a restricted key
// code has been pressed. Exit full-screen mode.
NS_DispatchToCurrentThread(
NS_NewRunnableMethod(mCurrentEventContent->OwnerDoc(),
&nsIDocument::CancelFullScreen));
}
nsIDocument *doc = mCurrentEventContent ?
mCurrentEventContent->OwnerDoc() : nsnull;
if (doc &&
doc->IsFullScreenDoc() &&
static_cast<const nsKeyEvent*>(aEvent)->keyCode == NS_VK_ESCAPE) {
// Prevent default action on ESC key press when exiting
// DOM full-screen mode. This prevents the browser ESC key
// handler from stopping all loads in the document, which
// would cause <video> loads to stop.
aEvent->flags |= (NS_EVENT_FLAG_NO_DEFAULT |
NS_EVENT_FLAG_ONLY_CHROME_DISPATCH);
}
// Else not full-screen mode or key code is unrestricted, fall
// through to normal handling.
}
case NS_MOUSE_BUTTON_DOWN:
case NS_MOUSE_BUTTON_UP:
isHandlingUserInput = true;