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

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

Issue 2971783002: Skeleton for showing "Show all saved passwords row" for Linux/CrOs/Windows platforms (Closed)
Patch Set: . Created 3 years, 4 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 (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 "build/build_config.h"
11 #include "chrome/browser/ui/autofill/autofill_popup_view.h" 12 #include "chrome/browser/ui/autofill/autofill_popup_view.h"
12 #include "chrome/browser/ui/autofill/popup_constants.h" 13 #include "chrome/browser/ui/autofill/popup_constants.h"
13 #include "components/autofill/core/browser/autofill_experiments.h" 14 #include "components/autofill/core/browser/autofill_experiments.h"
14 #include "components/autofill/core/browser/credit_card.h" 15 #include "components/autofill/core/browser/credit_card.h"
15 #include "components/autofill/core/browser/popup_item_ids.h" 16 #include "components/autofill/core/browser/popup_item_ids.h"
16 #include "components/autofill/core/browser/suggestion.h" 17 #include "components/autofill/core/browser/suggestion.h"
17 #include "components/autofill/core/common/autofill_util.h" 18 #include "components/autofill/core/common/autofill_util.h"
18 #include "components/grit/components_scaled_resources.h" 19 #include "components/grit/components_scaled_resources.h"
19 #include "third_party/skia/include/core/SkColor.h" 20 #include "third_party/skia/include/core/SkColor.h"
20 #include "ui/base/resource/resource_bundle.h" 21 #include "ui/base/resource/resource_bundle.h"
21 #include "ui/gfx/color_palette.h" 22 #include "ui/gfx/color_palette.h"
22 #include "ui/gfx/color_utils.h" 23 #include "ui/gfx/color_utils.h"
23 #include "ui/gfx/font_list.h" 24 #include "ui/gfx/font_list.h"
24 #include "ui/gfx/geometry/rect_conversions.h" 25 #include "ui/gfx/geometry/rect_conversions.h"
25 #include "ui/gfx/image/image_skia.h" 26 #include "ui/gfx/image/image_skia.h"
26 #include "ui/gfx/paint_vector_icon.h" 27 #include "ui/gfx/paint_vector_icon.h"
27 28
28 #if !defined(OS_ANDROID) 29 #if !defined(OS_ANDROID)
30 #include "chrome/app/vector_icons/vector_icons.h"
29 #include "components/toolbar/vector_icons.h" // nogncheck 31 #include "components/toolbar/vector_icons.h" // nogncheck
30 #endif 32 #endif
31 33
32 namespace autofill { 34 namespace autofill {
33 35
34 namespace { 36 namespace {
35 37
36 // The vertical height of each row in pixels. 38 // The vertical height of each row in pixels.
37 const size_t kRowHeight = 24; 39 const size_t kRowHeight = 24;
38 40
39 // The vertical height of a separator in pixels. 41 // The vertical height of a separator in pixels.
40 const size_t kSeparatorHeight = 1; 42 const size_t kSeparatorHeight = 1;
41 43
42 #if !defined(OS_ANDROID) 44 #if !defined(OS_ANDROID)
43 // Size difference between the normal font and the smaller font, in pixels. 45 // Size difference between the normal font and the smaller font, in pixels.
44 const int kSmallerFontSizeDelta = -1; 46 const int kSmallerFontSizeDelta = -1;
45
46 const int kHttpWarningIconWidth = 16;
47 #endif 47 #endif
48 48
49 const struct { 49 const struct {
50 const char* name; 50 const char* name;
51 int id; 51 int id;
52 } kDataResources[] = { 52 } kDataResources[] = {
53 {autofill::kAmericanExpressCard, IDR_AUTOFILL_CC_AMEX}, 53 {autofill::kAmericanExpressCard, IDR_AUTOFILL_CC_AMEX},
54 {autofill::kDinersCard, IDR_AUTOFILL_CC_DINERS}, 54 {autofill::kDinersCard, IDR_AUTOFILL_CC_DINERS},
55 {autofill::kDiscoverCard, IDR_AUTOFILL_CC_DISCOVER}, 55 {autofill::kDiscoverCard, IDR_AUTOFILL_CC_DISCOVER},
56 {autofill::kEloCard, IDR_AUTOFILL_CC_ELO}, 56 {autofill::kEloCard, IDR_AUTOFILL_CC_ELO},
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 } 103 }
104 104
105 int AutofillPopupLayoutModel::GetDesiredPopupWidth() const { 105 int AutofillPopupLayoutModel::GetDesiredPopupWidth() const {
106 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); 106 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions();
107 107
108 int popup_width = RoundedElementBounds().width(); 108 int popup_width = RoundedElementBounds().width();
109 109
110 for (size_t i = 0; i < suggestions.size(); ++i) { 110 for (size_t i = 0; i < suggestions.size(); ++i) {
111 int label_size = delegate_->GetElidedLabelWidthForRow(i); 111 int label_size = delegate_->GetElidedLabelWidthForRow(i);
112 int row_size = delegate_->GetElidedValueWidthForRow(i) + label_size + 112 int row_size = delegate_->GetElidedValueWidthForRow(i) + label_size +
113 RowWidthWithoutText(i, /* with_label= */ label_size > 0); 113 RowWidthWithoutText(i, /* has_substext= */ label_size > 0);
114 114
115 popup_width = std::max(popup_width, row_size); 115 popup_width = std::max(popup_width, row_size);
116 } 116 }
117 117
118 return popup_width; 118 return popup_width;
119 } 119 }
120 120
121 int AutofillPopupLayoutModel::RowWidthWithoutText(int row, 121 int AutofillPopupLayoutModel::RowWidthWithoutText(int row,
122 bool with_label) const { 122 bool has_substext) const {
Evan Stade 2017/07/27 18:17:57 nit: s/substext/subtext/g
melandory 2017/07/28 10:24:50 Done.
123 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); 123 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions();
124 bool is_warning_message = (suggestions[row].frontend_id == 124 bool is_warning_message = (suggestions[row].frontend_id ==
125 POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE); 125 POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE);
126 const bool is_row_with_icon_positioned_at_start =
Evan Stade 2017/07/27 18:17:57 nit: variable name is a mouthful. Can we go withou
melandory 2017/07/28 10:24:50 Done.
127 (is_warning_message || (suggestions[row].frontend_id ==
128 POPUP_ITEM_ID_ALL_SAVED_PASSWORDS_ENTRY));
126 129
127 int row_size = kEndPadding; 130 int row_size = 2 * (kEndPadding + kPopupBorderThickness);
128 131 if (has_substext)
129 if (with_label)
130 row_size += is_warning_message ? kHttpWarningNamePadding : kNamePadding; 132 row_size += is_warning_message ? kHttpWarningNamePadding : kNamePadding;
131 133
132 // Add the Autofill icon size, if required. 134 // Add the Autofill icon size, if required.
133 const base::string16& icon = suggestions[row].icon; 135 const base::string16& icon = suggestions[row].icon;
134 if (!icon.empty()) { 136 if (!icon.empty()) {
135 row_size += GetIconImage(row).width() + 137 row_size += GetIconImage(row).width() +
136 (is_warning_message ? kHttpWarningIconPadding : kIconPadding); 138 (is_row_with_icon_positioned_at_start ? kPaddingAfterLeadingIcon
139 : kIconPadding);
137 } 140 }
138
139 // Add the padding at the end.
140 row_size += kEndPadding;
141
142 // Add room for the popup border.
143 row_size += 2 * kPopupBorderThickness;
144
145 return row_size; 141 return row_size;
146 } 142 }
147 143
148 int AutofillPopupLayoutModel::GetAvailableWidthForRow(int row, 144 int AutofillPopupLayoutModel::GetAvailableWidthForRow(int row,
149 bool with_label) const { 145 bool has_substext) const {
150 return popup_bounds_.width() - RowWidthWithoutText(row, with_label); 146 return popup_bounds_.width() - RowWidthWithoutText(row, has_substext);
151 } 147 }
152 148
153 void AutofillPopupLayoutModel::UpdatePopupBounds() { 149 void AutofillPopupLayoutModel::UpdatePopupBounds() {
154 int popup_width = GetDesiredPopupWidth(); 150 int popup_width = GetDesiredPopupWidth();
155 int popup_height = GetDesiredPopupHeight(); 151 int popup_height = GetDesiredPopupHeight();
156 152
157 popup_bounds_ = view_common_.CalculatePopupBounds( 153 popup_bounds_ = view_common_.CalculatePopupBounds(
158 popup_width, popup_height, RoundedElementBounds(), 154 popup_width, popup_height, RoundedElementBounds(),
159 delegate_->container_view(), delegate_->IsRTL()); 155 delegate_->container_view(), delegate_->IsRTL());
160 } 156 }
(...skipping 12 matching lines...) Expand all
173 case POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE: 169 case POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE:
174 case POPUP_ITEM_ID_CLEAR_FORM: 170 case POPUP_ITEM_ID_CLEAR_FORM:
175 case POPUP_ITEM_ID_CREDIT_CARD_SIGNIN_PROMO: 171 case POPUP_ITEM_ID_CREDIT_CARD_SIGNIN_PROMO:
176 case POPUP_ITEM_ID_AUTOFILL_OPTIONS: 172 case POPUP_ITEM_ID_AUTOFILL_OPTIONS:
177 case POPUP_ITEM_ID_CREATE_HINT: 173 case POPUP_ITEM_ID_CREATE_HINT:
178 case POPUP_ITEM_ID_SCAN_CREDIT_CARD: 174 case POPUP_ITEM_ID_SCAN_CREDIT_CARD:
179 case POPUP_ITEM_ID_SEPARATOR: 175 case POPUP_ITEM_ID_SEPARATOR:
180 case POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE: 176 case POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE:
181 case POPUP_ITEM_ID_TITLE: 177 case POPUP_ITEM_ID_TITLE:
182 case POPUP_ITEM_ID_PASSWORD_ENTRY: 178 case POPUP_ITEM_ID_PASSWORD_ENTRY:
179 case POPUP_ITEM_ID_ALL_SAVED_PASSWORDS_ENTRY:
183 return normal_font_list_; 180 return normal_font_list_;
184 case POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY: 181 case POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY:
185 case POPUP_ITEM_ID_DATALIST_ENTRY: 182 case POPUP_ITEM_ID_DATALIST_ENTRY:
186 case POPUP_ITEM_ID_USERNAME_ENTRY: 183 case POPUP_ITEM_ID_USERNAME_ENTRY:
187 return bold_font_list_; 184 return bold_font_list_;
188 } 185 }
189 NOTREACHED(); 186 NOTREACHED();
190 return normal_font_list_; 187 return normal_font_list_;
191 } 188 }
192 189
(...skipping 16 matching lines...) Expand all
209 case POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE: 206 case POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE:
210 return ui::NativeTheme::kColorId_ResultsTableNormalDimmedText; 207 return ui::NativeTheme::kColorId_ResultsTableNormalDimmedText;
211 default: 208 default:
212 return ui::NativeTheme::kColorId_ResultsTableNormalText; 209 return ui::NativeTheme::kColorId_ResultsTableNormalText;
213 } 210 }
214 } 211 }
215 212
216 gfx::ImageSkia AutofillPopupLayoutModel::GetIconImage(size_t index) const { 213 gfx::ImageSkia AutofillPopupLayoutModel::GetIconImage(size_t index) const {
217 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); 214 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions();
218 const base::string16& icon_str = suggestions[index].icon; 215 const base::string16& icon_str = suggestions[index].icon;
216 constexpr int kIconSize = 16;
219 217
220 // For http warning message, get icon images from VectorIcon, which is the 218 // For http warning message, get icon images from VectorIcon, which is the
221 // same as security indicator icons in location bar. 219 // same as security indicator icons in location bar.
222 if (suggestions[index].frontend_id == 220 if (icon_str == base::ASCIIToUTF16("httpWarning")) {
223 POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE) { 221 return gfx::CreateVectorIcon(toolbar::kHttpIcon, kIconSize,
224 if (icon_str == base::ASCIIToUTF16("httpWarning")) { 222 gfx::kChromeIconGrey);
225 return gfx::CreateVectorIcon(toolbar::kHttpIcon, kHttpWarningIconWidth, 223 }
226 gfx::kChromeIconGrey); 224 if (icon_str == base::ASCIIToUTF16("httpsInvalid")) {
227 } 225 return gfx::CreateVectorIcon(toolbar::kHttpsInvalidIcon, kIconSize,
228 DCHECK_EQ(icon_str, base::ASCIIToUTF16("httpsInvalid")); 226 gfx::kGoogleRed700);
229 return gfx::CreateVectorIcon(toolbar::kHttpsInvalidIcon, 227 }
230 kHttpWarningIconWidth, gfx::kGoogleRed700); 228
229 if (icon_str == base::ASCIIToUTF16("showAllSavedPasswords")) {
230 return gfx::CreateVectorIcon(kOpenInNewIcon, kIconSize,
231 gfx::kChromeIconGrey);
231 } 232 }
232 233
233 // For other suggestion entries, get icon from PNG files. 234 // For other suggestion entries, get icon from PNG files.
234 int icon_id = GetIconResourceID(icon_str); 235 int icon_id = GetIconResourceID(icon_str);
235 DCHECK_NE(-1, icon_id); 236 DCHECK_NE(-1, icon_id);
236 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(icon_id); 237 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(icon_id);
237 } 238 }
238 #endif 239 #endif // !defined(OS_ANDROID)
239 240
240 int AutofillPopupLayoutModel::LineFromY(int y) const { 241 int AutofillPopupLayoutModel::LineFromY(int y) const {
241 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); 242 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions();
242 int current_height = kPopupBorderThickness; 243 int current_height = kPopupBorderThickness;
243 244
244 for (size_t i = 0; i < suggestions.size(); ++i) { 245 for (size_t i = 0; i < suggestions.size(); ++i) {
245 current_height += GetRowHeightFromId(suggestions[i].frontend_id); 246 current_height += GetRowHeightFromId(suggestions[i].frontend_id);
246 247
247 if (y <= current_height) 248 if (y <= current_height)
248 return i; 249 return i;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 bool AutofillPopupLayoutModel::IsIconAtStart(int frontend_id) const { 305 bool AutofillPopupLayoutModel::IsIconAtStart(int frontend_id) const {
305 return frontend_id == POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE || 306 return frontend_id == POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE ||
306 (is_credit_card_popup_ && IsIconInCreditCardPopupAtStart()); 307 (is_credit_card_popup_ && IsIconInCreditCardPopupAtStart());
307 } 308 }
308 309
309 unsigned int AutofillPopupLayoutModel::GetMargin() const { 310 unsigned int AutofillPopupLayoutModel::GetMargin() const {
310 return GetPopupMargin(); 311 return GetPopupMargin();
311 } 312 }
312 313
313 } // namespace autofill 314 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698