1 // Copyright 2015 The Chromium 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.
5 #import "ui/gfx/mac/nswindow_frame_controls.h"
7 #import "base/mac/mac_util.h"
8 #import "base/mac/sdk_forward_declarations.h"
9 #include "ui/gfx/geometry/size.h"
13 // The value used to represent an unbounded width or height.
14 const int kUnboundedSize = 0;
16 void SetResizableStyleMask(NSWindow* window, bool resizable) {
17 NSUInteger style_mask = [window styleMask];
19 style_mask |= NSResizableWindowMask;
21 style_mask &= ~NSResizableWindowMask;
22 [window setStyleMask:style_mask];
29 void SetNSWindowCanFullscreen(NSWindow* window, bool allow_fullscreen) {
30 NSWindowCollectionBehavior behavior = [window collectionBehavior];
32 behavior |= NSWindowCollectionBehaviorFullScreenPrimary;
34 behavior &= ~NSWindowCollectionBehaviorFullScreenPrimary;
35 [window setCollectionBehavior:behavior];
38 void ApplyNSWindowSizeConstraints(NSWindow* window,
39 const gfx::Size& min_size,
40 const gfx::Size& max_size,
42 bool can_fullscreen) {
43 [window setContentMinSize:NSMakeSize(min_size.width(), min_size.height())];
46 max_size.width() == kUnboundedSize ? CGFLOAT_MAX : max_size.width();
48 max_size.height() == kUnboundedSize ? CGFLOAT_MAX : max_size.height();
49 [window setContentMaxSize:NSMakeSize(max_width, max_height)];
51 SetResizableStyleMask(window, can_resize);
52 [window setShowsResizeIndicator:can_resize];
54 // Set the window to participate in Lion Fullscreen mode. Setting this flag
55 // has no effect on Snow Leopard or earlier. UI controls for fullscreen are
56 // only shown for windows that have unbounded size.
57 if (base::mac::IsOSLionOrLater())
58 SetNSWindowCanFullscreen(window, can_fullscreen);
60 [[window standardWindowButton:NSWindowZoomButton] setEnabled:can_fullscreen];