| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008, 2011 Apple 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 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 19 matching lines...) Expand all Loading... |
| 30 #include "core/css/CSSFontSelector.h" | 30 #include "core/css/CSSFontSelector.h" |
| 31 #include "core/css/CSSSegmentedFontFace.h" | 31 #include "core/css/CSSSegmentedFontFace.h" |
| 32 #include "core/css/FontLoader.h" | 32 #include "core/css/FontLoader.h" |
| 33 #include "core/dom/Document.h" | 33 #include "core/dom/Document.h" |
| 34 #include "RuntimeEnabledFeatures.h" | 34 #include "RuntimeEnabledFeatures.h" |
| 35 #include "core/platform/graphics/FontDescription.h" | 35 #include "core/platform/graphics/FontDescription.h" |
| 36 #include "core/platform/graphics/SimpleFontData.h" | 36 #include "core/platform/graphics/SimpleFontData.h" |
| 37 | 37 |
| 38 namespace WebCore { | 38 namespace WebCore { |
| 39 | 39 |
| 40 DEFINE_GC_TYPE_MARKER(CSSFontFace); |
| 41 |
| 40 bool CSSFontFace::isLoaded() const | 42 bool CSSFontFace::isLoaded() const |
| 41 { | 43 { |
| 42 size_t size = m_sources.size(); | 44 size_t size = m_sources.size(); |
| 43 for (size_t i = 0; i < size; i++) { | 45 for (size_t i = 0; i < size; i++) { |
| 44 if (!m_sources[i]->isLoaded()) | 46 if (!m_sources[i]->isLoaded()) |
| 45 return false; | 47 return false; |
| 46 } | 48 } |
| 47 return true; | 49 return true; |
| 48 } | 50 } |
| 49 | 51 |
| 50 bool CSSFontFace::isValid() const | 52 bool CSSFontFace::isValid() const |
| 51 { | 53 { |
| 52 size_t size = m_sources.size(); | 54 size_t size = m_sources.size(); |
| 53 for (size_t i = 0; i < size; i++) { | 55 for (size_t i = 0; i < size; i++) { |
| 54 if (m_sources[i]->isValid()) | 56 if (m_sources[i]->isValid()) |
| 55 return true; | 57 return true; |
| 56 } | 58 } |
| 57 return false; | 59 return false; |
| 58 } | 60 } |
| 59 | 61 |
| 60 void CSSFontFace::addedToSegmentedFontFace(CSSSegmentedFontFace* segmentedFontFa
ce) | 62 void CSSFontFace::addedToSegmentedFontFace(Handle<CSSSegmentedFontFace> segmente
dFontFace) |
| 61 { | 63 { |
| 62 m_segmentedFontFaces.add(segmentedFontFace); | 64 m_segmentedFontFaces.add(segmentedFontFace); |
| 63 } | 65 } |
| 64 | 66 |
| 65 void CSSFontFace::removedFromSegmentedFontFace(CSSSegmentedFontFace* segmentedFo
ntFace) | 67 void CSSFontFace::removedFromSegmentedFontFace(Handle<CSSSegmentedFontFace> segm
entedFontFace) |
| 66 { | 68 { |
| 67 m_segmentedFontFaces.remove(segmentedFontFace); | 69 m_segmentedFontFaces.remove(segmentedFontFace); |
| 68 } | 70 } |
| 69 | 71 |
| 70 void CSSFontFace::addSource(PassOwnPtr<CSSFontFaceSource> source) | 72 void CSSFontFace::addSource(PassOwnPtr<CSSFontFaceSource> source) |
| 71 { | 73 { |
| 72 source->setFontFace(this); | 74 source->setFontFace(Handle<CSSFontFace>(this)); |
| 73 m_sources.append(source); | 75 m_sources.append(source); |
| 74 } | 76 } |
| 75 | 77 |
| 76 void CSSFontFace::fontLoaded(CSSFontFaceSource* source) | 78 void CSSFontFace::fontLoaded(CSSFontFaceSource* source) |
| 77 { | 79 { |
| 78 if (source != m_activeSource) | 80 if (source != m_activeSource) |
| 79 return; | 81 return; |
| 80 | 82 |
| 81 // FIXME: Can we assert that m_segmentedFontFaces is not empty? That may | 83 // FIXME: Can we assert that m_segmentedFontFaces is not empty? That may |
| 82 // require stopping in-progress font loading when the last | 84 // require stopping in-progress font loading when the last |
| 83 // CSSSegmentedFontFace is removed. | 85 // CSSSegmentedFontFace is removed. |
| 84 if (m_segmentedFontFaces.isEmpty()) | 86 if (m_segmentedFontFaces.isEmpty()) |
| 85 return; | 87 return; |
| 86 | 88 |
| 87 // Use one of the CSSSegmentedFontFaces' font selector. They all have | 89 // Use one of the CSSSegmentedFontFaces' font selector. They all have |
| 88 // the same font selector, so it's wasteful to store it in the CSSFontFace. | 90 // the same font selector, so it's wasteful to store it in the CSSFontFace. |
| 89 CSSFontSelector* fontSelector = (*m_segmentedFontFaces.begin())->fontSelecto
r(); | 91 CSSFontSelector* fontSelector = (*m_segmentedFontFaces.begin())->fontSelecto
r(); |
| 90 fontSelector->fontLoaded(); | 92 fontSelector->fontLoaded(); |
| 91 | 93 |
| 92 if (RuntimeEnabledFeatures::fontLoadEventsEnabled() && m_loadState == Loadin
g) { | 94 if (RuntimeEnabledFeatures::fontLoadEventsEnabled() && m_loadState == Loadin
g) { |
| 93 if (source->ensureFontData()) | 95 if (source->ensureFontData()) |
| 94 notifyFontLoader(Loaded); | 96 notifyFontLoader(Loaded); |
| 95 else if (!isValid()) | 97 else if (!isValid()) |
| 96 notifyFontLoader(Error); | 98 notifyFontLoader(Error); |
| 97 } | 99 } |
| 98 | 100 |
| 99 HashSet<CSSSegmentedFontFace*>::iterator end = m_segmentedFontFaces.end(); | 101 HashSet<Member<CSSSegmentedFontFace> >::iterator end = m_segmentedFontFaces.
end(); |
| 100 for (HashSet<CSSSegmentedFontFace*>::iterator it = m_segmentedFontFaces.begi
n(); it != end; ++it) | 102 for (HashSet<Member<CSSSegmentedFontFace> >::iterator it = m_segmentedFontFa
ces.begin(); it != end; ++it) |
| 101 (*it)->fontLoaded(this); | 103 (*it)->fontLoaded(Handle<CSSFontFace>(this)); |
| 102 } | 104 } |
| 103 | 105 |
| 104 PassRefPtr<SimpleFontData> CSSFontFace::getFontData(const FontDescription& fontD
escription, bool syntheticBold, bool syntheticItalic) | 106 PassRefPtr<SimpleFontData> CSSFontFace::getFontData(const FontDescription& fontD
escription, bool syntheticBold, bool syntheticItalic) |
| 105 { | 107 { |
| 106 m_activeSource = 0; | 108 m_activeSource = 0; |
| 107 if (!isValid()) | 109 if (!isValid()) |
| 108 return 0; | 110 return 0; |
| 109 | 111 |
| 110 ASSERT(!m_segmentedFontFaces.isEmpty()); | 112 ASSERT(!m_segmentedFontFaces.isEmpty()); |
| 111 CSSFontSelector* fontSelector = (*m_segmentedFontFaces.begin())->fontSelecto
r(); | 113 CSSFontSelector* fontSelector = (*m_segmentedFontFaces.begin())->fontSelecto
r(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 { | 158 { |
| 157 size_t size = m_sources.size(); | 159 size_t size = m_sources.size(); |
| 158 for (size_t i = 0; i < size; i++) { | 160 for (size_t i = 0; i < size; i++) { |
| 159 if (m_sources[i]->isSVGFontFaceSource()) | 161 if (m_sources[i]->isSVGFontFaceSource()) |
| 160 return true; | 162 return true; |
| 161 } | 163 } |
| 162 return false; | 164 return false; |
| 163 } | 165 } |
| 164 #endif | 166 #endif |
| 165 | 167 |
| 168 void CSSFontFace::accept(Visitor* visitor) const |
| 169 { |
| 170 visitor->visit(m_rule); |
| 171 visitor->visit(m_segmentedFontFaces); |
| 166 } | 172 } |
| 173 |
| 174 } |
| OLD | NEW |