Update broken references to image assets
[chromium-blink-merge.git] / remoting / webapp / crd / js / fullscreen_v1.js
blobc22dcd0ce772240499424d108e536e61bc33c072
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 /**
6 * @fileoverview
7 * Full-screen implementation for apps v1, using webkitRequestFullscreen.
8 */
10 'use strict';
12 /** @suppress {duplicate} */
13 var remoting = remoting || {};
15 /**
16 * @constructor
17 * @implements {remoting.Fullscreen}
19 remoting.FullscreenAppsV1 = function() {
20 /** @private {string} Internal 'full-screen changed' event name */
21 this.kEventName_ = '_fullscreenchanged';
23 /** @private {base.EventSourceImpl} */
24 this.eventSource_ = new base.EventSourceImpl();
25 this.eventSource_.defineEvents([this.kEventName_]);
27 document.addEventListener(
28 'webkitfullscreenchange',
29 this.onFullscreenChanged_.bind(this),
30 false);
33 remoting.FullscreenAppsV1.prototype.activate = function(
34 fullscreen, opt_onDone) {
35 if (opt_onDone) {
36 if (this.isActive() == fullscreen) {
37 opt_onDone();
38 } else {
39 /** @type {remoting.Fullscreen} */
40 var that = this;
41 var callbackAndRemoveListener = function() {
42 that.removeListener(callbackAndRemoveListener);
43 opt_onDone();
45 this.addListener(callbackAndRemoveListener);
49 if (fullscreen) {
50 document.body.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
51 } else {
52 document.webkitCancelFullScreen();
56 /** @return {void} */
57 remoting.FullscreenAppsV1.prototype.toggle = function() {
58 this.activate(!this.isActive());
61 /**
62 * @return {boolean} True if full-screen mode is active.
64 remoting.FullscreenAppsV1.prototype.isActive = function() {
65 return document.webkitIsFullScreen;
68 /**
69 * @param {function(boolean=):void} callback
71 remoting.FullscreenAppsV1.prototype.addListener = function(callback) {
72 this.eventSource_.addEventListener(this.kEventName_, callback);
75 /**
76 * @param {function(boolean=):void} callback
78 remoting.FullscreenAppsV1.prototype.removeListener = function(callback) {
79 this.eventSource_.removeEventListener(this.kEventName_, callback);
82 /**
83 * @private
85 remoting.FullscreenAppsV1.prototype.onFullscreenChanged_ = function() {
86 /** @this {remoting.FullscreenAppsV1} */
87 var checkIsActive = function() {
88 if (this.isActive()) {
89 document.body.classList.add('fullscreen');
90 } else {
91 document.body.classList.remove('fullscreen');
93 this.eventSource_.raiseEvent(this.kEventName_, this.isActive());
96 // Querying full-screen immediately after the webkitfullscreenchange
97 // event fires sometimes gives the wrong answer on Mac, perhaps due to
98 // the time taken to animate presentation mode. Since I haven't been able
99 // to isolate the exact repro steps, and we're not planning on using this
100 // API for much longer, this hack will suffice for now.
101 window.setTimeout(checkIsActive.bind(this), 500);