Chromium Code Reviews| 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/profiles/profile_metrics.h" | 7 #include "chrome/browser/profiles/profile_metrics.h" |
| 8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h" | 9 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h" |
| 10 #include "chrome/browser/ui/views/frame/browser_view.h" | 10 #include "chrome/browser/ui/views/frame/browser_view.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 } | 71 } |
| 72 taskbar->SetOverlayIcon(window, icon, L""); | 72 taskbar->SetOverlayIcon(window, icon, L""); |
| 73 if (icon) | 73 if (icon) |
| 74 DestroyIcon(icon); | 74 DestroyIcon(icon); |
| 75 #endif | 75 #endif |
| 76 } | 76 } |
| 77 | 77 |
| 78 AvatarMenuButton::AvatarMenuButton(Browser* browser, bool has_menu) | 78 AvatarMenuButton::AvatarMenuButton(Browser* browser, bool has_menu) |
| 79 : MenuButton(NULL, string16(), this, false), | 79 : MenuButton(NULL, string16(), this, false), |
| 80 browser_(browser), | 80 browser_(browser), |
| 81 bubble_(NULL), | |
| 82 has_menu_(has_menu), | 81 has_menu_(has_menu), |
| 83 set_taskbar_decoration_(false) { | 82 set_taskbar_decoration_(false) { |
| 84 // In RTL mode, the avatar icon should be looking the opposite direction. | 83 // In RTL mode, the avatar icon should be looking the opposite direction. |
| 85 EnableCanvasFlippingForRTLUI(true); | 84 EnableCanvasFlippingForRTLUI(true); |
| 86 } | 85 } |
| 87 | 86 |
| 88 AvatarMenuButton::~AvatarMenuButton() { | 87 AvatarMenuButton::~AvatarMenuButton() { |
| 89 if (bubble_) | |
| 90 OnBubbleClosing(); | |
| 91 // During destruction of the browser frame, we might not have a window | 88 // During destruction of the browser frame, we might not have a window |
| 92 // so the taskbar button will be removed by windows anyway. | 89 // so the taskbar button will be removed by windows anyway. |
| 93 if (browser_->IsAttemptingToCloseBrowser()) | 90 if (browser_->IsAttemptingToCloseBrowser()) |
| 94 return; | 91 return; |
| 95 DrawTaskBarDecoration(browser_, NULL); | 92 DrawTaskBarDecoration(browser_, NULL); |
| 96 } | 93 } |
| 97 | 94 |
| 98 void AvatarMenuButton::OnPaint(gfx::Canvas* canvas) { | 95 void AvatarMenuButton::OnPaint(gfx::Canvas* canvas) { |
| 99 const SkBitmap& icon = GetImageToPaint(); | 96 const SkBitmap& icon = GetImageToPaint(); |
| 100 if (icon.isNull()) | 97 if (icon.isNull()) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 views::MenuButton::SetIcon(icon); | 137 views::MenuButton::SetIcon(icon); |
| 141 set_taskbar_decoration_ = true; | 138 set_taskbar_decoration_ = true; |
| 142 } | 139 } |
| 143 | 140 |
| 144 // views::ViewMenuDelegate implementation | 141 // views::ViewMenuDelegate implementation |
| 145 void AvatarMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { | 142 void AvatarMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { |
| 146 ShowAvatarBubble(); | 143 ShowAvatarBubble(); |
| 147 } | 144 } |
| 148 | 145 |
| 149 void AvatarMenuButton::ShowAvatarBubble() { | 146 void AvatarMenuButton::ShowAvatarBubble() { |
| 150 if (!has_menu_ || bubble_) | 147 if (!has_menu_) |
| 151 return; | 148 return; |
| 152 | 149 |
| 153 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); | 150 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); |
| 154 gfx::Point origin; | 151 gfx::Point origin; |
| 155 views::View::ConvertPointToScreen(this, &origin); | 152 views::View::ConvertPointToScreen(this, &origin); |
| 156 gfx::Rect bounds(0, 0, width(), height()); | 153 gfx::Rect bounds(origin, size()); |
| 157 bounds.set_origin(origin); | |
| 158 | 154 |
| 159 AvatarMenuBubbleView* bubble_view = new AvatarMenuBubbleView(browser_); | 155 AvatarMenuBubbleView* bubble = new AvatarMenuBubbleView(this, |
| 160 // Bubble::Show() takes ownership of the view. | 156 views::BubbleBorder::TOP_LEFT, bounds, browser_); |
|
Ben Goodger (Google)
2011/11/21 20:23:22
4-space indent
msw
2011/11/21 20:39:01
Done.
| |
| 161 bubble_ = Bubble::Show(browser_view->GetWidget(), bounds, | 157 views::BubbleDelegateView::CreateBubble(bubble); |
| 162 views::BubbleBorder::TOP_LEFT, | 158 bubble->Show(); |
| 163 views::BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR, bubble_view, bubble_view); | |
| 164 bubble_->AddObserver(this); | |
| 165 | 159 |
| 166 ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::ICON_AVATAR_BUBBLE); | 160 ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::ICON_AVATAR_BUBBLE); |
| 167 } | 161 } |
| 168 | |
| 169 void AvatarMenuButton::OnBubbleClosing() { | |
| 170 bubble_->RemoveObserver(this); | |
| 171 bubble_ = NULL; | |
| 172 } | |
| OLD | NEW |