Chromium Code Reviews| 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 |
| 11 #import "base/mac/foundation_util.h" | |
| 12 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 13 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 15 #import "chrome/browser/ui/cocoa/view_id_util.h" | 14 #import "chrome/browser/ui/cocoa/view_id_util.h" |
| 16 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 17 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 18 #include "content/public/browser/web_contents_view.h" | 17 #include "content/public/browser/web_contents_view.h" |
| 19 | 18 |
| 20 using content::WebContents; | 19 using content::WebContents; |
| 21 | 20 |
| 22 @interface GraySplitView : NSSplitView { | 21 @interface GraySplitView : NSSplitView { |
| 23 CGFloat topContentOffset_; | |
| 24 BOOL dividerHidden_; | 22 BOOL dividerHidden_; |
| 25 } | 23 } |
| 26 | 24 |
| 27 @property(assign, nonatomic) CGFloat topContentOffset; | |
| 28 @property(assign, nonatomic) BOOL dividerHidden; | 25 @property(assign, nonatomic) BOOL dividerHidden; |
| 29 | 26 |
| 30 - (NSColor*)dividerColor; | 27 - (NSColor*)dividerColor; |
| 31 - (CGFloat)dividerThickness; | 28 - (CGFloat)dividerThickness; |
| 32 | 29 |
| 33 @end | 30 @end |
| 34 | 31 |
| 35 | 32 |
| 36 @implementation GraySplitView | 33 @implementation GraySplitView |
| 37 | 34 |
| 38 @synthesize topContentOffset = topContentOffset_; | |
| 39 @synthesize dividerHidden = dividerHidden_; | 35 @synthesize dividerHidden = dividerHidden_; |
| 40 | 36 |
| 41 - (NSColor*)dividerColor { | 37 - (NSColor*)dividerColor { |
| 42 return [NSColor darkGrayColor]; | 38 return [NSColor darkGrayColor]; |
| 43 } | 39 } |
| 44 | 40 |
| 45 - (CGFloat)dividerThickness { | 41 - (CGFloat)dividerThickness { |
| 46 return dividerHidden_ ? 0 : [super dividerThickness]; | 42 return dividerHidden_ ? 0 : [super dividerThickness]; |
| 47 } | 43 } |
| 48 | 44 |
| 49 - (void)drawDividerInRect:(NSRect)aRect { | |
| 50 NSRect dividerRect = aRect; | |
| 51 if ([self isVertical]) { | |
| 52 dividerRect.size.height -= topContentOffset_; | |
| 53 dividerRect.origin.y += topContentOffset_; | |
| 54 } | |
| 55 [super drawDividerInRect:dividerRect]; | |
| 56 } | |
| 57 | |
| 58 - (NSView*)hitTest:(NSPoint)point { | |
| 59 NSPoint viewPoint = [self convertPoint:point fromView:[self superview]]; | |
| 60 if (viewPoint.y < topContentOffset_) | |
| 61 return nil; | |
| 62 return [super hitTest:point]; | |
| 63 } | |
| 64 | |
| 65 @end | 45 @end |
| 66 | 46 |
| 67 @interface DevToolsController (Private) | 47 @interface DevToolsController (Private) |
| 68 - (void)showDevToolsContainer; | 48 - (void)showDevToolsContainer; |
| 69 - (void)hideDevToolsContainer; | 49 - (void)hideDevToolsContainer; |
| 70 - (void)updateDevToolsSplitPosition; | 50 - (void)updateDevToolsSplitPosition; |
| 71 - (void)updateDevToolsViewFrame; | |
| 72 @end | 51 @end |
| 73 | 52 |
| 74 | 53 |
| 75 @implementation DevToolsController | 54 @implementation DevToolsController |
| 76 | 55 |
| 77 - (id)init { | 56 - (id)init { |
| 78 if ((self = [super init])) { | 57 if ((self = [super init])) { |
| 79 splitView_.reset([[GraySplitView alloc] initWithFrame:NSZeroRect]); | 58 splitView_.reset([[GraySplitView alloc] initWithFrame:NSZeroRect]); |
| 80 [splitView_ setDividerStyle:NSSplitViewDividerStyleThin]; | 59 [splitView_ setDividerStyle:NSSplitViewDividerStyleThin]; |
| 81 [splitView_ setVertical:NO]; | 60 [splitView_ setVertical:NO]; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 [self hideDevToolsContainer]; | 108 [self hideDevToolsContainer]; |
| 130 | 109 |
| 131 devToolsWindow_ = newDevToolsWindow; | 110 devToolsWindow_ = newDevToolsWindow; |
| 132 | 111 |
| 133 if (devToolsWindow_) { | 112 if (devToolsWindow_) { |
| 134 dockSide_ = devToolsWindow_->dock_side(); | 113 dockSide_ = devToolsWindow_->dock_side(); |
| 135 [self showDevToolsContainer]; | 114 [self showDevToolsContainer]; |
| 136 } | 115 } |
| 137 } | 116 } |
| 138 | 117 |
| 139 - (CGFloat)topContentOffset { | |
| 140 return [splitView_ topContentOffset]; | |
| 141 } | |
| 142 | |
| 143 - (void)setTopContentOffset:(CGFloat)offset { | |
| 144 [splitView_ setTopContentOffset:offset]; | |
| 145 if ([[splitView_ subviews] count] > 1) | |
| 146 [self updateDevToolsViewFrame]; | |
| 147 } | |
| 148 | |
| 149 - (void)showDevToolsContainer { | 118 - (void)showDevToolsContainer { |
| 150 NSArray* subviews = [splitView_ subviews]; | 119 NSArray* subviews = [splitView_ subviews]; |
| 151 DCHECK_EQ([subviews count], 1u); | 120 DCHECK_EQ([subviews count], 1u); |
| 152 WebContents* devToolsContents = devToolsWindow_->web_contents(); | 121 WebContents* devToolsContents = devToolsWindow_->web_contents(); |
| 153 | 122 |
| 154 // |devToolsView| is a TabContentsViewCocoa object, whose ViewID was | 123 // |devToolsView| is a TabContentsViewCocoa object, whose ViewID was |
| 155 // set to VIEW_ID_TAB_CONTAINER initially, so we need to change it to | 124 // set to VIEW_ID_TAB_CONTAINER initially, so we need to change it to |
| 156 // VIEW_ID_DEV_TOOLS_DOCKED here. | 125 // VIEW_ID_DEV_TOOLS_DOCKED here. |
| 157 NSView* devToolsView = devToolsContents->GetView()->GetNativeView(); | 126 NSView* devToolsView = devToolsContents->GetView()->GetNativeView(); |
| 158 view_id_util::SetID(devToolsView, VIEW_ID_DEV_TOOLS_DOCKED); | 127 view_id_util::SetID(devToolsView, VIEW_ID_DEV_TOOLS_DOCKED); |
| 159 [devToolsView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; | 128 [splitView_ addSubview:devToolsView]; |
|
Robert Sesek
2013/06/27 13:29:48
Did you mean to remove the autoresizing mask?
sail
2013/06/27 18:26:03
Yea. I added the resizing mask when I put devTools
| |
| 160 | |
| 161 NSRect containerRect = NSMakeRect(0, 0, 100, 100); | |
| 162 base::scoped_nsobject<NSView> devToolsContainerView( | |
| 163 [[NSView alloc] initWithFrame:containerRect]); | |
| 164 [devToolsContainerView addSubview:devToolsView]; | |
| 165 [splitView_ addSubview:devToolsContainerView]; | |
| 166 | 129 |
| 167 BOOL isVertical = devToolsWindow_->dock_side() == DEVTOOLS_DOCK_SIDE_RIGHT; | 130 BOOL isVertical = devToolsWindow_->dock_side() == DEVTOOLS_DOCK_SIDE_RIGHT; |
| 168 [splitView_ setVertical:isVertical]; | 131 [splitView_ setVertical:isVertical]; |
| 169 [self updateDevToolsSplitPosition]; | 132 [self updateDevToolsSplitPosition]; |
| 170 [self updateDevToolsViewFrame]; | |
| 171 } | 133 } |
| 172 | 134 |
| 173 - (void)hideDevToolsContainer { | 135 - (void)hideDevToolsContainer { |
| 174 NSArray* subviews = [splitView_ subviews]; | 136 NSArray* subviews = [splitView_ subviews]; |
| 175 DCHECK_EQ([subviews count], 2u); | 137 DCHECK_EQ([subviews count], 2u); |
| 176 NSView* oldDevToolsContentsView = [subviews objectAtIndex:1]; | 138 NSView* oldDevToolsContentsView = [subviews objectAtIndex:1]; |
| 177 [oldDevToolsContentsView removeFromSuperview]; | 139 [oldDevToolsContentsView removeFromSuperview]; |
| 178 [splitView_ adjustSubviews]; | 140 [splitView_ adjustSubviews]; |
| 179 } | 141 } |
| 180 | 142 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 208 NSHeight([splitView_ frame]) - ([splitView_ dividerThickness] + size); | 170 NSHeight([splitView_ frame]) - ([splitView_ dividerThickness] + size); |
| 209 } | 171 } |
| 210 | 172 |
| 211 [[splitView_ window] disableScreenUpdatesUntilFlush]; | 173 [[splitView_ window] disableScreenUpdatesUntilFlush]; |
| 212 [webView setFrame:webFrame]; | 174 [webView setFrame:webFrame]; |
| 213 [devToolsView setFrame:devToolsFrame]; | 175 [devToolsView setFrame:devToolsFrame]; |
| 214 | 176 |
| 215 [splitView_ adjustSubviews]; | 177 [splitView_ adjustSubviews]; |
| 216 } | 178 } |
| 217 | 179 |
| 218 - (void)updateDevToolsViewFrame { | |
| 219 NSView* devToolsView = | |
| 220 devToolsWindow_->web_contents()->GetView()->GetNativeView(); | |
| 221 NSRect devToolsRect = [[devToolsView superview] bounds]; | |
| 222 if (devToolsWindow_->dock_side() == DEVTOOLS_DOCK_SIDE_RIGHT) | |
| 223 devToolsRect.size.height -= [splitView_ topContentOffset]; | |
| 224 [devToolsView setFrame:devToolsRect]; | |
| 225 } | |
| 226 | |
| 227 // NSSplitViewDelegate protocol. | 180 // NSSplitViewDelegate protocol. |
| 228 - (BOOL)splitView:(NSSplitView *)splitView | 181 - (BOOL)splitView:(NSSplitView *)splitView |
| 229 shouldAdjustSizeOfSubview:(NSView *)subview { | 182 shouldAdjustSizeOfSubview:(NSView *)subview { |
| 230 // Return NO for the devTools view to indicate that it should not be resized | 183 // Return NO for the devTools view to indicate that it should not be resized |
| 231 // automatically. It preserves the height set by the user and also keeps | 184 // automatically. It preserves the height set by the user and also keeps |
| 232 // view height the same while changing tabs when one of the tabs shows infobar | 185 // view height the same while changing tabs when one of the tabs shows infobar |
| 233 // and others are not. | 186 // and others are not. |
| 234 if ([[splitView_ subviews] indexOfObject:subview] == 1) | 187 if ([[splitView_ subviews] indexOfObject:subview] == 1) |
| 235 return NO; | 188 return NO; |
| 236 return YES; | 189 return YES; |
| 237 } | 190 } |
| 238 | 191 |
| 239 - (CGFloat)splitView:(NSSplitView*)splitView | |
| 240 constrainSplitPosition:(CGFloat)proposedPosition | |
| 241 ofSubviewAt:(NSInteger)dividerIndex { | |
| 242 if (![splitView_ isVertical] && | |
| 243 proposedPosition < [splitView_ topContentOffset]) { | |
| 244 return [splitView_ topContentOffset]; | |
| 245 } | |
| 246 return proposedPosition; | |
| 247 } | |
| 248 | |
| 249 - (NSRect)splitView:(NSSplitView*)splitView | 192 - (NSRect)splitView:(NSSplitView*)splitView |
| 250 effectiveRect:(NSRect)proposedEffectiveRect | 193 effectiveRect:(NSRect)proposedEffectiveRect |
| 251 forDrawnRect:(NSRect)drawnRect | 194 forDrawnRect:(NSRect)drawnRect |
| 252 ofDividerAtIndex:(NSInteger)dividerIndex { | 195 ofDividerAtIndex:(NSInteger)dividerIndex { |
| 253 if (devToolsWindow_->dock_side() == DEVTOOLS_DOCK_SIDE_MINIMIZED) { | 196 if (devToolsWindow_->dock_side() == DEVTOOLS_DOCK_SIDE_MINIMIZED) { |
| 254 return NSZeroRect; | 197 return NSZeroRect; |
| 255 } else { | 198 } else { |
| 256 return proposedEffectiveRect; | 199 return proposedEffectiveRect; |
| 257 } | 200 } |
| 258 } | 201 } |
| 259 | 202 |
| 260 - (CGFloat)splitView:(NSSplitView*)splitView | 203 - (CGFloat)splitView:(NSSplitView*)splitView |
| 261 constrainMaxCoordinate:(CGFloat)proposedMax | 204 constrainMaxCoordinate:(CGFloat)proposedMax |
| 262 ofSubviewAt:(NSInteger)dividerIndex { | 205 ofSubviewAt:(NSInteger)dividerIndex { |
| 263 if ([splitView_ isVertical]) { | 206 if ([splitView_ isVertical]) { |
| 264 return NSWidth([splitView_ frame]) - [splitView_ dividerThickness] - | 207 return NSWidth([splitView_ frame]) - [splitView_ dividerThickness] - |
| 265 devToolsWindow_->GetMinimumWidth(); | 208 devToolsWindow_->GetMinimumWidth(); |
| 266 } else { | 209 } else { |
| 267 return NSHeight([splitView_ frame]) - [splitView_ dividerThickness] - | 210 return NSHeight([splitView_ frame]) - [splitView_ dividerThickness] - |
| 268 devToolsWindow_->GetMinimumHeight(); | 211 devToolsWindow_->GetMinimumHeight(); |
| 269 } | 212 } |
| 270 } | 213 } |
| 271 | 214 |
| 272 -(void)splitViewWillResizeSubviews:(NSNotification *)notification { | 215 -(void)splitViewWillResizeSubviews:(NSNotification *)notification { |
| 273 [[splitView_ window] disableScreenUpdatesUntilFlush]; | 216 [[splitView_ window] disableScreenUpdatesUntilFlush]; |
| 274 } | 217 } |
| 275 | 218 |
| 276 @end | 219 @end |
| OLD | NEW |