Chromium Code Reviews| 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 bool transient) { | |
| 52 [window setLevel:(always_on_top ? AlwaysOnTopWindowLevel() | |
| 53 : NSNormalWindowLevel)]; | |
| 54 // Since always-on-top windows have a higher window level than | |
| 55 // NSNormalWindowLevel, they will default to | |
| 56 // NSWindowCollectionBehaviorTransient. Set the value explicitly here to match | |
| 57 // normal windows. | |
| 58 if (!transient) { | |
|
jackhou1
2015/04/24 07:04:24
The call from NativeWidgetMac::AlwaysOnTop should
tapted
2015/05/06 02:00:19
I would assume transient is always false (i.e. dro
jackhou1
2015/05/12 01:42:12
Done.
| |
| 59 NSWindowCollectionBehavior behavior = | |
| 60 [window collectionBehavior] | NSWindowCollectionBehaviorManaged; | |
| 61 [window setCollectionBehavior:behavior]; | |
| 62 } | |
| 63 } | |
| 64 | |
| 65 void SetNSWindowVisibleOnAllWorkspaces(NSWindow* window, bool always_visible) { | |
| 66 NSWindowCollectionBehavior behavior = [window collectionBehavior]; | |
| 67 if (always_visible) | |
| 68 behavior |= NSWindowCollectionBehaviorCanJoinAllSpaces; | |
| 69 else | |
| 70 behavior &= ~NSWindowCollectionBehaviorCanJoinAllSpaces; | |
| 71 [window setCollectionBehavior:behavior]; | |
| 72 } | |
| 73 | |
| 38 void ApplyNSWindowSizeConstraints(NSWindow* window, | 74 void ApplyNSWindowSizeConstraints(NSWindow* window, |
| 39 const gfx::Size& min_size, | 75 const gfx::Size& min_size, |
| 40 const gfx::Size& max_size, | 76 const gfx::Size& max_size, |
| 41 bool can_resize, | 77 bool can_resize, |
| 42 bool can_fullscreen) { | 78 bool can_fullscreen) { |
| 43 [window setContentMinSize:NSMakeSize(min_size.width(), min_size.height())]; | 79 [window setContentMinSize:NSMakeSize(min_size.width(), min_size.height())]; |
| 44 | 80 |
| 45 CGFloat max_width = | 81 CGFloat max_width = |
| 46 max_size.width() == kUnboundedSize ? CGFLOAT_MAX : max_size.width(); | 82 max_size.width() == kUnboundedSize ? CGFLOAT_MAX : max_size.width(); |
| 47 CGFloat max_height = | 83 CGFloat max_height = |
| 48 max_size.height() == kUnboundedSize ? CGFLOAT_MAX : max_size.height(); | 84 max_size.height() == kUnboundedSize ? CGFLOAT_MAX : max_size.height(); |
| 49 [window setContentMaxSize:NSMakeSize(max_width, max_height)]; | 85 [window setContentMaxSize:NSMakeSize(max_width, max_height)]; |
| 50 | 86 |
| 51 SetResizableStyleMask(window, can_resize); | 87 SetResizableStyleMask(window, can_resize); |
| 52 [window setShowsResizeIndicator:can_resize]; | 88 [window setShowsResizeIndicator:can_resize]; |
| 53 | 89 |
| 54 // Set the window to participate in Lion Fullscreen mode. Setting this flag | 90 // 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 | 91 // has no effect on Snow Leopard or earlier. UI controls for fullscreen are |
| 56 // only shown for windows that have unbounded size. | 92 // only shown for windows that have unbounded size. |
| 57 if (base::mac::IsOSLionOrLater()) | 93 if (base::mac::IsOSLionOrLater()) |
| 58 SetNSWindowCanFullscreen(window, can_fullscreen); | 94 SetNSWindowCanFullscreen(window, can_fullscreen); |
| 59 | 95 |
| 60 [[window standardWindowButton:NSWindowZoomButton] setEnabled:can_fullscreen]; | 96 [[window standardWindowButton:NSWindowZoomButton] setEnabled:can_fullscreen]; |
| 61 } | 97 } |
| 62 | 98 |
| 63 } // namespace gfx | 99 } // namespace gfx |
| OLD | NEW |