Index: chrome/browser/cocoa/tab_contents_controller.mm |
diff --git a/chrome/browser/cocoa/tab_contents_controller.mm b/chrome/browser/cocoa/tab_contents_controller.mm |
index 8072683957279d596ffddd6509f8571b10ca0d73..70daa32979233719ffbad825b3e3ce2d40d2a06c 100644 |
--- a/chrome/browser/cocoa/tab_contents_controller.mm |
+++ b/chrome/browser/cocoa/tab_contents_controller.mm |
@@ -6,8 +6,19 @@ |
#include "base/mac_util.h" |
#include "base/sys_string_conversions.h" |
+#include "chrome/browser/browser_process.h" |
#include "chrome/browser/bookmarks/bookmark_model.h" |
#include "chrome/browser/tab_contents/tab_contents.h" |
+#include "chrome/common/pref_names.h" |
+#include "chrome/common/pref_service.h" |
+ |
+// Default offset of the contents splitter in pixels. |
+static const int kDefaultContentsSplitOffset = 400; |
+ |
+// Never make the web part of the tab contents smaller than this (needed if the |
+// window is only a few pixels high). |
+static const int kMinWebHeight = 50; |
+ |
@implementation TabContentsController |
@@ -29,7 +40,12 @@ |
// Call when the tab view is properly sized and the render widget host view |
// should be put into the view hierarchy. |
- (void)ensureContentsVisible { |
- [contentsBox_ setContentView:contents_->GetNativeView()]; |
+ NSArray* subviews = [contentsContainer_ subviews]; |
+ if ([subviews count] == 0) |
+ [contentsContainer_ addSubview:contents_->GetNativeView()]; |
+ else if ([subviews objectAtIndex:0] != contents_->GetNativeView()) |
+ [contentsContainer_ replaceSubview:[subviews objectAtIndex:0] |
+ with:contents_->GetNativeView()]; |
} |
// Returns YES if the tab represented by this controller is the front-most. |
@@ -57,8 +73,64 @@ |
// the view is different. |
if (contents_ != updatedContents) { |
contents_ = updatedContents; |
- [contentsBox_ setContentView:contents_->GetNativeView()]; |
+ [self ensureContentsVisible]; |
} |
} |
+- (void)showDevToolsContents:(TabContents*)devToolsContents { |
+ NSArray* subviews = [contentsContainer_ subviews]; |
+ if (devToolsContents) { |
+ DCHECK_GE([subviews count], 1u); |
+ if ([subviews count] == 1) { |
+ [contentsContainer_ addSubview:devToolsContents->GetNativeView()]; |
+ } else { |
+ DCHECK_EQ([subviews count], 2u); |
+ [contentsContainer_ replaceSubview:[subviews objectAtIndex:1] |
+ with:devToolsContents->GetNativeView()]; |
+ } |
+ // Restore split offset. |
+ CGFloat splitOffset = g_browser_process->local_state()->GetInteger( |
+ prefs::kDevToolsSplitLocation); |
+ if (splitOffset == -1) { |
+ // Initial load, set to default value. |
+ splitOffset = kDefaultContentsSplitOffset; |
+ } |
+ splitOffset = MIN(splitOffset, |
+ NSHeight([contentsContainer_ frame]) - kMinWebHeight); |
+ DCHECK_GE(splitOffset, 0) << "kMinWebHeight needs to be smaller than " |
+ << "smallest available tab contents space."; |
+ splitOffset = MAX(0, splitOffset); |
+ |
+ // It seems as if |-setPosition:ofDividerAtIndex:| should do what's needed, |
+ // but I can't figure out how to use it. Manually resize web and devtools. |
+ NSRect devtoolsFrame = [devToolsContents->GetNativeView() frame]; |
+ devtoolsFrame.size.height = splitOffset; |
+ [devToolsContents->GetNativeView() setFrame:devtoolsFrame]; |
+ |
+ NSRect webFrame = [[subviews objectAtIndex:0] frame]; |
+ webFrame.size.height = NSHeight([contentsContainer_ frame]) - |
+ [self devToolsHeight]; |
+ [[subviews objectAtIndex:0] setFrame:webFrame]; |
+ |
+ [contentsContainer_ adjustSubviews]; |
+ } else { |
+ if ([subviews count] > 1) { |
+ NSView* oldDevToolsContentsView = [subviews objectAtIndex:1]; |
+ // Store split offset when hiding devtools window only. |
+ int splitOffset = NSHeight([oldDevToolsContentsView frame]); |
+ g_browser_process->local_state()->SetInteger( |
+ prefs::kDevToolsSplitLocation, splitOffset); |
+ [oldDevToolsContentsView removeFromSuperview]; |
+ } |
+ } |
+} |
+ |
+- (CGFloat)devToolsHeight { |
+ NSArray* subviews = [contentsContainer_ subviews]; |
+ if ([subviews count] < 2) |
+ return 0; |
+ return NSHeight([[subviews objectAtIndex:1] frame]) + |
+ [contentsContainer_ dividerThickness]; |
+} |
+ |
@end |