Bug 1550804 - Add color scheme simulation to the inspector. r=pbro
[gecko.git] / layout / style / PostTraversalTask.h
blobdd96d4a82361cd9d0fedd1f454be62f7fdf6c3da
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 } // namespace dom
20 namespace fontlist {
21 struct Family;
22 } // namespace fontlist
23 } // namespace mozilla
24 class gfxUserFontEntry;
26 namespace mozilla {
28 /**
29 * A PostTraversalTask is a task to be performed immediately after a Servo
30 * traversal. There are just a few tasks we need to perform, so we use this
31 * class rather than Runnables, to avoid virtual calls and some allocations.
33 * A PostTraversalTask is only safe to run immediately after the Servo
34 * traversal, since it can hold raw pointers to DOM objects.
36 class PostTraversalTask {
37 public:
38 static PostTraversalTask ResolveFontFaceLoadedPromise(
39 dom::FontFace* aFontFace) {
40 auto task = PostTraversalTask(Type::ResolveFontFaceLoadedPromise);
41 task.mTarget = aFontFace;
42 return task;
45 static PostTraversalTask RejectFontFaceLoadedPromise(dom::FontFace* aFontFace,
46 nsresult aResult) {
47 auto task = PostTraversalTask(Type::ResolveFontFaceLoadedPromise);
48 task.mTarget = aFontFace;
49 task.mResult = aResult;
50 return task;
53 static PostTraversalTask DispatchLoadingEventAndReplaceReadyPromise(
54 dom::FontFaceSet* aFontFaceSet) {
55 auto task =
56 PostTraversalTask(Type::DispatchLoadingEventAndReplaceReadyPromise);
57 task.mTarget = aFontFaceSet;
58 return task;
61 static PostTraversalTask DispatchFontFaceSetCheckLoadingFinishedAfterDelay(
62 dom::FontFaceSet* aFontFaceSet) {
63 auto task = PostTraversalTask(
64 Type::DispatchFontFaceSetCheckLoadingFinishedAfterDelay);
65 task.mTarget = aFontFaceSet;
66 return task;
69 static PostTraversalTask LoadFontEntry(gfxUserFontEntry* aFontEntry) {
70 auto task = PostTraversalTask(Type::LoadFontEntry);
71 task.mTarget = aFontEntry;
72 return task;
75 static PostTraversalTask InitializeFamily(fontlist::Family* aFamily) {
76 auto task = PostTraversalTask(Type::InitializeFamily);
77 task.mTarget = aFamily;
78 return task;
81 static PostTraversalTask FontInfoUpdate(ServoStyleSet* aSet) {
82 auto task = PostTraversalTask(Type::FontInfoUpdate);
83 task.mTarget = aSet;
84 return task;
87 void Run();
89 private:
90 // For any new raw pointer type that we need to store in a PostTraversalTask,
91 // please add an assertion that class' destructor that we are not in a Servo
92 // traversal, to protect against the possibility of having dangling pointers.
93 enum class Type {
94 // mTarget (FontFace*)
95 ResolveFontFaceLoadedPromise,
97 // mTarget (FontFace*)
98 // mResult
99 RejectFontFaceLoadedPromise,
101 // mTarget (FontFaceSet*)
102 DispatchLoadingEventAndReplaceReadyPromise,
104 // mTarget (FontFaceSet*)
105 DispatchFontFaceSetCheckLoadingFinishedAfterDelay,
107 // mTarget (gfxUserFontEntry*)
108 LoadFontEntry,
110 // mTarget (fontlist::Family*)
111 InitializeFamily,
113 // mTarget (ServoStyleSet*)
114 FontInfoUpdate,
117 explicit PostTraversalTask(Type aType)
118 : mType(aType), mTarget(nullptr), mResult(NS_OK) {}
120 Type mType;
121 void* mTarget;
122 nsresult mResult;
125 } // namespace mozilla
127 #endif // mozilla_PostTraversalTask_h