| Flutter Windows Embedder |

flutter_platform_node_delegate_windows.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter 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.
4
5 #include <oleacc.h>
6
7 #include "flutter/shell/platform/windows/flutter_platform_node_delegate_windows.h"
8
9 #include "flutter/fml/logging.h"
10 #include "flutter/shell/platform/windows/accessibility_bridge_windows.h"
11 #include "flutter/shell/platform/windows/flutter_windows_view.h"
12 #include "flutter/third_party/accessibility/ax/ax_clipping_behavior.h"
13 #include "flutter/third_party/accessibility/ax/ax_coordinate_system.h"
14 #include "flutter/third_party/accessibility/ax/platform/ax_fragment_root_win.h"
15
16 namespace flutter {
17
18 FlutterPlatformNodeDelegateWindows::FlutterPlatformNodeDelegateWindows(
19 std::weak_ptr<AccessibilityBridge> bridge,
20 FlutterWindowsView* view)
21 : bridge_(bridge), view_(view) {
22 FML_DCHECK(!bridge_.expired())
23 << "Expired AccessibilityBridge passed to node delegate";
24 FML_DCHECK(view_);
25 }
26
27 FlutterPlatformNodeDelegateWindows::~FlutterPlatformNodeDelegateWindows() {
28 if (ax_platform_node_) {
29 ax_platform_node_->Destroy();
30 }
31 }
32
33 bool FlutterPlatformNodeDelegateWindows::IsIAccessibleExEnabled() {
34 return view_->GetEngine()->iaccessibleex_enabled();
35 }
36
37 // |ui::AXPlatformNodeDelegate|
38 void FlutterPlatformNodeDelegateWindows::Init(std::weak_ptr<OwnerBridge> bridge,
39 ui::AXNode* node) {
40 FlutterPlatformNodeDelegate::Init(bridge, node);
41 ax_platform_node_ = ui::AXPlatformNode::Create(this);
42 FML_DCHECK(ax_platform_node_) << "Failed to create AXPlatformNode";
43 }
44
45 // |ui::AXPlatformNodeDelegate|
46 gfx::NativeViewAccessible
47 FlutterPlatformNodeDelegateWindows::GetNativeViewAccessible() {
48 FML_DCHECK(ax_platform_node_) << "AXPlatformNode hasn't been created";
49 return ax_platform_node_->GetNativeViewAccessible();
50 }
51
52 // |ui::AXPlatformNodeDelegate|
53 gfx::NativeViewAccessible FlutterPlatformNodeDelegateWindows::HitTestSync(
54 int screen_physical_pixel_x,
55 int screen_physical_pixel_y) const {
56 // If this node doesn't contain the point, return.
57 ui::AXOffscreenResult result;
58 gfx::Rect rect = GetBoundsRect(ui::AXCoordinateSystem::kScreenPhysicalPixels,
59 ui::AXClippingBehavior::kUnclipped, &result);
60 gfx::Point screen_point(screen_physical_pixel_x, screen_physical_pixel_y);
61 if (!rect.Contains(screen_point)) {
62 return nullptr;
63 }
64
65 // If any child in this node's subtree contains the point, return that child.
66 auto bridge = bridge_.lock();
67 FML_DCHECK(bridge);
68 for (const ui::AXNode* child : GetAXNode()->children()) {
69 std::shared_ptr<FlutterPlatformNodeDelegateWindows> win_delegate =
70 std::static_pointer_cast<FlutterPlatformNodeDelegateWindows>(
71 bridge->GetFlutterPlatformNodeDelegateFromID(child->id()).lock());
72 FML_DCHECK(win_delegate)
73 << "No FlutterPlatformNodeDelegate found for node " << child->id();
74 auto hit_view = win_delegate->HitTestSync(screen_physical_pixel_x,
75 screen_physical_pixel_y);
76 if (hit_view) {
77 return hit_view;
78 }
79 }
80
81 // If no children contain the point, but this node does, return this node.
82 return ax_platform_node_->GetNativeViewAccessible();
83 }
84
85 // |FlutterPlatformNodeDelegate|
86 gfx::Rect FlutterPlatformNodeDelegateWindows::GetBoundsRect(
87 const ui::AXCoordinateSystem coordinate_system,
88 const ui::AXClippingBehavior clipping_behavior,
89 ui::AXOffscreenResult* offscreen_result) const {
90 gfx::Rect bounds = FlutterPlatformNodeDelegate::GetBoundsRect(
91 coordinate_system, clipping_behavior, offscreen_result);
92 POINT origin{bounds.x(), bounds.y()};
93 POINT extent{bounds.x() + bounds.width(), bounds.y() + bounds.height()};
94 ClientToScreen(view_->GetWindowHandle(), &origin);
95 ClientToScreen(view_->GetWindowHandle(), &extent);
96 return gfx::Rect(origin.x, origin.y, extent.x - origin.x,
97 extent.y - origin.y);
98 }
99
100 void FlutterPlatformNodeDelegateWindows::DispatchWinAccessibilityEvent(
101 ax::mojom::Event event_type) {
102 ax_platform_node_->NotifyAccessibilityEvent(event_type);
103 }
104
105 void FlutterPlatformNodeDelegateWindows::SetFocus() {
106 VARIANT varchild{};
107 varchild.vt = VT_I4;
108 varchild.lVal = CHILDID_SELF;
109 GetNativeViewAccessible()->accSelect(SELFLAG_TAKEFOCUS, varchild);
110 }
111
112 gfx::AcceleratedWidget
113 FlutterPlatformNodeDelegateWindows::GetTargetForNativeAccessibilityEvent() {
114 return view_->GetWindowHandle();
115 }
116
117 ui::AXPlatformNode* FlutterPlatformNodeDelegateWindows::GetPlatformNode()
118 const {
119 return ax_platform_node_;
120 }
121
122 } // namespace flutter
accessibility_bridge_windows.h
event_type
ax::mojom::Event event_type
Definition: accessibility_bridge_windows_unittests.cc:34
flutter::FlutterPlatformNodeDelegate::GetBoundsRect
gfx::Rect GetBoundsRect(const ui::AXCoordinateSystem coordinate_system, const ui::AXClippingBehavior clipping_behavior, ui::AXOffscreenResult *offscreen_result) const override
Definition: flutter_platform_node_delegate.cc:94
flutter::FlutterPlatformNodeDelegate::Init
virtual void Init(std::weak_ptr< OwnerBridge > bridge, ui::AXNode *node)
Called only once, immediately after construction. The constructor doesn't take any arguments because ...
Definition: flutter_platform_node_delegate.cc:20
flutter::FlutterPlatformNodeDelegate::GetAXNode
ui::AXNode * GetAXNode() const
Gets the underlying ax node for this platform node delegate.
Definition: flutter_platform_node_delegate.cc:26
flutter::FlutterPlatformNodeDelegateWindows::GetPlatformNode
ui::AXPlatformNode * GetPlatformNode() const override
Definition: flutter_platform_node_delegate_windows.cc:117
flutter::FlutterPlatformNodeDelegateWindows::GetTargetForNativeAccessibilityEvent
gfx::AcceleratedWidget GetTargetForNativeAccessibilityEvent() override
Definition: flutter_platform_node_delegate_windows.cc:113
flutter::FlutterPlatformNodeDelegateWindows::SetFocus
void SetFocus()
Definition: flutter_platform_node_delegate_windows.cc:105
flutter::FlutterPlatformNodeDelegateWindows::GetNativeViewAccessible
gfx::NativeViewAccessible GetNativeViewAccessible() override
Definition: flutter_platform_node_delegate_windows.cc:47
flutter::FlutterPlatformNodeDelegateWindows::IsIAccessibleExEnabled
bool IsIAccessibleExEnabled() override
Definition: flutter_platform_node_delegate_windows.cc:33
flutter::FlutterPlatformNodeDelegateWindows::Init
void Init(std::weak_ptr< OwnerBridge > bridge, ui::AXNode *node) override
Called only once, immediately after construction. The constructor doesn't take any arguments because ...
Definition: flutter_platform_node_delegate_windows.cc:38
flutter::FlutterPlatformNodeDelegateWindows::~FlutterPlatformNodeDelegateWindows
virtual ~FlutterPlatformNodeDelegateWindows()
Definition: flutter_platform_node_delegate_windows.cc:27
flutter::FlutterPlatformNodeDelegateWindows::DispatchWinAccessibilityEvent
virtual void DispatchWinAccessibilityEvent(ax::mojom::Event event_type)
Definition: flutter_platform_node_delegate_windows.cc:100
flutter::FlutterPlatformNodeDelegateWindows::FlutterPlatformNodeDelegateWindows
FlutterPlatformNodeDelegateWindows(std::weak_ptr< AccessibilityBridge > bridge, FlutterWindowsView *view)
Definition: flutter_platform_node_delegate_windows.cc:18
flutter::FlutterPlatformNodeDelegateWindows::HitTestSync
gfx::NativeViewAccessible HitTestSync(int screen_physical_pixel_x, int screen_physical_pixel_y) const override
Definition: flutter_platform_node_delegate_windows.cc:53
flutter::FlutterPlatformNodeDelegateWindows::GetBoundsRect
gfx::Rect GetBoundsRect(const ui::AXCoordinateSystem coordinate_system, const ui::AXClippingBehavior clipping_behavior, ui::AXOffscreenResult *offscreen_result) const override
Definition: flutter_platform_node_delegate_windows.cc:86
flutter::FlutterWindowsEngine::iaccessibleex_enabled
bool iaccessibleex_enabled() const
Definition: flutter_windows_engine.h:263
flutter::FlutterWindowsView
Definition: flutter_windows_view.h:47
flutter::FlutterWindowsView::GetEngine
FlutterWindowsEngine * GetEngine() const
Definition: flutter_windows_view.cc:868
flutter::FlutterWindowsView::GetWindowHandle
virtual HWND GetWindowHandle() const
Definition: flutter_windows_view.cc:864
flutter_platform_node_delegate_windows.h
flutter_windows_view.h
flutter
Definition: accessibility_bridge_windows.cc:11