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.
5 #ifndef CHROME_BROWSER_UI_COCOA_BROWSER_WINDOW_CONTROLLER_LAYOUT_H_
6 #define CHROME_BROWSER_UI_COCOA_BROWSER_WINDOW_CONTROLLER_LAYOUT_H_
8 #import <Cocoa/Cocoa.h>
10 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h"
14 // The height of the tab strip.
15 extern const CGFloat kTabStripHeight
;
17 // The parameters used to calculate the layout of the views managed by the
18 // BrowserWindowController.
19 struct LayoutParameters
{
20 // The size of the content view of the window.
21 NSSize contentViewSize
;
22 // The size of the window.
25 // Whether the controller is in any fullscreen mode. This parameter should be
26 // NO if the controller is in the process of entering fullscreen.
28 // The fullscreen sliding style. See presentation_mode_controller.h for more
30 fullscreen_mac::SlidingStyle slidingStyle
;
31 // The minY of the AppKit Menu Bar, relative to the top of the screen. Ranges
32 // from 0 to -22. Only relevant in fullscreen mode.
33 CGFloat menubarOffset
;
34 // The fraction of the sliding toolbar that is visible in fullscreenm mode.
35 // Ranges from 0 to 1. Only relevant in fullscreen mode.
36 CGFloat toolbarFraction
;
39 // The frame of the fullscreen button. May be NSZeroRect if the fullscreen
40 // button doesn't exist. Only needs to be set when hasTabStrip is YES.
41 NSRect fullscreenButtonFrame
;
42 // Whether the avatar button should be shown. Only needs to be set when
43 // hasTabStrip is YES.
44 BOOL shouldShowAvatar
;
45 // Whether to use the new avatar button. Only needs to be set when
46 // shouldShowAvatar is YES.
47 BOOL shouldUseNewAvatar
;
48 // The size of the avatar button. Only needs to be set when shouldShowAvatar
51 // The line width that will generate a 1 pixel wide line for the avatar's
52 // superview. Only needs to be set when shouldShowAvatar is YES.
53 CGFloat avatarLineWidth
;
57 CGFloat toolbarHeight
;
59 BOOL bookmarkBarHidden
;
60 // If the bookmark bar is not hidden, then the bookmark bar should either be
61 // directly below the omnibox, or directly below the info bar. This parameter
62 // selects between those 2 cases.
63 BOOL placeBookmarkBarBelowInfoBar
;
64 CGFloat bookmarkBarHeight
;
66 // The height of the info bar, not including the top arrow.
67 CGFloat infoBarHeight
;
68 // The distance from the bottom of the location icon to the bottom of the
69 // toolbar. Only needs to be set if infoBarHeight is not 0 and hasToolbar is
71 CGFloat pageInfoBubblePointY
;
73 BOOL hasDownloadShelf
;
74 CGFloat downloadShelfHeight
;
76 // This parameter exists so that unit tests can configure the OS version.
77 BOOL isOSYosemiteOrLater
;
80 // The parameters required to lay out the tab strip and its components.
81 struct TabStripLayout
{
82 // The frame of the tab strip in window coordinates.
84 // The left indent for the controls of the TabStripController.
86 // The right indent for the controls of the TabStripController.
88 // Whether the TabStripController needs to add custom traffic light buttons.
89 BOOL addCustomWindowControls
;
90 // The frame of the avatar in window coordinates.
94 // The output frames of the views managed by the BrowserWindowController. All
95 // frames are in the coordinate system of the window. The lower-left corner of
96 // the contentView coincides with the lower-left corner of the window, so these
97 // frames are also in the coordinate system of the contentView.
99 TabStripLayout tabStripLayout
;
101 NSRect bookmarkFrame
;
102 NSRect fullscreenBackingBarFrame
;
104 CGFloat fullscreenExitButtonMaxY
;
106 CGFloat infoBarMaxTopArrowHeight
;
107 NSRect downloadShelfFrame
;
108 NSRect contentAreaFrame
;
111 } // namespace chrome
113 // This class is the sole entity responsible for calculating the layout of the
114 // views managed by the BrowserWindowController. The parameters used to
115 // calculate the layout are the fields of |parameters_|. These fields should be
116 // filled by calling the appropriate setters on this class. Once the parameters
117 // have been set, calling -computeLayout will return a LayoutOutput that
118 // includes sufficient information to lay out all views managed by
119 // BrowserWindowController.
121 // This is a lightweight class. It should be created on demand.
122 @interface BrowserWindowLayout
: NSObject
{
124 // Stores the parameters used to compute layout.
125 chrome::LayoutParameters parameters_
;
127 // Stores the layout output as it's being computed.
128 chrome::LayoutOutput output_
;
130 // The offset of the maxY of the tab strip during fullscreen mode.
131 CGFloat fullscreenYOffset_
;
133 // The views are laid out from highest Y to lowest Y. This variable holds the
134 // current highest Y that the next view is expected to be laid under.
138 // Designated initializer.
139 - (instancetype
)init
;
141 // Performs the layout computation and returns the results. This method is fast
142 // and does not perform any caching.
143 - (chrome::LayoutOutput
)computeLayout
;
145 - (void)setContentViewSize
:(NSSize
)size
;
146 - (void)setWindowSize
:(NSSize
)size
;
148 // Whether the controller is in any fullscreen mode. |inAnyFullscreen| should
149 // be NO if the controller is in the process of entering fullscreen.
150 - (void)setInAnyFullscreen
:(BOOL
)inAnyFullscreen
;
151 - (void)setFullscreenSlidingStyle
:(fullscreen_mac::SlidingStyle
)slidingStyle
;
152 - (void)setFullscreenMenubarOffset
:(CGFloat
)menubarOffset
;
153 - (void)setFullscreenToolbarFraction
:(CGFloat
)toolbarFraction
;
155 - (void)setHasTabStrip
:(BOOL
)hasTabStrip
;
156 - (void)setFullscreenButtonFrame
:(NSRect
)frame
;
157 - (void)setShouldShowAvatar
:(BOOL
)shouldShowAvatar
;
158 - (void)setShouldUseNewAvatar
:(BOOL
)shouldUseNewAvatar
;
159 - (void)setAvatarSize
:(NSSize
)avatarSize
;
160 - (void)setAvatarLineWidth
:(CGFloat
)avatarLineWidth
;
162 - (void)setHasToolbar
:(BOOL
)hasToolbar
;
163 - (void)setHasLocationBar
:(BOOL
)hasLocationBar
;
164 - (void)setToolbarHeight
:(CGFloat
)toolbarHeight
;
166 - (void)setBookmarkBarHidden
:(BOOL
)bookmarkBarHidden
;
167 - (void)setPlaceBookmarkBarBelowInfoBar
:(BOOL
)placeBookmarkBarBelowInfoBar
;
168 - (void)setBookmarkBarHeight
:(CGFloat
)bookmarkBarHeight
;
170 // The height of the info bar, not including the top arrow.
171 - (void)setInfoBarHeight
:(CGFloat
)infoBarHeight
;
172 // The min Y of the bubble point, relative to the toolbar.
173 - (void)setPageInfoBubblePointY
:(CGFloat
)pageInfoBubblePointY
;
175 - (void)setHasDownloadShelf
:(BOOL
)hasDownloadShelf
;
176 - (void)setDownloadShelfHeight
:(CGFloat
)downloadShelfHeight
;
179 @interface
BrowserWindowLayout (ExposedForTesting
)
180 - (void)setOSYosemiteOrLater
:(BOOL
)osYosemiteOrLater
;
183 #endif // CHROME_BROWSER_UI_COCOA_BROWSER_WINDOW_CONTROLLER_LAYOUT_H_