Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(434)

Side by Side Diff: Source/core/css/CSSFontFaceSource.cpp

Issue 23446007: Use unicode-range to prevent unnecessary @font-face donwnloads (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008, 2010, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008, 2010, 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 if (m_font) 61 if (m_font)
62 m_font->removeClient(this); 62 m_font->removeClient(this);
63 pruneTable(); 63 pruneTable();
64 } 64 }
65 65
66 void CSSFontFaceSource::pruneTable() 66 void CSSFontFaceSource::pruneTable()
67 { 67 {
68 if (m_fontDataTable.isEmpty()) 68 if (m_fontDataTable.isEmpty())
69 return; 69 return;
70 70
71 for (FontDataTable::iterator it = m_fontDataTable.begin(); it != m_fontDataT able.end(); ++it) {
72 if (SimpleFontData* fontData = it->value.get())
73 fontData->clearCSSFontFaceSource();
74 }
71 m_fontDataTable.clear(); 75 m_fontDataTable.clear();
72 } 76 }
73 77
74 bool CSSFontFaceSource::isLocal() const 78 bool CSSFontFaceSource::isLocal() const
75 { 79 {
76 if (m_font) 80 if (m_font)
77 return false; 81 return false;
78 #if ENABLE(SVG_FONTS) 82 #if ENABLE(SVG_FONTS)
79 if (m_svgFontFaceElement) 83 if (m_svgFontFaceElement)
80 return false; 84 return false;
81 #endif 85 #endif
82 return true; 86 return true;
83 } 87 }
84 88
89 bool CSSFontFaceSource::isLoading() const
90 {
91 if (m_font)
92 return !m_font->stillNeedsLoad() && !m_font->isLoaded();
93 return false;
94 }
95
85 bool CSSFontFaceSource::isLoaded() const 96 bool CSSFontFaceSource::isLoaded() const
86 { 97 {
87 if (m_font) 98 if (m_font)
88 return m_font->isLoaded(); 99 return m_font->isLoaded();
89 return true; 100 return true;
90 } 101 }
91 102
92 bool CSSFontFaceSource::isValid() const 103 bool CSSFontFaceSource::isValid() const
93 { 104 {
94 if (m_font) 105 if (m_font)
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 fontDescription.orientation(), fontDescription.widthVariant( )), true, false); 197 fontDescription.orientation(), fontDescription.widthVariant( )), true, false);
187 } 198 }
188 } else { 199 } else {
189 #if ENABLE(SVG_FONTS) 200 #if ENABLE(SVG_FONTS)
190 // In-Document SVG Fonts 201 // In-Document SVG Fonts
191 if (m_svgFontFaceElement) 202 if (m_svgFontFaceElement)
192 fontData = SimpleFontData::create(SVGFontData::create(m_svgFontF aceElement.get()), fontDescription.computedPixelSize(), syntheticBold, synthetic Italic); 203 fontData = SimpleFontData::create(SVGFontData::create(m_svgFontF aceElement.get()), fontDescription.computedPixelSize(), syntheticBold, synthetic Italic);
193 #endif 204 #endif
194 } 205 }
195 } else { 206 } else {
196 // Kick off the load. Do it soon rather than now, because we may be in t he middle of layout,
197 // and the loader may invoke arbitrary delegate or event handler code.
198 fontSelector->beginLoadingFontSoon(m_font.get());
199
200 // This temporary font is not retained and should not be returned. 207 // This temporary font is not retained and should not be returned.
201 FontCachePurgePreventer fontCachePurgePreventer; 208 FontCachePurgePreventer fontCachePurgePreventer;
202 SimpleFontData* temporaryFont = fontCache()->getNonRetainedLastResortFal lbackFont(fontDescription); 209 SimpleFontData* temporaryFont = fontCache()->getNonRetainedLastResortFal lbackFont(fontDescription);
203 fontData = SimpleFontData::create(temporaryFont->platformData(), true, t rue); 210 fontData = SimpleFontData::create(temporaryFont->platformData(), true, t rue);
211 fontData->setCSSFontFaceSource(this);
204 } 212 }
205 213
206 return fontData; // No release, because fontData is a reference to a RefPtr that is held in the m_fontDataTable. 214 return fontData; // No release, because fontData is a reference to a RefPtr that is held in the m_fontDataTable.
207 } 215 }
208 216
209 #if ENABLE(SVG_FONTS) 217 #if ENABLE(SVG_FONTS)
210 SVGFontFaceElement* CSSFontFaceSource::svgFontFaceElement() const 218 SVGFontFaceElement* CSSFontFaceSource::svgFontFaceElement() const
211 { 219 {
212 return m_svgFontFaceElement.get(); 220 return m_svgFontFaceElement.get();
213 } 221 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 return false; 255 return false;
248 return fontCache()->isPlatformFontAvailable(fontDescription, m_string, true) ; 256 return fontCache()->isPlatformFontAvailable(fontDescription, m_string, true) ;
249 } 257 }
250 258
251 void CSSFontFaceSource::willUseFontData() 259 void CSSFontFaceSource::willUseFontData()
252 { 260 {
253 if (!isLoaded()) 261 if (!isLoaded())
254 m_histograms.willUseFontData(); 262 m_histograms.willUseFontData();
255 } 263 }
256 264
265 void CSSFontFaceSource::beginLoadingFontSoon()
266 {
267 ASSERT(m_face);
268 ASSERT(m_font);
269 m_face->beginLoadingFontSoon(m_font.get());
270 }
271
257 CSSFontFaceSource::FontLoadHistograms::~FontLoadHistograms() 272 CSSFontFaceSource::FontLoadHistograms::~FontLoadHistograms()
258 { 273 {
259 if (m_styledTime > 0) 274 if (m_styledTime > 0)
260 HistogramSupport::histogramEnumeration("WebFont.UsageType", StyledButNot Used, UsageTypeMax); 275 HistogramSupport::histogramEnumeration("WebFont.UsageType", StyledButNot Used, UsageTypeMax);
261 } 276 }
262 277
263 void CSSFontFaceSource::FontLoadHistograms::willUseFontData() 278 void CSSFontFaceSource::FontLoadHistograms::willUseFontData()
264 { 279 {
265 if (!m_styledTime) 280 if (!m_styledTime)
266 m_styledTime = currentTimeMS(); 281 m_styledTime = currentTimeMS();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 if (size < 50 * 1024) 326 if (size < 50 * 1024)
312 return "WebFont.DownloadTime.1.10KBTo50KB"; 327 return "WebFont.DownloadTime.1.10KBTo50KB";
313 if (size < 100 * 1024) 328 if (size < 100 * 1024)
314 return "WebFont.DownloadTime.2.50KBTo100KB"; 329 return "WebFont.DownloadTime.2.50KBTo100KB";
315 if (size < 1024 * 1024) 330 if (size < 1024 * 1024)
316 return "WebFont.DownloadTime.3.100KBTo1MB"; 331 return "WebFont.DownloadTime.3.100KBTo1MB";
317 return "WebFont.DownloadTime.4.Over1MB"; 332 return "WebFont.DownloadTime.4.Over1MB";
318 } 333 }
319 334
320 } 335 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698