| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/user_view.h" | 5 #include "chrome/browser/chromeos/login/user_view.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "chrome/browser/chromeos/login/helper.h" | 9 #include "chrome/browser/chromeos/login/helper.h" |
| 10 #include "chrome/browser/chromeos/login/rounded_rect_painter.h" | 10 #include "chrome/browser/chromeos/login/rounded_rect_painter.h" |
| 11 #include "chrome/browser/chromeos/login/rounded_view.h" | 11 #include "chrome/browser/chromeos/login/rounded_view.h" |
| 12 #include "gfx/canvas.h" | 12 #include "gfx/canvas.h" |
| 13 #include "gfx/canvas_skia.h" | 13 #include "gfx/canvas_skia.h" |
| 14 #include "gfx/rect.h" | 14 #include "gfx/rect.h" |
| 15 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
| 16 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
| 17 #include "views/background.h" | 17 #include "views/background.h" |
| 18 #include "views/controls/button/text_button.h" | 18 #include "views/controls/button/text_button.h" |
| 19 #include "views/controls/image_view.h" | 19 #include "views/controls/image_view.h" |
| 20 #include "views/controls/label.h" | 20 #include "views/controls/label.h" |
| 21 #include "views/controls/link.h" | 21 #include "views/controls/link.h" |
| 22 #include "views/controls/throbber.h" | |
| 23 #include "views/painter.h" | 22 #include "views/painter.h" |
| 24 | 23 |
| 25 namespace { | 24 namespace { |
| 26 | 25 |
| 27 // Background color and corner radius of the login status label and | 26 // Background color and corner radius of the login status label and |
| 28 // signout button. | 27 // signout button. |
| 29 const SkColor kSignoutBackgroundColor = 0xFF007700; | 28 const SkColor kSignoutBackgroundColor = 0xFF007700; |
| 30 const int kSignoutBackgroundCornerRadius = 4; | 29 const int kSignoutBackgroundCornerRadius = 4; |
| 31 | 30 |
| 32 // Horiz/Vert insets for Signout view. | 31 // Horiz/Vert insets for Signout view. |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 SkBitmap image_; | 235 SkBitmap image_; |
| 237 SkBitmap image_hot_; | 236 SkBitmap image_hot_; |
| 238 | 237 |
| 239 DISALLOW_COPY_AND_ASSIGN(PodImageView); | 238 DISALLOW_COPY_AND_ASSIGN(PodImageView); |
| 240 }; | 239 }; |
| 241 | 240 |
| 242 UserView::UserView(Delegate* delegate, bool is_login, bool need_background) | 241 UserView::UserView(Delegate* delegate, bool is_login, bool need_background) |
| 243 : delegate_(delegate), | 242 : delegate_(delegate), |
| 244 signout_view_(NULL), | 243 signout_view_(NULL), |
| 245 image_view_(NULL), | 244 image_view_(NULL), |
| 246 throbber_(CreateDefaultSmoothedThrobber()), | |
| 247 remove_button_(NULL) { | 245 remove_button_(NULL) { |
| 248 DCHECK(delegate); | 246 DCHECK(delegate); |
| 249 if (!is_login) | 247 if (!is_login) |
| 250 signout_view_ = new SignoutView(this); | 248 signout_view_ = new SignoutView(this); |
| 251 | 249 |
| 252 if (need_background) | 250 if (need_background) |
| 253 image_view_ = new RoundedView<PodImageView>; | 251 image_view_ = new RoundedView<PodImageView>; |
| 254 else | 252 else |
| 255 image_view_ = new PodImageView; | 253 image_view_ = new PodImageView; |
| 256 | 254 |
| 257 Init(need_background); | 255 Init(need_background); |
| 258 } | 256 } |
| 259 | 257 |
| 260 void UserView::Init(bool need_background) { | 258 void UserView::Init(bool need_background) { |
| 261 if (need_background) { | 259 if (need_background) { |
| 262 image_view_->set_background( | 260 image_view_->set_background( |
| 263 views::Background::CreateSolidBackground(kBackgroundColor)); | 261 views::Background::CreateSolidBackground(kBackgroundColor)); |
| 264 } | 262 } |
| 265 if (throbber_) { | |
| 266 int w = throbber_->GetPreferredSize().width(); | |
| 267 int h = throbber_->GetPreferredSize().height(); | |
| 268 throbber_->SetBounds(kUserImageSize / 2 - w / 2, | |
| 269 kUserImageSize / 2 - h / 2 , w, h); | |
| 270 // Throbber should be actually hidden while stopped so tooltip manager | |
| 271 // doesn't find it. | |
| 272 throbber_->SetVisible(false); | |
| 273 image_view_->AddChildView(throbber_); | |
| 274 } | |
| 275 | 263 |
| 276 // UserView's layout never changes, so let's layout once here. | 264 // UserView's layout never changes, so let's layout once here. |
| 277 image_view_->SetBounds(0, 0, kUserImageSize, kUserImageSize); | 265 image_view_->SetBounds(0, 0, kUserImageSize, kUserImageSize); |
| 278 AddChildView(image_view_); | 266 AddChildView(image_view_); |
| 279 | 267 |
| 280 if (signout_view_) { | 268 if (signout_view_) { |
| 281 signout_view_->SetBounds(0, kUserImageSize, kUserImageSize, | 269 signout_view_->SetBounds(0, kUserImageSize, kUserImageSize, |
| 282 signout_view_->GetPreferredSize().height()); | 270 signout_view_->GetPreferredSize().height()); |
| 283 AddChildView(signout_view_); | 271 AddChildView(signout_view_); |
| 284 } | 272 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 300 desired_size = kUserImageSize; | 288 desired_size = kUserImageSize; |
| 301 image_view_->SetImageSize(gfx::Size(desired_size, desired_size)); | 289 image_view_->SetImageSize(gfx::Size(desired_size, desired_size)); |
| 302 image_view_->SetImage(image, image_hot); | 290 image_view_->SetImage(image, image_hot); |
| 303 } | 291 } |
| 304 | 292 |
| 305 void UserView::SetTooltipText(const std::wstring& text) { | 293 void UserView::SetTooltipText(const std::wstring& text) { |
| 306 DCHECK(image_view_); | 294 DCHECK(image_view_); |
| 307 image_view_->SetTooltipText(text); | 295 image_view_->SetTooltipText(text); |
| 308 } | 296 } |
| 309 | 297 |
| 310 void UserView::StartThrobber() { | |
| 311 throbber_->SetVisible(true); | |
| 312 throbber_->Start(); | |
| 313 } | |
| 314 | |
| 315 void UserView::StopThrobber() { | |
| 316 throbber_->Stop(); | |
| 317 throbber_->SetVisible(false); | |
| 318 } | |
| 319 | |
| 320 gfx::Size UserView::GetPreferredSize() { | 298 gfx::Size UserView::GetPreferredSize() { |
| 321 return gfx::Size( | 299 return gfx::Size( |
| 322 kUserImageSize, | 300 kUserImageSize, |
| 323 kUserImageSize + | 301 kUserImageSize + |
| 324 (signout_view_ ? signout_view_->GetPreferredSize().height() : 0)); | 302 (signout_view_ ? signout_view_->GetPreferredSize().height() : 0)); |
| 325 } | 303 } |
| 326 | 304 |
| 327 void UserView::SetSignoutEnabled(bool enabled) { | 305 void UserView::SetSignoutEnabled(bool enabled) { |
| 328 DCHECK(signout_view_); | 306 DCHECK(signout_view_); |
| 329 signout_view_->signout_link_->SetEnabled(enabled); | 307 signout_view_->signout_link_->SetEnabled(enabled); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 344 DCHECK(delegate_); | 322 DCHECK(delegate_); |
| 345 if (remove_button_ == sender) | 323 if (remove_button_ == sender) |
| 346 delegate_->OnRemoveUser(); | 324 delegate_->OnRemoveUser(); |
| 347 } | 325 } |
| 348 | 326 |
| 349 void UserView::OnLocaleChanged() { | 327 void UserView::OnLocaleChanged() { |
| 350 remove_button_->SetText(l10n_util::GetString(IDS_LOGIN_REMOVE)); | 328 remove_button_->SetText(l10n_util::GetString(IDS_LOGIN_REMOVE)); |
| 351 } | 329 } |
| 352 | 330 |
| 353 } // namespace chromeos | 331 } // namespace chromeos |
| OLD | NEW |