Bug 1728955: part 8) Refactor `DisplayErrCode` in Windows' `nsClipboard`. r=masayuki
[gecko.git] / dom / l10n / L10nMutations.h
blob47c11a3a9d014d30cee9b73646ccf9ab4848bd14
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"
15 #include "mozilla/dom/DOMLocalization.h"
17 class nsRefreshDriver;
19 namespace mozilla {
20 namespace dom {
22 /**
23 * L10nMutations manage observing roots for localization
24 * changes and coalescing pending translations into
25 * batches - one per animation frame.
27 class L10nMutations final : public nsStubMutationObserver,
28 public nsARefreshObserver {
29 public:
30 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
31 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(L10nMutations, nsIMutationObserver)
32 NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
33 NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
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 protected:
66 bool mObserving = false;
67 bool mRefreshObserver = false;
68 RefPtr<nsRefreshDriver> mRefreshDriver;
69 DOMLocalization* mDOMLocalization;
71 // The hash is used to speed up lookups into mPendingElements.
72 nsTHashSet<RefPtr<Element>> mPendingElementsHash;
73 nsTArray<RefPtr<Element>> mPendingElements;
75 virtual void WillRefresh(mozilla::TimeStamp aTime) override;
77 void StartRefreshObserver();
78 void StopRefreshObserver();
79 void L10nElementChanged(Element* aElement);
80 void FlushPendingTranslations();
82 private:
83 ~L10nMutations();
84 bool IsInRoots(nsINode* aNode);
87 } // namespace dom
88 } // namespace mozilla
90 #endif // mozilla_dom_l10n_L10nMutations_h__