bug 9271 - correctly insert cells, rows when insertion index equals number of elements.

This commit is contained in:
karnaze%netscape.com 2000-05-03 14:57:00 +00:00
parent d3dd6e17e4
commit 902ff895ab
4 changed files with 48 additions and 66 deletions

View File

@ -523,35 +523,32 @@ nsHTMLTableRowElement::InsertCell(PRInt32 aIndex, nsIDOMHTMLElement** aValue)
*aValue = nsnull;
PRInt32 refIndex = (0 <= aIndex) ? aIndex : 0;
nsIDOMHTMLCollection *cells;
GetCells(&cells);
nsCOMPtr<nsIDOMHTMLCollection> cells;
GetCells(getter_AddRefs(cells));
PRUint32 cellCount;
cells->GetLength(&cellCount);
if (cellCount <= PRUint32(aIndex)) {
refIndex = cellCount - 1; // refIndex will be -1 if there are no cells
}
// create the cell
nsIHTMLContent *cellContent = nsnull;
PRBool doInsert = (aIndex < PRInt32(cellCount));
// create the cell
nsIHTMLContent* cellContent = nsnull;
nsresult rv = NS_NewHTMLTableCellElement(&cellContent, nsHTMLAtoms::td);
if (NS_SUCCEEDED(rv) && (nsnull != cellContent)) {
nsIDOMNode *cellNode = nsnull;
nsIDOMNode* cellNode = nsnull;
rv = cellContent->QueryInterface(kIDOMNodeIID, (void **)&cellNode);
if (NS_SUCCEEDED(rv) && (nsnull != cellNode)) {
if (refIndex >= 0) {
nsIDOMNode *refCell;
cells->Item(refIndex, &refCell);
if (doInsert) {
PRInt32 refIndex = PR_MAX(aIndex, 0);
nsCOMPtr<nsIDOMNode> refCell;
cells->Item(refIndex, getter_AddRefs(refCell));
rv = InsertBefore(cellNode, refCell, (nsIDOMNode **)aValue);
} else {
rv = AppendChild(cellNode, (nsIDOMNode **)aValue);
}
NS_RELEASE(cellNode);
}
NS_RELEASE(cellContent);
}
NS_RELEASE(cells);
}
return NS_OK;
}

View File

@ -168,37 +168,31 @@ nsHTMLTableSectionElement::InsertRow(PRInt32 aIndex, nsIDOMHTMLElement** aValue)
{
*aValue = nsnull;
PRInt32 refIndex = (0 <= aIndex) ? aIndex : 0;
nsIDOMHTMLCollection *rows;
GetRows(&rows);
nsCOMPtr<nsIDOMHTMLCollection> rows;
GetRows(getter_AddRefs(rows));
PRUint32 rowCount;
rows->GetLength(&rowCount);
if (rowCount <= PRUint32(aIndex)) {
refIndex = rowCount - 1; // refIndex will be -1 if there are no rows
}
PRBool doInsert = (aIndex < PRInt32(rowCount));
// create the row
nsIHTMLContent *rowContent = nsnull;
nsIHTMLContent* rowContent = nsnull;
nsresult rv = NS_NewHTMLTableRowElement(&rowContent, nsHTMLAtoms::tr);
if (NS_SUCCEEDED(rv) && (nsnull != rowContent)) {
nsIDOMNode *rowNode = nsnull;
nsIDOMNode* rowNode = nsnull;
rv = rowContent->QueryInterface(kIDOMNodeIID, (void **)&rowNode);
if (NS_SUCCEEDED(rv) && (nsnull != rowNode)) {
if (refIndex >= 0) {
nsIDOMNode *refRow;
rows->Item(refIndex, &refRow);
if (doInsert) {
PRInt32 refIndex = PR_MAX(aIndex, 0);
nsCOMPtr<nsIDOMNode> refRow;
rows->Item(refIndex, getter_AddRefs(refRow));
rv = InsertBefore(rowNode, refRow, (nsIDOMNode **)aValue);
NS_RELEASE(refRow);
} else {
rv = AppendChild(rowNode, (nsIDOMNode **)aValue);
}
NS_RELEASE(rowNode);
}
NS_RELEASE(rowContent);
}
NS_RELEASE(rows);
}
return NS_OK;
}

View File

@ -523,35 +523,32 @@ nsHTMLTableRowElement::InsertCell(PRInt32 aIndex, nsIDOMHTMLElement** aValue)
*aValue = nsnull;
PRInt32 refIndex = (0 <= aIndex) ? aIndex : 0;
nsIDOMHTMLCollection *cells;
GetCells(&cells);
nsCOMPtr<nsIDOMHTMLCollection> cells;
GetCells(getter_AddRefs(cells));
PRUint32 cellCount;
cells->GetLength(&cellCount);
if (cellCount <= PRUint32(aIndex)) {
refIndex = cellCount - 1; // refIndex will be -1 if there are no cells
}
// create the cell
nsIHTMLContent *cellContent = nsnull;
PRBool doInsert = (aIndex < PRInt32(cellCount));
// create the cell
nsIHTMLContent* cellContent = nsnull;
nsresult rv = NS_NewHTMLTableCellElement(&cellContent, nsHTMLAtoms::td);
if (NS_SUCCEEDED(rv) && (nsnull != cellContent)) {
nsIDOMNode *cellNode = nsnull;
nsIDOMNode* cellNode = nsnull;
rv = cellContent->QueryInterface(kIDOMNodeIID, (void **)&cellNode);
if (NS_SUCCEEDED(rv) && (nsnull != cellNode)) {
if (refIndex >= 0) {
nsIDOMNode *refCell;
cells->Item(refIndex, &refCell);
if (doInsert) {
PRInt32 refIndex = PR_MAX(aIndex, 0);
nsCOMPtr<nsIDOMNode> refCell;
cells->Item(refIndex, getter_AddRefs(refCell));
rv = InsertBefore(cellNode, refCell, (nsIDOMNode **)aValue);
} else {
rv = AppendChild(cellNode, (nsIDOMNode **)aValue);
}
NS_RELEASE(cellNode);
}
NS_RELEASE(cellContent);
}
NS_RELEASE(cells);
}
return NS_OK;
}

View File

@ -168,37 +168,31 @@ nsHTMLTableSectionElement::InsertRow(PRInt32 aIndex, nsIDOMHTMLElement** aValue)
{
*aValue = nsnull;
PRInt32 refIndex = (0 <= aIndex) ? aIndex : 0;
nsIDOMHTMLCollection *rows;
GetRows(&rows);
nsCOMPtr<nsIDOMHTMLCollection> rows;
GetRows(getter_AddRefs(rows));
PRUint32 rowCount;
rows->GetLength(&rowCount);
if (rowCount <= PRUint32(aIndex)) {
refIndex = rowCount - 1; // refIndex will be -1 if there are no rows
}
PRBool doInsert = (aIndex < PRInt32(rowCount));
// create the row
nsIHTMLContent *rowContent = nsnull;
nsIHTMLContent* rowContent = nsnull;
nsresult rv = NS_NewHTMLTableRowElement(&rowContent, nsHTMLAtoms::tr);
if (NS_SUCCEEDED(rv) && (nsnull != rowContent)) {
nsIDOMNode *rowNode = nsnull;
nsIDOMNode* rowNode = nsnull;
rv = rowContent->QueryInterface(kIDOMNodeIID, (void **)&rowNode);
if (NS_SUCCEEDED(rv) && (nsnull != rowNode)) {
if (refIndex >= 0) {
nsIDOMNode *refRow;
rows->Item(refIndex, &refRow);
if (doInsert) {
PRInt32 refIndex = PR_MAX(aIndex, 0);
nsCOMPtr<nsIDOMNode> refRow;
rows->Item(refIndex, getter_AddRefs(refRow));
rv = InsertBefore(rowNode, refRow, (nsIDOMNode **)aValue);
NS_RELEASE(refRow);
} else {
rv = AppendChild(rowNode, (nsIDOMNode **)aValue);
}
NS_RELEASE(rowNode);
}
NS_RELEASE(rowContent);
}
NS_RELEASE(rows);
}
return NS_OK;
}