2019-06-25 22:39:53 +03:00
|
|
|
#ifndef mozilla_dom_l10n_L10nMutations_h
|
|
|
|
#define mozilla_dom_l10n_L10nMutations_h
|
2019-05-21 22:21:54 +03:00
|
|
|
|
|
|
|
#include "nsRefreshDriver.h"
|
|
|
|
#include "nsStubMutationObserver.h"
|
|
|
|
#include "nsTHashtable.h"
|
2019-06-06 19:32:58 +03:00
|
|
|
#include "mozilla/dom/DOMLocalization.h"
|
2019-05-21 22:21:54 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
/**
|
2019-06-06 19:32:58 +03:00
|
|
|
* L10nMutations manage observing roots for localization
|
2019-05-21 22:21:54 +03:00
|
|
|
* changes and coalescing pending translations into
|
|
|
|
* batches - one per animation frame.
|
|
|
|
*/
|
2019-06-06 19:32:58 +03:00
|
|
|
class L10nMutations final : public nsStubMutationObserver,
|
|
|
|
public nsARefreshObserver {
|
2019-05-21 22:21:54 +03:00
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2019-06-06 19:32:58 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(L10nMutations, nsIMutationObserver)
|
2019-05-21 22:21:54 +03:00
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
|
|
|
|
|
2019-06-06 19:32:58 +03:00
|
|
|
explicit L10nMutations(DOMLocalization* aDOMLocalization);
|
2019-05-21 22:21:54 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Pause root observation.
|
|
|
|
* This is useful for injecting already-translated
|
|
|
|
* content into an observed root, without causing
|
|
|
|
* superflues translation.
|
|
|
|
*/
|
|
|
|
void PauseObserving();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resume root observation.
|
|
|
|
*/
|
|
|
|
void ResumeObserving();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disconnect roots, stop refresh observer
|
|
|
|
* and break the cycle collection deadlock
|
2019-06-06 19:31:25 +03:00
|
|
|
* by removing the reference to mDOMLocalization.
|
2019-05-21 22:21:54 +03:00
|
|
|
*/
|
|
|
|
void Disconnect();
|
|
|
|
|
2019-06-03 13:00:47 +03:00
|
|
|
/**
|
|
|
|
* Called when PresShell gets created for the document.
|
|
|
|
* If there are already pending mutations, this
|
|
|
|
* will schedule the refresh driver to translate them.
|
|
|
|
*/
|
|
|
|
void OnCreatePresShell();
|
|
|
|
|
2019-05-21 22:21:54 +03:00
|
|
|
protected:
|
|
|
|
bool mObserving = false;
|
|
|
|
bool mRefreshObserver = false;
|
|
|
|
RefPtr<nsRefreshDriver> mRefreshDriver;
|
2019-06-06 19:31:25 +03:00
|
|
|
DOMLocalization* mDOMLocalization;
|
2019-05-21 22:21:54 +03:00
|
|
|
|
|
|
|
// The hash is used to speed up lookups into mPendingElements.
|
|
|
|
nsTHashtable<nsRefPtrHashKey<Element>> mPendingElementsHash;
|
|
|
|
nsTArray<RefPtr<Element>> mPendingElements;
|
|
|
|
|
|
|
|
virtual void WillRefresh(mozilla::TimeStamp aTime) override;
|
|
|
|
|
|
|
|
void StartRefreshObserver();
|
|
|
|
void StopRefreshObserver();
|
|
|
|
void L10nElementChanged(Element* aElement);
|
|
|
|
void FlushPendingTranslations();
|
|
|
|
|
|
|
|
private:
|
2019-06-06 19:32:58 +03:00
|
|
|
~L10nMutations() {
|
2019-05-21 22:21:54 +03:00
|
|
|
StopRefreshObserver();
|
2019-06-06 19:31:25 +03:00
|
|
|
MOZ_ASSERT(!mDOMLocalization,
|
2019-06-06 19:32:58 +03:00
|
|
|
"DOMLocalization<-->L10nMutations cycle should be broken.");
|
2019-05-21 22:21:54 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2019-06-06 19:32:58 +03:00
|
|
|
#endif // mozilla_dom_l10n_L10nMutations_h__
|