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 | 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 Loading... |
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 Loading... |
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 Loading... |
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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 if (m_status != Unloaded) | 399 if (m_status != Unloaded) |
400 return; | 400 return; |
401 | 401 |
402 m_cssFontFace->load(); | 402 m_cssFontFace->load(); |
403 } | 403 } |
404 | 404 |
405 FontTraits FontFace::traits() const | 405 FontTraits FontFace::traits() const |
406 { | 406 { |
407 FontStretch stretch = FontStretchNormal; | 407 FontStretch stretch = FontStretchNormal; |
408 if (m_stretch) { | 408 if (m_stretch) { |
409 if (!m_stretch->isPrimitiveValue()) | 409 if (!m_stretch->isIdentifierValue()) |
410 return 0; | 410 return 0; |
411 | 411 |
412 switch (toCSSPrimitiveValue(m_stretch.get())->getValueID()) { | 412 switch (toCSSIdentifierValue(m_stretch.get())->getValueID()) { |
413 case CSSValueUltraCondensed: | 413 case CSSValueUltraCondensed: |
414 stretch = FontStretchUltraCondensed; | 414 stretch = FontStretchUltraCondensed; |
415 break; | 415 break; |
416 case CSSValueExtraCondensed: | 416 case CSSValueExtraCondensed: |
417 stretch = FontStretchExtraCondensed; | 417 stretch = FontStretchExtraCondensed; |
418 break; | 418 break; |
419 case CSSValueCondensed: | 419 case CSSValueCondensed: |
420 stretch = FontStretchCondensed; | 420 stretch = FontStretchCondensed; |
421 break; | 421 break; |
422 case CSSValueSemiCondensed: | 422 case CSSValueSemiCondensed: |
(...skipping 11 matching lines...) Expand all Loading... |
434 case CSSValueUltraExpanded: | 434 case CSSValueUltraExpanded: |
435 stretch = FontStretchUltraExpanded; | 435 stretch = FontStretchUltraExpanded; |
436 break; | 436 break; |
437 default: | 437 default: |
438 break; | 438 break; |
439 } | 439 } |
440 } | 440 } |
441 | 441 |
442 FontStyle style = FontStyleNormal; | 442 FontStyle style = FontStyleNormal; |
443 if (m_style) { | 443 if (m_style) { |
444 if (!m_style->isPrimitiveValue()) | 444 if (!m_style->isIdentifierValue()) |
445 return 0; | 445 return 0; |
446 | 446 |
447 switch (toCSSPrimitiveValue(m_style.get())->getValueID()) { | 447 switch (toCSSIdentifierValue(m_style.get())->getValueID()) { |
448 case CSSValueNormal: | 448 case CSSValueNormal: |
449 style = FontStyleNormal; | 449 style = FontStyleNormal; |
450 break; | 450 break; |
451 case CSSValueOblique: | 451 case CSSValueOblique: |
452 style = FontStyleOblique; | 452 style = FontStyleOblique; |
453 break; | 453 break; |
454 case CSSValueItalic: | 454 case CSSValueItalic: |
455 style = FontStyleItalic; | 455 style = FontStyleItalic; |
456 break; | 456 break; |
457 default: | 457 default: |
458 break; | 458 break; |
459 } | 459 } |
460 } | 460 } |
461 | 461 |
462 FontWeight weight = FontWeight400; | 462 FontWeight weight = FontWeight400; |
463 if (m_weight) { | 463 if (m_weight) { |
464 if (!m_weight->isPrimitiveValue()) | 464 if (!m_weight->isIdentifierValue()) |
465 return 0; | 465 return 0; |
466 | 466 |
467 switch (toCSSPrimitiveValue(m_weight.get())->getValueID()) { | 467 switch (toCSSIdentifierValue(m_weight.get())->getValueID()) { |
468 case CSSValueBold: | 468 case CSSValueBold: |
469 case CSSValue700: | 469 case CSSValue700: |
470 weight = FontWeight700; | 470 weight = FontWeight700; |
471 break; | 471 break; |
472 case CSSValueNormal: | 472 case CSSValueNormal: |
473 case CSSValue400: | 473 case CSSValue400: |
474 weight = FontWeight400; | 474 weight = FontWeight400; |
475 break; | 475 break; |
476 case CSSValue900: | 476 case CSSValue900: |
477 weight = FontWeight900; | 477 weight = FontWeight900; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 | 510 |
511 size_t FontFace::approximateBlankCharacterCount() const | 511 size_t FontFace::approximateBlankCharacterCount() const |
512 { | 512 { |
513 if (m_status == Loading) | 513 if (m_status == Loading) |
514 return m_cssFontFace->approximateBlankCharacterCount(); | 514 return m_cssFontFace->approximateBlankCharacterCount(); |
515 return 0; | 515 return 0; |
516 } | 516 } |
517 | 517 |
518 static FontDisplay CSSValueToFontDisplay(const CSSValue* value) | 518 static FontDisplay CSSValueToFontDisplay(const CSSValue* value) |
519 { | 519 { |
520 if (value && value->isPrimitiveValue()) { | 520 if (value && value->isIdentifierValue()) { |
521 switch (toCSSPrimitiveValue(value)->getValueID()) { | 521 switch (toCSSIdentifierValue(value)->getValueID()) { |
522 case CSSValueAuto: | 522 case CSSValueAuto: |
523 return FontDisplayAuto; | 523 return FontDisplayAuto; |
524 case CSSValueBlock: | 524 case CSSValueBlock: |
525 return FontDisplayBlock; | 525 return FontDisplayBlock; |
526 case CSSValueSwap: | 526 case CSSValueSwap: |
527 return FontDisplaySwap; | 527 return FontDisplaySwap; |
528 case CSSValueFallback: | 528 case CSSValueFallback: |
529 return FontDisplayFallback; | 529 return FontDisplayFallback; |
530 case CSSValueOptional: | 530 case CSSValueOptional: |
531 return FontDisplayOptional; | 531 return FontDisplayOptional; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 { | 626 { |
627 return m_cssFontFace->hadBlankText(); | 627 return m_cssFontFace->hadBlankText(); |
628 } | 628 } |
629 | 629 |
630 bool FontFace::hasPendingActivity() const | 630 bool FontFace::hasPendingActivity() const |
631 { | 631 { |
632 return m_status == Loading && getExecutionContext() && !getExecutionContext(
)->activeDOMObjectsAreStopped(); | 632 return m_status == Loading && getExecutionContext() && !getExecutionContext(
)->activeDOMObjectsAreStopped(); |
633 } | 633 } |
634 | 634 |
635 } // namespace blink | 635 } // namespace blink |
OLD | NEW |