OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_manager.h" |
14 #include "chrome/browser/tab_contents/tab_contents.h" | 15 #include "chrome/browser/tab_contents/tab_contents.h" |
15 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
16 #import "chrome/browser/ui/cocoa/view_id_util.h" | 17 #import "chrome/browser/ui/cocoa/view_id_util.h" |
17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 // Default offset of the contents splitter in pixels. | 22 // Default offset of the contents splitter in pixels. |
22 const int kDefaultContentsSplitOffset = 400; | 23 const int kDefaultContentsSplitOffset = 400; |
23 | 24 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 | 86 |
86 // |devToolsView| is a TabContentsViewCocoa object, whose ViewID was | 87 // |devToolsView| is a TabContentsViewCocoa object, whose ViewID was |
87 // set to VIEW_ID_TAB_CONTAINER initially, so we need to change it to | 88 // set to VIEW_ID_TAB_CONTAINER initially, so we need to change it to |
88 // VIEW_ID_DEV_TOOLS_DOCKED here. | 89 // VIEW_ID_DEV_TOOLS_DOCKED here. |
89 view_id_util::SetID( | 90 view_id_util::SetID( |
90 devToolsContents->GetNativeView(), VIEW_ID_DEV_TOOLS_DOCKED); | 91 devToolsContents->GetNativeView(), VIEW_ID_DEV_TOOLS_DOCKED); |
91 | 92 |
92 CGFloat splitOffset = 0; | 93 CGFloat splitOffset = 0; |
93 if ([subviews count] == 1) { | 94 if ([subviews count] == 1) { |
94 // Load the default split offset. | 95 // Load the default split offset. |
95 splitOffset = g_browser_process->local_state()->GetInteger( | 96 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
96 prefs::kDevToolsSplitLocation); | 97 splitOffset = profile_manager->GetDefaultProfile()->GetPrefs()-> |
| 98 GetInteger(prefs::kDevToolsSplitLocation); |
97 if (splitOffset < 0) { | 99 if (splitOffset < 0) { |
98 // Initial load, set to default value. | 100 // Initial load, set to default value. |
99 splitOffset = kDefaultContentsSplitOffset; | 101 splitOffset = kDefaultContentsSplitOffset; |
100 } | 102 } |
101 [splitView_ addSubview:[contentsController_ view]]; | 103 [splitView_ addSubview:[contentsController_ view]]; |
102 } else { | 104 } else { |
103 DCHECK_EQ([subviews count], 2u); | 105 DCHECK_EQ([subviews count], 2u); |
104 // If devtools are already visible, keep the current size. | 106 // If devtools are already visible, keep the current size. |
105 splitOffset = NSHeight([[subviews objectAtIndex:1] frame]); | 107 splitOffset = NSHeight([[subviews objectAtIndex:1] frame]); |
106 } | 108 } |
107 | 109 |
108 // Make sure |splitOffset| isn't too large or too small. | 110 // Make sure |splitOffset| isn't too large or too small. |
109 splitOffset = std::max(static_cast<CGFloat>(kMinWebHeight), splitOffset); | 111 splitOffset = std::max(static_cast<CGFloat>(kMinWebHeight), splitOffset); |
110 splitOffset = | 112 splitOffset = |
111 std::min(splitOffset, NSHeight([splitView_ frame]) - kMinWebHeight); | 113 std::min(splitOffset, NSHeight([splitView_ frame]) - kMinWebHeight); |
112 DCHECK_GE(splitOffset, 0) << "kMinWebHeight needs to be smaller than " | 114 DCHECK_GE(splitOffset, 0) << "kMinWebHeight needs to be smaller than " |
113 << "smallest available tab contents space."; | 115 << "smallest available tab contents space."; |
114 | 116 |
115 [self resizeDevToolsToNewHeight:splitOffset]; | 117 [self resizeDevToolsToNewHeight:splitOffset]; |
116 } else { | 118 } else { |
117 if ([subviews count] > 1) { | 119 if ([subviews count] > 1) { |
118 NSView* oldDevToolsContentsView = [subviews objectAtIndex:1]; | 120 NSView* oldDevToolsContentsView = [subviews objectAtIndex:1]; |
119 // Store split offset when hiding devtools window only. | 121 // Store split offset when hiding devtools window only. |
120 int splitOffset = NSHeight([oldDevToolsContentsView frame]); | 122 int splitOffset = NSHeight([oldDevToolsContentsView frame]); |
121 g_browser_process->local_state()->SetInteger( | 123 ProfileManager* profileManager = g_browser_process->profile_manager(); |
122 prefs::kDevToolsSplitLocation, splitOffset); | 124 profileManager->GetDefaultProfile()->GetPrefs()-> |
| 125 SetInteger(prefs::kDevToolsSplitLocation, splitOffset); |
123 [oldDevToolsContentsView removeFromSuperview]; | 126 [oldDevToolsContentsView removeFromSuperview]; |
124 [splitView_ adjustSubviews]; | 127 [splitView_ adjustSubviews]; |
125 } | 128 } |
126 } | 129 } |
127 | 130 |
128 [contentsController_ changeTabContents:devToolsContents]; | 131 [contentsController_ changeTabContents:devToolsContents]; |
129 } | 132 } |
130 | 133 |
131 - (void)resizeDevToolsToNewHeight:(CGFloat)height { | 134 - (void)resizeDevToolsToNewHeight:(CGFloat)height { |
132 NSArray* subviews = [splitView_ subviews]; | 135 NSArray* subviews = [splitView_ subviews]; |
(...skipping 22 matching lines...) Expand all Loading... |
155 // Return NO for the devTools view to indicate that it should not be resized | 158 // Return NO for the devTools view to indicate that it should not be resized |
156 // automatically. It preserves the height set by the user and also keeps | 159 // automatically. It preserves the height set by the user and also keeps |
157 // view height the same while changing tabs when one of the tabs shows infobar | 160 // view height the same while changing tabs when one of the tabs shows infobar |
158 // and others are not. | 161 // and others are not. |
159 if ([[splitView_ subviews] indexOfObject:subview] == 1) | 162 if ([[splitView_ subviews] indexOfObject:subview] == 1) |
160 return NO; | 163 return NO; |
161 return YES; | 164 return YES; |
162 } | 165 } |
163 | 166 |
164 @end | 167 @end |
OLD | NEW |