| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 #include "core/dom/ExceptionCode.h" | 55 #include "core/dom/ExceptionCode.h" |
| 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/SharedBuffer.h" | 61 #include "platform/SharedBuffer.h" |
| 62 | 62 |
| 63 namespace blink { | 63 namespace blink { |
| 64 | 64 |
| 65 static PassRefPtrWillBeRawPtr<CSSValue> parseCSSValue(const Document* document,
const String& value, CSSPropertyID propertyID) | 65 static PassRefPtr<CSSValue> parseCSSValue(const Document* document, const String
& value, CSSPropertyID propertyID) |
| 66 { | 66 { |
| 67 CSSParserContext context(*document, UseCounter::getFrom(document)); | 67 CSSParserContext context(*document, UseCounter::getFrom(document)); |
| 68 return CSSParser::parseFontFaceDescriptor(propertyID, value, context); | 68 return CSSParser::parseFontFaceDescriptor(propertyID, value, context); |
| 69 } | 69 } |
| 70 | 70 |
| 71 PassRefPtrWillBeRawPtr<FontFace> FontFace::create(ExecutionContext* context, con
st AtomicString& family, StringOrArrayBufferOrArrayBufferView& source, const Fon
tFaceDescriptors& descriptors) | 71 PassRefPtrWillBeRawPtr<FontFace> FontFace::create(ExecutionContext* context, con
st AtomicString& family, StringOrArrayBufferOrArrayBufferView& source, const Fon
tFaceDescriptors& descriptors) |
| 72 { | 72 { |
| 73 if (source.isString()) | 73 if (source.isString()) |
| 74 return create(context, family, source.getAsString(), descriptors); | 74 return create(context, family, source.getAsString(), descriptors); |
| 75 if (source.isArrayBuffer()) | 75 if (source.isArrayBuffer()) |
| 76 return create(context, family, source.getAsArrayBuffer(), descriptors); | 76 return create(context, family, source.getAsArrayBuffer(), descriptors); |
| 77 if (source.isArrayBufferView()) | 77 if (source.isArrayBufferView()) |
| 78 return create(context, family, source.getAsArrayBufferView(), descriptor
s); | 78 return create(context, family, source.getAsArrayBufferView(), descriptor
s); |
| 79 ASSERT_NOT_REACHED(); | 79 ASSERT_NOT_REACHED(); |
| 80 return nullptr; | 80 return nullptr; |
| 81 } | 81 } |
| 82 | 82 |
| 83 PassRefPtrWillBeRawPtr<FontFace> FontFace::create(ExecutionContext* context, con
st AtomicString& family, const String& source, const FontFaceDescriptors& descri
ptors) | 83 PassRefPtrWillBeRawPtr<FontFace> FontFace::create(ExecutionContext* context, con
st AtomicString& family, const String& source, const FontFaceDescriptors& descri
ptors) |
| 84 { | 84 { |
| 85 RefPtrWillBeRawPtr<FontFace> fontFace = adoptRefWillBeNoop(new FontFace(cont
ext, family, descriptors)); | 85 RefPtrWillBeRawPtr<FontFace> fontFace = adoptRefWillBeNoop(new FontFace(cont
ext, family, descriptors)); |
| 86 | 86 |
| 87 RefPtrWillBeRawPtr<CSSValue> src = parseCSSValue(toDocument(context), source
, CSSPropertySrc); | 87 RefPtr<CSSValue> src = parseCSSValue(toDocument(context), source, CSSPropert
ySrc); |
| 88 if (!src || !src->isValueList()) | 88 if (!src || !src->isValueList()) |
| 89 fontFace->setError(DOMException::create(SyntaxError, "The source provide
d ('" + source + "') could not be parsed as a value list.")); | 89 fontFace->setError(DOMException::create(SyntaxError, "The source provide
d ('" + source + "') could not be parsed as a value list.")); |
| 90 | 90 |
| 91 fontFace->initCSSFontFace(toDocument(context), src); | 91 fontFace->initCSSFontFace(toDocument(context), src); |
| 92 return fontFace.release(); | 92 return fontFace.release(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 PassRefPtrWillBeRawPtr<FontFace> FontFace::create(ExecutionContext* context, con
st AtomicString& family, PassRefPtr<DOMArrayBuffer> source, const FontFaceDescri
ptors& descriptors) | 95 PassRefPtrWillBeRawPtr<FontFace> FontFace::create(ExecutionContext* context, con
st AtomicString& family, PassRefPtr<DOMArrayBuffer> source, const FontFaceDescri
ptors& descriptors) |
| 96 { | 96 { |
| 97 RefPtrWillBeRawPtr<FontFace> fontFace = adoptRefWillBeNoop(new FontFace(cont
ext, family, descriptors)); | 97 RefPtrWillBeRawPtr<FontFace> fontFace = adoptRefWillBeNoop(new FontFace(cont
ext, family, descriptors)); |
| 98 fontFace->initCSSFontFace(static_cast<const unsigned char*>(source->data()),
source->byteLength()); | 98 fontFace->initCSSFontFace(static_cast<const unsigned char*>(source->data()),
source->byteLength()); |
| 99 return fontFace.release(); | 99 return fontFace.release(); |
| 100 } | 100 } |
| 101 | 101 |
| 102 PassRefPtrWillBeRawPtr<FontFace> FontFace::create(ExecutionContext* context, con
st AtomicString& family, PassRefPtr<DOMArrayBufferView> source, const FontFaceDe
scriptors& descriptors) | 102 PassRefPtrWillBeRawPtr<FontFace> FontFace::create(ExecutionContext* context, con
st AtomicString& family, PassRefPtr<DOMArrayBufferView> source, const FontFaceDe
scriptors& descriptors) |
| 103 { | 103 { |
| 104 RefPtrWillBeRawPtr<FontFace> fontFace = adoptRefWillBeNoop(new FontFace(cont
ext, family, descriptors)); | 104 RefPtrWillBeRawPtr<FontFace> fontFace = adoptRefWillBeNoop(new FontFace(cont
ext, family, descriptors)); |
| 105 fontFace->initCSSFontFace(static_cast<const unsigned char*>(source->baseAddr
ess()), source->byteLength()); | 105 fontFace->initCSSFontFace(static_cast<const unsigned char*>(source->baseAddr
ess()), source->byteLength()); |
| 106 return fontFace.release(); | 106 return fontFace.release(); |
| 107 } | 107 } |
| 108 | 108 |
| 109 PassRefPtrWillBeRawPtr<FontFace> FontFace::create(Document* document, const Styl
eRuleFontFace* fontFaceRule) | 109 PassRefPtrWillBeRawPtr<FontFace> FontFace::create(Document* document, const Styl
eRuleFontFace* fontFaceRule) |
| 110 { | 110 { |
| 111 const StylePropertySet& properties = fontFaceRule->properties(); | 111 const StylePropertySet& properties = fontFaceRule->properties(); |
| 112 | 112 |
| 113 // Obtain the font-family property and the src property. Both must be define
d. | 113 // Obtain the font-family property and the src property. Both must be define
d. |
| 114 RefPtrWillBeRawPtr<CSSValue> family = properties.getPropertyCSSValue(CSSProp
ertyFontFamily); | 114 RefPtr<CSSValue> family = properties.getPropertyCSSValue(CSSPropertyFontFami
ly); |
| 115 if (!family || !family->isValueList()) | 115 if (!family || !family->isValueList()) |
| 116 return nullptr; | 116 return nullptr; |
| 117 RefPtrWillBeRawPtr<CSSValue> src = properties.getPropertyCSSValue(CSSPropert
ySrc); | 117 RefPtr<CSSValue> src = properties.getPropertyCSSValue(CSSPropertySrc); |
| 118 if (!src || !src->isValueList()) | 118 if (!src || !src->isValueList()) |
| 119 return nullptr; | 119 return nullptr; |
| 120 | 120 |
| 121 RefPtrWillBeRawPtr<FontFace> fontFace = adoptRefWillBeNoop(new FontFace(docu
ment)); | 121 RefPtrWillBeRawPtr<FontFace> fontFace = adoptRefWillBeNoop(new FontFace(docu
ment)); |
| 122 | 122 |
| 123 if (fontFace->setFamilyValue(toCSSValueList(family.get())) | 123 if (fontFace->setFamilyValue(toCSSValueList(family.get())) |
| 124 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontStyle) | 124 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontStyle) |
| 125 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontWeight) | 125 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontWeight) |
| 126 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontStretch) | 126 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontStretch) |
| 127 && fontFace->setPropertyFromStyle(properties, CSSPropertyUnicodeRange) | 127 && fontFace->setPropertyFromStyle(properties, CSSPropertyUnicodeRange) |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 setPropertyFromString(toDocument(context), s, CSSPropertyFontVariant, &excep
tionState); | 217 setPropertyFromString(toDocument(context), s, CSSPropertyFontVariant, &excep
tionState); |
| 218 } | 218 } |
| 219 | 219 |
| 220 void FontFace::setFeatureSettings(ExecutionContext* context, const String& s, Ex
ceptionState& exceptionState) | 220 void FontFace::setFeatureSettings(ExecutionContext* context, const String& s, Ex
ceptionState& exceptionState) |
| 221 { | 221 { |
| 222 setPropertyFromString(toDocument(context), s, CSSPropertyWebkitFontFeatureSe
ttings, &exceptionState); | 222 setPropertyFromString(toDocument(context), s, CSSPropertyWebkitFontFeatureSe
ttings, &exceptionState); |
| 223 } | 223 } |
| 224 | 224 |
| 225 void FontFace::setPropertyFromString(const Document* document, const String& s,
CSSPropertyID propertyID, ExceptionState* exceptionState) | 225 void FontFace::setPropertyFromString(const Document* document, const String& s,
CSSPropertyID propertyID, ExceptionState* exceptionState) |
| 226 { | 226 { |
| 227 RefPtrWillBeRawPtr<CSSValue> value = parseCSSValue(document, s, propertyID); | 227 RefPtr<CSSValue> value = parseCSSValue(document, s, propertyID); |
| 228 if (value && setPropertyValue(value, propertyID)) | 228 if (value && setPropertyValue(value, propertyID)) |
| 229 return; | 229 return; |
| 230 | 230 |
| 231 String message = "Failed to set '" + s + "' as a property value."; | 231 String message = "Failed to set '" + s + "' as a property value."; |
| 232 if (exceptionState) | 232 if (exceptionState) |
| 233 exceptionState->throwDOMException(SyntaxError, message); | 233 exceptionState->throwDOMException(SyntaxError, message); |
| 234 else | 234 else |
| 235 setError(DOMException::create(SyntaxError, message)); | 235 setError(DOMException::create(SyntaxError, message)); |
| 236 } | 236 } |
| 237 | 237 |
| 238 bool FontFace::setPropertyFromStyle(const StylePropertySet& properties, CSSPrope
rtyID propertyID) | 238 bool FontFace::setPropertyFromStyle(const StylePropertySet& properties, CSSPrope
rtyID propertyID) |
| 239 { | 239 { |
| 240 return setPropertyValue(properties.getPropertyCSSValue(propertyID), property
ID); | 240 return setPropertyValue(properties.getPropertyCSSValue(propertyID), property
ID); |
| 241 } | 241 } |
| 242 | 242 |
| 243 bool FontFace::setPropertyValue(PassRefPtrWillBeRawPtr<CSSValue> value, CSSPrope
rtyID propertyID) | 243 bool FontFace::setPropertyValue(PassRefPtr<CSSValue> value, CSSPropertyID proper
tyID) |
| 244 { | 244 { |
| 245 switch (propertyID) { | 245 switch (propertyID) { |
| 246 case CSSPropertyFontStyle: | 246 case CSSPropertyFontStyle: |
| 247 m_style = value; | 247 m_style = value; |
| 248 break; | 248 break; |
| 249 case CSSPropertyFontWeight: | 249 case CSSPropertyFontWeight: |
| 250 m_weight = value; | 250 m_weight = value; |
| 251 break; | 251 break; |
| 252 case CSSPropertyFontStretch: | 252 case CSSPropertyFontStretch: |
| 253 m_stretch = value; | 253 m_stretch = value; |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 case CSSValueLighter: | 493 case CSSValueLighter: |
| 494 case CSSValueBolder: | 494 case CSSValueBolder: |
| 495 break; | 495 break; |
| 496 default: | 496 default: |
| 497 ASSERT_NOT_REACHED(); | 497 ASSERT_NOT_REACHED(); |
| 498 break; | 498 break; |
| 499 } | 499 } |
| 500 } | 500 } |
| 501 | 501 |
| 502 FontVariant variant = FontVariantNormal; | 502 FontVariant variant = FontVariantNormal; |
| 503 if (RefPtrWillBeRawPtr<CSSValue> fontVariant = m_variant) { | 503 if (RefPtr<CSSValue> fontVariant = m_variant) { |
| 504 // font-variant descriptor can be a value list. | 504 // font-variant descriptor can be a value list. |
| 505 if (fontVariant->isPrimitiveValue()) { | 505 if (fontVariant->isPrimitiveValue()) { |
| 506 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSep
arated(); | 506 RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); |
| 507 list->append(fontVariant); | 507 list->append(fontVariant); |
| 508 fontVariant = list; | 508 fontVariant = list; |
| 509 } else if (!fontVariant->isValueList()) { | 509 } else if (!fontVariant->isValueList()) { |
| 510 return 0; | 510 return 0; |
| 511 } | 511 } |
| 512 | 512 |
| 513 CSSValueList* variantList = toCSSValueList(fontVariant.get()); | 513 CSSValueList* variantList = toCSSValueList(fontVariant.get()); |
| 514 unsigned numVariants = variantList->length(); | 514 unsigned numVariants = variantList->length(); |
| 515 if (!numVariants) | 515 if (!numVariants) |
| 516 return 0; | 516 return 0; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 539 unsigned numRanges = rangeList->length(); | 539 unsigned numRanges = rangeList->length(); |
| 540 for (unsigned i = 0; i < numRanges; i++) { | 540 for (unsigned i = 0; i < numRanges; i++) { |
| 541 CSSUnicodeRangeValue* range = toCSSUnicodeRangeValue(rangeList->item
(i)); | 541 CSSUnicodeRangeValue* range = toCSSUnicodeRangeValue(rangeList->item
(i)); |
| 542 ranges.append(CSSFontFace::UnicodeRange(range->from(), range->to()))
; | 542 ranges.append(CSSFontFace::UnicodeRange(range->from(), range->to()))
; |
| 543 } | 543 } |
| 544 } | 544 } |
| 545 | 545 |
| 546 return adoptPtrWillBeNoop(new CSSFontFace(fontFace, ranges)); | 546 return adoptPtrWillBeNoop(new CSSFontFace(fontFace, ranges)); |
| 547 } | 547 } |
| 548 | 548 |
| 549 void FontFace::initCSSFontFace(Document* document, PassRefPtrWillBeRawPtr<CSSVal
ue> src) | 549 void FontFace::initCSSFontFace(Document* document, PassRefPtr<CSSValue> src) |
| 550 { | 550 { |
| 551 m_cssFontFace = createCSSFontFace(this, m_unicodeRange.get()); | 551 m_cssFontFace = createCSSFontFace(this, m_unicodeRange.get()); |
| 552 if (m_error) | 552 if (m_error) |
| 553 return; | 553 return; |
| 554 | 554 |
| 555 // Each item in the src property's list is a single CSSFontFaceSource. Put t
hem all into a CSSFontFace. | 555 // Each item in the src property's list is a single CSSFontFaceSource. Put t
hem all into a CSSFontFace. |
| 556 ASSERT(src); | 556 ASSERT(src); |
| 557 ASSERT(src->isValueList()); | 557 ASSERT(src->isValueList()); |
| 558 CSSValueList* srcList = toCSSValueList(src.get()); | 558 CSSValueList* srcList = toCSSValueList(src.get()); |
| 559 int srcLength = srcList->length(); | 559 int srcLength = srcList->length(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 OwnPtrWillBeRawPtr<BinaryDataFontFaceSource> source = adoptPtrWillBeNoop(new
BinaryDataFontFaceSource(buffer.get(), m_otsParseMessage)); | 592 OwnPtrWillBeRawPtr<BinaryDataFontFaceSource> source = adoptPtrWillBeNoop(new
BinaryDataFontFaceSource(buffer.get(), m_otsParseMessage)); |
| 593 if (source->isValid()) | 593 if (source->isValid()) |
| 594 setLoadStatus(Loaded); | 594 setLoadStatus(Loaded); |
| 595 else | 595 else |
| 596 setError(DOMException::create(SyntaxError, "Invalid font data in ArrayBu
ffer.")); | 596 setError(DOMException::create(SyntaxError, "Invalid font data in ArrayBu
ffer.")); |
| 597 m_cssFontFace->addSource(source.release()); | 597 m_cssFontFace->addSource(source.release()); |
| 598 } | 598 } |
| 599 | 599 |
| 600 DEFINE_TRACE(FontFace) | 600 DEFINE_TRACE(FontFace) |
| 601 { | 601 { |
| 602 visitor->trace(m_src); | |
| 603 visitor->trace(m_style); | |
| 604 visitor->trace(m_weight); | |
| 605 visitor->trace(m_stretch); | |
| 606 visitor->trace(m_unicodeRange); | |
| 607 visitor->trace(m_variant); | |
| 608 visitor->trace(m_featureSettings); | |
| 609 visitor->trace(m_error); | 602 visitor->trace(m_error); |
| 610 visitor->trace(m_loadedProperty); | 603 visitor->trace(m_loadedProperty); |
| 611 visitor->trace(m_cssFontFace); | 604 visitor->trace(m_cssFontFace); |
| 612 visitor->trace(m_callbacks); | 605 visitor->trace(m_callbacks); |
| 613 ActiveDOMObject::trace(visitor); | 606 ActiveDOMObject::trace(visitor); |
| 614 } | 607 } |
| 615 | 608 |
| 616 bool FontFace::hadBlankText() const | 609 bool FontFace::hadBlankText() const |
| 617 { | 610 { |
| 618 return m_cssFontFace->hadBlankText(); | 611 return m_cssFontFace->hadBlankText(); |
| 619 } | 612 } |
| 620 | 613 |
| 621 bool FontFace::hasPendingActivity() const | 614 bool FontFace::hasPendingActivity() const |
| 622 { | 615 { |
| 623 return m_status == Loading && executionContext() && !executionContext()->act
iveDOMObjectsAreStopped(); | 616 return m_status == Loading && executionContext() && !executionContext()->act
iveDOMObjectsAreStopped(); |
| 624 } | 617 } |
| 625 | 618 |
| 626 } // namespace blink | 619 } // namespace blink |
| OLD | NEW |