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

Side by Side Diff: chrome/browser/ui/autofill/autofill_popup_layout_model.cc

Issue 2531223003: Expanded Autofill Credit Card Popup Layout Experiment in Android. (Closed)
Patch Set: Adds clarification for SkColor Created 4 years 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 (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 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 "chrome/browser/ui/autofill/autofill_popup_layout_model.h" 5 #include "chrome/browser/ui/autofill/autofill_popup_layout_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/ui/autofill/autofill_popup_view.h" 11 #include "chrome/browser/ui/autofill/autofill_popup_view.h"
12 #include "chrome/browser/ui/autofill/popup_constants.h" 12 #include "chrome/browser/ui/autofill/popup_constants.h"
13 #include "components/autofill/core/browser/autofill_experiments.h"
13 #include "components/autofill/core/browser/popup_item_ids.h" 14 #include "components/autofill/core/browser/popup_item_ids.h"
14 #include "components/autofill/core/browser/suggestion.h" 15 #include "components/autofill/core/browser/suggestion.h"
15 #include "components/autofill/core/common/autofill_util.h" 16 #include "components/autofill/core/common/autofill_util.h"
16 #include "components/grit/components_scaled_resources.h" 17 #include "components/grit/components_scaled_resources.h"
18 #include "third_party/skia/include/core/SkColor.h"
17 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/gfx/color_palette.h" 20 #include "ui/gfx/color_palette.h"
19 #include "ui/gfx/font_list.h" 21 #include "ui/gfx/font_list.h"
20 #include "ui/gfx/geometry/rect_conversions.h" 22 #include "ui/gfx/geometry/rect_conversions.h"
21 23
22 namespace autofill { 24 namespace autofill {
23 25
24 namespace { 26 namespace {
25 27
26 // The vertical height of each row in pixels. 28 // The vertical height of each row in pixels.
27 const size_t kRowHeight = 24; 29 const size_t kRowHeight = 24;
28 30
29 // The vertical height of a separator in pixels. 31 // The vertical height of a separator in pixels.
30 const size_t kSeparatorHeight = 1; 32 const size_t kSeparatorHeight = 1;
31 33
32 #if !defined(OS_ANDROID) 34 #if !defined(OS_ANDROID)
33 // Size difference between the normal font and the smaller font, in pixels. 35 // Size difference between the normal font and the smaller font, in pixels.
34 const int kSmallerFontSizeDelta = -1; 36 const int kSmallerFontSizeDelta = -1;
35 #endif 37 #endif
36 38
37 const struct { 39 struct data_resource {
38 const char* name; 40 const char* name;
39 int id; 41 int id;
40 } kDataResources[] = { 42 };
43
44 static const data_resource kDataResources[] = {
41 {"americanExpressCC", IDR_AUTOFILL_CC_AMEX}, 45 {"americanExpressCC", IDR_AUTOFILL_CC_AMEX},
42 {"dinersCC", IDR_AUTOFILL_CC_GENERIC}, 46 {"dinersCC", IDR_AUTOFILL_CC_GENERIC},
43 {"discoverCC", IDR_AUTOFILL_CC_DISCOVER}, 47 {"discoverCC", IDR_AUTOFILL_CC_DISCOVER},
44 {"genericCC", IDR_AUTOFILL_CC_GENERIC}, 48 {"genericCC", IDR_AUTOFILL_CC_GENERIC},
45 {"jcbCC", IDR_AUTOFILL_CC_GENERIC}, 49 {"jcbCC", IDR_AUTOFILL_CC_GENERIC},
46 {"masterCardCC", IDR_AUTOFILL_CC_MASTERCARD}, 50 {"masterCardCC", IDR_AUTOFILL_CC_MASTERCARD},
47 {"visaCC", IDR_AUTOFILL_CC_VISA}, 51 {"visaCC", IDR_AUTOFILL_CC_VISA},
48 #if defined(OS_ANDROID) 52 #if defined(OS_ANDROID)
49 {"scanCreditCardIcon", IDR_AUTOFILL_CC_SCAN_NEW}, 53 {"scanCreditCardIcon", IDR_AUTOFILL_CC_SCAN_NEW},
50 {"settings", IDR_AUTOFILL_SETTINGS}, 54 {"settings", IDR_AUTOFILL_SETTINGS},
51 #endif 55 #endif
52 }; 56 };
53 57
58 static const data_resource kLargeDataResources[] = {
59 {"americanExpressCC", IDR_AUTOFILL_LARGE_CC_AMEX},
60 {"dinersCC", IDR_AUTOFILL_LARGE_CC_GENERIC},
61 {"discoverCC", IDR_AUTOFILL_LARGE_CC_DISCOVER},
62 {"genericCC", IDR_AUTOFILL_LARGE_CC_GENERIC},
63 {"jcbCC", IDR_AUTOFILL_LARGE_CC_GENERIC},
64 {"masterCardCC", IDR_AUTOFILL_LARGE_CC_MASTERCARD},
65 {"visaCC", IDR_AUTOFILL_LARGE_CC_VISA},
66 #if defined(OS_ANDROID)
67 {"scanCreditCardIcon", IDR_AUTOFILL_CC_SCAN_NEW},
68 {"settings", IDR_AUTOFILL_SETTINGS},
69 #endif
70 };
71
54 int GetRowHeightFromId(int identifier) { 72 int GetRowHeightFromId(int identifier) {
55 if (identifier == POPUP_ITEM_ID_SEPARATOR) 73 if (identifier == POPUP_ITEM_ID_SEPARATOR)
56 return kSeparatorHeight; 74 return kSeparatorHeight;
57 75
58 return kRowHeight; 76 return kRowHeight;
59 } 77 }
60 78
61 } // namespace 79 } // namespace
62 80
63 AutofillPopupLayoutModel::AutofillPopupLayoutModel( 81 AutofillPopupLayoutModel::AutofillPopupLayoutModel(
64 AutofillPopupViewDelegate* delegate) 82 AutofillPopupViewDelegate* delegate, bool is_credit_card_field)
65 : delegate_(delegate) { 83 : delegate_(delegate), is_credit_card_field_(is_credit_card_field) {
66 #if !defined(OS_ANDROID) 84 #if !defined(OS_ANDROID)
67 smaller_font_list_ = 85 smaller_font_list_ =
68 normal_font_list_.DeriveWithSizeDelta(kSmallerFontSizeDelta); 86 normal_font_list_.DeriveWithSizeDelta(kSmallerFontSizeDelta);
69 bold_font_list_ = normal_font_list_.DeriveWithWeight(gfx::Font::Weight::BOLD); 87 bold_font_list_ = normal_font_list_.DeriveWithWeight(gfx::Font::Weight::BOLD);
70 #if defined(OS_MACOSX) 88 #if defined(OS_MACOSX)
71 // There is no italic version of the system font. 89 // There is no italic version of the system font.
72 warning_font_list_ = normal_font_list_; 90 warning_font_list_ = normal_font_list_;
73 #else 91 #else
74 warning_font_list_ = normal_font_list_.DeriveWithStyle(gfx::Font::ITALIC); 92 warning_font_list_ = normal_font_list_.DeriveWithStyle(gfx::Font::ITALIC);
75 #endif 93 #endif
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 } 236 }
219 237
220 return gfx::Rect(kPopupBorderThickness, top, 238 return gfx::Rect(kPopupBorderThickness, top,
221 popup_bounds_.width() - 2 * kPopupBorderThickness, 239 popup_bounds_.width() - 2 * kPopupBorderThickness,
222 GetRowHeightFromId(suggestions[index].frontend_id)); 240 GetRowHeightFromId(suggestions[index].frontend_id));
223 } 241 }
224 242
225 int AutofillPopupLayoutModel::GetIconResourceID( 243 int AutofillPopupLayoutModel::GetIconResourceID(
226 const base::string16& resource_name) const { 244 const base::string16& resource_name) const {
227 int result = -1; 245 int result = -1;
228 for (size_t i = 0; i < arraysize(kDataResources); ++i) { 246 const bool is_popup_layout_experiment_enabled =
229 if (resource_name == base::ASCIIToUTF16(kDataResources[i].name)) { 247 IsPopupLayoutExperimentEnabled();
230 result = kDataResources[i].id; 248 const size_t num_data_resources = is_popup_layout_experiment_enabled ?
249 arraysize(kLargeDataResources) : arraysize(kDataResources);
250 const data_resource *resources =
251 is_popup_layout_experiment_enabled ? kLargeDataResources : kDataResources;
252 for (size_t i = 0; i < num_data_resources; ++i) {
253 if (resource_name == base::ASCIIToUTF16(resources[i].name)) {
254 result = resources[i].id;
231 break; 255 break;
232 } 256 }
233 } 257 }
234 258
235 #if defined(OS_ANDROID) && !defined(USE_AURA) 259 #if defined(OS_ANDROID) && !defined(USE_AURA)
236 if (result == IDR_AUTOFILL_CC_SCAN_NEW && IsKeyboardAccessoryEnabled()) 260 if (result == IDR_AUTOFILL_CC_SCAN_NEW && IsKeyboardAccessoryEnabled())
237 result = IDR_AUTOFILL_CC_SCAN_NEW_KEYBOARD_ACCESSORY; 261 result = IDR_AUTOFILL_CC_SCAN_NEW_KEYBOARD_ACCESSORY;
238 #endif 262 #endif
239 263
240 return result; 264 return result;
241 } 265 }
242 266
243 const gfx::Rect AutofillPopupLayoutModel::RoundedElementBounds() const { 267 const gfx::Rect AutofillPopupLayoutModel::RoundedElementBounds() const {
244 return gfx::ToEnclosingRect(delegate_->element_bounds()); 268 return gfx::ToEnclosingRect(delegate_->element_bounds());
245 } 269 }
246 270
271 bool AutofillPopupLayoutModel::IsPopupLayoutExperimentEnabled() const {
272 return is_credit_card_field_ ?
273 IsAutofillCreditCardPopupLayoutExperimentEnabled() : false;
274 }
275
276 SkColor AutofillPopupLayoutModel::GetBackgroundColor() const {
277 return is_credit_card_field_ ?
278 GetCreditCardPopupBackgroundColor() : SK_ColorTRANSPARENT;
279 }
280
281 SkColor AutofillPopupLayoutModel::GetDividerColor() const {
282 return is_credit_card_field_ ?
283 GetCreditCardPopupDividerColor() : SK_ColorTRANSPARENT;
284 }
285
286 int AutofillPopupLayoutModel::GetDropdownItemHeight() const {
287 return is_credit_card_field_ ? GetCreditCardPopupDropdownItemHeight() : -1;
288 }
289
290 bool AutofillPopupLayoutModel::IsIconAtLeft() const {
291 return is_credit_card_field_ ? IsCreditCardIconInPopupAtLeft() : -1;
292 }
293
247 } // namespace autofill 294 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698