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