Adjust current index of combobox when options are added or removed. b=286170 r+sr=bzbarsky a=asa

This commit is contained in:
mats.palmgren%bredband.net 2005-06-20 23:26:35 +00:00
Родитель a3adad8b4f
Коммит 05cc19b763
2 изменённых файлов: 29 добавлений и 18 удалений

Просмотреть файл

@ -21,6 +21,7 @@
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
* Mats Palmgren <mats.palmgren@bredband.net>
*
* 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();
}

Просмотреть файл

@ -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);
}