OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/chromeos/arc/accessibility/arc_accessibility_helper_bri dge.h" | 5 #include "chrome/browser/chromeos/arc/accessibility/arc_accessibility_helper_bri dge.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | 8 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
9 #include "chrome/browser/chromeos/arc/accessibility/ax_tree_source_arc.h" | 9 #include "chrome/browser/chromeos/arc/accessibility/ax_tree_source_arc.h" |
10 #include "chromeos/chromeos_switches.h" | 10 #include "chromeos/chromeos_switches.h" |
11 #include "components/arc/arc_bridge_service.h" | 11 #include "components/arc/arc_bridge_service.h" |
12 #include "components/exo/shell_surface.h" | 12 #include "components/exo/shell_surface.h" |
13 #include "components/exo/surface.h" | 13 #include "components/exo/surface.h" |
14 #include "ui/aura/client/aura_constants.h" | 14 #include "ui/aura/client/aura_constants.h" |
15 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
16 #include "ui/gfx/geometry/rect.h" | 16 #include "ui/gfx/geometry/rect.h" |
17 #include "ui/views/view.h" | 17 #include "ui/views/view.h" |
18 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 // This class keeps focus on a |ShellSurface| without interfering with default | 22 // This class keeps focus on a |ShellSurface| without interfering with default |
23 // focus management in |ShellSurface|. For example, touch causes the | 23 // focus management in |ShellSurface|. For example, touch causes the |
24 // |ShellSurface| to lose focus to its ancestor containing View. | 24 // |ShellSurface| to lose focus to its ancestor containing View. |
25 class FocusStealer : public views::View { | 25 class FocusStealer : public views::View { |
26 public: | 26 public: |
27 explicit FocusStealer(int32_t id) : id_(id) { | 27 explicit FocusStealer(int32_t id) : id_(id) { |
28 set_owned_by_client(); | |
29 } | |
30 | |
31 void StartStealing() { | |
28 SetFocusBehavior(views::View::FocusBehavior::ALWAYS); | 32 SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
29 set_owned_by_client(); | 33 RequestFocus(); |
34 parent()->NotifyAccessibilityEvent(ui::AX_EVENT_CHILDREN_CHANGED, false); | |
35 } | |
36 | |
37 void StopStealing() { | |
38 SetFocusBehavior(views::View::FocusBehavior::NEVER); | |
39 parent()->NotifyAccessibilityEvent(ui::AX_EVENT_CHILDREN_CHANGED, false); | |
30 } | 40 } |
31 | 41 |
32 // views::View overrides. | 42 // views::View overrides. |
33 void GetAccessibleNodeData(ui::AXNodeData* node_data) override { | 43 void GetAccessibleNodeData(ui::AXNodeData* node_data) override { |
34 node_data->AddIntAttribute(ui::AX_ATTR_CHILD_TREE_ID, id_); | 44 node_data->AddIntAttribute(ui::AX_ATTR_CHILD_TREE_ID, id_); |
35 node_data->role = ui::AX_ROLE_CLIENT; | 45 node_data->role = ui::AX_ROLE_CLIENT; |
36 } | 46 } |
37 | 47 |
38 private: | 48 private: |
39 int32_t id_; | 49 int32_t id_; |
(...skipping 23 matching lines...) Expand all Loading... | |
63 | 73 |
64 aura::Window* toplevel_window = focused_window->GetToplevelWindow(); | 74 aura::Window* toplevel_window = focused_window->GetToplevelWindow(); |
65 | 75 |
66 gfx::Rect bounds_in_screen = gfx::ScaleToEnclosingRect( | 76 gfx::Rect bounds_in_screen = gfx::ScaleToEnclosingRect( |
67 node_data->boundsInScreen, | 77 node_data->boundsInScreen, |
68 1.0f / toplevel_window->layer()->device_scale_factor()); | 78 1.0f / toplevel_window->layer()->device_scale_factor()); |
69 | 79 |
70 accessibility_manager->OnViewFocusedInArc(bounds_in_screen); | 80 accessibility_manager->OnViewFocusedInArc(bounds_in_screen); |
71 } | 81 } |
72 | 82 |
83 arc::mojom::AccessibilityFilterType GetFilterType() { | |
84 chromeos::AccessibilityManager* accessibility_manager = | |
85 chromeos::AccessibilityManager::Get(); | |
86 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
87 chromeos::switches::kEnableChromeVoxArcSupport)) | |
Luis Héctor Chávez
2017/04/21 15:20:07
nit: you cannot elide braces on this block since t
David Tseng
2017/04/25 18:29:48
Done (though note that this seems somewhat ambiguo
| |
88 return arc::mojom::AccessibilityFilterType::ALL; | |
89 | |
90 if (!accessibility_manager) | |
91 return arc::mojom::AccessibilityFilterType::OFF; | |
92 | |
93 if (accessibility_manager->IsSpokenFeedbackEnabled()) | |
94 return arc::mojom::AccessibilityFilterType::WHITELISTED_PACKAGE_NAME; | |
95 | |
96 if (accessibility_manager->IsFocusHighlightEnabled()) | |
97 return arc::mojom::AccessibilityFilterType::FOCUS; | |
98 | |
99 return arc::mojom::AccessibilityFilterType::OFF; | |
100 } | |
101 | |
73 } // namespace | 102 } // namespace |
74 | 103 |
75 namespace arc { | 104 namespace arc { |
76 | 105 |
77 ArcAccessibilityHelperBridge::ArcAccessibilityHelperBridge( | 106 ArcAccessibilityHelperBridge::ArcAccessibilityHelperBridge( |
78 ArcBridgeService* bridge_service) | 107 ArcBridgeService* bridge_service) |
79 : ArcService(bridge_service), binding_(this) { | 108 : ArcService(bridge_service), binding_(this) { |
80 arc_bridge_service()->accessibility_helper()->AddObserver(this); | 109 arc_bridge_service()->accessibility_helper()->AddObserver(this); |
81 } | 110 } |
82 | 111 |
83 ArcAccessibilityHelperBridge::~ArcAccessibilityHelperBridge() { | 112 ArcAccessibilityHelperBridge::~ArcAccessibilityHelperBridge() { |
84 arc_bridge_service()->accessibility_helper()->RemoveObserver(this); | 113 arc_bridge_service()->accessibility_helper()->RemoveObserver(this); |
85 } | 114 } |
86 | 115 |
87 void ArcAccessibilityHelperBridge::OnInstanceReady() { | 116 void ArcAccessibilityHelperBridge::OnInstanceReady() { |
88 auto* instance = ARC_GET_INSTANCE_FOR_METHOD( | 117 auto* instance = ARC_GET_INSTANCE_FOR_METHOD( |
89 arc_bridge_service()->accessibility_helper(), Init); | 118 arc_bridge_service()->accessibility_helper(), Init); |
90 DCHECK(instance); | 119 DCHECK(instance); |
91 instance->Init(binding_.CreateInterfacePtrAndBind()); | 120 instance->Init(binding_.CreateInterfacePtrAndBind()); |
92 | 121 |
93 chromeos::AccessibilityManager* accessibility_manager = | 122 arc::mojom::AccessibilityFilterType filter_type = GetFilterType(); |
94 chromeos::AccessibilityManager::Get(); | 123 instance->SetFilter(filter_type); |
95 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 124 |
96 chromeos::switches::kEnableChromeVoxArcSupport)) { | 125 switch (filter_type) { |
97 instance->SetFilter(arc::mojom::AccessibilityFilterType::ALL); | 126 case arc::mojom::AccessibilityFilterType::ALL: |
Luis Héctor Chávez
2017/04/21 15:20:07
Consider adding
// fallthrough
on the cases wher
David Tseng
2017/04/25 18:29:48
Acknowledged.
| |
98 if (!tree_source_) { | 127 case arc::mojom::AccessibilityFilterType::WHITELISTED_PACKAGE_NAME: |
99 tree_source_.reset(new AXTreeSourceArc(tree_id())); | 128 if (!tree_source_) { |
100 focus_stealer_.reset(new FocusStealer(tree_source_->tree_id())); | 129 tree_source_.reset(new AXTreeSourceArc(tree_id())); |
101 exo::WMHelper::GetInstance()->AddActivationObserver(this); | 130 focus_stealer_.reset(new FocusStealer(tree_source_->tree_id())); |
102 } | 131 exo::WMHelper::GetInstance()->AddActivationObserver(this); |
103 } else if (accessibility_manager && | 132 } |
104 accessibility_manager->IsFocusHighlightEnabled()) { | 133 break; |
105 instance->SetFilter(arc::mojom::AccessibilityFilterType::FOCUS); | 134 case arc::mojom::AccessibilityFilterType::FOCUS: |
135 case arc::mojom::AccessibilityFilterType::OFF: | |
136 break; | |
hidehiko
2017/04/21 06:27:02
nit: how about commenting
// Do nothing.
to expli
David Tseng
2017/04/25 18:29:48
Acknowledged.
| |
106 } | 137 } |
107 } | 138 } |
108 | 139 |
109 void ArcAccessibilityHelperBridge::OnAccessibilityEventDeprecated( | 140 void ArcAccessibilityHelperBridge::OnAccessibilityEventDeprecated( |
110 mojom::AccessibilityEventType event_type, | 141 mojom::AccessibilityEventType event_type, |
111 mojom::AccessibilityNodeInfoDataPtr event_source) { | 142 mojom::AccessibilityNodeInfoDataPtr event_source) { |
112 if (event_type == arc::mojom::AccessibilityEventType::VIEW_FOCUSED) | 143 if (event_type == arc::mojom::AccessibilityEventType::VIEW_FOCUSED) |
113 DispatchFocusChange(event_source.get()); | 144 DispatchFocusChange(event_source.get()); |
114 } | 145 } |
115 | 146 |
116 void ArcAccessibilityHelperBridge::OnAccessibilityEvent( | 147 void ArcAccessibilityHelperBridge::OnAccessibilityEvent( |
117 mojom::AccessibilityEventDataPtr event_data) { | 148 mojom::AccessibilityEventDataPtr event_data) { |
149 arc::mojom::AccessibilityFilterType filter_type = GetFilterType(); | |
150 | |
151 if (!tree_source_ && | |
yawano
2017/04/21 04:26:36
How about to write this function as
switch (filte
David Tseng
2017/04/25 18:29:48
Acknowledged.
| |
152 (filter_type == arc::mojom::AccessibilityFilterType::ALL || | |
153 filter_type == | |
154 arc::mojom::AccessibilityFilterType::WHITELISTED_PACKAGE_NAME)) { | |
155 tree_source_.reset(new AXTreeSourceArc(tree_id())); | |
156 } | |
157 | |
118 if (tree_source_) { | 158 if (tree_source_) { |
119 tree_source_->NotifyAccessibilityEvent(event_data.get()); | 159 tree_source_->NotifyAccessibilityEvent(event_data.get()); |
120 return; | 160 return; |
121 } | 161 } |
122 | 162 |
123 if (event_data->eventType != arc::mojom::AccessibilityEventType::VIEW_FOCUSED) | 163 if (event_data->eventType != arc::mojom::AccessibilityEventType::VIEW_FOCUSED) |
124 return; | 164 return; |
125 | 165 |
126 CHECK_EQ(1U, event_data.get()->nodeData.size()); | 166 CHECK_EQ(1U, event_data.get()->nodeData.size()); |
127 DispatchFocusChange(event_data.get()->nodeData[0].get()); | 167 DispatchFocusChange(event_data.get()->nodeData[0].get()); |
128 } | 168 } |
129 | 169 |
170 void ArcAccessibilityHelperBridge::OnAccessibilityTreeDestroyed() { | |
171 tree_source_.reset(nullptr); | |
hidehiko
2017/04/21 06:27:02
nit: s/reset(nullptr)/reset()/
David Tseng
2017/04/25 18:29:48
Acknowledged.
| |
172 if (focus_stealer_->parent()) | |
173 focus_stealer_->parent()->RemoveChildView(focus_stealer_.get()); | |
174 } | |
175 | |
130 void ArcAccessibilityHelperBridge::OnWindowActivated( | 176 void ArcAccessibilityHelperBridge::OnWindowActivated( |
131 aura::Window* gained_active, | 177 aura::Window* gained_active, |
132 aura::Window* lost_active) { | 178 aura::Window* lost_active) { |
133 if (gained_active == lost_active || !tree_source_) | 179 if (gained_active == lost_active) |
134 return; | 180 return; |
135 | 181 |
136 exo::Surface* active_surface = GetArcSurface(gained_active); | 182 exo::Surface* active_surface = GetArcSurface(gained_active); |
137 exo::Surface* inactive_surface = GetArcSurface(lost_active); | 183 exo::Surface* inactive_surface = GetArcSurface(lost_active); |
138 | 184 |
139 // Detach the accessibility tree from an inactive ShellSurface so that any | 185 // Detach the accessibility tree from an inactive ShellSurface so that any |
140 // client walking the desktop tree gets non-duplicated linearization. | 186 // client walking the desktop tree gets non-duplicated linearization. |
141 if (inactive_surface) { | 187 if (inactive_surface) { |
142 views::Widget* widget = views::Widget::GetWidgetForNativeView(lost_active); | 188 views::Widget* widget = views::Widget::GetWidgetForNativeView(lost_active); |
143 if (widget && widget->GetContentsView()) { | 189 if (widget && widget->GetContentsView()) { |
144 views::View* view = widget->GetContentsView(); | 190 views::View* view = widget->GetContentsView(); |
145 view->RemoveChildView(focus_stealer_.get()); | 191 focus_stealer_->StopStealing(); |
146 view->NotifyAccessibilityEvent(ui::AX_EVENT_CHILDREN_CHANGED, false); | |
147 } | 192 } |
148 } | 193 } |
149 | 194 |
150 if (!active_surface) | 195 if (!active_surface) |
151 return; | 196 return; |
152 | 197 |
153 views::Widget* widget = views::Widget::GetWidgetForNativeView(gained_active); | 198 views::Widget* widget = views::Widget::GetWidgetForNativeView(gained_active); |
154 if (widget && widget->GetContentsView()) { | 199 if (widget && widget->GetContentsView()) { |
155 views::View* view = widget->GetContentsView(); | 200 views::View* view = widget->GetContentsView(); |
156 if (!view->Contains(focus_stealer_.get())) | 201 if (!view->Contains(focus_stealer_.get())) |
157 view->AddChildView(focus_stealer_.get()); | 202 view->AddChildView(focus_stealer_.get()); |
158 focus_stealer_->RequestFocus(); | 203 focus_stealer_->StartStealing(); |
159 view->NotifyAccessibilityEvent(ui::AX_EVENT_CHILDREN_CHANGED, false); | |
160 } | 204 } |
161 } | 205 } |
162 | 206 |
163 void ArcAccessibilityHelperBridge::PerformAction(const ui::AXActionData& data) { | 207 void ArcAccessibilityHelperBridge::PerformAction(const ui::AXActionData& data) { |
164 arc::mojom::AccessibilityActionType mojo_action; | 208 arc::mojom::AccessibilityActionType mojo_action; |
165 switch (data.action) { | 209 switch (data.action) { |
166 case ui::AX_ACTION_DO_DEFAULT: | 210 case ui::AX_ACTION_DO_DEFAULT: |
167 mojo_action = arc::mojom::AccessibilityActionType::CLICK; | 211 mojo_action = arc::mojom::AccessibilityActionType::CLICK; |
168 break; | 212 break; |
169 default: | 213 default: |
170 return; | 214 return; |
171 } | 215 } |
172 | 216 |
173 auto* instance = ARC_GET_INSTANCE_FOR_METHOD( | 217 auto* instance = ARC_GET_INSTANCE_FOR_METHOD( |
174 arc_bridge_service()->accessibility_helper(), PerformAction); | 218 arc_bridge_service()->accessibility_helper(), PerformAction); |
175 instance->PerformAction(data.target_node_id, mojo_action); | 219 instance->PerformAction(data.target_node_id, mojo_action); |
176 } | 220 } |
177 | 221 |
178 } // namespace arc | 222 } // namespace arc |
OLD | NEW |