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" |
22 #include "ui/views/view.h" | |
19 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
20 | 24 |
21 namespace autofill { | 25 namespace autofill { |
22 | 26 |
27 namespace { | |
28 | |
29 // Child view only for triggering accessibility events. Rendering is handled | |
30 // by |AutofillPopupViewViews|. | |
31 class AutofillPopupChildView : public views::View { | |
32 public: | |
33 // Internal class name. | |
34 static const char kViewClassName[]; | |
35 | |
36 // |controller| should not be NULL. | |
37 AutofillPopupChildView(AutofillPopupController* controller, size_t index) | |
38 : controller_(controller), index_(index) { | |
39 SetFocusBehavior(FocusBehavior::ALWAYS); | |
40 } | |
41 | |
42 private: | |
43 ~AutofillPopupChildView() override {} | |
44 | |
45 // views::Views implementation | |
46 const char* GetClassName() const override { return kViewClassName; } | |
47 | |
48 void GetAccessibleNodeData(ui::AXNodeData* node_data) override { | |
49 // We do not special case |POPUP_ITEM_ID_SEPARATOR| suggestion because we | |
50 // skip that suggestion when the user navigates through the popup | |
51 // suggestions. See | AutofillPopupControllerImpl::CanAccept|. | |
52 node_data->role = ui::AX_ROLE_MENU_ITEM; | |
53 node_data->SetName(controller_->GetElidedValueAt(index_)); | |
54 } | |
55 | |
56 AutofillPopupController* controller_; // Weak reference. | |
57 const size_t index_; | |
58 | |
59 DISALLOW_COPY_AND_ASSIGN(AutofillPopupChildView); | |
60 }; | |
61 | |
62 // static | |
63 const char AutofillPopupChildView::kViewClassName[] = "AutofillPopupChildView"; | |
64 | |
65 } // namespace | |
66 | |
23 AutofillPopupViewViews::AutofillPopupViewViews( | 67 AutofillPopupViewViews::AutofillPopupViewViews( |
24 AutofillPopupController* controller, | 68 AutofillPopupController* controller, |
25 views::Widget* parent_widget) | 69 views::Widget* parent_widget) |
26 : AutofillPopupBaseView(controller, parent_widget), | 70 : AutofillPopupBaseView(controller, parent_widget), |
27 controller_(controller) {} | 71 controller_(controller) { |
72 for (size_t i = 0; i < controller_->GetLineCount(); ++i) { | |
73 AutofillPopupChildView* child = new AutofillPopupChildView(controller, i); | |
Evan Stade
2017/03/03 04:41:29
You can repro this crash by filling in a form, the
csashi
2017/03/03 04:48:19
Thanks! This was Mathieu's hypothesis as well but
| |
74 AddChildView(child); | |
75 } | |
76 SetFocusBehavior(FocusBehavior::ALWAYS); | |
77 } | |
28 | 78 |
29 AutofillPopupViewViews::~AutofillPopupViewViews() {} | 79 AutofillPopupViewViews::~AutofillPopupViewViews() {} |
30 | 80 |
31 void AutofillPopupViewViews::Show() { | 81 void AutofillPopupViewViews::Show() { |
32 DoShow(); | 82 DoShow(); |
83 NotifyAccessibilityEvent(ui::AX_EVENT_MENU_START, true); | |
33 } | 84 } |
34 | 85 |
35 void AutofillPopupViewViews::Hide() { | 86 void AutofillPopupViewViews::Hide() { |
36 // The controller is no longer valid after it hides us. | 87 // The controller is no longer valid after it hides us. |
37 controller_ = NULL; | 88 controller_ = NULL; |
38 | |
39 DoHide(); | 89 DoHide(); |
90 NotifyAccessibilityEvent(ui::AX_EVENT_MENU_END, true); | |
40 } | 91 } |
41 | 92 |
42 void AutofillPopupViewViews::UpdateBoundsAndRedrawPopup() { | 93 void AutofillPopupViewViews::UpdateBoundsAndRedrawPopup() { |
43 DoUpdateBoundsAndRedrawPopup(); | 94 DoUpdateBoundsAndRedrawPopup(); |
44 } | 95 } |
45 | 96 |
46 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) { | 97 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) { |
47 if (!controller_) | 98 if (!controller_) |
48 return; | 99 return; |
49 | 100 |
50 canvas->DrawColor(GetNativeTheme()->GetSystemColor( | 101 canvas->DrawColor(GetNativeTheme()->GetSystemColor( |
51 ui::NativeTheme::kColorId_ResultsTableNormalBackground)); | 102 ui::NativeTheme::kColorId_ResultsTableNormalBackground)); |
52 OnPaintBorder(canvas); | 103 OnPaintBorder(canvas); |
53 | 104 |
105 CHECK_EQ(controller_->GetLineCount(), (size_t)child_count()); | |
54 for (size_t i = 0; i < controller_->GetLineCount(); ++i) { | 106 for (size_t i = 0; i < controller_->GetLineCount(); ++i) { |
55 gfx::Rect line_rect = controller_->layout_model().GetRowBounds(i); | 107 gfx::Rect line_rect = controller_->layout_model().GetRowBounds(i); |
56 | 108 |
57 if (controller_->GetSuggestionAt(i).frontend_id == | 109 if (controller_->GetSuggestionAt(i).frontend_id == |
58 POPUP_ITEM_ID_SEPARATOR) { | 110 POPUP_ITEM_ID_SEPARATOR) { |
59 canvas->FillRect( | 111 canvas->FillRect( |
60 line_rect, | 112 line_rect, |
61 GetNativeTheme()->GetSystemColor( | 113 GetNativeTheme()->GetSystemColor( |
62 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText)); | 114 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText)); |
63 } else { | 115 } else { |
64 DrawAutofillEntry(canvas, i, line_rect); | 116 DrawAutofillEntry(canvas, i, line_rect); |
65 } | 117 } |
66 } | 118 } |
67 } | 119 } |
68 | 120 |
69 void AutofillPopupViewViews::InvalidateRow(size_t row) { | 121 void AutofillPopupViewViews::InvalidateRow(size_t row) { |
70 SchedulePaintInRect(controller_->layout_model().GetRowBounds(row)); | 122 SchedulePaintInRect(controller_->layout_model().GetRowBounds(row)); |
71 } | 123 } |
72 | 124 |
125 void AutofillPopupViewViews::NotifyAccessibilityEventForRow( | |
126 ui::AXEvent event_type, | |
127 size_t row) { | |
128 CHECK_LT(row, (size_t)child_count()); | |
sky
2017/03/03 03:35:46
Use C++ style casts, .e.g static_cast<size_t>(chil
csashi
2017/03/03 04:39:42
Done.
| |
129 views::View* child = child_at(row); | |
130 CHECK(child); | |
131 CHECK_EQ(child->GetClassName(), AutofillPopupChildView::kViewClassName); | |
132 AutofillPopupChildView* child_view = | |
133 static_cast<AutofillPopupChildView*>(child); | |
134 child_view->NotifyAccessibilityEvent(event_type, true); | |
135 } | |
136 | |
73 /** | 137 /** |
74 * Autofill entries in ltr. | 138 * Autofill entries in ltr. |
75 * | 139 * |
76 * ............................................................................ | 140 * ............................................................................ |
77 * . ICON | HTTP WARNING MESSAGE VALUE | LABEL . | 141 * . ICON | HTTP WARNING MESSAGE VALUE | LABEL . |
78 * ............................................................................ | 142 * ............................................................................ |
79 * . OTHER AUTOFILL ENTRY VALUE | LABEL | ICON . | 143 * . OTHER AUTOFILL ENTRY VALUE | LABEL | ICON . |
80 * ............................................................................ | 144 * ............................................................................ |
81 * | 145 * |
82 * Autofill entries in rtl. | 146 * Autofill entries in rtl. |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 controller_->GetElidedLabelAt(index), | 246 controller_->GetElidedLabelAt(index), |
183 controller_->layout_model().GetLabelFontListForRow(index), | 247 controller_->layout_model().GetLabelFontListForRow(index), |
184 GetNativeTheme()->GetSystemColor( | 248 GetNativeTheme()->GetSystemColor( |
185 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText), | 249 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText), |
186 gfx::Rect(label_x_align_left, entry_rect.y(), label_width, | 250 gfx::Rect(label_x_align_left, entry_rect.y(), label_width, |
187 entry_rect.height()), | 251 entry_rect.height()), |
188 text_align); | 252 text_align); |
189 } | 253 } |
190 } | 254 } |
191 | 255 |
256 void AutofillPopupViewViews::GetAccessibleNodeData(ui::AXNodeData* node_data) { | |
257 node_data->role = ui::AX_ROLE_MENU; | |
258 node_data->SetName( | |
259 l10n_util::GetStringUTF16(IDS_AUTOFILL_POPUP_ACCESSIBLE_NODE_DATA)); | |
260 } | |
261 | |
192 AutofillPopupView* AutofillPopupView::Create( | 262 AutofillPopupView* AutofillPopupView::Create( |
193 AutofillPopupController* controller) { | 263 AutofillPopupController* controller) { |
194 views::Widget* observing_widget = | 264 views::Widget* observing_widget = |
195 views::Widget::GetTopLevelWidgetForNativeView( | 265 views::Widget::GetTopLevelWidgetForNativeView( |
196 controller->container_view()); | 266 controller->container_view()); |
197 | 267 |
198 // If the top level widget can't be found, cancel the popup since we can't | 268 // If the top level widget can't be found, cancel the popup since we can't |
199 // fully set it up. | 269 // fully set it up. |
200 if (!observing_widget) | 270 if (!observing_widget) |
201 return NULL; | 271 return NULL; |
202 | 272 |
203 return new AutofillPopupViewViews(controller, observing_widget); | 273 return new AutofillPopupViewViews(controller, observing_widget); |
204 } | 274 } |
205 | 275 |
206 } // namespace autofill | 276 } // namespace autofill |
OLD | NEW |