[MacViews] Show comboboxes with a native NSMenu
[chromium-blink-merge.git] / chrome / browser / resources / chromeos / login / header_bar.js
blob306f99ef0e36e79fc6a741a19261d90bd1d86026
1 // Copyright (c) 2012 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 Login UI header bar implementation.
7 */
9 cr.define('login', function() {
10 /**
11 * Creates a header bar element.
13 * @constructor
14 * @extends {HTMLDivElement}
16 var HeaderBar = cr.ui.define('div');
18 HeaderBar.prototype = {
19 __proto__: HTMLDivElement.prototype,
21 // Whether guest button should be shown when header bar is in normal mode.
22 showGuest_: false,
24 // Whether new Gaia flow is active.
25 isNewGaiaFlow_: false,
27 // Whether the reboot button should be shown the when header bar is in
28 // normal mode.
29 showReboot_: false,
31 // Whether the shutdown button should be shown when the header bar is in
32 // normal mode.
33 showShutdown_: true,
35 // Whether the create supervised user button should be shown when the header
36 // bar is in normal mode. It will be shown in "More settings" menu.
37 showCreateSupervised_: false,
39 // Current UI state of the sign-in screen.
40 signinUIState_: SIGNIN_UI_STATE.HIDDEN,
42 // Whether to show kiosk apps menu.
43 hasApps_: false,
45 /** @override */
46 decorate: function() {
47 document.addEventListener('click', this.handleClick_.bind(this));
48 $('shutdown-header-bar-item').addEventListener('click',
49 this.handleShutdownClick_);
50 $('shutdown-button').addEventListener('click',
51 this.handleShutdownClick_);
52 $('restart-header-bar-item').addEventListener('click',
53 this.handleShutdownClick_);
54 $('restart-button').addEventListener('click',
55 this.handleShutdownClick_);
56 $('add-user-button').addEventListener('click',
57 this.handleAddUserClick_);
58 $('more-settings-button').addEventListener('click',
59 this.handleMoreSettingsClick_.bind(this));
60 $('cancel-add-user-button').addEventListener('click',
61 this.handleCancelAddUserClick_);
62 $('guest-user-header-bar-item').addEventListener('click',
63 this.handleGuestClick_);
64 $('guest-user-button').addEventListener('click',
65 this.handleGuestClick_);
66 $('sign-out-user-button').addEventListener('click',
67 this.handleSignoutClick_);
68 $('cancel-multiple-sign-in-button').addEventListener('click',
69 this.handleCancelMultipleSignInClick_);
70 $('cancel-consumer-management-enrollment-button').addEventListener(
71 'click',
72 this.handleCancelConsumerManagementEnrollmentClick_);
73 this.addSupervisedUserMenu.addEventListener('click',
74 this.handleAddSupervisedUserClick_.bind(this));
75 if (Oobe.getInstance().displayType == DISPLAY_TYPE.LOGIN ||
76 Oobe.getInstance().displayType == DISPLAY_TYPE.OOBE) {
77 if (Oobe.getInstance().newKioskUI)
78 chrome.send('initializeKioskApps');
79 else
80 login.AppsMenuButton.decorate($('show-apps-button'));
82 this.updateUI_();
85 /**
86 * Tab index value for all button elements.
88 * @type {number}
90 set buttonsTabIndex(tabIndex) {
91 var buttons = this.getElementsByTagName('button');
92 for (var i = 0, button; button = buttons[i]; ++i) {
93 button.tabIndex = tabIndex;
97 /**
98 * Disables the header bar and all of its elements.
100 * @type {boolean}
102 set disabled(value) {
103 var buttons = this.getElementsByTagName('button');
104 for (var i = 0, button; button = buttons[i]; ++i)
105 if (!button.classList.contains('button-restricted'))
106 button.disabled = value;
109 get getMoreSettingsMenu() {
110 return $('more-settings-header-bar-item');
113 get addSupervisedUserMenu() {
114 return this.querySelector('.add-supervised-user-menu');
118 * Whether action box button is in active state.
119 * @type {boolean}
121 get isMoreSettingsActive() {
122 return this.getMoreSettingsMenu.classList.contains('active');
124 set isMoreSettingsActive(active) {
125 if (active == this.isMoreSettingsActive)
126 return;
127 if (active) {
128 this.getMoreSettingsMenu.classList.add('active');
129 } else {
130 this.getMoreSettingsMenu.classList.remove('active');
136 * Add user button click handler.
138 * @private
140 handleAddUserClick_: function(e) {
141 Oobe.showSigninUI();
142 // Prevent further propagation of click event. Otherwise, the click event
143 // handler of document object will set wallpaper to user's wallpaper when
144 // there is only one existing user. See http://crbug.com/166477
145 e.stopPropagation();
148 handleMoreSettingsClick_: function(e) {
149 this.isMoreSettingsActive = !this.isMoreSettingsActive;
150 this.addSupervisedUserMenu.focus();
151 e.stopPropagation();
154 handleClick_: function(e) {
155 this.isMoreSettingsActive = false;
158 handleAddSupervisedUserClick_: function(e) {
159 chrome.send('showSupervisedUserCreationScreen');
160 e.preventDefault();
164 * Cancel add user button click handler.
166 * @private
168 handleCancelAddUserClick_: function(e) {
169 // Let screen handle cancel itself if that is capable of doing so.
170 if (Oobe.getInstance().currentScreen &&
171 Oobe.getInstance().currentScreen.cancel) {
172 Oobe.getInstance().currentScreen.cancel();
173 return;
176 Oobe.showUserPods();
180 * Guest button click handler.
182 * @private
184 handleGuestClick_: function(e) {
185 Oobe.disableSigninUI();
186 chrome.send('launchIncognito');
187 e.stopPropagation();
191 * Sign out button click handler.
193 * @private
195 handleSignoutClick_: function(e) {
196 this.disabled = true;
197 chrome.send('signOutUser');
198 e.stopPropagation();
202 * Shutdown button click handler.
204 * @private
206 handleShutdownClick_: function(e) {
207 chrome.send('shutdownSystem');
208 e.stopPropagation();
212 * Cancel user adding button handler.
214 * @private
216 handleCancelMultipleSignInClick_: function(e) {
217 chrome.send('cancelUserAdding');
218 e.stopPropagation();
222 * Cancel consumer management enrollment button handler.
224 * @private
226 handleCancelConsumerManagementEnrollmentClick_: function(e) {
227 chrome.send('cancelConsumerManagementEnrollment');
228 e.stopPropagation();
232 * If true then "Browse as Guest" button is shown.
234 * @type {boolean}
236 set showGuestButton(value) {
237 this.showGuest_ = value;
238 this.updateUI_();
241 set newGaiaFlow(value) {
242 this.isNewGaiaFlow_ = value;
243 this.updateUI_();
246 set showCreateSupervisedButton(value) {
247 this.showCreateSupervised_ = value;
248 this.updateUI_();
252 * If true the "Restart" button is shown.
254 * @type {boolean}
256 set showRebootButton(value) {
257 this.showReboot_ = value;
258 this.updateUI_();
262 * If true the "Shutdown" button is shown.
264 * @type {boolean}
266 set showShutdownButton(value) {
267 this.showShutdown_ = value;
268 this.updateUI_();
272 * Current header bar UI / sign in state.
274 * @type {number} state Current state of the sign-in screen (see
275 * SIGNIN_UI_STATE).
277 get signinUIState() {
278 return this.signinUIState_;
280 set signinUIState(state) {
281 this.signinUIState_ = state;
282 this.updateUI_();
286 * Whether the Cancel button is enabled during Gaia sign-in.
288 * @type {boolean}
290 set allowCancel(value) {
291 this.allowCancel_ = value;
292 this.updateUI_();
295 get allowCancel() {
296 return !!this.allowCancel_;
300 * Update whether there are kiosk apps.
302 * @type {boolean}
304 set hasApps(value) {
305 this.hasApps_ = value;
306 this.updateUI_();
310 * Updates visibility state of action buttons.
312 * @private
314 updateUI_: function() {
315 var gaiaIsActive = (this.signinUIState_ == SIGNIN_UI_STATE.GAIA_SIGNIN);
316 var enrollmentIsActive =
317 (this.signinUIState_ == SIGNIN_UI_STATE.ENROLLMENT);
318 var accountPickerIsActive =
319 (this.signinUIState_ == SIGNIN_UI_STATE.ACCOUNT_PICKER);
320 var supervisedUserCreationDialogIsActive =
321 (this.signinUIState_ ==
322 SIGNIN_UI_STATE.SUPERVISED_USER_CREATION_FLOW);
323 var wrongHWIDWarningIsActive =
324 (this.signinUIState_ == SIGNIN_UI_STATE.WRONG_HWID_WARNING);
325 var isSamlPasswordConfirm =
326 (this.signinUIState_ == SIGNIN_UI_STATE.SAML_PASSWORD_CONFIRM);
327 var isEnrollingConsumerManagement = (this.signinUIState_ ==
328 SIGNIN_UI_STATE.CONSUMER_MANAGEMENT_ENROLLMENT);
329 var isPasswordChangedUI =
330 (this.signinUIState_ == SIGNIN_UI_STATE.PASSWORD_CHANGED);
331 var isMultiProfilesUI =
332 (Oobe.getInstance().displayType == DISPLAY_TYPE.USER_ADDING);
333 var isLockScreen =
334 (Oobe.getInstance().displayType == DISPLAY_TYPE.LOCK);
335 var isNewGaiaScreenWithBackButton =
336 gaiaIsActive &&
337 this.isNewGaiaFlow_ &&
338 !($('back-button-item').hidden);
339 var supervisedUserCreationDialogIsActiveAndNotIntro =
340 supervisedUserCreationDialogIsActive &&
341 $('supervised-user-creation').currentPage_ != 'intro';
342 var errorScreenIsActive =
343 (this.signinUIState_ == SIGNIN_UI_STATE.ERROR);
345 $('add-user-button').hidden =
346 (!this.isNewGaiaFlow_ && !accountPickerIsActive) ||
347 (this.isNewGaiaFlow_ && gaiaIsActive) ||
348 enrollmentIsActive ||
349 isMultiProfilesUI ||
350 isLockScreen ||
351 supervisedUserCreationDialogIsActiveAndNotIntro ||
352 errorScreenIsActive;
353 $('more-settings-header-bar-item').hidden =
354 !this.showCreateSupervised_ ||
355 isNewGaiaScreenWithBackButton ||
356 supervisedUserCreationDialogIsActive;
357 $('cancel-add-user-button').hidden =
358 ((gaiaIsActive || isPasswordChangedUI || isSamlPasswordConfirm ||
359 errorScreenIsActive) &&
360 this.isNewGaiaFlow_) ||
361 accountPickerIsActive ||
362 !this.allowCancel_ ||
363 wrongHWIDWarningIsActive ||
364 isMultiProfilesUI ||
365 supervisedUserCreationDialogIsActive;
366 $('guest-user-header-bar-item').hidden =
367 (gaiaIsActive && !this.isNewGaiaFlow_) ||
368 supervisedUserCreationDialogIsActiveAndNotIntro ||
369 !this.showGuest_ ||
370 wrongHWIDWarningIsActive ||
371 isSamlPasswordConfirm ||
372 isMultiProfilesUI ||
373 isNewGaiaScreenWithBackButton;
374 $('restart-header-bar-item').hidden = !this.showReboot_;
375 $('shutdown-header-bar-item').hidden = !this.showShutdown_;
376 $('sign-out-user-item').hidden = !isLockScreen;
378 $('add-user-header-bar-item').hidden =
379 $('add-user-button').hidden && $('cancel-add-user-button').hidden;
380 $('apps-header-bar-item').hidden = !this.hasApps_ ||
381 (!gaiaIsActive && !accountPickerIsActive);
382 $('cancel-multiple-sign-in-item').hidden = !isMultiProfilesUI;
383 $('cancel-consumer-management-enrollment').hidden =
384 !isEnrollingConsumerManagement;
386 if (!Oobe.getInstance().newKioskUI) {
387 if (!$('apps-header-bar-item').hidden)
388 $('show-apps-button').didShow();
393 * Animates Header bar to hide from the screen.
395 * @param {function()} callback will be called once animation is finished.
397 animateOut: function(callback) {
398 var launcher = this;
399 launcher.addEventListener(
400 'webkitTransitionEnd', function f(e) {
401 launcher.removeEventListener('webkitTransitionEnd', f);
402 callback();
404 // Guard timer for 2 seconds + 200 ms + epsilon.
405 ensureTransitionEndEvent(launcher, 2250);
407 this.classList.remove('login-header-bar-animate-slow');
408 this.classList.add('login-header-bar-animate-fast');
409 this.classList.add('login-header-bar-hidden');
413 * Animates Header bar to appear on the screen.
415 * @param {boolean} fast Whether the animation should complete quickly or
416 * slowly.
417 * @param {function()} callback will be called once animation is finished.
419 animateIn: function(fast, callback) {
420 if (callback) {
421 var launcher = this;
422 launcher.addEventListener(
423 'webkitTransitionEnd', function f(e) {
424 launcher.removeEventListener('webkitTransitionEnd', f);
425 callback();
427 // Guard timer for 2 seconds + 200 ms + epsilon.
428 ensureTransitionEndEvent(launcher, 2250);
431 if (fast) {
432 this.classList.remove('login-header-bar-animate-slow');
433 this.classList.add('login-header-bar-animate-fast');
434 } else {
435 this.classList.remove('login-header-bar-animate-fast');
436 this.classList.add('login-header-bar-animate-slow');
439 this.classList.remove('login-header-bar-hidden');
444 * Convenience wrapper of animateOut.
446 HeaderBar.animateOut = function(callback) {
447 $('login-header-bar').animateOut(callback);
451 * Convenience wrapper of animateIn.
453 HeaderBar.animateIn = function(fast, callback) {
454 $('login-header-bar').animateIn(fast, callback);
457 return {
458 HeaderBar: HeaderBar