Flutter Engine
FlutterView.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 
5 #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h"
6 
7 @implementation FlutterView {
8  __weak id<FlutterViewReshapeListener> _reshapeListener;
9 }
10 
11 - (instancetype)initWithShareContext:(NSOpenGLContext*)shareContext
12  reshapeListener:(id<FlutterViewReshapeListener>)reshapeListener {
13  return [self initWithFrame:NSZeroRect shareContext:shareContext reshapeListener:reshapeListener];
14 }
15 
16 - (instancetype)initWithFrame:(NSRect)frame
17  shareContext:(NSOpenGLContext*)shareContext
18  reshapeListener:(id<FlutterViewReshapeListener>)reshapeListener {
19  self = [super initWithFrame:frame];
20  if (self) {
21  self.openGLContext = [[NSOpenGLContext alloc] initWithFormat:shareContext.pixelFormat
22  shareContext:shareContext];
23  _reshapeListener = reshapeListener;
24  self.wantsBestResolutionOpenGLSurface = YES;
25  }
26  return self;
27 }
28 
29 #pragma mark - NSView overrides
30 
31 /**
32  * Declares that the view uses a flipped coordinate system, consistent with Flutter conventions.
33  */
34 - (BOOL)isFlipped {
35  return YES;
36 }
37 
38 - (BOOL)isOpaque {
39  return YES;
40 }
41 
42 - (void)reshape {
43  [super reshape];
44  [_reshapeListener viewDidReshape:self];
45 }
46 
47 - (BOOL)acceptsFirstResponder {
48  return YES;
49 }
50 
51 - (void)viewDidChangeBackingProperties {
52  [super viewDidChangeBackingProperties];
53  [_reshapeListener viewDidReshape:self];
54 }
55 
56 @end