| 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 Oobe user image screen implementation. | 6 * @fileoverview Oobe user image screen implementation. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 login.createScreen('UserImageScreen', 'user-image', function() { | 9 login.createScreen('UserImageScreen', 'user-image', function() { |
| 10 var CONTEXT_KEY_IS_CAMERA_PRESENT = 'isCameraPresent'; | 10 var CONTEXT_KEY_IS_CAMERA_PRESENT = 'isCameraPresent'; |
| 11 var CONTEXT_KEY_SELECTED_IMAGE_URL = 'selectedImageURL'; | 11 var CONTEXT_KEY_SELECTED_IMAGE_URL = 'selectedImageURL'; |
| 12 var CONTEXT_KEY_PROFILE_PICTURE_DATA_URL = 'profilePictureDataURL'; | 12 var CONTEXT_KEY_PROFILE_PICTURE_DATA_URL = 'profilePictureDataURL'; |
| 13 var CONTEXT_KEY_HAS_GAIA_ACCOUNT = 'hasGaiaAccount'; |
| 13 | 14 |
| 14 var UserImagesGrid = options.UserImagesGrid; | 15 var UserImagesGrid = options.UserImagesGrid; |
| 15 var ButtonImages = UserImagesGrid.ButtonImages; | 16 var ButtonImages = UserImagesGrid.ButtonImages; |
| 16 | 17 |
| 17 return { | 18 return { |
| 18 EXTERNAL_API: [ | 19 EXTERNAL_API: [ |
| 19 'setDefaultImages', | 20 'setDefaultImages', |
| 20 'hideCurtain' | 21 'hideCurtain' |
| 21 ], | 22 ], |
| 22 | 23 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 40 imageGrid.addEventListener('phototaken', | 41 imageGrid.addEventListener('phototaken', |
| 41 this.handlePhotoTaken_.bind(this)); | 42 this.handlePhotoTaken_.bind(this)); |
| 42 imageGrid.addEventListener('photoupdated', | 43 imageGrid.addEventListener('photoupdated', |
| 43 this.handlePhotoUpdated_.bind(this)); | 44 this.handlePhotoUpdated_.bind(this)); |
| 44 | 45 |
| 45 // Set the title for camera item in the grid. | 46 // Set the title for camera item in the grid. |
| 46 imageGrid.setCameraTitles( | 47 imageGrid.setCameraTitles( |
| 47 loadTimeData.getString('takePhoto'), | 48 loadTimeData.getString('takePhoto'), |
| 48 loadTimeData.getString('photoFromCamera')); | 49 loadTimeData.getString('photoFromCamera')); |
| 49 | 50 |
| 50 this.profileImageLoading = true; | |
| 51 | |
| 52 // Profile image data (if present). | |
| 53 this.profileImage_ = imageGrid.addItem( | |
| 54 ButtonImages.PROFILE_PICTURE, // Image URL. | |
| 55 loadTimeData.getString('profilePhoto'), // Title. | |
| 56 undefined, // Click handler. | |
| 57 0, // Position. | |
| 58 function(el) { | |
| 59 // Custom decorator for Profile image element. | |
| 60 var spinner = el.ownerDocument.createElement('div'); | |
| 61 spinner.className = 'spinner'; | |
| 62 var spinnerBg = el.ownerDocument.createElement('div'); | |
| 63 spinnerBg.className = 'spinner-bg'; | |
| 64 spinnerBg.appendChild(spinner); | |
| 65 el.appendChild(spinnerBg); | |
| 66 el.id = 'profile-image'; | |
| 67 }); | |
| 68 this.profileImage_.type = 'profile'; | |
| 69 | |
| 70 $('take-photo').addEventListener( | 51 $('take-photo').addEventListener( |
| 71 'click', this.handleTakePhoto_.bind(this)); | 52 'click', this.handleTakePhoto_.bind(this)); |
| 72 $('discard-photo').addEventListener( | 53 $('discard-photo').addEventListener( |
| 73 'click', this.handleDiscardPhoto_.bind(this)); | 54 'click', this.handleDiscardPhoto_.bind(this)); |
| 74 | 55 |
| 75 // Toggle 'animation' class for the duration of WebKit transition. | 56 // Toggle 'animation' class for the duration of WebKit transition. |
| 76 $('flip-photo').addEventListener( | 57 $('flip-photo').addEventListener( |
| 77 'click', this.handleFlipPhoto_.bind(this)); | 58 'click', this.handleFlipPhoto_.bind(this)); |
| 78 $('user-image-stream-crop').addEventListener( | 59 $('user-image-stream-crop').addEventListener( |
| 79 'webkitTransitionEnd', function(e) { | 60 'webkitTransitionEnd', function(e) { |
| 80 previewElement.classList.remove('animation'); | 61 previewElement.classList.remove('animation'); |
| 81 }); | 62 }); |
| 82 $('user-image-preview-img').addEventListener( | 63 $('user-image-preview-img').addEventListener( |
| 83 'webkitTransitionEnd', function(e) { | 64 'webkitTransitionEnd', function(e) { |
| 84 previewElement.classList.remove('animation'); | 65 previewElement.classList.remove('animation'); |
| 85 }); | 66 }); |
| 86 | 67 |
| 87 var self = this; | 68 var self = this; |
| 88 this.context.addObserver(CONTEXT_KEY_IS_CAMERA_PRESENT, | 69 this.context.addObserver(CONTEXT_KEY_IS_CAMERA_PRESENT, |
| 89 function(present) { | 70 function(present) { |
| 90 $('user-image-grid').cameraPresent = present; | 71 $('user-image-grid').cameraPresent = present; |
| 91 }); | 72 }); |
| 92 this.context.addObserver(CONTEXT_KEY_SELECTED_IMAGE_URL, | 73 this.context.addObserver(CONTEXT_KEY_SELECTED_IMAGE_URL, |
| 93 this.setSelectedImage_); | 74 this.setSelectedImage_); |
| 75 this.context.addObserver(CONTEXT_KEY_HAS_GAIA_ACCOUNT, |
| 76 function(hasGaiaAccount) { |
| 77 if (!hasGaiaAccount) { |
| 78 imageGrid.removeItem(self.profileImage_); |
| 79 } else { |
| 80 self.profileImageLoading = true; |
| 81 // Profile image data (if present). |
| 82 self.profileImage_ = imageGrid.addItem( |
| 83 ButtonImages.PROFILE_PICTURE, // Image URL. |
| 84 loadTimeData.getString('profilePhoto'), // Title. |
| 85 undefined, // Click handler. |
| 86 0, // Position. |
| 87 function(el) { |
| 88 // Custom decorator for Profile image element. |
| 89 var spinner = el.ownerDocument.createElement('div'); |
| 90 spinner.className = 'spinner'; |
| 91 var spinnerBg = el.ownerDocument.createElement('div'); |
| 92 spinnerBg.className = 'spinner-bg'; |
| 93 spinnerBg.appendChild(spinner); |
| 94 el.appendChild(spinnerBg); |
| 95 el.id = 'profile-image'; |
| 96 }); |
| 97 self.profileImage_.type = 'profile'; |
| 98 } |
| 99 }); |
| 94 this.context.addObserver(CONTEXT_KEY_PROFILE_PICTURE_DATA_URL, | 100 this.context.addObserver(CONTEXT_KEY_PROFILE_PICTURE_DATA_URL, |
| 95 function(url) { | 101 function(url) { |
| 96 self.profileImageLoading = false; | 102 self.profileImageLoading = false; |
| 97 if (url) { | 103 if (url) { |
| 98 self.profileImage_ = | 104 self.profileImage_ = |
| 99 $('user-image-grid').updateItem(self.profileImage_, url); | 105 $('user-image-grid').updateItem(self.profileImage_, url); |
| 100 } | 106 } |
| 101 }); | 107 }); |
| 102 | 108 |
| 103 this.updateLocalizedContent(); | 109 this.updateLocalizedContent(); |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 */ | 386 */ |
| 381 notifyImageSelected_: function() { | 387 notifyImageSelected_: function() { |
| 382 var imageGrid = $('user-image-grid'); | 388 var imageGrid = $('user-image-grid'); |
| 383 chrome.send('selectImage', | 389 chrome.send('selectImage', |
| 384 [imageGrid.selectedItemUrl, | 390 [imageGrid.selectedItemUrl, |
| 385 imageGrid.selectionType, | 391 imageGrid.selectionType, |
| 386 !imageGrid.inProgramSelection]); | 392 !imageGrid.inProgramSelection]); |
| 387 } | 393 } |
| 388 }; | 394 }; |
| 389 }); | 395 }); |
| OLD | NEW |