diff --git a/mozilla/layout/forms/nsComboboxControlFrame.cpp b/mozilla/layout/forms/nsComboboxControlFrame.cpp index 9eaa77a600a..682b133189f 100644 --- a/mozilla/layout/forms/nsComboboxControlFrame.cpp +++ b/mozilla/layout/forms/nsComboboxControlFrame.cpp @@ -484,13 +484,7 @@ nsComboboxControlFrame::SetFocus(PRBool aOn, PRBool aRepaint) { if (aOn) { nsListControlFrame::ComboboxFocusSet(); - if (mFocused != this) { - mFocused = this; - - // Store up the selected index so when we lose focus we can see if it's - // really changed - mListControlFrame->GetSelectedIndex(&mRecentSelectedIndex); - } + mFocused = this; } else { mFocused = nsnull; if (mDroppedDown) { @@ -2254,16 +2248,13 @@ nsComboboxControlFrame::RollupFromList(nsIPresContext* aPresContext) return NS_OK; } -NS_IMETHODIMP_(PRBool) -nsComboboxControlFrame::NeededToFireOnChange() +NS_IMETHODIMP_(PRInt32) +nsComboboxControlFrame::UpdateRecentIndex(PRInt32 aIndex) { - PRInt32 index; - mListControlFrame->GetSelectedIndex(&index); - if (index == mRecentSelectedIndex) - return PR_FALSE; - - mRecentSelectedIndex = index; - return PR_TRUE; + PRInt32 index = mRecentSelectedIndex; + if (mRecentSelectedIndex == -1 || aIndex == -1) + mRecentSelectedIndex = aIndex; + return index; } NS_METHOD diff --git a/mozilla/layout/forms/nsComboboxControlFrame.h b/mozilla/layout/forms/nsComboboxControlFrame.h index 9b55b10997b..3b942bc8819 100644 --- a/mozilla/layout/forms/nsComboboxControlFrame.h +++ b/mozilla/layout/forms/nsComboboxControlFrame.h @@ -174,7 +174,7 @@ public: NS_IMETHOD GetAbsoluteRect(nsRect* aRect); NS_IMETHOD GetIndexOfDisplayArea(PRInt32* aSelectedIndex); NS_IMETHOD RedisplaySelectedText(); - NS_IMETHOD_(PRBool) NeededToFireOnChange(); + NS_IMETHOD_(PRInt32) UpdateRecentIndex(PRInt32 aIndex); // nsISelectControlFrame NS_IMETHOD AddOption(nsIPresContext* aPresContext, PRInt32 index); diff --git a/mozilla/layout/forms/nsIComboboxControlFrame.h b/mozilla/layout/forms/nsIComboboxControlFrame.h index c666d99dc34..dba5fc99795 100644 --- a/mozilla/layout/forms/nsIComboboxControlFrame.h +++ b/mozilla/layout/forms/nsIComboboxControlFrame.h @@ -94,9 +94,9 @@ public: NS_IMETHOD RedisplaySelectedText() = 0; /** - * Method for the listbox to ask the combobox if onChange should be fired + * Method for the listbox to set and get the recent index */ - NS_IMETHOD_(PRBool) NeededToFireOnChange() = 0; + NS_IMETHOD_(PRInt32) UpdateRecentIndex(PRInt32 aIndex) = 0; /** * diff --git a/mozilla/layout/forms/nsListControlFrame.cpp b/mozilla/layout/forms/nsListControlFrame.cpp index 94fca569761..0b3d8e9d9dc 100644 --- a/mozilla/layout/forms/nsListControlFrame.cpp +++ b/mozilla/layout/forms/nsListControlFrame.cpp @@ -1488,6 +1488,12 @@ nsListControlFrame::ExtendedSelection(PRInt32 aStartIndex, PRBool nsListControlFrame::SingleSelection(PRInt32 aClickedIndex, PRBool aDoToggle) { + if (mComboboxFrame) { + PRInt32 selectedIndex; + GetSelectedIndex(&selectedIndex); + mComboboxFrame->UpdateRecentIndex(selectedIndex); + } + PRBool wasChanged = PR_FALSE; // Get Current selection if (aDoToggle) { @@ -2425,7 +2431,15 @@ nsListControlFrame::FireOnChange() nsresult rv = NS_OK; if (mComboboxFrame) { - if (!mComboboxFrame->NeededToFireOnChange()) + // Return hit without changing anything + PRInt32 index = mComboboxFrame->UpdateRecentIndex(-1); + if (index == -1) + return NS_OK; + + // See if the selection actually changed + PRInt32 selectedIndex; + GetSelectedIndex(&selectedIndex); + if (index == selectedIndex) return NS_OK; } diff --git a/mozilla/layout/html/forms/public/nsIComboboxControlFrame.h b/mozilla/layout/html/forms/public/nsIComboboxControlFrame.h index c666d99dc34..dba5fc99795 100644 --- a/mozilla/layout/html/forms/public/nsIComboboxControlFrame.h +++ b/mozilla/layout/html/forms/public/nsIComboboxControlFrame.h @@ -94,9 +94,9 @@ public: NS_IMETHOD RedisplaySelectedText() = 0; /** - * Method for the listbox to ask the combobox if onChange should be fired + * Method for the listbox to set and get the recent index */ - NS_IMETHOD_(PRBool) NeededToFireOnChange() = 0; + NS_IMETHOD_(PRInt32) UpdateRecentIndex(PRInt32 aIndex) = 0; /** * diff --git a/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp b/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp index 9eaa77a600a..682b133189f 100644 --- a/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp @@ -484,13 +484,7 @@ nsComboboxControlFrame::SetFocus(PRBool aOn, PRBool aRepaint) { if (aOn) { nsListControlFrame::ComboboxFocusSet(); - if (mFocused != this) { - mFocused = this; - - // Store up the selected index so when we lose focus we can see if it's - // really changed - mListControlFrame->GetSelectedIndex(&mRecentSelectedIndex); - } + mFocused = this; } else { mFocused = nsnull; if (mDroppedDown) { @@ -2254,16 +2248,13 @@ nsComboboxControlFrame::RollupFromList(nsIPresContext* aPresContext) return NS_OK; } -NS_IMETHODIMP_(PRBool) -nsComboboxControlFrame::NeededToFireOnChange() +NS_IMETHODIMP_(PRInt32) +nsComboboxControlFrame::UpdateRecentIndex(PRInt32 aIndex) { - PRInt32 index; - mListControlFrame->GetSelectedIndex(&index); - if (index == mRecentSelectedIndex) - return PR_FALSE; - - mRecentSelectedIndex = index; - return PR_TRUE; + PRInt32 index = mRecentSelectedIndex; + if (mRecentSelectedIndex == -1 || aIndex == -1) + mRecentSelectedIndex = aIndex; + return index; } NS_METHOD diff --git a/mozilla/layout/html/forms/src/nsComboboxControlFrame.h b/mozilla/layout/html/forms/src/nsComboboxControlFrame.h index 9b55b10997b..3b942bc8819 100644 --- a/mozilla/layout/html/forms/src/nsComboboxControlFrame.h +++ b/mozilla/layout/html/forms/src/nsComboboxControlFrame.h @@ -174,7 +174,7 @@ public: NS_IMETHOD GetAbsoluteRect(nsRect* aRect); NS_IMETHOD GetIndexOfDisplayArea(PRInt32* aSelectedIndex); NS_IMETHOD RedisplaySelectedText(); - NS_IMETHOD_(PRBool) NeededToFireOnChange(); + NS_IMETHOD_(PRInt32) UpdateRecentIndex(PRInt32 aIndex); // nsISelectControlFrame NS_IMETHOD AddOption(nsIPresContext* aPresContext, PRInt32 index); diff --git a/mozilla/layout/html/forms/src/nsListControlFrame.cpp b/mozilla/layout/html/forms/src/nsListControlFrame.cpp index 94fca569761..0b3d8e9d9dc 100644 --- a/mozilla/layout/html/forms/src/nsListControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsListControlFrame.cpp @@ -1488,6 +1488,12 @@ nsListControlFrame::ExtendedSelection(PRInt32 aStartIndex, PRBool nsListControlFrame::SingleSelection(PRInt32 aClickedIndex, PRBool aDoToggle) { + if (mComboboxFrame) { + PRInt32 selectedIndex; + GetSelectedIndex(&selectedIndex); + mComboboxFrame->UpdateRecentIndex(selectedIndex); + } + PRBool wasChanged = PR_FALSE; // Get Current selection if (aDoToggle) { @@ -2425,7 +2431,15 @@ nsListControlFrame::FireOnChange() nsresult rv = NS_OK; if (mComboboxFrame) { - if (!mComboboxFrame->NeededToFireOnChange()) + // Return hit without changing anything + PRInt32 index = mComboboxFrame->UpdateRecentIndex(-1); + if (index == -1) + return NS_OK; + + // See if the selection actually changed + PRInt32 selectedIndex; + GetSelectedIndex(&selectedIndex); + if (index == selectedIndex) return NS_OK; }