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 | |
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) { | 100 if (splitOffset < 0) |
104 // Initial load, set to default value. | 101 splitOffset = NSHeight([[subviews objectAtIndex:0] frame]) * 2 / 3; |
105 splitOffset = kDefaultContentsSplitOffset; | 102 |
106 } | |
107 [splitView_ addSubview:[contentsController_ view]]; | 103 [splitView_ addSubview:[contentsController_ view]]; |
108 } else { | 104 } else { |
109 DCHECK_EQ([subviews count], 2u); | 105 DCHECK_EQ([subviews count], 2u); |
110 // If devtools are already visible, keep the current size. | 106 // If devtools are already visible, keep the current size. |
111 splitOffset = NSHeight([[subviews objectAtIndex:1] frame]); | 107 splitOffset = NSHeight([[subviews objectAtIndex:1] frame]); |
112 } | 108 } |
113 | 109 |
114 // Make sure |splitOffset| isn't too large or too small. | 110 // Make sure |splitOffset| isn't too large or too small. |
115 splitOffset = std::max(static_cast<CGFloat>(kMinWebHeight), splitOffset); | 111 splitOffset = std::max(static_cast<CGFloat>(kMinDevToolsHeight), |
yurys
2011/06/08 08:14:27
Use of the kMinDevToolsHeight here is confusing, c
| |
116 splitOffset = | 112 splitOffset); |
117 std::min(splitOffset, NSHeight([splitView_ frame]) - kMinWebHeight); | 113 splitOffset = std::min(NSHeight([splitView_ frame]) - kMinDevToolsHeight, |
yurys
2011/06/08 08:14:27
What is the expected behavior when splitOffset her
| |
114 splitOffset); | |
118 DCHECK_GE(splitOffset, 0) << "kMinWebHeight needs to be smaller than " | 115 DCHECK_GE(splitOffset, 0) << "kMinWebHeight needs to be smaller than " |
119 << "smallest available tab contents space."; | 116 << "smallest available tab contents space."; |
120 | 117 |
121 [self resizeDevToolsToNewHeight:splitOffset]; | 118 [self resizeDevToolsToNewHeight:splitOffset]; |
122 } else { | 119 } else { |
123 if ([subviews count] > 1) { | 120 if ([subviews count] > 1) { |
124 NSView* oldDevToolsContentsView = [subviews objectAtIndex:1]; | 121 NSView* oldDevToolsContentsView = [subviews objectAtIndex:1]; |
125 // Store split offset when hiding devtools window only. | 122 // Store split offset when hiding devtools window only. |
126 int splitOffset = NSHeight([oldDevToolsContentsView frame]); | 123 int splitOffset = NSHeight([oldDevToolsContentsView frame]); |
127 | 124 |
(...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 | 159 // 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 | 160 // 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 | 161 // view height the same while changing tabs when one of the tabs shows infobar |
165 // and others are not. | 162 // and others are not. |
166 if ([[splitView_ subviews] indexOfObject:subview] == 1) | 163 if ([[splitView_ subviews] indexOfObject:subview] == 1) |
167 return NO; | 164 return NO; |
168 return YES; | 165 return YES; |
169 } | 166 } |
170 | 167 |
171 @end | 168 @end |
OLD | NEW |