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

Side by Side Diff: chrome/browser/chromeos/arc/accessibility/ax_tree_source_arc.cc

Issue 2826423003: Expand Chrome OS ARC support to create one tree source per package (Closed)
Patch Set: 1->n mapping from package name to task ids. Created 3 years, 8 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 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/ax_tree_source_arc.h" 5 #include "chrome/browser/chromeos/arc/accessibility/ax_tree_source_arc.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "chrome/browser/extensions/api/automation_internal/automation_event_rou ter.h" 9 #include "chrome/browser/extensions/api/automation_internal/automation_event_rou ter.h"
10 #include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h" 10 #include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h"
11 #include "chrome/common/extensions/chrome_extension_messages.h" 11 #include "chrome/common/extensions/chrome_extension_messages.h"
12 #include "components/exo/wm_helper.h" 12 #include "components/exo/wm_helper.h"
13 #include "ui/accessibility/platform/ax_android_constants.h" 13 #include "ui/accessibility/platform/ax_android_constants.h"
14 #include "ui/aura/window.h" 14 #include "ui/aura/window.h"
15 #include "ui/views/focus/focus_manager.h"
16 #include "ui/views/view.h"
17 #include "ui/views/widget/widget.h"
15 18
16 namespace { 19 namespace {
17 20
18 ui::AXEvent ToAXEvent(arc::mojom::AccessibilityEventType arc_event_type) { 21 ui::AXEvent ToAXEvent(arc::mojom::AccessibilityEventType arc_event_type) {
19 switch (arc_event_type) { 22 switch (arc_event_type) {
20 case arc::mojom::AccessibilityEventType::VIEW_FOCUSED: 23 case arc::mojom::AccessibilityEventType::VIEW_FOCUSED:
21 case arc::mojom::AccessibilityEventType::VIEW_ACCESSIBILITY_FOCUSED: 24 case arc::mojom::AccessibilityEventType::VIEW_ACCESSIBILITY_FOCUSED:
22 return ui::AX_EVENT_FOCUS; 25 return ui::AX_EVENT_FOCUS;
23 case arc::mojom::AccessibilityEventType::VIEW_CLICKED: 26 case arc::mojom::AccessibilityEventType::VIEW_CLICKED:
24 case arc::mojom::AccessibilityEventType::VIEW_LONG_CLICKED: 27 case arc::mojom::AccessibilityEventType::VIEW_LONG_CLICKED:
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 } 197 }
195 198
196 if (!GetBooleanProperty(node, AXBooleanProperty::ENABLED)) 199 if (!GetBooleanProperty(node, AXBooleanProperty::ENABLED))
197 out_data->AddStateFlag(ui::AX_STATE_DISABLED); 200 out_data->AddStateFlag(ui::AX_STATE_DISABLED);
198 } 201 }
199 202
200 } // namespace 203 } // namespace
201 204
202 namespace arc { 205 namespace arc {
203 206
204 AXTreeSourceArc::AXTreeSourceArc(int32_t id) 207 // This class keeps focus on a |ShellSurface| without interfering with default
205 : tree_id_(id), 208 // focus management in |ShellSurface|. For example, touch causes the
206 current_tree_serializer_(new AXTreeArcSerializer(this)), 209 // |ShellSurface| to lose focus to its ancestor containing View.
210 class AXTreeSourceArc::FocusStealer : public views::View {
211 public:
212 explicit FocusStealer(int32_t id) : id_(id) { set_owned_by_client(); }
213
214 void Steal() {
215 SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
216 RequestFocus();
217 }
218
219 // views::View overrides.
220 void GetAccessibleNodeData(ui::AXNodeData* node_data) override {
221 node_data->AddIntAttribute(ui::AX_ATTR_CHILD_TREE_ID, id_);
222 node_data->role = ui::AX_ROLE_CLIENT;
223 }
224
225 private:
226 const int32_t id_;
227 DISALLOW_COPY_AND_ASSIGN(FocusStealer);
228 };
229
230 AXTreeSourceArc::AXTreeSourceArc(Delegate* delegate)
231 : current_tree_serializer_(new AXTreeArcSerializer(this)),
207 root_id_(-1), 232 root_id_(-1),
208 focused_node_id_(-1) {} 233 focused_node_id_(-1),
234 delegate_(delegate),
235 focus_stealer_(new FocusStealer(tree_id())) {}
209 236
210 AXTreeSourceArc::~AXTreeSourceArc() { 237 AXTreeSourceArc::~AXTreeSourceArc() {
211 Reset(); 238 Reset();
212 } 239 }
213 240
214 void AXTreeSourceArc::NotifyAccessibilityEvent( 241 void AXTreeSourceArc::NotifyAccessibilityEvent(
215 mojom::AccessibilityEventData* event_data) { 242 mojom::AccessibilityEventData* event_data) {
216 tree_map_.clear(); 243 tree_map_.clear();
217 parent_map_.clear(); 244 parent_map_.clear();
218 root_id_ = -1; 245 root_id_ = -1;
(...skipping 16 matching lines...) Expand all
235 root_id_ = id; 262 root_id_ = id;
236 } 263 }
237 } 264 }
238 265
239 ExtensionMsg_AccessibilityEventParams params; 266 ExtensionMsg_AccessibilityEventParams params;
240 params.event_type = ToAXEvent(event_data->eventType); 267 params.event_type = ToAXEvent(event_data->eventType);
241 268
242 if (params.event_type == ui::AX_EVENT_FOCUS) 269 if (params.event_type == ui::AX_EVENT_FOCUS)
243 focused_node_id_ = event_data->sourceId; 270 focused_node_id_ = event_data->sourceId;
244 271
245 params.tree_id = tree_id_; 272 params.tree_id = tree_id();
246 params.id = event_data->sourceId; 273 params.id = event_data->sourceId;
247 274
248 current_tree_serializer_->SerializeChanges(GetFromId(event_data->sourceId), 275 current_tree_serializer_->SerializeChanges(GetFromId(event_data->sourceId),
249 &params.update); 276 &params.update);
250 277
251 extensions::AutomationEventRouter* router = 278 extensions::AutomationEventRouter* router =
252 extensions::AutomationEventRouter::GetInstance(); 279 extensions::AutomationEventRouter::GetInstance();
253 router->DispatchAccessibilityEvent(params); 280 router->DispatchAccessibilityEvent(params);
254 } 281 }
255 282
283 void AXTreeSourceArc::Focus(aura::Window* window) {
284 views::Widget* widget = views::Widget::GetWidgetForNativeView(window);
285 if (!widget || !widget->GetContentsView())
286 return;
287
288 views::View* view = widget->GetContentsView();
289 if (!view->Contains(focus_stealer_.get()))
290 view->AddChildView(focus_stealer_.get());
291 focus_stealer_->Steal();
292 }
293
256 bool AXTreeSourceArc::GetTreeData(ui::AXTreeData* data) const { 294 bool AXTreeSourceArc::GetTreeData(ui::AXTreeData* data) const {
257 data->tree_id = tree_id_; 295 data->tree_id = tree_id();
258 if (focused_node_id_ >= 0) 296 if (focused_node_id_ >= 0)
259 data->focus_id = focused_node_id_; 297 data->focus_id = focused_node_id_;
260 return true; 298 return true;
261 } 299 }
262 300
263 mojom::AccessibilityNodeInfoData* AXTreeSourceArc::GetRoot() const { 301 mojom::AccessibilityNodeInfoData* AXTreeSourceArc::GetRoot() const {
264 mojom::AccessibilityNodeInfoData* root = GetFromId(root_id_); 302 mojom::AccessibilityNodeInfoData* root = GetFromId(root_id_);
265 return root; 303 return root;
266 } 304 }
267 305
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 // Integer properties. 391 // Integer properties.
354 int32_t val; 392 int32_t val;
355 if (GetIntProperty(node, AXIntProperty::TEXT_SELECTION_START, &val) && 393 if (GetIntProperty(node, AXIntProperty::TEXT_SELECTION_START, &val) &&
356 val >= 0) 394 val >= 0)
357 out_data->AddIntAttribute(ui::AX_ATTR_TEXT_SEL_START, val); 395 out_data->AddIntAttribute(ui::AX_ATTR_TEXT_SEL_START, val);
358 396
359 if (GetIntProperty(node, AXIntProperty::TEXT_SELECTION_END, &val) && val >= 0) 397 if (GetIntProperty(node, AXIntProperty::TEXT_SELECTION_END, &val) && val >= 0)
360 out_data->AddIntAttribute(ui::AX_ATTR_TEXT_SEL_END, val); 398 out_data->AddIntAttribute(ui::AX_ATTR_TEXT_SEL_END, val);
361 } 399 }
362 400
401 void AXTreeSourceArc::PerformAction(const ui::AXActionData& data) {
402 delegate_->OnAction(data);
403 }
404
363 void AXTreeSourceArc::Reset() { 405 void AXTreeSourceArc::Reset() {
364 tree_map_.clear(); 406 tree_map_.clear();
365 parent_map_.clear(); 407 parent_map_.clear();
366 current_tree_serializer_.reset(new AXTreeArcSerializer(this)); 408 current_tree_serializer_.reset(new AXTreeArcSerializer(this));
367 root_id_ = -1; 409 root_id_ = -1;
368 focused_node_id_ = -1; 410 focused_node_id_ = -1;
369 extensions::AutomationEventRouter* router = 411 extensions::AutomationEventRouter* router =
370 extensions::AutomationEventRouter::GetInstance(); 412 extensions::AutomationEventRouter::GetInstance();
371 router->DispatchTreeDestroyedEvent(tree_id_, nullptr); 413 router->DispatchTreeDestroyedEvent(tree_id(), nullptr);
372 } 414 }
373 415
374 } // namespace arc 416 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698