未验证 提交 4cfbe450 编写于 作者: G gaaclarke 提交者: GitHub

Started clearing out the parent of orphaned semantic objects. (#17499)

上级 d5e7b807
...@@ -43,7 +43,7 @@ class AccessibilityBridge; ...@@ -43,7 +43,7 @@ class AccessibilityBridge;
* The parent of this node in the node tree. Will be nil for the root node and * The parent of this node in the node tree. Will be nil for the root node and
* during transient state changes. * during transient state changes.
*/ */
@property(nonatomic, assign) SemanticsObject* parent; @property(nonatomic, readonly) SemanticsObject* parent;
/** /**
* The accessibility bridge that this semantics object is attached to. This * The accessibility bridge that this semantics object is attached to. This
...@@ -85,13 +85,15 @@ class AccessibilityBridge; ...@@ -85,13 +85,15 @@ class AccessibilityBridge;
* Direct children of this semantics object. Each child's `parent` property must * Direct children of this semantics object. Each child's `parent` property must
* be equal to this object. * be equal to this object.
*/ */
@property(nonatomic, strong) NSMutableArray<SemanticsObject*>* children; @property(nonatomic, strong) NSArray<SemanticsObject*>* children;
/** /**
* Used if this SemanticsObject is for a platform view. * Used if this SemanticsObject is for a platform view.
*/ */
@property(strong, nonatomic) FlutterPlatformViewSemanticsContainer* platformViewSemanticsContainer; @property(strong, nonatomic) FlutterPlatformViewSemanticsContainer* platformViewSemanticsContainer;
- (void)replaceChildAtIndex:(NSInteger)index withChild:(SemanticsObject*)child;
- (BOOL)nodeWillCauseLayoutChange:(const flutter::SemanticsNode*)node; - (BOOL)nodeWillCauseLayoutChange:(const flutter::SemanticsNode*)node;
#pragma mark - Designated initializers #pragma mark - Designated initializers
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h" #include "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h"
#include "flutter/shell/platform/darwin/ios/platform_view_ios.h" #include "flutter/shell/platform/darwin/ios/platform_view_ios.h"
FLUTTER_ASSERT_NOT_ARC
namespace { namespace {
constexpr int32_t kRootNodeId = 0; constexpr int32_t kRootNodeId = 0;
...@@ -162,8 +164,14 @@ flutter::SemanticsAction GetSemanticsActionForScrollDirection( ...@@ -162,8 +164,14 @@ flutter::SemanticsAction GetSemanticsActionForScrollDirection(
@end @end
@interface SemanticsObject ()
/** Should only be called in conjunction with setting child/parent relationship. */
- (void)privateSetParent:(SemanticsObject*)parent;
@end
@implementation SemanticsObject { @implementation SemanticsObject {
fml::scoped_nsobject<SemanticsObjectContainer> _container; fml::scoped_nsobject<SemanticsObjectContainer> _container;
NSMutableArray<SemanticsObject*>* _children;
} }
#pragma mark - Override base class designated initializers #pragma mark - Override base class designated initializers
...@@ -197,7 +205,7 @@ flutter::SemanticsAction GetSemanticsActionForScrollDirection( ...@@ -197,7 +205,7 @@ flutter::SemanticsAction GetSemanticsActionForScrollDirection(
- (void)dealloc { - (void)dealloc {
for (SemanticsObject* child in _children) { for (SemanticsObject* child in _children) {
child.parent = nil; [child privateSetParent:nil];
} }
[_children removeAllObjects]; [_children removeAllObjects];
[_children release]; [_children release];
...@@ -239,6 +247,28 @@ flutter::SemanticsAction GetSemanticsActionForScrollDirection( ...@@ -239,6 +247,28 @@ flutter::SemanticsAction GetSemanticsActionForScrollDirection(
return [self.children count] != 0; return [self.children count] != 0;
} }
- (void)privateSetParent:(SemanticsObject*)parent {
_parent = parent;
}
- (void)setChildren:(NSArray<SemanticsObject*>*)children {
for (SemanticsObject* child in _children) {
[child privateSetParent:nil];
}
[_children release];
_children = [[NSMutableArray alloc] initWithArray:children];
for (SemanticsObject* child in _children) {
[child privateSetParent:self];
}
}
- (void)replaceChildAtIndex:(NSInteger)index withChild:(SemanticsObject*)child {
SemanticsObject* oldChild = _children[index];
[oldChild privateSetParent:nil];
[child privateSetParent:self];
[_children replaceObjectAtIndex:index withObject:child];
}
#pragma mark - UIAccessibility overrides #pragma mark - UIAccessibility overrides
- (BOOL)isAccessibilityElement { - (BOOL)isAccessibilityElement {
...@@ -653,7 +683,7 @@ flutter::SemanticsAction GetSemanticsActionForScrollDirection( ...@@ -653,7 +683,7 @@ flutter::SemanticsAction GetSemanticsActionForScrollDirection(
return ((FlutterPlatformViewSemanticsContainer*)element).index; return ((FlutterPlatformViewSemanticsContainer*)element).index;
} }
NSMutableArray<SemanticsObject*>* children = [_semanticsObject children]; NSArray<SemanticsObject*>* children = [_semanticsObject children];
for (size_t i = 0; i < [children count]; i++) { for (size_t i = 0; i < [children count]; i++) {
SemanticsObject* child = children[i]; SemanticsObject* child = children[i];
if ((![child hasChildren] && child == element) || if ((![child hasChildren] && child == element) ||
...@@ -741,7 +771,6 @@ void AccessibilityBridge::UpdateSemantics(flutter::SemanticsNodeUpdates nodes, ...@@ -741,7 +771,6 @@ void AccessibilityBridge::UpdateSemantics(flutter::SemanticsNodeUpdates nodes,
[[[NSMutableArray alloc] initWithCapacity:newChildCount] autorelease]; [[[NSMutableArray alloc] initWithCapacity:newChildCount] autorelease];
for (NSUInteger i = 0; i < newChildCount; ++i) { for (NSUInteger i = 0; i < newChildCount; ++i) {
SemanticsObject* child = GetOrCreateObject(node.childrenInTraversalOrder[i], nodes); SemanticsObject* child = GetOrCreateObject(node.childrenInTraversalOrder[i], nodes);
child.parent = object;
[newChildren addObject:child]; [newChildren addObject:child];
} }
object.children = newChildren; object.children = newChildren;
...@@ -847,10 +876,8 @@ static void ReplaceSemanticsObject(SemanticsObject* oldObject, ...@@ -847,10 +876,8 @@ static void ReplaceSemanticsObject(SemanticsObject* oldObject,
assert(oldObject.node.id == newObject.node.id); assert(oldObject.node.id == newObject.node.id);
NSNumber* nodeId = @(oldObject.node.id); NSNumber* nodeId = @(oldObject.node.id);
NSUInteger positionInChildlist = [oldObject.parent.children indexOfObject:oldObject]; NSUInteger positionInChildlist = [oldObject.parent.children indexOfObject:oldObject];
SemanticsObject* parent = oldObject.parent;
[objects removeObjectForKey:nodeId]; [objects removeObjectForKey:nodeId];
newObject.parent = parent; [oldObject.parent replaceChildAtIndex:positionInChildlist withChild:newObject];
[newObject.parent.children replaceObjectAtIndex:positionInChildlist withObject:newObject];
objects[nodeId] = newObject; objects[nodeId] = newObject;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册