nswindow_frame_controls.mm 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #import "ui/gfx/mac/nswindow_frame_controls.h"
  5. #import <AppKit/AppKit.h>
  6. #include "ui/gfx/geometry/size.h"
  7. namespace {
  8. // The value used to represent an unbounded width or height.
  9. const int kUnboundedSize = 0;
  10. void SetResizableStyleMask(NSWindow* window, bool resizable) {
  11. NSUInteger style_mask = [window styleMask];
  12. if (resizable)
  13. style_mask |= NSWindowStyleMaskResizable;
  14. else
  15. style_mask &= ~NSWindowStyleMaskResizable;
  16. [window setStyleMask:style_mask];
  17. }
  18. } // namespace
  19. namespace gfx {
  20. void SetNSWindowCanFullscreen(NSWindow* window, bool allow_fullscreen) {
  21. NSWindowCollectionBehavior behavior = [window collectionBehavior];
  22. if (behavior & NSWindowCollectionBehaviorFullScreenAuxiliary)
  23. return;
  24. if (allow_fullscreen)
  25. behavior |= NSWindowCollectionBehaviorFullScreenPrimary;
  26. else
  27. behavior &= ~NSWindowCollectionBehaviorFullScreenPrimary;
  28. [window setCollectionBehavior:behavior];
  29. }
  30. void SetNSWindowVisibleOnAllWorkspaces(NSWindow* window, bool always_visible) {
  31. NSWindowCollectionBehavior behavior = [window collectionBehavior];
  32. if (always_visible)
  33. behavior |= NSWindowCollectionBehaviorCanJoinAllSpaces;
  34. else
  35. behavior &= ~NSWindowCollectionBehaviorCanJoinAllSpaces;
  36. [window setCollectionBehavior:behavior];
  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. CGFloat max_width =
  45. max_size.width() == kUnboundedSize ? CGFLOAT_MAX : max_size.width();
  46. CGFloat max_height =
  47. max_size.height() == kUnboundedSize ? CGFLOAT_MAX : max_size.height();
  48. [window setContentMaxSize:NSMakeSize(max_width, max_height)];
  49. SetResizableStyleMask(window, can_resize);
  50. [window setShowsResizeIndicator:can_resize];
  51. // Set the window to participate in Lion Fullscreen mode.
  52. SetNSWindowCanFullscreen(window, can_fullscreen);
  53. [[window standardWindowButton:NSWindowZoomButton] setEnabled:can_fullscreen];
  54. }
  55. } // namespace gfx