summaryrefslogtreecommitdiffstats
path: root/views/controls
diff options
context:
space:
mode:
authorbryeung@chromium.org <bryeung@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-06 14:55:13 +0000
committerbryeung@chromium.org <bryeung@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-06 14:55:13 +0000
commita9a0417e2b621c778b0f1a8df7b424a32b284041 (patch)
tree1caeb4d3bf2c6708a8340f29924c8dbe61661973 /views/controls
parentbda863e986f517e04fbec41cf6034d483fc03f68 (diff)
downloadchromium_src-a9a0417e2b621c778b0f1a8df7b424a32b284041.zip
chromium_src-a9a0417e2b621c778b0f1a8df7b424a32b284041.tar.gz
chromium_src-a9a0417e2b621c778b0f1a8df7b424a32b284041.tar.bz2
Identify the omnibox as a URL field.
Although the omnibox is not strictly a URL field, for the purposes of TOUCH_UI, we would prefer to show the URL-friendly keyboard for the omnibox instead of a plain-text keyboard. BUG=none TEST=updated unittest Review URL: http://codereview.chromium.org/7826039 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99737 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls')
-rw-r--r--views/controls/textfield/native_textfield_views.cc6
-rw-r--r--views/controls/textfield/native_textfield_views_unittest.cc54
-rw-r--r--views/controls/textfield/textfield.cc30
-rw-r--r--views/controls/textfield/textfield.h11
4 files changed, 92 insertions, 9 deletions
diff --git a/views/controls/textfield/native_textfield_views.cc b/views/controls/textfield/native_textfield_views.cc
index 47ff302..9fad4c4 100644
--- a/views/controls/textfield/native_textfield_views.cc
+++ b/views/controls/textfield/native_textfield_views.cc
@@ -700,11 +700,7 @@ void NativeTextfieldViews::InsertChar(char16 ch, int flags) {
}
ui::TextInputType NativeTextfieldViews::GetTextInputType() {
- if (textfield_->read_only() || !textfield_->IsEnabled())
- return ui::TEXT_INPUT_TYPE_NONE;
- else if (textfield_->IsPassword())
- return ui::TEXT_INPUT_TYPE_PASSWORD;
- return ui::TEXT_INPUT_TYPE_TEXT;
+ return textfield_->GetTextInputType();
}
gfx::Rect NativeTextfieldViews::GetCaretBounds() {
diff --git a/views/controls/textfield/native_textfield_views_unittest.cc b/views/controls/textfield/native_textfield_views_unittest.cc
index 54844f3..ea8e023 100644
--- a/views/controls/textfield/native_textfield_views_unittest.cc
+++ b/views/controls/textfield/native_textfield_views_unittest.cc
@@ -225,6 +225,11 @@ class NativeTextfieldViewsTest : public ViewsTestBase,
gfx::SelectionModel(cursor_pos), false).x();
}
+ // Wrap for visibility in test classes.
+ ui::TextInputType GetTextInputType() {
+ return textfield_view_->GetTextInputType();
+ }
+
// We need widget to populate wrapper class.
Widget* widget_;
@@ -399,6 +404,8 @@ TEST_F(NativeTextfieldViewsTest, InsertionDeletionTest) {
TEST_F(NativeTextfieldViewsTest, PasswordTest) {
InitTextfield(Textfield::STYLE_PASSWORD);
+ EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType());
+
last_contents_.clear();
textfield_->SetText(ASCIIToUTF16("my password"));
// Just to make sure the text() and callback returns
@@ -407,6 +414,53 @@ TEST_F(NativeTextfieldViewsTest, PasswordTest) {
EXPECT_TRUE(last_contents_.empty());
}
+TEST_F(NativeTextfieldViewsTest, InputTypeSetsPassword) {
+ InitTextfield(Textfield::STYLE_DEFAULT);
+
+ // Defaults to TEXT
+ EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType());
+
+ // Setting to passwords also sets password state of textfield.
+ textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
+ EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType());
+ EXPECT_TRUE(textfield_->IsPassword());
+}
+
+TEST_F(NativeTextfieldViewsTest, PasswordSetsInputType) {
+ InitTextfield(Textfield::STYLE_DEFAULT);
+
+ // Defaults to TEXT
+ EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType());
+
+ textfield_->SetPassword(true);
+ EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType());
+
+ textfield_->SetPassword(false);
+ EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType());
+}
+
+TEST_F(NativeTextfieldViewsTest, TextInputType) {
+ InitTextfield(Textfield::STYLE_DEFAULT);
+
+ // Defaults to TEXT
+ EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType());
+
+ // And can be set.
+ textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_URL);
+ EXPECT_EQ(ui::TEXT_INPUT_TYPE_URL, GetTextInputType());
+
+ // Readonly textfields have type NONE
+ textfield_->SetReadOnly(true);
+ EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, GetTextInputType());
+
+ textfield_->SetReadOnly(false);
+ EXPECT_EQ(ui::TEXT_INPUT_TYPE_URL, GetTextInputType());
+
+ // As do disabled textfields
+ textfield_->SetEnabled(false);
+ EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, GetTextInputType());
+}
+
TEST_F(NativeTextfieldViewsTest, OnKeyPressReturnValueTest) {
InitTextfield(Textfield::STYLE_DEFAULT);
diff --git a/views/controls/textfield/textfield.cc b/views/controls/textfield/textfield.cc
index 8061126..c422a2c 100644
--- a/views/controls/textfield/textfield.cc
+++ b/views/controls/textfield/textfield.cc
@@ -13,6 +13,7 @@
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "ui/base/accessibility/accessible_view_state.h"
+#include "ui/base/ime/text_input_type.h"
#include "ui/base/keycodes/keyboard_codes.h"
#include "ui/base/range/range.h"
#include "ui/gfx/insets.h"
@@ -53,7 +54,8 @@ Textfield::Textfield()
use_default_background_color_(true),
initialized_(false),
horizontal_margins_were_set_(false),
- vertical_margins_were_set_(false) {
+ vertical_margins_were_set_(false),
+ text_input_type_(ui::TEXT_INPUT_TYPE_TEXT) {
set_focusable(true);
}
@@ -70,8 +72,11 @@ Textfield::Textfield(StyleFlags style)
use_default_background_color_(true),
initialized_(false),
horizontal_margins_were_set_(false),
- vertical_margins_were_set_(false) {
+ vertical_margins_were_set_(false),
+ text_input_type_(ui::TEXT_INPUT_TYPE_TEXT) {
set_focusable(true);
+ if (IsPassword())
+ SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
}
Textfield::~Textfield() {
@@ -99,14 +104,31 @@ bool Textfield::IsPassword() const {
}
void Textfield::SetPassword(bool password) {
- if (password)
+ if (password) {
style_ = static_cast<StyleFlags>(style_ | STYLE_PASSWORD);
- else
+ SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
+ } else {
style_ = static_cast<StyleFlags>(style_ & ~STYLE_PASSWORD);
+ SetTextInputType(ui::TEXT_INPUT_TYPE_TEXT);
+ }
if (native_wrapper_)
native_wrapper_->UpdateIsPassword();
}
+
+ui::TextInputType Textfield::GetTextInputType() const {
+ if (read_only() || !IsEnabled())
+ return ui::TEXT_INPUT_TYPE_NONE;
+ return text_input_type_;
+}
+
+void Textfield::SetTextInputType(ui::TextInputType type) {
+ text_input_type_ = type;
+ bool should_be_password = type == ui::TEXT_INPUT_TYPE_PASSWORD;
+ if (IsPassword() != should_be_password)
+ SetPassword(should_be_password);
+}
+
void Textfield::SetText(const string16& text) {
text_ = text;
if (native_wrapper_)
diff --git a/views/controls/textfield/textfield.h b/views/controls/textfield/textfield.h
index ad0198c..722a2c7 100644
--- a/views/controls/textfield/textfield.h
+++ b/views/controls/textfield/textfield.h
@@ -18,6 +18,7 @@
#include "base/compiler_specific.h"
#include "base/string16.h"
#include "third_party/skia/include/core/SkColor.h"
+#include "ui/base/ime/text_input_type.h"
#include "ui/base/keycodes/keyboard_codes.h"
#include "ui/gfx/font.h"
#include "ui/gfx/native_widget_types.h"
@@ -66,9 +67,16 @@ class VIEWS_EXPORT Textfield : public View {
void SetReadOnly(bool read_only);
// Gets/Sets whether or not this Textfield is a password field.
+ // TODO(bryeung): Currently this is only used in
+ // chrome/browser/chromeos/options/wifi_config_view.cc, which is being
+ // converted to WebUI. Please remove this when that happens.
bool IsPassword() const;
void SetPassword(bool password);
+ // Gets/Sets the input type of this textfield.
+ ui::TextInputType GetTextInputType() const;
+ void SetTextInputType(ui::TextInputType type);
+
// Gets/Sets the text currently displayed in the Textfield.
const string16& text() const { return text_; }
@@ -291,6 +299,9 @@ class VIEWS_EXPORT Textfield : public View {
// The accessible name of the text field.
string16 accessible_name_;
+ // The input type of this text field.
+ ui::TextInputType text_input_type_;
+
DISALLOW_COPY_AND_ASSIGN(Textfield);
};