| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are met: | 5 * modification, are permitted provided that the following conditions are met: |
| 6 * | 6 * |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 : public GarbageCollectedFinalized<LoadFontPromiseResolver>, | 51 : public GarbageCollectedFinalized<LoadFontPromiseResolver>, |
| 52 public FontFace::LoadFontCallback { | 52 public FontFace::LoadFontCallback { |
| 53 USING_GARBAGE_COLLECTED_MIXIN(LoadFontPromiseResolver); | 53 USING_GARBAGE_COLLECTED_MIXIN(LoadFontPromiseResolver); |
| 54 | 54 |
| 55 public: | 55 public: |
| 56 static LoadFontPromiseResolver* create(FontFaceArray faces, | 56 static LoadFontPromiseResolver* create(FontFaceArray faces, |
| 57 ScriptState* scriptState) { | 57 ScriptState* scriptState) { |
| 58 return new LoadFontPromiseResolver(faces, scriptState); | 58 return new LoadFontPromiseResolver(faces, scriptState); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void loadFonts(ExecutionContext*); | 61 void loadFonts(); |
| 62 ScriptPromise promise() { return m_resolver->promise(); } | 62 ScriptPromise promise() { return m_resolver->promise(); } |
| 63 | 63 |
| 64 void notifyLoaded(FontFace*) override; | 64 void notifyLoaded(FontFace*) override; |
| 65 void notifyError(FontFace*) override; | 65 void notifyError(FontFace*) override; |
| 66 | 66 |
| 67 DECLARE_VIRTUAL_TRACE(); | 67 DECLARE_VIRTUAL_TRACE(); |
| 68 | 68 |
| 69 private: | 69 private: |
| 70 LoadFontPromiseResolver(FontFaceArray faces, ScriptState* scriptState) | 70 LoadFontPromiseResolver(FontFaceArray faces, ScriptState* scriptState) |
| 71 : m_numLoading(faces.size()), | 71 : m_numLoading(faces.size()), |
| 72 m_errorOccured(false), | 72 m_errorOccured(false), |
| 73 m_resolver(ScriptPromiseResolver::create(scriptState)) { | 73 m_resolver(ScriptPromiseResolver::create(scriptState)) { |
| 74 m_fontFaces.swap(faces); | 74 m_fontFaces.swap(faces); |
| 75 } | 75 } |
| 76 | 76 |
| 77 HeapVector<Member<FontFace>> m_fontFaces; | 77 HeapVector<Member<FontFace>> m_fontFaces; |
| 78 int m_numLoading; | 78 int m_numLoading; |
| 79 bool m_errorOccured; | 79 bool m_errorOccured; |
| 80 Member<ScriptPromiseResolver> m_resolver; | 80 Member<ScriptPromiseResolver> m_resolver; |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 void LoadFontPromiseResolver::loadFonts(ExecutionContext* context) { | 83 void LoadFontPromiseResolver::loadFonts() { |
| 84 if (!m_numLoading) { | 84 if (!m_numLoading) { |
| 85 m_resolver->resolve(m_fontFaces); | 85 m_resolver->resolve(m_fontFaces); |
| 86 return; | 86 return; |
| 87 } | 87 } |
| 88 | 88 |
| 89 for (size_t i = 0; i < m_fontFaces.size(); i++) | 89 for (size_t i = 0; i < m_fontFaces.size(); i++) |
| 90 m_fontFaces[i]->loadWithCallback(this, context); | 90 m_fontFaces[i]->loadWithCallback(this); |
| 91 } | 91 } |
| 92 | 92 |
| 93 void LoadFontPromiseResolver::notifyLoaded(FontFace* fontFace) { | 93 void LoadFontPromiseResolver::notifyLoaded(FontFace* fontFace) { |
| 94 m_numLoading--; | 94 m_numLoading--; |
| 95 if (m_numLoading || m_errorOccured) | 95 if (m_numLoading || m_errorOccured) |
| 96 return; | 96 return; |
| 97 | 97 |
| 98 m_resolver->resolve(m_fontFaces); | 98 m_resolver->resolve(m_fontFaces); |
| 99 } | 99 } |
| 100 | 100 |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 CSSSegmentedFontFace* segmentedFontFace = | 389 CSSSegmentedFontFace* segmentedFontFace = |
| 390 fontFaceCache->get(font.getFontDescription(), f->family()); | 390 fontFaceCache->get(font.getFontDescription(), f->family()); |
| 391 if (segmentedFontFace) | 391 if (segmentedFontFace) |
| 392 segmentedFontFace->match(text, faces); | 392 segmentedFontFace->match(text, faces); |
| 393 } | 393 } |
| 394 | 394 |
| 395 LoadFontPromiseResolver* resolver = | 395 LoadFontPromiseResolver* resolver = |
| 396 LoadFontPromiseResolver::create(faces, scriptState); | 396 LoadFontPromiseResolver::create(faces, scriptState); |
| 397 ScriptPromise promise = resolver->promise(); | 397 ScriptPromise promise = resolver->promise(); |
| 398 // After this, resolver->promise() may return null. | 398 // After this, resolver->promise() may return null. |
| 399 resolver->loadFonts(getExecutionContext()); | 399 resolver->loadFonts(); |
| 400 return promise; | 400 return promise; |
| 401 } | 401 } |
| 402 | 402 |
| 403 bool FontFaceSet::check(const String& fontString, | 403 bool FontFaceSet::check(const String& fontString, |
| 404 const String& text, | 404 const String& text, |
| 405 ExceptionState& exceptionState) { | 405 ExceptionState& exceptionState) { |
| 406 if (!inActiveDocumentContext()) | 406 if (!inActiveDocumentContext()) |
| 407 return false; | 407 return false; |
| 408 | 408 |
| 409 Font font; | 409 Font font; |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 visitor->trace(m_failedFonts); | 561 visitor->trace(m_failedFonts); |
| 562 visitor->trace(m_nonCSSConnectedFaces); | 562 visitor->trace(m_nonCSSConnectedFaces); |
| 563 visitor->trace(m_asyncRunner); | 563 visitor->trace(m_asyncRunner); |
| 564 EventTargetWithInlineData::trace(visitor); | 564 EventTargetWithInlineData::trace(visitor); |
| 565 Supplement<Document>::trace(visitor); | 565 Supplement<Document>::trace(visitor); |
| 566 SuspendableObject::trace(visitor); | 566 SuspendableObject::trace(visitor); |
| 567 FontFace::LoadFontCallback::trace(visitor); | 567 FontFace::LoadFontCallback::trace(visitor); |
| 568 } | 568 } |
| 569 | 569 |
| 570 } // namespace blink | 570 } // namespace blink |
| OLD | NEW |