diff --git a/mozilla/content/html/content/src/nsHTMLSelectElement.cpp b/mozilla/content/html/content/src/nsHTMLSelectElement.cpp
index b8201a628ec..20544991453 100644
--- a/mozilla/content/html/content/src/nsHTMLSelectElement.cpp
+++ b/mozilla/content/html/content/src/nsHTMLSelectElement.cpp
@@ -21,6 +21,7 @@
*
* Contributor(s):
* Pierre Phaneuf
+ * Mats Palmgren
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@@ -395,6 +396,17 @@ protected:
*/
void DispatchDOMEvent(const nsAString& aName);
+ /**
+ * Is this a combobox?
+ */
+ PRBool IsCombobox() {
+ PRBool isMultiple = PR_TRUE;
+ PRInt32 size = 1;
+ GetSize(&size);
+ GetMultiple(&isMultiple);
+ return !isMultiple && size <= 1;
+ }
+
/** The options[] array */
nsHTMLOptionCollection* mOptions;
/** false if the parser is in the middle of adding children. */
@@ -1601,11 +1613,7 @@ PRBool
nsHTMLSelectElement::CheckSelectSomething()
{
if (mIsDoneAddingChildren) {
- PRInt32 size = 1;
- GetSize(&size);
- PRBool isMultiple;
- GetMultiple(&isMultiple);
- if (mSelectedIndex < 0 && !isMultiple && size <= 1) {
+ if (mSelectedIndex < 0 && IsCombobox()) {
return SelectSomething();
}
}
@@ -1905,13 +1913,7 @@ nsHTMLSelectElement::Reset()
//
// If nothing was selected and it's not multiple, select something
//
- PRInt32 size = 1;
- GetSize(&size);
-
- PRBool isMultiple = PR_FALSE;
- GetMultiple(&isMultiple);
-
- if (numSelected == 0 && !isMultiple && size <= 1) {
+ if (numSelected == 0 && IsCombobox()) {
SelectSomething();
}
diff --git a/mozilla/layout/forms/nsComboboxControlFrame.cpp b/mozilla/layout/forms/nsComboboxControlFrame.cpp
index 6bc7caaee4a..afef51ab4b9 100644
--- a/mozilla/layout/forms/nsComboboxControlFrame.cpp
+++ b/mozilla/layout/forms/nsComboboxControlFrame.cpp
@@ -1898,10 +1898,11 @@ nsComboboxControlFrame::DoneAddingChildren(PRBool aIsDone)
NS_IMETHODIMP
nsComboboxControlFrame::AddOption(nsPresContext* aPresContext, PRInt32 aIndex)
{
-#ifdef DO_REFLOW_DEBUGXX
- printf("*********AddOption: %d\n", aIndex);
-#endif
- nsListControlFrame * lcf = NS_STATIC_CAST(nsListControlFrame*, mDropdownFrame);
+ if (aIndex <= mDisplayedIndex) {
+ ++mDisplayedIndex;
+ }
+
+ nsListControlFrame* lcf = NS_STATIC_CAST(nsListControlFrame*, mDropdownFrame);
return lcf->AddOption(aPresContext, aIndex);
}
@@ -1909,10 +1910,18 @@ nsComboboxControlFrame::AddOption(nsPresContext* aPresContext, PRInt32 aIndex)
NS_IMETHODIMP
nsComboboxControlFrame::RemoveOption(nsPresContext* aPresContext, PRInt32 aIndex)
{
- // If we removed the last option, we need to blank things out
PRInt32 len;
mListControlFrame->GetNumberOfOptions(&len);
- if (len == 0) {
+ if (len > 0) {
+ if (aIndex < mDisplayedIndex) {
+ --mDisplayedIndex;
+ } else if (aIndex == mDisplayedIndex) {
+ mDisplayedIndex = 0; // IE6 compat
+ RedisplayText(mDisplayedIndex);
+ }
+ }
+ else {
+ // If we removed the last option, we need to blank things out
RedisplayText(-1);
}