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 "base/optional.h" |
7 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" | 8 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" |
8 #include "chrome/browser/ui/autofill/autofill_popup_layout_model.h" | 9 #include "chrome/browser/ui/autofill/autofill_popup_layout_model.h" |
| 10 #include "chrome/grit/generated_resources.h" |
9 #include "components/autofill/core/browser/popup_item_ids.h" | 11 #include "components/autofill/core/browser/popup_item_ids.h" |
10 #include "components/autofill/core/browser/suggestion.h" | 12 #include "components/autofill/core/browser/suggestion.h" |
| 13 #include "ui/accessibility/ax_node_data.h" |
| 14 #include "ui/base/l10n/l10n_util.h" |
11 #include "ui/events/keycodes/keyboard_codes.h" | 15 #include "ui/events/keycodes/keyboard_codes.h" |
12 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
13 #include "ui/gfx/geometry/point.h" | 17 #include "ui/gfx/geometry/point.h" |
14 #include "ui/gfx/geometry/rect.h" | 18 #include "ui/gfx/geometry/rect.h" |
15 #include "ui/gfx/image/image.h" | 19 #include "ui/gfx/image/image.h" |
16 #include "ui/gfx/native_widget_types.h" | 20 #include "ui/gfx/native_widget_types.h" |
17 #include "ui/gfx/text_utils.h" | 21 #include "ui/gfx/text_utils.h" |
18 #include "ui/views/border.h" | 22 #include "ui/views/border.h" |
| 23 #include "ui/views/view.h" |
19 #include "ui/views/widget/widget.h" | 24 #include "ui/views/widget/widget.h" |
20 | 25 |
21 namespace autofill { | 26 namespace autofill { |
22 | 27 |
| 28 namespace { |
| 29 |
| 30 // Child view only for triggering accessibility events. Rendering is handled |
| 31 // by |AutofillPopupViewViews|. |
| 32 class AutofillPopupChildView : public views::View { |
| 33 public: |
| 34 explicit AutofillPopupChildView(const Suggestion& suggestion) |
| 35 : suggestion_(suggestion) { |
| 36 SetFocusBehavior(FocusBehavior::ALWAYS); |
| 37 } |
| 38 |
| 39 private: |
| 40 ~AutofillPopupChildView() override {} |
| 41 |
| 42 // views::Views implementation |
| 43 void GetAccessibleNodeData(ui::AXNodeData* node_data) override { |
| 44 node_data->role = ui::AX_ROLE_MENU_ITEM; |
| 45 node_data->SetName(suggestion_.value); |
| 46 } |
| 47 |
| 48 const Suggestion& suggestion_; |
| 49 |
| 50 DISALLOW_COPY_AND_ASSIGN(AutofillPopupChildView); |
| 51 }; |
| 52 |
| 53 } // namespace |
| 54 |
23 AutofillPopupViewViews::AutofillPopupViewViews( | 55 AutofillPopupViewViews::AutofillPopupViewViews( |
24 AutofillPopupController* controller, | 56 AutofillPopupController* controller, |
25 views::Widget* parent_widget) | 57 views::Widget* parent_widget) |
26 : AutofillPopupBaseView(controller, parent_widget), | 58 : AutofillPopupBaseView(controller, parent_widget), |
27 controller_(controller) {} | 59 controller_(controller) { |
| 60 CreateChildViews(); |
| 61 SetFocusBehavior(FocusBehavior::ALWAYS); |
| 62 } |
28 | 63 |
29 AutofillPopupViewViews::~AutofillPopupViewViews() {} | 64 AutofillPopupViewViews::~AutofillPopupViewViews() {} |
30 | 65 |
31 void AutofillPopupViewViews::Show() { | 66 void AutofillPopupViewViews::Show() { |
32 DoShow(); | 67 DoShow(); |
| 68 NotifyAccessibilityEvent(ui::AX_EVENT_MENU_START, true); |
33 } | 69 } |
34 | 70 |
35 void AutofillPopupViewViews::Hide() { | 71 void AutofillPopupViewViews::Hide() { |
36 // The controller is no longer valid after it hides us. | 72 // The controller is no longer valid after it hides us. |
37 controller_ = NULL; | 73 controller_ = NULL; |
38 | |
39 DoHide(); | 74 DoHide(); |
| 75 NotifyAccessibilityEvent(ui::AX_EVENT_MENU_END, true); |
40 } | 76 } |
41 | 77 |
42 void AutofillPopupViewViews::UpdateBoundsAndRedrawPopup() { | 78 void AutofillPopupViewViews::OnSuggestionsChanged() { |
| 79 // We recreate the child views so we can be sure the |controller_|'s |
| 80 // |GetLineCount()| will match the number of child views. Otherwise, |
| 81 // the number of suggestions i.e. |GetLineCount()| may not match 1x1 with the |
| 82 // child views. See crbug.com/697466. |
| 83 CreateChildViews(); |
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 |
50 canvas->DrawColor(GetNativeTheme()->GetSystemColor( | 91 canvas->DrawColor(GetNativeTheme()->GetSystemColor( |
51 ui::NativeTheme::kColorId_ResultsTableNormalBackground)); | 92 ui::NativeTheme::kColorId_ResultsTableNormalBackground)); |
52 OnPaintBorder(canvas); | 93 OnPaintBorder(canvas); |
53 | 94 |
| 95 DCHECK_EQ(controller_->GetLineCount(), static_cast<size_t>(child_count())); |
54 for (size_t i = 0; i < controller_->GetLineCount(); ++i) { | 96 for (size_t i = 0; i < controller_->GetLineCount(); ++i) { |
55 gfx::Rect line_rect = controller_->layout_model().GetRowBounds(i); | 97 gfx::Rect line_rect = controller_->layout_model().GetRowBounds(i); |
56 | 98 |
57 if (controller_->GetSuggestionAt(i).frontend_id == | 99 if (controller_->GetSuggestionAt(i).frontend_id == |
58 POPUP_ITEM_ID_SEPARATOR) { | 100 POPUP_ITEM_ID_SEPARATOR) { |
59 canvas->FillRect( | 101 canvas->FillRect( |
60 line_rect, | 102 line_rect, |
61 GetNativeTheme()->GetSystemColor( | 103 GetNativeTheme()->GetSystemColor( |
62 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText)); | 104 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText)); |
63 } else { | 105 } else { |
64 DrawAutofillEntry(canvas, i, line_rect); | 106 DrawAutofillEntry(canvas, i, line_rect); |
65 } | 107 } |
66 } | 108 } |
67 } | 109 } |
68 | 110 |
69 void AutofillPopupViewViews::InvalidateRow(size_t row) { | 111 void AutofillPopupViewViews::OnSelectedRowChanged( |
70 SchedulePaintInRect(controller_->layout_model().GetRowBounds(row)); | 112 base::Optional<size_t> previous_row_selection, |
| 113 base::Optional<size_t> current_row_selection) { |
| 114 if (previous_row_selection && |
| 115 previous_row_selection < controller_->GetLineCount()) { |
| 116 SchedulePaintInRect( |
| 117 controller_->layout_model().GetRowBounds(*previous_row_selection)); |
| 118 } |
| 119 |
| 120 if (current_row_selection) { |
| 121 SchedulePaintInRect( |
| 122 controller_->layout_model().GetRowBounds(*current_row_selection)); |
| 123 DCHECK_LT(*current_row_selection, static_cast<size_t>(child_count())); |
| 124 child_at(*current_row_selection) |
| 125 ->NotifyAccessibilityEvent(ui::AX_EVENT_SELECTION, true); |
| 126 } |
71 } | 127 } |
72 | 128 |
73 /** | 129 /** |
74 * Autofill entries in ltr. | 130 * Autofill entries in ltr. |
75 * | 131 * |
76 * ............................................................................ | 132 * ............................................................................ |
77 * . ICON | HTTP WARNING MESSAGE VALUE | LABEL . | 133 * . ICON | HTTP WARNING MESSAGE VALUE | LABEL . |
78 * ............................................................................ | 134 * ............................................................................ |
79 * . OTHER AUTOFILL ENTRY VALUE | LABEL | ICON . | 135 * . OTHER AUTOFILL ENTRY VALUE | LABEL | ICON . |
80 * ............................................................................ | 136 * ............................................................................ |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 controller_->GetElidedLabelAt(index), | 238 controller_->GetElidedLabelAt(index), |
183 controller_->layout_model().GetLabelFontListForRow(index), | 239 controller_->layout_model().GetLabelFontListForRow(index), |
184 GetNativeTheme()->GetSystemColor( | 240 GetNativeTheme()->GetSystemColor( |
185 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText), | 241 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText), |
186 gfx::Rect(label_x_align_left, entry_rect.y(), label_width, | 242 gfx::Rect(label_x_align_left, entry_rect.y(), label_width, |
187 entry_rect.height()), | 243 entry_rect.height()), |
188 text_align); | 244 text_align); |
189 } | 245 } |
190 } | 246 } |
191 | 247 |
| 248 void AutofillPopupViewViews::GetAccessibleNodeData(ui::AXNodeData* node_data) { |
| 249 node_data->role = ui::AX_ROLE_MENU; |
| 250 node_data->SetName( |
| 251 l10n_util::GetStringUTF16(IDS_AUTOFILL_POPUP_ACCESSIBLE_NODE_DATA)); |
| 252 } |
| 253 |
| 254 void AutofillPopupViewViews::CreateChildViews() { |
| 255 RemoveAllChildViews(true /* delete_children */); |
| 256 |
| 257 for (size_t i = 0; i < controller_->GetLineCount(); ++i) { |
| 258 AddChildView(new AutofillPopupChildView(controller_->GetSuggestionAt(i))); |
| 259 } |
| 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 |