Bug 1879449 [wpt PR 44489] - [wptrunner] Add `infrastructure/expected-fail/` test...
[gecko.git] / layout / style / PostTraversalTask.h
blob64d67b0227c8b800bc6cdaa67dee545e335757e0
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_PostTraversalTask_h
8 #define mozilla_PostTraversalTask_h
10 #include "nscore.h"
12 /* a task to be performed immediately after a Servo traversal */
14 namespace mozilla {
15 class ServoStyleSet;
16 namespace dom {
17 class FontFace;
18 class FontFaceSet;
19 class FontFaceSetImpl;
20 } // namespace dom
21 namespace fontlist {
22 struct Family;
23 } // namespace fontlist
24 } // namespace mozilla
25 class gfxUserFontEntry;
27 namespace mozilla {
29 /**
30 * A PostTraversalTask is a task to be performed immediately after a Servo
31 * traversal. There are just a few tasks we need to perform, so we use this
32 * class rather than Runnables, to avoid virtual calls and some allocations.
34 * A PostTraversalTask is only safe to run immediately after the Servo
35 * traversal, since it can hold raw pointers to DOM objects.
37 class PostTraversalTask {
38 public:
39 static PostTraversalTask ResolveFontFaceLoadedPromise(
40 dom::FontFace* aFontFace) {
41 auto task = PostTraversalTask(Type::ResolveFontFaceLoadedPromise);
42 task.mTarget = aFontFace;
43 return task;
46 static PostTraversalTask RejectFontFaceLoadedPromise(dom::FontFace* aFontFace,
47 nsresult aResult) {
48 auto task = PostTraversalTask(Type::ResolveFontFaceLoadedPromise);
49 task.mTarget = aFontFace;
50 task.mResult = aResult;
51 return task;
54 static PostTraversalTask DispatchLoadingEventAndReplaceReadyPromise(
55 dom::FontFaceSet* aFontFaceSet) {
56 auto task =
57 PostTraversalTask(Type::DispatchLoadingEventAndReplaceReadyPromise);
58 task.mTarget = aFontFaceSet;
59 return task;
62 static PostTraversalTask DispatchFontFaceSetCheckLoadingFinishedAfterDelay(
63 dom::FontFaceSetImpl* aFontFaceSet) {
64 auto task = PostTraversalTask(
65 Type::DispatchFontFaceSetCheckLoadingFinishedAfterDelay);
66 task.mTarget = aFontFaceSet;
67 return task;
70 static PostTraversalTask LoadFontEntry(gfxUserFontEntry* aFontEntry) {
71 auto task = PostTraversalTask(Type::LoadFontEntry);
72 task.mTarget = aFontEntry;
73 return task;
76 static PostTraversalTask InitializeFamily(fontlist::Family* aFamily) {
77 auto task = PostTraversalTask(Type::InitializeFamily);
78 task.mTarget = aFamily;
79 return task;
82 static PostTraversalTask FontInfoUpdate(ServoStyleSet* aSet) {
83 auto task = PostTraversalTask(Type::FontInfoUpdate);
84 task.mTarget = aSet;
85 return task;
88 void Run();
90 private:
91 // For any new raw pointer type that we need to store in a PostTraversalTask,
92 // please add an assertion that class' destructor that we are not in a Servo
93 // traversal, to protect against the possibility of having dangling pointers.
94 enum class Type {
95 // mTarget (FontFace*)
96 ResolveFontFaceLoadedPromise,
98 // mTarget (FontFace*)
99 // mResult
100 RejectFontFaceLoadedPromise,
102 // mTarget (FontFaceSet*)
103 DispatchLoadingEventAndReplaceReadyPromise,
105 // mTarget (FontFaceSetImpl*)
106 DispatchFontFaceSetCheckLoadingFinishedAfterDelay,
108 // mTarget (gfxUserFontEntry*)
109 LoadFontEntry,
111 // mTarget (fontlist::Family*)
112 InitializeFamily,
114 // mTarget (ServoStyleSet*)
115 FontInfoUpdate,
118 explicit PostTraversalTask(Type aType)
119 : mType(aType), mTarget(nullptr), mResult(NS_OK) {}
121 Type mType;
122 void* mTarget;
123 nsresult mResult;
126 } // namespace mozilla
128 #endif // mozilla_PostTraversalTask_h