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

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

Issue 2040853002: Changed CSSParser::parseFontFaceDescriptor to return a const CSSValue* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@_fix_copy_locs
Patch Set: Rebase Created 4 years, 6 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 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 #include "core/dom/StyleEngine.h" 56 #include "core/dom/StyleEngine.h"
57 #include "core/frame/LocalFrame.h" 57 #include "core/frame/LocalFrame.h"
58 #include "core/frame/Settings.h" 58 #include "core/frame/Settings.h"
59 #include "core/frame/UseCounter.h" 59 #include "core/frame/UseCounter.h"
60 #include "platform/FontFamilyNames.h" 60 #include "platform/FontFamilyNames.h"
61 #include "platform/Histogram.h" 61 #include "platform/Histogram.h"
62 #include "platform/SharedBuffer.h" 62 #include "platform/SharedBuffer.h"
63 63
64 namespace blink { 64 namespace blink {
65 65
66 static CSSValue* parseCSSValue(const Document* document, const String& value, CS SPropertyID propertyID) 66 static const CSSValue* parseCSSValue(const Document* document, const String& val ue, CSSPropertyID propertyID)
67 { 67 {
68 CSSParserContext context(*document, UseCounter::getFrom(document)); 68 CSSParserContext context(*document, UseCounter::getFrom(document));
69 return CSSParser::parseFontFaceDescriptor(propertyID, value, context); 69 return CSSParser::parseFontFaceDescriptor(propertyID, value, context);
70 } 70 }
71 71
72 FontFace* FontFace::create(ExecutionContext* context, const AtomicString& family , StringOrArrayBufferOrArrayBufferView& source, const FontFaceDescriptors& descr iptors) 72 FontFace* FontFace::create(ExecutionContext* context, const AtomicString& family , StringOrArrayBufferOrArrayBufferView& source, const FontFaceDescriptors& descr iptors)
73 { 73 {
74 if (source.isString()) 74 if (source.isString())
75 return create(context, family, source.getAsString(), descriptors); 75 return create(context, family, source.getAsString(), descriptors);
76 if (source.isArrayBuffer()) 76 if (source.isArrayBuffer())
77 return create(context, family, source.getAsArrayBuffer(), descriptors); 77 return create(context, family, source.getAsArrayBuffer(), descriptors);
78 if (source.isArrayBufferView()) 78 if (source.isArrayBufferView())
79 return create(context, family, source.getAsArrayBufferView(), descriptor s); 79 return create(context, family, source.getAsArrayBufferView(), descriptor s);
80 ASSERT_NOT_REACHED(); 80 ASSERT_NOT_REACHED();
81 return nullptr; 81 return nullptr;
82 } 82 }
83 83
84 FontFace* FontFace::create(ExecutionContext* context, const AtomicString& family , const String& source, const FontFaceDescriptors& descriptors) 84 FontFace* FontFace::create(ExecutionContext* context, const AtomicString& family , const String& source, const FontFaceDescriptors& descriptors)
85 { 85 {
86 FontFace* fontFace = new FontFace(context, family, descriptors); 86 FontFace* fontFace = new FontFace(context, family, descriptors);
87 87
88 CSSValue* src = parseCSSValue(toDocument(context), source, CSSPropertySrc); 88 const CSSValue* src = parseCSSValue(toDocument(context), source, CSSProperty Src);
89 if (!src || !src->isValueList()) 89 if (!src || !src->isValueList())
90 fontFace->setError(DOMException::create(SyntaxError, "The source provide d ('" + source + "') could not be parsed as a value list.")); 90 fontFace->setError(DOMException::create(SyntaxError, "The source provide d ('" + source + "') could not be parsed as a value list."));
91 91
92 fontFace->initCSSFontFace(toDocument(context), src); 92 fontFace->initCSSFontFace(toDocument(context), src);
93 return fontFace; 93 return fontFace;
94 } 94 }
95 95
96 FontFace* FontFace::create(ExecutionContext* context, const AtomicString& family , DOMArrayBuffer* source, const FontFaceDescriptors& descriptors) 96 FontFace* FontFace::create(ExecutionContext* context, const AtomicString& family , DOMArrayBuffer* source, const FontFaceDescriptors& descriptors)
97 { 97 {
98 FontFace* fontFace = new FontFace(context, family, descriptors); 98 FontFace* fontFace = new FontFace(context, family, descriptors);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 setPropertyFromString(toDocument(context), s, CSSPropertyFontVariant, &excep tionState); 221 setPropertyFromString(toDocument(context), s, CSSPropertyFontVariant, &excep tionState);
222 } 222 }
223 223
224 void FontFace::setFeatureSettings(ExecutionContext* context, const String& s, Ex ceptionState& exceptionState) 224 void FontFace::setFeatureSettings(ExecutionContext* context, const String& s, Ex ceptionState& exceptionState)
225 { 225 {
226 setPropertyFromString(toDocument(context), s, CSSPropertyFontFeatureSettings , &exceptionState); 226 setPropertyFromString(toDocument(context), s, CSSPropertyFontFeatureSettings , &exceptionState);
227 } 227 }
228 228
229 void FontFace::setPropertyFromString(const Document* document, const String& s, CSSPropertyID propertyID, ExceptionState* exceptionState) 229 void FontFace::setPropertyFromString(const Document* document, const String& s, CSSPropertyID propertyID, ExceptionState* exceptionState)
230 { 230 {
231 CSSValue* value = parseCSSValue(document, s, propertyID); 231 const CSSValue* value = parseCSSValue(document, s, propertyID);
232 if (value && setPropertyValue(value, propertyID)) 232 if (value && setPropertyValue(value, propertyID))
233 return; 233 return;
234 234
235 String message = "Failed to set '" + s + "' as a property value."; 235 String message = "Failed to set '" + s + "' as a property value.";
236 if (exceptionState) 236 if (exceptionState)
237 exceptionState->throwDOMException(SyntaxError, message); 237 exceptionState->throwDOMException(SyntaxError, message);
238 else 238 else
239 setError(DOMException::create(SyntaxError, message)); 239 setError(DOMException::create(SyntaxError, message));
240 } 240 }
241 241
242 bool FontFace::setPropertyFromStyle(const StylePropertySet& properties, CSSPrope rtyID propertyID) 242 bool FontFace::setPropertyFromStyle(const StylePropertySet& properties, CSSPrope rtyID propertyID)
243 { 243 {
244 return setPropertyValue(properties.getPropertyCSSValue(propertyID), property ID); 244 return setPropertyValue(properties.getPropertyCSSValue(propertyID), property ID);
245 } 245 }
246 246
247 bool FontFace::setPropertyValue(CSSValue* value, CSSPropertyID propertyID) 247 bool FontFace::setPropertyValue(const CSSValue* value, CSSPropertyID propertyID)
248 { 248 {
249 switch (propertyID) { 249 switch (propertyID) {
250 case CSSPropertyFontStyle: 250 case CSSPropertyFontStyle:
251 m_style = value; 251 m_style = value;
252 break; 252 break;
253 case CSSPropertyFontWeight: 253 case CSSPropertyFontWeight:
254 m_weight = value; 254 m_weight = value;
255 break; 255 break;
256 case CSSPropertyFontStretch: 256 case CSSPropertyFontStretch:
257 m_stretch = value; 257 m_stretch = value;
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 return FontTraits(style, weight, stretch); 503 return FontTraits(style, weight, stretch);
504 } 504 }
505 505
506 size_t FontFace::approximateBlankCharacterCount() const 506 size_t FontFace::approximateBlankCharacterCount() const
507 { 507 {
508 if (m_status == Loading) 508 if (m_status == Loading)
509 return m_cssFontFace->approximateBlankCharacterCount(); 509 return m_cssFontFace->approximateBlankCharacterCount();
510 return 0; 510 return 0;
511 } 511 }
512 512
513 static FontDisplay CSSValueToFontDisplay(CSSValue* value) 513 static FontDisplay CSSValueToFontDisplay(const CSSValue* value)
514 { 514 {
515 if (value && value->isPrimitiveValue()) { 515 if (value && value->isPrimitiveValue()) {
516 switch (toCSSPrimitiveValue(value)->getValueID()) { 516 switch (toCSSPrimitiveValue(value)->getValueID()) {
517 case CSSValueAuto: 517 case CSSValueAuto:
518 return FontDisplayAuto; 518 return FontDisplayAuto;
519 case CSSValueBlock: 519 case CSSValueBlock:
520 return FontDisplayBlock; 520 return FontDisplayBlock;
521 case CSSValueSwap: 521 case CSSValueSwap:
522 return FontDisplaySwap; 522 return FontDisplaySwap;
523 case CSSValueFallback: 523 case CSSValueFallback:
524 return FontDisplayFallback; 524 return FontDisplayFallback;
525 case CSSValueOptional: 525 case CSSValueOptional:
526 return FontDisplayOptional; 526 return FontDisplayOptional;
527 default: 527 default:
528 break; 528 break;
529 } 529 }
530 } 530 }
531 return FontDisplayAuto; 531 return FontDisplayAuto;
532 } 532 }
533 533
534 static CSSFontFace* createCSSFontFace(FontFace* fontFace, CSSValue* unicodeRange ) 534 static CSSFontFace* createCSSFontFace(FontFace* fontFace, const CSSValue* unicod eRange)
535 { 535 {
536 Vector<UnicodeRange> ranges; 536 Vector<UnicodeRange> ranges;
537 if (CSSValueList* rangeList = toCSSValueList(unicodeRange)) { 537 if (const CSSValueList* rangeList = toCSSValueList(unicodeRange)) {
538 unsigned numRanges = rangeList->length(); 538 unsigned numRanges = rangeList->length();
539 for (unsigned i = 0; i < numRanges; i++) { 539 for (unsigned i = 0; i < numRanges; i++) {
540 const CSSUnicodeRangeValue& range = toCSSUnicodeRangeValue(rangeList ->item(i)); 540 const CSSUnicodeRangeValue& range = toCSSUnicodeRangeValue(rangeList ->item(i));
541 ranges.append(UnicodeRange(range.from(), range.to())); 541 ranges.append(UnicodeRange(range.from(), range.to()));
542 } 542 }
543 } 543 }
544 544
545 return new CSSFontFace(fontFace, ranges); 545 return new CSSFontFace(fontFace, ranges);
546 } 546 }
547 547
548 void FontFace::initCSSFontFace(Document* document, CSSValue* src) 548 void FontFace::initCSSFontFace(Document* document, const CSSValue* src)
549 { 549 {
550 m_cssFontFace = createCSSFontFace(this, m_unicodeRange.get()); 550 m_cssFontFace = createCSSFontFace(this, m_unicodeRange.get());
551 if (m_error) 551 if (m_error)
552 return; 552 return;
553 553
554 // Each item in the src property's list is a single CSSFontFaceSource. Put t hem all into a CSSFontFace. 554 // Each item in the src property's list is a single CSSFontFaceSource. Put t hem all into a CSSFontFace.
555 ASSERT(src); 555 ASSERT(src);
556 ASSERT(src->isValueList()); 556 ASSERT(src->isValueList());
557 CSSValueList* srcList = toCSSValueList(src); 557 const CSSValueList* srcList = toCSSValueList(src);
558 int srcLength = srcList->length(); 558 int srcLength = srcList->length();
559 559
560 for (int i = 0; i < srcLength; i++) { 560 for (int i = 0; i < srcLength; i++) {
561 // An item in the list either specifies a string (local font name) or a URL (remote font to download). 561 // An item in the list either specifies a string (local font name) or a URL (remote font to download).
562 const CSSFontFaceSrcValue& item = toCSSFontFaceSrcValue(srcList->item(i) ); 562 const CSSFontFaceSrcValue& item = toCSSFontFaceSrcValue(srcList->item(i) );
563 CSSFontFaceSource* source = nullptr; 563 CSSFontFaceSource* source = nullptr;
564 564
565 if (!item.isLocal()) { 565 if (!item.isLocal()) {
566 const Settings* settings = document ? document->settings() : nullptr ; 566 const Settings* settings = document ? document->settings() : nullptr ;
567 bool allowDownloading = settings && settings->downloadableBinaryFont sEnabled(); 567 bool allowDownloading = settings && settings->downloadableBinaryFont sEnabled();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 { 621 {
622 return m_cssFontFace->hadBlankText(); 622 return m_cssFontFace->hadBlankText();
623 } 623 }
624 624
625 bool FontFace::hasPendingActivity() const 625 bool FontFace::hasPendingActivity() const
626 { 626 {
627 return m_status == Loading && getExecutionContext() && !getExecutionContext( )->activeDOMObjectsAreStopped(); 627 return m_status == Loading && getExecutionContext() && !getExecutionContext( )->activeDOMObjectsAreStopped();
628 } 628 }
629 629
630 } // namespace blink 630 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/FontFace.h ('k') | third_party/WebKit/Source/core/css/parser/CSSParser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698