blob: 97c1d82fbb653912ab06059a7275cee6bd64f695 (
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
|
// Copyright (c) 2009 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 <Cocoa/Cocoa.h>
#import "chrome/browser/cocoa/fast_resize_view.h"
#include "base/logging.h"
@interface FastResizeView (PrivateMethods)
// Lays out this views subviews. If fast resize mode is on, does not resize any
// subviews and instead pegs them to the top left. If fast resize mode is off,
// sets the subviews' frame to be equal to this view's bounds.
- (void)layoutSubviews;
@end
@implementation FastResizeView
- (void)setFastResizeMode:(BOOL)fastResizeMode {
fastResizeMode_ = fastResizeMode;
// Force a relayout when coming out of fast resize mode.
if (!fastResizeMode_)
[self layoutSubviews];
}
- (void)resizeSubviewsWithOldSize:(NSSize)oldSize {
[self layoutSubviews];
}
- (void)drawRect:(NSRect)dirtyRect {
// If we are in fast resize mode, our subviews may not completely cover our
// bounds, so we fill with white. If we are not in fast resize mode, we do
// not need to draw anything.
if (fastResizeMode_) {
[[NSColor whiteColor] set];
NSRectFill(dirtyRect);
}
}
@end
@implementation FastResizeView (PrivateMethods)
- (void)layoutSubviews {
// There should never be more than one subview. There can be zero, if we are
// in the process of switching tabs or closing the window. In those cases, no
// layout is needed.
NSArray* subviews = [self subviews];
DCHECK([subviews count] <= 1);
if ([subviews count] < 1)
return;
NSView* subview = [subviews objectAtIndex:0];
NSRect bounds = [self bounds];
if (fastResizeMode_) {
NSRect frame = [subview frame];
frame.origin.x = 0;
frame.origin.y = NSHeight(bounds) - NSHeight(frame);
[subview setFrame:frame];
} else {
[subview setFrame:bounds];
}
}
@end
|