| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/chromeos/arc/accessibility/arc_accessibility_helper_bri
dge.h" | 5 #include "chrome/browser/chromeos/arc/accessibility/arc_accessibility_helper_bri
dge.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" |
| 7 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | 8 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
| 9 #include "chrome/browser/chromeos/arc/accessibility/ax_tree_source_arc.h" |
| 10 #include "chromeos/chromeos_switches.h" |
| 8 #include "components/arc/arc_bridge_service.h" | 11 #include "components/arc/arc_bridge_service.h" |
| 12 #include "components/exo/shell_surface.h" |
| 13 #include "components/exo/surface.h" |
| 9 #include "components/exo/wm_helper.h" | 14 #include "components/exo/wm_helper.h" |
| 15 #include "ui/aura/client/aura_constants.h" |
| 10 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 11 #include "ui/gfx/geometry/rect.h" | 17 #include "ui/gfx/geometry/rect.h" |
| 18 #include "ui/views/view.h" |
| 19 #include "ui/views/widget/widget.h" |
| 20 |
| 21 namespace { |
| 22 |
| 23 exo::Surface* GetArcSurface(const aura::Window* window) { |
| 24 if (!window) |
| 25 return nullptr; |
| 26 |
| 27 exo::Surface* arc_surface = exo::Surface::AsSurface(window); |
| 28 if (!arc_surface) |
| 29 arc_surface = exo::ShellSurface::GetMainSurface(window); |
| 30 return arc_surface; |
| 31 } |
| 32 |
| 33 void DispatchFocusChange(arc::mojom::AccessibilityNodeInfoData* node_data) { |
| 34 chromeos::AccessibilityManager* accessibility_manager = |
| 35 chromeos::AccessibilityManager::Get(); |
| 36 if (!accessibility_manager) |
| 37 return; |
| 38 |
| 39 exo::WMHelper* wmHelper = exo::WMHelper::GetInstance(); |
| 40 aura::Window* focused_window = wmHelper->GetFocusedWindow(); |
| 41 if (!focused_window) |
| 42 return; |
| 43 |
| 44 aura::Window* toplevel_window = focused_window->GetToplevelWindow(); |
| 45 |
| 46 gfx::Rect bounds_in_screen = gfx::ScaleToEnclosingRect( |
| 47 node_data->boundsInScreen, |
| 48 1.0f / toplevel_window->layer()->device_scale_factor()); |
| 49 |
| 50 accessibility_manager->OnViewFocusedInArc(bounds_in_screen); |
| 51 } |
| 52 |
| 53 } // namespace |
| 12 | 54 |
| 13 namespace arc { | 55 namespace arc { |
| 14 | 56 |
| 15 ArcAccessibilityHelperBridge::ArcAccessibilityHelperBridge( | 57 ArcAccessibilityHelperBridge::ArcAccessibilityHelperBridge( |
| 16 ArcBridgeService* bridge_service) | 58 ArcBridgeService* bridge_service) |
| 17 : ArcService(bridge_service), binding_(this) { | 59 : ArcService(bridge_service), binding_(this) { |
| 18 arc_bridge_service()->accessibility_helper()->AddObserver(this); | 60 arc_bridge_service()->accessibility_helper()->AddObserver(this); |
| 19 } | 61 } |
| 20 | 62 |
| 21 ArcAccessibilityHelperBridge::~ArcAccessibilityHelperBridge() { | 63 ArcAccessibilityHelperBridge::~ArcAccessibilityHelperBridge() { |
| 22 arc_bridge_service()->accessibility_helper()->RemoveObserver(this); | 64 arc_bridge_service()->accessibility_helper()->RemoveObserver(this); |
| 23 } | 65 } |
| 24 | 66 |
| 25 void ArcAccessibilityHelperBridge::OnInstanceReady() { | 67 void ArcAccessibilityHelperBridge::OnInstanceReady() { |
| 26 auto* instance = ARC_GET_INSTANCE_FOR_METHOD( | 68 auto* instance = ARC_GET_INSTANCE_FOR_METHOD( |
| 27 arc_bridge_service()->accessibility_helper(), Init); | 69 arc_bridge_service()->accessibility_helper(), Init); |
| 28 DCHECK(instance); | 70 DCHECK(instance); |
| 29 instance->Init(binding_.CreateInterfacePtrAndBind()); | 71 instance->Init(binding_.CreateInterfacePtrAndBind()); |
| 72 |
| 73 chromeos::AccessibilityManager* accessibility_manager = |
| 74 chromeos::AccessibilityManager::Get(); |
| 75 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 76 chromeos::switches::kEnableChromeVoxArcSupport)) { |
| 77 instance->SetFilter(arc::mojom::AccessibilityFilterType::ALL); |
| 78 if (!tree_source_) { |
| 79 tree_source_.reset(new AXTreeSourceArc()); |
| 80 exo::WMHelper::GetInstance()->AddActivationObserver(this); |
| 81 } |
| 82 } else if (accessibility_manager && |
| 83 accessibility_manager->IsFocusHighlightEnabled()) { |
| 84 instance->SetFilter(arc::mojom::AccessibilityFilterType::FOCUS); |
| 85 } |
| 86 } |
| 87 |
| 88 void ArcAccessibilityHelperBridge::OnAccessibilityEventDeprecated( |
| 89 mojom::AccessibilityEventType event_type, |
| 90 mojom::AccessibilityNodeInfoDataPtr event_source) { |
| 91 if (event_type == arc::mojom::AccessibilityEventType::VIEW_FOCUSED) |
| 92 DispatchFocusChange(event_source.get()); |
| 30 } | 93 } |
| 31 | 94 |
| 32 void ArcAccessibilityHelperBridge::OnAccessibilityEvent( | 95 void ArcAccessibilityHelperBridge::OnAccessibilityEvent( |
| 33 mojom::AccessibilityEventType event_type, | 96 mojom::AccessibilityEventDataPtr event_data) { |
| 34 mojom::AccessibilityNodeInfoDataPtr event_source) { | 97 if (tree_source_) { |
| 35 if (event_type != mojom::AccessibilityEventType::VIEW_FOCUSED || | 98 tree_source_->NotifyAccessibilityEvent(event_data.get()); |
| 36 event_source.is_null()) { | |
| 37 return; | 99 return; |
| 38 } | 100 } |
| 39 | 101 |
| 40 chromeos::AccessibilityManager* accessibility_manager = | 102 if (event_data->eventType != arc::mojom::AccessibilityEventType::VIEW_FOCUSED) |
| 41 chromeos::AccessibilityManager::Get(); | 103 return; |
| 42 | 104 |
| 43 if (!accessibility_manager || | 105 CHECK_EQ(1U, event_data.get()->nodeData.size()); |
| 44 !accessibility_manager->IsFocusHighlightEnabled()) { | 106 DispatchFocusChange(event_data.get()->nodeData[0].get()); |
| 107 } |
| 108 |
| 109 void ArcAccessibilityHelperBridge::OnWindowActivated( |
| 110 aura::Window* gained_active, |
| 111 aura::Window* lost_active) { |
| 112 if (gained_active == lost_active) |
| 45 return; | 113 return; |
| 114 |
| 115 exo::Surface* active_surface = GetArcSurface(gained_active); |
| 116 exo::Surface* inactive_surface = GetArcSurface(lost_active); |
| 117 |
| 118 // Detach the accessibility tree from an inactive ShellSurface so that any |
| 119 // client walking the desktop tree gets non-duplicated linearization. |
| 120 if (inactive_surface) { |
| 121 views::Widget* widget = views::Widget::GetWidgetForNativeView(lost_active); |
| 122 if (widget && widget->GetContentsView()) { |
| 123 widget->GetNativeWindow()->SetProperty( |
| 124 aura::client::kAccessibleChildTreeIdKey, 0); |
| 125 views::View* view = widget->GetContentsView(); |
| 126 view->SetFocusBehavior(views::View::FocusBehavior::NEVER); |
| 127 view->NotifyAccessibilityEvent(ui::AX_EVENT_CHILDREN_CHANGED, false); |
| 128 } |
| 46 } | 129 } |
| 47 | 130 |
| 48 exo::WMHelper* wmHelper = exo::WMHelper::GetInstance(); | 131 if (!active_surface) |
| 49 | |
| 50 aura::Window* focused_window = wmHelper->GetFocusedWindow(); | |
| 51 if (!focused_window) | |
| 52 return; | 132 return; |
| 53 | 133 |
| 54 aura::Window* toplevel_window = focused_window->GetToplevelWindow(); | 134 views::Widget* widget = views::Widget::GetWidgetForNativeView(gained_active); |
| 55 | 135 if (widget && widget->GetContentsView()) { |
| 56 gfx::Rect bounds_in_screen = gfx::ScaleToEnclosingRect( | 136 widget->GetNativeWindow()->SetProperty( |
| 57 event_source.get()->boundsInScreen, | 137 aura::client::kAccessibleChildTreeIdKey, tree_source_->tree_id()); |
| 58 1.0f / toplevel_window->layer()->device_scale_factor()); | 138 views::View* view = widget->GetContentsView(); |
| 59 | 139 view->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
| 60 accessibility_manager->OnViewFocusedInArc(bounds_in_screen); | 140 view->RequestFocus(); |
| 141 view->NotifyAccessibilityEvent(ui::AX_EVENT_CHILDREN_CHANGED, false); |
| 142 } |
| 61 } | 143 } |
| 62 | 144 |
| 63 } // namespace arc | 145 } // namespace arc |
| OLD | NEW |