This source file includes following definitions.
- m_resourceFetcher
- addFontToBeginLoading
- beginLoadTimerFired
- loadPendingFonts
- clearResourceFetcher
- m_genericFontFamilySettings
- registerForInvalidationCallbacks
- unregisterForInvalidationCallbacks
- dispatchInvalidationCallbacks
- fontLoaded
- fontCacheInvalidated
- familyNameFromSettings
- getFontData
- willUseFontData
- clearDocument
- beginLoadingFontSoon
- loadPendingFonts
- updateGenericFontFamilySettings
#include "config.h"
#include "core/css/CSSFontSelector.h"
#include "RuntimeEnabledFeatures.h"
#include "core/css/CSSSegmentedFontFace.h"
#include "core/css/CSSValueList.h"
#include "core/css/FontFaceSet.h"
#include "core/css/resolver/StyleResolver.h"
#include "core/dom/Document.h"
#include "core/fetch/FontResource.h"
#include "core/fetch/ResourceFetcher.h"
#include "core/frame/LocalFrame.h"
#include "core/frame/Settings.h"
#include "core/loader/FrameLoader.h"
#include "platform/fonts/FontCache.h"
#include "platform/fonts/SimpleFontData.h"
#include "wtf/text/AtomicString.h"
using namespace std;
namespace WebCore {
FontLoader::FontLoader(ResourceFetcher* resourceFetcher)
: m_beginLoadingTimer(this, &FontLoader::beginLoadTimerFired)
, m_resourceFetcher(resourceFetcher)
{
}
void FontLoader::addFontToBeginLoading(FontResource* fontResource)
{
if (!m_resourceFetcher || !fontResource->stillNeedsLoad())
return;
m_fontsToBeginLoading.append(fontResource);
m_resourceFetcher->incrementRequestCount(fontResource);
m_beginLoadingTimer.startOneShot(0, FROM_HERE);
}
void FontLoader::beginLoadTimerFired(Timer<WebCore::FontLoader>*)
{
loadPendingFonts();
}
void FontLoader::loadPendingFonts()
{
ASSERT(m_resourceFetcher);
Vector<ResourcePtr<FontResource> > fontsToBeginLoading;
fontsToBeginLoading.swap(m_fontsToBeginLoading);
for (size_t i = 0; i < fontsToBeginLoading.size(); ++i) {
fontsToBeginLoading[i]->beginLoadIfNeeded(m_resourceFetcher);
m_resourceFetcher->decrementRequestCount(fontsToBeginLoading[i].get());
}
}
void FontLoader::clearResourceFetcher()
{
if (!m_resourceFetcher) {
ASSERT(m_fontsToBeginLoading.isEmpty());
return;
}
m_beginLoadingTimer.stop();
for (size_t i = 0; i < m_fontsToBeginLoading.size(); ++i) {
m_resourceFetcher->decrementRequestCount(m_fontsToBeginLoading[i].get());
}
m_fontsToBeginLoading.clear();
m_resourceFetcher = 0;
}
CSSFontSelector::CSSFontSelector(Document* document)
: m_document(document)
, m_fontLoader(document->fetcher())
, m_genericFontFamilySettings(document->frame()->settings()->genericFontFamilySettings())
{
ASSERT(m_document);
ASSERT(m_document->frame());
FontCache::fontCache()->addClient(this);
FontFaceSet::from(*document)->addFontFacesToFontFaceCache(&m_fontFaceCache, this);
}
CSSFontSelector::~CSSFontSelector()
{
clearDocument();
FontCache::fontCache()->removeClient(this);
}
void CSSFontSelector::registerForInvalidationCallbacks(CSSFontSelectorClient* client)
{
m_clients.add(client);
}
#if !ENABLE(OILPAN)
void CSSFontSelector::unregisterForInvalidationCallbacks(CSSFontSelectorClient* client)
{
m_clients.remove(client);
}
#endif
void CSSFontSelector::dispatchInvalidationCallbacks()
{
WillBeHeapVector<RawPtrWillBeMember<CSSFontSelectorClient> > clients;
copyToVector(m_clients, clients);
for (size_t i = 0; i < clients.size(); ++i)
clients[i]->fontsNeedUpdate(this);
}
void CSSFontSelector::fontLoaded()
{
dispatchInvalidationCallbacks();
}
void CSSFontSelector::fontCacheInvalidated()
{
dispatchInvalidationCallbacks();
}
static AtomicString familyNameFromSettings(const GenericFontFamilySettings& settings, const FontDescription& fontDescription, const AtomicString& genericFamilyName)
{
UScriptCode script = fontDescription.script();
#if OS(ANDROID)
if (fontDescription.genericFamily() == FontDescription::StandardFamily)
return FontCache::getGenericFamilyNameForScript(FontFamilyNames::webkit_standard, script);
if (genericFamilyName.startsWith("-webkit-"))
return FontCache::getGenericFamilyNameForScript(genericFamilyName, script);
#else
if (fontDescription.genericFamily() == FontDescription::StandardFamily)
return settings.standard(script);
if (genericFamilyName == FontFamilyNames::webkit_serif)
return settings.serif(script);
if (genericFamilyName == FontFamilyNames::webkit_sans_serif)
return settings.sansSerif(script);
if (genericFamilyName == FontFamilyNames::webkit_cursive)
return settings.cursive(script);
if (genericFamilyName == FontFamilyNames::webkit_fantasy)
return settings.fantasy(script);
if (genericFamilyName == FontFamilyNames::webkit_monospace)
return settings.fixed(script);
if (genericFamilyName == FontFamilyNames::webkit_pictograph)
return settings.pictograph(script);
if (genericFamilyName == FontFamilyNames::webkit_standard)
return settings.standard(script);
#endif
return emptyAtom;
}
PassRefPtr<FontData> CSSFontSelector::getFontData(const FontDescription& fontDescription, const AtomicString& familyName)
{
if (CSSSegmentedFontFace* face = m_fontFaceCache.get(fontDescription, familyName))
return face->getFontData(fontDescription);
AtomicString settingsFamilyName = familyNameFromSettings(m_genericFontFamilySettings, fontDescription, familyName);
if (settingsFamilyName.isEmpty())
return nullptr;
return FontCache::fontCache()->getFontData(fontDescription, settingsFamilyName);
}
void CSSFontSelector::willUseFontData(const FontDescription& fontDescription, const AtomicString& family)
{
CSSSegmentedFontFace* face = m_fontFaceCache.get(fontDescription, family);
if (face)
face->willUseFontData(fontDescription);
}
void CSSFontSelector::clearDocument()
{
m_fontLoader.clearResourceFetcher();
m_document = 0;
}
void CSSFontSelector::beginLoadingFontSoon(FontResource* font)
{
m_fontLoader.addFontToBeginLoading(font);
}
void CSSFontSelector::loadPendingFonts()
{
m_fontLoader.loadPendingFonts();
}
void CSSFontSelector::updateGenericFontFamilySettings(Document& document)
{
ASSERT(document.settings());
m_genericFontFamilySettings = document.settings()->genericFontFamilySettings();
}
}