1 // Copyright 2014 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.
5 #import "chrome/browser/ui/cocoa/full_size_content_window.h"
7 #include "base/logging.h"
9 @interface FullSizeContentWindow ()
11 + (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle;
15 // This view always takes the size of its superview. It is intended to be used
16 // as a NSWindow's contentView. It is needed because NSWindow's implementation
17 // explicitly resizes the contentView at inopportune times.
18 @interface FullSizeContentView : NSView
21 @implementation FullSizeContentView
23 // This method is directly called by AppKit during a live window resize.
24 // Override it to prevent the content view from shrinking.
25 - (void)setFrameSize:(NSSize)size {
27 size = [[self superview] bounds].size;
28 [super setFrameSize:size];
33 @implementation FullSizeContentWindow
35 #pragma mark - Lifecycle
37 - (instancetype)init {
42 - (instancetype)initWithContentRect:(NSRect)contentRect
43 styleMask:(NSUInteger)windowStyle
44 backing:(NSBackingStoreType)bufferingType
45 defer:(BOOL)deferCreation {
46 return [self initWithContentRect:contentRect
50 wantsViewsOverTitlebar:NO];
53 - (instancetype)initWithContentRect:(NSRect)contentRect
54 styleMask:(NSUInteger)windowStyle
55 backing:(NSBackingStoreType)bufferingType
56 defer:(BOOL)deferCreation
57 wantsViewsOverTitlebar:(BOOL)wantsViewsOverTitlebar {
58 self = [super initWithContentRect:contentRect
63 if (wantsViewsOverTitlebar &&
64 [FullSizeContentWindow
65 shouldUseFullSizeContentViewForStyle:windowStyle]) {
66 chromeWindowView_.reset([[FullSizeContentView alloc] init]);
68 setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
69 [self setContentView:chromeWindowView_];
70 [chromeWindowView_ setFrame:[[chromeWindowView_ superview] bounds]];
72 // Our content view overlaps the window control buttons, so we must ensure
73 // it is positioned below the buttons.
74 NSView* superview = [chromeWindowView_ superview];
75 [chromeWindowView_ removeFromSuperview];
76 [superview addSubview:chromeWindowView_
77 positioned:NSWindowBelow
84 #pragma mark - Private Methods
86 + (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle {
87 return windowStyle & NSTitledWindowMask;
90 #pragma mark - NSWindow Overrides
92 + (NSRect)frameRectForContentRect:(NSRect)cRect styleMask:(NSUInteger)aStyle {
93 if ([self shouldUseFullSizeContentViewForStyle:aStyle])
95 return [super frameRectForContentRect:cRect styleMask:aStyle];
98 - (NSRect)frameRectForContentRect:(NSRect)contentRect {
99 if (chromeWindowView_)
101 return [super frameRectForContentRect:contentRect];
104 + (NSRect)contentRectForFrameRect:(NSRect)fRect styleMask:(NSUInteger)aStyle {
105 if ([self shouldUseFullSizeContentViewForStyle:aStyle])
107 return [super contentRectForFrameRect:fRect styleMask:aStyle];
110 - (NSRect)contentRectForFrameRect:(NSRect)frameRect {
111 if (chromeWindowView_)
113 return [super contentRectForFrameRect:frameRect];