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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 } | 135 } |
136 | 136 |
137 // If the icon changes, we need to set the taskbar decoration again. | 137 // If the icon changes, we need to set the taskbar decoration again. |
138 void AvatarMenuButton::SetIcon(const SkBitmap& icon) { | 138 void AvatarMenuButton::SetIcon(const SkBitmap& icon) { |
139 views::MenuButton::SetIcon(icon); | 139 views::MenuButton::SetIcon(icon); |
140 set_taskbar_decoration_ = true; | 140 set_taskbar_decoration_ = true; |
141 } | 141 } |
142 | 142 |
143 // views::ViewMenuDelegate implementation | 143 // views::ViewMenuDelegate implementation |
144 void AvatarMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { | 144 void AvatarMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { |
| 145 ShowAvatarBubble(); |
| 146 } |
| 147 |
| 148 void AvatarMenuButton::ShowAvatarBubble() { |
145 if (!has_menu_ || bubble_) | 149 if (!has_menu_ || bubble_) |
146 return; | 150 return; |
147 | 151 |
148 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); | 152 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); |
149 gfx::Point origin; | 153 gfx::Point origin; |
150 views::View::ConvertPointToScreen(this, &origin); | 154 views::View::ConvertPointToScreen(this, &origin); |
151 gfx::Rect bounds(0, 0, width(), height()); | 155 gfx::Rect bounds(0, 0, width(), height()); |
152 bounds.set_origin(origin); | 156 bounds.set_origin(origin); |
153 | 157 |
154 AvatarMenuBubbleView* bubble_view = new AvatarMenuBubbleView(browser_); | 158 AvatarMenuBubbleView* bubble_view = new AvatarMenuBubbleView(browser_); |
155 // Bubble::Show() takes ownership of the view. | 159 // Bubble::Show() takes ownership of the view. |
156 bubble_ = Bubble::Show(browser_view->GetWidget(), bounds, | 160 bubble_ = Bubble::Show(browser_view->GetWidget(), bounds, |
157 views::BubbleBorder::TOP_LEFT, bubble_view, bubble_view); | 161 views::BubbleBorder::TOP_LEFT, bubble_view, bubble_view); |
158 bubble_->AddObserver(this); | 162 bubble_->AddObserver(this); |
159 } | 163 } |
160 | 164 |
161 void AvatarMenuButton::OnBubbleClosing() { | 165 void AvatarMenuButton::OnBubbleClosing() { |
162 bubble_->RemoveObserver(this); | 166 bubble_->RemoveObserver(this); |
163 bubble_ = NULL; | 167 bubble_ = NULL; |
164 } | 168 } |
OLD | NEW |