Backed out changeset 2e7e9d83e56b (bug 1655391) for bustage at HTMLEditor. CLOSED TREE

This commit is contained in:
Butkovits Atila 2020-08-03 14:54:27 +03:00
Родитель de8ebff591
Коммит 7a09391039
2 изменённых файлов: 49 добавлений и 97 удалений

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

@ -2612,16 +2612,14 @@ EditActionResult HTMLEditor::HandleDeleteAroundCollapsedSelection(
if (NS_WARN_IF(!scanFromStartPointResult.GetContent()->IsElement())) {
return EditActionResult(NS_ERROR_FAILURE);
}
AutoBlockElementsJoiner joiner;
if (!joiner.PrepareToDeleteCollapsedSelectionAtCurrentBlockBoundary(
*this, aDirectionAndAmount, *scanFromStartPointResult.ElementPtr(),
startPoint)) {
return EditActionCanceled();
}
EditActionResult result = joiner.Run(*this, startPoint);
NS_WARNING_ASSERTION(result.Succeeded(),
"HTMLEditor::AutoBlockElementsJoiner::Run() failed "
"(current block boundary)");
EditActionResult result =
HandleDeleteCollapsedSelectionAtCurrentBlockBoundary(
aDirectionAndAmount,
MOZ_KnownLive(*scanFromStartPointResult.ElementPtr()), startPoint);
NS_WARNING_ASSERTION(
result.Succeeded(),
"HTMLEditor::HandleDeleteCollapsedSelectionAtCurrentBlockBoundary() "
"failed");
return result;
}
@ -3159,54 +3157,52 @@ EditActionResult HTMLEditor::HandleDeleteCollapsedSelectionAtOtherBlockBoundary(
return result;
}
bool HTMLEditor::AutoBlockElementsJoiner::
PrepareToDeleteCollapsedSelectionAtCurrentBlockBoundary(
const HTMLEditor& aHTMLEditor,
nsIEditor::EDirection aDirectionAndAmount,
Element& aCurrentBlockElement, const EditorDOMPoint& aCaretPoint) {
MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
EditActionResult
HTMLEditor::HandleDeleteCollapsedSelectionAtCurrentBlockBoundary(
nsIEditor::EDirection aDirectionAndAmount, Element& aCurrentBlockElement,
const EditorDOMPoint& aCaretPoint) {
MOZ_ASSERT(IsEditActionDataAvailable());
// At edge of our block. Look beside it and see if we can join to an
// adjacent block
mMode = Mode::JoinCurrentBlock;
// Make sure it's not a table element. If so, cancel the operation
// (translation: users cannot backspace or delete across table cells)
if (HTMLEditUtils::IsAnyTableElement(&aCurrentBlockElement)) {
return false;
return EditActionCanceled();
}
// First find the relevant nodes
nsCOMPtr<nsINode> leftNode, rightNode;
if (aDirectionAndAmount == nsIEditor::ePrevious) {
mLeftContent =
aHTMLEditor.GetPreviousEditableHTMLNode(aCurrentBlockElement);
mRightContent = aCaretPoint.GetContainerAsContent();
leftNode = GetPreviousEditableHTMLNode(aCurrentBlockElement);
rightNode = aCaretPoint.GetContainer();
} else {
mRightContent = aHTMLEditor.GetNextEditableHTMLNode(aCurrentBlockElement);
mLeftContent = aCaretPoint.GetContainerAsContent();
rightNode = GetNextEditableHTMLNode(aCurrentBlockElement);
leftNode = aCaretPoint.GetContainer();
}
// Nothing to join
if (!mLeftContent || !mRightContent) {
return false;
if (!leftNode || !rightNode) {
return EditActionCanceled();
}
// Don't cross table boundaries.
return !HTMLEditor::NodesInDifferentTableElements(*mLeftContent,
*mRightContent);
}
EditActionResult HTMLEditor::AutoBlockElementsJoiner::
HandleDeleteCollapsedSelectionAtCurrentBlockBoundary(
HTMLEditor& aHTMLEditor, const EditorDOMPoint& aCaretPoint) {
MOZ_ASSERT(mLeftContent);
MOZ_ASSERT(mRightContent);
// Don't cross table boundaries -- cancel it
if (HTMLEditor::NodesInDifferentTableElements(*leftNode, *rightNode)) {
return EditActionCanceled();
}
EditActionResult result(NS_OK);
EditorDOMPoint pointToPutCaret(aCaretPoint);
{
AutoTrackDOMPoint tracker(aHTMLEditor.RangeUpdaterRef(), &pointToPutCaret);
result |= aHTMLEditor.TryToJoinBlocksWithTransaction(
MOZ_KnownLive(*mLeftContent), MOZ_KnownLive(*mRightContent));
AutoTrackDOMPoint tracker(RangeUpdaterRef(), &pointToPutCaret);
if (NS_WARN_IF(!leftNode->IsContent()) ||
NS_WARN_IF(!rightNode->IsContent())) {
return EditActionResult(NS_ERROR_FAILURE);
}
result |=
TryToJoinBlocksWithTransaction(MOZ_KnownLive(*leftNode->AsContent()),
MOZ_KnownLive(*rightNode->AsContent()));
// This should claim that trying to join the block means that
// this handles the action because the caller shouldn't do anything
// anymore in this case.
@ -3216,7 +3212,7 @@ EditActionResult HTMLEditor::AutoBlockElementsJoiner::
return result;
}
}
nsresult rv = aHTMLEditor.CollapseSelectionTo(pointToPutCaret);
nsresult rv = CollapseSelectionTo(pointToPutCaret);
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
return result.SetResult(NS_ERROR_EDITOR_DESTROYED);
}

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

@ -2681,64 +2681,6 @@ class HTMLEditor final : public TextEditor,
nsIEditor::EStripWrappers aStripWrappers, nsIContent& aAtomicContent,
const EditorDOMPoint& aCaretPoint, WSRunScanner& aWSRunScannerAtCaret);
class MOZ_STACK_CLASS AutoBlockElementsJoiner final {
public:
/**
* PrepareToDeleteCollapsedSelectionAtCurrentBlockBoundary() considers
* left content and right content which are joined for handling deletion
* at current block boundary (i.e., at start or end of the current block).
*
* @param aHTMLEditor The HTML editor.
* @param aDirectionAndAmount Direction of the deletion.
* @param aCurrentBlockElement The current block element.
* @param aCaretPoint The caret point (i.e., selection start
* or end).
* @return true if can continue to handle the
* deletion.
*/
bool PrepareToDeleteCollapsedSelectionAtCurrentBlockBoundary(
const HTMLEditor& aHTMLEditor,
nsIEditor::EDirection aDirectionAndAmount,
Element& aCurrentBlockElement, const EditorDOMPoint& aCaretPoint);
/**
* Run() executes the joining.
*
* @param aHTMLEditor The HTML editor.
* @param aCaretPoint The caret point (i.e., selection start or end).
*/
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
Run(HTMLEditor& aHTMLEditor, const EditorDOMPoint& aCaretPoint) {
switch (mMode) {
case Mode::JoinCurrentBlock: {
EditActionResult result =
HandleDeleteCollapsedSelectionAtCurrentBlockBoundary(aHTMLEditor,
aCaretPoint);
NS_WARNING_ASSERTION(
result.Succeeded(),
"AutoBlockElementsJoiner::"
"HandleDeleteCollapsedSelectionAtCurrentBlockBoundary() failed");
return result;
}
case Mode::NotInitialized:
return EditActionIgnored();
}
}
private:
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
HandleDeleteCollapsedSelectionAtCurrentBlockBoundary(
HTMLEditor& aHTMLEditor, const EditorDOMPoint& aCaretPoint);
enum class Mode {
NotInitialized,
JoinCurrentBlock,
};
nsCOMPtr<nsIContent> mLeftContent;
nsCOMPtr<nsIContent> mRightContent;
Mode mMode = Mode::NotInitialized;
};
/**
* HandleDeleteCollapsedSelectionAtOtherBlockBoundary() handles deletion at
* other block boundary (i.e., immediately before or after a block).
@ -2760,6 +2702,20 @@ class HTMLEditor final : public TextEditor,
nsIEditor::EStripWrappers aStripWrappers, Element& aOtherBlockElement,
const EditorDOMPoint& aCaretPoint, WSRunScanner& aWSRunScannerAtCaret);
/**
* HandleDeleteCollapsedSelectionAtCurrentBlockBoundary() handles deletion
* at current block boundary (i.e., at start or end of current block).
*
* @param aDirectionAndAmount Direction of the deletion.
* @param aCurrentBlockElement The current block element.
* @param aCaretPoint The caret point (i.e., selection start
* or end).
*/
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
HandleDeleteCollapsedSelectionAtCurrentBlockBoundary(
nsIEditor::EDirection aDirectionAndAmount, Element& aCurrentBlockElement,
const EditorDOMPoint& aCaretPoint);
/**
* DeleteUnnecessaryNodesAndCollapseSelection() removes unnecessary nodes
* around aSelectionStartPoint and aSelectionEndPoint. Then, collapse