Flutter macOS Embedder
FlutterView.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_FLUTTERVIEW_H_
6 #define FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_FLUTTERVIEW_H_
7 
8 #import <Cocoa/Cocoa.h>
9 
12 
13 #include <stdint.h>
14 #include <optional>
15 
16 @class FlutterView;
17 
18 /**
19  * Interface that facilitates process of sizing the FlutterView to its
20  * content. It is used to determine the content constraints and to notify
21  * the view container about the size change so that the parent view can
22  * be resized (and repositioned) accordingly.
23  */
24 @protocol FlutterViewSizingDelegate <NSObject>
25 
26 /**
27  * When view should be sized to content, this method should return the minimum
28  * logical size of the view.
29  * For views that are not sized to content, will return std::nullopt;
30  */
31 - (std::optional<NSSize>)minimumViewSize:(nonnull FlutterView*)view;
32 
33 /**
34  * When view should be sized to content, this method should return the maximum
35  * logical size of the view.
36  * For views that are not sized to content, this method should return std::nullopt.
37  */
38 - (std::optional<NSSize>)maximumViewSize:(nonnull FlutterView*)view;
39 
40 /**
41  * Called when the view's size changes. The container should update its
42  * layout to accommodate the new size.
43  */
44 - (void)viewDidUpdateContents:(nonnull FlutterView*)view withSize:(NSSize)newSize;
45 
46 @end
47 
48 /**
49  * Delegate for FlutterView.
50  */
51 @protocol FlutterViewDelegate <NSObject>
52 /**
53  * Called when the view's backing store changes size.
54  */
55 - (void)viewDidReshape:(nonnull NSView*)view;
56 
57 /**
58  * Called to determine whether the view should accept first responder status.
59  */
60 - (BOOL)viewShouldAcceptFirstResponder:(nonnull NSView*)view;
61 
62 @end
63 
64 /**
65  * View capable of acting as a rendering target and input source for the Flutter
66  * engine.
67  */
68 @interface FlutterView : NSView
69 
70 /**
71  * Initialize a FlutterView that will be rendered to using Metal rendering apis.
72  */
73 - (nullable instancetype)initWithMTLDevice:(nonnull id<MTLDevice>)device
74  commandQueue:(nonnull id<MTLCommandQueue>)commandQueue
75  delegate:(nonnull id<FlutterViewDelegate>)delegate
76  viewIdentifier:(FlutterViewIdentifier)viewIdentifier
77  enableWideGamut:(BOOL)enableWideGamut NS_DESIGNATED_INITIALIZER;
78 
79 - (nullable instancetype)initWithFrame:(NSRect)frameRect
80  pixelFormat:(nullable NSOpenGLPixelFormat*)format NS_UNAVAILABLE;
81 - (nonnull instancetype)initWithFrame:(NSRect)frameRect NS_UNAVAILABLE;
82 - (nullable instancetype)initWithCoder:(nonnull NSCoder*)coder NS_UNAVAILABLE;
83 - (nonnull instancetype)init NS_UNAVAILABLE;
84 
85 /**
86  * Returns SurfaceManager for this view. SurfaceManager is responsible for
87  * providing and presenting render surfaces.
88  */
89 @property(readonly, nonatomic, nonnull) FlutterSurfaceManager* surfaceManager;
90 
91 /**
92  * Optional sizing delegate. If set, the view can be sized to its content.
93  */
94 @property(readwrite, nonatomic, weak, nullable) id<FlutterViewSizingDelegate> sizingDelegate;
95 
96 /**
97  * By default, the `FlutterSurfaceManager` creates two layers to manage Flutter
98  * content, the content layer and containing layer. To set the native background
99  * color, onto which the Flutter content is drawn, call this method with the
100  * NSColor which you would like to override the default, black background color
101  * with.
102  */
103 - (void)setBackgroundColor:(nonnull NSColor*)color;
104 
105 /**
106  * Called from the engine to notify the view that mouse cursor was updated while
107  * the mouse is over the view. The view is responsible from restoring the cursor
108  * when the mouse enters the view from another subview.
109  */
110 - (void)didUpdateMouseCursor:(nonnull NSCursor*)cursor;
111 
112 /**
113  * Called from the controller to unblock resize synchronizer when shutting down.
114  */
115 - (void)shutDown;
116 
117 /**
118  * Whether this view is sized to contents. If so, resize synchronization
119  * will be disabled.
120  */
121 @property(nonatomic, readonly) BOOL sizedToContents;
122 
123 /**
124  * When sized to contents, this property returns the minimum content size.
125  * If not sized to contents, this property returns NSZeroSize.
126  */
127 @property(nonatomic, readonly) CGSize minimumContentSize;
128 
129 /**
130  * When sized to contents, this property returns the maximum content size.
131  * If not sized to contents, this property returns NSZeroSize.
132  */
133 @property(nonatomic, readonly) CGSize maximumContentSize;
134 
135 /**
136  * Informs the view that layout constraints have changed. The view should
137  * send reconfigure event to the engine so that new content matches the constraints.
138  */
139 - (void)constraintsDidChange;
140 
141 @end
142 
143 #endif // FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_FLUTTERVIEW_H_
int64_t FlutterViewIdentifier
CGSize maximumContentSize
Definition: FlutterView.h:133
void shutDown()
Definition: FlutterView.mm:66
BOOL sizedToContents
Definition: FlutterView.h:121
FlutterSurfaceManager * surfaceManager
Definition: FlutterView.h:89
void constraintsDidChange()
Definition: FlutterView.mm:200
nonnull instancetype NS_UNAVAILABLE()
CGSize minimumContentSize
Definition: FlutterView.h:127
id< FlutterViewSizingDelegate > sizingDelegate
Definition: FlutterView.h:94