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

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

Issue 1009403002: Refactor the avatar button/icon class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 7 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
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 17 matching lines...) Expand all
28 #include "ui/views/widget/widget.h" 28 #include "ui/views/widget/widget.h"
29 29
30 static inline int Round(double x) { 30 static inline int Round(double x) {
31 return static_cast<int>(x + 0.5); 31 return static_cast<int>(x + 0.5);
32 } 32 }
33 33
34 // static 34 // static
35 const char AvatarMenuButton::kViewClassName[] = "AvatarMenuButton"; 35 const char AvatarMenuButton::kViewClassName[] = "AvatarMenuButton";
36 36
37 AvatarMenuButton::AvatarMenuButton(Browser* browser, bool disabled) 37 AvatarMenuButton::AvatarMenuButton(Browser* browser, bool disabled)
38 : MenuButton(NULL, base::string16(), this, false), 38 : AvatarBaseButton(browser),
39 browser_(browser), 39 MenuButton(NULL, base::string16(), this, false),
40 disabled_(disabled), 40 disabled_(disabled),
41 is_rectangle_(false), 41 is_rectangle_(false),
42 old_height_(0), 42 old_height_(0),
43 button_on_right_(false) { 43 button_on_right_(false) {
44 // In RTL mode, the avatar icon should be looking the opposite direction. 44 // In RTL mode, the avatar icon should be looking the opposite direction.
45 EnableCanvasFlippingForRTLUI(true); 45 EnableCanvasFlippingForRTLUI(true);
46 46
47 SetEventTargeter( 47 SetEventTargeter(
48 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); 48 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this)));
49
50 Update();
49 } 51 }
50 52
51 AvatarMenuButton::~AvatarMenuButton() { 53 AvatarMenuButton::~AvatarMenuButton() {
52 } 54 }
53 55
54 const char* AvatarMenuButton::GetClassName() const { 56 const char* AvatarMenuButton::GetClassName() const {
55 return kViewClassName; 57 return kViewClassName;
56 } 58 }
57 59
58 void AvatarMenuButton::OnPaint(gfx::Canvas* canvas) { 60 void AvatarMenuButton::OnPaint(gfx::Canvas* canvas) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 #endif 139 #endif
138 } else { 140 } else {
139 AvatarMenu::GetImageForMenuButton(profile->GetPath(), 141 AvatarMenu::GetImageForMenuButton(profile->GetPath(),
140 avatar, 142 avatar,
141 is_rectangle); 143 is_rectangle);
142 } 144 }
143 } 145 }
144 return true; 146 return true;
145 } 147 }
146 148
149 void AvatarMenuButton::Update() {
150 // The browser can be null in tests.
151 if (!browser())
152 return;
153
154 const bool should_show_avatar_menu = AvatarMenu::ShouldShowAvatarMenu();
155 SetEnabled(should_show_avatar_menu);
156
157 gfx::Image avatar;
158 gfx::Image taskbar_badge_avatar;
159 bool is_rectangle = false;
160 if (AvatarMenuButton::GetAvatarImages(
161 browser()->profile(), should_show_avatar_menu, &avatar,
162 &taskbar_badge_avatar, &is_rectangle)) {
163 SetAvatarIcon(avatar, is_rectangle);
164 }
165 }
166
147 // views::ViewTargeterDelegate: 167 // views::ViewTargeterDelegate:
148 bool AvatarMenuButton::DoesIntersectRect(const views::View* target, 168 bool AvatarMenuButton::DoesIntersectRect(const views::View* target,
149 const gfx::Rect& rect) const { 169 const gfx::Rect& rect) const {
150 CHECK_EQ(target, this); 170 CHECK_EQ(target, this);
151 return !disabled_ && 171 return !disabled_ &&
152 views::ViewTargeterDelegate::DoesIntersectRect(target, rect); 172 views::ViewTargeterDelegate::DoesIntersectRect(target, rect);
153 } 173 }
154 174
155 // views::MenuButtonListener implementation 175 // views::MenuButtonListener implementation
156 void AvatarMenuButton::OnMenuButtonClicked(views::View* source, 176 void AvatarMenuButton::OnMenuButtonClicked(views::View* source,
157 const gfx::Point& point) { 177 const gfx::Point& point) {
158 if (!disabled_) 178 if (!disabled_)
159 chrome::ShowAvatarMenu(browser_); 179 chrome::ShowAvatarMenu(browser());
160 } 180 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/profiles/avatar_menu_button.h ('k') | chrome/browser/ui/views/profiles/new_avatar_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698