Skip to content

Commit

Permalink
re-add tab patches
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex313031 committed Jun 1, 2023
1 parent e53c152 commit 17a3074
Show file tree
Hide file tree
Showing 5 changed files with 3,517 additions and 1 deletion.
8 changes: 7 additions & 1 deletion infra/PATCHES.md
Expand Up @@ -101,9 +101,15 @@ Always Show Component Extensions Patch > https://github.com/iridium-browser/irid

Increase default key length for newly-generated RSA keys from 1024 to 2048 Patch > https://github.com/iridium-browser/iridium-browser/commit/d016769081706d591188b5b2929c5fc2efd8ef20

Enable UI Features: Side Search, Side Panel Journeys, Chrome Labs, Extensions Access Menu, Tab Hover Cards, Tab Outlines in Low Contrast Themes, More Prominent Active Tab Title in Dark Mode, WebUI Tab Strip, Drag and Drop Tabs on Wayland, Tab Groups Saving > https://github.com/Alex313031/Thorium/blob/main/chrome/browser/ui/ui_features.cc
Enable UI Features: Side Search, Side Panel Journeys, Chrome Labs, Extensions Access Menu, Tab Hover Cards, WebUI Tab Strip, Drag and Drop Tabs on Wayland, Tab Groups Saving > https://github.com/Alex313031/Thorium/blob/main/chrome/browser/ui/ui_features.cc
- Made by me.

Tab Outlines in Low Contrast Themes, More Prominent Active Tab Title in Dark Mode: Restore after they removed it in M113 >
https://chromium-review.googlesource.com/c/chromium/src/+/4578380 \
https://chromium-review.googlesource.com/c/chromium/src/+/4578188 \

- Made by me.

Enable Precompiling of Inline Scripts in HTML - https://github.com/Alex313031/thorium/commit/8d237b76adff2ab4e89147b18ee1d0ab7bb29fb6
- Modified by me.

Expand Down
201 changes: 201 additions & 0 deletions src/chrome/browser/ui/tabs/tab_style.h
@@ -0,0 +1,201 @@
// Copyright 2023 The Chromium Authors, Alex313031
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_TABS_TAB_STYLE_H_
#define CHROME_BROWSER_UI_TABS_TAB_STYLE_H_

#include <tuple>

#include "chrome/browser/ui/color/chrome_color_id.h"
#include "chrome/browser/ui/tabs/tab_types.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/color/color_id.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/font_list.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/size.h"

namespace gfx {
class Canvas;
}

class SkPath;

// Holds the basic logic for rendering tabs, including preferred sizes, paths,
// etc.
class TabStyle {
public:
// The different types of path GetPath() can return. Different paths are used
// in different situations, but most (excluding |kClip|) are roughly the same
// shape.
enum class PathType {
// Interior fill outline. Extends halfway into the border so there are no
// gaps between border and fill.
kFill,
// Center of the border path. The path is guaranteed to fit into the tab
// bounds, including the stroke thickness.
kBorder,
// The hit test region. May be extended into a rectangle that touches the
// top of the bounding box when the window is maximized, for Fitts' Law.
kHitTest,
// The area inside the tab where children can be rendered, used to clip
// child views. Does not have to be the same shape as the border.
kInteriorClip,
// The path used for focus rings.
kHighlight,
};

// How we want the resulting path scaled.
enum class RenderUnits {
// The path is in pixels, and should have its internal area nicely aligned
// to pixel boundaries.
kPixels,
// The path is in DIPs. It will likely be calculated in pixels and then
// scaled back down.
kDips
};

enum class ShowHoverStyle { kSubtle, kPronounced };

enum class HideHoverStyle {
kGradual, // The hover should fade out.
kImmediate, // The hover should cut off, with no fade out.
};

// If we want to draw vertical separators between tabs, these are the leading
// and trailing separator stroke rectangles.
struct SeparatorBounds {
gfx::RectF leading;
gfx::RectF trailing;
};

// Contains values 0..1 representing the opacity of the corresponding
// separators. These are physical and not logical, so "left" is the left
// separator in both LTR and RTL.
struct SeparatorOpacities {
float left = 0, right = 0;
};

// Colors for various parts of the tab derived by TabStyle.
struct TabColors {
SkColor foreground_color = gfx::kPlaceholderColor;
SkColor background_color = gfx::kPlaceholderColor;
ui::ColorId focus_ring_color = kColorTabFocusRingInactive;
ui::ColorId close_button_focus_ring_color =
kColorTabCloseButtonFocusRingInactive;

TabColors() = default;
TabColors(SkColor foreground_color,
SkColor background_color,
ui::ColorId focus_ring_color,
ui::ColorId close_button_focus_ring_color)
: foreground_color(foreground_color),
background_color(background_color),
focus_ring_color(focus_ring_color),
close_button_focus_ring_color(close_button_focus_ring_color) {}
bool operator==(const TabColors& other) const {
return std::tie(foreground_color, background_color, focus_ring_color,
close_button_focus_ring_color) ==
std::tie(other.foreground_color, other.background_color,
other.focus_ring_color,
other.close_button_focus_ring_color);
}
};

TabStyle(const TabStyle&) = delete;
TabStyle& operator=(const TabStyle&) = delete;
virtual ~TabStyle();

// Gets the specific |path_type| associated with the specific |tab|.
// If |force_active| is true, applies an active appearance on the tab (usually
// involving painting an optional stroke) even if the tab is not the active
// tab.
virtual SkPath GetPath(
PathType path_type,
float scale,
bool force_active = false,
RenderUnits render_units = RenderUnits::kPixels) const = 0;

// Returns the insets to use for laying out tab contents.
virtual gfx::Insets GetContentsInsets() const = 0;

// Returns the z-value of the tab, which should be used to paint them in
// ascending order. Return values are in the range (0,
// TabStyle::GetMaximumZValue()).
virtual float GetZValue() const = 0;

// Returns the current opacity of the "active" portion of the tab's state.
virtual float GetActiveOpacity() const = 0;

// Returns whichever of (active, inactive) the tab appears more like given the
// active opacity.
virtual TabActive GetApparentActiveState() const = 0;

// Derives and returns colors for the tab. See TabColors, above.
virtual TabColors CalculateColors() const = 0;

// Returns the appropriate fonts for the current theme and active state.
virtual const gfx::FontList& GetFontList() const = 0;

// Paints the tab.
virtual void PaintTab(gfx::Canvas* canvas) const = 0;

// Sets the center of the radial highlight in the hover animation.
virtual void SetHoverLocation(const gfx::Point& location) = 0;

// Shows the hover animation.
virtual void ShowHover(ShowHoverStyle style) = 0;

// Hides the hover animation.
virtual void HideHover(HideHoverStyle style) = 0;

// Opacity of the active tab background painted over inactive selected tabs.
static constexpr float kSelectedTabOpacity = 0.75f;

// Returns the preferred width of a single Tab, assuming space is
// available.
static int GetStandardWidth();

// Returns the width for pinned tabs. Pinned tabs always have this width.
static int GetPinnedWidth();

// Returns the overlap between adjacent tabs.
static int GetTabOverlap();

// Get the space only partially occupied by a tab that we should
// consider to be padding rather than part of the body of the tab for
// interaction purposes.
static gfx::Insets GetTabInternalPadding();

// Gets the size of the separator drawn between tabs, if any.
static gfx::Size GetSeparatorSize();

// Returns, for a tab of height |height|, how far the window top drag handle
// can extend down into inactive tabs or the new tab button. This behavior
// is not used in all cases.
static int GetDragHandleExtension(int height);

// Gets the preferred size for tab previews, which could be screencaps, hero
// or og:image images, etc.
static gfx::Size GetPreviewImageSize();

// Returns the radius of the outer corners of the tab shape.
static int GetCornerRadius();

// The largest valid value of TabStyle::GetZValue(). Currently,
// GM2TabStyle::GetZValue is the only implementation, and it can't return
// values larger than 7.
static constexpr float kMaximumZValue = 7.0f;

protected:
// Avoid implicitly-deleted constructor.
TabStyle() = default;

// Returns how far from the leading and trailing edges of a tab the contents
// should actually be laid out.
static int GetContentsHorizontalInsetSize();
};

#endif // CHROME_BROWSER_UI_TABS_TAB_STYLE_H_
2 changes: 2 additions & 0 deletions src/chrome/browser/ui/views/tabs/tab.cc
Expand Up @@ -212,6 +212,7 @@ Tab::Tab(TabSlotController* controller)
title_->SetHandlesTooltips(false);
title_->SetAutoColorReadabilityEnabled(false);
title_->SetText(CoreTabHelper::GetDefaultTitle());
title_->SetFontList(tab_style_->GetFontList());
// |title_| paints on top of an opaque region (the tab background) of a
// non-opaque layer (the tabstrip's layer), which cannot currently be detected
// by the subpixel-rendering opacity check.
Expand Down Expand Up @@ -817,6 +818,7 @@ void Tab::ActiveStateChanged() {
UpdateTabIconNeedsAttentionBlocked();
UpdateForegroundColors();
alert_indicator_button_->OnParentTabButtonColorChanged();
title_->SetFontList(tab_style_->GetFontList());
Layout();
}

Expand Down

0 comments on commit 17a3074

Please sign in to comment.