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 // |controller| should not be NULL. |
| 33 AutofillPopupChildView(AutofillPopupController* controller, size_t index) |
| 34 : controller_(controller), index_(index) { |
| 35 SetFocusBehavior(FocusBehavior::ALWAYS); |
| 36 } |
| 37 |
| 38 private: |
| 39 ~AutofillPopupChildView() override {} |
| 40 |
| 41 // views::Views implementation |
| 42 void GetAccessibleNodeData(ui::AXNodeData* node_data) override { |
| 43 // We do not special case |POPUP_ITEM_ID_SEPARATOR| suggestion because we |
| 44 // skip that suggestion when the user navigates through the popup |
| 45 // suggestions. See | AutofillPopupControllerImpl::CanAccept|. |
| 46 node_data->role = ui::AX_ROLE_MENU_ITEM; |
| 47 node_data->SetName(controller_->GetElidedValueAt(index_)); |
| 48 } |
| 49 |
| 50 AutofillPopupController* controller_; // Weak reference. |
| 51 const size_t index_; |
| 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(AutofillPopupChildView); |
| 54 }; |
| 55 |
| 56 } // namespace |
| 57 |
23 AutofillPopupViewViews::AutofillPopupViewViews( | 58 AutofillPopupViewViews::AutofillPopupViewViews( |
24 AutofillPopupController* controller, | 59 AutofillPopupController* controller, views::Widget* parent_widget) |
25 views::Widget* parent_widget) | |
26 : AutofillPopupBaseView(controller, parent_widget), | 60 : AutofillPopupBaseView(controller, parent_widget), |
27 controller_(controller) {} | 61 controller_(controller) { |
| 62 for (size_t i = 0; i < controller_->GetLineCount(); ++i) { |
| 63 AutofillPopupChildView* child = new AutofillPopupChildView(controller, i); |
| 64 AddChildViewAt(child, static_cast<int>(i)); |
| 65 } |
| 66 SetFocusBehavior(FocusBehavior::ALWAYS); |
| 67 } |
28 | 68 |
29 AutofillPopupViewViews::~AutofillPopupViewViews() {} | 69 AutofillPopupViewViews::~AutofillPopupViewViews() {} |
30 | 70 |
31 void AutofillPopupViewViews::Show() { | 71 void AutofillPopupViewViews::Show() { |
32 DoShow(); | 72 DoShow(); |
| 73 NotifyAccessibilityEvent(ui::AX_EVENT_MENU_START, true); |
33 } | 74 } |
34 | 75 |
35 void AutofillPopupViewViews::Hide() { | 76 void AutofillPopupViewViews::Hide() { |
36 // The controller is no longer valid after it hides us. | 77 // The controller is no longer valid after it hides us. |
37 controller_ = NULL; | 78 controller_ = NULL; |
38 | |
39 DoHide(); | 79 DoHide(); |
| 80 NotifyAccessibilityEvent(ui::AX_EVENT_MENU_END, true); |
40 } | 81 } |
41 | 82 |
42 void AutofillPopupViewViews::UpdateBoundsAndRedrawPopup() { | 83 void AutofillPopupViewViews::UpdateBoundsAndRedrawPopup() { |
43 DoUpdateBoundsAndRedrawPopup(); | 84 DoUpdateBoundsAndRedrawPopup(); |
44 } | 85 } |
45 | 86 |
46 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) { | 87 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) { |
47 if (!controller_) | 88 if (!controller_) |
48 return; | 89 return; |
49 | 90 |
(...skipping 13 matching lines...) Expand all Loading... |
63 } else { | 104 } else { |
64 DrawAutofillEntry(canvas, i, line_rect); | 105 DrawAutofillEntry(canvas, i, line_rect); |
65 } | 106 } |
66 } | 107 } |
67 } | 108 } |
68 | 109 |
69 void AutofillPopupViewViews::InvalidateRow(size_t row) { | 110 void AutofillPopupViewViews::InvalidateRow(size_t row) { |
70 SchedulePaintInRect(controller_->layout_model().GetRowBounds(row)); | 111 SchedulePaintInRect(controller_->layout_model().GetRowBounds(row)); |
71 } | 112 } |
72 | 113 |
| 114 void AutofillPopupViewViews::NotifyAccessibilityEventForRow( |
| 115 ui::AXEvent event_type, size_t row) { |
| 116 AutofillPopupChildView *child_view = |
| 117 static_cast<AutofillPopupChildView*>(child_at(row)); |
| 118 child_view->NotifyAccessibilityEvent(event_type, true); |
| 119 } |
| 120 |
73 /** | 121 /** |
74 * Autofill entries in ltr. | 122 * Autofill entries in ltr. |
75 * | 123 * |
76 * ............................................................................ | 124 * ............................................................................ |
77 * . ICON | HTTP WARNING MESSAGE VALUE | LABEL . | 125 * . ICON | HTTP WARNING MESSAGE VALUE | LABEL . |
78 * ............................................................................ | 126 * ............................................................................ |
79 * . OTHER AUTOFILL ENTRY VALUE | LABEL | ICON . | 127 * . OTHER AUTOFILL ENTRY VALUE | LABEL | ICON . |
80 * ............................................................................ | 128 * ............................................................................ |
81 * | 129 * |
82 * Autofill entries in rtl. | 130 * Autofill entries in rtl. |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 controller_->GetElidedLabelAt(index), | 230 controller_->GetElidedLabelAt(index), |
183 controller_->layout_model().GetLabelFontListForRow(index), | 231 controller_->layout_model().GetLabelFontListForRow(index), |
184 GetNativeTheme()->GetSystemColor( | 232 GetNativeTheme()->GetSystemColor( |
185 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText), | 233 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText), |
186 gfx::Rect(label_x_align_left, entry_rect.y(), label_width, | 234 gfx::Rect(label_x_align_left, entry_rect.y(), label_width, |
187 entry_rect.height()), | 235 entry_rect.height()), |
188 text_align); | 236 text_align); |
189 } | 237 } |
190 } | 238 } |
191 | 239 |
| 240 void AutofillPopupViewViews::GetAccessibleNodeData(ui::AXNodeData* node_data) { |
| 241 node_data->role = ui::AX_ROLE_MENU; |
| 242 node_data->SetName(l10n_util::GetStringUTF16( |
| 243 IDS_AUTOFILL_POPUP_ACCESSIBLE_NODE_DATA)); |
| 244 } |
| 245 |
192 AutofillPopupView* AutofillPopupView::Create( | 246 AutofillPopupView* AutofillPopupView::Create( |
193 AutofillPopupController* controller) { | 247 AutofillPopupController* controller) { |
194 views::Widget* observing_widget = | 248 views::Widget* observing_widget = |
195 views::Widget::GetTopLevelWidgetForNativeView( | 249 views::Widget::GetTopLevelWidgetForNativeView( |
196 controller->container_view()); | 250 controller->container_view()); |
197 | 251 |
198 // If the top level widget can't be found, cancel the popup since we can't | 252 // If the top level widget can't be found, cancel the popup since we can't |
199 // fully set it up. | 253 // fully set it up. |
200 if (!observing_widget) | 254 if (!observing_widget) |
201 return NULL; | 255 return NULL; |
202 | 256 |
203 return new AutofillPopupViewViews(controller, observing_widget); | 257 return new AutofillPopupViewViews(controller, observing_widget); |
204 } | 258 } |
205 | 259 |
206 } // namespace autofill | 260 } // namespace autofill |
OLD | NEW |