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

Side by Side Diff: ash/system/user/tray_user.cc

Issue 9813020: Adjust uber tray spacing around avatar and draw avatar using rounded rectangle. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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
« ash/system/tray/system_tray.cc ('K') | « ash/system/user/tray_user.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ash/system/user/tray_user.h" 5 #include "ash/system/user/tray_user.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/system/tray/system_tray_delegate.h" 8 #include "ash/system/tray/system_tray_delegate.h"
9 #include "ash/system/tray/tray_constants.h" 9 #include "ash/system/tray/tray_constants.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "grit/ash_strings.h" 11 #include "grit/ash_strings.h"
12 #include "third_party/skia/include/core/SkCanvas.h"
13 #include "third_party/skia/include/core/SkPaint.h"
14 #include "third_party/skia/include/core/SkPath.h"
15 #include "third_party/skia/include/core/SkShader.h"
12 #include "ui/base/resource/resource_bundle.h" 16 #include "ui/base/resource/resource_bundle.h"
13 #include "ui/gfx/canvas.h" 17 #include "ui/gfx/canvas.h"
14 #include "ui/gfx/image/image.h" 18 #include "ui/gfx/image/image.h"
15 #include "ui/gfx/size.h" 19 #include "ui/gfx/size.h"
20 #include "ui/gfx/skia_util.h"
16 #include "ui/views/controls/button/button.h" 21 #include "ui/views/controls/button/button.h"
17 #include "ui/views/controls/button/text_button.h" 22 #include "ui/views/controls/button/text_button.h"
18 #include "ui/views/controls/image_view.h" 23 #include "ui/views/controls/image_view.h"
19 #include "ui/views/controls/label.h" 24 #include "ui/views/controls/label.h"
20 #include "ui/views/layout/box_layout.h" 25 #include "ui/views/layout/box_layout.h"
21 #include "ui/views/view.h" 26 #include "ui/views/view.h"
22 27
23 namespace { 28 namespace {
24 29
25 const int kPaddingAroundButtons = 5; 30 const int kPaddingAroundButtons = 5;
26 31
27 const int kUserInfoHorizontalPadding = 14; 32 const int kUserInfoHorizontalPadding = 14;
28 const int kUserInfoVerticalPadding = 10; 33 const int kUserInfoVerticalPadding = 10;
29 const int kUserInfoPaddingBetweenItems = 3; 34 const int kUserInfoPaddingBetweenItems = 3;
30 35
31 const int kUserIconSize = 32; 36 const int kUserIconSize = 27;
37 const int kUserIconCornerRadius = 2;
32 38
33 const SkColor kButtonStrokeColor = SkColorSetRGB(0xdd, 0xdd, 0xdd); 39 const SkColor kButtonStrokeColor = SkColorSetRGB(0xdd, 0xdd, 0xdd);
34 40
35 // A custom textbutton with some extra vertical padding, and custom border, 41 // A custom textbutton with some extra vertical padding, and custom border,
36 // alignment and hover-effects. 42 // alignment and hover-effects.
37 class TrayButton : public views::TextButton { 43 class TrayButton : public views::TextButton {
38 public: 44 public:
39 TrayButton(views::ButtonListener* listener, const string16& text) 45 TrayButton(views::ButtonListener* listener, const string16& text)
40 : views::TextButton(listener, text), 46 : views::TextButton(listener, text),
41 hover_(false), 47 hover_(false),
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 views::Label* email_; 259 views::Label* email_;
254 views::View* update_; 260 views::View* update_;
255 261
256 TrayButton* shutdown_; 262 TrayButton* shutdown_;
257 TrayButton* signout_; 263 TrayButton* signout_;
258 TrayButton* lock_; 264 TrayButton* lock_;
259 265
260 DISALLOW_COPY_AND_ASSIGN(UserView); 266 DISALLOW_COPY_AND_ASSIGN(UserView);
261 }; 267 };
262 268
269 // A custom image view with rounded edges.
270 class RoundedImageView : public views::View {
271 public:
272 // Constructs a new rounded image view with rounded corners of radius
273 // |corner_radius|.
274 RoundedImageView(int corner_radius) : corner_radius_(corner_radius) {
Ben Goodger (Google) 2012/03/21 22:10:41 explicit
flackr 2012/03/21 23:19:05 Done.
275 }
276
277 virtual ~RoundedImageView() {
278 }
279
280 // Set the bitmap that should be displayed from a pointer. The pointer
281 // contents is copied in the receiver's bitmap.
282 void SetImage(const SkBitmap& bm) {
283 image_ = bm;
284 SetImageSize(gfx::Size(bm.width(), bm.height()));
285 }
286
287 // Set the desired image size.
288 void SetImageSize(const gfx::Size& image_size) {
289 image_size_ = image_size;
290 PreferredSizeChanged();
291 }
292
293 // Overridden from views::View.
294 virtual gfx::Size GetPreferredSize() OVERRIDE {
295 return image_size_;
296 }
297
298 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
299 View::OnPaint(canvas);
300 gfx::Rect image_bounds(image_size_);
301 const SkScalar kRadius = SkIntToScalar(corner_radius_);
302 SkPath path;
303 path.addRoundRect(gfx::RectToSkRect(image_bounds), kRadius, kRadius);
304
305 SkPaint paint;
306 SkShader* shader = SkShader::CreateBitmapShader(image_,
307 SkShader::kRepeat_TileMode,
308 SkShader::kRepeat_TileMode);
309 SkMatrix shader_scale;
310 shader_scale.setScale(SkFloatToScalar(
311 static_cast<float>(image_bounds.width()) / image_.width()),
312 SkFloatToScalar(static_cast<float>(
313 image_bounds.height()) / image_.height()));
314 shader->setLocalMatrix(shader_scale);
315
316 paint.setShader(shader);
317 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode);
318 shader->unref();
319 canvas->sk_canvas()->drawPath(path, paint);
320 }
321
322 private:
323 SkBitmap image_;
324 gfx::Size image_size_;
325 int corner_radius_;
326 };
Ben Goodger (Google) 2012/03/21 22:10:41 DISALLOW_COPY
flackr 2012/03/21 23:19:05 Done.
327
263 } // namespace tray 328 } // namespace tray
264 329
265 TrayUser::TrayUser() { 330 TrayUser::TrayUser() {
266 } 331 }
267 332
268 TrayUser::~TrayUser() { 333 TrayUser::~TrayUser() {
269 } 334 }
270 335
271 views::View* TrayUser::CreateTrayView(user::LoginStatus status) { 336 views::View* TrayUser::CreateTrayView(user::LoginStatus status) {
272 avatar_.reset(new views::ImageView); 337 avatar_.reset(new tray::RoundedImageView(kUserIconCornerRadius));
273 if (status == user::LOGGED_IN_USER || status == user::LOGGED_IN_OWNER) { 338 if (status == user::LOGGED_IN_USER || status == user::LOGGED_IN_OWNER) {
274 avatar_->SetImage( 339 avatar_->SetImage(
275 ash::Shell::GetInstance()->tray_delegate()->GetUserImage()); 340 ash::Shell::GetInstance()->tray_delegate()->GetUserImage());
276 avatar_->SetImageSize(gfx::Size(kUserIconSize, kUserIconSize)); 341 avatar_->SetImageSize(gfx::Size(kUserIconSize, kUserIconSize));
277 } else { 342 } else {
278 avatar_->SetVisible(false); 343 avatar_->SetVisible(false);
279 } 344 }
280 return avatar_.get(); 345 return avatar_.get();
281 } 346 }
282 347
(...skipping 25 matching lines...) Expand all
308 user_->RefreshForUpdate(); 373 user_->RefreshForUpdate();
309 } 374 }
310 375
311 void TrayUser::OnUserUpdate() { 376 void TrayUser::OnUserUpdate() {
312 avatar_->SetImage( 377 avatar_->SetImage(
313 ash::Shell::GetInstance()->tray_delegate()->GetUserImage()); 378 ash::Shell::GetInstance()->tray_delegate()->GetUserImage());
314 } 379 }
315 380
316 } // namespace internal 381 } // namespace internal
317 } // namespace ash 382 } // namespace ash
OLDNEW
« ash/system/tray/system_tray.cc ('K') | « ash/system/user/tray_user.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698