Bug 214226 - Tidy up color usage in accessibility code
Summary: Tidy up color usage in accessibility code
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Sam Weinig
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-07-11 20:20 PDT by Sam Weinig
Modified: 2020-07-12 12:47 PDT (History)
10 users (show)

See Also:


Attachments
Patch (8.64 KB, patch)
2020-07-11 20:22 PDT, Sam Weinig
no flags Details | Formatted Diff | Diff
Patch (9.44 KB, patch)
2020-07-12 09:43 PDT, Sam Weinig
no flags Details | Formatted Diff | Diff
Patch (9.46 KB, patch)
2020-07-12 10:56 PDT, Sam Weinig
no flags Details | Formatted Diff | Diff
Patch (9.37 KB, patch)
2020-07-12 11:00 PDT, Sam Weinig
no flags Details | Formatted Diff | Diff
Patch (9.37 KB, patch)
2020-07-12 11:03 PDT, Sam Weinig
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sam Weinig 2020-07-11 20:20:54 PDT
Tidy up color usage in accessibility code
Comment 1 Sam Weinig 2020-07-11 20:22:35 PDT Comment hidden (obsolete)
Comment 2 Darin Adler 2020-07-12 08:57:13 PDT
Comment on attachment 404085 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=404085&action=review

> Source/WebCore/accessibility/AccessibilityNodeObject.cpp:1997
> +    SRGBA<uint8_t> result { 0, 0, 0, 0 };

I don’t see why this function benefits from a local variable.

But if we did keep it, is there no "tidier" way to write this? Related: Is there a significant downside to having a structure like SRGBA be initialized by default? I would prefer one of these:

    SRGBA<uint8_t> result = Color::transparentBlack;
    auto result = Color::transparentBlack;
    SRGBA<uint8_t> result = { };
    SRGBA<uint8_t> result { };
    SRGBA<uint8_t> result; // <initialized to transparent black because we change SRGBA to just do that>

> Source/WebCore/accessibility/AccessibilityNodeObject.cpp:2001
> +        return result;

I propose one of these:

    return Color::transparentBlack;
    return { };

> Source/WebCore/accessibility/AccessibilityNodeObject.cpp:2004
> +        return result;

Ditto.

> Source/WebCore/accessibility/AccessibilityNodeObject.cpp:2006
> +    result = downcast<HTMLInputElement>(*node()).valueAsColor().toSRGBALossy<uint8_t>();

I propose:

    return downcast ...

> Source/WebCore/accessibility/AccessibilityNodeObject.cpp:2009
> +    return result;

I propose one of these:

    return Color::transparentBlack;
    return { };

But also changing structure a bit perhaps.
Comment 3 Sam Weinig 2020-07-12 09:43:56 PDT Comment hidden (obsolete)
Comment 4 Darin Adler 2020-07-12 09:58:39 PDT
Comment on attachment 404102 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=404102&action=review

My comments on the previous patch still apply to this one.

> Source/WebCore/accessibility/ios/WebAccessibilityObjectWrapperIOS.mm:1425
> +        auto color = self.axBackingObject->colorValue();

Build failures seems to be because this is missing the call to convertToComponentFloats.
Comment 5 Sam Weinig 2020-07-12 10:56:34 PDT Comment hidden (obsolete)
Comment 6 Sam Weinig 2020-07-12 11:00:44 PDT
Created attachment 404107 [details]
Patch
Comment 7 Sam Weinig 2020-07-12 11:01:25 PDT
(In reply to Darin Adler from comment #2)
> Comment on attachment 404085 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=404085&action=review
> 
> > Source/WebCore/accessibility/AccessibilityNodeObject.cpp:1997
> > +    SRGBA<uint8_t> result { 0, 0, 0, 0 };
> 
> I don’t see why this function benefits from a local variable.
> 
> But if we did keep it, is there no "tidier" way to write this? Related: Is
> there a significant downside to having a structure like SRGBA be initialized
> by default? I would prefer one of these:
> 
>     SRGBA<uint8_t> result = Color::transparentBlack;
>     auto result = Color::transparentBlack;
>     SRGBA<uint8_t> result = { };
>     SRGBA<uint8_t> result { };
>     SRGBA<uint8_t> result; // <initialized to transparent black because we
> change SRGBA to just do that>
> 
> > Source/WebCore/accessibility/AccessibilityNodeObject.cpp:2001
> > +        return result;
> 
> I propose one of these:
> 
>     return Color::transparentBlack;
>     return { };
> 
> > Source/WebCore/accessibility/AccessibilityNodeObject.cpp:2004
> > +        return result;
> 
> Ditto.
> 
> > Source/WebCore/accessibility/AccessibilityNodeObject.cpp:2006
> > +    result = downcast<HTMLInputElement>(*node()).valueAsColor().toSRGBALossy<uint8_t>();
> 
> I propose:
> 
>     return downcast ...
> 
> > Source/WebCore/accessibility/AccessibilityNodeObject.cpp:2009
> > +    return result;
> 
> I propose one of these:
> 
>     return Color::transparentBlack;
>     return { };
> 
> But also changing structure a bit perhaps.

Reworked it to remove the local variable and use early returns of Color::transparent;
Comment 8 Sam Weinig 2020-07-12 11:03:01 PDT
Created attachment 404109 [details]
Patch
Comment 9 EWS 2020-07-12 12:46:04 PDT
Committed r264284: <https://trac.webkit.org/changeset/264284>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 404109 [details].
Comment 10 Radar WebKit Bug Importer 2020-07-12 12:47:15 PDT
<rdar://problem/65440513>