mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1055032 part 4 - Clean up DeleteTextTxn and friends; r=ehsan
This commit is contained in:
parent
9d43c392fa
commit
a542d2e393
@ -139,8 +139,6 @@ DeleteRangeTxn::CreateTxnsToDeleteBetween(nsINode* aNode,
|
||||
// see what kind of node we have
|
||||
if (aNode->IsNodeOfType(nsINode::eDATA_NODE)) {
|
||||
// if the node is a chardata node, then delete chardata content
|
||||
nsRefPtr<DeleteTextTxn> txn = new DeleteTextTxn();
|
||||
|
||||
int32_t numToDel;
|
||||
if (aStartOffset == aEndOffset) {
|
||||
numToDel = 1;
|
||||
@ -148,9 +146,14 @@ DeleteRangeTxn::CreateTxnsToDeleteBetween(nsINode* aNode,
|
||||
numToDel = aEndOffset - aStartOffset;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMCharacterData> charDataNode = do_QueryInterface(aNode);
|
||||
nsresult res = txn->Init(mEditor, charDataNode, aStartOffset, numToDel,
|
||||
mRangeUpdater);
|
||||
nsRefPtr<nsGenericDOMDataNode> charDataNode =
|
||||
static_cast<nsGenericDOMDataNode*>(aNode);
|
||||
|
||||
nsRefPtr<DeleteTextTxn> txn =
|
||||
new DeleteTextTxn(*mEditor, *charDataNode, aStartOffset, numToDel,
|
||||
mRangeUpdater);
|
||||
|
||||
nsresult res = txn->Init();
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
|
||||
AppendChild(txn);
|
||||
@ -193,11 +196,12 @@ DeleteRangeTxn::CreateTxnsToDeleteContent(nsINode* aNode,
|
||||
}
|
||||
|
||||
if (numToDelete) {
|
||||
nsRefPtr<DeleteTextTxn> txn = new DeleteTextTxn();
|
||||
nsRefPtr<nsGenericDOMDataNode> dataNode =
|
||||
static_cast<nsGenericDOMDataNode*>(aNode);
|
||||
nsRefPtr<DeleteTextTxn> txn = new DeleteTextTxn(*mEditor, *dataNode,
|
||||
start, numToDelete, mRangeUpdater);
|
||||
|
||||
nsCOMPtr<nsIDOMCharacterData> charDataNode = do_QueryInterface(aNode);
|
||||
nsresult res = txn->Init(mEditor, charDataNode, start, numToDelete,
|
||||
mRangeUpdater);
|
||||
nsresult res = txn->Init();
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
|
||||
AppendChild(txn);
|
||||
|
@ -19,14 +19,19 @@
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
||||
DeleteTextTxn::DeleteTextTxn() :
|
||||
EditTxn(),
|
||||
mEditor(nullptr),
|
||||
mCharData(),
|
||||
mOffset(0),
|
||||
mNumCharsToDelete(0),
|
||||
mRangeUpdater(nullptr)
|
||||
DeleteTextTxn::DeleteTextTxn(nsEditor& aEditor,
|
||||
nsGenericDOMDataNode& aCharData, uint32_t aOffset,
|
||||
uint32_t aNumCharsToDelete,
|
||||
nsRangeUpdater* aRangeUpdater)
|
||||
: EditTxn()
|
||||
, mEditor(aEditor)
|
||||
, mCharData(&aCharData)
|
||||
, mOffset(aOffset)
|
||||
, mNumCharsToDelete(aNumCharsToDelete)
|
||||
, mRangeUpdater(aRangeUpdater)
|
||||
{
|
||||
NS_ASSERTION(mCharData->Length() >= aOffset + aNumCharsToDelete,
|
||||
"Trying to delete more characters than in node");
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_INHERITED(DeleteTextTxn, EditTxn,
|
||||
@ -35,42 +40,23 @@ NS_IMPL_CYCLE_COLLECTION_INHERITED(DeleteTextTxn, EditTxn,
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DeleteTextTxn)
|
||||
NS_INTERFACE_MAP_END_INHERITING(EditTxn)
|
||||
|
||||
NS_IMETHODIMP
|
||||
DeleteTextTxn::Init(nsEditor* aEditor,
|
||||
nsIDOMCharacterData* aCharData,
|
||||
uint32_t aOffset,
|
||||
uint32_t aNumCharsToDelete,
|
||||
nsRangeUpdater* aRangeUpdater)
|
||||
nsresult
|
||||
DeleteTextTxn::Init()
|
||||
{
|
||||
MOZ_ASSERT(aEditor && aCharData);
|
||||
|
||||
mEditor = aEditor;
|
||||
mCharData = aCharData;
|
||||
|
||||
// do nothing if the node is read-only
|
||||
if (!mEditor->IsModifiableNode(mCharData)) {
|
||||
// Do nothing if the node is read-only
|
||||
if (!mEditor.IsModifiableNode(mCharData)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
mOffset = aOffset;
|
||||
mNumCharsToDelete = aNumCharsToDelete;
|
||||
#ifdef DEBUG
|
||||
uint32_t length;
|
||||
mCharData->GetLength(&length);
|
||||
NS_ASSERTION(length >= aOffset + aNumCharsToDelete,
|
||||
"Trying to delete more characters than in node");
|
||||
#endif
|
||||
mDeletedText.Truncate();
|
||||
mRangeUpdater = aRangeUpdater;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DeleteTextTxn::DoTransaction()
|
||||
{
|
||||
MOZ_ASSERT(mEditor && mCharData);
|
||||
MOZ_ASSERT(mCharData);
|
||||
|
||||
// get the text that we're about to delete
|
||||
// Get the text that we're about to delete
|
||||
nsresult res = mCharData->SubstringData(mOffset, mNumCharsToDelete,
|
||||
mDeletedText);
|
||||
MOZ_ASSERT(NS_SUCCEEDED(res));
|
||||
@ -81,27 +67,25 @@ DeleteTextTxn::DoTransaction()
|
||||
mRangeUpdater->SelAdjDeleteText(mCharData, mOffset, mNumCharsToDelete);
|
||||
}
|
||||
|
||||
// only set selection to deletion point if editor gives permission
|
||||
bool bAdjustSelection;
|
||||
mEditor->ShouldTxnSetSelection(&bAdjustSelection);
|
||||
if (bAdjustSelection) {
|
||||
nsRefPtr<Selection> selection = mEditor->GetSelection();
|
||||
// Only set selection to deletion point if editor gives permission
|
||||
if (mEditor.GetShouldTxnSetSelection()) {
|
||||
nsRefPtr<Selection> selection = mEditor.GetSelection();
|
||||
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
|
||||
res = selection->Collapse(mCharData, mOffset);
|
||||
NS_ASSERTION(NS_SUCCEEDED(res),
|
||||
"selection could not be collapsed after undo of deletetext.");
|
||||
"Selection could not be collapsed after undo of deletetext");
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
}
|
||||
// else do nothing - dom range gravity will adjust selection
|
||||
// Else do nothing - DOM Range gravity will adjust selection
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//XXX: we may want to store the selection state and restore it properly
|
||||
// was it an insertion point or an extended selection?
|
||||
//XXX: We may want to store the selection state and restore it properly. Was
|
||||
// it an insertion point or an extended selection?
|
||||
NS_IMETHODIMP
|
||||
DeleteTextTxn::UndoTransaction()
|
||||
{
|
||||
MOZ_ASSERT(mEditor && mCharData);
|
||||
MOZ_ASSERT(mCharData);
|
||||
|
||||
return mCharData->InsertData(mOffset, mDeletedText);
|
||||
}
|
||||
|
@ -9,14 +9,17 @@
|
||||
#include "EditTxn.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsGenericDOMDataNode.h"
|
||||
#include "nsID.h"
|
||||
#include "nsIDOMCharacterData.h"
|
||||
#include "nsString.h"
|
||||
#include "nscore.h"
|
||||
|
||||
class nsEditor;
|
||||
class nsRangeUpdater;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
/**
|
||||
* A transaction that removes text from a content node.
|
||||
*/
|
||||
@ -29,13 +32,13 @@ public:
|
||||
* @param aOffset the location in aElement to begin the deletion
|
||||
* @param aNumCharsToDelete the number of characters to delete. Not the number of bytes!
|
||||
*/
|
||||
NS_IMETHOD Init(nsEditor* aEditor,
|
||||
nsIDOMCharacterData* aCharData,
|
||||
uint32_t aOffset,
|
||||
uint32_t aNumCharsToDelete,
|
||||
nsRangeUpdater* aRangeUpdater);
|
||||
DeleteTextTxn(nsEditor& aEditor,
|
||||
nsGenericDOMDataNode& aCharData,
|
||||
uint32_t aOffset,
|
||||
uint32_t aNumCharsToDelete,
|
||||
nsRangeUpdater* aRangeUpdater);
|
||||
|
||||
DeleteTextTxn();
|
||||
nsresult Init();
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DeleteTextTxn, EditTxn)
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
|
||||
@ -49,10 +52,10 @@ public:
|
||||
protected:
|
||||
|
||||
/** the provider of basic editing operations */
|
||||
nsEditor* mEditor;
|
||||
nsEditor& mEditor;
|
||||
|
||||
/** the CharacterData node to operate upon */
|
||||
nsCOMPtr<nsIDOMCharacterData> mCharData;
|
||||
nsRefPtr<nsGenericDOMDataNode> mCharData;
|
||||
|
||||
/** the offset into mCharData where the deletion is to take place */
|
||||
uint32_t mOffset;
|
||||
@ -67,4 +70,7 @@ protected:
|
||||
nsRangeUpdater* mRangeUpdater;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -2567,46 +2567,47 @@ NS_IMETHODIMP nsEditor::CreateTxnForInsertText(const nsAString & aStringToInsert
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsEditor::DeleteText(nsIDOMCharacterData *aElement,
|
||||
uint32_t aOffset,
|
||||
uint32_t aLength)
|
||||
nsresult
|
||||
nsEditor::DeleteText(nsGenericDOMDataNode& aCharData, uint32_t aOffset,
|
||||
uint32_t aLength)
|
||||
{
|
||||
nsRefPtr<DeleteTextTxn> txn;
|
||||
nsresult result = CreateTxnForDeleteText(aElement, aOffset, aLength,
|
||||
getter_AddRefs(txn));
|
||||
nsRefPtr<DeleteTextTxn> txn =
|
||||
CreateTxnForDeleteText(aCharData, aOffset, aLength);
|
||||
NS_ENSURE_STATE(txn);
|
||||
|
||||
nsAutoRules beginRulesSniffing(this, EditAction::deleteText, nsIEditor::ePrevious);
|
||||
if (NS_SUCCEEDED(result))
|
||||
{
|
||||
// let listeners know what's up
|
||||
int32_t i;
|
||||
for (i = 0; i < mActionListeners.Count(); i++)
|
||||
mActionListeners[i]->WillDeleteText(aElement, aOffset, aLength);
|
||||
|
||||
result = DoTransaction(txn);
|
||||
|
||||
// let listeners know what happened
|
||||
for (i = 0; i < mActionListeners.Count(); i++)
|
||||
mActionListeners[i]->DidDeleteText(aElement, aOffset, aLength, result);
|
||||
|
||||
// Let listeners know what's up
|
||||
for (int32_t i = 0; i < mActionListeners.Count(); i++) {
|
||||
mActionListeners[i]->WillDeleteText(
|
||||
static_cast<nsIDOMCharacterData*>(GetAsDOMNode(&aCharData)), aOffset,
|
||||
aLength);
|
||||
}
|
||||
return result;
|
||||
|
||||
nsresult res = DoTransaction(txn);
|
||||
|
||||
// Let listeners know what happened
|
||||
for (int32_t i = 0; i < mActionListeners.Count(); i++) {
|
||||
mActionListeners[i]->DidDeleteText(
|
||||
static_cast<nsIDOMCharacterData*>(GetAsDOMNode(&aCharData)), aOffset,
|
||||
aLength, res);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsEditor::CreateTxnForDeleteText(nsIDOMCharacterData* aElement,
|
||||
uint32_t aOffset,
|
||||
uint32_t aLength,
|
||||
DeleteTextTxn** aTxn)
|
||||
already_AddRefed<DeleteTextTxn>
|
||||
nsEditor::CreateTxnForDeleteText(nsGenericDOMDataNode& aCharData,
|
||||
uint32_t aOffset, uint32_t aLength)
|
||||
{
|
||||
NS_ENSURE_TRUE(aElement, NS_ERROR_NULL_POINTER);
|
||||
nsRefPtr<DeleteTextTxn> txn =
|
||||
new DeleteTextTxn(*this, aCharData, aOffset, aLength, &mRangeUpdater);
|
||||
|
||||
nsRefPtr<DeleteTextTxn> txn = new DeleteTextTxn();
|
||||
nsresult res = txn->Init();
|
||||
NS_ENSURE_SUCCESS(res, nullptr);
|
||||
|
||||
nsresult res = txn->Init(this, aElement, aOffset, aLength, &mRangeUpdater);
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
|
||||
txn.forget(aTxn);
|
||||
return NS_OK;
|
||||
return txn.forget();
|
||||
}
|
||||
|
||||
|
||||
@ -4433,25 +4434,23 @@ nsEditor::CreateTxnForDeleteSelection(EDirection aAction,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsEditor::CreateTxnForDeleteCharacter(nsIDOMCharacterData* aData,
|
||||
uint32_t aOffset,
|
||||
EDirection aDirection,
|
||||
DeleteTextTxn** aTxn)
|
||||
already_AddRefed<DeleteTextTxn>
|
||||
nsEditor::CreateTxnForDeleteCharacter(nsGenericDOMDataNode& aData,
|
||||
uint32_t aOffset, EDirection aDirection)
|
||||
{
|
||||
NS_ASSERTION(aDirection == eNext || aDirection == ePrevious,
|
||||
"invalid direction");
|
||||
"Invalid direction");
|
||||
nsAutoString data;
|
||||
aData->GetData(data);
|
||||
aData.GetData(data);
|
||||
NS_ASSERTION(data.Length(), "Trying to delete from a zero-length node");
|
||||
NS_ENSURE_STATE(data.Length());
|
||||
NS_ENSURE_TRUE(data.Length(), nullptr);
|
||||
|
||||
uint32_t segOffset = aOffset, segLength = 1;
|
||||
if (aDirection == eNext) {
|
||||
if (segOffset + 1 < data.Length() &&
|
||||
NS_IS_HIGH_SURROGATE(data[segOffset]) &&
|
||||
NS_IS_LOW_SURROGATE(data[segOffset+1])) {
|
||||
// delete both halves of the surrogate pair
|
||||
// Delete both halves of the surrogate pair
|
||||
++segLength;
|
||||
}
|
||||
} else if (aOffset > 0) {
|
||||
@ -4463,9 +4462,9 @@ nsEditor::CreateTxnForDeleteCharacter(nsIDOMCharacterData* aData,
|
||||
--segOffset;
|
||||
}
|
||||
} else {
|
||||
return NS_ERROR_FAILURE;
|
||||
return nullptr;
|
||||
}
|
||||
return CreateTxnForDeleteText(aData, segOffset, segLength, aTxn);
|
||||
return CreateTxnForDeleteText(aData, segOffset, segLength);
|
||||
}
|
||||
|
||||
//XXX: currently, this doesn't handle edge conditions because GetNext/GetPrior
|
||||
@ -4490,7 +4489,6 @@ nsEditor::CreateTxnForDeleteInsertionPoint(nsRange* aRange,
|
||||
|
||||
// determine if the insertion point is at the beginning, middle, or end of
|
||||
// the node
|
||||
nsCOMPtr<nsIDOMCharacterData> nodeAsCharData = do_QueryInterface(node);
|
||||
|
||||
uint32_t count = node->Length();
|
||||
|
||||
@ -4510,16 +4508,15 @@ nsEditor::CreateTxnForDeleteInsertionPoint(nsRange* aRange,
|
||||
|
||||
// there is a priorNode, so delete its last child (if chardata, delete the
|
||||
// last char). if it has no children, delete it
|
||||
nsCOMPtr<nsIDOMCharacterData> priorNodeAsCharData =
|
||||
do_QueryInterface(priorNode);
|
||||
if (priorNodeAsCharData) {
|
||||
if (priorNode->IsNodeOfType(nsINode::eDATA_NODE)) {
|
||||
nsRefPtr<nsGenericDOMDataNode> priorNodeAsCharData =
|
||||
static_cast<nsGenericDOMDataNode*>(priorNode.get());
|
||||
uint32_t length = priorNode->Length();
|
||||
// Bail out for empty chardata XXX: Do we want to do something else?
|
||||
NS_ENSURE_STATE(length);
|
||||
nsRefPtr<DeleteTextTxn> txn;
|
||||
res = CreateTxnForDeleteCharacter(priorNodeAsCharData, length,
|
||||
ePrevious, getter_AddRefs(txn));
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
nsRefPtr<DeleteTextTxn> txn =
|
||||
CreateTxnForDeleteCharacter(*priorNodeAsCharData, length, ePrevious);
|
||||
NS_ENSURE_STATE(txn);
|
||||
|
||||
*aOffset = txn->GetOffset();
|
||||
*aLength = txn->GetNumCharsToDelete();
|
||||
@ -4546,16 +4543,15 @@ nsEditor::CreateTxnForDeleteInsertionPoint(nsRange* aRange,
|
||||
|
||||
// there is a nextNode, so delete its first child (if chardata, delete the
|
||||
// first char). if it has no children, delete it
|
||||
nsCOMPtr<nsIDOMCharacterData> nextNodeAsCharData =
|
||||
do_QueryInterface(nextNode);
|
||||
if (nextNodeAsCharData) {
|
||||
if (nextNode->IsNodeOfType(nsINode::eDATA_NODE)) {
|
||||
nsRefPtr<nsGenericDOMDataNode> nextNodeAsCharData =
|
||||
static_cast<nsGenericDOMDataNode*>(nextNode.get());
|
||||
uint32_t length = nextNode->Length();
|
||||
// Bail out for empty chardata XXX: Do we want to do something else?
|
||||
NS_ENSURE_STATE(length);
|
||||
nsRefPtr<DeleteTextTxn> txn;
|
||||
res = CreateTxnForDeleteCharacter(nextNodeAsCharData, 0, eNext,
|
||||
getter_AddRefs(txn));
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
nsRefPtr<DeleteTextTxn> txn =
|
||||
CreateTxnForDeleteCharacter(*nextNodeAsCharData, 0, eNext);
|
||||
NS_ENSURE_STATE(txn);
|
||||
|
||||
*aOffset = txn->GetOffset();
|
||||
*aLength = txn->GetNumCharsToDelete();
|
||||
@ -4573,12 +4569,13 @@ nsEditor::CreateTxnForDeleteInsertionPoint(nsRange* aRange,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (nodeAsCharData) {
|
||||
if (node->IsNodeOfType(nsINode::eDATA_NODE)) {
|
||||
nsRefPtr<nsGenericDOMDataNode> nodeAsCharData =
|
||||
static_cast<nsGenericDOMDataNode*>(node.get());
|
||||
// we have chardata, so delete a char at the proper offset
|
||||
nsRefPtr<DeleteTextTxn> txn;
|
||||
res = CreateTxnForDeleteCharacter(nodeAsCharData, offset, aAction,
|
||||
getter_AddRefs(txn));
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
nsRefPtr<DeleteTextTxn> txn = CreateTxnForDeleteCharacter(*nodeAsCharData,
|
||||
offset, aAction);
|
||||
NS_ENSURE_STATE(txn);
|
||||
|
||||
aTxn->AppendChild(txn);
|
||||
NS_ADDREF(*aNode = node);
|
||||
@ -4606,18 +4603,17 @@ nsEditor::CreateTxnForDeleteInsertionPoint(nsRange* aRange,
|
||||
}
|
||||
NS_ENSURE_STATE(selectedNode);
|
||||
|
||||
nsCOMPtr<nsIDOMCharacterData> selectedNodeAsCharData =
|
||||
do_QueryInterface(selectedNode);
|
||||
if (selectedNodeAsCharData) {
|
||||
if (selectedNode->IsNodeOfType(nsINode::eDATA_NODE)) {
|
||||
nsRefPtr<nsGenericDOMDataNode> selectedNodeAsCharData =
|
||||
static_cast<nsGenericDOMDataNode*>(selectedNode.get());
|
||||
// we are deleting from a chardata node, so do a character deletion
|
||||
uint32_t position = 0;
|
||||
if (aAction == ePrevious) {
|
||||
position = selectedNode->Length();
|
||||
}
|
||||
nsRefPtr<DeleteTextTxn> delTextTxn;
|
||||
res = CreateTxnForDeleteCharacter(selectedNodeAsCharData, position,
|
||||
aAction, getter_AddRefs(delTextTxn));
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
nsRefPtr<DeleteTextTxn> delTextTxn =
|
||||
CreateTxnForDeleteCharacter(*selectedNodeAsCharData, position,
|
||||
aAction);
|
||||
NS_ENSURE_TRUE(delTextTxn, NS_ERROR_NULL_POINTER);
|
||||
|
||||
aTxn->AppendChild(delTextTxn);
|
||||
|
@ -30,7 +30,6 @@
|
||||
class AddStyleSheetTxn;
|
||||
class ChangeAttributeTxn;
|
||||
class DeleteNodeTxn;
|
||||
class DeleteTextTxn;
|
||||
class EditAggregateTxn;
|
||||
class IMETextTxn;
|
||||
class InsertElementTxn;
|
||||
@ -73,6 +72,7 @@ class TextComposition;
|
||||
namespace dom {
|
||||
class CreateElementTxn;
|
||||
class DataTransfer;
|
||||
class DeleteTextTxn;
|
||||
class Element;
|
||||
class EventTarget;
|
||||
class Selection;
|
||||
@ -330,28 +330,18 @@ protected:
|
||||
NS_IMETHOD CreateTxnForRemoveStyleSheet(mozilla::CSSStyleSheet* aSheet,
|
||||
RemoveStyleSheetTxn* *aTxn);
|
||||
|
||||
NS_IMETHOD DeleteText(nsIDOMCharacterData *aElement,
|
||||
uint32_t aOffset,
|
||||
uint32_t aLength);
|
||||
|
||||
inline nsresult DeleteText(mozilla::dom::Text* aText, uint32_t aOffset,
|
||||
uint32_t aLength)
|
||||
{
|
||||
return DeleteText(static_cast<nsIDOMCharacterData*>(GetAsDOMNode(aText)),
|
||||
aOffset, aLength);
|
||||
}
|
||||
nsresult DeleteText(nsGenericDOMDataNode& aElement,
|
||||
uint32_t aOffset, uint32_t aLength);
|
||||
|
||||
// NS_IMETHOD DeleteRange(nsIDOMRange *aRange);
|
||||
|
||||
nsresult CreateTxnForDeleteText(nsIDOMCharacterData* aElement,
|
||||
uint32_t aOffset,
|
||||
uint32_t aLength,
|
||||
DeleteTextTxn** aTxn);
|
||||
already_AddRefed<mozilla::dom::DeleteTextTxn>
|
||||
CreateTxnForDeleteText(nsGenericDOMDataNode& aElement,
|
||||
uint32_t aOffset, uint32_t aLength);
|
||||
|
||||
nsresult CreateTxnForDeleteCharacter(nsIDOMCharacterData* aData,
|
||||
uint32_t aOffset,
|
||||
EDirection aDirection,
|
||||
DeleteTextTxn** aTxn);
|
||||
already_AddRefed<mozilla::dom::DeleteTextTxn>
|
||||
CreateTxnForDeleteCharacter(nsGenericDOMDataNode& aData, uint32_t aOffset,
|
||||
EDirection aDirection);
|
||||
|
||||
NS_IMETHOD CreateTxnForSplitNode(nsIDOMNode *aNode,
|
||||
uint32_t aOffset,
|
||||
|
@ -2056,9 +2056,10 @@ nsHTMLEditRules::WillDeleteSelection(Selection* aSelection,
|
||||
address_of(visNode_), &so, address_of(visNode_), &eo);
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
visNode = GetAsDOMNode(visNode_);
|
||||
nsCOMPtr<nsIDOMCharacterData> nodeAsText(do_QueryInterface(visNode));
|
||||
nsRefPtr<Text> nodeAsText = visNode_->GetAsText();
|
||||
NS_ENSURE_STATE(mHTMLEditor);
|
||||
res = mHTMLEditor->DeleteText(nodeAsText, std::min(so, eo), DeprecatedAbs(eo - so));
|
||||
res = mHTMLEditor->DeleteText(*nodeAsText, std::min(so, eo),
|
||||
DeprecatedAbs(eo - so));
|
||||
*aHandled = true;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
res = InsertBRIfNeeded(aSelection);
|
||||
@ -2527,14 +2528,15 @@ nsHTMLEditRules::WillDeleteSelection(Selection* aSelection,
|
||||
if ( mHTMLEditor->IsTextNode(startNode) )
|
||||
{
|
||||
// delete to last character
|
||||
nsCOMPtr<nsIDOMCharacterData>nodeAsText;
|
||||
uint32_t len;
|
||||
nodeAsText = do_QueryInterface(startNode);
|
||||
nodeAsText->GetLength(&len);
|
||||
nsCOMPtr<nsINode> node = do_QueryInterface(startNode);
|
||||
uint32_t len = node->Length();
|
||||
if (len > (uint32_t)startOffset)
|
||||
{
|
||||
nsRefPtr<nsGenericDOMDataNode> dataNode =
|
||||
static_cast<nsGenericDOMDataNode*>(node.get());
|
||||
NS_ENSURE_STATE(mHTMLEditor);
|
||||
res = mHTMLEditor->DeleteText(nodeAsText,startOffset,len-startOffset);
|
||||
res = mHTMLEditor->DeleteText(*dataNode, startOffset,
|
||||
len - startOffset);
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
}
|
||||
}
|
||||
@ -2542,12 +2544,13 @@ nsHTMLEditRules::WillDeleteSelection(Selection* aSelection,
|
||||
if ( mHTMLEditor->IsTextNode(endNode) )
|
||||
{
|
||||
// delete to first character
|
||||
nsCOMPtr<nsIDOMCharacterData>nodeAsText;
|
||||
nodeAsText = do_QueryInterface(endNode);
|
||||
nsCOMPtr<nsINode> node = do_QueryInterface(endNode);
|
||||
if (endOffset)
|
||||
{
|
||||
NS_ENSURE_STATE(mHTMLEditor);
|
||||
res = mHTMLEditor->DeleteText(nodeAsText,0,endOffset);
|
||||
nsRefPtr<nsGenericDOMDataNode> dataNode =
|
||||
static_cast<nsGenericDOMDataNode*>(node.get());
|
||||
res = mHTMLEditor->DeleteText(*dataNode, 0, endOffset);
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
}
|
||||
}
|
||||
|
@ -3176,16 +3176,16 @@ nsHTMLEditor::DeleteNode(nsIDOMNode* aNode)
|
||||
return nsEditor::DeleteNode(aNode);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLEditor::DeleteText(nsIDOMCharacterData *aTextNode,
|
||||
uint32_t aOffset,
|
||||
uint32_t aLength)
|
||||
nsresult
|
||||
nsHTMLEditor::DeleteText(nsGenericDOMDataNode& aCharData, uint32_t aOffset,
|
||||
uint32_t aLength)
|
||||
{
|
||||
// do nothing if the node is read-only
|
||||
if (!IsModifiableNode(aTextNode)) {
|
||||
// Do nothing if the node is read-only
|
||||
if (!IsModifiableNode(&aCharData)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return nsEditor::DeleteText(aTextNode, aOffset, aLength);
|
||||
return nsEditor::DeleteText(aCharData, aOffset, aLength);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLEditor::InsertTextImpl(const nsAString& aStringToInsert,
|
||||
|
@ -312,10 +312,8 @@ public:
|
||||
EStripWrappers aStripWrappers);
|
||||
nsresult DeleteNode(nsINode* aNode);
|
||||
NS_IMETHODIMP DeleteNode(nsIDOMNode * aNode);
|
||||
using nsEditor::DeleteText;
|
||||
NS_IMETHODIMP DeleteText(nsIDOMCharacterData *aTextNode,
|
||||
uint32_t aOffset,
|
||||
uint32_t aLength);
|
||||
nsresult DeleteText(nsGenericDOMDataNode& aTextNode, uint32_t aOffset,
|
||||
uint32_t aLength);
|
||||
NS_IMETHOD InsertTextImpl(const nsAString& aStringToInsert,
|
||||
nsCOMPtr<nsIDOMNode> *aInOutNode,
|
||||
int32_t *aInOutOffset,
|
||||
|
@ -4,7 +4,9 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/Casting.h"
|
||||
#include "mozilla/mozalloc.h"
|
||||
|
||||
#include "nsAString.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsCRT.h"
|
||||
@ -1339,8 +1341,9 @@ nsWSRunObject::DeleteChars(nsINode* aStartNode, int32_t aStartOffset,
|
||||
}
|
||||
|
||||
if (aStartNode == aEndNode && aStartNode->GetAsText()) {
|
||||
return mHTMLEditor->DeleteText(aStartNode->GetAsText(),
|
||||
(uint32_t)aStartOffset, (uint32_t)(aEndOffset - aStartOffset));
|
||||
return mHTMLEditor->DeleteText(*aStartNode->GetAsText(),
|
||||
static_cast<uint32_t>(aStartOffset),
|
||||
static_cast<uint32_t>(aEndOffset - aStartOffset));
|
||||
}
|
||||
|
||||
nsresult res;
|
||||
@ -1355,13 +1358,13 @@ nsWSRunObject::DeleteChars(nsINode* aStartNode, int32_t aStartOffset,
|
||||
if (node == aStartNode) {
|
||||
uint32_t len = node->Length();
|
||||
if (uint32_t(aStartOffset) < len) {
|
||||
res = mHTMLEditor->DeleteText(node, (uint32_t)aStartOffset,
|
||||
res = mHTMLEditor->DeleteText(*node, SafeCast<uint32_t>(aStartOffset),
|
||||
len - aStartOffset);
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
}
|
||||
} else if (node == aEndNode) {
|
||||
if (aEndOffset) {
|
||||
res = mHTMLEditor->DeleteText(node, 0, (uint32_t)aEndOffset);
|
||||
res = mHTMLEditor->DeleteText(*node, 0, SafeCast<uint32_t>(aEndOffset));
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
}
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user