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

Side by Side Diff: third_party/WebKit/Source/core/css/FontFaceSet.cpp

Issue 2624893003: Move the FontFaceCache stored in CSSFontSelector to be stored in Document. (Closed)
Patch Set: Rebase Created 3 years, 10 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google 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 are met: 5 * modification, are permitted provided that the following conditions are met:
6 * 6 *
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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 129
130 Document* FontFaceSet::document() const { 130 Document* FontFaceSet::document() const {
131 return toDocument(getExecutionContext()); 131 return toDocument(getExecutionContext());
132 } 132 }
133 133
134 bool FontFaceSet::inActiveDocumentContext() const { 134 bool FontFaceSet::inActiveDocumentContext() const {
135 ExecutionContext* context = getExecutionContext(); 135 ExecutionContext* context = getExecutionContext();
136 return context && toDocument(context)->isActive(); 136 return context && toDocument(context)->isActive();
137 } 137 }
138 138
139 void FontFaceSet::addFontFacesToFontFaceCache(FontFaceCache* fontFaceCache, 139 void FontFaceSet::addFontFacesToFontFaceCache(CSSFontSelector* fontSelector) {
140 CSSFontSelector* fontSelector) { 140 FontFaceCache* fontFaceCache = document()->fontFaceCache();
141 for (const auto& fontFace : m_nonCSSConnectedFaces) 141 for (const auto& fontFace : m_nonCSSConnectedFaces)
142 fontFaceCache->addFontFace(fontSelector, fontFace, false); 142 fontFaceCache->addFontFace(fontSelector, fontFace, false);
143 } 143 }
144 144
145 const AtomicString& FontFaceSet::interfaceName() const { 145 const AtomicString& FontFaceSet::interfaceName() const {
146 return EventTargetNames::FontFaceSet; 146 return EventTargetNames::FontFaceSet;
147 } 147 }
148 148
149 ExecutionContext* FontFaceSet::getExecutionContext() const { 149 ExecutionContext* FontFaceSet::getExecutionContext() const {
150 return SuspendableObject::getExecutionContext(); 150 return SuspendableObject::getExecutionContext();
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 ExceptionState&) { 251 ExceptionState&) {
252 ASSERT(fontFace); 252 ASSERT(fontFace);
253 if (!inActiveDocumentContext()) 253 if (!inActiveDocumentContext())
254 return this; 254 return this;
255 if (m_nonCSSConnectedFaces.contains(fontFace)) 255 if (m_nonCSSConnectedFaces.contains(fontFace))
256 return this; 256 return this;
257 if (isCSSConnectedFontFace(fontFace)) 257 if (isCSSConnectedFontFace(fontFace))
258 return this; 258 return this;
259 CSSFontSelector* fontSelector = document()->styleEngine().fontSelector(); 259 CSSFontSelector* fontSelector = document()->styleEngine().fontSelector();
260 m_nonCSSConnectedFaces.add(fontFace); 260 m_nonCSSConnectedFaces.add(fontFace);
261 fontSelector->fontFaceCache()->addFontFace(fontSelector, fontFace, false); 261 document()->fontFaceCache()->addFontFace(fontSelector, fontFace, false);
262 if (fontFace->loadStatus() == FontFace::Loading) 262 if (fontFace->loadStatus() == FontFace::Loading)
263 addToLoadingFonts(fontFace); 263 addToLoadingFonts(fontFace);
264 fontSelector->fontFaceInvalidated(); 264 fontSelector->fontFaceInvalidated();
265 return this; 265 return this;
266 } 266 }
267 267
268 void FontFaceSet::clearForBinding(ScriptState*, ExceptionState&) { 268 void FontFaceSet::clearForBinding(ScriptState*, ExceptionState&) {
269 if (!inActiveDocumentContext() || m_nonCSSConnectedFaces.isEmpty()) 269 if (!inActiveDocumentContext() || m_nonCSSConnectedFaces.isEmpty())
270 return; 270 return;
271 CSSFontSelector* fontSelector = document()->styleEngine().fontSelector(); 271 CSSFontSelector* fontSelector = document()->styleEngine().fontSelector();
272 FontFaceCache* fontFaceCache = fontSelector->fontFaceCache(); 272 FontFaceCache* fontFaceCache = document()->fontFaceCache();
273 for (const auto& fontFace : m_nonCSSConnectedFaces) { 273 for (const auto& fontFace : m_nonCSSConnectedFaces) {
274 fontFaceCache->removeFontFace(fontFace.get(), false); 274 fontFaceCache->removeFontFace(fontFace.get(), false);
275 if (fontFace->loadStatus() == FontFace::Loading) 275 if (fontFace->loadStatus() == FontFace::Loading)
276 removeFromLoadingFonts(fontFace); 276 removeFromLoadingFonts(fontFace);
277 } 277 }
278 m_nonCSSConnectedFaces.clear(); 278 m_nonCSSConnectedFaces.clear();
279 fontSelector->fontFaceInvalidated(); 279 fontSelector->fontFaceInvalidated();
280 } 280 }
281 281
282 bool FontFaceSet::deleteForBinding(ScriptState*, 282 bool FontFaceSet::deleteForBinding(ScriptState*,
283 FontFace* fontFace, 283 FontFace* fontFace,
284 ExceptionState&) { 284 ExceptionState&) {
285 ASSERT(fontFace); 285 ASSERT(fontFace);
286 if (!inActiveDocumentContext()) 286 if (!inActiveDocumentContext())
287 return false; 287 return false;
288 HeapListHashSet<Member<FontFace>>::iterator it = 288 HeapListHashSet<Member<FontFace>>::iterator it =
289 m_nonCSSConnectedFaces.find(fontFace); 289 m_nonCSSConnectedFaces.find(fontFace);
290 if (it != m_nonCSSConnectedFaces.end()) { 290 if (it != m_nonCSSConnectedFaces.end()) {
291 m_nonCSSConnectedFaces.remove(it); 291 m_nonCSSConnectedFaces.remove(it);
292 CSSFontSelector* fontSelector = document()->styleEngine().fontSelector(); 292 CSSFontSelector* fontSelector = document()->styleEngine().fontSelector();
293 fontSelector->fontFaceCache()->removeFontFace(fontFace, false); 293 document()->fontFaceCache()->removeFontFace(fontFace, false);
294 if (fontFace->loadStatus() == FontFace::Loading) 294 if (fontFace->loadStatus() == FontFace::Loading)
295 removeFromLoadingFonts(fontFace); 295 removeFromLoadingFonts(fontFace);
296 fontSelector->fontFaceInvalidated(); 296 fontSelector->fontFaceInvalidated();
297 return true; 297 return true;
298 } 298 }
299 return false; 299 return false;
300 } 300 }
301 301
302 bool FontFaceSet::hasForBinding(ScriptState*, 302 bool FontFaceSet::hasForBinding(ScriptState*,
303 FontFace* fontFace, 303 FontFace* fontFace,
304 ExceptionState&) const { 304 ExceptionState&) const {
305 ASSERT(fontFace); 305 ASSERT(fontFace);
306 if (!inActiveDocumentContext()) 306 if (!inActiveDocumentContext())
307 return false; 307 return false;
308 return m_nonCSSConnectedFaces.contains(fontFace) || 308 return m_nonCSSConnectedFaces.contains(fontFace) ||
309 isCSSConnectedFontFace(fontFace); 309 isCSSConnectedFontFace(fontFace);
310 } 310 }
311 311
312 const HeapListHashSet<Member<FontFace>>& FontFaceSet::cssConnectedFontFaceList() 312 const HeapListHashSet<Member<FontFace>>& FontFaceSet::cssConnectedFontFaceList()
313 const { 313 const {
314 Document* document = this->document(); 314 Document* document = this->document();
315 document->updateActiveStyle(); 315 document->updateActiveStyle();
316 return document->styleEngine() 316 return document->fontFaceCache()->cssConnectedFontFaces();
317 .fontSelector()
318 ->fontFaceCache()
319 ->cssConnectedFontFaces();
320 } 317 }
321 318
322 bool FontFaceSet::isCSSConnectedFontFace(FontFace* fontFace) const { 319 bool FontFaceSet::isCSSConnectedFontFace(FontFace* fontFace) const {
323 return cssConnectedFontFaceList().contains(fontFace); 320 return cssConnectedFontFaceList().contains(fontFace);
324 } 321 }
325 322
326 size_t FontFaceSet::size() const { 323 size_t FontFaceSet::size() const {
327 if (!inActiveDocumentContext()) 324 if (!inActiveDocumentContext())
328 return m_nonCSSConnectedFaces.size(); 325 return m_nonCSSConnectedFaces.size();
329 return cssConnectedFontFaceList().size() + m_nonCSSConnectedFaces.size(); 326 return cssConnectedFontFaceList().size() + m_nonCSSConnectedFaces.size();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 Font font; 371 Font font;
375 if (!resolveFontStyle(fontString, font)) { 372 if (!resolveFontStyle(fontString, font)) {
376 ScriptPromiseResolver* resolver = 373 ScriptPromiseResolver* resolver =
377 ScriptPromiseResolver::create(scriptState); 374 ScriptPromiseResolver::create(scriptState);
378 ScriptPromise promise = resolver->promise(); 375 ScriptPromise promise = resolver->promise();
379 resolver->reject(DOMException::create( 376 resolver->reject(DOMException::create(
380 SyntaxError, "Could not resolve '" + fontString + "' as a font.")); 377 SyntaxError, "Could not resolve '" + fontString + "' as a font."));
381 return promise; 378 return promise;
382 } 379 }
383 380
384 FontFaceCache* fontFaceCache = 381 FontFaceCache* fontFaceCache = document()->fontFaceCache();
385 document()->styleEngine().fontSelector()->fontFaceCache();
386 FontFaceArray faces; 382 FontFaceArray faces;
387 for (const FontFamily* f = &font.getFontDescription().family(); f; 383 for (const FontFamily* f = &font.getFontDescription().family(); f;
388 f = f->next()) { 384 f = f->next()) {
389 CSSSegmentedFontFace* segmentedFontFace = 385 CSSSegmentedFontFace* segmentedFontFace =
390 fontFaceCache->get(font.getFontDescription(), f->family()); 386 fontFaceCache->get(font.getFontDescription(), f->family());
391 if (segmentedFontFace) 387 if (segmentedFontFace)
392 segmentedFontFace->match(text, faces); 388 segmentedFontFace->match(text, faces);
393 } 389 }
394 390
395 LoadFontPromiseResolver* resolver = 391 LoadFontPromiseResolver* resolver =
(...skipping 11 matching lines...) Expand all
407 return false; 403 return false;
408 404
409 Font font; 405 Font font;
410 if (!resolveFontStyle(fontString, font)) { 406 if (!resolveFontStyle(fontString, font)) {
411 exceptionState.throwDOMException( 407 exceptionState.throwDOMException(
412 SyntaxError, "Could not resolve '" + fontString + "' as a font."); 408 SyntaxError, "Could not resolve '" + fontString + "' as a font.");
413 return false; 409 return false;
414 } 410 }
415 411
416 CSSFontSelector* fontSelector = document()->styleEngine().fontSelector(); 412 CSSFontSelector* fontSelector = document()->styleEngine().fontSelector();
417 FontFaceCache* fontFaceCache = fontSelector->fontFaceCache(); 413 FontFaceCache* fontFaceCache = document()->fontFaceCache();
418 414
419 bool hasLoadedFaces = false; 415 bool hasLoadedFaces = false;
420 for (const FontFamily* f = &font.getFontDescription().family(); f; 416 for (const FontFamily* f = &font.getFontDescription().family(); f;
421 f = f->next()) { 417 f = f->next()) {
422 CSSSegmentedFontFace* face = 418 CSSSegmentedFontFace* face =
423 fontFaceCache->get(font.getFontDescription(), f->family()); 419 fontFaceCache->get(font.getFontDescription(), f->family());
424 if (face) { 420 if (face) {
425 if (!face->checkFont(text)) 421 if (!face->checkFont(text))
426 return false; 422 return false;
427 hasLoadedFaces = true; 423 hasLoadedFaces = true;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 visitor->trace(m_failedFonts); 557 visitor->trace(m_failedFonts);
562 visitor->trace(m_nonCSSConnectedFaces); 558 visitor->trace(m_nonCSSConnectedFaces);
563 visitor->trace(m_asyncRunner); 559 visitor->trace(m_asyncRunner);
564 EventTargetWithInlineData::trace(visitor); 560 EventTargetWithInlineData::trace(visitor);
565 Supplement<Document>::trace(visitor); 561 Supplement<Document>::trace(visitor);
566 SuspendableObject::trace(visitor); 562 SuspendableObject::trace(visitor);
567 FontFace::LoadFontCallback::trace(visitor); 563 FontFace::LoadFontCallback::trace(visitor);
568 } 564 }
569 565
570 } // namespace blink 566 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/FontFaceSet.h ('k') | third_party/WebKit/Source/core/css/resolver/ScopedStyleResolver.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698