Bug 1451672 - part 8: Rename EditorBase::DeleteText() to EditorBase::DeleteTextWithTransaction() r?m_kato
MozReview-Commit-ID: KK4dTpKbpLc
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -3040,19 +3040,19 @@ EditorBase::SetTextImpl(Selection& aSele
}
}
}
return rv;
}
nsresult
-EditorBase::DeleteText(CharacterData& aCharData,
- uint32_t aOffset,
- uint32_t aLength)
+EditorBase::DeleteTextWithTransaction(CharacterData& aCharData,
+ uint32_t aOffset,
+ uint32_t aLength)
{
RefPtr<DeleteTextTransaction> transaction =
DeleteTextTransaction::MaybeCreate(*this, aCharData, aOffset, aLength);
if (NS_WARN_IF(!transaction)) {
return NS_ERROR_FAILURE;
}
AutoRules beginRulesSniffing(this, EditAction::deleteText,
--- a/editor/libeditor/EditorBase.h
+++ b/editor/libeditor/EditorBase.h
@@ -575,18 +575,25 @@ protected:
*/
already_AddRefed<EditTransactionBase>
CreateTxnForDeleteRange(nsRange* aRangeToDelete,
EDirection aAction,
nsINode** aRemovingNode,
int32_t* aOffset,
int32_t* aLength);
- nsresult DeleteText(dom::CharacterData& aElement,
- uint32_t aOffset, uint32_t aLength);
+ /**
+ * DeleteTextWithTransaction() removes text in the range from aCharData.
+ *
+ * @param aCharData The data node which should be modified.
+ * @param aOffset Start offset of removing text in aCharData.
+ * @param aLength Length of removing text.
+ */
+ nsresult DeleteTextWithTransaction(dom::CharacterData& aCharacterData,
+ uint32_t aOffset, uint32_t aLength);
/**
* This method first deletes the selection, if it's not collapsed. Then if
* the selection lies in a CharacterData node, it splits it. If the
* selection is at this point collapsed in a CharacterData node, it's
* adjusted to be collapsed right before or after the node instead (which is
* always possible, since the node was split).
*/
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -2325,25 +2325,31 @@ HTMLEditRules::WillDeleteSelection(Selec
NS_ASSERTION(range->GetStartContainer() == visNode,
"selection start not in visNode");
NS_ASSERTION(range->GetEndContainer() == visNode,
"selection end not in visNode");
so = range->StartOffset();
eo = range->EndOffset();
}
- NS_ENSURE_STATE(mHTMLEditor);
- rv = WSRunObject::PrepareToDeleteRange(mHTMLEditor, address_of(visNode),
+ if (NS_WARN_IF(!mHTMLEditor)) {
+ return NS_ERROR_FAILURE;
+ }
+ RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
+ rv = WSRunObject::PrepareToDeleteRange(htmlEditor, address_of(visNode),
&so, address_of(visNode), &eo);
- NS_ENSURE_SUCCESS(rv, rv);
- NS_ENSURE_STATE(mHTMLEditor);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
*aHandled = true;
- rv = mHTMLEditor->DeleteText(nodeAsText, std::min(so, eo),
- DeprecatedAbs(eo - so));
- NS_ENSURE_SUCCESS(rv, rv);
+ rv = htmlEditor->DeleteTextWithTransaction(nodeAsText, std::min(so, eo),
+ DeprecatedAbs(eo - so));
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
// XXX When Backspace key is pressed, Chromium removes following empty
// text nodes when removing the last character of the non-empty text
// node. However, Edge never removes empty text nodes even if
// selection is in the following empty text node(s). For now, we
// should keep our traditional behavior same as Edge for backward
// compatibility.
// XXX When Delete key is pressed, Edge removes all preceding empty
@@ -2818,31 +2824,42 @@ HTMLEditRules::WillDeleteSelection(Selec
}
// Check endpoints for possible text deletion. We can assume that if
// text node is found, we can delete to end or to begining as
// appropriate, since the case where both sel endpoints in same text
// node was already handled (we wouldn't be here)
if (startNode->GetAsText() &&
startNode->Length() > static_cast<uint32_t>(startOffset)) {
+ if (NS_WARN_IF(!mHTMLEditor)) {
+ return NS_ERROR_FAILURE;
+ }
+ RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
// Delete to last character
OwningNonNull<CharacterData> dataNode =
*static_cast<CharacterData*>(startNode.get());
- NS_ENSURE_STATE(mHTMLEditor);
- rv = mHTMLEditor->DeleteText(dataNode, startOffset,
- startNode->Length() - startOffset);
- NS_ENSURE_SUCCESS(rv, rv);
+ rv = htmlEditor->DeleteTextWithTransaction(
+ dataNode, startOffset,
+ startNode->Length() - startOffset);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
}
if (endNode->GetAsText() && endOffset) {
+ if (NS_WARN_IF(!mHTMLEditor)) {
+ return NS_ERROR_FAILURE;
+ }
+ RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
// Delete to first character
- NS_ENSURE_STATE(mHTMLEditor);
OwningNonNull<CharacterData> dataNode =
*static_cast<CharacterData*>(endNode.get());
- rv = mHTMLEditor->DeleteText(dataNode, 0, endOffset);
- NS_ENSURE_SUCCESS(rv, rv);
+ rv = htmlEditor->DeleteTextWithTransaction(dataNode, 0, endOffset);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
}
if (join) {
EditActionResult ret =
TryToJoinBlocksWithTransaction(*leftParent, *rightParent);
MOZ_ASSERT(*aHandled);
*aCancel |= ret.Canceled();
if (NS_WARN_IF(ret.Failed())) {
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -3226,26 +3226,26 @@ HTMLEditor::DeleteNode(nsIDOMNode* aDOMN
nsresult rv = DeleteNodeWithTransaction(*node);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
nsresult
-HTMLEditor::DeleteText(CharacterData& aCharData,
- uint32_t aOffset,
- uint32_t aLength)
+HTMLEditor::DeleteTextWithTransaction(CharacterData& aCharData,
+ uint32_t aOffset,
+ uint32_t aLength)
{
// Do nothing if the node is read-only
if (!IsModifiableNode(&aCharData)) {
return NS_ERROR_FAILURE;
}
- return EditorBase::DeleteText(aCharData, aOffset, aLength);
+ return EditorBase::DeleteTextWithTransaction(aCharData, aOffset, aLength);
}
nsresult
HTMLEditor::InsertTextImpl(nsIDocument& aDocument,
const nsAString& aStringToInsert,
const EditorRawDOMPoint& aPointToInsert,
EditorRawDOMPoint* aPointAfterInsertedString)
{
--- a/editor/libeditor/HTMLEditor.h
+++ b/editor/libeditor/HTMLEditor.h
@@ -392,18 +392,28 @@ public:
* EditorBase.
*
* @param aNode The node to be removed from the DOM tree.
*/
nsresult DeleteNodeWithTransaction(nsINode& aNode);
NS_IMETHOD DeleteNode(nsIDOMNode* aNode) override;
- nsresult DeleteText(dom::CharacterData& aTextNode, uint32_t aOffset,
- uint32_t aLength);
+ /**
+ * DeleteTextWithTransaction() removes text in the range from aCharData if
+ * it's modifiable. Note that this not an override of same method of
+ * EditorBase.
+ *
+ * @param aCharData The data node which should be modified.
+ * @param aOffset Start offset of removing text in aCharData.
+ * @param aLength Length of removing text.
+ */
+ nsresult DeleteTextWithTransaction(dom::CharacterData& aTextNode,
+ uint32_t aOffset, uint32_t aLength);
+
virtual nsresult
InsertTextImpl(nsIDocument& aDocument,
const nsAString& aStringToInsert,
const EditorRawDOMPoint& aPointToInsert,
EditorRawDOMPoint* aPointAfterInsertedString =
nullptr) override;
virtual bool IsModifiableNode(nsINode* aNode) override;
--- a/editor/libeditor/WSRunObject.cpp
+++ b/editor/libeditor/WSRunObject.cpp
@@ -1362,19 +1362,20 @@ WSRunObject::DeleteRange(const EditorDOM
return NS_OK;
}
MOZ_ASSERT(mHTMLEditor);
RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
if (aStartPoint.GetContainer() == aEndPoint.GetContainer() &&
aStartPoint.IsInTextNode()) {
- return htmlEditor->DeleteText(*aStartPoint.GetContainerAsText(),
- aStartPoint.Offset(),
- aEndPoint.Offset() - aStartPoint.Offset());
+ return htmlEditor->DeleteTextWithTransaction(
+ *aStartPoint.GetContainerAsText(),
+ aStartPoint.Offset(),
+ aEndPoint.Offset() - aStartPoint.Offset());
}
RefPtr<nsRange> range;
int32_t count = mNodeArray.Length();
int32_t idx = mNodeArray.IndexOf(aStartPoint.GetContainer());
if (idx == -1) {
// If our starting point wasn't one of our ws text nodes, then just go
// through them from the beginning.
@@ -1384,26 +1385,28 @@ WSRunObject::DeleteRange(const EditorDOM
RefPtr<Text> node = mNodeArray[idx];
if (!node) {
// We ran out of ws nodes; must have been deleting to end
return NS_OK;
}
if (node == aStartPoint.GetContainer()) {
if (!aStartPoint.IsEndOfContainer()) {
nsresult rv =
- htmlEditor->DeleteText(*node, aStartPoint.Offset(),
- aStartPoint.GetContainer()->Length() -
- aStartPoint.Offset());
+ htmlEditor->DeleteTextWithTransaction(
+ *node, aStartPoint.Offset(),
+ aStartPoint.GetContainer()->Length() -
+ aStartPoint.Offset());
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
} else if (node == aEndPoint.GetContainer()) {
if (!aEndPoint.IsStartOfContainer()) {
- nsresult rv = htmlEditor->DeleteText(*node, 0, aEndPoint.Offset());
+ nsresult rv =
+ htmlEditor->DeleteTextWithTransaction(*node, 0, aEndPoint.Offset());
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
break;
} else {
if (!range) {
range = new nsRange(aStartPoint.GetContainer());