• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4
5#import <Cocoa/Cocoa.h>
6#import "chrome/browser/ui/cocoa/fast_resize_view.h"
7
8#include "base/logging.h"
9
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;
15@end
16
17@implementation FastResizeView
18- (void)setFastResizeMode:(BOOL)fastResizeMode {
19  fastResizeMode_ = fastResizeMode;
20
21  // Force a relayout when coming out of fast resize mode.
22  if (!fastResizeMode_)
23    [self layoutSubviews];
24}
25
26- (void)resizeSubviewsWithOldSize:(NSSize)oldSize {
27  [self layoutSubviews];
28}
29
30- (void)drawRect:(NSRect)dirtyRect {
31  // If we are in fast resize mode, our subviews may not completely cover our
32  // bounds, so we fill with white.  If we are not in fast resize mode, we do
33  // not need to draw anything.
34  if (fastResizeMode_) {
35    [[NSColor whiteColor] set];
36    NSRectFill(dirtyRect);
37  }
38}
39
40
41@end
42
43@implementation FastResizeView (PrivateMethods)
44- (void)layoutSubviews {
45  // There should never be more than one subview.  There can be zero, if we are
46  // in the process of switching tabs or closing the window.  In those cases, no
47  // layout is needed.
48  NSArray* subviews = [self subviews];
49  DCHECK([subviews count] <= 1);
50  if ([subviews count] < 1)
51    return;
52
53  NSView* subview = [subviews objectAtIndex:0];
54  NSRect bounds = [self bounds];
55
56  if (fastResizeMode_) {
57    NSRect frame = [subview frame];
58    frame.origin.x = 0;
59    frame.origin.y = NSHeight(bounds) - NSHeight(frame);
60    [subview setFrame:frame];
61  } else {
62    [subview setFrame:bounds];
63  }
64}
65@end
66