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

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

Issue 2878037: [Mac]Implement ViewID support. (third approach) (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Update according to review feedback. Created 10 years, 5 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
« no previous file with comments | « chrome/browser/cocoa/reload_button.mm ('k') | chrome/browser/cocoa/tab_strip_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/view_id_util.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...) Expand 10 before | Expand all | Expand 10 after
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 // |devtoolsView| is a TabContentsViewCocoa object, whose ViewID was
97 // set to VIEW_ID_TAB_CONTAINER initially, so we need to change it to
98 // VIEW_ID_DEV_TOOLS_DOCKED here.
99 NSView* devtoolsView = devToolsContents->GetNativeView();
100 view_id_util::SetID(devtoolsView, VIEW_ID_DEV_TOOLS_DOCKED);
95 if ([subviews count] == 1) { 101 if ([subviews count] == 1) {
96 [contentsContainer_ addSubview:devToolsContents->GetNativeView()]; 102 [contentsContainer_ addSubview:devtoolsView];
97 } else { 103 } else {
98 DCHECK_EQ([subviews count], 2u); 104 DCHECK_EQ([subviews count], 2u);
99 [contentsContainer_ replaceSubview:[subviews objectAtIndex:1] 105 [contentsContainer_ replaceSubview:[subviews objectAtIndex:1]
100 with:devToolsContents->GetNativeView()]; 106 with:devToolsContents->GetNativeView()];
101 // If devtools are already visible, keep the current size. 107 // If devtools are already visible, keep the current size.
102 splitOffset = NSHeight([devToolsContents->GetNativeView() frame]); 108 splitOffset = NSHeight([devtoolsView frame]);
103 } 109 }
104 110
105 // Make sure |splitOffset| isn't too large or too small. 111 // Make sure |splitOffset| isn't too large or too small.
106 splitOffset = MIN(splitOffset, 112 splitOffset = MIN(splitOffset,
107 NSHeight([contentsContainer_ frame]) - kMinWebHeight); 113 NSHeight([contentsContainer_ frame]) - kMinWebHeight);
108 DCHECK_GE(splitOffset, 0) << "kMinWebHeight needs to be smaller than " 114 DCHECK_GE(splitOffset, 0) << "kMinWebHeight needs to be smaller than "
109 << "smallest available tab contents space."; 115 << "smallest available tab contents space.";
110 splitOffset = MAX(0, splitOffset); 116 splitOffset = MAX(0, splitOffset);
111 117
112 // It seems as if |-setPosition:ofDividerAtIndex:| should do what's needed, 118 // 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. 119 // but I can't figure out how to use it. Manually resize web and devtools.
114 NSRect devtoolsFrame = [devToolsContents->GetNativeView() frame]; 120 NSRect devtoolsFrame = [devtoolsView frame];
115 devtoolsFrame.size.height = splitOffset; 121 devtoolsFrame.size.height = splitOffset;
116 [devToolsContents->GetNativeView() setFrame:devtoolsFrame]; 122 [devtoolsView setFrame:devtoolsFrame];
117 123
118 NSRect webFrame = [[subviews objectAtIndex:0] frame]; 124 NSRect webFrame = [[subviews objectAtIndex:0] frame];
119 webFrame.size.height = NSHeight([contentsContainer_ frame]) - 125 webFrame.size.height = NSHeight([contentsContainer_ frame]) -
120 [self devToolsHeight]; 126 [self devToolsHeight];
121 [[subviews objectAtIndex:0] setFrame:webFrame]; 127 [[subviews objectAtIndex:0] setFrame:webFrame];
122 128
123 [contentsContainer_ adjustSubviews]; 129 [contentsContainer_ adjustSubviews];
124 } else { 130 } else {
125 if ([subviews count] > 1) { 131 if ([subviews count] > 1) {
126 NSView* oldDevToolsContentsView = [subviews objectAtIndex:1]; 132 NSView* oldDevToolsContentsView = [subviews objectAtIndex:1];
127 // Store split offset when hiding devtools window only. 133 // Store split offset when hiding devtools window only.
128 int splitOffset = NSHeight([oldDevToolsContentsView frame]); 134 int splitOffset = NSHeight([oldDevToolsContentsView frame]);
129 g_browser_process->local_state()->SetInteger( 135 g_browser_process->local_state()->SetInteger(
130 prefs::kDevToolsSplitLocation, splitOffset); 136 prefs::kDevToolsSplitLocation, splitOffset);
131 [oldDevToolsContentsView removeFromSuperview]; 137 [oldDevToolsContentsView removeFromSuperview];
132 } 138 }
133 } 139 }
134 } 140 }
135 141
136 - (CGFloat)devToolsHeight { 142 - (CGFloat)devToolsHeight {
137 NSArray* subviews = [contentsContainer_ subviews]; 143 NSArray* subviews = [contentsContainer_ subviews];
138 if ([subviews count] < 2) 144 if ([subviews count] < 2)
139 return 0; 145 return 0;
140 return NSHeight([[subviews objectAtIndex:1] frame]) + 146 return NSHeight([[subviews objectAtIndex:1] frame]) +
141 [contentsContainer_ dividerThickness]; 147 [contentsContainer_ dividerThickness];
142 } 148 }
143 149
144 @end 150 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/reload_button.mm ('k') | chrome/browser/cocoa/tab_strip_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698