Commit 17b40315 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Remove GetLayoutSize().

This was only used for the new tab button, but the new tab button now reports
the relevant size as its preferred size.  So we can use that directly
everywhere.

This will make it easier to add padding around the new tab button, because the
button can report a larger size to other callers without having to keep the
layout size in sync with a padding value local to new_tab_button.cc.

Bug: none
Change-Id: Id513c23ba458857032b05ed8e266387d9e1f1f55
Reviewed-on: https://chromium-review.googlesource.com/1135764
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarAllen Bauer <kylixrd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575050}
parent f7df5b34
...@@ -125,19 +125,3 @@ gfx::Insets GetLayoutInsets(LayoutInset inset) { ...@@ -125,19 +125,3 @@ gfx::Insets GetLayoutInsets(LayoutInset inset) {
NOTREACHED(); NOTREACHED();
return gfx::Insets(); return gfx::Insets();
} }
gfx::Size GetLayoutSize(LayoutSize size, bool is_incognito) {
const int mode = ui::MaterialDesignController::GetMode();
switch (size) {
case NEW_TAB_BUTTON: {
const gfx::Size sizes[] = {{36, 18},
{39, 21},
{(is_incognito ? 42 : 24), 24},
{28, 28},
{28, 28}};
return sizes[mode];
}
}
NOTREACHED();
return gfx::Size();
}
...@@ -116,14 +116,6 @@ enum LayoutInset { ...@@ -116,14 +116,6 @@ enum LayoutInset {
TOOLBAR_ACTION_VIEW, TOOLBAR_ACTION_VIEW,
}; };
enum LayoutSize {
// The visible size of the new tab button; does not include any Fitts' Law
// extensions. Note that in touch-optimized UI mode, the new tab button's
// width is larger when the browser is in incognito mode. The height remains
// the same whether incognito or not.
NEW_TAB_BUTTON,
};
int GetLayoutConstant(LayoutConstant constant); int GetLayoutConstant(LayoutConstant constant);
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
// Use this function instead of GetLayoutConstant() for Cocoa browser. // Use this function instead of GetLayoutConstant() for Cocoa browser.
...@@ -133,6 +125,5 @@ int GetCocoaLayoutConstant(LayoutConstant constant); ...@@ -133,6 +125,5 @@ int GetCocoaLayoutConstant(LayoutConstant constant);
#endif #endif
gfx::Insets GetLayoutInsets(LayoutInset inset); gfx::Insets GetLayoutInsets(LayoutInset inset);
gfx::Size GetLayoutSize(LayoutSize size, bool is_incognito);
#endif // CHROME_BROWSER_UI_LAYOUT_CONSTANTS_H_ #endif // CHROME_BROWSER_UI_LAYOUT_CONSTANTS_H_
...@@ -41,7 +41,6 @@ class TestLayoutDelegate : public OpaqueBrowserFrameViewLayoutDelegate { ...@@ -41,7 +41,6 @@ class TestLayoutDelegate : public OpaqueBrowserFrameViewLayoutDelegate {
~TestLayoutDelegate() override {} ~TestLayoutDelegate() override {}
// OpaqueBrowserFrameViewLayoutDelegate: // OpaqueBrowserFrameViewLayoutDelegate:
bool IsIncognito() const override { return false; }
bool ShouldShowWindowIcon() const override { return false; } bool ShouldShowWindowIcon() const override { return false; }
bool ShouldShowWindowTitle() const override { return false; } bool ShouldShowWindowTitle() const override { return false; }
base::string16 GetWindowTitle() const override { return base::string16(); } base::string16 GetWindowTitle() const override { return base::string16(); }
...@@ -65,6 +64,9 @@ class TestLayoutDelegate : public OpaqueBrowserFrameViewLayoutDelegate { ...@@ -65,6 +64,9 @@ class TestLayoutDelegate : public OpaqueBrowserFrameViewLayoutDelegate {
gfx::Size GetTabstripPreferredSize() const override { gfx::Size GetTabstripPreferredSize() const override {
return gfx::Size(78, 29); return gfx::Size(78, 29);
} }
gfx::Size GetNewTabButtonPreferredSize() const override {
return gfx::Size(28, 28);
}
int GetTopAreaHeight() const override { return 0; } int GetTopAreaHeight() const override { return 0; }
bool UseCustomFrame() const override { return true; } bool UseCustomFrame() const override { return true; }
......
...@@ -14,11 +14,11 @@ ...@@ -14,11 +14,11 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/themes/theme_properties.h" #include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/ui/extensions/hosted_app_browser_controller.h" #include "chrome/browser/ui/extensions/hosted_app_browser_controller.h"
#include "chrome/browser/ui/layout_constants.h"
#include "chrome/browser/ui/view_ids.h" #include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/frame/browser_view.h" #include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/hosted_app_button_container.h" #include "chrome/browser/ui/views/frame/hosted_app_button_container.h"
#include "chrome/browser/ui/views/profiles/profile_indicator_icon.h" #include "chrome/browser/ui/views/profiles/profile_indicator_icon.h"
#include "chrome/browser/ui/views/tabs/new_tab_button.h"
#include "chrome/browser/ui/views/tabs/tab.h" #include "chrome/browser/ui/views/tabs/tab.h"
#include "chrome/browser/ui/views/tabs/tab_strip.h" #include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h" #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
...@@ -644,8 +644,9 @@ int GlassBrowserFrameView::TabStripCaptionSpacing() const { ...@@ -644,8 +644,9 @@ int GlassBrowserFrameView::TabStripCaptionSpacing() const {
// When not maximized, allow the new tab button to slide completely under the // When not maximized, allow the new tab button to slide completely under the
// the profile switcher button. // the profile switcher button.
const bool incognito = browser_view()->tabstrip()->IsIncognito(); const auto* new_tab_button = browser_view()->tabstrip()->new_tab_button();
profile_spacing -= GetLayoutSize(NEW_TAB_BUTTON, incognito).width(); profile_spacing -= new_tab_button->GetPreferredSize().width();
return std::max(caption_spacing, profile_spacing); return std::max(caption_spacing, profile_spacing);
} }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "chrome/browser/ui/views/frame/opaque_browser_frame_view_platform_specific.h" #include "chrome/browser/ui/views/frame/opaque_browser_frame_view_platform_specific.h"
#include "chrome/browser/ui/views/profiles/profile_indicator_icon.h" #include "chrome/browser/ui/views/profiles/profile_indicator_icon.h"
#include "chrome/browser/ui/views/tab_icon_view.h" #include "chrome/browser/ui/views/tab_icon_view.h"
#include "chrome/browser/ui/views/tabs/new_tab_button.h"
#include "chrome/browser/ui/views/tabs/tab_strip.h" #include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h" #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
...@@ -357,10 +358,6 @@ gfx::ImageSkia OpaqueBrowserFrameView::GetFaviconForTabIconView() { ...@@ -357,10 +358,6 @@ gfx::ImageSkia OpaqueBrowserFrameView::GetFaviconForTabIconView() {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// OpaqueBrowserFrameView, OpaqueBrowserFrameViewLayoutDelegate implementation: // OpaqueBrowserFrameView, OpaqueBrowserFrameViewLayoutDelegate implementation:
bool OpaqueBrowserFrameView::IsIncognito() const {
return browser_view()->tabstrip()->IsIncognito();
}
bool OpaqueBrowserFrameView::ShouldShowWindowIcon() const { bool OpaqueBrowserFrameView::ShouldShowWindowIcon() const {
views::WidgetDelegate* delegate = frame()->widget_delegate(); views::WidgetDelegate* delegate = frame()->widget_delegate();
return ShouldShowWindowTitleBar() && delegate && return ShouldShowWindowTitleBar() && delegate &&
...@@ -434,8 +431,11 @@ int OpaqueBrowserFrameView::GetTabStripHeight() const { ...@@ -434,8 +431,11 @@ int OpaqueBrowserFrameView::GetTabStripHeight() const {
} }
gfx::Size OpaqueBrowserFrameView::GetTabstripPreferredSize() const { gfx::Size OpaqueBrowserFrameView::GetTabstripPreferredSize() const {
gfx::Size s = browser_view()->tabstrip()->GetPreferredSize(); return browser_view()->tabstrip()->GetPreferredSize();
return s; }
gfx::Size OpaqueBrowserFrameView::GetNewTabButtonPreferredSize() const {
return browser_view()->tabstrip()->new_tab_button()->GetPreferredSize();
} }
int OpaqueBrowserFrameView::GetTopAreaHeight() const { int OpaqueBrowserFrameView::GetTopAreaHeight() const {
......
...@@ -86,7 +86,6 @@ class OpaqueBrowserFrameView : public BrowserNonClientFrameView, ...@@ -86,7 +86,6 @@ class OpaqueBrowserFrameView : public BrowserNonClientFrameView,
gfx::ImageSkia GetFaviconForTabIconView() override; gfx::ImageSkia GetFaviconForTabIconView() override;
// OpaqueBrowserFrameViewLayoutDelegate implementation: // OpaqueBrowserFrameViewLayoutDelegate implementation:
bool IsIncognito() const override;
bool ShouldShowWindowIcon() const override; bool ShouldShowWindowIcon() const override;
bool ShouldShowWindowTitle() const override; bool ShouldShowWindowTitle() const override;
base::string16 GetWindowTitle() const override; base::string16 GetWindowTitle() const override;
...@@ -102,6 +101,7 @@ class OpaqueBrowserFrameView : public BrowserNonClientFrameView, ...@@ -102,6 +101,7 @@ class OpaqueBrowserFrameView : public BrowserNonClientFrameView,
int GetTabStripHeight() const override; int GetTabStripHeight() const override;
bool IsToolbarVisible() const override; bool IsToolbarVisible() const override;
gfx::Size GetTabstripPreferredSize() const override; gfx::Size GetTabstripPreferredSize() const override;
gfx::Size GetNewTabButtonPreferredSize() const override;
int GetTopAreaHeight() const override; int GetTopAreaHeight() const override;
bool UseCustomFrame() const override; bool UseCustomFrame() const override;
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "base/containers/adapters.h" #include "base/containers/adapters.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/profiles/profiles_state.h" #include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/ui/layout_constants.h"
#include "chrome/browser/ui/views/profiles/profile_indicator_icon.h" #include "chrome/browser/ui/views/profiles/profile_indicator_icon.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "components/signin/core/browser/profile_management_switches.h" #include "components/signin/core/browser/profile_management_switches.h"
...@@ -300,8 +299,7 @@ void OpaqueBrowserFrameViewLayout::LayoutNewStyleAvatar(views::View* host) { ...@@ -300,8 +299,7 @@ void OpaqueBrowserFrameViewLayout::LayoutNewStyleAvatar(views::View* host) {
// the avatar button. // the avatar button.
if (!IsTitleBarCondensed()) { if (!IsTitleBarCondensed()) {
trailing_button_start_ -= trailing_button_start_ -=
GetLayoutSize(NEW_TAB_BUTTON, delegate_->IsIncognito()).width() + delegate_->GetNewTabButtonPreferredSize().width() + kCaptionSpacing;
kCaptionSpacing;
} }
new_avatar_button_->SetBounds(button_x, button_y, button_width, new_avatar_button_->SetBounds(button_x, button_y, button_width,
......
...@@ -14,9 +14,6 @@ class Size; ...@@ -14,9 +14,6 @@ class Size;
// Browser{,Frame,View}. // Browser{,Frame,View}.
class OpaqueBrowserFrameViewLayoutDelegate { class OpaqueBrowserFrameViewLayoutDelegate {
public: public:
// Returns true if the browser is in incognito mode.
virtual bool IsIncognito() const = 0;
// Controls the visual placement of the window icon/title in non-tabstrip // Controls the visual placement of the window icon/title in non-tabstrip
// mode. // mode.
virtual bool ShouldShowWindowIcon() const = 0; virtual bool ShouldShowWindowIcon() const = 0;
...@@ -55,6 +52,9 @@ class OpaqueBrowserFrameViewLayoutDelegate { ...@@ -55,6 +52,9 @@ class OpaqueBrowserFrameViewLayoutDelegate {
// it. // it.
virtual gfx::Size GetTabstripPreferredSize() const = 0; virtual gfx::Size GetTabstripPreferredSize() const = 0;
// Returns the New Tab Button's preferred size.
virtual gfx::Size GetNewTabButtonPreferredSize() const = 0;
// Computes the height of the top area of the frame. // Computes the height of the top area of the frame.
virtual int GetTopAreaHeight() const = 0; virtual int GetTopAreaHeight() const = 0;
......
...@@ -49,7 +49,6 @@ class TestLayoutDelegate : public OpaqueBrowserFrameViewLayoutDelegate { ...@@ -49,7 +49,6 @@ class TestLayoutDelegate : public OpaqueBrowserFrameViewLayoutDelegate {
void set_maximized(bool maximized) { maximized_ = maximized; } void set_maximized(bool maximized) { maximized_ = maximized; }
// OpaqueBrowserFrameViewLayoutDelegate: // OpaqueBrowserFrameViewLayoutDelegate:
bool IsIncognito() const override { return false; }
bool ShouldShowWindowIcon() const override { return !window_title_.empty(); } bool ShouldShowWindowIcon() const override { return !window_title_.empty(); }
bool ShouldShowWindowTitle() const override { return !window_title_.empty(); } bool ShouldShowWindowTitle() const override { return !window_title_.empty(); }
base::string16 GetWindowTitle() const override { return window_title_; } base::string16 GetWindowTitle() const override { return window_title_; }
...@@ -75,6 +74,9 @@ class TestLayoutDelegate : public OpaqueBrowserFrameViewLayoutDelegate { ...@@ -75,6 +74,9 @@ class TestLayoutDelegate : public OpaqueBrowserFrameViewLayoutDelegate {
gfx::Size GetTabstripPreferredSize() const override { gfx::Size GetTabstripPreferredSize() const override {
return IsTabStripVisible() ? gfx::Size(78, 29) : gfx::Size(); return IsTabStripVisible() ? gfx::Size(78, 29) : gfx::Size();
} }
gfx::Size GetNewTabButtonPreferredSize() const override {
return gfx::Size(28, 28);
}
int GetTopAreaHeight() const override { return 0; } int GetTopAreaHeight() const override { return 0; }
bool UseCustomFrame() const override { return true; } bool UseCustomFrame() const override { return true; }
...@@ -245,8 +247,7 @@ class OpaqueBrowserFrameViewLayoutTest : public ChromeViewsTestBase { ...@@ -245,8 +247,7 @@ class OpaqueBrowserFrameViewLayoutTest : public ChromeViewsTestBase {
caption_buttons_width += caption_buttons_width +=
avatar_button_->GetPreferredSize().width() + avatar_button_->GetPreferredSize().width() +
(maximized ? OpaqueBrowserFrameViewLayout::kCaptionSpacing (maximized ? OpaqueBrowserFrameViewLayout::kCaptionSpacing
: -GetLayoutSize(NEW_TAB_BUTTON, delegate_->IsIncognito()) : -delegate_->GetNewTabButtonPreferredSize().width());
.width());
} }
int tabstrip_x = OpaqueBrowserFrameView::GetAvatarIconPadding(); int tabstrip_x = OpaqueBrowserFrameView::GetAvatarIconPadding();
if (show_caption_buttons && caption_buttons_on_left) { if (show_caption_buttons && caption_buttons_on_left) {
......
...@@ -48,6 +48,13 @@ namespace { ...@@ -48,6 +48,13 @@ namespace {
constexpr int kDistanceBetweenIcons = 6; constexpr int kDistanceBetweenIcons = 6;
constexpr int kStrokeThickness = 1; constexpr int kStrokeThickness = 1;
// Returns the size of the button without any spacing/padding.
gfx::Size GetButtonSize(bool is_incognito) {
const gfx::Size sizes[] = {
{36, 18}, {39, 21}, {(is_incognito ? 42 : 24), 24}, {28, 28}, {28, 28}};
return sizes[MD::GetMode()];
}
sk_sp<SkDrawLooper> CreateShadowDrawLooper(SkColor color) { sk_sp<SkDrawLooper> CreateShadowDrawLooper(SkColor color) {
SkLayerDrawLooper::Builder looper_builder; SkLayerDrawLooper::Builder looper_builder;
looper_builder.addLayer(); looper_builder.addLayer();
...@@ -108,10 +115,9 @@ NewTabButton::NewTabButton(TabStrip* tab_strip, views::ButtonListener* listener) ...@@ -108,10 +115,9 @@ NewTabButton::NewTabButton(TabStrip* tab_strip, views::ButtonListener* listener)
// In newer material UI, the button is placed vertically exactly in the // In newer material UI, the button is placed vertically exactly in the
// center of the tabstrip. In older UI, the new tab button is placed at a // center of the tabstrip. In older UI, the new tab button is placed at a
// fixed distance from the bottom of the tabstrip. // fixed distance from the bottom of the tabstrip.
const int extra_vertical_space = const int extra_vertical_space = GetLayoutConstant(TAB_HEIGHT) -
GetLayoutConstant(TAB_HEIGHT) - GetLayoutConstant(TABSTRIP_TOOLBAR_OVERLAP) -
GetLayoutConstant(TABSTRIP_TOOLBAR_OVERLAP) - GetButtonSize(is_incognito_).height();
GetLayoutSize(NEW_TAB_BUTTON, is_incognito_).height();
constexpr int kNewTabButtonBottomOffset = 4; constexpr int kNewTabButtonBottomOffset = 4;
const int top = MD::IsNewerMaterialUi() const int top = MD::IsNewerMaterialUi()
? (extra_vertical_space / 2) ? (extra_vertical_space / 2)
...@@ -353,7 +359,7 @@ void NewTabButton::OnThemeChanged() { ...@@ -353,7 +359,7 @@ void NewTabButton::OnThemeChanged() {
} }
gfx::Size NewTabButton::CalculatePreferredSize() const { gfx::Size NewTabButton::CalculatePreferredSize() const {
gfx::Size size = GetLayoutSize(NEW_TAB_BUTTON, is_incognito_); gfx::Size size = GetButtonSize(is_incognito_);
const auto insets = GetInsets(); const auto insets = GetInsets();
size.Enlarge(insets.width(), insets.height()); size.Enlarge(insets.width(), insets.height());
return size; return size;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment