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/profile_menu_model.h" | 8 #include "chrome/browser/ui/profile_menu_model.h" |
9 #include "chrome/browser/ui/views/avatar_menu.h" | 9 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h" |
| 10 #include "chrome/browser/ui/views/frame/browser_view.h" |
10 #include "ui/gfx/canvas_skia.h" | 11 #include "ui/gfx/canvas_skia.h" |
11 #include "views/widget/widget.h" | 12 #include "views/widget/widget.h" |
12 | 13 |
13 static inline int Round(double x) { | 14 static inline int Round(double x) { |
14 return static_cast<int>(x + 0.5); | 15 return static_cast<int>(x + 0.5); |
15 } | 16 } |
16 | 17 |
17 AvatarMenuButton::AvatarMenuButton(Browser* browser, bool has_menu) | 18 AvatarMenuButton::AvatarMenuButton(Browser* browser, bool has_menu) |
18 : MenuButton(NULL, std::wstring(), this, false), | 19 : MenuButton(NULL, std::wstring(), this, false), |
19 browser_(browser), | 20 browser_(browser), |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 if (!has_menu_) | 56 if (!has_menu_) |
56 return false; | 57 return false; |
57 return views::MenuButton::HitTest(point); | 58 return views::MenuButton::HitTest(point); |
58 } | 59 } |
59 | 60 |
60 // views::ViewMenuDelegate implementation | 61 // views::ViewMenuDelegate implementation |
61 void AvatarMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { | 62 void AvatarMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { |
62 if (!has_menu_) | 63 if (!has_menu_) |
63 return; | 64 return; |
64 | 65 |
65 menu_model_.reset(new ProfileMenuModel(browser_)); | 66 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow( |
66 // The avatar menu will automatically delete itself when done. | 67 browser_->window()->GetNativeHandle()); |
67 AvatarMenu* avatar_menu = | 68 |
68 new AvatarMenu(menu_model_.get(), browser_->profile()); | 69 gfx::Point origin; |
69 avatar_menu->RunMenu(this); | 70 views::View::ConvertPointToScreen(this, &origin); |
| 71 gfx::Rect bounds(0, 0, width(), height()); |
| 72 bounds.set_origin(origin); |
| 73 |
| 74 AvatarMenuBubbleView* bubble_view = new AvatarMenuBubbleView(browser_); |
| 75 // Bubble::Show() takes ownership of the view. |
| 76 Bubble::Show(browser_view->GetWidget(), bounds, BubbleBorder::TOP_LEFT, |
| 77 bubble_view, bubble_view); |
70 } | 78 } |
OLD | NEW |