1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #import <Cocoa/Cocoa.h>
6 #import "chrome/browser/ui/cocoa/fast_resize_view.h"
8 #include "base/logging.h"
10 @interface FastResizeView (PrivateMethods)
11 // Lays out this views subviews. If fast resize mode is on, does not resize any
12 // subviews and instead pegs them to the top left. If fast resize mode is off,
13 // sets the subviews' frame to be equal to this view's bounds.
14 - (void)layoutSubviews;
17 @implementation FastResizeView
19 - (void)setFastResizeMode:(BOOL)fastResizeMode {
20 if (fastResizeMode_ == fastResizeMode)
23 fastResizeMode_ = fastResizeMode;
25 // Force a relayout when coming out of fast resize mode.
27 [self layoutSubviews];
29 [self setNeedsDisplay:YES];
32 - (void)resizeSubviewsWithOldSize:(NSSize)oldSize {
33 [self layoutSubviews];
36 - (void)drawRect:(NSRect)dirtyRect {
37 // If we are in fast resize mode, our subviews may not completely cover our
38 // bounds, so we fill with white. If we are not in fast resize mode, we do
39 // not need to draw anything.
43 [[NSColor whiteColor] set];
44 NSRectFill(dirtyRect);
49 @implementation FastResizeView (PrivateMethods)
51 - (void)layoutSubviews {
52 // There should never be more than one subview. There can be zero, if we are
53 // in the process of switching tabs or closing the window. In those cases, no
55 NSArray* subviews = [self subviews];
56 DCHECK([subviews count] <= 1);
57 if ([subviews count] < 1)
60 NSView* subview = [subviews objectAtIndex:0];
61 NSRect bounds = [self bounds];
63 if (fastResizeMode_) {
64 NSRect frame = [subview frame];
66 frame.origin.y = NSHeight(bounds) - NSHeight(frame);
67 [subview setFrame:frame];
69 [subview setFrame:bounds];