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

Unified 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: Address comments. Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/profiles/avatar_menu_button.cc
diff --git a/chrome/browser/ui/views/profiles/avatar_menu_button.cc b/chrome/browser/ui/views/profiles/avatar_menu_button.cc
index 3100a621347f5472fc4cd93069aa26796d068af4..9d26f7076e7fafce1b5ce9330f78af96d7481208 100644
--- a/chrome/browser/ui/views/profiles/avatar_menu_button.cc
+++ b/chrome/browser/ui/views/profiles/avatar_menu_button.cc
@@ -35,8 +35,8 @@ static inline int Round(double x) {
const char AvatarMenuButton::kViewClassName[] = "AvatarMenuButton";
AvatarMenuButton::AvatarMenuButton(Browser* browser, bool disabled)
- : MenuButton(NULL, base::string16(), this, false),
- browser_(browser),
+ : AvatarBaseButton(browser),
+ MenuButton(NULL, base::string16(), this, false),
disabled_(disabled),
is_rectangle_(false),
old_height_(0),
@@ -46,6 +46,8 @@ AvatarMenuButton::AvatarMenuButton(Browser* browser, bool disabled)
SetEventTargeter(
scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this)));
+
+ Update();
}
AvatarMenuButton::~AvatarMenuButton() {
@@ -144,6 +146,24 @@ bool AvatarMenuButton::GetAvatarImages(Profile* profile,
return true;
}
+void AvatarMenuButton::Update() {
+ // The browser can be null in tests.
+ if (!browser())
+ return;
+
+ const bool should_show_avatar_menu = AvatarMenu::ShouldShowAvatarMenu();
msw 2015/05/05 17:36:39 nit: inline this in the SetEnabled call below.
yao 2015/05/05 17:45:00 You mean like: SetEnabled(AvatarMenu::ShouldShowAv
msw 2015/05/05 17:56:09 Ah, ok. Ignore that comment.
+ SetEnabled(should_show_avatar_menu);
+
+ gfx::Image avatar;
+ gfx::Image taskbar_badge_avatar;
+ bool is_rectangle = false;
+ if (AvatarMenuButton::GetAvatarImages(
+ browser()->profile(), should_show_avatar_menu, &avatar,
+ &taskbar_badge_avatar, &is_rectangle)) {
+ SetAvatarIcon(avatar, is_rectangle);
+ }
+}
+
// views::ViewTargeterDelegate:
bool AvatarMenuButton::DoesIntersectRect(const views::View* target,
const gfx::Rect& rect) const {
@@ -156,5 +176,5 @@ bool AvatarMenuButton::DoesIntersectRect(const views::View* target,
void AvatarMenuButton::OnMenuButtonClicked(views::View* source,
const gfx::Point& point) {
if (!disabled_)
- chrome::ShowAvatarMenu(browser_);
+ chrome::ShowAvatarMenu(browser());
}

Powered by Google App Engine
This is Rietveld 408576698