Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/autofill/core/common/autofill_util.h" | 5 #include "components/autofill/core/common/autofill_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/feature_list.h" | 10 #include "base/feature_list.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 "animation_duration_millis"; | 27 "animation_duration_millis"; |
| 28 const char kAutofillKeyboardAccessoryLimitLabelWidthKey[] = | 28 const char kAutofillKeyboardAccessoryLimitLabelWidthKey[] = |
| 29 "should_limit_label_width"; | 29 "should_limit_label_width"; |
| 30 const char kAutofillKeyboardAccessoryHintKey[] = | 30 const char kAutofillKeyboardAccessoryHintKey[] = |
| 31 "is_hint_shown_before_suggestion"; | 31 "is_hint_shown_before_suggestion"; |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 const char kSplitCharacters[] = " .,-_@"; | 35 const char kSplitCharacters[] = " .,-_@"; |
| 36 | 36 |
| 37 const char kPrefixMatchTockens[] = "@"; | |
| 38 | |
| 37 template <typename Char> | 39 template <typename Char> |
| 38 struct Compare : base::CaseInsensitiveCompareASCII<Char> { | 40 struct Compare : base::CaseInsensitiveCompareASCII<Char> { |
| 39 explicit Compare(bool case_sensitive) : case_sensitive_(case_sensitive) {} | 41 explicit Compare(bool case_sensitive) : case_sensitive_(case_sensitive) {} |
| 40 bool operator()(Char x, Char y) const { | 42 bool operator()(Char x, Char y) const { |
| 41 return case_sensitive_ ? (x == y) | 43 return case_sensitive_ ? (x == y) |
| 42 : base::CaseInsensitiveCompareASCII<Char>:: | 44 : base::CaseInsensitiveCompareASCII<Char>:: |
| 43 operator()(x, y); | 45 operator()(x, y); |
| 44 } | 46 } |
| 45 | 47 |
| 46 private: | 48 private: |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 bool IsHintEnabledInKeyboardAccessory() { | 94 bool IsHintEnabledInKeyboardAccessory() { |
| 93 #if defined(OS_ANDROID) | 95 #if defined(OS_ANDROID) |
| 94 return base::GetFieldTrialParamByFeatureAsBool( | 96 return base::GetFieldTrialParamByFeatureAsBool( |
| 95 kAutofillKeyboardAccessory, kAutofillKeyboardAccessoryHintKey, false); | 97 kAutofillKeyboardAccessory, kAutofillKeyboardAccessoryHintKey, false); |
| 96 #else // !defined(OS_ANDROID) | 98 #else // !defined(OS_ANDROID) |
| 97 NOTREACHED(); | 99 NOTREACHED(); |
| 98 return false; | 100 return false; |
| 99 #endif | 101 #endif |
| 100 } | 102 } |
| 101 | 103 |
| 102 bool FieldIsSuggestionSubstringStartingOnTokenBoundary( | 104 bool IsSubstringStartingOnTokenBoundary(const base::string16& suggestion, |
| 103 const base::string16& suggestion, | 105 const base::string16& field_contents, |
| 104 const base::string16& field_contents, | 106 bool case_sensitive) { |
| 105 bool case_sensitive) { | |
| 106 if (!IsFeatureSubstringMatchEnabled()) { | 107 if (!IsFeatureSubstringMatchEnabled()) { |
| 107 return base::StartsWith(suggestion, field_contents, | 108 return base::StartsWith(suggestion, field_contents, |
| 108 case_sensitive | 109 case_sensitive |
| 109 ? base::CompareCase::SENSITIVE | 110 ? base::CompareCase::SENSITIVE |
| 110 : base::CompareCase::INSENSITIVE_ASCII); | 111 : base::CompareCase::INSENSITIVE_ASCII); |
| 111 } | 112 } |
| 112 | 113 |
| 113 return suggestion.length() >= field_contents.length() && | 114 return suggestion.length() >= field_contents.length() && |
| 114 GetTextSelectionStart(suggestion, field_contents, case_sensitive) != | 115 GetTextSelectionStart(suggestion, field_contents, case_sensitive) != |
| 115 base::string16::npos; | 116 base::string16::npos; |
| 116 } | 117 } |
| 117 | 118 |
| 119 bool IsPrefixStartingOnTokenBoundary(const base::string16& full_string, | |
| 120 const base::string16& prefix, | |
| 121 bool case_sensitive) { | |
| 122 if (base::StartsWith(full_string, prefix, | |
| 123 case_sensitive ? base::CompareCase::SENSITIVE | |
| 124 : base::CompareCase::INSENSITIVE_ASCII)) { | |
| 125 if (full_string.size() > prefix.size()) { | |
| 126 char token = full_string[prefix.size()]; | |
| 127 | |
| 128 const std::string tokens(kPrefixMatchTockens); | |
|
dvadym
2017/06/01 12:15:56
Since kPrefixMatchTockens is array only with 1 ele
| |
| 129 return tokens.find(token) != std::string::npos; | |
| 130 } | |
| 131 } | |
| 132 return false; | |
| 133 } | |
| 134 | |
| 118 size_t GetTextSelectionStart(const base::string16& suggestion, | 135 size_t GetTextSelectionStart(const base::string16& suggestion, |
| 119 const base::string16& field_contents, | 136 const base::string16& field_contents, |
| 120 bool case_sensitive) { | 137 bool case_sensitive) { |
| 121 const base::string16 kSplitChars = base::ASCIIToUTF16(kSplitCharacters); | 138 const base::string16 kSplitChars = base::ASCIIToUTF16(kSplitCharacters); |
| 122 | 139 |
| 123 // Loop until we find either the |field_contents| is a prefix of |suggestion| | 140 // Loop until we find either the |field_contents| is a prefix of |suggestion| |
| 124 // or character right before the match is one of the splitting characters. | 141 // or character right before the match is one of the splitting characters. |
| 125 for (base::string16::const_iterator it = suggestion.begin(); | 142 for (base::string16::const_iterator it = suggestion.begin(); |
| 126 (it = std::search( | 143 (it = std::search( |
| 127 it, suggestion.end(), field_contents.begin(), field_contents.end(), | 144 it, suggestion.end(), field_contents.begin(), field_contents.end(), |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 } | 193 } |
| 177 | 194 |
| 178 std::vector<std::string> LowercaseAndTokenizeAttributeString( | 195 std::vector<std::string> LowercaseAndTokenizeAttributeString( |
| 179 const std::string& attribute) { | 196 const std::string& attribute) { |
| 180 return base::SplitString(base::ToLowerASCII(attribute), | 197 return base::SplitString(base::ToLowerASCII(attribute), |
| 181 base::kWhitespaceASCII, base::TRIM_WHITESPACE, | 198 base::kWhitespaceASCII, base::TRIM_WHITESPACE, |
| 182 base::SPLIT_WANT_NONEMPTY); | 199 base::SPLIT_WANT_NONEMPTY); |
| 183 } | 200 } |
| 184 | 201 |
| 185 } // namespace autofill | 202 } // namespace autofill |
| OLD | NEW |