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