Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/views/autofill/autofill_popup_view_views.h" | 5 #include "chrome/browser/ui/views/autofill/autofill_popup_view_views.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" | 7 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" |
| 8 #include "chrome/browser/ui/autofill/autofill_popup_layout_model.h" | 8 #include "chrome/browser/ui/autofill/autofill_popup_layout_model.h" |
| 9 #include "chrome/browser/ui/autofill/popup_constants.h" | 9 #include "chrome/browser/ui/autofill/popup_constants.h" |
| 10 #include "components/autofill/core/browser/popup_item_ids.h" | 10 #include "components/autofill/core/browser/popup_item_ids.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 } else { | 60 } else { |
| 61 DrawAutofillEntry(canvas, i, line_rect); | 61 DrawAutofillEntry(canvas, i, line_rect); |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 | 65 |
| 66 void AutofillPopupViewViews::InvalidateRow(size_t row) { | 66 void AutofillPopupViewViews::InvalidateRow(size_t row) { |
| 67 SchedulePaintInRect(controller_->layout_model().GetRowBounds(row)); | 67 SchedulePaintInRect(controller_->layout_model().GetRowBounds(row)); |
| 68 } | 68 } |
| 69 | 69 |
| 70 /** | |
| 71 * Autofill entries in ltr. | |
| 72 * | |
| 73 * ............................................................................ | |
| 74 * . ICON | HTTP WARNING MESSAGE VALUE | LABEL . | |
| 75 * ............................................................................ | |
| 76 * . OTHER AUTOFILL ENTRY VALUE | LABEL | ICON . | |
| 77 * ............................................................................ | |
| 78 * | |
| 79 * Autofill entries in rtl. | |
| 80 * | |
| 81 * ............................................................................ | |
| 82 * . LABEL | HTTP WARNING MESSAGE VALUE | ICON . | |
| 83 * ............................................................................ | |
| 84 * . ICON | LABEL | OTHER AUTOFILL ENTRY VALUE . | |
| 85 * ............................................................................ | |
| 86 * | |
| 87 * Anyone who wants to modify the code below, remember to make sure that HTTP | |
| 88 * warning entry displays right. To trigger the warning message entry, enable | |
| 89 * #mark-non-secure-as flag as "display form warning", go to goo.gl/CEIjc6 with | |
| 90 * stored autofill info and check for credit card or password forms. | |
| 91 */ | |
| 70 void AutofillPopupViewViews::DrawAutofillEntry(gfx::Canvas* canvas, | 92 void AutofillPopupViewViews::DrawAutofillEntry(gfx::Canvas* canvas, |
| 71 int index, | 93 int index, |
| 72 const gfx::Rect& entry_rect) { | 94 const gfx::Rect& entry_rect) { |
| 73 canvas->FillRect(entry_rect, controller_->GetBackgroundColorForRow(index)); | 95 canvas->FillRect(entry_rect, controller_->GetBackgroundColorForRow(index)); |
| 74 | 96 |
| 97 const bool is_http_warning = | |
| 98 (controller_->GetSuggestionAt(index).frontend_id == | |
| 99 POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE); | |
| 75 const bool is_rtl = controller_->IsRTL(); | 100 const bool is_rtl = controller_->IsRTL(); |
| 76 const int text_align = | 101 const int text_align = |
| 77 is_rtl ? gfx::Canvas::TEXT_ALIGN_RIGHT : gfx::Canvas::TEXT_ALIGN_LEFT; | 102 is_rtl ? gfx::Canvas::TEXT_ALIGN_RIGHT : gfx::Canvas::TEXT_ALIGN_LEFT; |
| 78 gfx::Rect value_rect = entry_rect; | 103 gfx::Rect value_rect = entry_rect; |
| 79 value_rect.Inset(AutofillPopupLayoutModel::kEndPadding, 0); | 104 value_rect.Inset(AutofillPopupLayoutModel::kEndPadding, 0); |
| 80 canvas->DrawStringRectWithFlags( | |
| 81 controller_->GetElidedValueAt(index), | |
| 82 controller_->layout_model().GetValueFontListForRow(index), | |
| 83 controller_->layout_model().GetValueFontColorForRow(index), value_rect, | |
| 84 text_align); | |
| 85 | 105 |
| 86 // Use this to figure out where all the other Autofill items should be placed. | 106 int x_align_left = 0; |
| 87 int x_align_left = | 107 // If the icon is on the right of the rect, no matter in RTL or LTR mode. |
| 88 is_rtl ? AutofillPopupLayoutModel::kEndPadding | 108 bool icon_on_the_right = false; |
|
Evan Stade
2016/11/30 16:22:30
I was kind of thinking
bool icon_on_the_left = is
lshang
2016/12/01 07:42:14
Done.
| |
| 89 : entry_rect.right() - AutofillPopupLayoutModel::kEndPadding; | 109 if (is_http_warning != is_rtl) { |
| 110 x_align_left = value_rect.x(); | |
| 111 } else { | |
| 112 x_align_left = value_rect.right(); | |
| 113 icon_on_the_right = true; | |
| 114 } | |
| 90 | 115 |
| 91 // Draw the Autofill icon, if one exists | 116 // Draw the Autofill icon, if one exists |
| 92 int row_height = controller_->layout_model().GetRowBounds(index).height(); | 117 int row_height = controller_->layout_model().GetRowBounds(index).height(); |
| 93 if (!controller_->GetSuggestionAt(index).icon.empty()) { | 118 if (!controller_->GetSuggestionAt(index).icon.empty()) { |
| 94 const gfx::ImageSkia image = | 119 const gfx::ImageSkia image = |
| 95 controller_->layout_model().GetIconImage(index); | 120 controller_->layout_model().GetIconImage(index); |
| 96 int icon_y = entry_rect.y() + (row_height - image.height()) / 2; | 121 int icon_y = entry_rect.y() + (row_height - image.height()) / 2; |
| 97 | 122 |
| 98 x_align_left += is_rtl ? 0 : -image.width(); | 123 int icon_x_align_left = |
| 124 icon_on_the_right ? x_align_left - image.width() : x_align_left; | |
| 99 | 125 |
| 100 canvas->DrawImageInt(image, x_align_left, icon_y); | 126 canvas->DrawImageInt(image, icon_x_align_left, icon_y); |
| 101 | 127 |
| 102 x_align_left += is_rtl | 128 // An icon was drawn; adjust the |x_align_left| value for the next element. |
| 103 ? image.width() + AutofillPopupLayoutModel::kIconPadding | 129 if (is_http_warning) { |
| 104 : -AutofillPopupLayoutModel::kIconPadding; | 130 x_align_left = |
| 131 icon_x_align_left + | |
| 132 (is_rtl ? -AutofillPopupLayoutModel::kHttpWarningIconPadding | |
| 133 : image.width() + | |
| 134 AutofillPopupLayoutModel::kHttpWarningIconPadding); | |
| 135 } else { | |
| 136 x_align_left = | |
| 137 icon_x_align_left + | |
| 138 (is_rtl ? image.width() + AutofillPopupLayoutModel::kIconPadding | |
| 139 : -AutofillPopupLayoutModel::kIconPadding); | |
| 140 } | |
| 105 } | 141 } |
| 106 | 142 |
| 107 // Draw the label text. | 143 // Draw the value text |
| 108 const int label_width = | 144 const int value_width = gfx::GetStringWidth( |
| 109 gfx::GetStringWidth(controller_->GetElidedLabelAt(index), | 145 controller_->GetElidedValueAt(index), |
| 110 controller_->layout_model().GetLabelFontList()); | 146 controller_->layout_model().GetValueFontListForRow(index)); |
| 111 if (!is_rtl) | 147 int value_x_align_left = x_align_left; |
| 112 x_align_left -= label_width; | 148 |
| 149 if (is_http_warning) { | |
| 150 value_x_align_left += is_rtl ? -value_width : 0; | |
| 151 } else { | |
| 152 value_x_align_left = | |
| 153 is_rtl ? value_rect.right() - value_width : value_rect.x(); | |
| 154 } | |
| 113 | 155 |
| 114 canvas->DrawStringRectWithFlags( | 156 canvas->DrawStringRectWithFlags( |
| 115 controller_->GetElidedLabelAt(index), | 157 controller_->GetElidedValueAt(index), |
| 116 controller_->layout_model().GetLabelFontList(), kLabelTextColor, | 158 controller_->layout_model().GetValueFontListForRow(index), |
| 117 gfx::Rect(x_align_left, entry_rect.y(), label_width, entry_rect.height()), | 159 controller_->layout_model().GetValueFontColorForRow(index), |
| 160 gfx::Rect(value_x_align_left, value_rect.y(), value_width, | |
| 161 value_rect.height()), | |
| 118 text_align); | 162 text_align); |
| 163 | |
| 164 // Draw the label text, if one exists. | |
| 165 if (!controller_->GetSuggestionAt(index).label.empty()) { | |
| 166 const int label_width = gfx::GetStringWidth( | |
| 167 controller_->GetElidedLabelAt(index), | |
| 168 controller_->layout_model().GetLabelFontListForRow(index)); | |
| 169 int label_x_align_left = x_align_left; | |
| 170 | |
| 171 if (is_http_warning) { | |
| 172 label_x_align_left = | |
| 173 is_rtl ? value_rect.x() : value_rect.right() - label_width; | |
| 174 } else { | |
| 175 label_x_align_left += is_rtl ? 0 : -label_width; | |
| 176 } | |
| 177 | |
| 178 canvas->DrawStringRectWithFlags( | |
| 179 controller_->GetElidedLabelAt(index), | |
| 180 controller_->layout_model().GetLabelFontListForRow(index), | |
| 181 kLabelTextColor, gfx::Rect(label_x_align_left, entry_rect.y(), | |
| 182 label_width, entry_rect.height()), | |
| 183 text_align); | |
| 184 } | |
| 119 } | 185 } |
| 120 | 186 |
| 121 AutofillPopupView* AutofillPopupView::Create( | 187 AutofillPopupView* AutofillPopupView::Create( |
| 122 AutofillPopupController* controller) { | 188 AutofillPopupController* controller) { |
| 123 views::Widget* observing_widget = | 189 views::Widget* observing_widget = |
| 124 views::Widget::GetTopLevelWidgetForNativeView( | 190 views::Widget::GetTopLevelWidgetForNativeView( |
| 125 controller->container_view()); | 191 controller->container_view()); |
| 126 | 192 |
| 127 // If the top level widget can't be found, cancel the popup since we can't | 193 // If the top level widget can't be found, cancel the popup since we can't |
| 128 // fully set it up. | 194 // fully set it up. |
| 129 if (!observing_widget) | 195 if (!observing_widget) |
| 130 return NULL; | 196 return NULL; |
| 131 | 197 |
| 132 return new AutofillPopupViewViews(controller, observing_widget); | 198 return new AutofillPopupViewViews(controller, observing_widget); |
| 133 } | 199 } |
| 134 | 200 |
| 135 } // namespace autofill | 201 } // namespace autofill |
| OLD | NEW |