7#import <QuartzCore/QuartzCore.h>
9#import "flutter/shell/platform/darwin/common/InternalFlutterSwiftCommon/InternalFlutterSwiftCommon.h"
10#import "flutter/shell/platform/darwin/macos/InternalFlutterSwift/InternalFlutterSwift.h"
13@interface FlutterView () <FlutterSurfaceManagerDelegate> {
25- (instancetype)initWithMTLDevice:(
id<MTLDevice>)device
26 commandQueue:(
id<MTLCommandQueue>)commandQueue
27 delegate:(
id<FlutterViewDelegate>)delegate
29 enableWideGamut:(
BOOL)enableWideGamut {
30 self = [
super initWithFrame:NSZeroRect];
32 [
self setWantsLayer:YES];
33 [
self setBackgroundColor:[NSColor blackColor]];
34 [
self setLayerContentsRedrawPolicy:NSViewLayerContentsRedrawDuringViewResize];
35 _viewIdentifier = viewIdentifier;
36 _viewDelegate = delegate;
38 commandQueue:commandQueue
41 wideGamut:enableWideGamut];
42 _resizeSynchronizer = [[FlutterResizeSynchronizer alloc] init];
47- (void)onPresent:(CGSize)frameSize withBlock:(dispatch_block_t)block delay:(NSTimeInterval)delay {
51 NSSize scaledSize = [
self convertSizeFromBacking:frameSize];
52 [
self.sizingDelegate viewDidUpdateContents:self withSize:scaledSize];
55 [_resizeSynchronizer performCommitForSize:frameSize afterDelay:delay notify:notifyBlock];
59 return _surfaceManager;
62- (void)setEnableWideGamut:(
BOOL)enableWideGamut {
63 [_surfaceManager setEnableWideGamut:enableWideGamut];
67 [_resizeSynchronizer shutDown];
70- (void)setBackgroundColor:(NSColor*)color {
71 self.layer.backgroundColor = color.CGColor;
74#pragma mark - NSView overrides
76- (void)setFrameSize:(NSSize)newSize {
77 [
super setFrameSize:newSize];
78 if (!
self.sizedToContents) {
79 CGSize scaledSize = [
self convertSizeToBacking:self.bounds.size];
80 [_resizeSynchronizer beginResizeForSize:scaledSize
82 [_viewDelegate viewDidReshape:self];
85 [FlutterLogger logError:@"Resize timed out"];
105- (
BOOL)acceptsFirstMouse:(NSEvent*)event {
109- (
BOOL)acceptsFirstResponder {
112 return [_viewDelegate viewShouldAcceptFirstResponder:self];
115- (void)didUpdateMouseCursor:(NSCursor*)cursor {
116 _lastCursor = cursor;
125- (void)cursorUpdate:(NSEvent*)event {
127 NSPoint mouseLocation = [[
self superview] convertPoint:event.locationInWindow fromView:nil];
128 NSView* hitTestView = [
self hitTest:mouseLocation];
129 if (hitTestView !=
self) {
137 [[NSRunLoop currentRunLoop] performBlock:^{
142- (void)viewDidChangeBackingProperties {
143 [
super viewDidChangeBackingProperties];
145 [_viewDelegate viewDidReshape:self];
148- (
BOOL)layer:(CALayer*)layer
149 shouldInheritContentsScale:(CGFloat)newScale
150 fromWindow:(NSWindow*)window {
154#pragma mark - NSAccessibility overrides
156- (
BOOL)isAccessibilityElement {
160- (NSAccessibilityRole)accessibilityRole {
161 return NSAccessibilityGroupRole;
164- (NSString*)accessibilityLabel {
168 NSString* applicationName =
169 [NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleDisplayName"];
170 if (!applicationName) {
171 applicationName = [NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleName"];
173 return applicationName;
177 return _sizingDelegate != nil && [_sizingDelegate minimumViewSize:self] != std::nullopt;
181 if (_sizingDelegate != nil) {
182 std::optional<NSSize> minSize = [_sizingDelegate minimumViewSize:self];
187 return self.bounds.size;
191 if (_sizingDelegate != nil) {
192 std::optional<NSSize> maxSize = [_sizingDelegate maximumViewSize:self];
197 return self.bounds.size;
201 [_viewDelegate viewDidReshape:self];
__weak id< FlutterViewDelegate > _viewDelegate
FlutterSurfaceManager * _surfaceManager
FlutterViewIdentifier _viewIdentifier
FlutterResizeSynchronizer * _resizeSynchronizer
CGSize maximumContentSize
FlutterSurfaceManager * surfaceManager
void constraintsDidChange()
CGSize minimumContentSize