OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 cr.define('settings_test', function() { | 5 cr.define('settings_test', function() { |
6 var changePictureOptions = settings_test.changePictureOptions || { | 6 var changePictureOptions = settings_test.changePictureOptions || { |
7 /** | 7 /** |
8 * True if property changes should fire events for testing purposes. | 8 * True if property changes should fire events for testing purposes. |
9 * @type {boolean} | 9 * @type {boolean} |
10 */ | 10 */ |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 this.$.selector.select(this.$.selector.indexOf(this.$.oldImage)); | 153 this.$.selector.select(this.$.selector.indexOf(this.$.oldImage)); |
154 }.bind(this), | 154 }.bind(this), |
155 | 155 |
156 /** | 156 /** |
157 * Called from C++ to provide the URL of the profile image. | 157 * Called from C++ to provide the URL of the profile image. |
158 * @param {string} imageUrl | 158 * @param {string} imageUrl |
159 * @param {boolean} selected | 159 * @param {boolean} selected |
160 */ | 160 */ |
161 receiveProfileImage: function(imageUrl, selected) { | 161 receiveProfileImage: function(imageUrl, selected) { |
162 this.profileImageUrl_ = imageUrl; | 162 this.profileImageUrl_ = imageUrl; |
| 163 this.$.profileImage.alt = this.i18n('profilePhoto'); |
163 | 164 |
164 if (!selected) | 165 if (!selected) |
165 return; | 166 return; |
166 | 167 |
167 this.fallbackImage_ = this.$.profileImage; | 168 this.fallbackImage_ = this.$.profileImage; |
168 | 169 |
169 // If user is currently taking a photo, do not steal the focus. | 170 // If user is currently taking a photo, do not steal the focus. |
170 if (!this.selectedItem_ || this.selectedItem_.dataset.type != 'camera') | 171 if (!this.selectedItem_ || this.selectedItem_.dataset.type != 'camera') |
171 this.$.selector.select(this.$.selector.indexOf(this.$.profileImage)); | 172 this.$.selector.select(this.$.selector.indexOf(this.$.profileImage)); |
172 }.bind(this), | 173 }.bind(this), |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 this.selectImage_(image); | 229 this.selectImage_(image); |
229 }, | 230 }, |
230 | 231 |
231 /** | 232 /** |
232 * Handle photo captured event, which contains the data URL of the image. | 233 * Handle photo captured event, which contains the data URL of the image. |
233 * @param {!{detail: !{photoDataUrl: string}}} event | 234 * @param {!{detail: !{photoDataUrl: string}}} event |
234 * containing a data URL. | 235 * containing a data URL. |
235 */ | 236 */ |
236 onPhotoTaken_: function(event) { | 237 onPhotoTaken_: function(event) { |
237 settings.ChangePicturePrivateApi.photoTaken(event.detail.photoDataUrl); | 238 settings.ChangePicturePrivateApi.photoTaken(event.detail.photoDataUrl); |
238 | |
239 // TODO(tommycli): Add announce of accessible message for photo capture. | |
240 }, | 239 }, |
241 | 240 |
242 /** | 241 /** |
243 * Discard currently selected old image. Selects the first default icon. | 242 * Discard currently selected old image. Selects the first default icon. |
244 * Returns to the camera stream if the user had just taken a picture. | 243 * Returns to the camera stream if the user had just taken a picture. |
245 * @private | 244 * @private |
246 */ | 245 */ |
247 onTapDiscardOldImage_: function() { | 246 onTapDiscardOldImage_: function() { |
248 this.oldImageUrl_ = ''; | 247 this.oldImageUrl_ = ''; |
249 | 248 |
250 if (this.lastSelectedImageType_ == 'camera') | 249 if (this.lastSelectedImageType_ == 'camera') |
251 this.$.selector.select(this.$.selector.indexOf(this.$.cameraImage)); | 250 this.$.selector.select(this.$.selector.indexOf(this.$.cameraImage)); |
252 | 251 |
253 if (this.fallbackImage_ != null) { | 252 if (this.fallbackImage_ != null) { |
254 this.selectImage_(this.fallbackImage_); | 253 this.selectImage_(this.fallbackImage_); |
255 return; | 254 return; |
256 } | 255 } |
257 | 256 |
258 // If the user has not chosen an image since opening the subpage and | 257 // If the user has not chosen an image since opening the subpage and |
259 // discards the current photo, select the first default image. | 258 // discards the current photo, select the first default image. |
260 assert(this.defaultImages_.length > 0); | 259 assert(this.defaultImages_.length > 0); |
261 settings.ChangePicturePrivateApi.selectDefaultImage( | 260 settings.ChangePicturePrivateApi.selectDefaultImage( |
262 this.defaultImages_[0].url); | 261 this.defaultImages_[0].url); |
| 262 |
| 263 announceAccessibleMessage( |
| 264 loadTimeData.getString('photoDiscardAccessibleText')); |
263 }, | 265 }, |
264 | 266 |
265 /** | 267 /** |
266 * @param {string} oldImageUrl | 268 * @param {string} oldImageUrl |
267 * @return {boolean} True if there is no old image and the old image icon | 269 * @return {boolean} True if there is no old image and the old image icon |
268 * should be hidden. | 270 * should be hidden. |
269 * @private | 271 * @private |
270 */ | 272 */ |
271 isOldImageHidden_: function(oldImageUrl) { return oldImageUrl.length == 0; }, | 273 isOldImageHidden_: function(oldImageUrl) { return oldImageUrl.length == 0; }, |
272 | 274 |
273 /** | 275 /** |
274 * @param {settings.ChangePictureImageElement} selectedItem | 276 * @param {settings.ChangePictureImageElement} selectedItem |
| 277 * @return {boolean} True if the preview image should be hidden. |
| 278 * @private |
| 279 */ |
| 280 isPreviewImageHidden_: function(selectedItem) { |
| 281 if (selectedItem == undefined) |
| 282 return true; |
| 283 |
| 284 var type = selectedItem.dataset.type; |
| 285 return type != 'default' && type != 'profile' && type != 'old'; |
| 286 }, |
| 287 |
| 288 /** |
| 289 * @param {settings.ChangePictureImageElement} selectedItem |
275 * @return {boolean} True if the camera is selected in the image grid. | 290 * @return {boolean} True if the camera is selected in the image grid. |
276 * @private | 291 * @private |
277 */ | 292 */ |
278 isCameraActive_: function(cameraPresent, selectedItem) { | 293 isCameraActive_: function(cameraPresent, selectedItem) { |
279 return cameraPresent && | 294 return cameraPresent && |
280 selectedItem != undefined && | 295 selectedItem != undefined && |
281 selectedItem.dataset.type == 'camera'; | 296 selectedItem.dataset.type == 'camera'; |
282 }, | 297 }, |
283 | 298 |
284 /** | 299 /** |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 * @private | 337 * @private |
323 */ | 338 */ |
324 getAuthorWebsite_: function(selectedItem, defaultImages) { | 339 getAuthorWebsite_: function(selectedItem, defaultImages) { |
325 if (!this.isAuthorCreditShown_(selectedItem)) | 340 if (!this.isAuthorCreditShown_(selectedItem)) |
326 return ''; | 341 return ''; |
327 | 342 |
328 assert(selectedItem.dataset.defaultImageIndex < defaultImages.length); | 343 assert(selectedItem.dataset.defaultImageIndex < defaultImages.length); |
329 return defaultImages[selectedItem.dataset.defaultImageIndex].website; | 344 return defaultImages[selectedItem.dataset.defaultImageIndex].website; |
330 }, | 345 }, |
331 }); | 346 }); |
OLD | NEW |