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

Side by Side Diff: chrome/browser/ui/aura/accessibility/automation_manager_aura.cc

Issue 1231603009: Re-land: Reimplement automation API on top of C++-backed AXTree. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix nested event sending in AutomationManagerAura Created 5 years, 5 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/aura/accessibility/automation_manager_aura.h" 5 #include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/memory/singleton.h" 9 #include "base/memory/singleton.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/extensions/api/automation_internal/automation_util.h" 11 #include "chrome/browser/extensions/api/automation_internal/automation_event_rou ter.h"
12 #include "chrome/browser/profiles/profile_manager.h" 12 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/common/extensions/chrome_extension_messages.h"
13 #include "content/public/browser/ax_event_notification_details.h" 14 #include "content/public/browser/ax_event_notification_details.h"
14 #include "content/public/browser/browser_context.h" 15 #include "content/public/browser/browser_context.h"
15 #include "ui/aura/window.h" 16 #include "ui/aura/window.h"
16 #include "ui/views/accessibility/ax_aura_obj_cache.h" 17 #include "ui/views/accessibility/ax_aura_obj_cache.h"
17 #include "ui/views/accessibility/ax_aura_obj_wrapper.h" 18 #include "ui/views/accessibility/ax_aura_obj_wrapper.h"
18 #include "ui/views/view.h" 19 #include "ui/views/view.h"
19 #include "ui/views/widget/widget.h" 20 #include "ui/views/widget/widget.h"
20 21
21 using content::BrowserContext; 22 using content::BrowserContext;
23 using extensions::AutomationEventRouter;
22 24
23 // static 25 // static
24 AutomationManagerAura* AutomationManagerAura::GetInstance() { 26 AutomationManagerAura* AutomationManagerAura::GetInstance() {
25 return Singleton<AutomationManagerAura>::get(); 27 return Singleton<AutomationManagerAura>::get();
26 } 28 }
27 29
28 void AutomationManagerAura::Enable(BrowserContext* context) { 30 void AutomationManagerAura::Enable(BrowserContext* context) {
29 enabled_ = true; 31 enabled_ = true;
30 if (!current_tree_.get()) 32 if (!current_tree_.get())
31 current_tree_.reset(new AXTreeSourceAura()); 33 current_tree_.reset(new AXTreeSourceAura());
(...skipping 25 matching lines...) Expand all
57 if (!context && g_browser_process->profile_manager()) 59 if (!context && g_browser_process->profile_manager())
58 context = g_browser_process->profile_manager()->GetLastUsedProfile(); 60 context = g_browser_process->profile_manager()->GetLastUsedProfile();
59 61
60 if (!context) { 62 if (!context) {
61 LOG(WARNING) << "Accessibility notification but no browser context"; 63 LOG(WARNING) << "Accessibility notification but no browser context";
62 return; 64 return;
63 } 65 }
64 66
65 views::AXAuraObjWrapper* aura_obj = 67 views::AXAuraObjWrapper* aura_obj =
66 views::AXAuraObjCache::GetInstance()->GetOrCreate(view); 68 views::AXAuraObjCache::GetInstance()->GetOrCreate(view);
67
68 if (processing_events_) {
69 pending_events_.push_back(std::make_pair(aura_obj, event_type));
70 return;
71 }
72
73 processing_events_ = true;
74 SendEvent(context, aura_obj, event_type); 69 SendEvent(context, aura_obj, event_type);
75
76 for (size_t i = 0; i < pending_events_.size(); ++i)
77 SendEvent(context, pending_events_[i].first, pending_events_[i].second);
78
79 processing_events_ = false;
80 pending_events_.clear();
81 } 70 }
82 71
83 void AutomationManagerAura::HandleAlert(content::BrowserContext* context, 72 void AutomationManagerAura::HandleAlert(content::BrowserContext* context,
84 const std::string& text) { 73 const std::string& text) {
85 if (!enabled_) 74 if (!enabled_)
86 return; 75 return;
87 76
88 views::AXAuraObjWrapper* obj = 77 views::AXAuraObjWrapper* obj =
89 static_cast<AXRootObjWrapper*>(current_tree_->GetRoot()) 78 static_cast<AXRootObjWrapper*>(current_tree_->GetRoot())
90 ->GetAlertForText(text); 79 ->GetAlertForText(text);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 } 114 }
126 115
127 void AutomationManagerAura::ResetSerializer() { 116 void AutomationManagerAura::ResetSerializer() {
128 current_tree_serializer_.reset( 117 current_tree_serializer_.reset(
129 new ui::AXTreeSerializer<views::AXAuraObjWrapper*>(current_tree_.get())); 118 new ui::AXTreeSerializer<views::AXAuraObjWrapper*>(current_tree_.get()));
130 } 119 }
131 120
132 void AutomationManagerAura::SendEvent(BrowserContext* context, 121 void AutomationManagerAura::SendEvent(BrowserContext* context,
133 views::AXAuraObjWrapper* aura_obj, 122 views::AXAuraObjWrapper* aura_obj,
134 ui::AXEvent event_type) { 123 ui::AXEvent event_type) {
135 ui::AXTreeUpdate update; 124 if (processing_events_) {
136 current_tree_serializer_->SerializeChanges(aura_obj, &update); 125 pending_events_.push_back(std::make_pair(aura_obj, event_type));
126 return;
127 }
128 processing_events_ = true;
137 129
138 // Route this event to special process/routing ids recognized by the 130 ExtensionMsg_AccessibilityEventParams params;
139 // Automation API as the desktop tree. 131 current_tree_serializer_->SerializeChanges(aura_obj, &params.update);
140 // TODO(dtseng): Would idealy define these special desktop constants in idl. 132 params.tree_id = 0;
141 content::AXEventNotificationDetails detail( 133 params.id = aura_obj->GetID();
142 update.node_id_to_clear, update.nodes, event_type, aura_obj->GetID(), 134 params.event_type = event_type;
143 std::map<int32, int>(), 135 AutomationEventRouter* router = AutomationEventRouter::GetInstance();
144 0, /* process_id */ 136 router->DispatchAccessibilityEvent(params);
145 0 /* routing_id */); 137
146 std::vector<content::AXEventNotificationDetails> details; 138 processing_events_ = false;
147 details.push_back(detail); 139 auto pending_events_copy = pending_events_;
148 extensions::automation_util::DispatchAccessibilityEventsToAutomation( 140 pending_events_.clear();
149 details, context, gfx::Vector2d()); 141 for (size_t i = 0; i < pending_events_copy.size(); ++i) {
142 SendEvent(context,
143 pending_events_copy[i].first,
144 pending_events_copy[i].second);
145 }
150 } 146 }
151 147
152 void AutomationManagerAura::OnNativeFocusChanged(aura::Window* focused_now) { 148 void AutomationManagerAura::OnNativeFocusChanged(aura::Window* focused_now) {
153 focused_window_ = focused_now; 149 focused_window_ = focused_now;
154 if (focused_now && !focused_now->HasObserver(this)) 150 if (focused_now && !focused_now->HasObserver(this))
155 focused_now->AddObserver(this); 151 focused_now->AddObserver(this);
156 } 152 }
157 153
158 void AutomationManagerAura::OnWindowDestroying(aura::Window* window) { 154 void AutomationManagerAura::OnWindowDestroying(aura::Window* window) {
159 if (focused_window_ == window) { 155 if (focused_window_ == window) {
160 window->RemoveObserver(this); 156 window->RemoveObserver(this);
161 focused_window_ = nullptr; 157 focused_window_ = nullptr;
162 } 158 }
163 } 159 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/chromeos/chromevox/cvox2/background/output.js ('k') | chrome/chrome_browser_extensions.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698