| 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 /** | 5 /** |
| 6 * @fileoverview | 6 * @fileoverview |
| 7 * 'settings-camera' is the Polymer control used to take a picture from the | 7 * 'settings-camera' is the Polymer control used to take a picture from the |
| 8 * user webcam to use as a ChromeOS profile picture. | 8 * user webcam to use as a ChromeOS profile picture. |
| 9 * | 9 * |
| 10 * @group Chrome Settings Elements | 10 * @group Chrome Settings Elements |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 }, | 127 }, |
| 128 | 128 |
| 129 /** | 129 /** |
| 130 * Flip the live camera stream. | 130 * Flip the live camera stream. |
| 131 * @private | 131 * @private |
| 132 */ | 132 */ |
| 133 onTapFlipPhoto_: function() { | 133 onTapFlipPhoto_: function() { |
| 134 this.isFlipped_ = !this.isFlipped_; | 134 this.isFlipped_ = !this.isFlipped_; |
| 135 this.$.userImageStreamCrop.classList.toggle('flip-x', this.isFlipped_); | 135 this.$.userImageStreamCrop.classList.toggle('flip-x', this.isFlipped_); |
| 136 | 136 |
| 137 // TODO(tommycli): Add announce of accessible message for photo flipping. | 137 var flipMessageId = this.isFlipped_ ? |
| 138 'photoFlippedAccessibleText' : 'photoFlippedBackAccessibleText'; |
| 139 announceAccessibleMessage(loadTimeData.getString(flipMessageId)); |
| 138 }, | 140 }, |
| 139 | 141 |
| 140 /** | 142 /** |
| 141 * Performs photo capture from the live camera stream. 'phototaken' event | 143 * Performs photo capture from the live camera stream. 'phototaken' event |
| 142 * will be fired as soon as captured photo is available, with 'dataURL' | 144 * will be fired as soon as captured photo is available, with 'dataURL' |
| 143 * property containing the photo encoded as a data URL. | 145 * property containing the photo encoded as a data URL. |
| 144 * @private | 146 * @private |
| 145 */ | 147 */ |
| 146 onTapTakePhoto_: function() { | 148 onTapTakePhoto_: function() { |
| 147 if (!this.cameraOnline_) | 149 if (!this.cameraOnline_) |
| 148 return; | 150 return; |
| 149 var canvas = /** @type {HTMLCanvasElement} */( | 151 var canvas = /** @type {HTMLCanvasElement} */( |
| 150 document.createElement('canvas')); | 152 document.createElement('canvas')); |
| 151 canvas.width = CAPTURE_SIZE.width; | 153 canvas.width = CAPTURE_SIZE.width; |
| 152 canvas.height = CAPTURE_SIZE.height; | 154 canvas.height = CAPTURE_SIZE.height; |
| 153 this.captureFrame_( | 155 this.captureFrame_( |
| 154 this.$.cameraVideo, | 156 this.$.cameraVideo, |
| 155 /** @type {!CanvasRenderingContext2D} */(canvas.getContext('2d'))); | 157 /** @type {!CanvasRenderingContext2D} */(canvas.getContext('2d'))); |
| 156 | 158 |
| 157 var photoDataUrl = this.isFlipped_ ? this.flipFrame_(canvas) : | 159 var photoDataUrl = this.isFlipped_ ? this.flipFrame_(canvas) : |
| 158 canvas.toDataURL('image/png'); | 160 canvas.toDataURL('image/png'); |
| 159 this.fire('phototaken', {photoDataUrl: photoDataUrl}); | 161 this.fire('phototaken', {photoDataUrl: photoDataUrl}); |
| 162 |
| 163 announceAccessibleMessage( |
| 164 loadTimeData.getString('photoCaptureAccessibleText')); |
| 160 }, | 165 }, |
| 161 | 166 |
| 162 /** | 167 /** |
| 163 * Captures a single still frame from a <video> element, placing it at the | 168 * Captures a single still frame from a <video> element, placing it at the |
| 164 * current drawing origin of a canvas context. | 169 * current drawing origin of a canvas context. |
| 165 * @param {!HTMLVideoElement} video Video element to capture from. | 170 * @param {!HTMLVideoElement} video Video element to capture from. |
| 166 * @param {!CanvasRenderingContext2D} ctx Canvas context to draw onto. | 171 * @param {!CanvasRenderingContext2D} ctx Canvas context to draw onto. |
| 167 * @private | 172 * @private |
| 168 */ | 173 */ |
| 169 captureFrame_: function(video, ctx) { | 174 captureFrame_: function(video, ctx) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 canvas.height = CAPTURE_SIZE.height; | 206 canvas.height = CAPTURE_SIZE.height; |
| 202 var ctx = canvas.getContext('2d'); | 207 var ctx = canvas.getContext('2d'); |
| 203 ctx.translate(CAPTURE_SIZE.width, 0); | 208 ctx.translate(CAPTURE_SIZE.width, 0); |
| 204 ctx.scale(-1.0, 1.0); | 209 ctx.scale(-1.0, 1.0); |
| 205 ctx.drawImage(source, 0, 0); | 210 ctx.drawImage(source, 0, 0); |
| 206 return canvas.toDataURL('image/png'); | 211 return canvas.toDataURL('image/png'); |
| 207 }, | 212 }, |
| 208 }); | 213 }); |
| 209 | 214 |
| 210 })(); | 215 })(); |
| OLD | NEW |