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 
8 
9 #include "flutter/fml/logging.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 
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 
28  if (ax_platform_node_) {
29  ax_platform_node_->Destroy();
30  }
31 }
32 
34  return view_->GetEngine()->iaccessibleex_enabled();
35 }
36 
37 // |ui::AXPlatformNodeDelegate|
38 void FlutterPlatformNodeDelegateWindows::Init(std::weak_ptr<OwnerBridge> bridge,
39  ui::AXNode* 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
48  FML_DCHECK(ax_platform_node_) << "AXPlatformNode hasn't been created";
49  return ax_platform_node_->GetNativeViewAccessible();
50 }
51 
52 // |ui::AXPlatformNodeDelegate|
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|
87  const ui::AXCoordinateSystem coordinate_system,
88  const ui::AXClippingBehavior clipping_behavior,
89  ui::AXOffscreenResult* offscreen_result) const {
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 
101  ax::mojom::Event event_type) {
102  ax_platform_node_->NotifyAccessibilityEvent(event_type);
103 }
104 
106  VARIANT varchild{};
107  varchild.vt = VT_I4;
108  varchild.lVal = CHILDID_SELF;
109  GetNativeViewAccessible()->accSelect(SELFLAG_TAKEFOCUS, varchild);
110 }
111 
112 gfx::AcceleratedWidget
114  return view_->GetWindowHandle();
115 }
116 
118  const {
119  return ax_platform_node_;
120 }
121 
122 } // namespace flutter
ax::mojom::Event event_type
gfx::Rect GetBoundsRect(const ui::AXCoordinateSystem coordinate_system, const ui::AXClippingBehavior clipping_behavior, ui::AXOffscreenResult *offscreen_result) const override
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 ...
ui::AXNode * GetAXNode() const
Gets the underlying ax node for this platform node delegate.
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 ...
virtual void DispatchWinAccessibilityEvent(ax::mojom::Event event_type)
FlutterPlatformNodeDelegateWindows(std::weak_ptr< AccessibilityBridge > bridge, FlutterWindowsView *view)
gfx::NativeViewAccessible HitTestSync(int screen_physical_pixel_x, int screen_physical_pixel_y) const override
gfx::Rect GetBoundsRect(const ui::AXCoordinateSystem coordinate_system, const ui::AXClippingBehavior clipping_behavior, ui::AXOffscreenResult *offscreen_result) const override
FlutterWindowsEngine * GetEngine() const
virtual HWND GetWindowHandle() const