summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--app/l10n_util.cc17
-rw-r--r--app/l10n_util.h4
-rw-r--r--chrome/browser/gtk/edit_keyword_controller.cc25
3 files changed, 31 insertions, 15 deletions
diff --git a/app/l10n_util.cc b/app/l10n_util.cc
index 81fb7f4..d51b113 100644
--- a/app/l10n_util.cc
+++ b/app/l10n_util.cc
@@ -476,25 +476,18 @@ std::wstring TruncateString(const std::wstring& string, size_t length) {
#if defined(WCHAR_T_IS_UTF32)
std::wstring ToLower(const std::wstring& string) {
- string16 string_utf16 = WideToUTF16(string);
- UnicodeString lower_u_str(
- UnicodeString(string_utf16.c_str()).toLower(Locale::getDefault()));
- string16 result_utf16;
- lower_u_str.extract(0, lower_u_str.length(),
- WriteInto(&result_utf16, lower_u_str.length() + 1));
- std::wstring result = UTF16ToWide(result_utf16);
- return result;
+ return UTF16ToWide(ToLower(WideToUTF16(string)));
}
-#else
-std::wstring ToLower(const std::wstring& string) {
+#endif // defined(WCHAR_T_IS_UTF32)
+
+string16 ToLower(const string16& string) {
UnicodeString lower_u_str(
UnicodeString(string.c_str()).toLower(Locale::getDefault()));
- std::wstring result;
+ string16 result;
lower_u_str.extract(0, lower_u_str.length(),
WriteInto(&result, lower_u_str.length() + 1));
return result;
}
-#endif // defined(WCHAR_T_IS_UTF32)
// Returns the text direction for the default ICU locale. It is assumed
// that SetICUDefaultLocale has been called to set the default locale to
diff --git a/app/l10n_util.h b/app/l10n_util.h
index 69d3271..c4c62e13 100644
--- a/app/l10n_util.h
+++ b/app/l10n_util.h
@@ -124,7 +124,11 @@ std::wstring GetStringF(int message_id, int64 a);
std::wstring TruncateString(const std::wstring& string, size_t length);
// Returns the lower case equivalent of string.
+#if defined(WCHAR_T_IS_UTF32)
+// Deprecated. The string16 version should be used instead.
std::wstring ToLower(const std::wstring& string);
+#endif // defined(WCHAR_T_IS_UTF32)
+string16 ToLower(const string16& string);
// Represents the text direction returned by the GetTextDirection() function.
enum TextDirection {
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);