зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1407854 - Part 2: Add an optional argument to CreateNode() to allow callers to pass the child node when they know it; r=masayuki
This commit is contained in:
Родитель
e9a78d5b18
Коммит
bf1f474a3d
|
@ -34,12 +34,14 @@ using namespace dom;
|
|||
CreateElementTransaction::CreateElementTransaction(EditorBase& aEditorBase,
|
||||
nsAtom& aTag,
|
||||
nsINode& aParent,
|
||||
int32_t aOffsetInParent)
|
||||
int32_t aOffsetInParent,
|
||||
nsIContent* aChildAtOffset)
|
||||
: EditTransactionBase()
|
||||
, mEditorBase(&aEditorBase)
|
||||
, mTag(&aTag)
|
||||
, mParent(&aParent)
|
||||
, mOffsetInParent(aOffsetInParent)
|
||||
, mRefNode(aChildAtOffset)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -83,8 +85,10 @@ CreateElementTransaction::DoTransaction()
|
|||
mOffsetInParent = std::min(mOffsetInParent,
|
||||
static_cast<int32_t>(mParent->GetChildCount()));
|
||||
|
||||
// Note, it's ok for mRefNode to be null. That means append
|
||||
mRefNode = mParent->GetChildAt(mOffsetInParent);
|
||||
if (!mRefNode) {
|
||||
// Note, it's ok for mRefNode to be null. That means append
|
||||
mRefNode = mParent->GetChildAt(mOffsetInParent);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIContent> refNode = mRefNode;
|
||||
mParent->InsertBefore(*mNewNode, refNode, rv);
|
||||
|
|
|
@ -41,7 +41,8 @@ public:
|
|||
CreateElementTransaction(EditorBase& aEditorBase,
|
||||
nsAtom& aTag,
|
||||
nsINode& aParent,
|
||||
int32_t aOffsetInParent);
|
||||
int32_t aOffsetInParent,
|
||||
nsIContent* aChildAtOffset);
|
||||
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(CreateElementTransaction,
|
||||
|
@ -71,7 +72,8 @@ protected:
|
|||
// The new node to insert.
|
||||
nsCOMPtr<dom::Element> mNewNode;
|
||||
|
||||
// The node we will insert mNewNode before. We compute this ourselves.
|
||||
// The node we will insert mNewNode before. We compute this ourselves if it
|
||||
// is not set by the constructor.
|
||||
nsCOMPtr<nsIContent> mRefNode;
|
||||
};
|
||||
|
||||
|
|
|
@ -1418,7 +1418,8 @@ EditorBase::SetSpellcheckUserOverride(bool enable)
|
|||
already_AddRefed<Element>
|
||||
EditorBase::CreateNode(nsAtom* aTag,
|
||||
nsINode* aParent,
|
||||
int32_t aPosition)
|
||||
int32_t aPosition,
|
||||
nsIContent* aChildAtPosition)
|
||||
{
|
||||
MOZ_ASSERT(aTag && aParent);
|
||||
|
||||
|
@ -1435,7 +1436,8 @@ EditorBase::CreateNode(nsAtom* aTag,
|
|||
nsCOMPtr<Element> ret;
|
||||
|
||||
RefPtr<CreateElementTransaction> transaction =
|
||||
CreateTxnForCreateElement(*aTag, *aParent, aPosition);
|
||||
CreateTxnForCreateElement(*aTag, *aParent, aPosition,
|
||||
aChildAtPosition);
|
||||
nsresult rv = DoTransaction(transaction);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
ret = transaction->GetNewNode();
|
||||
|
@ -4371,10 +4373,12 @@ EditorBase::CreateTxnForRemoveAttribute(Element& aElement,
|
|||
already_AddRefed<CreateElementTransaction>
|
||||
EditorBase::CreateTxnForCreateElement(nsAtom& aTag,
|
||||
nsINode& aParent,
|
||||
int32_t aPosition)
|
||||
int32_t aPosition,
|
||||
nsIContent* aChildAtPosition)
|
||||
{
|
||||
RefPtr<CreateElementTransaction> transaction =
|
||||
new CreateElementTransaction(*this, aTag, aParent, aPosition);
|
||||
new CreateElementTransaction(*this, aTag, aParent, aPosition,
|
||||
aChildAtPosition);
|
||||
|
||||
return transaction.forget();
|
||||
}
|
||||
|
|
|
@ -398,10 +398,12 @@ protected:
|
|||
already_AddRefed<CreateElementTransaction>
|
||||
CreateTxnForCreateElement(nsAtom& aTag,
|
||||
nsINode& aParent,
|
||||
int32_t aPosition);
|
||||
int32_t aPosition,
|
||||
nsIContent* aChildAtPosition);
|
||||
|
||||
already_AddRefed<Element> CreateNode(nsAtom* aTag, nsINode* aParent,
|
||||
int32_t aPosition);
|
||||
int32_t aPosition,
|
||||
nsIContent* aChildAtPosition = nullptr);
|
||||
|
||||
/**
|
||||
* Create a transaction for inserting aNode as a child of aParent.
|
||||
|
|
Загрузка…
Ссылка в новой задаче