From 7becb2bb130e11155b2e5c4d916665804482f2ee Mon Sep 17 00:00:00 2001 From: "jkeiser%netscape.com" Date: Wed, 20 Feb 2002 05:59:46 +0000 Subject: [PATCH] Tabbing out of dropdown does not reset selected item (bug 100188), r=rods@netscape.com, sr=attinasi@netscape.com git-svn-id: svn://10.0.0.236/trunk@115061 18797224-902f-48f8-a5cc-f745e15eee43 --- .../layout/forms/nsComboboxControlFrame.cpp | 28 +++++++++---------- mozilla/layout/forms/nsIListControlFrame.h | 7 +++++ mozilla/layout/forms/nsListControlFrame.cpp | 4 ++- mozilla/layout/forms/nsListControlFrame.h | 3 +- .../html/forms/public/nsIListControlFrame.h | 7 +++++ .../html/forms/src/nsComboboxControlFrame.cpp | 28 +++++++++---------- .../html/forms/src/nsListControlFrame.cpp | 4 ++- .../html/forms/src/nsListControlFrame.h | 3 +- 8 files changed, 50 insertions(+), 34 deletions(-) diff --git a/mozilla/layout/forms/nsComboboxControlFrame.cpp b/mozilla/layout/forms/nsComboboxControlFrame.cpp index 0b9c9b03ad1..667d5dd3de1 100644 --- a/mozilla/layout/forms/nsComboboxControlFrame.cpp +++ b/mozilla/layout/forms/nsComboboxControlFrame.cpp @@ -510,20 +510,20 @@ nsComboboxControlFrame::SetFocus(PRBool aOn, PRBool aRepaint) } else { mFocused = nsnull; if (mDroppedDown) { - ToggleList(mPresContext); - } - - // Fire onChange if selected index has changed due to keyboard - // (see nsListControlFrame::UpdateSelection) - if (mNeedToFireOnChange) { - PRInt32 selectedIndex; - mListControlFrame->GetSelectedIndex(&selectedIndex); - if (selectedIndex != mRecentSelectedIndex) { - // mNeedToFireOnChange will be set to false from within FireOnChange - mListControlFrame->FireOnChange(); - } else { - // Need to set it to false anyway ... just in case - SetNeedToFireOnChange(PR_FALSE); + mListControlFrame->ComboboxFinish(mDisplayedIndex); + } else { + // Fire onChange if selected index has changed due to keyboard + // (see nsListControlFrame::UpdateSelection) + if (mNeedToFireOnChange) { + PRInt32 selectedIndex; + mListControlFrame->GetSelectedIndex(&selectedIndex); + if (selectedIndex != mRecentSelectedIndex) { + // mNeedToFireOnChange will be set to false from within FireOnChange + mListControlFrame->FireOnChange(); + } else { + // Need to set it to false anyway ... just in case + SetNeedToFireOnChange(PR_FALSE); + } } } } diff --git a/mozilla/layout/forms/nsIListControlFrame.h b/mozilla/layout/forms/nsIListControlFrame.h index af27bb71f27..9d788c40b31 100644 --- a/mozilla/layout/forms/nsIListControlFrame.h +++ b/mozilla/layout/forms/nsIListControlFrame.h @@ -125,6 +125,13 @@ public: NS_IMETHOD GetOptionsContainer(nsIPresContext* aPresContext, nsIFrame** aFrame) = 0; + /** + * Tell the selected list to roll up and ensure that the proper index is + * selected, possibly firing onChange if the index has changed + * + * @param aIndex the index to actually select + */ + NS_IMETHOD ComboboxFinish(PRInt32 aIndex) = 0; }; #endif diff --git a/mozilla/layout/forms/nsListControlFrame.cpp b/mozilla/layout/forms/nsListControlFrame.cpp index ea24269a10f..7a8d4d9ccd9 100644 --- a/mozilla/layout/forms/nsListControlFrame.cpp +++ b/mozilla/layout/forms/nsListControlFrame.cpp @@ -2110,7 +2110,7 @@ nsListControlFrame::UpdateSelection() return rv; } -void +NS_IMETHODIMP nsListControlFrame::ComboboxFinish(PRInt32 aIndex) { if (mComboboxFrame) { @@ -2129,6 +2129,8 @@ nsListControlFrame::ComboboxFinish(PRInt32 aIndex) FireOnChange(); } } + + return NS_OK; } NS_IMETHODIMP diff --git a/mozilla/layout/forms/nsListControlFrame.h b/mozilla/layout/forms/nsListControlFrame.h index f84ff4c3fc9..e4dfd2b6fd8 100644 --- a/mozilla/layout/forms/nsListControlFrame.h +++ b/mozilla/layout/forms/nsListControlFrame.h @@ -277,7 +277,7 @@ public: NS_IMETHOD SetOverrideReflowOptimization(PRBool aValue) { mOverrideReflowOpt = aValue; return NS_OK; } NS_IMETHOD GetOptionsContainer(nsIPresContext* aPresContext, nsIFrame** aFrame); NS_IMETHOD FireOnChange(); - + NS_IMETHOD ComboboxFinish(PRInt32 aIndex); // nsISelectControlFrame NS_IMETHOD AddOption(nsIPresContext* aPresContext, PRInt32 index); @@ -362,7 +362,6 @@ protected: // Dropped down stuff void SetComboboxItem(PRInt32 aIndex); - void ComboboxFinish(PRInt32 aIndex); PRBool IsInDropDownMode(); // Selection diff --git a/mozilla/layout/html/forms/public/nsIListControlFrame.h b/mozilla/layout/html/forms/public/nsIListControlFrame.h index af27bb71f27..9d788c40b31 100644 --- a/mozilla/layout/html/forms/public/nsIListControlFrame.h +++ b/mozilla/layout/html/forms/public/nsIListControlFrame.h @@ -125,6 +125,13 @@ public: NS_IMETHOD GetOptionsContainer(nsIPresContext* aPresContext, nsIFrame** aFrame) = 0; + /** + * Tell the selected list to roll up and ensure that the proper index is + * selected, possibly firing onChange if the index has changed + * + * @param aIndex the index to actually select + */ + NS_IMETHOD ComboboxFinish(PRInt32 aIndex) = 0; }; #endif diff --git a/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp b/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp index 0b9c9b03ad1..667d5dd3de1 100644 --- a/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp @@ -510,20 +510,20 @@ nsComboboxControlFrame::SetFocus(PRBool aOn, PRBool aRepaint) } else { mFocused = nsnull; if (mDroppedDown) { - ToggleList(mPresContext); - } - - // Fire onChange if selected index has changed due to keyboard - // (see nsListControlFrame::UpdateSelection) - if (mNeedToFireOnChange) { - PRInt32 selectedIndex; - mListControlFrame->GetSelectedIndex(&selectedIndex); - if (selectedIndex != mRecentSelectedIndex) { - // mNeedToFireOnChange will be set to false from within FireOnChange - mListControlFrame->FireOnChange(); - } else { - // Need to set it to false anyway ... just in case - SetNeedToFireOnChange(PR_FALSE); + mListControlFrame->ComboboxFinish(mDisplayedIndex); + } else { + // Fire onChange if selected index has changed due to keyboard + // (see nsListControlFrame::UpdateSelection) + if (mNeedToFireOnChange) { + PRInt32 selectedIndex; + mListControlFrame->GetSelectedIndex(&selectedIndex); + if (selectedIndex != mRecentSelectedIndex) { + // mNeedToFireOnChange will be set to false from within FireOnChange + mListControlFrame->FireOnChange(); + } else { + // Need to set it to false anyway ... just in case + SetNeedToFireOnChange(PR_FALSE); + } } } } diff --git a/mozilla/layout/html/forms/src/nsListControlFrame.cpp b/mozilla/layout/html/forms/src/nsListControlFrame.cpp index ea24269a10f..7a8d4d9ccd9 100644 --- a/mozilla/layout/html/forms/src/nsListControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsListControlFrame.cpp @@ -2110,7 +2110,7 @@ nsListControlFrame::UpdateSelection() return rv; } -void +NS_IMETHODIMP nsListControlFrame::ComboboxFinish(PRInt32 aIndex) { if (mComboboxFrame) { @@ -2129,6 +2129,8 @@ nsListControlFrame::ComboboxFinish(PRInt32 aIndex) FireOnChange(); } } + + return NS_OK; } NS_IMETHODIMP diff --git a/mozilla/layout/html/forms/src/nsListControlFrame.h b/mozilla/layout/html/forms/src/nsListControlFrame.h index f84ff4c3fc9..e4dfd2b6fd8 100644 --- a/mozilla/layout/html/forms/src/nsListControlFrame.h +++ b/mozilla/layout/html/forms/src/nsListControlFrame.h @@ -277,7 +277,7 @@ public: NS_IMETHOD SetOverrideReflowOptimization(PRBool aValue) { mOverrideReflowOpt = aValue; return NS_OK; } NS_IMETHOD GetOptionsContainer(nsIPresContext* aPresContext, nsIFrame** aFrame); NS_IMETHOD FireOnChange(); - + NS_IMETHOD ComboboxFinish(PRInt32 aIndex); // nsISelectControlFrame NS_IMETHOD AddOption(nsIPresContext* aPresContext, PRInt32 index); @@ -362,7 +362,6 @@ protected: // Dropped down stuff void SetComboboxItem(PRInt32 aIndex); - void ComboboxFinish(PRInt32 aIndex); PRBool IsInDropDownMode(); // Selection