- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / fast_resize_view.mm
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
19 - (void)setFastResizeMode:(BOOL)fastResizeMode {
20   if (fastResizeMode_ == fastResizeMode)
21     return;
22
23   fastResizeMode_ = fastResizeMode;
24
25   // Force a relayout when coming out of fast resize mode.
26   if (!fastResizeMode_)
27     [self layoutSubviews];
28
29   [self setNeedsDisplay:YES];
30 }
31
32 - (void)resizeSubviewsWithOldSize:(NSSize)oldSize {
33   [self layoutSubviews];
34 }
35
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.
40   if (!fastResizeMode_)
41     return;
42
43   [[NSColor whiteColor] set];
44   NSRectFill(dirtyRect);
45 }
46
47 @end
48
49 @implementation FastResizeView (PrivateMethods)
50
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
54   // layout is needed.
55   NSArray* subviews = [self subviews];
56   DCHECK([subviews count] <= 1);
57   if ([subviews count] < 1)
58     return;
59
60   NSView* subview = [subviews objectAtIndex:0];
61   NSRect bounds = [self bounds];
62
63   if (fastResizeMode_) {
64     NSRect frame = [subview frame];
65     frame.origin.x = 0;
66     frame.origin.y = NSHeight(bounds) - NSHeight(frame);
67     [subview setFrame:frame];
68   } else {
69     [subview setFrame:bounds];
70   }
71 }
72
73 @end