Chromium Code Reviews| 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/ash/accessibility/automation_manager_ash.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_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 AutomationManagerAsh* AutomationManagerAsh::GetInstance() { | 24 AutomationManagerAura* AutomationManagerAura::GetInstance() { |
| 25 return Singleton<AutomationManagerAsh>::get(); | 25 return Singleton<AutomationManagerAura>::get(); |
| 26 } | 26 } |
| 27 | 27 |
| 28 void AutomationManagerAsh::Enable(BrowserContext* context) { | 28 void AutomationManagerAura::Enable(BrowserContext* context) { |
| 29 enabled_ = true; | 29 enabled_ = true; |
| 30 if (!current_tree_.get()) | 30 if (!current_tree_.get()) |
| 31 current_tree_.reset(new AXTreeSourceAsh()); | 31 current_tree_.reset(new AXTreeSourceAura()); |
| 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 AutomationManagerAsh::Disable() { | 40 void AutomationManagerAura::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 AutomationManagerAsh::HandleEvent(BrowserContext* context, | 47 void AutomationManagerAura::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; | |
| 63 SendEvent(context, aura_obj, event_type); | 70 SendEvent(context, aura_obj, event_type); |
| 71 processing_events_ = false; | |
|
dmazzoni
2015/03/26 18:44:58
Should you set it back to false after sending the
David Tseng
2015/03/26 23:20:47
Done.
| |
| 72 | |
| 73 for (size_t i = 0; i < pending_events_.size(); ++i) | |
| 74 SendEvent(context, pending_events_[i].first, pending_events_[i].second); | |
| 75 | |
| 76 pending_events_.clear(); | |
| 64 } | 77 } |
| 65 | 78 |
| 66 void AutomationManagerAsh::HandleAlert(content::BrowserContext* context, | 79 void AutomationManagerAura::HandleAlert(content::BrowserContext* context, |
| 67 const std::string& text) { | 80 const std::string& text) { |
| 68 if (!enabled_) { | 81 if (!enabled_) { |
| 69 pending_alert_text_ = text; | 82 pending_alert_text_ = text; |
| 70 return; | 83 return; |
| 71 } | 84 } |
| 72 | 85 |
| 73 views::AXAuraObjWrapper* obj = | 86 views::AXAuraObjWrapper* obj = |
| 74 static_cast<AXRootObjWrapper*>(current_tree_->GetRoot()) | 87 static_cast<AXRootObjWrapper*>(current_tree_->GetRoot()) |
| 75 ->GetAlertForText(text); | 88 ->GetAlertForText(text); |
| 76 SendEvent(context, obj, ui::AX_EVENT_ALERT); | 89 SendEvent(context, obj, ui::AX_EVENT_ALERT); |
| 77 } | 90 } |
| 78 | 91 |
| 79 void AutomationManagerAsh::DoDefault(int32 id) { | 92 void AutomationManagerAura::DoDefault(int32 id) { |
| 80 CHECK(enabled_); | 93 CHECK(enabled_); |
| 81 current_tree_->DoDefault(id); | 94 current_tree_->DoDefault(id); |
| 82 } | 95 } |
| 83 | 96 |
| 84 void AutomationManagerAsh::Focus(int32 id) { | 97 void AutomationManagerAura::Focus(int32 id) { |
| 85 CHECK(enabled_); | 98 CHECK(enabled_); |
| 86 current_tree_->Focus(id); | 99 current_tree_->Focus(id); |
| 87 } | 100 } |
| 88 | 101 |
| 89 void AutomationManagerAsh::MakeVisible(int32 id) { | 102 void AutomationManagerAura::MakeVisible(int32 id) { |
| 90 CHECK(enabled_); | 103 CHECK(enabled_); |
| 91 current_tree_->MakeVisible(id); | 104 current_tree_->MakeVisible(id); |
| 92 } | 105 } |
| 93 | 106 |
| 94 void AutomationManagerAsh::SetSelection(int32 id, int32 start, int32 end) { | 107 void AutomationManagerAura::SetSelection(int32 id, int32 start, int32 end) { |
| 95 CHECK(enabled_); | 108 CHECK(enabled_); |
| 96 current_tree_->SetSelection(id, start, end); | 109 current_tree_->SetSelection(id, start, end); |
| 97 } | 110 } |
| 98 | 111 |
| 99 AutomationManagerAsh::AutomationManagerAsh() : enabled_(false) { | 112 AutomationManagerAura::AutomationManagerAura() |
| 113 : enabled_(false), processing_events_(false) { | |
| 100 } | 114 } |
| 101 | 115 |
| 102 AutomationManagerAsh::~AutomationManagerAsh() {} | 116 AutomationManagerAura::~AutomationManagerAura() { |
| 103 | |
| 104 void AutomationManagerAsh::ResetSerializer() { | |
| 105 current_tree_serializer_.reset( | |
| 106 new ui::AXTreeSerializer<views::AXAuraObjWrapper*>( | |
| 107 current_tree_.get())); | |
| 108 } | 117 } |
| 109 | 118 |
| 110 void AutomationManagerAsh::SendEvent(BrowserContext* context, | 119 void AutomationManagerAura::ResetSerializer() { |
| 111 views::AXAuraObjWrapper* aura_obj, | 120 current_tree_serializer_.reset( |
| 112 ui::AXEvent event_type) { | 121 new ui::AXTreeSerializer<views::AXAuraObjWrapper*>(current_tree_.get())); |
| 122 } | |
| 123 | |
| 124 void AutomationManagerAura::SendEvent(BrowserContext* context, | |
| 125 views::AXAuraObjWrapper* aura_obj, | |
| 126 ui::AXEvent event_type) { | |
| 113 ui::AXTreeUpdate update; | 127 ui::AXTreeUpdate update; |
| 114 current_tree_serializer_->SerializeChanges(aura_obj, &update); | 128 current_tree_serializer_->SerializeChanges(aura_obj, &update); |
| 115 | 129 |
| 116 // Route this event to special process/routing ids recognized by the | 130 // Route this event to special process/routing ids recognized by the |
| 117 // Automation API as the desktop tree. | 131 // Automation API as the desktop tree. |
| 118 // TODO(dtseng): Would idealy define these special desktop constants in idl. | 132 // TODO(dtseng): Would idealy define these special desktop constants in idl. |
| 119 content::AXEventNotificationDetails detail(update.node_id_to_clear, | 133 content::AXEventNotificationDetails detail( |
| 120 update.nodes, | 134 update.node_id_to_clear, update.nodes, event_type, aura_obj->GetID(), |
| 121 event_type, | 135 0, /* process_id */ |
| 122 aura_obj->GetID(), | 136 0 /* routing_id */); |
| 123 0, /* process_id */ | |
| 124 0 /* routing_id */); | |
| 125 std::vector<content::AXEventNotificationDetails> details; | 137 std::vector<content::AXEventNotificationDetails> details; |
| 126 details.push_back(detail); | 138 details.push_back(detail); |
| 127 extensions::automation_util::DispatchAccessibilityEventsToAutomation( | 139 extensions::automation_util::DispatchAccessibilityEventsToAutomation( |
| 128 details, context, gfx::Vector2d()); | 140 details, context, gfx::Vector2d()); |
| 129 } | 141 } |
| OLD | NEW |