Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(382)

Unified Diff: ui/gfx/mac/nswindow_frame_controls.mm

Issue 1023083002: [MacViews] Implement size constraints for app windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update ui/gfx/BUILD.gn Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/mac/nswindow_frame_controls.h ('k') | ui/views/cocoa/bridged_native_widget.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/mac/nswindow_frame_controls.mm
diff --git a/ui/gfx/mac/nswindow_frame_controls.mm b/ui/gfx/mac/nswindow_frame_controls.mm
new file mode 100644
index 0000000000000000000000000000000000000000..34f7d266516c823bc53ea6f612eee9dc22446057
--- /dev/null
+++ b/ui/gfx/mac/nswindow_frame_controls.mm
@@ -0,0 +1,63 @@
+// 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.
+
+#import "ui/gfx/mac/nswindow_frame_controls.h"
+
+#import "base/mac/mac_util.h"
+#import "base/mac/sdk_forward_declarations.h"
+#include "ui/gfx/geometry/size.h"
+
+namespace {
+
+// The value used to represent an unbounded width or height.
+const int kUnboundedSize = 0;
+
+void SetResizableStyleMask(NSWindow* window, bool resizable) {
+ NSUInteger style_mask = [window styleMask];
+ if (resizable)
+ style_mask |= NSResizableWindowMask;
+ else
+ style_mask &= ~NSResizableWindowMask;
+ [window setStyleMask:style_mask];
+}
+
+} // namespace
+
+namespace gfx {
+
+void SetNSWindowCanFullscreen(NSWindow* window, bool allow_fullscreen) {
+ NSWindowCollectionBehavior behavior = [window collectionBehavior];
+ if (allow_fullscreen)
+ behavior |= NSWindowCollectionBehaviorFullScreenPrimary;
+ else
+ behavior &= ~NSWindowCollectionBehaviorFullScreenPrimary;
+ [window setCollectionBehavior:behavior];
+}
+
+void ApplyNSWindowSizeConstraints(NSWindow* window,
+ const gfx::Size& min_size,
+ const 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);
+ [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 windows that have unbounded size.
+ if (base::mac::IsOSLionOrLater())
+ SetNSWindowCanFullscreen(window, can_fullscreen);
+
+ [[window standardWindowButton:NSWindowZoomButton] setEnabled:can_fullscreen];
+}
+
+} // namespace gfx
« no previous file with comments | « ui/gfx/mac/nswindow_frame_controls.h ('k') | ui/views/cocoa/bridged_native_widget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698