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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/ash/accessibility/automation_manager_ash.h"
9 #include "base/memory/singleton.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/extensions/api/automation_internal/automation_util.h"
12 #include "chrome/browser/profiles/profile_manager.h"
13 #include "content/public/browser/ax_event_notification_details.h"
14 #include "content/public/browser/browser_context.h"
15 #include "ui/views/accessibility/ax_aura_obj_cache.h"
16 #include "ui/views/accessibility/ax_aura_obj_wrapper.h"
17 #include "ui/views/view.h"
18 #include "ui/views/widget/widget.h"
20 using content::BrowserContext;
23 AutomationManagerAsh* AutomationManagerAsh::GetInstance() {
24 return Singleton<AutomationManagerAsh>::get();
27 void AutomationManagerAsh::Enable(BrowserContext* context) {
30 SendEvent(context, current_tree_->GetRoot(), ui::AX_EVENT_LOAD_COMPLETE);
33 void AutomationManagerAsh::Disable() {
36 // Reset the serializer to save memory.
37 current_tree_serializer_->Reset();
40 void AutomationManagerAsh::HandleEvent(BrowserContext* context,
42 ui::AXEvent event_type) {
47 views::Widget* widget = view->GetWidget();
51 if (!context && g_browser_process->profile_manager()) {
52 context = g_browser_process->profile_manager()->GetLastUsedProfile();
55 LOG(WARNING) << "Accessibility notification but no browser context";
59 views::AXAuraObjWrapper* aura_obj =
60 views::AXAuraObjCache::GetInstance()->GetOrCreate(view);
61 SendEvent(context, aura_obj, event_type);
64 void AutomationManagerAsh::DoDefault(int32 id) {
66 current_tree_->DoDefault(id);
69 void AutomationManagerAsh::Focus(int32 id) {
71 current_tree_->Focus(id);
74 void AutomationManagerAsh::MakeVisible(int32 id) {
76 current_tree_->MakeVisible(id);
79 void AutomationManagerAsh::SetSelection(int32 id, int32 start, int32 end) {
81 current_tree_->SetSelection(id, start, end);
84 AutomationManagerAsh::AutomationManagerAsh() : enabled_(false) {
87 AutomationManagerAsh::~AutomationManagerAsh() {}
89 void AutomationManagerAsh::Reset() {
90 current_tree_.reset(new AXTreeSourceAsh());
91 current_tree_serializer_.reset(
92 new ui::AXTreeSerializer<views::AXAuraObjWrapper*>(
93 current_tree_.get()));
96 void AutomationManagerAsh::SendEvent(BrowserContext* context,
97 views::AXAuraObjWrapper* aura_obj,
98 ui::AXEvent event_type) {
99 ui::AXTreeUpdate update;
100 current_tree_serializer_->SerializeChanges(aura_obj, &update);
102 // Route this event to special process/routing ids recognized by the
103 // Automation API as the desktop tree.
104 // TODO(dtseng): Would idealy define these special desktop constants in idl.
105 content::AXEventNotificationDetails detail(update.node_id_to_clear,
111 std::vector<content::AXEventNotificationDetails> details;
112 details.push_back(detail);
113 extensions::automation_util::DispatchAccessibilityEventsToAutomation(
114 details, context, gfx::Vector2d());