-
Notifications
You must be signed in to change notification settings - Fork 901
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Address brave/brave-browser#962
- Loading branch information
Showing
7 changed files
with
158 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* 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.h" | ||
|
||
#include "chrome/browser/ui/views/tabs/tab_controller.h" | ||
#include "ui/gfx/canvas.h" | ||
#include "ui/gfx/scoped_canvas.h" | ||
|
||
using namespace chrome_browser_ui_views_tabs_tab_cc; | ||
|
||
// Same as Chomium Tab implementation except separators are | ||
// achored to bottom (instead of floating in middle) and rounded ends | ||
void BraveTab::PaintSeparators(gfx::Canvas* canvas) { | ||
const auto separator_opacities = GetSeparatorOpacities(false); | ||
if (!separator_opacities.left && !separator_opacities.right) | ||
return; | ||
|
||
gfx::ScopedCanvas scoped_canvas(canvas); | ||
const float scale = canvas->UndoDeviceScaleFactor(); | ||
|
||
const gfx::RectF aligned_bounds = | ||
ScaleAndAlignBounds(bounds(), scale, GetStrokeThickness()); | ||
const int corner_radius = GetCornerRadius(); | ||
const float separator_height = GetTabSeparatorHeight() * scale; | ||
gfx::RectF leading_separator_bounds( | ||
aligned_bounds.x() + corner_radius * scale, | ||
aligned_bounds.y() + aligned_bounds.height() - separator_height, | ||
kSeparatorThickness * scale, separator_height); | ||
gfx::RectF trailing_separator_bounds = leading_separator_bounds; | ||
trailing_separator_bounds.set_x( | ||
aligned_bounds.right() - (corner_radius + kSeparatorThickness) * scale); | ||
|
||
gfx::PointF origin(bounds().origin()); | ||
origin.Scale(scale); | ||
leading_separator_bounds.Offset(-origin.x(), -origin.y()); | ||
trailing_separator_bounds.Offset(-origin.x(), -origin.y()); | ||
|
||
const SkColor separator_base_color = controller_->GetTabSeparatorColor(); | ||
const auto separator_color = [separator_base_color](float opacity) { | ||
return SkColorSetA(separator_base_color, | ||
gfx::Tween::IntValueBetween(opacity, SK_AlphaTRANSPARENT, | ||
SK_AlphaOPAQUE)); | ||
}; | ||
const int separator_radius = kSeparatorThickness / 2; | ||
const SkScalar scaled_separator_radius = SkIntToScalar( | ||
separator_radius * scale); | ||
cc::PaintFlags flags; | ||
flags.setAntiAlias(true); | ||
flags.setColor(separator_color(separator_opacities.left)); | ||
canvas->DrawRoundRect( | ||
leading_separator_bounds, scaled_separator_radius, flags); | ||
flags.setColor(separator_color(separator_opacities.right)); | ||
canvas->DrawRoundRect( | ||
trailing_separator_bounds, scaled_separator_radius, flags); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* 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_H_ | ||
#define BRAVE_BROWSER_UI_VIEWS_TABS_BRAVE_TAB_H_ | ||
|
||
#include "chrome/browser/ui/views/tabs/tab.h" | ||
#include "ui/gfx/geometry/rect.h" | ||
|
||
namespace chrome_browser_ui_views_tabs_tab_cc { | ||
|
||
const gfx::RectF ScaleAndAlignBounds(const gfx::Rect& bounds, | ||
float scale, | ||
float stroke_thickness); | ||
|
||
} | ||
|
||
class BraveTab : public Tab { | ||
public: | ||
using Tab::Tab; | ||
private: | ||
// Paints the separator lines on the left and right edge of the tab if in | ||
// material refresh mode. | ||
void PaintSeparators(gfx::Canvas* canvas) override; | ||
DISALLOW_COPY_AND_ASSIGN(BraveTab); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
#include "brave/browser/ui/views/tabs/brave_new_tab_button.h" | ||
// include brave_tab header so that patch inside tab_strip works | ||
#include "brave/browser/ui/views/tabs/brave_tab.h" | ||
|
||
#define NewTabButton BraveNewTabButton | ||
#include "../../../../../../chrome/browser/ui/views/tabs/tab_strip.cc" | ||
#undef NewTabButton |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
diff --git a/chrome/browser/ui/views/tabs/tab.h b/chrome/browser/ui/views/tabs/tab.h | ||
index 5be5d08990a6133511b9cb16ee660ce17cc907e8..6b55d3e9f733c2fe99ff6cf460def4d12f87b60d 100644 | ||
--- a/chrome/browser/ui/views/tabs/tab.h | ||
+++ b/chrome/browser/ui/views/tabs/tab.h | ||
@@ -56,7 +56,7 @@ class Tab : public gfx::AnimationDelegate, | ||
|
||
// Under refresh, thickness in DIPs of the separator painted on the left and | ||
// right edges of the tab. | ||
- static constexpr int kSeparatorThickness = 1; | ||
+ static constexpr int kSeparatorThickness = 2; | ||
|
||
// When the content's width of the tab shrinks to below this size we should | ||
// hide the close button on inactive tabs. Any smaller and they're too easy | ||
@@ -235,6 +235,7 @@ class Tab : public gfx::AnimationDelegate, | ||
friend class AlertIndicatorButtonTest; | ||
friend class TabTest; | ||
friend class TabStripTest; | ||
+ friend class BraveTab; | ||
FRIEND_TEST_ALL_PREFIXES(TabStripTest, TabCloseButtonVisibilityWhenStacked); | ||
FRIEND_TEST_ALL_PREFIXES(TabStripTest, | ||
TabCloseButtonVisibilityWhenNotStacked); | ||
@@ -284,7 +285,7 @@ class Tab : public gfx::AnimationDelegate, | ||
|
||
// Paints the separator lines on the left and right edge of the tab if in | ||
// material refresh mode. | ||
- void PaintSeparators(gfx::Canvas* canvas); | ||
+ virtual void PaintSeparators(gfx::Canvas* canvas); | ||
|
||
// Computes which icons are visible in the tab. Should be called everytime | ||
// before layout is performed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
diff --git a/chrome/browser/ui/views/tabs/tab_strip.cc b/chrome/browser/ui/views/tabs/tab_strip.cc | ||
index 1f7870f9ec645bd5eb15fc7b0e688bc9e60cb6eb..cbe8b005d8e11fbb00a2515127fcad34a128a3ab 100644 | ||
index 1f7870f9ec645bd5eb15fc7b0e688bc9e60cb6eb..591ebbef63d609b18d997fc8d8bd95f9aaf074be 100644 | ||
--- a/chrome/browser/ui/views/tabs/tab_strip.cc | ||
+++ b/chrome/browser/ui/views/tabs/tab_strip.cc | ||
@@ -446,7 +446,7 @@ void TabStrip::StopAllHighlighting() { | ||
void TabStrip::AddTabAt(int model_index, TabRendererData data, bool is_active) { | ||
const bool was_single_tab_mode = SingleTabMode(); | ||
|
||
- Tab* tab = new Tab(this, animation_container_.get()); | ||
+ Tab* tab = new BraveTab(this, animation_container_.get()); | ||
AddChildView(tab); | ||
const bool pinned = data.pinned; | ||
tab->SetData(std::move(data)); |