| 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 @synthesize tabContentArea = tabContentArea_; |
| 17 | 17 |
| 18 - (id)initWithWindow:(NSWindow *)window { | 18 - (id)initWithWindow:(NSWindow*)window { |
| 19 if ((self = [super initWithWindow:window]) != nil) { | 19 if ((self = [super initWithWindow:window]) != nil) { |
| 20 lockedTabs_.reset([[NSMutableSet alloc] initWithCapacity:10]); | 20 lockedTabs_.reset([[NSMutableSet alloc] initWithCapacity:10]); |
| 21 } | 21 } |
| 22 return self; | 22 return self; |
| 23 } | 23 } |
| 24 | 24 |
| 25 - (void)windowDidLoad { | 25 - (void)windowDidLoad { |
| 26 if ([self isNormalWindow]) { | 26 if ([self isNormalWindow]) { |
| 27 // Place the tab bar above the content box and add it to the view hierarchy | 27 // Place the tab bar above the content box and add it to the view hierarchy |
| 28 // as a sibling of the content view so it can overlap with the window frame. | 28 // as a sibling of the content view so it can overlap with the window frame. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 if (useOverlay) { | 67 if (useOverlay) { |
| 68 [[[overlayWindow_ contentView] superview] addSubview:[self tabStripView]]; | 68 [[[overlayWindow_ contentView] superview] addSubview:[self tabStripView]]; |
| 69 // Add the original window's content view as a subview of the overlay | 69 // Add the original window's content view as a subview of the overlay |
| 70 // window's content view. We cannot simply use setContentView: here because | 70 // window's content view. We cannot simply use setContentView: here because |
| 71 // the overlay window has a different content size (due to it being | 71 // the overlay window has a different content size (due to it being |
| 72 // borderless). | 72 // borderless). |
| 73 [[overlayWindow_ contentView] addSubview:cachedContentView_]; | 73 [[overlayWindow_ contentView] addSubview:cachedContentView_]; |
| 74 } else { | 74 } else { |
| 75 [[[[self window] contentView] superview] addSubview:[self tabStripView]]; | 75 [[[[self window] contentView] superview] addSubview:[self tabStripView]]; |
| 76 [[self window] setContentView:cachedContentView_]; | 76 [[self window] setContentView:cachedContentView_]; |
| 77 [[[[self window] contentView] superview] updateTrackingAreas]; |
| 77 } | 78 } |
| 78 } | 79 } |
| 79 | 80 |
| 80 // If |useOverlay| is YES, creates a new overlay window and puts the tab strip | 81 // If |useOverlay| is YES, creates a new overlay window and puts the tab strip |
| 81 // and the content area inside of it. This allows it to have a different opacity | 82 // and the content area inside of it. This allows it to have a different opacity |
| 82 // from the title bar. If NO, returns everything to the previous state and | 83 // from the title bar. If NO, returns everything to the previous state and |
| 83 // destroys the overlay window until it's needed again. The tab strip and window | 84 // destroys the overlay window until it's needed again. The tab strip and window |
| 84 // contents are returned to the original window. | 85 // contents are returned to the original window. |
| 85 - (void)setUseOverlay:(BOOL)useOverlay { | 86 - (void)setUseOverlay:(BOOL)useOverlay { |
| 86 [NSObject cancelPreviousPerformRequestsWithTarget:self | 87 [NSObject cancelPreviousPerformRequestsWithTarget:self |
| 87 selector:@selector(removeOverlay) | 88 selector:@selector(removeOverlay) |
| 88 object:nil]; | 89 object:nil]; |
| 90 NSWindow* window = [self window]; |
| 89 if (useOverlay && !overlayWindow_) { | 91 if (useOverlay && !overlayWindow_) { |
| 90 DCHECK(!cachedContentView_); | 92 DCHECK(!cachedContentView_); |
| 91 overlayWindow_ = [[NSPanel alloc] initWithContentRect:[[self window] frame] | 93 overlayWindow_ = [[NSPanel alloc] initWithContentRect:[window frame] |
| 92 styleMask:NSBorderlessWindowMask | 94 styleMask:NSBorderlessWindowMask |
| 93 backing:NSBackingStoreBuffered | 95 backing:NSBackingStoreBuffered |
| 94 defer:YES]; | 96 defer:YES]; |
| 95 [overlayWindow_ setTitle:@"overlay"]; | 97 [overlayWindow_ setTitle:@"overlay"]; |
| 96 [overlayWindow_ setBackgroundColor:[NSColor clearColor]]; | 98 [overlayWindow_ setBackgroundColor:[NSColor clearColor]]; |
| 97 [overlayWindow_ setOpaque:NO]; | 99 [overlayWindow_ setOpaque:NO]; |
| 98 [overlayWindow_ setDelegate:self]; | 100 [overlayWindow_ setDelegate:self]; |
| 99 cachedContentView_ = [[self window] contentView]; | 101 cachedContentView_ = [window contentView]; |
| 100 [self moveViewsBetweenWindowAndOverlay:useOverlay]; | 102 [self moveViewsBetweenWindowAndOverlay:useOverlay]; |
| 101 [[self window] addChildWindow:overlayWindow_ ordered:NSWindowAbove]; | 103 [window addChildWindow:overlayWindow_ ordered:NSWindowAbove]; |
| 102 [overlayWindow_ orderFront:nil]; | 104 [overlayWindow_ orderFront:nil]; |
| 103 } else if (!useOverlay && overlayWindow_) { | 105 } else if (!useOverlay && overlayWindow_) { |
| 104 DCHECK(cachedContentView_); | 106 DCHECK(cachedContentView_); |
| 105 [[self window] setContentView:cachedContentView_]; | 107 [window setContentView:cachedContentView_]; |
| 106 [self moveViewsBetweenWindowAndOverlay:useOverlay]; | 108 [self moveViewsBetweenWindowAndOverlay:useOverlay]; |
| 107 [[self window] makeFirstResponder:cachedContentView_]; | 109 [window makeFirstResponder:cachedContentView_]; |
| 108 [[self window] display]; | 110 [window display]; |
| 109 [[self window] removeChildWindow:overlayWindow_]; | 111 [window removeChildWindow:overlayWindow_]; |
| 110 [overlayWindow_ orderOut:nil]; | 112 [overlayWindow_ orderOut:nil]; |
| 111 [overlayWindow_ release]; | 113 [overlayWindow_ release]; |
| 112 overlayWindow_ = nil; | 114 overlayWindow_ = nil; |
| 113 cachedContentView_ = nil; | 115 cachedContentView_ = nil; |
| 114 } else { | 116 } else { |
| 115 NOTREACHED(); | 117 NOTREACHED(); |
| 116 } | 118 } |
| 117 } | 119 } |
| 118 | 120 |
| 119 - (NSWindow*)overlayWindow { | 121 - (NSWindow*)overlayWindow { |
| 120 return overlayWindow_; | 122 return overlayWindow_; |
| 121 } | 123 } |
| 122 | 124 |
| 123 - (BOOL)canReceiveFrom:(TabWindowController*)source { | 125 - (BOOL)canReceiveFrom:(TabWindowController*)source { |
| 124 // subclass must implement | 126 // subclass must implement |
| 125 NOTIMPLEMENTED(); | 127 NOTIMPLEMENTED(); |
| 126 return NO; | 128 return NO; |
| 127 } | 129 } |
| 128 | 130 |
| 129 - (void)moveTabView:(NSView*)view | 131 - (void)moveTabView:(NSView*)view |
| 130 fromController:(TabWindowController*)dragController { | 132 fromController:(TabWindowController*)dragController { |
| 131 NOTIMPLEMENTED(); | 133 NOTIMPLEMENTED(); |
| 132 } | 134 } |
| 133 | 135 |
| 134 - (NSView *)selectedTabView { | 136 - (NSView*)selectedTabView { |
| 135 NOTIMPLEMENTED(); | 137 NOTIMPLEMENTED(); |
| 136 return nil; | 138 return nil; |
| 137 } | 139 } |
| 138 | 140 |
| 139 - (void)layoutTabs { | 141 - (void)layoutTabs { |
| 140 // subclass must implement | 142 // subclass must implement |
| 141 NOTIMPLEMENTED(); | 143 NOTIMPLEMENTED(); |
| 142 } | 144 } |
| 143 | 145 |
| 144 - (TabWindowController*)detachTabToNewWindow:(TabView*)tabView { | 146 - (TabWindowController*)detachTabToNewWindow:(TabView*)tabView { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 } | 204 } |
| 203 | 205 |
| 204 // Tell the window that it needs to call performClose: as soon as the current | 206 // Tell the window that it needs to call performClose: as soon as the current |
| 205 // drag is complete. This prevents a window (and its overlay) from going away | 207 // drag is complete. This prevents a window (and its overlay) from going away |
| 206 // during a drag. | 208 // during a drag. |
| 207 - (void)deferPerformClose { | 209 - (void)deferPerformClose { |
| 208 closeDeferred_ = YES; | 210 closeDeferred_ = YES; |
| 209 } | 211 } |
| 210 | 212 |
| 211 @end | 213 @end |
| OLD | NEW |