diff options
author | mattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-05 23:09:04 +0000 |
---|---|---|
committer | mattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-05 23:09:04 +0000 |
commit | cc7c1c77040c26a56de3eeb953f468ced2a32186 (patch) | |
tree | 4ca3048a6d816ea9aaf324054703623c472a7a34 /chrome | |
parent | e9fd14ddb1888ac8906f04148f727467901c763b (diff) | |
download | chromium_src-cc7c1c77040c26a56de3eeb953f468ced2a32186.zip chromium_src-cc7c1c77040c26a56de3eeb953f468ced2a32186.tar.gz chromium_src-cc7c1c77040c26a56de3eeb953f468ced2a32186.tar.bz2 |
Move ConvertAcceleratorsFromWindowsStyle into chrome/common/gtk_util.
Use it on the custom startup url buttons.
BUG=11507
Review URL: http://codereview.chromium.org/118327
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17796 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/gtk/menu_gtk.cc | 24 | ||||
-rw-r--r-- | chrome/browser/gtk/menu_gtk.h | 5 | ||||
-rw-r--r-- | chrome/browser/gtk/options/general_page_gtk.cc | 18 | ||||
-rw-r--r-- | chrome/common/gtk_util.cc | 19 | ||||
-rw-r--r-- | chrome/common/gtk_util.h | 5 |
5 files changed, 37 insertions, 34 deletions
diff --git a/chrome/browser/gtk/menu_gtk.cc b/chrome/browser/gtk/menu_gtk.cc index 2721843..1636f67 100644 --- a/chrome/browser/gtk/menu_gtk.cc +++ b/chrome/browser/gtk/menu_gtk.cc @@ -9,8 +9,11 @@ #include "base/logging.h" #include "base/stl_util-inl.h" #include "base/string_util.h" +#include "chrome/common/gtk_util.h" #include "third_party/skia/include/core/SkBitmap.h" +using gtk_util::ConvertAcceleratorsFromWindowsStyle; + MenuGtk::MenuGtk(MenuGtk::Delegate* delegate, const MenuCreateMaterial* menu_data, GtkAccelGroup* accel_group) @@ -98,27 +101,6 @@ void MenuGtk::Cancel() { gtk_menu_popdown(GTK_MENU(menu_.get())); } -// static -std::string MenuGtk::ConvertAcceleratorsFromWindowsStyle( - const std::string& label) { - std::string ret; - ret.reserve(label.length()); - for (size_t i = 0; i < label.length(); ++i) { - if ('&' == label[i]) { - if (i + 1 < label.length() && '&' == label[i + 1]) { - ret.push_back(label[i]); - ++i; - } else { - ret.push_back('_'); - } - } else { - ret.push_back(label[i]); - } - } - - return ret; -} - void MenuGtk::BuildMenuIn(GtkWidget* menu, const MenuCreateMaterial* menu_data, GtkAccelGroup* accel_group) { diff --git a/chrome/browser/gtk/menu_gtk.h b/chrome/browser/gtk/menu_gtk.h index 444ab96..4bf51cd 100644 --- a/chrome/browser/gtk/menu_gtk.h +++ b/chrome/browser/gtk/menu_gtk.h @@ -79,11 +79,6 @@ class MenuGtk { // Closes the menu. void Cancel(); - // Change windows accelerator style to GTK style. (GTK uses _ for - // accelerators. Windows uses & with && as an escape for &.) - static std::string ConvertAcceleratorsFromWindowsStyle( - const std::string& label); - // Repositions the menu to be right under the button. Alignment is set as // object data on |void_widget| with the tag "left_align". If "left_align" // is true, it aligns the left side of the menu with the left side of the diff --git a/chrome/browser/gtk/options/general_page_gtk.cc b/chrome/browser/gtk/options/general_page_gtk.cc index 76ee824..5bf8d49 100644 --- a/chrome/browser/gtk/options/general_page_gtk.cc +++ b/chrome/browser/gtk/options/general_page_gtk.cc @@ -14,6 +14,7 @@ #include "chrome/browser/net/url_fixer_upper.h" #include "chrome/browser/session_startup_pref.h" #include "chrome/browser/shell_integration.h" +#include "chrome/common/gtk_util.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" #include "chrome/common/url_constants.h" @@ -229,22 +230,23 @@ GtkWidget* GeneralPageGtk::InitStartupGroup() { gtk_box_pack_end(GTK_BOX(url_list_container), url_list_buttons, FALSE, FALSE, 0); - // TODO(mattm): fix mnemonics (see - // MenuGtk::ConvertAcceleratorsFromWindowsStyle) - startup_add_custom_page_button_ = gtk_button_new_with_label( - l10n_util::GetStringUTF8(IDS_OPTIONS_STARTUP_ADD_BUTTON).c_str()); + startup_add_custom_page_button_ = gtk_button_new_with_mnemonic( + gtk_util::ConvertAcceleratorsFromWindowsStyle( + l10n_util::GetStringUTF8(IDS_OPTIONS_STARTUP_ADD_BUTTON)).c_str()); g_signal_connect(G_OBJECT(startup_add_custom_page_button_), "clicked", G_CALLBACK(OnStartupAddCustomPageClicked), this); gtk_box_pack_start(GTK_BOX(url_list_buttons), startup_add_custom_page_button_, FALSE, FALSE, 0); - startup_remove_custom_page_button_ = gtk_button_new_with_label( - l10n_util::GetStringUTF8(IDS_OPTIONS_STARTUP_REMOVE_BUTTON).c_str()); + startup_remove_custom_page_button_ = gtk_button_new_with_mnemonic( + gtk_util::ConvertAcceleratorsFromWindowsStyle( + l10n_util::GetStringUTF8(IDS_OPTIONS_STARTUP_REMOVE_BUTTON)).c_str()); g_signal_connect(G_OBJECT(startup_remove_custom_page_button_), "clicked", G_CALLBACK(OnStartupRemoveCustomPageClicked), this); gtk_box_pack_start(GTK_BOX(url_list_buttons), startup_remove_custom_page_button_, FALSE, FALSE, 0); - startup_use_current_page_button_ = gtk_button_new_with_label( - l10n_util::GetStringUTF8(IDS_OPTIONS_STARTUP_USE_CURRENT).c_str()); + startup_use_current_page_button_ = gtk_button_new_with_mnemonic( + gtk_util::ConvertAcceleratorsFromWindowsStyle( + l10n_util::GetStringUTF8(IDS_OPTIONS_STARTUP_USE_CURRENT)).c_str()); g_signal_connect(G_OBJECT(startup_use_current_page_button_), "clicked", G_CALLBACK(OnStartupUseCurrentPageClicked), this); gtk_box_pack_start(GTK_BOX(url_list_buttons), diff --git a/chrome/common/gtk_util.cc b/chrome/common/gtk_util.cc index fb34a66..515482b 100644 --- a/chrome/common/gtk_util.cc +++ b/chrome/common/gtk_util.cc @@ -132,4 +132,23 @@ void CenterWidgetInHBox(GtkWidget* hbox, GtkWidget* widget, bool pack_at_end, gtk_box_pack_start(GTK_BOX(hbox), centering_vbox, FALSE, FALSE, padding); } +std::string ConvertAcceleratorsFromWindowsStyle(const std::string& label) { + std::string ret; + ret.reserve(label.length()); + for (size_t i = 0; i < label.length(); ++i) { + if ('&' == label[i]) { + if (i + 1 < label.length() && '&' == label[i + 1]) { + ret.push_back(label[i]); + ++i; + } else { + ret.push_back('_'); + } + } else { + ret.push_back(label[i]); + } + } + + return ret; +} + } // namespace gtk_util diff --git a/chrome/common/gtk_util.h b/chrome/common/gtk_util.h index 45ebdbb..d9827d82 100644 --- a/chrome/common/gtk_util.h +++ b/chrome/common/gtk_util.h @@ -6,6 +6,7 @@ #define CHROME_COMMON_GTK_UTIL_H_ #include <gtk/gtk.h> +#include <string> #include "base/gfx/point.h" #include "base/gfx/rect.h" @@ -50,6 +51,10 @@ void InitRCStyles(); void CenterWidgetInHBox(GtkWidget* hbox, GtkWidget* widget, bool pack_at_end, int padding); +// Change windows accelerator style to GTK style. (GTK uses _ for +// accelerators. Windows uses & with && as an escape for &.) +std::string ConvertAcceleratorsFromWindowsStyle(const std::string& label); + } // namespace gtk_util #endif // CHROME_COMMON_GTK_UTIL_H_ |