Bug 1649121: part 11) Factor some functionality of GetMostAncestorListOrTableElement out. r=masayuki

Differential Revision: https://phabricator.services.mozilla.com/D81849
This commit is contained in:
Mirko Brodesser 2020-07-03 09:26:19 +00:00
parent 4fb30e0688
commit bb175a0e82
3 changed files with 22 additions and 18 deletions

View File

@ -654,6 +654,18 @@ bool HTMLEditUtils::IsSingleLineContainer(nsINode& aNode) {
aNode.IsAnyOfHTMLElements(nsGkAtoms::li, nsGkAtoms::dt, nsGkAtoms::dd);
}
// static
Element* HTMLEditUtils::GetClosestAncestorAnyListElement(
const nsIContent& aContent) {
for (Element* element : aContent.AncestorsOfType<Element>()) {
if (HTMLEditUtils::IsAnyListElement(element)) {
return element;
}
}
return nullptr;
}
EditAction HTMLEditUtils::GetEditActionForInsert(const nsAtom& aTagName) {
// This method may be in a hot path. So, return only necessary
// EditAction::eInsert*Element.

View File

@ -533,6 +533,10 @@ class HTMLEditUtils final {
* <table> element of aContent.
*/
static Element* GetClosestAncestorTableElement(const nsIContent& aContent) {
// TODO: the method name and its documentation clash with the
// implementation. Split this method into
// `GetClosestAncestorTableElement` and
// `GetClosestInclusiveAncestorTableElement`.
if (!aContent.GetParent()) {
return nullptr;
}
@ -544,6 +548,8 @@ class HTMLEditUtils final {
return nullptr;
}
static Element* GetClosestAncestorAnyListElement(const nsIContent& aContent);
/**
* GetElementIfOnlyOneSelected() returns an element if aRange selects only
* the element node (and its descendants).

View File

@ -3130,15 +3130,8 @@ HTMLEditor::AutoHTMLFragmentBoundariesFixer::GetMostAncestorListOrTableElement(
Element* lastFoundAncestorListOrTableElement = nullptr;
for (auto& content : aArrayOfTopMostChildContents) {
if (HTMLEditUtils::IsAnyTableElementButNotTable(content)) {
Element* tableElement = nullptr;
for (Element* maybeTableElement = content->GetParentElement();
maybeTableElement;
maybeTableElement = maybeTableElement->GetParentElement()) {
if (maybeTableElement->IsHTMLElement(nsGkAtoms::table)) {
tableElement = maybeTableElement;
break;
}
}
Element* tableElement =
HTMLEditUtils::GetClosestAncestorTableElement(*content);
if (!tableElement) {
continue;
}
@ -3165,15 +3158,8 @@ HTMLEditor::AutoHTMLFragmentBoundariesFixer::GetMostAncestorListOrTableElement(
if (!HTMLEditUtils::IsListItem(content)) {
continue;
}
Element* listElement = nullptr;
for (Element* maybeListElement = content->GetParentElement();
maybeListElement;
maybeListElement = maybeListElement->GetParentElement()) {
if (HTMLEditUtils::IsAnyListElement(maybeListElement)) {
listElement = maybeListElement;
break;
}
}
Element* listElement =
HTMLEditUtils::GetClosestAncestorAnyListElement(*content);
if (!listElement) {
continue;
}