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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 65 |
66 private: | 66 private: |
67 LoadFontPromiseResolver(FontFaceArray faces, ScriptState* scriptState) | 67 LoadFontPromiseResolver(FontFaceArray faces, ScriptState* scriptState) |
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 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; |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 } | 317 } |
318 | 318 |
319 bool FontFaceSet::remove(FontFace* fontFace, ExceptionState& exceptionState) | 319 bool FontFaceSet::remove(FontFace* fontFace, ExceptionState& exceptionState) |
320 { | 320 { |
321 if (!inActiveDocumentContext()) | 321 if (!inActiveDocumentContext()) |
322 return false; | 322 return false; |
323 if (!fontFace) { | 323 if (!fontFace) { |
324 exceptionState.throwTypeError("The argument is not a FontFace."); | 324 exceptionState.throwTypeError("The argument is not a FontFace."); |
325 return false; | 325 return false; |
326 } | 326 } |
327 WillBeHeapListHashSet<RefPtrWillBeMember<FontFace> >::iterator it = m_nonCSS
ConnectedFaces.find(fontFace); | 327 WillBeHeapListHashSet<RefPtrWillBeMember<FontFace>>::iterator it = m_nonCSSC
onnectedFaces.find(fontFace); |
328 if (it != m_nonCSSConnectedFaces.end()) { | 328 if (it != m_nonCSSConnectedFaces.end()) { |
329 m_nonCSSConnectedFaces.remove(it); | 329 m_nonCSSConnectedFaces.remove(it); |
330 CSSFontSelector* fontSelector = document()->styleEngine().fontSelector()
; | 330 CSSFontSelector* fontSelector = document()->styleEngine().fontSelector()
; |
331 fontSelector->fontFaceCache()->removeFontFace(fontFace, false); | 331 fontSelector->fontFaceCache()->removeFontFace(fontFace, false); |
332 if (fontFace->loadStatus() == FontFace::Loading) | 332 if (fontFace->loadStatus() == FontFace::Loading) |
333 removeFromLoadingFonts(fontFace); | 333 removeFromLoadingFonts(fontFace); |
334 fontSelector->fontFaceInvalidated(); | 334 fontSelector->fontFaceInvalidated(); |
335 return true; | 335 return true; |
336 } | 336 } |
337 if (isCSSConnectedFontFace(fontFace)) | 337 if (isCSSConnectedFontFace(fontFace)) |
338 exceptionState.throwDOMException(InvalidModificationError, "Cannot delet
e a CSS-connected FontFace."); | 338 exceptionState.throwDOMException(InvalidModificationError, "Cannot delet
e a CSS-connected FontFace."); |
339 return false; | 339 return false; |
340 } | 340 } |
341 | 341 |
342 bool FontFaceSet::has(FontFace* fontFace, ExceptionState& exceptionState) const | 342 bool FontFaceSet::has(FontFace* fontFace, ExceptionState& exceptionState) const |
343 { | 343 { |
344 if (!inActiveDocumentContext()) | 344 if (!inActiveDocumentContext()) |
345 return false; | 345 return false; |
346 if (!fontFace) { | 346 if (!fontFace) { |
347 exceptionState.throwTypeError("The argument is not a FontFace."); | 347 exceptionState.throwTypeError("The argument is not a FontFace."); |
348 return false; | 348 return false; |
349 } | 349 } |
350 return m_nonCSSConnectedFaces.contains(fontFace) || isCSSConnectedFontFace(f
ontFace); | 350 return m_nonCSSConnectedFaces.contains(fontFace) || isCSSConnectedFontFace(f
ontFace); |
351 } | 351 } |
352 | 352 |
353 const WillBeHeapListHashSet<RefPtrWillBeMember<FontFace> >& FontFaceSet::cssConn
ectedFontFaceList() const | 353 const WillBeHeapListHashSet<RefPtrWillBeMember<FontFace>>& FontFaceSet::cssConne
ctedFontFaceList() const |
354 { | 354 { |
355 Document* d = document(); | 355 Document* d = document(); |
356 d->ensureStyleResolver(); // Flush pending style changes. | 356 d->ensureStyleResolver(); // Flush pending style changes. |
357 return d->styleEngine().fontSelector()->fontFaceCache()->cssConnectedFontFac
es(); | 357 return d->styleEngine().fontSelector()->fontFaceCache()->cssConnectedFontFac
es(); |
358 } | 358 } |
359 | 359 |
360 bool FontFaceSet::isCSSConnectedFontFace(FontFace* fontFace) const | 360 bool FontFaceSet::isCSSConnectedFontFace(FontFace* fontFace) const |
361 { | 361 { |
362 return cssConnectedFontFaceList().contains(fontFace); | 362 return cssConnectedFontFaceList().contains(fontFace); |
363 } | 363 } |
364 | 364 |
365 void FontFaceSet::forEach(FontFaceSetForEachCallback* callback, const ScriptValu
e& thisArg) const | 365 void FontFaceSet::forEach(FontFaceSetForEachCallback* callback, const ScriptValu
e& thisArg) const |
366 { | 366 { |
367 forEachInternal(callback, &thisArg); | 367 forEachInternal(callback, &thisArg); |
368 } | 368 } |
369 | 369 |
370 void FontFaceSet::forEach(FontFaceSetForEachCallback* callback) const | 370 void FontFaceSet::forEach(FontFaceSetForEachCallback* callback) const |
371 { | 371 { |
372 forEachInternal(callback, 0); | 372 forEachInternal(callback, 0); |
373 } | 373 } |
374 | 374 |
375 void FontFaceSet::forEachInternal(FontFaceSetForEachCallback* callback, const Sc
riptValue* thisArg) const | 375 void FontFaceSet::forEachInternal(FontFaceSetForEachCallback* callback, const Sc
riptValue* thisArg) const |
376 { | 376 { |
377 if (!inActiveDocumentContext()) | 377 if (!inActiveDocumentContext()) |
378 return; | 378 return; |
379 const WillBeHeapListHashSet<RefPtrWillBeMember<FontFace> >& cssConnectedFace
s = cssConnectedFontFaceList(); | 379 const WillBeHeapListHashSet<RefPtrWillBeMember<FontFace>>& cssConnectedFaces
= cssConnectedFontFaceList(); |
380 WillBeHeapVector<RefPtrWillBeMember<FontFace> > fontFaces; | 380 WillBeHeapVector<RefPtrWillBeMember<FontFace>> fontFaces; |
381 fontFaces.reserveInitialCapacity(cssConnectedFaces.size() + m_nonCSSConnecte
dFaces.size()); | 381 fontFaces.reserveInitialCapacity(cssConnectedFaces.size() + m_nonCSSConnecte
dFaces.size()); |
382 for (const auto& fontFace : cssConnectedFaces) | 382 for (const auto& fontFace : cssConnectedFaces) |
383 fontFaces.append(fontFace); | 383 fontFaces.append(fontFace); |
384 for (const auto& fontFace : m_nonCSSConnectedFaces) | 384 for (const auto& fontFace : m_nonCSSConnectedFaces) |
385 fontFaces.append(fontFace); | 385 fontFaces.append(fontFace); |
386 | 386 |
387 for (size_t i = 0; i < fontFaces.size(); ++i) { | 387 for (size_t i = 0; i < fontFaces.size(); ++i) { |
388 FontFace* face = fontFaces[i].get(); | 388 FontFace* face = fontFaces[i].get(); |
389 if (thisArg) | 389 if (thisArg) |
390 callback->handleItem(*thisArg, face, face, const_cast<FontFaceSet*>(
this)); | 390 callback->handleItem(*thisArg, face, face, const_cast<FontFaceSet*>(
this)); |
(...skipping 31 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> > resolve
rs; | 432 WillBeHeapVector<OwnPtrWillBeMember<FontsReadyPromiseResolver>> resolver
s; |
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(); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 visitor->trace(m_loadedFonts); | 594 visitor->trace(m_loadedFonts); |
595 visitor->trace(m_failedFonts); | 595 visitor->trace(m_failedFonts); |
596 visitor->trace(m_nonCSSConnectedFaces); | 596 visitor->trace(m_nonCSSConnectedFaces); |
597 DocumentSupplement::trace(visitor); | 597 DocumentSupplement::trace(visitor); |
598 #endif | 598 #endif |
599 EventTargetWithInlineData::trace(visitor); | 599 EventTargetWithInlineData::trace(visitor); |
600 ActiveDOMObject::trace(visitor); | 600 ActiveDOMObject::trace(visitor); |
601 } | 601 } |
602 | 602 |
603 } // namespace blink | 603 } // namespace blink |
OLD | NEW |