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 : AvatarBaseButton(browser), | 38 : MenuButton(NULL, base::string16(), this, false), |
39 MenuButton(NULL, base::string16(), this, false), | 39 browser_(browser), |
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(); | |
51 } | 49 } |
52 | 50 |
53 AvatarMenuButton::~AvatarMenuButton() { | 51 AvatarMenuButton::~AvatarMenuButton() { |
54 } | 52 } |
55 | 53 |
56 const char* AvatarMenuButton::GetClassName() const { | 54 const char* AvatarMenuButton::GetClassName() const { |
57 return kViewClassName; | 55 return kViewClassName; |
58 } | 56 } |
59 | 57 |
60 void AvatarMenuButton::OnPaint(gfx::Canvas* canvas) { | 58 void AvatarMenuButton::OnPaint(gfx::Canvas* canvas) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 #endif | 137 #endif |
140 } else { | 138 } else { |
141 AvatarMenu::GetImageForMenuButton(profile->GetPath(), | 139 AvatarMenu::GetImageForMenuButton(profile->GetPath(), |
142 avatar, | 140 avatar, |
143 is_rectangle); | 141 is_rectangle); |
144 } | 142 } |
145 } | 143 } |
146 return true; | 144 return true; |
147 } | 145 } |
148 | 146 |
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 | |
167 // views::ViewTargeterDelegate: | 147 // views::ViewTargeterDelegate: |
168 bool AvatarMenuButton::DoesIntersectRect(const views::View* target, | 148 bool AvatarMenuButton::DoesIntersectRect(const views::View* target, |
169 const gfx::Rect& rect) const { | 149 const gfx::Rect& rect) const { |
170 CHECK_EQ(target, this); | 150 CHECK_EQ(target, this); |
171 return !disabled_ && | 151 return !disabled_ && |
172 views::ViewTargeterDelegate::DoesIntersectRect(target, rect); | 152 views::ViewTargeterDelegate::DoesIntersectRect(target, rect); |
173 } | 153 } |
174 | 154 |
175 // views::MenuButtonListener implementation | 155 // views::MenuButtonListener implementation |
176 void AvatarMenuButton::OnMenuButtonClicked(views::View* source, | 156 void AvatarMenuButton::OnMenuButtonClicked(views::View* source, |
177 const gfx::Point& point) { | 157 const gfx::Point& point) { |
178 if (!disabled_) | 158 if (!disabled_) |
179 chrome::ShowAvatarMenu(browser()); | 159 chrome::ShowAvatarMenu(browser_); |
180 } | 160 } |
OLD | NEW |