Chromium Code Reviews| 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 | |
| 9 | 36 |
| 10 @interface VersionIndependentWindow () | 37 @interface VersionIndependentWindow () |
| 11 | 38 |
| 12 + (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle; | 39 + (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle; |
| 13 | 40 |
| 14 - (NSView*)chromeWindowView; | 41 - (NSView*)chromeWindowView; |
| 15 | 42 |
| 16 @end | 43 @end |
| 17 | 44 |
| 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 | |
| 24 @implementation FullSizeContentView | 45 @implementation FullSizeContentView |
| 25 | 46 |
| 26 // This method is directly called by NSWindow during a window resize on OSX | 47 // This method is directly called by NSWindow during a window resize on OSX |
| 27 // 10.10.0, beta 2. We must override it to prevent the content view from | 48 // 10.10.0, beta 2. We must override it to prevent the content view from |
| 28 // shrinking. | 49 // shrinking. |
| 29 - (void)setFrameSize:(NSSize)size { | 50 - (void)setFrameSize:(NSSize)size { |
| 30 if ([self superview]) | 51 if ([self superview]) |
| 31 size = [[self superview] bounds].size; | 52 size = [[self superview] bounds].size; |
| 32 [super setFrameSize:size]; | 53 [super setFrameSize:size]; |
| 33 } | 54 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 backing:bufferingType | 95 backing:bufferingType |
| 75 defer:deferCreation]; | 96 defer:deferCreation]; |
| 76 if (self) { | 97 if (self) { |
| 77 if ([VersionIndependentWindow | 98 if ([VersionIndependentWindow |
| 78 shouldUseFullSizeContentViewForStyle:windowStyle]) { | 99 shouldUseFullSizeContentViewForStyle:windowStyle]) { |
| 79 chromeWindowView_.reset([[FullSizeContentView alloc] init]); | 100 chromeWindowView_.reset([[FullSizeContentView alloc] init]); |
| 80 [chromeWindowView_ | 101 [chromeWindowView_ |
| 81 setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; | 102 setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
| 82 [chromeWindowView_ setFrame:[[[self contentView] superview] bounds]]; | 103 [chromeWindowView_ setFrame:[[[self contentView] superview] bounds]]; |
| 83 [self setContentView:chromeWindowView_]; | 104 [self setContentView:chromeWindowView_]; |
| 105 | |
| 106 // Move the content view to the back. | |
| 107 // In Yosemite, the content view takes up the full size of the window, | |
| 108 // and when it is in front of the zoom/fullscreen button, alt-clicking | |
| 109 // the button has the wrong effect. | |
| 110 // Adding subviews to the NSThemeFrame provokes a warning in Yosemite, so | |
| 111 // we sort the subviews in place. | |
| 112 // http://crbug.com/393808 | |
| 113 | |
| 114 NSView* superview = [[self contentView] superview]; | |
| 115 base::scoped_nsobject<NSArray> subviews([[superview subviews] copy]); | |
| 116 [superview sortSubviewsUsingFunction:&ReorderContentViewToBack | |
| 117 context:subviews.get()]; | |
|
Scott Hess - ex-Googler
2014/07/17 21:03:09
Wow.
I'm assuming the comment refers to an attemp
erikchen
2014/07/17 21:17:08
I tried out your suggestion. It works fine and doe
| |
| 84 } | 118 } |
| 85 } | 119 } |
| 86 return self; | 120 return self; |
| 87 } | 121 } |
| 88 | 122 |
| 89 #pragma mark - Private Methods | 123 #pragma mark - Private Methods |
| 90 | 124 |
| 91 + (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle { | 125 + (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle { |
| 92 return (windowStyle & NSTitledWindowMask) && base::mac::IsOSYosemiteOrLater(); | 126 return (windowStyle & NSTitledWindowMask) && base::mac::IsOSYosemiteOrLater(); |
| 93 } | 127 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 return [super contentRectForFrameRect:fRect styleMask:aStyle]; | 174 return [super contentRectForFrameRect:fRect styleMask:aStyle]; |
| 141 } | 175 } |
| 142 | 176 |
| 143 - (NSRect)contentRectForFrameRect:(NSRect)frameRect { | 177 - (NSRect)contentRectForFrameRect:(NSRect)frameRect { |
| 144 if (chromeWindowView_) | 178 if (chromeWindowView_) |
| 145 return frameRect; | 179 return frameRect; |
| 146 return [super contentRectForFrameRect:frameRect]; | 180 return [super contentRectForFrameRect:frameRect]; |
| 147 } | 181 } |
| 148 | 182 |
| 149 @end | 183 @end |
| OLD | NEW |