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

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: 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 "base/logging.h" 7 #include "base/logging.h"
8 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
8 9
9 namespace chrome { 10 namespace chrome {
10 11
11 const CGFloat kTabStripHeight = 37; 12 const CGFloat kTabStripHeight = 37;
12 13
13 } // namespace chrome 14 } // namespace chrome
14 15
15 namespace { 16 namespace {
16 17
17 // Insets for the location bar, used when the full toolbar is hidden. 18 // 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 19 // TODO(viettrungluu): We can argue about the "correct" insetting; I like the
19 // following best, though arguably 0 inset is better/more correct. 20 // following best, though arguably 0 inset is better/more correct.
20 const CGFloat kLocBarLeftRightInset = 1; 21 const CGFloat kLocBarLeftRightInset = 1;
21 const CGFloat kLocBarTopInset = 0; 22 const CGFloat kLocBarTopInset = 0;
22 const CGFloat kLocBarBottomInset = 1; 23 const CGFloat kLocBarBottomInset = 1;
23 24
25 // Space between the incognito badge and the right edge of the window.
26 const CGFloat kAvatarRightOffset = 4;
24 } // namespace 27 } // namespace
25 28
26 @interface BrowserWindowLayout () 29 @interface BrowserWindowLayout ()
27 30
28 // Computes the y offset to use when laying out the tab strip in fullscreen 31 // Computes the y offset to use when laying out the tab strip in fullscreen
29 // mode. 32 // mode.
30 - (void)computeFullscreenYOffset; 33 - (void)computeFullscreenYOffset;
31 34
32 // Computes the layout of the tab strip. 35 // Computes the layout of the tab strip.
33 - (void)computeTabStripLayout; 36 - (void)computeTabStripLayout;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 77 }
75 78
76 - (void)setFullscreenToolbarFraction:(CGFloat)toolbarFraction { 79 - (void)setFullscreenToolbarFraction:(CGFloat)toolbarFraction {
77 parameters_.toolbarFraction = toolbarFraction; 80 parameters_.toolbarFraction = toolbarFraction;
78 } 81 }
79 82
80 - (void)setHasTabStrip:(BOOL)hasTabStrip { 83 - (void)setHasTabStrip:(BOOL)hasTabStrip {
81 parameters_.hasTabStrip = hasTabStrip; 84 parameters_.hasTabStrip = hasTabStrip;
82 } 85 }
83 86
87 - (void)setFullscreenButtonFrame:(NSRect)frame {
88 parameters_.fullscreenButtonFrame = frame;
89 }
90
91 - (void)setShouldShowAvatar:(BOOL)shouldShowAvatar {
92 parameters_.shouldShowAvatar = shouldShowAvatar;
93 }
94
95 - (void)setShouldUseNewAvatar:(BOOL)shouldUseNewAvatar {
96 parameters_.shouldUseNewAvatar = shouldUseNewAvatar;
97 }
98
99 - (void)setAvatarSize:(NSSize)avatarSize {
100 parameters_.avatarSize = avatarSize;
101 }
102
103 - (void)setAvatarLineWidth:(BOOL)avatarLineWidth {
104 parameters_.avatarLineWidth = avatarLineWidth;
105 }
106
84 - (void)setHasToolbar:(BOOL)hasToolbar { 107 - (void)setHasToolbar:(BOOL)hasToolbar {
85 parameters_.hasToolbar = hasToolbar; 108 parameters_.hasToolbar = hasToolbar;
86 } 109 }
87 110
88 - (void)setHasLocationBar:(BOOL)hasLocationBar { 111 - (void)setHasLocationBar:(BOOL)hasLocationBar {
89 parameters_.hasLocationBar = hasLocationBar; 112 parameters_.hasLocationBar = hasLocationBar;
90 } 113 }
91 114
92 - (void)setToolbarHeight:(CGFloat)toolbarHeight { 115 - (void)setToolbarHeight:(CGFloat)toolbarHeight {
93 parameters_.toolbarHeight = toolbarHeight; 116 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. 156 // the floating bar and the extra offset needed to dodge the menu bar.
134 yOffset += std::floor((1 - parameters_.toolbarFraction) * 157 yOffset += std::floor((1 - parameters_.toolbarFraction) *
135 [self fullscreenBackingBarHeight]); 158 [self fullscreenBackingBarHeight]);
136 break; 159 break;
137 } 160 }
138 } 161 }
139 fullscreenYOffset_ = yOffset; 162 fullscreenYOffset_ = yOffset;
140 } 163 }
141 164
142 - (void)computeTabStripLayout { 165 - (void)computeTabStripLayout {
143 if (parameters_.hasTabStrip) { 166 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_; 167 maxY_ = parameters_.contentViewSize.height + fullscreenYOffset_;
168 return;
151 } 169 }
170
171 // Temporary variable to hold the output.
172 chrome::TabStripLayout layout;
173 memset(&layout, 0, sizeof(layout));
Robert Sesek 2014/09/26 16:55:55 Can you not do = {0} or = {} instead? Otherwise, I
erikchen 2014/09/26 17:39:05 = {} will correctly zero initialize the struct. I
174
175 // Lay out the tab strip.
176 maxY_ = parameters_.windowSize.height + fullscreenYOffset_;
177 CGFloat width = parameters_.contentViewSize.width;
178 layout.frame = NSMakeRect(
179 0, maxY_ - chrome::kTabStripHeight, width, chrome::kTabStripHeight);
180 maxY_ = NSMinY(layout.frame);
181
182 // In Yosemite fullscreen, manually add the fullscreen controls to the tab
183 // strip.
184 layout.addWindowControls =
185 parameters_.inAnyFullscreen && base::mac::IsOSYosemiteOrLater();
Robert Sesek 2014/09/26 16:55:55 What about when not in screen?
erikchen 2014/09/26 17:39:06 I don't understand your question. My best interpre
Robert Sesek 2014/09/26 19:06:23 Sorry, yes meant fullscreen. The naming of the mem
erikchen 2014/09/26 20:55:59 I renamed all of the fields, properties, and metho
186
187 // Set left indentation based on fullscreen mode status.
188 if (!parameters_.inAnyFullscreen || layout.addWindowControls)
189 layout.leftIndent = [TabStripController defaultLeftIndentForControls];
190
191 // Lay out the icognito/avatar badge because calculating the indentation on
192 // the right depends on it.
193 if (parameters_.shouldShowAvatar) {
194 CGFloat badgeXOffset = -kAvatarRightOffset;
195 CGFloat badgeYOffset = 0;
196 CGFloat buttonHeight = parameters_.avatarSize.height;
197
198 if (parameters_.shouldUseNewAvatar) {
199 // The fullscreen icon is displayed to the right of the avatar button.
200 if (!parameters_.inAnyFullscreen &&
201 !NSIsEmptyRect(parameters_.fullscreenButtonFrame)) {
202 badgeXOffset -= width - NSMinX(parameters_.fullscreenButtonFrame);
203 }
204 // Center the button vertically on the tabstrip.
205 badgeYOffset = (chrome::kTabStripHeight - buttonHeight) / 2;
206 } else {
207 // Actually place the badge *above* |maxY|, by +2 to miss the divider.
208 badgeYOffset = 2 * parameters_.avatarLineWidth;
209 }
210
211 NSSize size = NSMakeSize(parameters_.avatarSize.width,
212 std::min(buttonHeight, chrome::kTabStripHeight));
213 NSPoint origin =
214 NSMakePoint(width - parameters_.avatarSize.width + badgeXOffset,
215 maxY_ + badgeYOffset);
216 layout.avatarFrame =
217 NSMakeRect(origin.x, origin.y, size.width, size.height);
218 }
219
220 // Calculate the right indentation. The default indentation built into the
Robert Sesek 2014/09/26 16:55:55 nit: preference is for one space between sentences
erikchen 2014/09/26 17:39:05 Done. (This was a copy paste).
221 // tabstrip leaves enough room for the fullscreen button on Lion (10.7) to
222 // Mavericks (10.9). On 10.6 and >=10.10, the right indent needs to be
223 // adjusted to make room for the new tab button when an avatar is present.
224 CGFloat rightIndent = 0;
225 if (!parameters_.inAnyFullscreen &&
226 !NSIsEmptyRect(parameters_.fullscreenButtonFrame)) {
227 rightIndent = width - NSMinX(parameters_.fullscreenButtonFrame);
228
229 if (parameters_.shouldUseNewAvatar) {
230 // The new avatar button is to the left of the fullscreen button.
231 // (The old avatar button is to the right).
232 rightIndent += parameters_.avatarSize.width + kAvatarRightOffset;
233 }
234 } else if (parameters_.shouldShowAvatar) {
235 rightIndent += parameters_.avatarSize.width + kAvatarRightOffset;
236 }
237 layout.rightIndent = rightIndent;
238
239 output_.tabStripLayout = layout;
152 } 240 }
153 241
154 - (void)computeContentViewLayout { 242 - (void)computeContentViewLayout {
155 chrome::LayoutParameters parameters = parameters_; 243 chrome::LayoutParameters parameters = parameters_;
156 CGFloat maxY = maxY_; 244 CGFloat maxY = maxY_;
157 245
158 // Sanity-check |maxY|. 246 // Sanity-check |maxY|.
159 DCHECK_GE(maxY, 0); 247 DCHECK_GE(maxY, 0);
160 DCHECK_LE(maxY, parameters_.contentViewSize.height + fullscreenYOffset_); 248 DCHECK_LE(maxY, parameters_.contentViewSize.height + fullscreenYOffset_);
161 249
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 } 353 }
266 354
267 if (!parameters_.bookmarkBarHidden && 355 if (!parameters_.bookmarkBarHidden &&
268 !parameters_.placeBookmarkBarBelowInfoBar) 356 !parameters_.placeBookmarkBarBelowInfoBar)
269 totalHeight += parameters_.bookmarkBarHeight; 357 totalHeight += parameters_.bookmarkBarHeight;
270 358
271 return totalHeight; 359 return totalHeight;
272 } 360 }
273 361
274 @end 362 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698