Flutter iOS Embedder
SemanticsObject Class Reference

#import <SemanticsObject.h>

Inheritance diagram for SemanticsObject:
FlutterPlatformViewSemanticsContainer FlutterScrollableSemanticsObject FlutterSemanticsObject FlutterSwitchSemanticsObject TextInputSemanticsObject

Instance Methods

(BOOL) - isAccessibilityBridgeAlive
 
(void) - setSemanticsNode:
 
(void) - replaceChildAtIndex:withChild:
 
(BOOL) - nodeWillCauseLayoutChange:
 
(BOOL) - nodeWillCauseScroll:
 
(BOOL) - nodeShouldTriggerAnnouncement:
 
(void) - collectRoutes:
 
(NSString *) - routeName
 
(BOOL) - onCustomAccessibilityAction:
 
(void) - accessibilityBridgeDidFinishUpdate
 
((unavailable("Use initWithBridge instead") - __attribute__
 
(instancetype) - initWithBridge:uid:
 
(BOOL) - accessibilityScrollToVisible
 
(BOOL) - accessibilityScrollToVisibleWithChild:
 
(id) - _accessibilityHitTest:withEvent:
 

Properties

int32_t uid
 
SemanticsObjectparent
 
fml::WeakPtr< flutter::AccessibilityBridgeIosbridge
 
flutter::SemanticsNode node
 
BOOL hasChildren
 
NSArray< SemanticsObject * > * children
 
NSArray< SemanticsObject * > * childrenInHitTestOrder
 
id nativeAccessibility
 

Detailed Description

A node in the iOS semantics tree. This object is a wrapper over a native accessibiliy object, which is stored in the property nativeAccessibility. In the most case, the nativeAccessibility directly returns this object. Some subclasses such as the FlutterScrollableSemanticsObject creates a native UIScrollView as its nativeAccessibility so that it can interact with iOS.

Definition at line 31 of file SemanticsObject.h.

Method Documentation

◆ __attribute__

- ((unavailable("Use initWithBridge instead") __attribute__

◆ _accessibilityHitTest:withEvent:

- (id) _accessibilityHitTest: (CGPoint)  point
withEvent: (UIEvent *)  event 

Provided by category SemanticsObject(Tests).

◆ accessibilityBridgeDidFinishUpdate

- (void) accessibilityBridgeDidFinishUpdate

Called after accessibility bridge finishes a semantics update.

Subclasses can override this method if they contain states that can only be updated once every node in the accessibility tree has finished updating.

Definition at line 337 of file SemanticsObject.mm.

337  { /* Do nothing by default */
338 }

◆ accessibilityScrollToVisible

- (BOOL) accessibilityScrollToVisible

Provided by category SemanticsObject(Tests).

◆ accessibilityScrollToVisibleWithChild:

- (BOOL) accessibilityScrollToVisibleWithChild: (id)  child

Provided by category SemanticsObject(Tests).

◆ collectRoutes:

- (void) collectRoutes: (NSMutableArray<SemanticsObject*>*)  edges

Definition at line 474 of file SemanticsObject.mm.

474  :(NSMutableArray<SemanticsObject*>*)edges {
475  if (self.node.HasFlag(flutter::SemanticsFlags::kScopesRoute)) {
476  [edges addObject:self];
477  }
478  if ([self hasChildren]) {
479  for (SemanticsObject* child in self.children) {
480  [child collectRoutes:edges];
481  }
482  }
483 }

◆ initWithBridge:uid:

- (instancetype) initWithBridge: (fml::WeakPtr<flutter::AccessibilityBridgeIos>)  bridge
uid: (int32_t)  NS_DESIGNATED_INITIALIZER 

Reimplemented in FlutterPlatformViewSemanticsContainer.

Definition at line 265 of file SemanticsObject.mm.

265  :(fml::WeakPtr<flutter::AccessibilityBridgeIos>)bridge
266  uid:(int32_t)uid {
267  FML_DCHECK(bridge) << "bridge must be set";
268  FML_DCHECK(uid >= kRootNodeId);
269  // Initialize with the UIView as the container.
270  // The UIView will not necessarily be accessibility parent for this object.
271  // The bridge informs the OS of the actual structure via
272  // `accessibilityContainer` and `accessibilityElementAtIndex`.
273  self = [super initWithAccessibilityContainer:bridge->view()];
274 
275  if (self) {
276  _bridge = bridge;
277  _uid = uid;
278  _children = [[NSMutableArray alloc] init];
279  _childrenInHitTestOrder = [[NSArray alloc] init];
280  }
281 
282  return self;
283 }

References kRootNodeId.

◆ isAccessibilityBridgeAlive

- (BOOL) isAccessibilityBridgeAlive

Due to the fact that VoiceOver may hold onto SemanticObjects even after it shuts down, there can be situations where the AccessibilityBridge is shutdown, but the SemanticObject will still be alive. If VoiceOver is turned on again, it may try to access this orphaned SemanticObject. Methods that are called from the accessiblity framework should use this to guard against this case by just returning early if its bridge has been shutdown.

See https://github.com/flutter/flutter/issues/43795 for more information.

Definition at line 329 of file SemanticsObject.mm.

329  {
330  return self.bridge.get() != nil;
331 }

References bridge.

◆ nodeShouldTriggerAnnouncement:

- (BOOL) nodeShouldTriggerAnnouncement: (const flutter::SemanticsNode*)  node

Whether calling setSemanticsNode: with node should trigger an announcement.

Definition at line 359 of file SemanticsObject.mm.

359  :(const flutter::SemanticsNode*)node {
360  // The node dropped the live region flag, if it ever had one.
361  if (!node || !node->HasFlag(flutter::SemanticsFlags::kIsLiveRegion)) {
362  return NO;
363  }
364 
365  // The node has gained a new live region flag, always announce.
366  if (!self.node.HasFlag(flutter::SemanticsFlags::kIsLiveRegion)) {
367  return YES;
368  }
369 
370  // The label has updated, and the new node has a live region flag.
371  return self.node.label != node->label;
372 }

◆ nodeWillCauseLayoutChange:

- (BOOL) nodeWillCauseLayoutChange: (const flutter::SemanticsNode*)  node

Whether calling setSemanticsNode: with node would cause a layout change.

Definition at line 343 of file SemanticsObject.mm.

343  :(const flutter::SemanticsNode*)node {
344  return self.node.rect != node->rect || self.node.transform != node->transform;
345 }

◆ nodeWillCauseScroll:

- (BOOL) nodeWillCauseScroll: (const flutter::SemanticsNode*)  node

Whether calling setSemanticsNode: with node would cause a scroll event.

Definition at line 350 of file SemanticsObject.mm.

350  :(const flutter::SemanticsNode*)node {
351  return !isnan(self.node.scrollPosition) && !isnan(node->scrollPosition) &&
352  self.node.scrollPosition != node->scrollPosition;
353 }

◆ onCustomAccessibilityAction:

- (BOOL) onCustomAccessibilityAction: (FlutterCustomAccessibilityAction*)  action

Definition at line 485 of file SemanticsObject.mm.

486  if (!self.node.HasAction(flutter::SemanticsAction::kCustomAction)) {
487  return NO;
488  }
489  int32_t action_id = action.uid;
490  std::vector<uint8_t> args;
491  args.push_back(3); // type=int32.
492  args.push_back(action_id);
493  args.push_back(action_id >> 8);
494  args.push_back(action_id >> 16);
495  args.push_back(action_id >> 24);
496  self.bridge->DispatchSemanticsAction(
497  self.uid, flutter::SemanticsAction::kCustomAction,
498  fml::MallocMapping::Copy(args.data(), args.size() * sizeof(uint8_t)));
499  return YES;
500 }

References FlutterCustomAccessibilityAction::uid.

◆ replaceChildAtIndex:withChild:

- (void) replaceChildAtIndex: (NSInteger)  index
withChild: (SemanticsObject*)  child 

Definition at line 374 of file SemanticsObject.mm.

374  :(NSInteger)index withChild:(SemanticsObject*)child {
375  SemanticsObject* oldChild = _children[index];
376  oldChild.parent = nil;
377  child.parent = self;
378  [_children replaceObjectAtIndex:index withObject:child];
379 }

References parent.

◆ routeName

- (NSString *) routeName

Definition at line 381 of file SemanticsObject.mm.

381  {
382  // Returns the first non-null and non-empty semantic label of a child
383  // with an NamesRoute flag. Otherwise returns nil.
384  if (self.node.HasFlag(flutter::SemanticsFlags::kNamesRoute)) {
385  NSString* newName = self.accessibilityLabel;
386  if (newName != nil && [newName length] > 0) {
387  return newName;
388  }
389  }
390  if ([self hasChildren]) {
391  for (SemanticsObject* child in self.children) {
392  NSString* newName = [child routeName];
393  if (newName != nil && [newName length] > 0) {
394  return newName;
395  }
396  }
397  }
398  return nil;
399 }

◆ setSemanticsNode:

- (void) setSemanticsNode: (const flutter::SemanticsNode*)  NS_REQUIRES_SUPER

Updates this semantics object using data from the node argument.

Definition at line 333 of file SemanticsObject.mm.

333  :(const flutter::SemanticsNode*)node {
334  _node = *node;
335 }

Property Documentation

◆ bridge

- (WeakPtr<)flutter:
readnonatomicassign

The accessibility bridge that this semantics object is attached to. This object may use the bridge to access contextual application information. A weak pointer is used because the platform view owns the accessibility bridge. If you are referencing this property from an iOS callback, be sure to use isAccessibilityBridgeActive to protect against the case where this node may be orphaned.

Definition at line 52 of file SemanticsObject.h.

Referenced by FLUTTER_ASSERT_ARC::ConvertPointToGlobal(), FLUTTER_ASSERT_ARC::ConvertRectToGlobal(), and isAccessibilityBridgeAlive.

◆ children

- (NSArray<SemanticsObject*>*) children
readwritenonatomiccopy

Direct children of this semantics object. Each child's parent property must be equal to this object.

Definition at line 68 of file SemanticsObject.h.

◆ childrenInHitTestOrder

- (NSArray<SemanticsObject*>*) childrenInHitTestOrder
readwritenonatomiccopy

Direct children of this semantics object in hit test order. Each child's parent property must be equal to this object.

Definition at line 74 of file SemanticsObject.h.

◆ hasChildren

- (BOOL) hasChildren
readnonatomicassign

Whether this semantics object has child semantics objects.

Definition at line 62 of file SemanticsObject.h.

◆ nativeAccessibility

- (id) nativeAccessibility
readnonatomicassign

The UIAccessibility that represents this object.

By default, this return self. Subclasses can override to return different objects to represent them. For example, FlutterScrollableSemanticsObject[s] maintain UIScrollView[s] to represent their UIAccessibility[s].

Definition at line 83 of file SemanticsObject.h.

◆ node

- (SemanticsNode) SemanticsObject:
readnonatomicassign

The semantics node used to produce this semantics object.

Definition at line 57 of file SemanticsObject.h.

◆ parent

- (SemanticsObject*) parent
readnonatomicweak

The parent of this node in the node tree. Will be nil for the root node and during transient state changes.

Definition at line 42 of file SemanticsObject.h.

Referenced by FLUTTER_ASSERT_ARC::GetGlobalTransform(), and replaceChildAtIndex:withChild:.

◆ uid

- (int32_t) uid
readnonatomicassign

The globally unique identifier for this node.

Definition at line 36 of file SemanticsObject.h.


The documentation for this class was generated from the following files:
SemanticsObject::parent
SemanticsObject * parent
Definition: SemanticsObject.h:42
FlutterCustomAccessibilityAction
Definition: SemanticsObject.h:135
FlutterCustomAccessibilityAction::uid
int32_t uid
Definition: SemanticsObject.h:140
SemanticsObject::bridge
fml::WeakPtr< flutter::AccessibilityBridgeIos > bridge
Definition: SemanticsObject.h:52
SemanticsObject::node
flutter::SemanticsNode node
Definition: SemanticsObject.h:57
kRootNodeId
constexpr int32_t kRootNodeId
Definition: SemanticsObject.h:16
SemanticsObject::hasChildren
BOOL hasChildren
Definition: SemanticsObject.h:62
SemanticsObject::children
NSArray< SemanticsObject * > * children
Definition: SemanticsObject.h:68
SemanticsObject::uid
int32_t uid
Definition: SemanticsObject.h:36
SemanticsObject
Definition: SemanticsObject.h:31