зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1627809 - Make the DocumentL10n translate the document when initialized lazily. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D71224
This commit is contained in:
Родитель
ff33f89421
Коммит
816c29ddb0
|
@ -3865,8 +3865,6 @@ void Document::LocalizationLinkAdded(Element* aLinkElement) {
|
|||
return;
|
||||
}
|
||||
|
||||
bool mWasDocumentL10nSet = mDocumentL10n;
|
||||
|
||||
EnsureL10n();
|
||||
|
||||
nsAutoString href;
|
||||
|
@ -3875,15 +3873,15 @@ void Document::LocalizationLinkAdded(Element* aLinkElement) {
|
|||
mDocumentL10n->AddResourceId(href);
|
||||
|
||||
if (mReadyState >= READYSTATE_INTERACTIVE) {
|
||||
// We're past the initial translation. No need to block layout, let's go
|
||||
// directly to activate DocumentL10n.
|
||||
mDocumentL10n->Activate(true);
|
||||
mDocumentL10n->TriggerInitialTranslation();
|
||||
} else {
|
||||
if (!mWasDocumentL10nSet) {
|
||||
if (!mDocumentL10n->mBlockingLayout) {
|
||||
// Our initial translation is going to block layout start. Make sure
|
||||
// we don't fire the load event until after that stops happening and
|
||||
// layout has a chance to start.
|
||||
BlockOnload();
|
||||
mDocumentL10n->mBlockingLayout = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3933,13 +3931,14 @@ void Document::OnParsingCompleted() {
|
|||
}
|
||||
|
||||
void Document::InitialTranslationCompleted() {
|
||||
MOZ_ASSERT(mDocumentL10n,
|
||||
"DocumentL10n must be initialized before this point.");
|
||||
// This means we blocked the load event in LocalizationLinkAdded. It's
|
||||
// important that the load blocker removal here be async, because our caller
|
||||
// will notify the content sink after us, and we want the content sync's
|
||||
// work to happen before the load event fires.
|
||||
UnblockOnload(/* aFireSync = */ false);
|
||||
if (mDocumentL10n->mBlockingLayout) {
|
||||
// This means we blocked the load event in LocalizationLinkAdded. It's
|
||||
// important that the load blocker removal here be async, because our caller
|
||||
// will notify the content sink after us, and we want the content sync's
|
||||
// work to happen before the load event fires.
|
||||
UnblockOnload(/* aFireSync = */ false);
|
||||
mDocumentL10n->mBlockingLayout = false;
|
||||
}
|
||||
|
||||
mL10nProtoElements.Clear();
|
||||
|
||||
|
|
|
@ -60,20 +60,23 @@ void DocumentL10n::Activate(const bool aLazy) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (aLazy) {
|
||||
DOMLocalization::Activate(false, true, {});
|
||||
mReady->MaybeResolveWithUndefined();
|
||||
mState = DocumentL10nState::Ready;
|
||||
} else {
|
||||
Element* elem = mDocument->GetDocumentElement();
|
||||
if (NS_WARN_IF(!elem)) {
|
||||
return;
|
||||
}
|
||||
bool isSync = elem->HasAttr(kNameSpaceID_None, nsGkAtoms::datal10nsync);
|
||||
|
||||
DOMLocalization::Activate(isSync, true, {});
|
||||
mState = DocumentL10nState::Activated;
|
||||
Element* elem = mDocument->GetDocumentElement();
|
||||
if (NS_WARN_IF(!elem)) {
|
||||
return;
|
||||
}
|
||||
bool isSync = elem->HasAttr(kNameSpaceID_None, nsGkAtoms::datal10nsync);
|
||||
|
||||
if (aLazy) {
|
||||
if (isSync) {
|
||||
NS_WARNING(
|
||||
"Document localization initialized lazy, data-l10n-sync attribute "
|
||||
"has no effect.");
|
||||
}
|
||||
DOMLocalization::Activate(false, true, {});
|
||||
} else {
|
||||
DOMLocalization::Activate(isSync, true, {});
|
||||
}
|
||||
mState = DocumentL10nState::Activated;
|
||||
}
|
||||
|
||||
JSObject* DocumentL10n::WrapObject(JSContext* aCx,
|
||||
|
|
|
@ -79,6 +79,8 @@ class DocumentL10n final : public DOMLocalization {
|
|||
void ConnectRoot(nsINode& aNode, bool aTranslate, ErrorResult& aRv);
|
||||
|
||||
DocumentL10nState GetState() { return mState; };
|
||||
|
||||
bool mBlockingLayout = false;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
|
|
@ -22,10 +22,10 @@
|
|||
link.setAttribute("href", "crashreporter/aboutcrashes.ftl");
|
||||
document.head.appendChild(link);
|
||||
|
||||
// Verify now that `l10n.ready` exists and is fulfilled.
|
||||
await document.l10n.ready;
|
||||
|
||||
await document.l10n.translateElements([desc]);
|
||||
|
||||
// Lazy initialized localization should translate the document.
|
||||
is(desc.textContent.length > 0, true, "main-desc is translated");
|
||||
|
||||
document.head.removeChild(link);
|
||||
|
|
Загрузка…
Ссылка в новой задаче