Flutter Engine
The Flutter Engine
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
16namespace flutter {
17
19 std::weak_ptr<AccessibilityBridge> bridge,
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
33// |ui::AXPlatformNodeDelegate|
34void FlutterPlatformNodeDelegateWindows::Init(std::weak_ptr<OwnerBridge> bridge,
35 ui::AXNode* node) {
37 ax_platform_node_ = ui::AXPlatformNode::Create(this);
38 FML_DCHECK(ax_platform_node_) << "Failed to create AXPlatformNode";
39}
40
41// |ui::AXPlatformNodeDelegate|
44 FML_DCHECK(ax_platform_node_) << "AXPlatformNode hasn't been created";
45 return ax_platform_node_->GetNativeViewAccessible();
46}
47
48// |ui::AXPlatformNodeDelegate|
50 int screen_physical_pixel_x,
51 int screen_physical_pixel_y) const {
52 // If this node doesn't contain the point, return.
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|
83 const ui::AXCoordinateSystem coordinate_system,
84 const ui::AXClippingBehavior clipping_behavior,
85 ui::AXOffscreenResult* offscreen_result) const {
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
98 ax_platform_node_->NotifyAccessibilityEvent(event_type);
99}
100
102 VARIANT varchild{};
103 varchild.vt = VT_I4;
104 varchild.lVal = CHILDID_SELF;
105 GetNativeViewAccessible()->accSelect(SELFLAG_TAKEFOCUS, varchild);
106}
107
108gfx::AcceleratedWidget
110 return view_->GetWindowHandle();
111}
112
114 const {
115 return ax_platform_node_;
116}
117
118} // namespace flutter
ax::mojom::Event event_type
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
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.
virtual HWND GetWindowHandle() const
Definition: rect.h:36
virtual void NotifyAccessibilityEvent(ax::mojom::Event event_type)=0
static AXPlatformNode * Create(AXPlatformNodeDelegate *delegate)
virtual gfx::NativeViewAccessible GetNativeViewAccessible()=0
virtual void Destroy()
GAsyncResult * result
#define FML_DCHECK(condition)
Definition: logging.h:103
Optional< SkRect > bounds
Definition: SkRecords.h:189
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
UnimplementedNativeViewAccessible * NativeViewAccessible
TRect< Scalar > Rect
Definition: rect.h:769