Chromium Code Reviews| Index: Source/core/css/FontFace.cpp |
| diff --git a/Source/core/css/FontFace.cpp b/Source/core/css/FontFace.cpp |
| index 4a604d50f318710b8eaa28d8f5d844d15764c17f..a76660c1060e4bdfb32a9191c5e233335eb5eef7 100644 |
| --- a/Source/core/css/FontFace.cpp |
| +++ b/Source/core/css/FontFace.cpp |
| @@ -378,8 +378,18 @@ void FontFace::setLoadStatus(LoadStatus status) |
| m_status = status; |
| if (m_status == Error) |
| m_error = DOMError::create(NetworkError); |
| - if (m_status == Loaded || m_status == Error) |
| + if (m_status == Loaded || m_status == Error) { |
| resolveReadyPromises(); |
| + |
| + Vector<RefPtr<LoadFontCallback> > callbacks; |
| + m_callbacks.swap(callbacks); |
| + for (size_t i = 0; i < callbacks.size(); ++i) { |
| + if (m_status == Loaded) |
| + callbacks[i]->notifyLoaded(this); |
| + else |
| + callbacks[i]->notifyError(this); |
| + } |
| + } |
| } |
| ScriptPromise FontFace::load(ExecutionContext* context) |
|
dglazkov
2014/03/19 15:42:34
This is the actual Promise FontFace.load. Maybe it
Kunihiko Sakamoto
2014/03/20 01:06:32
This is a method of the FontFace interface, so it'
|
| @@ -391,20 +401,37 @@ ScriptPromise FontFace::load(ExecutionContext* context) |
| else |
| 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(); |
| - } |
| + loadInternal(context); |
| return promise; |
| } |
| +void FontFace::load(PassRefPtr<LoadFontCallback> callback, ExecutionContext* context) |
| +{ |
| + loadInternal(context); |
| + if (m_status == Loaded) |
| + callback->notifyLoaded(this); |
| + else if (m_status == Error) |
| + callback->notifyError(this); |
| + else |
| + m_callbacks.append(callback); |
| +} |
| + |
| +void FontFace::loadInternal(ExecutionContext* context) |
|
dglazkov
2014/03/19 15:42:34
This is the actual "load"
|
| +{ |
| + 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(); |
| +} |
| + |
| void FontFace::resolveReadyPromises() |
| { |
| for (size_t i = 0; i < m_readyResolvers.size(); i++) |