Title: [290046] trunk/Source/WebCore
Revision
290046
Author
akeer...@apple.com
Date
2022-02-17 12:04:07 -0800 (Thu, 17 Feb 2022)

Log Message

[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):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (290045 => 290046)


--- trunk/Source/WebCore/ChangeLog	2022-02-17 20:02:04 UTC (rev 290045)
+++ trunk/Source/WebCore/ChangeLog	2022-02-17 20:04:07 UTC (rev 290046)
@@ -1,3 +1,29 @@
+2022-02-17  Aditya Keerthi  <akeer...@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  <al...@gnome.org>
 
         [GTK] REGRESSION: Cumulative velocity for scrolling doesn't work

Modified: trunk/Source/WebCore/rendering/RenderThemeMac.h (290045 => 290046)


--- trunk/Source/WebCore/rendering/RenderThemeMac.h	2022-02-17 20:02:04 UTC (rev 290045)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.h	2022-02-17 20:04:07 UTC (rev 290046)
@@ -165,6 +165,8 @@
 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).

Modified: trunk/Source/WebCore/rendering/RenderThemeMac.mm (290045 => 290046)


--- trunk/Source/WebCore/rendering/RenderThemeMac.mm	2022-02-17 20:02:04 UTC (rev 290045)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.mm	2022-02-17 20:04:07 UTC (rev 290046)
@@ -1095,28 +1095,52 @@
 }
 #endif
 
+bool RenderThemeMac::shouldPaintCustomTextField(const RenderObject& renderer) const
+{
+    // <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
+}
+
 bool RenderThemeMac::paintTextField(const RenderObject& o, const PaintInfo& paintInfo, const FloatRect& r)
 {
-    LocalCurrentGraphicsContext localContext(paintInfo.context());
+    FloatRect paintRect(r);
+    auto& context = paintInfo.context();
 
-    // <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();
+    LocalCurrentGraphicsContext localContext(context);
+    GraphicsContextStateSaver stateSaver(context);
 
-    GraphicsContextStateSaver stateSaver(paintInfo.context());
+    auto enabled = isEnabled(o) && !isReadOnlyControl(o);
 
-    [textField setEnabled:(isEnabled(o) && !isReadOnlyControl(o))];
-    [textField drawWithFrame:NSRect(adjustedPaintRect) inView:documentViewFor(o)];
+    if (shouldPaintCustomTextField(o)) {
+        constexpr int strokeThickness = 1;
 
-    [textField setControlView:nil];
+        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());
+        }
+
+        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;
@@ -1123,7 +1147,7 @@
 
     const auto& input = downcast<HTMLInputElement>(*(o.generatingNode()));
     if (input.list())
-        paintListButtonForInput(o, paintInfo.context(), adjustedPaintRect);
+        paintListButtonForInput(o, context, paintRect);
 #endif
 
     return false;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to