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 {
|
2020-04-30 21:22:38 +03:00
|
|
|
// State set when the DocumentL10n gets constructed.
|
2020-06-04 20:02:01 +03:00
|
|
|
Constructed = 0,
|
2020-04-30 21:22:38 +03:00
|
|
|
|
|
|
|
// State set when the initial translation got triggered. This happens
|
|
|
|
// if DocumentL10n was constructed during parsing of the document.
|
|
|
|
//
|
|
|
|
// If the DocumentL10n gets constructed later, we'll skip directly to
|
|
|
|
// Ready state.
|
2019-01-26 02:14:03 +03:00
|
|
|
InitialTranslationTriggered,
|
2020-04-30 21:22:38 +03:00
|
|
|
|
|
|
|
// State set the DocumentL10n has been fully initialized, potentially
|
|
|
|
// with initial translation being completed.
|
2020-04-30 20:56:41 +03:00
|
|
|
Ready,
|
2019-01-26 02:14:03 +03:00
|
|
|
};
|
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
|
|
|
|
2020-06-04 20:02:01 +03:00
|
|
|
static RefPtr<DocumentL10n> Create(Document* aDocument, const bool aSync);
|
2018-09-07 04:20:18 +03:00
|
|
|
|
2019-06-06 19:32:58 +03:00
|
|
|
protected:
|
2020-06-04 20:02:01 +03:00
|
|
|
explicit DocumentL10n(Document* aDocument, const bool aSync);
|
|
|
|
bool Init() override;
|
2020-04-30 21:22:38 +03:00
|
|
|
|
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();
|
|
|
|
|
2020-04-30 20:55:26 +03:00
|
|
|
void TriggerInitialTranslation();
|
2020-04-30 20:56:54 +03:00
|
|
|
already_AddRefed<Promise> TranslateDocument(ErrorResult& aRv);
|
2019-01-26 02:14:03 +03:00
|
|
|
|
2020-05-14 19:56:57 +03:00
|
|
|
void InitialTranslationCompleted(bool aL10nCached);
|
2019-05-21 22:21:54 +03:00
|
|
|
|
|
|
|
Document* GetDocument() { return mDocument; };
|
2019-06-03 13:00:47 +03:00
|
|
|
void OnCreatePresShell();
|
2020-04-30 20:56:41 +03:00
|
|
|
|
2020-04-30 20:56:54 +03:00
|
|
|
void ConnectRoot(nsINode& aNode, bool aTranslate, ErrorResult& aRv);
|
|
|
|
|
2020-04-30 20:56:41 +03:00
|
|
|
DocumentL10nState GetState() { return mState; };
|
2020-04-30 20:57:06 +03:00
|
|
|
|
|
|
|
bool mBlockingLayout = false;
|
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
|