style element and link element for CSS stylesheet should emit load/error event when...
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Feb 2012 16:50:55 +0000 (16:50 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Feb 2012 16:50:55 +0000 (16:50 +0000)
commit2fe5ee2b73659baf459b40504df72310d823da02
tree2c1f595f2e17ff33d5205cd2e8a853e00ff83239
parentf37aee2c955863d31d4c171a9ca858dfba783fac
style element and link element for CSS stylesheet should emit load/error event when sheet loads/fails to load
https://bugs.webkit.org/show_bug.cgi?id=38995

Reviewed by Adam Barth and Nate Chapin.

Source/WebCore:

Tests: fast/dom/HTMLLinkElement/link-onerror-stylesheet-with-existent-and-non-existent-import.html
       fast/dom/HTMLLinkElement/link-onerror-stylesheet-with-non-existent-import.html
       fast/dom/HTMLLinkElement/link-onerror.html
       fast/dom/HTMLLinkElement/link-onload-before-page-load.html
       fast/dom/HTMLLinkElement/link-onload-stylesheet-with-import.html
       fast/dom/HTMLLinkElement/link-onload.html
       fast/dom/HTMLLinkElement/link-onload2.html
       fast/dom/HTMLLinkElement/programmatically-add-link-with-onerror-handler.html
       fast/dom/HTMLLinkElement/programmatically-add-link-with-onload-handler.html
       fast/dom/HTMLStyleElement/programmatically-add-style-with-onerror-handler.html
       fast/dom/HTMLStyleElement/programmatically-add-style-with-onload-handler.html
       fast/dom/HTMLStyleElement/style-onerror-with-existent-and-non-existent-import.html
       fast/dom/HTMLStyleElement/style-onerror.html
       fast/dom/HTMLStyleElement/style-onload-before-page-load.html
       fast/dom/HTMLStyleElement/style-onload.html
       fast/dom/HTMLStyleElement/style-onload2.html

Implements support for firing Load and Error events at HTML Link and HTML Style elements as per
the HTML5 spec. (draft 05/25/2011) section "The link element" <http://www.w3.org/TR/html5/semantics.html#the-link-element>
and "The style element" <http://www.w3.org/TR/html5/semantics.html#the-style-element>, respectively.

* css/CSSImportRule.cpp:
(WebCore::CSSImportRule::setCSSStyleSheet): Modified to call CSSStyleSheet::notifyLoadedSheet()
after the style sheet associated with the @import rule loaded.
* css/CSSStyleSheet.cpp: Added instance variable m_didLoadErrorOccur to track whether a network error
occurred while loading any @import style sheets.
(WebCore::CSSStyleSheet::CSSStyleSheet):
(WebCore::CSSStyleSheet::checkLoaded):
(WebCore):
(WebCore::CSSStyleSheet::notifyLoadedSheet): Added; update m_didLoadErrorOccur to reflect if a network
error occurred while loading a style sheet associated with an @import rule.
* css/CSSStyleSheet.h:
(WebCore):
(CSSStyleSheet):
* dom/Document.cpp:
(WebCore::Document::implicitClose): Call HTML{LinkElement, StyleElement}::dispatchPendingLoadEvents() to
ensure that all pending Load events for link and style elements are dispatched before we fire the Load
event for the window.
* dom/Node.h:
(WebCore::Node::notifyLoadedSheetAndAllCriticalSubresources): Added; as stated in its name, this method is
called once a style sheet and all its critical subresources (@imports) have loaded.
* html/HTMLLinkElement.cpp:
(WebCore::loadEventSender):
(WebCore):
(WebCore::HTMLLinkElement::HTMLLinkElement):
(WebCore::HTMLLinkElement::~HTMLLinkElement): Modified to cancel all pending Load events on destruction.
(WebCore::HTMLLinkElement::parseAttribute): Register event listeners for Load and Error events regardless of whether we
built with link prefetch support.
(WebCore::HTMLLinkElement::setCSSStyleSheet):
(WebCore::HTMLLinkElement::dispatchPendingLoadEvents): Added; called from Document::implicitClose() to
ensure that all pending Load events for link elements have been dispatched before we fire the Load event
for the window.
(WebCore::HTMLLinkElement::dispatchPendingEvent): Added; called by EventSender.
(WebCore::HTMLLinkElement::notifyLoadedSheetAndAllCriticalSubresources): Added.
* html/HTMLLinkElement.h:
(WebCore):
(HTMLLinkElement):
* html/HTMLStyleElement.cpp:
(WebCore::loadEventSender):
(WebCore):
(WebCore::HTMLStyleElement::HTMLStyleElement):
(WebCore::HTMLStyleElement::~HTMLStyleElement): Modified to cancel all pending Load events on destruction.
(WebCore::HTMLStyleElement::parseAttribute): Register event listeners for Load and Error events.
(WebCore::HTMLStyleElement::dispatchPendingLoadEvents): Added; called from Document::implicitClose() to
ensure that all pending Load events for link elements have been dispatched before we fire the Load event
for the window.
(WebCore::HTMLStyleElement::dispatchPendingEvent): Added; called by EventSender.
(WebCore::HTMLStyleElement::notifyLoadedSheetAndAllCriticalSubresources): Added.
* html/HTMLStyleElement.h:
(WebCore):
(HTMLStyleElement):

LayoutTests:

Add test cases to ensure we dispatch Load/Error events to HTML Link and HTML Style elements.

* fast/dom/HTMLLinkElement/link-onerror-expected.txt: Added.
* fast/dom/HTMLLinkElement/link-onerror-stylesheet-with-existent-and-non-existent-import-expected.txt: Added.
* fast/dom/HTMLLinkElement/link-onerror-stylesheet-with-existent-and-non-existent-import.html: Added.
* fast/dom/HTMLLinkElement/link-onerror-stylesheet-with-non-existent-import-expected.txt: Added.
* fast/dom/HTMLLinkElement/link-onerror-stylesheet-with-non-existent-import.html: Added.
* fast/dom/HTMLLinkElement/link-onerror.html: Added.
* fast/dom/HTMLLinkElement/link-onload-before-page-load-expected.txt: Added.
* fast/dom/HTMLLinkElement/link-onload-before-page-load.html: Added.
* fast/dom/HTMLLinkElement/link-onload-expected.txt: Added.
* fast/dom/HTMLLinkElement/link-onload-stylesheet-with-import-expected.txt: Added.
* fast/dom/HTMLLinkElement/link-onload-stylesheet-with-import.html: Added.
* fast/dom/HTMLLinkElement/link-onload.html: Added.
* fast/dom/HTMLLinkElement/link-onload2-expected.txt: Added.
* fast/dom/HTMLLinkElement/link-onload2.html: Added.
* fast/dom/HTMLLinkElement/programmatically-add-link-with-onerror-handler-expected.txt: Added.
* fast/dom/HTMLLinkElement/programmatically-add-link-with-onerror-handler.html: Added.
* fast/dom/HTMLLinkElement/programmatically-add-link-with-onload-handler-expected.txt: Added.
* fast/dom/HTMLLinkElement/programmatically-add-link-with-onload-handler.html: Added.
* fast/dom/HTMLLinkElement/resources/link-load-utilities.js: Added.
(shouldComputedColorOfElementBeEqualToRGBString):
(createLinkElementWithStylesheet):
(createStyleElementWithString):
(log):
(testPassed):
(testFailed):
(testPassedAndNotifyDone):
(testFailedAndNotifyDone):
(testFinished):
* fast/dom/HTMLLinkElement/resources/stylesheet-with-existent-and-non-existent-import.css: Added.
(#test):
* fast/dom/HTMLLinkElement/resources/stylesheet-with-import.css: Added.
(#test):
* fast/dom/HTMLLinkElement/resources/stylesheet-with-non-existent-import.css: Added.
(#test):
* fast/dom/HTMLLinkElement/resources/stylesheet.css: Added.
(#test):
* fast/dom/HTMLStyleElement/programmatically-add-style-with-onerror-handler-expected.txt: Added.
* fast/dom/HTMLStyleElement/programmatically-add-style-with-onerror-handler.html: Added.
* fast/dom/HTMLStyleElement/programmatically-add-style-with-onload-handler-expected.txt: Added.
* fast/dom/HTMLStyleElement/programmatically-add-style-with-onload-handler.html: Added.
* fast/dom/HTMLStyleElement/style-onerror-expected.txt: Added.
* fast/dom/HTMLStyleElement/style-onerror-with-existent-and-non-existent-import-expected.txt: Added.
* fast/dom/HTMLStyleElement/style-onerror-with-existent-and-non-existent-import.html: Added.
* fast/dom/HTMLStyleElement/style-onerror.html: Added.
* fast/dom/HTMLStyleElement/style-onload-before-page-load-expected.txt: Added.
* fast/dom/HTMLStyleElement/style-onload-before-page-load.html: Added.
* fast/dom/HTMLStyleElement/style-onload-expected.txt: Added.
* fast/dom/HTMLStyleElement/style-onload.html: Added.
* fast/dom/HTMLStyleElement/style-onload2-expected.txt: Added.
* fast/dom/HTMLStyleElement/style-onload2.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@108809 268f45cc-cd09-0410-ab3c-d52691b4dbfc
48 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/dom/HTMLLinkElement/link-onerror-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/HTMLLinkElement/link-onerror-stylesheet-with-existent-and-non-existent-import-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/HTMLLinkElement/link-onerror-stylesheet-with-existent-and-non-existent-import.html [new file with mode: 0644]
LayoutTests/fast/dom/HTMLLinkElement/link-onerror-stylesheet-with-non-existent-import-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/HTMLLinkElement/link-onerror-stylesheet-with-non-existent-import.html [new file with mode: 0644]
LayoutTests/fast/dom/HTMLLinkElement/link-onerror.html [new file with mode: 0644]
LayoutTests/fast/dom/HTMLLinkElement/link-onload-before-page-load-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/HTMLLinkElement/link-onload-before-page-load.html [new file with mode: 0644]
LayoutTests/fast/dom/HTMLLinkElement/link-onload-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/HTMLLinkElement/link-onload-stylesheet-with-import-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/HTMLLinkElement/link-onload-stylesheet-with-import.html [new file with mode: 0644]
LayoutTests/fast/dom/HTMLLinkElement/link-onload.html [new file with mode: 0644]
LayoutTests/fast/dom/HTMLLinkElement/link-onload2-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/HTMLLinkElement/link-onload2.html [new file with mode: 0644]
LayoutTests/fast/dom/HTMLLinkElement/programmatically-add-link-with-onerror-handler-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/HTMLLinkElement/programmatically-add-link-with-onerror-handler.html [new file with mode: 0644]
LayoutTests/fast/dom/HTMLLinkElement/programmatically-add-link-with-onload-handler-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/HTMLLinkElement/programmatically-add-link-with-onload-handler.html [new file with mode: 0644]
LayoutTests/fast/dom/HTMLLinkElement/resources/link-load-utilities.js [new file with mode: 0644]
LayoutTests/fast/dom/HTMLLinkElement/resources/stylesheet-with-existent-and-non-existent-import.css [new file with mode: 0644]
LayoutTests/fast/dom/HTMLLinkElement/resources/stylesheet-with-import.css [new file with mode: 0644]
LayoutTests/fast/dom/HTMLLinkElement/resources/stylesheet-with-non-existent-import.css [new file with mode: 0644]
LayoutTests/fast/dom/HTMLLinkElement/resources/stylesheet.css [new file with mode: 0644]
LayoutTests/fast/dom/HTMLStyleElement/programmatically-add-style-with-onerror-handler-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/HTMLStyleElement/programmatically-add-style-with-onerror-handler.html [new file with mode: 0644]
LayoutTests/fast/dom/HTMLStyleElement/programmatically-add-style-with-onload-handler-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/HTMLStyleElement/programmatically-add-style-with-onload-handler.html [new file with mode: 0644]
LayoutTests/fast/dom/HTMLStyleElement/style-onerror-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/HTMLStyleElement/style-onerror-with-existent-and-non-existent-import-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/HTMLStyleElement/style-onerror-with-existent-and-non-existent-import.html [new file with mode: 0644]
LayoutTests/fast/dom/HTMLStyleElement/style-onerror.html [new file with mode: 0644]
LayoutTests/fast/dom/HTMLStyleElement/style-onload-before-page-load-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/HTMLStyleElement/style-onload-before-page-load.html [new file with mode: 0644]
LayoutTests/fast/dom/HTMLStyleElement/style-onload-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/HTMLStyleElement/style-onload.html [new file with mode: 0644]
LayoutTests/fast/dom/HTMLStyleElement/style-onload2-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/HTMLStyleElement/style-onload2.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/css/CSSImportRule.cpp
Source/WebCore/css/CSSStyleSheet.cpp
Source/WebCore/css/CSSStyleSheet.h
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Node.h
Source/WebCore/html/HTMLLinkElement.cpp
Source/WebCore/html/HTMLLinkElement.h
Source/WebCore/html/HTMLStyleElement.cpp
Source/WebCore/html/HTMLStyleElement.h