| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 CSSSegmentedFontFace* segmentedFontFace) { | 46 CSSSegmentedFontFace* segmentedFontFace) { |
| 47 ASSERT(!m_segmentedFontFace); | 47 ASSERT(!m_segmentedFontFace); |
| 48 m_segmentedFontFace = segmentedFontFace; | 48 m_segmentedFontFace = segmentedFontFace; |
| 49 } | 49 } |
| 50 | 50 |
| 51 void CSSFontFace::didBeginLoad() { | 51 void CSSFontFace::didBeginLoad() { |
| 52 if (loadStatus() == FontFace::Unloaded) | 52 if (loadStatus() == FontFace::Unloaded) |
| 53 setLoadStatus(FontFace::Loading); | 53 setLoadStatus(FontFace::Loading); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void CSSFontFace::fontLoaded(RemoteFontFaceSource* source) { | 56 void CSSFontFace::fontLoaded(RemoteFontFaceSource* source, Document* document) { |
| 57 if (!isValid() || source != m_sources.first()) | 57 if (!isValid() || source != m_sources.first()) |
| 58 return; | 58 return; |
| 59 | 59 |
| 60 if (loadStatus() == FontFace::Loading) { | 60 if (loadStatus() == FontFace::Loading) { |
| 61 if (source->isValid()) { | 61 if (source->isValid()) { |
| 62 setLoadStatus(FontFace::Loaded); | 62 setLoadStatus(FontFace::Loaded); |
| 63 } else if (source->getDisplayPeriod() == | 63 } else if (source->getDisplayPeriod() == |
| 64 RemoteFontFaceSource::FailurePeriod) { | 64 RemoteFontFaceSource::FailurePeriod) { |
| 65 m_sources.clear(); | 65 m_sources.clear(); |
| 66 setLoadStatus(FontFace::Error); | 66 setLoadStatus(FontFace::Error); |
| 67 } else { | 67 } else { |
| 68 m_sources.removeFirst(); | 68 m_sources.removeFirst(); |
| 69 load(); | 69 load(document); |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 | 72 |
| 73 if (m_segmentedFontFace) | 73 if (m_segmentedFontFace) |
| 74 m_segmentedFontFace->fontFaceInvalidated(); | 74 m_segmentedFontFace->fontFaceInvalidated(); |
| 75 } | 75 } |
| 76 | 76 |
| 77 size_t CSSFontFace::approximateBlankCharacterCount() const { | 77 size_t CSSFontFace::approximateBlankCharacterCount() const { |
| 78 if (!m_sources.isEmpty() && m_sources.first()->isBlank() && | 78 if (!m_sources.isEmpty() && m_sources.first()->isBlank() && |
| 79 m_segmentedFontFace) | 79 m_segmentedFontFace) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 106 m_sources.removeFirst(); | 106 m_sources.removeFirst(); |
| 107 } | 107 } |
| 108 | 108 |
| 109 if (loadStatus() == FontFace::Unloaded) | 109 if (loadStatus() == FontFace::Unloaded) |
| 110 setLoadStatus(FontFace::Loading); | 110 setLoadStatus(FontFace::Loading); |
| 111 if (loadStatus() == FontFace::Loading) | 111 if (loadStatus() == FontFace::Loading) |
| 112 setLoadStatus(FontFace::Error); | 112 setLoadStatus(FontFace::Error); |
| 113 return nullptr; | 113 return nullptr; |
| 114 } | 114 } |
| 115 | 115 |
| 116 bool CSSFontFace::maybeLoadFont(const FontDescription& fontDescription, | 116 bool CSSFontFace::maybeLoadFont(Document* document, |
| 117 const FontDescription& fontDescription, |
| 117 const String& text) { | 118 const String& text) { |
| 118 // This is a fast path of loading web font in style phase. For speed, this | 119 // This is a fast path of loading web font in style phase. For speed, this |
| 119 // only checks if the first character of the text is included in the font's | 120 // only checks if the first character of the text is included in the font's |
| 120 // unicode range. If this font is needed by subsequent characters, load is | 121 // unicode range. If this font is needed by subsequent characters, load is |
| 121 // kicked off in layout phase. | 122 // kicked off in layout phase. |
| 122 UChar32 character = text.characterStartingAt(0); | 123 UChar32 character = text.characterStartingAt(0); |
| 123 if (m_ranges->contains(character)) { | 124 if (m_ranges->contains(character)) { |
| 124 if (loadStatus() == FontFace::Unloaded) | 125 if (loadStatus() == FontFace::Unloaded) |
| 125 load(fontDescription); | 126 load(document, fontDescription); |
| 126 return true; | 127 return true; |
| 127 } | 128 } |
| 128 return false; | 129 return false; |
| 129 } | 130 } |
| 130 | 131 |
| 131 bool CSSFontFace::maybeLoadFont(const FontDescription& fontDescription, | 132 bool CSSFontFace::maybeLoadFont(Document* document, |
| 133 const FontDescription& fontDescription, |
| 132 const FontDataForRangeSet& rangeSet) { | 134 const FontDataForRangeSet& rangeSet) { |
| 133 if (m_ranges == rangeSet.ranges()) { | 135 if (m_ranges == rangeSet.ranges()) { |
| 134 if (loadStatus() == FontFace::Unloaded) { | 136 if (loadStatus() == FontFace::Unloaded) { |
| 135 load(fontDescription); | 137 load(document, fontDescription); |
| 136 } | 138 } |
| 137 return true; | 139 return true; |
| 138 } | 140 } |
| 139 return false; | 141 return false; |
| 140 } | 142 } |
| 141 | 143 |
| 142 void CSSFontFace::load() { | 144 void CSSFontFace::load(Document* document) { |
| 143 FontDescription fontDescription; | 145 FontDescription fontDescription; |
| 144 FontFamily fontFamily; | 146 FontFamily fontFamily; |
| 145 fontFamily.setFamily(m_fontFace->family()); | 147 fontFamily.setFamily(m_fontFace->family()); |
| 146 fontDescription.setFamily(fontFamily); | 148 fontDescription.setFamily(fontFamily); |
| 147 fontDescription.setTraits(m_fontFace->traits()); | 149 fontDescription.setTraits(m_fontFace->traits()); |
| 148 load(fontDescription); | 150 load(document, fontDescription); |
| 149 } | 151 } |
| 150 | 152 |
| 151 void CSSFontFace::load(const FontDescription& fontDescription) { | 153 void CSSFontFace::load(Document* document, |
| 152 if (loadStatus() == FontFace::Unloaded) | 154 const FontDescription& fontDescription) { |
| 155 if (loadStatus() == FontFace::Unloaded) { |
| 153 setLoadStatus(FontFace::Loading); | 156 setLoadStatus(FontFace::Loading); |
| 157 // Only begin loading if we have been added to a CSSSegmentedFontFace |
| 158 // (which happens when we are ready to start loading). |
| 159 if (m_segmentedFontFace) |
| 160 FontFaceSet::from(*document)->beginFontLoading(m_fontFace); |
| 161 } |
| 154 ASSERT(loadStatus() == FontFace::Loading); | 162 ASSERT(loadStatus() == FontFace::Loading); |
| 155 | 163 |
| 156 while (!m_sources.isEmpty()) { | 164 while (!m_sources.isEmpty()) { |
| 157 Member<CSSFontFaceSource>& source = m_sources.first(); | 165 Member<CSSFontFaceSource>& source = m_sources.first(); |
| 158 if (source->isValid()) { | 166 if (source->isValid()) { |
| 159 if (source->isLocal()) { | 167 if (source->isLocal()) { |
| 160 if (source->isLocalFontAvailable(fontDescription)) { | 168 if (source->isLocalFontAvailable(fontDescription)) { |
| 161 setLoadStatus(FontFace::Loaded); | 169 setLoadStatus(FontFace::Loaded); |
| 162 return; | 170 return; |
| 163 } | 171 } |
| 164 } else { | 172 } else { |
| 165 if (!source->isLoaded()) | 173 if (!source->isLoaded()) |
| 166 source->beginLoadIfNeeded(); | 174 source->beginLoadIfNeeded(); |
| 167 else | 175 else |
| 168 setLoadStatus(FontFace::Loaded); | 176 setLoadStatus(FontFace::Loaded); |
| 169 return; | 177 return; |
| 170 } | 178 } |
| 171 } | 179 } |
| 172 m_sources.removeFirst(); | 180 m_sources.removeFirst(); |
| 173 } | 181 } |
| 174 setLoadStatus(FontFace::Error); | 182 setLoadStatus(FontFace::Error); |
| 175 } | 183 } |
| 176 | 184 |
| 177 void CSSFontFace::setLoadStatus(FontFace::LoadStatusType newStatus) { | 185 void CSSFontFace::setLoadStatus(FontFace::LoadStatusType newStatus) { |
| 178 ASSERT(m_fontFace); | 186 ASSERT(m_fontFace); |
| 179 if (newStatus == FontFace::Error) | 187 if (newStatus == FontFace::Error) |
| 180 m_fontFace->setError(); | 188 m_fontFace->setError(); |
| 181 else | 189 else |
| 182 m_fontFace->setLoadStatus(newStatus); | 190 m_fontFace->setLoadStatus(newStatus); |
| 183 | |
| 184 if (!m_segmentedFontFace) | |
| 185 return; | |
| 186 Document* document = m_segmentedFontFace->fontSelector()->document(); | |
| 187 if (document && newStatus == FontFace::Loading) | |
| 188 FontFaceSet::from(*document)->beginFontLoading(m_fontFace); | |
| 189 } | 191 } |
| 190 | 192 |
| 191 DEFINE_TRACE(CSSFontFace) { | 193 DEFINE_TRACE(CSSFontFace) { |
| 192 visitor->trace(m_segmentedFontFace); | 194 visitor->trace(m_segmentedFontFace); |
| 193 visitor->trace(m_sources); | 195 visitor->trace(m_sources); |
| 194 visitor->trace(m_fontFace); | 196 visitor->trace(m_fontFace); |
| 195 } | 197 } |
| 196 | 198 |
| 197 } // namespace blink | 199 } // namespace blink |
| OLD | NEW |