Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(555)

Side by Side Diff: chrome/browser/ui/views/extensions/browser_action_overflow_menu_controller.cc

Issue 331993009: MacViews: Run native Cocoa context menus to support Services. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add VIEWS_EXPORT for unit test access Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/message_loop.h" 7 #include "base/message_loop/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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 BrowserActionButton* button_; 56 BrowserActionButton* button_;
57 57
58 DISALLOW_COPY_AND_ASSIGN(IconUpdater); 58 DISALLOW_COPY_AND_ASSIGN(IconUpdater);
59 }; 59 };
60 60
61 BrowserActionOverflowMenuController::BrowserActionOverflowMenuController( 61 BrowserActionOverflowMenuController::BrowserActionOverflowMenuController(
62 BrowserActionsContainer* owner, 62 BrowserActionsContainer* owner,
63 Browser* browser, 63 Browser* browser,
64 views::MenuButton* menu_button, 64 views::MenuButton* menu_button,
65 const std::vector<BrowserActionView*>& views, 65 const std::vector<BrowserActionView*>& views,
66 int start_index) 66 int start_index,
67 bool for_drop)
67 : owner_(owner), 68 : owner_(owner),
68 browser_(browser), 69 browser_(browser),
69 observer_(NULL), 70 observer_(NULL),
70 menu_button_(menu_button), 71 menu_button_(menu_button),
71 menu_(NULL), 72 menu_(NULL),
72 views_(&views), 73 views_(&views),
73 start_index_(start_index), 74 start_index_(start_index),
74 for_drop_(false) { 75 for_drop_(for_drop) {
75 menu_ = new views::MenuItemView(this); 76 menu_ = new views::MenuItemView(this);
76 menu_runner_.reset(new views::MenuRunner(menu_)); 77 menu_runner_.reset(new views::MenuRunner(
78 menu_, for_drop_ ? views::MenuRunner::FOR_DROP : 0));
77 menu_->set_has_icons(true); 79 menu_->set_has_icons(true);
78 80
79 size_t command_id = 1; // Menu id 0 is reserved, start with 1. 81 size_t command_id = 1; // Menu id 0 is reserved, start with 1.
80 for (size_t i = start_index; i < views_->size(); ++i) { 82 for (size_t i = start_index; i < views_->size(); ++i) {
81 BrowserActionView* view = (*views_)[i]; 83 BrowserActionView* view = (*views_)[i];
82 views::MenuItemView* menu_item = menu_->AppendMenuItemWithIcon( 84 views::MenuItemView* menu_item = menu_->AppendMenuItemWithIcon(
83 command_id, 85 command_id,
84 base::UTF8ToUTF16(view->button()->extension()->name()), 86 base::UTF8ToUTF16(view->button()->extension()->name()),
85 view->GetIconWithBadge()); 87 view->GetIconWithBadge());
86 88
87 // Set the tooltip for this item. 89 // Set the tooltip for this item.
88 base::string16 tooltip = base::UTF8ToUTF16( 90 base::string16 tooltip = base::UTF8ToUTF16(
89 extensions::ExtensionActionManager::Get(owner_->profile())-> 91 extensions::ExtensionActionManager::Get(owner_->profile())->
90 GetBrowserAction(*view->button()->extension())-> 92 GetBrowserAction(*view->button()->extension())->
91 GetTitle(owner_->GetCurrentTabId())); 93 GetTitle(owner_->GetCurrentTabId()));
92 menu_->SetTooltip(tooltip, command_id); 94 menu_->SetTooltip(tooltip, command_id);
93 95
94 icon_updaters_.push_back(new IconUpdater(menu_item, view->button())); 96 icon_updaters_.push_back(new IconUpdater(menu_item, view->button()));
95 97
96 ++command_id; 98 ++command_id;
97 } 99 }
98 } 100 }
99 101
100 BrowserActionOverflowMenuController::~BrowserActionOverflowMenuController() { 102 BrowserActionOverflowMenuController::~BrowserActionOverflowMenuController() {
101 if (observer_) 103 if (observer_)
102 observer_->NotifyMenuDeleted(this); 104 observer_->NotifyMenuDeleted(this);
103 } 105 }
104 106
105 bool BrowserActionOverflowMenuController::RunMenu(views::Widget* window, 107 bool BrowserActionOverflowMenuController::RunMenu(views::Widget* window) {
106 bool for_drop) {
107 for_drop_ = for_drop;
108
109 gfx::Rect bounds = menu_button_->bounds(); 108 gfx::Rect bounds = menu_button_->bounds();
110 gfx::Point screen_loc; 109 gfx::Point screen_loc;
111 views::View::ConvertPointToScreen(menu_button_, &screen_loc); 110 views::View::ConvertPointToScreen(menu_button_, &screen_loc);
112 bounds.set_x(screen_loc.x()); 111 bounds.set_x(screen_loc.x());
113 bounds.set_y(screen_loc.y()); 112 bounds.set_y(screen_loc.y());
114 113
115 views::MenuAnchorPosition anchor = views::MENU_ANCHOR_TOPRIGHT; 114 views::MenuAnchorPosition anchor = views::MENU_ANCHOR_TOPRIGHT;
116 // As we maintain our own lifetime we can safely ignore the result. 115 // As we maintain our own lifetime we can safely ignore the result.
117 ignore_result(menu_runner_->RunMenuAt(window, menu_button_, bounds, anchor, 116 ignore_result(menu_runner_->RunMenuAt(
118 ui::MENU_SOURCE_NONE, for_drop_ ? views::MenuRunner::FOR_DROP : 0)); 117 window, menu_button_, bounds, anchor, ui::MENU_SOURCE_NONE));
119 if (!for_drop_) { 118 if (!for_drop_) {
120 // Give the context menu (if any) a chance to execute the user-selected 119 // Give the context menu (if any) a chance to execute the user-selected
121 // command. 120 // command.
122 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); 121 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
123 } 122 }
124 return true; 123 return true;
125 } 124 }
126 125
127 void BrowserActionOverflowMenuController::CancelMenu() { 126 void BrowserActionOverflowMenuController::CancelMenu() {
128 menu_->Cancel(); 127 menu_->Cancel();
(...skipping 14 matching lines...) Expand all
143 int id, 142 int id,
144 const gfx::Point& p, 143 const gfx::Point& p,
145 ui::MenuSourceType source_type) { 144 ui::MenuSourceType source_type) {
146 const extensions::Extension* extension = 145 const extensions::Extension* extension =
147 (*views_)[start_index_ + id - 1]->button()->extension(); 146 (*views_)[start_index_ + id - 1]->button()->extension();
148 if (!extension->ShowConfigureContextMenus()) 147 if (!extension->ShowConfigureContextMenus())
149 return false; 148 return false;
150 149
151 scoped_refptr<ExtensionContextMenuModel> context_menu_contents = 150 scoped_refptr<ExtensionContextMenuModel> context_menu_contents =
152 new ExtensionContextMenuModel(extension, browser_, owner_); 151 new ExtensionContextMenuModel(extension, browser_, owner_);
153 views::MenuRunner context_menu_runner(context_menu_contents.get()); 152 views::MenuRunner context_menu_runner(context_menu_contents.get(),
153 views::MenuRunner::HAS_MNEMONICS |
154 views::MenuRunner::IS_NESTED |
155 views::MenuRunner::CONTEXT_MENU);
154 156
155 // We can ignore the result as we delete ourself. 157 // We can ignore the result as we delete ourself.
156 // This blocks until the user choses something or dismisses the menu. 158 // This blocks until the user choses something or dismisses the menu.
157 ignore_result(context_menu_runner.RunMenuAt( 159 ignore_result(context_menu_runner.RunMenuAt(menu_button_->GetWidget(),
158 menu_button_->GetWidget(), 160 NULL,
159 NULL, 161 gfx::Rect(p, gfx::Size()),
160 gfx::Rect(p, gfx::Size()), 162 views::MENU_ANCHOR_TOPLEFT,
161 views::MENU_ANCHOR_TOPLEFT, 163 source_type));
162 source_type,
163 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::IS_NESTED |
164 views::MenuRunner::CONTEXT_MENU));
165 164
166 // The user is done with the context menu, so we can close the underlying 165 // The user is done with the context menu, so we can close the underlying
167 // menu. 166 // menu.
168 menu_->Cancel(); 167 menu_->Cancel();
169 168
170 return true; 169 return true;
171 } 170 }
172 171
173 void BrowserActionOverflowMenuController::DropMenuClosed( 172 void BrowserActionOverflowMenuController::DropMenuClosed(
174 views::MenuItemView* menu) { 173 views::MenuItemView* menu) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 260
262 BrowserActionView* BrowserActionOverflowMenuController::ViewForId( 261 BrowserActionView* BrowserActionOverflowMenuController::ViewForId(
263 int id, size_t* index) { 262 int id, size_t* index) {
264 // The index of the view being dragged (GetCommand gives a 1-based index into 263 // The index of the view being dragged (GetCommand gives a 1-based index into
265 // the overflow menu). 264 // the overflow menu).
266 size_t view_index = owner_->VisibleBrowserActions() + id - 1; 265 size_t view_index = owner_->VisibleBrowserActions() + id - 1;
267 if (index) 266 if (index)
268 *index = view_index; 267 *index = view_index;
269 return owner_->GetBrowserActionViewAt(view_index); 268 return owner_->GetBrowserActionViewAt(view_index);
270 } 269 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698