Flutter Engine
 
Loading...
Searching...
No Matches
flutter_runner::AccessibilityBridge Class Reference

#include <accessibility_bridge.h>

Inheritance diagram for flutter_runner::AccessibilityBridge:

Public Types

using SetSemanticsEnabledCallback = std::function< void(bool)>
 
using DispatchSemanticsActionCallback = std::function< void(int32_t, flutter::SemanticsAction)>
 

Public Member Functions

 AccessibilityBridge (SetSemanticsEnabledCallback set_semantics_enabled_callback, DispatchSemanticsActionCallback dispatch_semantics_action_callback, fuchsia::accessibility::semantics::SemanticsManagerHandle semantics_manager, fuchsia::ui::views::ViewRef view_ref, inspect::Node inspect_node)
 
bool GetSemanticsEnabled () const
 
void SetSemanticsEnabled (bool enabled)
 
void AddSemanticsNodeUpdate (const flutter::SemanticsNodeUpdates update, float view_pixel_ratio)
 
void RequestAnnounce (const std::string message)
 
zx_status_t OnHoverMove (double x, double y)
 
void HitTest (fuchsia::math::PointF local_point, fuchsia::accessibility::semantics::SemanticListener::HitTestCallback callback) override
 
void OnAccessibilityActionRequested (uint32_t node_id, fuchsia::accessibility::semantics::Action action, fuchsia::accessibility::semantics::SemanticListener::OnAccessibilityActionRequestedCallback callback) override
 

Static Public Attributes

static constexpr uint32_t kMaxMessageSize = ZX_CHANNEL_MAX_MSG_BYTES / 2
 
static constexpr size_t kNodeIdSize = sizeof(flutter::SemanticsNode::id)
 
static constexpr size_t kMaxDeletionsPerUpdate
 

Detailed Description

Definition at line 41 of file accessibility_bridge.h.

Member Typedef Documentation

◆ DispatchSemanticsActionCallback

◆ SetSemanticsEnabledCallback

Definition at line 44 of file accessibility_bridge.h.

Constructor & Destructor Documentation

◆ AccessibilityBridge()

flutter_runner::AccessibilityBridge::AccessibilityBridge ( SetSemanticsEnabledCallback  set_semantics_enabled_callback,
DispatchSemanticsActionCallback  dispatch_semantics_action_callback,
fuchsia::accessibility::semantics::SemanticsManagerHandle  semantics_manager,
fuchsia::ui::views::ViewRef  view_ref,
inspect::Node  inspect_node 
)

Definition at line 230 of file accessibility_bridge.cc.

236 : set_semantics_enabled_callback_(
237 std::move(set_semantics_enabled_callback)),
238 dispatch_semantics_action_callback_(
239 std::move(dispatch_semantics_action_callback)),
240 binding_(this),
241 fuchsia_semantics_manager_(semantics_manager.Bind()),
242 atomic_updates_(std::make_shared<std::queue<FuchsiaAtomicUpdate>>()),
243 inspect_node_(std::move(inspect_node)) {
244 fuchsia_semantics_manager_.set_error_handler([](zx_status_t status) {
245 FML_LOG(ERROR) << "Flutter cannot connect to SemanticsManager with status: "
246 << zx_status_get_string(status) << ".";
247 });
248 fuchsia_semantics_manager_->RegisterViewForSemantics(
249 std::move(view_ref), binding_.NewBinding(), tree_ptr_.NewRequest());
250
251#if !FLUTTER_RELEASE
252 // The first argument to |CreateLazyValues| is the name of the lazy node, and
253 // will only be displayed if the callback used to generate the node's content
254 // fails. Therefore, we use an error message for this node name.
255 inspect_node_tree_dump_ =
256 inspect_node_.CreateLazyValues("dump_fail", [this]() {
257 inspect::Inspector inspector;
258 if (auto it = nodes_.find(kRootNodeId); it == nodes_.end()) {
259 inspector.GetRoot().CreateString(
260 "empty_tree", "this semantic tree is empty", &inspector);
261 } else {
262 FillInspectTree(
263 kRootNodeId, /*current_level=*/1,
264 inspector.GetRoot().CreateChild(kTreeDumpInspectRootName),
265 &inspector);
266 }
267 return fpromise::make_ok_promise(std::move(inspector));
268 });
269#endif // !FLUTTER_RELEASE
270}
#define FML_LOG(severity)
Definition logging.h:101

References FML_LOG.

Member Function Documentation

◆ AddSemanticsNodeUpdate()

void flutter_runner::AccessibilityBridge::AddSemanticsNodeUpdate ( const flutter::SemanticsNodeUpdates  update,
float  view_pixel_ratio 
)

Definition at line 534 of file accessibility_bridge.cc.

536 {
537 if (update.empty()) {
538 return;
539 }
540 FML_DCHECK(nodes_.find(kRootNodeId) != nodes_.end() ||
541 update.find(kRootNodeId) != update.end())
542 << "AccessibilityBridge received an update with out ever getting a root "
543 "node.";
544
545 FuchsiaAtomicUpdate atomic_update;
546 bool has_root_node_update = false;
547 // TODO(MI4-2498): Actions, Roles, hit test children, additional
548 // flags/states/attr
549
550 // TODO(MI4-1478): Support for partial updates for nodes > 64kb
551 // e.g. if a node has a long label or more than 64k children.
552 for (const auto& [flutter_node_id, flutter_node] : update) {
553 size_t this_node_size = sizeof(fuchsia::accessibility::semantics::Node);
554 // We handle root update separately in GetRootNodeUpdate.
555 // TODO(chunhtai): remove this special case after we remove the inverse
556 // view pixel ratio transformation in scenic view.
557 // TODO(http://fxbug.dev/75908): Investigate flutter a11y bridge refactor
558 // after removal of the inverse view pixel ratio transformation in scenic
559 // view).
560 if (flutter_node.id == kRootNodeId) {
561 root_flutter_semantics_node_ = flutter_node;
562 has_root_node_update = true;
563 continue;
564 }
565 // Store the nodes for later hit testing and logging.
566 nodes_[flutter_node.id].data = flutter_node;
567
568 fuchsia::accessibility::semantics::Node fuchsia_node;
569 std::vector<uint32_t> child_ids;
570 // Send the nodes in traversal order, so the manager can figure out
571 // traversal.
572 for (int32_t flutter_child_id : flutter_node.childrenInTraversalOrder) {
573 child_ids.push_back(FlutterIdToFuchsiaId(flutter_child_id));
574 }
575 // TODO(http://fxbug.dev/75910): check the usage of FlutterIdToFuchsiaId in
576 // the flutter accessibility bridge.
577 fuchsia_node.set_node_id(flutter_node.id)
578 .set_role(GetNodeRole(flutter_node))
579 .set_location(GetNodeLocation(flutter_node))
580 .set_transform(GetNodeTransform(flutter_node))
581 .set_attributes(GetNodeAttributes(flutter_node, &this_node_size))
582 .set_states(GetNodeStates(flutter_node, &this_node_size))
583 .set_actions(GetNodeActions(flutter_node, &this_node_size))
584 .set_child_ids(child_ids);
585 this_node_size +=
586 kNodeIdSize * flutter_node.childrenInTraversalOrder.size();
587
588 atomic_update.AddNodeUpdate(std::move(fuchsia_node), this_node_size);
589 }
590
591 // Handles root node update.
592 if (has_root_node_update || last_seen_view_pixel_ratio_ != view_pixel_ratio) {
593 last_seen_view_pixel_ratio_ = view_pixel_ratio;
594 size_t root_node_size;
595 fuchsia::accessibility::semantics::Node root_update =
596 GetRootNodeUpdate(root_node_size);
597 atomic_update.AddNodeUpdate(std::move(root_update), root_node_size);
598 }
599
600 PruneUnreachableNodes(&atomic_update);
601 UpdateScreenRects();
602
603 atomic_updates_->push(std::move(atomic_update));
604 if (atomic_updates_->size() == 1) {
605 // There were no commits in the queue, so send this one.
606 Apply(&atomic_updates_->front());
607 }
608}
#define FML_DCHECK(condition)
Definition logging.h:122
static uint32_t FlutterIdToFuchsiaId(int32_t flutter_node_id)

References flutter_runner::FlutterIdToFuchsiaId(), FML_DCHECK, and kNodeIdSize.

◆ GetSemanticsEnabled()

bool flutter_runner::AccessibilityBridge::GetSemanticsEnabled ( ) const

Definition at line 272 of file accessibility_bridge.cc.

272 {
273 return semantics_enabled_;
274}

◆ HitTest()

void flutter_runner::AccessibilityBridge::HitTest ( fuchsia::math::PointF  local_point,
fuchsia::accessibility::semantics::SemanticListener::HitTestCallback  callback 
)
override

Definition at line 767 of file accessibility_bridge.cc.

770 {
771 auto hit_node_id = GetHitNode(kRootNodeId, local_point.x, local_point.y);
772 FML_DCHECK(hit_node_id.has_value());
773 fuchsia::accessibility::semantics::Hit hit;
774 // TODO(http://fxbug.dev/75910): check the usage of FlutterIdToFuchsiaId in
775 // the flutter accessibility bridge.
776 hit.set_node_id(hit_node_id.value_or(kRootNodeId));
777 callback(std::move(hit));
778}
FlutterDesktopBinaryReply callback

References callback, and FML_DCHECK.

◆ OnAccessibilityActionRequested()

void flutter_runner::AccessibilityBridge::OnAccessibilityActionRequested ( uint32_t  node_id,
fuchsia::accessibility::semantics::Action  action,
fuchsia::accessibility::semantics::SemanticListener::OnAccessibilityActionRequestedCallback  callback 
)
override

Definition at line 740 of file accessibility_bridge.cc.

744 {
745 // TODO(http://fxbug.dev/75910): check the usage of FlutterIdToFuchsiaId in
746 // the flutter accessibility bridge.
747 if (nodes_.find(node_id) == nodes_.end()) {
748 FML_LOG(ERROR) << "Attempted to send accessibility action "
749 << static_cast<int32_t>(action)
750 << " to unknown node id: " << node_id;
751 callback(false);
752 return;
753 }
754
755 std::optional<flutter::SemanticsAction> flutter_action =
756 GetFlutterSemanticsAction(action, node_id);
757 if (!flutter_action.has_value()) {
758 callback(false);
759 return;
760 }
761 dispatch_semantics_action_callback_(static_cast<int32_t>(node_id),
762 flutter_action.value());
763 callback(true);
764}

References action, callback, and FML_LOG.

◆ OnHoverMove()

zx_status_t flutter_runner::AccessibilityBridge::OnHoverMove ( double  x,
double  y 
)

◆ RequestAnnounce()

void flutter_runner::AccessibilityBridge::RequestAnnounce ( const std::string  message)

Definition at line 645 of file accessibility_bridge.cc.

645 {
646 fuchsia::accessibility::semantics::SemanticEvent semantic_event;
647 fuchsia::accessibility::semantics::AnnounceEvent announce_event;
648 announce_event.set_message(message);
649 semantic_event.set_announce(std::move(announce_event));
650
651 tree_ptr_->SendSemanticEvent(std::move(semantic_event), []() {});
652}
G_BEGIN_DECLS GBytes * message

References message.

◆ SetSemanticsEnabled()

void flutter_runner::AccessibilityBridge::SetSemanticsEnabled ( bool  enabled)

Definition at line 276 of file accessibility_bridge.cc.

276 {
277 semantics_enabled_ = enabled;
278 if (!enabled) {
279 nodes_.clear();
280 }
281}

Member Data Documentation

◆ kMaxDeletionsPerUpdate

constexpr size_t flutter_runner::AccessibilityBridge::kMaxDeletionsPerUpdate
staticconstexpr
Initial value:

Definition at line 68 of file accessibility_bridge.h.

◆ kMaxMessageSize

constexpr uint32_t flutter_runner::AccessibilityBridge::kMaxMessageSize = ZX_CHANNEL_MAX_MSG_BYTES / 2
staticconstexpr

Definition at line 52 of file accessibility_bridge.h.

◆ kNodeIdSize

constexpr size_t flutter_runner::AccessibilityBridge::kNodeIdSize = sizeof(flutter::SemanticsNode::id)
staticconstexpr

The documentation for this class was generated from the following files: