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