@@ -32,7 +32,18 @@ @interface FLEViewController ()
32
32
/* *
33
33
* A list of additional responders to keyboard events. Keybord events are forwarded to all of them.
34
34
*/
35
- @property NSMutableOrderedSet <NSResponder*>* additionalKeyResponders;
35
+ @property (nonatomic ) NSMutableOrderedSet <NSResponder*>* additionalKeyResponders;
36
+
37
+ /* *
38
+ * The tracking area used to generate hover events, if enabled.
39
+ */
40
+ @property (nonatomic ) NSTrackingArea * trackingArea;
41
+
42
+ /* *
43
+ * Updates |trackingArea| for the current tracking settings, creating it with
44
+ * the correct mode if tracking is enabled, or removing it if not.
45
+ */
46
+ - (void )configureTrackingArea ;
36
47
37
48
/* *
38
49
* Creates and registers plugins used by this view controller.
@@ -202,12 +213,28 @@ - (void)dealloc {
202
213
}
203
214
}
204
215
216
+ - (void )setView : (NSView *)view {
217
+ if (_trackingArea) {
218
+ [self .view removeTrackingArea: _trackingArea];
219
+ }
220
+ [super setView: view];
221
+ [self configureTrackingArea ];
222
+ }
223
+
205
224
- (void )loadView {
206
225
self.view = [[FLEView alloc ] init ];
207
226
}
208
227
209
228
#pragma mark - Public methods
210
229
230
+ - (void )setMouseTrackingMode : (FlutterMouseTrackingMode)mode {
231
+ if (_mouseTrackingMode == mode) {
232
+ return ;
233
+ }
234
+ _mouseTrackingMode = mode;
235
+ [self configureTrackingArea ];
236
+ }
237
+
211
238
- (BOOL )launchEngineWithAssetsPath : (NSURL *)assets
212
239
commandLineArguments : (NSArray <NSString*>*)arguments {
213
240
return [self launchEngineInternalWithAssetsPath: assets
@@ -241,6 +268,35 @@ - (void)removeKeyResponder:(NSResponder*)responder {
241
268
242
269
#pragma mark - Private methods
243
270
271
+ - (void )configureTrackingArea {
272
+ if (_mouseTrackingMode != FlutterMouseTrackingModeNone && self.view ) {
273
+ NSTrackingAreaOptions options =
274
+ NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingInVisibleRect;
275
+ switch (_mouseTrackingMode) {
276
+ case FlutterMouseTrackingModeInKeyWindow:
277
+ options |= NSTrackingActiveInKeyWindow;
278
+ break ;
279
+ case FlutterMouseTrackingModeInActiveApp:
280
+ options |= NSTrackingActiveInActiveApp;
281
+ break ;
282
+ case FlutterMouseTrackingModeAlways:
283
+ options |= NSTrackingActiveAlways;
284
+ break ;
285
+ default :
286
+ NSLog (@" Error: Unrecognized mouse tracking mode: %ld " , _mouseTrackingMode);
287
+ return ;
288
+ }
289
+ _trackingArea = [[NSTrackingArea alloc ] initWithRect: NSZeroRect
290
+ options: options
291
+ owner: self
292
+ userInfo: nil ];
293
+ [self .view addTrackingArea: _trackingArea];
294
+ } else if (_trackingArea) {
295
+ [self .view removeTrackingArea: _trackingArea];
296
+ _trackingArea = nil ;
297
+ }
298
+ }
299
+
244
300
- (void )addInternalPlugins {
245
301
_textInputPlugin = [[FLETextInputPlugin alloc ] initWithViewController: self ];
246
302
_keyEventChannel =
@@ -471,4 +527,16 @@ - (void)mouseDragged:(NSEvent*)event {
471
527
[self dispatchMouseEvent: event phase: kMove ];
472
528
}
473
529
530
+ - (void )mouseEntered : (NSEvent *)event {
531
+ [self dispatchMouseEvent: event phase: kAdd ];
532
+ }
533
+
534
+ - (void )mouseExited : (NSEvent *)event {
535
+ [self dispatchMouseEvent: event phase: kRemove ];
536
+ }
537
+
538
+ - (void )mouseMoved : (NSEvent *)event {
539
+ [self dispatchMouseEvent: event phase: kHover ];
540
+ }
541
+
474
542
@end
0 commit comments