Implement FontLoader interface
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Mar 2013 05:59:58 +0000 (05:59 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Mar 2013 05:59:58 +0000 (05:59 +0000)
commitb3fb879f9cae8c35d07cf7ac24f3959cb3e3c564
treec863e8f894b07c743841a7640e08c12a7dd857d4
parentac93d5ef1c7ae5cee2d0397ef8f78a4df438ab2b
Implement FontLoader interface
https://bugs.webkit.org/show_bug.cgi?id=98395

Patch by Kunihiko Sakamoto <ksakamoto@chromium.org> on 2013-03-13
Reviewed by Eric Seidel.

Source/WebCore:

This patch implements the FontLoader interface defined in CSS Font
Load Events Module Level 3.[1] It adds fontloader attribute to
Document, and adds two interfaces, FontLoader and
CSSFontFaceLoadEvent to WebCore.

[1]: http://dev.w3.org/csswg/css-font-load-events-3/

This feature is guarded by FONT_LOAD_EVENTS compiler flag and
RuntimeEnabledFeatures::fontLoadEventsEnabled() runtime flag.

Tests: fast/css/fontloader-download-error.html
       fast/css/fontloader-events.html
       fast/css/fontloader-loadingdone.html
       fast/css/fontloader-multiple-faces-download-error.html
       fast/css/fontloader-multiple-faces.html
       fast/css/fontloader-multiple-families.html
       http/tests/webfont/fontloader-loading-attribute.html

* CMakeLists.txt: Adding FontLoader/CSSFontFaceLoadEvent files.
* DerivedSources.cpp: Ditto.
* DerivedSources.make: Ditto.
* DerivedSources.pri: Ditto.
* GNUmakefile.list.am: Ditto.
* Target.pri: Ditto.
* WebCore.gypi: Ditto.
* WebCore.vcproj/WebCore.vcproj: Ditto.
* WebCore.vcxproj/WebCore.vcxproj: Ditto.
* WebCore.vcxproj/WebCore.vcxproj.filters: Ditto.
* WebCore.xcodeproj/project.pbxproj: Ditto.
* bindings/js/JSDictionary.cpp:
(WebCore::JSDictionary::convertValue): Add convertValue() for CSSFontFaceRule, DOMError, and VoidCallback.
* bindings/js/JSDictionary.h: Ditto.
* bindings/v8/Dictionary.cpp: Add get() for CSSFontFaceRule, DOMError, and VoidCallback.
(WebCore::Dictionary::get):
* bindings/v8/Dictionary.h: Ditto.
(Dictionary):
* css/CSSFontFace.cpp: Notifies FontLoader as load progresses.
(WebCore::CSSFontFace::fontLoaded):
(WebCore::CSSFontFace::getFontData):
(WebCore::CSSFontFace::notifyFontLoader):
(WebCore::CSSFontFace::notifyLoadingDone):
* css/CSSFontFace.h: Add two member variables. m_rule stores CSSFontFaceRule for the fontface. m_loadState holds current state of the fontface in terms of FontLoader.
(WebCore::CSSFontFace::create): Takes additional parameter of type CSSFontFaceRule.
(WebCore::CSSFontFace::loadState):
(WebCore::CSSFontFace::CSSFontFace):
* css/CSSFontFaceLoadEvent.cpp: Added.
(WebCore::CSSFontFaceLoadEvent::CSSFontFaceLoadEvent):
(WebCore::CSSFontFaceLoadEvent::~CSSFontFaceLoadEvent):
(WebCore::CSSFontFaceLoadEvent::interfaceName):
* css/CSSFontFaceLoadEvent.h: Added.
(CSSFontFaceLoadEventInit):
(CSSFontFaceLoadEvent):
(WebCore::CSSFontFaceLoadEvent::create):
(WebCore::CSSFontFaceLoadEvent::createForFontFaceRule):
(WebCore::CSSFontFaceLoadEvent::createForError):
(WebCore::CSSFontFaceLoadEvent::fontface):
(WebCore::CSSFontFaceLoadEvent::error):
* css/CSSFontFaceLoadEvent.idl: Added.
* css/CSSFontFaceRule.idl: Add JSGenerateToJSObject and JSGenerateToNativeObject as JSC binding needs them.
* css/CSSFontFaceSource.cpp:
(WebCore::CSSFontFaceSource::isDecodeError): Added.
(WebCore::CSSFontFaceSource::ensureFontData): Added.
* css/CSSFontFaceSource.h:
(CSSFontFaceSource):
* css/CSSFontSelector.cpp:
(WebCore::CSSFontSelector::addFontFaceRule): Pass a CSSFontFaceRule to CSSFontFace::create().
(WebCore::CSSFontSelector::getFontData): Moved logic for creating a CSSSegmentedFontFace to a helper function getFontFace().
(WebCore::CSSFontSelector::getFontFace): Added.
* css/CSSFontSelector.h:
* css/CSSSegmentedFontFace.cpp:
(WebCore::CSSSegmentedFontFace::fontLoaded): Fires callbacks when load is completed.
(WebCore::CSSSegmentedFontFace::isLoading): Returns true if any fonts are still loading.
(WebCore::CSSSegmentedFontFace::checkFont): Returns true if all fonts are loaded.
(WebCore::CSSSegmentedFontFace::loadFont): Starts load by calling getFontData().
* css/CSSSegmentedFontFace.h:
(CSSSegmentedFontFace): Declares new functions and a vector to store callbacks.
(LoadFontCallback):
(WebCore::CSSSegmentedFontFace::LoadFontCallback::~LoadFontCallback):
* css/FontLoader.cpp: Added.
(LoadFontCallback): Holds callback functions of FontLoader.loadFont().
(WebCore::LoadFontCallback::create):
(WebCore::LoadFontCallback::createFromParams):
(WebCore::LoadFontCallback::LoadFontCallback):
(WebCore::LoadFontCallback::notifyLoaded):
(WebCore::LoadFontCallback::notifyError):
(WebCore::FontLoader::FontLoader):
(WebCore::FontLoader::~FontLoader):
(WebCore::FontLoader::eventTargetData):
(WebCore::FontLoader::ensureEventTargetData):
(WebCore::FontLoader::interfaceName):
(WebCore::FontLoader::scriptExecutionContext):
(WebCore::FontLoader::didLayout): Fires pending events and callbacks. This is called when layout have completed.
(WebCore::FontLoader::scheduleEvent): Defers event dispatching until layout completes.
(WebCore::FontLoader::firePendingEvents): Dispatches pending events.
(WebCore::FontLoader::beginFontLoading): Schedules loading/loadstart events. This is called from CSSFontFace.
(WebCore::FontLoader::fontLoaded): Schedules load/loadingdone events. This is called from CSSFontFace.
(WebCore::FontLoader::loadError): Schedules error/loadingdone events. This is called from CSSFontFace.
(WebCore::FontLoader::notifyWhenFontsReady): Implements fontloader.notifyWhenFontsReady().
(WebCore::FontLoader::loadingDone): Fires callbacks of notifyWhenFontsReady.
(WebCore::FontLoader::loadFont): Implements fontloader.loadFont().
(WebCore::FontLoader::checkFont): Implements fontloader.checkFont().
(WebCore::FontLoader::resolveFontStyle): Parses the given font parameter using the syntax of CSS 'font' property and creates Font object. The logic is taken from CanvasRenderingContext2D::setFont().
* css/FontLoader.h: Added.
(FontLoader):
(WebCore::FontLoader::create):
(WebCore::FontLoader::loading):
(WebCore::FontLoader::document):
(WebCore::FontLoader::refEventTarget):
(WebCore::FontLoader::derefEventTarget):
* css/FontLoader.idl: Added.
* dom/Document.cpp:
(WebCore::Document::Document):
(WebCore::Document::fontloader): Added.
* dom/Document.h:
(Document): Add m_fontloader and fontloader().
* dom/Document.idl: Add fontloader attribute.
* dom/EventNames.h: Add loading and loadingdone events.
* dom/EventNames.in: Add CSSFontFaceLoadEvent.
* dom/EventTargetFactory.in: Add FontLoader.
* page/FrameView.cpp:
(WebCore::FrameView::performPostLayoutTasks): Calls FontLoader::didLayout().

Tools:

Enable FontLoadEvents runtime flag for TestShell.

* DumpRenderTree/chromium/TestRunner/src/TestInterfaces.cpp:
(WebTestRunner::TestInterfaces::TestInterfaces):

LayoutTests:

Add tests for document.fontloader. Since the feature is currently enabled
only for chromium, the tests are expected to fail on the other ports.

* fast/css/fontloader-download-error-expected.txt: Added.
* fast/css/fontloader-download-error.html: Added.
* fast/css/fontloader-events-expected.txt: Added.
* fast/css/fontloader-events.html: Added.
* fast/css/fontloader-loadingdone-expected.txt: Added.
* fast/css/fontloader-loadingdone.html: Added.
* fast/css/fontloader-multiple-faces-download-error-expected.txt: Added.
* fast/css/fontloader-multiple-faces-download-error.html: Added.
* fast/css/fontloader-multiple-faces-expected.txt: Added.
* fast/css/fontloader-multiple-faces.html: Added.
* fast/css/fontloader-multiple-families-expected.txt: Added.
* fast/css/fontloader-multiple-families.html: Added.
* http/tests/webfont/fontloader-loading-attribute-expected.txt: Added.
* http/tests/webfont/fontloader-loading-attribute.html: Added.
* platform/chromium/fast/css/fontloader-download-error-expected.txt: Added.
* platform/chromium/fast/css/fontloader-events-expected.txt: Added.
* platform/chromium/fast/css/fontloader-loadingdone-expected.txt: Added.
* platform/chromium/fast/css/fontloader-multiple-faces-download-error-expected.txt: Added.
* platform/chromium/fast/css/fontloader-multiple-faces-expected.txt: Added.
* platform/chromium/fast/css/fontloader-multiple-families-expected.txt: Added.
* platform/chromium/http/tests/webfont/fontloader-loading-attribute-expected.txt: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@145787 268f45cc-cd09-0410-ab3c-d52691b4dbfc
62 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/css/fontloader-download-error-expected.txt [new file with mode: 0644]
LayoutTests/fast/css/fontloader-download-error.html [new file with mode: 0644]
LayoutTests/fast/css/fontloader-events-expected.txt [new file with mode: 0644]
LayoutTests/fast/css/fontloader-events.html [new file with mode: 0644]
LayoutTests/fast/css/fontloader-loadingdone-expected.txt [new file with mode: 0644]
LayoutTests/fast/css/fontloader-loadingdone.html [new file with mode: 0644]
LayoutTests/fast/css/fontloader-multiple-faces-download-error-expected.txt [new file with mode: 0644]
LayoutTests/fast/css/fontloader-multiple-faces-download-error.html [new file with mode: 0644]
LayoutTests/fast/css/fontloader-multiple-faces-expected.txt [new file with mode: 0644]
LayoutTests/fast/css/fontloader-multiple-faces.html [new file with mode: 0644]
LayoutTests/fast/css/fontloader-multiple-families-expected.txt [new file with mode: 0644]
LayoutTests/fast/css/fontloader-multiple-families.html [new file with mode: 0644]
LayoutTests/http/tests/webfont/fontloader-loading-attribute-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/webfont/fontloader-loading-attribute.html [new file with mode: 0644]
LayoutTests/platform/chromium/fast/css/fontloader-download-error-expected.txt [new file with mode: 0644]
LayoutTests/platform/chromium/fast/css/fontloader-events-expected.txt [new file with mode: 0644]
LayoutTests/platform/chromium/fast/css/fontloader-loadingdone-expected.txt [new file with mode: 0644]
LayoutTests/platform/chromium/fast/css/fontloader-multiple-faces-download-error-expected.txt [new file with mode: 0644]
LayoutTests/platform/chromium/fast/css/fontloader-multiple-faces-expected.txt [new file with mode: 0644]
LayoutTests/platform/chromium/fast/css/fontloader-multiple-families-expected.txt [new file with mode: 0644]
LayoutTests/platform/chromium/http/tests/webfont/fontloader-loading-attribute-expected.txt [new file with mode: 0644]
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/DerivedSources.cpp
Source/WebCore/DerivedSources.make
Source/WebCore/DerivedSources.pri
Source/WebCore/GNUmakefile.list.am
Source/WebCore/Target.pri
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.vcproj/WebCore.vcproj
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/JSDictionary.cpp
Source/WebCore/bindings/js/JSDictionary.h
Source/WebCore/bindings/v8/Dictionary.cpp
Source/WebCore/bindings/v8/Dictionary.h
Source/WebCore/css/CSSFontFace.cpp
Source/WebCore/css/CSSFontFace.h
Source/WebCore/css/CSSFontFaceLoadEvent.cpp [new file with mode: 0644]
Source/WebCore/css/CSSFontFaceLoadEvent.h [new file with mode: 0644]
Source/WebCore/css/CSSFontFaceLoadEvent.idl [new file with mode: 0644]
Source/WebCore/css/CSSFontFaceRule.idl
Source/WebCore/css/CSSFontFaceSource.cpp
Source/WebCore/css/CSSFontFaceSource.h
Source/WebCore/css/CSSFontSelector.cpp
Source/WebCore/css/CSSFontSelector.h
Source/WebCore/css/CSSSegmentedFontFace.cpp
Source/WebCore/css/CSSSegmentedFontFace.h
Source/WebCore/css/FontLoader.cpp [new file with mode: 0644]
Source/WebCore/css/FontLoader.h [new file with mode: 0644]
Source/WebCore/css/FontLoader.idl [new file with mode: 0644]
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/Document.idl
Source/WebCore/dom/EventNames.h
Source/WebCore/dom/EventNames.in
Source/WebCore/dom/EventTargetFactory.in
Source/WebCore/page/FrameView.cpp
Tools/ChangeLog
Tools/DumpRenderTree/chromium/TestRunner/src/TestInterfaces.cpp