Bug 1663370 - part 7: Make AutoInclusiveAncestorBlockElementsJoiner::Prepare() check the relation of its mLeftBlockElement and mRightBlockElement r=m_kato

The relation is important when the class handles both joining them and computing
target ranges.  Additionally, it's required to consider whether it can join the
block elements.  So, it should store the relation when `Prepare()` is called.

Depends on D89576

Differential Revision: https://phabricator.services.mozilla.com/D89577
This commit is contained in:
Masayuki Nakano 2020-09-14 11:40:34 +00:00
parent da0f19a5f3
commit 4a6cf53eeb

View File

@ -2959,6 +2959,7 @@ class MOZ_STACK_CLASS HTMLEditor::AutoDeleteRangesHandler final {
RefPtr<Element> mLeftBlockElement; RefPtr<Element> mLeftBlockElement;
RefPtr<Element> mRightBlockElement; RefPtr<Element> mRightBlockElement;
Maybe<nsAtom*> mNewListElementTagNameOfRightListElement; Maybe<nsAtom*> mNewListElementTagNameOfRightListElement;
EditorDOMPoint mPointContainingTheOtherBlockElement;
bool mCanJoinBlocks; bool mCanJoinBlocks;
}; // HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner:: }; // HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
// AutoInclusiveAncestorBlockElementsJoiner // AutoInclusiveAncestorBlockElementsJoiner
@ -5972,6 +5973,13 @@ HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
} }
} }
if (!EditorUtils::IsDescendantOf(*mLeftBlockElement, *mRightBlockElement,
&mPointContainingTheOtherBlockElement)) {
Unused << EditorUtils::IsDescendantOf(
*mRightBlockElement, *mLeftBlockElement,
&mPointContainingTheOtherBlockElement);
}
mCanJoinBlocks = true; mCanJoinBlocks = true;
return true; return true;
} }
@ -5993,13 +6001,13 @@ EditActionResult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
// If the left block element is in the right block element, move the hard // If the left block element is in the right block element, move the hard
// line including the right block element to end of the left block. // line including the right block element to end of the left block.
// However, if we are merging list elements, we don't join them. // However, if we are merging list elements, we don't join them.
EditorDOMPoint atRightBlockChild; if (mPointContainingTheOtherBlockElement.GetContainer() ==
if (EditorUtils::IsDescendantOf(*mLeftBlockElement, *mRightBlockElement, mRightBlockElement) {
&atRightBlockChild)) {
EditActionResult result = WhiteSpaceVisibilityKeeper:: EditActionResult result = WhiteSpaceVisibilityKeeper::
MergeFirstLineOfRightBlockElementIntoDescendantLeftBlockElement( MergeFirstLineOfRightBlockElementIntoDescendantLeftBlockElement(
aHTMLEditor, MOZ_KnownLive(*mLeftBlockElement), aHTMLEditor, MOZ_KnownLive(*mLeftBlockElement),
MOZ_KnownLive(*mRightBlockElement), atRightBlockChild, MOZ_KnownLive(*mRightBlockElement),
mPointContainingTheOtherBlockElement,
mNewListElementTagNameOfRightListElement); mNewListElementTagNameOfRightListElement);
NS_WARNING_ASSERTION(result.Succeeded(), NS_WARNING_ASSERTION(result.Succeeded(),
"WhiteSpaceVisibilityKeeper::" "WhiteSpaceVisibilityKeeper::"
@ -6008,21 +6016,19 @@ EditActionResult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
return result; return result;
} }
MOZ_DIAGNOSTIC_ASSERT(!atRightBlockChild.IsSet());
// If the right block element is in the left block element: // If the right block element is in the left block element:
// - move list item elements in the right block element to where the left // - move list item elements in the right block element to where the left
// list element is // list element is
// - or first hard line in the right block element to where: // - or first hard line in the right block element to where:
// - the left block element is. // - the left block element is.
// - or the given left content in the left block is. // - or the given left content in the left block is.
EditorDOMPoint atLeftBlockChild; if (mPointContainingTheOtherBlockElement.GetContainer() ==
if (EditorUtils::IsDescendantOf(*mRightBlockElement, *mLeftBlockElement, mLeftBlockElement) {
&atLeftBlockChild)) {
EditActionResult result = WhiteSpaceVisibilityKeeper:: EditActionResult result = WhiteSpaceVisibilityKeeper::
MergeFirstLineOfRightBlockElementIntoAncestorLeftBlockElement( MergeFirstLineOfRightBlockElementIntoAncestorLeftBlockElement(
aHTMLEditor, MOZ_KnownLive(*mLeftBlockElement), aHTMLEditor, MOZ_KnownLive(*mLeftBlockElement),
MOZ_KnownLive(*mRightBlockElement), atLeftBlockChild, MOZ_KnownLive(*mRightBlockElement),
mPointContainingTheOtherBlockElement,
MOZ_KnownLive(*mInclusiveDescendantOfLeftBlockElement), MOZ_KnownLive(*mInclusiveDescendantOfLeftBlockElement),
mNewListElementTagNameOfRightListElement); mNewListElementTagNameOfRightListElement);
NS_WARNING_ASSERTION(result.Succeeded(), NS_WARNING_ASSERTION(result.Succeeded(),
@ -6032,6 +6038,8 @@ EditActionResult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
return result; return result;
} }
MOZ_ASSERT(!mPointContainingTheOtherBlockElement.IsSet());
// Normal case. Blocks are siblings, or at least close enough. An example // Normal case. Blocks are siblings, or at least close enough. An example
// of the latter is <p>paragraph</p><ul><li>one<li>two<li>three</ul>. The // of the latter is <p>paragraph</p><ul><li>one<li>two<li>three</ul>. The
// first li and the p are not true siblings, but we still want to join them // first li and the p are not true siblings, but we still want to join them