| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 bool CSSFontFace::isValid() const | 50 bool CSSFontFace::isValid() const |
| 51 { | 51 { |
| 52 size_t size = m_sources.size(); | 52 size_t size = m_sources.size(); |
| 53 for (size_t i = 0; i < size; i++) { | 53 for (size_t i = 0; i < size; i++) { |
| 54 if (m_sources[i]->isValid()) | 54 if (m_sources[i]->isValid()) |
| 55 return true; | 55 return true; |
| 56 } | 56 } |
| 57 return false; | 57 return false; |
| 58 } | 58 } |
| 59 | 59 |
| 60 void CSSFontFace::addedToSegmentedFontFace(CSSSegmentedFontFace* segmentedFontFa
ce) | 60 void CSSFontFace::addedToSegmentedFontFace(Handle<CSSSegmentedFontFace> segmente
dFontFace) |
| 61 { | 61 { |
| 62 m_segmentedFontFaces.add(segmentedFontFace); | 62 m_segmentedFontFaces.add(segmentedFontFace.raw()); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void CSSFontFace::removedFromSegmentedFontFace(CSSSegmentedFontFace* segmentedFo
ntFace) | 65 void CSSFontFace::removedFromSegmentedFontFace(Handle<CSSSegmentedFontFace> segm
entedFontFace) |
| 66 { | 66 { |
| 67 m_segmentedFontFaces.remove(segmentedFontFace); | 67 m_segmentedFontFaces.remove(segmentedFontFace.raw()); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void CSSFontFace::addSource(PassOwnPtr<CSSFontFaceSource> source) | 70 void CSSFontFace::addSource(PassOwnPtr<CSSFontFaceSource> source) |
| 71 { | 71 { |
| 72 source->setFontFace(this); | 72 source->setFontFace(this); |
| 73 m_sources.append(source); | 73 m_sources.append(source); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void CSSFontFace::fontLoaded(CSSFontFaceSource* source) | 76 void CSSFontFace::fontLoaded(CSSFontFaceSource* source) |
| 77 { | 77 { |
| 78 if (source != m_activeSource) | 78 if (source != m_activeSource) |
| 79 return; | 79 return; |
| 80 | 80 |
| 81 // FIXME: Can we assert that m_segmentedFontFaces is not empty? That may | 81 // FIXME: Can we assert that m_segmentedFontFaces is not empty? That may |
| 82 // require stopping in-progress font loading when the last | 82 // require stopping in-progress font loading when the last |
| 83 // CSSSegmentedFontFace is removed. | 83 // CSSSegmentedFontFace is removed. |
| 84 if (m_segmentedFontFaces.isEmpty()) | 84 if (m_segmentedFontFaces.isEmpty()) |
| 85 return; | 85 return; |
| 86 | 86 |
| 87 // Use one of the CSSSegmentedFontFaces' font selector. They all have | 87 // 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. | 88 // the same font selector, so it's wasteful to store it in the CSSFontFace. |
| 89 CSSFontSelector* fontSelector = (*m_segmentedFontFaces.begin())->fontSelecto
r(); | 89 CSSFontSelector* fontSelector = (*m_segmentedFontFaces.begin())->fontSelecto
r(); |
| 90 if (!fontSelector) |
| 91 return; |
| 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<CSSSegmentedFontFace*>::iterator end = m_segmentedFontFaces.end(); |
| 100 for (HashSet<CSSSegmentedFontFace*>::iterator it = m_segmentedFontFaces.begi
n(); it != end; ++it) | 102 for (HashSet<CSSSegmentedFontFace*>::iterator it = m_segmentedFontFaces.begi
n(); it != end; ++it) |
| 101 (*it)->fontLoaded(this); | 103 (*it)->fontLoaded(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(); |
| 114 if (!fontSelector) |
| 115 return 0; |
| 112 | 116 |
| 113 if (RuntimeEnabledFeatures::fontLoadEventsEnabled() && m_loadState == NotLoa
ded) | 117 if (RuntimeEnabledFeatures::fontLoadEventsEnabled() && m_loadState == NotLoa
ded) |
| 114 notifyFontLoader(Loading); | 118 notifyFontLoader(Loading); |
| 115 | 119 |
| 116 size_t size = m_sources.size(); | 120 size_t size = m_sources.size(); |
| 117 for (size_t i = 0; i < size; ++i) { | 121 for (size_t i = 0; i < size; ++i) { |
| 118 if (RefPtr<SimpleFontData> result = m_sources[i]->getFontData(fontDescri
ption, syntheticBold, syntheticItalic, fontSelector)) { | 122 if (RefPtr<SimpleFontData> result = m_sources[i]->getFontData(fontDescri
ption, syntheticBold, syntheticItalic, fontSelector)) { |
| 119 m_activeSource = m_sources[i].get(); | 123 m_activeSource = m_sources[i].get(); |
| 120 if (RuntimeEnabledFeatures::fontLoadEventsEnabled() && m_loadState =
= Loading && m_sources[i]->isLoaded()) | 124 if (RuntimeEnabledFeatures::fontLoadEventsEnabled() && m_loadState =
= Loading && m_sources[i]->isLoaded()) |
| 121 notifyFontLoader(Loaded); | 125 notifyFontLoader(Loaded); |
| 122 return result.release(); | 126 return result.release(); |
| 123 } | 127 } |
| 124 } | 128 } |
| 125 | 129 |
| 126 if (RuntimeEnabledFeatures::fontLoadEventsEnabled() && m_loadState == Loadin
g) | 130 if (RuntimeEnabledFeatures::fontLoadEventsEnabled() && m_loadState == Loadin
g) |
| 127 notifyFontLoader(Error); | 131 notifyFontLoader(Error); |
| 128 return 0; | 132 return 0; |
| 129 } | 133 } |
| 130 | 134 |
| 131 void CSSFontFace::notifyFontLoader(LoadState newState) | 135 void CSSFontFace::notifyFontLoader(LoadState newState) |
| 132 { | 136 { |
| 133 m_loadState = newState; | 137 m_loadState = newState; |
| 134 | 138 |
| 135 Document* document = (*m_segmentedFontFaces.begin())->fontSelector()->docume
nt(); | 139 CSSFontSelector* fontSelector = (*m_segmentedFontFaces.begin())->fontSelecto
r(); |
| 140 if (!fontSelector) |
| 141 return; |
| 142 Document* document = fontSelector->document(); |
| 136 if (!document) | 143 if (!document) |
| 137 return; | 144 return; |
| 138 | 145 |
| 139 switch (newState) { | 146 switch (newState) { |
| 140 case Loading: | 147 case Loading: |
| 141 document->fontloader()->beginFontLoading(m_rule); | 148 document->fontloader()->beginFontLoading(m_rule); |
| 142 break; | 149 break; |
| 143 case Loaded: | 150 case Loaded: |
| 144 document->fontloader()->fontLoaded(m_rule); | 151 document->fontloader()->fontLoaded(m_rule); |
| 145 break; | 152 break; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 157 size_t size = m_sources.size(); | 164 size_t size = m_sources.size(); |
| 158 for (size_t i = 0; i < size; i++) { | 165 for (size_t i = 0; i < size; i++) { |
| 159 if (m_sources[i]->isSVGFontFaceSource()) | 166 if (m_sources[i]->isSVGFontFaceSource()) |
| 160 return true; | 167 return true; |
| 161 } | 168 } |
| 162 return false; | 169 return false; |
| 163 } | 170 } |
| 164 #endif | 171 #endif |
| 165 | 172 |
| 166 } | 173 } |
| OLD | NEW |