From 902ff895ab9f3844a4b5a8f09924d480241183d8 Mon Sep 17 00:00:00 2001 From: "karnaze%netscape.com" Date: Wed, 3 May 2000 14:57:00 +0000 Subject: [PATCH] bug 9271 - correctly insert cells, rows when insertion index equals number of elements. --- .../content/src/nsHTMLTableRowElement.cpp | 29 +++++++++---------- .../content/src/nsHTMLTableSectionElement.cpp | 28 +++++++----------- .../content/src/nsHTMLTableRowElement.cpp | 29 +++++++++---------- .../content/src/nsHTMLTableSectionElement.cpp | 28 +++++++----------- 4 files changed, 48 insertions(+), 66 deletions(-) diff --git a/content/html/content/src/nsHTMLTableRowElement.cpp b/content/html/content/src/nsHTMLTableRowElement.cpp index 223a7f132e20..2bbb74dc325d 100644 --- a/content/html/content/src/nsHTMLTableRowElement.cpp +++ b/content/html/content/src/nsHTMLTableRowElement.cpp @@ -523,35 +523,32 @@ nsHTMLTableRowElement::InsertCell(PRInt32 aIndex, nsIDOMHTMLElement** aValue) *aValue = nsnull; PRInt32 refIndex = (0 <= aIndex) ? aIndex : 0; - - nsIDOMHTMLCollection *cells; - GetCells(&cells); + + nsCOMPtr 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 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; } diff --git a/content/html/content/src/nsHTMLTableSectionElement.cpp b/content/html/content/src/nsHTMLTableSectionElement.cpp index 609e0852d320..ff22fb872241 100644 --- a/content/html/content/src/nsHTMLTableSectionElement.cpp +++ b/content/html/content/src/nsHTMLTableSectionElement.cpp @@ -168,37 +168,31 @@ nsHTMLTableSectionElement::InsertRow(PRInt32 aIndex, nsIDOMHTMLElement** aValue) { *aValue = nsnull; - PRInt32 refIndex = (0 <= aIndex) ? aIndex : 0; - - nsIDOMHTMLCollection *rows; - GetRows(&rows); + nsCOMPtr 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 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; } diff --git a/layout/html/content/src/nsHTMLTableRowElement.cpp b/layout/html/content/src/nsHTMLTableRowElement.cpp index 223a7f132e20..2bbb74dc325d 100644 --- a/layout/html/content/src/nsHTMLTableRowElement.cpp +++ b/layout/html/content/src/nsHTMLTableRowElement.cpp @@ -523,35 +523,32 @@ nsHTMLTableRowElement::InsertCell(PRInt32 aIndex, nsIDOMHTMLElement** aValue) *aValue = nsnull; PRInt32 refIndex = (0 <= aIndex) ? aIndex : 0; - - nsIDOMHTMLCollection *cells; - GetCells(&cells); + + nsCOMPtr 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 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; } diff --git a/layout/html/content/src/nsHTMLTableSectionElement.cpp b/layout/html/content/src/nsHTMLTableSectionElement.cpp index 609e0852d320..ff22fb872241 100644 --- a/layout/html/content/src/nsHTMLTableSectionElement.cpp +++ b/layout/html/content/src/nsHTMLTableSectionElement.cpp @@ -168,37 +168,31 @@ nsHTMLTableSectionElement::InsertRow(PRInt32 aIndex, nsIDOMHTMLElement** aValue) { *aValue = nsnull; - PRInt32 refIndex = (0 <= aIndex) ? aIndex : 0; - - nsIDOMHTMLCollection *rows; - GetRows(&rows); + nsCOMPtr 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 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; }