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

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

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

471  :(NSMutableArray<SemanticsObject*>*)edges {
472  if (self.node.flags.scopesRoute) {
473  [edges addObject:self];
474  }
475  if ([self hasChildren]) {
476  for (SemanticsObject* child in self.children) {
477  [child collectRoutes:edges];
478  }
479  }
480 }
flutter::SemanticsNode node
NSArray< SemanticsObject * > * children

◆ initWithBridge:uid:

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

Reimplemented in FlutterPlatformViewSemanticsContainer.

Definition at line 259 of file SemanticsObject.mm.

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

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

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

◆ nodeShouldTriggerAnnouncement:

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

Whether calling setSemanticsNode: with node should trigger an announcement.

Definition at line 259 of file SemanticsObject.mm.

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

◆ nodeWillCauseLayoutChange:

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

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

Definition at line 259 of file SemanticsObject.mm.

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

◆ nodeWillCauseScroll:

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

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

Definition at line 259 of file SemanticsObject.mm.

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

◆ onCustomAccessibilityAction:

- (BOOL) onCustomAccessibilityAction: (FlutterCustomAccessibilityAction*)  action

Definition at line 259 of file SemanticsObject.mm.

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

◆ replaceChildAtIndex:withChild:

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

Definition at line 259 of file SemanticsObject.mm.

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

◆ routeName

- (NSString *) routeName

Definition at line 259 of file SemanticsObject.mm.

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

◆ setSemanticsNode:

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

Updates this semantics object using data from the node argument.

Definition at line 259 of file SemanticsObject.mm.

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

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 SemanticsObjectContainer::initWithSemanticsObject:bridge:.

◆ 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().

◆ uid

- (int32_t) uid
readnonatomicassign

The globally unique identifier for this node.

Definition at line 36 of file SemanticsObject.h.

Referenced by FlutterPlatformViewSemanticsContainer::initWithBridge:uid:, and SemanticsObjectContainer::initWithSemanticsObject:bridge:.


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