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" |
11 #include "chrome/browser/profiles/avatar_menu.h" | 11 #include "chrome/browser/profiles/avatar_menu.h" |
12 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 12 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
13 #include "chrome/browser/profiles/profile_metrics.h" | 13 #include "chrome/browser/profiles/profile_metrics.h" |
14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/browser_commands.h" | 15 #include "chrome/browser/ui/browser_commands.h" |
16 #include "chrome/browser/ui/views/frame/browser_view.h" | 16 #include "chrome/browser/ui/views/frame/browser_view.h" |
17 #include "chrome/browser/ui/views/profiles/avatar_menu_bubble_view.h" | 17 #include "chrome/browser/ui/views/profiles/avatar_menu_bubble_view.h" |
18 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" | 18 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" |
19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
20 #include "components/signin/core/common/profile_management_switches.h" | 20 #include "components/signin/core/common/profile_management_switches.h" |
21 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
22 #include "ui/gfx/canvas.h" | 22 #include "ui/gfx/canvas.h" |
| 23 #include "ui/views/view_targeter.h" |
23 #include "ui/views/widget/widget.h" | 24 #include "ui/views/widget/widget.h" |
24 | 25 |
25 static inline int Round(double x) { | 26 static inline int Round(double x) { |
26 return static_cast<int>(x + 0.5); | 27 return static_cast<int>(x + 0.5); |
27 } | 28 } |
28 | 29 |
29 // static | 30 // static |
30 const char AvatarMenuButton::kViewClassName[] = "AvatarMenuButton"; | 31 const char AvatarMenuButton::kViewClassName[] = "AvatarMenuButton"; |
31 | 32 |
32 AvatarMenuButton::AvatarMenuButton(Browser* browser, bool disabled) | 33 AvatarMenuButton::AvatarMenuButton(Browser* browser, bool disabled) |
33 : MenuButton(NULL, base::string16(), this, false), | 34 : MenuButton(NULL, base::string16(), this, false), |
34 browser_(browser), | 35 browser_(browser), |
35 disabled_(disabled), | 36 disabled_(disabled), |
36 is_rectangle_(false), | 37 is_rectangle_(false), |
37 old_height_(0), | 38 old_height_(0), |
38 button_on_right_(false) { | 39 button_on_right_(false) { |
39 // In RTL mode, the avatar icon should be looking the opposite direction. | 40 // In RTL mode, the avatar icon should be looking the opposite direction. |
40 EnableCanvasFlippingForRTLUI(true); | 41 EnableCanvasFlippingForRTLUI(true); |
| 42 |
| 43 SetEventTargeter( |
| 44 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); |
41 } | 45 } |
42 | 46 |
43 AvatarMenuButton::~AvatarMenuButton() { | 47 AvatarMenuButton::~AvatarMenuButton() { |
44 } | 48 } |
45 | 49 |
46 const char* AvatarMenuButton::GetClassName() const { | 50 const char* AvatarMenuButton::GetClassName() const { |
47 return kViewClassName; | 51 return kViewClassName; |
48 } | 52 } |
49 | 53 |
50 void AvatarMenuButton::OnPaint(gfx::Canvas* canvas) { | 54 void AvatarMenuButton::OnPaint(gfx::Canvas* canvas) { |
(...skipping 20 matching lines...) Expand all Loading... |
71 int dst_height = Round(button_icon_.height() * scale); | 75 int dst_height = Round(button_icon_.height() * scale); |
72 // Round rather than truncating, so that for odd heights we select an extra | 76 // Round rather than truncating, so that for odd heights we select an extra |
73 // pixel below the image center rather than above. This is because the | 77 // pixel below the image center rather than above. This is because the |
74 // incognito image has shadows at the top that make the apparent center below | 78 // incognito image has shadows at the top that make the apparent center below |
75 // the real center. | 79 // the real center. |
76 int dst_y = Round((height() - dst_height) / 2.0); | 80 int dst_y = Round((height() - dst_height) / 2.0); |
77 canvas->DrawImageInt(button_icon_, 0, 0, button_icon_.width(), | 81 canvas->DrawImageInt(button_icon_, 0, 0, button_icon_.width(), |
78 button_icon_.height(), dst_x, dst_y, dst_width, dst_height, false); | 82 button_icon_.height(), dst_x, dst_y, dst_width, dst_height, false); |
79 } | 83 } |
80 | 84 |
81 bool AvatarMenuButton::HitTestRect(const gfx::Rect& rect) const { | |
82 return !disabled_ && views::MenuButton::HitTestRect(rect); | |
83 } | |
84 | |
85 void AvatarMenuButton::SetAvatarIcon(const gfx::Image& icon, | 85 void AvatarMenuButton::SetAvatarIcon(const gfx::Image& icon, |
86 bool is_rectangle) { | 86 bool is_rectangle) { |
87 icon_.reset(new gfx::Image(icon)); | 87 icon_.reset(new gfx::Image(icon)); |
88 button_icon_ = gfx::ImageSkia(); | 88 button_icon_ = gfx::ImageSkia(); |
89 is_rectangle_ = is_rectangle; | 89 is_rectangle_ = is_rectangle; |
90 SchedulePaint(); | 90 SchedulePaint(); |
91 } | 91 } |
92 | 92 |
| 93 // views::ViewTargeterDelegate: |
| 94 bool AvatarMenuButton::DoesIntersectRect(const views::View* target, |
| 95 const gfx::Rect& rect) const { |
| 96 CHECK_EQ(target, this); |
| 97 return !disabled_ && |
| 98 views::ViewTargeterDelegate::DoesIntersectRect(target, rect); |
| 99 } |
| 100 |
93 // views::MenuButtonListener implementation | 101 // views::MenuButtonListener implementation |
94 void AvatarMenuButton::OnMenuButtonClicked(views::View* source, | 102 void AvatarMenuButton::OnMenuButtonClicked(views::View* source, |
95 const gfx::Point& point) { | 103 const gfx::Point& point) { |
96 if (!disabled_) | 104 if (!disabled_) |
97 chrome::ShowAvatarMenu(browser_); | 105 chrome::ShowAvatarMenu(browser_); |
98 } | 106 } |
OLD | NEW |