зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1213168 - Use the top window for checking window state in fullscreen test utils. rs=smaug
--HG-- extra : source : 5c94ae5936b81cb4e5f19ddb9c231f91d1496d1e
This commit is contained in:
Родитель
6ab3d4ccd1
Коммит
2814f667b7
|
@ -1,23 +1,18 @@
|
|||
// Remember the window size in non-fullscreen mode.
|
||||
var normalSize = new function() {
|
||||
this.w = window.outerWidth;
|
||||
this.h = window.outerHeight;
|
||||
}();
|
||||
|
||||
// Returns true if the window occupies the entire screen.
|
||||
// Note this only returns true once the transition from normal to
|
||||
// fullscreen mode is complete.
|
||||
function inFullscreenMode() {
|
||||
return window.outerWidth == window.screen.width &&
|
||||
window.outerHeight == window.screen.height;
|
||||
function inFullscreenMode(win) {
|
||||
return win.outerWidth == win.screen.width &&
|
||||
win.outerHeight == win.screen.height;
|
||||
}
|
||||
|
||||
// Returns true if the window is in normal mode, i.e. non fullscreen mode.
|
||||
// Note this only returns true once the transition from fullscreen back to
|
||||
// normal mode is complete.
|
||||
function inNormalMode() {
|
||||
return window.outerWidth == normalSize.w &&
|
||||
window.outerHeight == normalSize.h;
|
||||
function inNormalMode(win) {
|
||||
return win.outerWidth == win.normalSize.w &&
|
||||
win.outerHeight == win.normalSize.h;
|
||||
}
|
||||
|
||||
// Adds a listener that will be called once a fullscreen transition
|
||||
|
@ -31,17 +26,24 @@ function inNormalMode() {
|
|||
// the current document.
|
||||
function addFullscreenChangeContinuation(type, callback, inDoc) {
|
||||
var doc = inDoc || document;
|
||||
var topWin = doc.defaultView.top;
|
||||
// Remember the window size in non-fullscreen mode.
|
||||
if (!topWin.normalSize) {
|
||||
topWin.normalSize = {
|
||||
w: window.outerWidth,
|
||||
h: window.outerHeight
|
||||
};
|
||||
}
|
||||
function checkCondition() {
|
||||
if (type == "enter") {
|
||||
return inFullscreenMode();
|
||||
return inFullscreenMode(topWin);
|
||||
} else if (type == "exit") {
|
||||
// If we just revert the state to a previous fullscreen state,
|
||||
// the window won't back to the normal mode. Hence we check
|
||||
// mozFullScreenElement first here. Note that we need to check
|
||||
// the fullscreen element of the outmost document here instead
|
||||
// of the current one.
|
||||
var topDoc = doc.defaultView.top.document;
|
||||
return topDoc.mozFullScreenElement || inNormalMode();
|
||||
return topWin.document.mozFullScreenElement || inNormalMode(topWin);
|
||||
} else {
|
||||
throw "'type' must be either 'enter', or 'exit'.";
|
||||
}
|
||||
|
@ -57,14 +59,13 @@ function addFullscreenChangeContinuation(type, callback, inDoc) {
|
|||
invokeCallback(event);
|
||||
return;
|
||||
}
|
||||
var win = doc.defaultView;
|
||||
function onResize() {
|
||||
if (checkCondition()) {
|
||||
win.removeEventListener("resize", onResize, false);
|
||||
topWin.removeEventListener("resize", onResize, false);
|
||||
invokeCallback(event);
|
||||
}
|
||||
}
|
||||
win.addEventListener("resize", onResize, false);
|
||||
topWin.addEventListener("resize", onResize, false);
|
||||
}
|
||||
doc.addEventListener("mozfullscreenchange", onFullscreenChange, false);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче