mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 10:44:56 +00:00
Bug 1318479 part 2. Remove uses of nsIDOMNode::AppendChild in editor. r=ehsan
This commit is contained in:
parent
cadde4fe44
commit
6cee715d54
@ -2098,6 +2098,7 @@ HTMLEditor::CreateDOMFragmentFromPaste(const nsAString& aInputString,
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIContent> contextLeafAsContent = do_QueryInterface(contextLeaf);
|
||||
MOZ_ASSERT_IF(contextLeaf, contextLeafAsContent);
|
||||
|
||||
// create fragment for pasted html
|
||||
nsIAtom* contextAtom;
|
||||
@ -2122,8 +2123,8 @@ HTMLEditor::CreateDOMFragmentFromPaste(const nsAString& aInputString,
|
||||
|
||||
if (contextAsNode) {
|
||||
// unite the two trees
|
||||
nsCOMPtr<nsIDOMNode> junk;
|
||||
contextLeaf->AppendChild(fragment, getter_AddRefs(junk));
|
||||
IgnoredErrorResult ignored;
|
||||
contextLeafAsContent->AppendChild(*fragment, ignored);
|
||||
fragment = contextAsNode;
|
||||
}
|
||||
|
||||
|
@ -643,26 +643,23 @@ HTMLEditor::InsertTableRow(int32_t aNumber,
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsINode> cellNodeForRowParent = do_QueryInterface(cellForRowParent);
|
||||
|
||||
if (cellsInRow > 0) {
|
||||
// The row parent and offset where we will insert new row
|
||||
nsCOMPtr<nsIDOMNode> parentOfRow;
|
||||
int32_t newRowOffset;
|
||||
|
||||
NS_NAMED_LITERAL_STRING(trStr, "tr");
|
||||
if (!cellForRowParent) {
|
||||
if (!cellNodeForRowParent) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMElement> parentRow;
|
||||
rv = GetElementOrParentByTagName(trStr, cellForRowParent,
|
||||
getter_AddRefs(parentRow));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<Element> parentRow =
|
||||
GetElementOrParentByTagName(trStr, cellNodeForRowParent);
|
||||
NS_ENSURE_TRUE(parentRow, NS_ERROR_NULL_POINTER);
|
||||
|
||||
parentRow->GetParentNode(getter_AddRefs(parentOfRow));
|
||||
// The row parent and offset where we will insert new row
|
||||
nsCOMPtr<nsINode> parentOfRow = parentRow->GetParentNode();
|
||||
NS_ENSURE_TRUE(parentOfRow, NS_ERROR_NULL_POINTER);
|
||||
|
||||
newRowOffset = GetChildOffset(parentRow, parentOfRow);
|
||||
int32_t newRowOffset = parentOfRow->IndexOf(parentRow);
|
||||
|
||||
// Adjust for when adding past the end
|
||||
if (aAfter && startRowIndex >= rowCount) {
|
||||
@ -671,28 +668,27 @@ HTMLEditor::InsertTableRow(int32_t aNumber,
|
||||
|
||||
for (int32_t row = 0; row < aNumber; row++) {
|
||||
// Create a new row
|
||||
nsCOMPtr<nsIDOMElement> newRow;
|
||||
rv = CreateElementWithDefaults(trStr, getter_AddRefs(newRow));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
NS_ENSURE_TRUE(newRow, NS_ERROR_FAILURE);
|
||||
nsCOMPtr<Element> newRow = CreateElementWithDefaults(trStr);
|
||||
NS_ENSURE_TRUE(newRow, NS_ERROR_FAILURE);
|
||||
|
||||
for (int32_t i = 0; i < cellsInRow; i++) {
|
||||
nsCOMPtr<nsIDOMElement> newCell;
|
||||
rv = CreateElementWithDefaults(NS_LITERAL_STRING("td"),
|
||||
getter_AddRefs(newCell));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ENSURE_TRUE(newCell, NS_ERROR_FAILURE);
|
||||
for (int32_t i = 0; i < cellsInRow; i++) {
|
||||
nsCOMPtr<Element> newCell =
|
||||
CreateElementWithDefaults(NS_LITERAL_STRING("td"));
|
||||
NS_ENSURE_TRUE(newCell, NS_ERROR_FAILURE);
|
||||
|
||||
// Don't use transaction system yet! (not until entire row is inserted)
|
||||
nsCOMPtr<nsIDOMNode>resultNode;
|
||||
rv = newRow->AppendChild(newCell, getter_AddRefs(resultNode));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
// Don't use transaction system yet! (not until entire row is
|
||||
// inserted)
|
||||
ErrorResult result;
|
||||
newRow->AppendChild(*newCell, result);
|
||||
if (NS_WARN_IF(result.Failed())) {
|
||||
return result.StealNSResult();
|
||||
}
|
||||
// Use transaction system to insert the entire row+cells
|
||||
// (Note that rows are inserted at same childoffset each time)
|
||||
rv = InsertNode(newRow, parentOfRow, newRowOffset);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
// Use transaction system to insert the entire row+cells
|
||||
// (Note that rows are inserted at same childoffset each time)
|
||||
rv = InsertNode(*newRow, *parentOfRow, newRowOffset);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
}
|
||||
// XXX This might be the result of the last call of
|
||||
|
@ -19,6 +19,8 @@
|
||||
#include "nsIEditor.h" // for nsIEditor
|
||||
#include "nsIHTMLEditor.h" // for nsIHTMLEditor
|
||||
#include "nsLiteralString.h" // for NS_LITERAL_STRING
|
||||
#include "nsTextNode.h" // for nsTextNode
|
||||
#include "nsQueryObject.h" // for do_QueryObject
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
@ -164,26 +166,25 @@ SetDocumentTitleTransaction::SetDomTitle(const nsAString& aTitle)
|
||||
|
||||
// Append a text node under the TITLE only if the title text isn't empty.
|
||||
if (titleNode && !aTitle.IsEmpty()) {
|
||||
nsCOMPtr<nsIDOMText> textNode;
|
||||
rv = domDoc->CreateTextNode(aTitle, getter_AddRefs(textNode));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMNode> newNode = do_QueryInterface(textNode);
|
||||
if (NS_WARN_IF(!newNode)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
RefPtr<nsTextNode> textNode = document->CreateTextNode(aTitle);
|
||||
|
||||
if (newTitleNode) {
|
||||
// Not undoable: We will insert newTitleNode below
|
||||
nsCOMPtr<nsIDOMNode> resultNode;
|
||||
rv = titleNode->AppendChild(newNode, getter_AddRefs(resultNode));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
nsCOMPtr<nsINode> title = do_QueryInterface(titleNode);
|
||||
MOZ_ASSERT(title);
|
||||
|
||||
ErrorResult result;
|
||||
title->AppendChild(*textNode, result);
|
||||
if (NS_WARN_IF(result.Failed())) {
|
||||
return result.StealNSResult();
|
||||
}
|
||||
} else {
|
||||
// This is an undoable transaction
|
||||
nsCOMPtr<nsIDOMNode> newNode = do_QueryObject(textNode);
|
||||
if (NS_WARN_IF(!newNode)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
rv = editor->InsertNode(newNode, titleNode, 0);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
|
Loading…
Reference in New Issue
Block a user