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

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

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

Powered by Google App Engine
This is Rietveld 408576698