| Flutter iOS Embedder |

Instance Methods | Properties | List of all members
SemanticsObject Class Reference

`#import <SemanticsObject.h>`

Inheritance diagram for SemanticsObject:

## 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
SemanticsObject * | parent
fml::WeakPtr< flutter::AccessibilityBridgeIos > | bridge
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 332 of file SemanticsObject.mm.

332 { /* Do nothing by default */
333 }

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

469 :(NSMutableArray<SemanticsObject*>*)edges {
470 if (self.node.HasFlag(flutter::SemanticsFlags::kScopesRoute)) {
471 [edges addObject:self];
472 }
473 if ([self hasChildren]) {
474 for (SemanticsObject* child in self.children) {
475 [child collectRoutes:edges];
476 }
477 }
478 }

## ◆ initWithBridge:uid:

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

Reimplemented in FlutterPlatformViewSemanticsContainer.

Definition at line 260 of file SemanticsObject.mm.

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

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

324 {
325 return self.bridge.get() != nil;
326 }

References bridge.

## ◆ nodeShouldTriggerAnnouncement:

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

Whether calling `setSemanticsNode:` with `node` should trigger an announcement.

Definition at line 354 of file SemanticsObject.mm.

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

## ◆ nodeWillCauseLayoutChange:

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

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

Definition at line 338 of file SemanticsObject.mm.

338 :(const flutter::SemanticsNode*)node {
339 return self.node.rect != node->rect || self.node.transform != node->transform;
340 }

## ◆ nodeWillCauseScroll:

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

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

Definition at line 345 of file SemanticsObject.mm.

345 :(const flutter::SemanticsNode*)node {
346 return !isnan(self.node.scrollPosition) && !isnan(node->scrollPosition) &&
347 self.node.scrollPosition != node->scrollPosition;
348 }

## ◆ onCustomAccessibilityAction:

- (BOOL) onCustomAccessibilityAction: |  | (FlutterCustomAccessibilityAction*) | action |

Definition at line 480 of file SemanticsObject.mm.

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

References FlutterCustomAccessibilityAction::uid.

## ◆ replaceChildAtIndex:withChild:

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

Definition at line 369 of file SemanticsObject.mm.

369 :(NSInteger)index withChild:(SemanticsObject*)child {
370 SemanticsObject* oldChild = _children[index];
371 oldChild.parent = nil;
372 child.parent = self;
373 [_children replaceObjectAtIndex:index withObject:child];
374 }

References parent.

## ◆ routeName

- (NSString *) routeName |  |  |

Definition at line 376 of file SemanticsObject.mm.

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

## ◆ setSemanticsNode:

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

Updates this semantics object using data from the `node` argument.

Definition at line 328 of file SemanticsObject.mm.

328 :(const flutter::SemanticsNode*)node {
329 _node = *node;
330 }

## Property Documentation

## ◆ bridge

- (WeakPtr<)flutter:
| read nonatomic assign

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 FLUTTER_ASSERT_ARC::ConvertPointToGlobal(), FLUTTER_ASSERT_ARC::ConvertRectToGlobal(), and isAccessibilityBridgeAlive.

## ◆ children

- (NSArray<SemanticsObject*>*) children
| read write nonatomic copy

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
| read write nonatomic copy

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
| read nonatomic assign

Whether this semantics object has child semantics objects.

Definition at line 61 of file SemanticsObject.h.

## ◆ nativeAccessibility

- (id) nativeAccessibility
| read nonatomic assign

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:
| read nonatomic assign

The semantics node used to produce this semantics object.

Definition at line 56 of file SemanticsObject.h.

## ◆ parent

- (SemanticsObject*) parent
| read nonatomic weak

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.

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

## ◆ uid

- (int32_t) uid
| read nonatomic assign

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:

- shell/platform/darwin/ios/framework/Source/SemanticsObject.h
- shell/platform/darwin/ios/framework/Source/SemanticsObject.mm

SemanticsObject::parent
SemanticsObject * parent
Definition: SemanticsObject.h:41
FlutterCustomAccessibilityAction
Definition: SemanticsObject.h:134
FlutterCustomAccessibilityAction::uid
int32_t uid
Definition: SemanticsObject.h:139
SemanticsObject::bridge
fml::WeakPtr< flutter::AccessibilityBridgeIos > bridge
Definition: SemanticsObject.h:51
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