1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_PostTraversalTask_h
#define mozilla_PostTraversalTask_h
#include "nsString.h"
#include "nscore.h"
/* a task to be performed immediately after a Servo traversal */
namespace mozilla {
class ServoStyleSet;
namespace dom {
enum class FontFaceLoadedRejectReason : uint8_t;
class FontFace;
class FontFaceSet;
class FontFaceSetImpl;
} // namespace dom
namespace fontlist {
struct Family;
} // namespace fontlist
} // namespace mozilla
class gfxUserFontEntry;
namespace mozilla {
/**
* A PostTraversalTask is a task to be performed immediately after a Servo
* traversal. There are just a few tasks we need to perform, so we use this
* class rather than Runnables, to avoid virtual calls and some allocations.
*
* A PostTraversalTask is only safe to run immediately after the Servo
* traversal, since it can hold raw pointers to DOM objects.
*/
class PostTraversalTask {
public:
static PostTraversalTask ResolveFontFaceLoadedPromise(
dom::FontFace* aFontFace) {
auto task = PostTraversalTask(Type::ResolveFontFaceLoadedPromise);
task.mTarget = aFontFace;
return task;
}
static PostTraversalTask RejectFontFaceLoadedPromise(
dom::FontFace* aFontFace, dom::FontFaceLoadedRejectReason aReason,
nsCString&& aMessage) {
auto task = PostTraversalTask(Type::ResolveFontFaceLoadedPromise);
task.mTarget = aFontFace;
task.mResult.emplace(aReason);
task.mMessage = std::move(aMessage);
return task;
}
static PostTraversalTask DispatchLoadingEventAndReplaceReadyPromise(
dom::FontFaceSet* aFontFaceSet) {
auto task =
PostTraversalTask(Type::DispatchLoadingEventAndReplaceReadyPromise);
task.mTarget = aFontFaceSet;
return task;
}
static PostTraversalTask DispatchFontFaceSetCheckLoadingFinishedAfterDelay(
dom::FontFaceSetImpl* aFontFaceSet) {
auto task = PostTraversalTask(
Type::DispatchFontFaceSetCheckLoadingFinishedAfterDelay);
task.mTarget = aFontFaceSet;
return task;
}
static PostTraversalTask LoadFontEntry(gfxUserFontEntry* aFontEntry) {
auto task = PostTraversalTask(Type::LoadFontEntry);
task.mTarget = aFontEntry;
return task;
}
static PostTraversalTask InitializeFamily(fontlist::Family* aFamily) {
auto task = PostTraversalTask(Type::InitializeFamily);
task.mTarget = aFamily;
return task;
}
static PostTraversalTask FontInfoUpdate(ServoStyleSet* aSet) {
auto task = PostTraversalTask(Type::FontInfoUpdate);
task.mTarget = aSet;
return task;
}
void Run();
private:
// For any new raw pointer type that we need to store in a PostTraversalTask,
// please add an assertion that class' destructor that we are not in a Servo
// traversal, to protect against the possibility of having dangling pointers.
enum class Type {
// mTarget (FontFace*)
ResolveFontFaceLoadedPromise,
// mTarget (FontFace*)
// mResult / mMessage
RejectFontFaceLoadedPromise,
// mTarget (FontFaceSet*)
DispatchLoadingEventAndReplaceReadyPromise,
// mTarget (FontFaceSetImpl*)
DispatchFontFaceSetCheckLoadingFinishedAfterDelay,
// mTarget (gfxUserFontEntry*)
LoadFontEntry,
// mTarget (fontlist::Family*)
InitializeFamily,
// mTarget (ServoStyleSet*)
FontInfoUpdate,
};
explicit PostTraversalTask(Type aType) : mType(aType) {}
const Type mType;
void* mTarget = nullptr;
nsCString mMessage;
Maybe<dom::FontFaceLoadedRejectReason> mResult;
};
} // namespace mozilla
#endif // mozilla_PostTraversalTask_h
|