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 | 9 |
10 // This view always takes the size of its superview. It is intended to be used | |
11 // as a NSWindow's contentView. It is needed because NSWindow's implementation | |
12 // explicitly resizes the contentView at inopportune times. | |
13 @interface FullSizeContentView : NSView | |
14 @end | |
15 | |
16 namespace { | |
17 | |
18 // Moves subclasses of FullSizeContentView to the back. Maintains the | |
19 // ordering of the other subviews. | |
20 // |context| should be an NSArray containing the subviews as they were | |
21 // previously ordered. | |
22 // The logic of this function does not work if there is more than 1 subclass of | |
23 // FullSizeContentView in the subviews being reordered. | |
24 int ReorderContentViewToBack(id firstView, id secondView, void* context) { | |
25 NSArray* subviews = static_cast<NSArray*>(context); | |
26 if ([firstView isKindOfClass:[FullSizeContentView class]]) | |
Andre
2014/07/17 17:56:16
How about (firstView == [[firstView window] conten
erikchen
2014/07/17 18:22:45
Seems reasonable to me. Done.
| |
27 return NSOrderedAscending; | |
28 if ([secondView isKindOfClass:[FullSizeContentView class]]) | |
29 return NSOrderedDescending; | |
30 NSUInteger index1 = [subviews indexOfObject:firstView]; | |
31 NSUInteger index2 = [subviews indexOfObject:secondView]; | |
32 if (index1 < index2) | |
33 return NSOrderedAscending; | |
34 return NSOrderedDescending; | |
Andre
2014/07/17 17:56:16
Suggestion: return (index1 < index2) ? NSOrderedAs
erikchen
2014/07/17 18:22:44
I see that you are a fan of the ternary operator.
| |
35 } | |
36 | |
37 } // namespace | |
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 backing:bufferingType | 97 backing:bufferingType |
75 defer:deferCreation]; | 98 defer:deferCreation]; |
76 if (self) { | 99 if (self) { |
77 if ([VersionIndependentWindow | 100 if ([VersionIndependentWindow |
78 shouldUseFullSizeContentViewForStyle:windowStyle]) { | 101 shouldUseFullSizeContentViewForStyle:windowStyle]) { |
79 chromeWindowView_.reset([[FullSizeContentView alloc] init]); | 102 chromeWindowView_.reset([[FullSizeContentView alloc] init]); |
80 [chromeWindowView_ | 103 [chromeWindowView_ |
81 setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; | 104 setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
82 [chromeWindowView_ setFrame:[[[self contentView] superview] bounds]]; | 105 [chromeWindowView_ setFrame:[[[self contentView] superview] bounds]]; |
83 [self setContentView:chromeWindowView_]; | 106 [self setContentView:chromeWindowView_]; |
107 | |
108 // Move the content view to the back. | |
109 // In Yosemite, the content view takes up the full size of the window, | |
110 // and when it is in front of the zoom/fullscreen button, alt-clicking | |
111 // the button has the wrong effect. | |
112 // Adding subviews to the NSThemeFrame provokes a warning in Yosemite, so | |
113 // we sort the subviews in place. | |
114 // http://crbug.com/393808 | |
115 | |
116 NSView* superview = [[self contentView] superview]; | |
117 NSArray* subviews = [[[superview subviews] copy] autorelease]; | |
Andre
2014/07/17 17:56:16
Use scoped_nsobject?
erikchen
2014/07/17 18:22:44
Done.
| |
118 [superview sortSubviewsUsingFunction:&ReorderContentViewToBack | |
119 context:subviews]; | |
84 } | 120 } |
85 } | 121 } |
86 return self; | 122 return self; |
87 } | 123 } |
88 | 124 |
89 #pragma mark - Private Methods | 125 #pragma mark - Private Methods |
90 | 126 |
91 + (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle { | 127 + (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle { |
92 return (windowStyle & NSTitledWindowMask) && base::mac::IsOSYosemiteOrLater(); | 128 return (windowStyle & NSTitledWindowMask) && base::mac::IsOSYosemiteOrLater(); |
93 } | 129 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 return [super contentRectForFrameRect:fRect styleMask:aStyle]; | 176 return [super contentRectForFrameRect:fRect styleMask:aStyle]; |
141 } | 177 } |
142 | 178 |
143 - (NSRect)contentRectForFrameRect:(NSRect)frameRect { | 179 - (NSRect)contentRectForFrameRect:(NSRect)frameRect { |
144 if (chromeWindowView_) | 180 if (chromeWindowView_) |
145 return frameRect; | 181 return frameRect; |
146 return [super contentRectForFrameRect:frameRect]; | 182 return [super contentRectForFrameRect:frameRect]; |
147 } | 183 } |
148 | 184 |
149 @end | 185 @end |
OLD | NEW |