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 30 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 356 of file SemanticsObject.mm.

356  { /* Do nothing by default */
357 }

◆ 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 499 of file SemanticsObject.mm.

499  :(NSMutableArray<SemanticsObject*>*)edges {
500  if ([self node].HasFlag(flutter::SemanticsFlags::kScopesRoute)) {
501  [edges addObject:self];
502  }
503  if ([self hasChildren]) {
504  for (SemanticsObject* child in self.children) {
505  [child collectRoutes:edges];
506  }
507  }
508 }

◆ initWithBridge:uid:

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

Reimplemented in FlutterPlatformViewSemanticsContainer.

Definition at line 283 of file SemanticsObject.mm.

283  :(fml::WeakPtr<flutter::AccessibilityBridgeIos>)bridge
284  uid:(int32_t)uid {
285  FML_DCHECK(bridge) << "bridge must be set";
286  FML_DCHECK(uid >= kRootNodeId);
287  // Initialize with the UIView as the container.
288  // The UIView will not necessarily be accessibility parent for this object.
289  // The bridge informs the OS of the actual structure via
290  // `accessibilityContainer` and `accessibilityElementAtIndex`.
291  self = [super initWithAccessibilityContainer:bridge->view()];
292 
293  if (self) {
294  _bridge = bridge;
295  _uid = uid;
296  _children = [[NSMutableArray alloc] init];
297  _childrenInHitTestOrder = [[NSMutableArray alloc] init];
298  }
299 
300  return self;
301 }

References _bridge, _children, _childrenInHitTestOrder, and 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 348 of file SemanticsObject.mm.

348  {
349  return [self bridge].get() != nil;
350 }

References bridge.

◆ nodeShouldTriggerAnnouncement:

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

Whether calling setSemanticsNode: with node should trigger an announcement.

Definition at line 378 of file SemanticsObject.mm.

378  :(const flutter::SemanticsNode*)node {
379  // The node dropped the live region flag, if it ever had one.
380  if (!node || !node->HasFlag(flutter::SemanticsFlags::kIsLiveRegion)) {
381  return NO;
382  }
383 
384  // The node has gained a new live region flag, always announce.
385  if (![self node].HasFlag(flutter::SemanticsFlags::kIsLiveRegion)) {
386  return YES;
387  }
388 
389  // The label has updated, and the new node has a live region flag.
390  return [self node].label != node->label;
391 }

References node.

◆ nodeWillCauseLayoutChange:

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

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

Definition at line 362 of file SemanticsObject.mm.

362  :(const flutter::SemanticsNode*)node {
363  return [self node].rect != node->rect || [self node].transform != node->transform;
364 }

References node.

◆ nodeWillCauseScroll:

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

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

Definition at line 369 of file SemanticsObject.mm.

369  :(const flutter::SemanticsNode*)node {
370  return !isnan([self node].scrollPosition) && !isnan(node->scrollPosition) &&
371  [self node].scrollPosition != node->scrollPosition;
372 }

References node.

◆ onCustomAccessibilityAction:

- (BOOL) onCustomAccessibilityAction: (FlutterCustomAccessibilityAction*)  action

Definition at line 510 of file SemanticsObject.mm.

511  if (![self node].HasAction(flutter::SemanticsAction::kCustomAction)) {
512  return NO;
513  }
514  int32_t action_id = action.uid;
515  std::vector<uint8_t> args;
516  args.push_back(3); // type=int32.
517  args.push_back(action_id);
518  args.push_back(action_id >> 8);
519  args.push_back(action_id >> 16);
520  args.push_back(action_id >> 24);
521  [self bridge]->DispatchSemanticsAction(
522  [self uid], flutter::SemanticsAction::kCustomAction,
523  fml::MallocMapping::Copy(args.data(), args.size() * sizeof(uint8_t)));
524  return YES;
525 }

References bridge, and FlutterCustomAccessibilityAction::uid.

◆ replaceChildAtIndex:withChild:

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

Definition at line 393 of file SemanticsObject.mm.

393  :(NSInteger)index withChild:(SemanticsObject*)child {
394  SemanticsObject* oldChild = _children[index];
395  [oldChild privateSetParent:nil];
396  [child privateSetParent:self];
397  [_children replaceObjectAtIndex:index withObject:child];
398 }

References _children.

◆ routeName

- (NSString *) routeName

Definition at line 400 of file SemanticsObject.mm.

400  {
401  // Returns the first non-null and non-empty semantic label of a child
402  // with an NamesRoute flag. Otherwise returns nil.
403  if ([self node].HasFlag(flutter::SemanticsFlags::kNamesRoute)) {
404  NSString* newName = [self accessibilityLabel];
405  if (newName != nil && [newName length] > 0) {
406  return newName;
407  }
408  }
409  if ([self hasChildren]) {
410  for (SemanticsObject* child in self.children) {
411  NSString* newName = [child routeName];
412  if (newName != nil && [newName length] > 0) {
413  return newName;
414  }
415  }
416  }
417  return nil;
418 }

◆ setSemanticsNode:

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

Updates this semantics object using data from the node argument.

Definition at line 352 of file SemanticsObject.mm.

352  :(const flutter::SemanticsNode*)node {
353  _node = *node;
354 }

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 51 of file SemanticsObject.h.

Referenced by isAccessibilityBridgeAlive, and onCustomAccessibilityAction:.

◆ children

- (NSArray<SemanticsObject*>*) children
readwritenonatomicstrong

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

Definition at line 67 of file SemanticsObject.h.

◆ childrenInHitTestOrder

- (NSArray<SemanticsObject*>*) childrenInHitTestOrder
readwritenonatomicstrong

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

Definition at line 73 of file SemanticsObject.h.

◆ hasChildren

- (BOOL) hasChildren
readnonatomicassign

Whether this semantics object has child semantics objects.

Definition at line 61 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 82 of file SemanticsObject.h.

◆ node

- (SemanticsNode) SemanticsObject:
readnonatomicassign

The semantics node used to produce this semantics object.

Definition at line 56 of file SemanticsObject.h.

Referenced by nodeShouldTriggerAnnouncement:, nodeWillCauseLayoutChange:, and nodeWillCauseScroll:.

◆ parent

- (SemanticsObject*) parent
readwritenonatomicassign

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

Definition at line 41 of file SemanticsObject.h.

◆ uid

- (int32_t) uid
readnonatomicassign

The globally unique identifier for this node.

Definition at line 35 of file SemanticsObject.h.


The documentation for this class was generated from the following files:
FlutterCustomAccessibilityAction
Definition: SemanticsObject.h:134
_childrenInHitTestOrder
NSMutableArray< SemanticsObject * > * _childrenInHitTestOrder
Definition: SemanticsObject.mm:268
_children
NSMutableArray< SemanticsObject * > * _children
Definition: SemanticsObject.mm:265
FlutterCustomAccessibilityAction::uid
int32_t uid
Definition: SemanticsObject.h:139
SemanticsObject::bridge
fml::WeakPtr< flutter::AccessibilityBridgeIos > bridge
Definition: SemanticsObject.h:51
_bridge
fml::WeakPtr< flutter::AccessibilityBridgeIos > _bridge
Definition: SemanticsObject.mm:897
SemanticsObject::node
flutter::SemanticsNode node
Definition: SemanticsObject.h:56
kRootNodeId
constexpr int32_t kRootNodeId
Definition: SemanticsObject.h:15
SemanticsObject::hasChildren
BOOL hasChildren
Definition: SemanticsObject.h:61
SemanticsObject::children
NSArray< SemanticsObject * > * children
Definition: SemanticsObject.h:67
SemanticsObject::uid
int32_t uid
Definition: SemanticsObject.h:35
SemanticsObject
Definition: SemanticsObject.h:30