Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: remoting/webapp/title_bar.js

Issue 265393005: Implement apps v2 custom window frame. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed file added accidentally. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 /**
6 * @fileoverview
7 * Apps v2 custom title bar implementation
8 */
9
10 'use strict';
11
12 /** @suppress {duplicate} */
13 var remoting = remoting || {};
14
15 /**
16 * @constructor
17 */
18 remoting.TitleBar = function() {
19 /**
20 * @type {remoting.ClientSession}
21 * @private
22 */
23 this.clientSession_ = null;
kelvinp 2014/05/06 04:42:15 It seems like this is only used as a boolean to in
Jamie 2014/05/06 21:11:08 I've renamed it to setConnected. I had originally
24
25 /**
26 * @type {Array.<{id:string, fn: function()}>}
27 */
28 var handlers = [
29 { id: 'window-disconnect', fn: this.disconnectSession_.bind(this) },
30 { id: 'window-maximize-restore',
31 fn: this.maximizeOrRestoreWindow_.bind(this) },
32 { id: 'window-minimize', fn: this.minimizeWindow_.bind(this) },
33 { id: 'window-close', fn: window.close.bind(window) },
34 { id: 'window-controls-stub', fn: this.toggleWindowControls_.bind(this) }
35 ];
36 for (var i = 0; i < handlers.length; ++i) {
37 var element = document.getElementById(handlers[i].id);
38 element.addEventListener('click', handlers[i].fn, false);
39 }
40
41 // Ensure that tool-tips are always correct.
42 this.updateMaximizeOrRestoreIconTitle_();
43 chrome.app.window.current().onMaximized.addListener(
44 this.updateMaximizeOrRestoreIconTitle_.bind(this));
45 chrome.app.window.current().onRestored.addListener(
46 this.updateMaximizeOrRestoreIconTitle_.bind(this));
47 chrome.app.window.current().onFullscreened.addListener(
48 this.updateMaximizeOrRestoreIconTitle_.bind(this));
49 };
50
51 /**
52 * @param {remoting.ClientSession} clientSession The current session, or null
53 * if there is no active session.
54 */
55 remoting.TitleBar.prototype.setClientSession = function(clientSession) {
56 this.clientSession_ = clientSession;
57 if (this.clientSession_) {
58 document.body.classList.add('connected');
59 } else {
60 document.body.classList.remove('connected');
61 }
62 this.updateMaximizeOrRestoreIconTitle_();
63 };
64
65 /**
66 * @return {{width: number, height: number}} The size of the window, ignoring
67 * the title-bar and window borders, if visible.
68 */
69 remoting.TitleBar.prototype.getClientArea = function() {
kelvinp 2014/05/06 04:42:15 It seems a bit odd to have a getClientArea method
Jamie 2014/05/06 21:11:08 I've gone with WindowFrame instead, since AppWindo
70 if (chrome.app.window.current().isFullscreen()) {
71 return { 'height': window.innerHeight, 'width': window.innerWidth };
72 } else {
73 var kBorderWidth = 1;
74 var titleBar = document.getElementById('title-bar');
75 base.debug.assert(titleBar != null);
76 return {
77 'height': window.innerHeight - titleBar.clientHeight - 2 * kBorderWidth,
78 'width': window.innerWidth - 2 * kBorderWidth
79 };
80 }
81 };
82
83 /**
84 * @private
85 */
86 remoting.TitleBar.prototype.disconnectSession_ = function() {
87 remoting.disconnect();
88 };
89
90 /**
91 * @private
92 */
93 remoting.TitleBar.prototype.maximizeOrRestoreWindow_ = function() {
94 /** @type {boolean} */
95 var restore =
96 chrome.app.window.current().isFullscreen() ||
kelvinp 2014/05/06 04:42:15 It seems a bit odd that some of the fullscreen man
Jamie 2014/05/06 21:11:08 Since we don't encapsulate the maximized state, I
97 chrome.app.window.current().isMaximized();
98 if (restore) {
99 // Restore twice: once to exit full-screen and once to exit maximized.
100 // If the app is not full-screen, or went full-screen without first
101 // being maximized, then the second restore has no effect.
102 chrome.app.window.current().restore();
103 chrome.app.window.current().restore();
104 } else {
105 chrome.app.window.current().maximize();
106 }
107 };
108
109 /**
110 * @private
111 */
112 remoting.TitleBar.prototype.minimizeWindow_ = function() {
113 chrome.app.window.current().minimize();
114 };
115
116 /**
117 * @private
118 */
119 remoting.TitleBar.prototype.restoreWindow_ = function() {
120 chrome.app.window.current().restore();
121 };
122
123 /**
124 * @private
125 */
126 remoting.TitleBar.prototype.toggleWindowControls_ = function() {
127 document.getElementById('window-controls').classList.toggle('opened');
128 };
129
130 /**
131 * Update the tool-top for the maximize/full-screen/restore icon to reflect
132 * its current behaviour.
133 *
134 * @private
135 */
136 remoting.TitleBar.prototype.updateMaximizeOrRestoreIconTitle_ = function() {
137 var icon = document.getElementById('window-maximize-restore');
138 /** @type {string} */
139 var tag = '';
140 if (chrome.app.window.current().isFullscreen()) {
141 tag = /*i18n-content*/'EXIT_FULL_SCREEN';
142 } else if (chrome.app.window.current().isMaximized()) {
143 tag = /*i18n-content*/'RESTORE_WINDOW';
144 } else if (this.clientSession_) {
145 tag = /*i18n-content*/'FULL_SCREEN';
146 } else {
147 tag = /*i18n-content*/'MAXIMIZE_WINDOW';
148 }
149 icon.title = l10n.getTranslationOrError(tag);
150 };
151
152 /** @type {remoting.TitleBar} */
153 remoting.titleBar = null;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698