OLD | NEW |
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 Loading... |
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 Loading... |
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 |
| 174 // Lay out the tab strip. |
| 175 maxY_ = parameters_.windowSize.height + fullscreenYOffset_; |
| 176 CGFloat width = parameters_.contentViewSize.width; |
| 177 layout.frame = NSMakeRect( |
| 178 0, maxY_ - chrome::kTabStripHeight, width, chrome::kTabStripHeight); |
| 179 maxY_ = NSMinY(layout.frame); |
| 180 |
| 181 // In Yosemite fullscreen, manually add the traffic light buttons to the tab |
| 182 // strip. |
| 183 layout.addWindowControls = |
| 184 parameters_.inAnyFullscreen && base::mac::IsOSYosemiteOrLater(); |
| 185 |
| 186 // Set left indentation based on fullscreen mode status. |
| 187 if (!parameters_.inAnyFullscreen || layout.addWindowControls) |
| 188 layout.leftIndent = [TabStripController defaultLeftIndentForControls]; |
| 189 |
| 190 // Lay out the icognito/avatar badge because calculating the indentation on |
| 191 // the right depends on it. |
| 192 if (parameters_.shouldShowAvatar) { |
| 193 CGFloat badgeXOffset = -kAvatarRightOffset; |
| 194 CGFloat badgeYOffset = 0; |
| 195 CGFloat buttonHeight = parameters_.avatarSize.height; |
| 196 |
| 197 if (parameters_.shouldUseNewAvatar) { |
| 198 // The fullscreen icon is displayed to the right of the avatar button. |
| 199 if (!parameters_.inAnyFullscreen && |
| 200 !NSIsEmptyRect(parameters_.fullscreenButtonFrame)) { |
| 201 badgeXOffset -= width - NSMinX(parameters_.fullscreenButtonFrame); |
| 202 } |
| 203 // Center the button vertically on the tabstrip. |
| 204 badgeYOffset = (chrome::kTabStripHeight - buttonHeight) / 2; |
| 205 } else { |
| 206 // Actually place the badge *above* |maxY|, by +2 to miss the divider. |
| 207 badgeYOffset = 2 * parameters_.avatarLineWidth; |
| 208 } |
| 209 |
| 210 NSSize size = NSMakeSize(parameters_.avatarSize.width, |
| 211 std::min(buttonHeight, chrome::kTabStripHeight)); |
| 212 NSPoint origin = |
| 213 NSMakePoint(width - parameters_.avatarSize.width + badgeXOffset, |
| 214 maxY_ + badgeYOffset); |
| 215 layout.avatarFrame = |
| 216 NSMakeRect(origin.x, origin.y, size.width, size.height); |
| 217 } |
| 218 |
| 219 // Calculate the right indentation. The default indentation built into the |
| 220 // tabstrip leaves enough room for the fullscreen button on Lion (10.7) to |
| 221 // Mavericks (10.9). On 10.6 and >=10.10, the right indent needs to be |
| 222 // adjusted to make room for the new tab button when an avatar is present. |
| 223 CGFloat rightIndent = 0; |
| 224 if (!parameters_.inAnyFullscreen && |
| 225 !NSIsEmptyRect(parameters_.fullscreenButtonFrame)) { |
| 226 rightIndent = width - NSMinX(parameters_.fullscreenButtonFrame); |
| 227 |
| 228 if (parameters_.shouldUseNewAvatar) { |
| 229 // The new avatar button is to the left of the fullscreen button. |
| 230 // (The old avatar button is to the right). |
| 231 rightIndent += parameters_.avatarSize.width + kAvatarRightOffset; |
| 232 } |
| 233 } else if (parameters_.shouldShowAvatar) { |
| 234 rightIndent += parameters_.avatarSize.width + kAvatarRightOffset; |
| 235 } |
| 236 layout.rightIndent = rightIndent; |
| 237 |
| 238 output_.tabStripLayout = layout; |
152 } | 239 } |
153 | 240 |
154 - (void)computeContentViewLayout { | 241 - (void)computeContentViewLayout { |
155 chrome::LayoutParameters parameters = parameters_; | 242 chrome::LayoutParameters parameters = parameters_; |
156 CGFloat maxY = maxY_; | 243 CGFloat maxY = maxY_; |
157 | 244 |
158 // Sanity-check |maxY|. | 245 // Sanity-check |maxY|. |
159 DCHECK_GE(maxY, 0); | 246 DCHECK_GE(maxY, 0); |
160 DCHECK_LE(maxY, parameters_.contentViewSize.height + fullscreenYOffset_); | 247 DCHECK_LE(maxY, parameters_.contentViewSize.height + fullscreenYOffset_); |
161 | 248 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 } | 352 } |
266 | 353 |
267 if (!parameters_.bookmarkBarHidden && | 354 if (!parameters_.bookmarkBarHidden && |
268 !parameters_.placeBookmarkBarBelowInfoBar) | 355 !parameters_.placeBookmarkBarBelowInfoBar) |
269 totalHeight += parameters_.bookmarkBarHeight; | 356 totalHeight += parameters_.bookmarkBarHeight; |
270 | 357 |
271 return totalHeight; | 358 return totalHeight; |
272 } | 359 } |
273 | 360 |
274 @end | 361 @end |
OLD | NEW |