diff options
author | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-22 17:21:04 +0000 |
---|---|---|
committer | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-22 17:21:04 +0000 |
commit | b1b945e8f3586a8d08acc9e7d29b4efe99606373 (patch) | |
tree | 6d9a280621bb7d55b641b787f887b31503d91dd6 /chrome | |
parent | 0f8a6b4de386b469859f6cd12c0ba091453c9a4d (diff) | |
download | chromium_src-b1b945e8f3586a8d08acc9e7d29b4efe99606373.zip chromium_src-b1b945e8f3586a8d08acc9e7d29b4efe99606373.tar.gz chromium_src-b1b945e8f3586a8d08acc9e7d29b4efe99606373.tar.bz2 |
Fixes mnemonic bug in chrome menus. After this change you can indicate
whether menus have mnemonics. Mnemonics are shown if the menus have
mnemonics, and the OS says we should show them.
BUG=1355952
TEST=add a bookmark and change the title to &foo. Move the bookmark to
a folder, click on the folder and make sure the title shows the &.
Review URL: http://codereview.chromium.org/4002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2442 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/bookmark_bar_context_menu_controller.cc | 2 | ||||
-rw-r--r-- | chrome/browser/views/tabs/tab.cc | 2 | ||||
-rw-r--r-- | chrome/views/chrome_menu.cc | 28 | ||||
-rw-r--r-- | chrome/views/chrome_menu.h | 12 |
4 files changed, 31 insertions, 13 deletions
diff --git a/chrome/browser/bookmark_bar_context_menu_controller.cc b/chrome/browser/bookmark_bar_context_menu_controller.cc index cb195ef..8bce486 100644 --- a/chrome/browser/bookmark_bar_context_menu_controller.cc +++ b/chrome/browser/bookmark_bar_context_menu_controller.cc @@ -237,7 +237,7 @@ void BookmarkBarContextMenuController::RunMenuAt(int x, int y) { // width/height don't matter here. menu_.RunMenuAt(view_->GetViewContainer()->GetHWND(), gfx::Rect(x, y, 0, 0), - ChromeViews::MenuItemView::TOPLEFT, false); + ChromeViews::MenuItemView::TOPLEFT, true); if (view_->GetModelChangedListener() == this) view_->SetModelChangedListener(last_listener); diff --git a/chrome/browser/views/tabs/tab.cc b/chrome/browser/views/tabs/tab.cc index 82bb795..8a283bf 100644 --- a/chrome/browser/views/tabs/tab.cc +++ b/chrome/browser/views/tabs/tab.cc @@ -54,7 +54,7 @@ class TabContextMenuController : public ChromeViews::MenuDelegate { void RunMenuAt(int x, int y) { menu_->RunMenuAt(tab_->GetViewContainer()->GetHWND(), gfx::Rect(x, y, 0, 0), ChromeViews::MenuItemView::TOPLEFT, - false); + true); } private: diff --git a/chrome/views/chrome_menu.cc b/chrome/views/chrome_menu.cc index 360f8c4..537503f 100644 --- a/chrome/views/chrome_menu.cc +++ b/chrome/views/chrome_menu.cc @@ -103,6 +103,9 @@ static const int kScrollTimerMS = 30; // Preferred height of menu items. Reset every time a menu is run. static int pref_menu_height; +// Are mnemonics shown? This is updated before the menus are shown. +static bool show_mnemonics; + using gfx::NativeTheme; namespace ChromeViews { @@ -1069,8 +1072,8 @@ MenuItemView::~MenuItemView() { void MenuItemView::RunMenuAt(HWND parent, const gfx::Rect& bounds, AnchorPosition anchor, - bool show_mnemonics) { - PrepareForRun(show_mnemonics); + bool has_mnemonics) { + PrepareForRun(has_mnemonics); int mouse_event_flags; @@ -1190,6 +1193,9 @@ MenuItemView* MenuItemView::GetRootMenuItem() { } wchar_t MenuItemView::GetMnemonic() { + if (!has_mnemonics_) + return 0; + const std::wstring& title = GetTitle(); size_t index = 0; do { @@ -1285,7 +1291,7 @@ void MenuItemView::DropMenuClosed(bool notify_delegate) { // WARNING: its possible the delegate deleted us at this point. } -void MenuItemView::PrepareForRun(bool show_mnemonics) { +void MenuItemView::PrepareForRun(bool has_mnemonics) { // Currently we only support showing the root. DCHECK(!parent_menu_item_); @@ -1297,11 +1303,16 @@ void MenuItemView::PrepareForRun(bool show_mnemonics) { canceled_ = false; - show_mnemonics_ = show_mnemonics; + has_mnemonics_ = has_mnemonics; AddEmptyMenus(); UpdateMenuPartSizes(); + + BOOL show_cues; + show_mnemonics = + (SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &show_cues, 0) && + show_cues == TRUE); } int MenuItemView::GetDrawStringFlags() { @@ -1311,8 +1322,13 @@ int MenuItemView::GetDrawStringFlags() { else flags |= ChromeCanvas::TEXT_ALIGN_LEFT; - return flags | - (show_mnemonics_ ? ChromeCanvas::SHOW_PREFIX : ChromeCanvas::HIDE_PREFIX); + if (has_mnemonics_) { + if (show_mnemonics) + flags |= ChromeCanvas::SHOW_PREFIX; + else + flags |= ChromeCanvas::HIDE_PREFIX; + } + return flags; } void MenuItemView::AddEmptyMenus() { diff --git a/chrome/views/chrome_menu.h b/chrome/views/chrome_menu.h index 05cce11..b192c9c 100644 --- a/chrome/views/chrome_menu.h +++ b/chrome/views/chrome_menu.h @@ -238,11 +238,13 @@ class MenuItemView : public View { virtual ~MenuItemView(); // Run methods. See description above class for details. Both Run methods take - // a rectangle, which is used to position the menu. + // a rectangle, which is used to position the menu. |has_mnemonics| indicates + // whether the items have mnemonics. Mnemonics are identified by way of the + // character following the '&'. void RunMenuAt(HWND parent, const gfx::Rect& bounds, AnchorPosition anchor, - bool show_mnemonics); + bool has_mnemonics); void RunMenuForDropAt(HWND parent, const gfx::Rect& bounds, AnchorPosition anchor); @@ -397,7 +399,7 @@ class MenuItemView : public View { // The RunXXX methods call into this to set up the necessary state before // running. - void PrepareForRun(bool show_mnemonics); + void PrepareForRun(bool has_mnemonics); // Returns the flags passed to DrawStringInt. int GetDrawStringFlags(); @@ -459,8 +461,8 @@ class MenuItemView : public View { // Icon. SkBitmap icon_; - // Whether mnemonics should be shown. - bool show_mnemonics_; + // Does the title have a mnemonic? + bool has_mnemonics_; DISALLOW_EVIL_CONSTRUCTORS(MenuItemView); }; |