Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
SemanticsObject Class Reference

#include <SemanticsObject.h>

Inheritance diagram for SemanticsObject:
FlutterPlatformViewSemanticsContainer FlutterScrollableSemanticsObject FlutterSemanticsObject FlutterSwitchSemanticsObject TextInputSemanticsObject

Instance Methods

(nullable flutter::AccessibilityBridgeIos *) - bridge
 
(nullable UIView *) - bridgeView
 
(void) - setSemanticsNode:
 
(void) - replaceChildAtIndex:withChild:
 
(BOOL- nodeWillCauseLayoutChange:
 
(BOOL- nodeWillCauseScroll:
 
(BOOL- nodeShouldTriggerAnnouncement:
 
(void) - collectRoutes:
 
(nullable 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
 
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 33 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 272 of file SemanticsObject.mm.

358 { /* Do nothing by default */
359}

◆ accessibilityScrollToVisible

- (BOOL) accessibilityScrollToVisible

Provided by category SemanticsObject(Tests).

◆ accessibilityScrollToVisibleWithChild:

- (BOOL) accessibilityScrollToVisibleWithChild: (id child

Provided by category SemanticsObject(Tests).

◆ bridge

- (AccessibilityBridgeIos *) SemanticsObject:

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 accessibility framework should use bridge (or bridgeView) 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.

Returns a raw pointer to the AccessibilityBridge if it is still alive, or nullptr if destroyed.

Definition at line 272 of file SemanticsObject.mm.

345 {
346 return _weakBridge.get();
347}

◆ bridgeView

- (UIView *) bridgeView

Returns the underlying UIView from the bridge if alive, or nil if destroyed.

Definition at line 272 of file SemanticsObject.mm.

349 {
351 return bridge ? bridge->view() : nil;
352}
Interface that represents an accessibility bridge for iOS.
virtual UIView * view() const =0
nullable flutter::AccessibilityBridgeIos * bridge()

◆ collectRoutes:

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

Definition at line 272 of file SemanticsObject.mm.

509 :(NSMutableArray<SemanticsObject*>*)edges {
510 if (self.node.flags.scopesRoute) {
511 [edges addObject:self];
512 }
513 if ([self hasChildren]) {
514 for (SemanticsObject* child in self.children) {
515 [child collectRoutes:edges];
516 }
517 }
518}
NSArray< SemanticsObject * > * children
flutter::SemanticsNode node

◆ initWithBridge:uid:

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

Reimplemented in FlutterPlatformViewSemanticsContainer.

Definition at line 272 of file SemanticsObject.mm.

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

◆ nodeShouldTriggerAnnouncement:

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

◆ nodeWillCauseLayoutChange:

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

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

Definition at line 272 of file SemanticsObject.mm.

365 return self.node.rect != node->rect || self.node.transform != node->transform;
366}

◆ nodeWillCauseScroll:

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

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

Definition at line 272 of file SemanticsObject.mm.

372 return !isnan(self.node.scrollPosition) && !isnan(node->scrollPosition) &&
373 self.node.scrollPosition != node->scrollPosition;
374}

◆ onCustomAccessibilityAction:

- (BOOL) onCustomAccessibilityAction: (FlutterCustomAccessibilityAction*)  action

Definition at line 272 of file SemanticsObject.mm.

522 if (!bridge) {
523 return NO;
524 }
526 return NO;
527 }
528 int32_t action_id = action.uid;
529 std::vector<uint8_t> args;
530 args.push_back(3); // type=int32.
531 args.push_back(action_id);
532 args.push_back(action_id >> 8);
533 args.push_back(action_id >> 16);
534 args.push_back(action_id >> 24);
537 fml::MallocMapping::Copy(args.data(), args.size() * sizeof(uint8_t)));
538 return YES;
539}
virtual void DispatchSemanticsAction(int32_t id, flutter::SemanticsAction action)=0
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 272 of file SemanticsObject.mm.

395 :(NSInteger)index withChild:(SemanticsObject*)child {
396 SemanticsObject* oldChild = _children[index];
397 oldChild.parent = nil;
398 child.parent = self;
399 [_children replaceObjectAtIndex:index withObject:child];
400}
SemanticsObject * parent

◆ routeName

- (NSString *) routeName

Definition at line 272 of file SemanticsObject.mm.

402 {
403 // Returns the first non-null and non-empty semantic label of a child
404 // with an NamesRoute flag. Otherwise returns nil.
405 if (self.node.flags.namesRoute) {
406 NSString* newName = self.accessibilityLabel;
407 if (newName != nil && [newName length] > 0) {
408 return newName;
409 }
410 }
411 if ([self hasChildren]) {
412 for (SemanticsObject* child in self.children) {
413 NSString* newName = [child routeName];
414 if (newName != nil && [newName length] > 0) {
415 return newName;
416 }
417 }
418 }
419 return nil;
420}
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 272 of file SemanticsObject.mm.

355 _node = *node;
356}

Property Documentation

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

◆ hasChildren

- (BOOL) hasChildren
readnonatomicassign

Whether this semantics object has child semantics objects.

Definition at line 54 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 75 of file SemanticsObject.h.

◆ node

- (SemanticsNode) SemanticsObject:
readnonatomicassign

The semantics node used to produce this semantics object.

Definition at line 49 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 44 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 38 of file SemanticsObject.h.


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