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

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

Issue 2498503002: Http Bad: Add icons to the http warning message (Closed)
Patch Set: rebase 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/popup_item_ids.h" 13 #include "components/autofill/core/browser/popup_item_ids.h"
14 #include "components/autofill/core/browser/suggestion.h" 14 #include "components/autofill/core/browser/suggestion.h"
15 #include "components/autofill/core/common/autofill_util.h" 15 #include "components/autofill/core/common/autofill_util.h"
16 #include "components/grit/components_scaled_resources.h" 16 #include "components/grit/components_scaled_resources.h"
17 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/gfx/color_palette.h" 18 #include "ui/gfx/color_palette.h"
19 #include "ui/gfx/color_utils.h"
19 #include "ui/gfx/font_list.h" 20 #include "ui/gfx/font_list.h"
20 #include "ui/gfx/geometry/rect_conversions.h" 21 #include "ui/gfx/geometry/rect_conversions.h"
22 #include "ui/gfx/image/image_skia.h"
23 #include "ui/gfx/paint_vector_icon.h"
24 #include "ui/gfx/vector_icons_public.h"
21 25
22 namespace autofill { 26 namespace autofill {
23 27
24 namespace { 28 namespace {
25 29
26 // The vertical height of each row in pixels. 30 // The vertical height of each row in pixels.
27 const size_t kRowHeight = 24; 31 const size_t kRowHeight = 24;
28 32
29 // The vertical height of a separator in pixels. 33 // The vertical height of a separator in pixels.
30 const size_t kSeparatorHeight = 1; 34 const size_t kSeparatorHeight = 1;
31 35
32 #if !defined(OS_ANDROID) 36 #if !defined(OS_ANDROID)
33 // Size difference between the normal font and the smaller font, in pixels. 37 // Size difference between the normal font and the smaller font, in pixels.
34 const int kSmallerFontSizeDelta = -1; 38 const int kSmallerFontSizeDelta = -1;
39
40 const int kHttpWarningIconWidth = 16;
35 #endif 41 #endif
36 42
37 const struct { 43 const struct {
38 const char* name; 44 const char* name;
39 int id; 45 int id;
40 } kDataResources[] = { 46 } kDataResources[] = {
41 {"americanExpressCC", IDR_AUTOFILL_CC_AMEX}, 47 {"americanExpressCC", IDR_AUTOFILL_CC_AMEX},
42 {"dinersCC", IDR_AUTOFILL_CC_GENERIC}, 48 {"dinersCC", IDR_AUTOFILL_CC_GENERIC},
43 {"discoverCC", IDR_AUTOFILL_CC_DISCOVER}, 49 {"discoverCC", IDR_AUTOFILL_CC_DISCOVER},
44 {"genericCC", IDR_AUTOFILL_CC_GENERIC}, 50 {"genericCC", IDR_AUTOFILL_CC_GENERIC},
45 {"jcbCC", IDR_AUTOFILL_CC_GENERIC}, 51 {"jcbCC", IDR_AUTOFILL_CC_GENERIC},
46 {"masterCardCC", IDR_AUTOFILL_CC_MASTERCARD}, 52 {"masterCardCC", IDR_AUTOFILL_CC_MASTERCARD},
47 {"mirCC", IDR_AUTOFILL_CC_MIR}, 53 {"mirCC", IDR_AUTOFILL_CC_MIR},
48 {"visaCC", IDR_AUTOFILL_CC_VISA}, 54 {"visaCC", IDR_AUTOFILL_CC_VISA},
49 #if defined(OS_ANDROID) 55 #if defined(OS_ANDROID)
56 {"httpWarning", IDR_AUTOFILL_HTTP_WARNING},
57 {"httpsInvalid", IDR_AUTOFILL_HTTPS_INVALID_WARNING},
50 {"scanCreditCardIcon", IDR_AUTOFILL_CC_SCAN_NEW}, 58 {"scanCreditCardIcon", IDR_AUTOFILL_CC_SCAN_NEW},
51 {"settings", IDR_AUTOFILL_SETTINGS}, 59 {"settings", IDR_AUTOFILL_SETTINGS},
52 #endif 60 #endif
53 }; 61 };
54 62
55 int GetRowHeightFromId(int identifier) { 63 int GetRowHeightFromId(int identifier) {
56 if (identifier == POPUP_ITEM_ID_SEPARATOR) 64 if (identifier == POPUP_ITEM_ID_SEPARATOR)
57 return kSeparatorHeight; 65 return kSeparatorHeight;
58 66
59 return kRowHeight; 67 return kRowHeight;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); 120 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions();
113 121
114 int row_size = kEndPadding; 122 int row_size = kEndPadding;
115 123
116 if (with_label) 124 if (with_label)
117 row_size += kNamePadding; 125 row_size += kNamePadding;
118 126
119 // Add the Autofill icon size, if required. 127 // Add the Autofill icon size, if required.
120 const base::string16& icon = suggestions[row].icon; 128 const base::string16& icon = suggestions[row].icon;
121 if (!icon.empty()) { 129 if (!icon.empty()) {
122 int icon_width = ui::ResourceBundle::GetSharedInstance() 130 row_size += GetIconImage(row).width() + kIconPadding;
123 .GetImageNamed(GetIconResourceID(icon))
124 .Width();
125 row_size += icon_width + kIconPadding;
126 } 131 }
127 132
128 // Add the padding at the end. 133 // Add the padding at the end.
129 row_size += kEndPadding; 134 row_size += kEndPadding;
130 135
131 // Add room for the popup border. 136 // Add room for the popup border.
132 row_size += 2 * kPopupBorderThickness; 137 row_size += 2 * kPopupBorderThickness;
133 138
134 return row_size; 139 return row_size;
135 } 140 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); 191 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions();
187 switch (suggestions[index].frontend_id) { 192 switch (suggestions[index].frontend_id) {
188 case POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE: 193 case POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE:
189 return gfx::kGoogleRed700; 194 return gfx::kGoogleRed700;
190 case POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE: 195 case POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE:
191 return kLabelTextColor; 196 return kLabelTextColor;
192 default: 197 default:
193 return kValueTextColor; 198 return kValueTextColor;
194 } 199 }
195 } 200 }
201
202 gfx::ImageSkia AutofillPopupLayoutModel::GetIconImage(size_t index) const {
203 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions();
204 const base::string16& icon_str = suggestions[index].icon;
205
206 // For http warning message, get icon images from VectorIconId, which is the
207 // same as security indicator icons in location bar.
208 if (suggestions[index].frontend_id ==
209 POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE) {
210 if (icon_str == base::ASCIIToUTF16("httpWarning")) {
211 return gfx::CreateVectorIcon(gfx::VectorIconId::LOCATION_BAR_HTTP,
212 kHttpWarningIconWidth, gfx::kChromeIconGrey);
213 }
214 DCHECK_EQ(icon_str, base::ASCIIToUTF16("httpsInvalid"));
215 return gfx::CreateVectorIcon(gfx::VectorIconId::LOCATION_BAR_HTTPS_INVALID,
216 kHttpWarningIconWidth, gfx::kGoogleRed700);
217 }
218
219 // For other suggestion entries, get icon from PNG files.
220 int icon_id = GetIconResourceID(icon_str);
221 DCHECK_NE(-1, icon_id);
222 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(icon_id);
223 }
196 #endif 224 #endif
197 225
198 int AutofillPopupLayoutModel::LineFromY(int y) const { 226 int AutofillPopupLayoutModel::LineFromY(int y) const {
199 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); 227 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions();
200 int current_height = kPopupBorderThickness; 228 int current_height = kPopupBorderThickness;
201 229
202 for (size_t i = 0; i < suggestions.size(); ++i) { 230 for (size_t i = 0; i < suggestions.size(); ++i) {
203 current_height += GetRowHeightFromId(suggestions[i].frontend_id); 231 current_height += GetRowHeightFromId(suggestions[i].frontend_id);
204 232
205 if (y <= current_height) 233 if (y <= current_height)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 #endif 267 #endif
240 268
241 return result; 269 return result;
242 } 270 }
243 271
244 const gfx::Rect AutofillPopupLayoutModel::RoundedElementBounds() const { 272 const gfx::Rect AutofillPopupLayoutModel::RoundedElementBounds() const {
245 return gfx::ToEnclosingRect(delegate_->element_bounds()); 273 return gfx::ToEnclosingRect(delegate_->element_bounds());
246 } 274 }
247 275
248 } // namespace autofill 276 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698