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/grit/generated_resources.h" | |
9 #include "components/autofill/core/browser/popup_item_ids.h" | 10 #include "components/autofill/core/browser/popup_item_ids.h" |
10 #include "components/autofill/core/browser/suggestion.h" | 11 #include "components/autofill/core/browser/suggestion.h" |
12 #include "ui/accessibility/ax_node_data.h" | |
13 #include "ui/base/l10n/l10n_util.h" | |
11 #include "ui/events/keycodes/keyboard_codes.h" | 14 #include "ui/events/keycodes/keyboard_codes.h" |
12 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
13 #include "ui/gfx/geometry/point.h" | 16 #include "ui/gfx/geometry/point.h" |
14 #include "ui/gfx/geometry/rect.h" | 17 #include "ui/gfx/geometry/rect.h" |
15 #include "ui/gfx/image/image.h" | 18 #include "ui/gfx/image/image.h" |
16 #include "ui/gfx/native_widget_types.h" | 19 #include "ui/gfx/native_widget_types.h" |
17 #include "ui/gfx/text_utils.h" | 20 #include "ui/gfx/text_utils.h" |
18 #include "ui/views/border.h" | 21 #include "ui/views/border.h" |
19 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
20 | 23 |
21 namespace autofill { | 24 namespace autofill { |
22 | 25 |
26 namespace { | |
27 | |
28 // Child view only for triggering accessibility events. Rendering is handled | |
29 // by |AutofillPopupViewViews|. | |
30 class AutofillPopupChildView : public views::View { | |
31 public: | |
32 AutofillPopupChildView(AutofillPopupController* controller, size_t index); | |
33 | |
34 private: | |
35 ~AutofillPopupChildView() override; | |
36 | |
37 // views::Views implementation | |
38 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; | |
39 | |
40 AutofillPopupController* controller_; // Weak reference. | |
41 const size_t index_; | |
42 | |
43 DISALLOW_COPY_AND_ASSIGN(AutofillPopupChildView); | |
44 }; | |
45 | |
46 } // namespace | |
47 | |
23 AutofillPopupViewViews::AutofillPopupViewViews( | 48 AutofillPopupViewViews::AutofillPopupViewViews( |
24 AutofillPopupController* controller, | 49 AutofillPopupController* controller, views::Widget* parent_widget) |
25 views::Widget* parent_widget) | |
26 : AutofillPopupBaseView(controller, parent_widget), | 50 : AutofillPopupBaseView(controller, parent_widget), |
27 controller_(controller) {} | 51 controller_(controller) { |
52 for (size_t i = 0; i < controller_->GetLineCount(); ++i) { | |
53 AutofillPopupChildView *child = new AutofillPopupChildView(controller, i); | |
54 AddChildViewAt(child, static_cast<int>(i)); | |
55 } | |
56 SetFocusBehavior(FocusBehavior::ALWAYS); | |
57 } | |
28 | 58 |
29 AutofillPopupViewViews::~AutofillPopupViewViews() {} | 59 AutofillPopupViewViews::~AutofillPopupViewViews() {} |
30 | 60 |
31 void AutofillPopupViewViews::Show() { | 61 void AutofillPopupViewViews::Show() { |
32 DoShow(); | 62 DoShow(); |
63 NotifyAccessibilityEvent(ui::AX_EVENT_MENU_START, true); | |
33 } | 64 } |
34 | 65 |
35 void AutofillPopupViewViews::Hide() { | 66 void AutofillPopupViewViews::Hide() { |
36 // The controller is no longer valid after it hides us. | 67 // The controller is no longer valid after it hides us. |
37 controller_ = NULL; | 68 controller_ = NULL; |
38 | |
39 DoHide(); | 69 DoHide(); |
70 NotifyAccessibilityEvent(ui::AX_EVENT_MENU_END, true); | |
40 } | 71 } |
41 | 72 |
42 void AutofillPopupViewViews::UpdateBoundsAndRedrawPopup() { | 73 void AutofillPopupViewViews::UpdateBoundsAndRedrawPopup() { |
43 DoUpdateBoundsAndRedrawPopup(); | 74 DoUpdateBoundsAndRedrawPopup(); |
44 } | 75 } |
45 | 76 |
46 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) { | 77 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) { |
47 if (!controller_) | 78 if (!controller_) |
48 return; | 79 return; |
49 | 80 |
(...skipping 13 matching lines...) Expand all Loading... | |
63 } else { | 94 } else { |
64 DrawAutofillEntry(canvas, i, line_rect); | 95 DrawAutofillEntry(canvas, i, line_rect); |
65 } | 96 } |
66 } | 97 } |
67 } | 98 } |
68 | 99 |
69 void AutofillPopupViewViews::InvalidateRow(size_t row) { | 100 void AutofillPopupViewViews::InvalidateRow(size_t row) { |
70 SchedulePaintInRect(controller_->layout_model().GetRowBounds(row)); | 101 SchedulePaintInRect(controller_->layout_model().GetRowBounds(row)); |
71 } | 102 } |
72 | 103 |
104 void AutofillPopupViewViews::NotifyAccessibilityEventForRow( | |
105 ui::AXEvent event_type, size_t row) { | |
106 AutofillPopupChildView *child_view = | |
107 static_cast<AutofillPopupChildView*>(child_at(row)); | |
108 child_view->NotifyAccessibilityEvent(event_type, true); | |
109 } | |
110 | |
73 /** | 111 /** |
74 * Autofill entries in ltr. | 112 * Autofill entries in ltr. |
75 * | 113 * |
76 * ............................................................................ | 114 * ............................................................................ |
77 * . ICON | HTTP WARNING MESSAGE VALUE | LABEL . | 115 * . ICON | HTTP WARNING MESSAGE VALUE | LABEL . |
78 * ............................................................................ | 116 * ............................................................................ |
79 * . OTHER AUTOFILL ENTRY VALUE | LABEL | ICON . | 117 * . OTHER AUTOFILL ENTRY VALUE | LABEL | ICON . |
80 * ............................................................................ | 118 * ............................................................................ |
81 * | 119 * |
82 * Autofill entries in rtl. | 120 * Autofill entries in rtl. |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 controller_->GetElidedLabelAt(index), | 220 controller_->GetElidedLabelAt(index), |
183 controller_->layout_model().GetLabelFontListForRow(index), | 221 controller_->layout_model().GetLabelFontListForRow(index), |
184 GetNativeTheme()->GetSystemColor( | 222 GetNativeTheme()->GetSystemColor( |
185 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText), | 223 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText), |
186 gfx::Rect(label_x_align_left, entry_rect.y(), label_width, | 224 gfx::Rect(label_x_align_left, entry_rect.y(), label_width, |
187 entry_rect.height()), | 225 entry_rect.height()), |
188 text_align); | 226 text_align); |
189 } | 227 } |
190 } | 228 } |
191 | 229 |
230 void AutofillPopupViewViews::GetAccessibleNodeData(ui::AXNodeData* node_data) { | |
231 node_data->role = ui::AX_ROLE_MENU; | |
232 node_data->SetName(l10n_util::GetStringUTF16( | |
233 IDS_AUTOFILL_POPUP_ACCESSIBLE_NODE_DATA)); | |
234 } | |
235 | |
192 AutofillPopupView* AutofillPopupView::Create( | 236 AutofillPopupView* AutofillPopupView::Create( |
193 AutofillPopupController* controller) { | 237 AutofillPopupController* controller) { |
194 views::Widget* observing_widget = | 238 views::Widget* observing_widget = |
195 views::Widget::GetTopLevelWidgetForNativeView( | 239 views::Widget::GetTopLevelWidgetForNativeView( |
196 controller->container_view()); | 240 controller->container_view()); |
197 | 241 |
198 // If the top level widget can't be found, cancel the popup since we can't | 242 // If the top level widget can't be found, cancel the popup since we can't |
199 // fully set it up. | 243 // fully set it up. |
200 if (!observing_widget) | 244 if (!observing_widget) |
201 return NULL; | 245 return NULL; |
202 | 246 |
203 return new AutofillPopupViewViews(controller, observing_widget); | 247 return new AutofillPopupViewViews(controller, observing_widget); |
204 } | 248 } |
205 | 249 |
250 namespace { | |
251 | |
252 AutofillPopupChildView::AutofillPopupChildView( | |
253 AutofillPopupController* controller, size_t index) | |
254 : controller_(controller), index_(index) { | |
255 SetFocusBehavior(FocusBehavior::ALWAYS); | |
Mathieu
2017/02/27 19:01:05
I think we can have the function bodies in the ano
csashi
2017/02/27 19:09:38
Done.
| |
256 } | |
257 | |
258 AutofillPopupChildView::~AutofillPopupChildView() {} | |
259 | |
260 void AutofillPopupChildView::GetAccessibleNodeData(ui::AXNodeData* node_data) { | |
261 if (!controller_) | |
262 return; | |
263 // We do not special case |POPUP_ITEM_ID_SEPARATOR| suggestion because we | |
264 // skip that suggestion when the user navigates through the popup suggestions. | |
265 node_data->role = ui::AX_ROLE_MENU_ITEM; | |
266 node_data->SetName(controller_->GetElidedValueAt(index_)); | |
267 } | |
268 | |
269 } // namespace | |
270 | |
206 } // namespace autofill | 271 } // namespace autofill |
OLD | NEW |