| 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(); | 61 void loadFonts(Document*); |
| 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() { | 83 void LoadFontPromiseResolver::loadFonts(Document* document) { |
| 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); | 90 m_fontFaces[i]->loadWithCallback(document, 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 } | 132 } |
| 133 | 133 |
| 134 bool FontFaceSet::inActiveDocumentContext() const { | 134 bool FontFaceSet::inActiveDocumentContext() const { |
| 135 ExecutionContext* context = getExecutionContext(); | 135 ExecutionContext* context = getExecutionContext(); |
| 136 return context && toDocument(context)->isActive(); | 136 return context && toDocument(context)->isActive(); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void FontFaceSet::addFontFacesToFontFaceCache(CSSFontSelector* fontSelector) { | 139 void FontFaceSet::addFontFacesToFontFaceCache(CSSFontSelector* fontSelector) { |
| 140 FontFaceCache* fontFaceCache = document()->fontFaceCache(); | 140 FontFaceCache* fontFaceCache = document()->fontFaceCache(); |
| 141 for (const auto& fontFace : m_nonCSSConnectedFaces) | 141 for (const auto& fontFace : m_nonCSSConnectedFaces) |
| 142 fontFaceCache->addFontFace(fontSelector, fontFace, false); | 142 fontFaceCache->addFontFace(fontFace, false); |
| 143 } | 143 } |
| 144 | 144 |
| 145 const AtomicString& FontFaceSet::interfaceName() const { | 145 const AtomicString& FontFaceSet::interfaceName() const { |
| 146 return EventTargetNames::FontFaceSet; | 146 return EventTargetNames::FontFaceSet; |
| 147 } | 147 } |
| 148 | 148 |
| 149 ExecutionContext* FontFaceSet::getExecutionContext() const { | 149 ExecutionContext* FontFaceSet::getExecutionContext() const { |
| 150 return SuspendableObject::getExecutionContext(); | 150 return SuspendableObject::getExecutionContext(); |
| 151 } | 151 } |
| 152 | 152 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 ExceptionState&) { | 251 ExceptionState&) { |
| 252 ASSERT(fontFace); | 252 ASSERT(fontFace); |
| 253 if (!inActiveDocumentContext()) | 253 if (!inActiveDocumentContext()) |
| 254 return this; | 254 return this; |
| 255 if (m_nonCSSConnectedFaces.contains(fontFace)) | 255 if (m_nonCSSConnectedFaces.contains(fontFace)) |
| 256 return this; | 256 return this; |
| 257 if (isCSSConnectedFontFace(fontFace)) | 257 if (isCSSConnectedFontFace(fontFace)) |
| 258 return this; | 258 return this; |
| 259 CSSFontSelector* fontSelector = document()->styleEngine().fontSelector(); | 259 CSSFontSelector* fontSelector = document()->styleEngine().fontSelector(); |
| 260 m_nonCSSConnectedFaces.add(fontFace); | 260 m_nonCSSConnectedFaces.add(fontFace); |
| 261 document()->fontFaceCache()->addFontFace(fontSelector, fontFace, false); | 261 document()->fontFaceCache()->addFontFace(fontFace, false); |
| 262 if (fontFace->loadStatus() == FontFace::Loading) | 262 if (fontFace->loadStatus() == FontFace::Loading) |
| 263 addToLoadingFonts(fontFace); | 263 addToLoadingFonts(fontFace); |
| 264 fontSelector->fontFaceInvalidated(); | 264 fontSelector->fontFaceInvalidated(); |
| 265 return this; | 265 return this; |
| 266 } | 266 } |
| 267 | 267 |
| 268 void FontFaceSet::clearForBinding(ScriptState*, ExceptionState&) { | 268 void FontFaceSet::clearForBinding(ScriptState*, ExceptionState&) { |
| 269 if (!inActiveDocumentContext() || m_nonCSSConnectedFaces.isEmpty()) | 269 if (!inActiveDocumentContext() || m_nonCSSConnectedFaces.isEmpty()) |
| 270 return; | 270 return; |
| 271 CSSFontSelector* fontSelector = document()->styleEngine().fontSelector(); | 271 CSSFontSelector* fontSelector = document()->styleEngine().fontSelector(); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 CSSSegmentedFontFace* segmentedFontFace = | 385 CSSSegmentedFontFace* segmentedFontFace = |
| 386 fontFaceCache->get(font.getFontDescription(), f->family()); | 386 fontFaceCache->get(font.getFontDescription(), f->family()); |
| 387 if (segmentedFontFace) | 387 if (segmentedFontFace) |
| 388 segmentedFontFace->match(text, faces); | 388 segmentedFontFace->match(text, faces); |
| 389 } | 389 } |
| 390 | 390 |
| 391 LoadFontPromiseResolver* resolver = | 391 LoadFontPromiseResolver* resolver = |
| 392 LoadFontPromiseResolver::create(faces, scriptState); | 392 LoadFontPromiseResolver::create(faces, scriptState); |
| 393 ScriptPromise promise = resolver->promise(); | 393 ScriptPromise promise = resolver->promise(); |
| 394 // After this, resolver->promise() may return null. | 394 // After this, resolver->promise() may return null. |
| 395 resolver->loadFonts(); | 395 resolver->loadFonts(document()); |
| 396 return promise; | 396 return promise; |
| 397 } | 397 } |
| 398 | 398 |
| 399 bool FontFaceSet::check(const String& fontString, | 399 bool FontFaceSet::check(const String& fontString, |
| 400 const String& text, | 400 const String& text, |
| 401 ExceptionState& exceptionState) { | 401 ExceptionState& exceptionState) { |
| 402 if (!inActiveDocumentContext()) | 402 if (!inActiveDocumentContext()) |
| 403 return false; | 403 return false; |
| 404 | 404 |
| 405 Font font; | 405 Font font; |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 visitor->trace(m_failedFonts); | 557 visitor->trace(m_failedFonts); |
| 558 visitor->trace(m_nonCSSConnectedFaces); | 558 visitor->trace(m_nonCSSConnectedFaces); |
| 559 visitor->trace(m_asyncRunner); | 559 visitor->trace(m_asyncRunner); |
| 560 EventTargetWithInlineData::trace(visitor); | 560 EventTargetWithInlineData::trace(visitor); |
| 561 Supplement<Document>::trace(visitor); | 561 Supplement<Document>::trace(visitor); |
| 562 SuspendableObject::trace(visitor); | 562 SuspendableObject::trace(visitor); |
| 563 FontFace::LoadFontCallback::trace(visitor); | 563 FontFace::LoadFontCallback::trace(visitor); |
| 564 } | 564 } |
| 565 | 565 |
| 566 } // namespace blink | 566 } // namespace blink |
| OLD | NEW |