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 RefPtr<ScriptPromiseResolver> m_resolver; | 78 RefPtrWillBeMember<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 14 matching lines...) Expand all Loading... |
103 m_numLoading--; | 103 m_numLoading--; |
104 if (!m_errorOccured) { | 104 if (!m_errorOccured) { |
105 m_errorOccured = true; | 105 m_errorOccured = true; |
106 m_resolver->reject(fontFace->error()); | 106 m_resolver->reject(fontFace->error()); |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
110 void LoadFontPromiseResolver::trace(Visitor* visitor) | 110 void LoadFontPromiseResolver::trace(Visitor* visitor) |
111 { | 111 { |
112 visitor->trace(m_fontFaces); | 112 visitor->trace(m_fontFaces); |
| 113 visitor->trace(m_resolver); |
113 LoadFontCallback::trace(visitor); | 114 LoadFontCallback::trace(visitor); |
114 } | 115 } |
115 | 116 |
116 class FontsReadyPromiseResolver { | 117 class FontsReadyPromiseResolver final : public NoBaseWillBeGarbageCollected<Font
sReadyPromiseResolver> { |
117 public: | 118 public: |
118 static PassOwnPtr<FontsReadyPromiseResolver> create(ScriptState* scriptState
) | 119 static PassOwnPtrWillBeRawPtr<FontsReadyPromiseResolver> create(ScriptState*
scriptState) |
119 { | 120 { |
120 return adoptPtr(new FontsReadyPromiseResolver(scriptState)); | 121 return adoptPtrWillBeNoop(new FontsReadyPromiseResolver(scriptState)); |
121 } | 122 } |
122 | 123 |
123 void resolve(PassRefPtrWillBeRawPtr<FontFaceSet> fontFaceSet) | 124 void resolve(PassRefPtrWillBeRawPtr<FontFaceSet> fontFaceSet) |
124 { | 125 { |
125 m_resolver->resolve(fontFaceSet); | 126 m_resolver->resolve(fontFaceSet); |
126 } | 127 } |
127 | 128 |
128 ScriptPromise promise() { return m_resolver->promise(); } | 129 ScriptPromise promise() { return m_resolver->promise(); } |
129 | 130 |
| 131 void trace(Visitor* visitor) |
| 132 { |
| 133 visitor->trace(m_resolver); |
| 134 } |
| 135 |
130 private: | 136 private: |
131 explicit FontsReadyPromiseResolver(ScriptState* scriptState) | 137 explicit FontsReadyPromiseResolver(ScriptState* scriptState) |
132 : m_resolver(ScriptPromiseResolver::create(scriptState)) | 138 : m_resolver(ScriptPromiseResolver::create(scriptState)) |
133 { | 139 { |
134 } | 140 } |
135 | 141 |
136 RefPtr<ScriptPromiseResolver> m_resolver; | 142 RefPtrWillBeMember<ScriptPromiseResolver> m_resolver; |
137 }; | 143 }; |
138 | 144 |
139 FontFaceSet::FontFaceSet(Document& document) | 145 FontFaceSet::FontFaceSet(Document& document) |
140 : ActiveDOMObject(&document) | 146 : ActiveDOMObject(&document) |
141 , m_shouldFireLoadingEvent(false) | 147 , m_shouldFireLoadingEvent(false) |
142 , m_asyncRunner(this, &FontFaceSet::handlePendingEventsAndPromises) | 148 , m_asyncRunner(this, &FontFaceSet::handlePendingEventsAndPromises) |
143 { | 149 { |
144 suspendIfNeeded(); | 150 suspendIfNeeded(); |
145 } | 151 } |
146 | 152 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 { | 265 { |
260 m_loadingFonts.remove(fontFace); | 266 m_loadingFonts.remove(fontFace); |
261 if (m_loadingFonts.isEmpty()) | 267 if (m_loadingFonts.isEmpty()) |
262 handlePendingEventsAndPromisesSoon(); | 268 handlePendingEventsAndPromisesSoon(); |
263 } | 269 } |
264 | 270 |
265 ScriptPromise FontFaceSet::ready(ScriptState* scriptState) | 271 ScriptPromise FontFaceSet::ready(ScriptState* scriptState) |
266 { | 272 { |
267 if (!inActiveDocumentContext()) | 273 if (!inActiveDocumentContext()) |
268 return ScriptPromise(); | 274 return ScriptPromise(); |
269 OwnPtr<FontsReadyPromiseResolver> resolver = FontsReadyPromiseResolver::crea
te(scriptState); | 275 OwnPtrWillBeRawPtr<FontsReadyPromiseResolver> resolver = FontsReadyPromiseRe
solver::create(scriptState); |
270 ScriptPromise promise = resolver->promise(); | 276 ScriptPromise promise = resolver->promise(); |
271 m_readyResolvers.append(resolver.release()); | 277 m_readyResolvers.append(resolver.release()); |
272 handlePendingEventsAndPromisesSoon(); | 278 handlePendingEventsAndPromisesSoon(); |
273 return promise; | 279 return promise; |
274 } | 280 } |
275 | 281 |
276 void FontFaceSet::add(FontFace* fontFace, ExceptionState& exceptionState) | 282 void FontFaceSet::add(FontFace* fontFace, ExceptionState& exceptionState) |
277 { | 283 { |
278 if (!inActiveDocumentContext()) | 284 if (!inActiveDocumentContext()) |
279 return; | 285 return; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 if (!m_failedFonts.isEmpty()) { | 422 if (!m_failedFonts.isEmpty()) { |
417 errorEvent = FontFaceSetLoadEvent::createForFontFaces(EventTypeNames
::loadingerror, m_failedFonts); | 423 errorEvent = FontFaceSetLoadEvent::createForFontFaces(EventTypeNames
::loadingerror, m_failedFonts); |
418 m_failedFonts.clear(); | 424 m_failedFonts.clear(); |
419 } | 425 } |
420 dispatchEvent(doneEvent); | 426 dispatchEvent(doneEvent); |
421 if (errorEvent) | 427 if (errorEvent) |
422 dispatchEvent(errorEvent); | 428 dispatchEvent(errorEvent); |
423 } | 429 } |
424 | 430 |
425 if (!m_readyResolvers.isEmpty()) { | 431 if (!m_readyResolvers.isEmpty()) { |
426 Vector<OwnPtr<FontsReadyPromiseResolver> > resolvers; | 432 WillBeHeapVector<OwnPtrWillBeMember<FontsReadyPromiseResolver> > resolve
rs; |
427 m_readyResolvers.swap(resolvers); | 433 m_readyResolvers.swap(resolvers); |
428 for (size_t index = 0; index < resolvers.size(); ++index) | 434 for (size_t index = 0; index < resolvers.size(); ++index) |
429 resolvers[index]->resolve(this); | 435 resolvers[index]->resolve(this); |
430 } | 436 } |
431 } | 437 } |
432 | 438 |
433 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) |
434 { | 440 { |
435 if (!inActiveDocumentContext()) | 441 if (!inActiveDocumentContext()) |
436 return ScriptPromise(); | 442 return ScriptPromise(); |
437 | 443 |
438 Font font; | 444 Font font; |
439 if (!resolveFontStyle(fontString, font)) { | 445 if (!resolveFontStyle(fontString, font)) { |
440 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(s
criptState); | 446 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolv
er::create(scriptState); |
441 ScriptPromise promise = resolver->promise(); | 447 ScriptPromise promise = resolver->promise(); |
442 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.")); |
443 return promise; | 449 return promise; |
444 } | 450 } |
445 | 451 |
446 FontFaceCache* fontFaceCache = document()->styleEngine()->fontSelector()->fo
ntFaceCache(); | 452 FontFaceCache* fontFaceCache = document()->styleEngine()->fontSelector()->fo
ntFaceCache(); |
447 FontFaceArray faces; | 453 FontFaceArray faces; |
448 for (const FontFamily* f = &font.fontDescription().family(); f; f = f->next(
)) { | 454 for (const FontFamily* f = &font.fontDescription().family(); f; f = f->next(
)) { |
449 CSSSegmentedFontFace* segmentedFontFace = fontFaceCache->get(font.fontDe
scription(), f->family()); | 455 CSSSegmentedFontFace* segmentedFontFace = fontFaceCache->get(font.fontDe
scription(), f->family()); |
450 if (segmentedFontFace) | 456 if (segmentedFontFace) |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 void FontFaceSet::didLayout(Document& document) | 583 void FontFaceSet::didLayout(Document& document) |
578 { | 584 { |
579 if (FontFaceSet* fonts = static_cast<FontFaceSet*>(SupplementType::from(docu
ment, supplementName()))) | 585 if (FontFaceSet* fonts = static_cast<FontFaceSet*>(SupplementType::from(docu
ment, supplementName()))) |
580 fonts->didLayout(); | 586 fonts->didLayout(); |
581 } | 587 } |
582 | 588 |
583 #if ENABLE(OILPAN) | 589 #if ENABLE(OILPAN) |
584 void FontFaceSet::trace(Visitor* visitor) | 590 void FontFaceSet::trace(Visitor* visitor) |
585 { | 591 { |
586 visitor->trace(m_loadingFonts); | 592 visitor->trace(m_loadingFonts); |
| 593 visitor->trace(m_readyResolvers); |
587 visitor->trace(m_loadedFonts); | 594 visitor->trace(m_loadedFonts); |
588 visitor->trace(m_failedFonts); | 595 visitor->trace(m_failedFonts); |
589 visitor->trace(m_nonCSSConnectedFaces); | 596 visitor->trace(m_nonCSSConnectedFaces); |
590 DocumentSupplement::trace(visitor); | 597 DocumentSupplement::trace(visitor); |
591 EventTargetWithInlineData::trace(visitor); | 598 EventTargetWithInlineData::trace(visitor); |
592 } | 599 } |
593 #endif | 600 #endif |
594 | 601 |
595 } // namespace blink | 602 } // namespace blink |
OLD | NEW |