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 * (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> | 3 * (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 m_resourceFetcher->decrementRequestCount(m_fontsToBeginLoading[i].get())
; | 101 m_resourceFetcher->decrementRequestCount(m_fontsToBeginLoading[i].get())
; |
102 } | 102 } |
103 | 103 |
104 m_fontsToBeginLoading.clear(); | 104 m_fontsToBeginLoading.clear(); |
105 m_resourceFetcher = 0; | 105 m_resourceFetcher = 0; |
106 } | 106 } |
107 | 107 |
108 CSSFontSelector::CSSFontSelector(Document* document) | 108 CSSFontSelector::CSSFontSelector(Document* document) |
109 : m_document(document) | 109 : m_document(document) |
110 , m_fontLoader(document->fetcher()) | 110 , m_fontLoader(document->fetcher()) |
| 111 , m_genericFontFamilySettings(document->frame()->settings()->genericFontFami
lySettings()) |
111 { | 112 { |
112 // FIXME: An old comment used to say there was no need to hold a reference t
o m_document | 113 // FIXME: An old comment used to say there was no need to hold a reference t
o m_document |
113 // because "we are guaranteed to be destroyed before the document". But ther
e does not | 114 // because "we are guaranteed to be destroyed before the document". But ther
e does not |
114 // seem to be any such guarantee. | 115 // seem to be any such guarantee. |
115 | 116 |
116 ASSERT(m_document); | 117 ASSERT(m_document); |
| 118 ASSERT(m_document->frame()); |
117 fontCache()->addClient(this); | 119 fontCache()->addClient(this); |
118 } | 120 } |
119 | 121 |
120 CSSFontSelector::~CSSFontSelector() | 122 CSSFontSelector::~CSSFontSelector() |
121 { | 123 { |
122 clearDocument(); | 124 clearDocument(); |
123 fontCache()->removeClient(this); | 125 fontCache()->removeClient(this); |
124 } | 126 } |
125 | 127 |
126 void CSSFontSelector::registerForInvalidationCallbacks(FontSelectorClient* clien
t) | 128 void CSSFontSelector::registerForInvalidationCallbacks(FontSelectorClient* clien
t) |
(...skipping 27 matching lines...) Expand all Loading... |
154 void CSSFontSelector::addFontFaceRule(const StyleRuleFontFace* fontFaceRule) | 156 void CSSFontSelector::addFontFaceRule(const StyleRuleFontFace* fontFaceRule) |
155 { | 157 { |
156 m_cssSegmentedFontFaceCache.addFontFaceRule(this, fontFaceRule); | 158 m_cssSegmentedFontFaceCache.addFontFaceRule(this, fontFaceRule); |
157 } | 159 } |
158 | 160 |
159 void CSSFontSelector::removeFontFaceRule(const StyleRuleFontFace* fontFaceRule) | 161 void CSSFontSelector::removeFontFaceRule(const StyleRuleFontFace* fontFaceRule) |
160 { | 162 { |
161 m_cssSegmentedFontFaceCache.removeFontFaceRule(fontFaceRule); | 163 m_cssSegmentedFontFaceCache.removeFontFaceRule(fontFaceRule); |
162 } | 164 } |
163 | 165 |
164 static AtomicString familyNameFromSettings(Settings* settings, const FontDescrip
tion& fontDescription, const AtomicString& genericFamilyName) | 166 static AtomicString familyNameFromSettings(const GenericFontFamilySettings& sett
ings, const FontDescription& fontDescription, const AtomicString& genericFamilyN
ame) |
165 { | 167 { |
166 if (!settings) | |
167 return emptyAtom; | |
168 | |
169 UScriptCode script = fontDescription.script(); | 168 UScriptCode script = fontDescription.script(); |
170 | 169 |
171 if (fontDescription.genericFamily() == FontDescription::StandardFamily && !f
ontDescription.isSpecifiedFont()) | 170 if (fontDescription.genericFamily() == FontDescription::StandardFamily && !f
ontDescription.isSpecifiedFont()) |
172 return settings->genericFontFamilySettings().standard(script); | 171 return settings.standard(script); |
173 | 172 |
174 #if OS(ANDROID) | 173 #if OS(ANDROID) |
175 return FontCache::getGenericFamilyNameForScript(genericFamilyName, script); | 174 return FontCache::getGenericFamilyNameForScript(genericFamilyName, script); |
176 #else | 175 #else |
177 if (genericFamilyName == FontFamilyNames::webkit_serif) | 176 if (genericFamilyName == FontFamilyNames::webkit_serif) |
178 return settings->genericFontFamilySettings().serif(script); | 177 return settings.serif(script); |
179 if (genericFamilyName == FontFamilyNames::webkit_sans_serif) | 178 if (genericFamilyName == FontFamilyNames::webkit_sans_serif) |
180 return settings->genericFontFamilySettings().sansSerif(script); | 179 return settings.sansSerif(script); |
181 if (genericFamilyName == FontFamilyNames::webkit_cursive) | 180 if (genericFamilyName == FontFamilyNames::webkit_cursive) |
182 return settings->genericFontFamilySettings().cursive(script); | 181 return settings.cursive(script); |
183 if (genericFamilyName == FontFamilyNames::webkit_fantasy) | 182 if (genericFamilyName == FontFamilyNames::webkit_fantasy) |
184 return settings->genericFontFamilySettings().fantasy(script); | 183 return settings.fantasy(script); |
185 if (genericFamilyName == FontFamilyNames::webkit_monospace) | 184 if (genericFamilyName == FontFamilyNames::webkit_monospace) |
186 return settings->genericFontFamilySettings().fixed(script); | 185 return settings.fixed(script); |
187 if (genericFamilyName == FontFamilyNames::webkit_pictograph) | 186 if (genericFamilyName == FontFamilyNames::webkit_pictograph) |
188 return settings->genericFontFamilySettings().pictograph(script); | 187 return settings.pictograph(script); |
189 if (genericFamilyName == FontFamilyNames::webkit_standard) | 188 if (genericFamilyName == FontFamilyNames::webkit_standard) |
190 return settings->genericFontFamilySettings().standard(script); | 189 return settings.standard(script); |
191 #endif | 190 #endif |
192 return emptyAtom; | 191 return emptyAtom; |
193 } | 192 } |
194 | 193 |
195 PassRefPtr<FontData> CSSFontSelector::getFontData(const FontDescription& fontDes
cription, const AtomicString& familyName) | 194 PassRefPtr<FontData> CSSFontSelector::getFontData(const FontDescription& fontDes
cription, const AtomicString& familyName) |
196 { | 195 { |
197 if (!m_document || !m_document->frame()) | |
198 return 0; | |
199 | |
200 if (CSSSegmentedFontFace* face = m_cssSegmentedFontFaceCache.getFontFace(fon
tDescription, familyName)) | 196 if (CSSSegmentedFontFace* face = m_cssSegmentedFontFaceCache.getFontFace(fon
tDescription, familyName)) |
201 return face->getFontData(fontDescription); | 197 return face->getFontData(fontDescription); |
202 | 198 |
203 // Try to return the correct font based off our settings, in case we were ha
nded the generic font family name. | 199 // Try to return the correct font based off our settings, in case we were ha
nded the generic font family name. |
204 AtomicString settingsFamilyName = familyNameFromSettings(m_document->frame()
->settings(), fontDescription, familyName); | 200 AtomicString settingsFamilyName = familyNameFromSettings(m_genericFontFamily
Settings, fontDescription, familyName); |
205 if (settingsFamilyName.isEmpty()) | 201 if (settingsFamilyName.isEmpty()) |
206 return 0; | 202 return 0; |
207 | 203 |
208 return fontCache()->getFontResourceData(fontDescription, settingsFamilyName)
; | 204 return fontCache()->getFontResourceData(fontDescription, settingsFamilyName)
; |
209 } | 205 } |
210 | 206 |
211 CSSSegmentedFontFace* CSSFontSelector::getFontFace(const FontDescription& fontDe
scription, const AtomicString& familyName) | 207 CSSSegmentedFontFace* CSSFontSelector::getFontFace(const FontDescription& fontDe
scription, const AtomicString& familyName) |
212 { | 208 { |
213 return m_cssSegmentedFontFaceCache.getFontFace(fontDescription, familyName); | 209 return m_cssSegmentedFontFaceCache.getFontFace(fontDescription, familyName); |
214 } | 210 } |
(...skipping 15 matching lines...) Expand all Loading... |
230 { | 226 { |
231 m_fontLoader.addFontToBeginLoading(font); | 227 m_fontLoader.addFontToBeginLoading(font); |
232 } | 228 } |
233 | 229 |
234 void CSSFontSelector::loadPendingFonts() | 230 void CSSFontSelector::loadPendingFonts() |
235 { | 231 { |
236 m_fontLoader.loadPendingFonts(); | 232 m_fontLoader.loadPendingFonts(); |
237 } | 233 } |
238 | 234 |
239 } | 235 } |
OLD | NEW |