Skip to content

Commit

Permalink
De-duplicate input event send code
Browse files Browse the repository at this point in the history
  • Loading branch information
chkimes committed Jan 2, 2016
1 parent 12a0884 commit 0e663e0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
24 changes: 15 additions & 9 deletions components/script/dom/htmlinputelement.rs
Expand Up @@ -695,14 +695,7 @@ impl VirtualMethods for HTMLInputElement {
self.value_changed.set(true);

if event.IsTrusted() {
let window = window_from_node(self);
let window = window.r();
let chan = window.user_interaction_task_source();
let handler = Trusted::new(self.upcast::<Node>(), chan.clone());
let dispatcher = ChangeEventRunnable {
element: handler,
};
let _ = chan.send(CommonScriptMsg::RunnableMsg(InputEvent, box dispatcher));
ChangeEventRunnable::send(self.upcast::<Node>());
}

self.force_relayout();
Expand Down Expand Up @@ -937,7 +930,20 @@ impl Activatable for HTMLInputElement {
}

pub struct ChangeEventRunnable {
pub element: Trusted<Node>,
element: Trusted<Node>,
}

impl ChangeEventRunnable {
pub fn send(node: &Node) {
let window = window_from_node(node);
let window = window.r();
let chan = window.user_interaction_task_source();
let handler = Trusted::new(node, chan.clone());
let dispatcher = ChangeEventRunnable {
element: handler,
};
let _ = chan.send(CommonScriptMsg::RunnableMsg(InputEvent, box dispatcher));
}
}

impl Runnable for ChangeEventRunnable {
Expand Down
14 changes: 2 additions & 12 deletions components/script/dom/htmltextareaelement.rs
Expand Up @@ -10,7 +10,6 @@ use dom::bindings::codegen::Bindings::HTMLTextAreaElementBinding::HTMLTextAreaEl
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
use dom::bindings::inheritance::Castable;
use dom::bindings::js::{LayoutJS, Root};
use dom::bindings::refcounted::Trusted;
use dom::bindings::reflector::{Reflectable};
use dom::document::Document;
use dom::element::RawLayoutElementHelpers;
Expand All @@ -22,12 +21,10 @@ use dom::htmlformelement::{FormControl, HTMLFormElement};
use dom::htmlinputelement::ChangeEventRunnable;
use dom::keyboardevent::KeyboardEvent;
use dom::node::{ChildrenMutation, Node, NodeDamage, UnbindContext};
use dom::node::{document_from_node, window_from_node};
use dom::node::{document_from_node};
use dom::nodelist::NodeList;
use dom::virtualmethods::VirtualMethods;
use msg::constellation_msg::ConstellationChan;
use script_task::ScriptTaskEventCategory::InputEvent;
use script_task::{CommonScriptMsg};
use script_traits::ScriptMsg as ConstellationMsg;
use selectors::states::*;
use std::cell::Cell;
Expand Down Expand Up @@ -316,14 +313,7 @@ impl VirtualMethods for HTMLTextAreaElement {
self.value_changed.set(true);

if event.IsTrusted() {
let window = window_from_node(self);
let window = window.r();
let chan = window.user_interaction_task_source();
let handler = Trusted::new(self.upcast::<Node>(), chan.clone());
let dispatcher = ChangeEventRunnable {
element: handler,
};
let _ = chan.send(CommonScriptMsg::RunnableMsg(InputEvent, box dispatcher));
ChangeEventRunnable::send(self.upcast::<Node>());
}

self.force_relayout();
Expand Down

0 comments on commit 0e663e0

Please sign in to comment.