summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-26 00:26:26 +0000
committersky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-26 00:26:26 +0000
commit802cbf0fc2d88085b7ef5c5fa01d32b261287d6f (patch)
tree7b78d590d1aba7623ac8c82cbca9de766fc216a3
parentf42d28c678cd72979d64eebed9ea879c59e2576a (diff)
downloadchromium_src-802cbf0fc2d88085b7ef5c5fa01d32b261287d6f.zip
chromium_src-802cbf0fc2d88085b7ef5c5fa01d32b261287d6f.tar.gz
chromium_src-802cbf0fc2d88085b7ef5c5fa01d32b261287d6f.tar.bz2
Changes keyword editor to map all input in the keyword field to lower
case. BUG=4520 TEST=bring up the keyword editor, type some text and make sure it gets mapped to lower case. Review URL: http://codereview.chromium.org/12452 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6018 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/views/edit_keyword_controller.cc18
-rw-r--r--chrome/browser/views/edit_keyword_controller.h13
-rw-r--r--chrome/views/text_field.cc20
-rw-r--r--chrome/views/text_field.h3
4 files changed, 33 insertions, 21 deletions
diff --git a/chrome/browser/views/edit_keyword_controller.cc b/chrome/browser/views/edit_keyword_controller.cc
index 0ae528b..efbb43e 100644
--- a/chrome/browser/views/edit_keyword_controller.cc
+++ b/chrome/browser/views/edit_keyword_controller.cc
@@ -173,16 +173,16 @@ void EditKeywordController::Init() {
// Create the views we'll need.
view_ = new views::View();
if (template_url_) {
- title_tf_ = CreateTextField(template_url_->short_name());
- keyword_tf_ = CreateTextField(template_url_->keyword());
- url_tf_ = CreateTextField(GetDisplayURL(*template_url_));
+ title_tf_ = CreateTextField(template_url_->short_name(), false);
+ keyword_tf_ = CreateTextField(template_url_->keyword(), true);
+ url_tf_ = CreateTextField(GetDisplayURL(*template_url_), false);
// We don't allow users to edit prepopulate URLs. This is done as
// occasionally we need to update the URL of prepopulated TemplateURLs.
url_tf_->SetReadOnly(template_url_->prepopulate_id() != 0);
} else {
- title_tf_ = CreateTextField(std::wstring());
- keyword_tf_ = CreateTextField(std::wstring());
- url_tf_ = CreateTextField(std::wstring());
+ title_tf_ = CreateTextField(std::wstring(), false);
+ keyword_tf_ = CreateTextField(std::wstring(), true);
+ url_tf_ = CreateTextField(std::wstring(), false);
}
title_iv_ = new ImageView();
keyword_iv_ = new ImageView();
@@ -277,8 +277,10 @@ views::Label* EditKeywordController::CreateLabel(int message_id) {
return label;
}
-TextField* EditKeywordController::CreateTextField(const std::wstring& text) {
- TextField* text_field = new TextField();
+TextField* EditKeywordController::CreateTextField(const std::wstring& text,
+ bool lowercase) {
+ TextField* text_field = new TextField(
+ lowercase ? TextField::STYLE_LOWERCASE : TextField::STYLE_DEFAULT);
text_field->SetText(text);
text_field->SetController(this);
return text_field;
diff --git a/chrome/browser/views/edit_keyword_controller.h b/chrome/browser/views/edit_keyword_controller.h
index fa01a4f..7268e89 100644
--- a/chrome/browser/views/edit_keyword_controller.h
+++ b/chrome/browser/views/edit_keyword_controller.h
@@ -7,8 +7,8 @@
// dialog, and also on its own to confirm the addition of a keyword added by
// the ExternalJSObject via the RenderView.
-#ifndef CHROME_BROWSER_VIEWS_EDIT_KEYWORD_CONTROLLER_H__
-#define CHROME_BROWSER_VIEWS_EDIT_KEYWORD_CONTROLLER_H__
+#ifndef CHROME_BROWSER_VIEWS_EDIT_KEYWORD_CONTROLLER_H_
+#define CHROME_BROWSER_VIEWS_EDIT_KEYWORD_CONTROLLER_H_
#include <Windows.h>
@@ -68,8 +68,9 @@ class EditKeywordController : public views::TextField::Controller,
// Create a Label containing the text with the specified message id.
views::Label* CreateLabel(int message_id);
- // Creates a text field with the specified text.
- views::TextField* CreateTextField(const std::wstring& text);
+ // Creates a text field with the specified text. If |lowercase| is true, the
+ // textfield is configured to map all input to lower case.
+ views::TextField* CreateTextField(const std::wstring& text, bool lowercase);
// Returns true if the currently input URL is valid. The URL is valid if it
// contains no search terms and is a valid url, or if it contains a search
@@ -128,7 +129,7 @@ class EditKeywordController : public views::TextField::Controller,
views::ImageView* keyword_iv_;
views::ImageView* url_iv_;
- DISALLOW_EVIL_CONSTRUCTORS(EditKeywordController);
+ DISALLOW_COPY_AND_ASSIGN(EditKeywordController);
};
-#endif // CHROME_BROWSER_VIEWS_EDIT_KEYWORD_CONTROLLER_H__
+#endif // CHROME_BROWSER_VIEWS_EDIT_KEYWORD_CONTROLLER_H_
diff --git a/chrome/views/text_field.cc b/chrome/views/text_field.cc
index 072ff76..24fdc5a 100644
--- a/chrome/views/text_field.cc
+++ b/chrome/views/text_field.cc
@@ -269,6 +269,11 @@ TextField::Edit::Edit(TextField* parent, bool draw_border)
RECT r = {0, 0, parent_->width(), parent_->height()};
Create(parent_->GetWidget()->GetHWND(), r, NULL, style, ex_style);
+ if (parent->GetStyle() & TextField::STYLE_LOWERCASE) {
+ DCHECK((parent->GetStyle() & TextField::STYLE_PASSWORD) == 0);
+ SetEditStyle(SES_LOWERCASE, SES_LOWERCASE);
+ }
+
// Set up the text_object_model_.
CComPtr<IRichEditOle> ole_interface;
ole_interface.Attach(GetOleInterface());
@@ -302,11 +307,12 @@ std::wstring TextField::Edit::GetText() const {
void TextField::Edit::SetText(const std::wstring& text) {
// Adjusting the string direction before setting the text in order to make
// sure both RTL and LTR strings are displayed properly.
- std::wstring localized_text;
- if (l10n_util::AdjustStringForLocaleDirection(text, &localized_text))
- SetWindowText(localized_text.c_str());
- else
- SetWindowText(text.c_str());
+ std::wstring text_to_set;
+ if (!l10n_util::AdjustStringForLocaleDirection(text, &text_to_set))
+ text_to_set = text;
+ if (parent_->GetStyle() & STYLE_LOWERCASE)
+ text_to_set = l10n_util::ToLower(text_to_set);
+ SetWindowText(text_to_set.c_str());
}
std::wstring TextField::Edit::GetSelectedText() const {
@@ -739,7 +745,9 @@ void TextField::Edit::OnPaste() {
std::wstring clipboard_str;
clipboard->ReadText(&clipboard_str);
if (!clipboard_str.empty()) {
- const std::wstring collapsed(CollapseWhitespace(clipboard_str, false));
+ std::wstring collapsed(CollapseWhitespace(clipboard_str, false));
+ if (parent_->GetStyle() & STYLE_LOWERCASE)
+ collapsed = l10n_util::ToLower(collapsed);
ReplaceSel(collapsed.c_str(), true);
}
}
diff --git a/chrome/views/text_field.h b/chrome/views/text_field.h
index 6d75e3b..4fa876c 100644
--- a/chrome/views/text_field.h
+++ b/chrome/views/text_field.h
@@ -39,7 +39,8 @@ class TextField : public View {
enum StyleFlags {
STYLE_DEFAULT = 0,
STYLE_PASSWORD = 1<<0,
- STYLE_MULTILINE = 1<<1
+ STYLE_MULTILINE = 1<<1,
+ STYLE_LOWERCASE = 1<<2
};
TextField::TextField()