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 "CSSPropertyNames.h"
35#include "bindings/v8/ScriptPromise.h"
36#include "core/css/CSSValue.h"
37#include "wtf/PassRefPtr.h"
38#include "wtf/RefCounted.h"
39#include "wtf/text/WTFString.h"
40
41namespace WebCore {
42
43class CSSFontFace;
44class CSSValueList;
45class Dictionary;
46class Document;
47class ExceptionState;
48class FontFaceReadyPromiseResolver;
49class StylePropertySet;
50class StyleRuleFontFace;
51
52class FontFace : public RefCounted<FontFace> {
53public:
54    enum LoadStatus { Unloaded, Loading, Loaded, Error };
55
56    static PassRefPtr<FontFace> create(const AtomicString& family, const String& source, const Dictionary&, ExceptionState&);
57    static PassRefPtr<FontFace> create(const StyleRuleFontFace*);
58
59    ~FontFace();
60
61    const AtomicString& family() const { return m_family; }
62    String style() const;
63    String weight() const;
64    String stretch() const;
65    String unicodeRange() const;
66    String variant() const;
67    String featureSettings() const;
68
69    // FIXME: Changing these attributes should affect font matching.
70    void setFamily(const AtomicString& s, ExceptionState&) { m_family = s; }
71    void setStyle(const String&, ExceptionState&);
72    void setWeight(const String&, ExceptionState&);
73    void setStretch(const String&, ExceptionState&);
74    void setUnicodeRange(const String&, ExceptionState&);
75    void setVariant(const String&, ExceptionState&);
76    void setFeatureSettings(const String&, ExceptionState&);
77
78    String status() const;
79
80    void load();
81    ScriptPromise ready(ExecutionContext*);
82
83    LoadStatus loadStatus() const { return m_status; }
84    void setLoadStatus(LoadStatus);
85    unsigned traitsMask() const;
86    PassRefPtr<CSSFontFace> createCSSFontFace(Document*);
87    void cssFontFaceDestroyed() { m_cssFontFace = 0; }
88
89private:
90    FontFace(PassRefPtr<CSSValue> source);
91
92    void setPropertyFromString(const String&, CSSPropertyID, ExceptionState&);
93    bool setPropertyFromStyle(const StylePropertySet*, CSSPropertyID);
94    bool setPropertyValue(PassRefPtr<CSSValue>, CSSPropertyID);
95    bool setFamilyValue(CSSValueList*);
96    void resolveReadyPromises();
97
98    AtomicString m_family;
99    RefPtr<CSSValue> m_src;
100    RefPtr<CSSValue> m_style;
101    RefPtr<CSSValue> m_weight;
102    RefPtr<CSSValue> m_stretch;
103    RefPtr<CSSValue> m_unicodeRange;
104    RefPtr<CSSValue> m_variant;
105    RefPtr<CSSValue> m_featureSettings;
106    LoadStatus m_status;
107
108    Vector<OwnPtr<FontFaceReadyPromiseResolver> > m_readyResolvers;
109    CSSFontFace* m_cssFontFace;
110};
111
112typedef Vector<RefPtr<FontFace> > FontFaceArray;
113
114} // namespace WebCore
115
116#endif // FontFace_h
117