| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extensions/browser_action_overflow_menu_contro
ller.h" | 5 #include "chrome/browser/ui/views/extensions/browser_action_overflow_menu_contro
ller.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/extensions/extension_action.h" | 9 #include "chrome/browser/extensions/extension_action.h" |
| 10 #include "chrome/browser/extensions/extension_action_manager.h" | 10 #include "chrome/browser/extensions/extension_action_manager.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 69 |
| 70 gfx::Rect bounds = menu_button_->bounds(); | 70 gfx::Rect bounds = menu_button_->bounds(); |
| 71 gfx::Point screen_loc; | 71 gfx::Point screen_loc; |
| 72 views::View::ConvertPointToScreen(menu_button_, &screen_loc); | 72 views::View::ConvertPointToScreen(menu_button_, &screen_loc); |
| 73 bounds.set_x(screen_loc.x()); | 73 bounds.set_x(screen_loc.x()); |
| 74 bounds.set_y(screen_loc.y()); | 74 bounds.set_y(screen_loc.y()); |
| 75 | 75 |
| 76 views::MenuItemView::AnchorPosition anchor = views::MenuItemView::TOPRIGHT; | 76 views::MenuItemView::AnchorPosition anchor = views::MenuItemView::TOPRIGHT; |
| 77 // As we maintain our own lifetime we can safely ignore the result. | 77 // As we maintain our own lifetime we can safely ignore the result. |
| 78 ignore_result(menu_runner_->RunMenuAt(window, menu_button_, bounds, anchor, | 78 ignore_result(menu_runner_->RunMenuAt(window, menu_button_, bounds, anchor, |
| 79 for_drop_ ? views::MenuRunner::FOR_DROP : 0)); | 79 ui::MENU_SOURCE_NONE, for_drop_ ? views::MenuRunner::FOR_DROP : 0)); |
| 80 if (!for_drop_) { | 80 if (!for_drop_) { |
| 81 // Give the context menu (if any) a chance to execute the user-selected | 81 // Give the context menu (if any) a chance to execute the user-selected |
| 82 // command. | 82 // command. |
| 83 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 83 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 84 } | 84 } |
| 85 return true; | 85 return true; |
| 86 } | 86 } |
| 87 | 87 |
| 88 void BrowserActionOverflowMenuController::CancelMenu() { | 88 void BrowserActionOverflowMenuController::CancelMenu() { |
| 89 menu_->Cancel(); | 89 menu_->Cancel(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 bool BrowserActionOverflowMenuController::IsCommandEnabled(int id) const { | 92 bool BrowserActionOverflowMenuController::IsCommandEnabled(int id) const { |
| 93 BrowserActionView* view = (*views_)[start_index_ + id - 1]; | 93 BrowserActionView* view = (*views_)[start_index_ + id - 1]; |
| 94 return view->button()->IsEnabled(owner_->GetCurrentTabId()); | 94 return view->button()->IsEnabled(owner_->GetCurrentTabId()); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void BrowserActionOverflowMenuController::ExecuteCommand(int id) { | 97 void BrowserActionOverflowMenuController::ExecuteCommand(int id) { |
| 98 BrowserActionView* view = (*views_)[start_index_ + id - 1]; | 98 BrowserActionView* view = (*views_)[start_index_ + id - 1]; |
| 99 owner_->OnBrowserActionExecuted(view->button()); | 99 owner_->OnBrowserActionExecuted(view->button()); |
| 100 } | 100 } |
| 101 | 101 |
| 102 bool BrowserActionOverflowMenuController::ShowContextMenu( | 102 bool BrowserActionOverflowMenuController::ShowContextMenu( |
| 103 views::MenuItemView* source, | 103 views::MenuItemView* source, |
| 104 int id, | 104 int id, |
| 105 const gfx::Point& p, | 105 const gfx::Point& p, |
| 106 bool is_mouse_gesture) { | 106 ui::MenuSourceType source_type) { |
| 107 const extensions::Extension* extension = | 107 const extensions::Extension* extension = |
| 108 (*views_)[start_index_ + id - 1]->button()->extension(); | 108 (*views_)[start_index_ + id - 1]->button()->extension(); |
| 109 if (!extension->ShowConfigureContextMenus()) | 109 if (!extension->ShowConfigureContextMenus()) |
| 110 return false; | 110 return false; |
| 111 | 111 |
| 112 scoped_refptr<ExtensionContextMenuModel> context_menu_contents = | 112 scoped_refptr<ExtensionContextMenuModel> context_menu_contents = |
| 113 new ExtensionContextMenuModel(extension, browser_, owner_); | 113 new ExtensionContextMenuModel(extension, browser_, owner_); |
| 114 views::MenuRunner context_menu_runner(context_menu_contents.get()); | 114 views::MenuRunner context_menu_runner(context_menu_contents.get()); |
| 115 | 115 |
| 116 // We can ignore the result as we delete ourself. | 116 // We can ignore the result as we delete ourself. |
| 117 // This blocks until the user choses something or dismisses the menu. | 117 // This blocks until the user choses something or dismisses the menu. |
| 118 ignore_result(context_menu_runner.RunMenuAt(menu_button_->GetWidget(), | 118 ignore_result(context_menu_runner.RunMenuAt(menu_button_->GetWidget(), |
| 119 NULL, gfx::Rect(p, gfx::Size()), views::MenuItemView::TOPLEFT, | 119 NULL, gfx::Rect(p, gfx::Size()), views::MenuItemView::TOPLEFT, |
| 120 source_type, |
| 120 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::IS_NESTED | | 121 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::IS_NESTED | |
| 121 views::MenuRunner::CONTEXT_MENU)); | 122 views::MenuRunner::CONTEXT_MENU)); |
| 122 | 123 |
| 123 // The user is done with the context menu, so we can close the underlying | 124 // The user is done with the context menu, so we can close the underlying |
| 124 // menu. | 125 // menu. |
| 125 menu_->Cancel(); | 126 menu_->Cancel(); |
| 126 | 127 |
| 127 return true; | 128 return true; |
| 128 } | 129 } |
| 129 | 130 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 | 219 |
| 219 BrowserActionView* BrowserActionOverflowMenuController::ViewForId( | 220 BrowserActionView* BrowserActionOverflowMenuController::ViewForId( |
| 220 int id, size_t* index) { | 221 int id, size_t* index) { |
| 221 // The index of the view being dragged (GetCommand gives a 1-based index into | 222 // The index of the view being dragged (GetCommand gives a 1-based index into |
| 222 // the overflow menu). | 223 // the overflow menu). |
| 223 size_t view_index = owner_->VisibleBrowserActions() + id - 1; | 224 size_t view_index = owner_->VisibleBrowserActions() + id - 1; |
| 224 if (index) | 225 if (index) |
| 225 *index = view_index; | 226 *index = view_index; |
| 226 return owner_->GetBrowserActionViewAt(view_index); | 227 return owner_->GetBrowserActionViewAt(view_index); |
| 227 } | 228 } |
| OLD | NEW |