mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 761308 - Part b: Cleanup CreateElementTxn::DoTransaction(); r=ehsan
This commit is contained in:
parent
02dd71b0e0
commit
c839dab25b
@ -78,14 +78,11 @@ NS_IMETHODIMP CreateElementTxn::DoTransaction(void)
|
||||
//new call to use instead to get proper HTML element, bug# 39919
|
||||
nsresult result = mEditor->CreateHTMLContent(mTag, getter_AddRefs(newContent));
|
||||
NS_ENSURE_SUCCESS(result, result);
|
||||
nsCOMPtr<nsIDOMElement>newElement = do_QueryInterface(newContent);
|
||||
NS_ENSURE_TRUE(newElement, NS_ERROR_NULL_POINTER);
|
||||
mNewNode = do_QueryInterface(newElement);
|
||||
NS_ENSURE_STATE(newContent);
|
||||
|
||||
mNewNode = newContent->AsDOMNode();
|
||||
// Try to insert formatting whitespace for the new node:
|
||||
mEditor->MarkNodeDirty(mNewNode);
|
||||
|
||||
NS_ASSERTION(((NS_SUCCEEDED(result)) && (mNewNode)), "could not create element.");
|
||||
NS_ENSURE_TRUE(mNewNode, NS_ERROR_NULL_POINTER);
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
if (gNoisy)
|
||||
@ -95,50 +92,43 @@ NS_IMETHODIMP CreateElementTxn::DoTransaction(void)
|
||||
#endif
|
||||
|
||||
// insert the new node
|
||||
if (CreateElementTxn::eAppend == PRInt32(mOffsetInParent)) {
|
||||
nsCOMPtr<nsIDOMNode> resultNode;
|
||||
return mParent->AppendChild(mNewNode, getter_AddRefs(resultNode));
|
||||
}
|
||||
|
||||
nsCOMPtr<nsINode> parent = do_QueryInterface(mParent);
|
||||
NS_ENSURE_STATE(parent);
|
||||
|
||||
mOffsetInParent = NS_MIN(mOffsetInParent, parent->GetChildCount());
|
||||
|
||||
// note, it's ok for mRefNode to be null. that means append
|
||||
nsIContent* refNode = parent->GetChildAt(mOffsetInParent);
|
||||
mRefNode = refNode ? refNode->AsDOMNode() : nsnull;
|
||||
|
||||
nsCOMPtr<nsIDOMNode> resultNode;
|
||||
if (CreateElementTxn::eAppend==(PRInt32)mOffsetInParent)
|
||||
{
|
||||
result = mParent->AppendChild(mNewNode, getter_AddRefs(resultNode));
|
||||
result = mParent->InsertBefore(mNewNode, mRefNode, getter_AddRefs(resultNode));
|
||||
NS_ENSURE_SUCCESS(result, result);
|
||||
|
||||
// only set selection to insertion point if editor gives permission
|
||||
bool bAdjustSelection;
|
||||
mEditor->ShouldTxnSetSelection(&bAdjustSelection);
|
||||
if (!bAdjustSelection) {
|
||||
// do nothing - dom range gravity will adjust selection
|
||||
return NS_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
nsCOMPtr<nsIDOMNodeList> childNodes;
|
||||
result = mParent->GetChildNodes(getter_AddRefs(childNodes));
|
||||
if ((NS_SUCCEEDED(result)) && (childNodes))
|
||||
{
|
||||
PRUint32 count;
|
||||
childNodes->GetLength(&count);
|
||||
if (mOffsetInParent>count)
|
||||
mOffsetInParent = count;
|
||||
result = childNodes->Item(mOffsetInParent, getter_AddRefs(mRefNode));
|
||||
NS_ENSURE_SUCCESS(result, result); // note, it's ok for mRefNode to be null. that means append
|
||||
|
||||
result = mParent->InsertBefore(mNewNode, mRefNode, getter_AddRefs(resultNode));
|
||||
NS_ENSURE_SUCCESS(result, result);
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
result = mEditor->GetSelection(getter_AddRefs(selection));
|
||||
NS_ENSURE_SUCCESS(result, result);
|
||||
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
|
||||
|
||||
// only set selection to insertion point if editor gives permission
|
||||
bool bAdjustSelection;
|
||||
mEditor->ShouldTxnSetSelection(&bAdjustSelection);
|
||||
if (bAdjustSelection)
|
||||
{
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
result = mEditor->GetSelection(getter_AddRefs(selection));
|
||||
NS_ENSURE_SUCCESS(result, result);
|
||||
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
|
||||
nsCOMPtr<nsIContent> parentContent = do_QueryInterface(mParent);
|
||||
NS_ENSURE_STATE(parentContent);
|
||||
|
||||
PRInt32 offset=0;
|
||||
result = nsEditor::GetChildOffset(mNewNode, mParent, offset);
|
||||
NS_ENSURE_SUCCESS(result, result);
|
||||
|
||||
result = selection->Collapse(mParent, offset+1);
|
||||
NS_ASSERTION((NS_SUCCEEDED(result)), "selection could not be collapsed after insert.");
|
||||
}
|
||||
else
|
||||
{
|
||||
// do nothing - dom range gravity will adjust selection
|
||||
}
|
||||
}
|
||||
}
|
||||
result = selection->CollapseNative(parentContent,
|
||||
parentContent->IndexOf(newContent) + 1);
|
||||
NS_ASSERTION((NS_SUCCEEDED(result)), "selection could not be collapsed after insert.");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user