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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 : m_scriptState(ScriptState::current()) | 86 : m_scriptState(ScriptState::current()) |
87 , m_resolver(ScriptPromiseResolver::create(promise, context)) | 87 , m_resolver(ScriptPromiseResolver::create(promise, context)) |
88 { } | 88 { } |
89 ScriptState* m_scriptState; | 89 ScriptState* m_scriptState; |
90 RefPtr<ScriptPromiseResolver> m_resolver; | 90 RefPtr<ScriptPromiseResolver> m_resolver; |
91 }; | 91 }; |
92 | 92 |
93 static PassRefPtrWillBeRawPtr<CSSValue> parseCSSValue(const Document* document,
const String& s, CSSPropertyID propertyID) | 93 static PassRefPtrWillBeRawPtr<CSSValue> parseCSSValue(const Document* document,
const String& s, CSSPropertyID propertyID) |
94 { | 94 { |
95 if (s.isEmpty()) | 95 if (s.isEmpty()) |
96 return 0; | 96 return nullptr; |
97 RefPtr<MutableStylePropertySet> parsedStyle = MutableStylePropertySet::creat
e(); | 97 RefPtr<MutableStylePropertySet> parsedStyle = MutableStylePropertySet::creat
e(); |
98 BisonCSSParser::parseValue(parsedStyle.get(), propertyID, s, true, *document
); | 98 BisonCSSParser::parseValue(parsedStyle.get(), propertyID, s, true, *document
); |
99 return parsedStyle->getPropertyCSSValue(propertyID); | 99 return parsedStyle->getPropertyCSSValue(propertyID); |
100 } | 100 } |
101 | 101 |
102 PassRefPtr<FontFace> FontFace::create(ExecutionContext* context, const AtomicStr
ing& family, const String& source, const Dictionary& descriptors, ExceptionState
& exceptionState) | 102 PassRefPtr<FontFace> FontFace::create(ExecutionContext* context, const AtomicStr
ing& family, const String& source, const Dictionary& descriptors, ExceptionState
& exceptionState) |
103 { | 103 { |
104 RefPtrWillBeRawPtr<CSSValue> src = parseCSSValue(toDocument(context), source
, CSSPropertySrc); | 104 RefPtrWillBeRawPtr<CSSValue> src = parseCSSValue(toDocument(context), source
, CSSPropertySrc); |
105 if (!src || !src->isValueList()) { | 105 if (!src || !src->isValueList()) { |
106 exceptionState.throwDOMException(SyntaxError, "The source provided ('" +
source + "') could not be parsed as a value list."); | 106 exceptionState.throwDOMException(SyntaxError, "The source provided ('" +
source + "') could not be parsed as a value list."); |
107 return 0; | 107 return nullptr; |
108 } | 108 } |
109 | 109 |
110 RefPtr<FontFace> fontFace = adoptRef<FontFace>(new FontFace(src)); | 110 RefPtr<FontFace> fontFace = adoptRef<FontFace>(new FontFace(src)); |
111 fontFace->setFamily(context, family, exceptionState); | 111 fontFace->setFamily(context, family, exceptionState); |
112 if (exceptionState.hadException()) | 112 if (exceptionState.hadException()) |
113 return 0; | 113 return nullptr; |
114 | 114 |
115 String value; | 115 String value; |
116 if (descriptors.get("style", value)) { | 116 if (descriptors.get("style", value)) { |
117 fontFace->setStyle(context, value, exceptionState); | 117 fontFace->setStyle(context, value, exceptionState); |
118 if (exceptionState.hadException()) | 118 if (exceptionState.hadException()) |
119 return 0; | 119 return nullptr; |
120 } | 120 } |
121 if (descriptors.get("weight", value)) { | 121 if (descriptors.get("weight", value)) { |
122 fontFace->setWeight(context, value, exceptionState); | 122 fontFace->setWeight(context, value, exceptionState); |
123 if (exceptionState.hadException()) | 123 if (exceptionState.hadException()) |
124 return 0; | 124 return nullptr; |
125 } | 125 } |
126 if (descriptors.get("stretch", value)) { | 126 if (descriptors.get("stretch", value)) { |
127 fontFace->setStretch(context, value, exceptionState); | 127 fontFace->setStretch(context, value, exceptionState); |
128 if (exceptionState.hadException()) | 128 if (exceptionState.hadException()) |
129 return 0; | 129 return nullptr; |
130 } | 130 } |
131 if (descriptors.get("unicodeRange", value)) { | 131 if (descriptors.get("unicodeRange", value)) { |
132 fontFace->setUnicodeRange(context, value, exceptionState); | 132 fontFace->setUnicodeRange(context, value, exceptionState); |
133 if (exceptionState.hadException()) | 133 if (exceptionState.hadException()) |
134 return 0; | 134 return nullptr; |
135 } | 135 } |
136 if (descriptors.get("variant", value)) { | 136 if (descriptors.get("variant", value)) { |
137 fontFace->setVariant(context, value, exceptionState); | 137 fontFace->setVariant(context, value, exceptionState); |
138 if (exceptionState.hadException()) | 138 if (exceptionState.hadException()) |
139 return 0; | 139 return nullptr; |
140 } | 140 } |
141 if (descriptors.get("featureSettings", value)) { | 141 if (descriptors.get("featureSettings", value)) { |
142 fontFace->setFeatureSettings(context, value, exceptionState); | 142 fontFace->setFeatureSettings(context, value, exceptionState); |
143 if (exceptionState.hadException()) | 143 if (exceptionState.hadException()) |
144 return 0; | 144 return nullptr; |
145 } | 145 } |
146 | 146 |
147 fontFace->initCSSFontFace(toDocument(context)); | 147 fontFace->initCSSFontFace(toDocument(context)); |
148 return fontFace; | 148 return fontFace; |
149 } | 149 } |
150 | 150 |
151 PassRefPtr<FontFace> FontFace::create(Document* document, const StyleRuleFontFac
e* fontFaceRule) | 151 PassRefPtr<FontFace> FontFace::create(Document* document, const StyleRuleFontFac
e* fontFaceRule) |
152 { | 152 { |
153 const StylePropertySet* properties = fontFaceRule->properties(); | 153 const StylePropertySet* properties = fontFaceRule->properties(); |
154 | 154 |
155 // Obtain the font-family property and the src property. Both must be define
d. | 155 // Obtain the font-family property and the src property. Both must be define
d. |
156 RefPtrWillBeRawPtr<CSSValue> family = properties->getPropertyCSSValue(CSSPro
pertyFontFamily); | 156 RefPtrWillBeRawPtr<CSSValue> family = properties->getPropertyCSSValue(CSSPro
pertyFontFamily); |
157 if (!family || !family->isValueList()) | 157 if (!family || !family->isValueList()) |
158 return 0; | 158 return nullptr; |
159 RefPtrWillBeRawPtr<CSSValue> src = properties->getPropertyCSSValue(CSSProper
tySrc); | 159 RefPtrWillBeRawPtr<CSSValue> src = properties->getPropertyCSSValue(CSSProper
tySrc); |
160 if (!src || !src->isValueList()) | 160 if (!src || !src->isValueList()) |
161 return 0; | 161 return nullptr; |
162 | 162 |
163 RefPtr<FontFace> fontFace = adoptRef<FontFace>(new FontFace(src)); | 163 RefPtr<FontFace> fontFace = adoptRef<FontFace>(new FontFace(src)); |
164 | 164 |
165 if (fontFace->setFamilyValue(toCSSValueList(family.get())) | 165 if (fontFace->setFamilyValue(toCSSValueList(family.get())) |
166 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontStyle) | 166 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontStyle) |
167 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontWeight) | 167 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontWeight) |
168 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontStretch) | 168 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontStretch) |
169 && fontFace->setPropertyFromStyle(properties, CSSPropertyUnicodeRange) | 169 && fontFace->setPropertyFromStyle(properties, CSSPropertyUnicodeRange) |
170 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontVariant) | 170 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontVariant) |
171 && fontFace->setPropertyFromStyle(properties, CSSPropertyWebkitFontFeatu
reSettings) | 171 && fontFace->setPropertyFromStyle(properties, CSSPropertyWebkitFontFeatu
reSettings) |
172 && !fontFace->family().isEmpty() | 172 && !fontFace->family().isEmpty() |
173 && fontFace->traitsMask()) { | 173 && fontFace->traitsMask()) { |
174 fontFace->initCSSFontFace(document); | 174 fontFace->initCSSFontFace(document); |
175 return fontFace; | 175 return fontFace; |
176 } | 176 } |
177 return 0; | 177 return nullptr; |
178 } | 178 } |
179 | 179 |
180 FontFace::FontFace(PassRefPtrWillBeRawPtr<CSSValue> src) | 180 FontFace::FontFace(PassRefPtrWillBeRawPtr<CSSValue> src) |
181 : m_src(src) | 181 : m_src(src) |
182 , m_status(Unloaded) | 182 , m_status(Unloaded) |
183 { | 183 { |
184 } | 184 } |
185 | 185 |
186 FontFace::~FontFace() | 186 FontFace::~FontFace() |
187 { | 187 { |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 if (source) { | 533 if (source) { |
534 #if ENABLE(SVG_FONTS) | 534 #if ENABLE(SVG_FONTS) |
535 source->setSVGFontFaceElement(item->svgFontFaceElement()); | 535 source->setSVGFontFaceElement(item->svgFontFaceElement()); |
536 #endif | 536 #endif |
537 m_cssFontFace->addSource(source.release()); | 537 m_cssFontFace->addSource(source.release()); |
538 } | 538 } |
539 } | 539 } |
540 } | 540 } |
541 | 541 |
542 } // namespace WebCore | 542 } // namespace WebCore |
OLD | NEW |