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

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

Issue 2757623003: Initial support for accessible text fields and focus tracking in ARC++ (Closed)
Patch Set: Simpler fix. 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 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 15
16 namespace { 16 namespace {
17 17
18 ui::AXEvent ToAXEvent(arc::mojom::AccessibilityEventType arc_event_type) { 18 ui::AXEvent ToAXEvent(arc::mojom::AccessibilityEventType arc_event_type) {
19 switch (arc_event_type) { 19 switch (arc_event_type) {
20 case arc::mojom::AccessibilityEventType::VIEW_FOCUSED: 20 case arc::mojom::AccessibilityEventType::VIEW_FOCUSED:
21 return ui::AX_EVENT_FOCUS;
hidehiko 2017/03/21 03:43:23 nit: unnecessary change.
David Tseng 2017/03/21 16:41:16 Done.
21 case arc::mojom::AccessibilityEventType::VIEW_ACCESSIBILITY_FOCUSED: 22 case arc::mojom::AccessibilityEventType::VIEW_ACCESSIBILITY_FOCUSED:
22 return ui::AX_EVENT_FOCUS; 23 return ui::AX_EVENT_FOCUS;
23 case arc::mojom::AccessibilityEventType::VIEW_ACCESSIBILITY_FOCUS_CLEARED:
24 return ui::AX_EVENT_BLUR;
25 case arc::mojom::AccessibilityEventType::VIEW_CLICKED: 24 case arc::mojom::AccessibilityEventType::VIEW_CLICKED:
26 case arc::mojom::AccessibilityEventType::VIEW_LONG_CLICKED: 25 case arc::mojom::AccessibilityEventType::VIEW_LONG_CLICKED:
27 return ui::AX_EVENT_CLICKED; 26 return ui::AX_EVENT_CLICKED;
28 case arc::mojom::AccessibilityEventType::VIEW_TEXT_CHANGED: 27 case arc::mojom::AccessibilityEventType::VIEW_TEXT_CHANGED:
29 return ui::AX_EVENT_TEXT_CHANGED; 28 return ui::AX_EVENT_TEXT_CHANGED;
30 case arc::mojom::AccessibilityEventType::VIEW_TEXT_SELECTION_CHANGED: 29 case arc::mojom::AccessibilityEventType::VIEW_TEXT_SELECTION_CHANGED:
31 return ui::AX_EVENT_TEXT_SELECTION_CHANGED; 30 return ui::AX_EVENT_TEXT_SELECTION_CHANGED;
32 case arc::mojom::AccessibilityEventType::WINDOW_STATE_CHANGED: 31 case arc::mojom::AccessibilityEventType::WINDOW_STATE_CHANGED:
33 case arc::mojom::AccessibilityEventType::NOTIFICATION_STATE_CHANGED: 32 case arc::mojom::AccessibilityEventType::NOTIFICATION_STATE_CHANGED:
34 case arc::mojom::AccessibilityEventType::WINDOW_CONTENT_CHANGED: 33 case arc::mojom::AccessibilityEventType::WINDOW_CONTENT_CHANGED:
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 if (!node->booleanProperties) 75 if (!node->booleanProperties)
77 return false; 76 return false;
78 77
79 auto it = node->booleanProperties->find(prop); 78 auto it = node->booleanProperties->find(prop);
80 if (it == node->booleanProperties->end()) 79 if (it == node->booleanProperties->end())
81 return false; 80 return false;
82 81
83 return it->second; 82 return it->second;
84 } 83 }
85 84
85 bool GetIntProperty(arc::mojom::AccessibilityNodeInfoData* node,
86 arc::mojom::AccessibilityIntProperty prop,
87 int32_t* out_value) {
88 if (!node->intProperties)
89 return false;
90
91 auto it = node->intProperties->find(prop);
92 if (it == node->intProperties->end())
93 return false;
94
95 *out_value = it->second;
96 return true;
97 }
98
86 bool GetStringProperty(arc::mojom::AccessibilityNodeInfoData* node, 99 bool GetStringProperty(arc::mojom::AccessibilityNodeInfoData* node,
87 arc::mojom::AccessibilityStringProperty prop, 100 arc::mojom::AccessibilityStringProperty prop,
88 std::string* out_value) { 101 std::string* out_value) {
89 if (!node->stringProperties) 102 if (!node->stringProperties)
90 return false; 103 return false;
91 104
92 auto it = node->stringProperties->find(prop); 105 auto it = node->stringProperties->find(prop);
93 if (it == node->stringProperties->end()) 106 if (it == node->stringProperties->end())
94 return false; 107 return false;
95 108
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 int32_t id = event_data->nodeData[i]->id; 225 int32_t id = event_data->nodeData[i]->id;
213 tree_map_[id] = event_data->nodeData[i].get(); 226 tree_map_[id] = event_data->nodeData[i].get();
214 if (parent_map_.find(id) == parent_map_.end()) { 227 if (parent_map_.find(id) == parent_map_.end()) {
215 CHECK_EQ(-1, root_id_) << "Duplicated root"; 228 CHECK_EQ(-1, root_id_) << "Duplicated root";
216 root_id_ = id; 229 root_id_ = id;
217 } 230 }
218 } 231 }
219 232
220 ExtensionMsg_AccessibilityEventParams params; 233 ExtensionMsg_AccessibilityEventParams params;
221 params.event_type = ToAXEvent(event_data->eventType); 234 params.event_type = ToAXEvent(event_data->eventType);
235
222 if (params.event_type == ui::AX_EVENT_FOCUS) 236 if (params.event_type == ui::AX_EVENT_FOCUS)
223 focused_node_id_ = params.id; 237 focused_node_id_ = event_data->sourceId;
224 else if (params.event_type == ui::AX_EVENT_BLUR) 238
225 focused_node_id_ = -1;
226 params.tree_id = tree_id_; 239 params.tree_id = tree_id_;
227 params.id = event_data->sourceId; 240 params.id = event_data->sourceId;
228 241
229 current_tree_serializer_->SerializeChanges(GetFromId(event_data->sourceId), 242 current_tree_serializer_->SerializeChanges(GetFromId(event_data->sourceId),
230 &params.update); 243 &params.update);
231 244
232 extensions::AutomationEventRouter* router = 245 extensions::AutomationEventRouter* router =
233 extensions::AutomationEventRouter::GetInstance(); 246 extensions::AutomationEventRouter::GetInstance();
234 router->DispatchAccessibilityEvent(params); 247 router->DispatchAccessibilityEvent(params);
235 } 248 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 mojom::AccessibilityNodeInfoData* AXTreeSourceArc::GetNull() const { 312 mojom::AccessibilityNodeInfoData* AXTreeSourceArc::GetNull() const {
300 return nullptr; 313 return nullptr;
301 } 314 }
302 315
303 void AXTreeSourceArc::SerializeNode(mojom::AccessibilityNodeInfoData* node, 316 void AXTreeSourceArc::SerializeNode(mojom::AccessibilityNodeInfoData* node,
304 ui::AXNodeData* out_data) const { 317 ui::AXNodeData* out_data) const {
305 if (!node) 318 if (!node)
306 return; 319 return;
307 out_data->id = node->id; 320 out_data->id = node->id;
308 321
322 using AXIntProperty = arc::mojom::AccessibilityIntProperty;
309 using AXStringProperty = arc::mojom::AccessibilityStringProperty; 323 using AXStringProperty = arc::mojom::AccessibilityStringProperty;
310 std::string text; 324 std::string text;
311 if (GetStringProperty(node, AXStringProperty::TEXT, &text)) 325 if (GetStringProperty(node, AXStringProperty::TEXT, &text))
312 out_data->SetName(text); 326 out_data->SetName(text);
313 else if (GetStringProperty(node, AXStringProperty::CONTENT_DESCRIPTION, 327 else if (GetStringProperty(node, AXStringProperty::CONTENT_DESCRIPTION,
314 &text)) 328 &text))
315 out_data->SetName(text); 329 out_data->SetName(text);
316 330
317 int32_t id = node->id; 331 int32_t id = node->id;
318 if (id == root_id_) 332 if (id == root_id_)
319 out_data->role = ui::AX_ROLE_ROOT_WEB_AREA; 333 out_data->role = ui::AX_ROLE_ROOT_WEB_AREA;
320 else 334 else
321 PopulateAXRole(node, out_data); 335 PopulateAXRole(node, out_data);
322 336
323 PopulateAXState(node, out_data); 337 PopulateAXState(node, out_data);
324 338
325 const gfx::Rect bounds_in_screen = GetBounds(node); 339 const gfx::Rect bounds_in_screen = GetBounds(node);
326 out_data->location.SetRect(bounds_in_screen.x(), bounds_in_screen.y(), 340 out_data->location.SetRect(bounds_in_screen.x(), bounds_in_screen.y(),
327 bounds_in_screen.width(), 341 bounds_in_screen.width(),
328 bounds_in_screen.height()); 342 bounds_in_screen.height());
329 343
330 if (out_data->role == ui::AX_ROLE_TEXT_FIELD && !text.empty()) 344 if (out_data->role == ui::AX_ROLE_TEXT_FIELD && !text.empty())
331 out_data->AddStringAttribute(ui::AX_ATTR_VALUE, text); 345 out_data->AddStringAttribute(ui::AX_ATTR_VALUE, text);
346
347 // Integer properties.
348 int32_t val;
349 if (GetIntProperty(node, AXIntProperty::TEXT_SELECTION_START, &val) &&
350 val >= 0)
Luis Héctor Chávez 2017/03/17 22:13:20 nit: add braces since the condition spans two line
David Tseng 2017/03/21 16:41:16 STyle guide says "In general, curly braces are not
351 out_data->AddIntAttribute(ui::AX_ATTR_TEXT_SEL_START, val);
352
353 if (GetIntProperty(node, AXIntProperty::TEXT_SELECTION_END, &val) && val >= 0)
354 out_data->AddIntAttribute(ui::AX_ATTR_TEXT_SEL_END, val);
332 } 355 }
333 356
334 void AXTreeSourceArc::Reset() { 357 void AXTreeSourceArc::Reset() {
335 tree_map_.clear(); 358 tree_map_.clear();
336 parent_map_.clear(); 359 parent_map_.clear();
337 current_tree_serializer_.reset(new AXTreeArcSerializer(this)); 360 current_tree_serializer_.reset(new AXTreeArcSerializer(this));
338 root_id_ = -1; 361 root_id_ = -1;
339 focused_node_id_ = -1; 362 focused_node_id_ = -1;
340 extensions::AutomationEventRouter* router = 363 extensions::AutomationEventRouter* router =
341 extensions::AutomationEventRouter::GetInstance(); 364 extensions::AutomationEventRouter::GetInstance();
342 router->DispatchTreeDestroyedEvent(tree_id_, nullptr); 365 router->DispatchTreeDestroyedEvent(tree_id_, nullptr);
343 } 366 }
344 367
345 } // namespace arc 368 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698