Bug 1024350 - Support fire input event for select element.r=smaug

This commit is contained in:
John Dai 2016-06-01 00:10:00 +02:00
parent 682e2cdf72
commit 7b9485089a
4 changed files with 25 additions and 16 deletions

View File

@ -287,7 +287,7 @@ nsComboboxControlFrame::SetFocus(bool aOn, bool aRepaint)
}
}
// May delete |this|.
mListControlFrame->FireOnChange();
mListControlFrame->FireOnInputAndOnChange();
}
if (!weakFrame.IsAlive()) {

View File

@ -76,9 +76,9 @@ public:
virtual void AboutToRollup() = 0;
/**
* Fire on change (used by combobox)
* Fire on input and on change (used by combobox)
*/
virtual void FireOnChange() = 0;
virtual void FireOnInputAndOnChange() = 0;
/**
* Tell the selected list to roll up and ensure that the proper index is

View File

@ -1325,7 +1325,7 @@ nsListControlFrame::UpdateSelection()
}
}
if (mIsAllContentHere) {
FireOnChange();
FireOnInputAndOnChange();
}
return weakFrame.IsAlive();
}
@ -1358,23 +1358,30 @@ nsListControlFrame::ComboboxFinish(int32_t aIndex)
}
}
// Send out an onchange notification.
// Send out an onInput and onChange notification.
void
nsListControlFrame::FireOnChange()
nsListControlFrame::FireOnInputAndOnChange()
{
if (mComboboxFrame) {
// Return hit without changing anything
int32_t index = mComboboxFrame->UpdateRecentIndex(NS_SKIP_NOTIFY_INDEX);
if (index == NS_SKIP_NOTIFY_INDEX)
if (index == NS_SKIP_NOTIFY_INDEX) {
return;
}
// See if the selection actually changed
if (index == GetSelectedIndex())
if (index == GetSelectedIndex()) {
return;
}
}
nsCOMPtr<nsIContent> content = mContent;
// Dispatch the input event.
nsContentUtils::DispatchTrustedEvent(content->OwnerDoc(), content,
NS_LITERAL_STRING("input"), true,
false);
// Dispatch the change event.
nsContentUtils::DispatchTrustedEvent(mContent->OwnerDoc(), mContent,
nsContentUtils::DispatchTrustedEvent(content->OwnerDoc(), content,
NS_LITERAL_STRING("change"), true,
false);
}
@ -1666,9 +1673,11 @@ nsListControlFrame::MouseUp(nsIDOMEvent* aMouseEvent)
if (kNothingSelected != selectedIndex) {
nsWeakFrame weakFrame(this);
ComboboxFinish(selectedIndex);
if (!weakFrame.IsAlive())
if (!weakFrame.IsAlive()) {
return NS_OK;
FireOnChange();
}
FireOnInputAndOnChange();
}
mouseEvent->mClickCount = 1;
@ -1684,7 +1693,7 @@ nsListControlFrame::MouseUp(nsIDOMEvent* aMouseEvent)
// reset this so that future MouseUps without a prior MouseDown
// won't fire onchange
mChangesSinceDragStart = false;
FireOnChange();
FireOnInputAndOnChange();
}
}
@ -2079,7 +2088,7 @@ nsListControlFrame::DropDownToggleKey(nsIDOMEvent* aKeyEvent)
// mEndSelectionIndex is the last item that got selected.
ComboboxFinish(mEndSelectionIndex);
if (weakFrame.IsAlive()) {
FireOnChange();
FireOnInputAndOnChange();
}
}
}
@ -2184,7 +2193,7 @@ nsListControlFrame::KeyDown(nsIDOMEvent* aKeyEvent)
return NS_OK;
}
}
FireOnChange();
FireOnInputAndOnChange();
return NS_OK;
}

View File

@ -139,10 +139,10 @@ public:
virtual void AboutToRollup() override;
/**
* Dispatch a DOM onchange event synchroniously.
* Dispatch a DOM oninput and onchange event synchroniously.
* @note This method might destroy the frame, pres shell and other objects.
*/
virtual void FireOnChange() override;
virtual void FireOnInputAndOnChange() override;
/**
* Makes aIndex the selected option of a combobox list.