| 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_(new RoundedView<PodImageView>), | 244 image_view_(new RoundedView<PodImageView>), |
| 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 Init(need_background); | 250 Init(need_background); |
| 253 } | 251 } |
| 254 | 252 |
| 255 void UserView::Init(bool need_background) { | 253 void UserView::Init(bool need_background) { |
| 256 if (need_background) { | 254 if (need_background) { |
| 257 image_view_->set_background( | 255 image_view_->set_background( |
| 258 views::Background::CreateSolidBackground(kBackgroundColor)); | 256 views::Background::CreateSolidBackground(kBackgroundColor)); |
| 259 } | 257 } |
| 260 if (throbber_) { | |
| 261 int w = throbber_->GetPreferredSize().width(); | |
| 262 int h = throbber_->GetPreferredSize().height(); | |
| 263 throbber_->SetBounds(kUserImageSize / 2 - w / 2, | |
| 264 kUserImageSize / 2 - h / 2 , w, h); | |
| 265 // Throbber should be actually hidden while stopped so tooltip manager | |
| 266 // doesn't find it. | |
| 267 throbber_->SetVisible(false); | |
| 268 image_view_->AddChildView(throbber_); | |
| 269 } | |
| 270 | 258 |
| 271 // UserView's layout never changes, so let's layout once here. | 259 // UserView's layout never changes, so let's layout once here. |
| 272 image_view_->SetBounds(0, 0, kUserImageSize, kUserImageSize); | 260 image_view_->SetBounds(0, 0, kUserImageSize, kUserImageSize); |
| 273 AddChildView(image_view_); | 261 AddChildView(image_view_); |
| 274 | 262 |
| 275 if (signout_view_) { | 263 if (signout_view_) { |
| 276 signout_view_->SetBounds(0, kUserImageSize, kUserImageSize, | 264 signout_view_->SetBounds(0, kUserImageSize, kUserImageSize, |
| 277 signout_view_->GetPreferredSize().height()); | 265 signout_view_->GetPreferredSize().height()); |
| 278 AddChildView(signout_view_); | 266 AddChildView(signout_view_); |
| 279 } | 267 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 295 desired_size = kUserImageSize; | 283 desired_size = kUserImageSize; |
| 296 image_view_->SetImageSize(gfx::Size(desired_size, desired_size)); | 284 image_view_->SetImageSize(gfx::Size(desired_size, desired_size)); |
| 297 image_view_->SetImage(image, image_hot); | 285 image_view_->SetImage(image, image_hot); |
| 298 } | 286 } |
| 299 | 287 |
| 300 void UserView::SetTooltipText(const std::wstring& text) { | 288 void UserView::SetTooltipText(const std::wstring& text) { |
| 301 DCHECK(image_view_); | 289 DCHECK(image_view_); |
| 302 image_view_->SetTooltipText(text); | 290 image_view_->SetTooltipText(text); |
| 303 } | 291 } |
| 304 | 292 |
| 305 void UserView::StartThrobber() { | |
| 306 throbber_->SetVisible(true); | |
| 307 throbber_->Start(); | |
| 308 } | |
| 309 | |
| 310 void UserView::StopThrobber() { | |
| 311 throbber_->Stop(); | |
| 312 throbber_->SetVisible(false); | |
| 313 } | |
| 314 | |
| 315 gfx::Size UserView::GetPreferredSize() { | 293 gfx::Size UserView::GetPreferredSize() { |
| 316 return gfx::Size( | 294 return gfx::Size( |
| 317 kUserImageSize, | 295 kUserImageSize, |
| 318 kUserImageSize + | 296 kUserImageSize + |
| 319 (signout_view_ ? signout_view_->GetPreferredSize().height() : 0)); | 297 (signout_view_ ? signout_view_->GetPreferredSize().height() : 0)); |
| 320 } | 298 } |
| 321 | 299 |
| 322 void UserView::SetSignoutEnabled(bool enabled) { | 300 void UserView::SetSignoutEnabled(bool enabled) { |
| 323 DCHECK(signout_view_); | 301 DCHECK(signout_view_); |
| 324 signout_view_->signout_link_->SetEnabled(enabled); | 302 signout_view_->signout_link_->SetEnabled(enabled); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 339 DCHECK(delegate_); | 317 DCHECK(delegate_); |
| 340 if (remove_button_ == sender) | 318 if (remove_button_ == sender) |
| 341 delegate_->OnRemoveUser(); | 319 delegate_->OnRemoveUser(); |
| 342 } | 320 } |
| 343 | 321 |
| 344 void UserView::OnLocaleChanged() { | 322 void UserView::OnLocaleChanged() { |
| 345 remove_button_->SetText(l10n_util::GetString(IDS_LOGIN_REMOVE)); | 323 remove_button_->SetText(l10n_util::GetString(IDS_LOGIN_REMOVE)); |
| 346 } | 324 } |
| 347 | 325 |
| 348 } // namespace chromeos | 326 } // namespace chromeos |
| OLD | NEW |