Bug 1700051: part 26) Correct typo in comment of `mozInlineSpellWordUtil::BuildSoftTe...
[gecko.git] / dom / l10n / DocumentL10n.h
blobeb3cda5ecfb4e58bc665b57082676dd617262d68
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"
12 class nsIContentSink;
14 namespace mozilla {
15 namespace dom {
17 class Document;
19 enum class DocumentL10nState {
20 // State set when the DocumentL10n gets constructed.
21 Constructed = 0,
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
27 // Ready state.
28 InitialTranslationTriggered,
30 // State set the DocumentL10n has been fully initialized, potentially
31 // with initial translation being completed.
32 Ready,
35 /**
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 {
46 public:
47 NS_DECL_ISUPPORTS_INHERITED
48 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DocumentL10n, DOMLocalization)
50 static RefPtr<DocumentL10n> Create(Document* aDocument, const bool aSync);
52 protected:
53 explicit DocumentL10n(Document* aDocument, const bool aSync);
54 bool Init() override;
56 virtual ~DocumentL10n() = default;
58 RefPtr<Document> mDocument;
59 RefPtr<Promise> mReady;
60 DocumentL10nState mState;
61 nsCOMPtr<nsIContentSink> mContentSink;
63 public:
64 virtual JSObject* WrapObject(JSContext* aCx,
65 JS::Handle<JSObject*> aGivenProto) override;
67 Promise* Ready();
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;
89 } // namespace dom
90 } // namespace mozilla
92 #endif // mozilla_dom_l10n_DocumentL10n_h