Skip to content

Commit

Permalink
Only post UIAccessibilityLayoutChangedNotification if layout changed (f…
Browse files Browse the repository at this point in the history
…lutter#4279)

* Only post UIAccessibilityLayoutChangedNotification if layout actually changed

* ++

* review comment
  • Loading branch information
goderbauer authored Oct 25, 2017
1 parent 144dea3 commit 6665645
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ - (void)setSemanticsNode:(const blink::SemanticsNode*)node {
_node = *node;
}

/**
* Whether calling `setSemanticsNode:` with `node` would cause a layout change.
*/
- (BOOL)willCauseLayoutChange:(const blink::SemanticsNode*)node {
return _node.rect != node->rect || _node.transform != node->transform;
}

- (std::vector<SemanticsObject*>*)children {
return &_children;
}
Expand Down Expand Up @@ -363,9 +370,11 @@ - (BOOL)accessibilityScroll:(UIAccessibilityScrollDirection)direction {
// Children are received in paint order (inverse hit testing order). We need to bring them into
// traversal order (top left to bottom right, with hit testing order as tie breaker).
NSMutableSet<SemanticsObject*>* childOrdersToUpdate = [[[NSMutableSet alloc] init] autorelease];
BOOL layoutChanged = NO;

for (const blink::SemanticsNode& node : nodes) {
SemanticsObject* object = GetOrCreateObject(node.id);
layoutChanged = layoutChanged || [object willCauseLayoutChange:&node];
[object setSemanticsNode:&node];
const size_t childrenCount = node.children.size();
auto& children = *[object children];
Expand Down Expand Up @@ -403,8 +412,12 @@ - (BOOL)accessibilityScroll:(UIAccessibilityScrollDirection)direction {
VisitObjectsRecursivelyAndRemove(root, doomed_uids);
[objects_ removeObjectsForKeys:doomed_uids];

// TODO(goderbauer): figure out which node to focus next.
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil);
layoutChanged = layoutChanged || [doomed_uids count] > 0;

if (layoutChanged) {
// TODO(goderbauer): figure out which node to focus next.
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil);
}
}

void AccessibilityBridge::DispatchSemanticsAction(int32_t uid, blink::SemanticsAction action) {
Expand Down

0 comments on commit 6665645

Please sign in to comment.