2019-07-05 20:05:57 +03:00
|
|
|
/* -*- 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/. */
|
|
|
|
|
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
|
|
|
|
2020-08-05 00:17:50 +03:00
|
|
|
#include "nsRefreshObservers.h"
|
2019-05-21 22:21:54 +03:00
|
|
|
#include "nsStubMutationObserver.h"
|
2021-03-23 13:36:37 +03:00
|
|
|
#include "nsTHashSet.h"
|
2019-06-06 19:32:58 +03:00
|
|
|
#include "mozilla/dom/DOMLocalization.h"
|
2019-05-21 22:21:54 +03:00
|
|
|
|
2020-08-05 00:17:50 +03:00
|
|
|
class nsRefreshDriver;
|
|
|
|
|
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.
|
2021-03-23 13:36:37 +03:00
|
|
|
nsTHashSet<RefPtr<Element>> mPendingElementsHash;
|
2019-05-21 22:21:54 +03:00
|
|
|
nsTArray<RefPtr<Element>> mPendingElements;
|
|
|
|
|
|
|
|
virtual void WillRefresh(mozilla::TimeStamp aTime) override;
|
|
|
|
|
|
|
|
void StartRefreshObserver();
|
|
|
|
void StopRefreshObserver();
|
|
|
|
void L10nElementChanged(Element* aElement);
|
|
|
|
void FlushPendingTranslations();
|
|
|
|
|
|
|
|
private:
|
2020-08-05 00:17:50 +03:00
|
|
|
~L10nMutations();
|
2020-03-31 22:57:21 +03:00
|
|
|
bool IsInRoots(nsINode* aNode);
|
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__
|