Skip to content
Permalink
Browse files
[macOS] Light appearance text fields are invisible in Increased Contr…
…ast mode

https://bugs.webkit.org/show_bug.cgi?id=236753
rdar://89093315

Reviewed by Wenson Hsieh.

In Big Sur, the artwork for many form controls, including text fields, was
changed at the system level. When painting native text fields, WebKit has
long used the "borders only" option to support painting custom background
colors. System-level changes in Big Sur broke the behavior of light appearance
"borders only" text fields in Increased Contrast mode.

Until the artwork is updated at the system-level, work around the issue
in WebKit by painting our own borders for text fields under the necessary
conditions.

No new tests, as tests that change system preferences are often unreliable,
and we do not have existing hooks to toggle Increased Contrast mode.

* rendering/RenderThemeMac.h:
* rendering/RenderThemeMac.mm:
(WebCore::RenderThemeMac::shouldPaintCustomTextField const):
(WebCore::RenderThemeMac::paintTextField):



Canonical link: https://commits.webkit.org/247418@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@290046 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
pxlcoder committed Feb 17, 2022
1 parent dc13e59 commit 1df7e227f14a6e4f068efd66566aa8aea43e4897
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 17 deletions.
@@ -1,3 +1,29 @@
2022-02-17 Aditya Keerthi <akeerthi@apple.com>

[macOS] Light appearance text fields are invisible in Increased Contrast mode
https://bugs.webkit.org/show_bug.cgi?id=236753
rdar://89093315

Reviewed by Wenson Hsieh.

In Big Sur, the artwork for many form controls, including text fields, was
changed at the system level. When painting native text fields, WebKit has
long used the "borders only" option to support painting custom background
colors. System-level changes in Big Sur broke the behavior of light appearance
"borders only" text fields in Increased Contrast mode.

Until the artwork is updated at the system-level, work around the issue
in WebKit by painting our own borders for text fields under the necessary
conditions.

No new tests, as tests that change system preferences are often unreliable,
and we do not have existing hooks to toggle Increased Contrast mode.

* rendering/RenderThemeMac.h:
* rendering/RenderThemeMac.mm:
(WebCore::RenderThemeMac::shouldPaintCustomTextField const):
(WebCore::RenderThemeMac::paintTextField):

2022-02-17 Alexander Mikhaylenko <alexm@gnome.org>

[GTK] REGRESSION: Cumulative velocity for scrolling doesn't work
@@ -165,6 +165,8 @@ class RenderThemeMac final : public RenderThemeCocoa {
private:
String fileListNameForWidth(const FileList*, const FontCascade&, int width, bool multipleFilesAllowed) const final;

bool shouldPaintCustomTextField(const RenderObject&) const;

Color systemColor(CSSValueID, OptionSet<StyleColorOptions>) const final;

// Get the control size based off the font. Used by some of the controls (like buttons).
@@ -1095,35 +1095,59 @@ static FloatPoint convertToPaintingPosition(const RenderBox& inputRenderer, cons
}
#endif

bool RenderThemeMac::paintTextField(const RenderObject& o, const PaintInfo& paintInfo, const FloatRect& r)
bool RenderThemeMac::shouldPaintCustomTextField(const RenderObject& renderer) const
{
LocalCurrentGraphicsContext localContext(paintInfo.context());
// <rdar://problem/88948646> Prevent AppKit from painting textfields in the light appearance
// with increased contrast, as the border is not painted, rendering the control invisible.
#if HAVE_LARGE_CONTROL_SIZE
return Theme::singleton().userPrefersContrast() && !renderer.useDarkAppearance();
#else
return false;
#endif
}

// <rdar://problem/22896977> We adjust the paint rect here to account for how AppKit draws the text
// field cell slightly smaller than the rect we pass to drawWithFrame.
FloatRect adjustedPaintRect(r);
AffineTransform transform = paintInfo.context().getCTM();
if (transform.xScale() > 1 || transform.yScale() > 1) {
adjustedPaintRect.inflateX(1 / transform.xScale());
adjustedPaintRect.inflateY(2 / transform.yScale());
adjustedPaintRect.move(0, -1 / transform.yScale());
}
NSTextFieldCell *textField = this->textField();
bool RenderThemeMac::paintTextField(const RenderObject& o, const PaintInfo& paintInfo, const FloatRect& r)
{
FloatRect paintRect(r);
auto& context = paintInfo.context();

GraphicsContextStateSaver stateSaver(paintInfo.context());
LocalCurrentGraphicsContext localContext(context);
GraphicsContextStateSaver stateSaver(context);

[textField setEnabled:(isEnabled(o) && !isReadOnlyControl(o))];
[textField drawWithFrame:NSRect(adjustedPaintRect) inView:documentViewFor(o)];
auto enabled = isEnabled(o) && !isReadOnlyControl(o);

if (shouldPaintCustomTextField(o)) {
constexpr int strokeThickness = 1;

FloatRect strokeRect(paintRect);
strokeRect.inflate(-strokeThickness / 2.0f);

context.setStrokeColor(enabled ? Color::black : Color::darkGray);
context.setStrokeStyle(SolidStroke);
context.strokeRect(strokeRect, strokeThickness);
} else {
// <rdar://problem/22896977> We adjust the paint rect here to account for how AppKit draws the text
// field cell slightly smaller than the rect we pass to drawWithFrame.
AffineTransform transform = context.getCTM();
if (transform.xScale() > 1 || transform.yScale() > 1) {
paintRect.inflateX(1 / transform.xScale());
paintRect.inflateY(2 / transform.yScale());
paintRect.move(0, -1 / transform.yScale());
}

[textField setControlView:nil];
NSTextFieldCell *textField = this->textField();
[textField setEnabled:enabled];
[textField drawWithFrame:NSRect(paintRect) inView:documentViewFor(o)];
[textField setControlView:nil];
}

#if ENABLE(DATALIST_ELEMENT)
if (!is<HTMLInputElement>(o.generatingNode()))
return false;

const auto& input = downcast<HTMLInputElement>(*(o.generatingNode()));
if (input.list())
paintListButtonForInput(o, paintInfo.context(), adjustedPaintRect);
paintListButtonForInput(o, context, paintRect);
#endif

return false;

0 comments on commit 1df7e22

Please sign in to comment.