Bug 148141 - Web Inspector: Links for rules in <style> are incorrect, do not account for <style> offset in the document
Summary: Web Inspector: Links for rules in <style> are incorrect, do not account for <...
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: Joseph Pecoraro
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2015-08-18 14:19 PDT by Joseph Pecoraro
Modified: 2015-08-18 22:00 PDT (History)
9 users (show)

See Also:


Attachments
[PATCH] Proposed Fix (26.76 KB, patch)
2015-08-18 14:35 PDT, Joseph Pecoraro
no flags Details | Formatted Diff | Diff
[PATCH] Proposed Fix (27.03 KB, patch)
2015-08-18 17:30 PDT, Joseph Pecoraro
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph Pecoraro 2015-08-18 14:19:47 PDT
* SUMMARY
Links for rules in <style> are incorrect, do not account for <style> offset in the document

* TEST
<html>
<head>
<style>
body { color: red; }
</style>
</head>
<body>Test</body>
</html>

* STEPS TO REPRODUCE
1. Inspector <body> on test
2. Show Styles > Rules sidebar
  => location link for "body" rule/selector is test.html:2, should be test.html:4

* NOTES
- Works in Chrome, kinda works in Firefox (with issues)
- Related to, but does not fix Media Query location links
Comment 1 Radar WebKit Bug Importer 2015-08-18 14:20:22 PDT
<rdar://problem/22331966>
Comment 2 Joseph Pecoraro 2015-08-18 14:35:05 PDT
Blocked by cleanup in bug 148143.
Comment 3 Joseph Pecoraro 2015-08-18 14:35:45 PDT
Created attachment 259299 [details]
[PATCH] Proposed Fix
Comment 4 Matt Baker 2015-08-18 15:05:30 PDT
Comment on attachment 259299 [details]
[PATCH] Proposed Fix

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

> Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js:873
> +                console.log("BEFORE", mediaSourceCodeLocation.originalLocationString());

Debug logging?

> Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js:875
> +                console.log("AFTER", mediaSourceCodeLocation.originalLocationString());

See above.
Comment 5 BJ Burg 2015-08-18 15:07:41 PDT
Comment on attachment 259299 [details]
[PATCH] Proposed Fix

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

Have not gotten past the test yet, might look later today.

> LayoutTests/inspector/css/getAllStyleSheets.html:23
> +        InspectorTest.expectThat(styleSheets.length === 3, "There are three stylesheets.");

NIT: I prefer phrasing these as "should be" rather than "is/are". What do you think about this convention?

> LayoutTests/inspector/css/getAllStyleSheets.html:27
> +            InspectorTest.log(`URL: ${styleSheet.isInlineStyleTag() ? "<style> on " : ""}${sanitizeURL(styleSheet.url)}`);

NIT: I think we should err towards not performing (ternary) logic inside template ${placeholders}. It quickly becomes hard to follow IMO.

> LayoutTests/inspector/css/getAllStyleSheets.html:28
> +            InspectorTest.log(`OFFSET: (${styleSheet.startLineNumber}, ${styleSheet.startColumnNumber})`);

Nice.

> LayoutTests/inspector/css/getAllStyleSheets.html:29
> +            InspectorTest.expectThat(styleSheet.parentFrame, "Stylesheet has a frame.");

(see above): "should have a"

> Source/JavaScriptCore/inspector/protocol/CSS.json:100
> +                { "name": "isInline", "type": "boolean", "description": "Whether this stylesheet is a <style> tag created by the parser. This is not set for document.written <style> tags." },

Why don't tags from document.write get the flag?
Comment 6 Joseph Pecoraro 2015-08-18 15:13:16 PDT
(In reply to comment #4)
> Comment on attachment 259299 [details]
> [PATCH] Proposed Fix
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=259299&action=review
> 
> > Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js:873
> > +                console.log("BEFORE", mediaSourceCodeLocation.originalLocationString());
> 
> Debug logging?
> 
> > Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js:875
> > +                console.log("AFTER", mediaSourceCodeLocation.originalLocationString());
> 
> See above.

Yeah, oops!
Comment 7 Joseph Pecoraro 2015-08-18 15:17:23 PDT
(In reply to comment #5)
> Comment on attachment 259299 [details]
> [PATCH] Proposed Fix
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=259299&action=review
> 
> Have not gotten past the test yet, might look later today.
> 
> > LayoutTests/inspector/css/getAllStyleSheets.html:23
> > +        InspectorTest.expectThat(styleSheets.length === 3, "There are three stylesheets.");
> 
> NIT: I prefer phrasing these as "should be" rather than "is/are". What do
> you think about this convention?
> 
> > LayoutTests/inspector/css/getAllStyleSheets.html:27
> > +            InspectorTest.log(`URL: ${styleSheet.isInlineStyleTag() ? "<style> on " : ""}${sanitizeURL(styleSheet.url)}`);
> 
> NIT: I think we should err towards not performing (ternary) logic inside
> template ${placeholders}. It quickly becomes hard to follow IMO.
> 
> > LayoutTests/inspector/css/getAllStyleSheets.html:28
> > +            InspectorTest.log(`OFFSET: (${styleSheet.startLineNumber}, ${styleSheet.startColumnNumber})`);
> 
> Nice.
> 
> > LayoutTests/inspector/css/getAllStyleSheets.html:29
> > +            InspectorTest.expectThat(styleSheet.parentFrame, "Stylesheet has a frame.");
> 
> (see above): "should have a"
> 
> > Source/JavaScriptCore/inspector/protocol/CSS.json:100
> > +                { "name": "isInline", "type": "boolean", "description": "Whether this stylesheet is a <style> tag created by the parser. This is not set for document.written <style> tags." },
> 
> Why don't tags from document.write get the flag?

I think in case of a document.write / dynamically generated <style> we should link not to any location, but to the <style> node itself. As in the case of dynamic generation, source code locations don't link to any reasonable location in any Resource, as they were dynamic.

CSSStyleSheet has a reference to the ownerNode that we could create a DOMNode for and push to the frontend for dynamically generated <style>s. I was just not ambitious enough to go that far.
Comment 8 Devin Rousso 2015-08-18 17:03:15 PDT
(In reply to comment #3)
> Created attachment 259299 [details]
> [PATCH] Proposed Fix

NIT: You have used var instead of let in a lot of places.  If we are really moving over to let, we should be consistent in its addition.
Comment 9 Joseph Pecoraro 2015-08-18 17:30:59 PDT
Created attachment 259329 [details]
[PATCH] Proposed Fix
Comment 10 BJ Burg 2015-08-18 21:17:40 PDT
Comment on attachment 259329 [details]
[PATCH] Proposed Fix

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

> Source/WebInspectorUI/UserInterface/Controllers/CSSStyleManager.js:61
> +        return [...this._styleSheetIdentifierMap.values()];

Cool.

> Source/WebInspectorUI/UserInterface/Controllers/CSSStyleManager.js:107
> +        this._fetchInfoForAllStyleSheets(function() {});

You can make it even more of a placeholder: () => {}

> Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js:816
> +        var styleSheet = id ? WebInspector.cssStyleManager.styleSheetForIdentifier(id.styleSheetId) : null;

I'll 'let' it go.
Comment 11 WebKit Commit Bot 2015-08-18 22:00:44 PDT
Comment on attachment 259329 [details]
[PATCH] Proposed Fix

Clearing flags on attachment: 259329

Committed r188631: <http://trac.webkit.org/changeset/188631>
Comment 12 WebKit Commit Bot 2015-08-18 22:00:51 PDT
All reviewed patches have been landed.  Closing bug.