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

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

Issue 9265018: Change grow box computation back to a method on BrowserWindow (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 8 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 15 matching lines...) Expand all
26 const int kMinDevToolsHeight = 50; 26 const int kMinDevToolsHeight = 50;
27 const int kMinDevToolsWidth = 150; 27 const int kMinDevToolsWidth = 150;
28 const int kMinContentsSize = 50; 28 const int kMinContentsSize = 50;
29 29
30 } // end namespace 30 } // end namespace
31 31
32 32
33 @interface DevToolsController (Private) 33 @interface DevToolsController (Private)
34 - (void)showDevToolsContents:(WebContents*)devToolsContents 34 - (void)showDevToolsContents:(WebContents*)devToolsContents
35 withProfile:(Profile*)profile; 35 withProfile:(Profile*)profile;
36 - (void)showDevToolsContainer:(Profile*)profile; 36 - (void)showDevToolsContainer:(NSView*)container profile:(Profile*)profile;
37 - (void)hideDevToolsContainer:(Profile*)profile; 37 - (void)hideDevToolsContainer:(Profile*)profile;
38 - (void)resizeDevTools:(CGFloat)size; 38 - (void)resizeDevTools:(CGFloat)size;
39 @end 39 @end
40 40
41 41
42 @implementation DevToolsController 42 @implementation DevToolsController
43 43
44 - (id)initWithDelegate:(id<TabContentsControllerDelegate>)delegate { 44 - (id)init {
45 if ((self = [super init])) { 45 if ((self = [super init])) {
46 splitView_.reset([[NSSplitView alloc] initWithFrame:NSZeroRect]); 46 splitView_.reset([[NSSplitView alloc] initWithFrame:NSZeroRect]);
47 [splitView_ setDividerStyle:NSSplitViewDividerStyleThin]; 47 [splitView_ setDividerStyle:NSSplitViewDividerStyleThin];
48 [splitView_ setVertical:NO]; 48 [splitView_ setVertical:NO];
49 [splitView_ setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable]; 49 [splitView_ setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
50 [splitView_ setDelegate:self];
51 50
52 dockToRight_ = NO; 51 dockToRight_ = NO;
53
54 contentsController_.reset(
55 [[TabContentsController alloc] initWithContents:NULL
56 delegate:delegate]);
57 } 52 }
58 return self; 53 return self;
59 } 54 }
60 55
61 - (void)dealloc {
62 [splitView_ setDelegate:nil];
63 [super dealloc];
64 }
65
66 - (NSView*)view { 56 - (NSView*)view {
67 return splitView_.get(); 57 return splitView_.get();
68 } 58 }
69 59
70 - (NSSplitView*)splitView { 60 - (NSSplitView*)splitView {
71 return splitView_.get(); 61 return splitView_.get();
72 } 62 }
73 63
74 - (void)updateDevToolsForWebContents:(WebContents*)contents 64 - (void)updateDevToolsForWebContents:(WebContents*)contents
75 withProfile:(Profile*)profile { 65 withProfile:(Profile*)profile {
76 // Get current devtools content. 66 // Get current devtools content.
77 TabContentsWrapper* devToolsTab = contents ? 67 TabContentsWrapper* devToolsTab = contents ?
78 DevToolsWindow::GetDevToolsContents(contents) : NULL; 68 DevToolsWindow::GetDevToolsContents(contents) : NULL;
79 WebContents* devToolsContents = devToolsTab ? 69 WebContents* devToolsContents = devToolsTab ?
80 devToolsTab->web_contents() : NULL; 70 devToolsTab->web_contents() : NULL;
81 71
82 [self showDevToolsContents:devToolsContents withProfile:profile]; 72 [self showDevToolsContents:devToolsContents withProfile:profile];
83 } 73 }
84 74
85 - (void)setDockToRight:(BOOL)dockToRight 75 - (void)setDockToRight:(BOOL)dockToRight
86 withProfile:(Profile*)profile { 76 withProfile:(Profile*)profile {
87 if (dockToRight_ == dockToRight) 77 if (dockToRight_ == dockToRight)
88 return; 78 return;
89 79
90 NSArray* subviews = [splitView_ subviews]; 80 NSArray* subviews = [splitView_ subviews];
91 if ([subviews count] == 2) { 81 if ([subviews count] == 2) {
82 scoped_nsobject<NSView> devToolsContentsView(
83 [[subviews objectAtIndex:1] retain]);
92 [self hideDevToolsContainer:profile]; 84 [self hideDevToolsContainer:profile];
93 dockToRight_ = dockToRight; 85 dockToRight_ = dockToRight;
94 [self showDevToolsContainer:profile]; 86 [self showDevToolsContainer:devToolsContentsView profile:profile];
95 } else { 87 } else {
96 dockToRight_ = dockToRight; 88 dockToRight_ = dockToRight;
97 } 89 }
98 } 90 }
99 91
100 - (void)ensureContentsVisible {
101 [contentsController_ ensureContentsVisible];
102 }
103
104 - (void)showDevToolsContents:(WebContents*)devToolsContents 92 - (void)showDevToolsContents:(WebContents*)devToolsContents
105 withProfile:(Profile*)profile { 93 withProfile:(Profile*)profile {
106 [contentsController_ ensureContentsSizeDoesNotChange];
107
108 NSArray* subviews = [splitView_ subviews]; 94 NSArray* subviews = [splitView_ subviews];
109 if (devToolsContents) { 95 if (devToolsContents) {
110 // |devToolsView| is a TabContentsViewCocoa object, whose ViewID was 96 // |devToolsView| is a TabContentsViewCocoa object, whose ViewID was
111 // set to VIEW_ID_TAB_CONTAINER initially, so we need to change it to 97 // set to VIEW_ID_TAB_CONTAINER initially, so we need to change it to
112 // VIEW_ID_DEV_TOOLS_DOCKED here. 98 // VIEW_ID_DEV_TOOLS_DOCKED here.
113 view_id_util::SetID(devToolsContents->GetNativeView(), 99 NSView* devToolsView = devToolsContents->GetNativeView();
114 VIEW_ID_DEV_TOOLS_DOCKED); 100 view_id_util::SetID(devToolsView, VIEW_ID_DEV_TOOLS_DOCKED);
115 [self showDevToolsContainer:profile]; 101 [self showDevToolsContainer:devToolsView profile:profile];
116 } else { 102 } else {
117 if ([subviews count] > 1) { 103 if ([subviews count] > 1) {
118 [self hideDevToolsContainer:profile]; 104 [self hideDevToolsContainer:profile];
119 } 105 }
120 } 106 }
121
122 [contentsController_ changeWebContents:devToolsContents];
123 } 107 }
124 108
125 - (void)showDevToolsContainer:(Profile*)profile { 109 - (void)showDevToolsContainer:(NSView*)container profile:(Profile*)profile {
126 NSArray* subviews = [splitView_ subviews]; 110 NSArray* subviews = [splitView_ subviews];
127 DCHECK_GE([subviews count], 1u); 111 DCHECK_GE([subviews count], 1u);
128 112
129 CGFloat splitOffset = 0; 113 CGFloat splitOffset = 0;
130 114
131 CGFloat contentSize = 115 CGFloat contentSize =
132 dockToRight_ ? NSWidth([splitView_ frame]) 116 dockToRight_ ? NSWidth([splitView_ frame])
133 : NSHeight([splitView_ frame]); 117 : NSHeight([splitView_ frame]);
134 118
135 if ([subviews count] == 1) { 119 if ([subviews count] == 1) {
136 // Load the default split offset. 120 // Load the default split offset.
137 splitOffset = profile->GetPrefs()-> 121 splitOffset = profile->GetPrefs()->
138 GetInteger(prefs::kDevToolsSplitLocation); 122 GetInteger(prefs::kDevToolsSplitLocation);
139 123
140 if (splitOffset < 0) 124 if (splitOffset < 0)
141 splitOffset = contentSize * 1 / 3; 125 splitOffset = contentSize * 1 / 3;
142 126
143 [splitView_ addSubview:[contentsController_ view]]; 127 [splitView_ addSubview:container];
144 } else { 128 } else {
145 DCHECK_EQ([subviews count], 2u); 129 DCHECK_EQ([subviews count], 2u);
146 // If devtools are already visible, keep the current size. 130 // If devtools are already visible, keep the current size.
147 splitOffset = dockToRight_ ? NSWidth([[subviews objectAtIndex:1] frame]) 131 splitOffset = dockToRight_ ? NSWidth([[subviews objectAtIndex:1] frame])
148 : NSHeight([[subviews objectAtIndex:1] frame]); 132 : NSHeight([[subviews objectAtIndex:1] frame]);
149 } 133 }
150 134
151 // Make sure |splitOffset| isn't too large or too small. 135 // Make sure |splitOffset| isn't too large or too small.
152 CGFloat minSize = dockToRight_ ? kMinDevToolsWidth: kMinDevToolsHeight; 136 CGFloat minSize = dockToRight_ ? kMinDevToolsWidth: kMinDevToolsHeight;
153 splitOffset = std::max(minSize, splitOffset); 137 splitOffset = std::max(minSize, splitOffset);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 // Return NO for the devTools view to indicate that it should not be resized 199 // Return NO for the devTools view to indicate that it should not be resized
216 // automatically. It preserves the height set by the user and also keeps 200 // automatically. It preserves the height set by the user and also keeps
217 // view height the same while changing tabs when one of the tabs shows infobar 201 // view height the same while changing tabs when one of the tabs shows infobar
218 // and others are not. 202 // and others are not.
219 if ([[splitView_ subviews] indexOfObject:subview] == 1) 203 if ([[splitView_ subviews] indexOfObject:subview] == 1)
220 return NO; 204 return NO;
221 return YES; 205 return YES;
222 } 206 }
223 207
224 @end 208 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/dev_tools_controller.h ('k') | chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698