[Font Loading] Implement FontFace JavaScript object
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Feb 2016 23:39:02 +0000 (23:39 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Feb 2016 23:39:02 +0000 (23:39 +0000)
commit453ade50646711d4f890efad730bc72664293cba
tree83f8d7dd41f13a40219b0770297fba3bd1566188
parent4aa214c4dfd6181f0a41f9b01c490160881f5643
[Font Loading] Implement FontFace JavaScript object
https://bugs.webkit.org/show_bug.cgi?id=153345

Reviewed by Antti Koivisto.

Source/WebCore:

Test: fast/text/font-face-javascript.html

This patch implements the FontFace Javascript object. This object mostly consists of
style getters / setters, which we implement by parsing input strings and generating
output strings similarly to getComputedStyle(). This object also has a load() function
which returns a promise which will be fulfilled or rejected depending on the load.
There is also a "loaded" attribute which exposes this promise directly. Also, a status
field is exposed so script knows what the state of the load is.

Currently, loading depends on our CachedResourceLoader which is part of the Document,
so this API is not available in a non-document context.

Another caveat is that immediate-mode font loading (where the content provides an
ArrayBuffer containing the bytes of the font file) is forthcoming. This requires
changing the relationship between CSSFontFaceSource and CachedFont.

CSSFontFace has been modified to keep a strong reference to the CSSFontSelector. This
is because the lifetime of the CSSFontFace can now outlive the CSSFontSelector. When
the CSSFontSelector is removed from the Document, it explicitly clears its constituent
CSSFontFaces, thereby breaking the reference cycle.

Test: fast/text/font-face-javascript-expected.html

* CMakeLists.txt: Add new files.
* DerivedSources.cpp: Ditto.
* DerivedSources.make: Ditto.
* WebCore.vcxproj/WebCore.vcxproj: Ditto.
* WebCore.vcxproj/WebCore.vcxproj.filters: Ditto.
* WebCore.xcodeproj/project.pbxproj: Ditto.
* bindings/js/JSDOMPromise.cpp:
(WebCore::DeferredWrapper::globalObject): Remove whitespace.
(WebCore::DeferredWrapper::deferred): Allow access to the inner JSC object.
* bindings/js/JSDOMPromise.h:
(WebCore::DOMPromise::deferred): Ditto.
* bindings/js/JSFontFaceCustom.cpp: Copied from Source/WebCore/bindings/js/JSDOMPromise.cpp.
(WebCore::JSFontFace::loaded):
(WebCore::JSFontFace::load):
* css/CSSFontFace.cpp:
(WebCore::CSSFontFace::CSSFontFace):
(WebCore::CSSFontFace::adoptSource):
(WebCore::CSSFontFace::updateStatus): Enforce the state machine's transitions.
(WebCore::CSSFontFace::fontLoaded):
(WebCore::CSSFontFace::pump):
(WebCore::CSSFontFace::load):
* css/CSSFontFace.h:
(WebCore::CSSFontFaceClient::~CSSFontFaceClient):
(WebCore::CSSFontFace::create):
(WebCore::CSSFontFace::status):
* css/CSSFontSelector.cpp:
(WebCore::CSSFontSelector::appendSources): Update for new CSSFontFace API.
(WebCore::CSSFontSelector::registerLocalFontFacesForFamily): Ditto.
(WebCore::CSSFontSelector::addFontFaceRule): Ditto.
(WebCore::CSSFontSelector::kick): Ditto.
(WebCore::appendSources): Deleted.
(WebCore::registerLocalFontFacesForFamily): Deleted.
* css/CSSFontSelector.h:
* css/CSSUnicodeRangeValue.cpp: Use for serializing the "unicodeRange" property.
* css/FontFace.cpp:
(WebCore::createPromise): Implement the remaining Javascript API functions.
(WebCore::valueFromDictionary):
(WebCore::FontFace::create):
(WebCore::FontFace::FontFace):
(WebCore::FontFace::parseString):
(WebCore::FontFace::status):
(WebCore::FontFace::kick):
(WebCore::FontFace::load):
(WebCore::FontFace::fulfillPromise):
(WebCore::FontFace::rejectPromise):
(WebCore::parseString): Deleted.
* css/FontFace.h:
(WebCore::FontFace::promise):
(WebCore::FontFace::backing):
(WebCore::FontFace::create): Deleted.
* css/FontFace.idl: Copied from Source/WebCore/bindings/js/JSDOMPromise.cpp.

LayoutTests:

* fast/text/font-face-javascript-expected.txt: Added.
* fast/text/font-face-javascript.html: Added.
* js/dom/global-constructors-attributes-expected.txt:
* platform/efl/js/dom/global-constructors-attributes-expected.txt:
* platform/gtk/js/dom/global-constructors-attributes-expected.txt:
* platform/mac-mavericks/js/dom/global-constructors-attributes-expected.txt:
* platform/mac-yosemite/js/dom/global-constructors-attributes-expected.txt:
* platform/mac/js/dom/global-constructors-attributes-expected.txt:
* platform/win/js/dom/global-constructors-attributes-expected.txt:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@196604 268f45cc-cd09-0410-ab3c-d52691b4dbfc
28 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/text/font-face-javascript-expected.txt [new file with mode: 0644]
LayoutTests/fast/text/font-face-javascript.html [new file with mode: 0644]
LayoutTests/js/dom/global-constructors-attributes-expected.txt
LayoutTests/platform/efl/js/dom/global-constructors-attributes-expected.txt
LayoutTests/platform/gtk/js/dom/global-constructors-attributes-expected.txt
LayoutTests/platform/mac-mavericks/js/dom/global-constructors-attributes-expected.txt
LayoutTests/platform/mac-yosemite/js/dom/global-constructors-attributes-expected.txt
LayoutTests/platform/mac/js/dom/global-constructors-attributes-expected.txt
LayoutTests/platform/win/js/dom/global-constructors-attributes-expected.txt
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/DerivedSources.cpp
Source/WebCore/DerivedSources.make
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/JSDOMPromise.cpp
Source/WebCore/bindings/js/JSDOMPromise.h
Source/WebCore/bindings/js/JSFontFaceCustom.cpp [new file with mode: 0644]
Source/WebCore/css/CSSFontFace.cpp
Source/WebCore/css/CSSFontFace.h
Source/WebCore/css/CSSFontSelector.cpp
Source/WebCore/css/CSSFontSelector.h
Source/WebCore/css/CSSUnicodeRangeValue.cpp
Source/WebCore/css/FontFace.cpp
Source/WebCore/css/FontFace.h
Source/WebCore/css/FontFace.idl [new file with mode: 0644]