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

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

Issue 1452923002: Vectorize MD otr frame icon (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: dont crash in tests Created 5 years, 1 month 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
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/avatar_menu_button.h" 5 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
(...skipping 15 matching lines...) Expand all
26 #include "ui/views/view_targeter.h" 26 #include "ui/views/view_targeter.h"
27 #include "ui/views/widget/widget.h" 27 #include "ui/views/widget/widget.h"
28 28
29 static inline int Round(double x) { 29 static inline int Round(double x) {
30 return static_cast<int>(x + 0.5); 30 return static_cast<int>(x + 0.5);
31 } 31 }
32 32
33 // static 33 // static
34 const char AvatarMenuButton::kViewClassName[] = "AvatarMenuButton"; 34 const char AvatarMenuButton::kViewClassName[] = "AvatarMenuButton";
35 35
36 AvatarMenuButton::AvatarMenuButton(Browser* browser, bool disabled) 36 AvatarMenuButton::AvatarMenuButton(BrowserView* browser_view)
37 : MenuButton(NULL, base::string16(), this, false), 37 : MenuButton(NULL, base::string16(), this, false),
38 browser_(browser), 38 browser_view_(browser_view),
39 disabled_(disabled), 39 enabled_(browser_view_->IsRegularOrGuestSession()),
40 is_rectangle_(false), 40 is_rectangle_(false),
41 old_height_(0), 41 old_height_(0),
42 button_on_right_(false) { 42 button_on_right_(false) {
43 // In RTL mode, the avatar icon should be looking the opposite direction. 43 // In RTL mode, the avatar icon should be looking the opposite direction.
44 EnableCanvasFlippingForRTLUI(true); 44 EnableCanvasFlippingForRTLUI(true);
45 45
46 SetEventTargeter( 46 SetEventTargeter(
47 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); 47 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this)));
48 } 48 }
49 49
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 87
88 void AvatarMenuButton::SetAvatarIcon(const gfx::Image& icon, 88 void AvatarMenuButton::SetAvatarIcon(const gfx::Image& icon,
89 bool is_rectangle) { 89 bool is_rectangle) {
90 icon_.reset(new gfx::Image(icon)); 90 icon_.reset(new gfx::Image(icon));
91 button_icon_ = gfx::ImageSkia(); 91 button_icon_ = gfx::ImageSkia();
92 is_rectangle_ = is_rectangle; 92 is_rectangle_ = is_rectangle;
93 SchedulePaint(); 93 SchedulePaint();
94 } 94 }
95 95
96 // static 96 // static
97 bool AvatarMenuButton::GetAvatarImages(Profile* profile, 97 bool AvatarMenuButton::GetAvatarImages(BrowserView* browser_view,
98 bool should_show_avatar_menu, 98 bool should_show_avatar_menu,
99 gfx::Image* avatar, 99 gfx::Image* avatar,
100 gfx::Image* taskbar_badge_avatar, 100 gfx::Image* taskbar_badge_avatar,
101 bool* is_rectangle) { 101 bool* is_rectangle) {
102 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 102 const Profile* profile = browser_view->browser()->profile();
103 if (profile->GetProfileType() == Profile::GUEST_PROFILE) { 103 if (profile->GetProfileType() == Profile::GUEST_PROFILE) {
104 *avatar = rb. 104 *avatar = ui::ResourceBundle::GetSharedInstance().GetImageNamed(
105 GetImageNamed(profiles::GetPlaceholderAvatarIconResourceID()); 105 profiles::GetPlaceholderAvatarIconResourceID());
106 } else if (profile->GetProfileType() == Profile::INCOGNITO_PROFILE) { 106 } else if (profile->GetProfileType() == Profile::INCOGNITO_PROFILE) {
107 *avatar = rb.GetImageNamed(IDR_OTR_ICON); 107 *avatar = gfx::Image(browser_view->GetOTRAvatarIcon());
108 // TODO(nkostylev): Allow this on ChromeOS once the ChromeOS test 108 // TODO(nkostylev): Allow this on ChromeOS once the ChromeOS test
109 // environment handles profile directories correctly. 109 // environment handles profile directories correctly.
110 #if !defined(OS_CHROMEOS) 110 #if !defined(OS_CHROMEOS)
111 bool is_badge_rectangle = false; 111 bool is_badge_rectangle = false;
112 // The taskbar badge should be the profile avatar, not the OTR avatar. 112 // The taskbar badge should be the profile avatar, not the OTR avatar.
113 AvatarMenu::GetImageForMenuButton(profile->GetPath(), 113 AvatarMenu::GetImageForMenuButton(profile->GetPath(),
114 taskbar_badge_avatar, 114 taskbar_badge_avatar,
115 &is_badge_rectangle); 115 &is_badge_rectangle);
116 #endif 116 #endif
117 } else if (should_show_avatar_menu) { 117 } else if (should_show_avatar_menu) {
(...skipping 18 matching lines...) Expand all
136 &is_badge_rectangle); 136 &is_badge_rectangle);
137 #endif 137 #endif
138 } 138 }
139 return true; 139 return true;
140 } 140 }
141 141
142 // views::ViewTargeterDelegate: 142 // views::ViewTargeterDelegate:
143 bool AvatarMenuButton::DoesIntersectRect(const views::View* target, 143 bool AvatarMenuButton::DoesIntersectRect(const views::View* target,
144 const gfx::Rect& rect) const { 144 const gfx::Rect& rect) const {
145 CHECK_EQ(target, this); 145 CHECK_EQ(target, this);
146 return !disabled_ && 146 return enabled_ &&
147 views::ViewTargeterDelegate::DoesIntersectRect(target, rect); 147 views::ViewTargeterDelegate::DoesIntersectRect(target, rect);
148 } 148 }
149 149
150 // views::MenuButtonListener implementation 150 // views::MenuButtonListener implementation
151 void AvatarMenuButton::OnMenuButtonClicked(views::View* source, 151 void AvatarMenuButton::OnMenuButtonClicked(views::View* source,
152 const gfx::Point& point) { 152 const gfx::Point& point) {
153 if (!disabled_) 153 if (enabled_)
154 chrome::ShowAvatarMenu(browser_); 154 chrome::ShowAvatarMenu(browser_view_->browser());
155 } 155 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698