summaryrefslogtreecommitdiff
path: root/chromium/ui/native_theme
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/ui/native_theme')
-rw-r--r--chromium/ui/native_theme/common_theme.cc6
-rw-r--r--chromium/ui/native_theme/native_theme.cc21
-rw-r--r--chromium/ui/native_theme/native_theme.h52
-rw-r--r--chromium/ui/native_theme/native_theme_aura.cc42
-rw-r--r--chromium/ui/native_theme/native_theme_base.cc79
-rw-r--r--chromium/ui/native_theme/native_theme_base.h18
-rw-r--r--chromium/ui/native_theme/native_theme_color_id.h4
-rw-r--r--chromium/ui/native_theme/native_theme_mac.h60
-rw-r--r--chromium/ui/native_theme/native_theme_mac.mm296
-rw-r--r--chromium/ui/native_theme/native_theme_mac_unittest.cc27
-rw-r--r--chromium/ui/native_theme/native_theme_win.cc17
-rw-r--r--chromium/ui/native_theme/native_theme_win_unittest.cc108
-rw-r--r--chromium/ui/native_theme/themed_vector_icon.cc7
-rw-r--r--chromium/ui/native_theme/themed_vector_icon.h7
14 files changed, 617 insertions, 127 deletions
diff --git a/chromium/ui/native_theme/common_theme.cc b/chromium/ui/native_theme/common_theme.cc
index 5820f4ab68b..e0f4ef443d3 100644
--- a/chromium/ui/native_theme/common_theme.cc
+++ b/chromium/ui/native_theme/common_theme.cc
@@ -431,6 +431,8 @@ SkColor GetDefaultColor(NativeTheme::ColorId color_id,
case NativeTheme::kColorId_NotificationButtonBackground:
return SkColorSetA(SK_ColorWHITE, 0.9 * 0xff);
#endif
+ case NativeTheme::kColorId_NotificationDefaultAccentColor:
+ return gfx::kChromeIconGrey;
// Scrollbar
case NativeTheme::kColorId_OverlayScrollbarThumbBackground:
@@ -573,6 +575,10 @@ SkColor GetDefaultColor(NativeTheme::ColorId color_id,
case NativeTheme::kColorId_MenuIconColor:
case NativeTheme::kColorId_DefaultIconColor:
return gfx::kGoogleGrey700;
+ case NativeTheme::kColorId_DisabledIconColor:
+ return SkColorSetA(
+ base_theme->GetSystemColor(NativeTheme::kColorId_DefaultIconColor),
+ gfx::kDisabledControlAlpha);
// Sync info container
case NativeTheme::kColorId_SyncInfoContainerPaused:
diff --git a/chromium/ui/native_theme/native_theme.cc b/chromium/ui/native_theme/native_theme.cc
index 1d9716fc421..150f4455d49 100644
--- a/chromium/ui/native_theme/native_theme.cc
+++ b/chromium/ui/native_theme/native_theme.cc
@@ -254,20 +254,13 @@ bool NativeTheme::UsesHighContrastColors() const {
return is_high_contrast_;
}
-NativeTheme::HighContrastColorScheme NativeTheme::GetHighContrastColorScheme()
- const {
- if (!UsesHighContrastColors())
- return NativeTheme::HighContrastColorScheme::kNone;
- switch (GetPreferredColorScheme()) {
- case NativeTheme::PreferredColorScheme::kDark:
- return HighContrastColorScheme::kDark;
- case NativeTheme::PreferredColorScheme::kLight:
- return HighContrastColorScheme::kLight;
- case NativeTheme::PreferredColorScheme::kNoPreference:
- return NativeTheme::HighContrastColorScheme::kCustom;
- }
- NOTREACHED();
- return NativeTheme::HighContrastColorScheme::kNone;
+NativeTheme::PlatformHighContrastColorScheme
+NativeTheme::GetPlatformHighContrastColorScheme() const {
+ if (GetDefaultSystemColorScheme() != ColorScheme::kPlatformHighContrast)
+ return PlatformHighContrastColorScheme::kNone;
+ return (GetPreferredColorScheme() == PreferredColorScheme::kDark)
+ ? PlatformHighContrastColorScheme::kDark
+ : PlatformHighContrastColorScheme::kLight;
}
NativeTheme::PreferredColorScheme NativeTheme::GetPreferredColorScheme() const {
diff --git a/chromium/ui/native_theme/native_theme.h b/chromium/ui/native_theme/native_theme.h
index 82751ea52da..f4e9cc14b0b 100644
--- a/chromium/ui/native_theme/native_theme.h
+++ b/chromium/ui/native_theme/native_theme.h
@@ -108,7 +108,6 @@ class NATIVE_THEME_EXPORT NativeTheme {
// OS-level preferred color scheme. (Ex. high contrast or dark mode color
// preference.)
enum PreferredColorScheme {
- kNoPreference,
kDark,
kLight,
kMaxValue = kLight,
@@ -118,14 +117,13 @@ class NATIVE_THEME_EXPORT NativeTheme {
// This enum is reporting in metrics. Do not reorder; add additional values at
// the end.
//
- // This represents the OS-level high contrast theme. kNone if high contrast is
- // not enabled.
- enum class HighContrastColorScheme {
+ // This represents the OS-level high contrast theme. kNone unless the default
+ // system color scheme is kPlatformHighContrast.
+ enum class PlatformHighContrastColorScheme {
kNone = 0,
kDark = 1,
kLight = 2,
- kCustom = 3,
- kMaxValue = kCustom,
+ kMaxValue = kLight,
};
// The color scheme used for painting the native controls.
@@ -251,12 +249,32 @@ class NATIVE_THEME_EXPORT NativeTheme {
ScrollbarOverlayColorTheme scrollbar_theme;
};
+#if defined(OS_MACOSX)
+ enum ScrollbarOrientation {
+ // Vertical scrollbar on the right side of content.
+ kVerticalOnRight,
+ // Vertical scrollbar on the left side of content.
+ kVerticalOnLeft,
+ // Horizontal scrollbar (on the bottom of content).
+ kHorizontal,
+ };
+
+ // A unique set of scrollbar params. Currently needed for Mac.
+ struct ScrollbarExtraParams {
+ bool is_hovering;
+ bool is_overlay;
+ ScrollbarOverlayColorTheme scrollbar_theme;
+ ScrollbarOrientation orientation; // Used on Mac for drawing gradients.
+ };
+#endif
+
struct SliderExtraParams {
bool vertical;
bool in_drag;
int thumb_x;
int thumb_y;
float zoom;
+ bool right_to_left;
};
struct TextFieldExtraParams {
@@ -292,6 +310,9 @@ class NATIVE_THEME_EXPORT NativeTheme {
MenuBackgroundExtraParams menu_background;
ProgressBarExtraParams progress_bar;
ScrollbarArrowExtraParams scrollbar_arrow;
+#if defined(OS_MACOSX)
+ ScrollbarExtraParams scrollbar_extra;
+#endif
ScrollbarTrackExtraParams scrollbar_track;
ScrollbarThumbExtraParams scrollbar_thumb;
SliderExtraParams slider;
@@ -399,9 +420,10 @@ class NATIVE_THEME_EXPORT NativeTheme {
// system accessibility settings and the system theme.
virtual bool UsesHighContrastColors() const;
- // Returns the HighContrastColorScheme used by the OS. Returns kNone if high
- // contrast is not enabled.
- HighContrastColorScheme GetHighContrastColorScheme() const;
+ // Returns the PlatformHighContrastColorScheme used by the OS. Returns a value
+ // other than kNone only if the default system color scheme is
+ // kPlatformHighContrast.
+ PlatformHighContrastColorScheme GetPlatformHighContrastColorScheme() const;
// Returns true when the NativeTheme uses a light-on-dark color scheme. If
// you're considering using this function to choose between two hard-coded
@@ -465,12 +487,9 @@ class NATIVE_THEME_EXPORT NativeTheme {
// Some platforms override this behavior. On Windows, for example, we also
// look at the high contrast setting. If high contrast is enabled, the
// preferred color scheme calculation will ignore the state of dark mode.
- // Instead, preferred color scheme will be light, dark, or no-preference
- // depending on the OS high contrast theme. If high contrast is off, the
- // preferred color scheme calculation will follow the default behavior.
- //
- // Note, if the preferred color scheme is based on dark mode, it will never
- // be set to no-preference.
+ // Instead, preferred color scheme will be light, or dark depending on the OS
+ // high contrast theme. If high contrast is off, the preferred color scheme
+ // calculation will follow the default behavior.
virtual PreferredColorScheme CalculatePreferredColorScheme() const;
// A function to be called by native theme instances that need to set state
@@ -506,8 +525,7 @@ class NATIVE_THEME_EXPORT NativeTheme {
bool should_use_dark_colors_ = false;
bool is_high_contrast_ = false;
- PreferredColorScheme preferred_color_scheme_ =
- PreferredColorScheme::kNoPreference;
+ PreferredColorScheme preferred_color_scheme_ = PreferredColorScheme::kLight;
DISALLOW_COPY_AND_ASSIGN(NativeTheme);
};
diff --git a/chromium/ui/native_theme/native_theme_aura.cc b/chromium/ui/native_theme/native_theme_aura.cc
index c9f858e69e7..ff92427546f 100644
--- a/chromium/ui/native_theme/native_theme_aura.cc
+++ b/chromium/ui/native_theme/native_theme_aura.cc
@@ -40,7 +40,6 @@ constexpr int kOverlayScrollbarMinimumLength = 32;
// color. This prevents color interpolation between the patches.
constexpr int kOverlayScrollbarBorderPatchWidth = 2;
constexpr int kOverlayScrollbarCenterPatchSize = 1;
-const SkColor kTrackColor = SkColorSetRGB(0xF1, 0xF1, 0xF1);
const SkScalar kScrollRadius =
1; // select[multiple] radius+width are set in css
} // namespace
@@ -145,9 +144,7 @@ void NativeThemeAura::PaintArrowButton(
State state,
ColorScheme color_scheme,
const ScrollbarArrowExtraParams& arrow) const {
- SkColor bg_color = color_scheme == ui::NativeTheme::ColorScheme::kDark
- ? SkColorSetRGB(0x42, 0x42, 0x42)
- : kTrackColor;
+ SkColor bg_color = GetControlColor(kScrollbarArrowBackground, color_scheme);
// Aura-win uses slightly different arrow colors.
SkColor arrow_color = gfx::kPlaceholderColor;
switch (state) {
@@ -155,22 +152,17 @@ void NativeThemeAura::PaintArrowButton(
arrow_color = GetArrowColor(state, color_scheme);
break;
case kHovered:
- bg_color = color_scheme == ui::NativeTheme::ColorScheme::kDark
- ? SkColorSetRGB(0x4F, 0x4F, 0x4F)
- : SkColorSetRGB(0xD2, 0xD2, 0xD2);
- FALLTHROUGH;
+ bg_color =
+ GetControlColor(kScrollbarArrowBackgroundHovered, color_scheme);
+ arrow_color = GetControlColor(kScrollbarArrowHovered, color_scheme);
+ break;
case kNormal:
- arrow_color = color_scheme == ui::NativeTheme::ColorScheme::kDark
- ? SK_ColorWHITE
- : SkColorSetRGB(0x50, 0x50, 0x50);
+ arrow_color = GetControlColor(kScrollbarArrow, color_scheme);
break;
case kPressed:
- bg_color = color_scheme == ui::NativeTheme::ColorScheme::kDark
- ? SkColorSetRGB(0xB1, 0xB1, 0xB1)
- : SkColorSetRGB(0x78, 0x78, 0x78);
- arrow_color = color_scheme == ui::NativeTheme::ColorScheme::kDark
- ? SK_ColorBLACK
- : SK_ColorWHITE;
+ bg_color =
+ GetControlColor(kScrollbarArrowBackgroundPressed, color_scheme);
+ arrow_color = GetControlColor(kScrollbarArrowPressed, color_scheme);
break;
case kNumStates:
break;
@@ -220,9 +212,7 @@ void NativeThemeAura::PaintScrollbarTrack(
// Overlay Scrollbar should never paint a scrollbar track.
DCHECK(!use_overlay_scrollbars_);
cc::PaintFlags flags;
- SkColor track_color = color_scheme == ui::NativeTheme::ColorScheme::kDark
- ? SkColorSetRGB(0x42, 0x42, 0x42)
- : kTrackColor;
+ SkColor track_color = GetControlColor(kScrollbarTrack, color_scheme);
flags.setColor(track_color);
canvas->drawIRect(gfx::RectToSkIRect(rect), flags);
}
@@ -300,17 +290,20 @@ void NativeThemeAura::PaintScrollbarThumb(cc::PaintCanvas* canvas,
gfx::Insets fill_insets(kStrokeWidth);
thumb_rect.Inset(fill_insets + edge_adjust_insets);
} else {
+ ControlColorId color_id = kScrollbarThumb;
switch (state) {
case NativeTheme::kDisabled:
thumb_alpha = SK_AlphaTRANSPARENT;
break;
case NativeTheme::kHovered:
+ color_id = kScrollbarThumbHovered;
thumb_alpha = 0x4D;
break;
case NativeTheme::kNormal:
thumb_alpha = 0x33;
break;
case NativeTheme::kPressed:
+ color_id = kScrollbarThumbPressed;
thumb_alpha = 0x80;
break;
case NativeTheme::kNumStates:
@@ -327,9 +320,12 @@ void NativeThemeAura::PaintScrollbarThumb(cc::PaintCanvas* canvas,
else
thumb_rect.Inset(extra_padding, kThumbPadding);
- thumb_color = color_scheme == ui::NativeTheme::ColorScheme::kDark
- ? SK_ColorWHITE
- : SK_ColorBLACK;
+ if (UsesHighContrastColors() && features::IsForcedColorsEnabled()) {
+ thumb_alpha = 0xFF;
+ thumb_color = GetControlColor(color_id, color_scheme);
+ } else {
+ thumb_color = GetControlColor(kScrollbarThumb, color_scheme);
+ }
}
cc::PaintFlags flags;
diff --git a/chromium/ui/native_theme/native_theme_base.cc b/chromium/ui/native_theme/native_theme_base.cc
index d13499976b8..57bd8bf9905 100644
--- a/chromium/ui/native_theme/native_theme_base.cc
+++ b/chromium/ui/native_theme/native_theme_base.cc
@@ -1416,7 +1416,8 @@ SkColor NativeThemeBase::GetArrowColor(State state,
SkColorToHSV(GetColor(kTrackColor, color_scheme), track_hsv);
SkScalar thumb_hsv[3];
- SkColorToHSV(GetColor(kThumbInactiveColor, color_scheme), thumb_hsv);
+ SkColorToHSV(GetControlColor(kScrollbarThumbInactive, color_scheme),
+ thumb_hsv);
return OutlineColor(track_hsv, thumb_hsv);
}
@@ -1619,6 +1620,24 @@ SkColor NativeThemeBase::GetControlColor(ControlColorId color_id,
return SkColorSetRGB(0xCB, 0xCB, 0xCB);
case kAutoCompleteBackground:
return SkColorSetRGB(0xE8, 0xF0, 0xFE);
+ case kScrollbarArrowBackground:
+ case kScrollbarTrack:
+ return SkColorSetRGB(0xF1, 0xF1, 0xF1);
+ case kScrollbarArrowBackgroundHovered:
+ return SkColorSetRGB(0xD2, 0xD2, 0xD2);
+ case kScrollbarArrowBackgroundPressed:
+ return SkColorSetRGB(0x78, 0x78, 0x78);
+ case kScrollbarArrowHovered:
+ case kScrollbarArrow:
+ return SkColorSetRGB(0x50, 0x50, 0x50);
+ case kScrollbarArrowPressed:
+ return SK_ColorWHITE;
+ case kScrollbarThumbInactive:
+ return SkColorSetRGB(0xEA, 0xEA, 0xEA);
+ case kScrollbarThumbHovered:
+ case kScrollbarThumbPressed:
+ case kScrollbarThumb:
+ return SK_ColorBLACK;
}
NOTREACHED();
return gfx::kPlaceholderColor;
@@ -1665,6 +1684,24 @@ SkColor NativeThemeBase::GetDarkModeControlColor(
return SkColorSetRGB(0x45, 0x45, 0x45);
case kDisabledFill:
return SkColorSetARGB(0x4D, 0x3B, 0x3B, 0x3B);
+ case kScrollbarArrowBackground:
+ return SkColorSetRGB(0x42, 0x42, 0x42);
+ case kScrollbarArrowBackgroundHovered:
+ return SkColorSetRGB(0x4F, 0x4F, 0x4F);
+ case kScrollbarArrowBackgroundPressed:
+ return SkColorSetRGB(0xB1, 0xB1, 0xB1);
+ case kScrollbarArrowHovered:
+ case kScrollbarArrow:
+ return SK_ColorWHITE;
+ case kScrollbarArrowPressed:
+ return SK_ColorBLACK;
+ case kScrollbarTrack:
+ return SkColorSetRGB(0x42, 0x42, 0x42);
+ case kScrollbarThumbInactive:
+ case kScrollbarThumbHovered:
+ case kScrollbarThumbPressed:
+ case kScrollbarThumb:
+ return SK_ColorWHITE;
}
NOTREACHED();
return gfx::kPlaceholderColor;
@@ -1690,6 +1727,10 @@ SkColor NativeThemeBase::GetHighContrastControlColor(
case kSlider:
case kHoveredSlider:
case kPressedSlider:
+ case kScrollbarThumbHovered:
+ case kScrollbarThumbPressed:
+ case kScrollbarArrowBackgroundHovered:
+ case kScrollbarArrowBackgroundPressed:
return system_colors_[SystemThemeColor::kHighlight];
case kBackground:
case kDisabledBackground:
@@ -1699,10 +1740,19 @@ SkColor NativeThemeBase::GetHighContrastControlColor(
case kDisabledFill:
case kAutoCompleteBackground:
case kLightenLayer:
+ case kScrollbarArrowBackground:
+ case kScrollbarTrack:
return system_colors_[SystemThemeColor::kWindow];
+ case kScrollbarArrow:
+ case kScrollbarThumb:
+ case kScrollbarThumbInactive:
+ return system_colors_[SystemThemeColor::kWindowText];
+ case kScrollbarArrowHovered:
+ case kScrollbarArrowPressed:
+ return system_colors_[SystemThemeColor::kButtonFace];
}
} else {
- // Default high contrast colors (used in web test mode)
+ // // Default high contrast colors (used in web test mode)
switch (color_id) {
case kDisabledBorder:
case kDisabledAccent:
@@ -1711,6 +1761,9 @@ SkColor NativeThemeBase::GetHighContrastControlColor(
case kBorder:
case kHoveredBorder:
case kPressedBorder:
+ case kScrollbarThumbInactive:
+ case kScrollbarArrowBackground:
+ case kScrollbarTrack:
return SK_ColorWHITE;
case kAccent:
case kHoveredAccent:
@@ -1728,7 +1781,16 @@ SkColor NativeThemeBase::GetHighContrastControlColor(
case kDisabledFill:
case kAutoCompleteBackground:
case kLightenLayer:
+ case kScrollbarThumb:
+ case kScrollbarArrow:
+ case kScrollbarArrowHovered:
+ case kScrollbarArrowPressed:
return SK_ColorBLACK;
+ case kScrollbarThumbHovered:
+ case kScrollbarThumbPressed:
+ case kScrollbarArrowBackgroundHovered:
+ case kScrollbarArrowBackgroundPressed:
+ return SkColorSetRGB(0x1A, 0xEB, 0xFF);
}
}
NOTREACHED();
@@ -1769,11 +1831,16 @@ SkRect NativeThemeBase::AlignSliderTrack(
std::min(float(slider_rect.right()), mid_x + kAlignment),
slider_rect.bottom());
} else {
- const float right = is_value ? slider_rect.x() + slider.thumb_x + kAlignment
- : slider_rect.right();
+ const float right = is_value && !slider.right_to_left
+ ? slider_rect.x() + slider.thumb_x + kAlignment
+ : slider_rect.right();
+ const float left = is_value && slider.right_to_left
+ ? slider_rect.x() + slider.thumb_x + kAlignment
+ : slider_rect.x();
+
aligned_rect.setLTRB(
- slider_rect.x(), std::max(float(slider_rect.y()), mid_y - kAlignment),
- right, std::min(float(slider_rect.bottom()), mid_y + kAlignment));
+ left, std::max(float(slider_rect.y()), mid_y - kAlignment), right,
+ std::min(float(slider_rect.bottom()), mid_y + kAlignment));
}
return aligned_rect;
diff --git a/chromium/ui/native_theme/native_theme_base.h b/chromium/ui/native_theme/native_theme_base.h
index 9cc9c2d8884..ea2989929e4 100644
--- a/chromium/ui/native_theme/native_theme_base.h
+++ b/chromium/ui/native_theme/native_theme_base.h
@@ -65,7 +65,18 @@ class NATIVE_THEME_EXPORT NativeThemeBase : public NativeTheme {
kDisabledSlider,
kHoveredSlider,
kPressedSlider,
- kAutoCompleteBackground
+ kAutoCompleteBackground,
+ kScrollbarArrowBackground,
+ kScrollbarArrowBackgroundHovered,
+ kScrollbarArrowBackgroundPressed,
+ kScrollbarArrow,
+ kScrollbarArrowHovered,
+ kScrollbarArrowPressed,
+ kScrollbarTrack,
+ kScrollbarThumb,
+ kScrollbarThumbHovered,
+ kScrollbarThumbPressed,
+ kScrollbarThumbInactive
};
using NativeTheme::NativeTheme;
@@ -213,6 +224,8 @@ class NATIVE_THEME_EXPORT NativeThemeBase : public NativeTheme {
// Returns the color used to draw the arrow.
SkColor GetArrowColor(State state, ColorScheme color_scheme) const;
+ SkColor GetControlColor(ControlColorId color_id,
+ ColorScheme color_scheme) const;
int scrollbar_width_ = 15;
@@ -260,8 +273,7 @@ class NATIVE_THEME_EXPORT NativeThemeBase : public NativeTheme {
SkColor GetHighContrastControlColor(ControlColorId color_id,
ColorScheme color_scheme) const;
SkColor GetDarkModeControlColor(ControlColorId color_id) const;
- SkColor GetControlColor(ControlColorId color_id,
- ColorScheme color_scheme) const;
+
SkRect AlignSliderTrack(const gfx::Rect& slider_rect,
const NativeTheme::SliderExtraParams& slider,
bool is_value,
diff --git a/chromium/ui/native_theme/native_theme_color_id.h b/chromium/ui/native_theme/native_theme_color_id.h
index 9b3d8039bc2..60fb0ea1010 100644
--- a/chromium/ui/native_theme/native_theme_color_id.h
+++ b/chromium/ui/native_theme/native_theme_color_id.h
@@ -91,6 +91,7 @@
OP(kColorId_NotificationLargeImageBackground), \
OP(kColorId_NotificationPlaceholderIconColor), \
OP(kColorId_NotificationEmptyPlaceholderIconColor), \
+ OP(kColorId_NotificationDefaultAccentColor), \
/* Slider */ \
OP(kColorId_SliderThumbDefault), \
OP(kColorId_SliderTroughDefault), \
@@ -154,7 +155,8 @@
OP(kColorId_AlertSeverityMedium), \
OP(kColorId_AlertSeverityHigh), \
/* Colors for icons in non-menu contexts. */ \
- OP(kColorId_DefaultIconColor)
+ OP(kColorId_DefaultIconColor), \
+ OP(kColorId_DisabledIconColor)
#if defined(OS_CHROMEOS)
#define NATIVE_THEME_CHROMEOS_COLOR_IDS \
diff --git a/chromium/ui/native_theme/native_theme_mac.h b/chromium/ui/native_theme/native_theme_mac.h
index 4804b26ba82..fbaa33f4c9a 100644
--- a/chromium/ui/native_theme/native_theme_mac.h
+++ b/chromium/ui/native_theme/native_theme_mac.h
@@ -8,6 +8,7 @@
#include "base/mac/scoped_nsobject.h"
#include "base/macros.h"
#include "base/no_destructor.h"
+#include "ui/gfx/geometry/size.h"
#include "ui/native_theme/native_theme_base.h"
#include "ui/native_theme/native_theme_export.h"
@@ -44,6 +45,12 @@ class NATIVE_THEME_EXPORT NativeThemeMac : public NativeThemeBase {
SkColor GetSystemButtonPressedColor(SkColor base_color) const override;
// Overridden from NativeThemeBase:
+ void Paint(cc::PaintCanvas* canvas,
+ Part part,
+ State state,
+ const gfx::Rect& rect,
+ const ExtraParams& extra,
+ ColorScheme color_scheme) const override;
void PaintMenuPopupBackground(
cc::PaintCanvas* canvas,
const gfx::Size& size,
@@ -54,6 +61,20 @@ class NATIVE_THEME_EXPORT NativeThemeMac : public NativeThemeBase {
const gfx::Rect& rect,
const MenuItemExtraParams& menu_item,
ColorScheme color_scheme) const override;
+ void PaintMacScrollbarThumb(cc::PaintCanvas* canvas,
+ Part part,
+ State state,
+ const gfx::Rect& rect,
+ const ScrollbarExtraParams& scroll_thumb,
+ ColorScheme color_scheme) const;
+ // Paint the track. |track_bounds| is the bounds for the track.
+ void PaintMacScrollBarTrackOrCorner(cc::PaintCanvas* canvas,
+ Part part,
+ State state,
+ const ScrollbarExtraParams& extra_params,
+ const gfx::Rect& rect,
+ ColorScheme color_scheme,
+ bool is_corner) const;
// Paints the styled button shape used for default controls on Mac. The basic
// style is used for dialog buttons, comboboxes, and tabbed pane tabs.
@@ -81,6 +102,22 @@ class NATIVE_THEME_EXPORT NativeThemeMac : public NativeThemeBase {
const gfx::Rect& rect,
ColorScheme color_scheme) const;
+ void PaintScrollBarTrackGradient(cc::PaintCanvas* canvas,
+ const gfx::Rect& rect,
+ const ScrollbarExtraParams& extra_params,
+ bool is_corner,
+ ColorScheme color_scheme) const;
+ void PaintScrollbarTrackInnerBorder(cc::PaintCanvas* canvas,
+ const gfx::Rect& rect,
+ const ScrollbarExtraParams& extra_params,
+ bool is_corner,
+ ColorScheme color_scheme) const;
+ void PaintScrollbarTrackOuterBorder(cc::PaintCanvas* canvas,
+ const gfx::Rect& rect,
+ const ScrollbarExtraParams& extra_params,
+ bool is_corner,
+ ColorScheme color_scheme) const;
+
void InitializeDarkModeStateAndObserver();
void ConfigureWebInstance() override;
@@ -91,6 +128,29 @@ class NATIVE_THEME_EXPORT NativeThemeMac : public NativeThemeBase {
base::Optional<SkColor> GetOSColor(ColorId color_id,
ColorScheme color_scheme) const;
+ enum ScrollbarPart {
+ kThumb,
+ kTrackInnerBorder,
+ kTrackOuterBorder,
+ };
+
+ base::Optional<SkColor> GetScrollbarColor(
+ ScrollbarPart part,
+ ColorScheme color_scheme,
+ const ScrollbarExtraParams& extra_params) const;
+
+ int ScrollbarTrackBorderWidth() const { return 1; }
+
+ // The amount the thumb is inset from the ends and the inside edge of track
+ // border.
+ int GetScrollbarThumbInset(bool is_overlay) const {
+ return is_overlay ? 2 : 3;
+ }
+
+ // Returns the minimum size for the thumb. We will not inset the thumb if it
+ // will be smaller than this size.
+ gfx::Size GetThumbMinSize(bool vertical) const;
+
base::scoped_nsobject<NativeThemeEffectiveAppearanceObserver>
appearance_observer_;
id high_contrast_notification_token_;
diff --git a/chromium/ui/native_theme/native_theme_mac.mm b/chromium/ui/native_theme/native_theme_mac.mm
index fc84f17cd4d..1fda9fe5d26 100644
--- a/chromium/ui/native_theme/native_theme_mac.mm
+++ b/chromium/ui/native_theme/native_theme_mac.mm
@@ -6,6 +6,7 @@
#import <Cocoa/Cocoa.h>
#include <stddef.h>
+#include <vector>
#include "base/command_line.h"
#include "base/mac/mac_util.h"
@@ -15,8 +16,10 @@
#include "ui/base/ui_base_features.h"
#include "ui/base/ui_base_switches.h"
#include "ui/color/mac/scoped_current_nsappearance.h"
+#include "ui/gfx/canvas.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h"
+#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/skia_util.h"
#include "ui/native_theme/common_theme.h"
@@ -237,6 +240,299 @@ base::Optional<SkColor> NativeThemeMac::GetOSColor(
}
}
+void NativeThemeMac::Paint(cc::PaintCanvas* canvas,
+ Part part,
+ State state,
+ const gfx::Rect& rect,
+ const ExtraParams& extra,
+ ColorScheme color_scheme) const {
+ ColorScheme color_scheme_updated = color_scheme;
+ if (color_scheme_updated == ColorScheme::kDefault)
+ color_scheme_updated = GetDefaultSystemColorScheme();
+
+ if (rect.IsEmpty())
+ return;
+
+ switch (part) {
+ case kScrollbarHorizontalThumb:
+ case kScrollbarVerticalThumb:
+ PaintMacScrollbarThumb(canvas, part, state, rect, extra.scrollbar_extra,
+ color_scheme_updated);
+ break;
+ case kScrollbarHorizontalTrack:
+ case kScrollbarVerticalTrack:
+ PaintMacScrollBarTrackOrCorner(canvas, part, state, extra.scrollbar_extra,
+ rect, color_scheme_updated, false);
+ break;
+ case kScrollbarCorner:
+ PaintMacScrollBarTrackOrCorner(canvas, part, state, extra.scrollbar_extra,
+ rect, color_scheme_updated, true);
+ break;
+ default:
+ NativeThemeBase::Paint(canvas, part, state, rect, extra, color_scheme);
+ break;
+ }
+}
+
+void ConstrainInsets(int old_width, int min_width, int* left, int* right) {
+ int requested_total_inset = *left + *right;
+ if (requested_total_inset == 0)
+ return;
+ int max_total_inset = old_width - min_width;
+ if (requested_total_inset < max_total_inset)
+ return;
+ if (max_total_inset < 0) {
+ *left = *right = 0;
+ return;
+ }
+ // Multiply the right/bottom inset by the ratio by which we need to shrink the
+ // total inset. This has the effect of rounding down the right/bottom inset,
+ // if the two sides are to be affected unevenly.
+ // This is done instead of using inset scale functions to maintain expected
+ // behavior and to map to how it looks like other scrollbars work on MacOS.
+ *right *= max_total_inset * 1.0f / requested_total_inset;
+ *left = max_total_inset - *right;
+}
+
+void ConstrainedInset(gfx::Rect* rect,
+ gfx::Size min_size,
+ gfx::Insets initial_insets) {
+ int inset_left = initial_insets.left();
+ int inset_right = initial_insets.right();
+ int inset_top = initial_insets.top();
+ int inset_bottom = initial_insets.bottom();
+
+ ConstrainInsets(rect->width(), min_size.width(), &inset_left, &inset_right);
+ ConstrainInsets(rect->height(), min_size.height(), &inset_top, &inset_bottom);
+ rect->Inset(inset_left, inset_top, inset_right, inset_bottom);
+}
+
+void NativeThemeMac::PaintMacScrollBarTrackOrCorner(
+ cc::PaintCanvas* canvas,
+ Part part,
+ State state,
+ const ScrollbarExtraParams& extra_params,
+ const gfx::Rect& rect,
+ ColorScheme color_scheme,
+ bool is_corner) const {
+ if (is_corner && extra_params.is_overlay)
+ return;
+ PaintScrollBarTrackGradient(canvas, rect, extra_params, is_corner,
+ color_scheme);
+ PaintScrollbarTrackInnerBorder(canvas, rect, extra_params, is_corner,
+ color_scheme);
+ PaintScrollbarTrackOuterBorder(canvas, rect, extra_params, is_corner,
+ color_scheme);
+}
+
+void NativeThemeMac::PaintScrollBarTrackGradient(
+ cc::PaintCanvas* canvas,
+ const gfx::Rect& rect,
+ const ScrollbarExtraParams& extra_params,
+ bool is_corner,
+ ColorScheme color_scheme) const {
+ gfx::Canvas paint_canvas(canvas, 1.0f);
+ // Select colors.
+ std::vector<SkColor> gradient_colors;
+ bool dark_mode = color_scheme == ColorScheme::kDark;
+ if (extra_params.is_overlay) {
+ if (dark_mode) {
+ gradient_colors = {SkColorSetARGB(0x28, 0xD8, 0xD8, 0xD8),
+ SkColorSetARGB(0x26, 0xCC, 0xCC, 0xCC),
+ SkColorSetARGB(0x26, 0xCC, 0xCC, 0xCC),
+ SkColorSetARGB(0x26, 0xCC, 0xCC, 0xCC)};
+ } else {
+ gradient_colors = {SkColorSetARGB(0xC6, 0xF8, 0xF8, 0xF8),
+ SkColorSetARGB(0xC2, 0xF8, 0xF8, 0xF8),
+ SkColorSetARGB(0xC2, 0xF8, 0xF8, 0xF8),
+ SkColorSetARGB(0xC2, 0xF8, 0xF8, 0xF8)};
+ }
+ } else {
+ // Non-overlay scroller track colors are not transparent. On Safari, they
+ // are, but on all other macOS applications they are not.
+ if (dark_mode) {
+ gradient_colors = {SkColorSetRGB(0x2D, 0x2D, 0x2D),
+ SkColorSetRGB(0x2B, 0x2B, 0x2B)};
+ } else {
+ gradient_colors = {SkColorSetRGB(0xFA, 0xFA, 0xFA),
+ SkColorSetRGB(0xFA, 0xFA, 0xFA)};
+ }
+ }
+
+ // Set the gradient direction.
+ std::vector<SkPoint> gradient_bounds;
+ if (is_corner) {
+ if (extra_params.orientation == ScrollbarOrientation::kVerticalOnRight) {
+ gradient_bounds = {gfx::PointToSkPoint(rect.origin()),
+ gfx::PointToSkPoint(rect.bottom_right())};
+ } else {
+ gradient_bounds = {gfx::PointToSkPoint(rect.top_right()),
+ gfx::PointToSkPoint(rect.bottom_left())};
+ }
+ } else {
+ if (extra_params.orientation == ScrollbarOrientation::kHorizontal) {
+ gradient_bounds = {gfx::PointToSkPoint(rect.origin()),
+ gfx::PointToSkPoint(rect.top_right())};
+ } else {
+ gradient_bounds = {gfx::PointToSkPoint(rect.origin()),
+ gfx::PointToSkPoint(rect.bottom_left())};
+ }
+ }
+
+ // And draw.
+ cc::PaintFlags gradient;
+ gradient.setShader(cc::PaintShader::MakeLinearGradient(
+ gradient_bounds.data(), gradient_colors.data(), nullptr,
+ gradient_colors.size(), SkTileMode::kClamp));
+ paint_canvas.DrawRect(rect, gradient);
+}
+
+void NativeThemeMac::PaintScrollbarTrackInnerBorder(
+ cc::PaintCanvas* canvas,
+ const gfx::Rect& rect,
+ const ScrollbarExtraParams& extra_params,
+ bool is_corner,
+ ColorScheme color_scheme) const {
+ gfx::Canvas paint_canvas(canvas, 1.0f);
+
+ // Compute the rect for the border.
+ gfx::Rect inner_border(rect);
+ if (extra_params.orientation == ScrollbarOrientation::kVerticalOnLeft)
+ inner_border.set_x(rect.right() - ScrollbarTrackBorderWidth());
+ if (is_corner ||
+ extra_params.orientation == ScrollbarOrientation::kHorizontal)
+ inner_border.set_height(ScrollbarTrackBorderWidth());
+ if (is_corner ||
+ extra_params.orientation != ScrollbarOrientation::kHorizontal)
+ inner_border.set_width(ScrollbarTrackBorderWidth());
+
+ // And draw.
+ cc::PaintFlags flags;
+ SkColor inner_border_color =
+ GetScrollbarColor(ScrollbarPart::kTrackInnerBorder, color_scheme,
+ extra_params)
+ .value();
+ flags.setColor(inner_border_color);
+ paint_canvas.DrawRect(inner_border, flags);
+}
+
+void NativeThemeMac::PaintScrollbarTrackOuterBorder(
+ cc::PaintCanvas* canvas,
+ const gfx::Rect& rect,
+ const ScrollbarExtraParams& extra_params,
+ bool is_corner,
+ ColorScheme color_scheme) const {
+ gfx::Canvas paint_canvas(canvas, 1.0f);
+ cc::PaintFlags flags;
+ SkColor outer_border_color =
+ GetScrollbarColor(ScrollbarPart::kTrackOuterBorder, color_scheme,
+ extra_params)
+ .value();
+ flags.setColor(outer_border_color);
+
+ // Draw the horizontal outer border.
+ if (is_corner ||
+ extra_params.orientation == ScrollbarOrientation::kHorizontal) {
+ gfx::Rect outer_border(rect);
+ outer_border.set_height(ScrollbarTrackBorderWidth());
+ outer_border.set_y(rect.bottom() - ScrollbarTrackBorderWidth());
+ paint_canvas.DrawRect(outer_border, flags);
+ }
+
+ // Draw the vertial outer border.
+ if (is_corner ||
+ extra_params.orientation != ScrollbarOrientation::kHorizontal) {
+ gfx::Rect outer_border(rect);
+ outer_border.set_width(ScrollbarTrackBorderWidth());
+ if (extra_params.orientation == ScrollbarOrientation::kVerticalOnRight)
+ outer_border.set_x(rect.right() - ScrollbarTrackBorderWidth());
+ paint_canvas.DrawRect(outer_border, flags);
+ }
+}
+
+gfx::Size NativeThemeMac::GetThumbMinSize(bool vertical) const {
+ constexpr int kLength = 18;
+ constexpr int kGirth = 6;
+
+ return vertical ? gfx::Size(kGirth, kLength) : gfx::Size(kLength, kGirth);
+}
+
+void NativeThemeMac::PaintMacScrollbarThumb(
+ cc::PaintCanvas* canvas,
+ Part part,
+ State state,
+ const gfx::Rect& rect,
+ const ScrollbarExtraParams& scroll_thumb,
+ ColorScheme color_scheme) const {
+ gfx::Canvas paint_canvas(canvas, 1.0f);
+
+ // Compute the bounds for the rounded rect for the thumb from the bounds of
+ // the thumb.
+ gfx::Rect bounds(rect);
+ {
+ // Shrink the thumb evenly in length and girth to fit within the track.
+ gfx::Insets thumb_insets(GetScrollbarThumbInset(scroll_thumb.is_overlay));
+
+ // Also shrink the thumb in girth to not touch the border.
+ if (scroll_thumb.orientation == ScrollbarOrientation::kHorizontal) {
+ thumb_insets.set_top(thumb_insets.top() + ScrollbarTrackBorderWidth());
+ ConstrainedInset(&bounds, GetThumbMinSize(false), thumb_insets);
+ } else {
+ thumb_insets.set_left(thumb_insets.left() + ScrollbarTrackBorderWidth());
+ ConstrainedInset(&bounds, GetThumbMinSize(true), thumb_insets);
+ }
+ }
+
+ // Draw.
+ cc::PaintFlags flags;
+ flags.setAntiAlias(true);
+ flags.setStyle(cc::PaintFlags::kFill_Style);
+ SkColor thumb_color =
+ GetScrollbarColor(ScrollbarPart::kThumb, color_scheme, scroll_thumb)
+ .value();
+ flags.setColor(thumb_color);
+ const SkScalar radius = std::min(bounds.width(), bounds.height());
+ paint_canvas.DrawRoundRect(bounds, radius, flags);
+}
+
+base::Optional<SkColor> NativeThemeMac::GetScrollbarColor(
+ ScrollbarPart part,
+ ColorScheme color_scheme,
+ const ScrollbarExtraParams& extra_params) const {
+ // This function is called from the renderer process through the scrollbar
+ // drawing functions. Due to this, it cannot use any of the dynamic NS system
+ // colors.
+ bool dark_mode = color_scheme == ColorScheme::kDark;
+ if (part == ScrollbarPart::kThumb) {
+ if (extra_params.is_overlay)
+ return dark_mode ? SkColorSetARGB(0x80, 0xFF, 0xFF, 0xFF)
+ : SkColorSetARGB(0x80, 0, 0, 0);
+
+ if (dark_mode)
+ return extra_params.is_hovering ? SkColorSetRGB(0x93, 0x93, 0x93)
+ : SkColorSetRGB(0x6B, 0x6B, 0x6B);
+
+ return extra_params.is_hovering ? SkColorSetARGB(0x80, 0, 0, 0)
+ : SkColorSetARGB(0x3A, 0, 0, 0);
+ } else if (part == ScrollbarPart::kTrackInnerBorder) {
+ if (extra_params.is_overlay)
+ return dark_mode ? SkColorSetARGB(0x33, 0xE5, 0xE5, 0xE5)
+ : SkColorSetARGB(0xF9, 0xDF, 0xDF, 0xDF);
+
+ return dark_mode ? SkColorSetRGB(0x3D, 0x3D, 0x3D)
+ : SkColorSetRGB(0xE8, 0xE8, 0xE8);
+ } else if (part == ScrollbarPart::kTrackOuterBorder) {
+ if (extra_params.is_overlay)
+ return dark_mode ? SkColorSetARGB(0x28, 0xD8, 0xD8, 0xD8)
+ : SkColorSetARGB(0xC6, 0xE8, 0xE8, 0xE8);
+
+ return dark_mode ? SkColorSetRGB(0x51, 0x51, 0x51)
+ : SkColorSetRGB(0xED, 0xED, 0xED);
+ }
+
+ return base::nullopt;
+}
+
SkColor NativeThemeMac::GetSystemButtonPressedColor(SkColor base_color) const {
// TODO crbug.com/1003612: This should probably be replaced with a color
// transform.
diff --git a/chromium/ui/native_theme/native_theme_mac_unittest.cc b/chromium/ui/native_theme/native_theme_mac_unittest.cc
index 5ac53bdaf04..d6d3327bb1c 100644
--- a/chromium/ui/native_theme/native_theme_mac_unittest.cc
+++ b/chromium/ui/native_theme/native_theme_mac_unittest.cc
@@ -24,4 +24,31 @@ TEST(NativeThemeMacTest, SystemColorsExist) {
}
}
+TEST(NativeThemeMacTest, GetPlatformHighContrastColorScheme) {
+ using PrefScheme = NativeTheme::PreferredColorScheme;
+
+ constexpr NativeTheme::PlatformHighContrastColorScheme kNone =
+ NativeTheme::PlatformHighContrastColorScheme::kNone;
+
+ NativeTheme* native_theme = NativeTheme::GetInstanceForNativeUi();
+ ASSERT_TRUE(native_theme);
+
+ native_theme->set_high_contrast(false);
+ native_theme->set_preferred_color_scheme(PrefScheme::kDark);
+ EXPECT_EQ(native_theme->GetPlatformHighContrastColorScheme(), kNone);
+
+ native_theme->set_preferred_color_scheme(PrefScheme::kLight);
+ EXPECT_EQ(native_theme->GetPlatformHighContrastColorScheme(), kNone);
+
+ native_theme->set_high_contrast(true);
+ native_theme->set_preferred_color_scheme(PrefScheme::kDark);
+ EXPECT_EQ(native_theme->GetPlatformHighContrastColorScheme(), kNone);
+
+ native_theme->set_preferred_color_scheme(PrefScheme::kLight);
+ EXPECT_EQ(native_theme->GetPlatformHighContrastColorScheme(), kNone);
+
+ native_theme->set_high_contrast(false);
+ EXPECT_EQ(native_theme->GetPlatformHighContrastColorScheme(), kNone);
+}
+
} // namespace ui
diff --git a/chromium/ui/native_theme/native_theme_win.cc b/chromium/ui/native_theme/native_theme_win.cc
index 8cc9cdc5eab..91c5532be89 100644
--- a/chromium/ui/native_theme/native_theme_win.cc
+++ b/chromium/ui/native_theme/native_theme_win.cc
@@ -730,17 +730,16 @@ NativeThemeWin::CalculatePreferredColorScheme() const {
if (!UsesHighContrastColors())
return NativeTheme::CalculatePreferredColorScheme();
- // The Windows SystemParametersInfo API will return the high contrast theme
- // as a string. However, this string is language dependent. Instead, to
- // account for non-English systems, sniff out the system colors to
- // determine the high contrast color scheme.
- SkColor fg_color = system_colors_[SystemThemeColor::kWindowText];
+ // According to the spec, the preferred color scheme for web content is 'dark'
+ // if 'Canvas' has L<33% and 'light' if L>67%. On Windows, the 'Canvas'
+ // keyword is mapped to the 'Window' system color. As such, we use the
+ // luminance of 'Window' to calculate the corresponding luminance of 'Canvas'.
+ // https://www.w3.org/TR/css-color-adjust-1/#forced
SkColor bg_color = system_colors_[SystemThemeColor::kWindow];
- if (bg_color == SK_ColorWHITE && fg_color == SK_ColorBLACK)
- return NativeTheme::PreferredColorScheme::kLight;
- if (bg_color == SK_ColorBLACK && fg_color == SK_ColorWHITE)
+ float luminance = color_utils::GetRelativeLuminance(bg_color);
+ if (luminance < 0.33)
return NativeTheme::PreferredColorScheme::kDark;
- return NativeTheme::PreferredColorScheme::kNoPreference;
+ return NativeTheme::PreferredColorScheme::kLight;
}
NativeTheme::ColorScheme NativeThemeWin::GetDefaultSystemColorScheme() const {
diff --git a/chromium/ui/native_theme/native_theme_win_unittest.cc b/chromium/ui/native_theme/native_theme_win_unittest.cc
index 7d6b0dd60d9..5f0d0e842d8 100644
--- a/chromium/ui/native_theme/native_theme_win_unittest.cc
+++ b/chromium/ui/native_theme/native_theme_win_unittest.cc
@@ -9,10 +9,8 @@
namespace ui {
-using ColorScheme = NativeTheme::ColorScheme;
using PrefScheme = NativeTheme::PreferredColorScheme;
using SystemThemeColor = NativeTheme::SystemThemeColor;
-using ColorId = NativeTheme::ColorId;
class TestNativeThemeWin : public NativeThemeWin {
public:
@@ -20,108 +18,122 @@ class TestNativeThemeWin : public NativeThemeWin {
~TestNativeThemeWin() override = default;
// NativeTheme:
- bool UsesHighContrastColors() const override { return high_contrast_; }
- bool ShouldUseDarkColors() const override { return dark_mode_; }
-
- void SetDarkMode(bool dark_mode) { dark_mode_ = dark_mode; }
- void SetUsesHighContrastColors(bool high_contrast) {
- high_contrast_ = high_contrast;
- }
void SetSystemColor(SystemThemeColor system_color, SkColor color) {
system_colors_[system_color] = color;
}
- private:
- bool dark_mode_ = false;
- bool high_contrast_ = false;
-
DISALLOW_COPY_AND_ASSIGN(TestNativeThemeWin);
};
TEST(NativeThemeWinTest, CalculatePreferredColorScheme) {
TestNativeThemeWin theme;
- theme.SetUsesHighContrastColors(false);
- theme.SetDarkMode(true);
- ASSERT_EQ(theme.CalculatePreferredColorScheme(), PrefScheme::kDark);
+ theme.set_high_contrast(false);
+ theme.set_use_dark_colors(true);
+ EXPECT_EQ(theme.CalculatePreferredColorScheme(), PrefScheme::kDark);
- theme.SetDarkMode(false);
- ASSERT_EQ(theme.CalculatePreferredColorScheme(), PrefScheme::kLight);
+ theme.set_use_dark_colors(false);
+ EXPECT_EQ(theme.CalculatePreferredColorScheme(), PrefScheme::kLight);
- theme.SetUsesHighContrastColors(true);
+ theme.set_high_contrast(true);
theme.SetSystemColor(SystemThemeColor::kWindow, SK_ColorBLACK);
- theme.SetSystemColor(SystemThemeColor::kWindowText, SK_ColorWHITE);
- ASSERT_EQ(theme.CalculatePreferredColorScheme(), PrefScheme::kDark);
+ EXPECT_EQ(theme.CalculatePreferredColorScheme(), PrefScheme::kDark);
theme.SetSystemColor(SystemThemeColor::kWindow, SK_ColorWHITE);
- theme.SetSystemColor(SystemThemeColor::kWindowText, SK_ColorBLACK);
- ASSERT_EQ(theme.CalculatePreferredColorScheme(), PrefScheme::kLight);
+ EXPECT_EQ(theme.CalculatePreferredColorScheme(), PrefScheme::kLight);
- theme.SetSystemColor(SystemThemeColor::kWindowText, SK_ColorBLUE);
- ASSERT_EQ(theme.CalculatePreferredColorScheme(), PrefScheme::kNoPreference);
+ theme.SetSystemColor(SystemThemeColor::kWindow, SK_ColorBLUE);
+ EXPECT_EQ(theme.CalculatePreferredColorScheme(), PrefScheme::kDark);
+
+ theme.SetSystemColor(SystemThemeColor::kWindow, SK_ColorYELLOW);
+ EXPECT_EQ(theme.CalculatePreferredColorScheme(), PrefScheme::kLight);
- theme.SetUsesHighContrastColors(false);
- ASSERT_EQ(theme.CalculatePreferredColorScheme(), PrefScheme::kLight);
+ theme.set_high_contrast(false);
+ EXPECT_EQ(theme.CalculatePreferredColorScheme(), PrefScheme::kLight);
}
TEST(NativeThemeWinTest, GetDefaultSystemColorScheme) {
- TestNativeThemeWin theme;
+ using ColorScheme = NativeTheme::ColorScheme;
- theme.SetUsesHighContrastColors(false);
- theme.SetDarkMode(true);
- ASSERT_EQ(theme.GetDefaultSystemColorScheme(), ColorScheme::kDark);
+ TestNativeThemeWin theme;
+ theme.set_high_contrast(false);
+ theme.set_use_dark_colors(true);
+ EXPECT_EQ(theme.GetDefaultSystemColorScheme(), ColorScheme::kDark);
- theme.SetDarkMode(false);
- ASSERT_EQ(theme.GetDefaultSystemColorScheme(), ColorScheme::kLight);
+ theme.set_use_dark_colors(false);
+ EXPECT_EQ(theme.GetDefaultSystemColorScheme(), ColorScheme::kLight);
- theme.SetUsesHighContrastColors(true);
+ theme.set_high_contrast(true);
theme.SetSystemColor(SystemThemeColor::kWindow, SK_ColorBLACK);
theme.SetSystemColor(SystemThemeColor::kWindowText, SK_ColorWHITE);
- ASSERT_EQ(theme.GetDefaultSystemColorScheme(),
+ EXPECT_EQ(theme.GetDefaultSystemColorScheme(),
ColorScheme::kPlatformHighContrast);
theme.SetSystemColor(SystemThemeColor::kWindow, SK_ColorWHITE);
theme.SetSystemColor(SystemThemeColor::kWindowText, SK_ColorBLACK);
- ASSERT_EQ(theme.GetDefaultSystemColorScheme(),
+ EXPECT_EQ(theme.GetDefaultSystemColorScheme(),
ColorScheme::kPlatformHighContrast);
theme.SetSystemColor(SystemThemeColor::kWindowText, SK_ColorBLUE);
- ASSERT_EQ(theme.GetDefaultSystemColorScheme(),
+ EXPECT_EQ(theme.GetDefaultSystemColorScheme(),
ColorScheme::kPlatformHighContrast);
- theme.SetUsesHighContrastColors(false);
- ASSERT_EQ(theme.GetDefaultSystemColorScheme(), ColorScheme::kLight);
+ theme.set_high_contrast(false);
+ EXPECT_EQ(theme.GetDefaultSystemColorScheme(), ColorScheme::kLight);
}
TEST(NativeThemeWinTest, GetPlatformHighContrastColor) {
- TestNativeThemeWin theme;
+ using ColorId = NativeTheme::ColorId;
// These specific colors don't matter, but should be unique.
constexpr SkColor kWindowTextColor = SK_ColorGREEN;
constexpr SkColor kHighlightColor = SK_ColorYELLOW;
constexpr SkColor kHighlightTextColor = SK_ColorBLUE;
+ TestNativeThemeWin theme;
theme.SetSystemColor(SystemThemeColor::kWindowText, kWindowTextColor);
theme.SetSystemColor(SystemThemeColor::kHighlight, kHighlightColor);
theme.SetSystemColor(SystemThemeColor::kHighlightText, kHighlightTextColor);
// Test that we get regular colors when HC is off.
- theme.SetUsesHighContrastColors(false);
- ASSERT_NE(theme.GetSystemColor(ColorId::kColorId_LabelEnabledColor),
+ theme.set_high_contrast(false);
+ EXPECT_NE(theme.GetSystemColor(ColorId::kColorId_LabelEnabledColor),
kWindowTextColor);
- ASSERT_NE(theme.GetSystemColor(ColorId::kColorId_ProminentButtonColor),
+ EXPECT_NE(theme.GetSystemColor(ColorId::kColorId_ProminentButtonColor),
kHighlightColor);
- ASSERT_NE(theme.GetSystemColor(ColorId::kColorId_TextOnProminentButtonColor),
+ EXPECT_NE(theme.GetSystemColor(ColorId::kColorId_TextOnProminentButtonColor),
kHighlightTextColor);
// Test that we get HC colors when HC is on.
- theme.SetUsesHighContrastColors(true);
- ASSERT_EQ(theme.GetSystemColor(ColorId::kColorId_LabelEnabledColor),
+ theme.set_high_contrast(true);
+ EXPECT_EQ(theme.GetSystemColor(ColorId::kColorId_LabelEnabledColor),
kWindowTextColor);
- ASSERT_EQ(theme.GetSystemColor(ColorId::kColorId_ProminentButtonColor),
+ EXPECT_EQ(theme.GetSystemColor(ColorId::kColorId_ProminentButtonColor),
kHighlightColor);
- ASSERT_EQ(theme.GetSystemColor(ColorId::kColorId_TextOnProminentButtonColor),
+ EXPECT_EQ(theme.GetSystemColor(ColorId::kColorId_TextOnProminentButtonColor),
kHighlightTextColor);
}
+TEST(NativeThemeWinTest, GetPlatformHighContrastColorScheme) {
+ using HCColorScheme = NativeTheme::PlatformHighContrastColorScheme;
+
+ TestNativeThemeWin theme;
+ theme.set_high_contrast(false);
+ theme.set_preferred_color_scheme(PrefScheme::kDark);
+ EXPECT_EQ(theme.GetPlatformHighContrastColorScheme(), HCColorScheme::kNone);
+
+ theme.set_preferred_color_scheme(PrefScheme::kLight);
+ EXPECT_EQ(theme.GetPlatformHighContrastColorScheme(), HCColorScheme::kNone);
+
+ theme.set_high_contrast(true);
+ theme.set_preferred_color_scheme(PrefScheme::kDark);
+ EXPECT_EQ(theme.GetPlatformHighContrastColorScheme(), HCColorScheme::kDark);
+
+ theme.set_preferred_color_scheme(PrefScheme::kLight);
+ EXPECT_EQ(theme.GetPlatformHighContrastColorScheme(), HCColorScheme::kLight);
+
+ theme.set_high_contrast(false);
+ EXPECT_EQ(theme.GetPlatformHighContrastColorScheme(), HCColorScheme::kNone);
+}
+
} // namespace ui
diff --git a/chromium/ui/native_theme/themed_vector_icon.cc b/chromium/ui/native_theme/themed_vector_icon.cc
index 3881f84d423..bf3b0e65d9f 100644
--- a/chromium/ui/native_theme/themed_vector_icon.cc
+++ b/chromium/ui/native_theme/themed_vector_icon.cc
@@ -43,13 +43,14 @@ ThemedVectorIcon::ThemedVectorIcon(ThemedVectorIcon&&) = default;
ThemedVectorIcon& ThemedVectorIcon::operator=(ThemedVectorIcon&&) = default;
-const gfx::ImageSkia ThemedVectorIcon::GetImageSkia(NativeTheme* theme) const {
+const gfx::ImageSkia ThemedVectorIcon::GetImageSkia(
+ const NativeTheme* theme) const {
DCHECK(!empty());
return icon_size_ > 0 ? CreateVectorIcon(*icon_, icon_size_, GetColor(theme))
: CreateVectorIcon(*icon_, GetColor(theme));
}
-const gfx::ImageSkia ThemedVectorIcon::GetImageSkia(NativeTheme* theme,
+const gfx::ImageSkia ThemedVectorIcon::GetImageSkia(const NativeTheme* theme,
int icon_size) const {
DCHECK(!empty());
return CreateVectorIcon(*icon_, icon_size, GetColor(theme));
@@ -61,7 +62,7 @@ const gfx::ImageSkia ThemedVectorIcon::GetImageSkia(SkColor color) const {
: CreateVectorIcon(*icon_, color);
}
-SkColor ThemedVectorIcon::GetColor(NativeTheme* theme) const {
+SkColor ThemedVectorIcon::GetColor(const NativeTheme* theme) const {
DCHECK(color_id_ || color_);
return color_id_ ? theme->GetSystemColor(color_id_.value()) : color_.value();
}
diff --git a/chromium/ui/native_theme/themed_vector_icon.h b/chromium/ui/native_theme/themed_vector_icon.h
index e65348c9fde..bf929d6af94 100644
--- a/chromium/ui/native_theme/themed_vector_icon.h
+++ b/chromium/ui/native_theme/themed_vector_icon.h
@@ -40,12 +40,13 @@ class NATIVE_THEME_EXPORT ThemedVectorIcon {
void clear() { icon_ = nullptr; }
bool empty() const { return !icon_; }
- const gfx::ImageSkia GetImageSkia(NativeTheme* theme) const;
- const gfx::ImageSkia GetImageSkia(NativeTheme* theme, int icon_size) const;
+ const gfx::ImageSkia GetImageSkia(const NativeTheme* theme) const;
+ const gfx::ImageSkia GetImageSkia(const NativeTheme* theme,
+ int icon_size) const;
const gfx::ImageSkia GetImageSkia(SkColor color) const;
private:
- SkColor GetColor(NativeTheme* theme) const;
+ SkColor GetColor(const NativeTheme* theme) const;
const gfx::VectorIcon* icon_ = nullptr;
int icon_size_ = 0;