Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit bc57291

Browse files
Make FLEViewController's view an internal detail (#9741)
Rather than clients needing to create an appropriate view in a XIB and attach it to an FLEViewController, which is error-prone, have FLEViewController create its own view programatically. The view is now an internal detail, so calling setView: on an FLEViewController will no longer work. As a result of the view being internal, the public API surface is simplified. This is a breaking change for macOS Runners.
1 parent 9776043 commit bc57291

File tree

13 files changed

+134
-149
lines changed

13 files changed

+134
-149
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -750,9 +750,6 @@ FILE: ../../../flutter/shell/platform/darwin/ios/platform_view_ios.mm
750750
FILE: ../../../flutter/shell/platform/darwin/macos/framework/FlutterMacOS.podspec
751751
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FLEDartProject.h
752752
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FLEEngine.h
753-
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FLEOpenGLContextHandling.h
754-
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FLEReshapeListener.h
755-
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FLEView.h
756753
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FLEViewController.h
757754
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FlutterMacOS.h
758755
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FlutterPluginMacOS.h
@@ -766,9 +763,10 @@ FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FLETextInput
766763
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FLETextInputModel.mm
767764
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FLETextInputPlugin.h
768765
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FLETextInputPlugin.mm
769-
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FLEView.mm
770766
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FLEViewController.mm
771767
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FLEViewController_Internal.h
768+
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h
769+
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterView.mm
772770
FILE: ../../../flutter/shell/platform/darwin/macos/framework/module.modulemap
773771
FILE: ../../../flutter/shell/platform/embedder/assets/EmbedderInfo.plist
774772
FILE: ../../../flutter/shell/platform/embedder/assets/embedder.modulemap

shell/platform/darwin/macos/BUILD.gn

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ _flutter_framework_headers = [
3535
"framework/Headers/FlutterPluginRegistrarMacOS.h",
3636
"framework/Headers/FLEDartProject.h",
3737
"framework/Headers/FLEEngine.h",
38-
"framework/Headers/FLEOpenGLContextHandling.h",
39-
"framework/Headers/FLEReshapeListener.h",
40-
"framework/Headers/FLEView.h",
4138
"framework/Headers/FLEViewController.h",
4239
]
4340

@@ -58,9 +55,10 @@ shared_library("create_flutter_framework_dylib") {
5855
"framework/Source/FLETextInputModel.mm",
5956
"framework/Source/FLETextInputPlugin.h",
6057
"framework/Source/FLETextInputPlugin.mm",
61-
"framework/Source/FLEView.mm",
6258
"framework/Source/FLEViewController.mm",
6359
"framework/Source/FLEViewController_Internal.h",
60+
"framework/Source/FlutterView.h",
61+
"framework/Source/FlutterView.mm",
6462
]
6563

6664
sources += _flutter_framework_headers

shell/platform/darwin/macos/framework/Headers/FLEOpenGLContextHandling.h

Lines changed: 0 additions & 25 deletions
This file was deleted.

shell/platform/darwin/macos/framework/Headers/FLEReshapeListener.h

Lines changed: 0 additions & 19 deletions
This file was deleted.

shell/platform/darwin/macos/framework/Headers/FLEView.h

Lines changed: 0 additions & 23 deletions
This file was deleted.

shell/platform/darwin/macos/framework/Headers/FLEViewController.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
#import <Cocoa/Cocoa.h>
66

77
#import "FLEEngine.h"
8-
#import "FLEOpenGLContextHandling.h"
9-
#import "FLEReshapeListener.h"
108
#import "FlutterMacros.h"
119
#import "FlutterPluginRegistrarMacOS.h"
1210

@@ -29,13 +27,7 @@ typedef NS_ENUM(NSInteger, FlutterMouseTrackingMode) {
2927
* Flutter engine in non-interactive mode, or with a drawable Flutter canvas.
3028
*/
3129
FLUTTER_EXPORT
32-
@interface FLEViewController : NSViewController <FlutterPluginRegistry, FLEReshapeListener>
33-
34-
/**
35-
* The view this controller manages. Must be capable of handling text input events, and the OpenGL
36-
* context handling protocols.
37-
*/
38-
@property(nullable) NSView<FLEOpenGLContextHandling>* view;
30+
@interface FLEViewController : NSViewController <FlutterPluginRegistry>
3931

4032
/**
4133
* The Flutter engine associated with this view controller.

shell/platform/darwin/macos/framework/Headers/FlutterMacOS.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
#import "FLEDartProject.h"
66
#import "FLEEngine.h"
7-
#import "FLEOpenGLContextHandling.h"
8-
#import "FLEReshapeListener.h"
9-
#import "FLEView.h"
107
#import "FLEViewController.h"
118
#import "FlutterBinaryMessenger.h"
129
#import "FlutterChannels.h"

shell/platform/darwin/macos/framework/Source/FLEEngine.mm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,31 +210,31 @@ - (void)sendPointerEvent:(const FlutterPointerEvent&)event {
210210
#pragma mark - Private methods
211211

212212
- (bool)engineCallbackOnMakeCurrent {
213-
if (!_viewController.view) {
213+
if (!_viewController.flutterView) {
214214
return false;
215215
}
216-
[_viewController.view makeCurrentContext];
216+
[_viewController.flutterView makeCurrentContext];
217217
return true;
218218
}
219219

220220
- (bool)engineCallbackOnClearCurrent {
221-
if (!_viewController.view) {
221+
if (!_viewController.flutterView) {
222222
return false;
223223
}
224224
[NSOpenGLContext clearCurrentContext];
225225
return true;
226226
}
227227

228228
- (bool)engineCallbackOnPresent {
229-
if (!_viewController.view) {
229+
if (!_viewController.flutterView) {
230230
return false;
231231
}
232-
[_viewController.view onPresent];
232+
[_viewController.flutterView onPresent];
233233
return true;
234234
}
235235

236236
- (bool)engineCallbackOnMakeResourceCurrent {
237-
if (!_viewController.view) {
237+
if (!_viewController.flutterView) {
238238
return false;
239239
}
240240
[_viewController makeResourceContextCurrent];

shell/platform/darwin/macos/framework/Source/FLEView.mm

Lines changed: 0 additions & 43 deletions
This file was deleted.

shell/platform/darwin/macos/framework/Source/FLEViewController.mm

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h"
99
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterCodecs.h"
1010
#import "flutter/shell/platform/darwin/macos/framework/Headers/FLEEngine.h"
11-
#import "flutter/shell/platform/darwin/macos/framework/Headers/FLEReshapeListener.h"
12-
#import "flutter/shell/platform/darwin/macos/framework/Headers/FLEView.h"
1311
#import "flutter/shell/platform/darwin/macos/framework/Source/FLEEngine_Internal.h"
1412
#import "flutter/shell/platform/darwin/macos/framework/Source/FLETextInputPlugin.h"
13+
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h"
1514
#import "flutter/shell/platform/embedder/embedder.h"
1615

1716
namespace {
@@ -68,7 +67,7 @@ void Reset() {
6867
/**
6968
* Private interface declaration for FLEViewController.
7069
*/
71-
@interface FLEViewController ()
70+
@interface FLEViewController () <FlutterViewReshapeListener>
7271

7372
/**
7473
* A list of additional responders to keyboard events. Keybord events are forwarded to all of them.
@@ -195,16 +194,13 @@ - (instancetype)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBun
195194
return self;
196195
}
197196

198-
- (void)setView:(NSView*)view {
199-
if (_trackingArea) {
200-
[self.view removeTrackingArea:_trackingArea];
201-
}
202-
[super setView:view];
203-
[self configureTrackingArea];
197+
- (void)loadView {
198+
FlutterView* flutterView = [[FlutterView alloc] initWithReshapeListener:self];
199+
self.view = flutterView;
204200
}
205201

206-
- (void)loadView {
207-
self.view = [[FLEView alloc] init];
202+
- (void)viewDidLoad {
203+
[self configureTrackingArea];
208204
}
209205

210206
#pragma mark - Public methods
@@ -238,6 +234,10 @@ - (BOOL)launchEngineWithProject:(nullable FLEDartProject*)project {
238234

239235
#pragma mark - Framework-internal methods
240236

237+
- (FlutterView*)flutterView {
238+
return static_cast<FlutterView*>(self.view);
239+
}
240+
241241
- (void)addKeyResponder:(NSResponder*)responder {
242242
[self.additionalKeyResponders addObject:responder];
243243
}
@@ -449,12 +449,12 @@ - (void)setClipboardData:(NSDictionary*)data {
449449
}
450450
}
451451

452-
#pragma mark - FLEReshapeListener
452+
#pragma mark - FlutterViewReshapeListener
453453

454454
/**
455455
* Responds to view reshape by notifying the engine of the change in dimensions.
456456
*/
457-
- (void)viewDidReshape:(NSOpenGLView*)view {
457+
- (void)viewDidReshape:(NSView*)view {
458458
CGSize scaledSize = [view convertRectToBacking:view.bounds].size;
459459
double pixelRatio = view.bounds.size.width == 0 ? 1 : scaledSize.width / view.bounds.size.width;
460460
[_engine updateWindowMetricsWithSize:scaledSize pixelRatio:pixelRatio];

0 commit comments

Comments
 (0)