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 mac_browser { |
| 10 |
| 11 const CGFloat kTabStripHeight = 37; |
| 12 |
| 13 } // namespace mac_browser |
| 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 - (void)setContentViewSize:(NSSize)size { |
| 47 parameters_.contentViewSize = size; |
| 48 } |
| 49 |
| 50 - (void)setWindowSize:(NSSize)size { |
| 51 parameters_.windowSize = size; |
| 52 } |
| 53 |
| 54 - (void)setInAnyFullscreen:(BOOL)inAnyFullscreen { |
| 55 parameters_.inAnyFullscreen = inAnyFullscreen; |
| 56 } |
| 57 |
| 58 - (void)setFullscreenSlidingStyle:(fullscreen_mac::SlidingStyle)slidingStyle { |
| 59 parameters_.slidingStyle = slidingStyle; |
| 60 } |
| 61 |
| 62 - (void)setFullscreenMenubarOffset:(CGFloat)menubarOffset { |
| 63 parameters_.menubarOffset = menubarOffset; |
| 64 } |
| 65 |
| 66 - (void)setFullscreenToolbarFraction:(CGFloat)toolbarFraction { |
| 67 parameters_.toolbarFraction = toolbarFraction; |
| 68 } |
| 69 |
| 70 - (void)setHasTabStrip:(BOOL)hasTabStrip { |
| 71 parameters_.hasTabStrip = hasTabStrip; |
| 72 } |
| 73 |
| 74 - (void)setHasToolbar:(BOOL)hasToolbar { |
| 75 parameters_.hasToolbar = hasToolbar; |
| 76 } |
| 77 |
| 78 - (void)setHasLocationBar:(BOOL)hasLocationBar { |
| 79 parameters_.hasLocationBar = hasLocationBar; |
| 80 } |
| 81 |
| 82 - (void)setToolbarHeight:(CGFloat)toolbarHeight { |
| 83 parameters_.toolbarHeight = toolbarHeight; |
| 84 } |
| 85 |
| 86 - (void)setBookmarkBarHidden:(BOOL)bookmarkBarHidden { |
| 87 parameters_.bookmarkBarHidden = bookmarkBarHidden; |
| 88 } |
| 89 |
| 90 - (void)setPlaceBookmarkBarBelowInfoBar:(BOOL)placeBookmarkBarBelowInfoBar { |
| 91 parameters_.placeBookmarkBarBelowInfoBar = placeBookmarkBarBelowInfoBar; |
| 92 } |
| 93 |
| 94 - (void)setBookmarkBarHeight:(CGFloat)bookmarkBarHeight { |
| 95 parameters_.bookmarkBarHeight = bookmarkBarHeight; |
| 96 } |
| 97 |
| 98 - (void)setInfoBarHeight:(CGFloat)infoBarHeight { |
| 99 parameters_.infoBarHeight = infoBarHeight; |
| 100 } |
| 101 |
| 102 - (void)setPageInfoBubblePointY:(CGFloat)pageInfoBubblePointY { |
| 103 parameters_.pageInfoBubblePointY = pageInfoBubblePointY; |
| 104 } |
| 105 |
| 106 - (void)setHasDownloadShelf:(BOOL)hasDownloadShelf { |
| 107 parameters_.hasDownloadShelf = hasDownloadShelf; |
| 108 } |
| 109 |
| 110 - (void)setDownloadShelfHeight:(CGFloat)downloadShelfHeight { |
| 111 parameters_.downloadShelfHeight = downloadShelfHeight; |
| 112 } |
| 113 |
| 114 - (mac_browser::LayoutOutput)computeLayout { |
| 115 memset(&output_, 0, sizeof(mac_browser::LayoutOutput)); |
| 116 |
| 117 [self computeFullscreenYOffset]; |
| 118 [self computeTabStripLayout]; |
| 119 [self computeContentViewLayout]; |
| 120 |
| 121 return output_; |
| 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(0, |
| 147 maxY_ - mac_browser::kTabStripHeight, |
| 148 width, |
| 149 mac_browser::kTabStripHeight); |
| 150 maxY_ = NSMinY(output_.tabStripFrame); |
| 151 } else { |
| 152 maxY_ = parameters_.contentViewSize.height + fullscreenYOffset_; |
| 153 } |
| 154 } |
| 155 |
| 156 - (void)computeContentViewLayout { |
| 157 mac_browser::LayoutParameters parameters = parameters_; |
| 158 CGFloat maxY = maxY_; |
| 159 |
| 160 // Sanity-check |maxY|. |
| 161 DCHECK_GE(maxY, 0); |
| 162 DCHECK_LE(maxY, parameters_.contentViewSize.height + fullscreenYOffset_); |
| 163 |
| 164 CGFloat width = parameters_.contentViewSize.width; |
| 165 |
| 166 // Lay out the toolbar. |
| 167 if (parameters.hasToolbar) { |
| 168 output_.toolbarFrame = NSMakeRect( |
| 169 0, maxY - parameters_.toolbarHeight, width, parameters_.toolbarHeight); |
| 170 maxY = NSMinY(output_.toolbarFrame); |
| 171 } else if (parameters_.hasLocationBar) { |
| 172 CGFloat toolbarX = kLocBarLeftRightInset; |
| 173 CGFloat toolbarY = maxY - parameters_.toolbarHeight - kLocBarTopInset; |
| 174 CGFloat toolbarWidth = width - 2 * kLocBarLeftRightInset; |
| 175 output_.toolbarFrame = |
| 176 NSMakeRect(toolbarX, toolbarY, toolbarWidth, parameters_.toolbarHeight); |
| 177 maxY = NSMinY(output_.toolbarFrame) - kLocBarBottomInset; |
| 178 } |
| 179 |
| 180 // Lay out the bookmark bar, if it's above the info bar. |
| 181 if (!parameters.bookmarkBarHidden && |
| 182 !parameters.placeBookmarkBarBelowInfoBar) { |
| 183 output_.bookmarkFrame = NSMakeRect(0, |
| 184 maxY - parameters.bookmarkBarHeight, |
| 185 width, |
| 186 parameters.bookmarkBarHeight); |
| 187 maxY = NSMinY(output_.bookmarkFrame); |
| 188 } |
| 189 |
| 190 // Lay out the backing bar in fullscreen mode. |
| 191 if (parameters_.inAnyFullscreen) { |
| 192 output_.fullscreenBackingBarFrame = |
| 193 NSMakeRect(0, maxY, width, [self fullscreenBackingBarHeight]); |
| 194 } |
| 195 |
| 196 // Place the find bar immediately below the toolbar/attached bookmark bar. |
| 197 output_.findBarMaxY = maxY; |
| 198 output_.fullscreenExitButtonMaxY = maxY; |
| 199 |
| 200 if (parameters_.inAnyFullscreen) { |
| 201 switch (parameters_.slidingStyle) { |
| 202 case fullscreen_mac::OMNIBOX_TABS_PRESENT: |
| 203 // Do nothing in Canonical Fullscreen. All content slides. |
| 204 break; |
| 205 case fullscreen_mac::OMNIBOX_TABS_HIDDEN: |
| 206 // If in presentation mode, reset |maxY| to top of screen, so that the |
| 207 // floating bar slides over the things which appear to be in the content |
| 208 // area. |
| 209 maxY = parameters_.contentViewSize.height; |
| 210 break; |
| 211 } |
| 212 } |
| 213 |
| 214 // Lay out the info bar. It is never hidden. The frame needs to be high |
| 215 // enough to accomodate the top arrow, which might stretch all the way to the |
| 216 // page info bubble icon. |
| 217 if (parameters_.infoBarHeight != 0) { |
| 218 CGFloat infoBarMaxY = |
| 219 NSMinY(output_.toolbarFrame) + parameters.pageInfoBubblePointY; |
| 220 CGFloat infoBarMinY = maxY - parameters_.infoBarHeight; |
| 221 output_.infoBarFrame = |
| 222 NSMakeRect(0, infoBarMinY, width, infoBarMaxY - infoBarMinY); |
| 223 output_.infoBarMaxTopArrowHeight = |
| 224 NSHeight(output_.infoBarFrame) - parameters_.infoBarHeight; |
| 225 maxY = NSMinY(output_.infoBarFrame); |
| 226 } else { |
| 227 // The info bar has 0 height, but tests still expect it in the right |
| 228 // location. |
| 229 output_.infoBarFrame = NSMakeRect(0, maxY, width, 0); |
| 230 } |
| 231 |
| 232 // Lay out the bookmark bar when it is below the info bar. |
| 233 if (!parameters.bookmarkBarHidden && |
| 234 parameters.placeBookmarkBarBelowInfoBar) { |
| 235 output_.bookmarkFrame = NSMakeRect(0, |
| 236 maxY - parameters.bookmarkBarHeight, |
| 237 width, |
| 238 parameters.bookmarkBarHeight); |
| 239 maxY = NSMinY(output_.bookmarkFrame); |
| 240 } |
| 241 |
| 242 // Layout the download shelf at the bottom of the content view. |
| 243 CGFloat minY = 0; |
| 244 if (parameters.hasDownloadShelf) { |
| 245 output_.downloadShelfFrame = |
| 246 NSMakeRect(0, 0, width, parameters.downloadShelfHeight); |
| 247 minY = NSMaxY(output_.downloadShelfFrame); |
| 248 } |
| 249 |
| 250 // All the remaining space becomes the frame of the content area. |
| 251 output_.contentAreaFrame = NSMakeRect(0, minY, width, maxY - minY); |
| 252 } |
| 253 |
| 254 - (CGFloat)fullscreenBackingBarHeight { |
| 255 if (!parameters_.inAnyFullscreen) |
| 256 return 0; |
| 257 |
| 258 CGFloat totalHeight = 0; |
| 259 if (parameters_.hasTabStrip) |
| 260 totalHeight += mac_browser::kTabStripHeight; |
| 261 |
| 262 if (parameters_.hasToolbar) { |
| 263 totalHeight += parameters_.toolbarHeight; |
| 264 } else if (parameters_.hasLocationBar) { |
| 265 totalHeight += |
| 266 parameters_.toolbarHeight + kLocBarTopInset + kLocBarBottomInset; |
| 267 } |
| 268 |
| 269 if (!parameters_.bookmarkBarHidden && |
| 270 !parameters_.placeBookmarkBarBelowInfoBar) |
| 271 totalHeight += parameters_.bookmarkBarHeight; |
| 272 |
| 273 return totalHeight; |
| 274 } |
| 275 |
| 276 @end |
OLD | NEW |