Bug 1767386 - part 2: Make `HTMLEditor::RemoveInlinePropertyInternal` stop setting/removing style of an element if it's removed by `RemoveStyleInside` r=m_kato

`CSSEditUtils` will refer the composed document of the element to compute the
style of it.  However, it'll fail if `RemoveStyleInside` has already removed
the element from the DOM tree.  Therefore, `RemoveInlinePropertyInternal`
should stop handling the element immediately after calling `RemoveStyleInside`
if the element is removed.

Depends on D145303

Differential Revision: https://phabricator.services.mozilla.com/D145304
This commit is contained in:
Masayuki Nakano 2022-05-09 06:03:21 +00:00
Родитель ba7aebf080
Коммит 5e6b541ce8
2 изменённых файлов: 9 добавлений и 0 удалений

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

@ -4075,6 +4075,8 @@ class HTMLEditor final : public EditorBase,
* RemoveStyleInside() removes elements which represent aProperty/aAttribute
* and removes CSS style. This handles aElement and all its descendants
* (including leaf text nodes) recursively.
* TODO: Rename this to explain that this maybe remove aElement from the DOM
* tree.
*
* @param aSpecifiedStyle Whether the class and style attributes should
* be preserved or discareded.

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

@ -2156,6 +2156,11 @@ nsresult HTMLEditor::RemoveInlinePropertyInternal(
NS_WARNING("HTMLEditor::RemoveStyleInside() failed");
return rv;
}
// If the element was removed from the DOM tree by
// RemoveStyleInside, we need nothing to do for it anymore.
if (!content->GetParentNode()) {
continue;
}
}
Result<bool, nsresult> isRemovableParentStyleOrError =
@ -2222,6 +2227,8 @@ nsresult HTMLEditor::RemoveInlinePropertyInternal(
// they still have the style.
AutoTArray<OwningNonNull<Text>, 32> leafTextNodes;
for (OwningNonNull<nsIContent>& content : arrayOfContents) {
// XXX Should we ignore content which has already removed from the
// DOM tree by the previous for-loop?
if (content->IsElement()) {
CollectEditableLeafTextNodes(*content->AsElement(),
leafTextNodes);