Chromium Code Reviews

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

Issue 2973004: [Mac]Implement ViewID support. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Turns out that, it's not a good solution. Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « chrome/browser/cocoa/side_tab_strip_view.mm ('k') | chrome/browser/cocoa/tab_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 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/tab_contents_controller.h" 5 #import "chrome/browser/cocoa/tab_contents_controller.h"
6 6
7 #include "base/mac_util.h" 7 #include "base/mac_util.h"
8 #include "base/sys_string_conversions.h" 8 #include "base/sys_string_conversions.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/bookmarks/bookmark_model.h" 10 #include "chrome/browser/bookmarks/bookmark_model.h"
11 #import "chrome/browser/cocoa/base_view.h"
11 #include "chrome/browser/pref_service.h" 12 #include "chrome/browser/pref_service.h"
12 #include "chrome/browser/renderer_host/render_view_host.h" 13 #include "chrome/browser/renderer_host/render_view_host.h"
13 #include "chrome/browser/tab_contents/tab_contents.h" 14 #include "chrome/browser/tab_contents/tab_contents.h"
14 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
15 16
16 // Default offset of the contents splitter in pixels. 17 // Default offset of the contents splitter in pixels.
17 static const int kDefaultContentsSplitOffset = 400; 18 static const int kDefaultContentsSplitOffset = 400;
18 19
19 // Never make the web part of the tab contents smaller than this (needed if the 20 // Never make the web part of the tab contents smaller than this (needed if the
20 // window is only a few pixels high). 21 // window is only a few pixels high).
(...skipping 64 matching lines...)
85 86
86 // Load the default split offset. If we are already showing devtools, we 87 // Load the default split offset. If we are already showing devtools, we
87 // will replace the default with the current devtools height. 88 // will replace the default with the current devtools height.
88 CGFloat splitOffset = g_browser_process->local_state()->GetInteger( 89 CGFloat splitOffset = g_browser_process->local_state()->GetInteger(
89 prefs::kDevToolsSplitLocation); 90 prefs::kDevToolsSplitLocation);
90 if (splitOffset == -1) { 91 if (splitOffset == -1) {
91 // Initial load, set to default value. 92 // Initial load, set to default value.
92 splitOffset = kDefaultContentsSplitOffset; 93 splitOffset = kDefaultContentsSplitOffset;
93 } 94 }
94 95
96 BaseView* devtoolsView =
97 static_cast<BaseView*>(devToolsContents->GetNativeView());
98 DCHECK([devtoolsView isKindOfClass:[BaseView class]]);
99 [devtoolsView setViewID:VIEW_ID_DEV_TOOLS_DOCKED];
95 if ([subviews count] == 1) { 100 if ([subviews count] == 1) {
96 [contentsContainer_ addSubview:devToolsContents->GetNativeView()]; 101 [contentsContainer_ addSubview:devtoolsView];
97 } else { 102 } else {
98 DCHECK_EQ([subviews count], 2u); 103 DCHECK_EQ([subviews count], 2u);
99 [contentsContainer_ replaceSubview:[subviews objectAtIndex:1] 104 [contentsContainer_ replaceSubview:[subviews objectAtIndex:1]
100 with:devToolsContents->GetNativeView()]; 105 with:devtoolsView];
101 // If devtools are already visible, keep the current size. 106 // If devtools are already visible, keep the current size.
102 splitOffset = NSHeight([devToolsContents->GetNativeView() frame]); 107 splitOffset = NSHeight([devtoolsView frame]);
103 } 108 }
104 109
105 // Make sure |splitOffset| isn't too large or too small. 110 // Make sure |splitOffset| isn't too large or too small.
106 splitOffset = MIN(splitOffset, 111 splitOffset = MIN(splitOffset,
107 NSHeight([contentsContainer_ frame]) - kMinWebHeight); 112 NSHeight([contentsContainer_ frame]) - kMinWebHeight);
108 DCHECK_GE(splitOffset, 0) << "kMinWebHeight needs to be smaller than " 113 DCHECK_GE(splitOffset, 0) << "kMinWebHeight needs to be smaller than "
109 << "smallest available tab contents space."; 114 << "smallest available tab contents space.";
110 splitOffset = MAX(0, splitOffset); 115 splitOffset = MAX(0, splitOffset);
111 116
112 // It seems as if |-setPosition:ofDividerAtIndex:| should do what's needed, 117 // It seems as if |-setPosition:ofDividerAtIndex:| should do what's needed,
113 // but I can't figure out how to use it. Manually resize web and devtools. 118 // but I can't figure out how to use it. Manually resize web and devtools.
114 NSRect devtoolsFrame = [devToolsContents->GetNativeView() frame]; 119 NSRect devtoolsFrame = [devtoolsView frame];
115 devtoolsFrame.size.height = splitOffset; 120 devtoolsFrame.size.height = splitOffset;
116 [devToolsContents->GetNativeView() setFrame:devtoolsFrame]; 121 [devtoolsView setFrame:devtoolsFrame];
117 122
118 NSRect webFrame = [[subviews objectAtIndex:0] frame]; 123 NSRect webFrame = [[subviews objectAtIndex:0] frame];
119 webFrame.size.height = NSHeight([contentsContainer_ frame]) - 124 webFrame.size.height = NSHeight([contentsContainer_ frame]) -
120 [self devToolsHeight]; 125 [self devToolsHeight];
121 [[subviews objectAtIndex:0] setFrame:webFrame]; 126 [[subviews objectAtIndex:0] setFrame:webFrame];
122 127
123 [contentsContainer_ adjustSubviews]; 128 [contentsContainer_ adjustSubviews];
124 } else { 129 } else {
125 if ([subviews count] > 1) { 130 if ([subviews count] > 1) {
126 NSView* oldDevToolsContentsView = [subviews objectAtIndex:1]; 131 NSView* oldDevToolsContentsView = [subviews objectAtIndex:1];
127 // Store split offset when hiding devtools window only. 132 // Store split offset when hiding devtools window only.
128 int splitOffset = NSHeight([oldDevToolsContentsView frame]); 133 int splitOffset = NSHeight([oldDevToolsContentsView frame]);
129 g_browser_process->local_state()->SetInteger( 134 g_browser_process->local_state()->SetInteger(
130 prefs::kDevToolsSplitLocation, splitOffset); 135 prefs::kDevToolsSplitLocation, splitOffset);
131 [oldDevToolsContentsView removeFromSuperview]; 136 [oldDevToolsContentsView removeFromSuperview];
132 } 137 }
133 } 138 }
134 } 139 }
135 140
136 - (CGFloat)devToolsHeight { 141 - (CGFloat)devToolsHeight {
137 NSArray* subviews = [contentsContainer_ subviews]; 142 NSArray* subviews = [contentsContainer_ subviews];
138 if ([subviews count] < 2) 143 if ([subviews count] < 2)
139 return 0; 144 return 0;
140 return NSHeight([[subviews objectAtIndex:1] frame]) + 145 return NSHeight([[subviews objectAtIndex:1] frame]) +
141 [contentsContainer_ dividerThickness]; 146 [contentsContainer_ dividerThickness];
142 } 147 }
143 148
144 @end 149 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/side_tab_strip_view.mm ('k') | chrome/browser/cocoa/tab_controller.h » ('j') | no next file with comments »

Powered by Google App Engine