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