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

Unified Diff: chrome/browser/ui/views/avatar_menu_button.cc

Issue 11646008: Close avatar bubble when avatar button is clicked a second time (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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/avatar_menu_button.cc
diff --git a/chrome/browser/ui/views/avatar_menu_button.cc b/chrome/browser/ui/views/avatar_menu_button.cc
index f1385b046762477962113c6c39e8739f4382c76f..20fa0ac5e69a1e66fd575afac864cf2918831373 100644
--- a/chrome/browser/ui/views/avatar_menu_button.cc
+++ b/chrome/browser/ui/views/avatar_menu_button.cc
@@ -100,6 +100,8 @@ AvatarMenuButton::AvatarMenuButton(Browser* browser, bool incognito)
}
AvatarMenuButton::~AvatarMenuButton() {
+ if (bubble_widget_)
+ OnWidgetClosing(bubble_widget_);
}
void AvatarMenuButton::OnPaint(gfx::Canvas* canvas) {
@@ -159,7 +161,27 @@ void AvatarMenuButton::OnMenuButtonClicked(views::View* source,
ShowAvatarBubble();
}
+void AvatarMenuButton::OnWidgetClosing(views::Widget* widget) {
+ bubble_widget_->RemoveObserver(this);
+ bubble_widget_ = NULL;
+ // If the avatar bubble is about to be shown the cancel the operation. This
+ // prevents the bubble from closing and immediately reopening when the user
+ // clicks the avatar button a second time.
+ show_avatar_bubble_closure_.Cancel();
+}
+
void AvatarMenuButton::ShowAvatarBubble() {
+ show_avatar_bubble_closure_.Reset(
+ base::Bind(&AvatarMenuButton::ShowAvatarBubbleImpl,
+ base::Unretained(this)));
+ MessageLoop::current()->PostTask(FROM_HERE,
+ show_avatar_bubble_closure_.callback());
Peter Kasting 2012/12/28 18:55:55 This has three problems: (1) It makes the menu op
sail 2013/01/02 21:06:01 Done. I changed this to match the bookmark code by
+}
+
+void AvatarMenuButton::ShowAvatarBubbleImpl() {
Peter Kasting 2012/12/28 18:55:55 There's nearly identical code to this in browser_v
sail 2013/01/02 21:06:01 Done.
+ if (bubble_widget_)
+ return;
+
DCHECK(chrome::IsCommandEnabled(browser_, IDC_SHOW_AVATAR_MENU));
gfx::Point origin;
@@ -168,7 +190,8 @@ void AvatarMenuButton::ShowAvatarBubble() {
AvatarMenuBubbleView* bubble = new AvatarMenuBubbleView(this,
views::BubbleBorder::TOP_LEFT, bounds, browser_);
- views::BubbleDelegateView::CreateBubble(bubble);
+ bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble);
+ bubble_widget_->AddObserver(this);
bubble->Show();
ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::ICON_AVATAR_BUBBLE);
« no previous file with comments | « chrome/browser/ui/views/avatar_menu_button.h ('k') | chrome/browser/ui/views/avatar_menu_button_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698