| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/chromeos/login/helper.h" | 10 #include "chrome/browser/chromeos/login/helper.h" |
| 11 #include "chrome/browser/chromeos/login/rounded_rect_painter.h" | |
| 12 #include "chrome/browser/chromeos/view_ids.h" | 11 #include "chrome/browser/chromeos/view_ids.h" |
| 13 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" |
| 14 #include "grit/theme_resources_standard.h" | 13 #include "grit/theme_resources_standard.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
| 16 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
| 17 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
| 18 #include "ui/gfx/canvas_skia.h" | 17 #include "ui/gfx/canvas_skia.h" |
| 19 #include "ui/gfx/gtk_util.h" | 18 #include "ui/gfx/gtk_util.h" |
| 20 #include "ui/gfx/rect.h" | 19 #include "ui/gfx/rect.h" |
| 21 #include "views/background.h" | 20 #include "views/background.h" |
| 22 #include "views/controls/button/text_button.h" | 21 #include "views/controls/button/text_button.h" |
| 23 #include "views/controls/image_view.h" | 22 #include "views/controls/image_view.h" |
| 24 #include "views/controls/label.h" | 23 #include "views/controls/label.h" |
| 25 #include "views/controls/link.h" | 24 #include "views/controls/link.h" |
| 26 #include "views/controls/link_listener.h" | 25 #include "views/controls/link_listener.h" |
| 27 #include "views/painter.h" | |
| 28 | 26 |
| 29 namespace { | 27 namespace { |
| 30 | 28 |
| 31 // Background color and corner radius of the login status label and | 29 // Background color of the signout button. |
| 32 // signout button. | |
| 33 const SkColor kSignoutBackgroundColor = 0xFF007700; | 30 const SkColor kSignoutBackgroundColor = 0xFF007700; |
| 34 | 31 |
| 35 // Horiz/Vert insets for Signout view. | 32 // Horiz/Vert insets for Signout view. |
| 36 const int kSignoutViewHorizontalInsets = 10; | 33 const int kSignoutViewHorizontalInsets = 10; |
| 37 const int kSignoutViewVerticalInsets = 5; | 34 const int kSignoutViewVerticalInsets = 5; |
| 38 const int kMinControlHeight = 16; | 35 const int kMinControlHeight = 16; |
| 39 | 36 |
| 40 // 1x Border around image pod. | 37 // 1x Border around image pod. |
| 41 const SkColor kImageBorderColor = 0xFFCCCCCC; | 38 const SkColor kImageBorderColor = 0xFFCCCCCC; |
| 42 | 39 |
| 43 // Padding between remove button and top right image corner. | 40 // Padding between remove button and top right image corner. |
| 44 const int kRemoveButtonPadding = 3; | 41 const int kRemoveButtonPadding = 3; |
| 45 | 42 |
| 46 // Draws green-ish background for signout view with | |
| 47 // rounded corners at the bottom. | |
| 48 class SignoutBackgroundPainter : public views::Painter { | |
| 49 virtual void Paint(int w, int h, gfx::Canvas* canvas) { | |
| 50 SkRect rect = {0, 0, w, h}; | |
| 51 SkPath path; | |
| 52 path.addRect(rect); | |
| 53 SkPaint paint; | |
| 54 paint.setStyle(SkPaint::kFill_Style); | |
| 55 paint.setFlags(SkPaint::kAntiAlias_Flag); | |
| 56 paint.setColor(kSignoutBackgroundColor); | |
| 57 canvas->GetSkCanvas()->drawPath(path, paint); | |
| 58 } | |
| 59 }; | |
| 60 | |
| 61 } // namespace | 43 } // namespace |
| 62 | 44 |
| 63 namespace chromeos { | 45 namespace chromeos { |
| 64 | 46 |
| 65 using login::kBackgroundColor; | 47 using login::kBackgroundColor; |
| 66 using login::kTextColor; | 48 using login::kTextColor; |
| 67 using login::kUserImageSize; | 49 using login::kUserImageSize; |
| 68 | 50 |
| 69 // The view that shows the Sign out button below the user's image. | 51 // The view that shows the Sign out button below the user's image. |
| 70 class SignoutView : public views::View { | 52 class SignoutView : public views::View { |
| 71 public: | 53 public: |
| 72 explicit SignoutView(views::LinkListener* link_listener) { | 54 explicit SignoutView(views::LinkListener* link_listener) { |
| 73 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 55 set_background( |
| 74 const gfx::Font& font = rb.GetFont(ResourceBundle::SmallFont); | 56 views::Background::CreateSolidBackground(kSignoutBackgroundColor)); |
| 75 | 57 |
| 76 active_user_label_ = new views::Label( | 58 active_user_label_ = new views::Label( |
| 77 l10n_util::GetStringUTF16(IDS_SCREEN_LOCK_ACTIVE_USER)); | 59 l10n_util::GetStringUTF16(IDS_SCREEN_LOCK_ACTIVE_USER)); |
| 60 const gfx::Font& font = |
| 61 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::SmallFont); |
| 78 active_user_label_->SetFont(font); | 62 active_user_label_->SetFont(font); |
| 79 active_user_label_->SetColor(kTextColor); | 63 active_user_label_->SetBackgroundColor(background()->get_color()); |
| 64 active_user_label_->SetEnabledColor(kTextColor); |
| 80 | 65 |
| 81 signout_link_ = new views::Link( | 66 signout_link_ = new views::Link( |
| 82 l10n_util::GetStringUTF16(IDS_SCREEN_LOCK_SIGN_OUT)); | 67 l10n_util::GetStringUTF16(IDS_SCREEN_LOCK_SIGN_OUT)); |
| 83 signout_link_->set_listener(link_listener); | 68 signout_link_->set_listener(link_listener); |
| 84 signout_link_->SetFont(font); | 69 signout_link_->SetFont(font); |
| 85 signout_link_->SetColor(kTextColor); | |
| 86 signout_link_->set_focusable(true); | 70 signout_link_->set_focusable(true); |
| 87 signout_link_->SetHighlightedColor(kTextColor); | 71 signout_link_->SetBackgroundColor(background()->get_color()); |
| 72 signout_link_->SetPressedColor(kTextColor); |
| 88 signout_link_->SetDisabledColor(kTextColor); | 73 signout_link_->SetDisabledColor(kTextColor); |
| 89 signout_link_->SetNormalColor(kTextColor); | 74 signout_link_->SetEnabledColor(kTextColor); |
| 90 signout_link_->set_id(VIEW_ID_SCREEN_LOCKER_SIGNOUT_LINK); | 75 signout_link_->set_id(VIEW_ID_SCREEN_LOCKER_SIGNOUT_LINK); |
| 91 | 76 |
| 92 AddChildView(active_user_label_); | 77 AddChildView(active_user_label_); |
| 93 AddChildView(signout_link_); | 78 AddChildView(signout_link_); |
| 94 | |
| 95 set_background(views::Background::CreateBackgroundPainter( | |
| 96 true, new SignoutBackgroundPainter())); | |
| 97 } | 79 } |
| 98 | 80 |
| 99 // views::View overrides. | 81 // views::View overrides. |
| 100 virtual void Layout() { | 82 virtual void Layout() { |
| 101 gfx::Size label = active_user_label_->GetPreferredSize(); | 83 gfx::Size label = active_user_label_->GetPreferredSize(); |
| 102 gfx::Size button = signout_link_->GetPreferredSize(); | 84 gfx::Size button = signout_link_->GetPreferredSize(); |
| 103 active_user_label_->SetBounds( | 85 active_user_label_->SetBounds( |
| 104 kSignoutViewHorizontalInsets, (height() - label.height()) / 2, | 86 kSignoutViewHorizontalInsets, (height() - label.height()) / 2, |
| 105 label.width(), label.height()); | 87 label.width(), label.height()); |
| 106 signout_link_->SetBounds( | 88 signout_link_->SetBounds( |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 SetIcon(SkBitmap()); | 149 SetIcon(SkBitmap()); |
| 168 views::TextButton::SetText(text_); | 150 views::TextButton::SetText(text_); |
| 169 | 151 |
| 170 const SkColor kStrokeColor = SK_ColorWHITE; | 152 const SkColor kStrokeColor = SK_ColorWHITE; |
| 171 const SkColor kButtonColor = 0xFFE94949; | 153 const SkColor kButtonColor = 0xFFE94949; |
| 172 const int kStrokeWidth = 1; | 154 const int kStrokeWidth = 1; |
| 173 const int kVerticalPadding = 4; | 155 const int kVerticalPadding = 4; |
| 174 const int kHorizontalPadding = 8; | 156 const int kHorizontalPadding = 8; |
| 175 const int kCornerRadius = 4; | 157 const int kCornerRadius = 4; |
| 176 | 158 |
| 177 set_background( | 159 set_background(CreateRoundedBackground(kCornerRadius, kStrokeWidth, |
| 178 CreateRoundedBackground( | 160 kButtonColor, kStrokeColor)); |
| 179 kCornerRadius, kStrokeWidth, kButtonColor, kStrokeColor)); | |
| 180 | 161 |
| 181 set_border( | 162 set_border(views::Border::CreateEmptyBorder(kVerticalPadding, |
| 182 views::Border::CreateEmptyBorder(kVerticalPadding, | 163 kHorizontalPadding, kVerticalPadding, kHorizontalPadding)); |
| 183 kHorizontalPadding, | |
| 184 kVerticalPadding, | |
| 185 kHorizontalPadding)); | |
| 186 | 164 |
| 187 UpdatePosition(); | 165 UpdatePosition(); |
| 188 was_first_click_ = true; | 166 was_first_click_ = true; |
| 189 } else { | 167 } else { |
| 190 // On second click propagate to base class to fire ButtonPressed. | 168 // On second click propagate to base class to fire ButtonPressed. |
| 191 views::TextButton::NotifyClick(event); | 169 views::TextButton::NotifyClick(event); |
| 192 } | 170 } |
| 193 } | 171 } |
| 194 | 172 |
| 195 virtual void SetText(const std::wstring& text) OVERRIDE { | 173 virtual void SetText(const std::wstring& text) OVERRIDE { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 // UserView's layout never changes, so let's layout once here. | 254 // UserView's layout never changes, so let's layout once here. |
| 277 image_view_->SetBounds(0, 0, kUserImageSize, kUserImageSize); | 255 image_view_->SetBounds(0, 0, kUserImageSize, kUserImageSize); |
| 278 AddChildView(image_view_); | 256 AddChildView(image_view_); |
| 279 | 257 |
| 280 if (signout_view_) { | 258 if (signout_view_) { |
| 281 signout_view_->SetBounds(0, kUserImageSize, kUserImageSize, | 259 signout_view_->SetBounds(0, kUserImageSize, kUserImageSize, |
| 282 signout_view_->GetPreferredSize().height()); | 260 signout_view_->GetPreferredSize().height()); |
| 283 AddChildView(signout_view_); | 261 AddChildView(signout_view_); |
| 284 } | 262 } |
| 285 | 263 |
| 286 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
| 287 remove_button_ = new RemoveButton( | 264 remove_button_ = new RemoveButton( |
| 288 this, | 265 this, |
| 289 *rb.GetBitmapNamed(IDR_CLOSE_BAR_H), | 266 *ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_CLOSE_BAR_H), |
| 290 UTF16ToWide(l10n_util::GetStringUTF16(IDS_LOGIN_REMOVE)), | 267 UTF16ToWide(l10n_util::GetStringUTF16(IDS_LOGIN_REMOVE)), |
| 291 gfx::Point(kUserImageSize - kRemoveButtonPadding, kRemoveButtonPadding)); | 268 gfx::Point(kUserImageSize - kRemoveButtonPadding, kRemoveButtonPadding)); |
| 292 remove_button_->SetVisible(false); | 269 remove_button_->SetVisible(false); |
| 293 AddChildView(remove_button_); | 270 AddChildView(remove_button_); |
| 294 } | 271 } |
| 295 | 272 |
| 296 void UserView::SetImage(const SkBitmap& image, const SkBitmap& image_hot) { | 273 void UserView::SetImage(const SkBitmap& image, const SkBitmap& image_hot) { |
| 297 int desired_size = std::min(image.width(), image.height()); | 274 int desired_size = std::min(image.width(), image.height()); |
| 298 // Desired size is not preserved if it's greater than 75% of kUserImageSize. | 275 // Desired size is not preserved if it's greater than 75% of kUserImageSize. |
| 299 if (desired_size * 4 > 3 * kUserImageSize) | 276 if (desired_size * 4 > 3 * kUserImageSize) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 delegate_->OnRemoveUser(); | 312 delegate_->OnRemoveUser(); |
| 336 } | 313 } |
| 337 | 314 |
| 338 void UserView::OnLocaleChanged() { | 315 void UserView::OnLocaleChanged() { |
| 339 remove_button_->SetText( | 316 remove_button_->SetText( |
| 340 UTF16ToWide(l10n_util::GetStringUTF16(IDS_LOGIN_REMOVE))); | 317 UTF16ToWide(l10n_util::GetStringUTF16(IDS_LOGIN_REMOVE))); |
| 341 delegate_->OnLocaleChanged(); | 318 delegate_->OnLocaleChanged(); |
| 342 } | 319 } |
| 343 | 320 |
| 344 } // namespace chromeos | 321 } // namespace chromeos |
| OLD | NEW |