Backed out changeset 83762a3e8989 (bug 1581555) for suspicion of causing bug 1607140.

--HG--
extra : rebase_source : dfbf0316e1b1f65038240264eb14915b2e7557bf
This commit is contained in:
Ryan VanderMeulen 2020-01-06 12:59:04 -05:00
Родитель e9f7bfd194
Коммит e01b63ab9f
2 изменённых файлов: 19 добавлений и 36 удалений

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

@ -237,11 +237,6 @@ const kBuiltInInputs = {
},
};
// We create a new flat object to cache strings. Since gBuiltInInputs is a
// tree, caching/retrieval of localized strings would otherwise require tree
// traversal.
var localizedStrings = {};
const kHelperObservers = new Set([
"bookmark-icon-updated",
"reader-mode-available",
@ -308,6 +303,8 @@ class TouchBarHelper {
// icons) are loaded. We keep track of which inputs haven't updated and
// run an update on them after the first location change.
this._inputsNotUpdated = new Set(Object.keys(kBuiltInInputs));
// This is a temporary workaround until bug 1596723 is resolved.
this._inputsNotUpdated.delete("SearchPopover");
return layoutItems;
}
@ -354,8 +351,8 @@ class TouchBarHelper {
// Skip localization if there is already a cached localized title or if
// no title is needed.
if (
!inputData.hasOwnProperty("title") ||
localizedStrings[inputData.title]
kBuiltInInputs[inputName].hasOwnProperty("localTitle") ||
!kBuiltInInputs[inputName].hasOwnProperty("title")
) {
return item;
}
@ -363,7 +360,7 @@ class TouchBarHelper {
// Async l10n fills in the localized input labels after the initial load.
this._l10n.formatValue(item.key).then(result => {
item.title = result;
localizedStrings[inputData.title] = result; // Cache result.
kBuiltInInputs[inputName].localTitle = result; // Cache result.
// Checking TouchBarHelper.window since this callback can fire after all windows are closed.
if (TouchBarHelper.window) {
if (this._inputsNotUpdated) {
@ -478,16 +475,12 @@ class TouchBarHelper {
);
break;
case "intl:app-locales-changed":
// On locale change, refresh all inputs after loading new localTitle.
this._searchPopover = null;
localizedStrings = {};
// This event can fire before this._l10n updates to switch languages,
// so all the new translations are in the old language. To avoid this,
// we need to reinitialize this._l10n.
this._l10n = new Localization(["browser/touchbar/touchbar.ftl"]);
helperProto._l10n = this._l10n;
this._updateTouchBarInputs(...Object.keys(kBuiltInInputs));
for (let input in kBuiltInInputs) {
delete input.localTitle;
}
this._updateTouchBarInputs(...kBuiltInInputs.keys());
break;
case "quit-application":
this.destructor();
@ -530,7 +523,7 @@ helperProto._l10n = new Localization(["browser/touchbar/touchbar.ftl"]);
class TouchBarInput {
constructor(input) {
this._key = input.key || input.title;
this._title = localizedStrings[this._key] || "";
this._title = input.hasOwnProperty("localTitle") ? input.localTitle : "";
this._image = input.image;
this._type = input.type;
this._callback = input.callback;
@ -551,7 +544,7 @@ class TouchBarInput {
initializedChild.type = input.type + "-" + initializedChild.type;
this._children.push(initializedChild);
// Skip l10n for inputs without a title or those already localized.
if (childData.title && !localizedStrings[childData.title]) {
if (childData.title && childData.title != "") {
toLocalize.push(initializedChild);
}
}
@ -613,14 +606,9 @@ class TouchBarInput {
/**
* Apply Fluent l10n to child inputs.
* @param {Array} children
* An array of initialized TouchBarInputs.
* @param {Array} children An array of initialized TouchBarInputs.
*/
async _localizeChildren(children) {
if (!children || !children.length) {
return;
}
let titles = await helperProto._l10n.formatValues(
children.map(child => ({ id: child.key }))
);
@ -629,9 +617,7 @@ class TouchBarInput {
// results in titles match up with the inputs to be localized.
children.forEach(function(child, index) {
child.title = titles[index];
localizedStrings[child.key] = child.title;
});
gTouchBarUpdater.updateTouchBarInputs(TouchBarHelper.baseWindow, children);
}
}

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

@ -210,12 +210,15 @@ static const uint32_t kInputIconSize = 16;
- (bool)updateItem:(TouchBarInput*)aInput {
NSTouchBarItem* item = [self itemForIdentifier:[aInput nativeIdentifier]];
// Update our canonical copy of the input.
[self replaceMappedLayoutItem:aInput];
// If we can't immediately find item, there are three possibilities:
// * It is a button in a ScrollView, or
// * It is contained within a popover, or
// * It is a button in a ScrollView, which can't be found with itemForIdentifier; or
// * It is contained within a popover; or
// * It simply does not exist.
// We check for each possibility here.
if (!self.mappedLayoutItems[[aInput nativeIdentifier]]) {
if (!item) {
if ([self maybeUpdateScrollViewChild:aInput]) {
return true;
}
@ -225,9 +228,6 @@ static const uint32_t kInputIconSize = 16;
return false;
}
// Update our canonical copy of the input.
[self replaceMappedLayoutItem:aInput];
if ([aInput baseType] == TouchBarInputBaseType::kButton) {
[(NSCustomTouchBarItem*)item setCustomizationLabel:[aInput title]];
[self updateButton:(NSCustomTouchBarItem*)item withIdentifier:[aInput nativeIdentifier]];
@ -240,9 +240,6 @@ static const uint32_t kInputIconSize = 16;
} else if ([aInput baseType] == TouchBarInputBaseType::kPopover) {
[(NSPopoverTouchBarItem*)item setCustomizationLabel:[aInput title]];
[self updatePopover:(NSPopoverTouchBarItem*)item withIdentifier:[aInput nativeIdentifier]];
for (TouchBarInput* child in [aInput children]) {
[(nsTouchBar*)[(NSPopoverTouchBarItem*)item popoverTouchBar] updateItem:child];
}
} else if ([aInput baseType] == TouchBarInputBaseType::kLabel) {
[self updateLabel:(NSTextField*)item.view withIdentifier:[aInput nativeIdentifier]];
}