| 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" |
| 11 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 14 #import "chrome/browser/ui/cocoa/view_id_util.h" | 15 #import "chrome/browser/ui/cocoa/view_id_util.h" |
| 15 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 16 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 17 | 18 |
| 18 using content::WebContents; | 19 using content::WebContents; |
| 19 | 20 |
| 20 @interface GraySplitView : NSSplitView { | 21 @interface GraySplitView : NSSplitView { |
| 21 CGFloat topContentOffset_; | 22 CGFloat topContentOffset_; |
| 22 } | 23 } |
| 23 | 24 |
| 24 @property(assign, nonatomic) CGFloat topContentOffset; | 25 @property(assign, nonatomic) CGFloat topContentOffset; |
| 25 | 26 |
| 26 - (NSColor*)dividerColor; | 27 - (NSColor*)dividerColor; |
| 27 | 28 |
| 28 @end | 29 @end |
| 29 | 30 |
| 30 | 31 |
| 31 @implementation GraySplitView | 32 @implementation GraySplitView |
| 32 | 33 |
| 33 @synthesize topContentOffset = topContentOffset_; | 34 @synthesize topContentOffset = topContentOffset_; |
| 34 | 35 |
| 35 - (NSColor*)dividerColor { | 36 - (NSColor*)dividerColor { |
| 36 return [NSColor darkGrayColor]; | 37 return [NSColor darkGrayColor]; |
| 37 } | 38 } |
| 38 | 39 |
| 40 - (void)drawDividerInRect:(NSRect)aRect { |
| 41 NSRect dividerRect = aRect; |
| 42 if ([self isVertical]) { |
| 43 dividerRect.size.height -= topContentOffset_; |
| 44 dividerRect.origin.y += topContentOffset_; |
| 45 } |
| 46 [super drawDividerInRect:dividerRect]; |
| 47 } |
| 48 |
| 39 - (NSView*)hitTest:(NSPoint)point { | 49 - (NSView*)hitTest:(NSPoint)point { |
| 40 NSPoint viewPoint = [self convertPoint:point fromView:[self superview]]; | 50 NSPoint viewPoint = [self convertPoint:point fromView:[self superview]]; |
| 41 if (viewPoint.y < topContentOffset_) | 51 if (viewPoint.y < topContentOffset_) |
| 42 return nil; | 52 return nil; |
| 43 return [super hitTest:point]; | 53 return [super hitTest:point]; |
| 44 } | 54 } |
| 45 | 55 |
| 46 @end | 56 @end |
| 47 | 57 |
| 58 // Superview for the dev tools contents view. This class ensures that dev tools |
| 59 // view doesn't overlap the toolbar when split vertically. |
| 60 @interface DevToolsContainerView : NSView |
| 61 @end |
| 62 |
| 63 @implementation DevToolsContainerView |
| 64 |
| 65 - (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize { |
| 66 NSRect subviewFrame = [self bounds]; |
| 67 GraySplitView* splitView = |
| 68 base::mac::ObjCCastStrict<GraySplitView>([self superview]); |
| 69 if ([splitView isVertical]) |
| 70 subviewFrame.size.height -= [splitView topContentOffset]; |
| 71 |
| 72 DCHECK_EQ(1u, [[self subviews] count]); |
| 73 [[[self subviews] lastObject] setFrame:subviewFrame]; |
| 74 } |
| 75 |
| 76 @end |
| 77 |
| 48 | 78 |
| 49 @interface DevToolsController (Private) | 79 @interface DevToolsController (Private) |
| 50 - (void)showDevToolsContainer; | 80 - (void)showDevToolsContainer; |
| 51 - (void)hideDevToolsContainer; | 81 - (void)hideDevToolsContainer; |
| 52 - (void)updateDevToolsSplitPosition; | 82 - (void)updateDevToolsSplitPosition; |
| 53 @end | 83 @end |
| 54 | 84 |
| 55 | 85 |
| 56 @implementation DevToolsController | 86 @implementation DevToolsController |
| 57 | 87 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 - (void)showDevToolsContainer { | 155 - (void)showDevToolsContainer { |
| 126 NSArray* subviews = [splitView_ subviews]; | 156 NSArray* subviews = [splitView_ subviews]; |
| 127 DCHECK_EQ([subviews count], 1u); | 157 DCHECK_EQ([subviews count], 1u); |
| 128 WebContents* devToolsContents = devToolsWindow_->web_contents(); | 158 WebContents* devToolsContents = devToolsWindow_->web_contents(); |
| 129 | 159 |
| 130 // |devToolsView| is a TabContentsViewCocoa object, whose ViewID was | 160 // |devToolsView| is a TabContentsViewCocoa object, whose ViewID was |
| 131 // set to VIEW_ID_TAB_CONTAINER initially, so we need to change it to | 161 // set to VIEW_ID_TAB_CONTAINER initially, so we need to change it to |
| 132 // VIEW_ID_DEV_TOOLS_DOCKED here. | 162 // VIEW_ID_DEV_TOOLS_DOCKED here. |
| 133 NSView* devToolsView = devToolsContents->GetNativeView(); | 163 NSView* devToolsView = devToolsContents->GetNativeView(); |
| 134 view_id_util::SetID(devToolsView, VIEW_ID_DEV_TOOLS_DOCKED); | 164 view_id_util::SetID(devToolsView, VIEW_ID_DEV_TOOLS_DOCKED); |
| 135 [splitView_ addSubview:devToolsView]; | 165 |
| 166 scoped_nsobject<DevToolsContainerView> devToolsContainerView( |
| 167 [[DevToolsContainerView alloc] initWithFrame:[devToolsView bounds]]); |
| 168 [devToolsContainerView addSubview:devToolsView]; |
| 169 [splitView_ addSubview:devToolsContainerView]; |
| 136 | 170 |
| 137 BOOL isVertical = devToolsWindow_->dock_side() == DEVTOOLS_DOCK_SIDE_RIGHT; | 171 BOOL isVertical = devToolsWindow_->dock_side() == DEVTOOLS_DOCK_SIDE_RIGHT; |
| 138 [splitView_ setVertical:isVertical]; | 172 [splitView_ setVertical:isVertical]; |
| 139 [self updateDevToolsSplitPosition]; | 173 [self updateDevToolsSplitPosition]; |
| 140 } | 174 } |
| 141 | 175 |
| 142 - (void)hideDevToolsContainer { | 176 - (void)hideDevToolsContainer { |
| 143 NSArray* subviews = [splitView_ subviews]; | 177 NSArray* subviews = [splitView_ subviews]; |
| 144 DCHECK_EQ([subviews count], 2u); | 178 DCHECK_EQ([subviews count], 2u); |
| 145 NSView* oldDevToolsContentsView = [subviews objectAtIndex:1]; | 179 NSView* oldDevToolsContentsView = [subviews objectAtIndex:1]; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 shouldAdjustSizeOfSubview:(NSView *)subview { | 217 shouldAdjustSizeOfSubview:(NSView *)subview { |
| 184 // Return NO for the devTools view to indicate that it should not be resized | 218 // Return NO for the devTools view to indicate that it should not be resized |
| 185 // automatically. It preserves the height set by the user and also keeps | 219 // automatically. It preserves the height set by the user and also keeps |
| 186 // view height the same while changing tabs when one of the tabs shows infobar | 220 // view height the same while changing tabs when one of the tabs shows infobar |
| 187 // and others are not. | 221 // and others are not. |
| 188 if ([[splitView_ subviews] indexOfObject:subview] == 1) | 222 if ([[splitView_ subviews] indexOfObject:subview] == 1) |
| 189 return NO; | 223 return NO; |
| 190 return YES; | 224 return YES; |
| 191 } | 225 } |
| 192 | 226 |
| 227 - (CGFloat)splitView:(NSSplitView*)splitView |
| 228 constrainSplitPosition:(CGFloat)proposedPosition |
| 229 ofSubviewAt:(NSInteger)dividerIndex { |
| 230 if (![splitView_ isVertical] && |
| 231 proposedPosition < [splitView_ topContentOffset]) { |
| 232 return [splitView_ topContentOffset]; |
| 233 } |
| 234 return proposedPosition; |
| 235 } |
| 236 |
| 193 -(void)splitViewWillResizeSubviews:(NSNotification *)notification { | 237 -(void)splitViewWillResizeSubviews:(NSNotification *)notification { |
| 194 [[splitView_ window] disableScreenUpdatesUntilFlush]; | 238 [[splitView_ window] disableScreenUpdatesUntilFlush]; |
| 195 } | 239 } |
| 196 | 240 |
| 197 @end | 241 @end |
| OLD | NEW |