Bug 1835406 - Fix translations button focus on restoring page; r=nordzilla

The button was getting removed and returned, causing the focus to be
removed.

Differential Revision: https://phabricator.services.mozilla.com/D181655
This commit is contained in:
Greg Tatum 2023-06-21 18:27:39 +00:00
Родитель 1a256b19b8
Коммит 3c5d1abef3
1 изменённых файлов: 18 добавлений и 2 удалений

Просмотреть файл

@ -148,8 +148,20 @@ export class TranslationsParent extends JSWindowActorParent {
*/
#isDestroyed = false;
/**
* Remember the detected languages on a page reload. This will keep the translations
* button from disappearing and reappearing, which causes the button to lose focus.
*
* @type {LangTags | null} previousDetectedLanguages
*/
static #previousDetectedLanguages = null;
actorCreated() {
this.languageState = new TranslationsLanguageState(this);
this.languageState = new TranslationsLanguageState(
this,
TranslationsParent.#previousDetectedLanguages
);
TranslationsParent.#previousDetectedLanguages = null;
if (TranslationsParent.#translateOnPageReload) {
// The actor was recreated after a page reload, start the translation.
@ -1639,6 +1651,8 @@ export class TranslationsParent extends JSWindowActorParent {
TranslationsParent.#isPageRestoredForAutoTranslate = true;
}
this.languageState.requestedTranslationPair = null;
TranslationsParent.#previousDetectedLanguages =
this.languageState.detectedLanguages;
const browser = this.browsingContext.embedderElement;
browser.reload();
@ -2022,9 +2036,11 @@ function detectSimdSupport() {
class TranslationsLanguageState {
/**
* @param {TranslationsParent} actor
* @param {LangTags | null} previousDetectedLanguages
*/
constructor(actor) {
constructor(actor, previousDetectedLanguages = null) {
this.#actor = actor;
this.#detectedLanguages = previousDetectedLanguages;
this.dispatch();
}