OLD | NEW |
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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 if (!fontFace) { | 286 if (!fontFace) { |
287 exceptionState.throwTypeError("The argument is not a FontFace."); | 287 exceptionState.throwTypeError("The argument is not a FontFace."); |
288 return; | 288 return; |
289 } | 289 } |
290 if (m_nonCSSConnectedFaces.contains(fontFace)) | 290 if (m_nonCSSConnectedFaces.contains(fontFace)) |
291 return; | 291 return; |
292 if (isCSSConnectedFontFace(fontFace)) { | 292 if (isCSSConnectedFontFace(fontFace)) { |
293 exceptionState.throwDOMException(InvalidModificationError, "Cannot add a
CSS-connected FontFace."); | 293 exceptionState.throwDOMException(InvalidModificationError, "Cannot add a
CSS-connected FontFace."); |
294 return; | 294 return; |
295 } | 295 } |
296 CSSFontSelector* fontSelector = document()->styleEngine()->fontSelector(); | 296 CSSFontSelector* fontSelector = document()->styleEngine().fontSelector(); |
297 m_nonCSSConnectedFaces.add(fontFace); | 297 m_nonCSSConnectedFaces.add(fontFace); |
298 fontSelector->fontFaceCache()->addFontFace(fontSelector, fontFace, false); | 298 fontSelector->fontFaceCache()->addFontFace(fontSelector, fontFace, false); |
299 if (fontFace->loadStatus() == FontFace::Loading) | 299 if (fontFace->loadStatus() == FontFace::Loading) |
300 addToLoadingFonts(fontFace); | 300 addToLoadingFonts(fontFace); |
301 fontSelector->fontFaceInvalidated(); | 301 fontSelector->fontFaceInvalidated(); |
302 } | 302 } |
303 | 303 |
304 void FontFaceSet::clear() | 304 void FontFaceSet::clear() |
305 { | 305 { |
306 if (!inActiveDocumentContext() || m_nonCSSConnectedFaces.isEmpty()) | 306 if (!inActiveDocumentContext() || m_nonCSSConnectedFaces.isEmpty()) |
307 return; | 307 return; |
308 CSSFontSelector* fontSelector = document()->styleEngine()->fontSelector(); | 308 CSSFontSelector* fontSelector = document()->styleEngine().fontSelector(); |
309 FontFaceCache* fontFaceCache = fontSelector->fontFaceCache(); | 309 FontFaceCache* fontFaceCache = fontSelector->fontFaceCache(); |
310 for (const auto& fontFace : m_nonCSSConnectedFaces) { | 310 for (const auto& fontFace : m_nonCSSConnectedFaces) { |
311 fontFaceCache->removeFontFace(fontFace.get(), false); | 311 fontFaceCache->removeFontFace(fontFace.get(), false); |
312 if (fontFace->loadStatus() == FontFace::Loading) | 312 if (fontFace->loadStatus() == FontFace::Loading) |
313 removeFromLoadingFonts(fontFace); | 313 removeFromLoadingFonts(fontFace); |
314 } | 314 } |
315 m_nonCSSConnectedFaces.clear(); | 315 m_nonCSSConnectedFaces.clear(); |
316 fontSelector->fontFaceInvalidated(); | 316 fontSelector->fontFaceInvalidated(); |
317 } | 317 } |
318 | 318 |
319 bool FontFaceSet::remove(FontFace* fontFace, ExceptionState& exceptionState) | 319 bool FontFaceSet::remove(FontFace* fontFace, ExceptionState& exceptionState) |
320 { | 320 { |
321 if (!inActiveDocumentContext()) | 321 if (!inActiveDocumentContext()) |
322 return false; | 322 return false; |
323 if (!fontFace) { | 323 if (!fontFace) { |
324 exceptionState.throwTypeError("The argument is not a FontFace."); | 324 exceptionState.throwTypeError("The argument is not a FontFace."); |
325 return false; | 325 return false; |
326 } | 326 } |
327 WillBeHeapListHashSet<RefPtrWillBeMember<FontFace> >::iterator it = m_nonCSS
ConnectedFaces.find(fontFace); | 327 WillBeHeapListHashSet<RefPtrWillBeMember<FontFace> >::iterator it = m_nonCSS
ConnectedFaces.find(fontFace); |
328 if (it != m_nonCSSConnectedFaces.end()) { | 328 if (it != m_nonCSSConnectedFaces.end()) { |
329 m_nonCSSConnectedFaces.remove(it); | 329 m_nonCSSConnectedFaces.remove(it); |
330 CSSFontSelector* fontSelector = document()->styleEngine()->fontSelector(
); | 330 CSSFontSelector* fontSelector = document()->styleEngine().fontSelector()
; |
331 fontSelector->fontFaceCache()->removeFontFace(fontFace, false); | 331 fontSelector->fontFaceCache()->removeFontFace(fontFace, false); |
332 if (fontFace->loadStatus() == FontFace::Loading) | 332 if (fontFace->loadStatus() == FontFace::Loading) |
333 removeFromLoadingFonts(fontFace); | 333 removeFromLoadingFonts(fontFace); |
334 fontSelector->fontFaceInvalidated(); | 334 fontSelector->fontFaceInvalidated(); |
335 return true; | 335 return true; |
336 } | 336 } |
337 if (isCSSConnectedFontFace(fontFace)) | 337 if (isCSSConnectedFontFace(fontFace)) |
338 exceptionState.throwDOMException(InvalidModificationError, "Cannot delet
e a CSS-connected FontFace."); | 338 exceptionState.throwDOMException(InvalidModificationError, "Cannot delet
e a CSS-connected FontFace."); |
339 return false; | 339 return false; |
340 } | 340 } |
341 | 341 |
342 bool FontFaceSet::has(FontFace* fontFace, ExceptionState& exceptionState) const | 342 bool FontFaceSet::has(FontFace* fontFace, ExceptionState& exceptionState) const |
343 { | 343 { |
344 if (!inActiveDocumentContext()) | 344 if (!inActiveDocumentContext()) |
345 return false; | 345 return false; |
346 if (!fontFace) { | 346 if (!fontFace) { |
347 exceptionState.throwTypeError("The argument is not a FontFace."); | 347 exceptionState.throwTypeError("The argument is not a FontFace."); |
348 return false; | 348 return false; |
349 } | 349 } |
350 return m_nonCSSConnectedFaces.contains(fontFace) || isCSSConnectedFontFace(f
ontFace); | 350 return m_nonCSSConnectedFaces.contains(fontFace) || isCSSConnectedFontFace(f
ontFace); |
351 } | 351 } |
352 | 352 |
353 const WillBeHeapListHashSet<RefPtrWillBeMember<FontFace> >& FontFaceSet::cssConn
ectedFontFaceList() const | 353 const WillBeHeapListHashSet<RefPtrWillBeMember<FontFace> >& FontFaceSet::cssConn
ectedFontFaceList() const |
354 { | 354 { |
355 Document* d = document(); | 355 Document* d = document(); |
356 d->ensureStyleResolver(); // Flush pending style changes. | 356 d->ensureStyleResolver(); // Flush pending style changes. |
357 return d->styleEngine()->fontSelector()->fontFaceCache()->cssConnectedFontFa
ces(); | 357 return d->styleEngine().fontSelector()->fontFaceCache()->cssConnectedFontFac
es(); |
358 } | 358 } |
359 | 359 |
360 bool FontFaceSet::isCSSConnectedFontFace(FontFace* fontFace) const | 360 bool FontFaceSet::isCSSConnectedFontFace(FontFace* fontFace) const |
361 { | 361 { |
362 return cssConnectedFontFaceList().contains(fontFace); | 362 return cssConnectedFontFaceList().contains(fontFace); |
363 } | 363 } |
364 | 364 |
365 void FontFaceSet::forEach(FontFaceSetForEachCallback* callback, const ScriptValu
e& thisArg) const | 365 void FontFaceSet::forEach(FontFaceSetForEachCallback* callback, const ScriptValu
e& thisArg) const |
366 { | 366 { |
367 forEachInternal(callback, &thisArg); | 367 forEachInternal(callback, &thisArg); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 return ScriptPromise(); | 442 return ScriptPromise(); |
443 | 443 |
444 Font font; | 444 Font font; |
445 if (!resolveFontStyle(fontString, font)) { | 445 if (!resolveFontStyle(fontString, font)) { |
446 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolv
er::create(scriptState); | 446 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolv
er::create(scriptState); |
447 ScriptPromise promise = resolver->promise(); | 447 ScriptPromise promise = resolver->promise(); |
448 resolver->reject(DOMException::create(SyntaxError, "Could not resolve '"
+ fontString + "' as a font.")); | 448 resolver->reject(DOMException::create(SyntaxError, "Could not resolve '"
+ fontString + "' as a font.")); |
449 return promise; | 449 return promise; |
450 } | 450 } |
451 | 451 |
452 FontFaceCache* fontFaceCache = document()->styleEngine()->fontSelector()->fo
ntFaceCache(); | 452 FontFaceCache* fontFaceCache = document()->styleEngine().fontSelector()->fon
tFaceCache(); |
453 FontFaceArray faces; | 453 FontFaceArray faces; |
454 for (const FontFamily* f = &font.fontDescription().family(); f; f = f->next(
)) { | 454 for (const FontFamily* f = &font.fontDescription().family(); f; f = f->next(
)) { |
455 CSSSegmentedFontFace* segmentedFontFace = fontFaceCache->get(font.fontDe
scription(), f->family()); | 455 CSSSegmentedFontFace* segmentedFontFace = fontFaceCache->get(font.fontDe
scription(), f->family()); |
456 if (segmentedFontFace) | 456 if (segmentedFontFace) |
457 segmentedFontFace->match(text, faces); | 457 segmentedFontFace->match(text, faces); |
458 } | 458 } |
459 | 459 |
460 RefPtrWillBeRawPtr<LoadFontPromiseResolver> resolver = LoadFontPromiseResolv
er::create(faces, scriptState); | 460 RefPtrWillBeRawPtr<LoadFontPromiseResolver> resolver = LoadFontPromiseResolv
er::create(faces, scriptState); |
461 ScriptPromise promise = resolver->promise(); | 461 ScriptPromise promise = resolver->promise(); |
462 resolver->loadFonts(executionContext()); // After this, resolver->promise()
may return null. | 462 resolver->loadFonts(executionContext()); // After this, resolver->promise()
may return null. |
463 return promise; | 463 return promise; |
464 } | 464 } |
465 | 465 |
466 bool FontFaceSet::check(const String& fontString, const String& text, ExceptionS
tate& exceptionState) | 466 bool FontFaceSet::check(const String& fontString, const String& text, ExceptionS
tate& exceptionState) |
467 { | 467 { |
468 if (!inActiveDocumentContext()) | 468 if (!inActiveDocumentContext()) |
469 return false; | 469 return false; |
470 | 470 |
471 Font font; | 471 Font font; |
472 if (!resolveFontStyle(fontString, font)) { | 472 if (!resolveFontStyle(fontString, font)) { |
473 exceptionState.throwDOMException(SyntaxError, "Could not resolve '" + fo
ntString + "' as a font."); | 473 exceptionState.throwDOMException(SyntaxError, "Could not resolve '" + fo
ntString + "' as a font."); |
474 return false; | 474 return false; |
475 } | 475 } |
476 | 476 |
477 CSSFontSelector* fontSelector = document()->styleEngine()->fontSelector(); | 477 CSSFontSelector* fontSelector = document()->styleEngine().fontSelector(); |
478 FontFaceCache* fontFaceCache = fontSelector->fontFaceCache(); | 478 FontFaceCache* fontFaceCache = fontSelector->fontFaceCache(); |
479 | 479 |
480 bool hasLoadedFaces = false; | 480 bool hasLoadedFaces = false; |
481 for (const FontFamily* f = &font.fontDescription().family(); f; f = f->next(
)) { | 481 for (const FontFamily* f = &font.fontDescription().family(); f; f = f->next(
)) { |
482 CSSSegmentedFontFace* face = fontFaceCache->get(font.fontDescription(),
f->family()); | 482 CSSSegmentedFontFace* face = fontFaceCache->get(font.fontDescription(),
f->family()); |
483 if (face) { | 483 if (face) { |
484 if (!face->checkFont(text)) | 484 if (!face->checkFont(text)) |
485 return false; | 485 return false; |
486 hasLoadedFaces = true; | 486 hasLoadedFaces = true; |
487 } | 487 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 CSSPropertyValue(CSSPropertyFontStyle, *parsedStyle), | 531 CSSPropertyValue(CSSPropertyFontStyle, *parsedStyle), |
532 CSSPropertyValue(CSSPropertyFontVariant, *parsedStyle), | 532 CSSPropertyValue(CSSPropertyFontVariant, *parsedStyle), |
533 CSSPropertyValue(CSSPropertyFontWeight, *parsedStyle), | 533 CSSPropertyValue(CSSPropertyFontWeight, *parsedStyle), |
534 CSSPropertyValue(CSSPropertyFontSize, *parsedStyle), | 534 CSSPropertyValue(CSSPropertyFontSize, *parsedStyle), |
535 CSSPropertyValue(CSSPropertyLineHeight, *parsedStyle), | 535 CSSPropertyValue(CSSPropertyLineHeight, *parsedStyle), |
536 }; | 536 }; |
537 StyleResolver& styleResolver = document()->ensureStyleResolver(); | 537 StyleResolver& styleResolver = document()->ensureStyleResolver(); |
538 styleResolver.applyPropertiesToStyle(properties, WTF_ARRAY_LENGTH(properties
), style.get()); | 538 styleResolver.applyPropertiesToStyle(properties, WTF_ARRAY_LENGTH(properties
), style.get()); |
539 | 539 |
540 font = style->font(); | 540 font = style->font(); |
541 font.update(document()->styleEngine()->fontSelector()); | 541 font.update(document()->styleEngine().fontSelector()); |
542 return true; | 542 return true; |
543 } | 543 } |
544 | 544 |
545 void FontFaceSet::FontLoadHistogram::updateStatus(FontFace* fontFace) | 545 void FontFaceSet::FontLoadHistogram::updateStatus(FontFace* fontFace) |
546 { | 546 { |
547 if (m_status == Reported) | 547 if (m_status == Reported) |
548 return; | 548 return; |
549 if (fontFace->hadBlankText()) | 549 if (fontFace->hadBlankText()) |
550 m_status = HadBlankText; | 550 m_status = HadBlankText; |
551 else if (m_status == NoWebFonts) | 551 else if (m_status == NoWebFonts) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 visitor->trace(m_loadedFonts); | 594 visitor->trace(m_loadedFonts); |
595 visitor->trace(m_failedFonts); | 595 visitor->trace(m_failedFonts); |
596 visitor->trace(m_nonCSSConnectedFaces); | 596 visitor->trace(m_nonCSSConnectedFaces); |
597 DocumentSupplement::trace(visitor); | 597 DocumentSupplement::trace(visitor); |
598 #endif | 598 #endif |
599 EventTargetWithInlineData::trace(visitor); | 599 EventTargetWithInlineData::trace(visitor); |
600 ActiveDOMObject::trace(visitor); | 600 ActiveDOMObject::trace(visitor); |
601 } | 601 } |
602 | 602 |
603 } // namespace blink | 603 } // namespace blink |
OLD | NEW |