Chromium Code Reviews| 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 #include "ui/gfx/mac/nswindow_util.h" | |
| 6 | |
| 7 #include "base/mac/mac_util.h" | |
| 8 #include "base/mac/sdk_forward_declarations.h" | |
|
tapted
2015/03/25 18:50:23
nit: include->import all (3) of these.
jackhou1
2015/03/26 03:50:46
Done.
| |
| 9 | |
| 10 namespace { | |
| 11 | |
| 12 // The value used to represent an unbounded width or height. | |
| 13 const int kUnboundedSize = 0; | |
| 14 | |
| 15 } // namespace | |
| 16 | |
| 17 void SetFullScreenCollectionBehavior(NSWindow* window, bool allow_fullscreen) { | |
| 18 NSWindowCollectionBehavior behavior = [window collectionBehavior]; | |
| 19 if (allow_fullscreen) | |
| 20 behavior |= NSWindowCollectionBehaviorFullScreenPrimary; | |
| 21 else | |
| 22 behavior &= ~NSWindowCollectionBehaviorFullScreenPrimary; | |
| 23 [window setCollectionBehavior:behavior]; | |
| 24 } | |
| 25 | |
| 26 void SetResizableStyleMask(NSWindow* window, bool resizable) { | |
| 27 NSUInteger style_mask = [window styleMask]; | |
| 28 if (resizable) | |
| 29 style_mask |= NSResizableWindowMask; | |
| 30 else | |
| 31 style_mask &= ~NSResizableWindowMask; | |
| 32 [window setStyleMask:style_mask]; | |
| 33 } | |
| 34 | |
| 35 void ApplySizeConstraints(NSWindow* window, | |
| 36 gfx::Size min_size, | |
| 37 gfx::Size max_size, | |
| 38 bool can_resize, | |
| 39 bool can_fullscreen) { | |
| 40 [window setContentMinSize:NSMakeSize(min_size.width(), min_size.height())]; | |
| 41 | |
| 42 CGFloat max_width = | |
| 43 max_size.width() == kUnboundedSize ? CGFLOAT_MAX : max_size.width(); | |
| 44 CGFloat max_height = | |
| 45 max_size.height() == kUnboundedSize ? CGFLOAT_MAX : max_size.height(); | |
| 46 [window setContentMaxSize:NSMakeSize(max_width, max_height)]; | |
| 47 | |
| 48 SetResizableStyleMask(window, can_resize); | |
| 49 if (base::mac::IsOSSnowLeopard()) | |
| 50 [window setShowsResizeIndicator:can_resize]; | |
| 51 | |
| 52 // Set the window to participate in Lion Fullscreen mode. Setting this flag | |
| 53 // has no effect on Snow Leopard or earlier. UI controls for fullscreen are | |
| 54 // only shown for apps that have unbounded size. | |
| 55 if (base::mac::IsOSLionOrLater()) | |
| 56 SetFullScreenCollectionBehavior(window, can_fullscreen); | |
| 57 | |
| 58 [[window standardWindowButton:NSWindowZoomButton] setEnabled:can_fullscreen]; | |
| 59 } | |
| OLD | NEW |