Skip to content

Commit

Permalink
Reduce number of patches in tab_style_views.cc
Browse files Browse the repository at this point in the history
  • Loading branch information
mkarolin committed Oct 20, 2020
1 parent 568b73e commit 4c19f3e
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 52 deletions.
68 changes: 47 additions & 21 deletions chromium_src/chrome/browser/ui/views/tabs/tab_style_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,56 @@
* 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/. */

#define BRAVE_GM2_TAB_STYLE_H \
private: \
#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 GM2TabStyle&) = delete;
BraveGM2TabStyle& operator=(const BraveGM2TabStyle&) = delete;

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

private:
gfx::FontList semibold_font_;
};

#define BRAVE_GM2_TAB_STYLE \
semibold_font_ = normal_font_.DeriveWithWeight(gfx::Font::Weight::SEMIBOLD);
BraveGM2TabStyle::BraveGM2TabStyle(Tab* tab)
: GM2TabStyle(tab),
semibold_font_(
normal_font_.DeriveWithWeight(gfx::Font::Weight::SEMIBOLD)) {}

#define BRAVE_CALCULATE_COLORS \
const SkColor inactive_non_hovered_fg_color = \
SkColorSetA(foreground_color, \
gfx::Tween::IntValueBetween(0.7, \
SK_AlphaTRANSPARENT, \
SK_AlphaOPAQUE)); \
const SkColor final_fg_color = \
(tab_->IsActive() || tab_->mouse_hovered()) ? \
foreground_color : inactive_non_hovered_fg_color; \
return { final_fg_color, background_color};
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};
}

#define BRAVE_GET_FONT_LIST \
return tab_->IsActive() ? semibold_font_ : normal_font_;
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;
}

#include "../../../../../../../chrome/browser/ui/views/tabs/tab_style_views.cc"
} // namespace

#undef BRAVE_GM2_TAB_STYLE_H
#undef BRAVE_GM2_TAB_STYLE
#undef BRAVE_CALCULATE_COLORS
#undef BRAVE_GET_FONT_LIST
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_
38 changes: 7 additions & 31 deletions patches/chrome-browser-ui-views-tabs-tab_style_views.cc.patch
Original file line number Diff line number Diff line change
@@ -1,48 +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..d488846079f3d0521bd9d1bbe6ffeae158c3393b 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
@@ -65,6 +65,7 @@ class GM2TabStyle : public TabStyleViews {
void ShowHover(ShowHoverStyle style) override;
@@ -66,6 +66,7 @@ class GM2TabStyle : public TabStyleViews {
void HideHover(HideHoverStyle style) override;

+ BRAVE_GM2_TAB_STYLE_H
private:
+ BRAVE_GM2_TAB_STYLE_H
// Gets the bounds for the leading and trailing separators for a tab.
SeparatorBounds GetSeparatorBounds(float scale) const;
@@ -191,6 +192,7 @@ GM2TabStyle::GM2TabStyle(Tab* tab)
views::style::STYLE_PRIMARY)),
heavy_font_(views::style::GetFont(views::style::CONTEXT_BUTTON_MD,
views::style::STYLE_PRIMARY)) {
+ BRAVE_GM2_TAB_STYLE
// TODO(dfried): create a new STYLE_PROMINENT or similar to use instead of
// repurposing CONTEXT_BUTTON_MD.
}
@@ -280,6 +282,7 @@ SkPath GM2TabStyle::GetPath(PathType path_type,

@@ -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;

@@ -459,6 +462,7 @@ TabStyle::TabColors GM2TabStyle::CalculateColors() const {
expected_opacity > 0.5f ? TabActive::kActive : TabActive::kInactive,
background_color);

+ BRAVE_CALCULATE_COLORS
return {foreground_color, background_color};
}

@@ -472,6 +476,7 @@ const gfx::FontList& GM2TabStyle::GetFontList() const {
return heavy_font_;
}

+ BRAVE_GET_FONT_LIST
return normal_font_;
}

@@ -533,7 +538,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 @@ -51,7 +27,7 @@ index 950c967b5f87a6e3f531e3155a420002a7510d3a..d488846079f3d0521bd9d1bbe6ffeae1
separator_size.width(), separator_size.height());

separator_bounds.trailing = separator_bounds.leading;
@@ -888,12 +893,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 4c19f3e

Please sign in to comment.