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

Side by Side Diff: chrome/browser/ui/views/toolbar/toolbar_action_view.cc

Issue 2790773002: Cleanup MenuRunner API (Closed)
Patch Set: Rebase Created 3 years, 8 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/toolbar/toolbar_action_view.h" 5 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 ui::MenuModel* context_menu_model = view_controller_->GetContextMenu(); 267 ui::MenuModel* context_menu_model = view_controller_->GetContextMenu();
268 // It's possible the action doesn't have a context menu. 268 // It's possible the action doesn't have a context menu.
269 if (!context_menu_model) 269 if (!context_menu_model)
270 return; 270 return;
271 271
272 DCHECK(visible()); // We should never show a context menu for a hidden item. 272 DCHECK(visible()); // We should never show a context menu for a hidden item.
273 273
274 gfx::Point screen_loc; 274 gfx::Point screen_loc;
275 ConvertPointToScreen(this, &screen_loc); 275 ConvertPointToScreen(this, &screen_loc);
276 276
277 int run_types = views::MenuRunner::HAS_MNEMONICS | 277 int run_types =
278 views::MenuRunner::CONTEXT_MENU | views::MenuRunner::ASYNC; 278 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU;
279 if (delegate_->ShownInsideMenu()) 279 if (delegate_->ShownInsideMenu())
280 run_types |= views::MenuRunner::IS_NESTED; 280 run_types |= views::MenuRunner::IS_NESTED;
281 281
282 // RunMenuAt expects a nested menu to be parented by the same widget as the 282 // RunMenuAt expects a nested menu to be parented by the same widget as the
283 // already visible menu, in this case the Chrome menu. 283 // already visible menu, in this case the Chrome menu.
284 views::Widget* parent = delegate_->ShownInsideMenu() ? 284 views::Widget* parent = delegate_->ShownInsideMenu() ?
285 delegate_->GetOverflowReferenceView()->GetWidget() : 285 delegate_->GetOverflowReferenceView()->GetWidget() :
286 GetWidget(); 286 GetWidget();
287 287
288 // Unretained() is safe here as ToolbarActionView will always outlive the 288 // Unretained() is safe here as ToolbarActionView will always outlive the
289 // menu. Any action that would lead to the deletion of |this| first triggers 289 // menu. Any action that would lead to the deletion of |this| first triggers
290 // the closing of the menu through lost capture. 290 // the closing of the menu through lost capture.
291 menu_adapter_.reset(new views::MenuModelAdapter( 291 menu_adapter_.reset(new views::MenuModelAdapter(
292 context_menu_model, 292 context_menu_model,
293 base::Bind(&ToolbarActionView::OnMenuClosed, base::Unretained(this)))); 293 base::Bind(&ToolbarActionView::OnMenuClosed, base::Unretained(this))));
294 menu_ = menu_adapter_->CreateMenu(); 294 menu_ = menu_adapter_->CreateMenu();
295 menu_runner_.reset(new views::MenuRunner(menu_, run_types)); 295 menu_runner_.reset(new views::MenuRunner(menu_, run_types));
296 296
297 ignore_result( 297 menu_runner_->RunMenuAt(parent, this, gfx::Rect(screen_loc, size()),
298 menu_runner_->RunMenuAt(parent, this, gfx::Rect(screen_loc, size()), 298 views::MENU_ANCHOR_TOPLEFT, source_type);
299 views::MENU_ANCHOR_TOPLEFT, source_type));
300 } 299 }
301 300
302 bool ToolbarActionView::CloseActiveMenuIfNeeded() { 301 bool ToolbarActionView::CloseActiveMenuIfNeeded() {
303 // If this view is shown inside another menu, there's a possibility that there 302 // If this view is shown inside another menu, there's a possibility that there
304 // is another context menu showing that we have to close before we can 303 // is another context menu showing that we have to close before we can
305 // activate a different menu. 304 // activate a different menu.
306 if (delegate_->ShownInsideMenu()) { 305 if (delegate_->ShownInsideMenu()) {
307 views::MenuController* menu_controller = 306 views::MenuController* menu_controller =
308 views::MenuController::GetActiveInstance(); 307 views::MenuController::GetActiveInstance();
309 // If this is shown inside a menu, then there should always be an active 308 // If this is shown inside a menu, then there should always be an active
310 // menu controller. 309 // menu controller.
311 DCHECK(menu_controller); 310 DCHECK(menu_controller);
312 if (menu_controller->in_nested_run()) { 311 if (menu_controller->in_nested_run()) {
313 // There is another menu showing. Close the outermost menu (since we are 312 // There is another menu showing. Close the outermost menu (since we are
314 // shown in the same menu, we don't want to close the whole thing). 313 // shown in the same menu, we don't want to close the whole thing).
315 menu_controller->Cancel(views::MenuController::EXIT_OUTERMOST); 314 menu_controller->Cancel(views::MenuController::EXIT_OUTERMOST);
316 return true; 315 return true;
317 } 316 }
318 } 317 }
319 318
320 return false; 319 return false;
321 } 320 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/toolbar/app_menu.cc ('k') | chrome/browser/ui/views/toolbar/toolbar_button.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698