From c632ba2c5a1c7d2ce6fa4f2cc5ad27a47f0ac1f9 Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Fri, 19 Apr 2024 14:14:19 -0700 Subject: [PATCH] Break dependency cycle of FlutterViewController <-> FlutterPlatformView --- .../ios/framework/Source/FlutterOverlayView.h | 9 ------ .../framework/Source/FlutterOverlayView.mm | 13 ++------- .../framework/Source/FlutterPlatformViews.mm | 20 ++++--------- .../Source/FlutterPlatformViewsTest.mm | 5 ++-- .../Source/FlutterPlatformViews_Internal.h | 18 +++++++----- .../darwin/ios/framework/Source/FlutterView.h | 9 ++---- .../ios/framework/Source/FlutterView.mm | 11 ------- .../Source/FlutterViewController_Internal.h | 3 -- .../framework/Source/FlutterViewResponder.h | 29 +++++++++++++++++++ .../ios/framework/Source/FlutterViewTest.mm | 2 -- .../Source/accessibility_bridge_test.mm | 2 +- 11 files changed, 52 insertions(+), 69 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h b/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h index f94a0c4028888..fe050d1ffccdc 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h @@ -8,15 +8,6 @@ #include #include -#include - -#include "flutter/fml/memory/weak_ptr.h" -#include "flutter/shell/common/shell.h" -#import "flutter/shell/platform/darwin/ios/ios_surface.h" -#include "fml/platform/darwin/cf_utils.h" - -#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h" - /// UIViews that are used by |FlutterPlatformViews| to present Flutter /// rendering on top of system compositor rendering (ex. a web view). /// diff --git a/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.mm b/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.mm index 1bf00d8b40a62..dc29cd85dd7bf 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.mm @@ -3,20 +3,11 @@ // found in the LICENSE file. #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h" + #include -#include -#include "flutter/common/settings.h" -#include "flutter/common/task_runners.h" -#include "flutter/flow/layers/layer_tree.h" -#include "flutter/fml/platform/darwin/cf_utils.h" -#include "flutter/fml/synchronization/waitable_event.h" -#include "flutter/fml/trace_event.h" -#include "flutter/shell/common/platform_view.h" -#include "flutter/shell/common/rasterizer.h" #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h" -#import "flutter/shell/platform/darwin/ios/ios_surface_software.h" -#include "third_party/skia/include/utils/mac/SkCGUtils.h" +#include "fml/platform/darwin/cf_utils.h" // This is mostly a duplication of FlutterView. // TODO(amirh): once GL support is in evaluate if we can merge this with FlutterView. diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm index 6d605414e5b4f..56ab003c8d0b7 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm @@ -2,21 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include -#import +#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h" -#include -#include -#include -#include +#include -#include "flutter/common/graphics/persistent_cache.h" #include "flutter/fml/platform/darwin/scoped_nsobject.h" -#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h" #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h" -#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h" #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h" -#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h" #import "flutter/shell/platform/darwin/ios/ios_surface.h" @implementation UIView (FirstResponder) @@ -171,11 +163,11 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect, } void FlutterPlatformViewsController::SetFlutterViewController( - UIViewController* flutter_view_controller) { + UIViewController* flutter_view_controller) { flutter_view_controller_.reset([flutter_view_controller retain]); } -UIViewController* FlutterPlatformViewsController::getFlutterViewController() { +UIViewController* FlutterPlatformViewsController::getFlutterViewController() { return flutter_view_controller_.get(); } @@ -1147,7 +1139,7 @@ @implementation ForwardingGestureRecognizer { // This gesture recognizer retains the `FlutterViewController` until the // end of a gesture sequence, that is all the touches in touchesBegan are concluded // with |touchesCancelled| or |touchesEnded|. - fml::scoped_nsobject _flutterViewController; + fml::scoped_nsobject> _flutterViewController; } - (instancetype)initWithTarget:(id)target @@ -1198,7 +1190,7 @@ - (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event { // Flutter needs all the cancelled touches to be "cancelled" change types in order to correctly // handle gesture sequence. // We always override the change type to "cancelled". - [((FlutterViewController*)_flutterViewController.get()) forceTouchesCancelled:touches]; + [_flutterViewController.get() forceTouchesCancelled:touches]; _currentTouchPointersCount -= touches.count; if (_currentTouchPointersCount == 0) { self.state = UIGestureRecognizerStateFailed; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm index aad952fa87e15..2dc397d756a7c 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm @@ -6,13 +6,12 @@ #import #import -#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterBinaryMessenger.h" +#import "flutter/fml/thread.h" #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h" #import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlatformViews.h" #import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h" #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h" #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterTouchInterceptingView_Test.h" -#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h" #import "flutter/shell/platform/darwin/ios/platform_view_ios.h" FLUTTER_ASSERT_ARC @@ -2158,7 +2157,7 @@ - (void)testSetFlutterViewControllerInTheMiddleOfTouchEventShouldStillAllowGestu [forwardGectureRecognizer touchesBegan:touches1 withEvent:event1]; OCMVerify([mockFlutterViewContoller touchesBegan:touches1 withEvent:event1]); - UIViewController* mockFlutterViewContoller2 = OCMClassMock([UIViewController class]); + FlutterViewController* mockFlutterViewContoller2 = OCMClassMock([FlutterViewController class]); flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller2); // Touch events should still send to the old FlutterViewController if FlutterViewController diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h index 6dba0efd89365..b3337a1d69283 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h @@ -5,15 +5,17 @@ #ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERPLATFORMVIEWS_INTERNAL_H_ #define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERPLATFORMVIEWS_INTERNAL_H_ +#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlatformViews.h" + #include -#include "flutter/flow/embedded_views.h" + +#include "flutter/flow/surface.h" +#include "flutter/fml/memory/weak_ptr.h" #include "flutter/fml/platform/darwin/scoped_nsobject.h" -#include "flutter/shell/common/shell.h" -#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterBinaryMessenger.h" +#include "flutter/fml/trace_event.h" #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h" -#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlatformViews.h" #import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h" -#import "flutter/shell/platform/darwin/ios/framework/Source/SemanticsObject.h" +#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewResponder.h" #import "flutter/shell/platform/darwin/ios/ios_context.h" @class FlutterTouchInterceptingView; @@ -210,9 +212,9 @@ class FlutterPlatformViewsController { void SetFlutterView(UIView* flutter_view); - void SetFlutterViewController(UIViewController* flutter_view_controller); + void SetFlutterViewController(UIViewController* flutter_view_controller); - UIViewController* getFlutterViewController(); + UIViewController* getFlutterViewController(); void RegisterViewFactory( NSObject* factory, @@ -353,7 +355,7 @@ class FlutterPlatformViewsController { fml::scoped_nsobject channel_; fml::scoped_nsobject flutter_view_; - fml::scoped_nsobject flutter_view_controller_; + fml::scoped_nsobject> flutter_view_controller_; fml::scoped_nsobject mask_view_pool_; std::map>> factories_; std::map>> views_; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterView.h b/shell/platform/darwin/ios/framework/Source/FlutterView.h index 83d101dba13cb..53e3bf330be6d 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterView.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterView.h @@ -5,16 +5,11 @@ #ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERVIEW_H_ #define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERVIEW_H_ -#include +#import #import -#include - -#include "flutter/fml/memory/weak_ptr.h" -#include "flutter/shell/common/shell.h" +#include "flutter/shell/common/rasterizer.h" #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h" -#import "flutter/shell/platform/darwin/ios/ios_context.h" -#import "flutter/shell/platform/darwin/ios/ios_surface.h" @protocol FlutterViewEngineDelegate diff --git a/shell/platform/darwin/ios/framework/Source/FlutterView.mm b/shell/platform/darwin/ios/framework/Source/FlutterView.mm index 60dae326622db..1576e0cb8e2a0 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterView.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterView.mm @@ -3,19 +3,8 @@ // found in the LICENSE file. #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h" -#include -#include "flutter/common/settings.h" -#include "flutter/common/task_runners.h" -#include "flutter/flow/layers/layer_tree.h" #include "flutter/fml/platform/darwin/cf_utils.h" -#include "flutter/fml/synchronization/waitable_event.h" -#include "flutter/fml/trace_event.h" -#include "flutter/shell/common/platform_view.h" -#include "flutter/shell/common/rasterizer.h" -#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h" -#import "flutter/shell/platform/darwin/ios/ios_surface_software.h" -#include "third_party/skia/include/utils/mac/SkCGUtils.h" @implementation FlutterView { id _delegate; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h b/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h index ed99a3339b617..c1dc2f61cfe97 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h @@ -60,9 +60,6 @@ typedef void (^FlutterKeyboardAnimationCallback)(fml::TimePoint); - (fml::WeakNSObject)getWeakNSObject; - (std::shared_ptr&)platformViewsController; - (FlutterRestorationPlugin*)restorationPlugin; -// Send touches to the Flutter Engine while forcing the change type to be cancelled. -// The `phase`s in `touches` are ignored. -- (void)forceTouchesCancelled:(NSSet*)touches; // Accepts keypress events, and then calls |nextAction| if the event was not // handled. diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewResponder.h b/shell/platform/darwin/ios/framework/Source/FlutterViewResponder.h index 5cb25ca05d9f1..e1f4aafd73283 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewResponder.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewResponder.h @@ -8,16 +8,45 @@ #import NS_ASSUME_NONNULL_BEGIN + +/** + * Protocol to send touch events, typically a `FlutterViewController`. + */ @protocol FlutterViewResponder @property(nonatomic, strong) UIView* view; +/** + * See `-[UIResponder touchesBegan:withEvent:]` + */ - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event; + +/** + * See `-[UIResponder touchesMoved:withEvent:]` + */ - (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event; + +/** + * See `-[UIResponder touchesEnded:withEvent:]` + */ - (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event; + +/** + * See `-[UIResponder touchesCancelled:withEvent:]` + */ - (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event; + +/** + * See `-[UIResponder touchesEstimatedPropertiesUpdated:]` + */ - (void)touchesEstimatedPropertiesUpdated:(NSSet*)touches; +/** + * Send touches to the Flutter Engine while forcing the change type to be cancelled. + * The `phase`s in `touches` are ignored. + */ +- (void)forceTouchesCancelled:(NSSet*)touches; + @end NS_ASSUME_NONNULL_END diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm index e1c1846873fac..4a514f8e20fdd 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm @@ -4,8 +4,6 @@ #import -#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h" -#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h" #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h" FLUTTER_ASSERT_ARC diff --git a/shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm b/shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm index 7d90da63cc8df..ec823293681c8 100644 --- a/shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm +++ b/shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm @@ -5,7 +5,7 @@ #import #import -#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterBinaryMessenger.h" +#import "flutter/fml/thread.h" #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h" #import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlatformViews.h" #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h"