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" |
| 19 #include "ui/views/background.h" |
18 #include "ui/views/border.h" | 20 #include "ui/views/border.h" |
19 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
20 | 22 |
21 namespace autofill { | 23 namespace autofill { |
22 | 24 |
23 AutofillPopupViewViews::AutofillPopupViewViews( | 25 AutofillPopupViewViews::AutofillPopupViewViews( |
24 AutofillPopupController* controller, | 26 AutofillPopupController* controller, |
25 views::Widget* parent_widget) | 27 views::Widget* parent_widget) |
26 : AutofillPopupBaseView(controller, parent_widget), | 28 : AutofillPopupBaseView(controller, parent_widget), |
27 controller_(controller) {} | 29 controller_(controller) { |
| 30 for (size_t i = 0; i < controller_->GetLineCount(); ++i) { |
| 31 AutofillPopupChildView *child = new AutofillPopupChildView(controller, i); |
| 32 AddChildViewAt(child, static_cast<int>(i)); |
| 33 } |
| 34 SetFocusBehavior(FocusBehavior::ALWAYS); |
| 35 set_background(views::Background::CreateSolidBackground( |
| 36 GetNativeTheme()->GetSystemColor( |
| 37 ui::NativeTheme::kColorId_ResultsTableNormalBackground))); |
| 38 } |
28 | 39 |
29 AutofillPopupViewViews::~AutofillPopupViewViews() {} | 40 AutofillPopupViewViews::~AutofillPopupViewViews() {} |
30 | 41 |
31 void AutofillPopupViewViews::Show() { | 42 void AutofillPopupViewViews::Show() { |
32 DoShow(); | 43 DoShow(); |
| 44 NotifyAccessibilityEvent(ui::AX_EVENT_MENU_POPUP_START, true); |
33 } | 45 } |
34 | 46 |
35 void AutofillPopupViewViews::Hide() { | 47 void AutofillPopupViewViews::Hide() { |
36 // The controller is no longer valid after it hides us. | |
37 controller_ = NULL; | |
38 | |
39 DoHide(); | 48 DoHide(); |
| 49 NotifyAccessibilityEvent(ui::AX_EVENT_MENU_POPUP_END, true); |
40 } | 50 } |
41 | 51 |
42 void AutofillPopupViewViews::UpdateBoundsAndRedrawPopup() { | 52 void AutofillPopupViewViews::UpdateBoundsAndRedrawPopup() { |
43 DoUpdateBoundsAndRedrawPopup(); | 53 DoUpdateBoundsAndRedrawPopup(); |
44 } | 54 } |
45 | 55 |
46 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) { | 56 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) { |
47 if (!controller_) | 57 OnPaintBackground(canvas); |
48 return; | |
49 | |
50 canvas->DrawColor(GetNativeTheme()->GetSystemColor( | |
51 ui::NativeTheme::kColorId_ResultsTableNormalBackground)); | |
52 OnPaintBorder(canvas); | 58 OnPaintBorder(canvas); |
53 | 59 for (int i = 0; i < child_count(); ++i) { |
54 for (size_t i = 0; i < controller_->GetLineCount(); ++i) { | 60 (static_cast<AutofillPopupChildView*>(child_at(i)))->OnPaint(canvas); |
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 } | 61 } |
67 } | 62 } |
68 | 63 |
69 void AutofillPopupViewViews::InvalidateRow(size_t row) { | 64 void AutofillPopupViewViews::InvalidateRow(size_t row) { |
70 SchedulePaintInRect(controller_->layout_model().GetRowBounds(row)); | 65 child_at(row)->SchedulePaint(); |
| 66 } |
| 67 |
| 68 AutofillPopupChildView::AutofillPopupChildView( |
| 69 AutofillPopupController* controller, size_t index) |
| 70 : controller_(controller), index_(index) { |
| 71 SetFocusBehavior(FocusBehavior::ALWAYS); |
| 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) { |
| 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 if (!controller_) |
| 212 return; |
| 213 if (controller_->GetSuggestionAt(index_).frontend_id == |
| 214 POPUP_ITEM_ID_SEPARATOR) { |
| 215 node_data->role = ui::AX_ROLE_SPLITTER; |
| 216 node_data->AddStateFlag(ui::AX_STATE_READ_ONLY); |
| 217 return; |
| 218 } |
| 219 node_data->role = ui::AX_ROLE_TEXT_FIELD; |
| 220 node_data->SetName(controller_->GetElidedLabelAt(index_)); |
| 221 node_data->SetValue(controller_->GetElidedValueAt(index_)); |
| 222 node_data->AddStateFlag(ui::AX_STATE_EDITABLE); |
| 223 } |
| 224 |
192 AutofillPopupView* AutofillPopupView::Create( | 225 AutofillPopupView* AutofillPopupView::Create( |
193 AutofillPopupController* controller) { | 226 AutofillPopupController* controller) { |
194 views::Widget* observing_widget = | 227 views::Widget* observing_widget = |
195 views::Widget::GetTopLevelWidgetForNativeView( | 228 views::Widget::GetTopLevelWidgetForNativeView( |
196 controller->container_view()); | 229 controller->container_view()); |
197 | 230 |
198 // If the top level widget can't be found, cancel the popup since we can't | 231 // If the top level widget can't be found, cancel the popup since we can't |
199 // fully set it up. | 232 // fully set it up. |
200 if (!observing_widget) | 233 if (!observing_widget) |
201 return NULL; | 234 return NULL; |
202 | 235 |
203 return new AutofillPopupViewViews(controller, observing_widget); | 236 return new AutofillPopupViewViews(controller, observing_widget); |
204 } | 237 } |
205 | 238 |
206 } // namespace autofill | 239 } // namespace autofill |
OLD | NEW |