Bug 1814101 - Add requestAdapterInfo for webgpu. r=gfx-reviewers,webidl,jimb,smaug
[gecko.git] / dom / l10n / L10nMutations.h
blobafc08445e05773ec46658729dd45bdd6aae913e3
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_dom_l10n_L10nMutations_h
8 #define mozilla_dom_l10n_L10nMutations_h
10 #include "nsCycleCollectionParticipant.h"
11 #include "nsHashKeys.h"
12 #include "nsRefreshObservers.h"
13 #include "nsStubMutationObserver.h"
14 #include "nsTHashSet.h"
16 class nsRefreshDriver;
18 namespace mozilla::dom {
19 class Document;
20 class DOMLocalization;
21 /**
22 * L10nMutations manage observing roots for localization
23 * changes and coalescing pending translations into
24 * batches - one per animation frame.
26 class L10nMutations final : public nsStubMultiMutationObserver,
27 public nsARefreshObserver {
28 public:
29 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
30 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(L10nMutations, nsIMutationObserver)
31 NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
32 NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
33 NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
34 NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
36 explicit L10nMutations(DOMLocalization* aDOMLocalization);
38 /**
39 * Pause root observation.
40 * This is useful for injecting already-translated
41 * content into an observed root, without causing
42 * superflues translation.
44 void PauseObserving();
46 /**
47 * Resume root observation.
49 void ResumeObserving();
51 /**
52 * Disconnect roots, stop refresh observer
53 * and break the cycle collection deadlock
54 * by removing the reference to mDOMLocalization.
56 void Disconnect();
58 /**
59 * Called when PresShell gets created for the document.
60 * If there are already pending mutations, this
61 * will schedule the refresh driver to translate them.
63 void OnCreatePresShell();
65 bool HasPendingMutations() const {
66 return !mPendingElements.IsEmpty() || mPendingPromises;
69 MOZ_CAN_RUN_SCRIPT void PendingPromiseSettled();
71 private:
72 bool mObserving = false;
73 bool mBlockingLoad = false;
74 bool mPendingBlockingLoadFlush = false;
75 uint32_t mPendingPromises = 0;
76 RefPtr<nsRefreshDriver> mRefreshDriver;
77 DOMLocalization* mDOMLocalization;
79 // The hash is used to speed up lookups into mPendingElements, which we need
80 // to guarantee some consistent ordering of operations.
81 nsTHashSet<RefPtr<Element>> mPendingElementsHash;
82 nsTArray<RefPtr<Element>> mPendingElements;
84 Document* GetDocument() const;
86 MOZ_CAN_RUN_SCRIPT void WillRefresh(mozilla::TimeStamp aTime) override;
88 void StartRefreshObserver();
89 void StopRefreshObserver();
90 void L10nElementChanged(Element* aElement);
91 MOZ_CAN_RUN_SCRIPT void FlushPendingTranslations();
92 MOZ_CAN_RUN_SCRIPT void FlushPendingTranslationsBeforeLoad();
93 MOZ_CAN_RUN_SCRIPT void MaybeFirePendingTranslationsFinished();
95 ~L10nMutations();
96 bool IsInRoots(nsINode* aNode);
99 } // namespace mozilla::dom
101 #endif // mozilla_dom_l10n_L10nMutations_h__