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

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

Issue 2346193002: Split CSSPrimitiveValue into CSSPrimitiveValue and CSSIdentifierValue (Closed)
Patch Set: Replaced ASSERTs with DCHECKS in presubmit warnings Created 4 years, 3 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 21 matching lines...) Expand all
32 32
33 #include "bindings/core/v8/ExceptionState.h" 33 #include "bindings/core/v8/ExceptionState.h"
34 #include "bindings/core/v8/ScriptState.h" 34 #include "bindings/core/v8/ScriptState.h"
35 #include "bindings/core/v8/StringOrArrayBufferOrArrayBufferView.h" 35 #include "bindings/core/v8/StringOrArrayBufferOrArrayBufferView.h"
36 #include "core/CSSValueKeywords.h" 36 #include "core/CSSValueKeywords.h"
37 #include "core/css/BinaryDataFontFaceSource.h" 37 #include "core/css/BinaryDataFontFaceSource.h"
38 #include "core/css/CSSFontFace.h" 38 #include "core/css/CSSFontFace.h"
39 #include "core/css/CSSFontFaceSrcValue.h" 39 #include "core/css/CSSFontFaceSrcValue.h"
40 #include "core/css/CSSFontFamilyValue.h" 40 #include "core/css/CSSFontFamilyValue.h"
41 #include "core/css/CSSFontSelector.h" 41 #include "core/css/CSSFontSelector.h"
42 #include "core/css/CSSPrimitiveValue.h" 42 #include "core/css/CSSIdentifierValue.h"
43 #include "core/css/CSSUnicodeRangeValue.h" 43 #include "core/css/CSSUnicodeRangeValue.h"
44 #include "core/css/CSSValueList.h" 44 #include "core/css/CSSValueList.h"
45 #include "core/css/FontFaceDescriptors.h" 45 #include "core/css/FontFaceDescriptors.h"
46 #include "core/css/LocalFontFaceSource.h" 46 #include "core/css/LocalFontFaceSource.h"
47 #include "core/css/RemoteFontFaceSource.h" 47 #include "core/css/RemoteFontFaceSource.h"
48 #include "core/css/StylePropertySet.h" 48 #include "core/css/StylePropertySet.h"
49 #include "core/css/StyleRule.h" 49 #include "core/css/StyleRule.h"
50 #include "core/css/parser/CSSParser.h" 50 #include "core/css/parser/CSSParser.h"
51 #include "core/dom/DOMArrayBuffer.h" 51 #include "core/dom/DOMArrayBuffer.h"
52 #include "core/dom/DOMArrayBufferView.h" 52 #include "core/dom/DOMArrayBufferView.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 fontFace->initCSSFontFace(static_cast<const unsigned char*>(source->baseAddr ess()), source->byteLength()); 106 fontFace->initCSSFontFace(static_cast<const unsigned char*>(source->baseAddr ess()), source->byteLength());
107 return fontFace; 107 return fontFace;
108 } 108 }
109 109
110 FontFace* FontFace::create(Document* document, const StyleRuleFontFace* fontFace Rule) 110 FontFace* FontFace::create(Document* document, const StyleRuleFontFace* fontFace Rule)
111 { 111 {
112 const StylePropertySet& properties = fontFaceRule->properties(); 112 const StylePropertySet& properties = fontFaceRule->properties();
113 113
114 // Obtain the font-family property and the src property. Both must be define d. 114 // Obtain the font-family property and the src property. Both must be define d.
115 const CSSValue* family = properties.getPropertyCSSValue(CSSPropertyFontFamil y); 115 const CSSValue* family = properties.getPropertyCSSValue(CSSPropertyFontFamil y);
116 if (!family || (!family->isFontFamilyValue() && !family->isPrimitiveValue()) ) 116 if (!family || (!family->isFontFamilyValue() && !family->isIdentifierValue() ))
117 return nullptr; 117 return nullptr;
118 const CSSValue* src = properties.getPropertyCSSValue(CSSPropertySrc); 118 const CSSValue* src = properties.getPropertyCSSValue(CSSPropertySrc);
119 if (!src || !src->isValueList()) 119 if (!src || !src->isValueList())
120 return nullptr; 120 return nullptr;
121 121
122 FontFace* fontFace = new FontFace(document); 122 FontFace* fontFace = new FontFace(document);
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)
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 return false; 275 return false;
276 } 276 }
277 return true; 277 return true;
278 } 278 }
279 279
280 bool FontFace::setFamilyValue(const CSSValue& familyValue) 280 bool FontFace::setFamilyValue(const CSSValue& familyValue)
281 { 281 {
282 AtomicString family; 282 AtomicString family;
283 if (familyValue.isFontFamilyValue()) { 283 if (familyValue.isFontFamilyValue()) {
284 family = AtomicString(toCSSFontFamilyValue(familyValue).value()); 284 family = AtomicString(toCSSFontFamilyValue(familyValue).value());
285 } else if (toCSSPrimitiveValue(familyValue).isValueID()) { 285 } else if (familyValue.isIdentifierValue()) {
286 // We need to use the raw text for all the generic family types, since @ font-face is a way of actually 286 // We need to use the raw text for all the generic family types, since @ font-face is a way of actually
287 // defining what font to use for those types. 287 // defining what font to use for those types.
288 switch (toCSSPrimitiveValue(familyValue).getValueID()) { 288 switch (toCSSIdentifierValue(familyValue).getValueID()) {
289 case CSSValueSerif: 289 case CSSValueSerif:
290 family = FontFamilyNames::webkit_serif; 290 family = FontFamilyNames::webkit_serif;
291 break; 291 break;
292 case CSSValueSansSerif: 292 case CSSValueSansSerif:
293 family = FontFamilyNames::webkit_sans_serif; 293 family = FontFamilyNames::webkit_sans_serif;
294 break; 294 break;
295 case CSSValueCursive: 295 case CSSValueCursive:
296 family = FontFamilyNames::webkit_cursive; 296 family = FontFamilyNames::webkit_cursive;
297 break; 297 break;
298 case CSSValueFantasy: 298 case CSSValueFantasy:
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 if (m_status != Unloaded) 394 if (m_status != Unloaded)
395 return; 395 return;
396 396
397 m_cssFontFace->load(); 397 m_cssFontFace->load();
398 } 398 }
399 399
400 FontTraits FontFace::traits() const 400 FontTraits FontFace::traits() const
401 { 401 {
402 FontStretch stretch = FontStretchNormal; 402 FontStretch stretch = FontStretchNormal;
403 if (m_stretch) { 403 if (m_stretch) {
404 if (!m_stretch->isPrimitiveValue()) 404 if (!m_stretch->isIdentifierValue())
405 return 0; 405 return 0;
406 406
407 switch (toCSSPrimitiveValue(m_stretch.get())->getValueID()) { 407 switch (toCSSIdentifierValue(m_stretch.get())->getValueID()) {
408 case CSSValueUltraCondensed: 408 case CSSValueUltraCondensed:
409 stretch = FontStretchUltraCondensed; 409 stretch = FontStretchUltraCondensed;
410 break; 410 break;
411 case CSSValueExtraCondensed: 411 case CSSValueExtraCondensed:
412 stretch = FontStretchExtraCondensed; 412 stretch = FontStretchExtraCondensed;
413 break; 413 break;
414 case CSSValueCondensed: 414 case CSSValueCondensed:
415 stretch = FontStretchCondensed; 415 stretch = FontStretchCondensed;
416 break; 416 break;
417 case CSSValueSemiCondensed: 417 case CSSValueSemiCondensed:
(...skipping 11 matching lines...) Expand all
429 case CSSValueUltraExpanded: 429 case CSSValueUltraExpanded:
430 stretch = FontStretchUltraExpanded; 430 stretch = FontStretchUltraExpanded;
431 break; 431 break;
432 default: 432 default:
433 break; 433 break;
434 } 434 }
435 } 435 }
436 436
437 FontStyle style = FontStyleNormal; 437 FontStyle style = FontStyleNormal;
438 if (m_style) { 438 if (m_style) {
439 if (!m_style->isPrimitiveValue()) 439 if (!m_style->isIdentifierValue())
440 return 0; 440 return 0;
441 441
442 switch (toCSSPrimitiveValue(m_style.get())->getValueID()) { 442 switch (toCSSIdentifierValue(m_style.get())->getValueID()) {
443 case CSSValueNormal: 443 case CSSValueNormal:
444 style = FontStyleNormal; 444 style = FontStyleNormal;
445 break; 445 break;
446 case CSSValueOblique: 446 case CSSValueOblique:
447 style = FontStyleOblique; 447 style = FontStyleOblique;
448 break; 448 break;
449 case CSSValueItalic: 449 case CSSValueItalic:
450 style = FontStyleItalic; 450 style = FontStyleItalic;
451 break; 451 break;
452 default: 452 default:
453 break; 453 break;
454 } 454 }
455 } 455 }
456 456
457 FontWeight weight = FontWeight400; 457 FontWeight weight = FontWeight400;
458 if (m_weight) { 458 if (m_weight) {
459 if (!m_weight->isPrimitiveValue()) 459 if (!m_weight->isIdentifierValue())
460 return 0; 460 return 0;
461 461
462 switch (toCSSPrimitiveValue(m_weight.get())->getValueID()) { 462 switch (toCSSIdentifierValue(m_weight.get())->getValueID()) {
463 case CSSValueBold: 463 case CSSValueBold:
464 case CSSValue700: 464 case CSSValue700:
465 weight = FontWeight700; 465 weight = FontWeight700;
466 break; 466 break;
467 case CSSValueNormal: 467 case CSSValueNormal:
468 case CSSValue400: 468 case CSSValue400:
469 weight = FontWeight400; 469 weight = FontWeight400;
470 break; 470 break;
471 case CSSValue900: 471 case CSSValue900:
472 weight = FontWeight900; 472 weight = FontWeight900;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(const CSSValue* value) 513 static FontDisplay CSSValueToFontDisplay(const CSSValue* value)
514 { 514 {
515 if (value && value->isPrimitiveValue()) { 515 if (value && value->isIdentifierValue()) {
516 switch (toCSSPrimitiveValue(value)->getValueID()) { 516 switch (toCSSIdentifierValue(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;
(...skipping 94 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

Powered by Google App Engine
This is Rietveld 408576698