Flutter macOS Embedder
FlutterWindowController.mm
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 
6 #include <Foundation/Foundation.h>
7 
12 
14 
15 // A delegate for a Flutter managed window.
17  : NSObject <NSWindowDelegate, FlutterViewContentDelegate, FlutterViewSizingDelegate> {
18  // Strong reference to the window. This is the only strong reference to the
19  // window.
20  NSWindow* _window;
22  std::optional<flutter::Isolate> _isolate;
24 
25  // Extra size constraints coming from the window positioner.
27 }
28 
29 @property(readonly, nonatomic) NSWindow* window;
30 @property(readonly, nonatomic) FlutterViewController* flutterViewController;
31 @property(readwrite, nonatomic) BOOL closeWhenParentResignsKey;
32 @property(readwrite, nonatomic) dispatch_block_t onFirstFrame;
33 
34 - (instancetype)initWithWindow:(NSWindow*)window
35  flutterViewController:(FlutterViewController*)viewController
36  creationRequest:(const FlutterWindowCreationRequest&)creationRequest;
37 
38 @end
39 
41 
42 - (void)flutterSetContentSize:(FlutterWindowSize)contentSize;
43 - (void)flutterSetConstraints:(FlutterWindowConstraints)constraints;
44 
45 @end
46 
47 @implementation NSWindow (FlutterWindowSizing)
48 - (void)flutterSetContentSize:(FlutterWindowSize)contentSize {
49  [self setContentSize:NSMakeSize(contentSize.width, contentSize.height)];
50 }
51 
52 - (void)flutterSetConstraints:(FlutterWindowConstraints)constraints {
53  NSSize size = [self frameRectForContentRect:self.frame].size;
54  NSSize originalSize = size;
55  [self setContentMinSize:NSMakeSize(constraints.min_width, constraints.min_height)];
56  size.width = std::max(size.width, constraints.min_width);
57  size.height = std::max(size.height, constraints.min_height);
58  if (constraints.max_width > 0 && constraints.max_height > 0) {
59  [self setContentMaxSize:NSMakeSize(constraints.max_width, constraints.max_height)];
60  size.width = std::min(size.width, constraints.max_width);
61  size.height = std::min(size.height, constraints.max_height);
62  } else {
63  [self setContentMaxSize:NSMakeSize(CGFLOAT_MAX, CGFLOAT_MAX)];
64  }
65  if (!NSEqualSizes(originalSize, size)) {
66  [self setContentSize:size];
67  }
68 }
69 
70 @end
71 
72 @interface FlutterWindowController () {
73  NSMutableArray<FlutterWindowOwner*>* _windows;
75 }
76 
77 - (void)windowDidResignKey:(FlutterWindowOwner*)window;
78 
79 @end
80 
81 @implementation FlutterWindowOwner
82 
83 @synthesize window = _window;
85 
86 - (instancetype)initWithWindow:(NSWindow*)window
87  flutterViewController:(FlutterViewController*)viewController
88  creationRequest:(const FlutterWindowCreationRequest&)creationRequest {
89  if (self = [super init]) {
90  _window = window;
91  _flutterViewController = viewController;
92  _creationRequest = creationRequest;
94  }
95  return self;
96 }
97 
98 - (void)windowDidBecomeKey:(NSNotification*)notification {
99  [_flutterViewController.engine windowDidBecomeKey:_flutterViewController.viewIdentifier];
100 }
101 
102 - (void)windowDidResignKey:(NSNotification*)notification {
103  [_flutterViewController.engine windowDidResignKey:_flutterViewController.viewIdentifier];
104  [[_flutterViewController.engine windowController] windowDidResignKey:self];
105 }
106 
107 - (BOOL)windowShouldClose:(NSWindow*)sender {
108  flutter::IsolateScope isolate_scope(*_isolate);
110  return NO;
111 }
112 
113 - (void)windowWillClose {
115 }
116 
117 - (void)windowDidResize:(NSNotification*)notification {
118  flutter::IsolateScope isolate_scope(*_isolate);
120 }
121 
122 // Miniaturize does not trigger resize event, but for now there
123 // is no other way to get notification about the state change.
124 - (void)windowDidMiniaturize:(NSNotification*)notification {
125  flutter::IsolateScope isolate_scope(*_isolate);
127 }
128 
129 // Deminiaturize does not trigger resize event, but for now there
130 // is no other way to get notification about the state change.
131 - (void)windowDidDeminiaturize:(NSNotification*)notification {
132  flutter::IsolateScope isolate_scope(*_isolate);
134 }
135 
136 - (void)windowWillEnterFullScreen:(NSNotification*)notification {
137  flutter::IsolateScope isolate_scope(*_isolate);
139 }
140 
141 - (void)windowWillExitFullScreen:(NSNotification*)notification {
142  flutter::IsolateScope isolate_scope(*_isolate);
144 }
145 
146 - (std::optional<NSSize>)minimumViewSize:(FlutterView*)view {
148  return NSMakeSize(_creationRequest.constraints.min_width,
150  } else {
151  return std::nullopt;
152  }
153 }
154 
155 - (std::optional<NSSize>)maximumViewSize:(FlutterView*)view {
157  // Window is not sized to contents.
158  return std::nullopt;
159  }
160  NSSize screenSize = self.window.screen.visibleFrame.size;
161  double width = screenSize.width;
162  width = std::min(width, _creationRequest.constraints.max_width);
163  if (_positionerSizeConstraints.width > 0) {
164  width = std::min(width, _positionerSizeConstraints.width);
165  }
166  double height = screenSize.height;
167  height = std::min(height, _creationRequest.constraints.max_height);
168  if (_positionerSizeConstraints.height > 0) {
169  height = std::min(height, _positionerSizeConstraints.height);
170  }
171  return NSMakeSize(width, height);
172 }
173 
174 // Returns the frame that includes all screen. This is used to flip coordinates
175 // of individual screen to match Flutter coordinate system.
176 static NSRect ComputeGlobalScreenFrame() {
177  NSRect frame = NSZeroRect;
178  for (NSScreen* screen in [NSScreen screens]) {
179  NSRect screenFrame = screen.frame;
180  if (NSIsEmptyRect(frame)) {
181  frame = screenFrame;
182  } else {
183  frame = NSUnionRect(frame, screenFrame);
184  }
185  }
186  return frame;
187 }
188 
189 static void FlipRect(NSRect& rect, const NSRect& globalScreenFrame) {
190  // Flip the y coordinate to match Flutter coordinate system.
191  rect.origin.y = (globalScreenFrame.origin.y + globalScreenFrame.size.height) -
192  (rect.origin.y + rect.size.height);
193 }
194 
195 - (void)updatePosition {
196  [self viewDidUpdateContents:self.flutterViewController.flutterView
197  withSize:self.flutterViewController.flutterView.bounds.size];
198 }
199 
200 - (void)viewDidUpdateContents:(FlutterView*)view withSize:(NSSize)newSize {
201  // There is no positioner associated with this window.
202  if (_creationRequest.on_get_window_position == nullptr) {
203  bool firstFrame = self.onFirstFrame != nil;
204  // Either missing initial size or always sized to content, resize the window
205  // based on content size.
206  if ((firstFrame && !_creationRequest.has_size) || !_creationRequest.resizable) {
207  [view.window setContentSize:newSize];
208  }
210  view.sizingDelegate = nil;
211  }
212  if (firstFrame) {
213  self.onFirstFrame();
214  self.onFirstFrame = nil;
215  }
216  } else {
217  NSRect globalScreenFrame = ComputeGlobalScreenFrame();
218 
219  NSRect parentRect =
220  [self.window.parentWindow contentRectForFrameRect:self.window.parentWindow.frame];
221  FlipRect(parentRect, globalScreenFrame);
222 
223  NSRect screenRect = [self.window.screen visibleFrame];
224  FlipRect(screenRect, globalScreenFrame);
225 
226  flutter::IsolateScope isolate_scope(*_isolate);
229  FlutterWindowRect::fromNSRect(screenRect));
230 
231  NSRect positionRect = position->toNSRect();
232  FlipRect(positionRect, globalScreenFrame);
233 
234  [self.window setFrame:positionRect display:NO animate:NO];
235 
236  free(position);
237 
238  // For windows sized to contents if the positioner size doesn't match actual size
239  // the requested size needs to be passed through constraints.
240  if (view.sizedToContents &&
241  (positionRect.size.width < newSize.width || positionRect.size.height < newSize.height)) {
242  // Positioner disagreed with content size, tighten the constraints and regenerate
243  // the frame.
244  _positionerSizeConstraints = positionRect.size;
245  [view constraintsDidChange];
246  return;
247  }
248 
249  if (self.onFirstFrame) {
250  self.onFirstFrame();
251  self.onFirstFrame = nil;
252  }
253  }
254 }
255 
256 - (void)setConstraints:(FlutterWindowConstraints)constraints {
257  if (_flutterViewController.flutterView.sizedToContents) {
258  self->_creationRequest.constraints = constraints;
259  [_flutterViewController.flutterView constraintsDidChange];
260  } else {
261  [self.window flutterSetConstraints:constraints];
262  }
263 }
264 
265 @end
266 
267 @interface FlutterPopupWindow : NSPanel
268 @end
269 
270 @implementation FlutterPopupWindow
271 
272 - (BOOL)canBecomeKeyWindow {
273  return NO;
274 }
275 
276 - (BOOL)acceptsFirstResponder {
277  return NO;
278 }
279 
280 - (BOOL)canBecomeMainWindow {
281  return NO;
282 }
283 
284 @end
285 
286 @interface _FlutterRunLoopModeFixWindowDelegate : NSObject <NSWindowDelegate>
287 @end
288 
290 
291 - (NSRect)windowWillUseStandardFrame:(NSWindow*)window defaultFrame:(NSRect)newFrame {
292  // Small frame difference (100px to 110px) to trigger the animation but make it fast.
293  newFrame.size.width = 110;
294  newFrame.size.height = 110;
295  return newFrame;
296 }
297 
298 @end
299 
300 @implementation FlutterWindowController
301 
302 - (instancetype)init {
303  self = [super init];
304  if (self != nil) {
305  _windows = [NSMutableArray array];
306  }
307  return self;
308 }
309 
311  if (_runLoopModeFixApplied) {
312  return;
313  }
314  // When modal sheet is presented, for the duration of the animation the run loop
315  // is running in _NSMoveTimerRunLoopMode. This prevents Flutter content from
316  // being rendered. The solution is to add _NSMoveTimerRunLoopMode to common
317  // run loop modes, but referencing it directly may be flagged as SPI usage.
318  // Instead as a workaround a very short window zoom animation is triggered, which
319  // runs in _NSMoveTimerRunLoopMode adding the mode to CFRunLoop all modes list.
320  // After that it can be queried and added to common modes.
321  NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100)
322  styleMask:NSWindowStyleMaskResizable
323  backing:NSBackingStoreNonretained
324  defer:NO];
327  window.releasedWhenClosed = NO;
328  window.delegate = delegate;
329  window.ignoresMouseEvents = YES;
330  window.alphaValue = 0;
331  [window orderFront:nil];
332  [window zoom:nil];
333  [window close];
334  NSArray* modes = (__bridge_transfer NSArray*)CFRunLoopCopyAllModes(CFRunLoopGetCurrent());
335  for (NSString* mode in modes) {
336  if ([mode hasSuffix:@"MoveTimerRunLoopMode"]) {
337  CFRunLoopAddCommonMode(CFRunLoopGetCurrent(), (__bridge CFStringRef)mode);
338  }
339  }
340  _runLoopModeFixApplied = YES;
341 }
342 
343 - (FlutterViewIdentifier)createDialogWindow:(const FlutterWindowCreationRequest*)request {
344  FlutterViewController* controller = [[FlutterViewController alloc] initWithEngine:_engine
345  nibName:nil
346  bundle:nil];
347 
348  NSWindow* window = [[NSWindow alloc] init];
349  // If this is not set there will be double free on window close when
350  // using ARC.
351  [window setReleasedWhenClosed:NO];
352 
353  window.contentViewController = controller;
354  window.styleMask = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable;
355  if (request->resizable) {
356  window.styleMask |= NSWindowStyleMaskResizable;
357  }
358 
359  window.collectionBehavior = NSWindowCollectionBehaviorFullScreenAuxiliary;
360  if (request->has_size) {
361  [window flutterSetContentSize:request->size];
362  }
363  if (request->resizable && request->has_constraints) {
364  [window flutterSetConstraints:request->constraints];
365  }
366 
367  FlutterWindowOwner* owner = [[FlutterWindowOwner alloc] initWithWindow:window
368  flutterViewController:controller
369  creationRequest:*request];
370  window.delegate = owner;
371  [_windows addObject:owner];
372 
373  if (!request->has_size) {
374  controller.flutterView.sizingDelegate = owner;
375  [controller.flutterView constraintsDidChange];
376  }
377  controller.flutterView.contentDelegate = owner;
378 
379  NSWindow* parent = nil;
380 
381  if (request->parent_view_id != 0) {
382  for (FlutterWindowOwner* owner in _windows) {
383  if (owner.flutterViewController.viewIdentifier == request->parent_view_id) {
384  parent = owner.window;
385  break;
386  }
387  }
388  if (parent == nil) {
389  FML_LOG(WARNING) << "Failed to find parent window for ID " << request->parent_view_id;
390  }
391  }
392 
393  FML_DCHECK(owner.onFirstFrame == nil);
394  owner.onFirstFrame = ^{
395  if (parent != nil) {
396  dispatch_async(dispatch_get_main_queue(), ^{
397  [self fixMoveRunLoopModeIfNeeded];
398  // beginCriticalSheet blocks with nested run loop until the
399  // sheet animation is finished.
400  [parent beginCriticalSheet:window
401  completionHandler:^(NSModalResponse response){
402  }];
403  });
404 
405  } else {
406  [window setIsVisible:YES];
407  [window makeKeyAndOrderFront:nil];
408  }
409  };
410 
411  return controller.viewIdentifier;
412 }
413 
414 - (FlutterViewIdentifier)createTooltipWindow:(const FlutterWindowCreationRequest*)request {
415  FlutterViewController* controller = [[FlutterViewController alloc] initWithEngine:_engine
416  nibName:nil
417  bundle:nil];
418 
419  NSWindow* window = [[NSWindow alloc] init];
420  // If this is not set there will be double free on window close when
421  // using ARC.
422  [window setReleasedWhenClosed:NO];
423 
424  window.contentViewController = controller;
425  window.styleMask = NSWindowStyleMaskBorderless;
426  window.hasShadow = NO;
427  window.opaque = NO;
428  window.backgroundColor = [NSColor clearColor];
429 
430  FlutterWindowOwner* owner = [[FlutterWindowOwner alloc] initWithWindow:window
431  flutterViewController:controller
432  creationRequest:*request];
433 
434  controller.flutterView.sizingDelegate = owner;
435  controller.flutterView.contentDelegate = owner;
436  controller.flutterView.backgroundColor = [NSColor clearColor];
437  // Resend configure event after setting the sizing delegate.
438  [controller.flutterView constraintsDidChange];
439  owner.closeWhenParentResignsKey = YES;
440 
441  window.delegate = owner;
442  [_windows addObject:owner];
443 
444  NSWindow* parent = nil;
445 
446  FML_DCHECK(request->parent_view_id != 0);
447  for (FlutterWindowOwner* owner in _windows) {
448  if (owner.flutterViewController.viewIdentifier == request->parent_view_id) {
449  parent = owner.window;
450  break;
451  }
452  }
453 
454  NSAssert(parent != nil, @"Tooltip window must have a parent window.");
455 
456  window.ignoresMouseEvents = YES;
457  window.collectionBehavior = NSWindowCollectionBehaviorAuxiliary;
458  [parent addChildWindow:window ordered:NSWindowAbove];
459  window.alphaValue = 0.0;
460 
461  FML_DCHECK(owner.onFirstFrame == nil);
462  owner.onFirstFrame = ^{
463  window.alphaValue = 1.0;
464  };
465 
466  return controller.viewIdentifier;
467 }
468 
469 - (FlutterViewIdentifier)createPopupWindow:(const FlutterWindowCreationRequest*)request {
470  FlutterViewController* controller = [[FlutterViewController alloc] initWithEngine:_engine
471  nibName:nil
472  bundle:nil];
473  // By default this is kFlutterMouseTrackingModeInKeyWindow but popup window is never
474  // key window.
475  controller.mouseTrackingMode = kFlutterMouseTrackingModeInActiveApp;
476 
477  NSWindow* window = [[FlutterPopupWindow alloc] init];
478  // If this is not set there will be double free on window close when
479  // using ARC.
480  [window setReleasedWhenClosed:NO];
481 
482  window.contentViewController = controller;
483  window.styleMask = NSWindowStyleMaskBorderless;
484  window.hasShadow = NO;
485  window.opaque = NO;
486  window.backgroundColor = [NSColor clearColor];
487 
488  FlutterWindowOwner* owner = [[FlutterWindowOwner alloc] initWithWindow:window
489  flutterViewController:controller
490  creationRequest:*request];
491 
492  controller.flutterView.sizingDelegate = owner;
493  controller.flutterView.contentDelegate = owner;
494  [controller.flutterView setBackgroundColor:[NSColor clearColor]];
495  // Resend configure event after setting the sizing delegate.
496  [controller.flutterView constraintsDidChange];
497  owner.closeWhenParentResignsKey = NO;
498 
499  window.delegate = owner;
500  [_windows addObject:owner];
501 
502  NSWindow* parent = nil;
503 
504  FML_DCHECK(request->parent_view_id != 0);
505  for (FlutterWindowOwner* owner in _windows) {
506  if (owner.flutterViewController.viewIdentifier == request->parent_view_id) {
507  parent = owner.window;
508  break;
509  }
510  }
511 
512  NSAssert(parent != nil, @"Popup window must have a parent window.");
513 
514  window.collectionBehavior = NSWindowCollectionBehaviorAuxiliary;
515  [parent addChildWindow:window ordered:NSWindowAbove];
516  window.alphaValue = 0.0;
517 
518  FML_DCHECK(owner.onFirstFrame == nil);
519  owner.onFirstFrame = ^{
520  window.alphaValue = 1.0;
521  };
522 
523  return controller.viewIdentifier;
524 }
525 
526 - (FlutterViewIdentifier)createRegularWindow:(const FlutterWindowCreationRequest*)request {
527  FlutterViewController* controller = [[FlutterViewController alloc] initWithEngine:_engine
528  nibName:nil
529  bundle:nil];
530 
531  NSWindow* window = [[NSWindow alloc] init];
532  // If this is not set there will be double free on window close when
533  // using ARC.
534  [window setReleasedWhenClosed:NO];
535 
536  window.styleMask =
537  NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable;
538  if (request->resizable) {
539  window.styleMask |= NSWindowStyleMaskResizable;
540  }
541 
542  window.contentViewController = controller;
543 
544  if (request->has_size) {
545  [window flutterSetContentSize:request->size];
546  }
547  if (request->resizable && request->has_constraints) {
548  [window flutterSetConstraints:request->constraints];
549  }
550 
551  FlutterWindowOwner* owner = [[FlutterWindowOwner alloc] initWithWindow:window
552  flutterViewController:controller
553  creationRequest:*request];
554 
555  controller.flutterView.contentDelegate = owner;
556 
557  if (!request->has_size) {
558  controller.flutterView.sizingDelegate = owner;
559  [controller.flutterView constraintsDidChange];
560  }
561 
562  window.delegate = owner;
563  [_windows addObject:owner];
564 
565  FML_DCHECK(owner.onFirstFrame == nil);
566  owner.onFirstFrame = ^{
567  [window setIsVisible:YES];
568  [window makeKeyAndOrderFront:nil];
569  };
570 
571  return controller.viewIdentifier;
572 }
573 
574 - (void)destroyWindow:(NSWindow*)window {
575  FlutterWindowOwner* owner = nil;
576  for (FlutterWindowOwner* o in _windows) {
577  if (o.window == window) {
578  owner = o;
579  break;
580  }
581  }
582  if (owner != nil) {
583  [_windows removeObject:owner];
584  for (NSWindow* win in owner.window.sheets) {
585  [self destroyWindow:win];
586  }
587 
588  for (NSWindow* win in owner.window.childWindows) {
589  [self destroyWindow:win];
590  }
591  // Make sure to unregister the controller from the engine and remove the FlutterView
592  // before destroying the window and Flutter NSView.
593  [owner.flutterViewController dispose];
594  owner.window.delegate = nil;
595  [owner.window close];
596  [owner windowWillClose];
597  }
598 }
599 
600 - (void)closeAllWindows {
601  for (FlutterWindowOwner* owner in _windows) {
602  [owner.flutterViewController dispose];
603  [owner.window close];
604  }
605  [_windows removeAllObjects];
606 }
607 
608 static BOOL IsChildAncestor(NSWindow* child, NSWindow* ancestor) {
609  NSWindow* current = child.parentWindow;
610  while (current) {
611  if (current == ancestor) {
612  return YES;
613  }
614  current = current.parentWindow;
615  }
616 
617  return NO;
618 }
619 
620 - (void)windowDidResignKey:(FlutterWindowOwner*)parent {
621  for (FlutterWindowOwner* possibleChild in _windows) {
622  if (possibleChild.closeWhenParentResignsKey &&
623  IsChildAncestor(possibleChild.window, parent.window)) {
624  [possibleChild windowShouldClose:possibleChild.window];
625  }
626  }
627 }
628 
629 @end
630 
631 // NOLINTBEGIN(google-objc-function-naming)
632 
634  int64_t engine_id,
635  const FlutterWindowCreationRequest* request) {
636  FlutterEngine* engine = [FlutterEngine engineForIdentifier:engine_id];
637  [engine enableMultiView];
638  return [engine.windowController createRegularWindow:request];
639 }
640 
642  int64_t engine_id,
643  const FlutterWindowCreationRequest* request) {
644  FlutterEngine* engine = [FlutterEngine engineForIdentifier:engine_id];
645  [engine enableMultiView];
646  return [engine.windowController createDialogWindow:request];
647 }
648 
650  int64_t engine_id,
651  const FlutterWindowCreationRequest* request) {
652  FlutterEngine* engine = [FlutterEngine engineForIdentifier:engine_id];
653  [engine enableMultiView];
654  return [engine.windowController createTooltipWindow:request];
655 }
656 
658  int64_t engine_id,
659  const FlutterWindowCreationRequest* request) {
660  FlutterEngine* engine = [FlutterEngine engineForIdentifier:engine_id];
661  [engine enableMultiView];
662  return [engine.windowController createPopupWindow:request];
663 }
664 
665 void InternalFlutter_Window_Destroy(int64_t engine_id, void* window) {
666  NSWindow* w = (__bridge NSWindow*)window;
667  FlutterEngine* engine = [FlutterEngine engineForIdentifier:engine_id];
668  [engine.windowController destroyWindow:w];
669 }
670 
671 void* InternalFlutter_Window_GetHandle(int64_t engine_id, FlutterViewIdentifier view_id) {
672  FlutterEngine* engine = [FlutterEngine engineForIdentifier:engine_id];
673  FlutterViewController* controller = [engine viewControllerForIdentifier:view_id];
674  return (__bridge void*)controller.view.window;
675 }
676 
678  NSWindow* w = (__bridge NSWindow*)window;
679  NSRect contentRect = [w contentRectForFrameRect:w.frame];
680  return {
681  .width = contentRect.size.width,
682  .height = contentRect.size.height,
683  };
684 }
685 
687  NSWindow* w = (__bridge NSWindow*)window;
688  [w flutterSetContentSize:*size];
689 }
690 
693  const FlutterWindowConstraints* constraints) {
694  NSWindow* w = (__bridge NSWindow*)window;
695  FlutterWindowOwner* owner = (FlutterWindowOwner*)w.delegate;
696  [owner setConstraints:*constraints];
697 }
698 
699 void InternalFlutter_Window_SetTitle(void* window, const char* title) {
700  NSWindow* w = (__bridge NSWindow*)window;
701  w.title = [NSString stringWithUTF8String:title];
702 }
703 
704 void InternalFlutter_Window_SetMaximized(void* window, bool maximized) {
705  NSWindow* w = (__bridge NSWindow*)window;
706  if (maximized & !w.isZoomed) {
707  [w zoom:nil];
708  } else if (!maximized && w.isZoomed) {
709  [w zoom:nil];
710  }
711 }
712 
714  NSWindow* w = (__bridge NSWindow*)window;
715  return w.isZoomed;
716 }
717 
719  NSWindow* w = (__bridge NSWindow*)window;
720  [w miniaturize:nil];
721 }
722 
724  NSWindow* w = (__bridge NSWindow*)window;
725  [w deminiaturize:nil];
726 }
727 
729  NSWindow* w = (__bridge NSWindow*)window;
730  return w.isMiniaturized;
731 }
732 
733 void InternalFlutter_Window_SetFullScreen(void* window, bool fullScreen) {
734  NSWindow* w = (__bridge NSWindow*)window;
735  bool isFullScreen = (w.styleMask & NSWindowStyleMaskFullScreen) != 0;
736  if (fullScreen && !isFullScreen) {
737  [w toggleFullScreen:nil];
738  } else if (!fullScreen && isFullScreen) {
739  [w toggleFullScreen:nil];
740  }
741 }
742 
744  NSWindow* w = (__bridge NSWindow*)window;
745  return (w.styleMask & NSWindowStyleMaskFullScreen) != 0;
746 }
747 
749  NSWindow* w = (__bridge NSWindow*)window;
750  [NSApplication.sharedApplication activateIgnoringOtherApps:YES];
751  [w makeKeyAndOrderFront:nil];
752 }
753 
754 char* InternalFlutter_Window_GetTitle(void* window) {
755  NSWindow* w = (__bridge NSWindow*)window;
756  return strdup(w.title.UTF8String);
757 }
758 
760  NSWindow* w = (__bridge NSWindow*)window;
761  return w.isKeyWindow;
762 }
763 
765  NSWindow* w = (__bridge NSWindow*)window;
766  FlutterWindowOwner* owner = (FlutterWindowOwner*)w.delegate;
767  [owner updatePosition];
768 }
769 
771  NSWindow* w = (__bridge NSWindow*)window;
772  NSWindow* parent = w.parentWindow;
773  if (!parent) {
774  return {0, 0};
775  }
776  NSRect globalScreenFrame = ComputeGlobalScreenFrame();
777 
778  NSRect parentRect = [parent contentRectForFrameRect:parent.frame];
779  FlipRect(parentRect, globalScreenFrame);
780 
781  NSRect childRect = w.frame;
782  FlipRect(childRect, globalScreenFrame);
783 
784  return {
785  .x = childRect.origin.x - parentRect.origin.x,
786  .y = childRect.origin.y - parentRect.origin.y,
787  };
788 }
789 
790 // NOLINTEND(google-objc-function-naming)
#define FLUTTER_DARWIN_EXPORT
Definition: FlutterMacros.h:14
int64_t FlutterViewIdentifier
void InternalFlutter_Window_Activate(void *window)
void * InternalFlutter_Window_GetHandle(int64_t engine_id, FlutterViewIdentifier view_id)
bool InternalFlutter_Window_IsMaximized(void *window)
int64_t InternalFlutter_WindowController_CreateTooltipWindow(int64_t engine_id, const FlutterWindowCreationRequest *request)
int64_t InternalFlutter_WindowController_CreatePopupWindow(int64_t engine_id, const FlutterWindowCreationRequest *request)
FLUTTER_DARWIN_EXPORT void InternalFlutter_Window_SetConstraints(void *window, const FlutterWindowConstraints *constraints)
bool InternalFlutter_Window_IsActivated(void *window)
int64_t InternalFlutter_WindowController_CreateDialogWindow(int64_t engine_id, const FlutterWindowCreationRequest *request)
FlutterWindowOffset InternalFlutter_Window_GetOffsetInParent(void *window)
int64_t InternalFlutter_WindowController_CreateRegularWindow(int64_t engine_id, const FlutterWindowCreationRequest *request)
void InternalFlutter_Window_SetFullScreen(void *window, bool fullScreen)
void InternalFlutter_Window_UpdatePosition(void *window)
bool InternalFlutter_Window_IsFullScreen(void *window)
void InternalFlutter_Window_SetContentSize(void *window, const FlutterWindowSize *size)
void InternalFlutter_Window_Minimize(void *window)
char * InternalFlutter_Window_GetTitle(void *window)
void InternalFlutter_Window_SetTitle(void *window, const char *title)
bool InternalFlutter_Window_IsMinimized(void *window)
void InternalFlutter_Window_Destroy(int64_t engine_id, void *window)
void InternalFlutter_Window_SetMaximized(void *window, bool maximized)
FlutterWindowSize InternalFlutter_Window_GetContentSize(void *window)
void InternalFlutter_Window_Unminimize(void *window)
NSMutableArray< FlutterWindowOwner * > * _windows
static Isolate Current()
Definition: isolate_scope.cc:9
FlutterMouseTrackingMode mouseTrackingMode
FlutterViewIdentifier viewIdentifier
BOOL sizedToContents
Definition: FlutterView.h:130
void constraintsDidChange()
Definition: FlutterView.mm:200
id< FlutterViewSizingDelegate > sizingDelegate
Definition: FlutterView.h:103
dispatch_block_t onFirstFrame
FlutterViewController * _flutterViewController
FlutterViewController * flutterViewController
std::optional< flutter::Isolate > _isolate
FlutterWindowCreationRequest _creationRequest
struct FlutterWindowConstraints constraints
FlutterWindowRect *(* on_get_window_position)(const FlutterWindowSize &child_size, const FlutterWindowRect &parent_rect, const FlutterWindowRect &output_rect)
static FlutterWindowRect fromNSRect(const NSRect &rect)
static FlutterWindowSize fromNSSize(const NSSize &size)