#import "chrome/browser/ui/cocoa/browser_window_layout.h"
#import "chrome/browser/ui/cocoa/fast_resize_view.h"
#import "chrome/browser/ui/cocoa/framed_browser_window.h"
+#import "chrome/browser/ui/cocoa/tabs/tab_strip_background_view.h"
#import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h"
#import "chrome/browser/ui/cocoa/themed_window.h"
#import "chrome/browser/ui/cocoa/version_independent_window.h"
#import "ui/base/cocoa/focus_tracker.h"
#include "ui/base/theme_provider.h"
-@interface TabWindowController(PRIVATE)
+@interface TabWindowController ()
- (void)setUseOverlay:(BOOL)useOverlay;
+
+// The tab strip background view should always be inserted as the back-most
+// subview of the root view. It cannot be a subview of the contentView, as that
+// would cause it to become layer backed, which would cause it to draw on top
+// of non-layer backed content like the window controls.
+- (void)insertTabStripBackgroundViewIntoWindow:(NSWindow*)window;
@end
@interface TabWindowOverlayWindow : NSWindow
@implementation TabWindowController
- (id)initTabWindowControllerWithTabStrip:(BOOL)hasTabStrip {
- NSRect contentRect = NSMakeRect(60, 229, 750, 600);
+ const CGFloat kDefaultWidth = 750;
+ const CGFloat kDefaultHeight = 600;
+
+ NSRect contentRect = NSMakeRect(60, 229, kDefaultWidth, kDefaultHeight);
base::scoped_nsobject<FramedBrowserWindow> window(
[[FramedBrowserWindow alloc] initWithContentRect:contentRect
hasTabStrip:hasTabStrip]);
- [self moveContentViewToBack:[window contentView]];
[window setReleasedWhenClosed:YES];
[window setAutorecalculatesKeyViewLoop:YES];
if ((self = [super initWithWindow:window])) {
[[self window] setDelegate:self];
- tabContentArea_.reset([[FastResizeView alloc] initWithFrame:
- NSMakeRect(0, 0, 750, 600)]);
+ chromeContentView_.reset([[NSView alloc]
+ initWithFrame:NSMakeRect(0, 0, kDefaultWidth, kDefaultHeight)]);
+ [chromeContentView_
+ setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
+ [chromeContentView_ setWantsLayer:YES];
+ [[[self window] contentView] addSubview:chromeContentView_];
+
+ tabContentArea_.reset(
+ [[FastResizeView alloc] initWithFrame:[chromeContentView_ bounds]]);
[tabContentArea_ setAutoresizingMask:NSViewWidthSizable |
NSViewHeightSizable];
- [[[self window] contentView] addSubview:tabContentArea_];
+ [chromeContentView_ addSubview:tabContentArea_];
+
+ // tabStripBackgroundView_ draws the theme image behind the tab strip area.
+ // When making a tab dragging window (setUseOverlay:), this view stays in
+ // the parent window so that it can be translucent, while the tab strip view
+ // moves to the child window and stays opaque.
+ NSView* windowView = [window cr_windowView];
+ tabStripBackgroundView_.reset([[TabStripBackgroundView alloc]
+ initWithFrame:NSMakeRect(0,
+ NSMaxY([windowView bounds]) -
+ kBrowserFrameViewPaintHeight,
+ NSWidth([windowView bounds]),
+ kBrowserFrameViewPaintHeight)]);
+ [tabStripBackgroundView_
+ setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin];
+ [self insertTabStripBackgroundViewIntoWindow:window];
+
+ [self moveContentViewToBack:[window contentView]];
tabStripView_.reset([[TabStripView alloc]
- initWithFrame:NSMakeRect(0, 0, 750, chrome::kTabStripHeight)]);
+ initWithFrame:NSMakeRect(
+ 0, 0, kDefaultWidth, chrome::kTabStripHeight)]);
[tabStripView_ setAutoresizingMask:NSViewWidthSizable |
NSViewMinYMargin];
if (hasTabStrip)
return self;
}
+- (NSView*)tabStripBackgroundView {
+ return tabStripBackgroundView_;
+}
+
- (TabStripView*)tabStripView {
return tabStripView_;
}
return tabContentArea_;
}
+- (NSView*)chromeContentView {
+ return chromeContentView_;
+}
+
- (void)removeOverlay {
[self setUseOverlay:NO];
if (closeDeferred_) {
[overlayWindow_ setBackgroundColor:[NSColor clearColor]];
[overlayWindow_ setOpaque:NO];
[overlayWindow_ setDelegate:self];
+ [[overlayWindow_ contentView] setWantsLayer:YES];
- originalContentView_ = [window contentView];
+ originalContentView_ = self.chromeContentView;
[window addChildWindow:overlayWindow_ ordered:NSWindowAbove];
// Explicitly set the responder to be nil here (for restoring later).
// places. The TabStripView always needs to be in front of the window's
// content view and therefore it should always be added after the content
// view is set.
- [window setContentView:originalContentView_];
- [self moveContentViewToBack:originalContentView_];
+ [[window contentView] addSubview:originalContentView_
+ positioned:NSWindowBelow
+ relativeTo:nil];
+ originalContentView_.frame = [[window contentView] bounds];
[self insertTabStripView:[self tabStripView] intoWindow:window];
[[window cr_windowView] updateTrackingAreas];
base::scoped_nsobject<NSView> contentView([cv retain]);
NSView* superview = [contentView superview];
[contentView removeFromSuperview];
- [superview addSubview:contentView positioned:NSWindowBelow relativeTo:nil];
+ DCHECK(tabStripBackgroundView_);
+ if (superview == [tabStripBackgroundView_ superview]) {
+ [superview addSubview:contentView
+ positioned:NSWindowAbove
+ relativeTo:tabStripBackgroundView_];
+ } else {
+ [superview addSubview:contentView positioned:NSWindowBelow relativeTo:nil];
+ }
}
- (void)insertTabStripView:(NSView*)tabStripView intoWindow:(NSWindow*)window {
}
}
+- (void)insertTabStripBackgroundViewIntoWindow:(NSWindow*)window {
+ DCHECK(tabStripBackgroundView_);
+ NSView* rootView = [[window contentView] superview];
+ [rootView addSubview:tabStripBackgroundView_
+ positioned:NSWindowBelow
+ relativeTo:nil];
+}
+
// Called when the size of the window content area has changed. Override to
// position specific views. Base class implementation does nothing.
- (void)layoutSubviews {