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

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

Issue 607723002: mac: Refactor tab strip layout logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tabstrip_relayout_bug_base
Patch Set: Fix unit test. Created 6 years, 2 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/browser_window_layout.h" 5 #import "chrome/browser/ui/cocoa/browser_window_layout.h"
6 6
7 #include <string.h>
8
7 #include "base/logging.h" 9 #include "base/logging.h"
10 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
8 11
9 namespace chrome { 12 namespace chrome {
10 13
11 const CGFloat kTabStripHeight = 37; 14 const CGFloat kTabStripHeight = 37;
12 15
13 } // namespace chrome 16 } // namespace chrome
14 17
15 namespace { 18 namespace {
16 19
17 // Insets for the location bar, used when the full toolbar is hidden. 20 // Insets for the location bar, used when the full toolbar is hidden.
18 // TODO(viettrungluu): We can argue about the "correct" insetting; I like the 21 // TODO(viettrungluu): We can argue about the "correct" insetting; I like the
19 // following best, though arguably 0 inset is better/more correct. 22 // following best, though arguably 0 inset is better/more correct.
20 const CGFloat kLocBarLeftRightInset = 1; 23 const CGFloat kLocBarLeftRightInset = 1;
21 const CGFloat kLocBarTopInset = 0; 24 const CGFloat kLocBarTopInset = 0;
22 const CGFloat kLocBarBottomInset = 1; 25 const CGFloat kLocBarBottomInset = 1;
23 26
27 // Space between the incognito badge and the right edge of the window.
28 const CGFloat kAvatarRightOffset = 4;
29
24 } // namespace 30 } // namespace
25 31
26 @interface BrowserWindowLayout () 32 @interface BrowserWindowLayout ()
27 33
28 // Computes the y offset to use when laying out the tab strip in fullscreen 34 // Computes the y offset to use when laying out the tab strip in fullscreen
29 // mode. 35 // mode.
30 - (void)computeFullscreenYOffset; 36 - (void)computeFullscreenYOffset;
31 37
32 // Computes the layout of the tab strip. 38 // Computes the layout of the tab strip.
33 - (void)computeTabStripLayout; 39 - (void)computeTabStripLayout;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 80 }
75 81
76 - (void)setFullscreenToolbarFraction:(CGFloat)toolbarFraction { 82 - (void)setFullscreenToolbarFraction:(CGFloat)toolbarFraction {
77 parameters_.toolbarFraction = toolbarFraction; 83 parameters_.toolbarFraction = toolbarFraction;
78 } 84 }
79 85
80 - (void)setHasTabStrip:(BOOL)hasTabStrip { 86 - (void)setHasTabStrip:(BOOL)hasTabStrip {
81 parameters_.hasTabStrip = hasTabStrip; 87 parameters_.hasTabStrip = hasTabStrip;
82 } 88 }
83 89
90 - (void)setFullscreenButtonFrame:(NSRect)frame {
91 parameters_.fullscreenButtonFrame = frame;
92 }
93
94 - (void)setShouldShowAvatar:(BOOL)shouldShowAvatar {
95 parameters_.shouldShowAvatar = shouldShowAvatar;
96 }
97
98 - (void)setShouldUseNewAvatar:(BOOL)shouldUseNewAvatar {
99 parameters_.shouldUseNewAvatar = shouldUseNewAvatar;
100 }
101
102 - (void)setAvatarSize:(NSSize)avatarSize {
103 parameters_.avatarSize = avatarSize;
104 }
105
106 - (void)setAvatarLineWidth:(BOOL)avatarLineWidth {
107 parameters_.avatarLineWidth = avatarLineWidth;
108 }
109
84 - (void)setHasToolbar:(BOOL)hasToolbar { 110 - (void)setHasToolbar:(BOOL)hasToolbar {
85 parameters_.hasToolbar = hasToolbar; 111 parameters_.hasToolbar = hasToolbar;
86 } 112 }
87 113
88 - (void)setHasLocationBar:(BOOL)hasLocationBar { 114 - (void)setHasLocationBar:(BOOL)hasLocationBar {
89 parameters_.hasLocationBar = hasLocationBar; 115 parameters_.hasLocationBar = hasLocationBar;
90 } 116 }
91 117
92 - (void)setToolbarHeight:(CGFloat)toolbarHeight { 118 - (void)setToolbarHeight:(CGFloat)toolbarHeight {
93 parameters_.toolbarHeight = toolbarHeight; 119 parameters_.toolbarHeight = toolbarHeight;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 // the floating bar and the extra offset needed to dodge the menu bar. 159 // the floating bar and the extra offset needed to dodge the menu bar.
134 yOffset += std::floor((1 - parameters_.toolbarFraction) * 160 yOffset += std::floor((1 - parameters_.toolbarFraction) *
135 [self fullscreenBackingBarHeight]); 161 [self fullscreenBackingBarHeight]);
136 break; 162 break;
137 } 163 }
138 } 164 }
139 fullscreenYOffset_ = yOffset; 165 fullscreenYOffset_ = yOffset;
140 } 166 }
141 167
142 - (void)computeTabStripLayout { 168 - (void)computeTabStripLayout {
143 if (parameters_.hasTabStrip) { 169 if (!parameters_.hasTabStrip) {
144 maxY_ = parameters_.windowSize.height + fullscreenYOffset_;
145 CGFloat width = parameters_.contentViewSize.width;
146 output_.tabStripFrame = NSMakeRect(
147 0, maxY_ - chrome::kTabStripHeight, width, chrome::kTabStripHeight);
148 maxY_ = NSMinY(output_.tabStripFrame);
149 } else {
150 maxY_ = parameters_.contentViewSize.height + fullscreenYOffset_; 170 maxY_ = parameters_.contentViewSize.height + fullscreenYOffset_;
171 return;
151 } 172 }
173
174 // Temporary variable to hold the output.
175 chrome::TabStripLayout layout = {};
176
177 // Lay out the tab strip.
178 maxY_ = parameters_.windowSize.height + fullscreenYOffset_;
179 CGFloat width = parameters_.contentViewSize.width;
180 layout.frame = NSMakeRect(
181 0, maxY_ - chrome::kTabStripHeight, width, chrome::kTabStripHeight);
182 maxY_ = NSMinY(layout.frame);
183
184 // In Yosemite fullscreen, manually add the traffic light buttons to the tab
185 // strip.
186 layout.addCustomWindowControls =
187 parameters_.inAnyFullscreen && base::mac::IsOSYosemiteOrLater();
188
189 // Set left indentation based on fullscreen mode status.
190 if (!parameters_.inAnyFullscreen || layout.addCustomWindowControls)
191 layout.leftIndent = [TabStripController defaultLeftIndentForControls];
192
193 // Lay out the icognito/avatar badge because calculating the indentation on
194 // the right depends on it.
195 if (parameters_.shouldShowAvatar) {
196 CGFloat badgeXOffset = -kAvatarRightOffset;
197 CGFloat badgeYOffset = 0;
198 CGFloat buttonHeight = parameters_.avatarSize.height;
199
200 if (parameters_.shouldUseNewAvatar) {
201 // The fullscreen icon is displayed to the right of the avatar button.
202 if (!parameters_.inAnyFullscreen &&
203 !NSIsEmptyRect(parameters_.fullscreenButtonFrame)) {
204 badgeXOffset -= width - NSMinX(parameters_.fullscreenButtonFrame);
205 }
206 // Center the button vertically on the tabstrip.
207 badgeYOffset = (chrome::kTabStripHeight - buttonHeight) / 2;
208 } else {
209 // Actually place the badge *above* |maxY|, by +2 to miss the divider.
210 badgeYOffset = 2 * parameters_.avatarLineWidth;
211 }
212
213 NSSize size = NSMakeSize(parameters_.avatarSize.width,
214 std::min(buttonHeight, chrome::kTabStripHeight));
215 NSPoint origin =
216 NSMakePoint(width - parameters_.avatarSize.width + badgeXOffset,
217 maxY_ + badgeYOffset);
218 layout.avatarFrame =
219 NSMakeRect(origin.x, origin.y, size.width, size.height);
220 }
221
222 // Calculate the right indentation. The default indentation built into the
223 // tabstrip leaves enough room for the fullscreen button on Lion (10.7) to
224 // Mavericks (10.9). On 10.6 and >=10.10, the right indent needs to be
225 // adjusted to make room for the new tab button when an avatar is present.
226 CGFloat rightIndent = 0;
227 if (!parameters_.inAnyFullscreen &&
228 !NSIsEmptyRect(parameters_.fullscreenButtonFrame)) {
229 rightIndent = width - NSMinX(parameters_.fullscreenButtonFrame);
230
231 if (parameters_.shouldUseNewAvatar) {
232 // The new avatar button is to the left of the fullscreen button.
233 // (The old avatar button is to the right).
234 rightIndent += parameters_.avatarSize.width + kAvatarRightOffset;
235 }
236 } else if (parameters_.shouldShowAvatar) {
237 rightIndent += parameters_.avatarSize.width + kAvatarRightOffset;
238 }
239 layout.rightIndent = rightIndent;
240
241 output_.tabStripLayout = layout;
152 } 242 }
153 243
154 - (void)computeContentViewLayout { 244 - (void)computeContentViewLayout {
155 chrome::LayoutParameters parameters = parameters_; 245 chrome::LayoutParameters parameters = parameters_;
156 CGFloat maxY = maxY_; 246 CGFloat maxY = maxY_;
157 247
158 // Sanity-check |maxY|. 248 // Sanity-check |maxY|.
159 DCHECK_GE(maxY, 0); 249 DCHECK_GE(maxY, 0);
160 DCHECK_LE(maxY, parameters_.contentViewSize.height + fullscreenYOffset_); 250 DCHECK_LE(maxY, parameters_.contentViewSize.height + fullscreenYOffset_);
161 251
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 minY = NSMaxY(output_.downloadShelfFrame); 329 minY = NSMaxY(output_.downloadShelfFrame);
240 } 330 }
241 331
242 if (parameters_.inAnyFullscreen && 332 if (parameters_.inAnyFullscreen &&
243 parameters_.slidingStyle == fullscreen_mac::OMNIBOX_TABS_PRESENT) { 333 parameters_.slidingStyle == fullscreen_mac::OMNIBOX_TABS_PRESENT) {
244 // If in Canonical Fullscreen, content should be shifted down by an amount 334 // If in Canonical Fullscreen, content should be shifted down by an amount
245 // equal to all the widgets and views at the top of the window. It should 335 // equal to all the widgets and views at the top of the window. It should
246 // not be further shifted by the appearance/disappearance of the AppKit 336 // not be further shifted by the appearance/disappearance of the AppKit
247 // menu bar. 337 // menu bar.
248 maxY = parameters_.windowSize.height; 338 maxY = parameters_.windowSize.height;
249 maxY -= NSHeight(output_.toolbarFrame) + NSHeight(output_.tabStripFrame) + 339 maxY -= NSHeight(output_.toolbarFrame) +
340 NSHeight(output_.tabStripLayout.frame) +
250 NSHeight(output_.bookmarkFrame) + parameters.infoBarHeight; 341 NSHeight(output_.bookmarkFrame) + parameters.infoBarHeight;
251 } 342 }
252 343
253 // All the remaining space becomes the frame of the content area. 344 // All the remaining space becomes the frame of the content area.
254 output_.contentAreaFrame = NSMakeRect(0, minY, width, maxY - minY); 345 output_.contentAreaFrame = NSMakeRect(0, minY, width, maxY - minY);
255 } 346 }
256 347
257 - (CGFloat)fullscreenBackingBarHeight { 348 - (CGFloat)fullscreenBackingBarHeight {
258 if (!parameters_.inAnyFullscreen) 349 if (!parameters_.inAnyFullscreen)
259 return 0; 350 return 0;
(...skipping 10 matching lines...) Expand all
270 } 361 }
271 362
272 if (!parameters_.bookmarkBarHidden && 363 if (!parameters_.bookmarkBarHidden &&
273 !parameters_.placeBookmarkBarBelowInfoBar) 364 !parameters_.placeBookmarkBarBelowInfoBar)
274 totalHeight += parameters_.bookmarkBarHeight; 365 totalHeight += parameters_.bookmarkBarHeight;
275 366
276 return totalHeight; 367 return totalHeight;
277 } 368 }
278 369
279 @end 370 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/browser_window_layout.h ('k') | chrome/browser/ui/cocoa/browser_window_layout_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698