| 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 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/css/FontFace.h" | 32 #include "core/css/FontFace.h" |
| 33 | 33 |
| 34 #include "bindings/core/v8/Dictionary.h" | |
| 35 #include "bindings/core/v8/ExceptionState.h" | 34 #include "bindings/core/v8/ExceptionState.h" |
| 36 #include "bindings/core/v8/ScriptPromiseResolver.h" | 35 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 37 #include "bindings/core/v8/ScriptState.h" | 36 #include "bindings/core/v8/ScriptState.h" |
| 38 #include "core/CSSValueKeywords.h" | 37 #include "core/CSSValueKeywords.h" |
| 39 #include "core/css/BinaryDataFontFaceSource.h" | 38 #include "core/css/BinaryDataFontFaceSource.h" |
| 40 #include "core/css/CSSFontFace.h" | 39 #include "core/css/CSSFontFace.h" |
| 41 #include "core/css/CSSFontFaceSrcValue.h" | 40 #include "core/css/CSSFontFaceSrcValue.h" |
| 42 #include "core/css/CSSFontSelector.h" | 41 #include "core/css/CSSFontSelector.h" |
| 43 #include "core/css/CSSPrimitiveValue.h" | 42 #include "core/css/CSSPrimitiveValue.h" |
| 44 #include "core/css/CSSUnicodeRangeValue.h" | 43 #include "core/css/CSSUnicodeRangeValue.h" |
| 45 #include "core/css/CSSValueList.h" | 44 #include "core/css/CSSValueList.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/BisonCSSParser.h" | 50 #include "core/css/parser/BisonCSSParser.h" |
| 51 #include "core/dom/DOMError.h" | 51 #include "core/dom/DOMError.h" |
| 52 #include "core/dom/Document.h" | 52 #include "core/dom/Document.h" |
| 53 #include "core/dom/ExceptionCode.h" | 53 #include "core/dom/ExceptionCode.h" |
| 54 #include "core/dom/StyleEngine.h" | 54 #include "core/dom/StyleEngine.h" |
| 55 #include "core/frame/LocalFrame.h" | 55 #include "core/frame/LocalFrame.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 | 96 |
| 97 static PassRefPtrWillBeRawPtr<CSSValue> parseCSSValue(const Document* document,
const String& s, CSSPropertyID propertyID) | 97 static PassRefPtrWillBeRawPtr<CSSValue> parseCSSValue(const Document* document,
const String& s, CSSPropertyID propertyID) |
| 98 { | 98 { |
| 99 if (s.isEmpty()) | 99 if (s.isEmpty()) |
| 100 return nullptr; | 100 return nullptr; |
| 101 RefPtrWillBeRawPtr<MutableStylePropertySet> parsedStyle = MutableStyleProper
tySet::create(); | 101 RefPtrWillBeRawPtr<MutableStylePropertySet> parsedStyle = MutableStyleProper
tySet::create(); |
| 102 BisonCSSParser::parseValue(parsedStyle.get(), propertyID, s, true, *document
); | 102 BisonCSSParser::parseValue(parsedStyle.get(), propertyID, s, true, *document
); |
| 103 return parsedStyle->getPropertyCSSValue(propertyID); | 103 return parsedStyle->getPropertyCSSValue(propertyID); |
| 104 } | 104 } |
| 105 | 105 |
| 106 static bool initFontFace(FontFace* fontFace, ExecutionContext* context, const At
omicString& family, const Dictionary& descriptors, ExceptionState& exceptionStat
e) | 106 static bool initFontFace(FontFace* fontFace, ExecutionContext* context, const At
omicString& family, const FontFaceDescriptors* descriptors, ExceptionState& exce
ptionState) |
| 107 { | 107 { |
| 108 fontFace->setFamily(context, family, exceptionState); | 108 fontFace->setFamily(context, family, exceptionState); |
| 109 if (exceptionState.hadException()) | 109 if (exceptionState.hadException()) |
| 110 return false; | 110 return false; |
| 111 | 111 |
| 112 String value; | 112 fontFace->setStyle(context, descriptors->style(), exceptionState); |
| 113 if (DictionaryHelper::get(descriptors, "style", value)) { | 113 if (exceptionState.hadException()) |
| 114 fontFace->setStyle(context, value, exceptionState); | 114 return false; |
| 115 if (exceptionState.hadException()) | 115 fontFace->setWeight(context, descriptors->weight(), exceptionState); |
| 116 return false; | 116 if (exceptionState.hadException()) |
| 117 } | 117 return false; |
| 118 if (DictionaryHelper::get(descriptors, "weight", value)) { | 118 fontFace->setStretch(context, descriptors->stretch(), exceptionState); |
| 119 fontFace->setWeight(context, value, exceptionState); | 119 if (exceptionState.hadException()) |
| 120 if (exceptionState.hadException()) | 120 return false; |
| 121 return false; | 121 fontFace->setUnicodeRange(context, descriptors->unicodeRange(), exceptionSta
te); |
| 122 } | 122 if (exceptionState.hadException()) |
| 123 if (DictionaryHelper::get(descriptors, "stretch", value)) { | 123 return false; |
| 124 fontFace->setStretch(context, value, exceptionState); | 124 fontFace->setVariant(context, descriptors->variant(), exceptionState); |
| 125 if (exceptionState.hadException()) | 125 if (exceptionState.hadException()) |
| 126 return false; | 126 return false; |
| 127 } | 127 fontFace->setFeatureSettings(context, descriptors->featureSettings(), except
ionState); |
| 128 if (DictionaryHelper::get(descriptors, "unicodeRange", value)) { | 128 if (exceptionState.hadException()) |
| 129 fontFace->setUnicodeRange(context, value, exceptionState); | 129 return false; |
| 130 if (exceptionState.hadException()) | |
| 131 return false; | |
| 132 } | |
| 133 if (DictionaryHelper::get(descriptors, "variant", value)) { | |
| 134 fontFace->setVariant(context, value, exceptionState); | |
| 135 if (exceptionState.hadException()) | |
| 136 return false; | |
| 137 } | |
| 138 if (DictionaryHelper::get(descriptors, "featureSettings", value)) { | |
| 139 fontFace->setFeatureSettings(context, value, exceptionState); | |
| 140 if (exceptionState.hadException()) | |
| 141 return false; | |
| 142 } | |
| 143 return true; | 130 return true; |
| 144 } | 131 } |
| 145 | 132 |
| 146 PassRefPtrWillBeRawPtr<FontFace> FontFace::create(ExecutionContext* context, con
st AtomicString& family, const String& source, const Dictionary& descriptors, Ex
ceptionState& exceptionState) | 133 PassRefPtrWillBeRawPtr<FontFace> FontFace::create(ExecutionContext* context, con
st AtomicString& family, const String& source, const FontFaceDescriptors* descri
ptors, ExceptionState& exceptionState) |
| 147 { | 134 { |
| 148 RefPtrWillBeRawPtr<CSSValue> src = parseCSSValue(toDocument(context), source
, CSSPropertySrc); | 135 RefPtrWillBeRawPtr<CSSValue> src = parseCSSValue(toDocument(context), source
, CSSPropertySrc); |
| 149 if (!src || !src->isValueList()) { | 136 if (!src || !src->isValueList()) { |
| 150 exceptionState.throwDOMException(SyntaxError, "The source provided ('" +
source + "') could not be parsed as a value list."); | 137 exceptionState.throwDOMException(SyntaxError, "The source provided ('" +
source + "') could not be parsed as a value list."); |
| 151 return nullptr; | 138 return nullptr; |
| 152 } | 139 } |
| 153 | 140 |
| 154 RefPtrWillBeRawPtr<FontFace> fontFace = adoptRefWillBeNoop(new FontFace()); | 141 RefPtrWillBeRawPtr<FontFace> fontFace = adoptRefWillBeNoop(new FontFace()); |
| 155 if (initFontFace(fontFace.get(), context, family, descriptors, exceptionStat
e)) | 142 if (initFontFace(fontFace.get(), context, family, descriptors, exceptionStat
e)) |
| 156 fontFace->initCSSFontFace(toDocument(context), src); | 143 fontFace->initCSSFontFace(toDocument(context), src); |
| 157 return fontFace.release(); | 144 return fontFace.release(); |
| 158 } | 145 } |
| 159 | 146 |
| 160 PassRefPtrWillBeRawPtr<FontFace> FontFace::create(ExecutionContext* context, con
st AtomicString& family, PassRefPtr<ArrayBuffer> source, const Dictionary& descr
iptors, ExceptionState& exceptionState) | 147 PassRefPtrWillBeRawPtr<FontFace> FontFace::create(ExecutionContext* context, con
st AtomicString& family, PassRefPtr<ArrayBuffer> source, const FontFaceDescripto
rs* descriptors, ExceptionState& exceptionState) |
| 161 { | 148 { |
| 162 RefPtrWillBeRawPtr<FontFace> fontFace = adoptRefWillBeNoop(new FontFace()); | 149 RefPtrWillBeRawPtr<FontFace> fontFace = adoptRefWillBeNoop(new FontFace()); |
| 163 if (initFontFace(fontFace.get(), context, family, descriptors, exceptionStat
e)) | 150 if (initFontFace(fontFace.get(), context, family, descriptors, exceptionStat
e)) |
| 164 fontFace->initCSSFontFace(static_cast<const unsigned char*>(source->data
()), source->byteLength()); | 151 fontFace->initCSSFontFace(static_cast<const unsigned char*>(source->data
()), source->byteLength()); |
| 165 return fontFace.release(); | 152 return fontFace.release(); |
| 166 } | 153 } |
| 167 | 154 |
| 168 PassRefPtrWillBeRawPtr<FontFace> FontFace::create(ExecutionContext* context, con
st AtomicString& family, PassRefPtr<ArrayBufferView> source, const Dictionary& d
escriptors, ExceptionState& exceptionState) | 155 PassRefPtrWillBeRawPtr<FontFace> FontFace::create(ExecutionContext* context, con
st AtomicString& family, PassRefPtr<ArrayBufferView> source, const FontFaceDescr
iptors* descriptors, ExceptionState& exceptionState) |
| 169 { | 156 { |
| 170 RefPtrWillBeRawPtr<FontFace> fontFace = adoptRefWillBeNoop(new FontFace()); | 157 RefPtrWillBeRawPtr<FontFace> fontFace = adoptRefWillBeNoop(new FontFace()); |
| 171 if (initFontFace(fontFace.get(), context, family, descriptors, exceptionStat
e)) | 158 if (initFontFace(fontFace.get(), context, family, descriptors, exceptionStat
e)) |
| 172 fontFace->initCSSFontFace(static_cast<const unsigned char*>(source->base
Address()), source->byteLength()); | 159 fontFace->initCSSFontFace(static_cast<const unsigned char*>(source->base
Address()), source->byteLength()); |
| 173 return fontFace.release(); | 160 return fontFace.release(); |
| 174 } | 161 } |
| 175 | 162 |
| 176 PassRefPtrWillBeRawPtr<FontFace> FontFace::create(Document* document, const Styl
eRuleFontFace* fontFaceRule) | 163 PassRefPtrWillBeRawPtr<FontFace> FontFace::create(Document* document, const Styl
eRuleFontFace* fontFaceRule) |
| 177 { | 164 { |
| 178 const StylePropertySet& properties = fontFaceRule->properties(); | 165 const StylePropertySet& properties = fontFaceRule->properties(); |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 visitor->trace(m_cssFontFace); | 618 visitor->trace(m_cssFontFace); |
| 632 visitor->trace(m_callbacks); | 619 visitor->trace(m_callbacks); |
| 633 } | 620 } |
| 634 | 621 |
| 635 bool FontFace::hadBlankText() const | 622 bool FontFace::hadBlankText() const |
| 636 { | 623 { |
| 637 return m_cssFontFace->hadBlankText(); | 624 return m_cssFontFace->hadBlankText(); |
| 638 } | 625 } |
| 639 | 626 |
| 640 } // namespace blink | 627 } // namespace blink |
| OLD | NEW |