Bug 193173 - Web Inspector: "white" and "black" aren't recognized as color keywords
Summary: Web Inspector: "white" and "black" aren't recognized as color keywords
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Nikita Vasilyev
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-01-05 15:39 PST by Nikita Vasilyev
Modified: 2019-01-07 12:20 PST (History)
5 users (show)

See Also:


Attachments
Patch (5.29 KB, patch)
2019-01-05 16:29 PST, Nikita Vasilyev
no flags Details | Formatted Diff | Diff
[Image] With patch applied (40.81 KB, image/png)
2019-01-05 16:31 PST, Nikita Vasilyev
no flags Details
Patch (5.10 KB, patch)
2019-01-06 12:12 PST, Nikita Vasilyev
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nikita Vasilyev 2019-01-05 15:39:44 PST
Color picker doesn't show up for "color: white".
Comment 1 Radar WebKit Bug Importer 2019-01-05 15:40:28 PST
<rdar://problem/47068595>
Comment 2 Nikita Vasilyev 2019-01-05 15:53:20 PST
That's because "white" is the value keyboard for -apple-pay-button-style:

    -apple-pay-button-style: Array (3)
    0 "black"
    1 "white"
    2 "white-outline"

Value keywords have precedence over color keywords in External/CodeMirror/css.js:

    function wordAsValue(stream) {
      var word = stream.current().toLowerCase();
      if (valueKeywords.hasOwnProperty(word))
        override = "atom";
      else if (colorKeywords.hasOwnProperty(word))
        override = "keyword";
      else
        override = "variable";
    }
Comment 3 Nikita Vasilyev 2019-01-05 16:29:27 PST
Created attachment 358445 [details]
Patch
Comment 4 Nikita Vasilyev 2019-01-05 16:31:37 PST
Created attachment 358446 [details]
[Image] With patch applied
Comment 5 Devin Rousso 2019-01-06 11:12:59 PST
Comment on attachment 358445 [details]
Patch

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

> Source/WebInspectorUI/UserInterface/Models/CSSKeywordCompletions.js:47
> +            acceptedKeywords.push(...WI.CSSKeywordCompletions._colors);

NIT: the `concat` approach is faster <https://jsperf.com/array-concat-vs-push-2/17>.

> Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js:425
> +            let isVariable = this._property.name.startsWith("--");

NIT: you can use the `this._properety.variable` getter and inline it in the `if`.

> Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js:570
> +            } else if (isNaN(colorFunctionStartIndex) && token.type && (token.type.includes("atom") || token.type.includes("keyword"))) {

What would happen with the following if this wasn't changed?

    -apple-pay-button-style: white;
    color: white;
    --foo: white;
Comment 6 Nikita Vasilyev 2019-01-06 12:07:48 PST
Comment on attachment 358445 [details]
Patch

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

>> Source/WebInspectorUI/UserInterface/Models/CSSKeywordCompletions.js:47
>> +            acceptedKeywords.push(...WI.CSSKeywordCompletions._colors);
> 
> NIT: the `concat` approach is faster <https://jsperf.com/array-concat-vs-push-2/17>.

Good to know!

>> Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js:425
>> +            let isVariable = this._property.name.startsWith("--");
> 
> NIT: you can use the `this._properety.variable` getter and inline it in the `if`.

Neat!

>> Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js:570
>> +            } else if (isNaN(colorFunctionStartIndex) && token.type && (token.type.includes("atom") || token.type.includes("keyword"))) {
> 
> What would happen with the following if this wasn't changed?
> 
>     -apple-pay-button-style: white;
>     color: white;
>     --foo: white;

It wouldn't show the color picker anywhere.
Comment 7 Nikita Vasilyev 2019-01-06 12:12:51 PST
Created attachment 358465 [details]
Patch
Comment 8 Joseph Pecoraro 2019-01-07 12:01:31 PST
Comment on attachment 358465 [details]
Patch

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

r=me

> Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js:422
>              // FIXME: <https://webkit.org/b/178636> Web Inspector: Styles: Make inline widgets work with CSS functions (var(), calc(), etc.)

Does this address this FIXME? Maybe not completely?
Comment 9 Nikita Vasilyev 2019-01-07 12:07:25 PST
Comment on attachment 358465 [details]
Patch

(In reply to Joseph Pecoraro from comment #8)
> Comment on attachment 358465 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=358465&action=review
> 
> r=me
> 
> > Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js:422
> >              // FIXME: <https://webkit.org/b/178636> Web Inspector: Styles: Make inline widgets work with CSS functions (var(), calc(), etc.)
> 
> Does this address this FIXME? Maybe not completely?

It doesn't address this FIXME at all. The FIXME is about cases like `linear-gradient(#fff2db, var(--myVar))`.
Comment 10 WebKit Commit Bot 2019-01-07 12:20:27 PST
Comment on attachment 358465 [details]
Patch

Clearing flags on attachment: 358465

Committed r239690: <https://trac.webkit.org/changeset/239690>
Comment 11 WebKit Commit Bot 2019-01-07 12:20:28 PST
All reviewed patches have been landed.  Closing bug.