Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/cocoa/dev_tools_controller.h" | 5 #import "chrome/browser/ui/cocoa/dev_tools_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include <Cocoa/Cocoa.h> | 9 #include <Cocoa/Cocoa.h> |
| 10 | 10 |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/debugger/devtools_window.h" | 12 #include "chrome/browser/debugger/devtools_window.h" |
| 13 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 16 #import "chrome/browser/ui/cocoa/view_id_util.h" | 16 #import "chrome/browser/ui/cocoa/view_id_util.h" |
| 17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 18 #include "content/browser/tab_contents/tab_contents.h" | 18 #include "content/browser/tab_contents/tab_contents.h" |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 // Default offset of the contents splitter in pixels. | 22 // Minimal height of devtools pane or content pane when devtools are docked |
| 23 const int kDefaultContentsSplitOffset = 400; | 23 // to the browser window. |
| 24 | 24 const int kMinDevToolsHeight = 100; |
|
pfeldman
2011/06/07 19:59:12
Please keep it 50.
| |
| 25 // Never make the web part of the tab contents smaller than this (needed if the | |
| 26 // window is only a few pixels high). | |
| 27 const int kMinWebHeight = 50; | |
| 28 | 25 |
| 29 } // end namespace | 26 } // end namespace |
| 30 | 27 |
| 31 | 28 |
| 32 @interface DevToolsController (Private) | 29 @interface DevToolsController (Private) |
| 33 - (void)showDevToolsContents:(TabContents*)devToolsContents | 30 - (void)showDevToolsContents:(TabContents*)devToolsContents |
| 34 withProfile:(Profile*)profile; | 31 withProfile:(Profile*)profile; |
| 35 - (void)resizeDevToolsToNewHeight:(CGFloat)height; | 32 - (void)resizeDevToolsToNewHeight:(CGFloat)height; |
| 36 @end | 33 @end |
| 37 | 34 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 // set to VIEW_ID_TAB_CONTAINER initially, so we need to change it to | 90 // set to VIEW_ID_TAB_CONTAINER initially, so we need to change it to |
| 94 // VIEW_ID_DEV_TOOLS_DOCKED here. | 91 // VIEW_ID_DEV_TOOLS_DOCKED here. |
| 95 view_id_util::SetID( | 92 view_id_util::SetID( |
| 96 devToolsContents->GetNativeView(), VIEW_ID_DEV_TOOLS_DOCKED); | 93 devToolsContents->GetNativeView(), VIEW_ID_DEV_TOOLS_DOCKED); |
| 97 | 94 |
| 98 CGFloat splitOffset = 0; | 95 CGFloat splitOffset = 0; |
| 99 if ([subviews count] == 1) { | 96 if ([subviews count] == 1) { |
| 100 // Load the default split offset. | 97 // Load the default split offset. |
| 101 splitOffset = profile->GetPrefs()-> | 98 splitOffset = profile->GetPrefs()-> |
| 102 GetInteger(prefs::kDevToolsSplitLocation); | 99 GetInteger(prefs::kDevToolsSplitLocation); |
| 103 if (splitOffset < 0) { | |
| 104 // Initial load, set to default value. | |
| 105 splitOffset = kDefaultContentsSplitOffset; | |
| 106 } | |
| 107 [splitView_ addSubview:[contentsController_ view]]; | 100 [splitView_ addSubview:[contentsController_ view]]; |
| 108 } else { | 101 } else { |
| 109 DCHECK_EQ([subviews count], 2u); | 102 DCHECK_EQ([subviews count], 2u); |
| 110 // If devtools are already visible, keep the current size. | 103 // If devtools are already visible, keep the current size. |
| 111 splitOffset = NSHeight([[subviews objectAtIndex:1] frame]); | 104 splitOffset = NSHeight([[subviews objectAtIndex:1] frame]); |
| 112 } | 105 } |
| 113 | 106 |
| 114 // Make sure |splitOffset| isn't too large or too small. | 107 // Make sure |splitOffset| isn't too large or too small. |
| 115 splitOffset = std::max(static_cast<CGFloat>(kMinWebHeight), splitOffset); | 108 splitOffset = std::max(static_cast<CGFloat>(kMinDevToolsHeight), |
|
pfeldman
2011/06/07 19:59:12
One of these should stay kMinWebHeight. I.e. we wh
| |
| 116 splitOffset = | 109 splitOffset); |
| 117 std::min(splitOffset, NSHeight([splitView_ frame]) - kMinWebHeight); | 110 splitOffset = std::min(NSHeight([splitView_ frame]) - kMinDevToolsHeight, |
| 111 splitOffset); | |
| 118 DCHECK_GE(splitOffset, 0) << "kMinWebHeight needs to be smaller than " | 112 DCHECK_GE(splitOffset, 0) << "kMinWebHeight needs to be smaller than " |
| 119 << "smallest available tab contents space."; | 113 << "smallest available tab contents space."; |
| 120 | 114 |
| 121 [self resizeDevToolsToNewHeight:splitOffset]; | 115 [self resizeDevToolsToNewHeight:splitOffset]; |
| 122 } else { | 116 } else { |
| 123 if ([subviews count] > 1) { | 117 if ([subviews count] > 1) { |
| 124 NSView* oldDevToolsContentsView = [subviews objectAtIndex:1]; | 118 NSView* oldDevToolsContentsView = [subviews objectAtIndex:1]; |
| 125 // Store split offset when hiding devtools window only. | 119 // Store split offset when hiding devtools window only. |
| 126 int splitOffset = NSHeight([oldDevToolsContentsView frame]); | 120 int splitOffset = NSHeight([oldDevToolsContentsView frame]); |
| 127 | 121 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 // Return NO for the devTools view to indicate that it should not be resized | 156 // Return NO for the devTools view to indicate that it should not be resized |
| 163 // automatically. It preserves the height set by the user and also keeps | 157 // automatically. It preserves the height set by the user and also keeps |
| 164 // view height the same while changing tabs when one of the tabs shows infobar | 158 // view height the same while changing tabs when one of the tabs shows infobar |
| 165 // and others are not. | 159 // and others are not. |
| 166 if ([[splitView_ subviews] indexOfObject:subview] == 1) | 160 if ([[splitView_ subviews] indexOfObject:subview] == 1) |
| 167 return NO; | 161 return NO; |
| 168 return YES; | 162 return YES; |
| 169 } | 163 } |
| 170 | 164 |
| 171 @end | 165 @end |
| OLD | NEW |