blob: 24284a490d064e8b943e5d236653544bd56db79c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "chrome/browser/ui/cocoa/version_independent_window.h"
#include "base/logging.h"
#include "base/mac/mac_util.h"
@interface VersionIndependentWindow ()
+ (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle;
- (NSView*)chromeWindowView;
@end
// This view always takes the size of its superview. It is intended to be used
// as a NSWindow's contentView. It is needed because NSWindow's implementation
// explicitly resizes the contentView at inopportune times.
@interface FullSizeContentView : NSView
@end
@implementation FullSizeContentView
// This method is directly called by NSWindow during a window resize on OSX
// 10.10.0, beta 2. We must override it to prevent the content view from
// shrinking.
- (void)setFrameSize:(NSSize)size {
if ([self superview])
size = [[self superview] bounds].size;
[super setFrameSize:size];
}
// The contentView gets moved around during certain full-screen operations.
// This is less than ideal, and should eventually be removed.
- (void)viewDidMoveToSuperview {
[self setFrame:[[self superview] bounds]];
}
@end
@implementation NSWindow (VersionIndependentWindow)
- (NSView*)cr_windowView {
if ([self isKindOfClass:[VersionIndependentWindow class]]) {
VersionIndependentWindow* window =
static_cast<VersionIndependentWindow*>(self);
NSView* chromeWindowView = [window chromeWindowView];
if (chromeWindowView)
return chromeWindowView;
}
return [[self contentView] superview];
}
@end
@implementation VersionIndependentWindow
#pragma mark - Lifecycle
- (instancetype)init {
NOTREACHED();
return nil;
}
- (instancetype)initWithContentRect:(NSRect)contentRect
styleMask:(NSUInteger)windowStyle
backing:(NSBackingStoreType)bufferingType
defer:(BOOL)deferCreation {
self = [super initWithContentRect:contentRect
styleMask:windowStyle
backing:bufferingType
defer:deferCreation];
if (self) {
if ([VersionIndependentWindow
shouldUseFullSizeContentViewForStyle:windowStyle]) {
chromeWindowView_.reset([[FullSizeContentView alloc] init]);
[chromeWindowView_
setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[chromeWindowView_ setFrame:[[[self contentView] superview] bounds]];
[self setContentView:chromeWindowView_];
}
}
return self;
}
#pragma mark - Private Methods
+ (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle {
return (windowStyle & NSTitledWindowMask) && base::mac::IsOSYosemiteOrLater();
}
- (NSView*)chromeWindowView {
return chromeWindowView_;
}
#pragma mark - NSWindow Overrides
#ifndef NDEBUG
- (void)setContentSize:(NSSize)size {
DCHECK(!chromeWindowView_);
[super setContentSize:size];
}
- (void)setContentMinSize:(NSSize)size {
DCHECK(!chromeWindowView_);
[super setContentMinSize:size];
}
- (void)setContentMaxSize:(NSSize)size {
DCHECK(!chromeWindowView_);
[super setContentMaxSize:size];
}
- (void)setContentAspectRatio:(NSSize)ratio {
DCHECK(!chromeWindowView_);
[super setContentAspectRatio:ratio];
}
#endif // NDEBUG
+ (NSRect)frameRectForContentRect:(NSRect)cRect styleMask:(NSUInteger)aStyle {
if ([self shouldUseFullSizeContentViewForStyle:aStyle])
return cRect;
return [super frameRectForContentRect:cRect styleMask:aStyle];
}
- (NSRect)frameRectForContentRect:(NSRect)contentRect {
if (chromeWindowView_)
return contentRect;
return [super frameRectForContentRect:contentRect];
}
+ (NSRect)contentRectForFrameRect:(NSRect)fRect styleMask:(NSUInteger)aStyle {
if ([self shouldUseFullSizeContentViewForStyle:aStyle])
return fRect;
return [super contentRectForFrameRect:fRect styleMask:aStyle];
}
- (NSRect)contentRectForFrameRect:(NSRect)frameRect {
if (chromeWindowView_)
return frameRect;
return [super contentRectForFrameRect:frameRect];
}
@end
|