Commit 43dce2b6 authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

macviews: hide accelerators in context menus

This change:
1) Moves the logic for showing accelerator text into MenuConfig
2) Adds a MenuConfig variable for whether to show accelerator text in
   context menus

Bug: 843703
Change-Id: Iedcef2ba4cdfc2a5390ddc0c9889af339625938d
Reviewed-on: https://chromium-review.googlesource.com/1069035
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560681}
parent 200d56fb
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "ui/views/controls/menu/menu_controller.h" #include "ui/views/controls/menu/menu_controller.h"
#include "ui/views/controls/menu/menu_image_util.h" #include "ui/views/controls/menu/menu_image_util.h"
#include "ui/views/controls/menu/menu_item_view.h"
#include "ui/views/round_rect_painter.h" #include "ui/views/round_rect_painter.h"
namespace views { namespace views {
...@@ -66,7 +67,8 @@ MenuConfig::MenuConfig() ...@@ -66,7 +67,8 @@ MenuConfig::MenuConfig()
touchable_menu_shadow_elevation(12), touchable_menu_shadow_elevation(12),
vertical_touchable_menu_item_padding(8), vertical_touchable_menu_item_padding(8),
padded_separator_left_margin(64), padded_separator_left_margin(64),
arrow_key_selection_wraps(true) { arrow_key_selection_wraps(true),
show_context_menu_accelerators(true) {
Init(); Init();
} }
...@@ -80,6 +82,21 @@ int MenuConfig::CornerRadiusForMenu(const MenuController* controller) const { ...@@ -80,6 +82,21 @@ int MenuConfig::CornerRadiusForMenu(const MenuController* controller) const {
return corner_radius; return corner_radius;
} }
bool MenuConfig::ShouldShowAcceleratorText(const MenuItemView* item,
base::string16* text) const {
if (!show_accelerators || !item->GetDelegate() || !item->GetCommand())
return false;
ui::Accelerator accelerator;
if (!item->GetDelegate()->GetAccelerator(item->GetCommand(), &accelerator))
return false;
if (item->GetMenuController() && item->GetMenuController()->IsContextMenu() &&
!show_context_menu_accelerators) {
return false;
}
*text = accelerator.GetShortcutText();
return true;
}
// static // static
const MenuConfig& MenuConfig::instance() { const MenuConfig& MenuConfig::instance() {
CR_DEFINE_STATIC_LOCAL(MenuConfig, instance, ()); CR_DEFINE_STATIC_LOCAL(MenuConfig, instance, ());
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
namespace views { namespace views {
class MenuController; class MenuController;
class MenuItemView;
// Layout type information for menu items. Use the instance() method to obtain // Layout type information for menu items. Use the instance() method to obtain
// the MenuConfig for the current platform. // the MenuConfig for the current platform.
...@@ -26,6 +27,11 @@ struct VIEWS_EXPORT MenuConfig { ...@@ -26,6 +27,11 @@ struct VIEWS_EXPORT MenuConfig {
// |controller|, or the default corner radius if |controller| is nullptr. // |controller|, or the default corner radius if |controller| is nullptr.
int CornerRadiusForMenu(const MenuController* controller) const; int CornerRadiusForMenu(const MenuController* controller) const;
// Returns whether |item_view| should show accelerator text. If so, returns
// the text to show.
bool ShouldShowAcceleratorText(const MenuItemView* item_view,
base::string16* text) const;
// Font list used by menus. // Font list used by menus.
gfx::FontList font_list; gfx::FontList font_list;
...@@ -196,6 +202,9 @@ struct VIEWS_EXPORT MenuConfig { ...@@ -196,6 +202,9 @@ struct VIEWS_EXPORT MenuConfig {
// Whether arrow keys should wrap around the end of the menu when selecting. // Whether arrow keys should wrap around the end of the menu when selecting.
bool arrow_key_selection_wraps; bool arrow_key_selection_wraps;
// Whether to show accelerators in context menus.
bool show_context_menu_accelerators;
private: private:
// Configures a MenuConfig as appropriate for the current platform. // Configures a MenuConfig as appropriate for the current platform.
void Init(); void Init();
......
...@@ -49,6 +49,7 @@ void MenuConfig::Init() { ...@@ -49,6 +49,7 @@ void MenuConfig::Init() {
check_selected_combobox_item = true; check_selected_combobox_item = true;
arrow_key_selection_wraps = false; arrow_key_selection_wraps = false;
use_mnemonics = false; use_mnemonics = false;
show_context_menu_accelerators = false;
if (ui::MaterialDesignController::IsSecondaryUiMaterial()) if (ui::MaterialDesignController::IsSecondaryUiMaterial())
InitMaterialMenuConfig(this); InitMaterialMenuConfig(this);
} }
......
...@@ -1213,12 +1213,9 @@ base::string16 MenuItemView::GetMinorText() const { ...@@ -1213,12 +1213,9 @@ base::string16 MenuItemView::GetMinorText() const {
return base::string16(); return base::string16();
} }
ui::Accelerator accelerator; base::string16 accel_text;
if (MenuConfig::instance().show_accelerators && GetDelegate() && if (MenuConfig::instance().ShouldShowAcceleratorText(this, &accel_text))
GetCommand() && return accel_text;
GetDelegate()->GetAccelerator(GetCommand(), &accelerator)) {
return accelerator.GetShortcutText();
}
return minor_text_; return minor_text_;
} }
......
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