Skip to content

Commit

Permalink
REGRESSION(266134@main): 3D border-style have very low contrast with …
Browse files Browse the repository at this point in the history
…very dark border-color

https://bugs.webkit.org/show_bug.cgi?id=261847
rdar://115812372

Reviewed by Darin Adler.

266134@main made 3D border styles like groove, ridge, inset, and outset honor the border-color instead of hardcoding a gray color.

Unfortunately, when a dark border-color is used, there is very little contrast between the light border and the dark border.

To fix this, we follow Firefox's algorithm of special casing very dark colors by contrasting 2 lightened versions of the border-color.

See Firefox's algorithm for reference:
https://searchfox.org/mozilla-central/rev/077fc34d03b85b09add26b5f99f1a3a3a72c8720/gfx/wr/webrender/res/cs_border_segment.glsl#112-132

* Source/WebCore/display/css/DisplayBoxDecorationPainter.cpp:
(WebCore::Display::BorderPainter::calculateBorderStyleColor):
* Source/WebCore/rendering/BorderPainter.cpp:
(WebCore::BorderPainter::calculateBorderStyleColor):

Canonical link: https://commits.webkit.org/268265@main
  • Loading branch information
nt1m committed Sep 21, 2023
1 parent 5faeb73 commit a449701
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
22 changes: 16 additions & 6 deletions Source/WebCore/display/css/DisplayBoxDecorationPainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,24 @@ void BorderPainter::calculateBorderStyleColor(BorderStyle style, BoxSide side, C

Operation operation = (side == BoxSide::Top || side == BoxSide::Left) == (style == BorderStyle::Inset) ? Darken : Lighten;

// Here we will darken the border decoration color when needed. This will yield a similar behavior as in FF.
bool isVeryDarkColor = color.luminance() <= baseDarkColorLuminance;
bool isVeryLightColor = color.luminance() > baseLightColorLuminance;

// Special case very dark colors to give them extra contrast.
if (isVeryDarkColor) {
color = operation == Darken ? color.lightened() : color.lightened().lightened();
return;
}

// Here we will darken the border decoration color when needed.
if (operation == Darken) {
if (color.luminance() > baseDarkColorLuminance)
color = color.darkened();
} else {
if (color.luminance() < baseLightColorLuminance)
color = color.lightened();
color = color.darkened();
return;
}

ASSERT(operation == Lighten);

color = isVeryLightColor ? color : color.lightened();
}

// This assumes that we draw in order: top, bottom, left, right.
Expand Down
23 changes: 14 additions & 9 deletions Source/WebCore/rendering/BorderPainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1422,15 +1422,20 @@ Color BorderPainter::calculateBorderStyleColor(const BorderStyle& style, const B

Operation operation = (side == BoxSide::Top || side == BoxSide::Left) == (style == BorderStyle::Inset) ? Darken : Lighten;

// Here we will darken the border decoration color when needed. This will yield a similar behavior as in FF.
if (operation == Darken) {
if (color.luminance() > baseDarkColorLuminance)
return color.darkened();
} else {
if (color.luminance() < baseLightColorLuminance)
return color.lightened();
}
return color;
bool isVeryDarkColor = color.luminance() <= baseDarkColorLuminance;
bool isVeryLightColor = color.luminance() > baseLightColorLuminance;

// Special case very dark colors to give them extra contrast.
if (isVeryDarkColor)
return operation == Darken ? color.lightened() : color.lightened().lightened();

// Here we will darken the border decoration color when needed.
if (operation == Darken)
return color.darkened();

ASSERT(operation == Lighten);

return isVeryLightColor ? color : color.lightened();
}

const Document& BorderPainter::document() const
Expand Down

0 comments on commit a449701

Please sign in to comment.