-
Notifications
You must be signed in to change notification settings - Fork 15.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable customizing symbolColor
- Loading branch information
1 parent
b0230d2
commit 056e89a
Showing
6 changed files
with
105 additions
and
14 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
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
80 changes: 80 additions & 0 deletions
80
patches/chromium/feat_enable_customizing_symbol_color_in_framecaptionbutton.patch
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,80 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Shelley Vohr <shelley.vohr@gmail.com> | ||
Date: Fri, 5 Apr 2024 11:07:22 +0200 | ||
Subject: feat: enable customizing symbol color in FrameCaptionButton | ||
|
||
This enables customizing the symbol color on a given FrameCaptionButton | ||
for the Window Controls Overlay API on Linux. By default, the symbol color | ||
is dynamically calculated based on the background color of the button to | ||
ensure it has minimum contrast required to be accessible. | ||
|
||
This should be upstreamed to Chromium if possible. | ||
|
||
diff --git a/ui/views/window/frame_caption_button.cc b/ui/views/window/frame_caption_button.cc | ||
index 73e6020e3b9b6e0d12a8dea991f189b3ddeab14c..b38e5bd1408c26cbbfc995fc2ac5dc5983cc0db7 100644 | ||
--- a/ui/views/window/frame_caption_button.cc | ||
+++ b/ui/views/window/frame_caption_button.cc | ||
@@ -107,7 +107,7 @@ FrameCaptionButton::FrameCaptionButton(PressedCallback callback, | ||
FrameCaptionButton::~FrameCaptionButton() = default; | ||
|
||
// static | ||
-SkColor FrameCaptionButton::GetButtonColor(SkColor background_color) { | ||
+SkColor FrameCaptionButton::GetAccessibleButtonColor(SkColor background_color) { | ||
// Use IsDark() to change target colors instead of PickContrastingColor(), so | ||
// that DefaultFrameHeader::GetTitleColor() (which uses different target | ||
// colors) can change between light/dark targets at the same time. It looks | ||
@@ -124,6 +124,22 @@ SkColor FrameCaptionButton::GetButtonColor(SkColor background_color) { | ||
.color; | ||
} | ||
|
||
+SkColor FrameCaptionButton::GetButtonColor(SkColor background_color) { | ||
+ // If the button color has been overridden, return that. | ||
+ if (button_color_ != SkColor()) | ||
+ return button_color_; | ||
+ | ||
+ return GetAccessibleButtonColor(background_color); | ||
+} | ||
+ | ||
+void FrameCaptionButton::SetButtonColor(SkColor button_color) { | ||
+ if (button_color_ == button_color) | ||
+ return; | ||
+ | ||
+ button_color_ = button_color; | ||
+ MaybeRefreshIconAndInkdropBaseColor(); | ||
+} | ||
+ | ||
// static | ||
float FrameCaptionButton::GetInactiveButtonColorAlphaRatio() { | ||
return 0.38f; | ||
diff --git a/ui/views/window/frame_caption_button.h b/ui/views/window/frame_caption_button.h | ||
index 0d20ec5891d08187b4dae7a6b46a9a6de2f7c39c..eb396811a39c4e6021916dbba1f89baa83d77d31 100644 | ||
--- a/ui/views/window/frame_caption_button.h | ||
+++ b/ui/views/window/frame_caption_button.h | ||
@@ -43,8 +43,18 @@ class VIEWS_EXPORT FrameCaptionButton : public Button { | ||
FrameCaptionButton& operator=(const FrameCaptionButton&) = delete; | ||
~FrameCaptionButton() override; | ||
|
||
+ // Gets the color to use for a frame caption button with accessible contrast | ||
+ // to the given background color. | ||
+ static SkColor GetAccessibleButtonColor(SkColor background_color); | ||
+ | ||
// Gets the color to use for a frame caption button. | ||
- static SkColor GetButtonColor(SkColor background_color); | ||
+ SkColor GetButtonColor(SkColor background_color); | ||
+ | ||
+ // Sets the color to use for a frame caption button. | ||
+ // The color is by default calculated to be an accessible contrast | ||
+ // to the background color, so you should keep that in mind when | ||
+ // overriding that behavior. | ||
+ void SetButtonColor(SkColor button_color); | ||
|
||
// Gets the alpha ratio for the colors of inactive frame caption buttons. | ||
static float GetInactiveButtonColorAlphaRatio(); | ||
@@ -133,6 +143,7 @@ class VIEWS_EXPORT FrameCaptionButton : public Button { | ||
// TODO(b/292154873): Store the foreground color instead of the background | ||
// color for the SkColor type. | ||
absl::variant<ui::ColorId, SkColor> color_ = gfx::kPlaceholderColor; | ||
+ SkColor button_color_ = SkColor(); | ||
|
||
// Whether the button should be painted as active. | ||
bool paint_as_active_ = false; |
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