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"
25 - (instancetype)initWithMTLDevice:(
id<MTLDevice>)device
26 commandQueue:(
id<MTLCommandQueue>)commandQueue
29 self = [
super initWithFrame:NSZeroRect];
31 [
self setWantsLayer:YES];
32 [
self setBackgroundColor:[NSColor blackColor]];
33 [
self setLayerContentsRedrawPolicy:NSViewLayerContentsRedrawDuringViewResize];
34 _viewIdentifier = viewIdentifier;
35 _viewDelegate = delegate;
37 commandQueue:commandQueue
40 _resizeSynchronizer = [[FlutterResizeSynchronizer alloc] init];
45 - (void)onPresent:(CGSize)frameSize withBlock:(dispatch_block_t)block delay:(NSTimeInterval)delay {
46 [_resizeSynchronizer performCommitForSize:frameSize afterDelay:delay notify:block];
50 return _surfaceManager;
54 [_resizeSynchronizer shutDown];
57 - (void)setBackgroundColor:(NSColor*)color {
58 self.layer.backgroundColor = color.CGColor;
61 #pragma mark - NSView overrides
63 - (void)setFrameSize:(NSSize)newSize {
64 [
super setFrameSize:newSize];
65 CGSize scaledSize = [
self convertSizeToBacking:self.bounds.size];
66 [_resizeSynchronizer beginResizeForSize:scaledSize
68 [_viewDelegate viewDidReshape:self];
71 [FlutterLogger logError:@"Resize timed out"];
90 - (BOOL)acceptsFirstMouse:(NSEvent*)event {
94 - (BOOL)acceptsFirstResponder {
97 return [_viewDelegate viewShouldAcceptFirstResponder:self];
100 - (void)didUpdateMouseCursor:(NSCursor*)cursor {
101 _lastCursor = cursor;
110 - (void)cursorUpdate:(NSEvent*)event {
112 NSPoint mouseLocation = [[
self superview] convertPoint:event.locationInWindow fromView:nil];
113 NSView* hitTestView = [
self hitTest:mouseLocation];
114 if (hitTestView !=
self) {
122 [[NSRunLoop currentRunLoop] performBlock:^{
127 - (void)viewDidChangeBackingProperties {
128 [
super viewDidChangeBackingProperties];
130 [_viewDelegate viewDidReshape:self];
133 - (BOOL)layer:(CALayer*)layer
134 shouldInheritContentsScale:(CGFloat)newScale
135 fromWindow:(NSWindow*)window {
139 #pragma mark - NSAccessibility overrides
141 - (BOOL)isAccessibilityElement {
145 - (NSAccessibilityRole)accessibilityRole {
146 return NSAccessibilityGroupRole;
149 - (NSString*)accessibilityLabel {
153 NSString* applicationName =
154 [NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleDisplayName"];
155 if (!applicationName) {
156 applicationName = [NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleName"];
158 return applicationName;
int64_t FlutterViewIdentifier
__weak id< FlutterViewDelegate > _viewDelegate
FlutterSurfaceManager * _surfaceManager
FlutterViewIdentifier _viewIdentifier
FlutterResizeSynchronizer * _resizeSynchronizer
FlutterSurfaceManager * surfaceManager