| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 CSSFontSelector::CSSFontSelector(Document* document) | 45 CSSFontSelector::CSSFontSelector(Document* document) |
| 46 : m_document(document), | 46 : m_document(document), |
| 47 m_genericFontFamilySettings( | 47 m_genericFontFamilySettings( |
| 48 document->frame()->settings()->genericFontFamilySettings()) { | 48 document->frame()->settings()->genericFontFamilySettings()) { |
| 49 // FIXME: An old comment used to say there was no need to hold a reference to | 49 // FIXME: An old comment used to say there was no need to hold a reference to |
| 50 // m_document because "we are guaranteed to be destroyed before the document". | 50 // m_document because "we are guaranteed to be destroyed before the document". |
| 51 // But there does not seem to be any such guarantee. | 51 // But there does not seem to be any such guarantee. |
| 52 ASSERT(m_document); | 52 ASSERT(m_document); |
| 53 DCHECK(m_document->frame()); | 53 DCHECK(m_document->frame()); |
| 54 FontCache::fontCache()->addClient(this); | 54 FontCache::fontCache()->addClient(this); |
| 55 FontFaceSet::from(*document)->addFontFacesToFontFaceCache(&m_fontFaceCache, | 55 FontFaceSet::from(*document)->addFontFacesToFontFaceCache(this); |
| 56 this); | |
| 57 } | 56 } |
| 58 | 57 |
| 59 CSSFontSelector::~CSSFontSelector() {} | 58 CSSFontSelector::~CSSFontSelector() {} |
| 60 | 59 |
| 61 void CSSFontSelector::registerForInvalidationCallbacks( | 60 void CSSFontSelector::registerForInvalidationCallbacks( |
| 62 CSSFontSelectorClient* client) { | 61 CSSFontSelectorClient* client) { |
| 63 m_clients.insert(client); | 62 m_clients.insert(client); |
| 64 } | 63 } |
| 65 | 64 |
| 66 void CSSFontSelector::unregisterForInvalidationCallbacks( | 65 void CSSFontSelector::unregisterForInvalidationCallbacks( |
| 67 CSSFontSelectorClient* client) { | 66 CSSFontSelectorClient* client) { |
| 68 m_clients.remove(client); | 67 m_clients.remove(client); |
| 69 } | 68 } |
| 70 | 69 |
| 71 void CSSFontSelector::dispatchInvalidationCallbacks() { | 70 void CSSFontSelector::dispatchInvalidationCallbacks() { |
| 72 m_fontFaceCache.incrementVersion(); | 71 m_document->incrementFontFaceVersion(); |
| 73 | 72 |
| 74 HeapVector<Member<CSSFontSelectorClient>> clients; | 73 HeapVector<Member<CSSFontSelectorClient>> clients; |
| 75 copyToVector(m_clients, clients); | 74 copyToVector(m_clients, clients); |
| 76 for (auto& client : clients) | 75 for (auto& client : clients) |
| 77 client->fontsNeedUpdate(this); | 76 client->fontsNeedUpdate(this); |
| 78 } | 77 } |
| 79 | 78 |
| 80 void CSSFontSelector::fontFaceInvalidated() { | 79 void CSSFontSelector::fontFaceInvalidated() { |
| 81 dispatchInvalidationCallbacks(); | 80 dispatchInvalidationCallbacks(); |
| 82 } | 81 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 if (genericFamilyName == FontFamilyNames::webkit_pictograph) | 113 if (genericFamilyName == FontFamilyNames::webkit_pictograph) |
| 115 return settings.pictograph(script); | 114 return settings.pictograph(script); |
| 116 if (genericFamilyName == FontFamilyNames::webkit_standard) | 115 if (genericFamilyName == FontFamilyNames::webkit_standard) |
| 117 return settings.standard(script); | 116 return settings.standard(script); |
| 118 #endif | 117 #endif |
| 119 return emptyAtom; | 118 return emptyAtom; |
| 120 } | 119 } |
| 121 | 120 |
| 122 PassRefPtr<FontData> CSSFontSelector::getFontData( | 121 PassRefPtr<FontData> CSSFontSelector::getFontData( |
| 123 const FontDescription& fontDescription, | 122 const FontDescription& fontDescription, |
| 124 const AtomicString& familyName) { | 123 const AtomicString& family) { |
| 125 if (CSSSegmentedFontFace* face = | 124 CSSSegmentedFontFace* face = getFontFaceFromCache(fontDescription, family); |
| 126 m_fontFaceCache.get(fontDescription, familyName)) | 125 if (face) |
| 127 return face->getFontData(fontDescription); | 126 return face->getFontData(fontDescription); |
| 128 | 127 |
| 129 // Try to return the correct font based off our settings, in case we were | 128 // Try to return the correct font based off our settings, in case we were |
| 130 // handed the generic font family name. | 129 // handed the generic font family name. |
| 131 AtomicString settingsFamilyName = familyNameFromSettings( | 130 AtomicString settingsFamilyName = familyNameFromSettings( |
| 132 m_genericFontFamilySettings, fontDescription, familyName); | 131 m_genericFontFamilySettings, fontDescription, family); |
| 133 if (settingsFamilyName.isEmpty()) | 132 if (settingsFamilyName.isEmpty()) |
| 134 return nullptr; | 133 return nullptr; |
| 135 | 134 |
| 136 return FontCache::fontCache()->getFontData(fontDescription, | 135 return FontCache::fontCache()->getFontData(fontDescription, |
| 137 settingsFamilyName); | 136 settingsFamilyName); |
| 138 } | 137 } |
| 139 | 138 |
| 140 void CSSFontSelector::willUseFontData(const FontDescription& fontDescription, | 139 void CSSFontSelector::willUseFontData(const FontDescription& fontDescription, |
| 141 const AtomicString& family, | 140 const AtomicString& family, |
| 142 const String& text) { | 141 const String& text) { |
| 143 CSSSegmentedFontFace* face = m_fontFaceCache.get(fontDescription, family); | 142 CSSSegmentedFontFace* face = getFontFaceFromCache(fontDescription, family); |
| 144 if (face) | 143 if (face) |
| 145 face->willUseFontData(fontDescription, text); | 144 face->willUseFontData(fontDescription, text); |
| 146 } | 145 } |
| 147 | 146 |
| 148 void CSSFontSelector::willUseRange(const FontDescription& fontDescription, | 147 void CSSFontSelector::willUseRange(const FontDescription& fontDescription, |
| 149 const AtomicString& family, | 148 const AtomicString& family, |
| 150 const FontDataForRangeSet& rangeSet) { | 149 const FontDataForRangeSet& rangeSet) { |
| 151 CSSSegmentedFontFace* face = m_fontFaceCache.get(fontDescription, family); | 150 CSSSegmentedFontFace* face = getFontFaceFromCache(fontDescription, family); |
| 152 if (face) | 151 if (face) |
| 153 face->willUseRange(fontDescription, rangeSet); | 152 face->willUseRange(fontDescription, rangeSet); |
| 154 } | 153 } |
| 155 | 154 |
| 156 bool CSSFontSelector::isPlatformFontAvailable( | 155 bool CSSFontSelector::isPlatformFontAvailable( |
| 157 const FontDescription& fontDescription, | 156 const FontDescription& fontDescription, |
| 158 const AtomicString& passedFamily) { | 157 const AtomicString& passedFamily) { |
| 159 AtomicString family = familyNameFromSettings(m_genericFontFamilySettings, | 158 AtomicString family = familyNameFromSettings(m_genericFontFamilySettings, |
| 160 fontDescription, passedFamily); | 159 fontDescription, passedFamily); |
| 161 if (family.isEmpty()) | 160 if (family.isEmpty()) |
| 162 family = passedFamily; | 161 family = passedFamily; |
| 163 return FontCache::fontCache()->isPlatformFontAvailable(fontDescription, | 162 return FontCache::fontCache()->isPlatformFontAvailable(fontDescription, |
| 164 family); | 163 family); |
| 165 } | 164 } |
| 166 | 165 |
| 167 void CSSFontSelector::updateGenericFontFamilySettings(Document& document) { | 166 void CSSFontSelector::updateGenericFontFamilySettings(Document& document) { |
| 168 if (!document.settings()) | 167 if (!document.settings()) |
| 169 return; | 168 return; |
| 170 m_genericFontFamilySettings = | 169 m_genericFontFamilySettings = |
| 171 document.settings()->genericFontFamilySettings(); | 170 document.settings()->genericFontFamilySettings(); |
| 172 fontCacheInvalidated(); | 171 fontCacheInvalidated(); |
| 173 } | 172 } |
| 174 | 173 |
| 175 DEFINE_TRACE(CSSFontSelector) { | 174 DEFINE_TRACE(CSSFontSelector) { |
| 176 visitor->trace(m_document); | 175 visitor->trace(m_document); |
| 177 visitor->trace(m_fontFaceCache); | |
| 178 visitor->trace(m_clients); | 176 visitor->trace(m_clients); |
| 179 FontSelector::trace(visitor); | 177 FontSelector::trace(visitor); |
| 180 } | 178 } |
| 181 | 179 |
| 182 } // namespace blink | 180 } // namespace blink |
| OLD | NEW |