Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(637)

Side by Side Diff: chrome/browser/resources/chromeos/user_images_grid.js

Issue 10825319: [cros] OOBE avatar picker fixes and polishing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/resources/chromeos/login/oobe_screen_user_image.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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;
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 * Updates the preview image, if present. 181 * Updates the preview image, if present.
182 * @private 182 * @private
183 */ 183 */
184 updatePreview_: function() { 184 updatePreview_: function() {
185 var url = this.selectedItemUrl; 185 var url = this.selectedItemUrl;
186 if (url && this.previewImage_) 186 if (url && this.previewImage_)
187 this.previewImage_.src = url; 187 this.previewImage_.src = url;
188 }, 188 },
189 189
190 /** 190 /**
191 * @param {boolean} present Whether a camera is present or not. 191 * Whether a camera is present or not.
192 * @type {boolean}
192 */ 193 */
193 get cameraPresent() { 194 get cameraPresent() {
194 return this.cameraPresent_; 195 return this.cameraPresent_;
195 }, 196 },
196 set cameraPresent(value) { 197 set cameraPresent(value) {
197 this.cameraPresent_ = value; 198 this.cameraPresent_ = value;
198 if (this.cameraLive) 199 if (this.cameraLive)
199 this.cameraImage = null; 200 this.cameraImage = null;
200 }, 201 },
201 202
202 /** 203 /**
204 * Whether camera is actually streaming video. May be |false| even when
205 * camera is present and shown but still initializing.
206 * @type {boolean}
207 */
208 get cameraOnline() {
209 return this.previewElement.classList.contains('online');
210 },
211
212 /**
203 * Start camera presence check. 213 * Start camera presence check.
204 * @param {boolean} autoplay Whether to start capture immediately. 214 * @param {boolean} autoplay Whether to start capture immediately.
205 * @param {boolean} preselect Whether to select camera automatically. 215 * @param {boolean} preselect Whether to select camera automatically.
206 */ 216 */
207 checkCameraPresence: function(autoplay, preselect) { 217 checkCameraPresence: function(autoplay, preselect) {
208 this.previewElement.classList.remove('online'); 218 this.previewElement.classList.remove('online');
209 if (!this.cameraVideo_) 219 if (!this.cameraVideo_)
210 return; 220 return;
211 navigator.webkitGetUserMedia( 221 navigator.webkitGetUserMedia(
212 {video: true}, 222 {video: true},
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 }, 442 },
433 set flipPhoto(value) { 443 set flipPhoto(value) {
434 this.flipPhoto_ = value; 444 this.flipPhoto_ = value;
435 this.previewElement.classList[value ? 'add' : 'remove']('flip-x'); 445 this.previewElement.classList[value ? 'add' : 'remove']('flip-x');
436 }, 446 },
437 447
438 /** 448 /**
439 * Performs photo capture from the live camera stream. 449 * Performs photo capture from the live camera stream.
440 * @param {function=} opt_callback Callback that receives taken photo as 450 * @param {function=} opt_callback Callback that receives taken photo as
441 * data URL. 451 * data URL.
452 * @return {boolean} Whether photo capture was successful.
442 */ 453 */
443 takePhoto: function(opt_callback) { 454 takePhoto: function(opt_callback) {
455 if (!this.cameraOnline)
456 return false;
444 var canvas = document.createElement('canvas'); 457 var canvas = document.createElement('canvas');
445 canvas.width = CAPTURE_SIZE.width; 458 canvas.width = CAPTURE_SIZE.width;
446 canvas.height = CAPTURE_SIZE.height; 459 canvas.height = CAPTURE_SIZE.height;
447 this.captureFrame_( 460 this.captureFrame_(
448 this.cameraVideo_, canvas.getContext('2d'), CAPTURE_SIZE); 461 this.cameraVideo_, canvas.getContext('2d'), CAPTURE_SIZE);
449 var photoURL = canvas.toDataURL('image/png'); 462 var photoURL = canvas.toDataURL('image/png');
450 if (opt_callback && typeof opt_callback == 'function') 463 if (opt_callback && typeof opt_callback == 'function')
451 opt_callback(photoURL); 464 opt_callback(photoURL);
452 // Wait until image is loaded before displaying it. 465 // Wait until image is loaded before displaying it.
453 var self = this; 466 var self = this;
454 var previewImg = new Image(); 467 var previewImg = new Image();
455 previewImg.addEventListener('load', function(e) { 468 previewImg.addEventListener('load', function(e) {
456 self.cameraImage = this.src; 469 self.cameraImage = this.src;
457 }); 470 });
458 previewImg.src = photoURL; 471 previewImg.src = photoURL;
472 return true;
459 }, 473 },
460 474
461 /** 475 /**
462 * Performs video capture from the live camera stream. 476 * Performs video capture from the live camera stream.
463 * @param {function=} opt_callback Callback that receives taken video as 477 * @param {function=} opt_callback Callback that receives taken video as
464 * data URL of a vertically stacked PNG sprite. 478 * data URL of a vertically stacked PNG sprite.
465 */ 479 */
466 takeVideo: function(opt_callback) { 480 takeVideo: function(opt_callback) {
467 var canvas = document.createElement('canvas'); 481 var canvas = document.createElement('canvas');
468 canvas.width = CAPTURE_SIZE.width; 482 canvas.width = CAPTURE_SIZE.width;
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 UserImagesGrid.ButtonImages = { 665 UserImagesGrid.ButtonImages = {
652 TAKE_PHOTO: 'chrome://theme/IDR_BUTTON_USER_IMAGE_TAKE_PHOTO', 666 TAKE_PHOTO: 'chrome://theme/IDR_BUTTON_USER_IMAGE_TAKE_PHOTO',
653 CHOOSE_FILE: 'chrome://theme/IDR_BUTTON_USER_IMAGE_CHOOSE_FILE', 667 CHOOSE_FILE: 'chrome://theme/IDR_BUTTON_USER_IMAGE_CHOOSE_FILE',
654 PROFILE_PICTURE: 'chrome://theme/IDR_PROFILE_PICTURE_LOADING' 668 PROFILE_PICTURE: 'chrome://theme/IDR_PROFILE_PICTURE_LOADING'
655 }; 669 };
656 670
657 return { 671 return {
658 UserImagesGrid: UserImagesGrid 672 UserImagesGrid: UserImagesGrid
659 }; 673 };
660 }); 674 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/chromeos/login/oobe_screen_user_image.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698