| 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 // |ui::AXPlatformNodeDelegate|
34 void FlutterPlatformNodeDelegateWindows::Init(std::weak_ptr<OwnerBridge> bridge,
35 ui::AXNode* node) {
36 FlutterPlatformNodeDelegate::Init(bridge, node);
37 ax_platform_node_ = ui::AXPlatformNode::Create(this);
38 FML_DCHECK(ax_platform_node_) << "Failed to create AXPlatformNode";
39 }
40
41 // |ui::AXPlatformNodeDelegate|
42 gfx::NativeViewAccessible
43 FlutterPlatformNodeDelegateWindows::GetNativeViewAccessible() {
44 FML_DCHECK(ax_platform_node_) << "AXPlatformNode hasn't been created";
45 return ax_platform_node_->GetNativeViewAccessible();
46 }
47
48 // |ui::AXPlatformNodeDelegate|
49 gfx::NativeViewAccessible FlutterPlatformNodeDelegateWindows::HitTestSync(
50 int screen_physical_pixel_x,
51 int screen_physical_pixel_y) const {
52 // If this node doesn't contain the point, return.
53 ui::AXOffscreenResult result;
54 gfx::Rect rect = GetBoundsRect(ui::AXCoordinateSystem::kScreenPhysicalPixels,
55 ui::AXClippingBehavior::kUnclipped, &result);
56 gfx::Point screen_point(screen_physical_pixel_x, screen_physical_pixel_y);
57 if (!rect.Contains(screen_point)) {
58 return nullptr;
59 }
60
61 // If any child in this node's subtree contains the point, return that child.
62 auto bridge = bridge_.lock();
63 FML_DCHECK(bridge);
64 for (const ui::AXNode* child : GetAXNode()->children()) {
65 std::shared_ptr<FlutterPlatformNodeDelegateWindows> win_delegate =
66 std::static_pointer_cast<FlutterPlatformNodeDelegateWindows>(
67 bridge->GetFlutterPlatformNodeDelegateFromID(child->id()).lock());
68 FML_DCHECK(win_delegate)
69 << "No FlutterPlatformNodeDelegate found for node " << child->id();
70 auto hit_view = win_delegate->HitTestSync(screen_physical_pixel_x,
71 screen_physical_pixel_y);
72 if (hit_view) {
73 return hit_view;
74 }
75 }
76
77 // If no children contain the point, but this node does, return this node.
78 return ax_platform_node_->GetNativeViewAccessible();
79 }
80
81 // |FlutterPlatformNodeDelegate|
82 gfx::Rect FlutterPlatformNodeDelegateWindows::GetBoundsRect(
83 const ui::AXCoordinateSystem coordinate_system,
84 const ui::AXClippingBehavior clipping_behavior,
85 ui::AXOffscreenResult* offscreen_result) const {
86 gfx::Rect bounds = FlutterPlatformNodeDelegate::GetBoundsRect(
87 coordinate_system, clipping_behavior, offscreen_result);
88 POINT origin{bounds.x(), bounds.y()};
89 POINT extent{bounds.x() + bounds.width(), bounds.y() + bounds.height()};
90 ClientToScreen(view_->GetWindowHandle(), &origin);
91 ClientToScreen(view_->GetWindowHandle(), &extent);
92 return gfx::Rect(origin.x, origin.y, extent.x - origin.x,
93 extent.y - origin.y);
94 }
95
96 void FlutterPlatformNodeDelegateWindows::DispatchWinAccessibilityEvent(
97 ax::mojom::Event event_type) {
98 ax_platform_node_->NotifyAccessibilityEvent(event_type);
99 }
100
101 void FlutterPlatformNodeDelegateWindows::SetFocus() {
102 VARIANT varchild{};
103 varchild.vt = VT_I4;
104 varchild.lVal = CHILDID_SELF;
105 GetNativeViewAccessible()->accSelect(SELFLAG_TAKEFOCUS, varchild);
106 }
107
108 gfx::AcceleratedWidget
109 FlutterPlatformNodeDelegateWindows::GetTargetForNativeAccessibilityEvent() {
110 return view_->GetWindowHandle();
111 }
112
113 ui::AXPlatformNode* FlutterPlatformNodeDelegateWindows::GetPlatformNode()
114 const {
115 return ax_platform_node_;
116 }
117
118 } // namespace flutter
flutter::FlutterWindowsView
Definition: flutter_windows_view.h:34
flutter::FlutterPlatformNodeDelegateWindows::GetNativeViewAccessible
gfx::NativeViewAccessible GetNativeViewAccessible() override
Definition: flutter_platform_node_delegate_windows.cc:43
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::FlutterPlatformNodeDelegateWindows::FlutterPlatformNodeDelegateWindows
FlutterPlatformNodeDelegateWindows(std::weak_ptr< AccessibilityBridge > bridge, FlutterWindowsView *view)
Definition: flutter_platform_node_delegate_windows.cc:18
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:82
flutter::FlutterPlatformNodeDelegateWindows::DispatchWinAccessibilityEvent
virtual void DispatchWinAccessibilityEvent(ax::mojom::Event event_type)
Definition: flutter_platform_node_delegate_windows.cc:96
flutter::FlutterPlatformNodeDelegateWindows::GetTargetForNativeAccessibilityEvent
gfx::AcceleratedWidget GetTargetForNativeAccessibilityEvent() override
Definition: flutter_platform_node_delegate_windows.cc:109
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:49
flutter::FlutterWindowsView::GetWindowHandle
virtual HWND GetWindowHandle() const
Definition: flutter_windows_view.cc:761
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:34
flutter_windows_view.h
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::FlutterPlatformNodeDelegateWindows::GetPlatformNode
ui::AXPlatformNode * GetPlatformNode() const override
Definition: flutter_platform_node_delegate_windows.cc:113
accessibility_bridge_windows.h
flutter
Definition: accessibility_bridge_windows.cc:11
flutter::FlutterPlatformNodeDelegateWindows::~FlutterPlatformNodeDelegateWindows
virtual ~FlutterPlatformNodeDelegateWindows()
Definition: flutter_platform_node_delegate_windows.cc:27
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_platform_node_delegate_windows.h
flutter::FlutterPlatformNodeDelegateWindows::SetFocus
void SetFocus()
Definition: flutter_platform_node_delegate_windows.cc:101
event_type
ax::mojom::Event event_type
Definition: accessibility_bridge_windows_unittests.cc:34