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 // Current UI state of the sign-in screen.
25 signinUIState_: SIGNIN_UI_STATE.HIDDEN,
27 // Whether to show kiosk apps menu.
31 decorate: function() {
32 $('shutdown-header-bar-item').addEventListener('click',
33 this.handleShutdownClick_);
34 $('shutdown-button').addEventListener('click',
35 this.handleShutdownClick_);
36 $('add-user-button').addEventListener('click',
37 this.handleAddUserClick_);
38 $('cancel-add-user-button').addEventListener('click',
39 this.handleCancelAddUserClick_);
40 $('guest-user-header-bar-item').addEventListener('click',
41 this.handleGuestClick_);
42 $('guest-user-button').addEventListener('click',
43 this.handleGuestClick_);
44 $('sign-out-user-button').addEventListener('click',
45 this.handleSignoutClick_);
46 $('cancel-multiple-sign-in-button').addEventListener('click',
47 this.handleCancelMultipleSignInClick_);
48 $('cancel-consumer-management-enrollment-button').addEventListener(
50 this.handleCancelConsumerManagementEnrollmentClick_);
51 if (Oobe.getInstance().displayType == DISPLAY_TYPE.LOGIN ||
52 Oobe.getInstance().displayType == DISPLAY_TYPE.OOBE) {
53 if (Oobe.getInstance().newKioskUI)
54 chrome.send('initializeKioskApps');
56 login.AppsMenuButton.decorate($('show-apps-button'));
62 * Tab index value for all button elements.
66 set buttonsTabIndex(tabIndex) {
67 var buttons = this.getElementsByTagName('button');
68 for (var i = 0, button; button = buttons[i]; ++i) {
69 button.tabIndex = tabIndex;
74 * Disables the header bar and all of its elements.
79 var buttons = this.getElementsByTagName('button');
80 for (var i = 0, button; button = buttons[i]; ++i)
81 if (!button.classList.contains('button-restricted'))
82 button.disabled = value;
86 * Add user button click handler.
90 handleAddUserClick_: function(e) {
92 // Prevent further propagation of click event. Otherwise, the click event
93 // handler of document object will set wallpaper to user's wallpaper when
94 // there is only one existing user. See http://crbug.com/166477
99 * Cancel add user button click handler.
103 handleCancelAddUserClick_: function(e) {
104 // Let screen handle cancel itself if that is capable of doing so.
105 if (Oobe.getInstance().currentScreen &&
106 Oobe.getInstance().currentScreen.cancel) {
107 Oobe.getInstance().currentScreen.cancel();
111 $('pod-row').loadLastWallpaper();
113 Oobe.showScreen({id: SCREEN_ACCOUNT_PICKER});
114 Oobe.resetSigninUI(true);
118 * Guest button click handler.
122 handleGuestClick_: function(e) {
123 Oobe.disableSigninUI();
124 chrome.send('launchIncognito');
129 * Sign out button click handler.
133 handleSignoutClick_: function(e) {
134 this.disabled = true;
135 chrome.send('signOutUser');
140 * Shutdown button click handler.
144 handleShutdownClick_: function(e) {
145 chrome.send('shutdownSystem');
150 * Cancel user adding button handler.
154 handleCancelMultipleSignInClick_: function(e) {
155 chrome.send('cancelUserAdding');
160 * Cancel consumer management enrollment button handler.
164 handleCancelConsumerManagementEnrollmentClick_: function(e) {
165 chrome.send('cancelConsumerManagementEnrollment');
170 * If true then "Browse as Guest" button is shown.
174 set showGuestButton(value) {
175 this.showGuest_ = value;
180 * Current header bar UI / sign in state.
182 * @type {number} state Current state of the sign-in screen (see
185 get signinUIState() {
186 return this.signinUIState_;
188 set signinUIState(state) {
189 this.signinUIState_ = state;
194 * Whether the Cancel button is enabled during Gaia sign-in.
198 set allowCancel(value) {
199 this.allowCancel_ = value;
204 * Update whether there are kiosk apps.
209 this.hasApps_ = value;
214 * Updates visibility state of action buttons.
218 updateUI_: function() {
219 var gaiaIsActive = (this.signinUIState_ == SIGNIN_UI_STATE.GAIA_SIGNIN);
220 var accountPickerIsActive =
221 (this.signinUIState_ == SIGNIN_UI_STATE.ACCOUNT_PICKER);
222 var supervisedUserCreationDialogIsActive =
223 (this.signinUIState_ ==
224 SIGNIN_UI_STATE.SUPERVISED_USER_CREATION_FLOW);
225 var wrongHWIDWarningIsActive =
226 (this.signinUIState_ == SIGNIN_UI_STATE.WRONG_HWID_WARNING);
227 var isSamlPasswordConfirm =
228 (this.signinUIState_ == SIGNIN_UI_STATE.SAML_PASSWORD_CONFIRM);
229 var isEnrollingConsumerManagement = (this.signinUIState_ ==
230 SIGNIN_UI_STATE.CONSUMER_MANAGEMENT_ENROLLMENT);
231 var isMultiProfilesUI =
232 (Oobe.getInstance().displayType == DISPLAY_TYPE.USER_ADDING);
234 (Oobe.getInstance().displayType == DISPLAY_TYPE.LOCK);
236 $('add-user-button').hidden =
237 !accountPickerIsActive || isMultiProfilesUI || isLockScreen;
238 $('cancel-add-user-button').hidden = accountPickerIsActive ||
239 !this.allowCancel_ ||
240 wrongHWIDWarningIsActive ||
242 $('guest-user-header-bar-item').hidden = gaiaIsActive ||
243 supervisedUserCreationDialogIsActive ||
245 wrongHWIDWarningIsActive ||
246 isSamlPasswordConfirm ||
248 $('sign-out-user-item').hidden = !isLockScreen;
250 $('add-user-header-bar-item').hidden =
251 $('add-user-button').hidden && $('cancel-add-user-button').hidden;
252 $('apps-header-bar-item').hidden = !this.hasApps_ ||
253 (!gaiaIsActive && !accountPickerIsActive);
254 $('cancel-multiple-sign-in-item').hidden = !isMultiProfilesUI;
255 $('cancel-consumer-management-enrollment').hidden =
256 !isEnrollingConsumerManagement;
258 if (!Oobe.getInstance().newKioskUI) {
259 if (!$('apps-header-bar-item').hidden)
260 $('show-apps-button').didShow();
265 * Animates Header bar to hide from the screen.
267 * @param {function()} callback will be called once animation is finished.
269 animateOut: function(callback) {
271 launcher.addEventListener(
272 'webkitTransitionEnd', function f(e) {
273 launcher.removeEventListener('webkitTransitionEnd', f);
276 // Guard timer for 2 seconds + 200 ms + epsilon.
277 ensureTransitionEndEvent(launcher, 2250);
279 this.classList.remove('login-header-bar-animate-slow');
280 this.classList.add('login-header-bar-animate-fast');
281 this.classList.add('login-header-bar-hidden');
285 * Animates Header bar to slowly appear on the screen.
287 * @param {function()} callback will be called once animation is finished.
289 animateIn: function(callback) {
292 launcher.addEventListener(
293 'webkitTransitionEnd', function f(e) {
294 launcher.removeEventListener('webkitTransitionEnd', f);
297 // Guard timer for 2 seconds + 200 ms + epsilon.
298 ensureTransitionEndEvent(launcher, 2250);
301 if (Oobe.getInstance().displayType == DISPLAY_TYPE.OOBE) {
302 this.classList.remove('login-header-bar-animate-slow');
303 this.classList.add('login-header-bar-animate-fast');
305 this.classList.remove('login-header-bar-animate-fast');
306 this.classList.add('login-header-bar-animate-slow');
309 this.classList.remove('login-header-bar-hidden');
314 * Convenience wrapper of animateOut.
316 HeaderBar.animateOut = function(callback) {
317 $('login-header-bar').animateOut(callback);
321 * Convenience wrapper of animateIn.
323 HeaderBar.animateIn = function(callback) {
324 $('login-header-bar').animateIn(callback);