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

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

Issue 1429713004: Implement CSS font-display (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: failure does not mean loaded Created 5 years, 1 month 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 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 121
122 RefPtrWillBeRawPtr<FontFace> fontFace = adoptRefWillBeNoop(new FontFace(docu ment)); 122 RefPtrWillBeRawPtr<FontFace> fontFace = adoptRefWillBeNoop(new FontFace(docu ment));
123 123
124 if (fontFace->setFamilyValue(*family) 124 if (fontFace->setFamilyValue(*family)
125 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontStyle) 125 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontStyle)
126 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontWeight) 126 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontWeight)
127 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontStretch) 127 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontStretch)
128 && fontFace->setPropertyFromStyle(properties, CSSPropertyUnicodeRange) 128 && fontFace->setPropertyFromStyle(properties, CSSPropertyUnicodeRange)
129 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontVariant) 129 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontVariant)
130 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontFeatureSett ings) 130 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontFeatureSett ings)
131 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontDisplay)
131 && !fontFace->family().isEmpty() 132 && !fontFace->family().isEmpty()
132 && fontFace->traits().bitfield()) { 133 && fontFace->traits().bitfield()) {
133 fontFace->initCSSFontFace(document, src); 134 fontFace->initCSSFontFace(document, src);
134 return fontFace.release(); 135 return fontFace.release();
135 } 136 }
136 return nullptr; 137 return nullptr;
137 } 138 }
138 139
139 FontFace::FontFace(ExecutionContext* context) 140 FontFace::FontFace(ExecutionContext* context)
140 : ActiveDOMObject(context) 141 : ActiveDOMObject(context)
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 if (value && !value->isValueList()) 258 if (value && !value->isValueList())
258 return false; 259 return false;
259 m_unicodeRange = value; 260 m_unicodeRange = value;
260 break; 261 break;
261 case CSSPropertyFontVariant: 262 case CSSPropertyFontVariant:
262 m_variant = value; 263 m_variant = value;
263 break; 264 break;
264 case CSSPropertyFontFeatureSettings: 265 case CSSPropertyFontFeatureSettings:
265 m_featureSettings = value; 266 m_featureSettings = value;
266 break; 267 break;
268 case CSSPropertyFontDisplay:
269 m_display = value;
270 break;
267 default: 271 default:
268 ASSERT_NOT_REACHED(); 272 ASSERT_NOT_REACHED();
269 return false; 273 return false;
270 } 274 }
271 return true; 275 return true;
272 } 276 }
273 277
274 bool FontFace::setFamilyValue(const CSSValue& familyValue) 278 bool FontFace::setFamilyValue(const CSSValue& familyValue)
275 { 279 {
276 AtomicString family; 280 AtomicString family;
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 break; 525 break;
522 default: 526 default:
523 break; 527 break;
524 } 528 }
525 } 529 }
526 } 530 }
527 531
528 return FontTraits(style, variant, weight, stretch); 532 return FontTraits(style, variant, weight, stretch);
529 } 533 }
530 534
535 static FontDisplay CSSValueToFontDisplay(CSSValue* value)
536 {
537 if (value && value->isPrimitiveValue()) {
538 switch (toCSSPrimitiveValue(value)->getValueID()) {
539 case CSSValueAuto:
540 return FontDisplayAuto;
541 case CSSValueBlock:
542 return FontDisplayBlock;
543 case CSSValueSwap:
544 return FontDisplaySwap;
545 case CSSValueFallback:
546 return FontDisplayFallback;
547 case CSSValueOptional:
548 return FontDisplayOptional;
549 default:
550 break;
551 }
552 }
553 return FontDisplayAuto;
554 }
555
531 static PassOwnPtrWillBeRawPtr<CSSFontFace> createCSSFontFace(FontFace* fontFace, CSSValue* unicodeRange) 556 static PassOwnPtrWillBeRawPtr<CSSFontFace> createCSSFontFace(FontFace* fontFace, CSSValue* unicodeRange)
532 { 557 {
533 Vector<CSSFontFace::UnicodeRange> ranges; 558 Vector<CSSFontFace::UnicodeRange> ranges;
534 if (CSSValueList* rangeList = toCSSValueList(unicodeRange)) { 559 if (CSSValueList* rangeList = toCSSValueList(unicodeRange)) {
535 unsigned numRanges = rangeList->length(); 560 unsigned numRanges = rangeList->length();
536 for (unsigned i = 0; i < numRanges; i++) { 561 for (unsigned i = 0; i < numRanges; i++) {
537 CSSUnicodeRangeValue* range = toCSSUnicodeRangeValue(rangeList->item (i)); 562 CSSUnicodeRangeValue* range = toCSSUnicodeRangeValue(rangeList->item (i));
538 ranges.append(CSSFontFace::UnicodeRange(range->from(), range->to())) ; 563 ranges.append(CSSFontFace::UnicodeRange(range->from(), range->to())) ;
539 } 564 }
540 } 565 }
(...skipping 18 matching lines...) Expand all
559 CSSFontFaceSrcValue* item = toCSSFontFaceSrcValue(srcList->item(i)); 584 CSSFontFaceSrcValue* item = toCSSFontFaceSrcValue(srcList->item(i));
560 OwnPtrWillBeRawPtr<CSSFontFaceSource> source = nullptr; 585 OwnPtrWillBeRawPtr<CSSFontFaceSource> source = nullptr;
561 586
562 if (!item->isLocal()) { 587 if (!item->isLocal()) {
563 const Settings* settings = document ? document->settings() : nullptr ; 588 const Settings* settings = document ? document->settings() : nullptr ;
564 bool allowDownloading = settings && settings->downloadableBinaryFont sEnabled(); 589 bool allowDownloading = settings && settings->downloadableBinaryFont sEnabled();
565 if (allowDownloading && item->isSupportedFormat() && document) { 590 if (allowDownloading && item->isSupportedFormat() && document) {
566 FontResource* fetched = item->fetch(document); 591 FontResource* fetched = item->fetch(document);
567 if (fetched) { 592 if (fetched) {
568 FontLoader* fontLoader = document->styleEngine().fontSelecto r()->fontLoader(); 593 FontLoader* fontLoader = document->styleEngine().fontSelecto r()->fontLoader();
569 source = adoptPtrWillBeNoop(new RemoteFontFaceSource(fetched , fontLoader)); 594 source = adoptPtrWillBeNoop(new RemoteFontFaceSource(fetched , fontLoader, CSSValueToFontDisplay(m_display.get())));
570 } 595 }
571 } 596 }
572 } else { 597 } else {
573 source = adoptPtrWillBeNoop(new LocalFontFaceSource(item->resource() )); 598 source = adoptPtrWillBeNoop(new LocalFontFaceSource(item->resource() ));
574 } 599 }
575 600
576 if (source) 601 if (source)
577 m_cssFontFace->addSource(source.release()); 602 m_cssFontFace->addSource(source.release());
578 } 603 }
579 } 604 }
(...skipping 14 matching lines...) Expand all
594 } 619 }
595 620
596 DEFINE_TRACE(FontFace) 621 DEFINE_TRACE(FontFace)
597 { 622 {
598 visitor->trace(m_style); 623 visitor->trace(m_style);
599 visitor->trace(m_weight); 624 visitor->trace(m_weight);
600 visitor->trace(m_stretch); 625 visitor->trace(m_stretch);
601 visitor->trace(m_unicodeRange); 626 visitor->trace(m_unicodeRange);
602 visitor->trace(m_variant); 627 visitor->trace(m_variant);
603 visitor->trace(m_featureSettings); 628 visitor->trace(m_featureSettings);
629 visitor->trace(m_display);
604 visitor->trace(m_error); 630 visitor->trace(m_error);
605 visitor->trace(m_loadedProperty); 631 visitor->trace(m_loadedProperty);
606 visitor->trace(m_cssFontFace); 632 visitor->trace(m_cssFontFace);
607 visitor->trace(m_callbacks); 633 visitor->trace(m_callbacks);
608 ActiveDOMObject::trace(visitor); 634 ActiveDOMObject::trace(visitor);
609 } 635 }
610 636
611 bool FontFace::hadBlankText() const 637 bool FontFace::hadBlankText() const
612 { 638 {
613 return m_cssFontFace->hadBlankText(); 639 return m_cssFontFace->hadBlankText();
614 } 640 }
615 641
616 bool FontFace::hasPendingActivity() const 642 bool FontFace::hasPendingActivity() const
617 { 643 {
618 return m_status == Loading && executionContext() && !executionContext()->act iveDOMObjectsAreStopped(); 644 return m_status == Loading && executionContext() && !executionContext()->act iveDOMObjectsAreStopped();
619 } 645 }
620 646
621 } // namespace blink 647 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/FontFace.h ('k') | third_party/WebKit/Source/core/css/RemoteFontFaceSource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698