Skip to content

Commit

Permalink
Merge pull request #6900 from brave/tab_contrast
Browse files Browse the repository at this point in the history
Increase contrast between active and inactive tabs
  • Loading branch information
simonhong authored Oct 21, 2020
2 parents 119bd75 + 68527dc commit 4b9ac7c
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 4 deletions.
2 changes: 2 additions & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ source_set("ui") {
"views/tabs/brave_browser_tab_strip_controller.h",
"views/tabs/brave_tab_context_menu_contents.cc",
"views/tabs/brave_tab_context_menu_contents.h",
"views/tabs/brave_tab_strip.cc",
"views/tabs/brave_tab_strip.h",
"views/toolbar/bookmark_button.cc",
"views/toolbar/bookmark_button.h",
]
Expand Down
47 changes: 47 additions & 0 deletions browser/ui/views/tabs/brave_tab_strip.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/browser/ui/views/tabs/brave_tab_strip.h"

#include "brave/browser/profiles/profile_util.h"
#include "brave/browser/themes/brave_dark_mode_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/ui/views/tabs/tab.h"
#include "chrome/browser/ui/views/tabs/tab_strip_controller.h"
#include "third_party/skia/include/core/SkColor.h"

BraveTabStrip::~BraveTabStrip() = default;

bool BraveTabStrip::ShouldHideCloseButtonForTab(Tab* tab) const {
bool should_hide = TabStrip::ShouldHideCloseButtonForTab(tab);

// If upstream logic want to hide, follow it.
if (should_hide)
return should_hide;

if (tab->IsActive())
return false;

// Only shows close button on tab when mouse is hovered on tab.
return !tab->mouse_hovered();
}

SkColor BraveTabStrip::GetTabSeparatorColor() const {
Profile* profile = controller()->GetProfile();
if (!brave::IsRegularProfile(profile))
return TabStrip::GetTabSeparatorColor();

// If custom theme is used, follow upstream separator color.
auto* theme_service = ThemeServiceFactory::GetForProfile(profile);
if (theme_service->GetThemeSupplier())
return TabStrip::GetTabSeparatorColor();

bool dark_mode = dark_mode::GetActiveBraveDarkModeType() ==
dark_mode::BraveDarkModeType::BRAVE_DARK_MODE_TYPE_DARK;
return dark_mode ? SkColorSetRGB(0x39, 0x38, 0x38)
: SkColorSetRGB(0xBE, 0xBF, 0xBF);
}
24 changes: 24 additions & 0 deletions browser/ui/views/tabs/brave_tab_strip.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_BROWSER_UI_VIEWS_TABS_BRAVE_TAB_STRIP_H_
#define BRAVE_BROWSER_UI_VIEWS_TABS_BRAVE_TAB_STRIP_H_

#include "chrome/browser/ui/views/tabs/tab_strip.h"

class BraveTabStrip : public TabStrip {
public:
using TabStrip::TabStrip;
~BraveTabStrip() override;
BraveTabStrip(const BraveTabStrip&) = delete;
BraveTabStrip& operator=(const BraveTabStrip&) = delete;

private:
// TabStrip overrides:
bool ShouldHideCloseButtonForTab(Tab* tab) const override;
SkColor GetTabSeparatorColor() const override;
};

#endif // BRAVE_BROWSER_UI_VIEWS_TABS_BRAVE_TAB_STRIP_H_
4 changes: 4 additions & 0 deletions chromium_src/chrome/browser/ui/views/frame/browser_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/browser/ui/views/tabs/brave_browser_tab_strip_controller.h"
#include "brave/browser/ui/views/tabs/brave_tab_strip.h"
#include "brave/browser/ui/views/toolbar/brave_toolbar_view.h"
#include "chrome/browser/ui/views/frame/tab_strip_region_view.h"

#define ToolbarView BraveToolbarView
#define BrowserTabStripController BraveBrowserTabStripController
#define TabStrip BraveTabStrip
#include "../../../../../../../chrome/browser/ui/views/frame/browser_view.cc" // NOLINT
#undef ToolbarView
#undef BrowserTabStripController
#undef TabStrip
58 changes: 58 additions & 0 deletions chromium_src/chrome/browser/ui/views/tabs/tab_style_views.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "chrome/browser/ui/views/tabs/tab_style_views.h"

#define BRAVE_GM2_TAB_STYLE_H protected:
#define CreateForTab CreateForTab_ChromiumImpl
#include "../../../../../../../chrome/browser/ui/views/tabs/tab_style_views.cc"
#undef CreateForTab
#undef BRAVE_GM2_TAB_STYLE_H

namespace {

class BraveGM2TabStyle : public GM2TabStyle {
public:
explicit BraveGM2TabStyle(Tab* tab);
BraveGM2TabStyle(const BraveGM2TabStyle&) = delete;
BraveGM2TabStyle& operator=(const BraveGM2TabStyle&) = delete;

protected:
TabStyle::TabColors CalculateColors() const override;
const gfx::FontList& GetFontList() const override;

private:
gfx::FontList semibold_font_;
};

BraveGM2TabStyle::BraveGM2TabStyle(Tab* tab)
: GM2TabStyle(tab),
semibold_font_(
normal_font_.DeriveWithWeight(gfx::Font::Weight::SEMIBOLD)) {}

TabStyle::TabColors BraveGM2TabStyle::CalculateColors() const {
auto colors = GM2TabStyle::CalculateColors();
const SkColor inactive_non_hovered_fg_color = SkColorSetA(
colors.foreground_color,
gfx::Tween::IntValueBetween(0.7, SK_AlphaTRANSPARENT, SK_AlphaOPAQUE));
const SkColor final_fg_color = (tab_->IsActive() || tab_->mouse_hovered())
? colors.foreground_color
: inactive_non_hovered_fg_color;
return {final_fg_color, colors.background_color};
}

const gfx::FontList& BraveGM2TabStyle::GetFontList() const {
const auto& font_list = GM2TabStyle::GetFontList();
if (&font_list == &normal_font_ && tab_->IsActive()) {
return semibold_font_;
}
return font_list;
}

} // namespace

std::unique_ptr<TabStyleViews> TabStyleViews::CreateForTab(Tab* tab) {
return std::make_unique<BraveGM2TabStyle>(tab);
}
15 changes: 15 additions & 0 deletions chromium_src/chrome/browser/ui/views/tabs/tab_style_views.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_TABS_TAB_STYLE_VIEWS_H_
#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_TABS_TAB_STYLE_VIEWS_H_

#define CreateForTab CreateForTab_ChromiumImpl(Tab* tab); \
static std::unique_ptr<TabStyleViews> CreateForTab

#include "../../../../../../../chrome/browser/ui/views/tabs/tab_style_views.h"
#undef CreateForTab

#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_TABS_TAB_STYLE_VIEWS_H_
16 changes: 12 additions & 4 deletions patches/chrome-browser-ui-views-tabs-tab_style_views.cc.patch
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
diff --git a/chrome/browser/ui/views/tabs/tab_style_views.cc b/chrome/browser/ui/views/tabs/tab_style_views.cc
index 950c967b5f87a6e3f531e3155a420002a7510d3a..a9b5b74a1a5c345727c1deb631fce7fcbb2762dc 100644
index 950c967b5f87a6e3f531e3155a420002a7510d3a..5e139df9f2061712ec7ed890dc493d5e27a32691 100644
--- a/chrome/browser/ui/views/tabs/tab_style_views.cc
+++ b/chrome/browser/ui/views/tabs/tab_style_views.cc
@@ -280,6 +280,7 @@ SkPath GM2TabStyle::GetPath(PathType path_type,
@@ -66,6 +66,7 @@ class GM2TabStyle : public TabStyleViews {
void HideHover(HideHoverStyle style) override;

private:
+ BRAVE_GM2_TAB_STYLE_H
// Gets the bounds for the leading and trailing separators for a tab.
SeparatorBounds GetSeparatorBounds(float scale) const;

@@ -280,6 +281,7 @@ SkPath GM2TabStyle::GetPath(PathType path_type,
const ShapeModifier shape_modifier = GetShapeModifier(path_type);
const bool extend_left_to_bottom = shape_modifier & kNoLowerLeftArc;
const bool extend_right_to_bottom = shape_modifier & kNoLowerRightArc;
+ bottom_radius = 0;

SkPath path;

@@ -533,7 +534,7 @@ TabStyle::SeparatorBounds GM2TabStyle::GetSeparatorBounds(float scale) const {
@@ -533,7 +535,7 @@ TabStyle::SeparatorBounds GM2TabStyle::GetSeparatorBounds(float scale) const {
separator_bounds.leading =
gfx::RectF(aligned_bounds.x() + corner_radius,
aligned_bounds.y() +
Expand All @@ -19,7 +27,7 @@ index 950c967b5f87a6e3f531e3155a420002a7510d3a..a9b5b74a1a5c345727c1deb631fce7fc
separator_size.width(), separator_size.height());

separator_bounds.trailing = separator_bounds.leading;
@@ -888,12 +889,16 @@ void GM2TabStyle::PaintSeparators(gfx::Canvas* canvas) const {
@@ -888,12 +890,16 @@ void GM2TabStyle::PaintSeparators(gfx::Canvas* canvas) const {
SK_AlphaOPAQUE));
};

Expand Down

0 comments on commit 4b9ac7c

Please sign in to comment.