summaryrefslogtreecommitdiffstats
path: root/layout/style/PostTraversalTask.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /layout/style/PostTraversalTask.h
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'layout/style/PostTraversalTask.h')
-rw-r--r--layout/style/PostTraversalTask.h128
1 files changed, 128 insertions, 0 deletions
diff --git a/layout/style/PostTraversalTask.h b/layout/style/PostTraversalTask.h
new file mode 100644
index 0000000000..64d67b0227
--- /dev/null
+++ b/layout/style/PostTraversalTask.h
@@ -0,0 +1,128 @@
+/* -*- 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 "nscore.h"
+
+/* a task to be performed immediately after a Servo traversal */
+
+namespace mozilla {
+class ServoStyleSet;
+namespace dom {
+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,
+ nsresult aResult) {
+ auto task = PostTraversalTask(Type::ResolveFontFaceLoadedPromise);
+ task.mTarget = aFontFace;
+ task.mResult = aResult;
+ 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
+ RejectFontFaceLoadedPromise,
+
+ // mTarget (FontFaceSet*)
+ DispatchLoadingEventAndReplaceReadyPromise,
+
+ // mTarget (FontFaceSetImpl*)
+ DispatchFontFaceSetCheckLoadingFinishedAfterDelay,
+
+ // mTarget (gfxUserFontEntry*)
+ LoadFontEntry,
+
+ // mTarget (fontlist::Family*)
+ InitializeFamily,
+
+ // mTarget (ServoStyleSet*)
+ FontInfoUpdate,
+ };
+
+ explicit PostTraversalTask(Type aType)
+ : mType(aType), mTarget(nullptr), mResult(NS_OK) {}
+
+ Type mType;
+ void* mTarget;
+ nsresult mResult;
+};
+
+} // namespace mozilla
+
+#endif // mozilla_PostTraversalTask_h