summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-05 19:28:08 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-05 19:28:08 +0000
commit89ac46c97e6a3b2f2726bd11d52824d27ee26a24 (patch)
treec976f9689ff7fabd3c3e54e06ed051d1bd4544c7 /base
parent9ac105a1023bc696e619e5714c524e1a3ffdc2ef (diff)
downloadchromium_src-89ac46c97e6a3b2f2726bd11d52824d27ee26a24.zip
chromium_src-89ac46c97e6a3b2f2726bd11d52824d27ee26a24.tar.gz
chromium_src-89ac46c97e6a3b2f2726bd11d52824d27ee26a24.tar.bz2
This CL adds the autofill UI in forms.
When the user types text in a text field in a form, the renderer queries the browser for suggestion based on the entered text and displays the suggestions in a popup. Listeners are set on the form text field in a similar fashion than for password save. The popup showing the suggestion uses the same mechanism as the select popup. Note that a difference between the select and the autofill popup is that the autofill should not take focus, so the page still has focus and the user can still type in while it shows. The creation of the render widget was modified for that purpose so we can specify the popup should not be focused when shown. Review URL: http://codereview.chromium.org/8885 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4804 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/string_util.cc13
-rw-r--r--base/string_util.h4
-rw-r--r--base/string_util_unittest.cc26
3 files changed, 37 insertions, 6 deletions
diff --git a/base/string_util.cc b/base/string_util.cc
index 5fa2f75..4c27693 100644
--- a/base/string_util.cc
+++ b/base/string_util.cc
@@ -659,6 +659,19 @@ bool StartsWithASCII(const std::string& str,
return base::strncasecmp(str.c_str(), search.c_str(), search.length()) == 0;
}
+bool StartsWith(const std::wstring& str,
+ const std::wstring& search,
+ bool case_sensitive) {
+ if (case_sensitive)
+ return str.compare(0, search.length(), search) == 0;
+ else {
+ if (search.size() > str.size())
+ return false;
+ return std::equal(search.begin(), search.end(), str.begin(),
+ CaseInsensitiveCompare<wchar_t>());
+ }
+}
+
DataUnits GetByteDisplayUnits(int64 bytes) {
// The byte thresholds at which we display amounts. A byte count is displayed
// in unit U when kUnitThresholds[U] <= bytes < kUnitThresholds[U+1].
diff --git a/base/string_util.h b/base/string_util.h
index 981cd30..d62e9b0 100644
--- a/base/string_util.h
+++ b/base/string_util.h
@@ -274,10 +274,12 @@ bool LowerCaseEqualsASCII(const wchar_t* a_begin,
const char* b);
// Returns true if str starts with search, or false otherwise.
-// This only works on ASCII strings.
bool StartsWithASCII(const std::string& str,
const std::string& search,
bool case_sensitive);
+bool StartsWith(const std::wstring& str,
+ const std::wstring& search,
+ bool case_sensitive);
// Determines the type of ASCII character, independent of locale (the C
// library versions will change based on locale).
diff --git a/base/string_util_unittest.cc b/base/string_util_unittest.cc
index 25f43c6..9a7f40f 100644
--- a/base/string_util_unittest.cc
+++ b/base/string_util_unittest.cc
@@ -1219,11 +1219,27 @@ TEST(StringUtilTest, SplitString) {
}
TEST(StringUtilTest, StartsWith) {
- EXPECT_EQ(true, StartsWithASCII("javascript:url", "javascript", true));
- EXPECT_EQ(true, StartsWithASCII("javascript:url", "javascript", false));
- EXPECT_EQ(true, StartsWithASCII("JavaScript:url", "javascript", false));
- EXPECT_EQ(false, StartsWithASCII("java", "javascript", true));
- EXPECT_EQ(false, StartsWithASCII("java", "javascript", false));
+ EXPECT_TRUE(StartsWithASCII("javascript:url", "javascript", true));
+ EXPECT_FALSE(StartsWithASCII("JavaScript:url", "javascript", true));
+ EXPECT_TRUE(StartsWithASCII("javascript:url", "javascript", false));
+ EXPECT_TRUE(StartsWithASCII("JavaScript:url", "javascript", false));
+ EXPECT_FALSE(StartsWithASCII("java", "javascript", true));
+ EXPECT_FALSE(StartsWithASCII("java", "javascript", false));
+ EXPECT_FALSE(StartsWithASCII("", "javascript", false));
+ EXPECT_FALSE(StartsWithASCII("", "javascript", true));
+ EXPECT_TRUE(StartsWithASCII("java", "", false));
+ EXPECT_TRUE(StartsWithASCII("java", "", true));
+
+ EXPECT_TRUE(StartsWith(L"javascript:url", L"javascript", true));
+ EXPECT_FALSE(StartsWith(L"JavaScript:url", L"javascript", true));
+ EXPECT_TRUE(StartsWith(L"javascript:url", L"javascript", false));
+ EXPECT_TRUE(StartsWith(L"JavaScript:url", L"javascript", false));
+ EXPECT_FALSE(StartsWith(L"java", L"javascript", true));
+ EXPECT_FALSE(StartsWith(L"java", L"javascript", false));
+ EXPECT_FALSE(StartsWith(L"", L"javascript", false));
+ EXPECT_FALSE(StartsWith(L"", L"javascript", true));
+ EXPECT_TRUE(StartsWith(L"java", L"", false));
+ EXPECT_TRUE(StartsWith(L"java", L"", true));
}
TEST(StringUtilTest, GetStringFWithOffsets) {