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/i18n/case_conversion.h" | 11 #include "base/i18n/case_conversion.h" |
11 #include "base/metrics/field_trial.h" | 12 #include "base/metrics/field_trial.h" |
| 13 #include "base/metrics/field_trial_params.h" |
| 14 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_piece.h" | 15 #include "base/strings/string_piece.h" |
13 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
14 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
15 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
16 #include "build/build_config.h" | 19 #include "build/build_config.h" |
17 #include "components/autofill/core/common/autofill_switches.h" | 20 #include "components/autofill/core/common/autofill_switches.h" |
18 | 21 |
19 namespace autofill { | 22 namespace autofill { |
20 | 23 |
| 24 const base::Feature kAutofillKeyboardAccessory{ |
| 25 "AutofillKeyboardAccessory", base::FEATURE_DISABLED_BY_DEFAULT}; |
| 26 const char kAutofillKeyboardAccessoryAnimationDurationKey[] = |
| 27 "animation_duration_millis"; |
| 28 const char kAutofillKeyboardAccessoryLimitLabelWidthKey[] = |
| 29 "should_limit_label_width"; |
| 30 const char kAutofillKeyboardAccessoryHintKey[] = |
| 31 "is_hint_shown_before_suggestion"; |
| 32 |
21 namespace { | 33 namespace { |
22 | 34 |
23 const char kSplitCharacters[] = " .,-_@"; | 35 const char kSplitCharacters[] = " .,-_@"; |
24 | 36 |
25 template <typename Char> | 37 template <typename Char> |
26 struct Compare : base::CaseInsensitiveCompareASCII<Char> { | 38 struct Compare : base::CaseInsensitiveCompareASCII<Char> { |
27 explicit Compare(bool case_sensitive) : case_sensitive_(case_sensitive) {} | 39 explicit Compare(bool case_sensitive) : case_sensitive_(case_sensitive) {} |
28 bool operator()(Char x, Char y) const { | 40 bool operator()(Char x, Char y) const { |
29 return case_sensitive_ ? (x == y) | 41 return case_sensitive_ ? (x == y) |
30 : base::CaseInsensitiveCompareASCII<Char>:: | 42 : base::CaseInsensitiveCompareASCII<Char>:: |
(...skipping 11 matching lines...) Expand all Loading... |
42 switches::kEnableSuggestionsWithSubstringMatch); | 54 switches::kEnableSuggestionsWithSubstringMatch); |
43 } | 55 } |
44 | 56 |
45 bool IsShowAutofillSignaturesEnabled() { | 57 bool IsShowAutofillSignaturesEnabled() { |
46 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 58 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
47 switches::kShowAutofillSignatures); | 59 switches::kShowAutofillSignatures); |
48 } | 60 } |
49 | 61 |
50 bool IsKeyboardAccessoryEnabled() { | 62 bool IsKeyboardAccessoryEnabled() { |
51 #if defined(OS_ANDROID) | 63 #if defined(OS_ANDROID) |
52 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 64 return base::FeatureList::IsEnabled(kAutofillKeyboardAccessory); |
53 switches::kEnableAccessorySuggestionView) || | |
54 (base::FieldTrialList::FindFullName("AutofillKeyboardAccessory") == | |
55 "Enabled" && | |
56 !base::CommandLine::ForCurrentProcess()->HasSwitch( | |
57 switches::kDisableAccessorySuggestionView)); | |
58 #else // !defined(OS_ANDROID) | 65 #else // !defined(OS_ANDROID) |
59 return false; | 66 return false; |
60 #endif | 67 #endif |
61 } | 68 } |
| 69 |
| 70 unsigned int GetKeyboardAccessoryAnimationDuration() { |
| 71 #if defined(OS_ANDROID) |
| 72 return base::GetFieldTrialParamByFeatureAsInt( |
| 73 kAutofillKeyboardAccessory, |
| 74 kAutofillKeyboardAccessoryAnimationDurationKey, 0); |
| 75 #else // !defined(OS_ANDROID) |
| 76 NOTREACHED(); |
| 77 return 0; |
| 78 #endif |
| 79 } |
| 80 |
| 81 bool ShouldLimitKeyboardAccessorySuggestionLabelWidth() { |
| 82 #if defined(OS_ANDROID) |
| 83 return base::GetFieldTrialParamByFeatureAsBool( |
| 84 kAutofillKeyboardAccessory, kAutofillKeyboardAccessoryLimitLabelWidthKey, |
| 85 false); |
| 86 #else // !defined(OS_ANDROID) |
| 87 NOTREACHED(); |
| 88 return false; |
| 89 #endif |
| 90 } |
| 91 |
| 92 bool IsHintEnabledInKeyboardAccessory() { |
| 93 #if defined(OS_ANDROID) |
| 94 return base::GetFieldTrialParamByFeatureAsBool( |
| 95 kAutofillKeyboardAccessory, kAutofillKeyboardAccessoryHintKey, false); |
| 96 #else // !defined(OS_ANDROID) |
| 97 NOTREACHED(); |
| 98 return false; |
| 99 #endif |
| 100 } |
62 | 101 |
63 bool FieldIsSuggestionSubstringStartingOnTokenBoundary( | 102 bool FieldIsSuggestionSubstringStartingOnTokenBoundary( |
64 const base::string16& suggestion, | 103 const base::string16& suggestion, |
65 const base::string16& field_contents, | 104 const base::string16& field_contents, |
66 bool case_sensitive) { | 105 bool case_sensitive) { |
67 if (!IsFeatureSubstringMatchEnabled()) { | 106 if (!IsFeatureSubstringMatchEnabled()) { |
68 return base::StartsWith(suggestion, field_contents, | 107 return base::StartsWith(suggestion, field_contents, |
69 case_sensitive | 108 case_sensitive |
70 ? base::CompareCase::SENSITIVE | 109 ? base::CompareCase::SENSITIVE |
71 : base::CompareCase::INSENSITIVE_ASCII); | 110 : base::CompareCase::INSENSITIVE_ASCII); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 } | 176 } |
138 | 177 |
139 std::vector<std::string> LowercaseAndTokenizeAttributeString( | 178 std::vector<std::string> LowercaseAndTokenizeAttributeString( |
140 const std::string& attribute) { | 179 const std::string& attribute) { |
141 return base::SplitString(base::ToLowerASCII(attribute), | 180 return base::SplitString(base::ToLowerASCII(attribute), |
142 base::kWhitespaceASCII, base::TRIM_WHITESPACE, | 181 base::kWhitespaceASCII, base::TRIM_WHITESPACE, |
143 base::SPLIT_WANT_NONEMPTY); | 182 base::SPLIT_WANT_NONEMPTY); |
144 } | 183 } |
145 | 184 |
146 } // namespace autofill | 185 } // namespace autofill |
OLD | NEW |