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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 : m_numLoading(faces.size()) | 68 : m_numLoading(faces.size()) |
69 , m_errorOccured(false) | 69 , m_errorOccured(false) |
70 , m_resolver(ScriptPromiseResolver::create(scriptState)) | 70 , m_resolver(ScriptPromiseResolver::create(scriptState)) |
71 { | 71 { |
72 m_fontFaces.swap(faces); | 72 m_fontFaces.swap(faces); |
73 } | 73 } |
74 | 74 |
75 WillBeHeapVector<RefPtrWillBeMember<FontFace>> m_fontFaces; | 75 WillBeHeapVector<RefPtrWillBeMember<FontFace>> m_fontFaces; |
76 int m_numLoading; | 76 int m_numLoading; |
77 bool m_errorOccured; | 77 bool m_errorOccured; |
78 RefPtrWillBeMember<ScriptPromiseResolver> m_resolver; | 78 PersistentWillBeMember<ScriptPromiseResolver> m_resolver; |
79 }; | 79 }; |
80 | 80 |
81 void LoadFontPromiseResolver::loadFonts(ExecutionContext* context) | 81 void LoadFontPromiseResolver::loadFonts(ExecutionContext* context) |
82 { | 82 { |
83 if (!m_numLoading) { | 83 if (!m_numLoading) { |
84 m_resolver->resolve(m_fontFaces); | 84 m_resolver->resolve(m_fontFaces); |
85 return; | 85 return; |
86 } | 86 } |
87 | 87 |
88 for (size_t i = 0; i < m_fontFaces.size(); i++) | 88 for (size_t i = 0; i < m_fontFaces.size(); i++) |
(...skipping 18 matching lines...) Expand all Loading... |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
110 DEFINE_TRACE(LoadFontPromiseResolver) | 110 DEFINE_TRACE(LoadFontPromiseResolver) |
111 { | 111 { |
112 visitor->trace(m_fontFaces); | 112 visitor->trace(m_fontFaces); |
113 visitor->trace(m_resolver); | 113 visitor->trace(m_resolver); |
114 LoadFontCallback::trace(visitor); | 114 LoadFontCallback::trace(visitor); |
115 } | 115 } |
116 | 116 |
117 class FontsReadyPromiseResolver final : public NoBaseWillBeGarbageCollected<Font
sReadyPromiseResolver> { | 117 class FontsReadyPromiseResolver final : public GarbageCollected<FontsReadyPromis
eResolver> { |
118 public: | 118 public: |
119 static PassOwnPtrWillBeRawPtr<FontsReadyPromiseResolver> create(ScriptState*
scriptState) | 119 static FontsReadyPromiseResolver* create(ScriptState* scriptState) |
120 { | 120 { |
121 return adoptPtrWillBeNoop(new FontsReadyPromiseResolver(scriptState)); | 121 return new FontsReadyPromiseResolver(scriptState); |
122 } | 122 } |
123 | 123 |
124 void resolve(PassRefPtrWillBeRawPtr<FontFaceSet> fontFaceSet) | 124 void resolve(PassRefPtrWillBeRawPtr<FontFaceSet> fontFaceSet) |
125 { | 125 { |
126 m_resolver->resolve(fontFaceSet); | 126 m_resolver->resolve(fontFaceSet); |
127 } | 127 } |
128 | 128 |
129 ScriptPromise promise() { return m_resolver->promise(); } | 129 ScriptPromise promise() { return m_resolver->promise(); } |
130 | 130 |
131 DEFINE_INLINE_TRACE() | 131 DEFINE_INLINE_TRACE() |
132 { | 132 { |
133 visitor->trace(m_resolver); | 133 visitor->trace(m_resolver); |
134 } | 134 } |
135 | 135 |
136 private: | 136 private: |
137 explicit FontsReadyPromiseResolver(ScriptState* scriptState) | 137 explicit FontsReadyPromiseResolver(ScriptState* scriptState) |
138 : m_resolver(ScriptPromiseResolver::create(scriptState)) | 138 : m_resolver(ScriptPromiseResolver::create(scriptState)) |
139 { | 139 { |
140 } | 140 } |
141 | 141 |
142 RefPtrWillBeMember<ScriptPromiseResolver> m_resolver; | 142 Member<ScriptPromiseResolver> m_resolver; |
143 }; | 143 }; |
144 | 144 |
145 FontFaceSet::FontFaceSet(Document& document) | 145 FontFaceSet::FontFaceSet(Document& document) |
146 : ActiveDOMObject(&document) | 146 : ActiveDOMObject(&document) |
147 , m_shouldFireLoadingEvent(false) | 147 , m_shouldFireLoadingEvent(false) |
148 , m_asyncRunner(this, &FontFaceSet::handlePendingEventsAndPromises) | 148 , m_asyncRunner(this, &FontFaceSet::handlePendingEventsAndPromises) |
149 { | 149 { |
150 suspendIfNeeded(); | 150 suspendIfNeeded(); |
151 } | 151 } |
152 | 152 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 { | 265 { |
266 m_loadingFonts.remove(fontFace); | 266 m_loadingFonts.remove(fontFace); |
267 if (m_loadingFonts.isEmpty()) | 267 if (m_loadingFonts.isEmpty()) |
268 handlePendingEventsAndPromisesSoon(); | 268 handlePendingEventsAndPromisesSoon(); |
269 } | 269 } |
270 | 270 |
271 ScriptPromise FontFaceSet::ready(ScriptState* scriptState) | 271 ScriptPromise FontFaceSet::ready(ScriptState* scriptState) |
272 { | 272 { |
273 if (!inActiveDocumentContext()) | 273 if (!inActiveDocumentContext()) |
274 return ScriptPromise(); | 274 return ScriptPromise(); |
275 OwnPtrWillBeRawPtr<FontsReadyPromiseResolver> resolver = FontsReadyPromiseRe
solver::create(scriptState); | 275 FontsReadyPromiseResolver* resolver = FontsReadyPromiseResolver::create(scri
ptState); |
276 ScriptPromise promise = resolver->promise(); | 276 ScriptPromise promise = resolver->promise(); |
277 m_readyResolvers.append(resolver.release()); | 277 m_readyResolvers.append(resolver); |
278 handlePendingEventsAndPromisesSoon(); | 278 handlePendingEventsAndPromisesSoon(); |
279 return promise; | 279 return promise; |
280 } | 280 } |
281 | 281 |
282 void FontFaceSet::add(FontFace* fontFace, ExceptionState& exceptionState) | 282 void FontFaceSet::add(FontFace* fontFace, ExceptionState& exceptionState) |
283 { | 283 { |
284 if (!inActiveDocumentContext()) | 284 if (!inActiveDocumentContext()) |
285 return; | 285 return; |
286 if (!fontFace) { | 286 if (!fontFace) { |
287 exceptionState.throwTypeError("The argument is not a FontFace."); | 287 exceptionState.throwTypeError("The argument is not a FontFace."); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 if (!m_failedFonts.isEmpty()) { | 422 if (!m_failedFonts.isEmpty()) { |
423 errorEvent = FontFaceSetLoadEvent::createForFontFaces(EventTypeNames
::loadingerror, m_failedFonts); | 423 errorEvent = FontFaceSetLoadEvent::createForFontFaces(EventTypeNames
::loadingerror, m_failedFonts); |
424 m_failedFonts.clear(); | 424 m_failedFonts.clear(); |
425 } | 425 } |
426 dispatchEvent(doneEvent); | 426 dispatchEvent(doneEvent); |
427 if (errorEvent) | 427 if (errorEvent) |
428 dispatchEvent(errorEvent); | 428 dispatchEvent(errorEvent); |
429 } | 429 } |
430 | 430 |
431 if (!m_readyResolvers.isEmpty()) { | 431 if (!m_readyResolvers.isEmpty()) { |
432 WillBeHeapVector<OwnPtrWillBeMember<FontsReadyPromiseResolver>> resolver
s; | 432 HeapVector<Member<FontsReadyPromiseResolver>> resolvers; |
433 m_readyResolvers.swap(resolvers); | 433 m_readyResolvers.swap(resolvers); |
434 for (size_t index = 0; index < resolvers.size(); ++index) | 434 for (size_t index = 0; index < resolvers.size(); ++index) |
435 resolvers[index]->resolve(this); | 435 resolvers[index]->resolve(this); |
436 } | 436 } |
437 } | 437 } |
438 | 438 |
439 ScriptPromise FontFaceSet::load(ScriptState* scriptState, const String& fontStri
ng, const String& text) | 439 ScriptPromise FontFaceSet::load(ScriptState* scriptState, const String& fontStri
ng, const String& text) |
440 { | 440 { |
441 if (!inActiveDocumentContext()) | 441 if (!inActiveDocumentContext()) |
442 return ScriptPromise(); | 442 return ScriptPromise(); |
443 | 443 |
444 Font font; | 444 Font font; |
445 if (!resolveFontStyle(fontString, font)) { | 445 if (!resolveFontStyle(fontString, font)) { |
446 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolv
er::create(scriptState); | 446 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptSt
ate); |
447 ScriptPromise promise = resolver->promise(); | 447 ScriptPromise promise = resolver->promise(); |
448 resolver->reject(DOMException::create(SyntaxError, "Could not resolve '"
+ fontString + "' as a font.")); | 448 resolver->reject(DOMException::create(SyntaxError, "Could not resolve '"
+ fontString + "' as a font.")); |
449 return promise; | 449 return promise; |
450 } | 450 } |
451 | 451 |
452 FontFaceCache* fontFaceCache = document()->styleEngine().fontSelector()->fon
tFaceCache(); | 452 FontFaceCache* fontFaceCache = document()->styleEngine().fontSelector()->fon
tFaceCache(); |
453 FontFaceArray faces; | 453 FontFaceArray faces; |
454 for (const FontFamily* f = &font.fontDescription().family(); f; f = f->next(
)) { | 454 for (const FontFamily* f = &font.fontDescription().family(); f; f = f->next(
)) { |
455 CSSSegmentedFontFace* segmentedFontFace = fontFaceCache->get(font.fontDe
scription(), f->family()); | 455 CSSSegmentedFontFace* segmentedFontFace = fontFaceCache->get(font.fontDe
scription(), f->family()); |
456 if (segmentedFontFace) | 456 if (segmentedFontFace) |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 } | 577 } |
578 | 578 |
579 DEFINE_TRACE(FontFaceSet) | 579 DEFINE_TRACE(FontFaceSet) |
580 { | 580 { |
581 #if ENABLE(OILPAN) | 581 #if ENABLE(OILPAN) |
582 visitor->trace(m_loadingFonts); | 582 visitor->trace(m_loadingFonts); |
583 visitor->trace(m_readyResolvers); | 583 visitor->trace(m_readyResolvers); |
584 visitor->trace(m_loadedFonts); | 584 visitor->trace(m_loadedFonts); |
585 visitor->trace(m_failedFonts); | 585 visitor->trace(m_failedFonts); |
586 visitor->trace(m_nonCSSConnectedFaces); | 586 visitor->trace(m_nonCSSConnectedFaces); |
587 WillBeHeapSupplement<Document>::trace(visitor); | 587 HeapSupplement<Document>::trace(visitor); |
588 #endif | 588 #endif |
589 EventTargetWithInlineData::trace(visitor); | 589 EventTargetWithInlineData::trace(visitor); |
590 ActiveDOMObject::trace(visitor); | 590 ActiveDOMObject::trace(visitor); |
591 } | 591 } |
592 | 592 |
593 } // namespace blink | 593 } // namespace blink |
OLD | NEW |