FlutterView.mm 1.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h"

@implementation FlutterView {
  __weak id<FlutterViewReshapeListener> _reshapeListener;
}

11 12 13
- (instancetype)initWithShareContext:(NSOpenGLContext*)shareContext
                     reshapeListener:(id<FlutterViewReshapeListener>)reshapeListener {
  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 22
    self.openGLContext = [[NSOpenGLContext alloc] initWithFormat:shareContext.pixelFormat
                                                    shareContext:shareContext];
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
    _reshapeListener = reshapeListener;
    self.wantsBestResolutionOpenGLSurface = YES;
  }
  return self;
}

#pragma mark - NSView overrides

/**
 * Declares that the view uses a flipped coordinate system, consistent with Flutter conventions.
 */
- (BOOL)isFlipped {
  return YES;
}

- (BOOL)isOpaque {
  return YES;
}

- (void)reshape {
  [super reshape];
  [_reshapeListener viewDidReshape:self];
}

- (BOOL)acceptsFirstResponder {
  return YES;
}

51 52 53 54 55
- (void)viewDidChangeBackingProperties {
  [super viewDidChangeBackingProperties];
  [_reshapeListener viewDidReshape:self];
}

56
@end