mirror of
https://github.com/encounter/engine.git
synced 2026-07-10 03:18:43 -07:00
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.
This commit is contained in:
@@ -750,9 +750,6 @@ FILE: ../../../flutter/shell/platform/darwin/ios/platform_view_ios.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/FlutterMacOS.podspec
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FLEDartProject.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FLEEngine.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FLEOpenGLContextHandling.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FLEReshapeListener.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FLEView.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FLEViewController.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FlutterMacOS.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FlutterPluginMacOS.h
|
||||
@@ -766,9 +763,10 @@ FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FLETextInput
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FLETextInputModel.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FLETextInputPlugin.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FLETextInputPlugin.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FLEView.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FLEViewController.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FLEViewController_Internal.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterView.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/module.modulemap
|
||||
FILE: ../../../flutter/shell/platform/embedder/assets/EmbedderInfo.plist
|
||||
FILE: ../../../flutter/shell/platform/embedder/assets/embedder.modulemap
|
||||
|
||||
@@ -35,9 +35,6 @@ _flutter_framework_headers = [
|
||||
"framework/Headers/FlutterPluginRegistrarMacOS.h",
|
||||
"framework/Headers/FLEDartProject.h",
|
||||
"framework/Headers/FLEEngine.h",
|
||||
"framework/Headers/FLEOpenGLContextHandling.h",
|
||||
"framework/Headers/FLEReshapeListener.h",
|
||||
"framework/Headers/FLEView.h",
|
||||
"framework/Headers/FLEViewController.h",
|
||||
]
|
||||
|
||||
@@ -58,9 +55,10 @@ shared_library("create_flutter_framework_dylib") {
|
||||
"framework/Source/FLETextInputModel.mm",
|
||||
"framework/Source/FLETextInputPlugin.h",
|
||||
"framework/Source/FLETextInputPlugin.mm",
|
||||
"framework/Source/FLEView.mm",
|
||||
"framework/Source/FLEViewController.mm",
|
||||
"framework/Source/FLEViewController_Internal.h",
|
||||
"framework/Source/FlutterView.h",
|
||||
"framework/Source/FlutterView.mm",
|
||||
]
|
||||
|
||||
sources += _flutter_framework_headers
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#import "FlutterMacros.h"
|
||||
|
||||
/**
|
||||
* Protocol for views owned by FLEViewController to handle context changes, specifically relating to
|
||||
* OpenGL context changes.
|
||||
*/
|
||||
FLUTTER_EXPORT
|
||||
@protocol FLEOpenGLContextHandling
|
||||
|
||||
/**
|
||||
* Sets the receiver as the current context object.
|
||||
*/
|
||||
- (void)makeCurrentContext;
|
||||
|
||||
/**
|
||||
* Called when the display is updated. In an NSOpenGLView this is best handled via a flushBuffer
|
||||
* call.
|
||||
*/
|
||||
- (void)onPresent;
|
||||
|
||||
@end
|
||||
@@ -1,19 +0,0 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#import "FlutterMacros.h"
|
||||
|
||||
/**
|
||||
* Protocol for listening to reshape events on this FlutterView.
|
||||
* Used to notify the underlying Flutter engine of the new screen dimensions.
|
||||
* Reflected from [NSOpenGLView.reshape].
|
||||
*/
|
||||
FLUTTER_EXPORT
|
||||
@protocol FLEReshapeListener
|
||||
|
||||
- (void)viewDidReshape:(nonnull NSOpenGLView*)view;
|
||||
|
||||
@end
|
||||
@@ -1,23 +0,0 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#import "FLEOpenGLContextHandling.h"
|
||||
#import "FLEReshapeListener.h"
|
||||
#import "FlutterMacros.h"
|
||||
|
||||
/**
|
||||
* View capable of acting as a rendering target and input source for the Flutter
|
||||
* engine.
|
||||
*/
|
||||
FLUTTER_EXPORT
|
||||
@interface FLEView : NSOpenGLView <FLEOpenGLContextHandling>
|
||||
|
||||
/**
|
||||
* Listener for reshape events. See protocol description.
|
||||
*/
|
||||
@property(nonatomic, weak, nullable) IBOutlet id<FLEReshapeListener> reshapeListener;
|
||||
|
||||
@end
|
||||
@@ -5,8 +5,6 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#import "FLEEngine.h"
|
||||
#import "FLEOpenGLContextHandling.h"
|
||||
#import "FLEReshapeListener.h"
|
||||
#import "FlutterMacros.h"
|
||||
#import "FlutterPluginRegistrarMacOS.h"
|
||||
|
||||
@@ -29,13 +27,7 @@ typedef NS_ENUM(NSInteger, FlutterMouseTrackingMode) {
|
||||
* Flutter engine in non-interactive mode, or with a drawable Flutter canvas.
|
||||
*/
|
||||
FLUTTER_EXPORT
|
||||
@interface FLEViewController : NSViewController <FlutterPluginRegistry, FLEReshapeListener>
|
||||
|
||||
/**
|
||||
* The view this controller manages. Must be capable of handling text input events, and the OpenGL
|
||||
* context handling protocols.
|
||||
*/
|
||||
@property(nullable) NSView<FLEOpenGLContextHandling>* view;
|
||||
@interface FLEViewController : NSViewController <FlutterPluginRegistry>
|
||||
|
||||
/**
|
||||
* The Flutter engine associated with this view controller.
|
||||
|
||||
@@ -4,9 +4,6 @@
|
||||
|
||||
#import "FLEDartProject.h"
|
||||
#import "FLEEngine.h"
|
||||
#import "FLEOpenGLContextHandling.h"
|
||||
#import "FLEReshapeListener.h"
|
||||
#import "FLEView.h"
|
||||
#import "FLEViewController.h"
|
||||
#import "FlutterBinaryMessenger.h"
|
||||
#import "FlutterChannels.h"
|
||||
|
||||
@@ -210,15 +210,15 @@ static void OnPlatformMessage(const FlutterPlatformMessage* message, FLEEngine*
|
||||
#pragma mark - Private methods
|
||||
|
||||
- (bool)engineCallbackOnMakeCurrent {
|
||||
if (!_viewController.view) {
|
||||
if (!_viewController.flutterView) {
|
||||
return false;
|
||||
}
|
||||
[_viewController.view makeCurrentContext];
|
||||
[_viewController.flutterView makeCurrentContext];
|
||||
return true;
|
||||
}
|
||||
|
||||
- (bool)engineCallbackOnClearCurrent {
|
||||
if (!_viewController.view) {
|
||||
if (!_viewController.flutterView) {
|
||||
return false;
|
||||
}
|
||||
[NSOpenGLContext clearCurrentContext];
|
||||
@@ -226,15 +226,15 @@ static void OnPlatformMessage(const FlutterPlatformMessage* message, FLEEngine*
|
||||
}
|
||||
|
||||
- (bool)engineCallbackOnPresent {
|
||||
if (!_viewController.view) {
|
||||
if (!_viewController.flutterView) {
|
||||
return false;
|
||||
}
|
||||
[_viewController.view onPresent];
|
||||
[_viewController.flutterView onPresent];
|
||||
return true;
|
||||
}
|
||||
|
||||
- (bool)engineCallbackOnMakeResourceCurrent {
|
||||
if (!_viewController.view) {
|
||||
if (!_viewController.flutterView) {
|
||||
return false;
|
||||
}
|
||||
[_viewController makeResourceContextCurrent];
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Headers/FLEView.h"
|
||||
|
||||
@implementation FLEView
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark FLEContextHandlingProtocol
|
||||
|
||||
- (void)makeCurrentContext {
|
||||
[self.openGLContext makeCurrentContext];
|
||||
}
|
||||
|
||||
- (void)onPresent {
|
||||
[self.openGLContext flushBuffer];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Implementation
|
||||
|
||||
/**
|
||||
* Declares that the view uses a flipped coordinate system, consistent with Flutter conventions.
|
||||
*/
|
||||
- (BOOL)isFlipped {
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)isOpaque {
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)reshape {
|
||||
[super reshape];
|
||||
[_reshapeListener viewDidReshape:self];
|
||||
}
|
||||
|
||||
- (BOOL)acceptsFirstResponder {
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -8,10 +8,9 @@
|
||||
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h"
|
||||
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterCodecs.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Headers/FLEEngine.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Headers/FLEReshapeListener.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Headers/FLEView.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FLEEngine_Internal.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FLETextInputPlugin.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h"
|
||||
#import "flutter/shell/platform/embedder/embedder.h"
|
||||
|
||||
namespace {
|
||||
@@ -68,7 +67,7 @@ struct MouseState {
|
||||
/**
|
||||
* Private interface declaration for FLEViewController.
|
||||
*/
|
||||
@interface FLEViewController ()
|
||||
@interface FLEViewController () <FlutterViewReshapeListener>
|
||||
|
||||
/**
|
||||
* A list of additional responders to keyboard events. Keybord events are forwarded to all of them.
|
||||
@@ -195,16 +194,13 @@ static void CommonInit(FLEViewController* controller) {
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setView:(NSView*)view {
|
||||
if (_trackingArea) {
|
||||
[self.view removeTrackingArea:_trackingArea];
|
||||
}
|
||||
[super setView:view];
|
||||
[self configureTrackingArea];
|
||||
- (void)loadView {
|
||||
FlutterView* flutterView = [[FlutterView alloc] initWithReshapeListener:self];
|
||||
self.view = flutterView;
|
||||
}
|
||||
|
||||
- (void)loadView {
|
||||
self.view = [[FLEView alloc] init];
|
||||
- (void)viewDidLoad {
|
||||
[self configureTrackingArea];
|
||||
}
|
||||
|
||||
#pragma mark - Public methods
|
||||
@@ -238,6 +234,10 @@ static void CommonInit(FLEViewController* controller) {
|
||||
|
||||
#pragma mark - Framework-internal methods
|
||||
|
||||
- (FlutterView*)flutterView {
|
||||
return static_cast<FlutterView*>(self.view);
|
||||
}
|
||||
|
||||
- (void)addKeyResponder:(NSResponder*)responder {
|
||||
[self.additionalKeyResponders addObject:responder];
|
||||
}
|
||||
@@ -449,12 +449,12 @@ static void CommonInit(FLEViewController* controller) {
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - FLEReshapeListener
|
||||
#pragma mark - FlutterViewReshapeListener
|
||||
|
||||
/**
|
||||
* Responds to view reshape by notifying the engine of the change in dimensions.
|
||||
*/
|
||||
- (void)viewDidReshape:(NSOpenGLView*)view {
|
||||
- (void)viewDidReshape:(NSView*)view {
|
||||
CGSize scaledSize = [view convertRectToBacking:view.bounds].size;
|
||||
double pixelRatio = view.bounds.size.width == 0 ? 1 : scaledSize.width / view.bounds.size.width;
|
||||
[_engine updateWindowMetricsWithSize:scaledSize pixelRatio:pixelRatio];
|
||||
|
||||
@@ -4,8 +4,13 @@
|
||||
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Headers/FLEViewController.h"
|
||||
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h"
|
||||
|
||||
@interface FLEViewController ()
|
||||
|
||||
// The FlutterView for this view controller.
|
||||
@property(nonatomic, readonly, nullable) FlutterView* flutterView;
|
||||
|
||||
/**
|
||||
* Adds a responder for keyboard events. Key up and key down events are forwarded to all added
|
||||
* responders.
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
/**
|
||||
* Listener for view resizing.
|
||||
*/
|
||||
@protocol FlutterViewReshapeListener <NSObject>
|
||||
/**
|
||||
* Called when the view's backing store changes size.
|
||||
*/
|
||||
- (void)viewDidReshape:(nonnull NSView*)view;
|
||||
@end
|
||||
|
||||
/**
|
||||
* View capable of acting as a rendering target and input source for the Flutter
|
||||
* engine.
|
||||
*/
|
||||
@interface FlutterView : NSOpenGLView
|
||||
|
||||
- (nullable instancetype)initWithFrame:(NSRect)frame
|
||||
reshapeListener:(nonnull id<FlutterViewReshapeListener>)reshapeListener
|
||||
NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
- (nullable instancetype)initWithReshapeListener:
|
||||
(nonnull id<FlutterViewReshapeListener>)reshapeListener;
|
||||
|
||||
- (nullable instancetype)initWithFrame:(NSRect)frameRect
|
||||
pixelFormat:(nullable NSOpenGLPixelFormat*)format NS_UNAVAILABLE;
|
||||
- (nonnull instancetype)initWithFrame:(NSRect)frameRect NS_UNAVAILABLE;
|
||||
- (nullable instancetype)initWithCoder:(nonnull NSCoder*)coder NS_UNAVAILABLE;
|
||||
- (nonnull instancetype)init NS_UNAVAILABLE;
|
||||
|
||||
/**
|
||||
* Sets this view as the current context object for OpenGL drawing.
|
||||
*/
|
||||
- (void)makeCurrentContext;
|
||||
|
||||
/**
|
||||
* Called when the OpenGL display should be updated.
|
||||
*/
|
||||
- (void)onPresent;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,59 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h"
|
||||
|
||||
@implementation FlutterView {
|
||||
__weak id<FlutterViewReshapeListener> _reshapeListener;
|
||||
}
|
||||
|
||||
- (instancetype)initWithReshapeListener:(id<FlutterViewReshapeListener>)reshapeListener {
|
||||
return [self initWithFrame:NSZeroRect reshapeListener:reshapeListener];
|
||||
}
|
||||
|
||||
- (instancetype)initWithFrame:(NSRect)frame
|
||||
reshapeListener:(id<FlutterViewReshapeListener>)reshapeListener {
|
||||
NSOpenGLPixelFormatAttribute attributes[] = {
|
||||
NSOpenGLPFAColorSize, 24, NSOpenGLPFAAlphaSize, 8, NSOpenGLPFADoubleBuffer, 0,
|
||||
};
|
||||
NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
|
||||
self = [super initWithFrame:frame pixelFormat:pixelFormat];
|
||||
if (self) {
|
||||
_reshapeListener = reshapeListener;
|
||||
self.wantsBestResolutionOpenGLSurface = YES;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)makeCurrentContext {
|
||||
[self.openGLContext makeCurrentContext];
|
||||
}
|
||||
|
||||
- (void)onPresent {
|
||||
[self.openGLContext flushBuffer];
|
||||
}
|
||||
|
||||
#pragma mark - NSView overrides
|
||||
|
||||
/**
|
||||
* Declares that the view uses a flipped coordinate system, consistent with Flutter conventions.
|
||||
*/
|
||||
- (BOOL)isFlipped {
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)isOpaque {
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)reshape {
|
||||
[super reshape];
|
||||
[_reshapeListener viewDidReshape:self];
|
||||
}
|
||||
|
||||
- (BOOL)acceptsFirstResponder {
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user