Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Attributes | Private Member Functions | 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
 

Private Member Functions

void OnSemanticsModeChanged (bool enabled, OnSemanticsModeChangedCallback callback) override
 

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

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

Member Function Documentation

◆ AddSemanticsNodeUpdate()

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

Definition at line 523 of file accessibility_bridge.cc.

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

◆ GetSemanticsEnabled()

bool flutter_runner::AccessibilityBridge::GetSemanticsEnabled ( ) const

Definition at line 260 of file accessibility_bridge.cc.

260 {
261 return semantics_enabled_;
262}

◆ HitTest()

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

Definition at line 756 of file accessibility_bridge.cc.

759 {
760 auto hit_node_id = GetHitNode(kRootNodeId, local_point.x, local_point.y);
761 FML_DCHECK(hit_node_id.has_value());
762 fuchsia::accessibility::semantics::Hit hit;
763 // TODO(http://fxbug.dev/75910): check the usage of FlutterIdToFuchsiaId in
764 // the flutter accessibility bridge.
765 hit.set_node_id(hit_node_id.value_or(kRootNodeId));
766 callback(std::move(hit));
767}
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 729 of file accessibility_bridge.cc.

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

◆ OnHoverMove()

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

◆ OnSemanticsModeChanged()

void flutter_runner::AccessibilityBridge::OnSemanticsModeChanged ( bool  enabled,
OnSemanticsModeChangedCallback  callback 
)
overrideprivate

Definition at line 822 of file accessibility_bridge.cc.

824 {
825 set_semantics_enabled_callback_(enabled);
826}

◆ RequestAnnounce()

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

Definition at line 634 of file accessibility_bridge.cc.

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

◆ SetSemanticsEnabled()

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

Definition at line 264 of file accessibility_bridge.cc.

264 {
265 semantics_enabled_ = enabled;
266 if (!enabled) {
267 nodes_.clear();
268 }
269}

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: