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 */
22 } // namespace fontlist
23 } // namespace mozilla
24 class gfxUserFontEntry
;
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
{
38 static PostTraversalTask
ResolveFontFaceLoadedPromise(
39 dom::FontFace
* aFontFace
) {
40 auto task
= PostTraversalTask(Type::ResolveFontFaceLoadedPromise
);
41 task
.mTarget
= aFontFace
;
45 static PostTraversalTask
RejectFontFaceLoadedPromise(dom::FontFace
* aFontFace
,
47 auto task
= PostTraversalTask(Type::ResolveFontFaceLoadedPromise
);
48 task
.mTarget
= aFontFace
;
49 task
.mResult
= aResult
;
53 static PostTraversalTask
DispatchLoadingEventAndReplaceReadyPromise(
54 dom::FontFaceSet
* aFontFaceSet
) {
56 PostTraversalTask(Type::DispatchLoadingEventAndReplaceReadyPromise
);
57 task
.mTarget
= aFontFaceSet
;
61 static PostTraversalTask
DispatchFontFaceSetCheckLoadingFinishedAfterDelay(
62 dom::FontFaceSet
* aFontFaceSet
) {
63 auto task
= PostTraversalTask(
64 Type::DispatchFontFaceSetCheckLoadingFinishedAfterDelay
);
65 task
.mTarget
= aFontFaceSet
;
69 static PostTraversalTask
LoadFontEntry(gfxUserFontEntry
* aFontEntry
) {
70 auto task
= PostTraversalTask(Type::LoadFontEntry
);
71 task
.mTarget
= aFontEntry
;
75 static PostTraversalTask
InitializeFamily(fontlist::Family
* aFamily
) {
76 auto task
= PostTraversalTask(Type::InitializeFamily
);
77 task
.mTarget
= aFamily
;
81 static PostTraversalTask
FontInfoUpdate(ServoStyleSet
* aSet
) {
82 auto task
= PostTraversalTask(Type::FontInfoUpdate
);
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.
94 // mTarget (FontFace*)
95 ResolveFontFaceLoadedPromise
,
97 // mTarget (FontFace*)
99 RejectFontFaceLoadedPromise
,
101 // mTarget (FontFaceSet*)
102 DispatchLoadingEventAndReplaceReadyPromise
,
104 // mTarget (FontFaceSet*)
105 DispatchFontFaceSetCheckLoadingFinishedAfterDelay
,
107 // mTarget (gfxUserFontEntry*)
110 // mTarget (fontlist::Family*)
113 // mTarget (ServoStyleSet*)
117 explicit PostTraversalTask(Type aType
)
118 : mType(aType
), mTarget(nullptr), mResult(NS_OK
) {}
125 } // namespace mozilla
127 #endif // mozilla_PostTraversalTask_h