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

Side by Side Diff: chrome/browser/resources/settings/people_page/camera.js

Issue 1720533002: Settings People Revamp: Change Picture: Add accessibility-key usage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@0095-settings-change-picture-announce-messags-old-image-alt-text
Patch Set: Created 4 years, 9 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
OLDNEW
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 }, 59 },
60 60
61 /** @override */ 61 /** @override */
62 attached: function() { 62 attached: function() {
63 this.$.cameraVideo.addEventListener('canplay', function() { 63 this.$.cameraVideo.addEventListener('canplay', function() {
64 this.cameraOnline_ = true; 64 this.cameraOnline_ = true;
65 }.bind(this)); 65 }.bind(this));
66 }, 66 },
67 67
68 /** 68 /**
69 * Performs photo capture from the live camera stream. 'phototaken' event
70 * will be fired as soon as captured photo is available, with 'dataURL'
71 * property containing the photo encoded as a data URL.
72 * @private
73 */
74 takePhoto: function() {
75 if (!this.cameraOnline_)
76 return;
77 var canvas =
78 /** @type {HTMLCanvasElement} */ (document.createElement('canvas'));
Dan Beam 2016/02/29 19:26:01 nit: don't put spaces between */ and (
tommycli 2016/02/29 20:28:25 Hi. This was the result of git cl format, and seem
79 canvas.width = CAPTURE_SIZE.width;
80 canvas.height = CAPTURE_SIZE.height;
81 this.captureFrame_(
82 this.$.cameraVideo,
83 /** @type {!CanvasRenderingContext2D} */ (canvas.getContext('2d')));
84
85 var photoDataUrl = this.isFlipped_ ? this.flipFrame_(canvas) :
86 canvas.toDataURL('image/png');
87 this.fire('phototaken', {photoDataUrl: photoDataUrl});
88
89 announceAccessibleMessage(
90 loadTimeData.getString('photoCaptureAccessibleText'));
91 },
92
93 /**
69 * Observer for the cameraActive property. 94 * Observer for the cameraActive property.
70 * @private 95 * @private
71 */ 96 */
72 cameraActiveChanged_: function() { 97 cameraActiveChanged_: function() {
73 if (this.cameraActive) 98 if (this.cameraActive)
74 this.startCamera_(); 99 this.startCamera_();
75 else 100 else
76 this.stopCamera_(); 101 this.stopCamera_();
77 }, 102 },
78 103
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 onTapFlipPhoto_: function() { 158 onTapFlipPhoto_: function() {
134 this.isFlipped_ = !this.isFlipped_; 159 this.isFlipped_ = !this.isFlipped_;
135 this.$.userImageStreamCrop.classList.toggle('flip-x', this.isFlipped_); 160 this.$.userImageStreamCrop.classList.toggle('flip-x', this.isFlipped_);
136 161
137 var flipMessageId = this.isFlipped_ ? 162 var flipMessageId = this.isFlipped_ ?
138 'photoFlippedAccessibleText' : 'photoFlippedBackAccessibleText'; 163 'photoFlippedAccessibleText' : 'photoFlippedBackAccessibleText';
139 announceAccessibleMessage(loadTimeData.getString(flipMessageId)); 164 announceAccessibleMessage(loadTimeData.getString(flipMessageId));
140 }, 165 },
141 166
142 /** 167 /**
143 * Performs photo capture from the live camera stream. 'phototaken' event
144 * will be fired as soon as captured photo is available, with 'dataURL'
145 * property containing the photo encoded as a data URL.
146 * @private
147 */
148 onTapTakePhoto_: function() {
149 if (!this.cameraOnline_)
150 return;
151 var canvas = /** @type {HTMLCanvasElement} */(
152 document.createElement('canvas'));
153 canvas.width = CAPTURE_SIZE.width;
154 canvas.height = CAPTURE_SIZE.height;
155 this.captureFrame_(
156 this.$.cameraVideo,
157 /** @type {!CanvasRenderingContext2D} */(canvas.getContext('2d')));
158
159 var photoDataUrl = this.isFlipped_ ? this.flipFrame_(canvas) :
160 canvas.toDataURL('image/png');
161 this.fire('phototaken', {photoDataUrl: photoDataUrl});
162
163 announceAccessibleMessage(
164 loadTimeData.getString('photoCaptureAccessibleText'));
165 },
166
167 /**
168 * 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
169 * current drawing origin of a canvas context. 169 * current drawing origin of a canvas context.
170 * @param {!HTMLVideoElement} video Video element to capture from. 170 * @param {!HTMLVideoElement} video Video element to capture from.
171 * @param {!CanvasRenderingContext2D} ctx Canvas context to draw onto. 171 * @param {!CanvasRenderingContext2D} ctx Canvas context to draw onto.
172 * @private 172 * @private
173 */ 173 */
174 captureFrame_: function(video, ctx) { 174 captureFrame_: function(video, ctx) {
175 var width = video.videoWidth; 175 var width = video.videoWidth;
176 var height = video.videoHeight; 176 var height = video.videoHeight;
177 if (width < CAPTURE_SIZE.width || height < CAPTURE_SIZE.height) { 177 if (width < CAPTURE_SIZE.width || height < CAPTURE_SIZE.height) {
(...skipping 28 matching lines...) Expand all
206 canvas.height = CAPTURE_SIZE.height; 206 canvas.height = CAPTURE_SIZE.height;
207 var ctx = canvas.getContext('2d'); 207 var ctx = canvas.getContext('2d');
208 ctx.translate(CAPTURE_SIZE.width, 0); 208 ctx.translate(CAPTURE_SIZE.width, 0);
209 ctx.scale(-1.0, 1.0); 209 ctx.scale(-1.0, 1.0);
210 ctx.drawImage(source, 0, 0); 210 ctx.drawImage(source, 0, 0);
211 return canvas.toDataURL('image/png'); 211 return canvas.toDataURL('image/png');
212 }, 212 },
213 }); 213 });
214 214
215 })(); 215 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698