| 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/version_independent_window.h" | 5 #import "chrome/browser/ui/cocoa/version_independent_window.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/mac/mac_util.h" | 8 #include "base/mac/mac_util.h" |
| 9 #include "base/mac/scoped_nsobject.h" | |
| 10 | |
| 11 // This view always takes the size of its superview. It is intended to be used | |
| 12 // as a NSWindow's contentView. It is needed because NSWindow's implementation | |
| 13 // explicitly resizes the contentView at inopportune times. | |
| 14 @interface FullSizeContentView : NSView | |
| 15 @end | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 // Reorders the subviews of NSWindow's root view so that the contentView is | |
| 20 // moved to the back, and the ordering of the other views is unchanged. | |
| 21 // |context| should be an NSArray containing the subviews of the root view as | |
| 22 // they were previously ordered. | |
| 23 int ReorderContentViewToBack(id firstView, id secondView, void* context) { | |
| 24 NSView* contentView = [[firstView window] contentView]; | |
| 25 NSArray* subviews = static_cast<NSArray*>(context); | |
| 26 if (firstView == contentView) | |
| 27 return NSOrderedAscending; | |
| 28 if (secondView == contentView) | |
| 29 return NSOrderedDescending; | |
| 30 NSUInteger index1 = [subviews indexOfObject:firstView]; | |
| 31 NSUInteger index2 = [subviews indexOfObject:secondView]; | |
| 32 return (index1 < index2) ? NSOrderedAscending : NSOrderedDescending; | |
| 33 } | |
| 34 | |
| 35 } // namespace | |
| 36 | 9 |
| 37 @interface VersionIndependentWindow () | 10 @interface VersionIndependentWindow () |
| 38 | 11 |
| 39 + (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle; | 12 + (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle; |
| 40 | 13 |
| 41 - (NSView*)chromeWindowView; | 14 - (NSView*)chromeWindowView; |
| 42 | 15 |
| 43 @end | 16 @end |
| 44 | 17 |
| 18 // This view always takes the size of its superview. It is intended to be used |
| 19 // as a NSWindow's contentView. It is needed because NSWindow's implementation |
| 20 // explicitly resizes the contentView at inopportune times. |
| 21 @interface FullSizeContentView : NSView |
| 22 @end |
| 23 |
| 45 @implementation FullSizeContentView | 24 @implementation FullSizeContentView |
| 46 | 25 |
| 47 // This method is directly called by NSWindow during a window resize on OSX | 26 // This method is directly called by NSWindow during a window resize on OSX |
| 48 // 10.10.0, beta 2. We must override it to prevent the content view from | 27 // 10.10.0, beta 2. We must override it to prevent the content view from |
| 49 // shrinking. | 28 // shrinking. |
| 50 - (void)setFrameSize:(NSSize)size { | 29 - (void)setFrameSize:(NSSize)size { |
| 51 if ([self superview]) | 30 if ([self superview]) |
| 52 size = [[self superview] bounds].size; | 31 size = [[self superview] bounds].size; |
| 53 [super setFrameSize:size]; | 32 [super setFrameSize:size]; |
| 54 } | 33 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 backing:bufferingType | 68 backing:bufferingType |
| 90 defer:deferCreation]; | 69 defer:deferCreation]; |
| 91 if (self) { | 70 if (self) { |
| 92 if ([VersionIndependentWindow | 71 if ([VersionIndependentWindow |
| 93 shouldUseFullSizeContentViewForStyle:windowStyle]) { | 72 shouldUseFullSizeContentViewForStyle:windowStyle]) { |
| 94 chromeWindowView_.reset([[FullSizeContentView alloc] init]); | 73 chromeWindowView_.reset([[FullSizeContentView alloc] init]); |
| 95 [chromeWindowView_ | 74 [chromeWindowView_ |
| 96 setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; | 75 setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
| 97 [self setContentView:chromeWindowView_]; | 76 [self setContentView:chromeWindowView_]; |
| 98 [chromeWindowView_ setFrame:[[[self contentView] superview] bounds]]; | 77 [chromeWindowView_ setFrame:[[[self contentView] superview] bounds]]; |
| 99 | |
| 100 // Move the content view to the back. | |
| 101 // In Yosemite, the content view takes up the full size of the window, | |
| 102 // and when it is in front of the zoom/fullscreen button, alt-clicking | |
| 103 // the button has the wrong effect. | |
| 104 // Adding subviews to the NSThemeFrame provokes a warning in Yosemite, so | |
| 105 // we sort the subviews in place. | |
| 106 // http://crbug.com/393808 | |
| 107 NSView* superview = [[self contentView] superview]; | |
| 108 base::scoped_nsobject<NSArray> subviews([[superview subviews] copy]); | |
| 109 [superview sortSubviewsUsingFunction:&ReorderContentViewToBack | |
| 110 context:subviews.get()]; | |
| 111 } | 78 } |
| 112 } | 79 } |
| 113 return self; | 80 return self; |
| 114 } | 81 } |
| 115 | 82 |
| 116 #pragma mark - Private Methods | 83 #pragma mark - Private Methods |
| 117 | 84 |
| 118 + (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle { | 85 + (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle { |
| 119 return (windowStyle & NSTitledWindowMask) && base::mac::IsOSYosemiteOrLater(); | 86 return (windowStyle & NSTitledWindowMask) && base::mac::IsOSYosemiteOrLater(); |
| 120 } | 87 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 return [super contentRectForFrameRect:fRect styleMask:aStyle]; | 134 return [super contentRectForFrameRect:fRect styleMask:aStyle]; |
| 168 } | 135 } |
| 169 | 136 |
| 170 - (NSRect)contentRectForFrameRect:(NSRect)frameRect { | 137 - (NSRect)contentRectForFrameRect:(NSRect)frameRect { |
| 171 if (chromeWindowView_) | 138 if (chromeWindowView_) |
| 172 return frameRect; | 139 return frameRect; |
| 173 return [super contentRectForFrameRect:frameRect]; | 140 return [super contentRectForFrameRect:frameRect]; |
| 174 } | 141 } |
| 175 | 142 |
| 176 @end | 143 @end |
| OLD | NEW |