Chromium Code Reviews| Index: chrome/browser/ui/views/autofill/autofill_popup_view_views.cc |
| diff --git a/chrome/browser/ui/views/autofill/autofill_popup_view_views.cc b/chrome/browser/ui/views/autofill/autofill_popup_view_views.cc |
| index ad9bd1d676f707874ef91c809544bfbe8ca8efab..ca5397921a9ca211f78bf2be64b822f879386ca6 100644 |
| --- a/chrome/browser/ui/views/autofill/autofill_popup_view_views.cc |
| +++ b/chrome/browser/ui/views/autofill/autofill_popup_view_views.cc |
| @@ -150,22 +150,25 @@ void AutofillPopupViewViews::DrawAutofillEntry(gfx::Canvas* canvas, |
| GetNativeTheme()->GetSystemColor( |
| controller_->GetBackgroundColorIDForRow(index))); |
| - const bool is_http_warning = |
| - (controller_->GetSuggestionAt(index).frontend_id == |
| - POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE); |
| + int current_row_frontend_id = controller_->GetSuggestionAt(index).frontend_id; |
|
Evan Stade
2017/07/12 17:53:52
nit: const
also, to shorten the variable name I t
|
| const bool is_rtl = controller_->IsRTL(); |
| const int text_align = |
| is_rtl ? gfx::Canvas::TEXT_ALIGN_RIGHT : gfx::Canvas::TEXT_ALIGN_LEFT; |
| gfx::Rect value_rect = entry_rect; |
| value_rect.Inset(AutofillPopupLayoutModel::kEndPadding, 0); |
| + const bool icon_in_front_of_text = |
| + (current_row_frontend_id == |
| + POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE || |
| + current_row_frontend_id == POPUP_ITEM_ID_ALL_SAVED_PASSWORDS_ENTRY); |
| - // If the icon is on the right of the rect, no matter in RTL or LTR mode. |
| - bool icon_on_the_right = is_http_warning == is_rtl; |
| - int x_align_left = icon_on_the_right ? value_rect.right() : value_rect.x(); |
| - |
| + int x_align_left = is_rtl ? value_rect.x() : value_rect.right(); |
| // Draw the Autofill icon, if one exists |
| - int row_height = controller_->layout_model().GetRowBounds(index).height(); |
| if (!controller_->GetSuggestionAt(index).icon.empty()) { |
| + int row_height = controller_->layout_model().GetRowBounds(index).height(); |
| + // If the icon is on the right of the rect, no matter in RTL or LTR mode. |
| + bool icon_on_the_right = icon_in_front_of_text == is_rtl; |
|
Evan Stade
2017/07/12 17:53:52
nit: const
|
| + x_align_left = icon_on_the_right ? value_rect.right() : value_rect.x(); |
| + |
| const gfx::ImageSkia image = |
| controller_->layout_model().GetIconImage(index); |
| int icon_y = entry_rect.y() + (row_height - image.height()) / 2; |
| @@ -175,28 +178,24 @@ void AutofillPopupViewViews::DrawAutofillEntry(gfx::Canvas* canvas, |
| canvas->DrawImageInt(image, icon_x_align_left, icon_y); |
| + const int width_icon_padding = |
| + image.width() + |
| + (icon_in_front_of_text |
| + ? AutofillPopupLayoutModel::kPaddingBetweenLeftSideIconAndText |
| + : AutofillPopupLayoutModel::kIconPadding); |
| + |
| // An icon was drawn; adjust the |x_align_left| value for the next element. |
| - if (is_http_warning) { |
| - x_align_left = |
| - icon_x_align_left + |
| - (is_rtl ? -AutofillPopupLayoutModel::kHttpWarningIconPadding |
| - : image.width() + |
| - AutofillPopupLayoutModel::kHttpWarningIconPadding); |
| - } else { |
| - x_align_left = |
| - icon_x_align_left + |
| - (is_rtl ? image.width() + AutofillPopupLayoutModel::kIconPadding |
| - : -AutofillPopupLayoutModel::kIconPadding); |
| - } |
| + x_align_left = x_align_left + (icon_on_the_right ? -width_icon_padding |
| + : width_icon_padding); |
| } |
| - // Draw the value text |
| + // Draw the value text. |
| const int value_width = gfx::GetStringWidth( |
| controller_->GetElidedValueAt(index), |
| controller_->layout_model().GetValueFontListForRow(index)); |
| int value_x_align_left = x_align_left; |
| - if (is_http_warning) { |
| + if (icon_in_front_of_text) { |
| value_x_align_left += is_rtl ? -value_width : 0; |
| } else { |
| value_x_align_left = |
| @@ -219,15 +218,15 @@ void AutofillPopupViewViews::DrawAutofillEntry(gfx::Canvas* canvas, |
| controller_->layout_model().GetLabelFontListForRow(index)); |
| int label_x_align_left = x_align_left; |
| - if (is_http_warning) { |
| + if (icon_in_front_of_text) { |
| label_x_align_left = |
| is_rtl ? value_rect.x() : value_rect.right() - label_width; |
| } else { |
| label_x_align_left += is_rtl ? 0 : -label_width; |
| } |
| - // TODO(crbug.com/678033):Add a GetLabelFontColorForRow function similar to |
| - // GetValueFontColorForRow so that the cocoa impl could use it too |
| + // TODO(crbug.com/678033): Add a GetLabelFontColorForRow function similar to |
| + // GetValueFontColorForRow so that the cocoa impl could use it too. |
| canvas->DrawStringRectWithFlags( |
| controller_->GetElidedLabelAt(index), |
| controller_->layout_model().GetLabelFontListForRow(index), |