forked from mirrors/gecko-dev
Bug 1658472 - part 6: Make some utility methods for AutoInclusiveAncestorBlockElementsJoiner r=m_kato
This patch changes the behavior in the following 2 points: * When both content is in same block element, won't return error * When `<hr>` element has block children accidentally, this solves its container The former case must not change actual behavior because `AutoBlockElementsJoiner` is used with content nodes which are in different blocks. Differential Revision: https://phabricator.services.mozilla.com/D86886
This commit is contained in:
parent
909288b9a6
commit
d550a723f8
3 changed files with 32 additions and 28 deletions
|
|
@ -4624,16 +4624,14 @@ HTMLEditor::AutoBlockElementsJoiner::JoinNodesDeepWithTransaction(
|
||||||
|
|
||||||
EditActionResult HTMLEditor::AutoBlockElementsJoiner::
|
EditActionResult HTMLEditor::AutoBlockElementsJoiner::
|
||||||
AutoInclusiveAncestorBlockElementsJoiner::Prepare() {
|
AutoInclusiveAncestorBlockElementsJoiner::Prepare() {
|
||||||
mLeftBlockElement = HTMLEditUtils::GetInclusiveAncestorBlockElement(
|
mLeftBlockElement =
|
||||||
mInclusiveDescendantOfLeftBlockElement);
|
HTMLEditUtils::GetInclusiveAncestorBlockElementExceptHRElement(
|
||||||
mRightBlockElement = HTMLEditUtils::GetInclusiveAncestorBlockElement(
|
mInclusiveDescendantOfLeftBlockElement);
|
||||||
mInclusiveDescendantOfRightBlockElement);
|
mRightBlockElement =
|
||||||
|
HTMLEditUtils::GetInclusiveAncestorBlockElementExceptHRElement(
|
||||||
|
mInclusiveDescendantOfRightBlockElement);
|
||||||
|
|
||||||
// Sanity checks
|
if (NS_WARN_IF(!IsSet())) {
|
||||||
if (NS_WARN_IF(!mLeftBlockElement) || NS_WARN_IF(!mRightBlockElement)) {
|
|
||||||
return EditActionIgnored(NS_ERROR_NULL_POINTER);
|
|
||||||
}
|
|
||||||
if (NS_WARN_IF(mLeftBlockElement == mRightBlockElement)) {
|
|
||||||
return EditActionIgnored(NS_ERROR_UNEXPECTED);
|
return EditActionIgnored(NS_ERROR_UNEXPECTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -4643,25 +4641,8 @@ EditActionResult HTMLEditor::AutoBlockElementsJoiner::
|
||||||
return EditActionCanceled();
|
return EditActionCanceled();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure we don't try to move things into HR's, which look like blocks
|
|
||||||
// but aren't containers
|
|
||||||
if (mLeftBlockElement->IsHTMLElement(nsGkAtoms::hr)) {
|
|
||||||
mLeftBlockElement =
|
|
||||||
HTMLEditUtils::GetAncestorBlockElement(*mLeftBlockElement);
|
|
||||||
if (NS_WARN_IF(!mLeftBlockElement)) {
|
|
||||||
return EditActionIgnored(NS_ERROR_UNEXPECTED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mRightBlockElement->IsHTMLElement(nsGkAtoms::hr)) {
|
|
||||||
mRightBlockElement =
|
|
||||||
HTMLEditUtils::GetAncestorBlockElement(*mRightBlockElement);
|
|
||||||
if (NS_WARN_IF(!mRightBlockElement)) {
|
|
||||||
return EditActionIgnored(NS_ERROR_UNEXPECTED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bail if both blocks the same
|
// Bail if both blocks the same
|
||||||
if (mLeftBlockElement == mRightBlockElement) {
|
if (IsSameBlockElement()) {
|
||||||
return EditActionIgnored();
|
return EditActionIgnored();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -4707,7 +4688,7 @@ EditActionResult HTMLEditor::AutoBlockElementsJoiner::
|
||||||
MOZ_ASSERT(mLeftBlockElement);
|
MOZ_ASSERT(mLeftBlockElement);
|
||||||
MOZ_ASSERT(mRightBlockElement);
|
MOZ_ASSERT(mRightBlockElement);
|
||||||
|
|
||||||
if (mLeftBlockElement == mRightBlockElement) {
|
if (IsSameBlockElement()) {
|
||||||
return EditActionIgnored();
|
return EditActionIgnored();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -528,6 +528,24 @@ class HTMLEditUtils final {
|
||||||
return GetAncestorBlockElement(aContent, aAncestorLimiter);
|
return GetAncestorBlockElement(aContent, aAncestorLimiter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GetInclusiveAncestorBlockElementExceptHRElement() returns inclusive
|
||||||
|
* ancestor block element except `<hr>` element.
|
||||||
|
*/
|
||||||
|
static Element* GetInclusiveAncestorBlockElementExceptHRElement(
|
||||||
|
const nsIContent& aContent, const nsINode* aAncestorLimiter = nullptr) {
|
||||||
|
Element* blockElement =
|
||||||
|
GetInclusiveAncestorBlockElement(aContent, aAncestorLimiter);
|
||||||
|
if (!blockElement || !blockElement->IsHTMLElement(nsGkAtoms::hr)) {
|
||||||
|
return blockElement;
|
||||||
|
}
|
||||||
|
if (!blockElement->GetParentElement()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return GetInclusiveAncestorBlockElementExceptHRElement(
|
||||||
|
*blockElement->GetParentElement(), aAncestorLimiter);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GetInclusiveAncestorEditableBlockElementOrInlineEditingHost() returns
|
* GetInclusiveAncestorEditableBlockElementOrInlineEditingHost() returns
|
||||||
* inclusive block ancestor element of aContent. If aContent is in inline
|
* inclusive block ancestor element of aContent. If aContent is in inline
|
||||||
|
|
|
||||||
|
|
@ -2947,6 +2947,11 @@ class HTMLEditor final : public TextEditor,
|
||||||
mInclusiveDescendantOfRightBlockElement(
|
mInclusiveDescendantOfRightBlockElement(
|
||||||
aInclusiveDescendantOfRightBlockElement) {}
|
aInclusiveDescendantOfRightBlockElement) {}
|
||||||
|
|
||||||
|
bool IsSet() const { return mLeftBlockElement && mRightBlockElement; }
|
||||||
|
bool IsSameBlockElement() const {
|
||||||
|
return mLeftBlockElement && mLeftBlockElement == mRightBlockElement;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare for joining inclusive ancestor block elements. When this
|
* Prepare for joining inclusive ancestor block elements. When this
|
||||||
* returns error or "canceled" or "handled" state, don't call Run().
|
* returns error or "canceled" or "handled" state, don't call Run().
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue