1/*
2 * Copyright (C) 2007, 2008, 2016 Apple 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
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#pragma once
27
28#include "CSSFontFace.h"
29#include "CSSPropertyNames.h"
30#include "DOMPromiseProxy.h"
31#include <wtf/Variant.h>
32#include <wtf/WeakPtr.h>
33
34namespace JSC {
35class ArrayBuffer;
36class ArrayBufferView;
37}
38
39namespace WebCore {
40
41class FontFace final : public RefCounted<FontFace>, public CanMakeWeakPtr<FontFace>, private CSSFontFace::Client {
42public:
43 struct Descriptors {
44 String style;
45 String weight;
46 String stretch;
47 String unicodeRange;
48 String variant;
49 String featureSettings;
50 String display;
51 };
52
53 using Source = Variant<String, RefPtr<JSC::ArrayBuffer>, RefPtr<JSC::ArrayBufferView>>;
54 static ExceptionOr<Ref<FontFace>> create(Document&, const String& family, Source&&, const Descriptors&);
55 static Ref<FontFace> create(CSSFontFace&);
56 virtual ~FontFace();
57
58 ExceptionOr<void> setFamily(const String&);
59 ExceptionOr<void> setStyle(const String&);
60 ExceptionOr<void> setWeight(const String&);
61 ExceptionOr<void> setStretch(const String&);
62 ExceptionOr<void> setUnicodeRange(const String&);
63 ExceptionOr<void> setVariant(const String&);
64 ExceptionOr<void> setFeatureSettings(const String&);
65 ExceptionOr<void> setDisplay(const String&);
66
67 String family() const;
68 String style() const;
69 String weight() const;
70 String stretch() const;
71 String unicodeRange() const;
72 String variant() const;
73 String featureSettings() const;
74 String display() const;
75
76 enum class LoadStatus { Unloaded, Loading, Loaded, Error };
77 LoadStatus status() const;
78
79 using LoadedPromise = DOMPromiseProxyWithResolveCallback<IDLInterface<FontFace>>;
80 LoadedPromise& loaded() { return m_loadedPromise; }
81 LoadedPromise& load();
82
83 void adopt(CSSFontFace&);
84
85 CSSFontFace& backing() { return m_backing; }
86
87 static RefPtr<CSSValue> parseString(const String&, CSSPropertyID);
88
89 void fontStateChanged(CSSFontFace&, CSSFontFace::Status oldState, CSSFontFace::Status newState) final;
90
91 void ref() final { RefCounted::ref(); }
92 void deref() final { RefCounted::deref(); }
93
94private:
95 explicit FontFace(CSSFontSelector&);
96 explicit FontFace(CSSFontFace&);
97
98 // Callback for LoadedPromise.
99 FontFace& loadedPromiseResolve();
100
101 Ref<CSSFontFace> m_backing;
102 LoadedPromise m_loadedPromise;
103};
104
105}
106