[CSS Font Loading] Remove FontFace#ready, fold its functionality into FontFace#load

As per a discussion on www-style [1], FontFace#ready is removed from the
spec [2], and FontFace#load() is changed to return a Promise which
fulfills when the font is ready.

[1] http://lists.w3.org/Archives/Public/www-style/2014Mar/0069.html
[2] http://dev.w3.org/csswg/css-font-loading/

TEST=fast/css/fontface-methods.html
BUG=53213

Review URL: https://codereview.chromium.org/184633005

git-svn-id: svn://svn.chromium.org/blink/trunk@169507 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent abe45cd7
...@@ -25,7 +25,7 @@ document.fonts.add(face2); ...@@ -25,7 +25,7 @@ document.fonts.add(face2);
var face3 = new FontFace('FontFromEmptyArrayBuffer', new ArrayBuffer(0), {}); var face3 = new FontFace('FontFromEmptyArrayBuffer', new ArrayBuffer(0), {});
shouldBeEqualToString('face3.status', 'error'); shouldBeEqualToString('face3.status', 'error');
face3.ready().catch(function(v) { face3.load().catch(function(v) {
rejectionValue = v; rejectionValue = v;
shouldBeEqualToString('rejectionValue.name', 'SyntaxError'); shouldBeEqualToString('rejectionValue.name', 'SyntaxError');
document.fonts.ready().then(verify); document.fonts.ready().then(verify);
......
Tests load() and ready() methods of FontFace. Tests load() method of FontFace.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
} }
</style> </style>
<script> <script>
description('Tests load() and ready() methods of FontFace.'); description('Tests load() method of FontFace.');
window.jsTestIsAsync = true; window.jsTestIsAsync = true;
...@@ -35,18 +35,16 @@ function testStep1() { ...@@ -35,18 +35,16 @@ function testStep1() {
face1 = faces[0]; face1 = faces[0];
face2 = faces[1]; face2 = faces[1];
face1.ready().then(testStep2, fail('face1.ready() rejected'));
shouldBeEqualToString('face1.status', 'unloaded'); shouldBeEqualToString('face1.status', 'unloaded');
face1.load(); face1.load().then(testStep2, fail('face1.load() rejected'));
shouldBeEqualToString('face1.status', 'loading'); shouldBeEqualToString('face1.status', 'loading');
} }
function testStep2() { function testStep2() {
shouldBeEqualToString('face1.status', 'loaded'); shouldBeEqualToString('face1.status', 'loaded');
face2.ready().then(fail('face2.ready() fulfilled'), testStep3);
shouldBeEqualToString('face2.status', 'unloaded'); shouldBeEqualToString('face2.status', 'unloaded');
face2.load(); face2.load().then(fail('face2.load() fulfilled'), testStep3);
shouldBeEqualToString('face2.status', 'loading'); shouldBeEqualToString('face2.status', 'loading');
} }
...@@ -54,9 +52,8 @@ function testStep3() { ...@@ -54,9 +52,8 @@ function testStep3() {
shouldBeEqualToString('face2.status', 'error'); shouldBeEqualToString('face2.status', 'error');
face3 = new FontFace('Font3', 'url(../../resources/Ahem.ttf)', {}); face3 = new FontFace('Font3', 'url(../../resources/Ahem.ttf)', {});
face3.ready().then(testStep4, fail('face3.ready() rejected'));
shouldBeEqualToString('face3.status', 'unloaded'); shouldBeEqualToString('face3.status', 'unloaded');
face3.load(); face3.load().then(testStep4, fail('face3.load() rejected'));
shouldBeEqualToString('face3.status', 'loading'); shouldBeEqualToString('face3.status', 'loading');
} }
...@@ -64,9 +61,8 @@ function testStep4() { ...@@ -64,9 +61,8 @@ function testStep4() {
shouldBeEqualToString('face3.status', 'loaded'); shouldBeEqualToString('face3.status', 'loaded');
face4 = new FontFace('Font4', 'url(../../resources/DownLoadErrorAhem.otf)', {}); face4 = new FontFace('Font4', 'url(../../resources/DownLoadErrorAhem.otf)', {});
face4.ready().then(fail('face4.ready() fulfilled'), testStep5);
shouldBeEqualToString('face4.status', 'unloaded'); shouldBeEqualToString('face4.status', 'unloaded');
face4.load(); face4.load().then(fail('face4.load() fulfilled'), testStep5);
shouldBeEqualToString('face4.status', 'loading'); shouldBeEqualToString('face4.status', 'loading');
} }
......
...@@ -27,14 +27,12 @@ function testStep2() { ...@@ -27,14 +27,12 @@ function testStep2() {
shouldBeEqualToString('face2.status', 'unloaded'); shouldBeEqualToString('face2.status', 'unloaded');
document.fonts.add(face2); document.fonts.add(face2);
face2.load(); face2.load().then(testStep3);
shouldBeEqualToString('document.fonts.status', 'loading'); shouldBeEqualToString('document.fonts.status', 'loading');
document.fonts.delete(face2); document.fonts.delete(face2);
shouldBeEqualToString('document.fonts.status', 'loaded'); shouldBeEqualToString('document.fonts.status', 'loaded');
shouldBeEqualToString('face2.status', 'loading'); shouldBeEqualToString('face2.status', 'loading');
face2.ready().then(testStep3);
} }
function testStep3() { function testStep3() {
......
...@@ -382,23 +382,7 @@ void FontFace::setLoadStatus(LoadStatus status) ...@@ -382,23 +382,7 @@ void FontFace::setLoadStatus(LoadStatus status)
resolveReadyPromises(); resolveReadyPromises();
} }
void FontFace::load(ExecutionContext* context) ScriptPromise FontFace::load(ExecutionContext* context)
{
if (m_status != Unloaded)
return;
FontDescription fontDescription;
FontFamily fontFamily;
fontFamily.setFamily(m_family);
fontDescription.setFamily(fontFamily);
fontDescription.setTraits(traits());
CSSFontSelector* fontSelector = toDocument(context)->styleEngine()->fontSelector();
m_cssFontFace->load(fontDescription, fontSelector);
fontSelector->loadPendingFonts();
}
ScriptPromise FontFace::ready(ExecutionContext* context)
{ {
OwnPtr<FontFaceReadyPromiseResolver> resolver = FontFaceReadyPromiseResolver::create(context); OwnPtr<FontFaceReadyPromiseResolver> resolver = FontFaceReadyPromiseResolver::create(context);
ScriptPromise promise = resolver->promise(); ScriptPromise promise = resolver->promise();
...@@ -406,6 +390,18 @@ ScriptPromise FontFace::ready(ExecutionContext* context) ...@@ -406,6 +390,18 @@ ScriptPromise FontFace::ready(ExecutionContext* context)
resolver->resolve(this); resolver->resolve(this);
else else
m_readyResolvers.append(resolver.release()); m_readyResolvers.append(resolver.release());
if (m_status == Unloaded) {
FontDescription fontDescription;
FontFamily fontFamily;
fontFamily.setFamily(m_family);
fontDescription.setFamily(fontFamily);
fontDescription.setTraits(traits());
CSSFontSelector* fontSelector = toDocument(context)->styleEngine()->fontSelector();
m_cssFontFace->load(fontDescription, fontSelector);
fontSelector->loadPendingFonts();
}
return promise; return promise;
} }
......
...@@ -81,8 +81,7 @@ public: ...@@ -81,8 +81,7 @@ public:
String status() const; String status() const;
void load(ExecutionContext*); ScriptPromise load(ExecutionContext*);
ScriptPromise ready(ExecutionContext*);
LoadStatus loadStatus() const { return m_status; } LoadStatus loadStatus() const { return m_status; }
void setLoadStatus(LoadStatus); void setLoadStatus(LoadStatus);
......
...@@ -54,6 +54,5 @@ enum FontFaceLoadStatus { ...@@ -54,6 +54,5 @@ enum FontFaceLoadStatus {
readonly attribute FontFaceLoadStatus status; readonly attribute FontFaceLoadStatus status;
[CallWith=ExecutionContext] void load(); [CallWith=ExecutionContext] Promise load();
[CallWith=ExecutionContext] Promise ready();
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment