Chromium Code Reviews| 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 // |controller| should not be NULL. | |
| 34 AutofillPopupChildView(AutofillPopupController* controller, size_t index) | |
| 35 : controller_(controller), index_(index) { | |
| 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 // We do not special case |POPUP_ITEM_ID_SEPARATOR| suggestion because we | |
| 45 // skip that suggestion when the user navigates through the popup | |
| 46 // suggestions. See | AutofillPopupControllerImpl::CanAccept|. | |
| 47 node_data->role = ui::AX_ROLE_MENU_ITEM; | |
| 48 node_data->SetName(controller_->GetElidedValueAt(index_)); | |
| 49 } | |
| 50 | |
| 51 AutofillPopupController* controller_; // Weak reference. | |
| 52 const size_t index_; | |
| 53 | |
| 54 DISALLOW_COPY_AND_ASSIGN(AutofillPopupChildView); | |
| 55 }; | |
| 56 | |
| 57 } // namespace | |
| 58 | |
| 23 AutofillPopupViewViews::AutofillPopupViewViews( | 59 AutofillPopupViewViews::AutofillPopupViewViews( |
| 24 AutofillPopupController* controller, | 60 AutofillPopupController* controller, views::Widget* parent_widget) |
| 25 views::Widget* parent_widget) | |
| 26 : AutofillPopupBaseView(controller, parent_widget), | 61 : AutofillPopupBaseView(controller, parent_widget), |
| 27 controller_(controller) {} | 62 controller_(controller) { |
| 63 for (size_t i = 0; i < controller_->GetLineCount(); ++i) { | |
| 64 AutofillPopupChildView* child = new AutofillPopupChildView(controller, i); | |
| 65 AddChildViewAt(child, static_cast<int>(i)); | |
|
sky
2017/02/27 21:05:57
optional: AddChildViewAt(child); works the same he
csashi
2017/02/27 21:32:38
Done.
| |
| 66 } | |
| 67 SetFocusBehavior(FocusBehavior::ALWAYS); | |
| 68 } | |
| 28 | 69 |
| 29 AutofillPopupViewViews::~AutofillPopupViewViews() {} | 70 AutofillPopupViewViews::~AutofillPopupViewViews() {} |
| 30 | 71 |
| 31 void AutofillPopupViewViews::Show() { | 72 void AutofillPopupViewViews::Show() { |
| 32 DoShow(); | 73 DoShow(); |
| 74 NotifyAccessibilityEvent(ui::AX_EVENT_MENU_START, true); | |
| 33 } | 75 } |
| 34 | 76 |
| 35 void AutofillPopupViewViews::Hide() { | 77 void AutofillPopupViewViews::Hide() { |
|
sky
2017/02/27 21:05:57
As DoHide is public, might that be called instead
csashi
2017/02/27 21:32:37
If I am reading correctly, DoHide is protected - I
sky
2017/02/27 23:31:04
I'm not sure either. Maybe Dominic has an opinion
sky
2017/02/28 04:03:32
Did Dominic respond to this?
dmazzoni
2017/02/28 16:53:18
We should be cautious about calling NotifyAccessib
| |
| 36 // The controller is no longer valid after it hides us. | 78 // The controller is no longer valid after it hides us. |
| 37 controller_ = NULL; | 79 controller_ = NULL; |
| 38 | |
| 39 DoHide(); | 80 DoHide(); |
| 81 NotifyAccessibilityEvent(ui::AX_EVENT_MENU_END, true); | |
| 40 } | 82 } |
| 41 | 83 |
| 42 void AutofillPopupViewViews::UpdateBoundsAndRedrawPopup() { | 84 void AutofillPopupViewViews::UpdateBoundsAndRedrawPopup() { |
| 43 DoUpdateBoundsAndRedrawPopup(); | 85 DoUpdateBoundsAndRedrawPopup(); |
| 44 } | 86 } |
| 45 | 87 |
| 46 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) { | 88 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) { |
| 47 if (!controller_) | 89 if (!controller_) |
| 48 return; | 90 return; |
| 49 | 91 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 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::InvalidateRow(size_t row) { |
| 70 SchedulePaintInRect(controller_->layout_model().GetRowBounds(row)); | 112 SchedulePaintInRect(controller_->layout_model().GetRowBounds(row)); |
| 71 } | 113 } |
| 72 | 114 |
| 115 void AutofillPopupViewViews::NotifyAccessibilityEventForRow( | |
| 116 ui::AXEvent event_type, size_t row) { | |
| 117 AutofillPopupChildView *child_view = | |
| 118 static_cast<AutofillPopupChildView*>(child_at(row)); | |
|
sky
2017/02/27 21:05:57
This code makes me nervous. How do you know some o
csashi
2017/02/27 21:32:38
This class hierarchy is currently not deep. Hence,
sky
2017/02/27 23:31:04
My concern is the static_cast, but I'm ok with it.
csashi
2017/02/28 00:03:06
Acknowledged.
| |
| 119 child_view->NotifyAccessibilityEvent(event_type, true); | |
| 120 } | |
| 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 * ............................................................................ |
| 81 * | 130 * |
| 82 * Autofill entries in rtl. | 131 * Autofill entries in rtl. |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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(l10n_util::GetStringUTF16( | |
| 244 IDS_AUTOFILL_POPUP_ACCESSIBLE_NODE_DATA)); | |
| 245 } | |
| 246 | |
| 192 AutofillPopupView* AutofillPopupView::Create( | 247 AutofillPopupView* AutofillPopupView::Create( |
| 193 AutofillPopupController* controller) { | 248 AutofillPopupController* controller) { |
| 194 views::Widget* observing_widget = | 249 views::Widget* observing_widget = |
| 195 views::Widget::GetTopLevelWidgetForNativeView( | 250 views::Widget::GetTopLevelWidgetForNativeView( |
| 196 controller->container_view()); | 251 controller->container_view()); |
| 197 | 252 |
| 198 // If the top level widget can't be found, cancel the popup since we can't | 253 // If the top level widget can't be found, cancel the popup since we can't |
| 199 // fully set it up. | 254 // fully set it up. |
| 200 if (!observing_widget) | 255 if (!observing_widget) |
| 201 return NULL; | 256 return NULL; |
| 202 | 257 |
| 203 return new AutofillPopupViewViews(controller, observing_widget); | 258 return new AutofillPopupViewViews(controller, observing_widget); |
| 204 } | 259 } |
| 205 | 260 |
| 206 } // namespace autofill | 261 } // namespace autofill |
| OLD | NEW |