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