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

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: Removes NotifyAccessibilityEventForRow and InvalidateRow wrapper methods. 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|.
Evan Stade 2017/03/09 03:21:15 nit: I'm not sure this comment is necessary, simpl
csashi 2017/03/09 05:16:33 Done.
52 node_data->role = ui::AX_ROLE_MENU_ITEM;
53 node_data->SetName(controller_->GetElidedValueAt(index_));
Evan Stade 2017/03/09 03:21:16 it seems like we shouldn't be using the elided ver
csashi 2017/03/09 05:16:33 Done.
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::OnSuggestionsChanged() {
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()));
Evan Stade 2017/03/09 03:21:16 nit: s/check/dcheck
csashi 2017/03/09 05:16:33 Done.
csashi 2017/03/09 05:16:33 Done.
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, bool is_selected) {
Evan Stade 2017/03/09 03:21:16 I think this is reasonable, but you should change
csashi 2017/03/09 05:16:33 Done.
70 SchedulePaintInRect(controller_->layout_model().GetRowBounds(row)); 131 SchedulePaintInRect(controller_->layout_model().GetRowBounds(row));
132 if (is_selected) {
133 CHECK_LT(row, static_cast<size_t>(child_count()));
134 views::View* child = child_at(row);
135 CHECK(child);
136 CHECK_EQ(child->GetClassName(), AutofillPopupChildView::kViewClassName);
137 AutofillPopupChildView* child_view =
138 static_cast<AutofillPopupChildView*>(child);
139 child_view->NotifyAccessibilityEvent(ui::AX_EVENT_SELECTION, true);
140 }
71 } 141 }
72 142
73 /** 143 /**
74 * Autofill entries in ltr. 144 * Autofill entries in ltr.
75 * 145 *
76 * ............................................................................ 146 * ............................................................................
77 * . ICON | HTTP WARNING MESSAGE VALUE | LABEL . 147 * . ICON | HTTP WARNING MESSAGE VALUE | LABEL .
78 * ............................................................................ 148 * ............................................................................
79 * . OTHER AUTOFILL ENTRY VALUE | LABEL | ICON . 149 * . OTHER AUTOFILL ENTRY VALUE | LABEL | ICON .
80 * ............................................................................ 150 * ............................................................................
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 controller_->GetElidedLabelAt(index), 252 controller_->GetElidedLabelAt(index),
183 controller_->layout_model().GetLabelFontListForRow(index), 253 controller_->layout_model().GetLabelFontListForRow(index),
184 GetNativeTheme()->GetSystemColor( 254 GetNativeTheme()->GetSystemColor(
185 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText), 255 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText),
186 gfx::Rect(label_x_align_left, entry_rect.y(), label_width, 256 gfx::Rect(label_x_align_left, entry_rect.y(), label_width,
187 entry_rect.height()), 257 entry_rect.height()),
188 text_align); 258 text_align);
189 } 259 }
190 } 260 }
191 261
262 void AutofillPopupViewViews::GetAccessibleNodeData(ui::AXNodeData* node_data) {
263 node_data->role = ui::AX_ROLE_MENU;
264 node_data->SetName(
265 l10n_util::GetStringUTF16(IDS_AUTOFILL_POPUP_ACCESSIBLE_NODE_DATA));
266 }
267
268 void AutofillPopupViewViews::CreateChildViews() {
269 for (size_t i = 0; i < controller_->GetLineCount(); ++i) {
270 AutofillPopupChildView* child = new AutofillPopupChildView(controller_, i);
271 AddChildView(child);
272 }
273 }
274
192 AutofillPopupView* AutofillPopupView::Create( 275 AutofillPopupView* AutofillPopupView::Create(
193 AutofillPopupController* controller) { 276 AutofillPopupController* controller) {
194 views::Widget* observing_widget = 277 views::Widget* observing_widget =
195 views::Widget::GetTopLevelWidgetForNativeView( 278 views::Widget::GetTopLevelWidgetForNativeView(
196 controller->container_view()); 279 controller->container_view());
197 280
198 // If the top level widget can't be found, cancel the popup since we can't 281 // If the top level widget can't be found, cancel the popup since we can't
199 // fully set it up. 282 // fully set it up.
200 if (!observing_widget) 283 if (!observing_widget)
201 return NULL; 284 return NULL;
202 285
203 return new AutofillPopupViewViews(controller, observing_widget); 286 return new AutofillPopupViewViews(controller, observing_widget);
204 } 287 }
205 288
206 } // namespace autofill 289 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698