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

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

Powered by Google App Engine
This is Rietveld 408576698