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

Side by Side Diff: ui/gfx/mac/nswindow_util.mm

Issue 1023083002: [MacViews] Implement size constraints for app windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. 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 unified diff | Download patch
OLDNEW
(Empty)
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
5 #import "ui/gfx/mac/nswindow_util.h"
6
7 #import "base/mac/mac_util.h"
8 #import "base/mac/sdk_forward_declarations.h"
9 #include "ui/gfx/geometry/size.h"
10
11 namespace {
12
13 // The value used to represent an unbounded width or height.
14 const int kUnboundedSize = 0;
tapted 2015/03/30 06:33:37 since `const` has internal linkage implicitly, thi
15
16 } // namespace
17
18 void SetFullScreenCollectionBehavior(NSWindow* window, bool allow_fullscreen) {
19 NSWindowCollectionBehavior behavior = [window collectionBehavior];
20 if (allow_fullscreen)
21 behavior |= NSWindowCollectionBehaviorFullScreenPrimary;
22 else
23 behavior &= ~NSWindowCollectionBehaviorFullScreenPrimary;
24 [window setCollectionBehavior:behavior];
25 }
26
27 void SetResizableStyleMask(NSWindow* window, bool resizable) {
28 NSUInteger style_mask = [window styleMask];
29 if (resizable)
30 style_mask |= NSResizableWindowMask;
31 else
32 style_mask &= ~NSResizableWindowMask;
33 [window setStyleMask:style_mask];
34 }
35
36 void ApplySizeConstraints(NSWindow* window,
37 const gfx::Size& min_size,
38 const gfx::Size& max_size,
39 bool can_resize,
40 bool can_fullscreen) {
41 [window setContentMinSize:NSMakeSize(min_size.width(), min_size.height())];
42
43 CGFloat max_width =
44 max_size.width() == kUnboundedSize ? CGFLOAT_MAX : max_size.width();
45 CGFloat max_height =
46 max_size.height() == kUnboundedSize ? CGFLOAT_MAX : max_size.height();
47 [window setContentMaxSize:NSMakeSize(max_width, max_height)];
48
49 SetResizableStyleMask(window, can_resize);
50 if (base::mac::IsOSSnowLeopard())
tapted 2015/03/30 06:33:37 Maybe a comment why this is snow leopard only (i.e
jackhou1 2015/03/31 00:50:42 Done.
51 [window setShowsResizeIndicator:can_resize];
52
53 // Set the window to participate in Lion Fullscreen mode. Setting this flag
54 // has no effect on Snow Leopard or earlier. UI controls for fullscreen are
55 // only shown for apps that have unbounded size.
56 if (base::mac::IsOSLionOrLater())
57 SetFullScreenCollectionBehavior(window, can_fullscreen);
58
59 [[window standardWindowButton:NSWindowZoomButton] setEnabled:can_fullscreen];
60 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698