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

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

Issue 3547008: Handle resize corner layout entirely in the platform BrowserWindow*/BrowserView* code... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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/cocoa/dev_tools_controller.h" 5 #import "chrome/browser/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
(...skipping 18 matching lines...) Expand all
29 29
30 30
31 @interface DevToolsController (Private) 31 @interface DevToolsController (Private)
32 - (void)showDevToolsContents:(TabContents*)devToolsContents; 32 - (void)showDevToolsContents:(TabContents*)devToolsContents;
33 - (void)resizeDevToolsToNewHeight:(CGFloat)height; 33 - (void)resizeDevToolsToNewHeight:(CGFloat)height;
34 @end 34 @end
35 35
36 36
37 @implementation DevToolsController 37 @implementation DevToolsController
38 38
39 - (id)init { 39 - (id)initWithDelegate:(id<TabContentsControllerDelegate>)delegate {
40 if ((self = [super init])) { 40 if ((self = [super init])) {
41 splitView_.reset([[NSSplitView alloc] initWithFrame:NSZeroRect]); 41 splitView_.reset([[NSSplitView alloc] initWithFrame:NSZeroRect]);
42 [splitView_ setDividerStyle:NSSplitViewDividerStyleThin]; 42 [splitView_ setDividerStyle:NSSplitViewDividerStyleThin];
43 [splitView_ setVertical:NO]; 43 [splitView_ setVertical:NO];
44 [splitView_ setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable]; 44 [splitView_ setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
45 [splitView_ setDelegate:self];
46
47 contentsController_.reset(
48 [[TabContentsController alloc] initWithContents:NULL
49 delegate:delegate]);
45 } 50 }
46 return self; 51 return self;
47 } 52 }
48 53
54 - (void)dealloc {
55 [splitView_ setDelegate:nil];
56 [super dealloc];
57 }
58
49 - (NSView*)view { 59 - (NSView*)view {
50 return splitView_.get(); 60 return splitView_.get();
51 } 61 }
52 62
53 - (NSSplitView*)splitView { 63 - (NSSplitView*)splitView {
54 return splitView_.get(); 64 return splitView_.get();
55 } 65 }
56 66
57 - (void)updateDevToolsForTabContents:(TabContents*)contents { 67 - (void)updateDevToolsForTabContents:(TabContents*)contents {
58 // Get current devtools content. 68 // Get current devtools content.
59 TabContents* devToolsContents = contents ? 69 TabContents* devToolsContents = contents ?
60 DevToolsWindow::GetDevToolsContents(contents) : NULL; 70 DevToolsWindow::GetDevToolsContents(contents) : NULL;
61 71
62 [self showDevToolsContents:devToolsContents]; 72 [self showDevToolsContents:devToolsContents];
63 } 73 }
64 74
75 - (void)ensureContentsVisible {
76 [contentsController_ ensureContentsVisible];
77 }
78
65 - (void)showDevToolsContents:(TabContents*)devToolsContents { 79 - (void)showDevToolsContents:(TabContents*)devToolsContents {
80 [contentsController_ ensureContentsSizeDoesNotChange];
81
66 NSArray* subviews = [splitView_ subviews]; 82 NSArray* subviews = [splitView_ subviews];
67 if (devToolsContents) { 83 if (devToolsContents) {
68 DCHECK_GE([subviews count], 1u); 84 DCHECK_GE([subviews count], 1u);
69 85
70 // |devToolsView| is a TabContentsViewCocoa object, whose ViewID was 86 // |devToolsView| is a TabContentsViewCocoa object, whose ViewID was
71 // set to VIEW_ID_TAB_CONTAINER initially, so we need to change it to 87 // set to VIEW_ID_TAB_CONTAINER initially, so we need to change it to
72 // VIEW_ID_DEV_TOOLS_DOCKED here. 88 // VIEW_ID_DEV_TOOLS_DOCKED here.
73 NSView* devToolsView = devToolsContents->GetNativeView(); 89 view_id_util::SetID(
74 view_id_util::SetID(devToolsView, VIEW_ID_DEV_TOOLS_DOCKED); 90 devToolsContents->GetNativeView(), VIEW_ID_DEV_TOOLS_DOCKED);
75 91
76 CGFloat splitOffset = 0; 92 CGFloat splitOffset = 0;
77 if ([subviews count] == 1) { 93 if ([subviews count] == 1) {
78 // Load the default split offset. 94 // Load the default split offset.
79 splitOffset = g_browser_process->local_state()->GetInteger( 95 splitOffset = g_browser_process->local_state()->GetInteger(
80 prefs::kDevToolsSplitLocation); 96 prefs::kDevToolsSplitLocation);
81 if (splitOffset < 0) { 97 if (splitOffset < 0) {
82 // Initial load, set to default value. 98 // Initial load, set to default value.
83 splitOffset = kDefaultContentsSplitOffset; 99 splitOffset = kDefaultContentsSplitOffset;
84 } 100 }
85 [splitView_ addSubview:devToolsView]; 101 [splitView_ addSubview:[contentsController_ view]];
86 } else { 102 } else {
87 DCHECK_EQ([subviews count], 2u); 103 DCHECK_EQ([subviews count], 2u);
88 // If devtools are already visible, keep the current size. 104 // If devtools are already visible, keep the current size.
89 splitOffset = NSHeight([devToolsView frame]); 105 splitOffset = NSHeight([[subviews objectAtIndex:1] frame]);
90 [splitView_ replaceSubview:[subviews objectAtIndex:1]
91 with:devToolsView];
92 } 106 }
93 107
94 // Make sure |splitOffset| isn't too large or too small. 108 // Make sure |splitOffset| isn't too large or too small.
95 splitOffset = std::max(static_cast<CGFloat>(kMinWebHeight), splitOffset); 109 splitOffset = std::max(static_cast<CGFloat>(kMinWebHeight), splitOffset);
96 splitOffset = 110 splitOffset =
97 std::min(splitOffset, NSHeight([splitView_ frame]) - kMinWebHeight); 111 std::min(splitOffset, NSHeight([splitView_ frame]) - kMinWebHeight);
98 DCHECK_GE(splitOffset, 0) << "kMinWebHeight needs to be smaller than " 112 DCHECK_GE(splitOffset, 0) << "kMinWebHeight needs to be smaller than "
99 << "smallest available tab contents space."; 113 << "smallest available tab contents space.";
100 114
101 [self resizeDevToolsToNewHeight:splitOffset]; 115 [self resizeDevToolsToNewHeight:splitOffset];
102 } else { 116 } else {
103 if ([subviews count] > 1) { 117 if ([subviews count] > 1) {
104 NSView* oldDevToolsContentsView = [subviews objectAtIndex:1]; 118 NSView* oldDevToolsContentsView = [subviews objectAtIndex:1];
105 // Store split offset when hiding devtools window only. 119 // Store split offset when hiding devtools window only.
106 int splitOffset = NSHeight([oldDevToolsContentsView frame]); 120 int splitOffset = NSHeight([oldDevToolsContentsView frame]);
107 g_browser_process->local_state()->SetInteger( 121 g_browser_process->local_state()->SetInteger(
108 prefs::kDevToolsSplitLocation, splitOffset); 122 prefs::kDevToolsSplitLocation, splitOffset);
109 [oldDevToolsContentsView removeFromSuperview]; 123 [oldDevToolsContentsView removeFromSuperview];
124 [splitView_ adjustSubviews];
110 } 125 }
111 } 126 }
127
128 [contentsController_ changeTabContents:devToolsContents];
112 } 129 }
113 130
114 - (void)resizeDevToolsToNewHeight:(CGFloat)height { 131 - (void)resizeDevToolsToNewHeight:(CGFloat)height {
115 NSArray* subviews = [splitView_ subviews]; 132 NSArray* subviews = [splitView_ subviews];
116 133
117 // It seems as if |-setPosition:ofDividerAtIndex:| should do what's needed, 134 // It seems as if |-setPosition:ofDividerAtIndex:| should do what's needed,
118 // but I can't figure out how to use it. Manually resize web and devtools. 135 // but I can't figure out how to use it. Manually resize web and devtools.
119 // TODO(alekseys): either make setPosition:ofDividerAtIndex: work or to add a 136 // TODO(alekseys): either make setPosition:ofDividerAtIndex: work or to add a
120 // category on NSSplitView to handle manual resizing. 137 // category on NSSplitView to handle manual resizing.
121 NSView* devToolsView = [subviews objectAtIndex:1]; 138 NSView* devToolsView = [subviews objectAtIndex:1];
122 NSRect devToolsFrame = [devToolsView frame]; 139 NSRect devToolsFrame = [devToolsView frame];
123 devToolsFrame.size.height = height; 140 devToolsFrame.size.height = height;
124 [devToolsView setFrame:devToolsFrame]; 141 [devToolsView setFrame:devToolsFrame];
125 142
126 NSView* webView = [subviews objectAtIndex:0]; 143 NSView* webView = [subviews objectAtIndex:0];
127 NSRect webFrame = [webView frame]; 144 NSRect webFrame = [webView frame];
128 webFrame.size.height = 145 webFrame.size.height =
129 NSHeight([splitView_ frame]) - ([splitView_ dividerThickness] + height); 146 NSHeight([splitView_ frame]) - ([splitView_ dividerThickness] + height);
130 [webView setFrame:webFrame]; 147 [webView setFrame:webFrame];
131 148
132 [splitView_ adjustSubviews]; 149 [splitView_ adjustSubviews];
133 } 150 }
134 151
135 152 // NSSplitViewDelegate protocol.
153 - (BOOL)splitView:(NSSplitView *)splitView
154 shouldAdjustSizeOfSubview:(NSView *)subview {
rohitrao (ping after 24h) 2010/11/15 23:46:58 Is this new? Is it now required because of some o
Aleksey Shlyapnikov 2010/11/16 02:07:37 It was broken since we switched to one devtools co
rohitrao (ping after 24h) 2010/11/16 02:14:47 Nah, this is fine. On 2010/11/16 02:07:37, Alekse
155 // 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
157 // view height the same while changing tabs when one of the tabs shows infobar
158 // and others are not.
159 if ([[splitView_ subviews] indexOfObject:subview] == 1)
160 return NO;
161 return YES;
162 }
136 163
137 @end 164 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698