Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
flutter_platform_node_delegate.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
6
7#include <utility>
8
9#include "flutter/shell/platform/common/accessibility_bridge.h"
10#include "flutter/third_party/accessibility/ax/ax_action_data.h"
11#include "flutter/third_party/accessibility/ax/ax_tree_manager_map.h"
12#include "flutter/third_party/accessibility/gfx/geometry/rect_conversions.h"
13
14namespace flutter {
15
17
19
20void FlutterPlatformNodeDelegate::Init(std::weak_ptr<OwnerBridge> bridge,
21 ui::AXNode* node) {
22 bridge_ = std::move(bridge);
23 ax_node_ = node;
24}
25
27 return ax_node_;
28}
29
31 const ui::AXActionData& data) {
32 AccessibilityNodeId target = ax_node_->id();
33 auto bridge_ptr = bridge_.lock();
34 BASE_DCHECK(bridge_ptr);
35 switch (data.action) {
37 bridge_ptr->DispatchAccessibilityAction(
39 return true;
41 bridge_ptr->SetLastFocusedId(target);
42 bridge_ptr->DispatchAccessibilityAction(
43 target,
46 {});
47 return true;
49 bridge_ptr->DispatchAccessibilityAction(
51 {});
52 return true;
53 // TODO(chunhtai): support more actions.
54 default:
55 return false;
56 }
57 return false;
58}
59
61 return ax_node_->data();
62}
63
65 if (!ax_node_->parent()) {
66 return nullptr;
67 }
68 auto bridge_ptr = bridge_.lock();
69 BASE_DCHECK(bridge_ptr);
70 return bridge_ptr->GetNativeAccessibleFromId(ax_node_->parent()->id());
71}
72
74 auto bridge_ptr = bridge_.lock();
75 BASE_DCHECK(bridge_ptr);
76 AccessibilityNodeId last_focused = bridge_ptr->GetLastFocusedId();
77 if (last_focused == ui::AXNode::kInvalidAXID) {
78 return nullptr;
79 }
80 return bridge_ptr->GetNativeAccessibleFromId(last_focused);
81}
82
84 return static_cast<int>(ax_node_->GetUnignoredChildCount());
85}
86
88 auto bridge_ptr = bridge_.lock();
89 BASE_DCHECK(bridge_ptr);
90 AccessibilityNodeId child = ax_node_->GetUnignoredChildAtIndex(index)->id();
91 return bridge_ptr->GetNativeAccessibleFromId(child);
92}
93
95 const ui::AXCoordinateSystem coordinate_system,
96 const ui::AXClippingBehavior clipping_behavior,
97 ui::AXOffscreenResult* offscreen_result) const {
98 auto bridge_ptr = bridge_.lock();
99 BASE_DCHECK(bridge_ptr);
100 // TODO(chunhtai): We need to apply screen dpr in here.
101 // https://github.com/flutter/flutter/issues/74283
102 const bool clip_bounds =
103 clipping_behavior == ui::AXClippingBehavior::kClipped;
104 bool offscreen = false;
105 gfx::RectF bounds =
106 bridge_ptr->RelativeToGlobalBounds(ax_node_, offscreen, clip_bounds);
107 if (offscreen_result != nullptr) {
108 *offscreen_result = offscreen ? ui::AXOffscreenResult::kOffscreen
110 }
111 return gfx::ToEnclosingRect(bounds);
112}
113
114std::weak_ptr<FlutterPlatformNodeDelegate::OwnerBridge>
116 return bridge_;
117}
118
122
125 auto bridge_ptr = bridge_.lock();
126 BASE_DCHECK(bridge_ptr);
127 auto lowest_platform_ancestor = ax_node_->GetLowestPlatformAncestor();
128 if (lowest_platform_ancestor) {
129 return bridge_ptr->GetNativeAccessibleFromId(
130 ax_node_->GetLowestPlatformAncestor()->id());
131 }
132 return nullptr;
133}
134
139
141 int32_t node_id) {
142 ui::AXTreeManager* tree_manager =
144 ax_node_->tree()->GetAXTreeID());
145 AccessibilityBridge* platform_manager =
146 static_cast<AccessibilityBridge*>(tree_manager);
147 return platform_manager->GetPlatformNodeFromTree(node_id);
148}
149
151 const ui::AXTreeID& tree_id,
152 int32_t node_id) {
153 ui::AXTreeManager* tree_manager =
155 AccessibilityBridge* platform_manager =
156 static_cast<AccessibilityBridge*>(tree_manager);
157 return platform_manager->GetPlatformNodeFromTree(node_id);
158}
159
164
165} // namespace flutter
ui::AXPlatformNode * GetPlatformNodeFromTree(const ui::AXNode::AXID node_id) const override
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
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
static AXPositionInstance CreatePosition(const AXNode &node, int child_index_or_text_offset, ax::mojom::TextAffinity affinity=ax::mojom::TextAffinity::kDownstream)
virtual AXTreeID GetAXTreeID() const =0
size_t GetUnignoredChildCount() const
Definition ax_node.cc:37
AXNode * GetLowestPlatformAncestor() const
Definition ax_node.cc:1202
AXID id() const
Definition ax_node.h:110
OwnerTree * tree() const
Definition ax_node.h:109
static constexpr AXID kInvalidAXID
Definition ax_node.h:41
OwnerTree::Selection GetUnignoredSelection() const
Definition ax_node.cc:1260
AXNode * GetUnignoredChildAtIndex(size_t index) const
Definition ax_node.cc:47
AXNode * parent() const
Definition ax_node.h:111
const AXNodeData & data() const
Definition ax_node.h:112
std::unique_ptr< AXPosition< AXNodePosition, AXNode > > AXPositionInstance
AXTreeManager * GetManager(AXTreeID tree_id)
static AXTreeManagerMap & GetInstance()
FlutterSemanticsAction
Definition embedder.h:113
@ kFlutterSemanticsActionShowOnScreen
A request to fully show the semantics node on screen.
Definition embedder.h:138
@ kFlutterSemanticsActionDidGainAccessibilityFocus
Indicate that the node has gained accessibility focus.
Definition embedder.h:152
@ kFlutterSemanticsActionTap
Definition embedder.h:116
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
Rect ToEnclosingRect(const RectF &r)
UnimplementedNativeViewAccessible * NativeViewAccessible
Point offset
#define BASE_DCHECK(condition)
Definition logging.h:63