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.
13 * @extends {HTMLDivElement}
15 var HeaderBar = cr.ui.define('div');
17 HeaderBar.prototype = {
18 __proto__: HTMLDivElement.prototype,
20 // Whether guest button should be shown when header bar is in normal mode.
23 // Current UI state of the sign-in screen.
24 signinUIState_: SIGNIN_UI_STATE.HIDDEN,
26 // Whether to show kiosk apps menu.
30 decorate: function() {
31 $('shutdown-header-bar-item').addEventListener('click',
32 this.handleShutdownClick_);
33 $('shutdown-button').addEventListener('click',
34 this.handleShutdownClick_);
35 $('add-user-button').addEventListener('click',
36 this.handleAddUserClick_);
37 $('cancel-add-user-button').addEventListener('click',
38 this.handleCancelAddUserClick_);
39 $('guest-user-header-bar-item').addEventListener('click',
40 this.handleGuestClick_);
41 $('guest-user-button').addEventListener('click',
42 this.handleGuestClick_);
43 $('sign-out-user-button').addEventListener('click',
44 this.handleSignoutClick_);
45 $('cancel-multiple-sign-in-button').addEventListener('click',
46 this.handleCancelMultipleSignInClick_);
47 if (Oobe.getInstance().displayType == DISPLAY_TYPE.LOGIN ||
48 Oobe.getInstance().displayType == DISPLAY_TYPE.OOBE)
49 login.AppsMenuButton.decorate($('show-apps-button'));
53 * Tab index value for all button elements.
56 set buttonsTabIndex(tabIndex) {
57 var buttons = this.getElementsByTagName('button');
58 for (var i = 0, button; button = buttons[i]; ++i) {
59 button.tabIndex = tabIndex;
64 * Disables the header bar and all of its elements.
68 var buttons = this.getElementsByTagName('button');
69 for (var i = 0, button; button = buttons[i]; ++i)
70 if (!button.classList.contains('button-restricted'))
71 button.disabled = value;
75 * Add user button click handler.
78 handleAddUserClick_: function(e) {
80 // Prevent further propagation of click event. Otherwise, the click event
81 // handler of document object will set wallpaper to user's wallpaper when
82 // there is only one existing user. See http://crbug.com/166477
87 * Cancel add user button click handler.
90 handleCancelAddUserClick_: function(e) {
91 // Let screen handle cancel itself if that is capable of doing so.
92 if (Oobe.getInstance().currentScreen &&
93 Oobe.getInstance().currentScreen.cancel) {
94 Oobe.getInstance().currentScreen.cancel();
98 $('pod-row').loadLastWallpaper();
100 Oobe.showScreen({id: SCREEN_ACCOUNT_PICKER});
101 Oobe.resetSigninUI(true);
105 * Guest button click handler.
108 handleGuestClick_: function(e) {
109 Oobe.disableSigninUI();
110 chrome.send('launchIncognito');
115 * Sign out button click handler.
118 handleSignoutClick_: function(e) {
119 this.disabled = true;
120 chrome.send('signOutUser');
125 * Shutdown button click handler.
128 handleShutdownClick_: function(e) {
129 chrome.send('shutdownSystem');
134 * Cancel user adding button handler.
137 handleCancelMultipleSignInClick_: function(e) {
138 chrome.send('cancelUserAdding');
143 * If true then "Browse as Guest" button is shown.
146 set showGuestButton(value) {
147 this.showGuest_ = value;
152 * Update current header bar UI.
153 * @type {number} state Current state of the sign-in screen
154 * (see SIGNIN_UI_STATE).
156 set signinUIState(state) {
157 this.signinUIState_ = state;
162 * Whether the Cancel button is enabled during Gaia sign-in.
165 set allowCancel(value) {
166 this.allowCancel_ = value;
171 * Update whether there are kiosk apps.
175 this.hasApps_ = value;
180 * Updates visibility state of action buttons.
183 updateUI_: function() {
184 var gaiaIsActive = (this.signinUIState_ == SIGNIN_UI_STATE.GAIA_SIGNIN);
185 var accountPickerIsActive =
186 (this.signinUIState_ == SIGNIN_UI_STATE.ACCOUNT_PICKER);
187 var managedUserCreationDialogIsActive =
188 (this.signinUIState_ == SIGNIN_UI_STATE.MANAGED_USER_CREATION_FLOW);
189 var wrongHWIDWarningIsActive =
190 (this.signinUIState_ == SIGNIN_UI_STATE.WRONG_HWID_WARNING);
191 var isMultiProfilesUI =
192 (Oobe.getInstance().displayType == DISPLAY_TYPE.USER_ADDING);
194 $('add-user-button').hidden = !accountPickerIsActive || isMultiProfilesUI;
195 $('cancel-add-user-button').hidden = accountPickerIsActive ||
196 !this.allowCancel_ ||
197 wrongHWIDWarningIsActive ||
199 $('guest-user-header-bar-item').hidden = gaiaIsActive ||
200 managedUserCreationDialogIsActive ||
202 wrongHWIDWarningIsActive ||
204 $('add-user-header-bar-item').hidden =
205 $('add-user-button').hidden && $('cancel-add-user-button').hidden;
206 $('apps-header-bar-item').hidden = !this.hasApps_ ||
207 (!gaiaIsActive && !accountPickerIsActive);
208 $('cancel-multiple-sign-in-item').hidden = !isMultiProfilesUI;
210 if (!$('apps-header-bar-item').hidden)
211 $('show-apps-button').didShow();
215 * Animates Header bar to hide from the screen.
216 * @param {function()} callback will be called once animation is finished.
218 animateOut: function(callback) {
220 launcher.addEventListener(
221 'webkitTransitionEnd', function f(e) {
222 launcher.removeEventListener('webkitTransitionEnd', f);
225 // Guard timer for 2 seconds + 200 ms + epsilon.
226 ensureTransitionEndEvent(launcher, 2250);
228 this.classList.remove('login-header-bar-animate-slow');
229 this.classList.add('login-header-bar-animate-fast');
230 this.classList.add('login-header-bar-hidden');
234 * Animates Header bar to slowly appear on the screen.
236 animateIn: function() {
237 this.classList.remove('login-header-bar-animate-fast');
238 this.classList.add('login-header-bar-animate-slow');
239 this.classList.remove('login-header-bar-hidden');
244 * Convenience wrapper of animateOut.
246 HeaderBar.animateOut = function(callback) {
247 $('login-header-bar').animateOut(callback);
251 * Convenience wrapper of animateIn.
253 HeaderBar.animateIn = function() {
254 $('login-header-bar').animateIn();