summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authormattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-18 20:19:19 +0000
committermattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-18 20:19:19 +0000
commit3ce3e04f248adb3f440493bdae9c303433bc1fc2 (patch)
tree798f13dc156541e4102bae4afa30f839085bee90 /chrome/browser
parent8279af57b7cffbc823f105b6b1115c15ff25658f (diff)
downloadchromium_src-3ce3e04f248adb3f440493bdae9c303433bc1fc2.zip
chromium_src-3ce3e04f248adb3f440493bdae9c303433bc1fc2.tar.gz
chromium_src-3ce3e04f248adb3f440493bdae9c303433bc1fc2.tar.bz2
Add helper for forcing a GtkEntry to lowercase.
Make l10n_util::ToLower string16 friendly. BUG=13326 Review URL: http://codereview.chromium.org/126260 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18742 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/gtk/edit_keyword_controller.cc25
1 files changed, 22 insertions, 3 deletions
diff --git a/chrome/browser/gtk/edit_keyword_controller.cc b/chrome/browser/gtk/edit_keyword_controller.cc
index 9cc6f0d..7599ea4 100644
--- a/chrome/browser/gtk/edit_keyword_controller.cc
+++ b/chrome/browser/gtk/edit_keyword_controller.cc
@@ -32,6 +32,26 @@ GtkWidget* CreateEntryImageHBox(GtkWidget* entry, GtkWidget* image) {
return hbox;
}
+// Forces text to lowercase when connected to an editable's "insert-text"
+// signal. (Like views Textfield::STYLE_LOWERCASE.)
+void LowercaseInsertTextHandler(GtkEditable *editable, const gchar *text,
+ gint length, gint *position, gpointer data) {
+ string16 original_text = UTF8ToUTF16(text);
+ string16 lower_text = l10n_util::ToLower(original_text);
+ if (lower_text != original_text) {
+ std::string result = UTF16ToUTF8(lower_text);
+ // Prevent ourselves getting called recursively about our own edit.
+ g_signal_handlers_block_by_func(G_OBJECT(editable),
+ reinterpret_cast<gpointer>(LowercaseInsertTextHandler), data);
+ gtk_editable_insert_text(editable, result.c_str(), result.size(), position);
+ g_signal_handlers_unblock_by_func(G_OBJECT(editable),
+ reinterpret_cast<gpointer>(LowercaseInsertTextHandler), data);
+ // We've inserted our modified version, stop the defalut handler from
+ // inserting the original.
+ g_signal_stop_emission_by_name(G_OBJECT(editable), "insert_text");
+ }
+}
+
} // namespace
// static
@@ -99,9 +119,8 @@ void EditKeywordController::Init(GtkWindow* parent_window) {
gtk_entry_set_activates_default(GTK_ENTRY(keyword_entry_), TRUE);
g_signal_connect(G_OBJECT(keyword_entry_), "changed",
G_CALLBACK(OnEntryChanged), this);
- // TODO(mattm): will add in subsequent CL.
- //g_signal_connect(G_OBJECT(keyword_entry_), "insert-text",
- // G_CALLBACK(LowercaseInsertTextHandler), NULL);
+ g_signal_connect(G_OBJECT(keyword_entry_), "insert-text",
+ G_CALLBACK(LowercaseInsertTextHandler), NULL);
url_entry_ = gtk_entry_new();
gtk_entry_set_activates_default(GTK_ENTRY(url_entry_), TRUE);