Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(397)

Side by Side Diff: chrome/browser/ui/cocoa/dev_tools_controller.mm

Issue 5915006: Remove user-related data from local_state and add to user_preferences, i... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.h"
14 #include "chrome/browser/tab_contents/tab_contents.h" 15 #include "chrome/browser/tab_contents/tab_contents.h"
15 #import "chrome/browser/ui/cocoa/view_id_util.h" 16 #import "chrome/browser/ui/cocoa/view_id_util.h"
16 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
17 18
18 namespace { 19 namespace {
19 20
20 // Default offset of the contents splitter in pixels. 21 // Default offset of the contents splitter in pixels.
21 const int kDefaultContentsSplitOffset = 400; 22 const int kDefaultContentsSplitOffset = 400;
22 23
23 // Never make the web part of the tab contents smaller than this (needed if the 24 // Never make the web part of the tab contents smaller than this (needed if the
24 // window is only a few pixels high). 25 // window is only a few pixels high).
25 const int kMinWebHeight = 50; 26 const int kMinWebHeight = 50;
26 27
27 } // end namespace 28 } // end namespace
28 29
29 30
30 @interface DevToolsController (Private) 31 @interface DevToolsController (Private)
31 - (void)showDevToolsContents:(TabContents*)devToolsContents; 32 - (void)showDevToolsContents:(TabContents*)devToolsContents
33 withProfile:(Profile*)profile;
32 - (void)resizeDevToolsToNewHeight:(CGFloat)height; 34 - (void)resizeDevToolsToNewHeight:(CGFloat)height;
33 @end 35 @end
34 36
35 37
36 @implementation DevToolsController 38 @implementation DevToolsController
37 39
38 - (id)initWithDelegate:(id<TabContentsControllerDelegate>)delegate { 40 - (id)initWithDelegate:(id<TabContentsControllerDelegate>)delegate {
39 if ((self = [super init])) { 41 if ((self = [super init])) {
40 splitView_.reset([[NSSplitView alloc] initWithFrame:NSZeroRect]); 42 splitView_.reset([[NSSplitView alloc] initWithFrame:NSZeroRect]);
41 [splitView_ setDividerStyle:NSSplitViewDividerStyleThin]; 43 [splitView_ setDividerStyle:NSSplitViewDividerStyleThin];
(...skipping 14 matching lines...) Expand all
56 } 58 }
57 59
58 - (NSView*)view { 60 - (NSView*)view {
59 return splitView_.get(); 61 return splitView_.get();
60 } 62 }
61 63
62 - (NSSplitView*)splitView { 64 - (NSSplitView*)splitView {
63 return splitView_.get(); 65 return splitView_.get();
64 } 66 }
65 67
66 - (void)updateDevToolsForTabContents:(TabContents*)contents { 68 - (void)updateDevToolsForTabContents:(TabContents*)contents
69 withProfile:(Profile*)profile {
67 // Get current devtools content. 70 // Get current devtools content.
68 TabContents* devToolsContents = contents ? 71 TabContents* devToolsContents = contents ?
69 DevToolsWindow::GetDevToolsContents(contents) : NULL; 72 DevToolsWindow::GetDevToolsContents(contents) : NULL;
70 73
71 [self showDevToolsContents:devToolsContents]; 74 [self showDevToolsContents:devToolsContents withProfile:profile];
72 } 75 }
73 76
74 - (void)ensureContentsVisible { 77 - (void)ensureContentsVisible {
75 [contentsController_ ensureContentsVisible]; 78 [contentsController_ ensureContentsVisible];
76 } 79 }
77 80
78 - (void)showDevToolsContents:(TabContents*)devToolsContents { 81 - (void)showDevToolsContents:(TabContents*)devToolsContents
82 withProfile:(Profile*)profile {
79 [contentsController_ ensureContentsSizeDoesNotChange]; 83 [contentsController_ ensureContentsSizeDoesNotChange];
80 84
81 NSArray* subviews = [splitView_ subviews]; 85 NSArray* subviews = [splitView_ subviews];
82 if (devToolsContents) { 86 if (devToolsContents) {
83 DCHECK_GE([subviews count], 1u); 87 DCHECK_GE([subviews count], 1u);
84 88
85 // |devToolsView| is a TabContentsViewCocoa object, whose ViewID was 89 // |devToolsView| is a TabContentsViewCocoa object, whose ViewID was
86 // 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
87 // VIEW_ID_DEV_TOOLS_DOCKED here. 91 // VIEW_ID_DEV_TOOLS_DOCKED here.
88 view_id_util::SetID( 92 view_id_util::SetID(
89 devToolsContents->GetNativeView(), VIEW_ID_DEV_TOOLS_DOCKED); 93 devToolsContents->GetNativeView(), VIEW_ID_DEV_TOOLS_DOCKED);
90 94
91 CGFloat splitOffset = 0; 95 CGFloat splitOffset = 0;
92 if ([subviews count] == 1) { 96 if ([subviews count] == 1) {
93 // Load the default split offset. 97 // Load the default split offset.
94 splitOffset = g_browser_process->local_state()->GetInteger( 98 splitOffset = profile->GetPrefs()->
95 prefs::kDevToolsSplitLocation); 99 GetInteger(prefs::kDevToolsSplitLocation);
96 if (splitOffset < 0) { 100 if (splitOffset < 0) {
97 // Initial load, set to default value. 101 // Initial load, set to default value.
98 splitOffset = kDefaultContentsSplitOffset; 102 splitOffset = kDefaultContentsSplitOffset;
99 } 103 }
100 [splitView_ addSubview:[contentsController_ view]]; 104 [splitView_ addSubview:[contentsController_ view]];
101 } else { 105 } else {
102 DCHECK_EQ([subviews count], 2u); 106 DCHECK_EQ([subviews count], 2u);
103 // If devtools are already visible, keep the current size. 107 // If devtools are already visible, keep the current size.
104 splitOffset = NSHeight([[subviews objectAtIndex:1] frame]); 108 splitOffset = NSHeight([[subviews objectAtIndex:1] frame]);
105 } 109 }
106 110
107 // Make sure |splitOffset| isn't too large or too small. 111 // Make sure |splitOffset| isn't too large or too small.
108 splitOffset = std::max(static_cast<CGFloat>(kMinWebHeight), splitOffset); 112 splitOffset = std::max(static_cast<CGFloat>(kMinWebHeight), splitOffset);
109 splitOffset = 113 splitOffset =
110 std::min(splitOffset, NSHeight([splitView_ frame]) - kMinWebHeight); 114 std::min(splitOffset, NSHeight([splitView_ frame]) - kMinWebHeight);
111 DCHECK_GE(splitOffset, 0) << "kMinWebHeight needs to be smaller than " 115 DCHECK_GE(splitOffset, 0) << "kMinWebHeight needs to be smaller than "
112 << "smallest available tab contents space."; 116 << "smallest available tab contents space.";
113 117
114 [self resizeDevToolsToNewHeight:splitOffset]; 118 [self resizeDevToolsToNewHeight:splitOffset];
115 } else { 119 } else {
116 if ([subviews count] > 1) { 120 if ([subviews count] > 1) {
117 NSView* oldDevToolsContentsView = [subviews objectAtIndex:1]; 121 NSView* oldDevToolsContentsView = [subviews objectAtIndex:1];
118 // Store split offset when hiding devtools window only. 122 // Store split offset when hiding devtools window only.
119 int splitOffset = NSHeight([oldDevToolsContentsView frame]); 123 int splitOffset = NSHeight([oldDevToolsContentsView frame]);
120 g_browser_process->local_state()->SetInteger( 124
125 profile->GetPrefs()->SetInteger(
121 prefs::kDevToolsSplitLocation, splitOffset); 126 prefs::kDevToolsSplitLocation, splitOffset);
122 [oldDevToolsContentsView removeFromSuperview]; 127 [oldDevToolsContentsView removeFromSuperview];
123 [splitView_ adjustSubviews]; 128 [splitView_ adjustSubviews];
124 } 129 }
125 } 130 }
126 131
127 [contentsController_ changeTabContents:devToolsContents]; 132 [contentsController_ changeTabContents:devToolsContents];
128 } 133 }
129 134
130 - (void)resizeDevToolsToNewHeight:(CGFloat)height { 135 - (void)resizeDevToolsToNewHeight:(CGFloat)height {
(...skipping 23 matching lines...) Expand all
154 // 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
155 // 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
156 // 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
157 // and others are not. 162 // and others are not.
158 if ([[splitView_ subviews] indexOfObject:subview] == 1) 163 if ([[splitView_ subviews] indexOfObject:subview] == 1)
159 return NO; 164 return NO;
160 return YES; 165 return YES;
161 } 166 }
162 167
163 @end 168 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/dev_tools_controller.h ('k') | chrome/browser/ui/cocoa/options/preferences_window_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698