Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "chrome/browser/cocoa/tab_window_controller.h" | 5 #import "chrome/browser/cocoa/tab_window_controller.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #import "chrome/browser/cocoa/tab_strip_view.h" | 8 #import "chrome/browser/cocoa/tab_strip_view.h" |
| 9 | 9 |
| 10 @interface TabWindowController(PRIVATE) | 10 @interface TabWindowController(PRIVATE) |
| 11 - (void)setUseOverlay:(BOOL)useOverlay; | 11 - (void)setUseOverlay:(BOOL)useOverlay; |
| 12 @end | 12 @end |
| 13 | 13 |
| 14 @implementation TabWindowController | 14 @implementation TabWindowController |
| 15 @synthesize tabStripView = tabStripView_; | 15 @synthesize tabStripView = tabStripView_; |
| 16 @synthesize tabContentArea = tabContentArea_; | |
| 16 | 17 |
| 17 - (void)windowDidLoad { | 18 - (void)windowDidLoad { |
| 18 // Place the tab bar above the content box and add it to the view hierarchy | 19 // Place the tab bar above the content box and add it to the view hierarchy |
| 19 // as a sibling of the content view so it can overlap with the window frame. | 20 // as a sibling of the content view so it can overlap with the window frame. |
| 20 NSRect tabFrame = [contentBox_ frame]; | 21 NSRect tabFrame = [tabContentArea_ frame]; |
|
TVL
2009/04/09 15:53:00
you could DCheck the class requirements on tabCont
pink (ping after 24hrs)
2009/04/09 16:00:48
do what, though? check that it's not an NSBox? tha
| |
| 21 tabFrame.origin = NSMakePoint(0, NSMaxY(tabFrame)); | 22 tabFrame.origin = NSMakePoint(0, NSMaxY(tabFrame)); |
| 22 tabFrame.size.height = NSHeight([tabStripView_ frame]); | 23 tabFrame.size.height = NSHeight([tabStripView_ frame]); |
| 23 [tabStripView_ setFrame:tabFrame]; | 24 [tabStripView_ setFrame:tabFrame]; |
| 24 [[[[self window] contentView] superview] addSubview:tabStripView_]; | 25 [[[[self window] contentView] superview] addSubview:tabStripView_]; |
| 25 | |
| 26 // tab switching will destroy the content area, so nil this out to ensure | |
| 27 // that nobody tries to use it. | |
| 28 contentBox_ = nil; | |
| 29 } | 26 } |
| 30 | 27 |
| 31 - (void)removeOverlay { | 28 - (void)removeOverlay { |
| 32 [self setUseOverlay:NO]; | 29 [self setUseOverlay:NO]; |
| 33 } | 30 } |
| 34 | 31 |
| 35 - (void)removeOverlayAfterDelay:(NSTimeInterval)delay { | 32 - (void)removeOverlayAfterDelay:(NSTimeInterval)delay { |
| 36 [NSObject cancelPreviousPerformRequestsWithTarget:self | 33 [NSObject cancelPreviousPerformRequestsWithTarget:self |
| 37 selector:@selector(removeOverlay) | 34 selector:@selector(removeOverlay) |
| 38 object:nil]; | 35 object:nil]; |
| 39 [self performSelector:@selector(removeOverlay) | 36 [self performSelector:@selector(removeOverlay) |
| 40 withObject:nil | 37 withObject:nil |
| 41 afterDelay:delay]; | 38 afterDelay:delay]; |
| 42 } | 39 } |
| 43 | 40 |
| 44 - (void)showOverlay { | 41 - (void)showOverlay { |
| 45 [self setUseOverlay:YES]; | 42 [self setUseOverlay:YES]; |
| 46 } | 43 } |
| 47 | 44 |
| 45 - (NSArray*)viewsToMoveToOverlay { | |
| 46 return [NSArray arrayWithObject:[self tabStripView]]; | |
| 47 } | |
| 48 | |
| 49 - (void)moveViewsBetweenWindowAndOverlay:(BOOL)useOverlay { | |
| 50 NSArray* viewsToMove = [self viewsToMoveToOverlay]; | |
| 51 for (NSView* view in viewsToMove) { | |
| 52 // if |useOverlay| is true, we're moving views into the overlay's content | |
| 53 // area. If false, we're moving out of the overlay back into the window's | |
| 54 // content. | |
| 55 NSView* moveTo = useOverlay ? | |
| 56 [overlayWindow_ contentView] : [cachedContentView_ superview]; | |
|
TVL
2009/04/09 15:53:00
move this outside the loop, it doesn't need loop s
pink (ping after 24hrs)
2009/04/09 16:00:48
duh. changed this around at the last minute and mi
| |
| 57 [moveTo addSubview:view]; | |
| 58 } | |
| 59 } | |
| 60 | |
| 48 // If |useOverlay| is YES, creates a new overlay window and puts the tab strip | 61 // If |useOverlay| is YES, creates a new overlay window and puts the tab strip |
| 49 // and the content area inside of it. This allows it to have a different opacity | 62 // and the content area inside of it. This allows it to have a different opacity |
| 50 // from the title bar. If NO, returns everything to the previous state and | 63 // from the title bar. If NO, returns everything to the previous state and |
| 51 // destroys the overlay window until it's needed again. The tab strip and window | 64 // destroys the overlay window until it's needed again. The tab strip and window |
| 52 // contents are returned to the original window. | 65 // contents are returned to the original window. |
| 53 - (void)setUseOverlay:(BOOL)useOverlay { | 66 - (void)setUseOverlay:(BOOL)useOverlay { |
| 54 [NSObject cancelPreviousPerformRequestsWithTarget:self | 67 [NSObject cancelPreviousPerformRequestsWithTarget:self |
| 55 selector:@selector(removeOverlay) | 68 selector:@selector(removeOverlay) |
| 56 object:nil]; | 69 object:nil]; |
| 57 if (useOverlay && !overlayWindow_) { | 70 if (useOverlay && !overlayWindow_) { |
| 58 DCHECK(!cachedContentView_); | 71 DCHECK(!cachedContentView_); |
| 59 overlayWindow_ = [[NSPanel alloc] initWithContentRect:[[self window] frame] | 72 overlayWindow_ = [[NSPanel alloc] initWithContentRect:[[self window] frame] |
| 60 styleMask:NSBorderlessWindowMask | 73 styleMask:NSBorderlessWindowMask |
| 61 backing:NSBackingStoreBuffered | 74 backing:NSBackingStoreBuffered |
| 62 defer:YES]; | 75 defer:YES]; |
| 63 [overlayWindow_ setTitle:@"overlay"]; | 76 [overlayWindow_ setTitle:@"overlay"]; |
| 64 [overlayWindow_ setBackgroundColor:[NSColor clearColor]]; | 77 [overlayWindow_ setBackgroundColor:[NSColor clearColor]]; |
| 65 [overlayWindow_ setOpaque:NO]; | 78 [overlayWindow_ setOpaque:NO]; |
| 66 NSView *contentView = [overlayWindow_ contentView]; | 79 NSView *contentView = [overlayWindow_ contentView]; |
| 67 [contentView addSubview:[self tabStripView]]; | 80 [contentView addSubview:[self tabStripView]]; |
| 68 cachedContentView_ = [[self window] contentView]; | 81 cachedContentView_ = [[self window] contentView]; |
| 69 [contentView addSubview:cachedContentView_]; | 82 [self moveViewsBetweenWindowAndOverlay:useOverlay]; |
| 70 [overlayWindow_ setHasShadow:YES]; | 83 [overlayWindow_ setHasShadow:YES]; |
| 71 [[self window] addChildWindow:overlayWindow_ ordered:NSWindowAbove]; | 84 [[self window] addChildWindow:overlayWindow_ ordered:NSWindowAbove]; |
| 72 [overlayWindow_ orderFront:nil]; | 85 [overlayWindow_ orderFront:nil]; |
| 73 [[self window] setHasShadow:NO]; | 86 [[self window] setHasShadow:NO]; |
| 74 } else if (!useOverlay && overlayWindow_) { | 87 } else if (!useOverlay && overlayWindow_) { |
| 75 DCHECK(cachedContentView_); | 88 DCHECK(cachedContentView_); |
| 76 [[self window] setHasShadow:YES]; | 89 [[self window] setHasShadow:YES]; |
| 77 [[self window] setContentView:cachedContentView_]; | 90 [[self window] setContentView:cachedContentView_]; |
| 78 [[cachedContentView_ superview] addSubview:[self tabStripView]]; | 91 [self moveViewsBetweenWindowAndOverlay:useOverlay]; |
| 79 [[self window] makeFirstResponder:cachedContentView_]; | 92 [[self window] makeFirstResponder:cachedContentView_]; |
| 80 [[self window] display]; | 93 [[self window] display]; |
| 81 [[self window] removeChildWindow:overlayWindow_]; | 94 [[self window] removeChildWindow:overlayWindow_]; |
| 82 [overlayWindow_ orderOut:nil]; | 95 [overlayWindow_ orderOut:nil]; |
| 83 [overlayWindow_ release]; | 96 [overlayWindow_ release]; |
| 84 overlayWindow_ = nil; | 97 overlayWindow_ = nil; |
| 85 cachedContentView_ = nil; | 98 cachedContentView_ = nil; |
| 86 } | 99 } |
| 87 } | 100 } |
| 88 | 101 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 111 NOTIMPLEMENTED(); | 124 NOTIMPLEMENTED(); |
| 112 } | 125 } |
| 113 | 126 |
| 114 - (NSInteger)numberOfTabs { | 127 - (NSInteger)numberOfTabs { |
| 115 // subclass must implement | 128 // subclass must implement |
| 116 NOTIMPLEMENTED(); | 129 NOTIMPLEMENTED(); |
| 117 return 0; | 130 return 0; |
| 118 } | 131 } |
| 119 | 132 |
| 120 @end | 133 @end |
| OLD | NEW |