Bug 28143: Set selectedIndex to -1 should deselect all options (1 of 2 - when frame exists) r=waqar

git-svn-id: svn://10.0.0.236/trunk@63494 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
pollmann%netscape.com 2000-03-20 23:43:07 +00:00
parent ef33586f26
commit d5fd8b4694
2 changed files with 58 additions and 46 deletions

View File

@ -2332,38 +2332,44 @@ nsListControlFrame::SetProperty(nsIPresContext* aPresContext, nsIAtom* aName, co
} else {
// Start by getting the num of options
// to make sure the new index is within the bounds
// if selectedIndex is -1, deselect all (bug 28143)
PRInt32 numOptions = 0;
GetNumberOfOptions(&numOptions);
if (selectedIndex < 0 || selectedIndex >= numOptions) {
if (selectedIndex < -1 || selectedIndex >= numOptions) {
return NS_ERROR_FAILURE;
}
// Get the DOM interface for the select
// we will use this to see if it is a "multiple" select
nsCOMPtr<nsIDOMHTMLSelectElement> selectElement = getter_AddRefs(GetSelect(mContent));
if (selectElement) {
// check to see if it is a mulitple select
PRBool multiple = PR_FALSE;
if (NS_FAILED(GetMultiple(&multiple, selectElement))) {
multiple = PR_FALSE;
}
// if it is a multiple, select the new item
if (multiple) {
SetOptionSelected(selectedIndex, PR_TRUE);
} else {
// if it is a single select,
// check to see if it is the currect selection
// if it is, then do nothing
if (mSelectedIndex != selectedIndex) {
ToggleSelected(selectedIndex); // sets mSelectedIndex
if (nsnull != mComboboxFrame && mIsAllFramesHere) {
mComboboxFrame->UpdateSelection(PR_FALSE, PR_TRUE, selectedIndex); // don't dispatch event
}
if (selectedIndex == -1) {
Deselect();
}
else {
// Get the DOM interface for the select
// we will use this to see if it is a "multiple" select
nsCOMPtr<nsIDOMHTMLSelectElement> selectElement = getter_AddRefs(GetSelect(mContent));
if (selectElement) {
// check to see if it is a mulitple select
PRBool multiple = PR_FALSE;
if (NS_FAILED(GetMultiple(&multiple, selectElement))) {
multiple = PR_FALSE;
}
// if it is a multiple, select the new item
if (multiple) {
SetOptionSelected(selectedIndex, PR_TRUE);
} else {
// if it is a single select,
// check to see if it is the currect selection
// if it is, then do nothing
if (mSelectedIndex != selectedIndex) {
ToggleSelected(selectedIndex); // sets mSelectedIndex
if (nsnull != mComboboxFrame && mIsAllFramesHere) {
mComboboxFrame->UpdateSelection(PR_FALSE, PR_TRUE, selectedIndex); // don't dispatch event
}
}
}
}
}
}
}
return NS_OK;
}

View File

@ -2332,38 +2332,44 @@ nsListControlFrame::SetProperty(nsIPresContext* aPresContext, nsIAtom* aName, co
} else {
// Start by getting the num of options
// to make sure the new index is within the bounds
// if selectedIndex is -1, deselect all (bug 28143)
PRInt32 numOptions = 0;
GetNumberOfOptions(&numOptions);
if (selectedIndex < 0 || selectedIndex >= numOptions) {
if (selectedIndex < -1 || selectedIndex >= numOptions) {
return NS_ERROR_FAILURE;
}
// Get the DOM interface for the select
// we will use this to see if it is a "multiple" select
nsCOMPtr<nsIDOMHTMLSelectElement> selectElement = getter_AddRefs(GetSelect(mContent));
if (selectElement) {
// check to see if it is a mulitple select
PRBool multiple = PR_FALSE;
if (NS_FAILED(GetMultiple(&multiple, selectElement))) {
multiple = PR_FALSE;
}
// if it is a multiple, select the new item
if (multiple) {
SetOptionSelected(selectedIndex, PR_TRUE);
} else {
// if it is a single select,
// check to see if it is the currect selection
// if it is, then do nothing
if (mSelectedIndex != selectedIndex) {
ToggleSelected(selectedIndex); // sets mSelectedIndex
if (nsnull != mComboboxFrame && mIsAllFramesHere) {
mComboboxFrame->UpdateSelection(PR_FALSE, PR_TRUE, selectedIndex); // don't dispatch event
}
if (selectedIndex == -1) {
Deselect();
}
else {
// Get the DOM interface for the select
// we will use this to see if it is a "multiple" select
nsCOMPtr<nsIDOMHTMLSelectElement> selectElement = getter_AddRefs(GetSelect(mContent));
if (selectElement) {
// check to see if it is a mulitple select
PRBool multiple = PR_FALSE;
if (NS_FAILED(GetMultiple(&multiple, selectElement))) {
multiple = PR_FALSE;
}
// if it is a multiple, select the new item
if (multiple) {
SetOptionSelected(selectedIndex, PR_TRUE);
} else {
// if it is a single select,
// check to see if it is the currect selection
// if it is, then do nothing
if (mSelectedIndex != selectedIndex) {
ToggleSelected(selectedIndex); // sets mSelectedIndex
if (nsnull != mComboboxFrame && mIsAllFramesHere) {
mComboboxFrame->UpdateSelection(PR_FALSE, PR_TRUE, selectedIndex); // don't dispatch event
}
}
}
}
}
}
}
return NS_OK;
}