2018-09-07 04:20:18 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
|
|
/* 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-06 19:31:44 +03:00
|
|
|
#ifndef mozilla_dom_l10n_DocumentL10n_h
|
|
|
|
#define mozilla_dom_l10n_DocumentL10n_h
|
2018-09-07 04:20:18 +03:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2019-06-06 19:32:58 +03:00
|
|
|
#include "mozilla/dom/DOMLocalization.h"
|
2018-09-07 04:20:18 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2019-01-26 02:14:03 +03:00
|
|
|
enum class DocumentL10nState {
|
|
|
|
Initialized = 0,
|
|
|
|
InitialTranslationTriggered,
|
|
|
|
InitialTranslationCompleted
|
|
|
|
};
|
2018-09-07 04:20:18 +03:00
|
|
|
|
|
|
|
/**
|
2018-12-31 17:10:19 +03:00
|
|
|
* This class maintains localization status of the document.
|
2018-09-07 04:20:18 +03:00
|
|
|
*
|
2019-01-02 16:05:23 +03:00
|
|
|
* The document will initialize it lazily when a link with a localization
|
2018-12-31 17:10:19 +03:00
|
|
|
* resource is added to the document.
|
2018-09-07 04:20:18 +03:00
|
|
|
*
|
|
|
|
* Once initialized, DocumentL10n relays all API methods to an
|
2019-05-21 22:22:36 +03:00
|
|
|
* instance of mozILocalization and maintains a single promise
|
2018-09-07 04:20:18 +03:00
|
|
|
* which gets resolved the first time the document gets translated.
|
|
|
|
*/
|
2019-06-06 19:32:58 +03:00
|
|
|
class DocumentL10n final : public DOMLocalization {
|
2018-09-07 04:20:18 +03:00
|
|
|
public:
|
2019-06-06 19:31:25 +03:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2019-06-06 19:32:58 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DocumentL10n, DOMLocalization)
|
2018-09-07 04:20:18 +03:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
explicit DocumentL10n(Document* aDocument);
|
2019-06-06 19:31:25 +03:00
|
|
|
void Init(nsTArray<nsString>& aResourceIds, ErrorResult& aRv);
|
2018-09-07 04:20:18 +03:00
|
|
|
|
2019-06-06 19:32:58 +03:00
|
|
|
protected:
|
2019-06-06 19:31:25 +03:00
|
|
|
virtual ~DocumentL10n() = default;
|
2018-09-07 04:20:18 +03:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
RefPtr<Document> mDocument;
|
2018-09-07 04:20:18 +03:00
|
|
|
RefPtr<Promise> mReady;
|
|
|
|
DocumentL10nState mState;
|
2019-01-26 02:14:03 +03:00
|
|
|
nsCOMPtr<nsIContentSink> mContentSink;
|
2018-10-24 20:41:46 +03:00
|
|
|
|
2018-09-07 04:20:18 +03:00
|
|
|
public:
|
|
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
|
|
|
|
|
|
|
Promise* Ready();
|
|
|
|
|
|
|
|
void TriggerInitialDocumentTranslation();
|
2019-01-26 02:14:03 +03:00
|
|
|
|
|
|
|
void InitialDocumentTranslationCompleted();
|
2019-05-21 22:21:54 +03:00
|
|
|
|
|
|
|
Document* GetDocument() { return mDocument; };
|
2019-06-03 13:00:47 +03:00
|
|
|
void OnCreatePresShell();
|
2018-09-07 04:20:18 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2019-06-06 19:31:44 +03:00
|
|
|
#endif // mozilla_dom_l10n_DocumentL10n_h
|