diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-16 21:49:56 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-16 21:49:56 +0000 |
commit | dfe0adbb3425f47c0236f5fc7b715ac4dc74312c (patch) | |
tree | 4e9d4c70f88719a28f7e1deb89e7fab5a95c0aa0 | |
parent | 4bee23f2f19aa81bc95c662a56d8b3ec66d611de (diff) | |
download | chromium_src-dfe0adbb3425f47c0236f5fc7b715ac4dc74312c.zip chromium_src-dfe0adbb3425f47c0236f5fc7b715ac4dc74312c.tar.gz chromium_src-dfe0adbb3425f47c0236f5fc7b715ac4dc74312c.tar.bz2 |
Escape ampersands in web view text selection for right click context menu so that they don't show up as mnemonics.
Also escape underscores in gtk menus so they don't show up as mnemonics (we use ampersands to match windows).
BUG=14587
Review URL: http://codereview.chromium.org/203078
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26401 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/tab_contents/render_view_context_menu.cc | 31 | ||||
-rw-r--r-- | chrome/common/gtk_util.cc | 7 |
2 files changed, 30 insertions, 8 deletions
diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc index 2b4345a..f8f9dcd 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.cc +++ b/chrome/browser/tab_contents/render_view_context_menu.cc @@ -31,6 +31,25 @@ #include "net/base/net_util.h" #include "webkit/glue/media_player_action.h" +namespace { + +string16 EscapeAmpersands(const string16& text) { + string16 ret; + ret.reserve(text.length() * 2); + for (string16::const_iterator i = text.begin(); + i != text.end(); ++i) { + // The escape for an ampersand is two ampersands. + if ('&' == *i) + ret.push_back(*i); + + ret.push_back(*i); + } + + return ret; +} + +} // namespace + RenderViewContextMenu::RenderViewContextMenu( TabContents* tab_contents, const ContextMenuParams& params) @@ -189,13 +208,13 @@ void RenderViewContextMenu::AppendSearchProvider() { const TemplateURL* const default_provider = profile_->GetTemplateURLModel()->GetDefaultSearchProvider(); if (default_provider != NULL) { - std::wstring selection_text = - l10n_util::TruncateString(params_.selection_text, 50); + string16 selection_text = EscapeAmpersands(WideToUTF16( + l10n_util::TruncateString(params_.selection_text, 50))); if (!selection_text.empty()) { - string16 label(WideToUTF16( - l10n_util::GetStringF(IDS_CONTENT_CONTEXT_SEARCHWEBFOR, - default_provider->short_name(), - selection_text))); + string16 label(l10n_util::GetStringFUTF16( + IDS_CONTENT_CONTEXT_SEARCHWEBFOR, + WideToUTF16(default_provider->short_name()), + selection_text)); AppendMenuItem(IDS_CONTENT_CONTEXT_SEARCHWEBFOR, label); } } diff --git a/chrome/common/gtk_util.cc b/chrome/common/gtk_util.cc index 007c24c..e88ceb7 100644 --- a/chrome/common/gtk_util.cc +++ b/chrome/common/gtk_util.cc @@ -267,9 +267,12 @@ void CenterWidgetInHBox(GtkWidget* hbox, GtkWidget* widget, bool pack_at_end, std::string ConvertAcceleratorsFromWindowsStyle(const std::string& label) { std::string ret; - ret.reserve(label.length()); + ret.reserve(label.length() * 2); for (size_t i = 0; i < label.length(); ++i) { - if ('&' == label[i]) { + if ('_' == label[i]) { + ret.push_back('_'); + ret.push_back('_'); + } else if ('&' == label[i]) { if (i + 1 < label.length() && '&' == label[i + 1]) { ret.push_back(label[i]); ++i; |