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.
6 * @fileoverview Login UI header bar implementation.
9 cr.define('login', function() {
11 * Creates a header bar element.
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.
24 // Whether new Gaia flow is active.
25 isNewGaiaFlow_: false,
27 // Whether the reboot button should be shown the when header bar is in
31 // Whether the shutdown button should be shown when the header bar is in
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.
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(
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');
80 login.AppsMenuButton.decorate($('show-apps-button'));
86 * Tab index value for all button elements.
90 set buttonsTabIndex(tabIndex) {
91 var buttons = this.getElementsByTagName('button');
92 for (var i = 0, button; button = buttons[i]; ++i) {
93 button.tabIndex = tabIndex;
98 * Disables the header bar and all of its elements.
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.
121 get isMoreSettingsActive() {
122 return this.getMoreSettingsMenu.classList.contains('active');
124 set isMoreSettingsActive(active) {
125 if (active == this.isMoreSettingsActive)
128 this.getMoreSettingsMenu.classList.add('active');
130 this.getMoreSettingsMenu.classList.remove('active');
136 * Add user button click handler.
140 handleAddUserClick_: function(e) {
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
148 handleMoreSettingsClick_: function(e) {
149 this.isMoreSettingsActive = !this.isMoreSettingsActive;
150 this.addSupervisedUserMenu.focus();
154 handleClick_: function(e) {
155 this.isMoreSettingsActive = false;
158 handleAddSupervisedUserClick_: function(e) {
159 chrome.send('showSupervisedUserCreationScreen');
164 * Cancel add user button click handler.
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();
180 * Guest button click handler.
184 handleGuestClick_: function(e) {
185 Oobe.disableSigninUI();
186 chrome.send('launchIncognito');
191 * Sign out button click handler.
195 handleSignoutClick_: function(e) {
196 this.disabled = true;
197 chrome.send('signOutUser');
202 * Shutdown button click handler.
206 handleShutdownClick_: function(e) {
207 chrome.send('shutdownSystem');
212 * Cancel user adding button handler.
216 handleCancelMultipleSignInClick_: function(e) {
217 chrome.send('cancelUserAdding');
222 * Cancel consumer management enrollment button handler.
226 handleCancelConsumerManagementEnrollmentClick_: function(e) {
227 chrome.send('cancelConsumerManagementEnrollment');
232 * If true then "Browse as Guest" button is shown.
236 set showGuestButton(value) {
237 this.showGuest_ = value;
241 set newGaiaFlow(value) {
242 this.isNewGaiaFlow_ = value;
246 set showCreateSupervisedButton(value) {
247 this.showCreateSupervised_ = value;
252 * If true the "Restart" button is shown.
256 set showRebootButton(value) {
257 this.showReboot_ = value;
262 * If true the "Shutdown" button is shown.
266 set showShutdownButton(value) {
267 this.showShutdown_ = value;
272 * Current header bar UI / sign in state.
274 * @type {number} state Current state of the sign-in screen (see
277 get signinUIState() {
278 return this.signinUIState_;
280 set signinUIState(state) {
281 this.signinUIState_ = state;
286 * Whether the Cancel button is enabled during Gaia sign-in.
290 set allowCancel(value) {
291 this.allowCancel_ = value;
296 return !!this.allowCancel_;
300 * Update whether there are kiosk apps.
305 this.hasApps_ = value;
310 * Updates visibility state of action buttons.
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);
334 (Oobe.getInstance().displayType == DISPLAY_TYPE.LOCK);
335 var isNewGaiaScreenWithBackButton =
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 ||
351 supervisedUserCreationDialogIsActiveAndNotIntro ||
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 ||
365 supervisedUserCreationDialogIsActive;
366 $('guest-user-header-bar-item').hidden =
367 (gaiaIsActive && !this.isNewGaiaFlow_) ||
368 supervisedUserCreationDialogIsActiveAndNotIntro ||
370 wrongHWIDWarningIsActive ||
371 isSamlPasswordConfirm ||
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) {
399 launcher.addEventListener(
400 'webkitTransitionEnd', function f(e) {
401 launcher.removeEventListener('webkitTransitionEnd', f);
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
417 * @param {function()} callback will be called once animation is finished.
419 animateIn: function(fast, callback) {
422 launcher.addEventListener(
423 'webkitTransitionEnd', function f(e) {
424 launcher.removeEventListener('webkitTransitionEnd', f);
427 // Guard timer for 2 seconds + 200 ms + epsilon.
428 ensureTransitionEndEvent(launcher, 2250);
432 this.classList.remove('login-header-bar-animate-slow');
433 this.classList.add('login-header-bar-animate-fast');
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);