Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly dispatch keypress event #14738

Merged
merged 3 commits into from Jan 4, 2017
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Prev

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

  • Loading branch information
wafflespeanut committed Dec 27, 2016
commit 5f0b3bd53c25c158117c91e9da36aaec0342244f
@@ -52,6 +52,7 @@ beforeunload
message
click
keydown
keypress
abort
beforescriptexecute
afterscriptexecute
@@ -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 {
@@ -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);
}
}
}
}

@@ -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);
}
}
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.