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
12 /* a task to be performed immediately after a Servo traversal */
19 class FontFaceSetImpl
;
23 } // namespace fontlist
24 } // namespace mozilla
25 class gfxUserFontEntry
;
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
{
39 static PostTraversalTask
ResolveFontFaceLoadedPromise(
40 dom::FontFace
* aFontFace
) {
41 auto task
= PostTraversalTask(Type::ResolveFontFaceLoadedPromise
);
42 task
.mTarget
= aFontFace
;
46 static PostTraversalTask
RejectFontFaceLoadedPromise(dom::FontFace
* aFontFace
,
48 auto task
= PostTraversalTask(Type::ResolveFontFaceLoadedPromise
);
49 task
.mTarget
= aFontFace
;
50 task
.mResult
= aResult
;
54 static PostTraversalTask
DispatchLoadingEventAndReplaceReadyPromise(
55 dom::FontFaceSet
* aFontFaceSet
) {
57 PostTraversalTask(Type::DispatchLoadingEventAndReplaceReadyPromise
);
58 task
.mTarget
= aFontFaceSet
;
62 static PostTraversalTask
DispatchFontFaceSetCheckLoadingFinishedAfterDelay(
63 dom::FontFaceSetImpl
* aFontFaceSet
) {
64 auto task
= PostTraversalTask(
65 Type::DispatchFontFaceSetCheckLoadingFinishedAfterDelay
);
66 task
.mTarget
= aFontFaceSet
;
70 static PostTraversalTask
LoadFontEntry(gfxUserFontEntry
* aFontEntry
) {
71 auto task
= PostTraversalTask(Type::LoadFontEntry
);
72 task
.mTarget
= aFontEntry
;
76 static PostTraversalTask
InitializeFamily(fontlist::Family
* aFamily
) {
77 auto task
= PostTraversalTask(Type::InitializeFamily
);
78 task
.mTarget
= aFamily
;
82 static PostTraversalTask
FontInfoUpdate(ServoStyleSet
* aSet
) {
83 auto task
= PostTraversalTask(Type::FontInfoUpdate
);
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.
95 // mTarget (FontFace*)
96 ResolveFontFaceLoadedPromise
,
98 // mTarget (FontFace*)
100 RejectFontFaceLoadedPromise
,
102 // mTarget (FontFaceSet*)
103 DispatchLoadingEventAndReplaceReadyPromise
,
105 // mTarget (FontFaceSetImpl*)
106 DispatchFontFaceSetCheckLoadingFinishedAfterDelay
,
108 // mTarget (gfxUserFontEntry*)
111 // mTarget (fontlist::Family*)
114 // mTarget (ServoStyleSet*)
118 explicit PostTraversalTask(Type aType
)
119 : mType(aType
), mTarget(nullptr), mResult(NS_OK
) {}
126 } // namespace mozilla
128 #endif // mozilla_PostTraversalTask_h