Bug 1297635 - Add a helper function for input to check whether input events with modifier should change the value. r=smaug, f=bevistseng

This commit is contained in:
Stone Shih
2016-09-06 14:30:00 +08:00
parent 268a50d257
commit 3a6eb5a9f4

View File

@@ -4128,6 +4128,17 @@ HTMLInputElement::MaybeInitPickers(EventChainPostVisitor& aVisitor)
return NS_OK;
}
/**
* Return true if the input event should be ignore because of it's modifiers
*/
static bool
IgnoreInputEventWithModifier(WidgetInputEvent* aEvent)
{
return aEvent->IsShift() || aEvent->IsControl() || aEvent->IsAlt() ||
aEvent->IsMeta() || aEvent->IsAltGraph() || aEvent->IsFn() ||
aEvent->IsOS();
}
nsresult
HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor)
{
@@ -4274,10 +4285,7 @@ HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor)
keyEvent && keyEvent->mMessage == eKeyPress &&
aVisitor.mEvent->IsTrusted() &&
(keyEvent->mKeyCode == NS_VK_UP || keyEvent->mKeyCode == NS_VK_DOWN) &&
!(keyEvent->IsShift() || keyEvent->IsControl() ||
keyEvent->IsAlt() || keyEvent->IsMeta() ||
keyEvent->IsAltGraph() || keyEvent->IsFn() ||
keyEvent->IsOS())) {
!IgnoreInputEventWithModifier(keyEvent)) {
// We handle the up/down arrow keys specially for <input type=number>.
// On some platforms the editor for the nested text control will
// process these keys to send the cursor to the start/end of the text
@@ -4496,10 +4504,7 @@ HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor)
}
if (mType == NS_FORM_INPUT_NUMBER && aVisitor.mEvent->IsTrusted()) {
if (mouseEvent->button == WidgetMouseEvent::eLeftButton &&
!(mouseEvent->IsShift() || mouseEvent->IsControl() ||
mouseEvent->IsAlt() || mouseEvent->IsMeta() ||
mouseEvent->IsAltGraph() || mouseEvent->IsFn() ||
mouseEvent->IsOS())) {
!IgnoreInputEventWithModifier(mouseEvent)) {
nsNumberControlFrame* numberControlFrame =
do_QueryFrame(GetPrimaryFrame());
if (numberControlFrame) {
@@ -4662,10 +4667,7 @@ HTMLInputElement::PostHandleEventForRangeThumb(EventChainPostVisitor& aVisitor)
break; // don't start drag if someone else is already capturing
}
WidgetInputEvent* inputEvent = aVisitor.mEvent->AsInputEvent();
if (inputEvent->IsShift() || inputEvent->IsControl() ||
inputEvent->IsAlt() || inputEvent->IsMeta() ||
inputEvent->IsAltGraph() || inputEvent->IsFn() ||
inputEvent->IsOS()) {
if (IgnoreInputEventWithModifier(inputEvent)) {
break; // ignore
}
if (aVisitor.mEvent->mMessage == eMouseDown) {