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

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: comments Created 3 years, 5 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 "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/autofill_experiments.h"
14 #include "components/autofill/core/browser/credit_card.h" 14 #include "components/autofill/core/browser/credit_card.h"
15 #include "components/autofill/core/browser/popup_item_ids.h" 15 #include "components/autofill/core/browser/popup_item_ids.h"
16 #include "components/autofill/core/browser/suggestion.h" 16 #include "components/autofill/core/browser/suggestion.h"
17 #include "components/autofill/core/common/autofill_util.h" 17 #include "components/autofill/core/common/autofill_util.h"
18 #include "components/grit/components_scaled_resources.h" 18 #include "components/grit/components_scaled_resources.h"
19 #include "third_party/skia/include/core/SkColor.h" 19 #include "third_party/skia/include/core/SkColor.h"
20 #include "ui/base/resource/resource_bundle.h" 20 #include "ui/base/resource/resource_bundle.h"
21 #include "ui/gfx/color_palette.h" 21 #include "ui/gfx/color_palette.h"
22 #include "ui/gfx/color_utils.h" 22 #include "ui/gfx/color_utils.h"
23 #include "ui/gfx/font_list.h" 23 #include "ui/gfx/font_list.h"
24 #include "ui/gfx/geometry/rect_conversions.h" 24 #include "ui/gfx/geometry/rect_conversions.h"
25 #include "ui/gfx/image/image_skia.h" 25 #include "ui/gfx/image/image_skia.h"
26 #include "ui/gfx/paint_vector_icon.h" 26 #include "ui/gfx/paint_vector_icon.h"
27 27
28 #if !defined(OS_ANDROID) 28 #if !defined(OS_ANDROID)
29 #include "chrome/app/vector_icons/vector_icons.h"
29 #include "components/toolbar/vector_icons.h" // nogncheck 30 #include "components/toolbar/vector_icons.h" // nogncheck
30 #endif 31 #endif
31 32
32 namespace autofill { 33 namespace autofill {
33 34
34 namespace { 35 namespace {
35 36
36 // The vertical height of each row in pixels. 37 // The vertical height of each row in pixels.
37 const size_t kRowHeight = 24; 38 const size_t kRowHeight = 24;
38 39
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 115
115 popup_width = std::max(popup_width, row_size); 116 popup_width = std::max(popup_width, row_size);
116 } 117 }
117 118
118 return popup_width; 119 return popup_width;
119 } 120 }
120 121
121 int AutofillPopupLayoutModel::RowWidthWithoutText(int row, 122 int AutofillPopupLayoutModel::RowWidthWithoutText(int row,
122 bool with_label) const { 123 bool with_label) const {
123 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); 124 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions();
124 bool is_warning_message = (suggestions[row].frontend_id == 125 bool is_row_with_left_handside_icon =
Evan Stade 2017/07/12 17:53:52 nit: const bool also, "lefthand side" would trans
melandory 2017/07/12 23:13:47 Done.
125 POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE); 126 ((suggestions[row].frontend_id ==
127 POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE) ||
128 (suggestions[row].frontend_id ==
129 POPUP_ITEM_ID_ALL_SAVED_PASSWORDS_ENTRY));
126 130
127 int row_size = kEndPadding; 131 int row_size = kEndPadding;
Evan Stade 2017/07/12 17:53:51 imo this would be easier to follow if you just sta
melandory 2017/07/12 23:13:47 Done.
128 132
129 if (with_label) 133 if (with_label) {
Evan Stade 2017/07/12 17:53:52 it's surprising to me there can be rows with no la
melandory 2017/07/12 23:13:47 Done.
130 row_size += is_warning_message ? kHttpWarningNamePadding : kNamePadding; 134 row_size +=
135 is_row_with_left_handside_icon ? kHttpWarningNamePadding : kNamePadding;
vasilii 2017/07/12 13:20:13 Can we also rename |kHttpWarningNamePadding|?
Evan Stade 2017/07/12 17:53:51 technically this is still only used for http warni
melandory 2017/07/12 23:13:47 Done.
136 }
131 137
132 // Add the Autofill icon size, if required. 138 // Add the Autofill icon size, if required.
133 const base::string16& icon = suggestions[row].icon; 139 const base::string16& icon = suggestions[row].icon;
134 if (!icon.empty()) { 140 if (!icon.empty()) {
135 row_size += GetIconImage(row).width() + 141 row_size +=
136 (is_warning_message ? kHttpWarningIconPadding : kIconPadding); 142 GetIconImage(row).width() + (is_row_with_left_handside_icon
143 ? kPaddingBetweenLeftSideIconAndText
144 : kIconPadding);
137 } 145 }
138 146
139 // Add the padding at the end. 147 // Add the padding at the end.
140 row_size += kEndPadding; 148 row_size += kEndPadding;
141 149
142 // Add room for the popup border. 150 // Add room for the popup border.
143 row_size += 2 * kPopupBorderThickness; 151 row_size += 2 * kPopupBorderThickness;
144 152
145 return row_size; 153 return row_size;
146 } 154 }
(...skipping 26 matching lines...) Expand all
173 case POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE: 181 case POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE:
174 case POPUP_ITEM_ID_CLEAR_FORM: 182 case POPUP_ITEM_ID_CLEAR_FORM:
175 case POPUP_ITEM_ID_CREDIT_CARD_SIGNIN_PROMO: 183 case POPUP_ITEM_ID_CREDIT_CARD_SIGNIN_PROMO:
176 case POPUP_ITEM_ID_AUTOFILL_OPTIONS: 184 case POPUP_ITEM_ID_AUTOFILL_OPTIONS:
177 case POPUP_ITEM_ID_CREATE_HINT: 185 case POPUP_ITEM_ID_CREATE_HINT:
178 case POPUP_ITEM_ID_SCAN_CREDIT_CARD: 186 case POPUP_ITEM_ID_SCAN_CREDIT_CARD:
179 case POPUP_ITEM_ID_SEPARATOR: 187 case POPUP_ITEM_ID_SEPARATOR:
180 case POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE: 188 case POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE:
181 case POPUP_ITEM_ID_TITLE: 189 case POPUP_ITEM_ID_TITLE:
182 case POPUP_ITEM_ID_PASSWORD_ENTRY: 190 case POPUP_ITEM_ID_PASSWORD_ENTRY:
191 case POPUP_ITEM_ID_ALL_SAVED_PASSWORDS_ENTRY:
183 return normal_font_list_; 192 return normal_font_list_;
184 case POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY: 193 case POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY:
185 case POPUP_ITEM_ID_DATALIST_ENTRY: 194 case POPUP_ITEM_ID_DATALIST_ENTRY:
186 case POPUP_ITEM_ID_USERNAME_ENTRY: 195 case POPUP_ITEM_ID_USERNAME_ENTRY:
187 return bold_font_list_; 196 return bold_font_list_;
188 } 197 }
189 NOTREACHED(); 198 NOTREACHED();
190 return normal_font_list_; 199 return normal_font_list_;
191 } 200 }
192 201
(...skipping 13 matching lines...) Expand all
206 switch (suggestions[index].frontend_id) { 215 switch (suggestions[index].frontend_id) {
207 case POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE: 216 case POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE:
208 return ui::NativeTheme::kColorId_AlertSeverityHigh; 217 return ui::NativeTheme::kColorId_AlertSeverityHigh;
209 case POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE: 218 case POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE:
210 return ui::NativeTheme::kColorId_ResultsTableNormalDimmedText; 219 return ui::NativeTheme::kColorId_ResultsTableNormalDimmedText;
211 default: 220 default:
212 return ui::NativeTheme::kColorId_ResultsTableNormalText; 221 return ui::NativeTheme::kColorId_ResultsTableNormalText;
213 } 222 }
214 } 223 }
215 224
216 gfx::ImageSkia AutofillPopupLayoutModel::GetIconImage(size_t index) const { 225 gfx::ImageSkia AutofillPopupLayoutModel::GetIconImage(size_t index) const {
Evan Stade 2017/07/12 17:53:51 side nit: I believe this interface should return a
melandory 2017/07/12 23:13:47 will address tomorrow, code search doesn't work fo
Evan Stade 2017/07/13 16:48:43 By "side nit" I intended to convey it wasn't impor
melandory 2017/07/25 15:08:49 Could you suggest what method should I use in orde
217 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); 226 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions();
218 const base::string16& icon_str = suggestions[index].icon; 227 const base::string16& icon_str = suggestions[index].icon;
219 228
220 // For http warning message, get icon images from VectorIcon, which is the 229 // For http warning message, get icon images from VectorIcon, which is the
221 // same as security indicator icons in location bar. 230 // same as security indicator icons in location bar.
222 if (suggestions[index].frontend_id == 231 if (suggestions[index].frontend_id ==
223 POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE) { 232 POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE) {
Evan Stade 2017/07/12 17:53:52 nit: why this check? aren't the string comparisons
melandory 2017/07/12 23:13:47 Done.
224 if (icon_str == base::ASCIIToUTF16("httpWarning")) { 233 if (icon_str == base::ASCIIToUTF16("httpWarning")) {
225 return gfx::CreateVectorIcon(toolbar::kHttpIcon, kHttpWarningIconWidth, 234 return gfx::CreateVectorIcon(toolbar::kHttpIcon, kHttpWarningIconWidth,
226 gfx::kChromeIconGrey); 235 gfx::kChromeIconGrey);
227 } 236 }
228 DCHECK_EQ(icon_str, base::ASCIIToUTF16("httpsInvalid")); 237 DCHECK_EQ(icon_str, base::ASCIIToUTF16("httpsInvalid"));
229 return gfx::CreateVectorIcon(toolbar::kHttpsInvalidIcon, 238 return gfx::CreateVectorIcon(toolbar::kHttpsInvalidIcon,
230 kHttpWarningIconWidth, gfx::kGoogleRed700); 239 kHttpWarningIconWidth, gfx::kGoogleRed700);
231 } 240 }
232 241
242 if (icon_str == base::ASCIIToUTF16("showAllSavedPasswords")) {
243 return gfx::CreateVectorIcon(kShowAllSavedPasswordsIcon,
244 kHttpWarningIconWidth, gfx::kChromeIconGrey);
Evan Stade 2017/07/12 17:53:52 nit: kHttpWarningIconWidth is one I'd rename.
melandory 2017/07/12 23:13:47 Done.
245 }
246
233 // For other suggestion entries, get icon from PNG files. 247 // For other suggestion entries, get icon from PNG files.
234 int icon_id = GetIconResourceID(icon_str); 248 int icon_id = GetIconResourceID(icon_str);
235 DCHECK_NE(-1, icon_id); 249 DCHECK_NE(-1, icon_id);
236 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(icon_id); 250 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(icon_id);
237 } 251 }
238 #endif 252 #endif
Evan Stade 2017/07/12 17:53:51 nit: can you add what condition this is the end of
melandory 2017/07/12 23:13:47 Done.
239 253
240 int AutofillPopupLayoutModel::LineFromY(int y) const { 254 int AutofillPopupLayoutModel::LineFromY(int y) const {
241 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); 255 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions();
242 int current_height = kPopupBorderThickness; 256 int current_height = kPopupBorderThickness;
243 257
244 for (size_t i = 0; i < suggestions.size(); ++i) { 258 for (size_t i = 0; i < suggestions.size(); ++i) {
245 current_height += GetRowHeightFromId(suggestions[i].frontend_id); 259 current_height += GetRowHeightFromId(suggestions[i].frontend_id);
246 260
247 if (y <= current_height) 261 if (y <= current_height)
248 return i; 262 return i;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 bool AutofillPopupLayoutModel::IsIconAtStart(int frontend_id) const { 318 bool AutofillPopupLayoutModel::IsIconAtStart(int frontend_id) const {
305 return frontend_id == POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE || 319 return frontend_id == POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE ||
306 (is_credit_card_popup_ && IsIconInCreditCardPopupAtStart()); 320 (is_credit_card_popup_ && IsIconInCreditCardPopupAtStart());
307 } 321 }
308 322
309 unsigned int AutofillPopupLayoutModel::GetMargin() const { 323 unsigned int AutofillPopupLayoutModel::GetMargin() const {
310 return GetPopupMargin(); 324 return GetPopupMargin();
311 } 325 }
312 326
313 } // namespace autofill 327 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698