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

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

Issue 646703002: mac: Use a full-size content view (reland 1). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments from avi. Created 6 years, 2 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 | « chrome/browser/ui/cocoa/version_independent_window.h ('k') | chrome/chrome_tests_unit.gypi » ('j') | 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/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/mac/mac_util.h" 9 #include "base/mac/mac_util.h"
10 #include "chrome/common/chrome_switches.h" 10 #include "chrome/common/chrome_switches.h"
11 11
12 @interface VersionIndependentWindow () 12 @interface VersionIndependentWindow ()
13 13
14 + (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle; 14 + (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle;
15 15
16 - (NSView*)chromeWindowView; 16 - (NSView*)chromeWindowView;
17 17
18 @end 18 @end
19 19
20 // This view always takes the size of its superview. It is intended to be used 20 // This view always takes the size of its superview. It is intended to be used
21 // as a NSWindow's contentView. It is needed because NSWindow's implementation 21 // as a NSWindow's contentView. It is needed because NSWindow's implementation
22 // explicitly resizes the contentView at inopportune times. 22 // explicitly resizes the contentView at inopportune times.
23 @interface FullSizeContentView : NSView 23 @interface FullSizeContentView : NSView
24 @end 24 @end
25 25
26 @implementation FullSizeContentView 26 @implementation FullSizeContentView
27 27
28 // This method is directly called by NSWindow during a window resize on OSX 28 // This method is directly called by AppKit during a live window resize.
29 // 10.10.0, beta 2. We must override it to prevent the content view from 29 // Override it to prevent the content view from shrinking.
30 // shrinking.
31 - (void)setFrameSize:(NSSize)size { 30 - (void)setFrameSize:(NSSize)size {
32 if ([self superview]) 31 if ([self superview])
33 size = [[self superview] bounds].size; 32 size = [[self superview] bounds].size;
34 [super setFrameSize:size]; 33 [super setFrameSize:size];
35 } 34 }
36 35
37 // The contentView gets moved around during certain full-screen operations.
38 // This is less than ideal, and should eventually be removed.
39 - (void)viewDidMoveToSuperview {
40 [self setFrame:[[self superview] bounds]];
41 }
42
43 @end 36 @end
44 37
45 @implementation NSWindow (VersionIndependentWindow) 38 @implementation NSWindow (VersionIndependentWindow)
46 39
47 - (NSView*)cr_windowView { 40 - (NSView*)cr_windowView {
48 if ([self isKindOfClass:[VersionIndependentWindow class]]) { 41 if ([self isKindOfClass:[VersionIndependentWindow class]]) {
49 VersionIndependentWindow* window = 42 VersionIndependentWindow* window =
50 static_cast<VersionIndependentWindow*>(self); 43 static_cast<VersionIndependentWindow*>(self);
51 NSView* chromeWindowView = [window chromeWindowView]; 44 NSView* chromeWindowView = [window chromeWindowView];
52 if (chromeWindowView) 45 if (chromeWindowView)
(...skipping 11 matching lines...) Expand all
64 57
65 - (instancetype)init { 58 - (instancetype)init {
66 NOTREACHED(); 59 NOTREACHED();
67 return nil; 60 return nil;
68 } 61 }
69 62
70 - (instancetype)initWithContentRect:(NSRect)contentRect 63 - (instancetype)initWithContentRect:(NSRect)contentRect
71 styleMask:(NSUInteger)windowStyle 64 styleMask:(NSUInteger)windowStyle
72 backing:(NSBackingStoreType)bufferingType 65 backing:(NSBackingStoreType)bufferingType
73 defer:(BOOL)deferCreation { 66 defer:(BOOL)deferCreation {
67 return [self initWithContentRect:contentRect
68 styleMask:windowStyle
69 backing:bufferingType
70 defer:deferCreation
71 wantsViewsOverTitlebar:NO];
72 }
73
74 - (instancetype)initWithContentRect:(NSRect)contentRect
75 styleMask:(NSUInteger)windowStyle
76 backing:(NSBackingStoreType)bufferingType
77 defer:(BOOL)deferCreation
78 wantsViewsOverTitlebar:(BOOL)wantsViewsOverTitlebar {
74 self = [super initWithContentRect:contentRect 79 self = [super initWithContentRect:contentRect
75 styleMask:windowStyle 80 styleMask:windowStyle
76 backing:bufferingType 81 backing:bufferingType
77 defer:deferCreation]; 82 defer:deferCreation];
78 if (self) { 83 if (self) {
79 if ([VersionIndependentWindow 84 if (wantsViewsOverTitlebar &&
80 shouldUseFullSizeContentViewForStyle:windowStyle]) { 85 [VersionIndependentWindow
86 shouldUseFullSizeContentViewForStyle:windowStyle]) {
81 chromeWindowView_.reset([[FullSizeContentView alloc] init]); 87 chromeWindowView_.reset([[FullSizeContentView alloc] init]);
82 [chromeWindowView_ 88 [chromeWindowView_
83 setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; 89 setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
84 [chromeWindowView_ setFrame:[[[self contentView] superview] bounds]];
85 [self setContentView:chromeWindowView_]; 90 [self setContentView:chromeWindowView_];
91 [chromeWindowView_ setFrame:[[chromeWindowView_ superview] bounds]];
86 } 92 }
87 } 93 }
88 return self; 94 return self;
89 } 95 }
90 96
91 #pragma mark - Private Methods 97 #pragma mark - Private Methods
92 98
93 + (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle { 99 + (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle {
94 // TODO(erikchen): Once OSX Yosemite is released, consider removing this 100 return windowStyle & NSTitledWindowMask;
95 // class entirely.
96 // http://crbug.com/398574
97 if (!CommandLine::ForCurrentProcess()->HasSwitch(
98 switches::kEnableFullSizeContentView))
99 return NO;
100 return (windowStyle & NSTitledWindowMask) && base::mac::IsOSYosemiteOrLater();
101 } 101 }
102 102
103 - (NSView*)chromeWindowView { 103 - (NSView*)chromeWindowView {
104 return chromeWindowView_; 104 return chromeWindowView_;
105 } 105 }
106 106
107 #pragma mark - NSWindow Overrides 107 #pragma mark - NSWindow Overrides
108 108
109 #ifndef NDEBUG
110
111 - (void)setContentSize:(NSSize)size {
112 DCHECK(!chromeWindowView_);
113 [super setContentSize:size];
114 }
115
116 - (void)setContentMinSize:(NSSize)size {
117 DCHECK(!chromeWindowView_);
118 [super setContentMinSize:size];
119 }
120
121 - (void)setContentMaxSize:(NSSize)size {
122 DCHECK(!chromeWindowView_);
123 [super setContentMaxSize:size];
124 }
125
126 - (void)setContentAspectRatio:(NSSize)ratio {
127 DCHECK(!chromeWindowView_);
128 [super setContentAspectRatio:ratio];
129 }
130
131 #endif // NDEBUG
132
133 + (NSRect)frameRectForContentRect:(NSRect)cRect styleMask:(NSUInteger)aStyle { 109 + (NSRect)frameRectForContentRect:(NSRect)cRect styleMask:(NSUInteger)aStyle {
134 if ([self shouldUseFullSizeContentViewForStyle:aStyle]) 110 if ([self shouldUseFullSizeContentViewForStyle:aStyle])
135 return cRect; 111 return cRect;
136 return [super frameRectForContentRect:cRect styleMask:aStyle]; 112 return [super frameRectForContentRect:cRect styleMask:aStyle];
137 } 113 }
138 114
139 - (NSRect)frameRectForContentRect:(NSRect)contentRect { 115 - (NSRect)frameRectForContentRect:(NSRect)contentRect {
140 if (chromeWindowView_) 116 if (chromeWindowView_)
141 return contentRect; 117 return contentRect;
142 return [super frameRectForContentRect:contentRect]; 118 return [super frameRectForContentRect:contentRect];
143 } 119 }
144 120
145 + (NSRect)contentRectForFrameRect:(NSRect)fRect styleMask:(NSUInteger)aStyle { 121 + (NSRect)contentRectForFrameRect:(NSRect)fRect styleMask:(NSUInteger)aStyle {
146 if ([self shouldUseFullSizeContentViewForStyle:aStyle]) 122 if ([self shouldUseFullSizeContentViewForStyle:aStyle])
147 return fRect; 123 return fRect;
148 return [super contentRectForFrameRect:fRect styleMask:aStyle]; 124 return [super contentRectForFrameRect:fRect styleMask:aStyle];
149 } 125 }
150 126
151 - (NSRect)contentRectForFrameRect:(NSRect)frameRect { 127 - (NSRect)contentRectForFrameRect:(NSRect)frameRect {
152 if (chromeWindowView_) 128 if (chromeWindowView_)
153 return frameRect; 129 return frameRect;
154 return [super contentRectForFrameRect:frameRect]; 130 return [super contentRectForFrameRect:frameRect];
155 } 131 }
156 132
157 @end 133 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/version_independent_window.h ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698