OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview Display manager for WebUI OOBE and login. | 6 * @fileoverview Display manager for WebUI OOBE and login. |
7 */ | 7 */ |
8 | 8 |
9 // TODO(xiyuan): Find a better to share those constants. | 9 // TODO(xiyuan): Find a better to share those constants. |
10 const SCREEN_SIGNIN = 'signin'; | |
11 const SCREEN_GAIA_SIGNIN = 'gaia-signin'; | 10 const SCREEN_GAIA_SIGNIN = 'gaia-signin'; |
12 const SCREEN_ACCOUNT_PICKER = 'account-picker'; | 11 const SCREEN_ACCOUNT_PICKER = 'account-picker'; |
13 | 12 |
14 /* Accelerator identifiers. Must be kept in sync with webui_login_view.cc. */ | 13 /* Accelerator identifiers. Must be kept in sync with webui_login_view.cc. */ |
15 const ACCELERATOR_ACCESSIBILITY = 'accessibility'; | 14 const ACCELERATOR_ACCESSIBILITY = 'accessibility'; |
16 const ACCELERATOR_CANCEL = 'cancel'; | 15 const ACCELERATOR_CANCEL = 'cancel'; |
17 const ACCELERATOR_ENROLLMENT = 'enrollment'; | 16 const ACCELERATOR_ENROLLMENT = 'enrollment'; |
18 const ACCELERATOR_EXIT = 'exit'; | 17 const ACCELERATOR_EXIT = 'exit'; |
19 const ACCELERATOR_VERSION = 'version'; | 18 const ACCELERATOR_VERSION = 'version'; |
20 | 19 |
21 cr.define('cr.ui.login', function() { | 20 cr.define('cr.ui.login', function() { |
| 21 var Bubble = cr.ui.Bubble; |
| 22 |
22 /** | 23 /** |
23 * Constructor a display manager that manages initialization of screens, | 24 * Constructor a display manager that manages initialization of screens, |
24 * transitions, error messages display. | 25 * transitions, error messages display. |
25 * | 26 * |
26 * @constructor | 27 * @constructor |
27 */ | 28 */ |
28 function DisplayManager() { | 29 function DisplayManager() { |
29 } | 30 } |
30 | 31 |
31 DisplayManager.prototype = { | 32 DisplayManager.prototype = { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 */ | 79 */ |
79 handleAccelerator: function(name) { | 80 handleAccelerator: function(name) { |
80 if (name == ACCELERATOR_ACCESSIBILITY) { | 81 if (name == ACCELERATOR_ACCESSIBILITY) { |
81 chrome.send('toggleAccessibility', []); | 82 chrome.send('toggleAccessibility', []); |
82 } else if (name == ACCELERATOR_CANCEL) { | 83 } else if (name == ACCELERATOR_CANCEL) { |
83 if (this.currentScreen.cancel) { | 84 if (this.currentScreen.cancel) { |
84 this.currentScreen.cancel(); | 85 this.currentScreen.cancel(); |
85 } | 86 } |
86 } else if (name == ACCELERATOR_ENROLLMENT) { | 87 } else if (name == ACCELERATOR_ENROLLMENT) { |
87 var currentStepId = this.screens_[this.currentStep_]; | 88 var currentStepId = this.screens_[this.currentStep_]; |
88 if (currentStepId == SCREEN_SIGNIN || | 89 if (currentStepId == SCREEN_GAIA_SIGNIN) |
89 currentStepId == SCREEN_GAIA_SIGNIN) { | |
90 chrome.send('toggleEnrollmentScreen', []); | 90 chrome.send('toggleEnrollmentScreen', []); |
91 } | |
92 } else if (name == ACCELERATOR_EXIT) { | 91 } else if (name == ACCELERATOR_EXIT) { |
93 if (this.currentScreen.exit) { | 92 if (this.currentScreen.exit) { |
94 this.currentScreen.exit(); | 93 this.currentScreen.exit(); |
95 } | 94 } |
96 } else if (name == ACCELERATOR_VERSION) { | 95 } else if (name == ACCELERATOR_VERSION) { |
97 if (this.allowToggleVersion_) | 96 if (this.allowToggleVersion_) |
98 $('version-labels').hidden = !$('version-labels').hidden; | 97 $('version-labels').hidden = !$('version-labels').hidden; |
99 } | 98 } |
100 }, | 99 }, |
101 | 100 |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 var y = 0; | 302 var y = 0; |
304 while (element && !isNaN(element.offsetLeft) && !isNaN(element.offsetTop)) { | 303 while (element && !isNaN(element.offsetLeft) && !isNaN(element.offsetTop)) { |
305 x += element.offsetLeft - element.scrollLeft; | 304 x += element.offsetLeft - element.scrollLeft; |
306 y += element.offsetTop - element.scrollTop; | 305 y += element.offsetTop - element.scrollTop; |
307 element = element.offsetParent; | 306 element = element.offsetParent; |
308 } | 307 } |
309 return { top: y, left: x }; | 308 return { top: y, left: x }; |
310 }; | 309 }; |
311 | 310 |
312 /** | 311 /** |
| 312 * Returns position (top, left, right, bottom) of the element. |
| 313 * @param {!Element} element HTML element. |
| 314 * @return {!Object} Element position (top, left, right, bottom). |
| 315 */ |
| 316 DisplayManager.getPosition = function(element) { |
| 317 var offset = DisplayManager.getOffset(element); |
| 318 return { top: offset.top, |
| 319 right: window.innerWidth - element.offsetWidth - offset.left, |
| 320 bottom: window.innerHeight - element.offsetHeight - offset.top, |
| 321 left: offset.left }; |
| 322 }; |
| 323 |
| 324 /** |
313 * Disables signin UI. | 325 * Disables signin UI. |
314 */ | 326 */ |
315 DisplayManager.disableSigninUI = function() { | 327 DisplayManager.disableSigninUI = function() { |
316 $('login-header-bar').disabled = true; | 328 $('login-header-bar').disabled = true; |
317 $('pod-row').disabled = true; | 329 $('pod-row').disabled = true; |
318 }; | 330 }; |
319 | 331 |
320 /** | 332 /** |
321 * Shows signin UI. | 333 * Shows signin UI. |
322 * @param {string} opt_email An optional email for signin UI. | 334 * @param {string} opt_email An optional email for signin UI. |
(...skipping 20 matching lines...) Expand all Loading... |
343 | 355 |
344 /** | 356 /** |
345 * Shows sign-in error bubble. | 357 * Shows sign-in error bubble. |
346 * @param {number} loginAttempts Number of login attemps tried. | 358 * @param {number} loginAttempts Number of login attemps tried. |
347 * @param {string} message Error message to show. | 359 * @param {string} message Error message to show. |
348 * @param {string} link Text to use for help link. | 360 * @param {string} link Text to use for help link. |
349 * @param {number} helpId Help topic Id associated with help link. | 361 * @param {number} helpId Help topic Id associated with help link. |
350 */ | 362 */ |
351 DisplayManager.showSignInError = function(loginAttempts, message, link, | 363 DisplayManager.showSignInError = function(loginAttempts, message, link, |
352 helpId) { | 364 helpId) { |
353 var currentScreenId = Oobe.getInstance().currentScreen.id; | |
354 var anchor = undefined; | |
355 var anchorPos = undefined; | |
356 if (currentScreenId == SCREEN_SIGNIN) { | |
357 anchor = $('email'); | |
358 | |
359 // Show email field so that bubble shows up at the right location. | |
360 $(SCREEN_SIGNIN).reset(true); | |
361 } else if (currentScreenId == SCREEN_GAIA_SIGNIN) { | |
362 if ($(SCREEN_GAIA_SIGNIN).isLocal) { | |
363 $('add-user-button').hidden = true; | |
364 $('cancel-add-user-button').hidden = false; | |
365 // Reload offline version of the sign-in extension, which will show | |
366 // error itself. | |
367 chrome.send('offlineLogin', [$(SCREEN_GAIA_SIGNIN).email]); | |
368 return; | |
369 } | |
370 // Use anchorPos since we won't be able to get the input fields of Gaia. | |
371 anchorPos = DisplayManager.getOffset(Oobe.getInstance().currentScreen); | |
372 | |
373 // Ideally, we should just use | |
374 // anchorPos = DisplayManager.getOffset($('signin-frame')); | |
375 // to get a good anchor point. However, this always gives (0,0) on | |
376 // the device. | |
377 // TODO(xiyuan): Figure out why the above fails and get rid of this. | |
378 anchorPos.left += 150; // (640 - 340) / 2 | |
379 | |
380 // TODO(xiyuan): Find a reliable way to align with Gaia UI. | |
381 anchorPos.left += 60; | |
382 anchorPos.top += 105; | |
383 } else if (currentScreenId == SCREEN_ACCOUNT_PICKER && | |
384 $('pod-row').activatedPod) { | |
385 const MAX_LOGIN_ATTEMMPTS_IN_POD = 3; | |
386 if (loginAttempts > MAX_LOGIN_ATTEMMPTS_IN_POD) { | |
387 $('pod-row').activatedPod.showSigninUI(); | |
388 return; | |
389 } | |
390 | |
391 anchor = $('pod-row').activatedPod.mainInput; | |
392 } | |
393 if (!anchor && !anchorPos) { | |
394 console.log('Warning: Failed to find anchor for error :' + | |
395 message); | |
396 return; | |
397 } | |
398 | |
399 var error = document.createElement('div'); | 365 var error = document.createElement('div'); |
400 | 366 |
401 var messageDiv = document.createElement('div'); | 367 var messageDiv = document.createElement('div'); |
402 messageDiv.className = 'error-message'; | 368 messageDiv.className = 'error-message'; |
403 messageDiv.textContent = message; | 369 messageDiv.textContent = message; |
404 error.appendChild(messageDiv); | 370 error.appendChild(messageDiv); |
405 | 371 |
406 if (link) { | 372 if (link) { |
407 messageDiv.classList.add('error-message-padding'); | 373 messageDiv.classList.add('error-message-padding'); |
408 | 374 |
409 var helpLink = document.createElement('a'); | 375 var helpLink = document.createElement('a'); |
410 helpLink.href = '#'; | 376 helpLink.href = '#'; |
411 helpLink.textContent = link; | 377 helpLink.textContent = link; |
412 helpLink.onclick = function(e) { | 378 helpLink.addEventListener('click', function(e) { |
413 chrome.send('launchHelpApp', [helpId]); | 379 chrome.send('launchHelpApp', [helpId]); |
414 }; | 380 e.preventDefault(); |
| 381 }); |
415 error.appendChild(helpLink); | 382 error.appendChild(helpLink); |
416 } | 383 } |
417 | 384 |
418 if (anchor) | 385 var currentScreenId = Oobe.getInstance().currentScreen.id; |
419 $('bubble').showContentForElement(anchor, error); | 386 $(currentScreenId).showErrorBubble(loginAttempts, error); |
420 else if (anchorPos) | |
421 $('bubble').showContentAt(anchorPos.left, anchorPos.top, error); | |
422 }; | 387 }; |
423 | 388 |
424 /** | 389 /** |
425 * Clears error bubble. | 390 * Clears error bubble. |
426 */ | 391 */ |
427 DisplayManager.clearErrors = function() { | 392 DisplayManager.clearErrors = function() { |
428 $('bubble').hide(); | 393 $('bubble').hide(); |
429 }; | 394 }; |
430 | 395 |
431 /** | 396 /** |
432 * Sets text content for a div with |labelId|. | 397 * Sets text content for a div with |labelId|. |
433 * @param {string} labelId Id of the label div. | 398 * @param {string} labelId Id of the label div. |
434 * @param {string} labelText Text for the label. | 399 * @param {string} labelText Text for the label. |
435 */ | 400 */ |
436 DisplayManager.setLabelText = function(labelId, labelText) { | 401 DisplayManager.setLabelText = function(labelId, labelText) { |
437 $(labelId).textContent = labelText; | 402 $(labelId).textContent = labelText; |
438 }; | 403 }; |
439 | 404 |
440 // Export | 405 // Export |
441 return { | 406 return { |
442 DisplayManager: DisplayManager | 407 DisplayManager: DisplayManager |
443 }; | 408 }; |
444 }); | 409 }); |
OLD | NEW |