Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: sky/engine/core/css/FontFace.cpp

Issue 922893002: Merge the Sky Engine changes from the SkyDart branch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/engine/core/css/FontFace.h ('k') | sky/engine/core/css/FontFace.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 15 matching lines...) Expand all
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 "sky/engine/config.h" 31 #include "sky/engine/config.h"
32 #include "sky/engine/core/css/FontFace.h" 32 #include "sky/engine/core/css/FontFace.h"
33 33
34 #include "gen/sky/core/CSSValueKeywords.h" 34 #include "gen/sky/core/CSSValueKeywords.h"
35 #include "gen/sky/platform/FontFamilyNames.h" 35 #include "gen/sky/platform/FontFamilyNames.h"
36 #include "sky/engine/bindings/core/v8/Dictionary.h" 36 #include "sky/engine/bindings2/exception_state.h"
37 #include "sky/engine/bindings/core/v8/ExceptionState.h"
38 #include "sky/engine/bindings/core/v8/ScriptState.h"
39 #include "sky/engine/core/css/BinaryDataFontFaceSource.h" 37 #include "sky/engine/core/css/BinaryDataFontFaceSource.h"
40 #include "sky/engine/core/css/CSSFontFace.h" 38 #include "sky/engine/core/css/CSSFontFace.h"
41 #include "sky/engine/core/css/CSSFontFaceSrcValue.h" 39 #include "sky/engine/core/css/CSSFontFaceSrcValue.h"
42 #include "sky/engine/core/css/CSSFontSelector.h" 40 #include "sky/engine/core/css/CSSFontSelector.h"
43 #include "sky/engine/core/css/CSSPrimitiveValue.h" 41 #include "sky/engine/core/css/CSSPrimitiveValue.h"
44 #include "sky/engine/core/css/CSSUnicodeRangeValue.h" 42 #include "sky/engine/core/css/CSSUnicodeRangeValue.h"
45 #include "sky/engine/core/css/CSSValueList.h" 43 #include "sky/engine/core/css/CSSValueList.h"
46 #include "sky/engine/core/css/LocalFontFaceSource.h" 44 #include "sky/engine/core/css/LocalFontFaceSource.h"
47 #include "sky/engine/core/css/RemoteFontFaceSource.h" 45 #include "sky/engine/core/css/RemoteFontFaceSource.h"
48 #include "sky/engine/core/css/StylePropertySet.h" 46 #include "sky/engine/core/css/StylePropertySet.h"
(...skipping 12 matching lines...) Expand all
61 59
62 static PassRefPtr<CSSValue> parseCSSValue(const Document* document, const String & s, CSSPropertyID propertyID) 60 static PassRefPtr<CSSValue> parseCSSValue(const Document* document, const String & s, CSSPropertyID propertyID)
63 { 61 {
64 if (s.isEmpty()) 62 if (s.isEmpty())
65 return nullptr; 63 return nullptr;
66 RefPtr<MutableStylePropertySet> parsedStyle = MutableStylePropertySet::creat e(); 64 RefPtr<MutableStylePropertySet> parsedStyle = MutableStylePropertySet::creat e();
67 BisonCSSParser::parseValue(parsedStyle.get(), propertyID, s, *document); 65 BisonCSSParser::parseValue(parsedStyle.get(), propertyID, s, *document);
68 return parsedStyle->getPropertyCSSValue(propertyID); 66 return parsedStyle->getPropertyCSSValue(propertyID);
69 } 67 }
70 68
71 PassRefPtr<FontFace> FontFace::create(ExecutionContext* context, const AtomicStr ing& family, const String& source, const Dictionary& descriptors) 69 PassRefPtr<FontFace> FontFace::create(ExecutionContext* context, const AtomicStr ing& family, const String& source)
72 { 70 {
73 RefPtr<FontFace> fontFace = adoptRef(new FontFace(context, family, descripto rs)); 71 RefPtr<FontFace> fontFace = adoptRef(new FontFace(context, family));
74 72
75 RefPtr<CSSValue> src = parseCSSValue(toDocument(context), source, CSSPropert ySrc); 73 RefPtr<CSSValue> src = parseCSSValue(toDocument(context), source, CSSPropert ySrc);
76 if (!src || !src->isValueList()) 74 if (!src || !src->isValueList())
77 fontFace->setError(DOMException::create(SyntaxError, "The source provide d ('" + source + "') could not be parsed as a value list.")); 75 fontFace->setError(DOMException::create(SyntaxError, "The source provide d ('" + source + "') could not be parsed as a value list."));
78 76
79 fontFace->initCSSFontFace(toDocument(context), src); 77 fontFace->initCSSFontFace(toDocument(context), src);
80 return fontFace.release(); 78 return fontFace.release();
81 } 79 }
82 80
83 PassRefPtr<FontFace> FontFace::create(ExecutionContext* context, const AtomicStr ing& family, PassRefPtr<ArrayBuffer> source, const Dictionary& descriptors) 81 PassRefPtr<FontFace> FontFace::create(ExecutionContext* context, const AtomicStr ing& family, PassRefPtr<ArrayBuffer> source)
84 { 82 {
85 RefPtr<FontFace> fontFace = adoptRef(new FontFace(context, family, descripto rs)); 83 RefPtr<FontFace> fontFace = adoptRef(new FontFace(context, family));
86 fontFace->initCSSFontFace(static_cast<const unsigned char*>(source->data()), source->byteLength()); 84 fontFace->initCSSFontFace(static_cast<const unsigned char*>(source->data()), source->byteLength());
87 return fontFace.release(); 85 return fontFace.release();
88 } 86 }
89 87
90 PassRefPtr<FontFace> FontFace::create(ExecutionContext* context, const AtomicStr ing& family, PassRefPtr<ArrayBufferView> source, const Dictionary& descriptors) 88 PassRefPtr<FontFace> FontFace::create(ExecutionContext* context, const AtomicStr ing& family, PassRefPtr<ArrayBufferView> source)
91 { 89 {
92 RefPtr<FontFace> fontFace = adoptRef(new FontFace(context, family, descripto rs)); 90 RefPtr<FontFace> fontFace = adoptRef(new FontFace(context, family));
93 fontFace->initCSSFontFace(static_cast<const unsigned char*>(source->baseAddr ess()), source->byteLength()); 91 fontFace->initCSSFontFace(static_cast<const unsigned char*>(source->baseAddr ess()), source->byteLength());
94 return fontFace.release(); 92 return fontFace.release();
95 } 93 }
96 94
97 PassRefPtr<FontFace> FontFace::create(Document* document, const StyleRuleFontFac e* fontFaceRule) 95 PassRefPtr<FontFace> FontFace::create(Document* document, const StyleRuleFontFac e* fontFaceRule)
98 { 96 {
99 const StylePropertySet& properties = fontFaceRule->properties(); 97 const StylePropertySet& properties = fontFaceRule->properties();
100 98
101 // Obtain the font-family property and the src property. Both must be define d. 99 // Obtain the font-family property and the src property. Both must be define d.
102 RefPtr<CSSValue> family = properties.getPropertyCSSValue(CSSPropertyFontFami ly); 100 RefPtr<CSSValue> family = properties.getPropertyCSSValue(CSSPropertyFontFami ly);
(...skipping 18 matching lines...) Expand all
121 return fontFace.release(); 119 return fontFace.release();
122 } 120 }
123 return nullptr; 121 return nullptr;
124 } 122 }
125 123
126 FontFace::FontFace() 124 FontFace::FontFace()
127 : m_status(Unloaded) 125 : m_status(Unloaded)
128 { 126 {
129 } 127 }
130 128
131 FontFace::FontFace(ExecutionContext* context, const AtomicString& family, const Dictionary& descriptors) 129 FontFace::FontFace(ExecutionContext* context, const AtomicString& family)
132 : m_family(family) 130 : m_family(family)
133 , m_status(Unloaded) 131 , m_status(Unloaded)
134 { 132 {
135 Document* document = toDocument(context);
136 String value;
137 if (DictionaryHelper::get(descriptors, "style", value))
138 setPropertyFromString(document, value, CSSPropertyFontStyle);
139 if (DictionaryHelper::get(descriptors, "weight", value))
140 setPropertyFromString(document, value, CSSPropertyFontWeight);
141 if (DictionaryHelper::get(descriptors, "stretch", value))
142 setPropertyFromString(document, value, CSSPropertyFontStretch);
143 if (DictionaryHelper::get(descriptors, "unicodeRange", value))
144 setPropertyFromString(document, value, CSSPropertyUnicodeRange);
145 if (DictionaryHelper::get(descriptors, "variant", value))
146 setPropertyFromString(document, value, CSSPropertyFontVariant);
147 if (DictionaryHelper::get(descriptors, "featureSettings", value))
148 setPropertyFromString(document, value, CSSPropertyWebkitFontFeatureSetti ngs);
149 } 133 }
150 134
151 FontFace::~FontFace() 135 FontFace::~FontFace()
152 { 136 {
153 } 137 }
154 138
155 String FontFace::style() const 139 String FontFace::style() const
156 { 140 {
157 return m_style ? m_style->cssText() : "normal"; 141 return m_style ? m_style->cssText() : "normal";
158 } 142 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 } 197 }
214 198
215 void FontFace::setPropertyFromString(const Document* document, const String& s, CSSPropertyID propertyID, ExceptionState* exceptionState) 199 void FontFace::setPropertyFromString(const Document* document, const String& s, CSSPropertyID propertyID, ExceptionState* exceptionState)
216 { 200 {
217 RefPtr<CSSValue> value = parseCSSValue(document, s, propertyID); 201 RefPtr<CSSValue> value = parseCSSValue(document, s, propertyID);
218 if (value && setPropertyValue(value, propertyID)) 202 if (value && setPropertyValue(value, propertyID))
219 return; 203 return;
220 204
221 String message = "Failed to set '" + s + "' as a property value."; 205 String message = "Failed to set '" + s + "' as a property value.";
222 if (exceptionState) 206 if (exceptionState)
223 exceptionState->throwDOMException(SyntaxError, message); 207 exceptionState->ThrowDOMException(SyntaxError, message);
224 else 208 else
225 setError(DOMException::create(SyntaxError, message)); 209 setError(DOMException::create(SyntaxError, message));
226 } 210 }
227 211
228 bool FontFace::setPropertyFromStyle(const StylePropertySet& properties, CSSPrope rtyID propertyID) 212 bool FontFace::setPropertyFromStyle(const StylePropertySet& properties, CSSPrope rtyID propertyID)
229 { 213 {
230 return setPropertyValue(properties.getPropertyCSSValue(propertyID), property ID); 214 return setPropertyValue(properties.getPropertyCSSValue(propertyID), property ID);
231 } 215 }
232 216
233 bool FontFace::setPropertyValue(PassRefPtr<CSSValue> value, CSSPropertyID proper tyID) 217 bool FontFace::setPropertyValue(PassRefPtr<CSSValue> value, CSSPropertyID proper tyID)
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 } 300 }
317 return emptyString(); 301 return emptyString();
318 } 302 }
319 303
320 void FontFace::setLoadStatus(LoadStatus status) 304 void FontFace::setLoadStatus(LoadStatus status)
321 { 305 {
322 m_status = status; 306 m_status = status;
323 ASSERT(m_status != Error || m_error); 307 ASSERT(m_status != Error || m_error);
324 308
325 if (m_status == Loaded || m_status == Error) { 309 if (m_status == Loaded || m_status == Error) {
326 if (m_loadedProperty) {
327 if (m_status == Loaded)
328 m_loadedProperty->resolve(this);
329 else
330 m_loadedProperty->reject(m_error.get());
331 }
332
333 Vector<RefPtr<LoadFontCallback> > callbacks; 310 Vector<RefPtr<LoadFontCallback> > callbacks;
334 m_callbacks.swap(callbacks); 311 m_callbacks.swap(callbacks);
335 for (size_t i = 0; i < callbacks.size(); ++i) { 312 for (size_t i = 0; i < callbacks.size(); ++i) {
336 if (m_status == Loaded) 313 if (m_status == Loaded)
337 callbacks[i]->notifyLoaded(this); 314 callbacks[i]->notifyLoaded(this);
338 else 315 else
339 callbacks[i]->notifyError(this); 316 callbacks[i]->notifyError(this);
340 } 317 }
341 } 318 }
342 } 319 }
343 320
344 void FontFace::setError(PassRefPtr<DOMException> error) 321 void FontFace::setError(PassRefPtr<DOMException> error)
345 { 322 {
346 if (!m_error) 323 if (!m_error)
347 m_error = error ? error : DOMException::create(NetworkError); 324 m_error = error ? error : DOMException::create(NetworkError);
348 setLoadStatus(Error); 325 setLoadStatus(Error);
349 } 326 }
350 327
351 ScriptPromise FontFace::fontStatusPromise(ScriptState* scriptState)
352 {
353 if (!m_loadedProperty) {
354 m_loadedProperty = adoptPtr(new LoadedProperty(scriptState->executionCon text(), this, LoadedProperty::Loaded));
355 if (m_status == Loaded)
356 m_loadedProperty->resolve(this);
357 else if (m_status == Error)
358 m_loadedProperty->reject(m_error.get());
359 }
360 return m_loadedProperty->promise(scriptState->world());
361 }
362
363 ScriptPromise FontFace::load(ScriptState* scriptState)
364 {
365 loadInternal(scriptState->executionContext());
366 return fontStatusPromise(scriptState);
367 }
368
369 void FontFace::loadWithCallback(PassRefPtr<LoadFontCallback> callback, Execution Context* context) 328 void FontFace::loadWithCallback(PassRefPtr<LoadFontCallback> callback, Execution Context* context)
370 { 329 {
371 loadInternal(context); 330 loadInternal(context);
372 if (m_status == Loaded) 331 if (m_status == Loaded)
373 callback->notifyLoaded(this); 332 callback->notifyLoaded(this);
374 else if (m_status == Error) 333 else if (m_status == Error)
375 callback->notifyError(this); 334 callback->notifyError(this);
376 else 335 else
377 m_callbacks.append(callback); 336 m_callbacks.append(callback);
378 } 337 }
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 setError(DOMException::create(SyntaxError, "Invalid font data in ArrayBu ffer.")); 504 setError(DOMException::create(SyntaxError, "Invalid font data in ArrayBu ffer."));
546 m_cssFontFace->addSource(source.release()); 505 m_cssFontFace->addSource(source.release());
547 } 506 }
548 507
549 bool FontFace::hadBlankText() const 508 bool FontFace::hadBlankText() const
550 { 509 {
551 return m_cssFontFace->hadBlankText(); 510 return m_cssFontFace->hadBlankText();
552 } 511 }
553 512
554 } // namespace blink 513 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/css/FontFace.h ('k') | sky/engine/core/css/FontFace.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698