| 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 ASSERT(fontSelector); |
| 90 fontSelector->fontLoaded(); | 91 fontSelector->fontLoaded(); |
| 91 | 92 |
| 92 if (RuntimeEnabledFeatures::fontLoadEventsEnabled() && m_loadState == Loadin
g) { | 93 if (RuntimeEnabledFeatures::fontLoadEventsEnabled() && m_loadState == Loadin
g) { |
| 93 if (source->ensureFontData()) | 94 if (source->ensureFontData()) |
| 94 notifyFontLoader(Loaded); | 95 notifyFontLoader(Loaded); |
| 95 else if (!isValid()) | 96 else if (!isValid()) |
| 96 notifyFontLoader(Error); | 97 notifyFontLoader(Error); |
| 97 } | 98 } |
| 98 | 99 |
| 99 HashSet<CSSSegmentedFontFace*>::iterator end = m_segmentedFontFaces.end(); | 100 HashSet<CSSSegmentedFontFace*>::iterator end = m_segmentedFontFaces.end(); |
| 100 for (HashSet<CSSSegmentedFontFace*>::iterator it = m_segmentedFontFaces.begi
n(); it != end; ++it) | 101 for (HashSet<CSSSegmentedFontFace*>::iterator it = m_segmentedFontFaces.begi
n(); it != end; ++it) |
| 101 (*it)->fontLoaded(this); | 102 (*it)->fontLoaded(this); |
| 102 } | 103 } |
| 103 | 104 |
| 104 PassRefPtr<SimpleFontData> CSSFontFace::getFontData(const FontDescription& fontD
escription, bool syntheticBold, bool syntheticItalic) | 105 PassRefPtr<SimpleFontData> CSSFontFace::getFontData(const FontDescription& fontD
escription, bool syntheticBold, bool syntheticItalic) |
| 105 { | 106 { |
| 106 m_activeSource = 0; | 107 m_activeSource = 0; |
| 107 if (!isValid()) | 108 if (!isValid()) |
| 108 return 0; | 109 return 0; |
| 109 | 110 |
| 110 ASSERT(!m_segmentedFontFaces.isEmpty()); | 111 ASSERT(!m_segmentedFontFaces.isEmpty()); |
| 111 CSSFontSelector* fontSelector = (*m_segmentedFontFaces.begin())->fontSelecto
r(); | 112 CSSFontSelector* fontSelector = (*m_segmentedFontFaces.begin())->fontSelecto
r(); |
| 113 ASSERT(fontSelector); |
| 112 | 114 |
| 113 if (RuntimeEnabledFeatures::fontLoadEventsEnabled() && m_loadState == NotLoa
ded) | 115 if (RuntimeEnabledFeatures::fontLoadEventsEnabled() && m_loadState == NotLoa
ded) |
| 114 notifyFontLoader(Loading); | 116 notifyFontLoader(Loading); |
| 115 | 117 |
| 116 size_t size = m_sources.size(); | 118 size_t size = m_sources.size(); |
| 117 for (size_t i = 0; i < size; ++i) { | 119 for (size_t i = 0; i < size; ++i) { |
| 118 if (RefPtr<SimpleFontData> result = m_sources[i]->getFontData(fontDescri
ption, syntheticBold, syntheticItalic, fontSelector)) { | 120 if (RefPtr<SimpleFontData> result = m_sources[i]->getFontData(fontDescri
ption, syntheticBold, syntheticItalic, fontSelector)) { |
| 119 m_activeSource = m_sources[i].get(); | 121 m_activeSource = m_sources[i].get(); |
| 120 if (RuntimeEnabledFeatures::fontLoadEventsEnabled() && m_loadState =
= Loading && m_sources[i]->isLoaded()) | 122 if (RuntimeEnabledFeatures::fontLoadEventsEnabled() && m_loadState =
= Loading && m_sources[i]->isLoaded()) |
| 121 notifyFontLoader(Loaded); | 123 notifyFontLoader(Loaded); |
| 122 return result.release(); | 124 return result.release(); |
| 123 } | 125 } |
| 124 } | 126 } |
| 125 | 127 |
| 126 if (RuntimeEnabledFeatures::fontLoadEventsEnabled() && m_loadState == Loadin
g) | 128 if (RuntimeEnabledFeatures::fontLoadEventsEnabled() && m_loadState == Loadin
g) |
| 127 notifyFontLoader(Error); | 129 notifyFontLoader(Error); |
| 128 return 0; | 130 return 0; |
| 129 } | 131 } |
| 130 | 132 |
| 131 void CSSFontFace::notifyFontLoader(LoadState newState) | 133 void CSSFontFace::notifyFontLoader(LoadState newState) |
| 132 { | 134 { |
| 133 m_loadState = newState; | 135 m_loadState = newState; |
| 134 | 136 |
| 135 Document* document = (*m_segmentedFontFaces.begin())->fontSelector()->docume
nt(); | 137 CSSFontSelector* fontSelector = (*m_segmentedFontFaces.begin())->fontSelecto
r(); |
| 138 ASSERT(fontSelector); |
| 139 Document* document = fontSelector->document(); |
| 136 if (!document) | 140 if (!document) |
| 137 return; | 141 return; |
| 138 | 142 |
| 139 switch (newState) { | 143 switch (newState) { |
| 140 case Loading: | 144 case Loading: |
| 141 document->fontloader()->beginFontLoading(m_rule); | 145 document->fontloader()->beginFontLoading(m_rule); |
| 142 break; | 146 break; |
| 143 case Loaded: | 147 case Loaded: |
| 144 document->fontloader()->fontLoaded(m_rule); | 148 document->fontloader()->fontLoaded(m_rule); |
| 145 break; | 149 break; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 157 size_t size = m_sources.size(); | 161 size_t size = m_sources.size(); |
| 158 for (size_t i = 0; i < size; i++) { | 162 for (size_t i = 0; i < size; i++) { |
| 159 if (m_sources[i]->isSVGFontFaceSource()) | 163 if (m_sources[i]->isSVGFontFaceSource()) |
| 160 return true; | 164 return true; |
| 161 } | 165 } |
| 162 return false; | 166 return false; |
| 163 } | 167 } |
| 164 #endif | 168 #endif |
| 165 | 169 |
| 166 } | 170 } |
| OLD | NEW |