Flutter Engine
The Flutter Engine
flutter_platform_node_delegate.h
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#ifndef FLUTTER_SHELL_PLATFORM_COMMON_FLUTTER_PLATFORM_NODE_DELEGATE_H_
6#define FLUTTER_SHELL_PLATFORM_COMMON_FLUTTER_PLATFORM_NODE_DELEGATE_H_
7
8#include "flutter/fml/mapping.h"
9#include "flutter/shell/platform/embedder/embedder.h"
10#include "flutter/third_party/accessibility/ax/ax_event_generator.h"
11#include "flutter/third_party/accessibility/ax/platform/ax_platform_node_delegate_base.h"
12
13namespace flutter {
14
16
17//------------------------------------------------------------------------------
18/// The platform node delegate to be used in accessibility bridge. This
19/// class is responsible for providing native accessibility object with
20/// appropriate information, such as accessibility label/value/bounds.
21///
22/// While most methods have default implementations and are ready to be used
23/// as-is, the subclasses must override the GetNativeViewAccessible to return
24/// native accessibility objects. To do that, subclasses should create and
25/// maintain AXPlatformNode[s] which delegate their accessibility attributes to
26/// this class.
27///
28/// For desktop platforms, subclasses also need to override the GetBoundsRect
29/// to apply window-to-screen transform.
30///
31/// This class transforms bounds assuming the device pixel ratio is 1.0. See
32/// the https://github.com/flutter/flutter/issues/74283 for more information.
34 public:
35 //----------------------------------------------------------------------------
36 /// The required interface to be able to own the flutter platform node
37 /// delegate.
39 public:
40 virtual ~OwnerBridge() = default;
41
42 //---------------------------------------------------------------------------
43 /// @brief Gets the rectangular bounds of the ax node relative to
44 /// global coordinate
45 ///
46 /// @param[in] node The ax node to look up.
47 /// @param[in] offscreen the bool reference to hold the result whether
48 /// the ax node is outside of its ancestors' bounds.
49 /// @param[in] clip_bounds whether to clip the result if the ax node cannot
50 /// be fully contained in its ancestors' bounds.
52 bool& offscreen,
53 bool clip_bounds) = 0;
54
55 protected:
57
58 //---------------------------------------------------------------------------
59 /// @brief Dispatch accessibility action back to the Flutter framework.
60 /// These actions are generated in the native accessibility
61 /// system when users interact with the assistive technologies.
62 /// For example, a
63 /// FlutterSemanticsAction::kFlutterSemanticsActionTap is
64 /// fired when user click or touch the screen.
65 ///
66 /// @param[in] target The semantics node id of the action
67 /// target.
68 /// @param[in] action The generated flutter semantics action.
69 /// @param[in] data Additional data associated with the
70 /// action.
74
75 //---------------------------------------------------------------------------
76 /// @brief Get the native accessibility node with the given id.
77 ///
78 /// @param[in] id The id of the native accessibility node you
79 /// want to retrieve.
81 AccessibilityNodeId id) = 0;
82
83 //---------------------------------------------------------------------------
84 /// @brief Get the last id of the node that received accessibility
85 /// focus.
87
88 //---------------------------------------------------------------------------
89 /// @brief Update the id of the node that is currently foucsed by the
90 /// native accessibility system.
91 ///
92 /// @param[in] node_id The id of the focused node.
93 virtual void SetLastFocusedId(AccessibilityNodeId node_id) = 0;
94 };
95
97
98 // |ui::AXPlatformNodeDelegateBase|
99 virtual ~FlutterPlatformNodeDelegate() override;
100
101 // |ui::AXPlatformNodeDelegateBase|
102 const ui::AXUniqueId& GetUniqueId() const override { return unique_id_; }
103
104 // |ui::AXPlatformNodeDelegateBase|
105 const ui::AXNodeData& GetData() const override;
106
107 // |ui::AXPlatformNodeDelegateBase|
109
110 // |ui::AXPlatformNodeDelegateBase|
112
113 // |ui::AXPlatformNodeDelegateBase|
115
116 // |ui::AXPlatformNodeDelegateBase|
117 int GetChildCount() const override;
118
119 // |ui::AXPlatformNodeDelegateBase|
120 gfx::NativeViewAccessible ChildAtIndex(int index) override;
121
122 // |ui::AXPlatformNodeDelegateBase|
124 const ui::AXCoordinateSystem coordinate_system,
125 const ui::AXClippingBehavior clipping_behavior,
126 ui::AXOffscreenResult* offscreen_result) const override;
127
128 // |ui::AXPlatformNodeDelegateBase|
130
131 // |ui::AXPlatformNodeDelegateBase|
133 int offset) const override;
134
135 //------------------------------------------------------------------------------
136 /// @brief Called only once, immediately after construction. The
137 /// constructor doesn't take any arguments because in the Windows
138 /// subclass we use a special function to construct a COM object.
139 /// Subclasses must call super.
140 virtual void Init(std::weak_ptr<OwnerBridge> bridge, ui::AXNode* node);
141
142 //------------------------------------------------------------------------------
143 /// @brief Gets the underlying ax node for this platform node delegate.
144 ui::AXNode* GetAXNode() const;
145
146 //------------------------------------------------------------------------------
147 /// @brief Gets the owner of this platform node delegate. This is useful
148 /// when you want to get the information about surrounding nodes
149 /// of this platform node delegate, e.g. the global rect of this
150 /// platform node delegate. This pointer is only safe in the
151 /// platform thread.
152 std::weak_ptr<OwnerBridge> GetOwnerBridge() const;
153
154 // Get the platform node represented by this delegate.
155 virtual ui::AXPlatformNode* GetPlatformNode() const;
156
157 // |ui::AXPlatformNodeDelegateBase|
158 virtual ui::AXPlatformNode* GetFromNodeID(int32_t id) override;
159
160 // |ui::AXPlatformNodeDelegateBase|
162 const ui::AXTreeID& tree_id,
163 int32_t node_id) override;
164
165 // |ui::AXPlatformNodeDelegateBase|
166 virtual const ui::AXTree::Selection GetUnignoredSelection() const override;
167
168 private:
169 ui::AXNode* ax_node_;
170 std::weak_ptr<OwnerBridge> bridge_;
171 ui::AXUniqueId unique_id_;
172};
173
174} // namespace flutter
175
176#endif // FLUTTER_SHELL_PLATFORM_COMMON_FLUTTER_PLATFORM_NODE_DELEGATE_H_
virtual void DispatchAccessibilityAction(AccessibilityNodeId target, FlutterSemanticsAction action, fml::MallocMapping data)=0
Dispatch accessibility action back to the Flutter framework. These actions are generated in the nativ...
virtual gfx::RectF RelativeToGlobalBounds(const ui::AXNode *node, bool &offscreen, bool clip_bounds)=0
Gets the rectangular bounds of the ax node relative to global coordinate.
virtual gfx::NativeViewAccessible GetNativeAccessibleFromId(AccessibilityNodeId id)=0
Get the native accessibility node with the given id.
virtual void SetLastFocusedId(AccessibilityNodeId node_id)=0
Update the id of the node that is currently foucsed by the native accessibility system.
virtual AccessibilityNodeId GetLastFocusedId()=0
Get the last id of the node that received accessibility focus.
ui::AXNodePosition::AXPositionInstance CreateTextPositionAt(int offset) const override
gfx::NativeViewAccessible GetParent() override
gfx::Rect GetBoundsRect(const ui::AXCoordinateSystem coordinate_system, const ui::AXClippingBehavior clipping_behavior, ui::AXOffscreenResult *offscreen_result) const override
gfx::NativeViewAccessible GetLowestPlatformAncestor() const override
virtual const ui::AXTree::Selection GetUnignoredSelection() 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 ...
std::weak_ptr< OwnerBridge > GetOwnerBridge() const
Gets the owner of this platform node delegate. This is useful when you want to get the information ab...
virtual ui::AXPlatformNode * GetPlatformNode() const
ui::AXNode * GetAXNode() const
Gets the underlying ax node for this platform node delegate.
virtual ui::AXPlatformNode * GetFromNodeID(int32_t id) override
const ui::AXNodeData & GetData() const override
virtual ~FlutterPlatformNodeDelegate() override
const ui::AXUniqueId & GetUniqueId() const override
virtual ui::AXPlatformNode * GetFromTreeIDAndNodeID(const ui::AXTreeID &tree_id, int32_t node_id) override
bool AccessibilityPerformAction(const ui::AXActionData &data) override
gfx::NativeViewAccessible ChildAtIndex(int index) override
gfx::NativeViewAccessible GetFocus() override
A Mapping like NonOwnedMapping, but uses Free as its release proc.
Definition: mapping.h:144
Definition: rect.h:36
int32_t AXID
Definition: ax_node.h:36
std::unique_ptr< AXPosition< AXNodePosition, AXNode > > AXPositionInstance
Definition: ax_position.h:163
FlutterSemanticsAction
Definition: embedder.h:113
uint32_t * target
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition: switches.h:41
ui::AXNode::AXID AccessibilityNodeId
UnimplementedNativeViewAccessible * NativeViewAccessible
SeparatedVector2 offset