From 9f60e09b3758cae8a289b64215dc147e131a3b74 Mon Sep 17 00:00:00 2001 From: "rods%netscape.com" Date: Sat, 18 Mar 2000 15:29:48 +0000 Subject: [PATCH] Fixed GetSelectedIndex so it gets it out of the pressate when there is no frame. for PDT+ bug 32119, I am checking in the fix in on the Tip, ducarroz will check it in on the branch r=kmcclusk --- .../html/content/src/nsHTMLSelectElement.cpp | 98 +++++++++++++------ .../html/content/src/nsHTMLSelectElement.cpp | 98 +++++++++++++------ 2 files changed, 136 insertions(+), 60 deletions(-) diff --git a/content/html/content/src/nsHTMLSelectElement.cpp b/content/html/content/src/nsHTMLSelectElement.cpp index a9eff9c3cb77..d2454dc4f1c0 100644 --- a/content/html/content/src/nsHTMLSelectElement.cpp +++ b/content/html/content/src/nsHTMLSelectElement.cpp @@ -511,37 +511,75 @@ nsHTMLSelectElement::GetSelectedIndex(PRInt32* aValue) } } else { // The frame hasn't been created yet. Use the options array *aValue = -1; - // If we are a combo box, our default selectedIndex is 0, not -1; - // XXX The logic here is duplicated in - // nsCSSFrameConstructor::ConstructSelectFrame and - // nsSelectControlFrame::GetDesiredSize - PRBool isMultiple; - rv = GetMultiple(&isMultiple); // Must not be multiple - if (NS_SUCCEEDED(rv) && !isMultiple) { - PRInt32 size = 1; - rv = GetSize(&size); // Size 1 or not set - if (NS_SUCCEEDED(rv) && ((1 >= size) || (NS_CONTENT_ATTR_NOT_THERE == size))) { - *aValue = 0; + // Call the helper method to get the PresState and + // the SupportsArray that contains the value + // + nsCOMPtr presState; + nsCOMPtr value; + nsresult res = GetPresState(getter_AddRefs(presState), getter_AddRefs(value)); + if (NS_SUCCEEDED(res) && presState) { + nsCOMPtr supp; + presState->GetStatePropertyAsSupports("selecteditems", getter_AddRefs(supp)); + + nsresult res = NS_ERROR_NULL_POINTER; + if (!supp) + return NS_ERROR_FAILURE; + + nsCOMPtr value = do_QueryInterface(supp); + if (!value) + return NS_ERROR_FAILURE; + + PRUint32 count = 0; + value->Count(&count); + + nsCOMPtr thisVal; + PRInt32 j=0; + for (PRUint32 i=0; i suppval = getter_AddRefs(value->ElementAt(i)); + thisVal = do_QueryInterface(suppval); + if (thisVal) { + res = thisVal->GetData(aValue); + if (NS_SUCCEEDED(res)) { + return NS_OK; + } + } else { + res = NS_ERROR_UNEXPECTED; + } + if (!NS_SUCCEEDED(res)) break; } - } - nsCOMPtr options; - rv = GetOptions(getter_AddRefs(options)); - if (NS_SUCCEEDED(rv) && options) { - PRUint32 numOptions; - rv = options->GetLength(&numOptions); - if (NS_SUCCEEDED(rv)) { - for (PRUint32 i = 0; i < numOptions; i++) { - nsCOMPtr node; - rv = options->Item(i, getter_AddRefs(node)); - if (NS_SUCCEEDED(rv) && node) { - nsCOMPtr option = do_QueryInterface(node, &rv); - if (NS_SUCCEEDED(rv) && option) { - PRBool selected; - rv = option->GetDefaultSelected(&selected); // DefaultSelected == HTML Selected - if (NS_SUCCEEDED(rv) && selected) { - *aValue = i; - break; - } + } else { + // If we are a combo box, our default selectedIndex is 0, not -1; + // XXX The logic here is duplicated in + // nsCSSFrameConstructor::ConstructSelectFrame and + // nsSelectControlFrame::GetDesiredSize + PRBool isMultiple; + rv = GetMultiple(&isMultiple); // Must not be multiple + if (NS_SUCCEEDED(rv) && !isMultiple) { + PRInt32 size = 1; + rv = GetSize(&size); // Size 1 or not set + if (NS_SUCCEEDED(rv) && ((1 >= size) || (NS_CONTENT_ATTR_NOT_THERE == size))) { + *aValue = 0; + } + } + nsCOMPtr options; + rv = GetOptions(getter_AddRefs(options)); + if (NS_SUCCEEDED(rv) && options) { + PRUint32 numOptions; + rv = options->GetLength(&numOptions); + if (NS_SUCCEEDED(rv)) { + for (PRUint32 i = 0; i < numOptions; i++) { + nsCOMPtr node; + rv = options->Item(i, getter_AddRefs(node)); + if (NS_SUCCEEDED(rv) && node) { + nsCOMPtr option = do_QueryInterface(node, &rv); + if (NS_SUCCEEDED(rv) && option) { + PRBool selected; + rv = option->GetDefaultSelected(&selected); // DefaultSelected == HTML Selected + if (NS_SUCCEEDED(rv) && selected) { + *aValue = i; + break; + } + } } } } diff --git a/layout/html/content/src/nsHTMLSelectElement.cpp b/layout/html/content/src/nsHTMLSelectElement.cpp index a9eff9c3cb77..d2454dc4f1c0 100644 --- a/layout/html/content/src/nsHTMLSelectElement.cpp +++ b/layout/html/content/src/nsHTMLSelectElement.cpp @@ -511,37 +511,75 @@ nsHTMLSelectElement::GetSelectedIndex(PRInt32* aValue) } } else { // The frame hasn't been created yet. Use the options array *aValue = -1; - // If we are a combo box, our default selectedIndex is 0, not -1; - // XXX The logic here is duplicated in - // nsCSSFrameConstructor::ConstructSelectFrame and - // nsSelectControlFrame::GetDesiredSize - PRBool isMultiple; - rv = GetMultiple(&isMultiple); // Must not be multiple - if (NS_SUCCEEDED(rv) && !isMultiple) { - PRInt32 size = 1; - rv = GetSize(&size); // Size 1 or not set - if (NS_SUCCEEDED(rv) && ((1 >= size) || (NS_CONTENT_ATTR_NOT_THERE == size))) { - *aValue = 0; + // Call the helper method to get the PresState and + // the SupportsArray that contains the value + // + nsCOMPtr presState; + nsCOMPtr value; + nsresult res = GetPresState(getter_AddRefs(presState), getter_AddRefs(value)); + if (NS_SUCCEEDED(res) && presState) { + nsCOMPtr supp; + presState->GetStatePropertyAsSupports("selecteditems", getter_AddRefs(supp)); + + nsresult res = NS_ERROR_NULL_POINTER; + if (!supp) + return NS_ERROR_FAILURE; + + nsCOMPtr value = do_QueryInterface(supp); + if (!value) + return NS_ERROR_FAILURE; + + PRUint32 count = 0; + value->Count(&count); + + nsCOMPtr thisVal; + PRInt32 j=0; + for (PRUint32 i=0; i suppval = getter_AddRefs(value->ElementAt(i)); + thisVal = do_QueryInterface(suppval); + if (thisVal) { + res = thisVal->GetData(aValue); + if (NS_SUCCEEDED(res)) { + return NS_OK; + } + } else { + res = NS_ERROR_UNEXPECTED; + } + if (!NS_SUCCEEDED(res)) break; } - } - nsCOMPtr options; - rv = GetOptions(getter_AddRefs(options)); - if (NS_SUCCEEDED(rv) && options) { - PRUint32 numOptions; - rv = options->GetLength(&numOptions); - if (NS_SUCCEEDED(rv)) { - for (PRUint32 i = 0; i < numOptions; i++) { - nsCOMPtr node; - rv = options->Item(i, getter_AddRefs(node)); - if (NS_SUCCEEDED(rv) && node) { - nsCOMPtr option = do_QueryInterface(node, &rv); - if (NS_SUCCEEDED(rv) && option) { - PRBool selected; - rv = option->GetDefaultSelected(&selected); // DefaultSelected == HTML Selected - if (NS_SUCCEEDED(rv) && selected) { - *aValue = i; - break; - } + } else { + // If we are a combo box, our default selectedIndex is 0, not -1; + // XXX The logic here is duplicated in + // nsCSSFrameConstructor::ConstructSelectFrame and + // nsSelectControlFrame::GetDesiredSize + PRBool isMultiple; + rv = GetMultiple(&isMultiple); // Must not be multiple + if (NS_SUCCEEDED(rv) && !isMultiple) { + PRInt32 size = 1; + rv = GetSize(&size); // Size 1 or not set + if (NS_SUCCEEDED(rv) && ((1 >= size) || (NS_CONTENT_ATTR_NOT_THERE == size))) { + *aValue = 0; + } + } + nsCOMPtr options; + rv = GetOptions(getter_AddRefs(options)); + if (NS_SUCCEEDED(rv) && options) { + PRUint32 numOptions; + rv = options->GetLength(&numOptions); + if (NS_SUCCEEDED(rv)) { + for (PRUint32 i = 0; i < numOptions; i++) { + nsCOMPtr node; + rv = options->Item(i, getter_AddRefs(node)); + if (NS_SUCCEEDED(rv) && node) { + nsCOMPtr option = do_QueryInterface(node, &rv); + if (NS_SUCCEEDED(rv) && option) { + PRBool selected; + rv = option->GetDefaultSelected(&selected); // DefaultSelected == HTML Selected + if (NS_SUCCEEDED(rv) && selected) { + *aValue = i; + break; + } + } } } }