Chromium Code Reviews| 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 d389f7cb722865eee782da4ee1da94c4c6148b9f..3420f2c8b109353d8d4bc76673de86c754e4075b 100644 |
| --- a/chrome/browser/ui/views/avatar_menu_button.cc |
| +++ b/chrome/browser/ui/views/avatar_menu_button.cc |
| @@ -65,6 +65,7 @@ void DrawTaskBarDecoration(const Browser* browser, const SkBitmap* bitmap) { |
| AvatarMenuButton::AvatarMenuButton(Browser* browser, bool has_menu) |
| : MenuButton(NULL, std::wstring(), this, false), |
| browser_(browser), |
| + bubble_(NULL), |
| has_menu_(has_menu), |
| set_taskbar_decoration_(false) { |
| // In RTL mode, the avatar icon should be looking the opposite direction. |
| @@ -72,6 +73,8 @@ AvatarMenuButton::AvatarMenuButton(Browser* browser, bool has_menu) |
| } |
| AvatarMenuButton::~AvatarMenuButton() { |
| + if (bubble_) |
|
Peter Kasting
2011/10/05 01:22:51
Nit: Maybe this should just call OnBubbleClosing()
sail
2011/10/05 01:32:10
Done.
|
| + bubble_->RemoveObserver(this); |
| // During destruction of the browser frame, we might not have a window |
| // so the taskbar button will be removed by windows anyway. |
| if (browser_->IsAttemptingToCloseBrowser()) |
| @@ -127,7 +130,7 @@ void AvatarMenuButton::SetIcon(const SkBitmap& icon) { |
| // views::ViewMenuDelegate implementation |
| void AvatarMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { |
| - if (!has_menu_) |
| + if (!has_menu_ || bubble_) |
| return; |
| BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); |
| @@ -138,7 +141,12 @@ void AvatarMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { |
| AvatarMenuBubbleView* bubble_view = new AvatarMenuBubbleView(browser_); |
| // Bubble::Show() takes ownership of the view. |
| - Bubble::Show(browser_view->GetWidget(), bounds, |
| - views::BubbleBorder::TOP_LEFT, |
| - bubble_view, bubble_view); |
| + bubble_ = Bubble::Show(browser_view->GetWidget(), bounds, |
| + views::BubbleBorder::TOP_LEFT, bubble_view, bubble_view); |
| + bubble_->AddObserver(this); |
| +} |
| + |
| +void AvatarMenuButton::OnBubbleClosing(Bubble* bubble, bool closed_by_escape) { |
| + bubble_->RemoveObserver(this); |
| + bubble_ = NULL; |
| } |