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/font_list.h" | 19 #include "ui/gfx/font_list.h" |
19 #include "ui/gfx/geometry/rect_conversions.h" | 20 #include "ui/gfx/geometry/rect_conversions.h" |
20 | 21 |
21 namespace autofill { | 22 namespace autofill { |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 // The vertical height of each row in pixels. | 26 // The vertical height of each row in pixels. |
26 const size_t kRowHeight = 24; | 27 const size_t kRowHeight = 24; |
27 | 28 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 size_t index) const { | 151 size_t index) const { |
151 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); | 152 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); |
152 | 153 |
153 // Autofill values have positive |frontend_id|. | 154 // Autofill values have positive |frontend_id|. |
154 if (suggestions[index].frontend_id > 0) | 155 if (suggestions[index].frontend_id > 0) |
155 return bold_font_list_; | 156 return bold_font_list_; |
156 | 157 |
157 // All other message types are defined here. | 158 // All other message types are defined here. |
158 PopupItemId id = static_cast<PopupItemId>(suggestions[index].frontend_id); | 159 PopupItemId id = static_cast<PopupItemId>(suggestions[index].frontend_id); |
159 switch (id) { | 160 switch (id) { |
160 case POPUP_ITEM_ID_WARNING_MESSAGE: | 161 case POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE: |
161 return warning_font_list_; | 162 return warning_font_list_; |
162 case POPUP_ITEM_ID_CLEAR_FORM: | 163 case POPUP_ITEM_ID_CLEAR_FORM: |
163 case POPUP_ITEM_ID_CREDIT_CARD_SIGNIN_PROMO: | 164 case POPUP_ITEM_ID_CREDIT_CARD_SIGNIN_PROMO: |
164 case POPUP_ITEM_ID_AUTOFILL_OPTIONS: | 165 case POPUP_ITEM_ID_AUTOFILL_OPTIONS: |
165 case POPUP_ITEM_ID_SCAN_CREDIT_CARD: | 166 case POPUP_ITEM_ID_SCAN_CREDIT_CARD: |
166 case POPUP_ITEM_ID_SEPARATOR: | 167 case POPUP_ITEM_ID_SEPARATOR: |
| 168 case POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE: |
167 return normal_font_list_; | 169 return normal_font_list_; |
168 case POPUP_ITEM_ID_TITLE: | 170 case POPUP_ITEM_ID_TITLE: |
169 case POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY: | 171 case POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY: |
170 case POPUP_ITEM_ID_DATALIST_ENTRY: | 172 case POPUP_ITEM_ID_DATALIST_ENTRY: |
171 case POPUP_ITEM_ID_PASSWORD_ENTRY: | 173 case POPUP_ITEM_ID_PASSWORD_ENTRY: |
172 return bold_font_list_; | 174 return bold_font_list_; |
173 } | 175 } |
174 NOTREACHED(); | 176 NOTREACHED(); |
175 return normal_font_list_; | 177 return normal_font_list_; |
176 } | 178 } |
177 | 179 |
178 const gfx::FontList& AutofillPopupLayoutModel::GetLabelFontList() const { | 180 const gfx::FontList& AutofillPopupLayoutModel::GetLabelFontList() const { |
179 return smaller_font_list_; | 181 return smaller_font_list_; |
180 } | 182 } |
| 183 |
| 184 SkColor AutofillPopupLayoutModel::GetValueFontColorForRow(size_t index) const { |
| 185 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); |
| 186 switch (suggestions[index].frontend_id) { |
| 187 case POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE: |
| 188 return gfx::kGoogleRed700; |
| 189 case POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE: |
| 190 return kLabelTextColor; |
| 191 default: |
| 192 return kValueTextColor; |
| 193 } |
| 194 } |
181 #endif | 195 #endif |
182 | 196 |
183 int AutofillPopupLayoutModel::LineFromY(int y) const { | 197 int AutofillPopupLayoutModel::LineFromY(int y) const { |
184 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); | 198 std::vector<autofill::Suggestion> suggestions = delegate_->GetSuggestions(); |
185 int current_height = kPopupBorderThickness; | 199 int current_height = kPopupBorderThickness; |
186 | 200 |
187 for (size_t i = 0; i < suggestions.size(); ++i) { | 201 for (size_t i = 0; i < suggestions.size(); ++i) { |
188 current_height += GetRowHeightFromId(suggestions[i].frontend_id); | 202 current_height += GetRowHeightFromId(suggestions[i].frontend_id); |
189 | 203 |
190 if (y <= current_height) | 204 if (y <= current_height) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 #endif | 238 #endif |
225 | 239 |
226 return result; | 240 return result; |
227 } | 241 } |
228 | 242 |
229 const gfx::Rect AutofillPopupLayoutModel::RoundedElementBounds() const { | 243 const gfx::Rect AutofillPopupLayoutModel::RoundedElementBounds() const { |
230 return gfx::ToEnclosingRect(delegate_->element_bounds()); | 244 return gfx::ToEnclosingRect(delegate_->element_bounds()); |
231 } | 245 } |
232 | 246 |
233 } // namespace autofill | 247 } // namespace autofill |
OLD | NEW |