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
This commit is contained in:
rods%netscape.com 2000-03-18 15:29:48 +00:00
Родитель 3b43798982
Коммит 9f60e09b37
2 изменённых файлов: 136 добавлений и 60 удалений

Просмотреть файл

@ -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<nsIPresState> presState;
nsCOMPtr<nsISupportsArray> value;
nsresult res = GetPresState(getter_AddRefs(presState), getter_AddRefs(value));
if (NS_SUCCEEDED(res) && presState) {
nsCOMPtr<nsISupports> supp;
presState->GetStatePropertyAsSupports("selecteditems", getter_AddRefs(supp));
nsresult res = NS_ERROR_NULL_POINTER;
if (!supp)
return NS_ERROR_FAILURE;
nsCOMPtr<nsISupportsArray> value = do_QueryInterface(supp);
if (!value)
return NS_ERROR_FAILURE;
PRUint32 count = 0;
value->Count(&count);
nsCOMPtr<nsISupportsPRInt32> thisVal;
PRInt32 j=0;
for (PRUint32 i=0; i<count; i++) {
nsCOMPtr<nsISupports> 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<nsIDOMNSHTMLOptionCollection> 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<nsIDOMNode> node;
rv = options->Item(i, getter_AddRefs(node));
if (NS_SUCCEEDED(rv) && node) {
nsCOMPtr<nsIDOMHTMLOptionElement> 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<nsIDOMNSHTMLOptionCollection> 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<nsIDOMNode> node;
rv = options->Item(i, getter_AddRefs(node));
if (NS_SUCCEEDED(rv) && node) {
nsCOMPtr<nsIDOMHTMLOptionElement> 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;
}
}
}
}
}

Просмотреть файл

@ -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<nsIPresState> presState;
nsCOMPtr<nsISupportsArray> value;
nsresult res = GetPresState(getter_AddRefs(presState), getter_AddRefs(value));
if (NS_SUCCEEDED(res) && presState) {
nsCOMPtr<nsISupports> supp;
presState->GetStatePropertyAsSupports("selecteditems", getter_AddRefs(supp));
nsresult res = NS_ERROR_NULL_POINTER;
if (!supp)
return NS_ERROR_FAILURE;
nsCOMPtr<nsISupportsArray> value = do_QueryInterface(supp);
if (!value)
return NS_ERROR_FAILURE;
PRUint32 count = 0;
value->Count(&count);
nsCOMPtr<nsISupportsPRInt32> thisVal;
PRInt32 j=0;
for (PRUint32 i=0; i<count; i++) {
nsCOMPtr<nsISupports> 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<nsIDOMNSHTMLOptionCollection> 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<nsIDOMNode> node;
rv = options->Item(i, getter_AddRefs(node));
if (NS_SUCCEEDED(rv) && node) {
nsCOMPtr<nsIDOMHTMLOptionElement> 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<nsIDOMNSHTMLOptionCollection> 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<nsIDOMNode> node;
rv = options->Item(i, getter_AddRefs(node));
if (NS_SUCCEEDED(rv) && node) {
nsCOMPtr<nsIDOMHTMLOptionElement> 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;
}
}
}
}
}