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 isSamlPasswordConfirm
=
192 (this.signinUIState_
== SIGNIN_UI_STATE
.SAML_PASSWORD_CONFIRM
);
193 var isMultiProfilesUI
=
194 (Oobe
.getInstance().displayType
== DISPLAY_TYPE
.USER_ADDING
);
196 $('add-user-button').hidden
= !accountPickerIsActive
|| isMultiProfilesUI
;
197 $('cancel-add-user-button').hidden
= accountPickerIsActive
||
198 !this.allowCancel_
||
199 wrongHWIDWarningIsActive
||
201 $('guest-user-header-bar-item').hidden
= gaiaIsActive
||
202 managedUserCreationDialogIsActive
||
204 wrongHWIDWarningIsActive
||
205 isSamlPasswordConfirm
||
207 $('add-user-header-bar-item').hidden
=
208 $('add-user-button').hidden
&& $('cancel-add-user-button').hidden
;
209 $('apps-header-bar-item').hidden
= !this.hasApps_
||
210 (!gaiaIsActive
&& !accountPickerIsActive
);
211 $('cancel-multiple-sign-in-item').hidden
= !isMultiProfilesUI
;
213 if (!$('apps-header-bar-item').hidden
)
214 $('show-apps-button').didShow();
218 * Animates Header bar to hide from the screen.
219 * @param {function()} callback will be called once animation is finished.
221 animateOut: function(callback
) {
223 launcher
.addEventListener(
224 'webkitTransitionEnd', function f(e
) {
225 launcher
.removeEventListener('webkitTransitionEnd', f
);
228 // Guard timer for 2 seconds + 200 ms + epsilon.
229 ensureTransitionEndEvent(launcher
, 2250);
231 this.classList
.remove('login-header-bar-animate-slow');
232 this.classList
.add('login-header-bar-animate-fast');
233 this.classList
.add('login-header-bar-hidden');
237 * Animates Header bar to slowly appear on the screen.
239 animateIn: function() {
240 this.classList
.remove('login-header-bar-animate-fast');
241 this.classList
.add('login-header-bar-animate-slow');
242 this.classList
.remove('login-header-bar-hidden');
247 * Convenience wrapper of animateOut.
249 HeaderBar
.animateOut = function(callback
) {
250 $('login-header-bar').animateOut(callback
);
254 * Convenience wrapper of animateIn.
256 HeaderBar
.animateIn = function() {
257 $('login-header-bar').animateIn();