Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / css / FontFace.h
1 /*
2  * Copyright (C) 2013 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
29  */
30
31 #ifndef FontFace_h
32 #define FontFace_h
33
34 #include "bindings/core/v8/ScriptPromise.h"
35 #include "bindings/core/v8/ScriptPromiseProperty.h"
36 #include "bindings/core/v8/ScriptWrappable.h"
37 #include "core/CSSPropertyNames.h"
38 #include "core/css/CSSValue.h"
39 #include "core/dom/ActiveDOMObject.h"
40 #include "core/dom/DOMException.h"
41 #include "platform/fonts/FontTraits.h"
42 #include "wtf/PassRefPtr.h"
43 #include "wtf/RefCounted.h"
44 #include "wtf/text/WTFString.h"
45
46 namespace blink {
47
48 class CSSFontFace;
49 class CSSValueList;
50 class DOMArrayBuffer;
51 class DOMArrayBufferView;
52 class Dictionary;
53 class Document;
54 class ExceptionState;
55 class FontFaceDescriptors;
56 class StringOrArrayBufferOrArrayBufferView;
57 class StylePropertySet;
58 class StyleRuleFontFace;
59
60 class FontFace : public RefCountedWillBeGarbageCollectedFinalized<FontFace>, public ScriptWrappable, public ActiveDOMObject {
61     DEFINE_WRAPPERTYPEINFO();
62 public:
63     enum LoadStatus { Unloaded, Loading, Loaded, Error };
64
65     static PassRefPtrWillBeRawPtr<FontFace> create(ExecutionContext*, const AtomicString& family, StringOrArrayBufferOrArrayBufferView&, const FontFaceDescriptors&);
66     static PassRefPtrWillBeRawPtr<FontFace> create(Document*, const StyleRuleFontFace*);
67
68     ~FontFace();
69
70     const AtomicString& family() const { return m_family; }
71     String style() const;
72     String weight() const;
73     String stretch() const;
74     String unicodeRange() const;
75     String variant() const;
76     String featureSettings() const;
77
78     // FIXME: Changing these attributes should affect font matching.
79     void setFamily(ExecutionContext*, const AtomicString& s, ExceptionState&) { m_family = s; }
80     void setStyle(ExecutionContext*, const String&, ExceptionState&);
81     void setWeight(ExecutionContext*, const String&, ExceptionState&);
82     void setStretch(ExecutionContext*, const String&, ExceptionState&);
83     void setUnicodeRange(ExecutionContext*, const String&, ExceptionState&);
84     void setVariant(ExecutionContext*, const String&, ExceptionState&);
85     void setFeatureSettings(ExecutionContext*, const String&, ExceptionState&);
86
87     String status() const;
88     ScriptPromise loaded(ScriptState* scriptState) { return fontStatusPromise(scriptState); }
89
90     ScriptPromise load(ScriptState*);
91
92     LoadStatus loadStatus() const { return m_status; }
93     void setLoadStatus(LoadStatus);
94     void setError(PassRefPtrWillBeRawPtr<DOMException> = nullptr);
95     DOMException* error() const { return m_error.get(); }
96     FontTraits traits() const;
97     CSSFontFace* cssFontFace() { return m_cssFontFace.get(); }
98
99     void trace(Visitor*);
100
101     bool hadBlankText() const;
102
103     class LoadFontCallback : public RefCountedWillBeGarbageCollectedFinalized<LoadFontCallback> {
104     public:
105         virtual ~LoadFontCallback() { }
106         virtual void notifyLoaded(FontFace*) = 0;
107         virtual void notifyError(FontFace*) = 0;
108         virtual void trace(Visitor*) { }
109     };
110     void loadWithCallback(PassRefPtrWillBeRawPtr<LoadFontCallback>, ExecutionContext*);
111
112     // ActiveDOMObject
113     virtual bool hasPendingActivity() const override;
114
115 private:
116     static PassRefPtrWillBeRawPtr<FontFace> create(ExecutionContext*, const AtomicString& family, PassRefPtr<DOMArrayBuffer> source, const FontFaceDescriptors&);
117     static PassRefPtrWillBeRawPtr<FontFace> create(ExecutionContext*, const AtomicString& family, PassRefPtr<DOMArrayBufferView>, const FontFaceDescriptors&);
118     static PassRefPtrWillBeRawPtr<FontFace> create(ExecutionContext*, const AtomicString& family, const String& source, const FontFaceDescriptors&);
119
120     explicit FontFace(ExecutionContext*);
121     FontFace(ExecutionContext*, const AtomicString& family, const FontFaceDescriptors&);
122
123     void initCSSFontFace(Document*, PassRefPtrWillBeRawPtr<CSSValue> src);
124     void initCSSFontFace(const unsigned char* data, unsigned size);
125     void setPropertyFromString(const Document*, const String&, CSSPropertyID, ExceptionState* = 0);
126     bool setPropertyFromStyle(const StylePropertySet&, CSSPropertyID);
127     bool setPropertyValue(PassRefPtrWillBeRawPtr<CSSValue>, CSSPropertyID);
128     bool setFamilyValue(CSSValueList*);
129     void loadInternal(ExecutionContext*);
130     ScriptPromise fontStatusPromise(ScriptState*);
131
132     typedef ScriptPromiseProperty<RawPtrWillBeMember<FontFace>, RawPtrWillBeMember<FontFace>, RefPtrWillBeMember<DOMException> > LoadedProperty;
133
134     AtomicString m_family;
135     RefPtrWillBeMember<CSSValue> m_src;
136     RefPtrWillBeMember<CSSValue> m_style;
137     RefPtrWillBeMember<CSSValue> m_weight;
138     RefPtrWillBeMember<CSSValue> m_stretch;
139     RefPtrWillBeMember<CSSValue> m_unicodeRange;
140     RefPtrWillBeMember<CSSValue> m_variant;
141     RefPtrWillBeMember<CSSValue> m_featureSettings;
142     LoadStatus m_status;
143     RefPtrWillBeMember<DOMException> m_error;
144
145     PersistentWillBeMember<LoadedProperty> m_loadedProperty;
146     OwnPtrWillBeMember<CSSFontFace> m_cssFontFace;
147     WillBeHeapVector<RefPtrWillBeMember<LoadFontCallback> > m_callbacks;
148 };
149
150 typedef WillBeHeapVector<RefPtrWillBeMember<FontFace> > FontFaceArray;
151
152 } // namespace blink
153
154 #endif // FontFace_h