summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/views/apps/app_window_native_widget_mac.mm
blob: ca79001e83c89887f725db972a7a2b6eca14f024 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/views/apps/app_window_native_widget_mac.h"

#import <Cocoa/Cocoa.h>

#import "chrome/browser/ui/cocoa/apps/titlebar_background_view.h"
#import "chrome/browser/ui/views/frame/native_widget_mac_frameless_nswindow.h"
#include "extensions/browser/app_window/native_app_window.h"
#import "ui/base/cocoa/window_size_constants.h"

AppWindowNativeWidgetMac::AppWindowNativeWidgetMac(
    views::Widget* widget,
    extensions::NativeAppWindow* native_app_window)
    : NativeWidgetMac(widget), native_app_window_(native_app_window) {
}

AppWindowNativeWidgetMac::~AppWindowNativeWidgetMac() {
}

NativeWidgetMacNSWindow* AppWindowNativeWidgetMac::CreateNSWindow(
    const views::Widget::InitParams& params) {
  // If the window has a native or colored frame, use the same NSWindow as
  // NativeWidgetMac.
  if (!native_app_window_->IsFrameless()) {
    NativeWidgetMacNSWindow* ns_window =
        NativeWidgetMac::CreateNSWindow(params);
    if (native_app_window_->HasFrameColor()) {
      [TitlebarBackgroundView
          addToNSWindow:ns_window
            activeColor:native_app_window_->ActiveFrameColor()
          inactiveColor:native_app_window_->InactiveFrameColor()];
    }
    return ns_window;
  }

  // NSTexturedBackgroundWindowMask is needed to implement draggable window
  // regions.
  NSUInteger style_mask = NSTexturedBackgroundWindowMask | NSTitledWindowMask |
                          NSClosableWindowMask | NSMiniaturizableWindowMask |
                          NSResizableWindowMask;
  return [[[NativeWidgetMacFramelessNSWindow alloc]
      initWithContentRect:ui::kWindowSizeDeterminedLater
                styleMask:style_mask
                  backing:NSBackingStoreBuffered
                    defer:NO] autorelease];
}