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/aura/accessibility/automation_manager_aura.h" | 5 #include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/extensions/api/automation_internal/automation_event_rou ter.h" | 14 #include "chrome/browser/extensions/api/automation_internal/automation_event_rou ter.h" |
| 15 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "chrome/common/extensions/chrome_extension_messages.h" | 16 #include "chrome/common/extensions/chrome_extension_messages.h" |
| 17 #include "content/public/browser/ax_event_notification_details.h" | 17 #include "content/public/browser/ax_event_notification_details.h" |
| 18 #include "content/public/browser/browser_context.h" | 18 #include "content/public/browser/browser_context.h" |
| 19 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
| 20 #include "ui/views/accessibility/ax_aura_obj_cache.h" | |
| 21 #include "ui/views/accessibility/ax_aura_obj_wrapper.h" | 20 #include "ui/views/accessibility/ax_aura_obj_wrapper.h" |
| 22 #include "ui/views/view.h" | 21 #include "ui/views/view.h" |
| 23 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
| 24 | 23 |
| 25 #if defined(OS_CHROMEOS) | 24 #if defined(OS_CHROMEOS) |
| 26 #include "ash/wm/window_util.h" // nogncheck | 25 #include "ash/wm/window_util.h" // nogncheck |
| 27 #endif | 26 #endif |
| 28 | 27 |
| 29 using content::BrowserContext; | 28 using content::BrowserContext; |
| 30 using extensions::AutomationEventRouter; | 29 using extensions::AutomationEventRouter; |
| 31 | 30 |
| 32 // static | 31 // static |
| 33 AutomationManagerAura* AutomationManagerAura::GetInstance() { | 32 AutomationManagerAura* AutomationManagerAura::GetInstance() { |
| 34 return base::Singleton<AutomationManagerAura>::get(); | 33 return base::Singleton<AutomationManagerAura>::get(); |
| 35 } | 34 } |
| 36 | 35 |
| 37 void AutomationManagerAura::Enable(BrowserContext* context) { | 36 void AutomationManagerAura::Enable(BrowserContext* context) { |
| 38 enabled_ = true; | 37 enabled_ = true; |
| 39 if (!current_tree_.get()) | 38 if (!current_tree_.get()) |
| 40 current_tree_.reset(new AXTreeSourceAura()); | 39 current_tree_.reset(new AXTreeSourceAura()); |
| 41 ResetSerializer(); | 40 ResetSerializer(); |
| 42 | 41 |
| 43 SendEvent(context, current_tree_->GetRoot(), ui::AX_EVENT_LOAD_COMPLETE); | 42 SendEvent(context, current_tree_->GetRoot(), ui::AX_EVENT_LOAD_COMPLETE); |
| 43 views::AXAuraObjCache::GetInstance()->SetDelegate(this); | |
| 44 | 44 |
| 45 #if defined(OS_CHROMEOS) | 45 #if defined(OS_CHROMEOS) |
| 46 aura::Window* active_window = ash::wm::GetActiveWindow(); | 46 aura::Window* active_window = ash::wm::GetActiveWindow(); |
| 47 if (active_window) { | 47 if (active_window) { |
| 48 views::AXAuraObjWrapper* focus = | 48 views::AXAuraObjWrapper* focus = |
| 49 views::AXAuraObjCache::GetInstance()->GetOrCreate(active_window); | 49 views::AXAuraObjCache::GetInstance()->GetOrCreate(active_window); |
| 50 SendEvent(context, focus, ui::AX_EVENT_CHILDREN_CHANGED); | 50 SendEvent(context, focus, ui::AX_EVENT_CHILDREN_CHANGED); |
| 51 } | 51 } |
| 52 #endif | 52 #endif |
| 53 } | 53 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 return; | 114 return; |
| 115 } | 115 } |
| 116 current_tree_->SetSelection(anchor_id, anchor_offset, focus_offset); | 116 current_tree_->SetSelection(anchor_id, anchor_offset, focus_offset); |
| 117 } | 117 } |
| 118 | 118 |
| 119 void AutomationManagerAura::ShowContextMenu(int32_t id) { | 119 void AutomationManagerAura::ShowContextMenu(int32_t id) { |
| 120 CHECK(enabled_); | 120 CHECK(enabled_); |
| 121 current_tree_->ShowContextMenu(id); | 121 current_tree_->ShowContextMenu(id); |
| 122 } | 122 } |
| 123 | 123 |
| 124 void AutomationManagerAura::OnChildWindowRemoved( | |
| 125 views::AXAuraObjWrapper* parent) { | |
| 126 if (!enabled_) | |
| 127 return; | |
| 128 | |
| 129 BrowserContext* context = nullptr; | |
| 130 if (g_browser_process->profile_manager()) { | |
| 131 context = g_browser_process->profile_manager()->GetLastUsedProfile(); | |
|
dmazzoni
2016/08/31 16:33:50
This is done in two places. I think it'd be better
David Tseng
2016/08/31 21:06:42
Done.
| |
| 132 } | |
| 133 | |
| 134 if (!context) { | |
| 135 LOG(WARNING) << "Accessibility notification but no browser context"; | |
| 136 return; | |
| 137 } | |
| 138 | |
| 139 if (!parent) | |
| 140 parent = current_tree_->GetRoot(); | |
| 141 | |
| 142 SendEvent(context, parent, ui::AX_EVENT_CHILDREN_CHANGED); | |
| 143 } | |
| 144 | |
| 124 AutomationManagerAura::AutomationManagerAura() | 145 AutomationManagerAura::AutomationManagerAura() |
| 125 : enabled_(false), processing_events_(false) {} | 146 : enabled_(false), processing_events_(false) {} |
| 126 | 147 |
| 127 AutomationManagerAura::~AutomationManagerAura() { | 148 AutomationManagerAura::~AutomationManagerAura() { |
| 128 } | 149 } |
| 129 | 150 |
| 130 void AutomationManagerAura::ResetSerializer() { | 151 void AutomationManagerAura::ResetSerializer() { |
| 131 current_tree_serializer_.reset( | 152 current_tree_serializer_.reset( |
| 132 new AuraAXTreeSerializer(current_tree_.get())); | 153 new AuraAXTreeSerializer(current_tree_.get())); |
| 133 } | 154 } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 161 | 182 |
| 162 processing_events_ = false; | 183 processing_events_ = false; |
| 163 auto pending_events_copy = pending_events_; | 184 auto pending_events_copy = pending_events_; |
| 164 pending_events_.clear(); | 185 pending_events_.clear(); |
| 165 for (size_t i = 0; i < pending_events_copy.size(); ++i) { | 186 for (size_t i = 0; i < pending_events_copy.size(); ++i) { |
| 166 SendEvent(context, | 187 SendEvent(context, |
| 167 pending_events_copy[i].first, | 188 pending_events_copy[i].first, |
| 168 pending_events_copy[i].second); | 189 pending_events_copy[i].second); |
| 169 } | 190 } |
| 170 } | 191 } |
| OLD | NEW |