OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #import "ui/gfx/mac/nswindow_frame_controls.h" | |
6 | |
7 #import "base/mac/mac_util.h" | |
8 #import "base/mac/sdk_forward_declarations.h" | |
9 #include "ui/gfx/geometry/size.h" | |
10 | |
11 namespace { | |
12 | |
13 // The value used to represent an unbounded width or height. | |
14 const int kUnboundedSize = 0; | |
15 | |
16 void SetResizableStyleMask(NSWindow* window, bool resizable) { | |
17 NSUInteger style_mask = [window styleMask]; | |
18 if (resizable) | |
19 style_mask |= NSResizableWindowMask; | |
20 else | |
21 style_mask &= ~NSResizableWindowMask; | |
22 [window setStyleMask:style_mask]; | |
23 } | |
24 | |
25 } // namespace | |
26 | |
27 namespace gfx { | |
28 | |
29 void SetNSWindowCanFullscreen(NSWindow* window, bool allow_fullscreen) { | |
30 NSWindowCollectionBehavior behavior = [window collectionBehavior]; | |
31 if (allow_fullscreen) | |
32 behavior |= NSWindowCollectionBehaviorFullScreenPrimary; | |
33 else | |
34 behavior &= ~NSWindowCollectionBehaviorFullScreenPrimary; | |
35 [window setCollectionBehavior:behavior]; | |
36 } | |
37 | |
38 void ApplyNSWindowSizeConstraints(NSWindow* window, | |
39 const gfx::Size& min_size, | |
40 const gfx::Size& max_size, | |
41 bool can_resize, | |
42 bool can_fullscreen) { | |
43 [window setContentMinSize:NSMakeSize(min_size.width(), min_size.height())]; | |
44 | |
45 CGFloat max_width = | |
46 max_size.width() == kUnboundedSize ? CGFLOAT_MAX : max_size.width(); | |
47 CGFloat max_height = | |
48 max_size.height() == kUnboundedSize ? CGFLOAT_MAX : max_size.height(); | |
49 [window setContentMaxSize:NSMakeSize(max_width, max_height)]; | |
50 | |
51 SetResizableStyleMask(window, can_resize); | |
52 [window setShowsResizeIndicator:can_resize]; | |
53 | |
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); | |
59 | |
60 [[window standardWindowButton:NSWindowZoomButton] setEnabled:can_fullscreen]; | |
61 } | |
62 | |
63 } // namespace gfx | |
OLD | NEW |