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

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

Issue 1622833002: Fix opaque frame incognito icon and tabstrip positioning. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cleanup
Patch Set: Created 4 years, 11 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/gfx/font.h" 15 #include "ui/gfx/font.h"
15 #include "ui/views/controls/button/image_button.h" 16 #include "ui/views/controls/button/image_button.h"
16 #include "ui/views/controls/label.h" 17 #include "ui/views/controls/label.h"
17 18
18 namespace { 19 namespace {
19 20
20 // Besides the frame border, there's empty space atop the window in restored 21 // Besides the frame border, there's empty space atop the window in restored
21 // mode, to use to drag the window around. 22 // mode, to use to drag the window around.
22 const int kNonClientRestoredExtraThickness = 11; 23 const int kNonClientRestoredExtraThickness = 11;
23 24
(...skipping 11 matching lines...) Expand all
35 36
36 // The titlebar has a 2 px 3D edge along the top and bottom. 37 // The titlebar has a 2 px 3D edge along the top and bottom.
37 const int kTitlebarTopAndBottomEdgeThickness = 2; 38 const int kTitlebarTopAndBottomEdgeThickness = 2;
38 39
39 // The icon is inset 2 px from the left frame border. 40 // The icon is inset 2 px from the left frame border.
40 const int kIconLeftSpacing = 2; 41 const int kIconLeftSpacing = 2;
41 42
42 // There is a 4 px gap between the icon and the title text. 43 // There is a 4 px gap between the icon and the title text.
43 const int kIconTitleSpacing = 4; 44 const int kIconTitleSpacing = 4;
44 45
45 // Space between the edge of the avatar and the tabstrip.
46 const int kAvatarInnerSpacing = 4;
47
48 // How far the new avatar button is from the closest caption button. 46 // How far the new avatar button is from the closest caption button.
49 const int kNewAvatarButtonOffset = 5; 47 const int kNewAvatarButtonOffset = 5;
50 48
51 // When the title bar is in its normal two row mode (usually the case for 49 // When the title bar is in its normal two row mode (usually the case for
52 // restored windows), the New Tab button isn't at the same height as the caption 50 // restored windows), the New Tab button isn't at the same height as the caption
53 // buttons, but the space will look cluttered if it actually slides under them, 51 // buttons, but the space will look cluttered if it actually slides under them,
54 // so we stop it when the gap between the two is down to 5 px. 52 // so we stop it when the gap between the two is down to 5 px.
55 const int kNewTabCaptionNormalSpacing = 5; 53 const int kNewTabCaptionNormalSpacing = 5;
56 54
57 // When the title bar is condensed to one row (as when maximized), the New Tab 55 // When the title bar is condensed to one row (as when maximized), the New Tab
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 const std::vector<views::FrameButton>& trailing_buttons) { 109 const std::vector<views::FrameButton>& trailing_buttons) {
112 leading_buttons_ = leading_buttons; 110 leading_buttons_ = leading_buttons;
113 trailing_buttons_ = trailing_buttons; 111 trailing_buttons_ = trailing_buttons;
114 } 112 }
115 113
116 gfx::Rect OpaqueBrowserFrameViewLayout::GetBoundsForTabStrip( 114 gfx::Rect OpaqueBrowserFrameViewLayout::GetBoundsForTabStrip(
117 const gfx::Size& tabstrip_preferred_size, 115 const gfx::Size& tabstrip_preferred_size,
118 int available_width) const { 116 int available_width) const {
119 int x = leading_button_start_ + GetLayoutInsets(AVATAR_ICON).right(); 117 int x = leading_button_start_ + GetLayoutInsets(AVATAR_ICON).right();
120 available_width -= x + NewTabCaptionSpacing() + trailing_button_start_; 118 available_width -= x + NewTabCaptionSpacing() + trailing_button_start_;
121 gfx::Rect bounds(x, GetTabStripInsetsTop(false), std::max(0, available_width), 119 return gfx::Rect(x, GetTabStripInsetsTop(false), std::max(0, available_width),
122 tabstrip_preferred_size.height()); 120 tabstrip_preferred_size.height());
123
124 if (delegate_->ShouldShowAvatar() && !ShouldIncognitoIconBeOnRight())
125 bounds.Inset(kAvatarInnerSpacing, 0, 0, 0);
126 return bounds;
127 } 121 }
128 122
129 gfx::Size OpaqueBrowserFrameViewLayout::GetMinimumSize( 123 gfx::Size OpaqueBrowserFrameViewLayout::GetMinimumSize(
130 int available_width) const { 124 int available_width) const {
131 gfx::Size min_size = delegate_->GetBrowserViewMinimumSize(); 125 gfx::Size min_size = delegate_->GetBrowserViewMinimumSize();
132 int border_thickness = NonClientBorderThickness(); 126 int border_thickness = NonClientBorderThickness();
133 min_size.Enlarge(2 * border_thickness, 127 min_size.Enlarge(2 * border_thickness,
134 NonClientTopBorderHeight(false) + border_thickness); 128 NonClientTopBorderHeight(false) + border_thickness);
135 129
136 // Ensure that we can, at minimum, hold our window controls and avatar icon. 130 // Ensure that we can, at minimum, hold our window controls and avatar icon.
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 GetLayoutSize(NEW_TAB_BUTTON).width() + kNewTabCaptionNormalSpacing; 373 GetLayoutSize(NEW_TAB_BUTTON).width() + kNewTabCaptionNormalSpacing;
380 } 374 }
381 375
382 new_avatar_button_->SetBounds(button_x, button_y, button_width, 376 new_avatar_button_->SetBounds(button_x, button_y, button_width,
383 kCaptionButtonHeight); 377 kCaptionButtonHeight);
384 } 378 }
385 379
386 void OpaqueBrowserFrameViewLayout::LayoutIncognitoIcon(views::View* host) { 380 void OpaqueBrowserFrameViewLayout::LayoutIncognitoIcon(views::View* host) {
387 const int old_button_size = leading_button_start_ + trailing_button_start_; 381 const int old_button_size = leading_button_start_ + trailing_button_start_;
388 382
383 // Any buttons/icon/title were laid out based on the frame border thickness,
384 // but the tabstrip bounds need to be based on the non-client border thickness
385 // on any side where there aren't other buttons forcing a larger inset.
386 const bool md = ui::MaterialDesignController::IsModeMaterial();
387 int min_button_width = NonClientBorderThickness();
388 // In non-MD, the toolbar has a rounded corner that we don't want the tabstrip
389 // to overlap.
390 if (!md && !avatar_button_)
391 min_button_width += delegate_->GetToolbarLeadingCornerClientWidth();
392 leading_button_start_ = std::max(leading_button_start_, min_button_width);
393 // The trailing corner is a mirror of the leading one.
394 trailing_button_start_ = std::max(trailing_button_start_, min_button_width);
395
389 if (avatar_button_) { 396 if (avatar_button_) {
390 const gfx::Insets insets(GetLayoutInsets(AVATAR_ICON)); 397 const gfx::Insets insets(GetLayoutInsets(AVATAR_ICON));
391 const gfx::Size size(delegate_->GetOTRAvatarIcon().size()); 398 const gfx::Size size(delegate_->GetOTRAvatarIcon().size());
392 const int incognito_width = insets.left() + size.width(); 399 const int incognito_width = insets.left() + size.width();
393 int x; 400 int x;
394 if (ShouldIncognitoIconBeOnRight()) { 401 if (ShouldIncognitoIconBeOnRight()) {
395 trailing_button_start_ += incognito_width; 402 trailing_button_start_ += incognito_width;
396 x = host->width() - trailing_button_start_; 403 x = host->width() - trailing_button_start_;
397 } else { 404 } else {
398 x = leading_button_start_ + insets.left(); 405 x = leading_button_start_ + insets.left();
399 leading_button_start_ += incognito_width; 406 leading_button_start_ += incognito_width;
400 } 407 }
401 const int bottom = GetTabStripInsetsTop(false) + 408 const int bottom = GetTabStripInsetsTop(false) +
402 delegate_->GetTabStripHeight() - insets.bottom(); 409 delegate_->GetTabStripHeight() - insets.bottom();
403 int y = IsTitleBarCondensed() ? 410 const int y = (md || !IsTitleBarCondensed()) ?
404 FrameBorderThickness(false) : (bottom - size.height()); 411 (bottom - size.height()) : FrameBorderThickness(false);
405 avatar_button_->SetBounds(x, y, size.width(), bottom - y); 412 avatar_button_->SetBounds(x, y, size.width(), bottom - y);
406 } 413 }
407 414
408 minimum_size_for_buttons_ += 415 minimum_size_for_buttons_ +=
409 (leading_button_start_ + trailing_button_start_ - old_button_size); 416 (leading_button_start_ + trailing_button_start_ - old_button_size);
410 } 417 }
411 418
412 void OpaqueBrowserFrameViewLayout::ConfigureButton( 419 void OpaqueBrowserFrameViewLayout::ConfigureButton(
413 views::View* host, 420 views::View* host,
414 views::FrameButton button_id, 421 views::FrameButton button_id,
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 int thickness = FrameBorderThickness(false); 606 int thickness = FrameBorderThickness(false);
600 leading_button_start_ = thickness; 607 leading_button_start_ = thickness;
601 trailing_button_start_ = thickness; 608 trailing_button_start_ = thickness;
602 minimum_size_for_buttons_ = leading_button_start_ + trailing_button_start_; 609 minimum_size_for_buttons_ = leading_button_start_ + trailing_button_start_;
603 has_leading_buttons_ = false; 610 has_leading_buttons_ = false;
604 has_trailing_buttons_ = false; 611 has_trailing_buttons_ = false;
605 612
606 LayoutWindowControls(host); 613 LayoutWindowControls(host);
607 LayoutTitleBar(host); 614 LayoutTitleBar(host);
608 615
609 // We now add a single pixel to the leading spacing. We do this because the
610 // avatar and tab strip start one pixel inward compared to where things start
611 // on the trailing side.
612 leading_button_start_++;
613
614 if (delegate_->IsRegularOrGuestSession()) 616 if (delegate_->IsRegularOrGuestSession())
615 LayoutNewStyleAvatar(host); 617 LayoutNewStyleAvatar(host);
616 else 618 LayoutIncognitoIcon(host);
617 LayoutIncognitoIcon(host);
618 619
619 client_view_bounds_ = CalculateClientAreaBounds( 620 client_view_bounds_ = CalculateClientAreaBounds(
620 host->width(), host->height()); 621 host->width(), host->height());
621 } 622 }
622 623
623 gfx::Size OpaqueBrowserFrameViewLayout::GetPreferredSize( 624 gfx::Size OpaqueBrowserFrameViewLayout::GetPreferredSize(
624 const views::View* host) const { 625 const views::View* host) const {
625 // This is never used; NonClientView::GetPreferredSize() will be called 626 // This is never used; NonClientView::GetPreferredSize() will be called
626 // instead. 627 // instead.
627 NOTREACHED(); 628 NOTREACHED();
628 return gfx::Size(); 629 return gfx::Size();
629 } 630 }
630 631
631 void OpaqueBrowserFrameViewLayout::ViewAdded(views::View* host, 632 void OpaqueBrowserFrameViewLayout::ViewAdded(views::View* host,
632 views::View* view) { 633 views::View* view) {
633 SetView(view->id(), view); 634 SetView(view->id(), view);
634 } 635 }
635 636
636 void OpaqueBrowserFrameViewLayout::ViewRemoved(views::View* host, 637 void OpaqueBrowserFrameViewLayout::ViewRemoved(views::View* host,
637 views::View* view) { 638 views::View* view) {
638 SetView(view->id(), nullptr); 639 SetView(view->id(), nullptr);
639 } 640 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698