OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "chrome/browser/ui/cocoa/browser_window_layout.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 |
| 9 namespace chrome { |
| 10 |
| 11 const CGFloat kTabStripHeight = 37; |
| 12 |
| 13 } // namespace chrome |
| 14 |
| 15 namespace { |
| 16 |
| 17 // 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 // following best, though arguably 0 inset is better/more correct. |
| 20 const CGFloat kLocBarLeftRightInset = 1; |
| 21 const CGFloat kLocBarTopInset = 0; |
| 22 const CGFloat kLocBarBottomInset = 1; |
| 23 |
| 24 } // namespace |
| 25 |
| 26 @interface BrowserWindowLayout () |
| 27 |
| 28 // Computes the y offset to use when laying out the tab strip in fullscreen |
| 29 // mode. |
| 30 - (void)computeFullscreenYOffset; |
| 31 |
| 32 // Computes the layout of the tab strip. |
| 33 - (void)computeTabStripLayout; |
| 34 |
| 35 // Computes the layout of the subviews of the content view. |
| 36 - (void)computeContentViewLayout; |
| 37 |
| 38 // Computes the height of the backing bar for the views in the omnibox area in |
| 39 // fullscreen mode. |
| 40 - (CGFloat)fullscreenBackingBarHeight; |
| 41 |
| 42 @end |
| 43 |
| 44 @implementation BrowserWindowLayout |
| 45 |
| 46 - (chrome::LayoutOutput)computeLayout { |
| 47 memset(&output_, 0, sizeof(chrome::LayoutOutput)); |
| 48 |
| 49 [self computeFullscreenYOffset]; |
| 50 [self computeTabStripLayout]; |
| 51 [self computeContentViewLayout]; |
| 52 |
| 53 return output_; |
| 54 } |
| 55 |
| 56 - (void)setContentViewSize:(NSSize)size { |
| 57 parameters_.contentViewSize = size; |
| 58 } |
| 59 |
| 60 - (void)setWindowSize:(NSSize)size { |
| 61 parameters_.windowSize = size; |
| 62 } |
| 63 |
| 64 - (void)setInAnyFullscreen:(BOOL)inAnyFullscreen { |
| 65 parameters_.inAnyFullscreen = inAnyFullscreen; |
| 66 } |
| 67 |
| 68 - (void)setFullscreenSlidingStyle:(fullscreen_mac::SlidingStyle)slidingStyle { |
| 69 parameters_.slidingStyle = slidingStyle; |
| 70 } |
| 71 |
| 72 - (void)setFullscreenMenubarOffset:(CGFloat)menubarOffset { |
| 73 parameters_.menubarOffset = menubarOffset; |
| 74 } |
| 75 |
| 76 - (void)setFullscreenToolbarFraction:(CGFloat)toolbarFraction { |
| 77 parameters_.toolbarFraction = toolbarFraction; |
| 78 } |
| 79 |
| 80 - (void)setHasTabStrip:(BOOL)hasTabStrip { |
| 81 parameters_.hasTabStrip = hasTabStrip; |
| 82 } |
| 83 |
| 84 - (void)setHasToolbar:(BOOL)hasToolbar { |
| 85 parameters_.hasToolbar = hasToolbar; |
| 86 } |
| 87 |
| 88 - (void)setHasLocationBar:(BOOL)hasLocationBar { |
| 89 parameters_.hasLocationBar = hasLocationBar; |
| 90 } |
| 91 |
| 92 - (void)setToolbarHeight:(CGFloat)toolbarHeight { |
| 93 parameters_.toolbarHeight = toolbarHeight; |
| 94 } |
| 95 |
| 96 - (void)setBookmarkBarHidden:(BOOL)bookmarkBarHidden { |
| 97 parameters_.bookmarkBarHidden = bookmarkBarHidden; |
| 98 } |
| 99 |
| 100 - (void)setPlaceBookmarkBarBelowInfoBar:(BOOL)placeBookmarkBarBelowInfoBar { |
| 101 parameters_.placeBookmarkBarBelowInfoBar = placeBookmarkBarBelowInfoBar; |
| 102 } |
| 103 |
| 104 - (void)setBookmarkBarHeight:(CGFloat)bookmarkBarHeight { |
| 105 parameters_.bookmarkBarHeight = bookmarkBarHeight; |
| 106 } |
| 107 |
| 108 - (void)setInfoBarHeight:(CGFloat)infoBarHeight { |
| 109 parameters_.infoBarHeight = infoBarHeight; |
| 110 } |
| 111 |
| 112 - (void)setPageInfoBubblePointY:(CGFloat)pageInfoBubblePointY { |
| 113 parameters_.pageInfoBubblePointY = pageInfoBubblePointY; |
| 114 } |
| 115 |
| 116 - (void)setHasDownloadShelf:(BOOL)hasDownloadShelf { |
| 117 parameters_.hasDownloadShelf = hasDownloadShelf; |
| 118 } |
| 119 |
| 120 - (void)setDownloadShelfHeight:(CGFloat)downloadShelfHeight { |
| 121 parameters_.downloadShelfHeight = downloadShelfHeight; |
| 122 } |
| 123 |
| 124 - (void)computeFullscreenYOffset { |
| 125 CGFloat yOffset = 0; |
| 126 if (parameters_.inAnyFullscreen) { |
| 127 yOffset += parameters_.menubarOffset; |
| 128 switch (parameters_.slidingStyle) { |
| 129 case fullscreen_mac::OMNIBOX_TABS_PRESENT: |
| 130 break; |
| 131 case fullscreen_mac::OMNIBOX_TABS_HIDDEN: |
| 132 // In presentation mode, |yOffset| accounts for the sliding position of |
| 133 // the floating bar and the extra offset needed to dodge the menu bar. |
| 134 yOffset += std::floor((1 - parameters_.toolbarFraction) * |
| 135 [self fullscreenBackingBarHeight]); |
| 136 break; |
| 137 } |
| 138 } |
| 139 fullscreenYOffset_ = yOffset; |
| 140 } |
| 141 |
| 142 - (void)computeTabStripLayout { |
| 143 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_; |
| 151 } |
| 152 } |
| 153 |
| 154 - (void)computeContentViewLayout { |
| 155 chrome::LayoutParameters parameters = parameters_; |
| 156 CGFloat maxY = maxY_; |
| 157 |
| 158 // Sanity-check |maxY|. |
| 159 DCHECK_GE(maxY, 0); |
| 160 DCHECK_LE(maxY, parameters_.contentViewSize.height + fullscreenYOffset_); |
| 161 |
| 162 CGFloat width = parameters_.contentViewSize.width; |
| 163 |
| 164 // Lay out the toolbar. |
| 165 if (parameters.hasToolbar) { |
| 166 output_.toolbarFrame = NSMakeRect( |
| 167 0, maxY - parameters_.toolbarHeight, width, parameters_.toolbarHeight); |
| 168 maxY = NSMinY(output_.toolbarFrame); |
| 169 } else if (parameters_.hasLocationBar) { |
| 170 CGFloat toolbarX = kLocBarLeftRightInset; |
| 171 CGFloat toolbarY = maxY - parameters_.toolbarHeight - kLocBarTopInset; |
| 172 CGFloat toolbarWidth = width - 2 * kLocBarLeftRightInset; |
| 173 output_.toolbarFrame = |
| 174 NSMakeRect(toolbarX, toolbarY, toolbarWidth, parameters_.toolbarHeight); |
| 175 maxY = NSMinY(output_.toolbarFrame) - kLocBarBottomInset; |
| 176 } |
| 177 |
| 178 // Lay out the bookmark bar, if it's above the info bar. |
| 179 if (!parameters.bookmarkBarHidden && |
| 180 !parameters.placeBookmarkBarBelowInfoBar) { |
| 181 output_.bookmarkFrame = NSMakeRect(0, |
| 182 maxY - parameters.bookmarkBarHeight, |
| 183 width, |
| 184 parameters.bookmarkBarHeight); |
| 185 maxY = NSMinY(output_.bookmarkFrame); |
| 186 } |
| 187 |
| 188 // Lay out the backing bar in fullscreen mode. |
| 189 if (parameters_.inAnyFullscreen) { |
| 190 output_.fullscreenBackingBarFrame = |
| 191 NSMakeRect(0, maxY, width, [self fullscreenBackingBarHeight]); |
| 192 } |
| 193 |
| 194 // Place the find bar immediately below the toolbar/attached bookmark bar. |
| 195 output_.findBarMaxY = maxY; |
| 196 output_.fullscreenExitButtonMaxY = maxY; |
| 197 |
| 198 if (parameters_.inAnyFullscreen) { |
| 199 switch (parameters_.slidingStyle) { |
| 200 case fullscreen_mac::OMNIBOX_TABS_PRESENT: |
| 201 // Do nothing in Canonical Fullscreen. All content slides. |
| 202 break; |
| 203 case fullscreen_mac::OMNIBOX_TABS_HIDDEN: |
| 204 // If in presentation mode, reset |maxY| to top of screen, so that the |
| 205 // floating bar slides over the things which appear to be in the content |
| 206 // area. |
| 207 maxY = parameters_.contentViewSize.height; |
| 208 break; |
| 209 } |
| 210 } |
| 211 |
| 212 // Lay out the info bar. It is never hidden. The frame needs to be high |
| 213 // enough to accomodate the top arrow, which might stretch all the way to the |
| 214 // page info bubble icon. |
| 215 if (parameters_.infoBarHeight != 0) { |
| 216 CGFloat infoBarMaxY = |
| 217 NSMinY(output_.toolbarFrame) + parameters.pageInfoBubblePointY; |
| 218 CGFloat infoBarMinY = maxY - parameters_.infoBarHeight; |
| 219 output_.infoBarFrame = |
| 220 NSMakeRect(0, infoBarMinY, width, infoBarMaxY - infoBarMinY); |
| 221 output_.infoBarMaxTopArrowHeight = |
| 222 NSHeight(output_.infoBarFrame) - parameters_.infoBarHeight; |
| 223 maxY = NSMinY(output_.infoBarFrame); |
| 224 } else { |
| 225 // The info bar has 0 height, but tests still expect it in the right |
| 226 // location. |
| 227 output_.infoBarFrame = NSMakeRect(0, maxY, width, 0); |
| 228 } |
| 229 |
| 230 // Lay out the bookmark bar when it is below the info bar. |
| 231 if (!parameters.bookmarkBarHidden && |
| 232 parameters.placeBookmarkBarBelowInfoBar) { |
| 233 output_.bookmarkFrame = NSMakeRect(0, |
| 234 maxY - parameters.bookmarkBarHeight, |
| 235 width, |
| 236 parameters.bookmarkBarHeight); |
| 237 maxY = NSMinY(output_.bookmarkFrame); |
| 238 } |
| 239 |
| 240 // Layout the download shelf at the bottom of the content view. |
| 241 CGFloat minY = 0; |
| 242 if (parameters.hasDownloadShelf) { |
| 243 output_.downloadShelfFrame = |
| 244 NSMakeRect(0, 0, width, parameters.downloadShelfHeight); |
| 245 minY = NSMaxY(output_.downloadShelfFrame); |
| 246 } |
| 247 |
| 248 // All the remaining space becomes the frame of the content area. |
| 249 output_.contentAreaFrame = NSMakeRect(0, minY, width, maxY - minY); |
| 250 } |
| 251 |
| 252 - (CGFloat)fullscreenBackingBarHeight { |
| 253 if (!parameters_.inAnyFullscreen) |
| 254 return 0; |
| 255 |
| 256 CGFloat totalHeight = 0; |
| 257 if (parameters_.hasTabStrip) |
| 258 totalHeight += chrome::kTabStripHeight; |
| 259 |
| 260 if (parameters_.hasToolbar) { |
| 261 totalHeight += parameters_.toolbarHeight; |
| 262 } else if (parameters_.hasLocationBar) { |
| 263 totalHeight += |
| 264 parameters_.toolbarHeight + kLocBarTopInset + kLocBarBottomInset; |
| 265 } |
| 266 |
| 267 if (!parameters_.bookmarkBarHidden && |
| 268 !parameters_.placeBookmarkBarBelowInfoBar) |
| 269 totalHeight += parameters_.bookmarkBarHeight; |
| 270 |
| 271 return totalHeight; |
| 272 } |
| 273 |
| 274 @end |
OLD | NEW |