Flutter Engine
 
Loading...
Searching...
No Matches
SemanticsObject Class Reference

#include <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 260 of file SemanticsObject.mm.

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

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

483 :(NSMutableArray<SemanticsObject*>*)edges {
484 if (self.node.flags.scopesRoute) {
485 [edges addObject:self];
486 }
487 if ([self hasChildren]) {
488 for (SemanticsObject* child in self.children) {
489 [child collectRoutes:edges];
490 }
491 }
492}
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 260 of file SemanticsObject.mm.

266 uid:(int32_t)uid {
267 FML_DCHECK(bridge) << "bridge must be set";
269 // Initialize with the UIView as the container.
270 // The UIView will not necessarily be accessibility parent for this object.
271 // The bridge informs the OS of the actual structure via
272 // `accessibilityContainer` and `accessibilityElementAtIndex`.
273 self = [super initWithAccessibilityContainer:bridge->view()];
274
275 if (self) {
276 _bridge = bridge;
277 _uid = uid;
278 _children = [[NSMutableArray alloc] init];
279 _childrenInHitTestOrder = [[NSArray alloc] init];
280 }
281
282 return self;
283}
constexpr int32_t kRootNodeId
#define FML_DCHECK(condition)
Definition logging.h:122
fml::WeakPtr< flutter::AccessibilityBridgeIos > bridge
std::shared_ptr< flutter::AccessibilityBridgeMac > _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 260 of file SemanticsObject.mm.

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

360 // The node dropped the live region flag, if it ever had one.
361 if (!node || !node->flags.isLiveRegion) {
362 return NO;
363 }
364
365 // The node has gained a new live region flag, always announce.
366 if (!self.node.flags.isLiveRegion) {
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}

◆ nodeWillCauseLayoutChange:

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

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

Definition at line 260 of file SemanticsObject.mm.

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

351 return !isnan(self.node.scrollPosition) && !isnan(node->scrollPosition) &&
352 self.node.scrollPosition != node->scrollPosition;
353}

◆ onCustomAccessibilityAction:

- (BOOL) onCustomAccessibilityAction: (FlutterCustomAccessibilityAction*)  action

Definition at line 260 of file SemanticsObject.mm.

496 return NO;
497 }
498 int32_t action_id = action.uid;
499 std::vector<uint8_t> args;
500 args.push_back(3); // type=int32.
501 args.push_back(action_id);
502 args.push_back(action_id >> 8);
503 args.push_back(action_id >> 16);
504 args.push_back(action_id >> 24);
505 self.bridge->DispatchSemanticsAction(
507 fml::MallocMapping::Copy(args.data(), args.size() * sizeof(uint8_t)));
508 return YES;
509}
static MallocMapping Copy(const T *begin, const T *end)
Definition mapping.h:162
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
bool HasAction(SemanticsAction action) const

◆ replaceChildAtIndex:withChild:

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

Definition at line 260 of file SemanticsObject.mm.

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

◆ routeName

- (NSString *) routeName

Definition at line 260 of file SemanticsObject.mm.

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.flags.namesRoute) {
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}
size_t length

◆ setSemanticsNode:

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

Updates this semantics object using data from the node argument.

Definition at line 260 of file SemanticsObject.mm.

334 _node = *node;
335}

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


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