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 "chrome/grit/generated_resources.h" | |
| 17 #include "content/public/browser/ax_event_notification_details.h" | 18 #include "content/public/browser/ax_event_notification_details.h" |
| 18 #include "content/public/browser/browser_context.h" | 19 #include "content/public/browser/browser_context.h" |
| 19 #include "ui/accessibility/ax_action_data.h" | 20 #include "ui/accessibility/ax_action_data.h" |
| 20 #include "ui/accessibility/ax_enums.h" | 21 #include "ui/accessibility/ax_enums.h" |
| 21 #include "ui/aura/env.h" | 22 #include "ui/aura/env.h" |
| 22 #include "ui/aura/window.h" | 23 #include "ui/aura/window.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | |
| 23 #include "ui/views/accessibility/ax_aura_obj_wrapper.h" | 25 #include "ui/views/accessibility/ax_aura_obj_wrapper.h" |
| 24 #include "ui/views/view.h" | 26 #include "ui/views/view.h" |
| 25 #include "ui/views/widget/widget.h" | 27 #include "ui/views/widget/widget.h" |
| 26 | 28 |
| 27 #if defined(OS_CHROMEOS) | 29 #if defined(OS_CHROMEOS) |
| 28 #include "ash/wm/window_util.h" // nogncheck | 30 #include "ash/wm/window_util.h" // nogncheck |
| 29 #endif | 31 #endif |
| 30 | 32 |
| 31 using content::BrowserContext; | 33 using content::BrowserContext; |
| 32 using extensions::AutomationEventRouter; | 34 using extensions::AutomationEventRouter; |
| 33 | 35 |
| 36 namespace { | |
| 37 | |
| 38 bool IsScreenOffAlert(const std::string& text) { | |
| 39 return text == l10n_util::GetStringUTF8(IDS_A11Y_ALERT_SCREEN_OFF); | |
| 40 } | |
| 41 | |
| 42 bool IsScreenOnAlert(const std::string& text) { | |
| 43 return text == l10n_util::GetStringUTF8(IDS_A11Y_ALERT_SCREEN_ON); | |
| 44 } | |
| 45 | |
| 46 } // namespace | |
| 47 | |
| 34 // static | 48 // static |
| 35 AutomationManagerAura* AutomationManagerAura::GetInstance() { | 49 AutomationManagerAura* AutomationManagerAura::GetInstance() { |
| 36 return base::Singleton<AutomationManagerAura>::get(); | 50 return base::Singleton<AutomationManagerAura>::get(); |
| 37 } | 51 } |
| 38 | 52 |
| 39 void AutomationManagerAura::Enable(BrowserContext* context) { | 53 void AutomationManagerAura::Enable(BrowserContext* context) { |
| 40 enabled_ = true; | 54 enabled_ = true; |
| 41 if (!current_tree_.get()) | 55 if (!current_tree_.get()) |
| 42 current_tree_.reset(new AXTreeSourceAura()); | 56 current_tree_.reset(new AXTreeSourceAura()); |
| 43 ResetSerializer(); | 57 ResetSerializer(); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 69 return; | 83 return; |
| 70 | 84 |
| 71 views::AXAuraObjWrapper* aura_obj = view ? | 85 views::AXAuraObjWrapper* aura_obj = view ? |
| 72 views::AXAuraObjCache::GetInstance()->GetOrCreate(view) : | 86 views::AXAuraObjCache::GetInstance()->GetOrCreate(view) : |
| 73 current_tree_->GetRoot(); | 87 current_tree_->GetRoot(); |
| 74 SendEvent(nullptr, aura_obj, event_type); | 88 SendEvent(nullptr, aura_obj, event_type); |
| 75 } | 89 } |
| 76 | 90 |
| 77 void AutomationManagerAura::HandleAlert(content::BrowserContext* context, | 91 void AutomationManagerAura::HandleAlert(content::BrowserContext* context, |
| 78 const std::string& text) { | 92 const std::string& text) { |
| 79 if (!enabled_) | 93 if (!enabled_ && !IsScreenOnAlert(text)) |
| 80 return; | 94 return; |
| 81 | 95 |
| 82 views::AXAuraObjWrapper* obj = | 96 views::AXAuraObjWrapper* obj = |
| 83 static_cast<AXRootObjWrapper*>(current_tree_->GetRoot()) | 97 static_cast<AXRootObjWrapper*>(current_tree_->GetRoot()) |
| 84 ->GetAlertForText(text); | 98 ->GetAlertForText(text); |
| 85 SendEvent(context, obj, ui::AX_EVENT_ALERT); | 99 SendEvent(context, obj, ui::AX_EVENT_ALERT); |
| 100 | |
| 101 if (IsScreenOffAlert(text)) | |
|
David Tseng
2017/02/03 00:27:15
I wouldn't want to check against this string every
Qiang(Joe) Xu
2017/02/03 02:46:54
Screen on/off info may come from chromeos::power_m
| |
| 102 Disable(); | |
| 103 else if (IsScreenOnAlert(text)) | |
| 104 Enable(context); | |
| 86 } | 105 } |
| 87 | 106 |
| 88 void AutomationManagerAura::PerformAction( | 107 void AutomationManagerAura::PerformAction( |
| 89 const ui::AXActionData& data) { | 108 const ui::AXActionData& data) { |
| 90 CHECK(enabled_); | 109 CHECK(enabled_); |
| 91 | 110 |
| 92 switch (data.action) { | 111 switch (data.action) { |
| 93 case ui::AX_ACTION_DO_DEFAULT: | 112 case ui::AX_ACTION_DO_DEFAULT: |
| 94 current_tree_->DoDefault(data.target_node_id); | 113 current_tree_->DoDefault(data.target_node_id); |
| 95 break; | 114 break; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 | 214 |
| 196 processing_events_ = false; | 215 processing_events_ = false; |
| 197 auto pending_events_copy = pending_events_; | 216 auto pending_events_copy = pending_events_; |
| 198 pending_events_.clear(); | 217 pending_events_.clear(); |
| 199 for (size_t i = 0; i < pending_events_copy.size(); ++i) { | 218 for (size_t i = 0; i < pending_events_copy.size(); ++i) { |
| 200 SendEvent(context, | 219 SendEvent(context, |
| 201 pending_events_copy[i].first, | 220 pending_events_copy[i].first, |
| 202 pending_events_copy[i].second); | 221 pending_events_copy[i].second); |
| 203 } | 222 } |
| 204 } | 223 } |
| OLD | NEW |