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

Side by Side Diff: chrome/browser/chromeos/login/take_photo_view.cc

Issue 10382144: Change SetImage, SetBackground, and SetToggledImage to take in a gfx::ImageSkia (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 8 years, 7 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
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 #include "chrome/browser/chromeos/login/take_photo_view.h" 5 #include "chrome/browser/chromeos/login/take_photo_view.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/chromeos/login/helper.h" 8 #include "chrome/browser/chromeos/login/helper.h"
9 #include "grit/generated_resources.h" 9 #include "grit/generated_resources.h"
10 #include "grit/theme_resources.h" 10 #include "grit/theme_resources.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 message_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 65 message_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
66 message_->SetVisible(false); 66 message_->SetVisible(false);
67 CorrectLabelFontSize(message_); 67 CorrectLabelFontSize(message_);
68 AddChildView(message_); 68 AddChildView(message_);
69 } 69 }
70 70
71 void SetInitializingState() { 71 void SetInitializingState() {
72 ShowThrobber(); 72 ShowThrobber();
73 SetMessage(string16()); 73 SetMessage(string16());
74 SetImage( 74 SetImage(
75 ResourceBundle::GetSharedInstance().GetBitmapNamed( 75 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
76 IDR_USER_IMAGE_INITIALIZING)); 76 IDR_USER_IMAGE_INITIALIZING));
77 } 77 }
78 78
79 void SetNormalState() { 79 void SetNormalState() {
80 HideThrobber(); 80 HideThrobber();
81 SetMessage(string16()); 81 SetMessage(string16());
82 } 82 }
83 83
84 void SetErrorState() { 84 void SetErrorState() {
85 HideThrobber(); 85 HideThrobber();
86 SetMessage(l10n_util::GetStringUTF16(IDS_USER_IMAGE_NO_VIDEO)); 86 SetMessage(l10n_util::GetStringUTF16(IDS_USER_IMAGE_NO_VIDEO));
87 SetImage( 87 SetImage(
88 ResourceBundle::GetSharedInstance().GetBitmapNamed( 88 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
89 IDR_USER_IMAGE_NO_VIDEO)); 89 IDR_USER_IMAGE_NO_VIDEO));
90 } 90 }
91 91
92 bool HasSnapshot() const { 92 bool HasSnapshot() const {
93 return !throbber_->visible() && !message_->visible(); 93 return !throbber_->visible() && !message_->visible();
94 } 94 }
95 95
96 private: 96 private:
97 void ShowThrobber() { 97 void ShowThrobber() {
98 DCHECK(throbber_); 98 DCHECK(throbber_);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 } 168 }
169 169
170 user_image_ = new CameraImageView(); 170 user_image_ = new CameraImageView();
171 user_image_->SetImageSize( 171 user_image_->SetImageSize(
172 gfx::Size(login::kUserImageSize, login::kUserImageSize)); 172 gfx::Size(login::kUserImageSize, login::kUserImageSize));
173 user_image_->Init(); 173 user_image_->Init();
174 174
175 snapshot_button_ = new views::ImageButton(this); 175 snapshot_button_ = new views::ImageButton(this);
176 snapshot_button_->set_focusable(true); 176 snapshot_button_->set_focusable(true);
177 snapshot_button_->SetImage(views::CustomButton::BS_NORMAL, 177 snapshot_button_->SetImage(views::CustomButton::BS_NORMAL,
178 ResourceBundle::GetSharedInstance().GetBitmapNamed( 178 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
179 IDR_USER_IMAGE_CAPTURE)); 179 IDR_USER_IMAGE_CAPTURE));
180 snapshot_button_->SetImage(views::CustomButton::BS_DISABLED, 180 snapshot_button_->SetImage(views::CustomButton::BS_DISABLED,
181 ResourceBundle::GetSharedInstance().GetBitmapNamed( 181 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
182 IDR_USER_IMAGE_CAPTURE_DISABLED)); 182 IDR_USER_IMAGE_CAPTURE_DISABLED));
183 snapshot_button_->SetAccessibleName(l10n_util::GetStringUTF16( 183 snapshot_button_->SetAccessibleName(l10n_util::GetStringUTF16(
184 IDS_CHROMEOS_ACC_ACCOUNT_PICTURE)); 184 IDS_CHROMEOS_ACC_ACCOUNT_PICTURE));
185 185
186 InitLayout(); 186 InitLayout();
187 // Request focus only after the button is added to views hierarchy. 187 // Request focus only after the button is added to views hierarchy.
188 snapshot_button_->RequestFocus(); 188 snapshot_button_->RequestFocus();
189 } 189 }
190 190
191 void TakePhotoView::InitLayout() { 191 void TakePhotoView::InitLayout() {
192 views::GridLayout* layout = new views::GridLayout(this); 192 views::GridLayout* layout = new views::GridLayout(this);
(...skipping 29 matching lines...) Expand all
222 222
223 void TakePhotoView::UpdateVideoFrame(const SkBitmap& frame) { 223 void TakePhotoView::UpdateVideoFrame(const SkBitmap& frame) {
224 if (!is_capturing_) 224 if (!is_capturing_)
225 return; 225 return;
226 226
227 if (!snapshot_button_->enabled()) { 227 if (!snapshot_button_->enabled()) {
228 user_image_->SetNormalState(); 228 user_image_->SetNormalState();
229 snapshot_button_->SetEnabled(true); 229 snapshot_button_->SetEnabled(true);
230 snapshot_button_->RequestFocus(); 230 snapshot_button_->RequestFocus();
231 } 231 }
232 SkBitmap user_image = 232 gfx::ImageSkia user_image =
233 skia::ImageOperations::Resize( 233 skia::ImageOperations::Resize(
234 frame, 234 frame,
235 skia::ImageOperations::RESIZE_BOX, 235 skia::ImageOperations::RESIZE_BOX,
236 login::kUserImageSize, 236 login::kUserImageSize,
237 login::kUserImageSize); 237 login::kUserImageSize);
238 238
239 user_image_->SetImage(&user_image); 239 user_image_->SetImage(&user_image);
240 } 240 }
241 241
242 void TakePhotoView::ShowCameraInitializing() { 242 void TakePhotoView::ShowCameraInitializing() {
243 is_capturing_ = true; 243 is_capturing_ = true;
244 snapshot_button_->SetImage(views::CustomButton::BS_NORMAL, 244 snapshot_button_->SetImage(views::CustomButton::BS_NORMAL,
245 ResourceBundle::GetSharedInstance().GetBitmapNamed( 245 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
246 IDR_USER_IMAGE_CAPTURE)); 246 IDR_USER_IMAGE_CAPTURE));
247 snapshot_button_->SetVisible(true); 247 snapshot_button_->SetVisible(true);
248 snapshot_button_->SetEnabled(false); 248 snapshot_button_->SetEnabled(false);
249 user_image_->SetInitializingState(); 249 user_image_->SetInitializingState();
250 } 250 }
251 251
252 void TakePhotoView::ShowCameraError() { 252 void TakePhotoView::ShowCameraError() {
253 if (!is_capturing_) 253 if (!is_capturing_)
254 return; 254 return;
255 snapshot_button_->SetEnabled(false); 255 snapshot_button_->SetEnabled(false);
256 user_image_->SetErrorState(); 256 user_image_->SetErrorState();
257 } 257 }
258 258
259 const SkBitmap& TakePhotoView::GetImage() const { 259 const SkBitmap& TakePhotoView::GetImage() const {
260 return user_image_->GetImage(); 260 return user_image_->GetImage();
261 } 261 }
262 262
263 void TakePhotoView::SetImage(SkBitmap* image) { 263 void TakePhotoView::SetImage(gfx::ImageSkia* image) {
264 is_capturing_ = false; 264 is_capturing_ = false;
265 snapshot_button_->SetVisible(false); 265 snapshot_button_->SetVisible(false);
266 snapshot_button_->SetEnabled(false); 266 snapshot_button_->SetEnabled(false);
267 user_image_->SetNormalState(); 267 user_image_->SetNormalState();
268 user_image_->SetImage(image); 268 user_image_->SetImage(image);
269 } 269 }
270 270
271 void TakePhotoView::CaptureImage() { 271 void TakePhotoView::CaptureImage() {
272 DCHECK(delegate_); 272 DCHECK(delegate_);
273 DCHECK(is_capturing_); 273 DCHECK(is_capturing_);
274 if (is_capturing_ && user_image_->HasSnapshot()) { 274 if (is_capturing_ && user_image_->HasSnapshot()) {
275 is_capturing_ = false; 275 is_capturing_ = false;
276 snapshot_button_->SetImage( 276 snapshot_button_->SetImage(
277 views::CustomButton::BS_NORMAL, 277 views::CustomButton::BS_NORMAL,
278 ResourceBundle::GetSharedInstance().GetBitmapNamed( 278 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
279 IDR_USER_IMAGE_RECYCLE)); 279 IDR_USER_IMAGE_RECYCLE));
280 delegate_->OnCapturingStopped(); 280 delegate_->OnCapturingStopped();
281 snapshot_button_->SchedulePaint(); 281 snapshot_button_->SchedulePaint();
282 } 282 }
283 } 283 }
284 284
285 gfx::Size TakePhotoView::GetPreferredSize() { 285 gfx::Size TakePhotoView::GetPreferredSize() {
286 return gfx::Size(width(), height()); 286 return gfx::Size(width(), height());
287 } 287 }
288 288
289 void TakePhotoView::ButtonPressed( 289 void TakePhotoView::ButtonPressed(
290 views::Button* sender, const views::Event& event) { 290 views::Button* sender, const views::Event& event) {
291 DCHECK(delegate_); 291 DCHECK(delegate_);
292 DCHECK(sender == snapshot_button_); 292 DCHECK(sender == snapshot_button_);
293 FlipCapturingState(); 293 FlipCapturingState();
294 } 294 }
295 295
296 void TakePhotoView::FlipCapturingState() { 296 void TakePhotoView::FlipCapturingState() {
297 if (is_capturing_) { 297 if (is_capturing_) {
298 CaptureImage(); 298 CaptureImage();
299 } else { 299 } else {
300 is_capturing_ = true; 300 is_capturing_ = true;
301 snapshot_button_->SetImage( 301 snapshot_button_->SetImage(
302 views::CustomButton::BS_NORMAL, 302 views::CustomButton::BS_NORMAL,
303 ResourceBundle::GetSharedInstance().GetBitmapNamed( 303 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
304 IDR_USER_IMAGE_CAPTURE)); 304 IDR_USER_IMAGE_CAPTURE));
305 delegate_->OnCapturingStarted(); 305 delegate_->OnCapturingStarted();
306 snapshot_button_->SchedulePaint(); 306 snapshot_button_->SchedulePaint();
307 } 307 }
308 } 308 }
309 309
310 } // namespace chromeos 310 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/take_photo_view.h ('k') | chrome/browser/chromeos/options/network_config_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698