| OLD | NEW |
| (Empty) | |
| 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. |
| 4 |
| 5 /** |
| 6 * @fileoverview Login UI header bar implementation. |
| 7 */ |
| 8 |
| 9 cr.define('login', function() { |
| 10 /** |
| 11 * Creates a header bar element. |
| 12 * |
| 13 * @constructor |
| 14 * @extends {HTMLDivElement} |
| 15 */ |
| 16 var HeaderBar = cr.ui.define('div'); |
| 17 |
| 18 HeaderBar.prototype = { |
| 19 __proto__: HTMLDivElement.prototype, |
| 20 |
| 21 // Whether guest button should be shown when header bar is in normal mode. |
| 22 showGuest_: false, |
| 23 |
| 24 // Whether the reboot button should be shown the when header bar is in |
| 25 // normal mode. |
| 26 showReboot_: false, |
| 27 |
| 28 // Whether the shutdown button should be shown when the header bar is in |
| 29 // normal mode. |
| 30 showShutdown_: true, |
| 31 |
| 32 // Whether the create supervised user button should be shown when the header |
| 33 // bar is in normal mode. It will be shown in "More settings" menu. |
| 34 showCreateSupervised_: false, |
| 35 |
| 36 // Current UI state of the sign-in screen. |
| 37 signinUIState_: SIGNIN_UI_STATE.HIDDEN, |
| 38 |
| 39 // Whether to show kiosk apps menu. |
| 40 hasApps_: false, |
| 41 |
| 42 /** @override */ |
| 43 decorate: function() { |
| 44 document.addEventListener('click', this.handleClick_.bind(this)); |
| 45 $('shutdown-header-bar-item') |
| 46 .addEventListener('click', this.handleShutdownClick_); |
| 47 $('shutdown-button').addEventListener('click', this.handleShutdownClick_); |
| 48 $('restart-header-bar-item') |
| 49 .addEventListener('click', this.handleShutdownClick_); |
| 50 $('restart-button').addEventListener('click', this.handleShutdownClick_); |
| 51 $('add-user-button').addEventListener('click', this.handleAddUserClick_); |
| 52 $('more-settings-button') |
| 53 .addEventListener('click', this.handleMoreSettingsClick_.bind(this)); |
| 54 $('guest-user-header-bar-item') |
| 55 .addEventListener('click', this.handleGuestClick_); |
| 56 $('guest-user-button').addEventListener('click', this.handleGuestClick_); |
| 57 $('sign-out-user-button') |
| 58 .addEventListener('click', this.handleSignoutClick_); |
| 59 $('cancel-multiple-sign-in-button') |
| 60 .addEventListener('click', this.handleCancelMultipleSignInClick_); |
| 61 this.addSupervisedUserMenu.addEventListener( |
| 62 'click', this.handleAddSupervisedUserClick_.bind(this)); |
| 63 this.addSupervisedUserMenu.addEventListener( |
| 64 'keydown', this.handleAddSupervisedUserKeyDown_.bind(this)); |
| 65 if (Oobe.getInstance().displayType == DISPLAY_TYPE.LOGIN || |
| 66 Oobe.getInstance().displayType == DISPLAY_TYPE.OOBE) { |
| 67 if (Oobe.getInstance().newKioskUI) |
| 68 chrome.send('initializeKioskApps'); |
| 69 else |
| 70 login.AppsMenuButton.decorate($('show-apps-button')); |
| 71 } |
| 72 this.updateUI_(); |
| 73 }, |
| 74 |
| 75 /** |
| 76 * Tab index value for all button elements. |
| 77 * |
| 78 * @type {number} |
| 79 */ |
| 80 set buttonsTabIndex(tabIndex) { |
| 81 var buttons = this.getElementsByTagName('button'); |
| 82 for (var i = 0, button; button = buttons[i]; ++i) { |
| 83 button.tabIndex = tabIndex; |
| 84 } |
| 85 }, |
| 86 |
| 87 /** |
| 88 * Disables the header bar and all of its elements. |
| 89 * |
| 90 * @type {boolean} |
| 91 */ |
| 92 set disabled(value) { |
| 93 var buttons = this.getElementsByTagName('button'); |
| 94 for (var i = 0, button; button = buttons[i]; ++i) |
| 95 if (!button.classList.contains('button-restricted')) |
| 96 button.disabled = value; |
| 97 }, |
| 98 |
| 99 get getMoreSettingsMenu() { |
| 100 return $('more-settings-header-bar-item'); |
| 101 }, |
| 102 |
| 103 get addSupervisedUserMenu() { |
| 104 return this.querySelector('.add-supervised-user-menu'); |
| 105 }, |
| 106 |
| 107 /** |
| 108 * Whether action box button is in active state. |
| 109 * @type {boolean} |
| 110 */ |
| 111 get isMoreSettingsActive() { |
| 112 return this.getMoreSettingsMenu.classList.contains('active'); |
| 113 }, |
| 114 set isMoreSettingsActive(active) { |
| 115 if (active == this.isMoreSettingsActive) |
| 116 return; |
| 117 this.getMoreSettingsMenu.classList.toggle('active', active); |
| 118 $('more-settings-button').tabIndex = active ? -1 : 0; |
| 119 }, |
| 120 |
| 121 /** |
| 122 * Add user button click handler. |
| 123 * |
| 124 * @private |
| 125 */ |
| 126 handleAddUserClick_: function(e) { |
| 127 Oobe.showSigninUI(); |
| 128 // Prevent further propagation of click event. Otherwise, the click event |
| 129 // handler of document object will set wallpaper to user's wallpaper when |
| 130 // there is only one existing user. See http://crbug.com/166477 |
| 131 e.stopPropagation(); |
| 132 }, |
| 133 |
| 134 handleMoreSettingsClick_: function(e) { |
| 135 this.isMoreSettingsActive = !this.isMoreSettingsActive; |
| 136 this.addSupervisedUserMenu.focus(); |
| 137 e.stopPropagation(); |
| 138 }, |
| 139 |
| 140 handleClick_: function(e) { |
| 141 this.isMoreSettingsActive = false; |
| 142 }, |
| 143 |
| 144 /** |
| 145 * Cancel add user button click handler. |
| 146 * |
| 147 * @private |
| 148 */ |
| 149 handleCancelAddUserClick_: function(e) { |
| 150 // Let screen handle cancel itself if that is capable of doing so. |
| 151 if (Oobe.getInstance().currentScreen && |
| 152 Oobe.getInstance().currentScreen.cancel) { |
| 153 Oobe.getInstance().currentScreen.cancel(); |
| 154 return; |
| 155 } |
| 156 |
| 157 Oobe.showUserPods(); |
| 158 }, |
| 159 |
| 160 /** |
| 161 * Guest button click handler. |
| 162 * |
| 163 * @private |
| 164 */ |
| 165 handleGuestClick_: function(e) { |
| 166 Oobe.disableSigninUI(); |
| 167 chrome.send('launchIncognito'); |
| 168 e.stopPropagation(); |
| 169 }, |
| 170 |
| 171 /** |
| 172 * Sign out button click handler. |
| 173 * |
| 174 * @private |
| 175 */ |
| 176 handleSignoutClick_: function(e) { |
| 177 this.disabled = true; |
| 178 chrome.send('signOutUser'); |
| 179 e.stopPropagation(); |
| 180 }, |
| 181 |
| 182 /** |
| 183 * Shutdown button click handler. |
| 184 * |
| 185 * @private |
| 186 */ |
| 187 handleShutdownClick_: function(e) { |
| 188 chrome.send('shutdownSystem'); |
| 189 e.stopPropagation(); |
| 190 }, |
| 191 |
| 192 /** |
| 193 * Cancel user adding button handler. |
| 194 * |
| 195 * @private |
| 196 */ |
| 197 handleCancelMultipleSignInClick_: function(e) { |
| 198 chrome.send('cancelUserAdding'); |
| 199 e.stopPropagation(); |
| 200 }, |
| 201 |
| 202 /** |
| 203 * Add supervised user button handler. |
| 204 * |
| 205 * @private |
| 206 */ |
| 207 handleAddSupervisedUserClick_: function(e) { |
| 208 chrome.send('showSupervisedUserCreationScreen'); |
| 209 e.preventDefault(); |
| 210 }, |
| 211 |
| 212 /** |
| 213 * Add supervised user key handler, ESC closes menu. |
| 214 * |
| 215 * @private |
| 216 */ |
| 217 handleAddSupervisedUserKeyDown_: function(e) { |
| 218 if (e.key == 'Escape' && this.isMoreSettingsActive) { |
| 219 this.isMoreSettingsActive = false; |
| 220 $('more-settings-button').focus(); |
| 221 } |
| 222 }, |
| 223 |
| 224 /** |
| 225 * If true then "Browse as Guest" button is shown. |
| 226 * |
| 227 * @type {boolean} |
| 228 */ |
| 229 set showGuestButton(value) { |
| 230 this.showGuest_ = value; |
| 231 this.updateUI_(); |
| 232 }, |
| 233 |
| 234 set showCreateSupervisedButton(value) { |
| 235 this.showCreateSupervised_ = value; |
| 236 this.updateUI_(); |
| 237 }, |
| 238 |
| 239 /** |
| 240 * If true the "Restart" button is shown. |
| 241 * |
| 242 * @type {boolean} |
| 243 */ |
| 244 set showRebootButton(value) { |
| 245 this.showReboot_ = value; |
| 246 this.updateUI_(); |
| 247 }, |
| 248 |
| 249 /** |
| 250 * If true the "Shutdown" button is shown. |
| 251 * |
| 252 * @type {boolean} |
| 253 */ |
| 254 set showShutdownButton(value) { |
| 255 this.showShutdown_ = value; |
| 256 this.updateUI_(); |
| 257 }, |
| 258 |
| 259 /** |
| 260 * Current header bar UI / sign in state. |
| 261 * |
| 262 * @type {number} state Current state of the sign-in screen (see |
| 263 * SIGNIN_UI_STATE). |
| 264 */ |
| 265 get signinUIState() { |
| 266 return this.signinUIState_; |
| 267 }, |
| 268 set signinUIState(state) { |
| 269 this.signinUIState_ = state; |
| 270 this.updateUI_(); |
| 271 }, |
| 272 |
| 273 /** |
| 274 * Update whether there are kiosk apps. |
| 275 * |
| 276 * @type {boolean} |
| 277 */ |
| 278 set hasApps(value) { |
| 279 this.hasApps_ = value; |
| 280 this.updateUI_(); |
| 281 }, |
| 282 |
| 283 /** |
| 284 * Updates visibility state of action buttons. |
| 285 * |
| 286 * @private |
| 287 */ |
| 288 updateUI_: function() { |
| 289 var gaiaIsActive = (this.signinUIState_ == SIGNIN_UI_STATE.GAIA_SIGNIN); |
| 290 var enrollmentIsActive = |
| 291 (this.signinUIState_ == SIGNIN_UI_STATE.ENROLLMENT); |
| 292 var accountPickerIsActive = |
| 293 (this.signinUIState_ == SIGNIN_UI_STATE.ACCOUNT_PICKER); |
| 294 var supervisedUserCreationDialogIsActive = |
| 295 (this.signinUIState_ == |
| 296 SIGNIN_UI_STATE.SUPERVISED_USER_CREATION_FLOW); |
| 297 var wrongHWIDWarningIsActive = |
| 298 (this.signinUIState_ == SIGNIN_UI_STATE.WRONG_HWID_WARNING); |
| 299 var isSamlPasswordConfirm = |
| 300 (this.signinUIState_ == SIGNIN_UI_STATE.SAML_PASSWORD_CONFIRM); |
| 301 var isPasswordChangedUI = |
| 302 (this.signinUIState_ == SIGNIN_UI_STATE.PASSWORD_CHANGED); |
| 303 var isMultiProfilesUI = |
| 304 (Oobe.getInstance().displayType == DISPLAY_TYPE.USER_ADDING); |
| 305 var isLockScreen = (Oobe.getInstance().displayType == DISPLAY_TYPE.LOCK); |
| 306 var errorScreenIsActive = (this.signinUIState_ == SIGNIN_UI_STATE.ERROR); |
| 307 |
| 308 $('add-user-button').hidden = !accountPickerIsActive || |
| 309 isMultiProfilesUI || isLockScreen || errorScreenIsActive; |
| 310 $('more-settings-header-bar-item').hidden = !this.showCreateSupervised_ || |
| 311 gaiaIsActive || isLockScreen || errorScreenIsActive || |
| 312 supervisedUserCreationDialogIsActive; |
| 313 $('guest-user-header-bar-item').hidden = !this.showGuest_ || |
| 314 isLockScreen || supervisedUserCreationDialogIsActive || |
| 315 wrongHWIDWarningIsActive || isSamlPasswordConfirm || |
| 316 isMultiProfilesUI || (gaiaIsActive && $('gaia-signin').closable) || |
| 317 (enrollmentIsActive && !$('oauth-enrollment').isAtTheBeginning()) || |
| 318 (gaiaIsActive && !$('gaia-signin').isAtTheBeginning()); |
| 319 $('restart-header-bar-item').hidden = !this.showReboot_; |
| 320 $('shutdown-header-bar-item').hidden = !this.showShutdown_; |
| 321 $('sign-out-user-item').hidden = !isLockScreen; |
| 322 |
| 323 $('add-user-header-bar-item').hidden = $('add-user-button').hidden; |
| 324 $('apps-header-bar-item').hidden = |
| 325 !this.hasApps_ || (!gaiaIsActive && !accountPickerIsActive); |
| 326 $('cancel-multiple-sign-in-item').hidden = !isMultiProfilesUI; |
| 327 |
| 328 if (!Oobe.getInstance().newKioskUI) { |
| 329 if (!$('apps-header-bar-item').hidden) |
| 330 $('show-apps-button').didShow(); |
| 331 } |
| 332 }, |
| 333 |
| 334 /** |
| 335 * Animates Header bar to hide from the screen. |
| 336 * |
| 337 * @param {function()} callback will be called once animation is finished. |
| 338 */ |
| 339 animateOut: function(callback) { |
| 340 var launcher = this; |
| 341 launcher.addEventListener('transitionend', function f(e) { |
| 342 launcher.removeEventListener('transitionend', f); |
| 343 callback(); |
| 344 }); |
| 345 // Guard timer for 2 seconds + 200 ms + epsilon. |
| 346 ensureTransitionEndEvent(launcher, 2250); |
| 347 |
| 348 this.classList.remove('login-header-bar-animate-slow'); |
| 349 this.classList.add('login-header-bar-animate-fast'); |
| 350 this.classList.add('login-header-bar-hidden'); |
| 351 }, |
| 352 |
| 353 /** |
| 354 * Animates Header bar to appear on the screen. |
| 355 * |
| 356 * @param {boolean} fast Whether the animation should complete quickly or |
| 357 * slowly. |
| 358 * @param {function()} callback will be called once animation is finished. |
| 359 */ |
| 360 animateIn: function(fast, callback) { |
| 361 if (callback) { |
| 362 var launcher = this; |
| 363 launcher.addEventListener('transitionend', function f(e) { |
| 364 launcher.removeEventListener('transitionend', f); |
| 365 callback(); |
| 366 }); |
| 367 // Guard timer for 2 seconds + 200 ms + epsilon. |
| 368 ensureTransitionEndEvent(launcher, 2250); |
| 369 } |
| 370 |
| 371 if (fast) { |
| 372 this.classList.remove('login-header-bar-animate-slow'); |
| 373 this.classList.add('login-header-bar-animate-fast'); |
| 374 } else { |
| 375 this.classList.remove('login-header-bar-animate-fast'); |
| 376 this.classList.add('login-header-bar-animate-slow'); |
| 377 } |
| 378 |
| 379 this.classList.remove('login-header-bar-hidden'); |
| 380 }, |
| 381 }; |
| 382 |
| 383 /** |
| 384 * Convenience wrapper of animateOut. |
| 385 */ |
| 386 HeaderBar.animateOut = function(callback) { |
| 387 $('login-header-bar').animateOut(callback); |
| 388 }; |
| 389 |
| 390 /** |
| 391 * Convenience wrapper of animateIn. |
| 392 */ |
| 393 HeaderBar.animateIn = function(fast, callback) { |
| 394 $('login-header-bar').animateIn(fast, callback); |
| 395 }; |
| 396 |
| 397 return {HeaderBar: HeaderBar}; |
| 398 }); |
| OLD | NEW |