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

Side by Side Diff: Source/core/fetch/FontResource.cpp

Issue 171823002: Make text visible when font loading takes longer than 3 seconds (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase Created 6 years, 9 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
« no previous file with comments | « Source/core/fetch/FontResource.h ('k') | Source/platform/fonts/CustomFontData.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Torch Mobile, Inc. 3 * Copyright (C) 2009 Torch Mobile, Inc.
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 26 matching lines...) Expand all
37 37
38 #if ENABLE(SVG_FONTS) 38 #if ENABLE(SVG_FONTS)
39 #include "SVGNames.h" 39 #include "SVGNames.h"
40 #include "core/html/HTMLCollection.h" 40 #include "core/html/HTMLCollection.h"
41 #include "core/svg/SVGDocument.h" 41 #include "core/svg/SVGDocument.h"
42 #include "core/svg/SVGFontElement.h" 42 #include "core/svg/SVGFontElement.h"
43 #endif 43 #endif
44 44
45 namespace WebCore { 45 namespace WebCore {
46 46
47 static const double fontLoadWaitLimitSec = 3.0;
48
47 FontResource::FontResource(const ResourceRequest& resourceRequest) 49 FontResource::FontResource(const ResourceRequest& resourceRequest)
48 : Resource(resourceRequest, Font) 50 : Resource(resourceRequest, Font)
49 , m_loadInitiated(false) 51 , m_loadInitiated(false)
52 , m_exceedsFontLoadWaitLimit(false)
53 , m_fontLoadWaitLimitTimer(this, &FontResource::fontLoadWaitLimitCallback)
50 { 54 {
51 } 55 }
52 56
53 FontResource::~FontResource() 57 FontResource::~FontResource()
54 { 58 {
55 } 59 }
56 60
57 void FontResource::load(ResourceFetcher*, const ResourceLoaderOptions& options) 61 void FontResource::load(ResourceFetcher*, const ResourceLoaderOptions& options)
58 { 62 {
59 // Don't load the file yet. Wait for an access before triggering the load. 63 // Don't load the file yet. Wait for an access before triggering the load.
60 setLoading(true); 64 setLoading(true);
61 m_options = options; 65 m_options = options;
62 } 66 }
63 67
64 void FontResource::didAddClient(ResourceClient* c) 68 void FontResource::didAddClient(ResourceClient* c)
65 { 69 {
66 ASSERT(c->resourceClientType() == FontResourceClient::expectedType()); 70 ASSERT(c->resourceClientType() == FontResourceClient::expectedType());
67 Resource::didAddClient(c); 71 Resource::didAddClient(c);
68 if (!isLoading()) 72 if (!isLoading())
69 static_cast<FontResourceClient*>(c)->fontLoaded(this); 73 static_cast<FontResourceClient*>(c)->fontLoaded(this);
70 } 74 }
71 75
72 void FontResource::beginLoadIfNeeded(ResourceFetcher* dl) 76 void FontResource::beginLoadIfNeeded(ResourceFetcher* dl)
73 { 77 {
74 if (!m_loadInitiated) { 78 if (!m_loadInitiated) {
75 m_loadInitiated = true; 79 m_loadInitiated = true;
76 Resource::load(dl, m_options); 80 Resource::load(dl, m_options);
81 m_fontLoadWaitLimitTimer.startOneShot(fontLoadWaitLimitSec);
77 82
78 ResourceClientWalker<FontResourceClient> walker(m_clients); 83 ResourceClientWalker<FontResourceClient> walker(m_clients);
79 while (FontResourceClient* client = walker.next()) 84 while (FontResourceClient* client = walker.next())
80 client->didStartFontLoad(this); 85 client->didStartFontLoad(this);
81 } 86 }
82 } 87 }
83 88
84 bool FontResource::ensureCustomFontData() 89 bool FontResource::ensureCustomFontData()
85 { 90 {
86 if (!m_fontData && !errorOccurred() && !isLoading()) { 91 if (!m_fontData && !errorOccurred() && !isLoading()) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 for (unsigned i = 0; i < collectionLength; ++i) { 153 for (unsigned i = 0; i < collectionLength; ++i) {
149 SVGFontElement* element = toSVGFontElement(collection->item(i)); 154 SVGFontElement* element = toSVGFontElement(collection->item(i));
150 if (element->getIdAttribute() == fontName) 155 if (element->getIdAttribute() == fontName)
151 return element; 156 return element;
152 } 157 }
153 158
154 return 0; 159 return 0;
155 } 160 }
156 #endif 161 #endif
157 162
163 void FontResource::fontLoadWaitLimitCallback(Timer<FontResource>*)
164 {
165 if (!isLoading())
166 return;
167 m_exceedsFontLoadWaitLimit = true;
168 ResourceClientWalker<FontResourceClient> walker(m_clients);
169 while (FontResourceClient* client = walker.next())
170 client->fontLoadWaitLimitExceeded(this);
171 }
172
158 void FontResource::allClientsRemoved() 173 void FontResource::allClientsRemoved()
159 { 174 {
160 m_fontData.clear(); 175 m_fontData.clear();
161 Resource::allClientsRemoved(); 176 Resource::allClientsRemoved();
162 } 177 }
163 178
164 void FontResource::checkNotify() 179 void FontResource::checkNotify()
165 { 180 {
181 m_fontLoadWaitLimitTimer.stop();
166 ResourceClientWalker<FontResourceClient> w(m_clients); 182 ResourceClientWalker<FontResourceClient> w(m_clients);
167 while (FontResourceClient* c = w.next()) 183 while (FontResourceClient* c = w.next())
168 c->fontLoaded(this); 184 c->fontLoaded(this);
169 } 185 }
170 186
171 } 187 }
OLDNEW
« no previous file with comments | « Source/core/fetch/FontResource.h ('k') | Source/platform/fonts/CustomFontData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698