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

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

Issue 1685763004: Fix various issues with popup/app window layout/drawing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cleanup
Patch Set: Fix unittest Created 4 years, 10 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"
11 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" 11 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h"
12 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
13 #include "components/signin/core/common/profile_management_switches.h" 13 #include "components/signin/core/common/profile_management_switches.h"
14 #include "ui/base/material_design/material_design_controller.h" 14 #include "ui/base/material_design/material_design_controller.h"
15 #include "ui/gfx/font.h" 15 #include "ui/gfx/font.h"
16 #include "ui/views/controls/button/image_button.h" 16 #include "ui/views/controls/button/image_button.h"
17 #include "ui/views/controls/label.h" 17 #include "ui/views/controls/label.h"
18 18
19 namespace { 19 namespace {
20 20
21 // The titlebar never shrinks too short to show the caption button plus some
22 // padding below it.
23 const int kCaptionButtonHeight = 18; 21 const int kCaptionButtonHeight = 18;
24 const int kTitleBarAdditionalPadding = 3;
25 22
26 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 23 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
27 // Default extra space between the top of the frame and the top of the window 24 // Default extra space between the top of the frame and the top of the window
28 // caption buttons. 25 // caption buttons.
29 const int kExtraCaption = 2; 26 const int kExtraCaption = 2;
30 27
31 // Default extra spacing between individual window caption buttons. 28 // Default extra spacing between individual window caption buttons.
32 const int kCaptionButtonSpacing = 2; 29 const int kCaptionButtonSpacing = 2;
33 #else 30 #else
34 const int kExtraCaption = 0; 31 const int kExtraCaption = 0;
(...skipping 14 matching lines...) Expand all
49 // mode, to use to drag the window around. 46 // mode, to use to drag the window around.
50 const int OpaqueBrowserFrameViewLayout::kNonClientRestoredExtraThickness = 11; 47 const int OpaqueBrowserFrameViewLayout::kNonClientRestoredExtraThickness = 11;
51 48
52 // The frame border is only visible in restored mode and is hardcoded to 4 px on 49 // The frame border is only visible in restored mode and is hardcoded to 4 px on
53 // each side regardless of the system window border size. 50 // each side regardless of the system window border size.
54 const int OpaqueBrowserFrameViewLayout::kFrameBorderThickness = 4; 51 const int OpaqueBrowserFrameViewLayout::kFrameBorderThickness = 4;
55 52
56 // The titlebar has a 2 px 3D edge along the top. 53 // The titlebar has a 2 px 3D edge along the top.
57 const int OpaqueBrowserFrameViewLayout::kTitlebarTopEdgeThickness = 2; 54 const int OpaqueBrowserFrameViewLayout::kTitlebarTopEdgeThickness = 2;
58 55
59 // The icon is inset 2 px from the left frame border. 56 // The icon is inset 1 px from the left frame border.
60 const int OpaqueBrowserFrameViewLayout::kIconLeftSpacing = 2; 57 const int OpaqueBrowserFrameViewLayout::kIconLeftSpacing = 1;
61 58
62 // There is a 4 px gap between the icon and the title text. 59 // There is a 4 px gap between the icon and the title text.
63 const int OpaqueBrowserFrameViewLayout::kIconTitleSpacing = 4; 60 const int OpaqueBrowserFrameViewLayout::kIconTitleSpacing = 4;
64 61
65 // The horizontal spacing to use in most cases when laying out things near the 62 // The horizontal spacing to use in most cases when laying out things near the
66 // caption button area. 63 // caption button area.
67 const int OpaqueBrowserFrameViewLayout::kCaptionSpacing = 5; 64 const int OpaqueBrowserFrameViewLayout::kCaptionSpacing = 5;
68 65
66 // The minimum vertical padding between the bottom of the caption buttons and
67 // the top of the content shadow.
68 const int OpaqueBrowserFrameViewLayout::kCaptionButtonBottomPadding = 3;
69
69 // When the title bar is condensed to one row (as when maximized), the New Tab 70 // When the title bar is condensed to one row (as when maximized), the New Tab
70 // button and the caption buttons are at similar vertical coordinates, so we 71 // button and the caption buttons are at similar vertical coordinates, so we
71 // need to reserve a larger, 16 px gap to avoid looking too cluttered. 72 // need to reserve a larger, 16 px gap to avoid looking too cluttered.
72 const int OpaqueBrowserFrameViewLayout::kNewTabCaptionCondensedSpacing = 16; 73 const int OpaqueBrowserFrameViewLayout::kNewTabCaptionCondensedSpacing = 16;
73 74
74 75
75 OpaqueBrowserFrameViewLayout::OpaqueBrowserFrameViewLayout( 76 OpaqueBrowserFrameViewLayout::OpaqueBrowserFrameViewLayout(
76 OpaqueBrowserFrameViewLayoutDelegate* delegate) 77 OpaqueBrowserFrameViewLayoutDelegate* delegate)
77 : delegate_(delegate), 78 : delegate_(delegate),
78 leading_button_start_(0), 79 leading_button_start_(0),
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 int OpaqueBrowserFrameViewLayout::NonClientBorderThickness() const { 154 int OpaqueBrowserFrameViewLayout::NonClientBorderThickness() const {
154 const int frame = FrameBorderThickness(false); 155 const int frame = FrameBorderThickness(false);
155 // 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.
156 return (IsTitleBarCondensed() || delegate_->IsFullscreen()) ? 157 return (IsTitleBarCondensed() || delegate_->IsFullscreen()) ?
157 frame : (frame + views::NonClientFrameView::kClientEdgeThickness); 158 frame : (frame + views::NonClientFrameView::kClientEdgeThickness);
158 } 159 }
159 160
160 int OpaqueBrowserFrameViewLayout::NonClientTopBorderHeight( 161 int OpaqueBrowserFrameViewLayout::NonClientTopBorderHeight(
161 bool restored) const { 162 bool restored) const {
162 if (delegate_->ShouldShowWindowTitle()) { 163 if (delegate_->ShouldShowWindowTitle()) {
163 return std::max(FrameBorderThickness(restored) + delegate_->GetIconSize(), 164 // The + 2 here puts at least 1 px of space on top and bottom of the icon.
164 CaptionButtonY(restored) + kCaptionButtonHeight) + 165 const int icon_height =
165 TitlebarBottomThickness(restored); 166 TitlebarTopThickness(restored) + delegate_->GetIconSize() + 2;
167 const int caption_button_height = CaptionButtonY(restored) +
168 kCaptionButtonHeight + kCaptionButtonBottomPadding;
169 return std::max(icon_height, caption_button_height) +
170 kContentEdgeShadowThickness;
166 } 171 }
167 172
168 int thickness = FrameBorderThickness(restored); 173 int thickness = FrameBorderThickness(restored);
169 // The tab top inset is equal to the height of any shadow region above the 174 // The tab top inset is equal to the height of any shadow region above the
170 // tabs, plus a 1 px top stroke. In maximized mode, we want to push the 175 // tabs, plus a 1 px top stroke. In maximized mode, we want to push the
171 // shadow region off the top of the screen but leave the top stroke. 176 // shadow region off the top of the screen but leave the top stroke.
172 if (!restored && delegate_->IsTabStripVisible() && IsTitleBarCondensed()) 177 if (!restored && delegate_->IsTabStripVisible() && IsTitleBarCondensed())
173 thickness -= GetLayoutInsets(TAB).top() - 1; 178 thickness -= GetLayoutInsets(TAB).top() - 1;
174 return thickness; 179 return thickness;
175 } 180 }
176 181
177 int OpaqueBrowserFrameViewLayout::GetTabStripInsetsTop(bool restored) const { 182 int OpaqueBrowserFrameViewLayout::GetTabStripInsetsTop(bool restored) const {
178 const int top = NonClientTopBorderHeight(restored); 183 const int top = NonClientTopBorderHeight(restored);
179 // Annoyingly, the pre-MD layout uses different heights for the hit-test 184 // Annoyingly, the pre-MD layout uses different heights for the hit-test
180 // exclusion region (which we want here, since we're trying to size the border 185 // exclusion region (which we want here, since we're trying to size the border
181 // so that the region above the tab's hit-test zone matches) versus the shadow 186 // so that the region above the tab's hit-test zone matches) versus the shadow
182 // thickness. 187 // thickness.
183 const int exclusion = GetLayoutConstant(TAB_TOP_EXCLUSION_HEIGHT); 188 const int exclusion = GetLayoutConstant(TAB_TOP_EXCLUSION_HEIGHT);
184 return (!restored && (IsTitleBarCondensed() || delegate_->IsFullscreen())) ? 189 return (!restored && (IsTitleBarCondensed() || delegate_->IsFullscreen())) ?
185 top : (top + kNonClientRestoredExtraThickness - exclusion); 190 top : (top + kNonClientRestoredExtraThickness - exclusion);
186 } 191 }
187 192
188 int OpaqueBrowserFrameViewLayout::TitlebarBottomThickness(bool restored) const { 193 int OpaqueBrowserFrameViewLayout::TitlebarTopThickness(bool restored) const {
189 const int thickness = 194 return (restored || !IsTitleBarCondensed()) ?
190 kTitleBarAdditionalPadding + kContentEdgeShadowThickness; 195 kTitlebarTopEdgeThickness : FrameBorderThickness(false);
191 return (delegate_->IsToolbarVisible() || !IsTitleBarCondensed() || restored)
192 ? (thickness + views::NonClientFrameView::kClientEdgeThickness)
193 : thickness;
194 } 196 }
195 197
196 int OpaqueBrowserFrameViewLayout::CaptionButtonY(bool restored) const { 198 int OpaqueBrowserFrameViewLayout::CaptionButtonY(bool restored) const {
197 // Maximized buttons start at window top, since the window has no border. This 199 // Maximized buttons start at window top, since the window has no border. This
198 // offset is for the image (the actual clickable bounds extend all the way to 200 // offset is for the image (the actual clickable bounds extend all the way to
199 // the top to take Fitts' Law into account). 201 // the top to take Fitts' Law into account).
200 const int frame = (!restored && IsTitleBarCondensed()) ? 202 const int frame = (!restored && IsTitleBarCondensed()) ?
201 FrameBorderThickness(false) : 203 FrameBorderThickness(false) :
202 views::NonClientFrameView::kFrameShadowThickness; 204 views::NonClientFrameView::kFrameShadowThickness;
203 return frame + extra_caption_y_; 205 return frame + extra_caption_y_;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 use_hidden_icon_location = false; 285 use_hidden_icon_location = false;
284 286
285 // Our frame border has a different "3D look" than Windows'. Theirs has 287 // Our frame border has a different "3D look" than Windows'. Theirs has
286 // a more complex gradient on the top that they push their icon/title 288 // a more complex gradient on the top that they push their icon/title
287 // below; then the maximized window cuts this off and the icon/title are 289 // below; then the maximized window cuts this off and the icon/title are
288 // centered in the remaining space. Because the apparent shape of our 290 // centered in the remaining space. Because the apparent shape of our
289 // border is simpler, using the same positioning makes things look 291 // border is simpler, using the same positioning makes things look
290 // slightly uncentered with restored windows, so when the window is 292 // slightly uncentered with restored windows, so when the window is
291 // restored, instead of calculating the remaining space from below the 293 // restored, instead of calculating the remaining space from below the
292 // frame border, we calculate from below the 3D edge. 294 // frame border, we calculate from below the 3D edge.
293 int unavailable_px_at_top = IsTitleBarCondensed() ? 295 const int unavailable_px_at_top = TitlebarTopThickness(false);
294 frame_thickness : kTitlebarTopEdgeThickness;
295 // When the icon is shorter than the minimum space we reserve for the 296 // When the icon is shorter than the minimum space we reserve for the
296 // caption button, we vertically center it. We want to bias rounding to 297 // caption button, we vertically center it. We want to bias rounding to
297 // put extra space above the icon, since the 3D edge (+ client edge, for 298 // put extra space below the icon, since we'll use the same Y coordinate for
298 // restored windows) below looks (to the eye) more like additional space 299 // the title, and the majority of the font weight is below the centerline.
299 // than does the 3D edge (or nothing at all, for maximized windows) 300 const int icon_height =
300 // above; hence the +1. 301 unavailable_px_at_top + size + kContentEdgeShadowThickness;
301 int y = unavailable_px_at_top + (NonClientTopBorderHeight(false) - 302 const int y = unavailable_px_at_top +
302 unavailable_px_at_top - size - 303 (NonClientTopBorderHeight(false) - icon_height) / 2;
303 TitlebarBottomThickness(false) + 1) / 2;
304 304
305 window_icon_bounds_ = gfx::Rect(leading_button_start_ + kIconLeftSpacing, y, 305 window_icon_bounds_ = gfx::Rect(leading_button_start_ + kIconLeftSpacing, y,
306 size, size); 306 size, size);
307 leading_button_start_ += size + kIconLeftSpacing; 307 leading_button_start_ += size + kIconLeftSpacing;
308 minimum_size_for_buttons_ += size + kIconLeftSpacing; 308 minimum_size_for_buttons_ += size + kIconLeftSpacing;
309 } 309 }
310 310
311 if (should_show_icon) 311 if (should_show_icon)
312 window_icon_->SetBoundsRect(window_icon_bounds_); 312 window_icon_->SetBoundsRect(window_icon_bounds_);
313 313
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 619
620 void OpaqueBrowserFrameViewLayout::ViewAdded(views::View* host, 620 void OpaqueBrowserFrameViewLayout::ViewAdded(views::View* host,
621 views::View* view) { 621 views::View* view) {
622 SetView(view->id(), view); 622 SetView(view->id(), view);
623 } 623 }
624 624
625 void OpaqueBrowserFrameViewLayout::ViewRemoved(views::View* host, 625 void OpaqueBrowserFrameViewLayout::ViewRemoved(views::View* host,
626 views::View* view) { 626 views::View* view) {
627 SetView(view->id(), nullptr); 627 SetView(view->id(), nullptr);
628 } 628 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698