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

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

Issue 498813003: Separate menu & disconnect buttons from the window controls and clean up CSS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * Apps v2 custom title bar implementation 7 * Apps v2 custom title bar implementation
8 */ 8 */
9 9
10 'use strict'; 10 'use strict';
(...skipping 12 matching lines...) Expand all
23 */ 23 */
24 this.clientSession_ = null; 24 this.clientSession_ = null;
25 25
26 /** 26 /**
27 * @type {HTMLElement} 27 * @type {HTMLElement}
28 * @private 28 * @private
29 */ 29 */
30 this.titleBar_ = titleBar; 30 this.titleBar_ = titleBar;
31 31
32 /** 32 /**
33 * @type {HTMLElement}
34 * @private
35 */
36 this.hoverTarget_ = /** @type {HTMLElement} */
37 (titleBar.querySelector('.window-controls-hover-target'));
38 base.debug.assert(this.hoverTarget_ != null);
39
40 /**
41 * @type {remoting.OptionsMenu} 33 * @type {remoting.OptionsMenu}
42 * @private 34 * @private
43 */ 35 */
44 this.optionsMenu_ = new remoting.OptionsMenu( 36 this.optionsMenu_ = new remoting.OptionsMenu(
45 titleBar.querySelector('.menu-send-ctrl-alt-del'), 37 titleBar.querySelector('.menu-send-ctrl-alt-del'),
46 titleBar.querySelector('.menu-send-print-screen'), 38 titleBar.querySelector('.menu-send-print-screen'),
47 titleBar.querySelector('.menu-resize-to-client'), 39 titleBar.querySelector('.menu-resize-to-client'),
48 titleBar.querySelector('.menu-shrink-to-fit'), 40 titleBar.querySelector('.menu-shrink-to-fit'),
49 titleBar.querySelector('.menu-new-connection'), 41 titleBar.querySelector('.menu-new-connection'),
50 null); 42 null);
(...skipping 15 matching lines...) Expand all
66 base.debug.assert(this.maximizeRestoreControl_ != null); 58 base.debug.assert(this.maximizeRestoreControl_ != null);
67 59
68 var optionsButton = titleBar.querySelector('.window-options'); 60 var optionsButton = titleBar.querySelector('.window-options');
69 base.debug.assert(optionsButton != null); 61 base.debug.assert(optionsButton != null);
70 this.optionMenuButton_ = new remoting.MenuButton( 62 this.optionMenuButton_ = new remoting.MenuButton(
71 optionsButton, 63 optionsButton,
72 this.onShowOptionsMenu_.bind(this), 64 this.onShowOptionsMenu_.bind(this),
73 this.onHideOptionsMenu_.bind(this)); 65 this.onHideOptionsMenu_.bind(this));
74 66
75 /** 67 /**
68 * @type {HTMLElement}
69 * @private
70 */
71 this.optionsMenuList_ = /** @type {HTMLElement} */
72 (optionsButton.querySelector('.window-options-menu'));
73 base.debug.assert(this.optionsMenu_ != null);
74
75 /**
76 * @type {Array.<{cls:string, fn: function()}>} 76 * @type {Array.<{cls:string, fn: function()}>}
77 */ 77 */
78 var handlers = [ 78 var handlers = [
79 { cls: 'window-disconnect', fn: this.disconnectSession_.bind(this) }, 79 { cls: 'window-disconnect', fn: this.disconnectSession_.bind(this) },
80 { cls: 'window-maximize-restore', 80 { cls: 'window-maximize-restore',
81 fn: this.maximizeOrRestoreWindow_.bind(this) }, 81 fn: this.maximizeOrRestoreWindow_.bind(this) },
82 { cls: 'window-minimize', fn: this.minimizeWindow_.bind(this) }, 82 { cls: 'window-minimize', fn: this.minimizeWindow_.bind(this) },
83 { cls: 'window-close', fn: window.close.bind(window) }, 83 { cls: 'window-close', fn: window.close.bind(window) },
84 { cls: 'window-controls-stub', fn: this.toggleWindowControls_.bind(this) } 84 { cls: 'window-controls-stub', fn: this.toggleWindowControls_.bind(this) }
85 ]; 85 ];
86 for (var i = 0; i < handlers.length; ++i) { 86 for (var i = 0; i < handlers.length; ++i) {
87 var element = titleBar.querySelector('.' + handlers[i].cls); 87 var element = titleBar.querySelector('.' + handlers[i].cls);
88 base.debug.assert(element != null); 88 base.debug.assert(element != null);
89 element.addEventListener('click', handlers[i].fn, false); 89 element.addEventListener('click', handlers[i].fn, false);
90 } 90 }
91 91
92 // Ensure that tool-tips are always correct. 92 // Ensure that tool-tips are always correct.
93 this.updateMaximizeOrRestoreIconTitle_(); 93 this.handleWindowStateChange_();
94 chrome.app.window.current().onMaximized.addListener( 94 chrome.app.window.current().onMaximized.addListener(
95 this.updateMaximizeOrRestoreIconTitle_.bind(this)); 95 this.handleWindowStateChange_.bind(this));
96 chrome.app.window.current().onRestored.addListener( 96 chrome.app.window.current().onRestored.addListener(
97 this.updateMaximizeOrRestoreIconTitle_.bind(this)); 97 this.handleWindowStateChange_.bind(this));
98 chrome.app.window.current().onFullscreened.addListener( 98 chrome.app.window.current().onFullscreened.addListener(
99 this.updateMaximizeOrRestoreIconTitle_.bind(this)); 99 this.handleWindowStateChange_.bind(this));
100 chrome.app.window.current().onFullscreened.addListener( 100 chrome.app.window.current().onFullscreened.addListener(
101 this.showWindowControlsPreview_.bind(this)); 101 this.showWindowControlsPreview_.bind(this));
102 }; 102 };
103 103
104 /** 104 /**
105 * @param {remoting.ClientSession} clientSession The client session, or null if 105 * @param {remoting.ClientSession} clientSession The client session, or null if
106 * there is no connection. 106 * there is no connection.
107 */ 107 */
108 remoting.WindowFrame.prototype.setClientSession = function(clientSession) { 108 remoting.WindowFrame.prototype.setClientSession = function(clientSession) {
109 this.optionsMenu_.setClientSession(clientSession); 109 this.optionsMenu_.setClientSession(clientSession);
110 this.clientSession_ = clientSession; 110 this.clientSession_ = clientSession;
111 var windowTitle = document.head.querySelector('title'); 111 var windowTitle = document.head.querySelector('title');
112 if (this.clientSession_) { 112 if (this.clientSession_) {
113 document.body.classList.add('connected'); 113 document.body.classList.add('connected');
114 this.title_.innerText = clientSession.getHostDisplayName(); 114 this.title_.innerText = clientSession.getHostDisplayName();
115 windowTitle.innerText = clientSession.getHostDisplayName() + ' - ' + 115 windowTitle.innerText = clientSession.getHostDisplayName() + ' - ' +
116 chrome.i18n.getMessage(/*i18n-content*/'PRODUCT_NAME'); 116 chrome.i18n.getMessage(/*i18n-content*/'PRODUCT_NAME');
117 } else { 117 } else {
118 document.body.classList.remove('connected'); 118 document.body.classList.remove('connected');
119 this.title_.innerHTML = '&nbsp;'; 119 this.title_.innerHTML = '&nbsp;';
120 windowTitle.innerText = 120 windowTitle.innerText =
121 chrome.i18n.getMessage(/*i18n-content*/'PRODUCT_NAME'); 121 chrome.i18n.getMessage(/*i18n-content*/'PRODUCT_NAME');
122 } 122 }
123 this.updateMaximizeOrRestoreIconTitle_(); 123 this.handleWindowStateChange_();
124 }; 124 };
125 125
126 /** 126 /**
127 * @return {{width: number, height: number}} The size of the window, ignoring 127 * @return {{width: number, height: number}} The size of the window, ignoring
128 * the title-bar and window borders, if visible. 128 * the title-bar and window borders, if visible.
129 */ 129 */
130 remoting.WindowFrame.prototype.getClientArea = function() { 130 remoting.WindowFrame.prototype.getClientArea = function() {
131 if (chrome.app.window.current().isFullscreen()) { 131 if (chrome.app.window.current().isFullscreen()) {
132 return { 'height': window.innerHeight, 'width': window.innerWidth }; 132 return { 'height': window.innerHeight, 'width': window.innerWidth };
133 } else { 133 } else {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 * @private 179 * @private
180 */ 180 */
181 remoting.WindowFrame.prototype.minimizeWindow_ = function() { 181 remoting.WindowFrame.prototype.minimizeWindow_ = function() {
182 chrome.app.window.current().minimize(); 182 chrome.app.window.current().minimize();
183 }; 183 };
184 184
185 /** 185 /**
186 * @private 186 * @private
187 */ 187 */
188 remoting.WindowFrame.prototype.toggleWindowControls_ = function() { 188 remoting.WindowFrame.prototype.toggleWindowControls_ = function() {
189 this.hoverTarget_.classList.toggle('opened'); 189 this.titleBar_.classList.toggle('opened');
190 }; 190 };
191 191
192 /** 192 /**
193 * Update the tool-top for the maximize/full-screen/restore icon to reflect 193 * Update the tool-top for the maximize/full-screen/restore icon to reflect
194 * its current behaviour. 194 * its current behaviour.
195 * 195 *
196 * @private 196 * @private
197 */ 197 */
198 remoting.WindowFrame.prototype.updateMaximizeOrRestoreIconTitle_ = function() { 198 remoting.WindowFrame.prototype.handleWindowStateChange_ = function() {
199 // Set the title for the maximize/restore/full-screen button
199 /** @type {string} */ 200 /** @type {string} */
200 var tag = ''; 201 var tag = '';
201 if (chrome.app.window.current().isFullscreen()) { 202 if (chrome.app.window.current().isFullscreen()) {
202 tag = /*i18n-content*/'EXIT_FULL_SCREEN'; 203 tag = /*i18n-content*/'EXIT_FULL_SCREEN';
203 } else if (chrome.app.window.current().isMaximized()) { 204 } else if (chrome.app.window.current().isMaximized()) {
204 tag = /*i18n-content*/'RESTORE_WINDOW'; 205 tag = /*i18n-content*/'RESTORE_WINDOW';
205 } else if (this.clientSession_) { 206 } else if (this.clientSession_) {
206 tag = /*i18n-content*/'FULL_SCREEN'; 207 tag = /*i18n-content*/'FULL_SCREEN';
207 } else { 208 } else {
208 tag = /*i18n-content*/'MAXIMIZE_WINDOW'; 209 tag = /*i18n-content*/'MAXIMIZE_WINDOW';
209 } 210 }
210 this.maximizeRestoreControl_.title = l10n.getTranslationOrError(tag); 211 this.maximizeRestoreControl_.title = l10n.getTranslationOrError(tag);
212
213 // Ensure that the options menu aligns correctly for the side of the window
214 // it occupies.
215 if (chrome.app.window.current().isFullscreen()) {
216 this.optionsMenuList_.classList.add('right-align');
217 } else {
218 this.optionsMenuList_.classList.remove('right-align');
219 }
211 }; 220 };
212 221
213 /** 222 /**
214 * Callback invoked when the options menu is shown. 223 * Callback invoked when the options menu is shown.
215 * @private 224 * @private
216 */ 225 */
217 remoting.WindowFrame.prototype.onShowOptionsMenu_ = function() { 226 remoting.WindowFrame.prototype.onShowOptionsMenu_ = function() {
218 this.optionsMenu_.onShow(); 227 this.optionsMenu_.onShow();
219 this.hoverTarget_.classList.add('menu-opened'); 228 this.titleBar_.classList.add('menu-opened');
220 }; 229 };
221 230
222 /** 231 /**
223 * Callback invoked when the options menu is shown. 232 * Callback invoked when the options menu is shown.
224 * @private 233 * @private
225 */ 234 */
226 remoting.WindowFrame.prototype.onHideOptionsMenu_ = function() { 235 remoting.WindowFrame.prototype.onHideOptionsMenu_ = function() {
227 this.hoverTarget_.classList.remove('menu-opened'); 236 this.titleBar_.classList.remove('menu-opened');
228 }; 237 };
229 238
230 /** 239 /**
231 * Show the window controls for a few seconds 240 * Show the window controls for a few seconds
232 * 241 *
233 * @private 242 * @private
234 */ 243 */
235 remoting.WindowFrame.prototype.showWindowControlsPreview_ = function() { 244 remoting.WindowFrame.prototype.showWindowControlsPreview_ = function() {
236 /** 245 /**
237 * @type {HTMLElement} 246 * @type {HTMLElement}
238 */ 247 */
239 var target = this.hoverTarget_; 248 var target = this.titleBar_;
240 var kPreviewTimeoutMs = 3000; 249 var kPreviewTimeoutMs = 3000;
241 var hidePreview = function() { 250 var hidePreview = function() {
242 target.classList.remove('preview'); 251 target.classList.remove('preview');
243 }; 252 };
244 target.classList.add('preview'); 253 target.classList.add('preview');
245 window.setTimeout(hidePreview, kPreviewTimeoutMs); 254 window.setTimeout(hidePreview, kPreviewTimeoutMs);
246 }; 255 };
247 256
248 257
249 /** @type {remoting.WindowFrame} */ 258 /** @type {remoting.WindowFrame} */
250 remoting.windowFrame = null; 259 remoting.windowFrame = null;
OLDNEW
« remoting/webapp/window_frame.css ('K') | « remoting/webapp/window_frame.css ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698