Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Side by Side Diff: chrome/browser/ui/cocoa/version_independent_window.mm

Issue 420323009: Revert of mac: [Yosemite] Fix bug where zoom button causes fullscreen mode. (reland) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
38 9
39 @interface VersionIndependentWindow () 10 @interface VersionIndependentWindow ()
40 11
41 + (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle; 12 + (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle;
42 13
43 - (NSView*)chromeWindowView; 14 - (NSView*)chromeWindowView;
44 15
45 @end 16 @end
46 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
47 @implementation FullSizeContentView 24 @implementation FullSizeContentView
48 25
49 // 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
50 // 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
51 // shrinking. 28 // shrinking.
52 - (void)setFrameSize:(NSSize)size { 29 - (void)setFrameSize:(NSSize)size {
53 if ([self superview]) 30 if ([self superview])
54 size = [[self superview] bounds].size; 31 size = [[self superview] bounds].size;
55 [super setFrameSize:size]; 32 [super setFrameSize:size];
56 } 33 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 backing:bufferingType 68 backing:bufferingType
92 defer:deferCreation]; 69 defer:deferCreation];
93 if (self) { 70 if (self) {
94 if ([VersionIndependentWindow 71 if ([VersionIndependentWindow
95 shouldUseFullSizeContentViewForStyle:windowStyle]) { 72 shouldUseFullSizeContentViewForStyle:windowStyle]) {
96 chromeWindowView_.reset([[FullSizeContentView alloc] init]); 73 chromeWindowView_.reset([[FullSizeContentView alloc] init]);
97 [chromeWindowView_ 74 [chromeWindowView_
98 setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; 75 setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
99 [self setContentView:chromeWindowView_]; 76 [self setContentView:chromeWindowView_];
100 [chromeWindowView_ setFrame:[[[self contentView] superview] bounds]]; 77 [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()];
113 } 78 }
114 } 79 }
115 return self; 80 return self;
116 } 81 }
117 82
118 #pragma mark - Private Methods 83 #pragma mark - Private Methods
119 84
120 + (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle { 85 + (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle {
121 return (windowStyle & NSTitledWindowMask) && base::mac::IsOSYosemiteOrLater(); 86 return (windowStyle & NSTitledWindowMask) && base::mac::IsOSYosemiteOrLater();
122 } 87 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 return [super contentRectForFrameRect:fRect styleMask:aStyle]; 134 return [super contentRectForFrameRect:fRect styleMask:aStyle];
170 } 135 }
171 136
172 - (NSRect)contentRectForFrameRect:(NSRect)frameRect { 137 - (NSRect)contentRectForFrameRect:(NSRect)frameRect {
173 if (chromeWindowView_) 138 if (chromeWindowView_)
174 return frameRect; 139 return frameRect;
175 return [super contentRectForFrameRect:frameRect]; 140 return [super contentRectForFrameRect:frameRect];
176 } 141 }
177 142
178 @end 143 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698