Backed out 4 changesets (bug 1825722) for causing reftest failures CLOSED TREE
[gecko.git] / layout / style / FontFace.h
blobbdb33a0449df44f2558cace7ff42682197636876
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_FontFace_h
8 #define mozilla_dom_FontFace_h
10 #include "mozilla/dom/FontFaceBinding.h"
11 #include "mozilla/FontPropertyTypes.h"
12 #include "mozilla/Maybe.h"
13 #include "mozilla/ServoStyleConsts.h"
14 #include "gfxUserFontSet.h"
15 #include "nsCSSPropertyID.h"
16 #include "nsCSSValue.h"
17 #include "nsWrapperCache.h"
19 class gfxFontFaceBufferSource;
20 class nsIGlobalObject;
22 namespace mozilla {
23 struct CSSFontFaceDescriptors;
24 class PostTraversalTask;
25 struct StyleLockedFontFaceRule;
27 namespace dom {
28 class CSSFontFaceRule;
29 class FontFaceBufferSource;
30 struct FontFaceDescriptors;
31 class FontFaceImpl;
32 class FontFaceSet;
33 class FontFaceSetImpl;
34 class Promise;
35 class UTF8StringOrArrayBufferOrArrayBufferView;
36 } // namespace dom
37 } // namespace mozilla
39 namespace mozilla::dom {
41 class FontFace final : public nsISupports, public nsWrapperCache {
42 friend class mozilla::PostTraversalTask;
44 public:
45 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
46 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(FontFace)
48 nsIGlobalObject* GetParentObject() const { return mParent; }
49 JSObject* WrapObject(JSContext*, JS::Handle<JSObject*> aGivenProto) override;
51 static already_AddRefed<FontFace> CreateForRule(
52 nsIGlobalObject* aGlobal, FontFaceSet* aFontFaceSet,
53 StyleLockedFontFaceRule* aRule);
55 // Web IDL
56 static already_AddRefed<FontFace> Constructor(
57 const GlobalObject& aGlobal, const nsACString& aFamily,
58 const UTF8StringOrArrayBufferOrArrayBufferView& aSource,
59 const FontFaceDescriptors& aDescriptors, ErrorResult& aRV);
61 void GetFamily(nsACString& aResult);
62 void SetFamily(const nsACString& aValue, ErrorResult& aRv);
63 void GetStyle(nsACString& aResult);
64 void SetStyle(const nsACString& aValue, ErrorResult& aRv);
65 void GetWeight(nsACString& aResult);
66 void SetWeight(const nsACString& aValue, ErrorResult& aRv);
67 void GetStretch(nsACString& aResult);
68 void SetStretch(const nsACString& aValue, ErrorResult& aRv);
69 void GetUnicodeRange(nsACString& aResult);
70 void SetUnicodeRange(const nsACString& aValue, ErrorResult& aRv);
71 void GetVariant(nsACString& aResult);
72 void SetVariant(const nsACString& aValue, ErrorResult& aRv);
73 void GetFeatureSettings(nsACString& aResult);
74 void SetFeatureSettings(const nsACString& aValue, ErrorResult& aRv);
75 void GetVariationSettings(nsACString& aResult);
76 void SetVariationSettings(const nsACString& aValue, ErrorResult& aRv);
77 void GetDisplay(nsACString& aResult);
78 void SetDisplay(const nsACString& aValue, ErrorResult& aRv);
79 void GetAscentOverride(nsACString& aResult);
80 void SetAscentOverride(const nsACString& aValue, ErrorResult& aRv);
81 void GetDescentOverride(nsACString& aResult);
82 void SetDescentOverride(const nsACString& aValue, ErrorResult& aRv);
83 void GetLineGapOverride(nsACString& aResult);
84 void SetLineGapOverride(const nsACString& aValue, ErrorResult& aRv);
85 void GetSizeAdjust(nsACString& aResult);
86 void SetSizeAdjust(const nsACString& aValue, ErrorResult& aRv);
88 FontFaceLoadStatus Status();
89 Promise* Load(ErrorResult& aRv);
90 Promise* GetLoaded(ErrorResult& aRv);
92 FontFaceImpl* GetImpl() const { return mImpl; }
94 void Destroy();
95 void MaybeResolve();
96 void MaybeReject(nsresult aResult);
98 private:
99 explicit FontFace(nsIGlobalObject* aParent);
100 ~FontFace();
103 * Returns and takes ownership of the buffer storing the font data.
105 void TakeBuffer(uint8_t*& aBuffer, uint32_t& aLength);
107 // Creates mLoaded if it doesn't already exist. It may immediately resolve or
108 // reject mLoaded based on mStatus and mLoadedRejection.
109 void EnsurePromise();
111 nsCOMPtr<nsIGlobalObject> mParent;
113 RefPtr<FontFaceImpl> mImpl;
115 // A Promise that is fulfilled once the font represented by this FontFace is
116 // loaded, and is rejected if the load fails. This promise is created lazily
117 // when JS asks for it.
118 RefPtr<Promise> mLoaded;
120 // Saves the rejection code for mLoaded if mLoaded hasn't been created yet.
121 nsresult mLoadedRejection;
124 } // namespace mozilla::dom
126 #endif // !defined(mozilla_dom_FontFace_h)