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 "components/autofill/core/browser/popup_item_ids.h" | 9 #include "components/autofill/core/browser/popup_item_ids.h" |
| 10 #include "components/autofill/core/browser/suggestion.h" | 10 #include "components/autofill/core/browser/suggestion.h" |
| 11 #include "ui/accessibility/ax_node_data.h" | |
| 11 #include "ui/events/keycodes/keyboard_codes.h" | 12 #include "ui/events/keycodes/keyboard_codes.h" |
| 12 #include "ui/gfx/canvas.h" | 13 #include "ui/gfx/canvas.h" |
| 13 #include "ui/gfx/geometry/point.h" | 14 #include "ui/gfx/geometry/point.h" |
| 14 #include "ui/gfx/geometry/rect.h" | 15 #include "ui/gfx/geometry/rect.h" |
| 15 #include "ui/gfx/image/image.h" | 16 #include "ui/gfx/image/image.h" |
| 16 #include "ui/gfx/native_widget_types.h" | 17 #include "ui/gfx/native_widget_types.h" |
| 17 #include "ui/gfx/text_utils.h" | 18 #include "ui/gfx/text_utils.h" |
| 18 #include "ui/views/border.h" | 19 #include "ui/views/border.h" |
| 19 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
| 20 | 21 |
| 21 namespace autofill { | 22 namespace autofill { |
| 22 | 23 |
| 23 AutofillPopupViewViews::AutofillPopupViewViews( | 24 AutofillPopupViewViews::AutofillPopupViewViews( |
| 24 AutofillPopupController* controller, | 25 AutofillPopupController* controller, |
| 25 views::Widget* parent_widget) | 26 views::Widget* parent_widget) |
| 26 : AutofillPopupBaseView(controller, parent_widget), | 27 : AutofillPopupBaseView(controller, parent_widget), |
| 27 controller_(controller) {} | 28 controller_(controller) { |
| 29 for (size_t i = 0; i < controller_->GetLineCount(); ++i) { | |
|
Mathieu
2017/02/02 22:07:44
if it's a separator, let's not create a child view
csashi
2017/02/02 23:27:18
Do we want an accessibility handler for the separa
| |
| 30 AutofillPopupChildView *child = new AutofillPopupChildView(controller, i); | |
| 31 AddChildViewAt(child, static_cast<int>(i)); | |
| 32 } | |
| 33 } | |
| 28 | 34 |
| 29 AutofillPopupViewViews::~AutofillPopupViewViews() {} | 35 AutofillPopupViewViews::~AutofillPopupViewViews() {} |
| 30 | 36 |
| 31 void AutofillPopupViewViews::Show() { | 37 void AutofillPopupViewViews::Show() { |
| 32 DoShow(); | 38 DoShow(); |
| 33 } | 39 } |
| 34 | 40 |
| 35 void AutofillPopupViewViews::Hide() { | 41 void AutofillPopupViewViews::Hide() { |
| 36 // The controller is no longer valid after it hides us. | 42 // The controller is no longer valid after it hides us. |
| 37 controller_ = NULL; | 43 controller_ = NULL; |
|
Mathieu
2017/02/02 22:07:44
Since DoHide just kills us, I wonder if this is ne
csashi
2017/02/02 23:27:18
Done.
| |
| 38 | 44 for (int i = 0; i < child_count(); ++i) { |
| 45 (static_cast<AutofillPopupChildView*>(child_at(i)))->clear_controller(); | |
| 46 } | |
| 39 DoHide(); | 47 DoHide(); |
| 40 } | 48 } |
| 41 | 49 |
| 42 void AutofillPopupViewViews::UpdateBoundsAndRedrawPopup() { | 50 void AutofillPopupViewViews::UpdateBoundsAndRedrawPopup() { |
| 43 DoUpdateBoundsAndRedrawPopup(); | 51 DoUpdateBoundsAndRedrawPopup(); |
| 44 } | 52 } |
| 45 | 53 |
| 46 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) { | 54 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) { |
| 47 if (!controller_) | 55 if (!controller_) |
| 48 return; | 56 return; |
| 49 | 57 |
| 50 canvas->DrawColor(GetNativeTheme()->GetSystemColor( | 58 canvas->DrawColor(GetNativeTheme()->GetSystemColor( |
|
Mathieu
2017/02/02 19:30:15
I think we could use set_background in the constru
Mathieu
2017/02/02 22:07:45
In the constructor:
set_background(views::Backgr
csashi
2017/02/02 23:27:18
Done.
csashi
2017/02/02 23:27:18
Done.
| |
| 51 ui::NativeTheme::kColorId_ResultsTableNormalBackground)); | 59 ui::NativeTheme::kColorId_ResultsTableNormalBackground)); |
| 52 OnPaintBorder(canvas); | 60 OnPaintBorder(canvas); |
|
Mathieu
2017/02/02 19:30:15
I think we could SetBorder in the constructor
Mathieu
2017/02/02 22:07:45
In the constructor (color to be confirmed):
SetBo
| |
| 53 | 61 for (int i = 0; i < child_count(); ++i) { |
| 54 for (size_t i = 0; i < controller_->GetLineCount(); ++i) { | 62 (static_cast<AutofillPopupChildView*>(child_at(i)))->OnPaint(canvas); |
|
Mathieu
2017/02/02 19:30:15
Since this is the last thing, we shouldn't need to
csashi
2017/02/02 23:27:18
I thought so too, but that didn't work. Not sure w
| |
| 55 gfx::Rect line_rect = controller_->layout_model().GetRowBounds(i); | |
| 56 | |
| 57 if (controller_->GetSuggestionAt(i).frontend_id == | |
| 58 POPUP_ITEM_ID_SEPARATOR) { | |
| 59 canvas->FillRect( | |
| 60 line_rect, | |
| 61 GetNativeTheme()->GetSystemColor( | |
| 62 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText)); | |
| 63 } else { | |
| 64 DrawAutofillEntry(canvas, i, line_rect); | |
| 65 } | |
| 66 } | 63 } |
| 67 } | 64 } |
| 68 | 65 |
| 69 void AutofillPopupViewViews::InvalidateRow(size_t row) { | 66 void AutofillPopupViewViews::InvalidateRow(size_t row) { |
| 70 SchedulePaintInRect(controller_->layout_model().GetRowBounds(row)); | 67 child_at(row)->SchedulePaint(); |
| 68 } | |
| 69 | |
| 70 void AutofillPopupViewViews::GetAccessibleNodeData(ui::AXNodeData* node_data) { | |
| 71 LOG(VERBOSE) << "AutofillPopupViewViews::GetAccessibleNodeData"; | |
| 72 } | |
| 73 | |
| 74 AutofillPopupChildView::~AutofillPopupChildView() {} | |
| 75 | |
| 76 void AutofillPopupChildView::OnPaint(gfx::Canvas* canvas) { | |
| 77 if (!controller_) | |
| 78 return; | |
| 79 const gfx::Rect line_rect = controller_->layout_model().GetRowBounds(index_); | |
| 80 if (controller_->GetSuggestionAt(index_).frontend_id == | |
| 81 POPUP_ITEM_ID_SEPARATOR) { | |
|
Mathieu
2017/02/02 22:07:45
As mentioned above, let's not draw separators but
csashi
2017/02/02 23:27:18
Same comment as above. Doesn't this depend on whet
| |
| 82 canvas->FillRect( | |
| 83 line_rect, | |
| 84 GetNativeTheme()->GetSystemColor( | |
| 85 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText)); | |
| 86 } else { | |
| 87 DrawAutofillEntry(canvas, index_, line_rect); | |
| 88 } | |
| 71 } | 89 } |
| 72 | 90 |
| 73 /** | 91 /** |
| 74 * Autofill entries in ltr. | 92 * Autofill entries in ltr. |
| 75 * | 93 * |
| 76 * ............................................................................ | 94 * ............................................................................ |
| 77 * . ICON | HTTP WARNING MESSAGE VALUE | LABEL . | 95 * . ICON | HTTP WARNING MESSAGE VALUE | LABEL . |
| 78 * ............................................................................ | 96 * ............................................................................ |
| 79 * . OTHER AUTOFILL ENTRY VALUE | LABEL | ICON . | 97 * . OTHER AUTOFILL ENTRY VALUE | LABEL | ICON . |
| 80 * ............................................................................ | 98 * ............................................................................ |
| 81 * | 99 * |
| 82 * Autofill entries in rtl. | 100 * Autofill entries in rtl. |
| 83 * | 101 * |
| 84 * ............................................................................ | 102 * ............................................................................ |
| 85 * . LABEL | HTTP WARNING MESSAGE VALUE | ICON . | 103 * . LABEL | HTTP WARNING MESSAGE VALUE | ICON . |
| 86 * ............................................................................ | 104 * ............................................................................ |
| 87 * . ICON | LABEL | OTHER AUTOFILL ENTRY VALUE . | 105 * . ICON | LABEL | OTHER AUTOFILL ENTRY VALUE . |
| 88 * ............................................................................ | 106 * ............................................................................ |
| 89 * | 107 * |
| 90 * Anyone who wants to modify the code below, remember to make sure that HTTP | 108 * Anyone who wants to modify the code below, remember to make sure that HTTP |
| 91 * warning entry displays right. To trigger the warning message entry, enable | 109 * warning entry displays right. To trigger the warning message entry, enable |
| 92 * #mark-non-secure-as flag as "display form warning", go to goo.gl/CEIjc6 with | 110 * #mark-non-secure-as flag as "display form warning", go to goo.gl/CEIjc6 with |
| 93 * stored autofill info and check for credit card or password forms. | 111 * stored autofill info and check for credit card or password forms. |
| 94 */ | 112 */ |
| 95 void AutofillPopupViewViews::DrawAutofillEntry(gfx::Canvas* canvas, | 113 void AutofillPopupChildView::DrawAutofillEntry(gfx::Canvas* canvas, |
| 96 int index, | 114 int index, |
| 97 const gfx::Rect& entry_rect) { | 115 const gfx::Rect& entry_rect) { |
| 98 canvas->FillRect( | 116 canvas->FillRect( |
| 99 entry_rect, | 117 entry_rect, |
| 100 GetNativeTheme()->GetSystemColor( | 118 GetNativeTheme()->GetSystemColor( |
| 101 controller_->GetBackgroundColorIDForRow(index))); | 119 controller_->GetBackgroundColorIDForRow(index))); |
| 102 | 120 |
| 103 const bool is_http_warning = | 121 const bool is_http_warning = |
| 104 (controller_->GetSuggestionAt(index).frontend_id == | 122 (controller_->GetSuggestionAt(index).frontend_id == |
| 105 POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE); | 123 POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 controller_->GetElidedLabelAt(index), | 200 controller_->GetElidedLabelAt(index), |
| 183 controller_->layout_model().GetLabelFontListForRow(index), | 201 controller_->layout_model().GetLabelFontListForRow(index), |
| 184 GetNativeTheme()->GetSystemColor( | 202 GetNativeTheme()->GetSystemColor( |
| 185 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText), | 203 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText), |
| 186 gfx::Rect(label_x_align_left, entry_rect.y(), label_width, | 204 gfx::Rect(label_x_align_left, entry_rect.y(), label_width, |
| 187 entry_rect.height()), | 205 entry_rect.height()), |
| 188 text_align); | 206 text_align); |
| 189 } | 207 } |
| 190 } | 208 } |
| 191 | 209 |
| 210 void AutofillPopupChildView::GetAccessibleNodeData(ui::AXNodeData* node_data) { | |
| 211 LOG(VERBOSE) << "AutofillPopupChildView::GetAccessibleNodeData"; | |
| 212 if (!controller_) | |
| 213 return; | |
| 214 if (controller_->GetSuggestionAt(index_).frontend_id == | |
| 215 POPUP_ITEM_ID_SEPARATOR) { | |
| 216 node_data->role = ui::AX_ROLE_SPLITTER; | |
| 217 node_data->AddStateFlag(ui::AX_STATE_READ_ONLY); | |
| 218 return; | |
| 219 } | |
| 220 node_data->role = ui::AX_ROLE_TEXT_FIELD; | |
| 221 node_data->SetName(controller_->GetElidedLabelAt(index_)); | |
| 222 node_data->SetValue(controller_->GetElidedValueAt(index_)); | |
| 223 node_data->AddStateFlag(ui::AX_STATE_EDITABLE); | |
| 224 } | |
| 225 | |
| 192 AutofillPopupView* AutofillPopupView::Create( | 226 AutofillPopupView* AutofillPopupView::Create( |
| 193 AutofillPopupController* controller) { | 227 AutofillPopupController* controller) { |
| 194 views::Widget* observing_widget = | 228 views::Widget* observing_widget = |
| 195 views::Widget::GetTopLevelWidgetForNativeView( | 229 views::Widget::GetTopLevelWidgetForNativeView( |
| 196 controller->container_view()); | 230 controller->container_view()); |
| 197 | 231 |
| 198 // If the top level widget can't be found, cancel the popup since we can't | 232 // If the top level widget can't be found, cancel the popup since we can't |
| 199 // fully set it up. | 233 // fully set it up. |
| 200 if (!observing_widget) | 234 if (!observing_widget) |
| 201 return NULL; | 235 return NULL; |
| 202 | 236 |
| 203 return new AutofillPopupViewViews(controller, observing_widget); | 237 return new AutofillPopupViewViews(controller, observing_widget); |
| 204 } | 238 } |
| 205 | 239 |
| 206 } // namespace autofill | 240 } // namespace autofill |
| OLD | NEW |