Bug 1563295 - Only rebuild native menu when specific elements added. r=mstange

The menuitem custom element inserts nodes when rendered. These nodes are
not related to the structure of the menu, but were causing nsMenuItemX
to mark the menu as needing a rebuild. The rebuild would remove all items
from the menu which caused the removal of the special menu items "Start
Dictation" and "Emoji and Symbols" that are automatically added by MacOS.

Differential Revision: https://phabricator.services.mozilla.com/D45420

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Brendan Dahl 2019-09-16 05:03:32 +00:00
parent 9a41a4d559
commit c077f5df49

View File

@ -331,19 +331,30 @@ void nsMenuItemX::ObserveAttributeChanged(dom::Document* aDocument, nsIContent*
NS_OBJC_END_TRY_ABORT_BLOCK;
}
bool IsMenuStructureElement(nsIContent* aContent) {
return aContent->IsAnyOfXULElements(nsGkAtoms::menu, nsGkAtoms::menuitem,
nsGkAtoms::menuseparator);
}
void nsMenuItemX::ObserveContentRemoved(dom::Document* aDocument, nsIContent* aContainer,
nsIContent* aChild, nsIContent* aPreviousSibling) {
if (aChild == mCommandElement) {
mMenuGroupOwner->UnregisterForContentChanges(mCommandElement);
mCommandElement = nullptr;
}
mMenuParent->SetRebuild(true);
if (IsMenuStructureElement(aChild)) {
mMenuParent->SetRebuild(true);
}
}
void nsMenuItemX::ObserveContentInserted(dom::Document* aDocument, nsIContent* aContainer,
nsIContent* aChild) {
mMenuParent->SetRebuild(true);
// The child node could come from the custom element that is for display, so
// only rebuild the menu if the child is related to the structure of the
// menu.
if (IsMenuStructureElement(aChild)) {
mMenuParent->SetRebuild(true);
}
}
void nsMenuItemX::SetupIcon() {