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...) 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/ScriptState.h" | 35 #include "bindings/core/v8/ScriptState.h" |
37 #include "core/CSSValueKeywords.h" | 36 #include "core/CSSValueKeywords.h" |
38 #include "core/css/BinaryDataFontFaceSource.h" | 37 #include "core/css/BinaryDataFontFaceSource.h" |
39 #include "core/css/CSSFontFace.h" | 38 #include "core/css/CSSFontFace.h" |
40 #include "core/css/CSSFontFaceSrcValue.h" | 39 #include "core/css/CSSFontFaceSrcValue.h" |
41 #include "core/css/CSSFontSelector.h" | 40 #include "core/css/CSSFontSelector.h" |
42 #include "core/css/CSSPrimitiveValue.h" | 41 #include "core/css/CSSPrimitiveValue.h" |
43 #include "core/css/CSSUnicodeRangeValue.h" | 42 #include "core/css/CSSUnicodeRangeValue.h" |
44 #include "core/css/CSSValueList.h" | 43 #include "core/css/CSSValueList.h" |
| 44 #include "core/css/FontFaceDescriptors.h" |
45 #include "core/css/LocalFontFaceSource.h" | 45 #include "core/css/LocalFontFaceSource.h" |
46 #include "core/css/RemoteFontFaceSource.h" | 46 #include "core/css/RemoteFontFaceSource.h" |
47 #include "core/css/StylePropertySet.h" | 47 #include "core/css/StylePropertySet.h" |
48 #include "core/css/StyleRule.h" | 48 #include "core/css/StyleRule.h" |
49 #include "core/css/parser/BisonCSSParser.h" | 49 #include "core/css/parser/BisonCSSParser.h" |
50 #include "core/dom/DOMException.h" | 50 #include "core/dom/DOMException.h" |
51 #include "core/dom/Document.h" | 51 #include "core/dom/Document.h" |
52 #include "core/dom/ExceptionCode.h" | 52 #include "core/dom/ExceptionCode.h" |
53 #include "core/dom/StyleEngine.h" | 53 #include "core/dom/StyleEngine.h" |
54 #include "core/frame/LocalFrame.h" | 54 #include "core/frame/LocalFrame.h" |
55 #include "core/frame/Settings.h" | 55 #include "core/frame/Settings.h" |
56 #include "core/svg/SVGFontFaceElement.h" | 56 #include "core/svg/SVGFontFaceElement.h" |
57 #include "core/svg/SVGFontFaceSource.h" | 57 #include "core/svg/SVGFontFaceSource.h" |
58 #include "core/svg/SVGRemoteFontFaceSource.h" | 58 #include "core/svg/SVGRemoteFontFaceSource.h" |
59 #include "platform/FontFamilyNames.h" | 59 #include "platform/FontFamilyNames.h" |
60 #include "platform/SharedBuffer.h" | 60 #include "platform/SharedBuffer.h" |
61 | 61 |
62 namespace blink { | 62 namespace blink { |
63 | 63 |
64 static PassRefPtrWillBeRawPtr<CSSValue> parseCSSValue(const Document* document,
const String& s, CSSPropertyID propertyID) | 64 static PassRefPtrWillBeRawPtr<CSSValue> parseCSSValue(const Document* document,
const String& s, CSSPropertyID propertyID) |
65 { | 65 { |
66 if (s.isEmpty()) | 66 if (s.isEmpty()) |
67 return nullptr; | 67 return nullptr; |
68 RefPtrWillBeRawPtr<MutableStylePropertySet> parsedStyle = MutableStyleProper
tySet::create(); | 68 RefPtrWillBeRawPtr<MutableStylePropertySet> parsedStyle = MutableStyleProper
tySet::create(); |
69 BisonCSSParser::parseValue(parsedStyle.get(), propertyID, s, true, *document
); | 69 BisonCSSParser::parseValue(parsedStyle.get(), propertyID, s, true, *document
); |
70 return parsedStyle->getPropertyCSSValue(propertyID); | 70 return parsedStyle->getPropertyCSSValue(propertyID); |
71 } | 71 } |
72 | 72 |
73 PassRefPtrWillBeRawPtr<FontFace> FontFace::create(ExecutionContext* context, con
st AtomicString& family, const String& source, const Dictionary& descriptors) | 73 PassRefPtrWillBeRawPtr<FontFace> FontFace::create(ExecutionContext* context, con
st AtomicString& family, const String& source, const FontFaceDescriptors* descri
ptors) |
74 { | 74 { |
75 RefPtrWillBeRawPtr<FontFace> fontFace = adoptRefWillBeNoop(new FontFace(cont
ext, family, descriptors)); | 75 RefPtrWillBeRawPtr<FontFace> fontFace = adoptRefWillBeNoop(new FontFace(cont
ext, family, descriptors)); |
76 | 76 |
77 RefPtrWillBeRawPtr<CSSValue> src = parseCSSValue(toDocument(context), source
, CSSPropertySrc); | 77 RefPtrWillBeRawPtr<CSSValue> src = parseCSSValue(toDocument(context), source
, CSSPropertySrc); |
78 if (!src || !src->isValueList()) | 78 if (!src || !src->isValueList()) |
79 fontFace->setError(DOMException::create(SyntaxError, "The source provide
d ('" + source + "') could not be parsed as a value list.")); | 79 fontFace->setError(DOMException::create(SyntaxError, "The source provide
d ('" + source + "') could not be parsed as a value list.")); |
80 | 80 |
81 fontFace->initCSSFontFace(toDocument(context), src); | 81 fontFace->initCSSFontFace(toDocument(context), src); |
82 return fontFace.release(); | 82 return fontFace.release(); |
83 } | 83 } |
84 | 84 |
85 PassRefPtrWillBeRawPtr<FontFace> FontFace::create(ExecutionContext* context, con
st AtomicString& family, PassRefPtr<ArrayBuffer> source, const Dictionary& descr
iptors) | 85 PassRefPtrWillBeRawPtr<FontFace> FontFace::create(ExecutionContext* context, con
st AtomicString& family, PassRefPtr<ArrayBuffer> source, const FontFaceDescripto
rs* descriptors) |
86 { | 86 { |
87 RefPtrWillBeRawPtr<FontFace> fontFace = adoptRefWillBeNoop(new FontFace(cont
ext, family, descriptors)); | 87 RefPtrWillBeRawPtr<FontFace> fontFace = adoptRefWillBeNoop(new FontFace(cont
ext, family, descriptors)); |
88 fontFace->initCSSFontFace(static_cast<const unsigned char*>(source->data()),
source->byteLength()); | 88 fontFace->initCSSFontFace(static_cast<const unsigned char*>(source->data()),
source->byteLength()); |
89 return fontFace.release(); | 89 return fontFace.release(); |
90 } | 90 } |
91 | 91 |
92 PassRefPtrWillBeRawPtr<FontFace> FontFace::create(ExecutionContext* context, con
st AtomicString& family, PassRefPtr<ArrayBufferView> source, const Dictionary& d
escriptors) | 92 PassRefPtrWillBeRawPtr<FontFace> FontFace::create(ExecutionContext* context, con
st AtomicString& family, PassRefPtr<ArrayBufferView> source, const FontFaceDescr
iptors* descriptors) |
93 { | 93 { |
94 RefPtrWillBeRawPtr<FontFace> fontFace = adoptRefWillBeNoop(new FontFace(cont
ext, family, descriptors)); | 94 RefPtrWillBeRawPtr<FontFace> fontFace = adoptRefWillBeNoop(new FontFace(cont
ext, family, descriptors)); |
95 fontFace->initCSSFontFace(static_cast<const unsigned char*>(source->baseAddr
ess()), source->byteLength()); | 95 fontFace->initCSSFontFace(static_cast<const unsigned char*>(source->baseAddr
ess()), source->byteLength()); |
96 return fontFace.release(); | 96 return fontFace.release(); |
97 } | 97 } |
98 | 98 |
99 PassRefPtrWillBeRawPtr<FontFace> FontFace::create(Document* document, const Styl
eRuleFontFace* fontFaceRule) | 99 PassRefPtrWillBeRawPtr<FontFace> FontFace::create(Document* document, const Styl
eRuleFontFace* fontFaceRule) |
100 { | 100 { |
101 const StylePropertySet& properties = fontFaceRule->properties(); | 101 const StylePropertySet& properties = fontFaceRule->properties(); |
102 | 102 |
(...skipping 20 matching lines...) Loading... |
123 return fontFace.release(); | 123 return fontFace.release(); |
124 } | 124 } |
125 return nullptr; | 125 return nullptr; |
126 } | 126 } |
127 | 127 |
128 FontFace::FontFace() | 128 FontFace::FontFace() |
129 : m_status(Unloaded) | 129 : m_status(Unloaded) |
130 { | 130 { |
131 } | 131 } |
132 | 132 |
133 FontFace::FontFace(ExecutionContext* context, const AtomicString& family, const
Dictionary& descriptors) | 133 FontFace::FontFace(ExecutionContext* context, const AtomicString& family, const
FontFaceDescriptors* descriptors) |
134 : m_family(family) | 134 : m_family(family) |
135 , m_status(Unloaded) | 135 , m_status(Unloaded) |
136 { | 136 { |
137 Document* document = toDocument(context); | 137 Document* document = toDocument(context); |
138 String value; | 138 setPropertyFromString(document, descriptors->style(), CSSPropertyFontStyle); |
139 if (DictionaryHelper::get(descriptors, "style", value)) | 139 setPropertyFromString(document, descriptors->weight(), CSSPropertyFontWeight
); |
140 setPropertyFromString(document, value, CSSPropertyFontStyle); | 140 // FIXME: we don't implement 'font-strech' property yet so we can't set the
property. |
141 if (DictionaryHelper::get(descriptors, "weight", value)) | 141 setPropertyFromString(document, descriptors->unicodeRange(), CSSPropertyUnic
odeRange); |
142 setPropertyFromString(document, value, CSSPropertyFontWeight); | 142 setPropertyFromString(document, descriptors->variant(), CSSPropertyFontVaria
nt); |
143 if (DictionaryHelper::get(descriptors, "stretch", value)) | 143 setPropertyFromString(document, descriptors->featureSettings(), CSSPropertyW
ebkitFontFeatureSettings); |
144 setPropertyFromString(document, value, CSSPropertyFontStretch); | |
145 if (DictionaryHelper::get(descriptors, "unicodeRange", value)) | |
146 setPropertyFromString(document, value, CSSPropertyUnicodeRange); | |
147 if (DictionaryHelper::get(descriptors, "variant", value)) | |
148 setPropertyFromString(document, value, CSSPropertyFontVariant); | |
149 if (DictionaryHelper::get(descriptors, "featureSettings", value)) | |
150 setPropertyFromString(document, value, CSSPropertyWebkitFontFeatureSetti
ngs); | |
151 } | 144 } |
152 | 145 |
153 FontFace::~FontFace() | 146 FontFace::~FontFace() |
154 { | 147 { |
155 } | 148 } |
156 | 149 |
157 String FontFace::style() const | 150 String FontFace::style() const |
158 { | 151 { |
159 return m_style ? m_style->cssText() : "normal"; | 152 return m_style ? m_style->cssText() : "normal"; |
160 } | 153 } |
(...skipping 430 matching lines...) Loading... |
591 visitor->trace(m_cssFontFace); | 584 visitor->trace(m_cssFontFace); |
592 visitor->trace(m_callbacks); | 585 visitor->trace(m_callbacks); |
593 } | 586 } |
594 | 587 |
595 bool FontFace::hadBlankText() const | 588 bool FontFace::hadBlankText() const |
596 { | 589 { |
597 return m_cssFontFace->hadBlankText(); | 590 return m_cssFontFace->hadBlankText(); |
598 } | 591 } |
599 | 592 |
600 } // namespace blink | 593 } // namespace blink |
OLD | NEW |