Changeset 290054 in webkit


Ignore:
Timestamp:
Feb 17, 2022, 12:41:01 PM (3 years ago)
Author:
Aditya Keerthi
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):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r290053 r290054  
     12022-02-17  Aditya Keerthi  <akeerthi@apple.com>
     2
     3        [macOS] Light appearance text fields are invisible in Increased Contrast mode
     4        https://bugs.webkit.org/show_bug.cgi?id=236753
     5        rdar://89093315
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        In Big Sur, the artwork for many form controls, including text fields, was
     10        changed at the system level. When painting native text fields, WebKit has
     11        long used the "borders only" option to support painting custom background
     12        colors. System-level changes in Big Sur broke the behavior of light appearance
     13        "borders only" text fields in Increased Contrast mode.
     14
     15        Until the artwork is updated at the system-level, work around the issue
     16        in WebKit by painting our own borders for text fields under the necessary
     17        conditions.
     18
     19        No new tests, as tests that change system preferences are often unreliable,
     20        and we do not have existing hooks to toggle Increased Contrast mode.
     21
     22        * rendering/RenderThemeMac.h:
     23        * rendering/RenderThemeMac.mm:
     24        (WebCore::RenderThemeMac::shouldPaintCustomTextField const):
     25        (WebCore::RenderThemeMac::paintTextField):
     26
    1272022-02-17  Commit Queue  <commit-queue@webkit.org>
    228
  • trunk/Source/WebCore/rendering/RenderThemeMac.h

    r290053 r290054  
    166166    String fileListNameForWidth(const FileList*, const FontCascade&, int width, bool multipleFilesAllowed) const final;
    167167
     168    bool shouldPaintCustomTextField(const RenderObject&) const;
     169
    168170    Color systemColor(CSSValueID, OptionSet<StyleColorOptions>) const final;
    169171
  • trunk/Source/WebCore/rendering/RenderThemeMac.mm

    r290053 r290054  
    10961096#endif
    10971097
     1098bool RenderThemeMac::shouldPaintCustomTextField(const RenderObject& renderer) const
     1099{
     1100    // <rdar://problem/88948646> Prevent AppKit from painting text fields in the light appearance
     1101    // with increased contrast, as the border is not painted, rendering the control invisible.
     1102#if HAVE(LARGE_CONTROL_SIZE)
     1103    return Theme::singleton().userPrefersContrast() && !renderer.useDarkAppearance();
     1104#else
     1105    UNUSED_PARAM(renderer);
     1106    return false;
     1107#endif
     1108}
     1109
    10981110bool RenderThemeMac::paintTextField(const RenderObject& o, const PaintInfo& paintInfo, const FloatRect& r)
    10991111{
    1100     LocalCurrentGraphicsContext localContext(paintInfo.context());
    1101 
    1102     // <rdar://problem/22896977> We adjust the paint rect here to account for how AppKit draws the text
    1103     // field cell slightly smaller than the rect we pass to drawWithFrame.
    1104     FloatRect adjustedPaintRect(r);
    1105     AffineTransform transform = paintInfo.context().getCTM();
    1106     if (transform.xScale() > 1 || transform.yScale() > 1) {
    1107         adjustedPaintRect.inflateX(1 / transform.xScale());
    1108         adjustedPaintRect.inflateY(2 / transform.yScale());
    1109         adjustedPaintRect.move(0, -1 / transform.yScale());
    1110     }
    1111     NSTextFieldCell *textField = this->textField();
    1112 
    1113     GraphicsContextStateSaver stateSaver(paintInfo.context());
    1114 
    1115     [textField setEnabled:(isEnabled(o) && !isReadOnlyControl(o))];
    1116     [textField drawWithFrame:NSRect(adjustedPaintRect) inView:documentViewFor(o)];
    1117 
    1118     [textField setControlView:nil];
     1112    FloatRect paintRect(r);
     1113    auto& context = paintInfo.context();
     1114
     1115    LocalCurrentGraphicsContext localContext(context);
     1116    GraphicsContextStateSaver stateSaver(context);
     1117
     1118    auto enabled = isEnabled(o) && !isReadOnlyControl(o);
     1119
     1120    if (shouldPaintCustomTextField(o)) {
     1121        constexpr int strokeThickness = 1;
     1122
     1123        FloatRect strokeRect(paintRect);
     1124        strokeRect.inflate(-strokeThickness / 2.0f);
     1125
     1126        context.setStrokeColor(enabled ? Color::black : Color::darkGray);
     1127        context.setStrokeStyle(SolidStroke);
     1128        context.strokeRect(strokeRect, strokeThickness);
     1129    } else {
     1130        // <rdar://problem/22896977> We adjust the paint rect here to account for how AppKit draws the text
     1131        // field cell slightly smaller than the rect we pass to drawWithFrame.
     1132        AffineTransform transform = context.getCTM();
     1133        if (transform.xScale() > 1 || transform.yScale() > 1) {
     1134            paintRect.inflateX(1 / transform.xScale());
     1135            paintRect.inflateY(2 / transform.yScale());
     1136            paintRect.move(0, -1 / transform.yScale());
     1137        }
     1138
     1139        NSTextFieldCell *textField = this->textField();
     1140        [textField setEnabled:enabled];
     1141        [textField drawWithFrame:NSRect(paintRect) inView:documentViewFor(o)];
     1142        [textField setControlView:nil];
     1143    }
    11191144
    11201145#if ENABLE(DATALIST_ELEMENT)
     
    11241149    const auto& input = downcast<HTMLInputElement>(*(o.generatingNode()));
    11251150    if (input.list())
    1126         paintListButtonForInput(o, paintInfo.context(), adjustedPaintRect);
     1151        paintListButtonForInput(o, context, paintRect);
    11271152#endif
    11281153
Note: See TracChangeset for help on using the changeset viewer.