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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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); | |
115 if (!family || !family->isPrimitiveValue()) | |
116 return nullptr; | |
117 RefPtrWillBeRawPtr<CSSValue> src = properties.getPropertyCSSValue(CSSPropert
ySrc); | 114 RefPtrWillBeRawPtr<CSSValue> src = properties.getPropertyCSSValue(CSSPropert
ySrc); |
118 if (!src || !src->isValueList()) | 115 if (!src || !src->isValueList()) |
119 return nullptr; | 116 return nullptr; |
120 | 117 |
121 RefPtrWillBeRawPtr<FontFace> fontFace = adoptRefWillBeNoop(new FontFace(docu
ment)); | 118 RefPtrWillBeRawPtr<FontFace> fontFace = adoptRefWillBeNoop(new FontFace(docu
ment)); |
122 | 119 |
123 if (fontFace->setFamilyValue(toCSSPrimitiveValue(family.get())) | 120 if (fontFace->setPropertyFromStyle(properties, CSSPropertyFontFamily) |
124 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontStyle) | 121 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontStyle) |
125 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontWeight) | 122 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontWeight) |
126 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontStretch) | 123 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontStretch) |
127 && fontFace->setPropertyFromStyle(properties, CSSPropertyUnicodeRange) | 124 && fontFace->setPropertyFromStyle(properties, CSSPropertyUnicodeRange) |
128 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontVariant) | 125 && fontFace->setPropertyFromStyle(properties, CSSPropertyFontVariant) |
129 && fontFace->setPropertyFromStyle(properties, CSSPropertyWebkitFontFeatu
reSettings) | 126 && fontFace->setPropertyFromStyle(properties, CSSPropertyWebkitFontFeatu
reSettings) |
130 && !fontFace->family().isEmpty() | 127 && !fontFace->family().isEmpty() |
131 && fontFace->traits().bitfield()) { | 128 && fontFace->traits().bitfield()) { |
132 fontFace->initCSSFontFace(document, src); | 129 fontFace->initCSSFontFace(document, src); |
133 return fontFace.release(); | 130 return fontFace.release(); |
134 } | 131 } |
135 return nullptr; | 132 return nullptr; |
136 } | 133 } |
137 | 134 |
138 FontFace::FontFace(ExecutionContext* context) | 135 FontFace::FontFace(ExecutionContext* context) |
139 : ActiveDOMObject(context) | 136 : ActiveDOMObject(context) |
140 , m_status(Unloaded) | 137 , m_status(Unloaded) |
141 { | 138 { |
142 suspendIfNeeded(); | 139 suspendIfNeeded(); |
143 } | 140 } |
144 | 141 |
145 FontFace::FontFace(ExecutionContext* context, const AtomicString& family, const
FontFaceDescriptors& descriptors) | 142 FontFace::FontFace(ExecutionContext* context, const AtomicString& family, const
FontFaceDescriptors& descriptors) |
146 : ActiveDOMObject(context) | 143 : ActiveDOMObject(context) |
147 , m_family(family) | |
148 , m_status(Unloaded) | 144 , m_status(Unloaded) |
149 { | 145 { |
150 Document* document = toDocument(context); | 146 Document* document = toDocument(context); |
| 147 setPropertyFromString(document, family, CSSPropertyFontFamily); |
151 setPropertyFromString(document, descriptors.style(), CSSPropertyFontStyle); | 148 setPropertyFromString(document, descriptors.style(), CSSPropertyFontStyle); |
152 setPropertyFromString(document, descriptors.weight(), CSSPropertyFontWeight)
; | 149 setPropertyFromString(document, descriptors.weight(), CSSPropertyFontWeight)
; |
153 setPropertyFromString(document, descriptors.stretch(), CSSPropertyFontStretc
h); | 150 setPropertyFromString(document, descriptors.stretch(), CSSPropertyFontStretc
h); |
154 setPropertyFromString(document, descriptors.unicodeRange(), CSSPropertyUnico
deRange); | 151 setPropertyFromString(document, descriptors.unicodeRange(), CSSPropertyUnico
deRange); |
155 setPropertyFromString(document, descriptors.variant(), CSSPropertyFontVarian
t); | 152 setPropertyFromString(document, descriptors.variant(), CSSPropertyFontVarian
t); |
156 setPropertyFromString(document, descriptors.featureSettings(), CSSPropertyWe
bkitFontFeatureSettings); | 153 setPropertyFromString(document, descriptors.featureSettings(), CSSPropertyWe
bkitFontFeatureSettings); |
157 | 154 |
158 suspendIfNeeded(); | 155 suspendIfNeeded(); |
159 } | 156 } |
160 | 157 |
(...skipping 24 matching lines...) Expand all Loading... |
185 String FontFace::variant() const | 182 String FontFace::variant() const |
186 { | 183 { |
187 return m_variant ? m_variant->cssText() : "normal"; | 184 return m_variant ? m_variant->cssText() : "normal"; |
188 } | 185 } |
189 | 186 |
190 String FontFace::featureSettings() const | 187 String FontFace::featureSettings() const |
191 { | 188 { |
192 return m_featureSettings ? m_featureSettings->cssText() : "normal"; | 189 return m_featureSettings ? m_featureSettings->cssText() : "normal"; |
193 } | 190 } |
194 | 191 |
| 192 void FontFace::setFamily(ExecutionContext* context, const String& s, ExceptionSt
ate& exceptionState) |
| 193 { |
| 194 setPropertyFromString(toDocument(context), s, CSSPropertyFontFamily, &except
ionState); |
| 195 } |
| 196 |
195 void FontFace::setStyle(ExecutionContext* context, const String& s, ExceptionSta
te& exceptionState) | 197 void FontFace::setStyle(ExecutionContext* context, const String& s, ExceptionSta
te& exceptionState) |
196 { | 198 { |
197 setPropertyFromString(toDocument(context), s, CSSPropertyFontStyle, &excepti
onState); | 199 setPropertyFromString(toDocument(context), s, CSSPropertyFontStyle, &excepti
onState); |
198 } | 200 } |
199 | 201 |
200 void FontFace::setWeight(ExecutionContext* context, const String& s, ExceptionSt
ate& exceptionState) | 202 void FontFace::setWeight(ExecutionContext* context, const String& s, ExceptionSt
ate& exceptionState) |
201 { | 203 { |
202 setPropertyFromString(toDocument(context), s, CSSPropertyFontWeight, &except
ionState); | 204 setPropertyFromString(toDocument(context), s, CSSPropertyFontWeight, &except
ionState); |
203 } | 205 } |
204 | 206 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 } | 238 } |
237 | 239 |
238 bool FontFace::setPropertyFromStyle(const StylePropertySet& properties, CSSPrope
rtyID propertyID) | 240 bool FontFace::setPropertyFromStyle(const StylePropertySet& properties, CSSPrope
rtyID propertyID) |
239 { | 241 { |
240 return setPropertyValue(properties.getPropertyCSSValue(propertyID), property
ID); | 242 return setPropertyValue(properties.getPropertyCSSValue(propertyID), property
ID); |
241 } | 243 } |
242 | 244 |
243 bool FontFace::setPropertyValue(PassRefPtrWillBeRawPtr<CSSValue> value, CSSPrope
rtyID propertyID) | 245 bool FontFace::setPropertyValue(PassRefPtrWillBeRawPtr<CSSValue> value, CSSPrope
rtyID propertyID) |
244 { | 246 { |
245 switch (propertyID) { | 247 switch (propertyID) { |
| 248 case CSSPropertyFontFamily: |
| 249 if (!value || !value->isPrimitiveValue()) |
| 250 return false; |
| 251 m_family = AtomicString(toCSSPrimitiveValue(value.get())->getStringValue
()); |
| 252 break; |
246 case CSSPropertyFontStyle: | 253 case CSSPropertyFontStyle: |
247 m_style = value; | 254 m_style = value; |
248 break; | 255 break; |
249 case CSSPropertyFontWeight: | 256 case CSSPropertyFontWeight: |
250 m_weight = value; | 257 m_weight = value; |
251 break; | 258 break; |
252 case CSSPropertyFontStretch: | 259 case CSSPropertyFontStretch: |
253 m_stretch = value; | 260 m_stretch = value; |
254 break; | 261 break; |
255 case CSSPropertyUnicodeRange: | 262 case CSSPropertyUnicodeRange: |
256 if (value && !value->isValueList()) | 263 if (value && !value->isValueList()) |
257 return false; | 264 return false; |
258 m_unicodeRange = value; | 265 m_unicodeRange = value; |
259 break; | 266 break; |
260 case CSSPropertyFontVariant: | 267 case CSSPropertyFontVariant: |
261 m_variant = value; | 268 m_variant = value; |
262 break; | 269 break; |
263 case CSSPropertyWebkitFontFeatureSettings: | 270 case CSSPropertyWebkitFontFeatureSettings: |
264 m_featureSettings = value; | 271 m_featureSettings = value; |
265 break; | 272 break; |
266 default: | 273 default: |
267 ASSERT_NOT_REACHED(); | 274 ASSERT_NOT_REACHED(); |
268 return false; | 275 return false; |
269 } | 276 } |
270 return true; | 277 return true; |
271 } | 278 } |
272 | 279 |
273 bool FontFace::setFamilyValue(CSSPrimitiveValue* familyValue) | |
274 { | |
275 AtomicString family; | |
276 if (familyValue->isCustomIdent()) { | |
277 family = AtomicString(familyValue->getStringValue()); | |
278 } else if (familyValue->isValueID()) { | |
279 // We need to use the raw text for all the generic family types, since @
font-face is a way of actually | |
280 // defining what font to use for those types. | |
281 switch (familyValue->getValueID()) { | |
282 case CSSValueSerif: | |
283 family = FontFamilyNames::webkit_serif; | |
284 break; | |
285 case CSSValueSansSerif: | |
286 family = FontFamilyNames::webkit_sans_serif; | |
287 break; | |
288 case CSSValueCursive: | |
289 family = FontFamilyNames::webkit_cursive; | |
290 break; | |
291 case CSSValueFantasy: | |
292 family = FontFamilyNames::webkit_fantasy; | |
293 break; | |
294 case CSSValueMonospace: | |
295 family = FontFamilyNames::webkit_monospace; | |
296 break; | |
297 case CSSValueWebkitPictograph: | |
298 family = FontFamilyNames::webkit_pictograph; | |
299 break; | |
300 default: | |
301 return false; | |
302 } | |
303 } | |
304 m_family = family; | |
305 return true; | |
306 } | |
307 | |
308 String FontFace::status() const | 280 String FontFace::status() const |
309 { | 281 { |
310 switch (m_status) { | 282 switch (m_status) { |
311 case Unloaded: | 283 case Unloaded: |
312 return "unloaded"; | 284 return "unloaded"; |
313 case Loading: | 285 case Loading: |
314 return "loading"; | 286 return "loading"; |
315 case Loaded: | 287 case Loaded: |
316 return "loaded"; | 288 return "loaded"; |
317 case Error: | 289 case Error: |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 { | 584 { |
613 return m_cssFontFace->hadBlankText(); | 585 return m_cssFontFace->hadBlankText(); |
614 } | 586 } |
615 | 587 |
616 bool FontFace::hasPendingActivity() const | 588 bool FontFace::hasPendingActivity() const |
617 { | 589 { |
618 return m_status == Loading && executionContext() && !executionContext()->act
iveDOMObjectsAreStopped(); | 590 return m_status == Loading && executionContext() && !executionContext()->act
iveDOMObjectsAreStopped(); |
619 } | 591 } |
620 | 592 |
621 } // namespace blink | 593 } // namespace blink |
OLD | NEW |