OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 return nil; | 52 return nil; |
53 return [super hitTest:point]; | 53 return [super hitTest:point]; |
54 } | 54 } |
55 | 55 |
56 @end | 56 @end |
57 | 57 |
58 @interface DevToolsController (Private) | 58 @interface DevToolsController (Private) |
59 - (void)showDevToolsContainer; | 59 - (void)showDevToolsContainer; |
60 - (void)hideDevToolsContainer; | 60 - (void)hideDevToolsContainer; |
61 - (void)updateDevToolsSplitPosition; | 61 - (void)updateDevToolsSplitPosition; |
| 62 - (void)updateDevToolsViewFrame; |
62 @end | 63 @end |
63 | 64 |
64 | 65 |
65 @implementation DevToolsController | 66 @implementation DevToolsController |
66 | 67 |
67 - (id)init { | 68 - (id)init { |
68 if ((self = [super init])) { | 69 if ((self = [super init])) { |
69 splitView_.reset([[GraySplitView alloc] initWithFrame:NSZeroRect]); | 70 splitView_.reset([[GraySplitView alloc] initWithFrame:NSZeroRect]); |
70 [splitView_ setDividerStyle:NSSplitViewDividerStyleThin]; | 71 [splitView_ setDividerStyle:NSSplitViewDividerStyleThin]; |
71 [splitView_ setVertical:NO]; | 72 [splitView_ setVertical:NO]; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 devToolsWindow_ = newDevToolsWindow; | 123 devToolsWindow_ = newDevToolsWindow; |
123 | 124 |
124 if (devToolsWindow_) { | 125 if (devToolsWindow_) { |
125 dockSide_ = devToolsWindow_->dock_side(); | 126 dockSide_ = devToolsWindow_->dock_side(); |
126 [self showDevToolsContainer]; | 127 [self showDevToolsContainer]; |
127 } | 128 } |
128 } | 129 } |
129 | 130 |
130 - (void)setTopContentOffset:(CGFloat)offset { | 131 - (void)setTopContentOffset:(CGFloat)offset { |
131 [splitView_ setTopContentOffset:offset]; | 132 [splitView_ setTopContentOffset:offset]; |
| 133 if ([[splitView_ subviews] count] > 1) |
| 134 [self updateDevToolsViewFrame]; |
132 } | 135 } |
133 | 136 |
134 - (void)showDevToolsContainer { | 137 - (void)showDevToolsContainer { |
135 NSArray* subviews = [splitView_ subviews]; | 138 NSArray* subviews = [splitView_ subviews]; |
136 DCHECK_EQ([subviews count], 1u); | 139 DCHECK_EQ([subviews count], 1u); |
137 WebContents* devToolsContents = devToolsWindow_->web_contents(); | 140 WebContents* devToolsContents = devToolsWindow_->web_contents(); |
138 | 141 |
139 // |devToolsView| is a TabContentsViewCocoa object, whose ViewID was | 142 // |devToolsView| is a TabContentsViewCocoa object, whose ViewID was |
140 // set to VIEW_ID_TAB_CONTAINER initially, so we need to change it to | 143 // set to VIEW_ID_TAB_CONTAINER initially, so we need to change it to |
141 // VIEW_ID_DEV_TOOLS_DOCKED here. | 144 // VIEW_ID_DEV_TOOLS_DOCKED here. |
142 NSView* devToolsView = devToolsContents->GetNativeView(); | 145 NSView* devToolsView = devToolsContents->GetNativeView(); |
143 view_id_util::SetID(devToolsView, VIEW_ID_DEV_TOOLS_DOCKED); | 146 view_id_util::SetID(devToolsView, VIEW_ID_DEV_TOOLS_DOCKED); |
| 147 [devToolsView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
144 | 148 |
145 NSRect containerRect = NSMakeRect(0, 0, 100, 100); | 149 NSRect containerRect = NSMakeRect(0, 0, 100, 100); |
146 scoped_nsobject<NSView> devToolsContainerView( | 150 scoped_nsobject<NSView> devToolsContainerView( |
147 [[NSView alloc] initWithFrame:containerRect]); | 151 [[NSView alloc] initWithFrame:containerRect]); |
148 | |
149 NSRect devToolsRect = containerRect; | |
150 if (devToolsWindow_->dock_side() == DEVTOOLS_DOCK_SIDE_RIGHT) { | |
151 devToolsRect.size.height -= [splitView_ topContentOffset]; | |
152 } | |
153 [devToolsView setFrame:devToolsRect]; | |
154 [devToolsView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; | |
155 | |
156 [devToolsContainerView addSubview:devToolsView]; | 152 [devToolsContainerView addSubview:devToolsView]; |
157 [splitView_ addSubview:devToolsContainerView]; | 153 [splitView_ addSubview:devToolsContainerView]; |
| 154 [self updateDevToolsViewFrame]; |
158 | 155 |
159 BOOL isVertical = devToolsWindow_->dock_side() == DEVTOOLS_DOCK_SIDE_RIGHT; | 156 BOOL isVertical = devToolsWindow_->dock_side() == DEVTOOLS_DOCK_SIDE_RIGHT; |
160 [splitView_ setVertical:isVertical]; | 157 [splitView_ setVertical:isVertical]; |
161 [self updateDevToolsSplitPosition]; | 158 [self updateDevToolsSplitPosition]; |
162 } | 159 } |
163 | 160 |
164 - (void)hideDevToolsContainer { | 161 - (void)hideDevToolsContainer { |
165 NSArray* subviews = [splitView_ subviews]; | 162 NSArray* subviews = [splitView_ subviews]; |
166 DCHECK_EQ([subviews count], 2u); | 163 DCHECK_EQ([subviews count], 2u); |
167 NSView* oldDevToolsContentsView = [subviews objectAtIndex:1]; | 164 NSView* oldDevToolsContentsView = [subviews objectAtIndex:1]; |
(...skipping 25 matching lines...) Expand all Loading... |
193 NSHeight([splitView_ frame]) - ([splitView_ dividerThickness] + size); | 190 NSHeight([splitView_ frame]) - ([splitView_ dividerThickness] + size); |
194 } | 191 } |
195 | 192 |
196 [[splitView_ window] disableScreenUpdatesUntilFlush]; | 193 [[splitView_ window] disableScreenUpdatesUntilFlush]; |
197 [webView setFrame:webFrame]; | 194 [webView setFrame:webFrame]; |
198 [devToolsView setFrame:devToolsFrame]; | 195 [devToolsView setFrame:devToolsFrame]; |
199 | 196 |
200 [splitView_ adjustSubviews]; | 197 [splitView_ adjustSubviews]; |
201 } | 198 } |
202 | 199 |
| 200 - (void)updateDevToolsViewFrame { |
| 201 NSView* devToolsView = devToolsWindow_->web_contents()->GetNativeView(); |
| 202 NSRect devToolsRect = [[devToolsView superview] bounds]; |
| 203 if (devToolsWindow_->dock_side() == DEVTOOLS_DOCK_SIDE_RIGHT) |
| 204 devToolsRect.size.height -= [splitView_ topContentOffset]; |
| 205 [devToolsView setFrame:devToolsRect]; |
| 206 } |
| 207 |
203 // NSSplitViewDelegate protocol. | 208 // NSSplitViewDelegate protocol. |
204 - (BOOL)splitView:(NSSplitView *)splitView | 209 - (BOOL)splitView:(NSSplitView *)splitView |
205 shouldAdjustSizeOfSubview:(NSView *)subview { | 210 shouldAdjustSizeOfSubview:(NSView *)subview { |
206 // Return NO for the devTools view to indicate that it should not be resized | 211 // Return NO for the devTools view to indicate that it should not be resized |
207 // automatically. It preserves the height set by the user and also keeps | 212 // automatically. It preserves the height set by the user and also keeps |
208 // view height the same while changing tabs when one of the tabs shows infobar | 213 // view height the same while changing tabs when one of the tabs shows infobar |
209 // and others are not. | 214 // and others are not. |
210 if ([[splitView_ subviews] indexOfObject:subview] == 1) | 215 if ([[splitView_ subviews] indexOfObject:subview] == 1) |
211 return NO; | 216 return NO; |
212 return YES; | 217 return YES; |
213 } | 218 } |
214 | 219 |
215 - (CGFloat)splitView:(NSSplitView*)splitView | 220 - (CGFloat)splitView:(NSSplitView*)splitView |
216 constrainSplitPosition:(CGFloat)proposedPosition | 221 constrainSplitPosition:(CGFloat)proposedPosition |
217 ofSubviewAt:(NSInteger)dividerIndex { | 222 ofSubviewAt:(NSInteger)dividerIndex { |
218 if (![splitView_ isVertical] && | 223 if (![splitView_ isVertical] && |
219 proposedPosition < [splitView_ topContentOffset]) { | 224 proposedPosition < [splitView_ topContentOffset]) { |
220 return [splitView_ topContentOffset]; | 225 return [splitView_ topContentOffset]; |
221 } | 226 } |
222 return proposedPosition; | 227 return proposedPosition; |
223 } | 228 } |
224 | 229 |
225 -(void)splitViewWillResizeSubviews:(NSNotification *)notification { | 230 -(void)splitViewWillResizeSubviews:(NSNotification *)notification { |
226 [[splitView_ window] disableScreenUpdatesUntilFlush]; | 231 [[splitView_ window] disableScreenUpdatesUntilFlush]; |
227 } | 232 } |
228 | 233 |
229 @end | 234 @end |
OLD | NEW |