| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/ui/cocoa/full_size_content_window.h" | 5 #import "chrome/browser/ui/cocoa/full_size_content_window.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/mac/foundation_util.h" |
| 8 | 9 |
| 9 @interface FullSizeContentWindow () | 10 @interface FullSizeContentWindow () |
| 10 | 11 |
| 11 + (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle; | 12 + (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle; |
| 12 | 13 |
| 13 @end | 14 @end |
| 14 | 15 |
| 15 // This view always takes the size of its superview. It is intended to be used | 16 // 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 // as a NSWindow's contentView. It is needed because NSWindow's implementation |
| 17 // explicitly resizes the contentView at inopportune times. | 18 // explicitly resizes the contentView at inopportune times. |
| 18 @interface FullSizeContentView : NSView | 19 @interface FullSizeContentView : NSView |
| 20 |
| 21 // This method allows us to set the content view size since setFrameSize is |
| 22 // overridden to prevent the view from shrinking. |
| 23 - (void)forceFrameSize:(NSSize)size; |
| 24 |
| 19 @end | 25 @end |
| 20 | 26 |
| 21 @implementation FullSizeContentView | 27 @implementation FullSizeContentView |
| 22 | 28 |
| 23 // This method is directly called by AppKit during a live window resize. | 29 // This method is directly called by AppKit during a live window resize. |
| 24 // Override it to prevent the content view from shrinking. | 30 // Override it to prevent the content view from shrinking. |
| 25 - (void)setFrameSize:(NSSize)size { | 31 - (void)setFrameSize:(NSSize)size { |
| 26 if ([self superview]) | 32 if ([self superview]) |
| 27 size = [[self superview] bounds].size; | 33 size = [[self superview] bounds].size; |
| 28 [super setFrameSize:size]; | 34 [super setFrameSize:size]; |
| 29 } | 35 } |
| 30 | 36 |
| 37 - (void)forceFrameSize:(NSSize)size { |
| 38 [super setFrameSize:size]; |
| 39 } |
| 40 |
| 31 @end | 41 @end |
| 32 | 42 |
| 33 @implementation FullSizeContentWindow | 43 @implementation FullSizeContentWindow |
| 34 | 44 |
| 35 #pragma mark - Lifecycle | 45 #pragma mark - Lifecycle |
| 36 | 46 |
| 37 - (instancetype)init { | 47 - (instancetype)init { |
| 38 NOTREACHED(); | 48 NOTREACHED(); |
| 39 return nil; | 49 return nil; |
| 40 } | 50 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 NSView* superview = [chromeWindowView_ superview]; | 84 NSView* superview = [chromeWindowView_ superview]; |
| 75 [chromeWindowView_ removeFromSuperview]; | 85 [chromeWindowView_ removeFromSuperview]; |
| 76 [superview addSubview:chromeWindowView_ | 86 [superview addSubview:chromeWindowView_ |
| 77 positioned:NSWindowBelow | 87 positioned:NSWindowBelow |
| 78 relativeTo:nil]; | 88 relativeTo:nil]; |
| 79 } | 89 } |
| 80 } | 90 } |
| 81 return self; | 91 return self; |
| 82 } | 92 } |
| 83 | 93 |
| 94 - (void)forceContentViewSize:(NSSize)size { |
| 95 FullSizeContentView* contentView = |
| 96 base::mac::ObjCCast<FullSizeContentView>(chromeWindowView_); |
| 97 [contentView forceFrameSize:size]; |
| 98 } |
| 99 |
| 84 #pragma mark - Private Methods | 100 #pragma mark - Private Methods |
| 85 | 101 |
| 86 + (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle { | 102 + (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle { |
| 87 return windowStyle & NSTitledWindowMask; | 103 return windowStyle & NSTitledWindowMask; |
| 88 } | 104 } |
| 89 | 105 |
| 90 #pragma mark - NSWindow Overrides | 106 #pragma mark - NSWindow Overrides |
| 91 | 107 |
| 92 + (NSRect)frameRectForContentRect:(NSRect)cRect styleMask:(NSUInteger)aStyle { | 108 + (NSRect)frameRectForContentRect:(NSRect)cRect styleMask:(NSUInteger)aStyle { |
| 93 if ([self shouldUseFullSizeContentViewForStyle:aStyle]) | 109 if ([self shouldUseFullSizeContentViewForStyle:aStyle]) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 107 return [super contentRectForFrameRect:fRect styleMask:aStyle]; | 123 return [super contentRectForFrameRect:fRect styleMask:aStyle]; |
| 108 } | 124 } |
| 109 | 125 |
| 110 - (NSRect)contentRectForFrameRect:(NSRect)frameRect { | 126 - (NSRect)contentRectForFrameRect:(NSRect)frameRect { |
| 111 if (chromeWindowView_) | 127 if (chromeWindowView_) |
| 112 return frameRect; | 128 return frameRect; |
| 113 return [super contentRectForFrameRect:frameRect]; | 129 return [super contentRectForFrameRect:frameRect]; |
| 114 } | 130 } |
| 115 | 131 |
| 116 @end | 132 @end |
| OLD | NEW |