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 44cb516869e0c3c887a38410464d108fc1485350..b7481c40a3652ce60c366d63313e98ca92937d94 100644 |
| --- a/chrome/browser/ui/views/autofill/autofill_popup_view_views.cc |
| +++ b/chrome/browser/ui/views/autofill/autofill_popup_view_views.cc |
| @@ -67,26 +67,47 @@ void AutofillPopupViewViews::InvalidateRow(size_t row) { |
| SchedulePaintInRect(controller_->layout_model().GetRowBounds(row)); |
| } |
| +/** |
| +* Autofill entries in ltr. |
| +* |
| +* ............................................................................ |
| +* . ICON | HTTP WARNING MESSAGE VALUE | LABEL . |
| +* ............................................................................ |
| +* . OTHER AUTOFILL ENTRY VALUE | LABEL | ICON . |
| +* ............................................................................ |
| +* |
| +* Autofill entries in rtl. |
| +* |
| +* ............................................................................ |
| +* . LABEL | HTTP WARNING MESSAGE VALUE | ICON . |
| +* ............................................................................ |
| +* . ICON | LABEL | OTHER AUTOFILL ENTRY VALUE . |
| +* ............................................................................ |
| +* |
| +* Anyone who wants to modify the code below, remember to make sure that HTTP |
| +* warning entry displays right. To trigger the warning message entry, enable |
| +* #mark-non-secure-as flag as "display form warning", go to goo.gl/CEIjc6 with |
| +* stored autofill info and check for credit card or password forms. |
| +*/ |
| void AutofillPopupViewViews::DrawAutofillEntry(gfx::Canvas* canvas, |
| int index, |
| const gfx::Rect& entry_rect) { |
| canvas->FillRect(entry_rect, controller_->GetBackgroundColorForRow(index)); |
| + const bool is_http_warning = |
| + (controller_->GetSuggestionAt(index).frontend_id == |
| + POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE); |
| 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); |
| - canvas->DrawStringRectWithFlags( |
| - controller_->GetElidedValueAt(index), |
| - controller_->layout_model().GetValueFontListForRow(index), |
| - controller_->layout_model().GetValueFontColorForRow(index), value_rect, |
| - text_align); |
| - // Use this to figure out where all the other Autofill items should be placed. |
| - int x_align_left = |
| - is_rtl ? AutofillPopupLayoutModel::kEndPadding |
| - : entry_rect.right() - AutofillPopupLayoutModel::kEndPadding; |
| + int icon_x_align_left = 0; |
| + if ((is_http_warning && !is_rtl) || (!is_http_warning && is_rtl)) |
|
Evan Stade
2016/11/29 15:43:17
nit: is_http_warning != is_rtl
lshang
2016/11/30 05:43:36
Done.
|
| + icon_x_align_left = value_rect.x(); |
| + else |
| + icon_x_align_left = value_rect.right(); |
| // Draw the Autofill icon, if one exists |
| int row_height = controller_->layout_model().GetRowBounds(index).height(); |
| @@ -95,27 +116,67 @@ void AutofillPopupViewViews::DrawAutofillEntry(gfx::Canvas* canvas, |
| controller_->layout_model().GetIconImage(index); |
| int icon_y = entry_rect.y() + (row_height - image.height()) / 2; |
| - x_align_left += is_rtl ? 0 : -image.width(); |
| + if (icon_x_align_left == value_rect.right()) |
|
Evan Stade
2016/11/29 15:43:17
nit: can you save the result of the directionality
lshang
2016/11/30 05:43:36
Done.
|
| + icon_x_align_left -= image.width(); |
| - canvas->DrawImageInt(image, x_align_left, icon_y); |
| + canvas->DrawImageInt(image, icon_x_align_left, icon_y); |
| - x_align_left += is_rtl |
| - ? image.width() + AutofillPopupLayoutModel::kIconPadding |
| - : -AutofillPopupLayoutModel::kIconPadding; |
| + // An icon was drawn; adjust the |icon_x_align_start| value for the next |
| + // element. |
| + if (is_http_warning) { |
| + icon_x_align_left += |
|
Evan Stade
2016/11/29 15:43:17
after this statement, this variable no longer real
lshang
2016/11/30 05:43:36
Done.
|
| + is_rtl ? -AutofillPopupLayoutModel::kHttpWarningIconPadding |
| + : image.width() + |
| + AutofillPopupLayoutModel::kHttpWarningIconPadding; |
| + } else { |
| + icon_x_align_left += |
| + is_rtl ? image.width() + AutofillPopupLayoutModel::kIconPadding |
| + : -AutofillPopupLayoutModel::kIconPadding; |
| + } |
| } |
| - // Draw the label text. |
| - const int label_width = |
| - gfx::GetStringWidth(controller_->GetElidedLabelAt(index), |
| - controller_->layout_model().GetLabelFontList()); |
| - if (!is_rtl) |
| - x_align_left -= label_width; |
| + // Draw the value text |
| + const int value_width = gfx::GetStringWidth( |
| + controller_->GetElidedValueAt(index), |
| + controller_->layout_model().GetValueFontListForRow(index)); |
| + int value_x_align_left = icon_x_align_left; |
| + |
| + if (is_http_warning) { |
| + value_x_align_left += is_rtl ? -value_width : 0; |
| + } else { |
| + value_x_align_left = |
| + is_rtl ? value_rect.right() - value_width : value_rect.x(); |
| + } |
| canvas->DrawStringRectWithFlags( |
| - controller_->GetElidedLabelAt(index), |
| - controller_->layout_model().GetLabelFontList(), kLabelTextColor, |
| - gfx::Rect(x_align_left, entry_rect.y(), label_width, entry_rect.height()), |
| + controller_->GetElidedValueAt(index), |
| + controller_->layout_model().GetValueFontListForRow(index), |
| + controller_->layout_model().GetValueFontColorForRow(index), |
| + gfx::Rect(value_x_align_left, value_rect.y(), value_width, |
| + value_rect.height()), |
| text_align); |
| + |
| + // Draw the label text, if one exists. |
| + if (!controller_->GetSuggestionAt(index).label.empty()) { |
| + const int label_width = gfx::GetStringWidth( |
| + controller_->GetElidedLabelAt(index), |
| + controller_->layout_model().GetLabelFontListForRow(index)); |
| + int label_x_align_left = icon_x_align_left; |
| + |
| + if (is_http_warning) { |
| + label_x_align_left = |
| + is_rtl ? value_rect.x() : value_rect.right() - label_width; |
| + } else { |
| + label_x_align_left += is_rtl ? 0 : -label_width; |
| + } |
| + |
| + canvas->DrawStringRectWithFlags( |
| + controller_->GetElidedLabelAt(index), |
| + controller_->layout_model().GetLabelFontListForRow(index), |
| + kLabelTextColor, gfx::Rect(label_x_align_left, entry_rect.y(), |
| + label_width, entry_rect.height()), |
| + text_align); |
| + } |
| } |
| AutofillPopupView* AutofillPopupView::Create( |