From d5fd8b4694f4b41bfda39bb95dd5eb4bccf5c818 Mon Sep 17 00:00:00 2001 From: "pollmann%netscape.com" Date: Mon, 20 Mar 2000 23:43:07 +0000 Subject: [PATCH] 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 --- mozilla/layout/forms/nsListControlFrame.cpp | 52 +++++++++++-------- .../html/forms/src/nsListControlFrame.cpp | 52 +++++++++++-------- 2 files changed, 58 insertions(+), 46 deletions(-) diff --git a/mozilla/layout/forms/nsListControlFrame.cpp b/mozilla/layout/forms/nsListControlFrame.cpp index e17dd6493eb..b7ec60a7d92 100644 --- a/mozilla/layout/forms/nsListControlFrame.cpp +++ b/mozilla/layout/forms/nsListControlFrame.cpp @@ -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 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 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; } diff --git a/mozilla/layout/html/forms/src/nsListControlFrame.cpp b/mozilla/layout/html/forms/src/nsListControlFrame.cpp index e17dd6493eb..b7ec60a7d92 100644 --- a/mozilla/layout/html/forms/src/nsListControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsListControlFrame.cpp @@ -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 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 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; }