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).
Created attachment 190040 [details] Protocol Dump
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.)
The fact that user agent rules and rules from other stylesheets are not included is odd too.
According to Antti, StyleResolver::styleRulesForElement() should return the set of rules currently matching the element, without waiting for the @imports to load.
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?
Antti, Hyatt, Simon, thoughts?
<rdar://problem/19106448>