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 11 matching lines...) Expand all Loading... |
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
23 * DAMAGE. | 23 * DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 #include "core/css/FontFaceSet.h" | 27 #include "core/css/FontFaceSet.h" |
28 | 28 |
29 #include "bindings/core/v8/Dictionary.h" | 29 #include "bindings/core/v8/Dictionary.h" |
30 #include "bindings/core/v8/ScriptPromiseResolver.h" | 30 #include "bindings/core/v8/ScriptPromiseResolver.h" |
31 #include "bindings/core/v8/ScriptState.h" | 31 #include "bindings/core/v8/ScriptState.h" |
| 32 #include "bindings/core/v8/V8FontFace.h" |
32 #include "core/css/CSSFontSelector.h" | 33 #include "core/css/CSSFontSelector.h" |
33 #include "core/css/CSSSegmentedFontFace.h" | 34 #include "core/css/CSSSegmentedFontFace.h" |
34 #include "core/css/FontFaceCache.h" | 35 #include "core/css/FontFaceCache.h" |
35 #include "core/css/FontFaceSetLoadEvent.h" | 36 #include "core/css/FontFaceSetLoadEvent.h" |
36 #include "core/css/StylePropertySet.h" | 37 #include "core/css/StylePropertySet.h" |
37 #include "core/css/parser/CSSParser.h" | 38 #include "core/css/parser/CSSParser.h" |
38 #include "core/css/resolver/StyleResolver.h" | 39 #include "core/css/resolver/StyleResolver.h" |
39 #include "core/dom/Document.h" | 40 #include "core/dom/Document.h" |
40 #include "core/dom/StyleEngine.h" | 41 #include "core/dom/StyleEngine.h" |
41 #include "core/frame/FrameView.h" | 42 #include "core/frame/FrameView.h" |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 | 381 |
381 for (size_t i = 0; i < fontFaces.size(); ++i) { | 382 for (size_t i = 0; i < fontFaces.size(); ++i) { |
382 FontFace* face = fontFaces[i].get(); | 383 FontFace* face = fontFaces[i].get(); |
383 if (thisArg) | 384 if (thisArg) |
384 callback->handleItem(*thisArg, face, face, const_cast<FontFaceSet*>(
this)); | 385 callback->handleItem(*thisArg, face, face, const_cast<FontFaceSet*>(
this)); |
385 else | 386 else |
386 callback->handleItem(face, face, const_cast<FontFaceSet*>(this)); | 387 callback->handleItem(face, face, const_cast<FontFaceSet*>(this)); |
387 } | 388 } |
388 } | 389 } |
389 | 390 |
| 391 Iterator* FontFaceSet::keys() |
| 392 { |
| 393 return new FontFaceSetIterator(this, FontFaceSetIterator::Keys); |
| 394 } |
| 395 |
| 396 Iterator* FontFaceSet::values() |
| 397 { |
| 398 return new FontFaceSetIterator(this, FontFaceSetIterator::Values); |
| 399 } |
| 400 |
| 401 Iterator* FontFaceSet::entries() |
| 402 { |
| 403 return new FontFaceSetIterator(this, FontFaceSetIterator::Entries); |
| 404 } |
| 405 |
390 unsigned long FontFaceSet::size() const | 406 unsigned long FontFaceSet::size() const |
391 { | 407 { |
392 if (!inActiveDocumentContext()) | 408 if (!inActiveDocumentContext()) |
393 return m_nonCSSConnectedFaces.size(); | 409 return m_nonCSSConnectedFaces.size(); |
394 return cssConnectedFontFaceList().size() + m_nonCSSConnectedFaces.size(); | 410 return cssConnectedFontFaceList().size() + m_nonCSSConnectedFaces.size(); |
395 } | 411 } |
396 | 412 |
| 413 FontFace* FontFaceSet::fontFaceAt(size_t index) const |
| 414 { |
| 415 if (inActiveDocumentContext()) { |
| 416 const WillBeHeapListHashSet<RefPtrWillBeMember<FontFace> >& cssConnected
Faces = cssConnectedFontFaceList(); |
| 417 if (index < cssConnectedFaces.size()) { |
| 418 WillBeHeapListHashSet<RefPtrWillBeMember<FontFace> >::const_iterator
it = cssConnectedFaces.begin(); |
| 419 for (size_t i = 0; i < index; i++) |
| 420 ++it; |
| 421 return it->get(); |
| 422 } |
| 423 index -= cssConnectedFaces.size(); |
| 424 } |
| 425 if (index < m_nonCSSConnectedFaces.size()) { |
| 426 WillBeHeapListHashSet<RefPtrWillBeMember<FontFace> >::const_iterator it
= m_nonCSSConnectedFaces.begin(); |
| 427 for (size_t i = 0; i < index; i++) |
| 428 ++it; |
| 429 return it->get(); |
| 430 } |
| 431 return 0; |
| 432 } |
| 433 |
397 void FontFaceSet::fireDoneEventIfPossible() | 434 void FontFaceSet::fireDoneEventIfPossible() |
398 { | 435 { |
399 if (m_shouldFireLoadingEvent) | 436 if (m_shouldFireLoadingEvent) |
400 return; | 437 return; |
401 if (!m_loadingFonts.isEmpty() || (!hasLoadedFonts() && m_readyResolvers.isEm
pty())) | 438 if (!m_loadingFonts.isEmpty() || (!hasLoadedFonts() && m_readyResolvers.isEm
pty())) |
402 return; | 439 return; |
403 | 440 |
404 // If the layout was invalidated in between when we thought layout | 441 // If the layout was invalidated in between when we thought layout |
405 // was updated and when we're ready to fire the event, just wait | 442 // was updated and when we're ready to fire the event, just wait |
406 // until after the next layout before firing events. | 443 // until after the next layout before firing events. |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 { | 622 { |
586 visitor->trace(m_loadingFonts); | 623 visitor->trace(m_loadingFonts); |
587 visitor->trace(m_loadedFonts); | 624 visitor->trace(m_loadedFonts); |
588 visitor->trace(m_failedFonts); | 625 visitor->trace(m_failedFonts); |
589 visitor->trace(m_nonCSSConnectedFaces); | 626 visitor->trace(m_nonCSSConnectedFaces); |
590 DocumentSupplement::trace(visitor); | 627 DocumentSupplement::trace(visitor); |
591 EventTargetWithInlineData::trace(visitor); | 628 EventTargetWithInlineData::trace(visitor); |
592 } | 629 } |
593 #endif | 630 #endif |
594 | 631 |
| 632 ScriptValue FontFaceSet::FontFaceSetIterator::next(ScriptState* scriptState, Exc
eptionState&) |
| 633 { |
| 634 // FIXME: It takes O(n^2) to iterate all font faces. A better solution |
| 635 // is needed. |
| 636 FontFace* fontFace = m_fontFaceSet->fontFaceAt(m_index); |
| 637 if (!fontFace) |
| 638 return ScriptValue(scriptState, v8DoneIteratorResult(scriptState->isolat
e())); |
| 639 m_index++; |
| 640 if (m_kind == FontFaceSetIterator::Entries) { |
| 641 Vector<ScriptValue> entry; |
| 642 ScriptValue value = ScriptValue(scriptState, toV8(fontFace, scriptState-
>context()->Global(), scriptState->isolate())); |
| 643 entry.append(value); |
| 644 entry.append(value); |
| 645 return ScriptValue(scriptState, v8IteratorResult(scriptState, entry)); |
| 646 } |
| 647 return ScriptValue(scriptState, v8IteratorResult(scriptState, fontFace)); |
| 648 } |
| 649 |
595 } // namespace blink | 650 } // namespace blink |
OLD | NEW |