Bug 177346 - Web Inspector: Add autocompletion suggestions for CSS attr based on the selected element's attributes
Summary: Web Inspector: Add autocompletion suggestions for CSS attr based on the selec...
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: Devin Rousso
URL:
Keywords: InRadar
Depends on:
Blocks: 177619
  Show dependency treegraph
 
Reported: 2017-09-22 00:20 PDT by Devin Rousso
Modified: 2017-09-28 14:31 PDT (History)
5 users (show)

See Also:


Attachments
Patch (3.49 KB, patch)
2017-09-22 00:22 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff
[Image] After Patch is applied (18.88 KB, image/png)
2017-09-22 00:22 PDT, Devin Rousso
no flags Details
Patch (6.02 KB, patch)
2017-09-22 23:04 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff
Patch (5.93 KB, patch)
2017-09-23 01:01 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews125 for ios-simulator-wk2 (947.50 KB, application/zip)
2017-09-23 02:31 PDT, Build Bot
no flags Details
Patch (5.95 KB, patch)
2017-09-25 17:08 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Devin Rousso 2017-09-22 00:20:15 PDT
If the user is asking for completions inside a CSS `attr()`, we should add entries based on the existing dataset attributes of the corresponding node.

In the following example:

    <style>
        div {
            content: attr();
        }
    </style>
    <div data-test="test"></div>

If the user puts their cursor at `attr(|`, the completions list should contain "data-test".
Comment 1 Devin Rousso 2017-09-22 00:22:05 PDT
Created attachment 321522 [details]
Patch
Comment 2 Devin Rousso 2017-09-22 00:22:33 PDT
Created attachment 321523 [details]
[Image] After Patch is applied
Comment 3 Joseph Pecoraro 2017-09-22 11:32:31 PDT
Comment on attachment 321522 [details]
Patch

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

We could use this as an opportunity to write a test for `DOMNode.prototype.attributes`, which this depends on and which we don't have any existing tests for! I suggest starting a new: LayoutTests/inspector/model/dom-node.html, then as we want to test different parts of DOMNode we just add a small method. A test for attributes can just have a few different nodes with different attributes and log their attributes + values.

> Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorCompletionController.js:589
> +            if (this._delegate && typeof this._delegate.completionControllerCSSFunctionValuesNeeded)
> +                functionCompletions = this._delegate.completionControllerCSSFunctionValuesNeeded(this, functionName, functionCompletions);

This feels a bit hacky, but its short and simple.

> Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationTextEditor.js:402
> +                if (!attribute.name.startsWith("data-"))
> +                    continue;

attr() can be used with any attribute, not just "data-" prefixed attributes. A common usage may be `title` or `alt`:

    <style>p::before { color: blue; content: attr(title); }</style>
    <p title="Test">Hello</p>

So I think we should just push all attribute names.

I don't know how this would work with XML namespaced attributes. Maybe we should ignore those (they may also be unlikely).
Comment 4 Devin Rousso 2017-09-22 22:51:07 PDT
Comment on attachment 321522 [details]
Patch

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

>> Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationTextEditor.js:402
>> +                    continue;
> 
> attr() can be used with any attribute, not just "data-" prefixed attributes. A common usage may be `title` or `alt`:
> 
>     <style>p::before { color: blue; content: attr(title); }</style>
>     <p title="Test">Hello</p>
> 
> So I think we should just push all attribute names.
> 
> I don't know how this would work with XML namespaced attributes. Maybe we should ignore those (they may also be unlikely).

I don't know why, but I thought this was "data-*" only.  It's awesome to know otherwise :)
Comment 5 Devin Rousso 2017-09-22 23:04:23 PDT
Created attachment 321616 [details]
Patch
Comment 6 Devin Rousso 2017-09-23 01:01:22 PDT
Created attachment 321619 [details]
Patch
Comment 7 Build Bot 2017-09-23 02:31:41 PDT
Comment on attachment 321619 [details]
Patch

Attachment 321619 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: http://webkit-queues.webkit.org/results/4635202

New failing tests:
http/tests/cache-storage/cache-representation.https.html
Comment 8 Build Bot 2017-09-23 02:31:42 PDT
Created attachment 321625 [details]
Archive of layout-test-results from ews125 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews125  Port: ios-simulator-wk2  Platform: Mac OS X 10.12.6
Comment 9 Devin Rousso 2017-09-25 17:08:41 PDT
Created attachment 321773 [details]
Patch
Comment 10 WebKit Commit Bot 2017-09-25 18:24:47 PDT
Comment on attachment 321773 [details]
Patch

Clearing flags on attachment: 321773

Committed r222483: <http://trac.webkit.org/changeset/222483>
Comment 11 WebKit Commit Bot 2017-09-25 18:24:48 PDT
All reviewed patches have been landed.  Closing bug.
Comment 12 Radar WebKit Bug Importer 2017-09-27 12:20:42 PDT
<rdar://problem/34693091>