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 = 50; |
25 // Never make the web part of the tab contents smaller than this (needed if the | 25 const int kMinContentsHeight = 50; |
26 // window is only a few pixels high). | |
27 const int kMinWebHeight = 50; | |
28 | 26 |
29 } // end namespace | 27 } // end namespace |
30 | 28 |
31 | 29 |
32 @interface DevToolsController (Private) | 30 @interface DevToolsController (Private) |
33 - (void)showDevToolsContents:(TabContents*)devToolsContents | 31 - (void)showDevToolsContents:(TabContents*)devToolsContents |
34 withProfile:(Profile*)profile; | 32 withProfile:(Profile*)profile; |
35 - (void)resizeDevToolsToNewHeight:(CGFloat)height; | 33 - (void)resizeDevToolsToNewHeight:(CGFloat)height; |
36 @end | 34 @end |
37 | 35 |
(...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 | 91 // set to VIEW_ID_TAB_CONTAINER initially, so we need to change it to |
94 // VIEW_ID_DEV_TOOLS_DOCKED here. | 92 // VIEW_ID_DEV_TOOLS_DOCKED here. |
95 view_id_util::SetID( | 93 view_id_util::SetID( |
96 devToolsContents->GetNativeView(), VIEW_ID_DEV_TOOLS_DOCKED); | 94 devToolsContents->GetNativeView(), VIEW_ID_DEV_TOOLS_DOCKED); |
97 | 95 |
98 CGFloat splitOffset = 0; | 96 CGFloat splitOffset = 0; |
99 if ([subviews count] == 1) { | 97 if ([subviews count] == 1) { |
100 // Load the default split offset. | 98 // Load the default split offset. |
101 splitOffset = profile->GetPrefs()-> | 99 splitOffset = profile->GetPrefs()-> |
102 GetInteger(prefs::kDevToolsSplitLocation); | 100 GetInteger(prefs::kDevToolsSplitLocation); |
103 if (splitOffset < 0) { | 101 if (splitOffset < 0) |
104 // Initial load, set to default value. | 102 splitOffset = NSHeight([[subviews objectAtIndex:0] frame]) * 2 / 3; |
105 splitOffset = kDefaultContentsSplitOffset; | 103 |
106 } | |
107 [splitView_ addSubview:[contentsController_ view]]; | 104 [splitView_ addSubview:[contentsController_ view]]; |
108 } else { | 105 } else { |
109 DCHECK_EQ([subviews count], 2u); | 106 DCHECK_EQ([subviews count], 2u); |
110 // If devtools are already visible, keep the current size. | 107 // If devtools are already visible, keep the current size. |
111 splitOffset = NSHeight([[subviews objectAtIndex:1] frame]); | 108 splitOffset = NSHeight([[subviews objectAtIndex:1] frame]); |
112 } | 109 } |
113 | 110 |
114 // Make sure |splitOffset| isn't too large or too small. | 111 // Make sure |splitOffset| isn't too large or too small. |
115 splitOffset = std::max(static_cast<CGFloat>(kMinWebHeight), splitOffset); | 112 splitOffset = std::min(NSHeight([splitView_ frame]) - kMinDevToolsHeight, |
116 splitOffset = | 113 splitOffset); |
117 std::min(splitOffset, NSHeight([splitView_ frame]) - kMinWebHeight); | 114 splitOffset = std::max(static_cast<CGFloat>(kMinContentsHeight), |
| 115 splitOffset); |
| 116 if (splitOffset < 0) |
| 117 splitOffset = NSHeight([[subviews objectAtIndex:0] frame]) * 2 / 3; |
118 DCHECK_GE(splitOffset, 0) << "kMinWebHeight needs to be smaller than " | 118 DCHECK_GE(splitOffset, 0) << "kMinWebHeight needs to be smaller than " |
119 << "smallest available tab contents space."; | 119 << "smallest available tab contents space."; |
120 | 120 |
121 [self resizeDevToolsToNewHeight:splitOffset]; | 121 [self resizeDevToolsToNewHeight:splitOffset]; |
122 } else { | 122 } else { |
123 if ([subviews count] > 1) { | 123 if ([subviews count] > 1) { |
124 NSView* oldDevToolsContentsView = [subviews objectAtIndex:1]; | 124 NSView* oldDevToolsContentsView = [subviews objectAtIndex:1]; |
125 // Store split offset when hiding devtools window only. | 125 // Store split offset when hiding devtools window only. |
126 int splitOffset = NSHeight([oldDevToolsContentsView frame]); | 126 int splitOffset = NSHeight([oldDevToolsContentsView frame]); |
127 | 127 |
(...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 | 162 // 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 | 163 // 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 | 164 // view height the same while changing tabs when one of the tabs shows infobar |
165 // and others are not. | 165 // and others are not. |
166 if ([[splitView_ subviews] indexOfObject:subview] == 1) | 166 if ([[splitView_ subviews] indexOfObject:subview] == 1) |
167 return NO; | 167 return NO; |
168 return YES; | 168 return YES; |
169 } | 169 } |
170 | 170 |
171 @end | 171 @end |
OLD | NEW |