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 * ............................................................................ | |
|
Mathieu
2016/11/28 15:01:35
Thanks, I would add a note in this comment for the
lshang
2016/11/29 10:44:30
Done.
| |
| 86 */ | |
| 70 void AutofillPopupViewViews::DrawAutofillEntry(gfx::Canvas* canvas, | 87 void AutofillPopupViewViews::DrawAutofillEntry(gfx::Canvas* canvas, |
| 71 int index, | 88 int index, |
| 72 const gfx::Rect& entry_rect) { | 89 const gfx::Rect& entry_rect) { |
| 73 canvas->FillRect(entry_rect, controller_->GetBackgroundColorForRow(index)); | 90 canvas->FillRect(entry_rect, controller_->GetBackgroundColorForRow(index)); |
| 74 | 91 |
| 92 const bool is_http_warning = | |
| 93 (controller_->GetSuggestionAt(index).frontend_id == | |
| 94 POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE); | |
| 75 const bool is_rtl = controller_->IsRTL(); | 95 const bool is_rtl = controller_->IsRTL(); |
| 76 const int text_align = | 96 const int text_align = |
| 77 is_rtl ? gfx::Canvas::TEXT_ALIGN_RIGHT : gfx::Canvas::TEXT_ALIGN_LEFT; | 97 is_rtl ? gfx::Canvas::TEXT_ALIGN_RIGHT : gfx::Canvas::TEXT_ALIGN_LEFT; |
| 78 gfx::Rect value_rect = entry_rect; | 98 gfx::Rect value_rect = entry_rect; |
| 79 value_rect.Inset(AutofillPopupLayoutModel::kEndPadding, 0); | 99 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 | 100 |
| 86 // Use this to figure out where all the other Autofill items should be placed. | 101 int icon_x_align_left = 0; |
|
Mathieu
2016/11/28 15:01:35
would change to icon_x_align_start, so that it's c
lshang
2016/11/29 10:44:30
Not for this case I think. RTL or LTR decides wher
| |
| 87 int x_align_left = | 102 if ((is_http_warning && !is_rtl) || (!is_http_warning && is_rtl)) |
| 88 is_rtl ? AutofillPopupLayoutModel::kEndPadding | 103 icon_x_align_left = value_rect.x(); |
| 89 : entry_rect.right() - AutofillPopupLayoutModel::kEndPadding; | 104 else |
| 105 icon_x_align_left = value_rect.right(); | |
| 90 | 106 |
| 91 // Draw the Autofill icon, if one exists | 107 // Draw the Autofill icon, if one exists |
| 92 int row_height = controller_->layout_model().GetRowBounds(index).height(); | 108 int row_height = controller_->layout_model().GetRowBounds(index).height(); |
| 93 if (!controller_->GetSuggestionAt(index).icon.empty()) { | 109 if (!controller_->GetSuggestionAt(index).icon.empty()) { |
| 94 const gfx::ImageSkia image = | 110 const gfx::ImageSkia image = |
| 95 controller_->layout_model().GetIconImage(index); | 111 controller_->layout_model().GetIconImage(index); |
| 96 int icon_y = entry_rect.y() + (row_height - image.height()) / 2; | 112 int icon_y = entry_rect.y() + (row_height - image.height()) / 2; |
| 97 | 113 |
| 98 x_align_left += is_rtl ? 0 : -image.width(); | 114 if (icon_x_align_left == value_rect.right()) |
| 115 icon_x_align_left -= image.width(); | |
| 99 | 116 |
| 100 canvas->DrawImageInt(image, x_align_left, icon_y); | 117 canvas->DrawImageInt(image, icon_x_align_left, icon_y); |
| 101 | 118 |
| 102 x_align_left += is_rtl | 119 if (is_http_warning) { |
|
Mathieu
2016/11/28 15:01:35
I would add a comment to the reader such as
// An
lshang
2016/11/29 10:44:30
Done.
| |
| 103 ? image.width() + AutofillPopupLayoutModel::kIconPadding | 120 icon_x_align_left += |
| 104 : -AutofillPopupLayoutModel::kIconPadding; | 121 is_rtl ? -AutofillPopupLayoutModel::kHttpWarningIconPadding |
| 122 : image.width() + | |
| 123 AutofillPopupLayoutModel::kHttpWarningIconPadding; | |
| 124 } else { | |
| 125 icon_x_align_left += | |
| 126 is_rtl ? image.width() + AutofillPopupLayoutModel::kIconPadding | |
| 127 : -AutofillPopupLayoutModel::kIconPadding; | |
| 128 } | |
| 105 } | 129 } |
| 106 | 130 |
| 107 // Draw the label text. | 131 // Draw the value text |
| 108 const int label_width = | 132 const int value_width = gfx::GetStringWidth( |
| 109 gfx::GetStringWidth(controller_->GetElidedLabelAt(index), | 133 controller_->GetElidedValueAt(index), |
| 110 controller_->layout_model().GetLabelFontList()); | 134 controller_->layout_model().GetValueFontListForRow(index)); |
| 111 if (!is_rtl) | 135 int value_x_align_left = icon_x_align_left; |
| 112 x_align_left -= label_width; | 136 |
| 137 if (is_http_warning) | |
|
Mathieu
2016/11/28 15:01:35
I would add {} here
lshang
2016/11/29 10:44:30
Done.
| |
| 138 value_x_align_left += is_rtl ? -value_width : 0; | |
| 139 else | |
| 140 value_x_align_left = | |
| 141 is_rtl ? value_rect.right() - value_width : value_rect.x(); | |
| 113 | 142 |
| 114 canvas->DrawStringRectWithFlags( | 143 canvas->DrawStringRectWithFlags( |
| 115 controller_->GetElidedLabelAt(index), | 144 controller_->GetElidedValueAt(index), |
| 116 controller_->layout_model().GetLabelFontList(), kLabelTextColor, | 145 controller_->layout_model().GetValueFontListForRow(index), |
| 117 gfx::Rect(x_align_left, entry_rect.y(), label_width, entry_rect.height()), | 146 controller_->layout_model().GetValueFontColorForRow(index), |
| 147 gfx::Rect(value_x_align_left, value_rect.y(), value_width, | |
| 148 value_rect.height()), | |
| 118 text_align); | 149 text_align); |
| 150 | |
| 151 // Draw the label text, if one exists. | |
| 152 if (!controller_->GetSuggestionAt(index).label.empty()) { | |
| 153 const int label_width = gfx::GetStringWidth( | |
| 154 controller_->GetElidedLabelAt(index), | |
| 155 controller_->layout_model().GetLabelFontListForRow(index)); | |
| 156 int label_x_align_left = icon_x_align_left; | |
| 157 | |
| 158 if (is_http_warning) | |
|
Mathieu
2016/11/28 15:01:35
I would add {} around the blocks
lshang
2016/11/29 10:44:30
Done.
| |
| 159 label_x_align_left = | |
| 160 is_rtl ? value_rect.x() : value_rect.right() - label_width; | |
| 161 else | |
| 162 label_x_align_left += is_rtl ? 0 : -label_width; | |
| 163 | |
| 164 canvas->DrawStringRectWithFlags( | |
| 165 controller_->GetElidedLabelAt(index), | |
| 166 controller_->layout_model().GetLabelFontListForRow(index), | |
| 167 kLabelTextColor, gfx::Rect(label_x_align_left, entry_rect.y(), | |
| 168 label_width, entry_rect.height()), | |
| 169 text_align); | |
| 170 } | |
| 119 } | 171 } |
| 120 | 172 |
| 121 AutofillPopupView* AutofillPopupView::Create( | 173 AutofillPopupView* AutofillPopupView::Create( |
| 122 AutofillPopupController* controller) { | 174 AutofillPopupController* controller) { |
| 123 views::Widget* observing_widget = | 175 views::Widget* observing_widget = |
| 124 views::Widget::GetTopLevelWidgetForNativeView( | 176 views::Widget::GetTopLevelWidgetForNativeView( |
| 125 controller->container_view()); | 177 controller->container_view()); |
| 126 | 178 |
| 127 // If the top level widget can't be found, cancel the popup since we can't | 179 // If the top level widget can't be found, cancel the popup since we can't |
| 128 // fully set it up. | 180 // fully set it up. |
| 129 if (!observing_widget) | 181 if (!observing_widget) |
| 130 return NULL; | 182 return NULL; |
| 131 | 183 |
| 132 return new AutofillPopupViewViews(controller, observing_widget); | 184 return new AutofillPopupViewViews(controller, observing_widget); |
| 133 } | 185 } |
| 134 | 186 |
| 135 } // namespace autofill | 187 } // namespace autofill |
| OLD | NEW |