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

Side by Side Diff: chrome/browser/ui/views/profiles/profile_chooser_view.cc

Issue 1250323003: Vectorize profile badges in avatar menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: self review Created 5 years, 4 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
« no previous file with comments | « no previous file | ui/gfx/paint_vector_icon.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/ui/views/profiles/profile_chooser_view.h" 5 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h"
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/lifetime/application_lifetime.h" 10 #include "chrome/browser/lifetime/application_lifetime.h"
(...skipping 28 matching lines...) Expand all
39 #include "components/signin/core/browser/signin_header_helper.h" 39 #include "components/signin/core/browser/signin_header_helper.h"
40 #include "components/signin/core/browser/signin_manager.h" 40 #include "components/signin/core/browser/signin_manager.h"
41 #include "components/signin/core/common/profile_management_switches.h" 41 #include "components/signin/core/common/profile_management_switches.h"
42 #include "content/public/browser/render_widget_host_view.h" 42 #include "content/public/browser/render_widget_host_view.h"
43 #include "grit/theme_resources.h" 43 #include "grit/theme_resources.h"
44 #include "third_party/skia/include/core/SkColor.h" 44 #include "third_party/skia/include/core/SkColor.h"
45 #include "ui/base/l10n/l10n_util.h" 45 #include "ui/base/l10n/l10n_util.h"
46 #include "ui/base/resource/resource_bundle.h" 46 #include "ui/base/resource/resource_bundle.h"
47 #include "ui/compositor/clip_transform_recorder.h" 47 #include "ui/compositor/clip_transform_recorder.h"
48 #include "ui/gfx/canvas.h" 48 #include "ui/gfx/canvas.h"
49 #include "ui/gfx/image/canvas_image_source.h"
49 #include "ui/gfx/image/image.h" 50 #include "ui/gfx/image/image.h"
50 #include "ui/gfx/image/image_skia.h" 51 #include "ui/gfx/image/image_skia.h"
51 #include "ui/gfx/paint_vector_icon.h" 52 #include "ui/gfx/paint_vector_icon.h"
52 #include "ui/gfx/path.h" 53 #include "ui/gfx/path.h"
53 #include "ui/gfx/skia_util.h" 54 #include "ui/gfx/skia_util.h"
54 #include "ui/gfx/text_elider.h" 55 #include "ui/gfx/text_elider.h"
55 #include "ui/gfx/vector_icons_public2.h" 56 #include "ui/gfx/vector_icons_public2.h"
56 #include "ui/native_theme/native_theme.h" 57 #include "ui/native_theme/native_theme.h"
57 #include "ui/views/controls/button/blue_button.h" 58 #include "ui/views/controls/button/blue_button.h"
58 #include "ui/views/controls/button/image_button.h" 59 #include "ui/views/controls/button/image_button.h"
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 back_button_->GetPreferredSize().height()); 468 back_button_->GetPreferredSize().height());
468 return gfx::Size(width(), height); 469 return gfx::Size(width(), height);
469 } 470 }
470 471
471 views::ImageButton* back_button_; 472 views::ImageButton* back_button_;
472 views::Label* title_label_; 473 views::Label* title_label_;
473 474
474 DISALLOW_COPY_AND_ASSIGN(TitleCard); 475 DISALLOW_COPY_AND_ASSIGN(TitleCard);
475 }; 476 };
476 477
478 // ProfileBadge --------------------------------------------------------
479
480 const size_t kProfileBadgeSize = 30;
481 const size_t kProfileBadgeWhitePadding = 2;
482
483 // Draws a white circle, then a light blue circle, then a dark blue icon.
484 class ProfileBadge : public gfx::CanvasImageSource {
Evan Stade 2015/07/24 22:51:15 Depending on how much of this kind of customizatio
485 public:
486 ProfileBadge(gfx::VectorIconId id, size_t icon_size)
487 : CanvasImageSource(gfx::Size(kProfileBadgeSize, kProfileBadgeSize),
488 false),
489 id_(id),
490 icon_size_(icon_size) {}
491
492 ~ProfileBadge() override {}
493
494 // CanvasImageSource:
495 void Draw(gfx::Canvas* canvas) override {
496 const SkISize size = canvas->sk_canvas()->getDeviceSize();
497 gfx::Rect bounds(0, 0, size.width(), size.height());
498
499 SkPaint paint;
500 paint.setAntiAlias(true);
501 paint.setColor(SK_ColorWHITE);
502 canvas->DrawCircle(bounds.CenterPoint(), size.width() / 2, paint);
503
504 paint.setColor(SkColorSetRGB(0xAF, 0xD9, 0xFC));
505 canvas->DrawCircle(bounds.CenterPoint(),
506 size.width() / 2 - kProfileBadgeWhitePadding, paint);
507
508 int offset = (kProfileBadgeSize - icon_size_) / 2;
509 canvas->Translate(gfx::Vector2d(offset, offset));
510 gfx::PaintVectorIcon(canvas, id_, icon_size_, SkColorSetRGB(0, 0x66, 0xff));
511 }
512
513 private:
514 const gfx::VectorIconId id_;
515 const size_t icon_size_;
516
517 DISALLOW_COPY_AND_ASSIGN(ProfileBadge);
518 };
519
520 gfx::ImageSkia CreateBadgeForProfile(Profile* profile) {
521 ProfileBadge* badge =
522 profile->IsChild()
523 ? new ProfileBadge(gfx::VectorIconId::ACCOUNT_CHILD_INVERT, 26)
524 : new ProfileBadge(gfx::VectorIconId::SUPERVISOR_ACCOUNT, 20);
525
526 return gfx::ImageSkia(badge, badge->size());
527 }
528
477 // ProfileChooserView --------------------------------------------------------- 529 // ProfileChooserView ---------------------------------------------------------
478 530
479 // static 531 // static
480 ProfileChooserView* ProfileChooserView::profile_bubble_ = NULL; 532 ProfileChooserView* ProfileChooserView::profile_bubble_ = NULL;
481 bool ProfileChooserView::close_on_deactivate_for_testing_ = true; 533 bool ProfileChooserView::close_on_deactivate_for_testing_ = true;
482 534
483 // static 535 // static
484 void ProfileChooserView::ShowBubble( 536 void ProfileChooserView::ShowBubble(
485 profiles::BubbleViewMode view_mode, 537 profiles::BubbleViewMode view_mode,
486 profiles::TutorialMode tutorial_mode, 538 profiles::TutorialMode tutorial_mode,
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after
1176 current_profile_photo_ = new EditableProfilePhoto( 1228 current_profile_photo_ = new EditableProfilePhoto(
1177 this, avatar_item.icon, !is_guest, 1229 this, avatar_item.icon, !is_guest,
1178 gfx::Rect(x_offset, 0, kLargeImageSide, kLargeImageSide)); 1230 gfx::Rect(x_offset, 0, kLargeImageSide, kLargeImageSide));
1179 SizedContainer* profile_icon_container = 1231 SizedContainer* profile_icon_container =
1180 new SizedContainer(gfx::Size(column_width, kLargeImageSide)); 1232 new SizedContainer(gfx::Size(column_width, kLargeImageSide));
1181 profile_icon_container->AddChildView(current_profile_photo_); 1233 profile_icon_container->AddChildView(current_profile_photo_);
1182 1234
1183 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 1235 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
1184 if (browser_->profile()->IsSupervised()) { 1236 if (browser_->profile()->IsSupervised()) {
1185 views::ImageView* supervised_icon = new views::ImageView(); 1237 views::ImageView* supervised_icon = new views::ImageView();
1186 int image_id = browser_->profile()->IsChild() 1238 supervised_icon->SetImage(CreateBadgeForProfile(browser_->profile()));
1187 ? IDR_ICON_PROFILES_MENU_CHILD
1188 : IDR_ICON_PROFILES_MENU_LEGACY_SUPERVISED;
1189 supervised_icon->SetImage(rb->GetImageSkiaNamed(image_id));
1190 gfx::Size preferred_size = supervised_icon->GetPreferredSize(); 1239 gfx::Size preferred_size = supervised_icon->GetPreferredSize();
1191 gfx::Rect parent_bounds = current_profile_photo_->bounds(); 1240 gfx::Rect parent_bounds = current_profile_photo_->bounds();
1192 supervised_icon->SetBounds( 1241 supervised_icon->SetBounds(
1193 parent_bounds.right() - preferred_size.width(), 1242 parent_bounds.right() - preferred_size.width(),
1194 parent_bounds.bottom() - preferred_size.height(), 1243 parent_bounds.bottom() - preferred_size.height(),
1195 preferred_size.width(), 1244 preferred_size.width(),
1196 preferred_size.height()); 1245 preferred_size.height());
1197 profile_icon_container->AddChildView(supervised_icon); 1246 profile_icon_container->AddChildView(supervised_icon);
1198 } 1247 }
1199 1248
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
1732 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != 1781 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) !=
1733 IncognitoModePrefs::DISABLED; 1782 IncognitoModePrefs::DISABLED;
1734 return incognito_available && !browser_->profile()->IsGuestSession(); 1783 return incognito_available && !browser_->profile()->IsGuestSession();
1735 } 1784 }
1736 1785
1737 void ProfileChooserView::PostActionPerformed( 1786 void ProfileChooserView::PostActionPerformed(
1738 ProfileMetrics::ProfileDesktopMenu action_performed) { 1787 ProfileMetrics::ProfileDesktopMenu action_performed) {
1739 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); 1788 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_);
1740 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; 1789 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE;
1741 } 1790 }
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/paint_vector_icon.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698