Chromium Code Reviews| Index: ui/gfx/mac/nswindow_util.mm |
| diff --git a/ui/gfx/mac/nswindow_util.mm b/ui/gfx/mac/nswindow_util.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a149de91f15c11e95ca7475473aa720d4026425d |
| --- /dev/null |
| +++ b/ui/gfx/mac/nswindow_util.mm |
| @@ -0,0 +1,59 @@ |
| +// 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 "ui/gfx/mac/nswindow_util.h" |
| + |
| +#include "base/mac/mac_util.h" |
| +#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.
|
| + |
| +namespace { |
| + |
| +// The value used to represent an unbounded width or height. |
| +const int kUnboundedSize = 0; |
| + |
| +} // namespace |
| + |
| +void SetFullScreenCollectionBehavior(NSWindow* window, bool allow_fullscreen) { |
| + NSWindowCollectionBehavior behavior = [window collectionBehavior]; |
| + if (allow_fullscreen) |
| + behavior |= NSWindowCollectionBehaviorFullScreenPrimary; |
| + else |
| + behavior &= ~NSWindowCollectionBehaviorFullScreenPrimary; |
| + [window setCollectionBehavior:behavior]; |
| +} |
| + |
| +void SetResizableStyleMask(NSWindow* window, bool resizable) { |
| + NSUInteger style_mask = [window styleMask]; |
| + if (resizable) |
| + style_mask |= NSResizableWindowMask; |
| + else |
| + style_mask &= ~NSResizableWindowMask; |
| + [window setStyleMask:style_mask]; |
| +} |
| + |
| +void ApplySizeConstraints(NSWindow* window, |
| + gfx::Size min_size, |
| + gfx::Size max_size, |
| + bool can_resize, |
| + bool can_fullscreen) { |
| + [window setContentMinSize:NSMakeSize(min_size.width(), min_size.height())]; |
| + |
| + CGFloat max_width = |
| + max_size.width() == kUnboundedSize ? CGFLOAT_MAX : max_size.width(); |
| + CGFloat max_height = |
| + max_size.height() == kUnboundedSize ? CGFLOAT_MAX : max_size.height(); |
| + [window setContentMaxSize:NSMakeSize(max_width, max_height)]; |
| + |
| + SetResizableStyleMask(window, can_resize); |
| + if (base::mac::IsOSSnowLeopard()) |
| + [window setShowsResizeIndicator:can_resize]; |
| + |
| + // Set the window to participate in Lion Fullscreen mode. Setting this flag |
| + // has no effect on Snow Leopard or earlier. UI controls for fullscreen are |
| + // only shown for apps that have unbounded size. |
| + if (base::mac::IsOSLionOrLater()) |
| + SetFullScreenCollectionBehavior(window, can_fullscreen); |
| + |
| + [[window standardWindowButton:NSWindowZoomButton] setEnabled:can_fullscreen]; |
| +} |