OLD | NEW |
---|---|
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 Loading... | |
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 : AvatarBaseController(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 Loading... | |
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 // Check the validity of browser() so that this function can be bypassed in | |
noms (inactive)
2015/03/26 15:26:56
nit: maybe just "The browser can be null in tests"
yao
2015/03/26 18:45:01
Yes, because nullptr is passsed when the button is
| |
151 // unit tests. | |
152 if (!browser()) | |
153 return; | |
154 | |
155 gfx::Image avatar; | |
156 gfx::Image taskbar_badge_avatar; | |
157 bool is_rectangle = false; | |
158 | |
159 // Update the avatar button in the window frame and the taskbar overlay. | |
160 bool should_show_avatar_menu = AvatarMenu::ShouldShowAvatarMenu(); | |
161 | |
162 if (!AvatarMenuButton::GetAvatarImages( | |
163 browser()->profile(), should_show_avatar_menu, &avatar, | |
164 &taskbar_badge_avatar, &is_rectangle)) { | |
165 return; | |
166 } | |
167 | |
168 // Disable the menu when we should not show the menu. | |
169 if (!AvatarMenu::ShouldShowAvatarMenu()) | |
170 this->SetEnabled(false); | |
171 this->SetAvatarIcon(avatar, is_rectangle); | |
172 } | |
173 | |
147 // views::ViewTargeterDelegate: | 174 // views::ViewTargeterDelegate: |
148 bool AvatarMenuButton::DoesIntersectRect(const views::View* target, | 175 bool AvatarMenuButton::DoesIntersectRect(const views::View* target, |
149 const gfx::Rect& rect) const { | 176 const gfx::Rect& rect) const { |
150 CHECK_EQ(target, this); | 177 CHECK_EQ(target, this); |
151 return !disabled_ && | 178 return !disabled_ && |
152 views::ViewTargeterDelegate::DoesIntersectRect(target, rect); | 179 views::ViewTargeterDelegate::DoesIntersectRect(target, rect); |
153 } | 180 } |
154 | 181 |
155 // views::MenuButtonListener implementation | 182 // views::MenuButtonListener implementation |
156 void AvatarMenuButton::OnMenuButtonClicked(views::View* source, | 183 void AvatarMenuButton::OnMenuButtonClicked(views::View* source, |
157 const gfx::Point& point) { | 184 const gfx::Point& point) { |
158 if (!disabled_) | 185 if (!disabled_) |
159 chrome::ShowAvatarMenu(browser_); | 186 chrome::ShowAvatarMenu(browser()); |
160 } | 187 } |
OLD | NEW |