Bug 1753487 - Make nsIContent::GetEditingHost() not assume that itself is an element if there is no parent element r=peterv

If the instance is not an element and is a child of `Document` or something
non-element node, the method calls `this->AsElement()` in non-element instance.

It should check whether it's an element node or not when there is no editable
parent element.

Differential Revision: https://phabricator.services.mozilla.com/D138230
This commit is contained in:
Masayuki Nakano 2022-02-10 12:48:14 +00:00
parent 450f97bf22
commit 04af341212
2 changed files with 15 additions and 4 deletions

View File

@ -247,13 +247,14 @@ dom::Element* nsIContent::GetEditingHost() {
return doc->GetBodyElement();
}
nsIContent* content = this;
dom::Element* editableParentElement = nullptr;
for (dom::Element* parent = GetParentElement();
parent && parent->HasFlag(NODE_IS_EDITABLE);
parent = content->GetParentElement()) {
content = parent;
parent = editableParentElement->GetParentElement()) {
editableParentElement = parent;
}
return content->AsElement();
return editableParentElement ? editableParentElement
: dom::Element::FromNode(this);
}
nsresult nsIContent::LookupNamespaceURIInternal(

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<meta charset="utf-8">
<script>
onload = () => {
document.designMode = 'on';
getSelection().selectAllChildren(document.body);
getSelection().modify('extend', 'backward', 'character');
};
</script>
<audio controls>