Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: components/autofill/core/common/autofill_util.cc

Issue 2874933008: Adds animation as feature variation to keyboard accessory. (Closed)
Patch Set: Uses only 1 Animator object. Removes redundant call to invalidate. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/strings/string_number_conversions.h"
12 #include "base/strings/string_piece.h" 14 #include "base/strings/string_piece.h"
13 #include "base/strings/string_split.h" 15 #include "base/strings/string_split.h"
14 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
15 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
16 #include "build/build_config.h" 18 #include "build/build_config.h"
17 #include "components/autofill/core/common/autofill_switches.h" 19 #include "components/autofill/core/common/autofill_switches.h"
20 #include "components/variations/variations_associated_data.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
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 unsigned int value;
73 const std::string param_value = variations::GetVariationParamValueByFeature(
Alexei Svitkine (slow) 2017/05/19 19:57:22 Please use base/metrics/field_trial_params.h APIs
csashi 2017/05/19 20:41:22 Done.
74 kAutofillKeyboardAccessory,
75 kAutofillKeyboardAccessoryAnimationDurationKey);
76 if (!param_value.empty() && base::StringToUint(param_value, &value))
77 return value;
78 return 0;
79 #else // !defined(OS_ANDROID)
80 NOTREACHED();
81 return 0;
82 #endif
83 }
84
85 bool ShouldLimitKeyboardAccessorySuggestionLabelWidth() {
86 #if defined(OS_ANDROID)
87 const std::string param_value = variations::GetVariationParamValueByFeature(
88 kAutofillKeyboardAccessory, kAutofillKeyboardAccessoryLimitLabelWidthKey);
89 return param_value == "true";
90 #else // !defined(OS_ANDROID)
91 NOTREACHED();
92 return false;
93 #endif
94 }
95
96 bool IsHintEnabledInKeyboardAccessory() {
97 #if defined(OS_ANDROID)
98 const std::string param_value = variations::GetVariationParamValueByFeature(
99 kAutofillKeyboardAccessory, kAutofillKeyboardAccessoryHintKey);
100 return param_value == "true";
101 #else // !defined(OS_ANDROID)
102 NOTREACHED();
103 return false;
104 #endif
105 }
62 106
63 bool FieldIsSuggestionSubstringStartingOnTokenBoundary( 107 bool FieldIsSuggestionSubstringStartingOnTokenBoundary(
64 const base::string16& suggestion, 108 const base::string16& suggestion,
65 const base::string16& field_contents, 109 const base::string16& field_contents,
66 bool case_sensitive) { 110 bool case_sensitive) {
67 if (!IsFeatureSubstringMatchEnabled()) { 111 if (!IsFeatureSubstringMatchEnabled()) {
68 return base::StartsWith(suggestion, field_contents, 112 return base::StartsWith(suggestion, field_contents,
69 case_sensitive 113 case_sensitive
70 ? base::CompareCase::SENSITIVE 114 ? base::CompareCase::SENSITIVE
71 : base::CompareCase::INSENSITIVE_ASCII); 115 : base::CompareCase::INSENSITIVE_ASCII);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 } 181 }
138 182
139 std::vector<std::string> LowercaseAndTokenizeAttributeString( 183 std::vector<std::string> LowercaseAndTokenizeAttributeString(
140 const std::string& attribute) { 184 const std::string& attribute) {
141 return base::SplitString(base::ToLowerASCII(attribute), 185 return base::SplitString(base::ToLowerASCII(attribute),
142 base::kWhitespaceASCII, base::TRIM_WHITESPACE, 186 base::kWhitespaceASCII, base::TRIM_WHITESPACE,
143 base::SPLIT_WANT_NONEMPTY); 187 base::SPLIT_WANT_NONEMPTY);
144 } 188 }
145 189
146 } // namespace autofill 190 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/common/autofill_util.h ('k') | components/resources/autofill_scaled_resources.grdp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698