| 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 14 matching lines...) Expand all Loading... |
| 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 #ifndef SKY_ENGINE_CORE_CSS_FONTFACE_H_ | 31 #ifndef SKY_ENGINE_CORE_CSS_FONTFACE_H_ |
| 32 #define SKY_ENGINE_CORE_CSS_FONTFACE_H_ | 32 #define SKY_ENGINE_CORE_CSS_FONTFACE_H_ |
| 33 | 33 |
| 34 #include "gen/sky/core/CSSPropertyNames.h" | 34 #include "gen/sky/core/CSSPropertyNames.h" |
| 35 #include "sky/engine/bindings/core/v8/ScriptPromise.h" | 35 #include "sky/engine/tonic/dart_wrappable.h" |
| 36 #include "sky/engine/bindings/core/v8/ScriptPromiseProperty.h" | |
| 37 #include "sky/engine/bindings/core/v8/ScriptWrappable.h" | |
| 38 #include "sky/engine/core/css/CSSValue.h" | 36 #include "sky/engine/core/css/CSSValue.h" |
| 39 #include "sky/engine/core/dom/DOMException.h" | 37 #include "sky/engine/core/dom/DOMException.h" |
| 40 #include "sky/engine/platform/fonts/FontTraits.h" | 38 #include "sky/engine/platform/fonts/FontTraits.h" |
| 41 #include "sky/engine/wtf/PassRefPtr.h" | 39 #include "sky/engine/wtf/PassRefPtr.h" |
| 42 #include "sky/engine/wtf/RefCounted.h" | 40 #include "sky/engine/wtf/RefCounted.h" |
| 43 #include "sky/engine/wtf/text/WTFString.h" | 41 #include "sky/engine/wtf/text/WTFString.h" |
| 44 | 42 |
| 45 namespace blink { | 43 namespace blink { |
| 46 | 44 |
| 47 class CSSFontFace; | 45 class CSSFontFace; |
| 48 class CSSValueList; | 46 class CSSValueList; |
| 49 class Dictionary; | |
| 50 class Document; | 47 class Document; |
| 51 class ExceptionState; | 48 class ExceptionState; |
| 49 class ExecutionContext; |
| 52 class FontFaceReadyPromiseResolver; | 50 class FontFaceReadyPromiseResolver; |
| 53 class StylePropertySet; | 51 class StylePropertySet; |
| 54 class StyleRuleFontFace; | 52 class StyleRuleFontFace; |
| 55 | 53 |
| 56 class FontFace : public RefCounted<FontFace>, public ScriptWrappable { | 54 class FontFace : public RefCounted<FontFace>, public DartWrappable { |
| 57 DEFINE_WRAPPERTYPEINFO(); | 55 DEFINE_WRAPPERTYPEINFO(); |
| 58 public: | 56 public: |
| 59 enum LoadStatus { Unloaded, Loading, Loaded, Error }; | 57 enum LoadStatus { Unloaded, Loading, Loaded, Error }; |
| 60 | 58 |
| 61 static PassRefPtr<FontFace> create(ExecutionContext*, const AtomicString& fa
mily, PassRefPtr<ArrayBuffer> source, const Dictionary&); | 59 static PassRefPtr<FontFace> create(ExecutionContext*, const AtomicString& fa
mily, PassRefPtr<ArrayBuffer> source); |
| 62 static PassRefPtr<FontFace> create(ExecutionContext*, const AtomicString& fa
mily, PassRefPtr<ArrayBufferView>, const Dictionary&); | 60 static PassRefPtr<FontFace> create(ExecutionContext*, const AtomicString& fa
mily, PassRefPtr<ArrayBufferView>); |
| 63 static PassRefPtr<FontFace> create(ExecutionContext*, const AtomicString& fa
mily, const String& source, const Dictionary&); | 61 static PassRefPtr<FontFace> create(ExecutionContext*, const AtomicString& fa
mily, const String& source); |
| 64 static PassRefPtr<FontFace> create(Document*, const StyleRuleFontFace*); | 62 static PassRefPtr<FontFace> create(Document*, const StyleRuleFontFace*); |
| 65 | 63 |
| 66 ~FontFace(); | 64 ~FontFace(); |
| 67 | 65 |
| 68 const AtomicString& family() const { return m_family; } | 66 const AtomicString& family() const { return m_family; } |
| 69 String style() const; | 67 String style() const; |
| 70 String weight() const; | 68 String weight() const; |
| 71 String stretch() const; | 69 String stretch() const; |
| 72 String unicodeRange() const; | 70 String unicodeRange() const; |
| 73 String variant() const; | 71 String variant() const; |
| 74 String featureSettings() const; | 72 String featureSettings() const; |
| 75 | 73 |
| 76 // FIXME: Changing these attributes should affect font matching. | 74 // FIXME: Changing these attributes should affect font matching. |
| 77 void setFamily(ExecutionContext*, const AtomicString& s, ExceptionState&) {
m_family = s; } | 75 void setFamily(ExecutionContext*, const AtomicString& s, ExceptionState&) {
m_family = s; } |
| 78 void setStyle(ExecutionContext*, const String&, ExceptionState&); | 76 void setStyle(ExecutionContext*, const String&, ExceptionState&); |
| 79 void setWeight(ExecutionContext*, const String&, ExceptionState&); | 77 void setWeight(ExecutionContext*, const String&, ExceptionState&); |
| 80 void setStretch(ExecutionContext*, const String&, ExceptionState&); | 78 void setStretch(ExecutionContext*, const String&, ExceptionState&); |
| 81 void setUnicodeRange(ExecutionContext*, const String&, ExceptionState&); | 79 void setUnicodeRange(ExecutionContext*, const String&, ExceptionState&); |
| 82 void setVariant(ExecutionContext*, const String&, ExceptionState&); | 80 void setVariant(ExecutionContext*, const String&, ExceptionState&); |
| 83 void setFeatureSettings(ExecutionContext*, const String&, ExceptionState&); | 81 void setFeatureSettings(ExecutionContext*, const String&, ExceptionState&); |
| 84 | 82 |
| 85 String status() const; | 83 String status() const; |
| 86 ScriptPromise loaded(ScriptState* scriptState) { return fontStatusPromise(sc
riptState); } | |
| 87 | |
| 88 ScriptPromise load(ScriptState*); | |
| 89 | 84 |
| 90 LoadStatus loadStatus() const { return m_status; } | 85 LoadStatus loadStatus() const { return m_status; } |
| 91 void setLoadStatus(LoadStatus); | 86 void setLoadStatus(LoadStatus); |
| 92 void setError(PassRefPtr<DOMException> = nullptr); | 87 void setError(PassRefPtr<DOMException> = nullptr); |
| 93 DOMException* error() const { return m_error.get(); } | 88 DOMException* error() const { return m_error.get(); } |
| 94 FontTraits traits() const; | 89 FontTraits traits() const; |
| 95 CSSFontFace* cssFontFace() { return m_cssFontFace.get(); } | 90 CSSFontFace* cssFontFace() { return m_cssFontFace.get(); } |
| 96 | 91 |
| 97 bool hadBlankText() const; | 92 bool hadBlankText() const; |
| 98 | 93 |
| 99 class LoadFontCallback : public RefCounted<LoadFontCallback> { | 94 class LoadFontCallback : public RefCounted<LoadFontCallback> { |
| 100 public: | 95 public: |
| 101 virtual ~LoadFontCallback() { } | 96 virtual ~LoadFontCallback() { } |
| 102 virtual void notifyLoaded(FontFace*) = 0; | 97 virtual void notifyLoaded(FontFace*) = 0; |
| 103 virtual void notifyError(FontFace*) = 0; | 98 virtual void notifyError(FontFace*) = 0; |
| 104 }; | 99 }; |
| 105 void loadWithCallback(PassRefPtr<LoadFontCallback>, ExecutionContext*); | 100 void loadWithCallback(PassRefPtr<LoadFontCallback>, ExecutionContext*); |
| 106 | 101 |
| 107 private: | 102 private: |
| 108 FontFace(); | 103 FontFace(); |
| 109 FontFace(ExecutionContext*, const AtomicString& family, const Dictionary& de
scriptors); | 104 FontFace(ExecutionContext*, const AtomicString& family); |
| 110 | 105 |
| 111 void initCSSFontFace(Document*, PassRefPtr<CSSValue> src); | 106 void initCSSFontFace(Document*, PassRefPtr<CSSValue> src); |
| 112 void initCSSFontFace(const unsigned char* data, unsigned size); | 107 void initCSSFontFace(const unsigned char* data, unsigned size); |
| 113 void setPropertyFromString(const Document*, const String&, CSSPropertyID, Ex
ceptionState* = 0); | 108 void setPropertyFromString(const Document*, const String&, CSSPropertyID, Ex
ceptionState* = 0); |
| 114 bool setPropertyFromStyle(const StylePropertySet&, CSSPropertyID); | 109 bool setPropertyFromStyle(const StylePropertySet&, CSSPropertyID); |
| 115 bool setPropertyValue(PassRefPtr<CSSValue>, CSSPropertyID); | 110 bool setPropertyValue(PassRefPtr<CSSValue>, CSSPropertyID); |
| 116 bool setFamilyValue(CSSValueList*); | 111 bool setFamilyValue(CSSValueList*); |
| 117 void loadInternal(ExecutionContext*); | 112 void loadInternal(ExecutionContext*); |
| 118 ScriptPromise fontStatusPromise(ScriptState*); | |
| 119 | |
| 120 typedef ScriptPromiseProperty<RawPtr<FontFace>, RawPtr<FontFace>, RefPtr<DOM
Exception> > LoadedProperty; | |
| 121 | 113 |
| 122 AtomicString m_family; | 114 AtomicString m_family; |
| 123 RefPtr<CSSValue> m_src; | 115 RefPtr<CSSValue> m_src; |
| 124 RefPtr<CSSValue> m_style; | 116 RefPtr<CSSValue> m_style; |
| 125 RefPtr<CSSValue> m_weight; | 117 RefPtr<CSSValue> m_weight; |
| 126 RefPtr<CSSValue> m_stretch; | 118 RefPtr<CSSValue> m_stretch; |
| 127 RefPtr<CSSValue> m_unicodeRange; | 119 RefPtr<CSSValue> m_unicodeRange; |
| 128 RefPtr<CSSValue> m_variant; | 120 RefPtr<CSSValue> m_variant; |
| 129 RefPtr<CSSValue> m_featureSettings; | 121 RefPtr<CSSValue> m_featureSettings; |
| 130 LoadStatus m_status; | 122 LoadStatus m_status; |
| 131 RefPtr<DOMException> m_error; | 123 RefPtr<DOMException> m_error; |
| 132 | 124 |
| 133 OwnPtr<LoadedProperty> m_loadedProperty; | |
| 134 OwnPtr<CSSFontFace> m_cssFontFace; | 125 OwnPtr<CSSFontFace> m_cssFontFace; |
| 135 Vector<RefPtr<LoadFontCallback> > m_callbacks; | 126 Vector<RefPtr<LoadFontCallback> > m_callbacks; |
| 136 }; | 127 }; |
| 137 | 128 |
| 138 typedef Vector<RefPtr<FontFace> > FontFaceArray; | 129 typedef Vector<RefPtr<FontFace> > FontFaceArray; |
| 139 | 130 |
| 140 } // namespace blink | 131 } // namespace blink |
| 141 | 132 |
| 142 #endif // SKY_ENGINE_CORE_CSS_FONTFACE_H_ | 133 #endif // SKY_ENGINE_CORE_CSS_FONTFACE_H_ |
| OLD | NEW |