Skip to content

Commit

Permalink
Adjust vertical tabs size (#15761)
Browse files Browse the repository at this point in the history
* Make height the same as that of sidebar button

* Make min width the same as that of sidebar button
  * In this case, sub controls' visibility will be as if the tab is
    pinned.
  • Loading branch information
sangwoo108 authored Nov 3, 2022
1 parent ee9b0b3 commit 91ee9e6
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 8 deletions.
9 changes: 4 additions & 5 deletions browser/ui/views/frame/vertical_tab_strip_region_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "brave/browser/ui/tabs/brave_tab_prefs.h"
#include "brave/browser/ui/views/tabs/brave_new_tab_button.h"
#include "brave/browser/ui/views/tabs/brave_tab_search_button.h"
#include "brave/browser/ui/views/tabs/brave_tab_strip_layout_helper.h"
#include "brave/browser/ui/views/tabs/features.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h"
Expand Down Expand Up @@ -44,7 +45,7 @@ class ToggleButton : public views::Button {
// text.
// https://github.com/brave/brave-browser/issues/24717
SetProperty(views::kSkipAccessibilityPaintChecks, true);
SetPreferredSize(gfx::Size{GetIconWidth(), GetIconWidth()});
SetPreferredSize(gfx::Size{tabs::kVerticalTabMinWidth, GetIconWidth()});
}
~ToggleButton() override = default;

Expand All @@ -70,8 +71,7 @@ class ToggleButton : public views::Button {

const int icon_inset = ui::TouchUiController::Get()->touch_ui() ? 10 : 9;
gfx::Rect icon_bounds(gfx::Size(icon_width, height()));
if (expanded)
icon_bounds.set_x(width() - icon_width);
icon_bounds.set_x((width() - icon_width) / 2);
icon_bounds.Inset(gfx::Insets::VH(icon_inset, icon_inset * 1.5));

if (expanded) {
Expand Down Expand Up @@ -432,8 +432,7 @@ gfx::Size VerticalTabStripRegionView::GetPreferredSizeForState(
DCHECK_EQ(state, State::kCollapsed)
<< "If a new state was added, " << __FUNCTION__
<< " should be revisited.";
return {TabStyle::GetPinnedWidth() - TabStyle::GetTabOverlap(),
View::CalculatePreferredSize().height()};
return {tabs::kVerticalTabMinWidth, View::CalculatePreferredSize().height()};
}

BEGIN_METADATA(VerticalTabStripRegionView, views::View)
Expand Down
2 changes: 1 addition & 1 deletion browser/ui/views/sidebar/sidebar_button_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class SidebarButtonView : public views::ImageButton {
public:
METADATA_HEADER(SidebarButtonView);
static const int kSidebarButtonSize = 42;
static constexpr int kSidebarButtonSize = 42;

explicit SidebarButtonView(const std::u16string& accessible_name);
~SidebarButtonView() override;
Expand Down
35 changes: 35 additions & 0 deletions browser/ui/views/tabs/brave_tab.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,38 @@ absl::optional<SkColor> BraveTab::GetGroupColor() const {

return Tab::GetGroupColor();
}

void BraveTab::UpdateIconVisibility() {
Tab::UpdateIconVisibility();
if (IsAtMinWidthForVerticalTabStrip()) {
const bool is_active = IsActive();
center_icon_ = true;
showing_icon_ = !is_active && !showing_alert_indicator_;
showing_close_button_ = is_active;
}
}

void BraveTab::Layout() {
Tab::Layout();
if (IsAtMinWidthForVerticalTabStrip()) {
if (showing_close_button_) {
close_button_->SetX(bounds().CenterPoint().x() -
(close_button_->width() / 2));
close_button_->SetButtonPadding({});
}
}
}

bool BraveTab::ShouldRenderAsNormalTab() const {
if (IsAtMinWidthForVerticalTabStrip()) {
// Returns false to hide title
return false;
}

return Tab::ShouldRenderAsNormalTab();
}

bool BraveTab::IsAtMinWidthForVerticalTabStrip() const {
return tabs::features::ShouldShowVerticalTabs(controller()->GetBrowser()) &&
width() == tabs::kVerticalTabMinWidth;
}
7 changes: 7 additions & 0 deletions browser/ui/views/tabs/brave_tab.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ class BraveTab : public Tab {
void ActiveStateChanged() override;

absl::optional<SkColor> GetGroupColor() const override;

void UpdateIconVisibility() override;
bool ShouldRenderAsNormalTab() const override;
void Layout() override;

private:
bool IsAtMinWidthForVerticalTabStrip() const;
};

#endif // BRAVE_BROWSER_UI_VIEWS_TABS_BRAVE_TAB_H_
4 changes: 2 additions & 2 deletions browser/ui/views/tabs/brave_tab_strip_layout_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ std::vector<gfx::Rect> CalculateVerticalTabBounds(
? BraveTabGroupHeader::GetLeftPaddingForVerticalTabs()
: 0);
rect.set_width(width.value_or(tabs.front().GetPreferredWidth()) - rect.x());
rect.set_height(
tab.state().open() == TabOpen::kOpen ? layout_constants.tab_height : 0);
rect.set_height(tab.state().open() == TabOpen::kOpen ? kVerticalTabHeight
: 0);
bounds.push_back(rect);
if (tab.state().open() == TabOpen::kOpen)
rect.set_y(rect.bottom());
Expand Down
4 changes: 4 additions & 0 deletions browser/ui/views/tabs/brave_tab_strip_layout_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <vector>

#include "brave/browser/ui/views/sidebar/sidebar_item_view.h"
#include "third_party/abseil-cpp/absl/types/optional.h"

namespace gfx {
Expand All @@ -21,6 +22,9 @@ struct TabLayoutConstants;

namespace tabs {

constexpr int kVerticalTabMinWidth = SidebarButtonView::kSidebarButtonSize;
constexpr int kVerticalTabHeight = SidebarButtonView::kSidebarButtonSize;

std::vector<gfx::Rect> CalculateVerticalTabBounds(
const TabLayoutConstants& layout_constants,
const std::vector<TabWidthConstraints>& tabs,
Expand Down
6 changes: 6 additions & 0 deletions chromium_src/chrome/browser/ui/views/tabs/tab.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ class BraveTab;

#define ActiveStateChanged virtual ActiveStateChanged
#define GetGroupColor virtual GetGroupColor
#define UpdateIconVisibility virtual UpdateIconVisibility
#define ShouldRenderAsNormalTab virtual ShouldRenderAsNormalTab

#include "src/chrome/browser/ui/views/tabs/tab.h"

#undef ShouldRenderAsNormalTab
#undef UpdateIconVisibility
#undef GetGroupColor
#undef ActiveStateChanged
#undef GetWidthOfLargestSelectableRegion
Expand Down

0 comments on commit 91ee9e6

Please sign in to comment.