Title: [290062] branches/safari-613.1.17.1-branch/Source/WebCore
Revision
290062
Author
[email protected]
Date
2022-02-17 13:01:18 -0800 (Thu, 17 Feb 2022)

Log Message

Cherry-pick r290054. rdar://problem/89093315

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

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@290054 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-613.1.17.1-branch/Source/WebCore/ChangeLog (290061 => 290062)


--- branches/safari-613.1.17.1-branch/Source/WebCore/ChangeLog	2022-02-17 21:01:15 UTC (rev 290061)
+++ branches/safari-613.1.17.1-branch/Source/WebCore/ChangeLog	2022-02-17 21:01:18 UTC (rev 290062)
@@ -1,5 +1,62 @@
 2022-02-17  Russell Epstein  <[email protected]>
 
+        Cherry-pick r290054. rdar://problem/89093315
+
+    [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):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@290054 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2022-02-17  Aditya Keerthi  <[email protected]>
+
+            [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  Russell Epstein  <[email protected]>
+
         Cherry-pick r290005. rdar://problem/87596724
 
     CrashTracer: com.apple.WebKit.WebContent at _javascript_Core: bmalloc_allocate_impl_impl_slow

Modified: branches/safari-613.1.17.1-branch/Source/WebCore/rendering/RenderThemeMac.h (290061 => 290062)


--- branches/safari-613.1.17.1-branch/Source/WebCore/rendering/RenderThemeMac.h	2022-02-17 21:01:15 UTC (rev 290061)
+++ branches/safari-613.1.17.1-branch/Source/WebCore/rendering/RenderThemeMac.h	2022-02-17 21:01:18 UTC (rev 290062)
@@ -163,6 +163,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: branches/safari-613.1.17.1-branch/Source/WebCore/rendering/RenderThemeMac.mm (290061 => 290062)


--- branches/safari-613.1.17.1-branch/Source/WebCore/rendering/RenderThemeMac.mm	2022-02-17 21:01:15 UTC (rev 290061)
+++ branches/safari-613.1.17.1-branch/Source/WebCore/rendering/RenderThemeMac.mm	2022-02-17 21:01:18 UTC (rev 290062)
@@ -1095,28 +1095,53 @@
 }
 #endif
 
+bool RenderThemeMac::shouldPaintCustomTextField(const RenderObject& renderer) const
+{
+    // <rdar://problem/88948646> Prevent AppKit from painting text fields 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
+    UNUSED_PARAM(renderer);
+    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 +1148,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
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to