Flutter Engine
SemanticsObject Class Reference

#import <SemanticsObject.h>

Inheritance diagram for SemanticsObject:
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:
 

Properties

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

Detailed Description

A node in the iOS semantics tree.

Definition at line 25 of file SemanticsObject.h.

Method Documentation

◆ __attribute__()

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

◆ 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 }

◆ collectRoutes:()

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

Definition at line 470 of file SemanticsObject.mm.

References flutter::kScopesRoute, and node.

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

◆ initWithBridge:uid:()

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

Definition at line 275 of file SemanticsObject.mm.

References _bridge, _children, _inDealloc, FML_DCHECK, and kRootNodeId.

276  uid:(int32_t)uid {
277  FML_DCHECK(bridge) << "bridge must be set";
279  // Initialize with the UIView as the container.
280  // The UIView will not necessarily be accessibility parent for this object.
281  // The bridge informs the OS of the actual structure via
282  // `accessibilityContainer` and `accessibilityElementAtIndex`.
283  self = [super initWithAccessibilityContainer:bridge->view()];
284 
285  if (self) {
286  _bridge = bridge;
287  _uid = uid;
288  _children = [[NSMutableArray alloc] init];
289  }
290 
291  return self;
292 }
fml::WeakPtr< flutter::AccessibilityBridgeIos > _bridge
#define FML_DCHECK(condition)
Definition: logging.h:86
fml::WeakPtr< flutter::AccessibilityBridgeIos > bridge
constexpr int32_t kRootNodeId
NSMutableArray< SemanticsObject * > * _children

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

References bridge.

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

◆ nodeShouldTriggerAnnouncement:()

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

Whether calling setSemanticsNode: with node should trigger an announcement.

Definition at line 359 of file SemanticsObject.mm.

References flutter::kIsLiveRegion, and node.

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 }
bool HasFlag(SemanticsFlags flag) const

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

References node.

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.

References node.

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

References _inDealloc, action, args, bridge, fml::MallocMapping::Copy(), id, flutter::kCustomAction, flutter::kDecrease, flutter::kDidGainAccessibilityFocus, flutter::kDidLoseAccessibilityFocus, flutter::kDismiss, flutter::kHasCheckedState, flutter::kHasEnabledState, flutter::kHasToggledState, flutter::kIncrease, flutter::kIsButton, flutter::kIsChecked, flutter::kIsEnabled, flutter::kIsHeader, flutter::kIsHidden, flutter::kIsImage, flutter::kIsLink, flutter::kIsLiveRegion, flutter::kIsSelected, flutter::kIsTextField, flutter::kIsToggled, kRootNodeId, flutter::kShowOnScreen, flutter::kTap, length, node, node, parent, FlutterCustomAccessibilityAction::uid, and value.

481  if (![self node].HasAction(flutter::SemanticsAction::kCustomAction))
482  return NO;
483  int32_t action_id = action.uid;
484  std::vector<uint8_t> args;
485  args.push_back(3); // type=int32.
486  args.push_back(action_id);
487  args.push_back(action_id >> 8);
488  args.push_back(action_id >> 16);
489  args.push_back(action_id >> 24);
490  [self bridge]->DispatchSemanticsAction(
492  fml::MallocMapping::Copy(args.data(), args.size() * sizeof(uint8_t)));
493  return YES;
494 }
G_BEGIN_DECLS FlValue * args
static MallocMapping Copy(const T *begin, const T *end)
Definition: mapping.h:147
flutter::SemanticsNode node

◆ replaceChildAtIndex:withChild:()

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

Definition at line 374 of file SemanticsObject.mm.

References _children.

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

◆ routeName()

- (NSString *) routeName

Definition at line 381 of file SemanticsObject.mm.

References flags, id, flutter::kIsHidden, flutter::kLocale, flutter::kNamesRoute, flutter::kScopesRoute, flutter::kScrollableSemanticsActions, flutter::kScrollableSemanticsFlags, flutter::kSpellOut, length, node, and node.

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 }
NSArray< SemanticsObject * > * children
size_t length
flutter::SemanticsNode node

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

References node.

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

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

Referenced by FlutterPlatformViewSemanticsContainer::initWithSemanticsObject:, 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 62 of file SemanticsObject.h.

Referenced by flutter::ReplaceSemanticsObject().

◆ hasChildren

- (BOOL) hasChildren
readnonatomicassign

Whether this semantics object has child semantics objects.

Definition at line 56 of file SemanticsObject.h.

Referenced by SemanticsObjectContainer::initWithSemanticsObject:bridge:.

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

Referenced by SemanticsObjectContainer::initWithSemanticsObject:bridge:.

◆ node

- (SemanticsNode) SemanticsObject:
readnonatomicassign

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

Referenced by onCustomAccessibilityAction:, and flutter::ReplaceSemanticsObject().

◆ platformViewSemanticsContainer

- (FlutterPlatformViewSemanticsContainer*) platformViewSemanticsContainer
readwritenonatomicstrong

Used if this SemanticsObject is for a platform view.

Definition at line 67 of file SemanticsObject.h.

Referenced by SemanticsObjectContainer::initWithSemanticsObject:bridge:.

◆ uid

- (int32_t) uid
readnonatomicassign

The globally unique identifier for this node.

Definition at line 30 of file SemanticsObject.h.

Referenced by flutter::ReplaceSemanticsObject().


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