Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Side by Side Diff: chrome/browser/ui/views/autofill/autofill_popup_view_views.cc

Issue 2727233003: Uses child views in Autofill Popup so we can trigger (Closed)
Patch Set: Adds test coverage for changing number of suggestions. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 CreateChildViews();
73 SetFocusBehavior(FocusBehavior::ALWAYS);
74 }
28 75
29 AutofillPopupViewViews::~AutofillPopupViewViews() {} 76 AutofillPopupViewViews::~AutofillPopupViewViews() {}
30 77
31 void AutofillPopupViewViews::Show() { 78 void AutofillPopupViewViews::Show() {
32 DoShow(); 79 DoShow();
80 NotifyAccessibilityEvent(ui::AX_EVENT_MENU_START, true);
33 } 81 }
34 82
35 void AutofillPopupViewViews::Hide() { 83 void AutofillPopupViewViews::Hide() {
36 // The controller is no longer valid after it hides us. 84 // The controller is no longer valid after it hides us.
37 controller_ = NULL; 85 controller_ = NULL;
38
39 DoHide(); 86 DoHide();
87 NotifyAccessibilityEvent(ui::AX_EVENT_MENU_END, true);
40 } 88 }
41 89
42 void AutofillPopupViewViews::UpdateBoundsAndRedrawPopup() { 90 void AutofillPopupViewViews::UpdateBoundsAndRedrawPopup() {
91 // We recreate the child views so we can be sure the |controller_|'s
92 // |GetLineCount()| will match the number of child views. Otherwise,
93 // the number of suggestions i.e. |GetLineCount()| may not match 1x1 with the
94 // child views. See crbug.com/697466.
95 // Currently, child views get the data from 'controller_'. If the child views
96 // save additional state corresponding to the suggestion, we must recreate the
97 // child views even when |GetLineCount()| == |child_count()| because the
98 // suggestion content may change.
99 if (controller_->GetLineCount() != static_cast<size_t>(child_count())) {
100 RemoveAllChildViews(true /* delete_children */);
101 CreateChildViews();
102 }
43 DoUpdateBoundsAndRedrawPopup(); 103 DoUpdateBoundsAndRedrawPopup();
44 } 104 }
45 105
46 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) { 106 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) {
47 if (!controller_) 107 if (!controller_)
48 return; 108 return;
49 109
50 canvas->DrawColor(GetNativeTheme()->GetSystemColor( 110 canvas->DrawColor(GetNativeTheme()->GetSystemColor(
51 ui::NativeTheme::kColorId_ResultsTableNormalBackground)); 111 ui::NativeTheme::kColorId_ResultsTableNormalBackground));
52 OnPaintBorder(canvas); 112 OnPaintBorder(canvas);
53 113
114 CHECK_EQ(controller_->GetLineCount(), static_cast<size_t>(child_count()));
54 for (size_t i = 0; i < controller_->GetLineCount(); ++i) { 115 for (size_t i = 0; i < controller_->GetLineCount(); ++i) {
55 gfx::Rect line_rect = controller_->layout_model().GetRowBounds(i); 116 gfx::Rect line_rect = controller_->layout_model().GetRowBounds(i);
56 117
57 if (controller_->GetSuggestionAt(i).frontend_id == 118 if (controller_->GetSuggestionAt(i).frontend_id ==
58 POPUP_ITEM_ID_SEPARATOR) { 119 POPUP_ITEM_ID_SEPARATOR) {
59 canvas->FillRect( 120 canvas->FillRect(
60 line_rect, 121 line_rect,
61 GetNativeTheme()->GetSystemColor( 122 GetNativeTheme()->GetSystemColor(
62 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText)); 123 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText));
63 } else { 124 } else {
64 DrawAutofillEntry(canvas, i, line_rect); 125 DrawAutofillEntry(canvas, i, line_rect);
65 } 126 }
66 } 127 }
67 } 128 }
68 129
69 void AutofillPopupViewViews::InvalidateRow(size_t row) { 130 void AutofillPopupViewViews::InvalidateRow(size_t row) {
70 SchedulePaintInRect(controller_->layout_model().GetRowBounds(row)); 131 SchedulePaintInRect(controller_->layout_model().GetRowBounds(row));
71 } 132 }
72 133
134 void AutofillPopupViewViews::NotifyAccessibilityEventForRow(
135 ui::AXEvent event_type,
136 size_t row) {
137 CHECK_LT(row, static_cast<size_t>(child_count()));
138 views::View* child = child_at(row);
139 CHECK(child);
140 CHECK_EQ(child->GetClassName(), AutofillPopupChildView::kViewClassName);
141 AutofillPopupChildView* child_view =
142 static_cast<AutofillPopupChildView*>(child);
143 child_view->NotifyAccessibilityEvent(event_type, true);
144 }
145
73 /** 146 /**
74 * Autofill entries in ltr. 147 * Autofill entries in ltr.
75 * 148 *
76 * ............................................................................ 149 * ............................................................................
77 * . ICON | HTTP WARNING MESSAGE VALUE | LABEL . 150 * . ICON | HTTP WARNING MESSAGE VALUE | LABEL .
78 * ............................................................................ 151 * ............................................................................
79 * . OTHER AUTOFILL ENTRY VALUE | LABEL | ICON . 152 * . OTHER AUTOFILL ENTRY VALUE | LABEL | ICON .
80 * ............................................................................ 153 * ............................................................................
81 * 154 *
82 * Autofill entries in rtl. 155 * Autofill entries in rtl.
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 controller_->GetElidedLabelAt(index), 255 controller_->GetElidedLabelAt(index),
183 controller_->layout_model().GetLabelFontListForRow(index), 256 controller_->layout_model().GetLabelFontListForRow(index),
184 GetNativeTheme()->GetSystemColor( 257 GetNativeTheme()->GetSystemColor(
185 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText), 258 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText),
186 gfx::Rect(label_x_align_left, entry_rect.y(), label_width, 259 gfx::Rect(label_x_align_left, entry_rect.y(), label_width,
187 entry_rect.height()), 260 entry_rect.height()),
188 text_align); 261 text_align);
189 } 262 }
190 } 263 }
191 264
265 void AutofillPopupViewViews::GetAccessibleNodeData(ui::AXNodeData* node_data) {
266 node_data->role = ui::AX_ROLE_MENU;
267 node_data->SetName(
268 l10n_util::GetStringUTF16(IDS_AUTOFILL_POPUP_ACCESSIBLE_NODE_DATA));
269 }
270
271 void AutofillPopupViewViews::CreateChildViews() {
272 for (size_t i = 0; i < controller_->GetLineCount(); ++i) {
273 AutofillPopupChildView* child = new AutofillPopupChildView(controller_, i);
274 AddChildView(child);
275 }
276 }
277
192 AutofillPopupView* AutofillPopupView::Create( 278 AutofillPopupView* AutofillPopupView::Create(
193 AutofillPopupController* controller) { 279 AutofillPopupController* controller) {
194 views::Widget* observing_widget = 280 views::Widget* observing_widget =
195 views::Widget::GetTopLevelWidgetForNativeView( 281 views::Widget::GetTopLevelWidgetForNativeView(
196 controller->container_view()); 282 controller->container_view());
197 283
198 // If the top level widget can't be found, cancel the popup since we can't 284 // If the top level widget can't be found, cancel the popup since we can't
199 // fully set it up. 285 // fully set it up.
200 if (!observing_widget) 286 if (!observing_widget)
201 return NULL; 287 return NULL;
202 288
203 return new AutofillPopupViewViews(controller, observing_widget); 289 return new AutofillPopupViewViews(controller, observing_widget);
204 } 290 }
205 291
206 } // namespace autofill 292 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698