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/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 |
| 39 // The vertical height of a separator in pixels. | 40 // The vertical height of a separator in pixels. |
| 40 const size_t kSeparatorHeight = 1; | 41 const size_t kSeparatorHeight = 1; |
| 41 | 42 |
| 42 #if !defined(OS_ANDROID) | 43 #if !defined(OS_ANDROID) |
| 43 // Size difference between the normal font and the smaller font, in pixels. | 44 // Size difference between the normal font and the smaller font, in pixels. |
| 44 const int kSmallerFontSizeDelta = -1; | 45 const int kSmallerFontSizeDelta = -1; |
| 45 | 46 |
| 46 const int kHttpWarningIconWidth = 16; | 47 const int kRowWithLeftHandsideIcon = 16; |
|
vasilii
2017/07/13 16:11:51
Confusing. The name shouldn't include 'Row' but sh
Evan Stade
2017/07/13 16:48:43
I would define this in the one function where it's
melandory
2017/07/25 15:08:49
Done.
| |
| 47 #endif | 48 #endif |
| 48 | 49 |
| 49 const struct { | 50 const struct { |
| 50 const char* name; | 51 const char* name; |
| 51 int id; | 52 int id; |
| 52 } kDataResources[] = { | 53 } kDataResources[] = { |
| 53 {autofill::kAmericanExpressCard, IDR_AUTOFILL_CC_AMEX}, | 54 {autofill::kAmericanExpressCard, IDR_AUTOFILL_CC_AMEX}, |
| 54 {autofill::kDinersCard, IDR_AUTOFILL_CC_DINERS}, | 55 {autofill::kDinersCard, IDR_AUTOFILL_CC_DINERS}, |
| 55 {autofill::kDiscoverCard, IDR_AUTOFILL_CC_DISCOVER}, | 56 {autofill::kDiscoverCard, IDR_AUTOFILL_CC_DISCOVER}, |
| 56 {autofill::kEloCard, IDR_AUTOFILL_CC_ELO}, | 57 {autofill::kEloCard, IDR_AUTOFILL_CC_ELO}, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 } | 104 } |
| 104 | 105 |
| 105 int AutofillPopupLayoutModel::GetDesiredPopupWidth() const { | 106 int AutofillPopupLayoutModel::GetDesiredPopupWidth() const { |
| 106 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); | 107 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); |
| 107 | 108 |
| 108 int popup_width = RoundedElementBounds().width(); | 109 int popup_width = RoundedElementBounds().width(); |
| 109 | 110 |
| 110 for (size_t i = 0; i < suggestions.size(); ++i) { | 111 for (size_t i = 0; i < suggestions.size(); ++i) { |
| 111 int label_size = delegate_->GetElidedLabelWidthForRow(i); | 112 int label_size = delegate_->GetElidedLabelWidthForRow(i); |
| 112 int row_size = delegate_->GetElidedValueWidthForRow(i) + label_size + | 113 int row_size = delegate_->GetElidedValueWidthForRow(i) + label_size + |
| 113 RowWidthWithoutText(i, /* with_label= */ label_size > 0); | 114 RowWidthWithoutText(i, /* has_substext= */ label_size > 0); |
| 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 has_substext) 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_warning_message = (suggestions[row].frontend_id == |
| 125 POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE); | 126 POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE); |
| 127 const bool is_row_with_icon_positioned_at_start = | |
| 128 (is_warning_message || (suggestions[row].frontend_id == | |
| 129 POPUP_ITEM_ID_ALL_SAVED_PASSWORDS_ENTRY)); | |
| 126 | 130 |
| 127 int row_size = kEndPadding; | 131 int row_size = 2 * (kEndPadding + kPopupBorderThickness); |
| 128 | 132 if (has_substext) { |
| 129 if (with_label) | |
| 130 row_size += is_warning_message ? kHttpWarningNamePadding : kNamePadding; | 133 row_size += is_warning_message ? kHttpWarningNamePadding : kNamePadding; |
| 134 } | |
|
Evan Stade
2017/07/13 16:48:43
nit: no curlies
melandory
2017/07/25 15:08:49
Done.
| |
| 131 | 135 |
| 132 // Add the Autofill icon size, if required. | 136 // Add the Autofill icon size, if required. |
| 133 const base::string16& icon = suggestions[row].icon; | 137 const base::string16& icon = suggestions[row].icon; |
| 134 if (!icon.empty()) { | 138 if (!icon.empty()) { |
| 135 row_size += GetIconImage(row).width() + | 139 row_size += |
| 136 (is_warning_message ? kHttpWarningIconPadding : kIconPadding); | 140 GetIconImage(row).width() + (is_row_with_icon_positioned_at_start |
| 141 ? kPaddingBetweenLeftSideIconAndText | |
| 142 : kIconPadding); | |
| 137 } | 143 } |
| 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; | 144 return row_size; |
| 146 } | 145 } |
| 147 | 146 |
| 148 int AutofillPopupLayoutModel::GetAvailableWidthForRow(int row, | 147 int AutofillPopupLayoutModel::GetAvailableWidthForRow(int row, |
| 149 bool with_label) const { | 148 bool has_substext) const { |
| 150 return popup_bounds_.width() - RowWidthWithoutText(row, with_label); | 149 return popup_bounds_.width() - RowWidthWithoutText(row, has_substext); |
| 151 } | 150 } |
| 152 | 151 |
| 153 void AutofillPopupLayoutModel::UpdatePopupBounds() { | 152 void AutofillPopupLayoutModel::UpdatePopupBounds() { |
| 154 int popup_width = GetDesiredPopupWidth(); | 153 int popup_width = GetDesiredPopupWidth(); |
| 155 int popup_height = GetDesiredPopupHeight(); | 154 int popup_height = GetDesiredPopupHeight(); |
| 156 | 155 |
| 157 popup_bounds_ = view_common_.CalculatePopupBounds( | 156 popup_bounds_ = view_common_.CalculatePopupBounds( |
| 158 popup_width, popup_height, RoundedElementBounds(), | 157 popup_width, popup_height, RoundedElementBounds(), |
| 159 delegate_->container_view(), delegate_->IsRTL()); | 158 delegate_->container_view(), delegate_->IsRTL()); |
| 160 } | 159 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 173 case POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE: | 172 case POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE: |
| 174 case POPUP_ITEM_ID_CLEAR_FORM: | 173 case POPUP_ITEM_ID_CLEAR_FORM: |
| 175 case POPUP_ITEM_ID_CREDIT_CARD_SIGNIN_PROMO: | 174 case POPUP_ITEM_ID_CREDIT_CARD_SIGNIN_PROMO: |
| 176 case POPUP_ITEM_ID_AUTOFILL_OPTIONS: | 175 case POPUP_ITEM_ID_AUTOFILL_OPTIONS: |
| 177 case POPUP_ITEM_ID_CREATE_HINT: | 176 case POPUP_ITEM_ID_CREATE_HINT: |
| 178 case POPUP_ITEM_ID_SCAN_CREDIT_CARD: | 177 case POPUP_ITEM_ID_SCAN_CREDIT_CARD: |
| 179 case POPUP_ITEM_ID_SEPARATOR: | 178 case POPUP_ITEM_ID_SEPARATOR: |
| 180 case POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE: | 179 case POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE: |
| 181 case POPUP_ITEM_ID_TITLE: | 180 case POPUP_ITEM_ID_TITLE: |
| 182 case POPUP_ITEM_ID_PASSWORD_ENTRY: | 181 case POPUP_ITEM_ID_PASSWORD_ENTRY: |
| 182 case POPUP_ITEM_ID_ALL_SAVED_PASSWORDS_ENTRY: | |
| 183 return normal_font_list_; | 183 return normal_font_list_; |
| 184 case POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY: | 184 case POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY: |
| 185 case POPUP_ITEM_ID_DATALIST_ENTRY: | 185 case POPUP_ITEM_ID_DATALIST_ENTRY: |
| 186 case POPUP_ITEM_ID_USERNAME_ENTRY: | 186 case POPUP_ITEM_ID_USERNAME_ENTRY: |
| 187 return bold_font_list_; | 187 return bold_font_list_; |
| 188 } | 188 } |
| 189 NOTREACHED(); | 189 NOTREACHED(); |
| 190 return normal_font_list_; | 190 return normal_font_list_; |
| 191 } | 191 } |
| 192 | 192 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 212 return ui::NativeTheme::kColorId_ResultsTableNormalText; | 212 return ui::NativeTheme::kColorId_ResultsTableNormalText; |
| 213 } | 213 } |
| 214 } | 214 } |
| 215 | 215 |
| 216 gfx::ImageSkia AutofillPopupLayoutModel::GetIconImage(size_t index) const { | 216 gfx::ImageSkia AutofillPopupLayoutModel::GetIconImage(size_t index) const { |
| 217 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); | 217 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); |
| 218 const base::string16& icon_str = suggestions[index].icon; | 218 const base::string16& icon_str = suggestions[index].icon; |
| 219 | 219 |
| 220 // For http warning message, get icon images from VectorIcon, which is the | 220 // For http warning message, get icon images from VectorIcon, which is the |
| 221 // same as security indicator icons in location bar. | 221 // same as security indicator icons in location bar. |
| 222 if (suggestions[index].frontend_id == | 222 if (icon_str == base::ASCIIToUTF16("httpWarning")) { |
| 223 POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE) { | 223 return gfx::CreateVectorIcon(toolbar::kHttpIcon, kRowWithLeftHandsideIcon, |
| 224 if (icon_str == base::ASCIIToUTF16("httpWarning")) { | 224 gfx::kChromeIconGrey); |
| 225 return gfx::CreateVectorIcon(toolbar::kHttpIcon, kHttpWarningIconWidth, | 225 } |
| 226 gfx::kChromeIconGrey); | 226 if (icon_str == base::ASCIIToUTF16("httpsInvalid")) { |
| 227 } | |
| 228 DCHECK_EQ(icon_str, base::ASCIIToUTF16("httpsInvalid")); | |
| 229 return gfx::CreateVectorIcon(toolbar::kHttpsInvalidIcon, | 227 return gfx::CreateVectorIcon(toolbar::kHttpsInvalidIcon, |
| 230 kHttpWarningIconWidth, gfx::kGoogleRed700); | 228 kRowWithLeftHandsideIcon, gfx::kGoogleRed700); |
| 229 } | |
| 230 | |
| 231 if (icon_str == base::ASCIIToUTF16("showAllSavedPasswords")) { | |
| 232 return gfx::CreateVectorIcon(kShowAllSavedPasswordsIcon, | |
| 233 kRowWithLeftHandsideIcon, | |
| 234 gfx::kChromeIconGrey); | |
| 231 } | 235 } |
| 232 | 236 |
| 233 // For other suggestion entries, get icon from PNG files. | 237 // For other suggestion entries, get icon from PNG files. |
| 234 int icon_id = GetIconResourceID(icon_str); | 238 int icon_id = GetIconResourceID(icon_str); |
| 235 DCHECK_NE(-1, icon_id); | 239 DCHECK_NE(-1, icon_id); |
| 236 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(icon_id); | 240 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(icon_id); |
| 237 } | 241 } |
| 238 #endif | 242 #endif // !defined(OS_ANDROID) |
| 239 | 243 |
| 240 int AutofillPopupLayoutModel::LineFromY(int y) const { | 244 int AutofillPopupLayoutModel::LineFromY(int y) const { |
| 241 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); | 245 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); |
| 242 int current_height = kPopupBorderThickness; | 246 int current_height = kPopupBorderThickness; |
| 243 | 247 |
| 244 for (size_t i = 0; i < suggestions.size(); ++i) { | 248 for (size_t i = 0; i < suggestions.size(); ++i) { |
| 245 current_height += GetRowHeightFromId(suggestions[i].frontend_id); | 249 current_height += GetRowHeightFromId(suggestions[i].frontend_id); |
| 246 | 250 |
| 247 if (y <= current_height) | 251 if (y <= current_height) |
| 248 return i; | 252 return i; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 bool AutofillPopupLayoutModel::IsIconAtStart(int frontend_id) const { | 308 bool AutofillPopupLayoutModel::IsIconAtStart(int frontend_id) const { |
| 305 return frontend_id == POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE || | 309 return frontend_id == POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE || |
| 306 (is_credit_card_popup_ && IsIconInCreditCardPopupAtStart()); | 310 (is_credit_card_popup_ && IsIconInCreditCardPopupAtStart()); |
| 307 } | 311 } |
| 308 | 312 |
| 309 unsigned int AutofillPopupLayoutModel::GetMargin() const { | 313 unsigned int AutofillPopupLayoutModel::GetMargin() const { |
| 310 return GetPopupMargin(); | 314 return GetPopupMargin(); |
| 311 } | 315 } |
| 312 | 316 |
| 313 } // namespace autofill | 317 } // namespace autofill |
| OLD | NEW |