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 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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_warning_message = (suggestions[row].frontend_id == |
| 125 POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE); | 126 POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE); |
| 126 | 127 |
| 127 int row_size = kEndPadding; | 128 int row_size = kEndPadding; |
| 128 | 129 |
| 129 if (with_label) | 130 if (with_label) |
| 130 row_size += is_warning_message ? kHttpWarningNamePadding : kNamePadding; | 131 row_size += is_warning_message ? kHttpWarningNamePadding : kNamePadding; |
|
vasilii
2017/07/06 15:15:21
It's strange that kHttpWarningNamePadding isn't us
| |
| 131 | 132 |
| 132 // Add the Autofill icon size, if required. | 133 // Add the Autofill icon size, if required. |
| 133 const base::string16& icon = suggestions[row].icon; | 134 const base::string16& icon = suggestions[row].icon; |
| 134 if (!icon.empty()) { | 135 if (!icon.empty()) { |
| 135 row_size += GetIconImage(row).width() + | 136 row_size += GetIconImage(row).width() + |
| 136 (is_warning_message ? kHttpWarningIconPadding : kIconPadding); | 137 (is_warning_message ? kRightHandSideIconPapping : kIconPadding); |
|
vasilii
2017/07/06 15:15:21
Isn't it applicable to the new state too?
It seems
melandory
2017/07/07 12:26:31
Done.
| |
| 137 } | 138 } |
| 138 | 139 |
| 139 // Add the padding at the end. | 140 // Add the padding at the end. |
| 140 row_size += kEndPadding; | 141 row_size += kEndPadding; |
| 141 | 142 |
| 142 // Add room for the popup border. | 143 // Add room for the popup border. |
| 143 row_size += 2 * kPopupBorderThickness; | 144 row_size += 2 * kPopupBorderThickness; |
| 144 | 145 |
| 145 return row_size; | 146 return row_size; |
| 146 } | 147 } |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 173 case POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE: | 174 case POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE: |
| 174 case POPUP_ITEM_ID_CLEAR_FORM: | 175 case POPUP_ITEM_ID_CLEAR_FORM: |
| 175 case POPUP_ITEM_ID_CREDIT_CARD_SIGNIN_PROMO: | 176 case POPUP_ITEM_ID_CREDIT_CARD_SIGNIN_PROMO: |
| 176 case POPUP_ITEM_ID_AUTOFILL_OPTIONS: | 177 case POPUP_ITEM_ID_AUTOFILL_OPTIONS: |
| 177 case POPUP_ITEM_ID_CREATE_HINT: | 178 case POPUP_ITEM_ID_CREATE_HINT: |
| 178 case POPUP_ITEM_ID_SCAN_CREDIT_CARD: | 179 case POPUP_ITEM_ID_SCAN_CREDIT_CARD: |
| 179 case POPUP_ITEM_ID_SEPARATOR: | 180 case POPUP_ITEM_ID_SEPARATOR: |
| 180 case POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE: | 181 case POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE: |
| 181 case POPUP_ITEM_ID_TITLE: | 182 case POPUP_ITEM_ID_TITLE: |
| 182 case POPUP_ITEM_ID_PASSWORD_ENTRY: | 183 case POPUP_ITEM_ID_PASSWORD_ENTRY: |
| 184 case POPUP_ITEM_ID_ALL_SAVED_PASSWORDS_ENTRY: | |
| 183 return normal_font_list_; | 185 return normal_font_list_; |
| 184 case POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY: | 186 case POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY: |
| 185 case POPUP_ITEM_ID_DATALIST_ENTRY: | 187 case POPUP_ITEM_ID_DATALIST_ENTRY: |
| 186 case POPUP_ITEM_ID_USERNAME_ENTRY: | 188 case POPUP_ITEM_ID_USERNAME_ENTRY: |
| 187 return bold_font_list_; | 189 return bold_font_list_; |
| 188 } | 190 } |
| 189 NOTREACHED(); | 191 NOTREACHED(); |
| 190 return normal_font_list_; | 192 return normal_font_list_; |
| 191 } | 193 } |
| 192 | 194 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 223 POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE) { | 225 POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE) { |
| 224 if (icon_str == base::ASCIIToUTF16("httpWarning")) { | 226 if (icon_str == base::ASCIIToUTF16("httpWarning")) { |
| 225 return gfx::CreateVectorIcon(toolbar::kHttpIcon, kHttpWarningIconWidth, | 227 return gfx::CreateVectorIcon(toolbar::kHttpIcon, kHttpWarningIconWidth, |
| 226 gfx::kChromeIconGrey); | 228 gfx::kChromeIconGrey); |
| 227 } | 229 } |
| 228 DCHECK_EQ(icon_str, base::ASCIIToUTF16("httpsInvalid")); | 230 DCHECK_EQ(icon_str, base::ASCIIToUTF16("httpsInvalid")); |
| 229 return gfx::CreateVectorIcon(toolbar::kHttpsInvalidIcon, | 231 return gfx::CreateVectorIcon(toolbar::kHttpsInvalidIcon, |
| 230 kHttpWarningIconWidth, gfx::kGoogleRed700); | 232 kHttpWarningIconWidth, gfx::kGoogleRed700); |
| 231 } | 233 } |
| 232 | 234 |
| 235 if (icon_str == base::ASCIIToUTF16("showAllSavedPasswords")) { | |
| 236 return gfx::CreateVectorIcon(kShowAllSavedPasswordsIcon, | |
| 237 kHttpWarningIconWidth, gfx::kChromeIconGrey); | |
| 238 } | |
| 239 | |
| 233 // For other suggestion entries, get icon from PNG files. | 240 // For other suggestion entries, get icon from PNG files. |
| 234 int icon_id = GetIconResourceID(icon_str); | 241 int icon_id = GetIconResourceID(icon_str); |
| 235 DCHECK_NE(-1, icon_id); | 242 DCHECK_NE(-1, icon_id); |
| 236 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(icon_id); | 243 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(icon_id); |
| 237 } | 244 } |
| 238 #endif | 245 #endif |
| 239 | 246 |
| 240 int AutofillPopupLayoutModel::LineFromY(int y) const { | 247 int AutofillPopupLayoutModel::LineFromY(int y) const { |
| 241 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); | 248 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); |
| 242 int current_height = kPopupBorderThickness; | 249 int current_height = kPopupBorderThickness; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 bool AutofillPopupLayoutModel::IsIconAtStart(int frontend_id) const { | 311 bool AutofillPopupLayoutModel::IsIconAtStart(int frontend_id) const { |
| 305 return frontend_id == POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE || | 312 return frontend_id == POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE || |
| 306 (is_credit_card_popup_ && IsIconInCreditCardPopupAtStart()); | 313 (is_credit_card_popup_ && IsIconInCreditCardPopupAtStart()); |
| 307 } | 314 } |
| 308 | 315 |
| 309 unsigned int AutofillPopupLayoutModel::GetMargin() const { | 316 unsigned int AutofillPopupLayoutModel::GetMargin() const { |
| 310 return GetPopupMargin(); | 317 return GetPopupMargin(); |
| 311 } | 318 } |
| 312 | 319 |
| 313 } // namespace autofill | 320 } // namespace autofill |
| OLD | NEW |