Upstream version 10.38.220.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / tabs / tab_window_controller.mm
index c6dfa62..6cca970 100644 (file)
@@ -51,6 +51,7 @@
   base::scoped_nsobject<FramedBrowserWindow> window(
       [[FramedBrowserWindow alloc] initWithContentRect:contentRect
                                            hasTabStrip:hasTabStrip]);
+  [self moveContentViewToBack:[window contentView]];
   [window setReleasedWhenClosed:YES];
   [window setAutorecalculatesKeyViewLoop:YES];
 
@@ -68,7 +69,7 @@
     [tabStripView_ setAutoresizingMask:NSViewWidthSizable |
                                        NSViewMinYMargin];
     if (hasTabStrip)
-      [self addTabStripToWindow];
+      [self insertTabStripView:tabStripView_ intoWindow:[self window]];
   }
   return self;
 }
   return tabContentArea_;
 }
 
-// Add the top tab strop to the window, above the content box and add it to the
-// view hierarchy as a sibling of the content view so it can overlap with the
-// window frame.
-- (void)addTabStripToWindow {
-  // The frame doesn't matter. This class relies on subclasses to do tab strip
-  // layout.
-  NSView* contentParent = [[self window] cr_windowView];
-  [contentParent addSubview:tabStripView_];
-}
-
 - (void)removeOverlay {
   [self setUseOverlay:NO];
   if (closeDeferred_) {
     // content view and therefore it should always be added after the content
     // view is set.
     [window setContentView:originalContentView_];
-    [[window cr_windowView] addSubview:[self tabStripView]];
+    [self moveContentViewToBack:originalContentView_];
+    [self insertTabStripView:[self tabStripView] intoWindow:window];
     [[window cr_windowView] updateTrackingAreas];
 
     [focusBeforeOverlay_ restoreFocusInWindow:window];
   closeDeferred_ = YES;
 }
 
+- (void)moveContentViewToBack:(NSView*)cv {
+  base::scoped_nsobject<NSView> contentView([cv retain]);
+  NSView* superview = [contentView superview];
+  [contentView removeFromSuperview];
+  [superview addSubview:contentView positioned:NSWindowBelow relativeTo:nil];
+}
+
+- (void)insertTabStripView:(NSView*)tabStripView intoWindow:(NSWindow*)window {
+  NSView* contentParent = [window cr_windowView];
+  if (contentParent == [[window contentView] superview]) {
+    // Add the tab strip directly above the content view, if they are siblings.
+    [contentParent addSubview:tabStripView
+                   positioned:NSWindowAbove
+                   relativeTo:[window contentView]];
+  } else {
+    [contentParent addSubview:tabStripView];
+  }
+}
+
 // Called when the size of the window content area has changed. Override to
 // position specific views. Base class implementation does nothing.
 - (void)layoutSubviews {