OLD | NEW |
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/ash/accessibility/automation_manager_ash.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_util.h" |
12 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
13 #include "content/public/browser/ax_event_notification_details.h" | 13 #include "content/public/browser/ax_event_notification_details.h" |
14 #include "content/public/browser/browser_context.h" | 14 #include "content/public/browser/browser_context.h" |
15 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
16 #include "ui/views/accessibility/ax_aura_obj_cache.h" | 16 #include "ui/views/accessibility/ax_aura_obj_cache.h" |
17 #include "ui/views/accessibility/ax_aura_obj_wrapper.h" | 17 #include "ui/views/accessibility/ax_aura_obj_wrapper.h" |
18 #include "ui/views/view.h" | 18 #include "ui/views/view.h" |
19 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
20 | 20 |
21 using content::BrowserContext; | 21 using content::BrowserContext; |
22 | 22 |
23 // static | 23 // static |
24 AutomationManagerAura* AutomationManagerAura::GetInstance() { | 24 AutomationManagerAsh* AutomationManagerAsh::GetInstance() { |
25 return Singleton<AutomationManagerAura>::get(); | 25 return Singleton<AutomationManagerAsh>::get(); |
26 } | 26 } |
27 | 27 |
28 void AutomationManagerAura::Enable(BrowserContext* context) { | 28 void AutomationManagerAsh::Enable(BrowserContext* context) { |
29 enabled_ = true; | 29 enabled_ = true; |
30 if (!current_tree_.get()) | 30 if (!current_tree_.get()) |
31 current_tree_.reset(new AXTreeSourceAura()); | 31 current_tree_.reset(new AXTreeSourceAsh()); |
32 ResetSerializer(); | 32 ResetSerializer(); |
33 SendEvent(context, current_tree_->GetRoot(), ui::AX_EVENT_LOAD_COMPLETE); | 33 SendEvent(context, current_tree_->GetRoot(), ui::AX_EVENT_LOAD_COMPLETE); |
34 if (!pending_alert_text_.empty()) { | 34 if (!pending_alert_text_.empty()) { |
35 HandleAlert(context, pending_alert_text_); | 35 HandleAlert(context, pending_alert_text_); |
36 pending_alert_text_.clear(); | 36 pending_alert_text_.clear(); |
37 } | 37 } |
38 } | 38 } |
39 | 39 |
40 void AutomationManagerAura::Disable() { | 40 void AutomationManagerAsh::Disable() { |
41 enabled_ = false; | 41 enabled_ = false; |
42 | 42 |
43 // Reset the serializer to save memory. | 43 // Reset the serializer to save memory. |
44 current_tree_serializer_->Reset(); | 44 current_tree_serializer_->Reset(); |
45 } | 45 } |
46 | 46 |
47 void AutomationManagerAura::HandleEvent(BrowserContext* context, | 47 void AutomationManagerAsh::HandleEvent(BrowserContext* context, |
48 views::View* view, | 48 views::View* view, |
49 ui::AXEvent event_type) { | 49 ui::AXEvent event_type) { |
50 if (!enabled_) | 50 if (!enabled_) |
51 return; | 51 return; |
52 | 52 |
53 if (!context && g_browser_process->profile_manager()) | 53 if (!context && g_browser_process->profile_manager()) |
54 context = g_browser_process->profile_manager()->GetLastUsedProfile(); | 54 context = g_browser_process->profile_manager()->GetLastUsedProfile(); |
55 | 55 |
56 if (!context) { | 56 if (!context) { |
57 LOG(WARNING) << "Accessibility notification but no browser context"; | 57 LOG(WARNING) << "Accessibility notification but no browser context"; |
58 return; | 58 return; |
59 } | 59 } |
60 | 60 |
61 views::AXAuraObjWrapper* aura_obj = | 61 views::AXAuraObjWrapper* aura_obj = |
62 views::AXAuraObjCache::GetInstance()->GetOrCreate(view); | 62 views::AXAuraObjCache::GetInstance()->GetOrCreate(view); |
63 | |
64 if (processing_events_) { | |
65 pending_events_.push_back(std::make_pair(aura_obj, event_type)); | |
66 return; | |
67 } | |
68 | |
69 processing_events_ = true; | |
70 SendEvent(context, aura_obj, event_type); | 63 SendEvent(context, aura_obj, event_type); |
71 | |
72 for (size_t i = 0; i < pending_events_.size(); ++i) | |
73 SendEvent(context, pending_events_[i].first, pending_events_[i].second); | |
74 | |
75 processing_events_ = false; | |
76 pending_events_.clear(); | |
77 } | 64 } |
78 | 65 |
79 void AutomationManagerAura::HandleAlert(content::BrowserContext* context, | 66 void AutomationManagerAsh::HandleAlert(content::BrowserContext* context, |
80 const std::string& text) { | 67 const std::string& text) { |
81 if (!enabled_) { | 68 if (!enabled_) { |
82 pending_alert_text_ = text; | 69 pending_alert_text_ = text; |
83 return; | 70 return; |
84 } | 71 } |
85 | 72 |
86 views::AXAuraObjWrapper* obj = | 73 views::AXAuraObjWrapper* obj = |
87 static_cast<AXRootObjWrapper*>(current_tree_->GetRoot()) | 74 static_cast<AXRootObjWrapper*>(current_tree_->GetRoot()) |
88 ->GetAlertForText(text); | 75 ->GetAlertForText(text); |
89 SendEvent(context, obj, ui::AX_EVENT_ALERT); | 76 SendEvent(context, obj, ui::AX_EVENT_ALERT); |
90 } | 77 } |
91 | 78 |
92 void AutomationManagerAura::DoDefault(int32 id) { | 79 void AutomationManagerAsh::DoDefault(int32 id) { |
93 CHECK(enabled_); | 80 CHECK(enabled_); |
94 current_tree_->DoDefault(id); | 81 current_tree_->DoDefault(id); |
95 } | 82 } |
96 | 83 |
97 void AutomationManagerAura::Focus(int32 id) { | 84 void AutomationManagerAsh::Focus(int32 id) { |
98 CHECK(enabled_); | 85 CHECK(enabled_); |
99 current_tree_->Focus(id); | 86 current_tree_->Focus(id); |
100 } | 87 } |
101 | 88 |
102 void AutomationManagerAura::MakeVisible(int32 id) { | 89 void AutomationManagerAsh::MakeVisible(int32 id) { |
103 CHECK(enabled_); | 90 CHECK(enabled_); |
104 current_tree_->MakeVisible(id); | 91 current_tree_->MakeVisible(id); |
105 } | 92 } |
106 | 93 |
107 void AutomationManagerAura::SetSelection(int32 id, int32 start, int32 end) { | 94 void AutomationManagerAsh::SetSelection(int32 id, int32 start, int32 end) { |
108 CHECK(enabled_); | 95 CHECK(enabled_); |
109 current_tree_->SetSelection(id, start, end); | 96 current_tree_->SetSelection(id, start, end); |
110 } | 97 } |
111 | 98 |
112 AutomationManagerAura::AutomationManagerAura() | 99 AutomationManagerAsh::AutomationManagerAsh() : enabled_(false) { |
113 : enabled_(false), processing_events_(false) { | |
114 } | 100 } |
115 | 101 |
116 AutomationManagerAura::~AutomationManagerAura() { | 102 AutomationManagerAsh::~AutomationManagerAsh() {} |
| 103 |
| 104 void AutomationManagerAsh::ResetSerializer() { |
| 105 current_tree_serializer_.reset( |
| 106 new ui::AXTreeSerializer<views::AXAuraObjWrapper*>( |
| 107 current_tree_.get())); |
117 } | 108 } |
118 | 109 |
119 void AutomationManagerAura::ResetSerializer() { | 110 void AutomationManagerAsh::SendEvent(BrowserContext* context, |
120 current_tree_serializer_.reset( | 111 views::AXAuraObjWrapper* aura_obj, |
121 new ui::AXTreeSerializer<views::AXAuraObjWrapper*>(current_tree_.get())); | 112 ui::AXEvent event_type) { |
122 } | |
123 | |
124 void AutomationManagerAura::SendEvent(BrowserContext* context, | |
125 views::AXAuraObjWrapper* aura_obj, | |
126 ui::AXEvent event_type) { | |
127 ui::AXTreeUpdate update; | 113 ui::AXTreeUpdate update; |
128 current_tree_serializer_->SerializeChanges(aura_obj, &update); | 114 current_tree_serializer_->SerializeChanges(aura_obj, &update); |
129 | 115 |
130 // Route this event to special process/routing ids recognized by the | 116 // Route this event to special process/routing ids recognized by the |
131 // Automation API as the desktop tree. | 117 // Automation API as the desktop tree. |
132 // TODO(dtseng): Would idealy define these special desktop constants in idl. | 118 // TODO(dtseng): Would idealy define these special desktop constants in idl. |
133 content::AXEventNotificationDetails detail( | 119 content::AXEventNotificationDetails detail(update.node_id_to_clear, |
134 update.node_id_to_clear, update.nodes, event_type, aura_obj->GetID(), | 120 update.nodes, |
135 0, /* process_id */ | 121 event_type, |
136 0 /* routing_id */); | 122 aura_obj->GetID(), |
| 123 0, /* process_id */ |
| 124 0 /* routing_id */); |
137 std::vector<content::AXEventNotificationDetails> details; | 125 std::vector<content::AXEventNotificationDetails> details; |
138 details.push_back(detail); | 126 details.push_back(detail); |
139 extensions::automation_util::DispatchAccessibilityEventsToAutomation( | 127 extensions::automation_util::DispatchAccessibilityEventsToAutomation( |
140 details, context, gfx::Vector2d()); | 128 details, context, gfx::Vector2d()); |
141 } | 129 } |
OLD | NEW |