Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 {"visaCC", IDR_AUTOFILL_CC_VISA}, | 53 {"visaCC", IDR_AUTOFILL_CC_VISA}, |
| 48 #if defined(OS_ANDROID) | 54 #if defined(OS_ANDROID) |
| 55 {"httpWarning", IDR_AUTOFILL_HTTP_WARNING}, | |
| 56 {"httpsInvalid", IDR_AUTOFILL_HTTPS_INVALID_WARNING}, | |
| 49 {"scanCreditCardIcon", IDR_AUTOFILL_CC_SCAN_NEW}, | 57 {"scanCreditCardIcon", IDR_AUTOFILL_CC_SCAN_NEW}, |
| 50 {"settings", IDR_AUTOFILL_SETTINGS}, | 58 {"settings", IDR_AUTOFILL_SETTINGS}, |
| 51 #endif | 59 #endif |
| 52 }; | 60 }; |
| 53 | 61 |
| 54 int GetRowHeightFromId(int identifier) { | 62 int GetRowHeightFromId(int identifier) { |
| 55 if (identifier == POPUP_ITEM_ID_SEPARATOR) | 63 if (identifier == POPUP_ITEM_ID_SEPARATOR) |
| 56 return kSeparatorHeight; | 64 return kSeparatorHeight; |
| 57 | 65 |
| 58 return kRowHeight; | 66 return kRowHeight; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); | 119 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); |
| 112 | 120 |
| 113 int row_size = kEndPadding; | 121 int row_size = kEndPadding; |
| 114 | 122 |
| 115 if (with_label) | 123 if (with_label) |
| 116 row_size += kNamePadding; | 124 row_size += kNamePadding; |
| 117 | 125 |
| 118 // Add the Autofill icon size, if required. | 126 // Add the Autofill icon size, if required. |
| 119 const base::string16& icon = suggestions[row].icon; | 127 const base::string16& icon = suggestions[row].icon; |
| 120 if (!icon.empty()) { | 128 if (!icon.empty()) { |
| 121 int icon_width = ui::ResourceBundle::GetSharedInstance() | 129 int icon_width = GetIconImage(row).width(); |
|
Evan Stade
2016/11/29 15:23:32
nit: inline below
lshang
2016/11/29 23:48:30
Done.
| |
| 122 .GetImageNamed(GetIconResourceID(icon)) | |
| 123 .Width(); | |
| 124 row_size += icon_width + kIconPadding; | 130 row_size += icon_width + kIconPadding; |
| 125 } | 131 } |
| 126 | 132 |
| 127 // Add the padding at the end. | 133 // Add the padding at the end. |
| 128 row_size += kEndPadding; | 134 row_size += kEndPadding; |
| 129 | 135 |
| 130 // Add room for the popup border. | 136 // Add room for the popup border. |
| 131 row_size += 2 * kPopupBorderThickness; | 137 row_size += 2 * kPopupBorderThickness; |
| 132 | 138 |
| 133 return row_size; | 139 return row_size; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); | 191 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); |
| 186 switch (suggestions[index].frontend_id) { | 192 switch (suggestions[index].frontend_id) { |
| 187 case POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE: | 193 case POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE: |
| 188 return gfx::kGoogleRed700; | 194 return gfx::kGoogleRed700; |
| 189 case POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE: | 195 case POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE: |
| 190 return kLabelTextColor; | 196 return kLabelTextColor; |
| 191 default: | 197 default: |
| 192 return kValueTextColor; | 198 return kValueTextColor; |
| 193 } | 199 } |
| 194 } | 200 } |
| 201 | |
| 202 gfx::ImageSkia AutofillPopupLayoutModel::GetIconImage(size_t index) const { | |
| 203 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); | |
| 204 base::string16 icon_str = suggestions[index].icon; | |
|
Evan Stade
2016/11/29 15:23:32
const ref
lshang
2016/11/29 23:48:30
Done.
| |
| 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(icon_str == base::ASCIIToUTF16("httpsInvalid")); | |
|
Evan Stade
2016/11/29 15:23:32
nit: DCHECK_EQ
lshang
2016/11/29 23:48:30
Done.
| |
| 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)); | |
|
Evan Stade
2016/11/29 15:23:32
I believe you have an extra set of parens here
lshang
2016/11/29 23:48:30
Done.
| |
| 223 } | |
| 195 #endif | 224 #endif |
| 196 | 225 |
| 197 int AutofillPopupLayoutModel::LineFromY(int y) const { | 226 int AutofillPopupLayoutModel::LineFromY(int y) const { |
| 198 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); | 227 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); |
| 199 int current_height = kPopupBorderThickness; | 228 int current_height = kPopupBorderThickness; |
| 200 | 229 |
| 201 for (size_t i = 0; i < suggestions.size(); ++i) { | 230 for (size_t i = 0; i < suggestions.size(); ++i) { |
| 202 current_height += GetRowHeightFromId(suggestions[i].frontend_id); | 231 current_height += GetRowHeightFromId(suggestions[i].frontend_id); |
| 203 | 232 |
| 204 if (y <= current_height) | 233 if (y <= current_height) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 #endif | 267 #endif |
| 239 | 268 |
| 240 return result; | 269 return result; |
| 241 } | 270 } |
| 242 | 271 |
| 243 const gfx::Rect AutofillPopupLayoutModel::RoundedElementBounds() const { | 272 const gfx::Rect AutofillPopupLayoutModel::RoundedElementBounds() const { |
| 244 return gfx::ToEnclosingRect(delegate_->element_bounds()); | 273 return gfx::ToEnclosingRect(delegate_->element_bounds()); |
| 245 } | 274 } |
| 246 | 275 |
| 247 } // namespace autofill | 276 } // namespace autofill |
| OLD | NEW |