Bug 1675015: Add Windows high contrast support to non-native theme. r=heycam

Differential Revision: https://phabricator.services.mozilla.com/D96803
This commit is contained in:
Stephen A Pohl 2020-11-17 20:53:01 +00:00
Родитель abd6c007c3
Коммит c2000738cd
4 изменённых файлов: 605 добавлений и 402 удалений

Просмотреть файл

@ -56,48 +56,6 @@ bool nsNativeBasicTheme::IsColorPickerButton(nsIFrame* aFrame) {
return colorPickerButton;
}
/* static */
std::pair<sRGBColor, sRGBColor> nsNativeBasicTheme::ComputeCheckColors(
const EventStates& aState) {
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
bool isPressed = !isDisabled && aState.HasAllStates(NS_EVENT_STATE_HOVER |
NS_EVENT_STATE_ACTIVE);
bool isHovered = !isDisabled && aState.HasState(NS_EVENT_STATE_HOVER);
bool isChecked = aState.HasState(NS_EVENT_STATE_CHECKED);
sRGBColor fillColor = sColorWhite;
sRGBColor borderColor = sColorGrey40;
if (isDisabled) {
if (isChecked) {
fillColor = borderColor = sColorGrey40Alpha50;
} else {
fillColor = sColorWhiteAlpha50;
borderColor = sColorGrey40Alpha50;
}
} else {
if (isChecked) {
if (isPressed) {
fillColor = borderColor = sColorAccentDarker;
} else if (isHovered) {
fillColor = borderColor = sColorAccentDark;
} else {
fillColor = borderColor = sColorAccent;
}
} else if (isPressed) {
fillColor = sColorGrey20;
borderColor = sColorGrey60;
} else if (isHovered) {
fillColor = sColorWhite;
borderColor = sColorGrey50;
} else {
fillColor = sColorWhite;
borderColor = sColorGrey40;
}
}
return std::make_pair(fillColor, borderColor);
}
/* static */
Rect nsNativeBasicTheme::FixAspectRatio(const Rect& aRect) {
// Checkbox and radio need to preserve aspect-ratio for compat.
@ -137,7 +95,268 @@ void nsNativeBasicTheme::GetFocusStrokeRect(DrawTarget* aDrawTarget,
aOutRect = MakePathForRoundedRect(*aDrawTarget, focusRect, radii);
}
/* static */
std::pair<sRGBColor, sRGBColor> nsNativeBasicTheme::ComputeCheckboxColors(
const EventStates& aState) {
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
bool isPressed = !isDisabled && aState.HasAllStates(NS_EVENT_STATE_HOVER |
NS_EVENT_STATE_ACTIVE);
bool isHovered = !isDisabled && aState.HasState(NS_EVENT_STATE_HOVER);
bool isChecked = aState.HasState(NS_EVENT_STATE_CHECKED);
sRGBColor backgroundColor = sColorWhite;
sRGBColor borderColor = sColorGrey40;
if (isDisabled) {
if (isChecked) {
backgroundColor = borderColor = sColorGrey40Alpha50;
} else {
backgroundColor = sColorWhiteAlpha50;
borderColor = sColorGrey40Alpha50;
}
} else {
if (isChecked) {
if (isPressed) {
backgroundColor = borderColor = sColorAccentDarker;
} else if (isHovered) {
backgroundColor = borderColor = sColorAccentDark;
} else {
backgroundColor = borderColor = sColorAccent;
}
} else if (isPressed) {
backgroundColor = sColorGrey20;
borderColor = sColorGrey60;
} else if (isHovered) {
backgroundColor = sColorWhite;
borderColor = sColorGrey50;
} else {
backgroundColor = sColorWhite;
borderColor = sColorGrey40;
}
}
return std::make_pair(backgroundColor, borderColor);
}
sRGBColor nsNativeBasicTheme::ComputeCheckmarkColor(const EventStates& aState) {
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
return isDisabled ? sColorWhiteAlpha50 : sColorWhite;
}
std::pair<sRGBColor, sRGBColor> nsNativeBasicTheme::ComputeRadioCheckmarkColors(
const EventStates& aState) {
auto [unusedColor, checkColor] = ComputeCheckboxColors(aState);
(void)unusedColor;
return std::make_pair(sColorWhite, checkColor);
}
sRGBColor nsNativeBasicTheme::ComputeBorderColor(const EventStates& aState) {
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
bool isActive =
aState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE);
bool isHovered = !isDisabled && aState.HasState(NS_EVENT_STATE_HOVER);
bool isFocused = aState.HasState(NS_EVENT_STATE_FOCUS);
if (isDisabled) {
return sColorGrey40Alpha50;
}
if (isFocused) {
return sColorAccent;
}
if (isActive) {
return sColorGrey60;
}
if (isHovered) {
return sColorGrey50;
}
return sColorGrey40;
}
std::pair<sRGBColor, sRGBColor> nsNativeBasicTheme::ComputeButtonColors(
const EventStates& aState, nsIFrame* aFrame) {
bool isActive =
aState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE);
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
bool isHovered = !isDisabled && aState.HasState(NS_EVENT_STATE_HOVER);
const sRGBColor& backgroundColor = [&] {
if (isDisabled) {
return sColorGrey10Alpha50;
}
if (IsDateTimeResetButton(aFrame)) {
return sColorWhite;
}
if (isActive) {
return sColorGrey30;
}
if (isHovered) {
return sColorGrey20;
}
return sColorGrey10;
}();
const sRGBColor borderColor = ComputeBorderColor(aState);
return std::make_pair(backgroundColor, borderColor);
}
std::pair<sRGBColor, sRGBColor> nsNativeBasicTheme::ComputeTextfieldColors(
const EventStates& aState) {
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
const sRGBColor& backgroundColor =
isDisabled ? sColorWhiteAlpha50 : sColorWhite;
const sRGBColor borderColor = ComputeBorderColor(aState);
return std::make_pair(backgroundColor, borderColor);
}
std::pair<sRGBColor, sRGBColor> nsNativeBasicTheme::ComputeRangeProgressColors(
const EventStates& aState) {
bool isActive =
aState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE);
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
bool isHovered = !isDisabled && aState.HasState(NS_EVENT_STATE_HOVER);
if (isDisabled) {
return std::make_pair(sColorGrey40Alpha50, sColorGrey40Alpha50);
}
if (isActive || isHovered) {
return std::make_pair(sColorAccentDark, sColorAccentDarker);
}
return std::make_pair(sColorAccent, sColorAccentDark);
}
std::pair<sRGBColor, sRGBColor> nsNativeBasicTheme::ComputeRangeTrackColors(
const EventStates& aState) {
bool isActive =
aState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE);
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
bool isHovered = !isDisabled && aState.HasState(NS_EVENT_STATE_HOVER);
if (isDisabled) {
return std::make_pair(sColorGrey10Alpha50, sColorGrey40Alpha50);
}
if (isActive || isHovered) {
return std::make_pair(sColorGrey20, sColorGrey50);
}
return std::make_pair(sColorGrey10, sColorGrey40);
}
std::pair<sRGBColor, sRGBColor> nsNativeBasicTheme::ComputeRangeThumbColors(
const EventStates& aState) {
bool isActive =
aState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE);
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
bool isHovered = !isDisabled && aState.HasState(NS_EVENT_STATE_HOVER);
const sRGBColor& backgroundColor = [&] {
if (isDisabled) {
return sColorGrey50Alpha50;
}
if (isActive) {
return sColorAccent;
}
if (isHovered) {
return sColorGrey60;
}
return sColorGrey50;
}();
const sRGBColor borderColor = sColorWhite;
return std::make_pair(backgroundColor, borderColor);
}
std::pair<sRGBColor, sRGBColor> nsNativeBasicTheme::ComputeProgressColors() {
return std::make_pair(sColorAccent, sColorAccentDark);
}
std::pair<sRGBColor, sRGBColor>
nsNativeBasicTheme::ComputeProgressTrackColors() {
return std::make_pair(sColorGrey10, sColorGrey40);
}
std::pair<sRGBColor, sRGBColor> nsNativeBasicTheme::ComputeMeterchunkColors(
const double aValue, const double aOptimum, const double aLow) {
sRGBColor borderColor = sColorMeterGreen20;
sRGBColor chunkColor = sColorMeterGreen10;
if (aValue < aOptimum) {
if (aValue < aLow) {
borderColor = sColorMeterRed20;
chunkColor = sColorMeterRed10;
} else {
borderColor = sColorMeterYellow20;
chunkColor = sColorMeterYellow10;
}
}
return std::make_pair(chunkColor, borderColor);
}
std::pair<sRGBColor, sRGBColor> nsNativeBasicTheme::ComputeMeterTrackColors() {
return std::make_pair(sColorGrey10, sColorGrey40);
}
sRGBColor nsNativeBasicTheme::ComputeMenulistArrowButtonColor(
const EventStates& aState) {
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
return isDisabled ? sColorGrey60Alpha50 : sColorGrey60;
}
std::array<sRGBColor, 3> nsNativeBasicTheme::ComputeFocusRectColors() {
std::array<sRGBColor, 3> colors = {sColorAccent, sColorWhiteAlpha80,
sColorAccentLight};
return colors;
}
sRGBColor nsNativeBasicTheme::ComputeScrollbarColor(
const ComputedStyle& aStyle, const EventStates& aDocumentState,
bool aIsRoot) {
const nsStyleUI* ui = aStyle.StyleUI();
nscolor color;
if (ui->mScrollbarColor.IsColors()) {
color = ui->mScrollbarColor.AsColors().track.CalcColor(aStyle);
} else if (aDocumentState.HasAllStates(NS_DOCUMENT_STATE_WINDOW_INACTIVE)) {
color = LookAndFeel::GetColor(LookAndFeel::ColorID::ThemedScrollbarInactive,
sScrollbarColor.ToABGR());
} else {
color = LookAndFeel::GetColor(LookAndFeel::ColorID::ThemedScrollbar,
sScrollbarColor.ToABGR());
}
if (aIsRoot) {
// Root scrollbars must be opaque.
nscolor bg = LookAndFeel::GetColor(LookAndFeel::ColorID::WindowBackground,
NS_RGB(0xff, 0xff, 0xff));
color = NS_ComposeColors(bg, color);
}
return gfx::sRGBColor::FromABGR(color);
}
sRGBColor nsNativeBasicTheme::ComputeScrollbarthumbColor(
const ComputedStyle& aStyle, const EventStates& aElementState,
const EventStates& aDocumentState) {
const nsStyleUI* ui = aStyle.StyleUI();
nscolor color;
if (ui->mScrollbarColor.IsColors()) {
color = ui->mScrollbarColor.AsColors().thumb.CalcColor(aStyle);
} else if (aDocumentState.HasAllStates(NS_DOCUMENT_STATE_WINDOW_INACTIVE)) {
color = LookAndFeel::GetColor(
LookAndFeel::ColorID::ThemedScrollbarThumbInactive,
sScrollbarThumbColor.ToABGR());
} else if (aElementState.HasAllStates(NS_EVENT_STATE_ACTIVE)) {
color =
LookAndFeel::GetColor(LookAndFeel::ColorID::ThemedScrollbarThumbActive,
sScrollbarThumbColorActive.ToABGR());
} else if (aElementState.HasAllStates(NS_EVENT_STATE_HOVER)) {
color =
LookAndFeel::GetColor(LookAndFeel::ColorID::ThemedScrollbarThumbHover,
sScrollbarThumbColorHover.ToABGR());
} else {
color = LookAndFeel::GetColor(LookAndFeel::ColorID::ThemedScrollbarThumb,
sScrollbarThumbColor.ToABGR());
}
return gfx::sRGBColor::FromABGR(color);
}
void nsNativeBasicTheme::PaintRoundedFocusRect(DrawTarget* aDrawTarget,
const Rect& aRect,
uint32_t aDpiRatio,
@ -145,6 +364,7 @@ void nsNativeBasicTheme::PaintRoundedFocusRect(DrawTarget* aDrawTarget,
CSSCoord aOffset) {
// NOTE(emilio): If the widths or offsets here change, make sure to tweak the
// GetWidgetOverflow path for FocusOutline.
auto [innerColor, middleColor, outerColor] = ComputeFocusRectColors();
Rect focusRect(aRect);
RefPtr<Path> roundedRect;
CSSCoord offset = aOffset * aDpiRatio;
@ -152,7 +372,7 @@ void nsNativeBasicTheme::PaintRoundedFocusRect(DrawTarget* aDrawTarget,
CSSCoord strokeWidth(2.0f * aDpiRatio);
GetFocusStrokeRect(aDrawTarget, focusRect, offset, strokeRadius, strokeWidth,
roundedRect);
aDrawTarget->Stroke(roundedRect, ColorPattern(ToDeviceColor(sColorAccent)),
aDrawTarget->Stroke(roundedRect, ColorPattern(ToDeviceColor(innerColor)),
StrokeOptions(strokeWidth));
offset = 1.0f * aDpiRatio;
@ -160,8 +380,7 @@ void nsNativeBasicTheme::PaintRoundedFocusRect(DrawTarget* aDrawTarget,
strokeWidth = 1.0f * aDpiRatio;
GetFocusStrokeRect(aDrawTarget, focusRect, offset, strokeRadius, strokeWidth,
roundedRect);
aDrawTarget->Stroke(roundedRect,
ColorPattern(ToDeviceColor(sColorWhiteAlpha80)),
aDrawTarget->Stroke(roundedRect, ColorPattern(ToDeviceColor(middleColor)),
StrokeOptions(strokeWidth));
offset = 2.0f * aDpiRatio;
@ -169,12 +388,10 @@ void nsNativeBasicTheme::PaintRoundedFocusRect(DrawTarget* aDrawTarget,
strokeWidth = 2.0f * aDpiRatio;
GetFocusStrokeRect(aDrawTarget, focusRect, offset, strokeRadius, strokeWidth,
roundedRect);
aDrawTarget->Stroke(roundedRect,
ColorPattern(ToDeviceColor(sColorAccentLight)),
aDrawTarget->Stroke(roundedRect, ColorPattern(ToDeviceColor(outerColor)),
StrokeOptions(strokeWidth));
}
/* static */
void nsNativeBasicTheme::PaintRoundedRect(DrawTarget* aDrawTarget,
const Rect& aRect,
const sRGBColor& aBackgroundColor,
@ -197,7 +414,6 @@ void nsNativeBasicTheme::PaintRoundedRect(DrawTarget* aDrawTarget,
StrokeOptions(borderWidth));
}
/* static */
void nsNativeBasicTheme::PaintRoundedRectWithRadius(
DrawTarget* aDrawTarget, const Rect& aRect,
const sRGBColor& aBackgroundColor, const sRGBColor& aBorderColor,
@ -208,14 +424,13 @@ void nsNativeBasicTheme::PaintRoundedRectWithRadius(
aBorderWidth, radii, aDpiRatio);
}
/* static */
void nsNativeBasicTheme::PaintCheckboxControl(DrawTarget* aDrawTarget,
const Rect& aRect,
const EventStates& aState,
uint32_t aDpiRatio) {
const CSSCoord borderWidth = 2.0f;
const CSSCoord radius = 3.0f - (borderWidth / 2.0f);
auto [backgroundColor, borderColor] = ComputeCheckColors(aState);
const CSSCoord radius = 2.0f;
auto [backgroundColor, borderColor] = ComputeCheckboxColors(aState);
PaintRoundedRectWithRadius(aDrawTarget, aRect, backgroundColor, borderColor,
borderWidth, radius, aDpiRatio);
@ -224,7 +439,6 @@ void nsNativeBasicTheme::PaintCheckboxControl(DrawTarget* aDrawTarget,
}
}
/* static */
void nsNativeBasicTheme::PaintCheckMark(DrawTarget* aDrawTarget,
const Rect& aRect,
const EventStates& aState,
@ -249,12 +463,10 @@ void nsNativeBasicTheme::PaintCheckMark(DrawTarget* aDrawTarget,
}
RefPtr<Path> path = builder->Finish();
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
sRGBColor fillColor = isDisabled ? sColorWhiteAlpha50 : sColorWhite;
sRGBColor fillColor = ComputeCheckmarkColor(aState);
aDrawTarget->Fill(path, ColorPattern(ToDeviceColor(fillColor)));
}
/* static */
void nsNativeBasicTheme::PaintIndeterminateMark(DrawTarget* aDrawTarget,
const Rect& aRect,
const EventStates& aState,
@ -269,12 +481,10 @@ void nsNativeBasicTheme::PaintIndeterminateMark(DrawTarget* aDrawTarget,
rect.x += (borderWidth * scale) + (borderWidth * scale / 8);
rect.width -= ((borderWidth * scale) + (borderWidth * scale / 8)) * 2;
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
sRGBColor fillColor = isDisabled ? sColorWhiteAlpha50 : sColorWhite;
sRGBColor fillColor = ComputeCheckmarkColor(aState);
aDrawTarget->FillRect(rect, ColorPattern(ToDeviceColor(fillColor)));
}
/* static */
void nsNativeBasicTheme::PaintStrokedEllipse(DrawTarget* aDrawTarget,
const Rect& aRect,
const sRGBColor& aBackgroundColor,
@ -295,7 +505,6 @@ void nsNativeBasicTheme::PaintStrokedEllipse(DrawTarget* aDrawTarget,
StrokeOptions(borderWidth));
}
/* static */
void nsNativeBasicTheme::PaintEllipseShadow(
DrawTarget* aDrawTarget, const Rect& aRect, float aShadowAlpha,
const Point& aShadowOffset, float aShadowBlurStdDev, uint32_t aDpiRatio) {
@ -336,13 +545,12 @@ void nsNativeBasicTheme::PaintEllipseShadow(
destinationPointOfSourceRect);
}
/* static */
void nsNativeBasicTheme::PaintRadioControl(DrawTarget* aDrawTarget,
const Rect& aRect,
const EventStates& aState,
uint32_t aDpiRatio) {
const CSSCoord borderWidth = 2.0f;
auto [backgroundColor, borderColor] = ComputeCheckColors(aState);
auto [backgroundColor, borderColor] = ComputeCheckboxColors(aState);
PaintStrokedEllipse(aDrawTarget, aRect, backgroundColor, borderColor,
borderWidth, aDpiRatio);
@ -352,16 +560,14 @@ void nsNativeBasicTheme::PaintRadioControl(DrawTarget* aDrawTarget,
}
}
/* static */
void nsNativeBasicTheme::PaintRadioCheckMark(DrawTarget* aDrawTarget,
void nsNativeBasicTheme::PaintRadioCheckmark(DrawTarget* aDrawTarget,
const Rect& aRect,
const EventStates& aState,
uint32_t aDpiRatio) {
const CSSCoord borderWidth = 2.0f;
const float scale = aDpiRatio * std::min(aRect.width, aRect.height) /
(kMinimumWidgetSize * (float)aDpiRatio);
auto [unusedColor, checkColor] = ComputeCheckColors(aState);
(void)unusedColor;
auto [backgroundColor, checkColor] = ComputeRadioCheckmarkColors(aState);
Rect rect(aRect);
rect.y += borderWidth * scale;
@ -369,41 +575,15 @@ void nsNativeBasicTheme::PaintRadioCheckMark(DrawTarget* aDrawTarget,
rect.height -= borderWidth * scale * 2;
rect.width -= borderWidth * scale * 2;
PaintStrokedEllipse(aDrawTarget, rect, checkColor, sColorWhite, borderWidth,
aDpiRatio);
PaintStrokedEllipse(aDrawTarget, rect, checkColor, backgroundColor,
borderWidth, aDpiRatio);
}
/* static */
sRGBColor nsNativeBasicTheme::ComputeBorderColor(const EventStates& aState) {
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
bool isActive =
aState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE);
bool isHovered = !isDisabled && aState.HasState(NS_EVENT_STATE_HOVER);
bool isFocused = aState.HasState(NS_EVENT_STATE_FOCUS);
if (isDisabled) {
return sColorGrey40Alpha50;
}
if (isFocused) {
return sColorAccent;
}
if (isActive) {
return sColorGrey60;
}
if (isHovered) {
return sColorGrey50;
}
return sColorGrey40;
}
/* static */
void nsNativeBasicTheme::PaintTextField(DrawTarget* aDrawTarget,
const Rect& aRect,
const EventStates& aState,
uint32_t aDpiRatio) {
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
const sRGBColor& backgroundColor =
isDisabled ? sColorWhiteAlpha50 : sColorWhite;
const sRGBColor borderColor = ComputeBorderColor(aState);
auto [backgroundColor, borderColor] = ComputeTextfieldColors(aState);
const CSSCoord radius = 2.0f;
@ -415,150 +595,14 @@ void nsNativeBasicTheme::PaintTextField(DrawTarget* aDrawTarget,
}
}
/* static */
std::pair<sRGBColor, sRGBColor> nsNativeBasicTheme::ComputeButtonColors(
const EventStates& aState, nsIFrame* aFrame) {
bool isActive =
aState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE);
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
bool isHovered = !isDisabled && aState.HasState(NS_EVENT_STATE_HOVER);
const sRGBColor& backgroundColor = [&] {
if (isDisabled) {
return sColorGrey10Alpha50;
}
if (IsDateTimeResetButton(aFrame)) {
return sColorWhite;
}
if (isActive) {
return sColorGrey30;
}
if (isHovered) {
return sColorGrey20;
}
return sColorGrey10;
}();
const sRGBColor borderColor = ComputeBorderColor(aState);
return std::make_pair(backgroundColor, borderColor);
}
sRGBColor nsNativeBasicTheme::ComputeRangeProgressBorderColor(
const EventStates& aState) {
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
bool isActive =
aState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE);
bool isHovered = !isDisabled && aState.HasState(NS_EVENT_STATE_HOVER);
if (isDisabled) {
return sColorGrey40Alpha50;
}
if (isActive || isHovered) {
return sColorAccentDarker;
}
return sColorAccentDark;
}
/* static */
sRGBColor nsNativeBasicTheme::ComputeRangeTrackBorderColor(
const EventStates& aState) {
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
bool isActive =
aState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE);
bool isHovered = !isDisabled && aState.HasState(NS_EVENT_STATE_HOVER);
if (isDisabled) {
return sColorGrey40Alpha50;
}
if (isActive || isHovered) {
return sColorGrey50;
}
return sColorGrey40;
}
/* static */
std::pair<sRGBColor, sRGBColor> nsNativeBasicTheme::ComputeRangeProgressColors(
const EventStates& aState) {
bool isActive =
aState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE);
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
bool isHovered = !isDisabled && aState.HasState(NS_EVENT_STATE_HOVER);
const sRGBColor& backgroundColor = [&] {
if (isDisabled) {
return sColorGrey40Alpha50;
}
if (isActive || isHovered) {
return sColorAccentDark;
}
return sColorAccent;
}();
const sRGBColor borderColor = ComputeRangeProgressBorderColor(aState);
return std::make_pair(backgroundColor, borderColor);
}
/* static */
std::pair<sRGBColor, sRGBColor> nsNativeBasicTheme::ComputeRangeTrackColors(
const EventStates& aState) {
bool isActive =
aState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE);
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
bool isHovered = !isDisabled && aState.HasState(NS_EVENT_STATE_HOVER);
const sRGBColor& backgroundColor = [&] {
if (isDisabled) {
return sColorGrey10Alpha50;
}
if (isActive || isHovered) {
return sColorGrey20;
}
return sColorGrey10;
}();
const sRGBColor borderColor = ComputeRangeTrackBorderColor(aState);
return std::make_pair(backgroundColor, borderColor);
}
/* static */
std::pair<sRGBColor, sRGBColor> nsNativeBasicTheme::ComputeRangeThumbColors(
const EventStates& aState) {
bool isActive =
aState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE);
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
bool isHovered = !isDisabled && aState.HasState(NS_EVENT_STATE_HOVER);
const sRGBColor& backgroundColor = [&] {
if (isDisabled) {
return sColorGrey50Alpha50;
}
if (isActive) {
return sColorAccent;
}
if (isHovered) {
return sColorGrey60;
}
return sColorGrey50;
}();
const sRGBColor borderColor = sColorWhite;
return std::make_pair(backgroundColor, borderColor);
}
/* static */
void nsNativeBasicTheme::PaintListbox(DrawTarget* aDrawTarget,
const Rect& aRect,
const EventStates& aState,
uint32_t aDpiRatio) {
const CSSCoord radius = 2.0f;
auto [unusedColor, borderColor] = ComputeButtonColors(aState);
(void)unusedColor;
auto [backgroundColor, borderColor] = ComputeTextfieldColors(aState);
PaintRoundedRectWithRadius(aDrawTarget, aRect, sColorWhite, borderColor,
PaintRoundedRectWithRadius(aDrawTarget, aRect, backgroundColor, borderColor,
kMenulistBorderWidth, radius, aDpiRatio);
if (aState.HasState(NS_EVENT_STATE_FOCUS)) {
@ -566,7 +610,6 @@ void nsNativeBasicTheme::PaintListbox(DrawTarget* aDrawTarget,
}
}
/* static */
void nsNativeBasicTheme::PaintMenulist(DrawTarget* aDrawTarget,
const Rect& aRect,
const EventStates& aState,
@ -582,7 +625,6 @@ void nsNativeBasicTheme::PaintMenulist(DrawTarget* aDrawTarget,
}
}
/* static */
void nsNativeBasicTheme::PaintArrow(
DrawTarget* aDrawTarget, const Rect& aRect, const int32_t aArrowPolygonX[],
const int32_t aArrowPolygonY[], const int32_t aArrowNumPoints,
@ -604,7 +646,6 @@ void nsNativeBasicTheme::PaintArrow(
StrokeOptions(2.0f * aDpiRatio));
}
/* static */
void nsNativeBasicTheme::PaintMenulistArrowButton(nsIFrame* aFrame,
DrawTarget* aDrawTarget,
const Rect& aRect,
@ -630,12 +671,10 @@ void nsNativeBasicTheme::PaintMenulistArrowButton(nsIFrame* aFrame,
}
RefPtr<Path> path = builder->Finish();
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
sRGBColor fillColor = isDisabled ? sColorGrey60Alpha50 : sColorGrey60;
aDrawTarget->Fill(path, ColorPattern(ToDeviceColor(fillColor)));
sRGBColor arrowColor = ComputeMenulistArrowButtonColor(aState);
aDrawTarget->Fill(path, ColorPattern(ToDeviceColor(arrowColor)));
}
/* static */
void nsNativeBasicTheme::PaintSpinnerButton(nsIFrame* aFrame,
DrawTarget* aDrawTarget,
const Rect& aRect,
@ -691,7 +730,6 @@ void nsNativeBasicTheme::PaintSpinnerButton(nsIFrame* aFrame,
aDrawTarget->Fill(path, ColorPattern(ToDeviceColor(borderColor)));
}
/* static */
void nsNativeBasicTheme::PaintRange(nsIFrame* aFrame, DrawTarget* aDrawTarget,
const Rect& aRect,
const EventStates& aState,
@ -741,11 +779,9 @@ void nsNativeBasicTheme::PaintRange(nsIFrame* aFrame, DrawTarget* aDrawTarget,
const CSSCoord borderWidth = 1.0f;
const CSSCoord radius = 2.0f;
sRGBColor progressColor, progressBorderColor;
std::tie(progressColor, progressBorderColor) =
auto [progressColor, progressBorderColor] =
ComputeRangeProgressColors(aState);
sRGBColor trackColor, trackBorderColor;
std::tie(trackColor, trackBorderColor) = ComputeRangeTrackColors(aState);
auto [trackColor, trackBorderColor] = ComputeRangeTrackColors(aState);
// Make a path that clips out the range thumb.
RefPtr<PathBuilder> builder =
@ -790,7 +826,6 @@ void nsNativeBasicTheme::PaintRange(nsIFrame* aFrame, DrawTarget* aDrawTarget,
}
}
/* static */
void nsNativeBasicTheme::PaintProgressBar(DrawTarget* aDrawTarget,
const Rect& aRect,
const EventStates& aState,
@ -803,11 +838,12 @@ void nsNativeBasicTheme::PaintProgressBar(DrawTarget* aDrawTarget,
rect.y += (rect.height - height) / 2;
rect.height = height;
PaintRoundedRectWithRadius(aDrawTarget, rect, sColorGrey10, sColorGrey40,
auto [trackColor, trackBorderColor] = ComputeProgressTrackColors();
PaintRoundedRectWithRadius(aDrawTarget, rect, trackColor, trackBorderColor,
borderWidth, radius, aDpiRatio);
}
/* static */
void nsNativeBasicTheme::PaintProgresschunk(nsIFrame* aFrame,
DrawTarget* aDrawTarget,
const Rect& aRect,
@ -845,11 +881,12 @@ void nsNativeBasicTheme::PaintProgresschunk(nsIFrame* aFrame,
RectCornerRadii(radius, progressEndRadius, progressEndRadius, radius);
}
PaintRoundedRect(aDrawTarget, rect, sColorAccent, sColorAccentDark,
auto [progressColor, progressBorderColor] = ComputeProgressColors();
PaintRoundedRect(aDrawTarget, rect, progressColor, progressBorderColor,
borderWidth, radii, aDpiRatio);
}
/* static */
void nsNativeBasicTheme::PaintMeter(DrawTarget* aDrawTarget, const Rect& aRect,
const EventStates& aState,
uint32_t aDpiRatio) {
@ -861,11 +898,12 @@ void nsNativeBasicTheme::PaintMeter(DrawTarget* aDrawTarget, const Rect& aRect,
rect.y += (rect.height - height) / 2;
rect.height = height;
PaintRoundedRectWithRadius(aDrawTarget, rect, sColorGrey10, sColorGrey40,
auto [backgroundColor, borderColor] = ComputeMeterTrackColors();
PaintRoundedRectWithRadius(aDrawTarget, rect, backgroundColor, borderColor,
borderWidth, radius, aDpiRatio);
}
/* static */
void nsNativeBasicTheme::PaintMeterchunk(nsIFrame* aFrame,
DrawTarget* aDrawTarget,
const Rect& aRect,
@ -905,20 +943,8 @@ void nsNativeBasicTheme::PaintMeterchunk(nsIFrame* aFrame,
RectCornerRadii(radius, progressEndRadius, progressEndRadius, radius);
}
sRGBColor borderColor = sColorMeterGreen20;
sRGBColor chunkColor = sColorMeterGreen10;
double optimum = meter->Optimum();
if (value < optimum) {
double low = meter->Low();
if (value < low) {
borderColor = sColorMeterRed20;
chunkColor = sColorMeterRed10;
} else {
borderColor = sColorMeterYellow20;
chunkColor = sColorMeterYellow10;
}
}
auto [chunkColor, borderColor] =
ComputeMeterchunkColors(value, meter->Optimum(), meter->Low());
PaintRoundedRect(aDrawTarget, rect, chunkColor, borderColor, borderWidth,
radii, aDpiRatio);
@ -939,55 +965,6 @@ void nsNativeBasicTheme::PaintButton(nsIFrame* aFrame, DrawTarget* aDrawTarget,
}
}
sRGBColor nsNativeBasicTheme::ComputeScrollbarthumbColor(
const ComputedStyle& aStyle, const EventStates& aElementState,
const EventStates& aDocumentState) {
const nsStyleUI* ui = aStyle.StyleUI();
nscolor color;
if (ui->mScrollbarColor.IsColors()) {
color = ui->mScrollbarColor.AsColors().thumb.CalcColor(aStyle);
} else if (aDocumentState.HasAllStates(NS_DOCUMENT_STATE_WINDOW_INACTIVE)) {
color = LookAndFeel::GetColor(
LookAndFeel::ColorID::ThemedScrollbarThumbInactive,
sScrollbarThumbColor.ToABGR());
} else if (aElementState.HasAllStates(NS_EVENT_STATE_ACTIVE)) {
color =
LookAndFeel::GetColor(LookAndFeel::ColorID::ThemedScrollbarThumbActive,
sScrollbarThumbColorActive.ToABGR());
} else if (aElementState.HasAllStates(NS_EVENT_STATE_HOVER)) {
color =
LookAndFeel::GetColor(LookAndFeel::ColorID::ThemedScrollbarThumbHover,
sScrollbarThumbColorHover.ToABGR());
} else {
color = LookAndFeel::GetColor(LookAndFeel::ColorID::ThemedScrollbarThumb,
sScrollbarThumbColor.ToABGR());
}
return gfx::sRGBColor::FromABGR(color);
}
sRGBColor nsNativeBasicTheme::ComputeScrollbarColor(
const ComputedStyle& aStyle, const EventStates& aDocumentState,
bool aIsRoot) {
const nsStyleUI* ui = aStyle.StyleUI();
nscolor color;
if (ui->mScrollbarColor.IsColors()) {
color = ui->mScrollbarColor.AsColors().track.CalcColor(aStyle);
} else if (aDocumentState.HasAllStates(NS_DOCUMENT_STATE_WINDOW_INACTIVE)) {
color = LookAndFeel::GetColor(LookAndFeel::ColorID::ThemedScrollbarInactive,
sScrollbarColor.ToABGR());
} else {
color = LookAndFeel::GetColor(LookAndFeel::ColorID::ThemedScrollbar,
sScrollbarColor.ToABGR());
}
if (aIsRoot) {
// Root scrollbars must be opaque.
nscolor bg = LookAndFeel::GetColor(LookAndFeel::ColorID::WindowBackground,
NS_RGB(0xff, 0xff, 0xff));
color = NS_ComposeColors(bg, color);
}
return gfx::sRGBColor::FromABGR(color);
}
void nsNativeBasicTheme::PaintScrollbarThumb(DrawTarget* aDrawTarget,
const Rect& aRect,
bool aHorizontal, nsIFrame* aFrame,
@ -1182,7 +1159,7 @@ nsNativeBasicTheme::DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
auto rect = FixAspectRatio(devPxRect);
PaintRadioControl(dt, rect, eventState, dpiRatio);
if (IsSelected(aFrame)) {
PaintRadioCheckMark(dt, rect, eventState, dpiRatio);
PaintRadioCheckmark(dt, rect, eventState, dpiRatio);
}
break;
}

Просмотреть файл

@ -187,8 +187,6 @@ class nsNativeBasicTheme : protected nsNativeTheme, public nsITheme {
static bool IsDateTimeTextField(nsIFrame* aFrame);
static bool IsColorPickerButton(nsIFrame* aFrame);
static bool IsRootScrollbar(nsIFrame* aFrame);
static std::pair<sRGBColor, sRGBColor> ComputeCheckColors(
const EventStates& aState);
static Rect FixAspectRatio(const Rect& aRect);
// This pushes and pops a clip rect to the draw target.
@ -213,96 +211,99 @@ class nsNativeBasicTheme : protected nsNativeTheme, public nsITheme {
static void GetFocusStrokeRect(DrawTarget* aDrawTarget, Rect& aFocusRect,
CSSCoord aOffset, const CSSCoord aRadius,
CSSCoord aFocusWidth, RefPtr<Path>& aOutRect);
static void PaintRoundedFocusRect(DrawTarget* aDrawTarget, const Rect& aRect,
uint32_t aDpiRatio, CSSCoord aRadius,
CSSCoord aOffset);
static void PaintRoundedRect(DrawTarget* aDrawTarget, const Rect& aRect,
const sRGBColor& aBackgroundColor,
const sRGBColor& aBorderColor,
CSSCoord aBorderWidth,
RectCornerRadii aDpiAdjustedRadii,
uint32_t aDpiRatio);
static void PaintRoundedRectWithRadius(DrawTarget* aDrawTarget,
const Rect& aRect,
const sRGBColor& aBackgroundColor,
const sRGBColor& aBorderColor,
CSSCoord aBorderWidth,
CSSCoord aRadius, uint32_t aDpiRatio);
static void PaintCheckboxControl(DrawTarget* aDrawTarget, const Rect& aRect,
const EventStates& aState,
uint32_t aDpiRatio);
static void PaintCheckMark(DrawTarget* aDrawTarget, const Rect& aRect,
const EventStates& aState, uint32_t aDpiRatio);
static void PaintIndeterminateMark(DrawTarget* aDrawTarget, const Rect& aRect,
const EventStates& aState,
uint32_t aDpiRatio);
static void PaintStrokedEllipse(DrawTarget* aDrawTarget, const Rect& aRect,
virtual std::pair<sRGBColor, sRGBColor> ComputeCheckboxColors(
const EventStates& aState);
virtual sRGBColor ComputeCheckmarkColor(const EventStates& aState);
virtual std::pair<sRGBColor, sRGBColor> ComputeRadioCheckmarkColors(
const EventStates& aState);
virtual sRGBColor ComputeBorderColor(const EventStates& aState);
virtual std::pair<sRGBColor, sRGBColor> ComputeButtonColors(
const EventStates& aState, nsIFrame* aFrame = nullptr);
virtual std::pair<sRGBColor, sRGBColor> ComputeTextfieldColors(
const EventStates& aState);
virtual std::pair<sRGBColor, sRGBColor> ComputeRangeProgressColors(
const EventStates& aState);
virtual std::pair<sRGBColor, sRGBColor> ComputeRangeTrackColors(
const EventStates& aState);
virtual std::pair<sRGBColor, sRGBColor> ComputeRangeThumbColors(
const EventStates& aState);
virtual std::pair<sRGBColor, sRGBColor> ComputeProgressColors();
virtual std::pair<sRGBColor, sRGBColor> ComputeProgressTrackColors();
virtual std::pair<sRGBColor, sRGBColor> ComputeMeterchunkColors(
const double aValue, const double aOptimum, const double aLow);
virtual std::pair<sRGBColor, sRGBColor> ComputeMeterTrackColors();
virtual sRGBColor ComputeMenulistArrowButtonColor(const EventStates& aState);
virtual std::array<sRGBColor, 3> ComputeFocusRectColors();
virtual sRGBColor ComputeScrollbarthumbColor(
const ComputedStyle& aStyle, const EventStates& aElementState,
const EventStates& aDocumentState);
virtual sRGBColor ComputeScrollbarColor(const ComputedStyle& aStyle,
const EventStates& aDocumentState,
bool aIsRoot);
void PaintRoundedFocusRect(DrawTarget* aDrawTarget, const Rect& aRect,
uint32_t aDpiRatio, CSSCoord aRadius,
CSSCoord aOffset);
void PaintRoundedRect(DrawTarget* aDrawTarget, const Rect& aRect,
const sRGBColor& aBackgroundColor,
const sRGBColor& aBorderColor, CSSCoord aBorderWidth,
RectCornerRadii aDpiAdjustedRadii, uint32_t aDpiRatio);
void PaintRoundedRectWithRadius(DrawTarget* aDrawTarget, const Rect& aRect,
const sRGBColor& aBackgroundColor,
const sRGBColor& aBorderColor,
const CSSCoord aBorderWidth,
CSSCoord aBorderWidth, CSSCoord aRadius,
uint32_t aDpiRatio);
static void PaintEllipseShadow(DrawTarget* aDrawTarget, const Rect& aRect,
float aShadowAlpha, const Point& aShadowOffset,
float aShadowBlurStdDev, uint32_t aDpiRatio);
static void PaintRadioControl(DrawTarget* aDrawTarget, const Rect& aRect,
const EventStates& aState, uint32_t aDpiRatio);
static void PaintRadioCheckMark(DrawTarget* aDrawTarget, const Rect& aRect,
const EventStates& aState,
uint32_t aDpiRatio);
static sRGBColor ComputeBorderColor(const EventStates& aState);
static void PaintTextField(DrawTarget* aDrawTarget, const Rect& aRect,
const EventStates& aState, uint32_t aDpiRatio);
static std::pair<sRGBColor, sRGBColor> ComputeButtonColors(
const EventStates& aState, nsIFrame* aFrame = nullptr);
static sRGBColor ComputeRangeProgressBorderColor(const EventStates& aState);
static sRGBColor ComputeRangeTrackBorderColor(const EventStates& aState);
static std::pair<sRGBColor, sRGBColor> ComputeRangeProgressColors(
const EventStates& aState);
static std::pair<sRGBColor, sRGBColor> ComputeRangeTrackColors(
const EventStates& aState);
static std::pair<sRGBColor, sRGBColor> ComputeRangeThumbColors(
const EventStates& aState);
static sRGBColor ComputeScrollbarColor(const ComputedStyle& aStyle,
const EventStates& aDocumentState,
bool aIsRoot);
static sRGBColor ComputeScrollbarthumbColor(
const ComputedStyle& aStyle, const EventStates& aState,
const EventStates& aDocumentState);
static void PaintListbox(DrawTarget* aDrawTarget, const Rect& aRect,
const EventStates& aState, uint32_t aDpiRatio);
static void PaintMenulist(DrawTarget* aDrawTarget, const Rect& aRect,
void PaintCheckboxControl(DrawTarget* aDrawTarget, const Rect& aRect,
const EventStates& aState, uint32_t aDpiRatio);
static void PaintArrow(DrawTarget* aDrawTarget, const Rect& aRect,
const int32_t aArrowPolygonX[],
const int32_t aArrowPolygonY[],
const int32_t aArrowNumPoints,
const int32_t aArrowSize, const sRGBColor aFillColor,
uint32_t aDpiRatio);
static void PaintMenulistArrowButton(nsIFrame* aFrame,
DrawTarget* aDrawTarget,
const Rect& aRect,
const EventStates& aState,
uint32_t aDpiRatio);
static void PaintSpinnerButton(nsIFrame* aFrame, DrawTarget* aDrawTarget,
const Rect& aRect, const EventStates& aState,
StyleAppearance aAppearance,
uint32_t aDpiRatio);
static void PaintRange(nsIFrame* aFrame, DrawTarget* aDrawTarget,
const Rect& aRect, const EventStates& aState,
uint32_t aDpiRatio, bool aHorizontal);
static void PaintProgressBar(DrawTarget* aDrawTarget, const Rect& aRect,
const EventStates& aState, uint32_t aDpiRatio);
static void PaintProgresschunk(nsIFrame* aFrame, DrawTarget* aDrawTarget,
const Rect& aRect, const EventStates& aState,
uint32_t aDpiRatio);
static void PaintMeter(DrawTarget* aDrawTarget, const Rect& aRect,
void PaintCheckMark(DrawTarget* aDrawTarget, const Rect& aRect,
const EventStates& aState, uint32_t aDpiRatio);
void PaintIndeterminateMark(DrawTarget* aDrawTarget, const Rect& aRect,
const EventStates& aState, uint32_t aDpiRatio);
void PaintStrokedEllipse(DrawTarget* aDrawTarget, const Rect& aRect,
const sRGBColor& aBackgroundColor,
const sRGBColor& aBorderColor,
const CSSCoord aBorderWidth, uint32_t aDpiRatio);
void PaintEllipseShadow(DrawTarget* aDrawTarget, const Rect& aRect,
float aShadowAlpha, const Point& aShadowOffset,
float aShadowBlurStdDev, uint32_t aDpiRatio);
void PaintRadioControl(DrawTarget* aDrawTarget, const Rect& aRect,
const EventStates& aState, uint32_t aDpiRatio);
static void PaintMeterchunk(nsIFrame* aFrame, DrawTarget* aDrawTarget,
const Rect& aRect, const EventStates& aState,
uint32_t aDpiRatio);
static void PaintButton(nsIFrame* aFrame, DrawTarget* aDrawTarget,
void PaintRadioCheckmark(DrawTarget* aDrawTarget, const Rect& aRect,
const EventStates& aState, uint32_t aDpiRatio);
void PaintTextField(DrawTarget* aDrawTarget, const Rect& aRect,
const EventStates& aState, uint32_t aDpiRatio);
void PaintListbox(DrawTarget* aDrawTarget, const Rect& aRect,
const EventStates& aState, uint32_t aDpiRatio);
void PaintMenulist(DrawTarget* aDrawTarget, const Rect& aRect,
const EventStates& aState, uint32_t aDpiRatio);
void PaintArrow(DrawTarget* aDrawTarget, const Rect& aRect,
const int32_t aArrowPolygonX[],
const int32_t aArrowPolygonY[], const int32_t aArrowNumPoints,
const int32_t aArrowSize, const sRGBColor aFillColor,
uint32_t aDpiRatio);
void PaintMenulistArrowButton(nsIFrame* aFrame, DrawTarget* aDrawTarget,
const Rect& aRect, const EventStates& aState,
uint32_t aDpiRatio);
void PaintSpinnerButton(nsIFrame* aFrame, DrawTarget* aDrawTarget,
const Rect& aRect, const EventStates& aState,
StyleAppearance aAppearance, uint32_t aDpiRatio);
void PaintRange(nsIFrame* aFrame, DrawTarget* aDrawTarget, const Rect& aRect,
const EventStates& aState, uint32_t aDpiRatio,
bool aHorizontal);
void PaintProgressBar(DrawTarget* aDrawTarget, const Rect& aRect,
const EventStates& aState, uint32_t aDpiRatio);
void PaintProgresschunk(nsIFrame* aFrame, DrawTarget* aDrawTarget,
const Rect& aRect, const EventStates& aState,
uint32_t aDpiRatio);
void PaintMeter(DrawTarget* aDrawTarget, const Rect& aRect,
const EventStates& aState, uint32_t aDpiRatio);
void PaintMeterchunk(nsIFrame* aFrame, DrawTarget* aDrawTarget,
const Rect& aRect, const EventStates& aState,
uint32_t aDpiRatio);
void PaintButton(nsIFrame* aFrame, DrawTarget* aDrawTarget, const Rect& aRect,
const EventStates& aState, uint32_t aDpiRatio);
virtual void PaintScrollbarThumb(DrawTarget* aDrawTarget, const Rect& aRect,
bool aHorizontal, nsIFrame* aFrame,

Просмотреть файл

@ -5,6 +5,207 @@
#include "nsNativeBasicThemeWin.h"
#include "LookAndFeel.h"
std::pair<sRGBColor, sRGBColor> nsNativeBasicThemeWin::ComputeCheckboxColors(
const EventStates& aState) {
if (!LookAndFeel::GetInt(LookAndFeel::IntID::UseAccessibilityTheme, 0)) {
return nsNativeBasicTheme::ComputeCheckboxColors(aState);
}
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
bool isChecked = aState.HasState(NS_EVENT_STATE_CHECKED);
sRGBColor backgroundColor = sRGBColor::FromABGR(
LookAndFeel::GetColor(LookAndFeel::ColorID::TextBackground));
sRGBColor borderColor = sRGBColor::FromABGR(
LookAndFeel::GetColor(LookAndFeel::ColorID::Buttontext));
if (isDisabled && isChecked) {
backgroundColor = borderColor = sRGBColor::FromABGR(
LookAndFeel::GetColor(LookAndFeel::ColorID::Graytext));
} else if (isDisabled) {
borderColor = sRGBColor::FromABGR(
LookAndFeel::GetColor(LookAndFeel::ColorID::Graytext));
} else if (isChecked) {
backgroundColor = borderColor = sRGBColor::FromABGR(
LookAndFeel::GetColor(LookAndFeel::ColorID::Highlight));
}
return std::make_pair(backgroundColor, borderColor);
}
sRGBColor nsNativeBasicThemeWin::ComputeCheckmarkColor(
const EventStates& aState) {
if (!LookAndFeel::GetInt(LookAndFeel::IntID::UseAccessibilityTheme, 0)) {
return nsNativeBasicTheme::ComputeCheckmarkColor(aState);
}
return sRGBColor::FromABGR(
LookAndFeel::GetColor(LookAndFeel::ColorID::TextBackground));
}
std::pair<sRGBColor, sRGBColor>
nsNativeBasicThemeWin::ComputeRadioCheckmarkColors(const EventStates& aState) {
if (!LookAndFeel::GetInt(LookAndFeel::IntID::UseAccessibilityTheme, 0)) {
return nsNativeBasicTheme::ComputeRadioCheckmarkColors(aState);
}
auto [unusedColor, checkColor] = ComputeCheckboxColors(aState);
(void)unusedColor;
sRGBColor backgroundColor = ComputeCheckmarkColor(aState);
return std::make_pair(backgroundColor, checkColor);
}
sRGBColor nsNativeBasicThemeWin::ComputeBorderColor(const EventStates& aState) {
if (!LookAndFeel::GetInt(LookAndFeel::IntID::UseAccessibilityTheme, 0)) {
return nsNativeBasicTheme::ComputeBorderColor(aState);
}
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
if (isDisabled) {
return sRGBColor::FromABGR(
LookAndFeel::GetColor(LookAndFeel::ColorID::Graytext));
}
return sRGBColor::FromABGR(
LookAndFeel::GetColor(LookAndFeel::ColorID::Buttontext));
}
std::pair<sRGBColor, sRGBColor> nsNativeBasicThemeWin::ComputeButtonColors(
const EventStates& aState, nsIFrame* aFrame) {
if (!LookAndFeel::GetInt(LookAndFeel::IntID::UseAccessibilityTheme, 0)) {
return nsNativeBasicTheme::ComputeButtonColors(aState, aFrame);
}
return std::make_pair(sRGBColor::FromABGR(LookAndFeel::GetColor(
LookAndFeel::ColorID::Buttonface)),
ComputeBorderColor(aState));
}
std::pair<sRGBColor, sRGBColor> nsNativeBasicThemeWin::ComputeTextfieldColors(
const EventStates& aState) {
if (!LookAndFeel::GetInt(LookAndFeel::IntID::UseAccessibilityTheme, 0)) {
return nsNativeBasicTheme::ComputeTextfieldColors(aState);
}
return std::make_pair(sRGBColor::FromABGR(LookAndFeel::GetColor(
LookAndFeel::ColorID::TextBackground)),
ComputeBorderColor(aState));
}
std::pair<sRGBColor, sRGBColor>
nsNativeBasicThemeWin::ComputeRangeProgressColors(const EventStates& aState) {
if (!LookAndFeel::GetInt(LookAndFeel::IntID::UseAccessibilityTheme, 0)) {
return nsNativeBasicTheme::ComputeRangeProgressColors(aState);
}
return std::make_pair(sRGBColor::FromABGR(LookAndFeel::GetColor(
LookAndFeel::ColorID::Highlight)),
sRGBColor::FromABGR(LookAndFeel::GetColor(
LookAndFeel::ColorID::Buttontext)));
}
std::pair<sRGBColor, sRGBColor> nsNativeBasicThemeWin::ComputeRangeTrackColors(
const EventStates& aState) {
if (!LookAndFeel::GetInt(LookAndFeel::IntID::UseAccessibilityTheme, 0)) {
return nsNativeBasicTheme::ComputeRangeTrackColors(aState);
}
return std::make_pair(sRGBColor::FromABGR(LookAndFeel::GetColor(
LookAndFeel::ColorID::TextBackground)),
sRGBColor::FromABGR(LookAndFeel::GetColor(
LookAndFeel::ColorID::Buttontext)));
}
std::pair<sRGBColor, sRGBColor> nsNativeBasicThemeWin::ComputeRangeThumbColors(
const EventStates& aState) {
if (!LookAndFeel::GetInt(LookAndFeel::IntID::UseAccessibilityTheme, 0)) {
return nsNativeBasicTheme::ComputeRangeThumbColors(aState);
}
return std::make_pair(sRGBColor::FromABGR(LookAndFeel::GetColor(
LookAndFeel::ColorID::Highlight)),
sRGBColor::FromABGR(LookAndFeel::GetColor(
LookAndFeel::ColorID::Highlight)));
}
std::pair<sRGBColor, sRGBColor> nsNativeBasicThemeWin::ComputeProgressColors() {
if (!LookAndFeel::GetInt(LookAndFeel::IntID::UseAccessibilityTheme, 0)) {
return nsNativeBasicTheme::ComputeProgressColors();
}
return std::make_pair(sRGBColor::FromABGR(LookAndFeel::GetColor(
LookAndFeel::ColorID::Highlight)),
sRGBColor::FromABGR(LookAndFeel::GetColor(
LookAndFeel::ColorID::Buttontext)));
}
std::pair<sRGBColor, sRGBColor>
nsNativeBasicThemeWin::ComputeProgressTrackColors() {
if (!LookAndFeel::GetInt(LookAndFeel::IntID::UseAccessibilityTheme, 0)) {
return nsNativeBasicTheme::ComputeProgressTrackColors();
}
return std::make_pair(sRGBColor::FromABGR(LookAndFeel::GetColor(
LookAndFeel::ColorID::TextBackground)),
sRGBColor::FromABGR(LookAndFeel::GetColor(
LookAndFeel::ColorID::Buttontext)));
}
std::pair<sRGBColor, sRGBColor> nsNativeBasicThemeWin::ComputeMeterchunkColors(
const double aValue, const double aOptimum, const double aLow) {
if (!LookAndFeel::GetInt(LookAndFeel::IntID::UseAccessibilityTheme, 0)) {
return nsNativeBasicTheme::ComputeMeterchunkColors(aValue, aOptimum, aLow);
}
return std::make_pair(sRGBColor::FromABGR(LookAndFeel::GetColor(
LookAndFeel::ColorID::Highlight)),
sRGBColor::FromABGR(LookAndFeel::GetColor(
LookAndFeel::ColorID::TextForeground)));
}
std::pair<sRGBColor, sRGBColor>
nsNativeBasicThemeWin::ComputeMeterTrackColors() {
if (!LookAndFeel::GetInt(LookAndFeel::IntID::UseAccessibilityTheme, 0)) {
return nsNativeBasicTheme::ComputeMeterTrackColors();
}
return std::make_pair(sRGBColor::FromABGR(LookAndFeel::GetColor(
LookAndFeel::ColorID::TextBackground)),
sRGBColor::FromABGR(LookAndFeel::GetColor(
LookAndFeel::ColorID::TextForeground)));
}
sRGBColor nsNativeBasicThemeWin::ComputeMenulistArrowButtonColor(
const EventStates& aState) {
if (!LookAndFeel::GetInt(LookAndFeel::IntID::UseAccessibilityTheme, 0)) {
return nsNativeBasicTheme::ComputeMenulistArrowButtonColor(aState);
}
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
if (isDisabled) {
return sRGBColor::FromABGR(
LookAndFeel::GetColor(LookAndFeel::ColorID::Graytext));
}
return sRGBColor::FromABGR(
LookAndFeel::GetColor(LookAndFeel::ColorID::TextForeground));
}
std::array<sRGBColor, 3> nsNativeBasicThemeWin::ComputeFocusRectColors() {
if (!LookAndFeel::GetInt(LookAndFeel::IntID::UseAccessibilityTheme, 0)) {
return nsNativeBasicTheme::ComputeFocusRectColors();
}
return {sRGBColor::FromABGR(
LookAndFeel::GetColor(LookAndFeel::ColorID::Highlight)),
sRGBColor::FromABGR(
LookAndFeel::GetColor(LookAndFeel::ColorID::Buttontext)),
sRGBColor::FromABGR(
LookAndFeel::GetColor(LookAndFeel::ColorID::TextBackground))};
}
already_AddRefed<nsITheme> do_GetBasicNativeThemeDoNotUseDirectly() {
static StaticRefPtr<nsITheme> gInstance;
if (MOZ_UNLIKELY(!gInstance)) {

Просмотреть файл

@ -15,6 +15,30 @@ class nsNativeBasicThemeWin : public nsNativeBasicTheme {
protected:
virtual ~nsNativeBasicThemeWin() = default;
std::pair<sRGBColor, sRGBColor> ComputeCheckboxColors(
const EventStates& aState) override;
sRGBColor ComputeCheckmarkColor(const EventStates& aState) override;
std::pair<sRGBColor, sRGBColor> ComputeRadioCheckmarkColors(
const EventStates& aState) override;
sRGBColor ComputeBorderColor(const EventStates& aState) override;
std::pair<sRGBColor, sRGBColor> ComputeButtonColors(
const EventStates& aState, nsIFrame* aFrame = nullptr) override;
std::pair<sRGBColor, sRGBColor> ComputeTextfieldColors(
const EventStates& aState) override;
std::pair<sRGBColor, sRGBColor> ComputeRangeProgressColors(
const EventStates& aState) override;
std::pair<sRGBColor, sRGBColor> ComputeRangeTrackColors(
const EventStates& aState) override;
std::pair<sRGBColor, sRGBColor> ComputeRangeThumbColors(
const EventStates& aState) override;
std::pair<sRGBColor, sRGBColor> ComputeProgressColors() override;
std::pair<sRGBColor, sRGBColor> ComputeProgressTrackColors() override;
std::pair<sRGBColor, sRGBColor> ComputeMeterchunkColors(
const double aValue, const double aOptimum, const double aLow) override;
std::pair<sRGBColor, sRGBColor> ComputeMeterTrackColors() override;
sRGBColor ComputeMenulistArrowButtonColor(const EventStates& aState) override;
std::array<sRGBColor, 3> ComputeFocusRectColors() override;
};
#endif