OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/avatar_menu_button.h" | 5 #include "chrome/browser/ui/views/avatar_menu_button.h" |
6 | 6 |
7 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
8 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h" | 8 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h" |
9 #include "chrome/browser/ui/views/frame/browser_view.h" | 9 #include "chrome/browser/ui/views/frame/browser_view.h" |
10 #include "ui/gfx/canvas_skia.h" | 10 #include "ui/gfx/canvas_skia.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 } | 58 } |
59 taskbar->SetOverlayIcon(window, icon, L""); | 59 taskbar->SetOverlayIcon(window, icon, L""); |
60 if (icon) | 60 if (icon) |
61 DestroyIcon(icon); | 61 DestroyIcon(icon); |
62 #endif | 62 #endif |
63 } | 63 } |
64 | 64 |
65 AvatarMenuButton::AvatarMenuButton(Browser* browser, bool has_menu) | 65 AvatarMenuButton::AvatarMenuButton(Browser* browser, bool has_menu) |
66 : MenuButton(NULL, std::wstring(), this, false), | 66 : MenuButton(NULL, std::wstring(), this, false), |
67 browser_(browser), | 67 browser_(browser), |
68 bubble_(NULL), | |
68 has_menu_(has_menu), | 69 has_menu_(has_menu), |
69 set_taskbar_decoration_(false) { | 70 set_taskbar_decoration_(false) { |
70 // In RTL mode, the avatar icon should be looking the opposite direction. | 71 // In RTL mode, the avatar icon should be looking the opposite direction. |
71 EnableCanvasFlippingForRTLUI(true); | 72 EnableCanvasFlippingForRTLUI(true); |
72 } | 73 } |
73 | 74 |
74 AvatarMenuButton::~AvatarMenuButton() { | 75 AvatarMenuButton::~AvatarMenuButton() { |
76 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.
| |
77 bubble_->RemoveObserver(this); | |
75 // During destruction of the browser frame, we might not have a window | 78 // During destruction of the browser frame, we might not have a window |
76 // so the taskbar button will be removed by windows anyway. | 79 // so the taskbar button will be removed by windows anyway. |
77 if (browser_->IsAttemptingToCloseBrowser()) | 80 if (browser_->IsAttemptingToCloseBrowser()) |
78 return; | 81 return; |
79 DrawTaskBarDecoration(browser_, NULL); | 82 DrawTaskBarDecoration(browser_, NULL); |
80 } | 83 } |
81 | 84 |
82 void AvatarMenuButton::OnPaint(gfx::Canvas* canvas) { | 85 void AvatarMenuButton::OnPaint(gfx::Canvas* canvas) { |
83 const SkBitmap& icon = GetImageToPaint(); | 86 const SkBitmap& icon = GetImageToPaint(); |
84 if (icon.isNull()) | 87 if (icon.isNull()) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 } | 123 } |
121 | 124 |
122 // If the icon changes, we need to set the taskbar decoration again. | 125 // If the icon changes, we need to set the taskbar decoration again. |
123 void AvatarMenuButton::SetIcon(const SkBitmap& icon) { | 126 void AvatarMenuButton::SetIcon(const SkBitmap& icon) { |
124 views::MenuButton::SetIcon(icon); | 127 views::MenuButton::SetIcon(icon); |
125 set_taskbar_decoration_ = true; | 128 set_taskbar_decoration_ = true; |
126 } | 129 } |
127 | 130 |
128 // views::ViewMenuDelegate implementation | 131 // views::ViewMenuDelegate implementation |
129 void AvatarMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { | 132 void AvatarMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { |
130 if (!has_menu_) | 133 if (!has_menu_ || bubble_) |
131 return; | 134 return; |
132 | 135 |
133 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); | 136 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); |
134 gfx::Point origin; | 137 gfx::Point origin; |
135 views::View::ConvertPointToScreen(this, &origin); | 138 views::View::ConvertPointToScreen(this, &origin); |
136 gfx::Rect bounds(0, 0, width(), height()); | 139 gfx::Rect bounds(0, 0, width(), height()); |
137 bounds.set_origin(origin); | 140 bounds.set_origin(origin); |
138 | 141 |
139 AvatarMenuBubbleView* bubble_view = new AvatarMenuBubbleView(browser_); | 142 AvatarMenuBubbleView* bubble_view = new AvatarMenuBubbleView(browser_); |
140 // Bubble::Show() takes ownership of the view. | 143 // Bubble::Show() takes ownership of the view. |
141 Bubble::Show(browser_view->GetWidget(), bounds, | 144 bubble_ = Bubble::Show(browser_view->GetWidget(), bounds, |
142 views::BubbleBorder::TOP_LEFT, | 145 views::BubbleBorder::TOP_LEFT, bubble_view, bubble_view); |
143 bubble_view, bubble_view); | 146 bubble_->AddObserver(this); |
144 } | 147 } |
148 | |
149 void AvatarMenuButton::OnBubbleClosing(Bubble* bubble, bool closed_by_escape) { | |
150 bubble_->RemoveObserver(this); | |
151 bubble_ = NULL; | |
152 } | |
OLD | NEW |