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