summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/cocoa/browser_window_layout.h
blob: 82cf1f9cfe6cf6148d50e30600a44477aa9e3379 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_COCOA_BROWSER_WINDOW_CONTROLLER_LAYOUT_H_
#define CHROME_BROWSER_UI_COCOA_BROWSER_WINDOW_CONTROLLER_LAYOUT_H_

#import <Cocoa/Cocoa.h>

#import "chrome/browser/ui/cocoa/presentation_mode_controller.h"

namespace chrome {

// The height of the tab strip.
extern const CGFloat kTabStripHeight;

// The parameters used to calculate the layout of the views managed by the
// BrowserWindowController.
struct LayoutParameters {
  // The size of the content view of the window.
  NSSize contentViewSize;
  // The size of the window.
  NSSize windowSize;

  // Whether the controller is in any fullscreen mode. This parameter should be
  // NO if the controller is in the process of entering fullscreen.
  BOOL inAnyFullscreen;
  // The fullscreen sliding style. See presentation_mode_controller.h for more
  // details.
  fullscreen_mac::SlidingStyle slidingStyle;
  // The minY of the AppKit Menu Bar, relative to the top of the screen. Ranges
  // from 0 to -22. Only relevant in fullscreen mode.
  CGFloat menubarOffset;
  // The fraction of the sliding toolbar that is visible in fullscreenm mode.
  // Ranges from 0 to 1. Only relevant in fullscreen mode.
  CGFloat toolbarFraction;

  BOOL hasTabStrip;
  // The frame of the fullscreen button. May be NSZeroRect if the fullscreen
  // button doesn't exist. Only needs to be set when hasTabStrip is YES.
  NSRect fullscreenButtonFrame;
  // Whether the avatar button should be shown. Only needs to be set when
  // hasTabStrip is YES.
  BOOL shouldShowAvatar;
  // Whether to use the new avatar button. Only needs to be set when
  // shouldShowAvatar is YES.
  BOOL shouldUseNewAvatar;
  // The size of the avatar button. Only needs to be set when shouldShowAvatar
  // is YES.
  NSSize avatarSize;
  // The line width that will generate a 1 pixel wide line for the avatar's
  // superview. Only needs to be set when shouldShowAvatar is YES.
  CGFloat avatarLineWidth;

  BOOL hasToolbar;
  BOOL hasLocationBar;
  CGFloat toolbarHeight;

  BOOL bookmarkBarHidden;
  // If the bookmark bar is not hidden, then the bookmark bar should either be
  // directly below the omnibox, or directly below the info bar. This parameter
  // selects between those 2 cases.
  BOOL placeBookmarkBarBelowInfoBar;
  CGFloat bookmarkBarHeight;

  // The height of the info bar, not including the top arrow.
  CGFloat infoBarHeight;
  // The distance from the bottom of the location icon to the bottom of the
  // toolbar. Only needs to be set if infoBarHeight is not 0 and hasToolbar is
  // YES.
  CGFloat pageInfoBubblePointY;

  BOOL hasDownloadShelf;
  CGFloat downloadShelfHeight;

  // This parameter exists so that unit tests can configure the OS version.
  BOOL isOSYosemiteOrLater;
};

// The parameters required to lay out the tab strip and its components.
struct TabStripLayout {
  // The frame of the tab strip in window coordinates.
  NSRect frame;
  // The left indent for the controls of the TabStripController.
  CGFloat leftIndent;
  // The right indent for the controls of the TabStripController.
  CGFloat rightIndent;
  // Whether the TabStripController needs to add custom traffic light buttons.
  BOOL addCustomWindowControls;
  // The frame of the avatar in window coordinates.
  NSRect avatarFrame;
};

// The output frames of the views managed by the BrowserWindowController. All
// frames are in the coordinate system of the window. The lower-left corner of
// the contentView coincides with the lower-left corner of the window, so these
// frames are also in the coordinate system of the contentView.
struct LayoutOutput {
  TabStripLayout tabStripLayout;
  NSRect toolbarFrame;
  NSRect bookmarkFrame;
  NSRect fullscreenBackingBarFrame;
  CGFloat findBarMaxY;
  CGFloat fullscreenExitButtonMaxY;
  NSRect infoBarFrame;
  CGFloat infoBarMaxTopArrowHeight;
  NSRect downloadShelfFrame;
  NSRect contentAreaFrame;
};

}  // namespace chrome

// This class is the sole entity responsible for calculating the layout of the
// views managed by the BrowserWindowController. The parameters used to
// calculate the layout are the fields of |parameters_|. These fields should be
// filled by calling the appropriate setters on this class. Once the parameters
// have been set, calling -computeLayout will return a LayoutOutput that
// includes sufficient information to lay out all views managed by
// BrowserWindowController.
//
// This is a lightweight class. It should be created on demand.
@interface BrowserWindowLayout : NSObject {
 @private
  // Stores the parameters used to compute layout.
  chrome::LayoutParameters parameters_;

  // Stores the layout output as it's being computed.
  chrome::LayoutOutput output_;

  // The offset of the maxY of the tab strip during fullscreen mode.
  CGFloat fullscreenYOffset_;

  // The views are laid out from highest Y to lowest Y. This variable holds the
  // current highest Y that the next view is expected to be laid under.
  CGFloat maxY_;
}

// Designated initializer.
- (instancetype)init;

// Performs the layout computation and returns the results. This method is fast
// and does not perform any caching.
- (chrome::LayoutOutput)computeLayout;

- (void)setContentViewSize:(NSSize)size;
- (void)setWindowSize:(NSSize)size;

// Whether the controller is in any fullscreen mode. |inAnyFullscreen| should
// be NO if the controller is in the process of entering fullscreen.
- (void)setInAnyFullscreen:(BOOL)inAnyFullscreen;
- (void)setFullscreenSlidingStyle:(fullscreen_mac::SlidingStyle)slidingStyle;
- (void)setFullscreenMenubarOffset:(CGFloat)menubarOffset;
- (void)setFullscreenToolbarFraction:(CGFloat)toolbarFraction;

- (void)setHasTabStrip:(BOOL)hasTabStrip;
- (void)setFullscreenButtonFrame:(NSRect)frame;
- (void)setShouldShowAvatar:(BOOL)shouldShowAvatar;
- (void)setShouldUseNewAvatar:(BOOL)shouldUseNewAvatar;
- (void)setAvatarSize:(NSSize)avatarSize;
- (void)setAvatarLineWidth:(CGFloat)avatarLineWidth;

- (void)setHasToolbar:(BOOL)hasToolbar;
- (void)setHasLocationBar:(BOOL)hasLocationBar;
- (void)setToolbarHeight:(CGFloat)toolbarHeight;

- (void)setBookmarkBarHidden:(BOOL)bookmarkBarHidden;
- (void)setPlaceBookmarkBarBelowInfoBar:(BOOL)placeBookmarkBarBelowInfoBar;
- (void)setBookmarkBarHeight:(CGFloat)bookmarkBarHeight;

// The height of the info bar, not including the top arrow.
- (void)setInfoBarHeight:(CGFloat)infoBarHeight;
// The min Y of the bubble point, relative to the toolbar.
- (void)setPageInfoBubblePointY:(CGFloat)pageInfoBubblePointY;

- (void)setHasDownloadShelf:(BOOL)hasDownloadShelf;
- (void)setDownloadShelfHeight:(CGFloat)downloadShelfHeight;
@end

@interface BrowserWindowLayout (ExposedForTesting)
- (void)setOSYosemiteOrLater:(BOOL)osYosemiteOrLater;
@end

#endif  // CHROME_BROWSER_UI_COCOA_BROWSER_WINDOW_CONTROLLER_LAYOUT_H_