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

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

Issue 555243002: mac: Refactor browser_window_controller layout logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fullscreen_layout
Patch Set: Comments from andresantoso, round 2. Created 6 years, 3 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
(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 + (CGFloat)infoBarContainerHeightFromInfoBarHeight:(CGFloat)infoBarHeight
47 maxTopArrowHeight:(CGFloat)maxTopArrowHeight {
48 if (infoBarHeight == 0)
49 return 0;
50 return infoBarHeight + maxTopArrowHeight;
51 }
52
53 - (void)setContentViewSize:(NSSize)size {
54 parameters_.contentViewSize = size;
55 }
56
57 - (void)setWindowSize:(NSSize)size {
58 parameters_.windowSize = size;
59 }
60
61 - (void)setInAnyFullscreen:(BOOL)inAnyFullscreen {
62 parameters_.inAnyFullscreen = inAnyFullscreen;
63 }
64
65 - (void)setFullscreenSlidingStyle:(fullscreen_mac::SlidingStyle)slidingStyle {
66 parameters_.slidingStyle = slidingStyle;
67 }
68
69 - (void)setFullscreenMenubarOffset:(CGFloat)menubarOffset {
70 parameters_.menubarOffset = menubarOffset;
71 }
72
73 - (void)setFullscreenToolbarFraction:(CGFloat)toolbarFraction {
74 parameters_.toolbarFraction = toolbarFraction;
75 }
76
77 - (void)setHasTabStrip:(BOOL)hasTabStrip {
78 parameters_.hasTabStrip = hasTabStrip;
79 }
80
81 - (void)setHasToolbar:(BOOL)hasToolbar {
82 parameters_.hasToolbar = hasToolbar;
83 }
84
85 - (void)setHasLocationBar:(BOOL)hasLocationBar {
86 parameters_.hasLocationBar = hasLocationBar;
87 }
88
89 - (void)setToolbarHeight:(CGFloat)toolbarHeight {
90 parameters_.toolbarHeight = toolbarHeight;
91 }
92
93 - (void)setBookmarkBarHidden:(BOOL)bookmarkBarHidden {
94 parameters_.bookmarkBarHidden = bookmarkBarHidden;
95 }
96
97 - (void)setPlaceBookmarkBarBelowInfoBar:(BOOL)placeBookmarkBarBelowInfoBar {
98 parameters_.placeBookmarkBarBelowInfoBar = placeBookmarkBarBelowInfoBar;
99 }
100
101 - (void)setBookmarkBarHeight:(CGFloat)bookmarkBarHeight {
102 parameters_.bookmarkBarHeight = bookmarkBarHeight;
103 }
104
105 - (void)setInfoBarHeight:(CGFloat)infoBarHeight {
106 parameters_.infoBarHeight = infoBarHeight;
107 }
108
109 - (void)setInfoBarMaxTopArrowHeight:(CGFloat)infoBarMaxTopArrowHeight {
110 parameters_.infoBarMaxTopArrowHeight = infoBarMaxTopArrowHeight;
111 }
112
113 - (void)setHasDownloadShelf:(BOOL)hasDownloadShelf {
114 parameters_.hasDownloadShelf = hasDownloadShelf;
115 }
116
117 - (void)setDownloadShelfHeight:(CGFloat)downloadShelfHeight {
118 parameters_.downloadShelfHeight = downloadShelfHeight;
119 }
120
121 - (mac_browser::LayoutOutput)computeLayout {
122 memset(&output_, 0, sizeof(mac_browser::LayoutOutput));
123
124 [self computeFullscreenYOffset];
125 [self computeTabStripLayout];
126 [self computeContentViewLayout];
127
128 return output_;
129 }
130
131 - (void)computeFullscreenYOffset {
132 CGFloat yOffset = 0;
133 if (parameters_.inAnyFullscreen) {
134 yOffset += parameters_.menubarOffset;
135 switch (parameters_.slidingStyle) {
136 case fullscreen_mac::OMNIBOX_TABS_PRESENT:
137 break;
138 case fullscreen_mac::OMNIBOX_TABS_HIDDEN:
139 // In presentation mode, |yOffset| accounts for the sliding position of
140 // the floating bar and the extra offset needed to dodge the menu bar.
141 yOffset += std::floor((1 - parameters_.toolbarFraction) *
142 [self fullscreenBackingBarHeight]);
143 break;
144 }
145 }
146 fullscreenYOffset_ = yOffset;
147 }
148
149 - (void)computeTabStripLayout {
150 if (parameters_.hasTabStrip) {
151 maxY_ = parameters_.windowSize.height + fullscreenYOffset_;
152 CGFloat width = parameters_.contentViewSize.width;
153 output_.tabStripFrame = NSMakeRect(0,
154 maxY_ - mac_browser::kTabStripHeight,
155 width,
156 mac_browser::kTabStripHeight);
157 maxY_ = NSMinY(output_.tabStripFrame);
158 } else {
159 maxY_ = parameters_.contentViewSize.height + fullscreenYOffset_;
160 }
161 }
162
163 - (void)computeContentViewLayout {
164 mac_browser::LayoutParameters parameters = parameters_;
165 CGFloat maxY = maxY_;
166
167 // Sanity-check |maxY|.
168 DCHECK_GE(maxY, 0);
169 DCHECK_LE(maxY, parameters_.contentViewSize.height + fullscreenYOffset_);
170
171 CGFloat width = parameters_.contentViewSize.width;
172
173 // Lay out the toolbar.
174 if (parameters.hasToolbar) {
175 output_.toolbarFrame = NSMakeRect(
176 0, maxY - parameters_.toolbarHeight, width, parameters_.toolbarHeight);
177 maxY = NSMinY(output_.toolbarFrame);
178 } else if (parameters_.hasLocationBar) {
179 CGFloat toolbarX = kLocBarLeftRightInset;
180 CGFloat toolbarY = maxY - parameters_.toolbarHeight - kLocBarTopInset;
181 CGFloat toolbarWidth = width - 2 * kLocBarLeftRightInset;
182 output_.toolbarFrame =
183 NSMakeRect(toolbarX, toolbarY, toolbarWidth, parameters_.toolbarHeight);
184 maxY = NSMinY(output_.toolbarFrame) - kLocBarBottomInset;
185 }
186
187 // Lay out the bookmark bar, if it's above the info bar.
188 if (!parameters.bookmarkBarHidden &&
189 !parameters.placeBookmarkBarBelowInfoBar) {
190 output_.bookmarkFrame = NSMakeRect(0,
191 maxY - parameters.bookmarkBarHeight,
192 width,
193 parameters.bookmarkBarHeight);
194 maxY = NSMinY(output_.bookmarkFrame);
195 }
196
197 // Lay out the backing bar in fullscreen mode.
198 if (parameters_.inAnyFullscreen) {
199 output_.fullscreenBackingBarFrame =
200 NSMakeRect(0, maxY, width, [self fullscreenBackingBarHeight]);
201 }
202
203 // Place the find bar immediately below the toolbar/attached bookmark bar.
204 output_.findBarMaxY = maxY;
205 output_.fullscreenExitButtonMaxY = maxY;
206
207 if (parameters_.inAnyFullscreen) {
208 switch (parameters_.slidingStyle) {
209 case fullscreen_mac::OMNIBOX_TABS_PRESENT:
210 // Do nothing in Canonical Fullscreen. All content slides.
211 break;
212 case fullscreen_mac::OMNIBOX_TABS_HIDDEN:
213 // If in presentation mode, reset |maxY| to top of screen, so that the
214 // floating bar slides over the things which appear to be in the content
215 // area.
216 maxY = parameters_.contentViewSize.height;
217 break;
218 }
219 }
220
221 // Lay out the info bar. It is never hidden.
222 CGFloat infoBarContainerHeight = [BrowserWindowLayout
223 infoBarContainerHeightFromInfoBarHeight:parameters_.infoBarHeight
224 maxTopArrowHeight:parameters_
225 .infoBarMaxTopArrowHeight];
226 output_.infoBarFrame = NSMakeRect(
227 0, maxY - parameters_.infoBarHeight, width, infoBarContainerHeight);
228 output_.infoBarMaxTopArrowHeight = parameters_.infoBarMaxTopArrowHeight;
229 maxY = NSMinY(output_.infoBarFrame);
230
231 // Lay out the bookmark bar when it is below the info bar.
232 if (!parameters.bookmarkBarHidden &&
233 parameters.placeBookmarkBarBelowInfoBar) {
234 output_.bookmarkFrame = NSMakeRect(0,
235 maxY - parameters.bookmarkBarHeight,
236 width,
237 parameters.bookmarkBarHeight);
238 maxY = NSMinY(output_.bookmarkFrame);
239 }
240
241 // Layout the download shelf at the bottom of the content view.
242 CGFloat minY = 0;
243 if (parameters.hasDownloadShelf) {
244 output_.downloadShelfFrame =
245 NSMakeRect(0, 0, width, parameters.downloadShelfHeight);
246 minY = NSMaxY(output_.downloadShelfFrame);
247 }
248
249 // All the remaining space becomes the frame of the content area.
250 output_.contentAreaFrame = NSMakeRect(0, minY, width, maxY - minY);
251 }
252
253 - (CGFloat)fullscreenBackingBarHeight {
254 if (!parameters_.inAnyFullscreen)
255 return 0;
256
257 CGFloat totalHeight = 0;
258 if (parameters_.hasTabStrip)
259 totalHeight += mac_browser::kTabStripHeight;
260
261 if (parameters_.hasToolbar) {
262 totalHeight += parameters_.toolbarHeight;
263 } else if (parameters_.hasLocationBar) {
264 totalHeight +=
265 parameters_.toolbarHeight + kLocBarTopInset + kLocBarBottomInset;
266 }
267
268 if (!parameters_.bookmarkBarHidden &&
269 !parameters_.placeBookmarkBarBelowInfoBar)
270 totalHeight += parameters_.bookmarkBarHeight;
271
272 return totalHeight;
273 }
274
275 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698