Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/third_party/closure/goog/dom/fullscreen.js
2868 views
1
// Copyright 2012 The Closure Library Authors. All Rights Reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS-IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
/**
16
* @fileoverview Functions for managing full screen status of the DOM.
17
*
18
*/
19
20
goog.provide('goog.dom.fullscreen');
21
goog.provide('goog.dom.fullscreen.EventType');
22
23
goog.require('goog.dom');
24
goog.require('goog.userAgent');
25
26
27
/**
28
* Event types for full screen.
29
* @enum {string}
30
*/
31
goog.dom.fullscreen.EventType = {
32
/** Dispatched by the Document when the fullscreen status changes. */
33
CHANGE: (function() {
34
if (goog.userAgent.WEBKIT) {
35
return 'webkitfullscreenchange';
36
}
37
if (goog.userAgent.GECKO) {
38
return 'mozfullscreenchange';
39
}
40
if (goog.userAgent.IE) {
41
return 'MSFullscreenChange';
42
}
43
// Opera 12-14, and W3C standard (Draft):
44
// https://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html
45
return 'fullscreenchange';
46
})()
47
};
48
49
50
/**
51
* Determines if full screen is supported.
52
* @param {!goog.dom.DomHelper=} opt_domHelper The DomHelper for the DOM being
53
* queried. If not provided, use the current DOM.
54
* @return {boolean} True iff full screen is supported.
55
*/
56
goog.dom.fullscreen.isSupported = function(opt_domHelper) {
57
var doc = goog.dom.fullscreen.getDocument_(opt_domHelper);
58
var body = doc.body;
59
return !!(
60
body.webkitRequestFullscreen ||
61
(body.mozRequestFullScreen && doc.mozFullScreenEnabled) ||
62
(body.msRequestFullscreen && doc.msFullscreenEnabled) ||
63
(body.requestFullscreen && doc.fullscreenEnabled));
64
};
65
66
67
/**
68
* Requests putting the element in full screen.
69
* @param {!Element} element The element to put full screen.
70
*/
71
goog.dom.fullscreen.requestFullScreen = function(element) {
72
if (element.webkitRequestFullscreen) {
73
element.webkitRequestFullscreen();
74
} else if (element.mozRequestFullScreen) {
75
element.mozRequestFullScreen();
76
} else if (element.msRequestFullscreen) {
77
element.msRequestFullscreen();
78
} else if (element.requestFullscreen) {
79
element.requestFullscreen();
80
}
81
};
82
83
84
/**
85
* Requests putting the element in full screen with full keyboard access.
86
* @param {!Element} element The element to put full screen.
87
*/
88
goog.dom.fullscreen.requestFullScreenWithKeys = function(element) {
89
if (element.mozRequestFullScreenWithKeys) {
90
element.mozRequestFullScreenWithKeys();
91
} else if (element.webkitRequestFullscreen) {
92
element.webkitRequestFullscreen();
93
} else {
94
goog.dom.fullscreen.requestFullScreen(element);
95
}
96
};
97
98
99
/**
100
* Exits full screen.
101
* @param {!goog.dom.DomHelper=} opt_domHelper The DomHelper for the DOM being
102
* queried. If not provided, use the current DOM.
103
*/
104
goog.dom.fullscreen.exitFullScreen = function(opt_domHelper) {
105
var doc = goog.dom.fullscreen.getDocument_(opt_domHelper);
106
if (doc.webkitCancelFullScreen) {
107
doc.webkitCancelFullScreen();
108
} else if (doc.mozCancelFullScreen) {
109
doc.mozCancelFullScreen();
110
} else if (doc.msExitFullscreen) {
111
doc.msExitFullscreen();
112
} else if (doc.exitFullscreen) {
113
doc.exitFullscreen();
114
}
115
};
116
117
118
/**
119
* Determines if the document is full screen.
120
* @param {!goog.dom.DomHelper=} opt_domHelper The DomHelper for the DOM being
121
* queried. If not provided, use the current DOM.
122
* @return {boolean} Whether the document is full screen.
123
*/
124
goog.dom.fullscreen.isFullScreen = function(opt_domHelper) {
125
var doc = goog.dom.fullscreen.getDocument_(opt_domHelper);
126
// IE 11 doesn't have similar boolean property, so check whether
127
// document.msFullscreenElement is null instead.
128
return !!(
129
doc.webkitIsFullScreen || doc.mozFullScreen || doc.msFullscreenElement ||
130
doc.fullscreenElement);
131
};
132
133
134
/**
135
* Get the root element in full screen mode.
136
* @param {!goog.dom.DomHelper=} opt_domHelper The DomHelper for the DOM being
137
* queried. If not provided, use the current DOM.
138
* @return {?Element} The root element in full screen mode.
139
*/
140
goog.dom.fullscreen.getFullScreenElement = function(opt_domHelper) {
141
var doc = goog.dom.fullscreen.getDocument_(opt_domHelper);
142
var element_list = [
143
doc.webkitFullscreenElement, doc.mozFullScreenElement,
144
doc.msFullscreenElement, doc.fullscreenElement
145
];
146
for (var i = 0; i < element_list.length; i++) {
147
if (element_list[i] != null) {
148
return element_list[i];
149
}
150
}
151
return null;
152
};
153
154
155
/**
156
* Gets the document object of the dom.
157
* @param {!goog.dom.DomHelper=} opt_domHelper The DomHelper for the DOM being
158
* queried. If not provided, use the current DOM.
159
* @return {!Document} The dom document.
160
* @private
161
*/
162
goog.dom.fullscreen.getDocument_ = function(opt_domHelper) {
163
return opt_domHelper ? opt_domHelper.getDocument() :
164
goog.dom.getDomHelper().getDocument();
165
};
166
167