Skip to content

Commit

Permalink
#4508 Adding simple test and actually getting the event to dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
mattnenterprise committed Mar 17, 2015
1 parent 5938a4c commit 0bd717e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
4 changes: 2 additions & 2 deletions components/script/dom/document.rs
Expand Up @@ -629,7 +629,7 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> {
ctrl, alt, shift, meta,
None, props.key_code).root();
let event = EventCast::from_ref(keyevent.r());
let _ = target.DispatchEvent(event);
event.fire(target);
let mut prevented = event.DefaultPrevented();

// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#keys-cancelable-keys
Expand All @@ -642,7 +642,7 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> {
ctrl, alt, shift, meta,
props.char_code, 0).root();
let ev = EventCast::from_ref(event.r());
let _ = target.DispatchEvent(ev);
ev.fire(target);
prevented = ev.DefaultPrevented();
// TODO: if keypress event is canceled, prevent firing input events
}
Expand Down
8 changes: 4 additions & 4 deletions components/script/dom/htmltextareaelement.rs
Expand Up @@ -13,7 +13,7 @@ use dom::bindings::codegen::InheritTypes::{ElementCast, EventTargetCast, HTMLEle
use dom::bindings::codegen::InheritTypes::{HTMLTextAreaElementDerived, HTMLFieldSetElementDerived};
use dom::bindings::codegen::InheritTypes::{KeyboardEventCast, TextDerived};
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JS, JSRef, LayoutJS, Temporary, OptionalRootable};
use dom::bindings::js::{JSRef, LayoutJS, Temporary, OptionalRootable};
use dom::bindings::refcounted::Trusted;
use dom::document::{Document, DocumentHelpers};
use dom::element::{Element, AttributeHandlers};
Expand Down Expand Up @@ -347,15 +347,15 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLTextAreaElement> {
KeyReaction::DispatchInput => {
self.value_changed.set(true);

if event.IsTrusted() == true {
if event.IsTrusted() {
let window = window_from_node(*self).root();
let window = window.r();
let chan = window.script_chan();
let handler = Trusted::new(window.get_cx(), *self , chan.clone());
let dispatcher = ChangeEventRunnable {
element: handler,
};
chan.send(ScriptMsg::RunnableMsg(box dispatcher));
let _ = chan.send(ScriptMsg::RunnableMsg(box dispatcher));
}

self.force_relayout();
Expand All @@ -382,4 +382,4 @@ impl Runnable for ChangeEventRunnable {
let target = self.element.to_temporary().root();
target.r().dispatch_change_event();
}
}
}
15 changes: 15 additions & 0 deletions tests/html/test_textarea_input.html
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<textarea id="textarea">
</textarea>
</body>
<script>
var area = document.getElementById('textarea');
area.addEventListener('input', function() {
alert('input detected');
});
</script>
</html>

5 comments on commit 0bd717e

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from jdm
at mattnenterprise@0bd717e

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging mattnenterprise/servo/dispatch_input_event = 0bd717e into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mattnenterprise/servo/dispatch_input_event = 0bd717e merged ok, testing candidate = 65d4b12

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 65d4b12

Please sign in to comment.