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"
19 enum class DocumentL10nState
{
20 // State set when the DocumentL10n gets constructed.
23 // State set when the initial translation got triggered. This happens
24 // if DocumentL10n was constructed during parsing of the document.
26 // If the DocumentL10n gets constructed later, we'll skip directly to
28 InitialTranslationTriggered
,
30 // State set the DocumentL10n has been fully initialized, potentially
31 // with initial translation being completed.
36 * This class maintains localization status of the document.
38 * The document will initialize it lazily when a link with a localization
39 * resource is added to the document.
41 * Once initialized, DocumentL10n relays all API methods to an
42 * instance of mozILocalization and maintains a single promise
43 * which gets resolved the first time the document gets translated.
45 class DocumentL10n final
: public DOMLocalization
{
47 NS_DECL_ISUPPORTS_INHERITED
48 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DocumentL10n
, DOMLocalization
)
50 static RefPtr
<DocumentL10n
> Create(Document
* aDocument
, const bool aSync
);
53 explicit DocumentL10n(Document
* aDocument
, const bool aSync
);
56 virtual ~DocumentL10n() = default;
58 RefPtr
<Document
> mDocument
;
59 RefPtr
<Promise
> mReady
;
60 DocumentL10nState mState
;
61 nsCOMPtr
<nsIContentSink
> mContentSink
;
64 virtual JSObject
* WrapObject(JSContext
* aCx
,
65 JS::Handle
<JSObject
*> aGivenProto
) override
;
69 void TriggerInitialTranslation();
70 already_AddRefed
<Promise
> TranslateDocument(ErrorResult
& aRv
);
72 void InitialTranslationCompleted(bool aL10nCached
);
74 Document
* GetDocument() { return mDocument
; };
75 void OnCreatePresShell();
77 void ConnectRoot(nsINode
& aNode
, bool aTranslate
, ErrorResult
& aRv
);
79 DocumentL10nState
GetState() { return mState
; };
81 void MaybeRecordTelemetry();
83 bool mBlockingLayout
= false;
85 mozilla::TimeStamp mInitialTranslationStart
;
86 static bool mIsFirstBrowserWindow
;
90 } // namespace mozilla
92 #endif // mozilla_dom_l10n_DocumentL10n_h