Flutter Engine
SemanticsObject Class Reference

#import <SemanticsObject.h>

Inheritance diagram for SemanticsObject:
FlutterSemanticsObject TextInputSemanticsObject

Instance Methods

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

Properties

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

Detailed Description

A node in the iOS semantics tree.

Definition at line 23 of file SemanticsObject.h.

Method Documentation

◆ __attribute__()

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

◆ collectRoutes:()

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

Definition at line 260 of file SemanticsObject.mm.

References collectRoutes:, and flutter::kScopesRoute.

Referenced by collectRoutes:.

260  :(NSMutableArray<SemanticsObject*>*)edges {
261  if ([self node].HasFlag(flutter::SemanticsFlags::kScopesRoute))
262  [edges addObject:self];
263  if ([self hasChildren]) {
264  for (SemanticsObject* child in self.children) {
265  [child collectRoutes:edges];
266  }
267  }
268 }
NSArray< SemanticsObject * > * children
flutter::SemanticsNode node

◆ initWithBridge:uid:()

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

Definition at line 127 of file SemanticsObject.mm.

References _bridge, _children, FML_DCHECK, and kRootNodeId.

128  uid:(int32_t)uid {
129  FML_DCHECK(bridge) << "bridge must be set";
131  // Initialize with the UIView as the container.
132  // The UIView will not necessarily be accessibility parent for this object.
133  // The bridge informs the OS of the actual structure via
134  // `accessibilityContainer` and `accessibilityElementAtIndex`.
135  self = [super initWithAccessibilityContainer:bridge->view()];
136 
137  if (self) {
138  _bridge = bridge;
139  _uid = uid;
140  _children = [[NSMutableArray alloc] init];
141  }
142 
143  return self;
144 }
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 160 of file SemanticsObject.mm.

References bridge.

160  {
161  return [self bridge].get() != nil;
162 }

◆ nodeShouldTriggerAnnouncement:()

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

Whether calling setSemanticsNode: with node should trigger an announcement.

Definition at line 187 of file SemanticsObject.mm.

References _children, flutter::kIsLiveRegion, and node.

187  :(const flutter::SemanticsNode*)node {
188  // The node dropped the live region flag, if it ever had one.
189  if (!node || !node->HasFlag(flutter::SemanticsFlags::kIsLiveRegion)) {
190  return NO;
191  }
192 
193  // The node has gained a new live region flag, always announce.
194  if (![self node].HasFlag(flutter::SemanticsFlags::kIsLiveRegion)) {
195  return YES;
196  }
197 
198  // The label has updated, and the new node has a live region flag.
199  return [self node].label != node->label;
200 }
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 171 of file SemanticsObject.mm.

References node.

171  :(const flutter::SemanticsNode*)node {
172  return [self node].rect != node->rect || [self node].transform != node->transform;
173 }

◆ nodeWillCauseScroll:()

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

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

Definition at line 178 of file SemanticsObject.mm.

References node.

178  :(const flutter::SemanticsNode*)node {
179  return !isnan([self node].scrollPosition) && !isnan(node->scrollPosition) &&
180  [self node].scrollPosition != node->scrollPosition;
181 }

◆ onCustomAccessibilityAction:()

- (BOOL) onCustomAccessibilityAction: (FlutterCustomAccessibilityAction*)  action

Definition at line 270 of file SemanticsObject.mm.

References args, bridge, flutter::kCustomAction, and FlutterCustomAccessibilityAction::uid.

271  if (![self node].HasAction(flutter::SemanticsAction::kCustomAction))
272  return NO;
273  int32_t action_id = action.uid;
274  std::vector<uint8_t> args;
275  args.push_back(3); // type=int32.
276  args.push_back(action_id);
277  args.push_back(action_id >> 8);
278  args.push_back(action_id >> 16);
279  args.push_back(action_id >> 24);
280  [self bridge]->DispatchSemanticsAction([self uid], flutter::SemanticsAction::kCustomAction,
281  std::move(args));
282  return YES;
283 }
G_BEGIN_DECLS FlValue * args
flutter::SemanticsNode node

◆ replaceChildAtIndex:withChild:()

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

Definition at line 224 of file SemanticsObject.mm.

References _children, flutter::flags, flutter::kIsHidden, flutter::kScopesRoute, flutter::kScrollableSemanticsActions, flutter::kScrollableSemanticsFlags, and node.

224  :(NSInteger)index withChild:(SemanticsObject*)child {
225  SemanticsObject* oldChild = _children[index];
226  [oldChild privateSetParent:nil];
227  [child privateSetParent:self];
228  [_children replaceObjectAtIndex:index withObject:child];
229 }
NSMutableArray< SemanticsObject * > * _children

◆ routeName()

- (NSString *) routeName

Definition at line 285 of file SemanticsObject.mm.

References bridge, id, 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::kIsToggled, flutter::kNamesRoute, kRootNodeId, flutter::kShowOnScreen, flutter::kTap, length, node, parent, routeName, flutter::SemanticsNode::transform, and value.

Referenced by routeName.

285  {
286  // Returns the first non-null and non-empty semantic label of a child
287  // with an NamesRoute flag. Otherwise returns nil.
288  if ([self node].HasFlag(flutter::SemanticsFlags::kNamesRoute)) {
289  NSString* newName = [self accessibilityLabel];
290  if (newName != nil && [newName length] > 0) {
291  return newName;
292  }
293  }
294  if ([self hasChildren]) {
295  for (SemanticsObject* child in self.children) {
296  NSString* newName = [child routeName];
297  if (newName != nil && [newName length] > 0) {
298  return newName;
299  }
300  }
301  }
302  return nil;
303 }
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 164 of file SemanticsObject.mm.

164  :(const flutter::SemanticsNode*)node {
165  _node = *node;
166 }
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 44 of file SemanticsObject.h.

Referenced by isAccessibilityBridgeAlive, onCustomAccessibilityAction:, and routeName.

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

Referenced by flutter::ReplaceSemanticsObject().

◆ hasChildren

- (BOOL) hasChildren
readnonatomicassign

Whether this semantics object has child semantics objects.

Definition at line 70 of file SemanticsObject.h.

Referenced by SemanticsObjectContainer::initWithSemanticsObject:bridge:.

◆ node

- (SemanticsNode) SemanticsObject:
readnonatomicassign

◆ parent

- (SemanticsObject*) parent
readnonatomicassign

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

Definition at line 34 of file SemanticsObject.h.

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

◆ platformViewSemanticsContainer

- (FlutterPlatformViewSemanticsContainer*) platformViewSemanticsContainer
readwritenonatomicstrong

Used if this SemanticsObject is for a platform view.

Definition at line 81 of file SemanticsObject.h.

Referenced by SemanticsObjectContainer::initWithSemanticsObject:bridge:.

◆ uid

- (int32_t) uid
readnonatomicassign

The globally unique identifier for this node.

Definition at line 28 of file SemanticsObject.h.


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