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

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

Issue 264303006: Support full-screen and single-profile avatar bubbles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Never enable the command on ChromeOS. Created 6 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 | Annotate | Revision Log
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"
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/views/frame/browser_view.h" 16 #include "chrome/browser/ui/views/frame/browser_view.h"
16 #include "chrome/browser/ui/views/profiles/avatar_menu_bubble_view.h" 17 #include "chrome/browser/ui/views/profiles/avatar_menu_bubble_view.h"
17 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" 18 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h"
18 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
19 #include "components/signin/core/common/profile_management_switches.h" 20 #include "components/signin/core/common/profile_management_switches.h"
20 #include "content/public/browser/notification_service.h" 21 #include "content/public/browser/notification_service.h"
21 #include "ui/gfx/canvas.h" 22 #include "ui/gfx/canvas.h"
22 #include "ui/views/widget/widget.h" 23 #include "ui/views/widget/widget.h"
23 24
24 static inline int Round(double x) { 25 static inline int Round(double x) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 // Round rather than truncating, so that for odd heights we select an extra 71 // Round rather than truncating, so that for odd heights we select an extra
71 // pixel below the image center rather than above. This is because the 72 // pixel below the image center rather than above. This is because the
72 // incognito image has shadows at the top that make the apparent center below 73 // incognito image has shadows at the top that make the apparent center below
73 // the real center. 74 // the real center.
74 int dst_y = Round((height() - dst_height) / 2.0); 75 int dst_y = Round((height() - dst_height) / 2.0);
75 canvas->DrawImageInt(button_icon_, 0, 0, button_icon_.width(), 76 canvas->DrawImageInt(button_icon_, 0, 0, button_icon_.width(),
76 button_icon_.height(), dst_x, dst_y, dst_width, dst_height, false); 77 button_icon_.height(), dst_x, dst_y, dst_width, dst_height, false);
77 } 78 }
78 79
79 bool AvatarMenuButton::HitTestRect(const gfx::Rect& rect) const { 80 bool AvatarMenuButton::HitTestRect(const gfx::Rect& rect) const {
80 if (disabled_) 81 return !disabled_ && views::MenuButton::HitTestRect(rect);
81 return false;
82 return views::MenuButton::HitTestRect(rect);
83 } 82 }
84 83
85 void AvatarMenuButton::SetAvatarIcon(const gfx::Image& icon, 84 void AvatarMenuButton::SetAvatarIcon(const gfx::Image& icon,
86 bool is_rectangle) { 85 bool is_rectangle) {
87 icon_.reset(new gfx::Image(icon)); 86 icon_.reset(new gfx::Image(icon));
88 button_icon_ = gfx::ImageSkia(); 87 button_icon_ = gfx::ImageSkia();
89 is_rectangle_ = is_rectangle; 88 is_rectangle_ = is_rectangle;
90 SchedulePaint(); 89 SchedulePaint();
91 } 90 }
92 91
93 // views::MenuButtonListener implementation 92 // views::MenuButtonListener implementation
94 void AvatarMenuButton::OnMenuButtonClicked(views::View* source, 93 void AvatarMenuButton::OnMenuButtonClicked(views::View* source,
95 const gfx::Point& point) { 94 const gfx::Point& point) {
96 if (disabled_) 95 if (!disabled_)
97 return; 96 chrome::ShowAvatarMenu(browser_);
98
99 ShowAvatarBubble();
100 } 97 }
101
102 void AvatarMenuButton::ShowAvatarBubble() {
103 gfx::Point origin;
104 views::View::ConvertPointToScreen(this, &origin);
105 gfx::Rect bounds(origin, size());
106 views::BubbleBorder::Arrow arrow = button_on_right_ ?
107 views::BubbleBorder::TOP_RIGHT : views::BubbleBorder::TOP_LEFT;
108 if (switches::IsNewAvatarMenu()) {
109 ProfileChooserView::ShowBubble(
110 ProfileChooserView::BUBBLE_VIEW_MODE_PROFILE_CHOOSER,
111 this, arrow, views::BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR, bounds,
112 browser_);
113 } else {
114 AvatarMenuBubbleView::ShowBubble(
115 this, arrow, views::BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR, bounds,
116 browser_);
117 }
118
119 ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::ICON_AVATAR_BUBBLE);
120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698