1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
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_DocumentL10n_h
8 #define mozilla_dom_l10n_DocumentL10n_h
10 #include "mozilla/dom/DOMLocalization.h"
14 namespace mozilla::dom
{
18 enum class DocumentL10nState
{
19 // State set when the DocumentL10n gets constructed.
22 // State set when the initial translation got triggered. This happens
23 // if DocumentL10n was constructed during parsing of the document.
25 // If the DocumentL10n gets constructed later, we'll skip directly to
27 InitialTranslationTriggered
,
29 // State set the DocumentL10n has been fully initialized, potentially
30 // with initial translation being completed.
35 * This class maintains localization status of the document.
37 * The document will initialize it lazily when a link with a localization
38 * resource is added to the document.
40 * Once initialized, DocumentL10n relays all API methods to an
41 * instance of mozILocalization and maintains a single promise
42 * which gets resolved the first time the document gets translated.
44 class DocumentL10n final
: public DOMLocalization
{
46 NS_DECL_ISUPPORTS_INHERITED
47 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DocumentL10n
, DOMLocalization
)
49 static RefPtr
<DocumentL10n
> Create(Document
* aDocument
, bool aSync
);
52 explicit DocumentL10n(Document
* aDocument
, bool aSync
);
53 virtual ~DocumentL10n() = default;
55 RefPtr
<Document
> mDocument
;
56 RefPtr
<Promise
> mReady
;
57 DocumentL10nState mState
;
58 nsCOMPtr
<nsIContentSink
> mContentSink
;
61 virtual JSObject
* WrapObject(JSContext
* aCx
,
62 JS::Handle
<JSObject
*> aGivenProto
) override
;
66 void TriggerInitialTranslation();
67 already_AddRefed
<Promise
> TranslateDocument(ErrorResult
& aRv
);
69 void InitialTranslationCompleted(bool aL10nCached
);
71 Document
* GetDocument() const { return mDocument
; };
72 void OnCreatePresShell();
74 void ConnectRoot(nsINode
& aNode
, bool aTranslate
, ErrorResult
& aRv
);
76 DocumentL10nState
GetState() { return mState
; };
78 bool mBlockingLayout
= false;
81 } // namespace mozilla::dom
83 #endif // mozilla_dom_l10n_DocumentL10n_h