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

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: Simplifies Views implementation by calling SchedulePaint instead of SchedulePaintInRect. 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 "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 SchedulePaint();
115 if (current_row_selection) {
116 DCHECK_LT(*current_row_selection, static_cast<size_t>(child_count()));
117 child_at(*current_row_selection)
118 ->NotifyAccessibilityEvent(ui::AX_EVENT_SELECTION, true);
119 }
71 } 120 }
72 121
73 /** 122 /**
74 * Autofill entries in ltr. 123 * Autofill entries in ltr.
75 * 124 *
76 * ............................................................................ 125 * ............................................................................
77 * . ICON | HTTP WARNING MESSAGE VALUE | LABEL . 126 * . ICON | HTTP WARNING MESSAGE VALUE | LABEL .
78 * ............................................................................ 127 * ............................................................................
79 * . OTHER AUTOFILL ENTRY VALUE | LABEL | ICON . 128 * . OTHER AUTOFILL ENTRY VALUE | LABEL | ICON .
80 * ............................................................................ 129 * ............................................................................
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 controller_->GetElidedLabelAt(index), 231 controller_->GetElidedLabelAt(index),
183 controller_->layout_model().GetLabelFontListForRow(index), 232 controller_->layout_model().GetLabelFontListForRow(index),
184 GetNativeTheme()->GetSystemColor( 233 GetNativeTheme()->GetSystemColor(
185 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText), 234 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText),
186 gfx::Rect(label_x_align_left, entry_rect.y(), label_width, 235 gfx::Rect(label_x_align_left, entry_rect.y(), label_width,
187 entry_rect.height()), 236 entry_rect.height()),
188 text_align); 237 text_align);
189 } 238 }
190 } 239 }
191 240
241 void AutofillPopupViewViews::GetAccessibleNodeData(ui::AXNodeData* node_data) {
242 node_data->role = ui::AX_ROLE_MENU;
243 node_data->SetName(
244 l10n_util::GetStringUTF16(IDS_AUTOFILL_POPUP_ACCESSIBLE_NODE_DATA));
245 }
246
247 void AutofillPopupViewViews::CreateChildViews() {
248 RemoveAllChildViews(true /* delete_children */);
249
250 for (size_t i = 0; i < controller_->GetLineCount(); ++i) {
251 AddChildView(new AutofillPopupChildView(controller_->GetSuggestionAt(i)));
252 }
253 }
254
192 AutofillPopupView* AutofillPopupView::Create( 255 AutofillPopupView* AutofillPopupView::Create(
193 AutofillPopupController* controller) { 256 AutofillPopupController* controller) {
194 views::Widget* observing_widget = 257 views::Widget* observing_widget =
195 views::Widget::GetTopLevelWidgetForNativeView( 258 views::Widget::GetTopLevelWidgetForNativeView(
196 controller->container_view()); 259 controller->container_view());
197 260
198 // If the top level widget can't be found, cancel the popup since we can't 261 // If the top level widget can't be found, cancel the popup since we can't
199 // fully set it up. 262 // fully set it up.
200 if (!observing_widget) 263 if (!observing_widget)
201 return NULL; 264 return NULL;
202 265
203 return new AutofillPopupViewViews(controller, observing_widget); 266 return new AutofillPopupViewViews(controller, observing_widget);
204 } 267 }
205 268
206 } // namespace autofill 269 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698