Bug 110750 - Web Inspector: CSS.styleSheetChanged before @import rules are loaded
Summary: Web Inspector: CSS.styleSheetChanged before @import rules are loaded
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2013-02-25 05:22 PST by Timothy Hatcher
Modified: 2016-12-13 15:40 PST (History)
14 users (show)

See Also:


Attachments
Test Case (113 bytes, text/html)
2013-02-25 05:22 PST, Timothy Hatcher
no flags Details
Protocol Dump (5.17 KB, text/plain)
2013-02-25 05:23 PST, Timothy Hatcher
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Timothy Hatcher 2013-02-25 05:22:58 PST
Created attachment 190039 [details]
Test Case

When editing a stylesheet text, the styleSheetChanged event fires before imported stylesheets are loaded. Normally this would be fine; however, calling CSS.getMatchedStylesForNode in response to the styleSheetChanged event results in a blank response. Calling after the Network.loadingFinished event for the imported stylesheet results in the expected matched rules.

First saw this on daringfireball.net editing fireball_screen.css, which @imports fireball_fontsize.php and fireball_unicode.css. Here is an attached test case that imports fireball_fontsize.php.

If you edit background-color in the attached test, the color applies right away but you can't get the parsed rules until after the imports load. I would expect rules to return no matter what the loading status is, since the background-color edit applies instantly.

Also attached is a protocol dump showing the order of operations (with some irrelevant layer tree messages removed and some blank lines added for clarity).
Comment 1 Timothy Hatcher 2013-02-25 05:23:20 PST
Created attachment 190040 [details]
Protocol Dump
Comment 2 Timothy Hatcher 2013-02-25 05:35:53 PST
Either the rules need to be available immediately, or we need a separate event that fires when they are (which would normally fire right after styleSheetChanged when there are no @import rules.)
Comment 3 Timothy Hatcher 2013-02-25 06:41:41 PST
The fact that user agent rules and rules from other stylesheets are not included is odd too.
Comment 4 Alexander Pavlov (apavlov) 2013-02-26 07:16:48 PST
According to Antti, StyleResolver::styleRulesForElement() should return the set of rules currently matching the element, without waiting for the @imports to load.
Comment 5 Alexander Pavlov (apavlov) 2013-02-27 07:31:28 PST
The root cause:

PassRefPtr<CSSRuleList> StyleResolver::pseudoStyleRulesForElement(Element* e, PseudoId pseudoId, unsigned rulesToInclude)
{
    if (!e || !e->document()->haveStylesheetsLoaded())
        return 0;
...

Antti, any ideas? Is it safe to just remove the second part of this check?
Comment 6 Timothy Hatcher 2013-04-18 07:41:35 PDT
Antti, Hyatt, Simon, thoughts?
Comment 7 Radar WebKit Bug Importer 2014-12-01 14:03:47 PST
<rdar://problem/19106448>