fix: background hover contrast for WCO buttons (#48596)

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
trop[bot] 2025-10-21 07:26:57 +02:00 committed by GitHub
commit 80b1defd81
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 20 additions and 17 deletions

View file

@ -11,6 +11,7 @@
#include "base/i18n/rtl.h"
#include "base/numerics/safe_conversions.h"
#include "base/win/windows_version.h"
#include "chrome/browser/ui/color/chrome_color_id.h"
#include "chrome/grit/theme_resources.h"
#include "shell/browser/native_window_views.h"
#include "shell/browser/ui/views/win_frame_view.h"
@ -47,6 +48,13 @@ std::unique_ptr<WinIconPainter> WinCaptionButton::CreateIconPainter() {
return std::make_unique<WinIconPainter>();
}
SkColor WinCaptionButton::GetBaseForegroundColor() const {
return GetColorProvider()->GetColor(
frame_view_->GetShouldPaintAsActive()
? kColorCaptionButtonForegroundActive
: kColorCaptionButtonForegroundInactive);
}
gfx::Size WinCaptionButton::CalculatePreferredSize(
const views::SizeBounds& available_size) const {
// TODO(bsep): The sizes in this function are for 1x device scale and don't
@ -76,7 +84,7 @@ void WinCaptionButton::OnPaintBackground(gfx::Canvas* canvas) {
pressed_alpha = 0x98;
} else {
// Match the native buttons.
base_color = frame_view_->GetReadableFeatureColor(bg_color);
base_color = GetBaseForegroundColor();
hovered_alpha = 0x1A;
pressed_alpha = 0x33;

View file

@ -49,6 +49,10 @@ class WinCaptionButton : public views::Button {
private:
std::unique_ptr<WinIconPainter> CreateIconPainter();
// The base color to use for the button symbols and background blending. Uses
// the more readable of black and white.
SkColor GetBaseForegroundColor() const;
// Returns the amount we should visually reserve on the left (right in RTL)
// for spacing between buttons. We do this instead of repositioning the
// buttons to avoid the sliver of deadspace that would result.
@ -59,10 +63,6 @@ class WinCaptionButton : public views::Button {
// smaller indices).
int GetButtonDisplayOrderIndex() const;
// The base color to use for the button symbols and background blending. Uses
// the more readable of black and white.
SkColor GetBaseColor() const;
// Paints the minimize/maximize/restore/close icon for the button.
void PaintSymbol(gfx::Canvas* canvas);

View file

@ -39,18 +39,6 @@ void WinFrameView::Init(NativeWindowViews* window, views::Widget* frame) {
}
}
SkColor WinFrameView::GetReadableFeatureColor(SkColor background_color) {
// color_utils::GetColorWithMaxContrast()/IsDark() aren't used here because
// they switch based on the Chrome light/dark endpoints, while we want to use
// the system native behavior below.
const auto windows_luma = [](SkColor c) {
return 0.25f * SkColorGetR(c) + 0.625f * SkColorGetG(c) +
0.125f * SkColorGetB(c);
};
return windows_luma(background_color) <= 128.0f ? SK_ColorWHITE
: SK_ColorBLACK;
}
void WinFrameView::InvalidateCaptionButtons() {
if (!caption_button_container_)
return;
@ -282,6 +270,10 @@ void WinFrameView::LayoutWindowControlsOverlay() {
window()->NotifyLayoutWindowControlsOverlay();
}
bool WinFrameView::GetShouldPaintAsActive() {
return ShouldPaintAsActive();
}
BEGIN_METADATA(WinFrameView)
END_METADATA

View file

@ -46,6 +46,9 @@ class WinFrameView : public FramelessView {
// the area above the top of the screen).
int TitlebarMaximizedVisualHeight() const;
// Returns true if the frame should be painted as active.
bool GetShouldPaintAsActive();
protected:
// views::View:
void Layout(PassKey) override;