-
Notifications
You must be signed in to change notification settings - Fork 8
/
fullscreen_v1.js
108 lines (94 loc) · 2.87 KB
/
fullscreen_v1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview
* Full-screen implementation for apps v1, using webkitRequestFullscreen.
*/
'use strict';
/** @suppress {duplicate} */
var remoting = remoting || {};
/**
* @constructor
* @implements {remoting.Fullscreen}
*/
remoting.FullscreenAppsV1 = function() {
/**
* @type {string} Internal 'full-screen changed' event name
* @private
*/
this.kEventName_ = '_fullscreenchanged';
/**
* @type {base.EventSourceImpl}
* @private
*/
this.eventSource_ = new base.EventSourceImpl();
this.eventSource_.defineEvents([this.kEventName_]);
document.addEventListener(
'webkitfullscreenchange',
this.onFullscreenChanged_.bind(this),
false);
};
remoting.FullscreenAppsV1.prototype.activate = function(
fullscreen, opt_onDone) {
if (opt_onDone) {
if (this.isActive() == fullscreen) {
opt_onDone();
} else {
/** @type {remoting.Fullscreen} */
var that = this;
var callbackAndRemoveListener = function() {
that.removeListener(callbackAndRemoveListener);
opt_onDone();
};
this.addListener(callbackAndRemoveListener);
}
}
if (fullscreen) {
document.body.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
} else {
document.webkitCancelFullScreen();
}
};
/** @return {void} */
remoting.FullscreenAppsV1.prototype.toggle = function() {
this.activate(!this.isActive());
};
/**
* @return {boolean} True if full-screen mode is active.
*/
remoting.FullscreenAppsV1.prototype.isActive = function() {
return document.webkitIsFullScreen;
};
/**
* @param {function(boolean=):void} callback
*/
remoting.FullscreenAppsV1.prototype.addListener = function(callback) {
this.eventSource_.addEventListener(this.kEventName_, callback);
};
/**
* @param {function(boolean=):void} callback
*/
remoting.FullscreenAppsV1.prototype.removeListener = function(callback) {
this.eventSource_.removeEventListener(this.kEventName_, callback);
};
/**
* @private
*/
remoting.FullscreenAppsV1.prototype.onFullscreenChanged_ = function() {
/** @this {remoting.FullscreenAppsV1} */
var checkIsActive = function() {
if (this.isActive()) {
document.body.classList.add('fullscreen');
} else {
document.body.classList.remove('fullscreen');
}
this.eventSource_.raiseEvent(this.kEventName_, this.isActive());
};
// Querying full-screen immediately after the webkitfullscreenchange
// event fires sometimes gives the wrong answer on Mac, perhaps due to
// the time taken to animate presentation mode. Since I haven't been able
// to isolate the exact repro steps, and we're not planning on using this
// API for much longer, this hack will suffice for now.
window.setTimeout(checkIsActive.bind(this), 500);
};