| 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 // If the icon is on the right of the rect, no matter in RTL or LTR mode. |
| 87 int x_align_left = | 107 bool icon_on_the_right = is_http_warning == is_rtl; |
| 88 is_rtl ? AutofillPopupLayoutModel::kEndPadding | 108 int x_align_left = icon_on_the_right ? value_rect.right() : value_rect.x(); |
| 89 : entry_rect.right() - AutofillPopupLayoutModel::kEndPadding; | |
| 90 | 109 |
| 91 // Draw the Autofill icon, if one exists | 110 // Draw the Autofill icon, if one exists |
| 92 int row_height = controller_->layout_model().GetRowBounds(index).height(); | 111 int row_height = controller_->layout_model().GetRowBounds(index).height(); |
| 93 if (!controller_->GetSuggestionAt(index).icon.empty()) { | 112 if (!controller_->GetSuggestionAt(index).icon.empty()) { |
| 94 const gfx::ImageSkia image = | 113 const gfx::ImageSkia image = |
| 95 controller_->layout_model().GetIconImage(index); | 114 controller_->layout_model().GetIconImage(index); |
| 96 int icon_y = entry_rect.y() + (row_height - image.height()) / 2; | 115 int icon_y = entry_rect.y() + (row_height - image.height()) / 2; |
| 97 | 116 |
| 98 x_align_left += is_rtl ? 0 : -image.width(); | 117 int icon_x_align_left = |
| 118 icon_on_the_right ? x_align_left - image.width() : x_align_left; |
| 99 | 119 |
| 100 canvas->DrawImageInt(image, x_align_left, icon_y); | 120 canvas->DrawImageInt(image, icon_x_align_left, icon_y); |
| 101 | 121 |
| 102 x_align_left += is_rtl | 122 // An icon was drawn; adjust the |x_align_left| value for the next element. |
| 103 ? image.width() + AutofillPopupLayoutModel::kIconPadding | 123 if (is_http_warning) { |
| 104 : -AutofillPopupLayoutModel::kIconPadding; | 124 x_align_left = |
| 125 icon_x_align_left + |
| 126 (is_rtl ? -AutofillPopupLayoutModel::kHttpWarningIconPadding |
| 127 : image.width() + |
| 128 AutofillPopupLayoutModel::kHttpWarningIconPadding); |
| 129 } else { |
| 130 x_align_left = |
| 131 icon_x_align_left + |
| 132 (is_rtl ? image.width() + AutofillPopupLayoutModel::kIconPadding |
| 133 : -AutofillPopupLayoutModel::kIconPadding); |
| 134 } |
| 105 } | 135 } |
| 106 | 136 |
| 107 // Draw the label text. | 137 // Draw the value text |
| 108 const int label_width = | 138 const int value_width = gfx::GetStringWidth( |
| 109 gfx::GetStringWidth(controller_->GetElidedLabelAt(index), | 139 controller_->GetElidedValueAt(index), |
| 110 controller_->layout_model().GetLabelFontList()); | 140 controller_->layout_model().GetValueFontListForRow(index)); |
| 111 if (!is_rtl) | 141 int value_x_align_left = x_align_left; |
| 112 x_align_left -= label_width; | 142 |
| 143 if (is_http_warning) { |
| 144 value_x_align_left += is_rtl ? -value_width : 0; |
| 145 } else { |
| 146 value_x_align_left = |
| 147 is_rtl ? value_rect.right() - value_width : value_rect.x(); |
| 148 } |
| 113 | 149 |
| 114 canvas->DrawStringRectWithFlags( | 150 canvas->DrawStringRectWithFlags( |
| 115 controller_->GetElidedLabelAt(index), | 151 controller_->GetElidedValueAt(index), |
| 116 controller_->layout_model().GetLabelFontList(), kLabelTextColor, | 152 controller_->layout_model().GetValueFontListForRow(index), |
| 117 gfx::Rect(x_align_left, entry_rect.y(), label_width, entry_rect.height()), | 153 controller_->layout_model().GetValueFontColorForRow(index), |
| 154 gfx::Rect(value_x_align_left, value_rect.y(), value_width, |
| 155 value_rect.height()), |
| 118 text_align); | 156 text_align); |
| 157 |
| 158 // Draw the label text, if one exists. |
| 159 if (!controller_->GetSuggestionAt(index).label.empty()) { |
| 160 const int label_width = gfx::GetStringWidth( |
| 161 controller_->GetElidedLabelAt(index), |
| 162 controller_->layout_model().GetLabelFontListForRow(index)); |
| 163 int label_x_align_left = x_align_left; |
| 164 |
| 165 if (is_http_warning) { |
| 166 label_x_align_left = |
| 167 is_rtl ? value_rect.x() : value_rect.right() - label_width; |
| 168 } else { |
| 169 label_x_align_left += is_rtl ? 0 : -label_width; |
| 170 } |
| 171 |
| 172 canvas->DrawStringRectWithFlags( |
| 173 controller_->GetElidedLabelAt(index), |
| 174 controller_->layout_model().GetLabelFontListForRow(index), |
| 175 kLabelTextColor, gfx::Rect(label_x_align_left, entry_rect.y(), |
| 176 label_width, entry_rect.height()), |
| 177 text_align); |
| 178 } |
| 119 } | 179 } |
| 120 | 180 |
| 121 AutofillPopupView* AutofillPopupView::Create( | 181 AutofillPopupView* AutofillPopupView::Create( |
| 122 AutofillPopupController* controller) { | 182 AutofillPopupController* controller) { |
| 123 views::Widget* observing_widget = | 183 views::Widget* observing_widget = |
| 124 views::Widget::GetTopLevelWidgetForNativeView( | 184 views::Widget::GetTopLevelWidgetForNativeView( |
| 125 controller->container_view()); | 185 controller->container_view()); |
| 126 | 186 |
| 127 // If the top level widget can't be found, cancel the popup since we can't | 187 // If the top level widget can't be found, cancel the popup since we can't |
| 128 // fully set it up. | 188 // fully set it up. |
| 129 if (!observing_widget) | 189 if (!observing_widget) |
| 130 return NULL; | 190 return NULL; |
| 131 | 191 |
| 132 return new AutofillPopupViewViews(controller, observing_widget); | 192 return new AutofillPopupViewViews(controller, observing_widget); |
| 133 } | 193 } |
| 134 | 194 |
| 135 } // namespace autofill | 195 } // namespace autofill |
| OLD | NEW |