layout/style/PostTraversalTask.h
author Mozilla Releng Treescript <release+treescript@mozilla.org>
Wed, 19 Feb 2020 10:59:03 +0000
changeset 575780 fb8151585dd3fd4778644aeda9d2d88f7bde6108
parent 530571 095b3edec3c8ba9318c71d0acc91e10ce57818dc
permissions -rw-r--r--
no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD mk -> 4132e362def6 mr -> 68d2b10b2db1 ms -> c6a13bac594d my -> 677a03a31701 nb-NO -> 5936459b1414 ne-NP -> aad4c70251f5 nl -> bbbba0097421 nn-NO -> 91c795b0fceb oc -> 93b5354a3725 pa-IN -> 8768cda1d880 pl -> 3028dd3d5ca9 pt-BR -> ee4a00bcdfaa pt-PT -> aa770983440e rm -> c3ca0d7b69f0 ro -> 3fc4d4e0726d ru -> 74d1a5b7f599 si -> f63c8d478db8 sk -> 0e3b08f6fc9a sl -> d92190900ae6 son -> 1530e7b12a77 sq -> bb20a1ced9a8 sr -> 64ee969b3bbe sv-SE -> b7a466953665 ta -> 1dc39d98ead5 te -> 483c84d48728 th -> 14dfadc0e589 tl -> 35eaa4a8ef91 tr -> cdb294b3db86 trs -> d0e2871936e1 uk -> 74411b867c2e ur -> e3880f1f1f02 uz -> 909894d5017c vi -> fa9585562032 xh -> 383e821be06b zh-CN -> c509d68dd545 zh-TW -> d108a91a8a97

/* -*- 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;
}  // 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::FontFaceSet* 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 (FontFaceSet*)
    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