Commit e35a8ac4 authored by Dana Fried's avatar Dana Fried Committed by Commit Bot

Use Views context menus on tabstrip on Mac.

This was the result of a discussion with ellyjones@ regarding the best
way to handle features that could only easily be implemented in Views
that we needed for user education.

The decision was made that context menus in Top Chrome could be moved to
Views, but not for web contents and context menus on text fields, which
would remain in Cocoa to provide visual distinction and to provide
access to e.g. the system emoji chooser.

This CL adds a mechanism by which Top Chrome code can force a context
menu that would otherwise be rendered natively to use Views code
instead, and applies it to tabstrip context menus.

Bug: 1109256
Change-Id: Ib3c3970f56df0714687aaf87a1267d7ae8e2c17b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2317809
Commit-Queue: Dana Fried <dfried@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792451}
parent 251cfc0e
...@@ -110,9 +110,13 @@ class BrowserTabStripController::TabContextMenuContents ...@@ -110,9 +110,13 @@ class BrowserTabStripController::TabContextMenuContents
tab_groups_iph_controller_(tab_groups_iph_controller) { tab_groups_iph_controller_(tab_groups_iph_controller) {
model_ = controller_->menu_model_factory_->Create( model_ = controller_->menu_model_factory_->Create(
this, controller->model_, controller->tabstrip_->GetModelIndexOf(tab)); this, controller->model_, controller->tabstrip_->GetModelIndexOf(tab));
menu_runner_ = std::make_unique<views::MenuRunner>(
model_.get(), // Because we use "new" badging for feature promos, we cannot use system-
views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU); // native context menus. (See crbug.com/1109256.)
const int run_flags = views::MenuRunner::HAS_MNEMONICS |
views::MenuRunner::CONTEXT_MENU |
views::MenuRunner::FORCE_VIEWS;
menu_runner_ = std::make_unique<views::MenuRunner>(model_.get(), run_flags);
} }
void Cancel() { controller_ = nullptr; } void Cancel() { controller_ = nullptr; }
......
...@@ -67,6 +67,7 @@ class VIEWS_EXPORT MenuRunner { ...@@ -67,6 +67,7 @@ class VIEWS_EXPORT MenuRunner {
// The menu is a nested context menu. For example, click a folder on the // The menu is a nested context menu. For example, click a folder on the
// bookmark bar, then right click an entry to get its context menu. // bookmark bar, then right click an entry to get its context menu.
// Currently implies FORCE_VIEWS.
IS_NESTED = 1 << 1, IS_NESTED = 1 << 1,
// Used for showing a menu during a drop operation. This does NOT block the // Used for showing a menu during a drop operation. This does NOT block the
...@@ -108,6 +109,10 @@ class VIEWS_EXPORT MenuRunner { ...@@ -108,6 +109,10 @@ class VIEWS_EXPORT MenuRunner {
// Indicates that the menu should show mnemonics. // Indicates that the menu should show mnemonics.
SHOULD_SHOW_MNEMONICS = 1 << 10, SHOULD_SHOW_MNEMONICS = 1 << 10,
// Indicates that the menu contains Views-only features, and therefore
// should not be rendered using a native system menu.
FORCE_VIEWS = 1 << 11,
}; };
// Creates a new MenuRunner, which may use a native menu if available. // Creates a new MenuRunner, which may use a native menu if available.
......
...@@ -124,7 +124,7 @@ MenuRunnerImplInterface* MenuRunnerImplInterface::Create( ...@@ -124,7 +124,7 @@ MenuRunnerImplInterface* MenuRunnerImplInterface::Create(
int32_t run_types, int32_t run_types,
base::RepeatingClosure on_menu_closed_callback) { base::RepeatingClosure on_menu_closed_callback) {
if ((run_types & MenuRunner::CONTEXT_MENU) && if ((run_types & MenuRunner::CONTEXT_MENU) &&
!(run_types & MenuRunner::IS_NESTED)) { !(run_types & (MenuRunner::IS_NESTED | MenuRunner::FORCE_VIEWS))) {
return new MenuRunnerImplCocoa(menu_model, return new MenuRunnerImplCocoa(menu_model,
std::move(on_menu_closed_callback)); std::move(on_menu_closed_callback));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment