Flutter Engine
The Flutter Engine
Classes | Public Types | Public Member Functions | Static Public Attributes | List of all members
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

Definition at line 45 of file accessibility_bridge.h.

◆ 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 221 of file accessibility_bridge.cc.

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

Member Function Documentation

◆ AddSemanticsNodeUpdate()

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

Definition at line 526 of file accessibility_bridge.cc.

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

◆ GetSemanticsEnabled()

bool flutter_runner::AccessibilityBridge::GetSemanticsEnabled ( ) const

Definition at line 263 of file accessibility_bridge.cc.

263 {
264 return semantics_enabled_;
265}

◆ HitTest()

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

Definition at line 759 of file accessibility_bridge.cc.

762 {
763 auto hit_node_id = GetHitNode(kRootNodeId, local_point.x, local_point.y);
764 FML_DCHECK(hit_node_id.has_value());
765 fuchsia::accessibility::semantics::Hit hit;
766 // TODO(http://fxbug.dev/75910): check the usage of FlutterIdToFuchsiaId in
767 // the flutter accessibility bridge.
768 hit.set_node_id(hit_node_id.value_or(kRootNodeId));
769 callback(std::move(hit));
770}
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback

◆ 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 732 of file accessibility_bridge.cc.

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

◆ 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 637 of file accessibility_bridge.cc.

637 {
638 fuchsia::accessibility::semantics::SemanticEvent semantic_event;
639 fuchsia::accessibility::semantics::AnnounceEvent announce_event;
640 announce_event.set_message(message);
641 semantic_event.set_announce(std::move(announce_event));
642
643 tree_ptr_->SendSemanticEvent(std::move(semantic_event), []() {});
644}
Win32Message message

◆ SetSemanticsEnabled()

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

Definition at line 267 of file accessibility_bridge.cc.

267 {
268 semantics_enabled_ = enabled;
269 if (!enabled) {
270 nodes_.clear();
271 }
272}

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

Definition at line 60 of file accessibility_bridge.h.


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