Path: blob/trunk/third_party/closure/goog/dom/fullscreen.js
2868 views
// Copyright 2012 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview Functions for managing full screen status of the DOM.16*17*/1819goog.provide('goog.dom.fullscreen');20goog.provide('goog.dom.fullscreen.EventType');2122goog.require('goog.dom');23goog.require('goog.userAgent');242526/**27* Event types for full screen.28* @enum {string}29*/30goog.dom.fullscreen.EventType = {31/** Dispatched by the Document when the fullscreen status changes. */32CHANGE: (function() {33if (goog.userAgent.WEBKIT) {34return 'webkitfullscreenchange';35}36if (goog.userAgent.GECKO) {37return 'mozfullscreenchange';38}39if (goog.userAgent.IE) {40return 'MSFullscreenChange';41}42// Opera 12-14, and W3C standard (Draft):43// https://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html44return 'fullscreenchange';45})()46};474849/**50* Determines if full screen is supported.51* @param {!goog.dom.DomHelper=} opt_domHelper The DomHelper for the DOM being52* queried. If not provided, use the current DOM.53* @return {boolean} True iff full screen is supported.54*/55goog.dom.fullscreen.isSupported = function(opt_domHelper) {56var doc = goog.dom.fullscreen.getDocument_(opt_domHelper);57var body = doc.body;58return !!(59body.webkitRequestFullscreen ||60(body.mozRequestFullScreen && doc.mozFullScreenEnabled) ||61(body.msRequestFullscreen && doc.msFullscreenEnabled) ||62(body.requestFullscreen && doc.fullscreenEnabled));63};646566/**67* Requests putting the element in full screen.68* @param {!Element} element The element to put full screen.69*/70goog.dom.fullscreen.requestFullScreen = function(element) {71if (element.webkitRequestFullscreen) {72element.webkitRequestFullscreen();73} else if (element.mozRequestFullScreen) {74element.mozRequestFullScreen();75} else if (element.msRequestFullscreen) {76element.msRequestFullscreen();77} else if (element.requestFullscreen) {78element.requestFullscreen();79}80};818283/**84* Requests putting the element in full screen with full keyboard access.85* @param {!Element} element The element to put full screen.86*/87goog.dom.fullscreen.requestFullScreenWithKeys = function(element) {88if (element.mozRequestFullScreenWithKeys) {89element.mozRequestFullScreenWithKeys();90} else if (element.webkitRequestFullscreen) {91element.webkitRequestFullscreen();92} else {93goog.dom.fullscreen.requestFullScreen(element);94}95};969798/**99* Exits full screen.100* @param {!goog.dom.DomHelper=} opt_domHelper The DomHelper for the DOM being101* queried. If not provided, use the current DOM.102*/103goog.dom.fullscreen.exitFullScreen = function(opt_domHelper) {104var doc = goog.dom.fullscreen.getDocument_(opt_domHelper);105if (doc.webkitCancelFullScreen) {106doc.webkitCancelFullScreen();107} else if (doc.mozCancelFullScreen) {108doc.mozCancelFullScreen();109} else if (doc.msExitFullscreen) {110doc.msExitFullscreen();111} else if (doc.exitFullscreen) {112doc.exitFullscreen();113}114};115116117/**118* Determines if the document is full screen.119* @param {!goog.dom.DomHelper=} opt_domHelper The DomHelper for the DOM being120* queried. If not provided, use the current DOM.121* @return {boolean} Whether the document is full screen.122*/123goog.dom.fullscreen.isFullScreen = function(opt_domHelper) {124var doc = goog.dom.fullscreen.getDocument_(opt_domHelper);125// IE 11 doesn't have similar boolean property, so check whether126// document.msFullscreenElement is null instead.127return !!(128doc.webkitIsFullScreen || doc.mozFullScreen || doc.msFullscreenElement ||129doc.fullscreenElement);130};131132133/**134* Get the root element in full screen mode.135* @param {!goog.dom.DomHelper=} opt_domHelper The DomHelper for the DOM being136* queried. If not provided, use the current DOM.137* @return {?Element} The root element in full screen mode.138*/139goog.dom.fullscreen.getFullScreenElement = function(opt_domHelper) {140var doc = goog.dom.fullscreen.getDocument_(opt_domHelper);141var element_list = [142doc.webkitFullscreenElement, doc.mozFullScreenElement,143doc.msFullscreenElement, doc.fullscreenElement144];145for (var i = 0; i < element_list.length; i++) {146if (element_list[i] != null) {147return element_list[i];148}149}150return null;151};152153154/**155* Gets the document object of the dom.156* @param {!goog.dom.DomHelper=} opt_domHelper The DomHelper for the DOM being157* queried. If not provided, use the current DOM.158* @return {!Document} The dom document.159* @private160*/161goog.dom.fullscreen.getDocument_ = function(opt_domHelper) {162return opt_domHelper ? opt_domHelper.getDocument() :163goog.dom.getDomHelper().getDocument();164};165166167