mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Migrate SemanticsObject and FlutterSemanticsScrollView to ARC (flutter/engine#52824)
On top of the `SemanticsObject` refactor https://github.com/flutter/engine/pull/52729 migrate `SemanticsObject` and `FlutterSemanticsScrollView` to ARC. Part of https://github.com/flutter/flutter/issues/137801.
This commit is contained in:
parent
91a74353b4
commit
a4dc4d92ba
@ -83,6 +83,8 @@ source_set("flutter_framework_source_arc") {
|
||||
"framework/Source/FlutterPluginAppLifeCycleDelegate.mm",
|
||||
"framework/Source/FlutterRestorationPlugin.h",
|
||||
"framework/Source/FlutterRestorationPlugin.mm",
|
||||
"framework/Source/FlutterSemanticsScrollView.h",
|
||||
"framework/Source/FlutterSemanticsScrollView.mm",
|
||||
"framework/Source/FlutterSpellCheckPlugin.h",
|
||||
"framework/Source/FlutterSpellCheckPlugin.mm",
|
||||
"framework/Source/FlutterTextInputDelegate.h",
|
||||
@ -100,6 +102,8 @@ source_set("flutter_framework_source_arc") {
|
||||
"framework/Source/FlutterViewResponder.h",
|
||||
"framework/Source/KeyCodeMap.g.mm",
|
||||
"framework/Source/KeyCodeMap_Internal.h",
|
||||
"framework/Source/SemanticsObject.h",
|
||||
"framework/Source/SemanticsObject.mm",
|
||||
"framework/Source/UIViewController+FlutterScreenAndSceneIfLoaded.h",
|
||||
"framework/Source/UIViewController+FlutterScreenAndSceneIfLoaded.mm",
|
||||
"framework/Source/connection_collection.h",
|
||||
@ -173,12 +177,8 @@ source_set("flutter_framework_source") {
|
||||
"framework/Source/FlutterHeadlessDartRunner.mm",
|
||||
"framework/Source/FlutterPlatformPlugin.h",
|
||||
"framework/Source/FlutterPlatformPlugin.mm",
|
||||
"framework/Source/FlutterSemanticsScrollView.h",
|
||||
"framework/Source/FlutterSemanticsScrollView.mm",
|
||||
"framework/Source/FlutterViewController.mm",
|
||||
"framework/Source/FlutterViewController_Internal.h",
|
||||
"framework/Source/SemanticsObject.h",
|
||||
"framework/Source/SemanticsObject.mm",
|
||||
"framework/Source/accessibility_bridge.h",
|
||||
"framework/Source/accessibility_bridge.mm",
|
||||
"framework/Source/accessibility_text_entry.h",
|
||||
|
||||
@ -20,7 +20,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
*/
|
||||
@interface FlutterSemanticsScrollView : UIScrollView
|
||||
|
||||
@property(nonatomic, assign, nullable) SemanticsObject* semanticsObject;
|
||||
@property(nonatomic, weak, nullable) SemanticsObject* semanticsObject;
|
||||
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
- (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE;
|
||||
|
||||
@ -4,8 +4,11 @@
|
||||
|
||||
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterSemanticsScrollView.h"
|
||||
|
||||
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
|
||||
#import "flutter/shell/platform/darwin/ios/framework/Source/SemanticsObject.h"
|
||||
|
||||
FLUTTER_ASSERT_ARC
|
||||
|
||||
@implementation FlutterSemanticsScrollView
|
||||
|
||||
- (instancetype)initWithSemanticsObject:(SemanticsObject*)semanticsObject {
|
||||
|
||||
@ -38,7 +38,7 @@ constexpr float kScrollExtentMaxForInf = 1000;
|
||||
* The parent of this node in the node tree. Will be nil for the root node and
|
||||
* during transient state changes.
|
||||
*/
|
||||
@property(nonatomic, assign, readonly) SemanticsObject* parent;
|
||||
@property(nonatomic, weak, readonly) SemanticsObject* parent;
|
||||
|
||||
/**
|
||||
* The accessibility bridge that this semantics object is attached to. This
|
||||
@ -231,7 +231,7 @@ constexpr float kScrollExtentMaxForInf = 1000;
|
||||
bridge:(fml::WeakPtr<flutter::AccessibilityBridgeIos>)bridge
|
||||
NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
@property(nonatomic, assign) SemanticsObject* semanticsObject;
|
||||
@property(nonatomic, weak) SemanticsObject* semanticsObject;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@ -7,6 +7,8 @@
|
||||
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h"
|
||||
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterSemanticsScrollView.h"
|
||||
|
||||
FLUTTER_ASSERT_ARC
|
||||
|
||||
namespace {
|
||||
|
||||
flutter::SemanticsAction GetSemanticsActionForScrollDirection(
|
||||
@ -107,11 +109,6 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) {
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[_nativeSwitch release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSMethodSignature*)methodSignatureForSelector:(SEL)sel {
|
||||
NSMethodSignature* result = [super methodSignatureForSelector:sel];
|
||||
if (!result) {
|
||||
@ -145,7 +142,7 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) {
|
||||
@end // FlutterSwitchSemanticsObject
|
||||
|
||||
@interface FlutterScrollableSemanticsObject ()
|
||||
@property(nonatomic, retain) FlutterSemanticsScrollView* scrollView;
|
||||
@property(nonatomic) FlutterSemanticsScrollView* scrollView;
|
||||
@end
|
||||
|
||||
@implementation FlutterScrollableSemanticsObject
|
||||
@ -164,9 +161,6 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) {
|
||||
|
||||
- (void)dealloc {
|
||||
[_scrollView removeFromSuperview];
|
||||
_scrollView.semanticsObject = nil;
|
||||
[_scrollView release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void)accessibilityBridgeDidFinishUpdate {
|
||||
@ -249,10 +243,10 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) {
|
||||
@end
|
||||
|
||||
@interface SemanticsObject ()
|
||||
@property(nonatomic, retain) SemanticsObjectContainer* container;
|
||||
@property(nonatomic) SemanticsObjectContainer* container;
|
||||
|
||||
/** Should only be called in conjunction with setting child/parent relationship. */
|
||||
@property(nonatomic, assign, readwrite) SemanticsObject* parent;
|
||||
@property(nonatomic, weak, readwrite) SemanticsObject* parent;
|
||||
|
||||
@end
|
||||
|
||||
@ -261,15 +255,6 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) {
|
||||
BOOL _inDealloc;
|
||||
}
|
||||
|
||||
#pragma mark - Override base class designated initializers
|
||||
|
||||
// Method declared as unavailable in the interface
|
||||
- (instancetype)init {
|
||||
[self release];
|
||||
[super doesNotRecognizeSelector:_cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
#pragma mark - Designated initializers
|
||||
|
||||
- (instancetype)initWithBridge:(fml::WeakPtr<flutter::AccessibilityBridgeIos>)bridge
|
||||
@ -293,17 +278,19 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) {
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
// Set parent and children parents to nil explicitly in dealloc.
|
||||
// -[UIAccessibilityElement dealloc] has in the past called into -accessibilityContainer
|
||||
// and self.children. There have also been crashes related to iOS
|
||||
// accessing methods during dealloc, and there's a lag before the tree changes.
|
||||
// See https://github.com/flutter/engine/pull/4602 and
|
||||
// https://github.com/flutter/engine/pull/27786.
|
||||
for (SemanticsObject* child in _children) {
|
||||
child.parent = nil;
|
||||
}
|
||||
[_children removeAllObjects];
|
||||
[_children release];
|
||||
[_childrenInHitTestOrder release];
|
||||
|
||||
_parent = nil;
|
||||
[_container release];
|
||||
_inDealloc = YES;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
#pragma mark - Semantic object property accesser
|
||||
@ -312,7 +299,6 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) {
|
||||
for (SemanticsObject* child in _children) {
|
||||
child.parent = nil;
|
||||
}
|
||||
[_children release];
|
||||
_children = [children mutableCopy];
|
||||
for (SemanticsObject* child in _children) {
|
||||
child.parent = self;
|
||||
@ -323,7 +309,6 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) {
|
||||
for (SemanticsObject* child in _childrenInHitTestOrder) {
|
||||
child.parent = nil;
|
||||
}
|
||||
[_childrenInHitTestOrder release];
|
||||
_childrenInHitTestOrder = [childrenInHitTestOrder copy];
|
||||
for (SemanticsObject* child in _childrenInHitTestOrder) {
|
||||
child.parent = self;
|
||||
@ -416,7 +401,7 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) {
|
||||
withAttributes:
|
||||
(const flutter::StringAttributes&)attributes {
|
||||
NSMutableAttributedString* attributedString =
|
||||
[[[NSMutableAttributedString alloc] initWithString:string] autorelease];
|
||||
[[NSMutableAttributedString alloc] initWithString:string];
|
||||
for (const auto& attribute : attributes) {
|
||||
NSRange range = NSMakeRange(attribute->start, attribute->end - attribute->start);
|
||||
switch (attribute->type) {
|
||||
@ -686,9 +671,8 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) {
|
||||
|
||||
if ([self hasChildren] || self.uid == kRootNodeId) {
|
||||
if (self.container == nil) {
|
||||
self.container =
|
||||
[[[SemanticsObjectContainer alloc] initWithSemanticsObject:self
|
||||
bridge:self.bridge] autorelease];
|
||||
self.container = [[SemanticsObjectContainer alloc] initWithSemanticsObject:self
|
||||
bridge:self.bridge];
|
||||
}
|
||||
return self.container;
|
||||
}
|
||||
@ -787,17 +771,7 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) {
|
||||
|
||||
@end
|
||||
|
||||
@implementation FlutterSemanticsObject {
|
||||
}
|
||||
|
||||
#pragma mark - Override base class designated initializers
|
||||
|
||||
// Method declared as unavailable in the interface
|
||||
- (instancetype)init {
|
||||
[self release];
|
||||
[super doesNotRecognizeSelector:_cmd];
|
||||
return nil;
|
||||
}
|
||||
@implementation FlutterSemanticsObject
|
||||
|
||||
#pragma mark - Designated initializers
|
||||
|
||||
@ -853,7 +827,7 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) {
|
||||
@end
|
||||
|
||||
@interface FlutterPlatformViewSemanticsContainer ()
|
||||
@property(nonatomic, assign) UIView* platformView;
|
||||
@property(nonatomic, weak) UIView* platformView;
|
||||
@end
|
||||
|
||||
@implementation FlutterPlatformViewSemanticsContainer
|
||||
@ -868,11 +842,6 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) {
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
_platformView = nil;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (id)nativeAccessibility {
|
||||
return self.platformView;
|
||||
}
|
||||
@ -885,13 +854,6 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) {
|
||||
|
||||
#pragma mark - initializers
|
||||
|
||||
// Method declared as unavailable in the interface
|
||||
- (instancetype)init {
|
||||
[self release];
|
||||
[super doesNotRecognizeSelector:_cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (instancetype)initWithSemanticsObject:(SemanticsObject*)semanticsObject
|
||||
bridge:(fml::WeakPtr<flutter::AccessibilityBridgeIos>)bridge {
|
||||
FML_DCHECK(semanticsObject) << "semanticsObject must be set";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user