OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/extensions/browser_action_overflow_menu_controlle
r.h" | 5 #include "chrome/browser/views/extensions/browser_action_overflow_menu_controlle
r.h" |
6 | 6 |
7 #include "app/gfx/canvas.h" | 7 #include "app/gfx/canvas.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/browser_list.h" | 9 #include "chrome/browser/browser_list.h" |
| 10 #include "chrome/browser/extensions/extension_context_menu_model.h" |
10 #include "chrome/browser/profile.h" | 11 #include "chrome/browser/profile.h" |
11 #include "chrome/browser/tab_contents/tab_contents.h" | 12 #include "chrome/browser/tab_contents/tab_contents.h" |
12 #include "chrome/browser/views/browser_actions_container.h" | 13 #include "chrome/browser/views/browser_actions_container.h" |
13 #include "chrome/browser/views/extensions/browser_action_drag_data.h" | 14 #include "chrome/browser/views/extensions/browser_action_drag_data.h" |
14 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
15 #include "views/controls/menu/menu_item_view.h" | 16 #include "views/controls/menu/menu_item_view.h" |
| 17 #include "views/controls/menu/menu_2.h" |
16 | 18 |
17 BrowserActionOverflowMenuController::BrowserActionOverflowMenuController( | 19 BrowserActionOverflowMenuController::BrowserActionOverflowMenuController( |
18 BrowserActionsContainer* owner, | 20 BrowserActionsContainer* owner, |
19 views::MenuButton* menu_button, | 21 views::MenuButton* menu_button, |
20 const std::vector<BrowserActionView*>& views, | 22 const std::vector<BrowserActionView*>& views, |
21 int start_index) | 23 int start_index) |
22 : owner_(owner), | 24 : owner_(owner), |
23 observer_(NULL), | 25 observer_(NULL), |
24 menu_button_(menu_button), | 26 menu_button_(menu_button), |
25 views_(&views), | 27 views_(&views), |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 bounds.set_x(screen_loc.x()); | 65 bounds.set_x(screen_loc.x()); |
64 bounds.set_y(screen_loc.y()); | 66 bounds.set_y(screen_loc.y()); |
65 | 67 |
66 views::MenuItemView::AnchorPosition anchor = | 68 views::MenuItemView::AnchorPosition anchor = |
67 menu_button_->UILayoutIsRightToLeft() ? views::MenuItemView::TOPLEFT : | 69 menu_button_->UILayoutIsRightToLeft() ? views::MenuItemView::TOPLEFT : |
68 views::MenuItemView::TOPRIGHT; | 70 views::MenuItemView::TOPRIGHT; |
69 if (for_drop) { | 71 if (for_drop) { |
70 menu_->RunMenuForDropAt(window, bounds, anchor); | 72 menu_->RunMenuForDropAt(window, bounds, anchor); |
71 } else { | 73 } else { |
72 menu_->RunMenuAt(window, menu_button_, bounds, anchor, false); | 74 menu_->RunMenuAt(window, menu_button_, bounds, anchor, false); |
73 delete this; | 75 // Give the context menu (if any) a chance to execute the user-selected |
| 76 // command. |
| 77 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
74 } | 78 } |
75 return true; | 79 return true; |
76 } | 80 } |
77 | 81 |
78 void BrowserActionOverflowMenuController::CancelMenu() { | 82 void BrowserActionOverflowMenuController::CancelMenu() { |
79 menu_->Cancel(); | 83 menu_->Cancel(); |
80 } | 84 } |
81 | 85 |
82 void BrowserActionOverflowMenuController::ExecuteCommand(int id) { | 86 void BrowserActionOverflowMenuController::ExecuteCommand(int id) { |
83 BrowserActionView* view = (*views_)[start_index_ + id - 1]; | 87 BrowserActionView* view = (*views_)[start_index_ + id - 1]; |
84 owner_->OnBrowserActionExecuted(view->button(), | 88 owner_->OnBrowserActionExecuted(view->button(), |
85 false); // inspect_with_devtools | 89 false); // inspect_with_devtools |
86 } | 90 } |
87 | 91 |
88 bool BrowserActionOverflowMenuController::ShowContextMenu( | 92 bool BrowserActionOverflowMenuController::ShowContextMenu( |
89 views::MenuItemView* source, | 93 views::MenuItemView* source, |
90 int id, | 94 int id, |
91 const gfx::Point& p, | 95 const gfx::Point& p, |
92 bool is_mouse_gesture) { | 96 bool is_mouse_gesture) { |
| 97 context_menu_contents_.reset(new ExtensionContextMenuModel( |
| 98 (*views_)[start_index_ + id - 1]->button()->extension(), |
| 99 owner_->browser(), |
| 100 owner_)); |
| 101 context_menu_menu_.reset(new views::Menu2(context_menu_contents_.get())); |
93 // This blocks until the user choses something or dismisses the menu. | 102 // This blocks until the user choses something or dismisses the menu. |
94 owner_->GetContextMenu()->Run( | 103 context_menu_menu_->RunContextMenuAt(p); |
95 (*views_)[start_index_ + id - 1]->button()->extension(), | |
96 (*views_)[start_index_ + id - 1]->button()->extension()->browser_action(), | |
97 owner_, | |
98 owner_->profile()->GetPrefs(), | |
99 p); | |
100 | 104 |
101 // The user is done with the context menu, so we can close the underlying | 105 // The user is done with the context menu, so we can close the underlying |
102 // menu. | 106 // menu. |
103 menu_->Cancel(); | 107 menu_->Cancel(); |
104 | 108 |
105 return true; | 109 return true; |
106 } | 110 } |
107 | 111 |
108 void BrowserActionOverflowMenuController::DropMenuClosed( | 112 void BrowserActionOverflowMenuController::DropMenuClosed( |
109 views::MenuItemView* menu) { | 113 views::MenuItemView* menu) { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 | 200 |
197 BrowserActionView* BrowserActionOverflowMenuController::ViewForId( | 201 BrowserActionView* BrowserActionOverflowMenuController::ViewForId( |
198 int id, size_t* index) { | 202 int id, size_t* index) { |
199 // The index of the view being dragged (GetCommand gives a 1-based index into | 203 // The index of the view being dragged (GetCommand gives a 1-based index into |
200 // the overflow menu). | 204 // the overflow menu). |
201 size_t view_index = owner_->VisibleBrowserActions() + id - 1; | 205 size_t view_index = owner_->VisibleBrowserActions() + id - 1; |
202 if (index) | 206 if (index) |
203 *index = view_index; | 207 *index = view_index; |
204 return owner_->GetBrowserActionViewAt(view_index); | 208 return owner_->GetBrowserActionViewAt(view_index); |
205 } | 209 } |
OLD | NEW |