From f0cbaf511aeae6f0dae8a6f1d7a7d55cf33f2c8c Mon Sep 17 00:00:00 2001 From: Chris Pearce Date: Tue, 8 Nov 2011 12:58:48 +1300 Subject: [PATCH] Bug 699885 part 2 - Exit DOM full-screen if we've changed tab or app by the time the request is granted. r=dao --- browser/base/content/browser.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 13a8c8103a0..ae06684d7a9 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -3913,14 +3913,36 @@ var FullScreen = { }, enterDomFullScreen : function(event) { + if (!document.mozFullScreen) { + return; + } + // We receive "mozfullscreenchange" events for each subdocument which // is an ancestor of the document containing the element which requested // full-screen. Only add listeners and show warning etc when the event we // receive is targeted at the chrome document, i.e. only once every time // we enter DOM full-screen mode. - if (!document.mozFullScreen || event.target.ownerDocument != document) { + let targetDoc = event.target.ownerDocument ? event.target.ownerDocument : event.target; + if (targetDoc != document) { + // However, if we receive a "mozfullscreenchange" event for a document + // which is not a subdocument of the currently selected tab, we know that + // we've switched tabs since the request to enter full-screen was made, + // so we should exit full-screen since the "full-screen document" isn't + // acutally visible. + if (targetDoc.defaultView.top != gBrowser.contentWindow) { + document.mozCancelFullScreen(); + } return; } + + let focusManger = Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager); + if (focusManger.activeWindow != window) { + // The top-level window has lost focus since the request to enter + // full-screen was made. Cancel full-screen. + document.mozCancelFullScreen(); + return; + } + this.showWarning(true); // Exit DOM full-screen mode upon open, close, or change tab.