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

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_subtext= */ 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_subtext) const {
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_ =
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_subtext)
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_ ? kPaddingAfterLeadingIcon : kIconPadding);
137 } 139 }
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; 140 return row_size;
146 } 141 }
147 142
148 int AutofillPopupLayoutModel::GetAvailableWidthForRow(int row, 143 int AutofillPopupLayoutModel::GetAvailableWidthForRow(int row,
149 bool with_label) const { 144 bool has_subtext) const {
150 return popup_bounds_.width() - RowWidthWithoutText(row, with_label); 145 return popup_bounds_.width() - RowWidthWithoutText(row, has_subtext);
151 } 146 }
152 147
153 void AutofillPopupLayoutModel::UpdatePopupBounds() { 148 void AutofillPopupLayoutModel::UpdatePopupBounds() {
154 int popup_width = GetDesiredPopupWidth(); 149 int popup_width = GetDesiredPopupWidth();
155 int popup_height = GetDesiredPopupHeight(); 150 int popup_height = GetDesiredPopupHeight();
156 151
157 popup_bounds_ = view_common_.CalculatePopupBounds( 152 popup_bounds_ = view_common_.CalculatePopupBounds(
158 popup_width, popup_height, RoundedElementBounds(), 153 popup_width, popup_height, RoundedElementBounds(),
159 delegate_->container_view(), delegate_->IsRTL()); 154 delegate_->container_view(), delegate_->IsRTL());
160 } 155 }
(...skipping 12 matching lines...) Expand all
173 case POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE: 168 case POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE:
174 case POPUP_ITEM_ID_CLEAR_FORM: 169 case POPUP_ITEM_ID_CLEAR_FORM:
175 case POPUP_ITEM_ID_CREDIT_CARD_SIGNIN_PROMO: 170 case POPUP_ITEM_ID_CREDIT_CARD_SIGNIN_PROMO:
176 case POPUP_ITEM_ID_AUTOFILL_OPTIONS: 171 case POPUP_ITEM_ID_AUTOFILL_OPTIONS:
177 case POPUP_ITEM_ID_CREATE_HINT: 172 case POPUP_ITEM_ID_CREATE_HINT:
178 case POPUP_ITEM_ID_SCAN_CREDIT_CARD: 173 case POPUP_ITEM_ID_SCAN_CREDIT_CARD:
179 case POPUP_ITEM_ID_SEPARATOR: 174 case POPUP_ITEM_ID_SEPARATOR:
180 case POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE: 175 case POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE:
181 case POPUP_ITEM_ID_TITLE: 176 case POPUP_ITEM_ID_TITLE:
182 case POPUP_ITEM_ID_PASSWORD_ENTRY: 177 case POPUP_ITEM_ID_PASSWORD_ENTRY:
178 case POPUP_ITEM_ID_ALL_SAVED_PASSWORDS_ENTRY:
183 return normal_font_list_; 179 return normal_font_list_;
184 case POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY: 180 case POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY:
185 case POPUP_ITEM_ID_DATALIST_ENTRY: 181 case POPUP_ITEM_ID_DATALIST_ENTRY:
186 case POPUP_ITEM_ID_USERNAME_ENTRY: 182 case POPUP_ITEM_ID_USERNAME_ENTRY:
187 return bold_font_list_; 183 return bold_font_list_;
188 } 184 }
189 NOTREACHED(); 185 NOTREACHED();
190 return normal_font_list_; 186 return normal_font_list_;
191 } 187 }
192 188
(...skipping 16 matching lines...) Expand all
209 case POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE: 205 case POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE:
210 return ui::NativeTheme::kColorId_ResultsTableNormalDimmedText; 206 return ui::NativeTheme::kColorId_ResultsTableNormalDimmedText;
211 default: 207 default:
212 return ui::NativeTheme::kColorId_ResultsTableNormalText; 208 return ui::NativeTheme::kColorId_ResultsTableNormalText;
213 } 209 }
214 } 210 }
215 211
216 gfx::ImageSkia AutofillPopupLayoutModel::GetIconImage(size_t index) const { 212 gfx::ImageSkia AutofillPopupLayoutModel::GetIconImage(size_t index) const {
217 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); 213 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions();
218 const base::string16& icon_str = suggestions[index].icon; 214 const base::string16& icon_str = suggestions[index].icon;
215 constexpr int kIconSize = 16;
219 216
220 // For http warning message, get icon images from VectorIcon, which is the 217 // For http warning message, get icon images from VectorIcon, which is the
221 // same as security indicator icons in location bar. 218 // same as security indicator icons in location bar.
222 if (suggestions[index].frontend_id == 219 if (icon_str == base::ASCIIToUTF16("httpWarning")) {
223 POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE) { 220 return gfx::CreateVectorIcon(toolbar::kHttpIcon, kIconSize,
224 if (icon_str == base::ASCIIToUTF16("httpWarning")) { 221 gfx::kChromeIconGrey);
225 return gfx::CreateVectorIcon(toolbar::kHttpIcon, kHttpWarningIconWidth, 222 }
226 gfx::kChromeIconGrey); 223 if (icon_str == base::ASCIIToUTF16("httpsInvalid")) {
227 } 224 return gfx::CreateVectorIcon(toolbar::kHttpsInvalidIcon, kIconSize,
228 DCHECK_EQ(icon_str, base::ASCIIToUTF16("httpsInvalid")); 225 gfx::kGoogleRed700);
229 return gfx::CreateVectorIcon(toolbar::kHttpsInvalidIcon, 226 }
230 kHttpWarningIconWidth, gfx::kGoogleRed700); 227
228 if (icon_str == base::ASCIIToUTF16("showAllSavedPasswords")) {
229 return gfx::CreateVectorIcon(kOpenInNewIcon, kIconSize,
230 gfx::kChromeIconGrey);
231 } 231 }
232 232
233 // For other suggestion entries, get icon from PNG files. 233 // For other suggestion entries, get icon from PNG files.
234 int icon_id = GetIconResourceID(icon_str); 234 int icon_id = GetIconResourceID(icon_str);
235 DCHECK_NE(-1, icon_id); 235 DCHECK_NE(-1, icon_id);
236 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(icon_id); 236 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(icon_id);
237 } 237 }
238 #endif 238 #endif // !defined(OS_ANDROID)
239 239
240 int AutofillPopupLayoutModel::LineFromY(int y) const { 240 int AutofillPopupLayoutModel::LineFromY(int y) const {
241 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); 241 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions();
242 int current_height = kPopupBorderThickness; 242 int current_height = kPopupBorderThickness;
243 243
244 for (size_t i = 0; i < suggestions.size(); ++i) { 244 for (size_t i = 0; i < suggestions.size(); ++i) {
245 current_height += GetRowHeightFromId(suggestions[i].frontend_id); 245 current_height += GetRowHeightFromId(suggestions[i].frontend_id);
246 246
247 if (y <= current_height) 247 if (y <= current_height)
248 return i; 248 return i;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 bool AutofillPopupLayoutModel::IsIconAtStart(int frontend_id) const { 304 bool AutofillPopupLayoutModel::IsIconAtStart(int frontend_id) const {
305 return frontend_id == POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE || 305 return frontend_id == POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE ||
306 (is_credit_card_popup_ && IsIconInCreditCardPopupAtStart()); 306 (is_credit_card_popup_ && IsIconInCreditCardPopupAtStart());
307 } 307 }
308 308
309 unsigned int AutofillPopupLayoutModel::GetMargin() const { 309 unsigned int AutofillPopupLayoutModel::GetMargin() const {
310 return GetPopupMargin(); 310 return GetPopupMargin();
311 } 311 }
312 312
313 } // namespace autofill 313 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698