From 93f06e008a473273da726b91ad34d9df324a391e Mon Sep 17 00:00:00 2001 From: "enndeakin%sympatico.ca" Date: Fri, 16 Feb 2007 14:23:35 +0000 Subject: [PATCH] Bug 308292, listbox getIndexOfItem/getItemAtIndex shouldn't throw exceptions, r+sr=neil --- layout/xul/base/src/nsListBoxBodyFrame.cpp | 41 +++++++++++----------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/layout/xul/base/src/nsListBoxBodyFrame.cpp b/layout/xul/base/src/nsListBoxBodyFrame.cpp index d26ad6f954f6..6a26cafe88bd 100644 --- a/layout/xul/base/src/nsListBoxBodyFrame.cpp +++ b/layout/xul/base/src/nsListBoxBodyFrame.cpp @@ -622,32 +622,31 @@ nsListBoxBodyFrame::ScrollByLines(PRInt32 aNumLines) NS_IMETHODIMP nsListBoxBodyFrame::GetIndexOfItem(nsIDOMElement* aItem, PRInt32* _retval) { - if (!aItem) - return NS_ERROR_NULL_POINTER; - - *_retval = 0; - nsCOMPtr itemContent(do_QueryInterface(aItem)); + if (aItem) { + *_retval = 0; + nsCOMPtr itemContent(do_QueryInterface(aItem)); - nsIContent* listbox = mContent->GetBindingParent(); - NS_ENSURE_STATE(listbox); + nsIContent* listbox = mContent->GetBindingParent(); + NS_ENSURE_STATE(listbox); - PRUint32 childCount = listbox->GetChildCount(); + PRUint32 childCount = listbox->GetChildCount(); + for (PRUint32 childIndex = 0; childIndex < childCount; childIndex++) { + nsIContent *child = listbox->GetChildAt(childIndex); - for (PRUint32 childIndex = 0; childIndex < childCount; childIndex++) { - nsIContent *child = listbox->GetChildAt(childIndex); + // we hit a list row, count it + if (child->Tag() == nsGkAtoms::listitem) { + // is this it? + if (child == itemContent) + return NS_OK; - // we hit a treerow, count it - if (child->Tag() == nsGkAtoms::listitem) { - // is this it? - if (child == itemContent) - return NS_OK; - - ++(*_retval); + ++(*_retval); + } } } // not found - return NS_ERROR_FAILURE; + *_retval = -1; + return NS_OK; } NS_IMETHODIMP @@ -655,7 +654,7 @@ nsListBoxBodyFrame::GetItemAtIndex(PRInt32 aIndex, nsIDOMElement** aItem) { *aItem = nsnull; if (aIndex < 0) - return NS_ERROR_ILLEGAL_VALUE; + return NS_OK; nsIContent* listbox = mContent->GetBindingParent(); NS_ENSURE_STATE(listbox); @@ -666,7 +665,7 @@ nsListBoxBodyFrame::GetItemAtIndex(PRInt32 aIndex, nsIDOMElement** aItem) for (PRUint32 childIndex = 0; childIndex < childCount; childIndex++) { nsIContent *child = listbox->GetChildAt(childIndex); - // we hit a treerow, count it + // we hit a list row, check if it is the one we are looking for if (child->Tag() == nsGkAtoms::listitem) { // is this it? if (itemCount == aIndex) { @@ -677,7 +676,7 @@ nsListBoxBodyFrame::GetItemAtIndex(PRInt32 aIndex, nsIDOMElement** aItem) } // not found - return NS_ERROR_FAILURE; + return NS_OK; } /////////// nsListBoxBodyFrame ///////////////