| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ui/gfx/mac/nswindow_frame_controls.h" | 5 #import "ui/gfx/mac/nswindow_frame_controls.h" |
| 6 | 6 |
| 7 #import "base/mac/mac_util.h" | 7 #import "base/mac/mac_util.h" |
| 8 #import "base/mac/sdk_forward_declarations.h" | 8 #import "base/mac/sdk_forward_declarations.h" |
| 9 #include "ui/gfx/geometry/size.h" | 9 #include "ui/gfx/geometry/size.h" |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 // The value used to represent an unbounded width or height. | 13 // The value used to represent an unbounded width or height. |
| 14 const int kUnboundedSize = 0; | 14 const int kUnboundedSize = 0; |
| 15 | 15 |
| 16 void SetResizableStyleMask(NSWindow* window, bool resizable) { | 16 void SetResizableStyleMask(NSWindow* window, bool resizable) { |
| 17 NSUInteger style_mask = [window styleMask]; | 17 NSUInteger style_mask = [window styleMask]; |
| 18 if (resizable) | 18 if (resizable) |
| 19 style_mask |= NSResizableWindowMask; | 19 style_mask |= NSResizableWindowMask; |
| 20 else | 20 else |
| 21 style_mask &= ~NSResizableWindowMask; | 21 style_mask &= ~NSResizableWindowMask; |
| 22 [window setStyleMask:style_mask]; | 22 [window setStyleMask:style_mask]; |
| 23 } | 23 } |
| 24 | 24 |
| 25 // Returns the level for windows that are configured to be always on top. |
| 26 // This is not a constant because NSFloatingWindowLevel is a macro defined |
| 27 // as a function call. |
| 28 NSInteger AlwaysOnTopWindowLevel() { |
| 29 return NSFloatingWindowLevel; |
| 30 } |
| 31 |
| 25 } // namespace | 32 } // namespace |
| 26 | 33 |
| 27 namespace gfx { | 34 namespace gfx { |
| 28 | 35 |
| 29 void SetNSWindowCanFullscreen(NSWindow* window, bool allow_fullscreen) { | 36 void SetNSWindowCanFullscreen(NSWindow* window, bool allow_fullscreen) { |
| 30 NSWindowCollectionBehavior behavior = [window collectionBehavior]; | 37 NSWindowCollectionBehavior behavior = [window collectionBehavior]; |
| 31 if (allow_fullscreen) | 38 if (allow_fullscreen) |
| 32 behavior |= NSWindowCollectionBehaviorFullScreenPrimary; | 39 behavior |= NSWindowCollectionBehaviorFullScreenPrimary; |
| 33 else | 40 else |
| 34 behavior &= ~NSWindowCollectionBehaviorFullScreenPrimary; | 41 behavior &= ~NSWindowCollectionBehaviorFullScreenPrimary; |
| 35 [window setCollectionBehavior:behavior]; | 42 [window setCollectionBehavior:behavior]; |
| 36 } | 43 } |
| 37 | 44 |
| 45 bool IsNSWindowAlwaysOnTop(NSWindow* window) { |
| 46 return [window level] == AlwaysOnTopWindowLevel(); |
| 47 } |
| 48 |
| 49 void SetNSWindowAlwaysOnTop(NSWindow* window, |
| 50 bool always_on_top) { |
| 51 [window setLevel:(always_on_top ? AlwaysOnTopWindowLevel() |
| 52 : NSNormalWindowLevel)]; |
| 53 // Since always-on-top windows have a higher window level than |
| 54 // NSNormalWindowLevel, they will default to |
| 55 // NSWindowCollectionBehaviorTransient. Set the value explicitly here to match |
| 56 // normal windows. |
| 57 NSWindowCollectionBehavior behavior = |
| 58 [window collectionBehavior] | NSWindowCollectionBehaviorManaged; |
| 59 [window setCollectionBehavior:behavior]; |
| 60 } |
| 61 |
| 62 void SetNSWindowVisibleOnAllWorkspaces(NSWindow* window, bool always_visible) { |
| 63 NSWindowCollectionBehavior behavior = [window collectionBehavior]; |
| 64 if (always_visible) |
| 65 behavior |= NSWindowCollectionBehaviorCanJoinAllSpaces; |
| 66 else |
| 67 behavior &= ~NSWindowCollectionBehaviorCanJoinAllSpaces; |
| 68 [window setCollectionBehavior:behavior]; |
| 69 } |
| 70 |
| 38 void ApplyNSWindowSizeConstraints(NSWindow* window, | 71 void ApplyNSWindowSizeConstraints(NSWindow* window, |
| 39 const gfx::Size& min_size, | 72 const gfx::Size& min_size, |
| 40 const gfx::Size& max_size, | 73 const gfx::Size& max_size, |
| 41 bool can_resize, | 74 bool can_resize, |
| 42 bool can_fullscreen) { | 75 bool can_fullscreen) { |
| 43 [window setContentMinSize:NSMakeSize(min_size.width(), min_size.height())]; | 76 [window setContentMinSize:NSMakeSize(min_size.width(), min_size.height())]; |
| 44 | 77 |
| 45 CGFloat max_width = | 78 CGFloat max_width = |
| 46 max_size.width() == kUnboundedSize ? CGFLOAT_MAX : max_size.width(); | 79 max_size.width() == kUnboundedSize ? CGFLOAT_MAX : max_size.width(); |
| 47 CGFloat max_height = | 80 CGFloat max_height = |
| 48 max_size.height() == kUnboundedSize ? CGFLOAT_MAX : max_size.height(); | 81 max_size.height() == kUnboundedSize ? CGFLOAT_MAX : max_size.height(); |
| 49 [window setContentMaxSize:NSMakeSize(max_width, max_height)]; | 82 [window setContentMaxSize:NSMakeSize(max_width, max_height)]; |
| 50 | 83 |
| 51 SetResizableStyleMask(window, can_resize); | 84 SetResizableStyleMask(window, can_resize); |
| 52 [window setShowsResizeIndicator:can_resize]; | 85 [window setShowsResizeIndicator:can_resize]; |
| 53 | 86 |
| 54 // Set the window to participate in Lion Fullscreen mode. Setting this flag | 87 // 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 | 88 // has no effect on Snow Leopard or earlier. UI controls for fullscreen are |
| 56 // only shown for windows that have unbounded size. | 89 // only shown for windows that have unbounded size. |
| 57 if (base::mac::IsOSLionOrLater()) | 90 if (base::mac::IsOSLionOrLater()) |
| 58 SetNSWindowCanFullscreen(window, can_fullscreen); | 91 SetNSWindowCanFullscreen(window, can_fullscreen); |
| 59 | 92 |
| 60 [[window standardWindowButton:NSWindowZoomButton] setEnabled:can_fullscreen]; | 93 [[window standardWindowButton:NSWindowZoomButton] setEnabled:can_fullscreen]; |
| 61 } | 94 } |
| 62 | 95 |
| 63 } // namespace gfx | 96 } // namespace gfx |
| OLD | NEW |