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

Side by Side Diff: chrome/browser/ui/views/frame/opaque_browser_frame_view_layout.cc

Issue 1869163003: Refactored GlassBrowserFrameView and BrowserDesktopTreeHostWin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix merge error Created 4 years, 8 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view_layout.h" 5 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view_layout.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "chrome/browser/profiles/profiles_state.h" 9 #include "chrome/browser/profiles/profiles_state.h"
10 #include "chrome/browser/ui/layout_constants.h" 10 #include "chrome/browser/ui/layout_constants.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 available_width -= x + NewTabCaptionSpacing() + trailing_button_start_; 112 available_width -= x + NewTabCaptionSpacing() + trailing_button_start_;
113 return gfx::Rect(x, GetTabStripInsetsTop(false), std::max(0, available_width), 113 return gfx::Rect(x, GetTabStripInsetsTop(false), std::max(0, available_width),
114 tabstrip_preferred_size.height()); 114 tabstrip_preferred_size.height());
115 } 115 }
116 116
117 gfx::Size OpaqueBrowserFrameViewLayout::GetMinimumSize( 117 gfx::Size OpaqueBrowserFrameViewLayout::GetMinimumSize(
118 int available_width) const { 118 int available_width) const {
119 gfx::Size min_size = delegate_->GetBrowserViewMinimumSize(); 119 gfx::Size min_size = delegate_->GetBrowserViewMinimumSize();
120 int border_thickness = NonClientBorderThickness(); 120 int border_thickness = NonClientBorderThickness();
121 min_size.Enlarge(2 * border_thickness, 121 min_size.Enlarge(2 * border_thickness,
122 NonClientTopBorderHeight(false) + border_thickness); 122 NonClientTopHeight(false) + border_thickness);
123 123
124 // Ensure that we can, at minimum, hold our window controls and avatar icon. 124 // Ensure that we can, at minimum, hold our window controls and avatar icon.
125 min_size.set_width(std::max(min_size.width(), minimum_size_for_buttons_)); 125 min_size.set_width(std::max(min_size.width(), minimum_size_for_buttons_));
126 126
127 // Ensure that the minimum width is enough to hold a minimum width tab strip 127 // Ensure that the minimum width is enough to hold a minimum width tab strip
128 // at its usual insets. 128 // at its usual insets.
129 if (delegate_->IsTabStripVisible()) { 129 if (delegate_->IsTabStripVisible()) {
130 gfx::Size preferred_size = delegate_->GetTabstripPreferredSize(); 130 gfx::Size preferred_size = delegate_->GetTabstripPreferredSize();
131 const int min_tabstrip_width = preferred_size.width(); 131 const int min_tabstrip_width = preferred_size.width();
132 const int caption_spacing = NewTabCaptionSpacing(); 132 const int caption_spacing = NewTabCaptionSpacing();
133 min_size.Enlarge(min_tabstrip_width + caption_spacing, 0); 133 min_size.Enlarge(min_tabstrip_width + caption_spacing, 0);
134 } 134 }
135 135
136 return min_size; 136 return min_size;
137 } 137 }
138 138
139 gfx::Rect OpaqueBrowserFrameViewLayout::GetWindowBoundsForClientBounds( 139 gfx::Rect OpaqueBrowserFrameViewLayout::GetWindowBoundsForClientBounds(
140 const gfx::Rect& client_bounds) const { 140 const gfx::Rect& client_bounds) const {
141 int top_height = NonClientTopBorderHeight(false); 141 int top_height = NonClientTopHeight(false);
142 int border_thickness = NonClientBorderThickness(); 142 int border_thickness = NonClientBorderThickness();
143 return gfx::Rect(std::max(0, client_bounds.x() - border_thickness), 143 return gfx::Rect(std::max(0, client_bounds.x() - border_thickness),
144 std::max(0, client_bounds.y() - top_height), 144 std::max(0, client_bounds.y() - top_height),
145 client_bounds.width() + (2 * border_thickness), 145 client_bounds.width() + (2 * border_thickness),
146 client_bounds.height() + top_height + border_thickness); 146 client_bounds.height() + top_height + border_thickness);
147 } 147 }
148 148
149 int OpaqueBrowserFrameViewLayout::FrameBorderThickness(bool restored) const { 149 int OpaqueBrowserFrameViewLayout::FrameBorderThickness(bool restored) const {
150 return (!restored && (IsTitleBarCondensed() || delegate_->IsFullscreen())) ? 150 return (!restored && (IsTitleBarCondensed() || delegate_->IsFullscreen())) ?
151 0 : kFrameBorderThickness; 151 0 : kFrameBorderThickness;
152 } 152 }
153 153
154 int OpaqueBrowserFrameViewLayout::NonClientBorderThickness() const { 154 int OpaqueBrowserFrameViewLayout::NonClientBorderThickness() const {
155 const int frame = FrameBorderThickness(false); 155 const int frame = FrameBorderThickness(false);
156 // When we fill the screen, we don't show a client edge. 156 // When we fill the screen, we don't show a client edge.
157 return (IsTitleBarCondensed() || delegate_->IsFullscreen()) ? 157 return (IsTitleBarCondensed() || delegate_->IsFullscreen()) ?
158 frame : (frame + views::NonClientFrameView::kClientEdgeThickness); 158 frame : (frame + views::NonClientFrameView::kClientEdgeThickness);
159 } 159 }
160 160
161 int OpaqueBrowserFrameViewLayout::NonClientTopBorderHeight( 161 int OpaqueBrowserFrameViewLayout::NonClientTopHeight(bool restored) const {
162 bool restored) const {
163 if (delegate_->ShouldShowWindowTitle()) { 162 if (delegate_->ShouldShowWindowTitle()) {
164 // The + 2 here puts at least 1 px of space on top and bottom of the icon. 163 // The + 2 here puts at least 1 px of space on top and bottom of the icon.
165 const int icon_height = 164 const int icon_height =
166 TitlebarTopThickness(restored) + delegate_->GetIconSize() + 2; 165 TitlebarTopThickness(restored) + delegate_->GetIconSize() + 2;
167 const int caption_button_height = CaptionButtonY(restored) + 166 const int caption_button_height = CaptionButtonY(restored) +
168 kCaptionButtonHeight + kCaptionButtonBottomPadding; 167 kCaptionButtonHeight + kCaptionButtonBottomPadding;
169 return std::max(icon_height, caption_button_height) + 168 return std::max(icon_height, caption_button_height) +
170 kContentEdgeShadowThickness; 169 kContentEdgeShadowThickness;
171 } 170 }
172 171
173 int thickness = FrameBorderThickness(restored); 172 int thickness = FrameBorderThickness(restored);
174 // The tab top inset is equal to the height of any shadow region above the 173 // The tab top inset is equal to the height of any shadow region above the
175 // tabs, plus a 1 px top stroke. In maximized mode, we want to push the 174 // tabs, plus a 1 px top stroke. In maximized mode, we want to push the
176 // shadow region off the top of the screen but leave the top stroke. 175 // shadow region off the top of the screen but leave the top stroke.
177 if (!restored && delegate_->IsTabStripVisible() && IsTitleBarCondensed()) 176 if (!restored && delegate_->IsTabStripVisible() && IsTitleBarCondensed())
178 thickness -= GetLayoutInsets(TAB).top() - 1; 177 thickness -= GetLayoutInsets(TAB).top() - 1;
179 return thickness; 178 return thickness;
180 } 179 }
181 180
182 int OpaqueBrowserFrameViewLayout::GetTabStripInsetsTop(bool restored) const { 181 int OpaqueBrowserFrameViewLayout::GetTabStripInsetsTop(bool restored) const {
183 const int top = NonClientTopBorderHeight(restored); 182 const int top = NonClientTopHeight(restored);
184 // Annoyingly, the pre-MD layout uses different heights for the hit-test 183 // Annoyingly, the pre-MD layout uses different heights for the hit-test
185 // exclusion region (which we want here, since we're trying to size the border 184 // exclusion region (which we want here, since we're trying to size the border
186 // so that the region above the tab's hit-test zone matches) versus the shadow 185 // so that the region above the tab's hit-test zone matches) versus the shadow
187 // thickness. 186 // thickness.
188 const int exclusion = GetLayoutConstant(TAB_TOP_EXCLUSION_HEIGHT); 187 const int exclusion = GetLayoutConstant(TAB_TOP_EXCLUSION_HEIGHT);
189 return (!restored && (IsTitleBarCondensed() || delegate_->IsFullscreen())) ? 188 return (!restored && (IsTitleBarCondensed() || delegate_->IsFullscreen())) ?
190 top : (top + kNonClientRestoredExtraThickness - exclusion); 189 top : (top + kNonClientRestoredExtraThickness - exclusion);
191 } 190 }
192 191
193 int OpaqueBrowserFrameViewLayout::TitlebarTopThickness(bool restored) const { 192 int OpaqueBrowserFrameViewLayout::TitlebarTopThickness(bool restored) const {
(...skipping 11 matching lines...) Expand all
205 return frame + extra_caption_y_; 204 return frame + extra_caption_y_;
206 } 205 }
207 206
208 gfx::Rect OpaqueBrowserFrameViewLayout::IconBounds() const { 207 gfx::Rect OpaqueBrowserFrameViewLayout::IconBounds() const {
209 return window_icon_bounds_; 208 return window_icon_bounds_;
210 } 209 }
211 210
212 gfx::Rect OpaqueBrowserFrameViewLayout::CalculateClientAreaBounds( 211 gfx::Rect OpaqueBrowserFrameViewLayout::CalculateClientAreaBounds(
213 int width, 212 int width,
214 int height) const { 213 int height) const {
215 int top_height = NonClientTopBorderHeight(false); 214 int top_height = NonClientTopHeight(false);
216 int border_thickness = NonClientBorderThickness(); 215 int border_thickness = NonClientBorderThickness();
217 return gfx::Rect(border_thickness, top_height, 216 return gfx::Rect(border_thickness, top_height,
218 std::max(0, width - (2 * border_thickness)), 217 std::max(0, width - (2 * border_thickness)),
219 std::max(0, height - top_height - border_thickness)); 218 std::max(0, height - top_height - border_thickness));
220 } 219 }
221 220
222 bool OpaqueBrowserFrameViewLayout::IsTitleBarCondensed() const { 221 bool OpaqueBrowserFrameViewLayout::IsTitleBarCondensed() const {
223 // If there are no caption buttons, there is no need to have an uncondensed 222 // If there are no caption buttons, there is no need to have an uncondensed
224 // title bar. If the window is maximized, the title bar is condensed 223 // title bar. If the window is maximized, the title bar is condensed
225 // regardless of whether there are caption buttons. 224 // regardless of whether there are caption buttons.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 // slightly uncentered with restored windows, so when the window is 291 // slightly uncentered with restored windows, so when the window is
293 // restored, instead of calculating the remaining space from below the 292 // restored, instead of calculating the remaining space from below the
294 // frame border, we calculate from below the 3D edge. 293 // frame border, we calculate from below the 3D edge.
295 const int unavailable_px_at_top = TitlebarTopThickness(false); 294 const int unavailable_px_at_top = TitlebarTopThickness(false);
296 // When the icon is shorter than the minimum space we reserve for the 295 // When the icon is shorter than the minimum space we reserve for the
297 // caption button, we vertically center it. We want to bias rounding to 296 // caption button, we vertically center it. We want to bias rounding to
298 // put extra space below the icon, since we'll use the same Y coordinate for 297 // put extra space below the icon, since we'll use the same Y coordinate for
299 // the title, and the majority of the font weight is below the centerline. 298 // the title, and the majority of the font weight is below the centerline.
300 const int icon_height = 299 const int icon_height =
301 unavailable_px_at_top + size + kContentEdgeShadowThickness; 300 unavailable_px_at_top + size + kContentEdgeShadowThickness;
302 const int y = unavailable_px_at_top + 301 const int y =
303 (NonClientTopBorderHeight(false) - icon_height) / 2; 302 unavailable_px_at_top + (NonClientTopHeight(false) - icon_height) / 2;
304 303
305 window_icon_bounds_ = gfx::Rect(leading_button_start_ + kIconLeftSpacing, y, 304 window_icon_bounds_ = gfx::Rect(leading_button_start_ + kIconLeftSpacing, y,
306 size, size); 305 size, size);
307 leading_button_start_ += size + kIconLeftSpacing; 306 leading_button_start_ += size + kIconLeftSpacing;
308 minimum_size_for_buttons_ += size + kIconLeftSpacing; 307 minimum_size_for_buttons_ += size + kIconLeftSpacing;
309 } 308 }
310 309
311 if (should_show_icon) 310 if (should_show_icon)
312 window_icon_->SetBoundsRect(window_icon_bounds_); 311 window_icon_->SetBoundsRect(window_icon_bounds_);
313 312
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 618
620 void OpaqueBrowserFrameViewLayout::ViewAdded(views::View* host, 619 void OpaqueBrowserFrameViewLayout::ViewAdded(views::View* host,
621 views::View* view) { 620 views::View* view) {
622 SetView(view->id(), view); 621 SetView(view->id(), view);
623 } 622 }
624 623
625 void OpaqueBrowserFrameViewLayout::ViewRemoved(views::View* host, 624 void OpaqueBrowserFrameViewLayout::ViewRemoved(views::View* host,
626 views::View* view) { 625 views::View* view) {
627 SetView(view->id(), nullptr); 626 SetView(view->id(), nullptr);
628 } 627 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/opaque_browser_frame_view_layout.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698