Bug 1787199 [wpt PR 35620] - Add tests for `VisibilityStateEntry`, a=testonly
[gecko.git] / dom / webscheduling / TaskSignal.h
blob2cc02cc2fc25accd4b75cd4bad0f4f2d649e1a37
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:expandtab:shiftwidth=2:tabstop=2:
3 */
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #ifndef mozilla_dom_TaskSignal_h
9 #define mozilla_dom_TaskSignal_h
11 #include "mozilla/DOMEventTargetHelper.h"
12 #include "mozilla/dom/AbortSignal.h"
13 #include "mozilla/dom/WebTaskSchedulingBinding.h"
14 #include "WebTaskScheduler.h"
16 namespace mozilla::dom {
17 class TaskSignal : public AbortSignal {
18 public:
19 TaskSignal(nsIGlobalObject* aGlobal, TaskPriority aPriority)
20 : AbortSignal(aGlobal, false, JS::UndefinedHandleValue),
21 mPriority(aPriority),
22 mPriorityChanging(false) {}
24 IMPL_EVENT_HANDLER(prioritychange);
26 TaskPriority Priority() const { return mPriority; }
28 JSObject* WrapObject(JSContext* aCx,
29 JS::Handle<JSObject*> aGivenProto) override {
30 return TaskSignal_Binding::Wrap(aCx, this, aGivenProto);
33 void SetPriority(TaskPriority aPriority) { mPriority = aPriority; }
35 bool IsTaskSignal() const override { return true; }
37 bool PriorityChanging() const { return mPriorityChanging; }
39 void SetPriorityChanging(bool aPriorityChanging) {
40 mPriorityChanging = aPriorityChanging;
43 void SetWebTaskScheduler(WebTaskScheduler* aScheduler) {
44 mSchedulers.AppendElement(aScheduler);
47 void RunPriorityChangeAlgorithms() {
48 for (const WeakPtr<WebTaskScheduler>& scheduler : mSchedulers) {
49 scheduler->RunTaskSignalPriorityChange(this);
53 private:
54 TaskPriority mPriority;
56 bool mPriorityChanging;
58 nsTArray<WeakPtr<WebTaskScheduler>> mSchedulers;
60 ~TaskSignal() = default;
62 } // namespace mozilla::dom
63 #endif