Fire 'input' event after 'keypress' in input and textarea elements

This commit is contained in:
Ravi Shankar 2016-12-27 13:18:45 +05:30
parent 08662cc64e
commit 5f0b3bd53c
4 changed files with 24 additions and 24 deletions

View file

@ -52,6 +52,7 @@ beforeunload
message
click
keydown
keypress
abort
beforescriptexecute
afterscriptexecute

View file

@ -1334,7 +1334,6 @@ impl Document {
let ev = event.upcast::<Event>();
ev.fire(target);
cancel_state = ev.get_cancel_state();
// TODO: if keypress event is canceled, prevent firing input events
}
if cancel_state == EventDefault::Allowed {

View file

@ -1105,17 +1105,6 @@ impl VirtualMethods for HTMLInputElement {
DispatchInput => {
self.value_changed.set(true);
self.update_placeholder_shown_state();
if event.IsTrusted() {
let window = window_from_node(self);
let _ = window.user_interaction_task_source().queue_event(
&self.upcast(),
atom!("input"),
EventBubbles::Bubbles,
EventCancelable::NotCancelable,
&window);
}
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
event.mark_as_handled();
}
@ -1126,7 +1115,19 @@ impl VirtualMethods for HTMLInputElement {
Nothing => (),
}
}
}
} else if event.type_() == atom!("keypress") && !event.DefaultPrevented() &&
(self.input_type.get() == InputType::InputText ||
self.input_type.get() == InputType::InputPassword) {
if event.IsTrusted() {
let window = window_from_node(self);
let _ = window.user_interaction_task_source()
.queue_event(&self.upcast(),
atom!("input"),
EventBubbles::Bubbles,
EventCancelable::NotCancelable,
&window);
}
}
}
}

View file

@ -403,17 +403,6 @@ impl VirtualMethods for HTMLTextAreaElement {
KeyReaction::DispatchInput => {
self.value_changed.set(true);
self.update_placeholder_shown_state();
if event.IsTrusted() {
let window = window_from_node(self);
let _ = window.user_interaction_task_source().queue_event(
&self.upcast(),
atom!("input"),
EventBubbles::Bubbles,
EventCancelable::NotCancelable,
&window);
}
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
event.mark_as_handled();
}
@ -424,6 +413,16 @@ impl VirtualMethods for HTMLTextAreaElement {
KeyReaction::Nothing => (),
}
}
} else if event.type_() == atom!("keypress") && !event.DefaultPrevented() {
if event.IsTrusted() {
let window = window_from_node(self);
let _ = window.user_interaction_task_source()
.queue_event(&self.upcast(),
atom!("input"),
EventBubbles::Bubbles,
EventCancelable::NotCancelable,
&window);
}
}
}
}