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 cr.define('options', function() { | 5 cr.define('options', function() { |
6 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; | 6 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; |
7 /** @const */ var Grid = cr.ui.Grid; | 7 /** @const */ var Grid = cr.ui.Grid; |
8 /** @const */ var GridItem = cr.ui.GridItem; | 8 /** @const */ var GridItem = cr.ui.GridItem; |
9 /** @const */ var GridSelectionController = cr.ui.GridSelectionController; | 9 /** @const */ var GridSelectionController = cr.ui.GridSelectionController; |
10 /** @const */ var ListSingleSelectionModel = cr.ui.ListSingleSelectionModel; | 10 /** @const */ var ListSingleSelectionModel = cr.ui.ListSingleSelectionModel; |
11 | 11 |
12 /** | 12 /** |
13 * Dimensions for camera capture. | 13 * Dimensions for camera capture. |
14 * @const | 14 * @const |
15 */ | 15 */ |
16 var CAPTURE_SIZE = { | 16 var CAPTURE_SIZE = { |
17 height: 480, | 17 height: 480, |
18 width: 480 | 18 width: 480 |
19 }; | 19 }; |
20 | 20 |
21 /** | 21 /** |
22 * Path for internal URLs. | 22 * Path for internal URLs. |
23 * @const | 23 * @const |
24 */ | 24 */ |
25 var CHROME_THEME_PATH = 'chrome://theme'; | 25 var CHROME_THEME_PATH = 'chrome://theme'; |
26 | 26 |
27 /** | 27 /** |
28 * Creates a new user images grid item. | 28 * Creates a new user images grid item. |
29 * @param {{url: string, title: string=, decorateFn: function=, | 29 * @param {{url: string, title: (string|undefined), |
30 * clickHandler: function=}} imageInfo User image URL, optional title, | 30 * decorateFn: (!Function|undefined), |
31 * decorator callback and click handler. | 31 * clickHandler: (!Function|undefined)}} imageInfo User image URL, |
| 32 * optional title, decorator callback and click handler. |
32 * @constructor | 33 * @constructor |
33 * @extends {cr.ui.GridItem} | 34 * @extends {cr.ui.GridItem} |
34 */ | 35 */ |
35 function UserImagesGridItem(imageInfo) { | 36 function UserImagesGridItem(imageInfo) { |
36 var el = new GridItem(imageInfo); | 37 var el = new GridItem(imageInfo); |
37 el.__proto__ = UserImagesGridItem.prototype; | 38 el.__proto__ = UserImagesGridItem.prototype; |
38 return el; | 39 return el; |
39 } | 40 } |
40 | 41 |
41 UserImagesGridItem.prototype = { | 42 UserImagesGridItem.prototype = { |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 if (this.cameraStream_) | 235 if (this.cameraStream_) |
235 this.cameraStream_.stop(); | 236 this.cameraStream_.stop(); |
236 // Cancel any pending getUserMedia() checks. | 237 // Cancel any pending getUserMedia() checks. |
237 this.cameraStartInProgress_ = false; | 238 this.cameraStartInProgress_ = false; |
238 }, | 239 }, |
239 | 240 |
240 /** | 241 /** |
241 * Handles successful camera check. | 242 * Handles successful camera check. |
242 * @param {function(): boolean} onAvailable Callback to call. If it returns | 243 * @param {function(): boolean} onAvailable Callback to call. If it returns |
243 * |true|, capture is started immediately. | 244 * |true|, capture is started immediately. |
244 * @param {MediaStream} stream Stream object as returned by getUserMedia. | 245 * @param {!MediaStream} stream Stream object as returned by getUserMedia. |
245 * @private | 246 * @private |
246 */ | 247 */ |
247 handleCameraAvailable_: function(onAvailable, stream) { | 248 handleCameraAvailable_: function(onAvailable, stream) { |
248 if (this.cameraStartInProgress_ && onAvailable()) { | 249 if (this.cameraStartInProgress_ && onAvailable()) { |
249 this.cameraVideo_.src = URL.createObjectURL(stream); | 250 this.cameraVideo_.src = URL.createObjectURL(stream); |
250 this.cameraStream_ = stream; | 251 this.cameraStream_ = stream; |
251 } else { | 252 } else { |
252 stream.stop(); | 253 stream.stop(); |
253 } | 254 } |
254 this.cameraStartInProgress_ = false; | 255 this.cameraStartInProgress_ = false; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 $('user-image-grid').focus(); | 306 $('user-image-grid').focus(); |
306 } | 307 } |
307 }; | 308 }; |
308 // Timeout guarantees processing AFTER style changes display attribute. | 309 // Timeout guarantees processing AFTER style changes display attribute. |
309 setTimeout(setFocusIfLost, 0); | 310 setTimeout(setFocusIfLost, 0); |
310 }, | 311 }, |
311 | 312 |
312 /** | 313 /** |
313 * Current image captured from camera as data URL. Setting to null will | 314 * Current image captured from camera as data URL. Setting to null will |
314 * return to the live camera stream. | 315 * return to the live camera stream. |
315 * @type {string=} | 316 * @type {(string|undefined)} |
316 */ | 317 */ |
317 get cameraImage() { | 318 get cameraImage() { |
318 return this.cameraImage_; | 319 return this.cameraImage_; |
319 }, | 320 }, |
320 set cameraImage(imageUrl) { | 321 set cameraImage(imageUrl) { |
321 this.cameraLive = !imageUrl; | 322 this.cameraLive = !imageUrl; |
322 if (this.cameraPresent && !imageUrl) | 323 if (this.cameraPresent && !imageUrl) |
323 imageUrl = UserImagesGrid.ButtonImages.TAKE_PHOTO; | 324 imageUrl = UserImagesGrid.ButtonImages.TAKE_PHOTO; |
324 if (imageUrl) { | 325 if (imageUrl) { |
325 this.cameraImage_ = this.cameraImage_ ? | 326 this.cameraImage_ = this.cameraImage_ ? |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 | 454 |
454 /** | 455 /** |
455 * Performs photo capture from the live camera stream. 'phototaken' event | 456 * Performs photo capture from the live camera stream. 'phototaken' event |
456 * will be fired as soon as captured photo is available, with 'dataURL' | 457 * will be fired as soon as captured photo is available, with 'dataURL' |
457 * property containing the photo encoded as a data URL. | 458 * property containing the photo encoded as a data URL. |
458 * @return {boolean} Whether photo capture was successful. | 459 * @return {boolean} Whether photo capture was successful. |
459 */ | 460 */ |
460 takePhoto: function() { | 461 takePhoto: function() { |
461 if (!this.cameraOnline) | 462 if (!this.cameraOnline) |
462 return false; | 463 return false; |
463 var canvas = document.createElement('canvas'); | 464 var canvas = /** @type {HTMLCanvasElement} */( |
| 465 document.createElement('canvas')); |
464 canvas.width = CAPTURE_SIZE.width; | 466 canvas.width = CAPTURE_SIZE.width; |
465 canvas.height = CAPTURE_SIZE.height; | 467 canvas.height = CAPTURE_SIZE.height; |
466 this.captureFrame_( | 468 this.captureFrame_( |
467 this.cameraVideo_, canvas.getContext('2d'), CAPTURE_SIZE); | 469 this.cameraVideo_, canvas.getContext('2d'), CAPTURE_SIZE); |
468 // Preload image before displaying it. | 470 // Preload image before displaying it. |
469 var previewImg = new Image(); | 471 var previewImg = new Image(); |
470 previewImg.addEventListener('load', function(e) { | 472 previewImg.addEventListener('load', function(e) { |
471 this.cameraTitle_ = this.capturedImageTitle_; | 473 this.cameraTitle_ = this.capturedImageTitle_; |
472 this.cameraImage = previewImg.src; | 474 this.cameraImage = previewImg.src; |
473 }.bind(this)); | 475 }.bind(this)); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 var imageIndex = this.indexOf(imageInfo); | 586 var imageIndex = this.indexOf(imageInfo); |
585 var wasSelected = this.selectionModel.selectedIndex == imageIndex; | 587 var wasSelected = this.selectionModel.selectedIndex == imageIndex; |
586 this.removeItem(imageInfo); | 588 this.removeItem(imageInfo); |
587 var newInfo = this.addItem( | 589 var newInfo = this.addItem( |
588 imageUrl, | 590 imageUrl, |
589 opt_title === undefined ? imageInfo.title : opt_title, | 591 opt_title === undefined ? imageInfo.title : opt_title, |
590 imageInfo.clickHandler, | 592 imageInfo.clickHandler, |
591 imageIndex, | 593 imageIndex, |
592 imageInfo.decorateFn); | 594 imageInfo.decorateFn); |
593 // Update image data with the reset of the keys from the old data. | 595 // Update image data with the reset of the keys from the old data. |
594 for (k in imageInfo) { | 596 for (var k in imageInfo) { |
595 if (!(k in newInfo)) | 597 if (!(k in newInfo)) |
596 newInfo[k] = imageInfo[k]; | 598 newInfo[k] = imageInfo[k]; |
597 } | 599 } |
598 if (wasSelected) | 600 if (wasSelected) |
599 this.selectedItem = newInfo; | 601 this.selectedItem = newInfo; |
600 return newInfo; | 602 return newInfo; |
601 }, | 603 }, |
602 | 604 |
603 /** | 605 /** |
604 * Removes previously added image from the grid. | 606 * Removes previously added image from the grid. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 UserImagesGrid.ButtonImages = { | 640 UserImagesGrid.ButtonImages = { |
639 TAKE_PHOTO: 'chrome://theme/IDR_BUTTON_USER_IMAGE_TAKE_PHOTO', | 641 TAKE_PHOTO: 'chrome://theme/IDR_BUTTON_USER_IMAGE_TAKE_PHOTO', |
640 CHOOSE_FILE: 'chrome://theme/IDR_BUTTON_USER_IMAGE_CHOOSE_FILE', | 642 CHOOSE_FILE: 'chrome://theme/IDR_BUTTON_USER_IMAGE_CHOOSE_FILE', |
641 PROFILE_PICTURE: 'chrome://theme/IDR_PROFILE_PICTURE_LOADING' | 643 PROFILE_PICTURE: 'chrome://theme/IDR_PROFILE_PICTURE_LOADING' |
642 }; | 644 }; |
643 | 645 |
644 return { | 646 return { |
645 UserImagesGrid: UserImagesGrid | 647 UserImagesGrid: UserImagesGrid |
646 }; | 648 }; |
647 }); | 649 }); |
OLD | NEW |