Skip to content
Permalink
Browse files

Make Event::new take enumerated values instead of booleans (fixes #3643)

  • Loading branch information...
ttaubert committed Oct 11, 2014
1 parent 9dfd5e7 commit 5080c0d86e4f3388f78fff535d746c51a757b618
@@ -35,6 +35,18 @@ pub enum EventTypeId {
UIEventTypeId
}

#[deriving(PartialEq)]
pub enum EventBubbles {
Bubbles,
DoesNotBubble
}

#[deriving(PartialEq)]
pub enum EventCancelable {
Cancelable,
NotCancelable
}

#[jstraceable]
#[must_root]
pub struct Event {
@@ -84,17 +96,19 @@ impl Event {

pub fn new(global: &GlobalRef,
type_: DOMString,
can_bubble: bool,
cancelable: bool) -> Temporary<Event> {
bubbles: EventBubbles,
cancelable: EventCancelable) -> Temporary<Event> {
let event = Event::new_uninitialized(global).root();
event.InitEvent(type_, can_bubble, cancelable);
event.InitEvent(type_, bubbles == Bubbles, cancelable == Cancelable);
Temporary::from_rooted(*event)
}

pub fn Constructor(global: &GlobalRef,
type_: DOMString,
init: &EventBinding::EventInit) -> Fallible<Temporary<Event>> {
Ok(Event::new(global, type_, init.bubbles, init.cancelable))
let bubbles = if init.bubbles { Bubbles } else { DoesNotBubble };
let cancelable = if init.cancelable { Cancelable } else { NotCancelable };
Ok(Event::new(global, type_, bubbles, cancelable))
}
}

@@ -15,7 +15,7 @@ use dom::bindings::utils::{Reflectable, Reflector};
use dom::document::{Document, DocumentHelpers};
use dom::element::{Element, AttributeHandlers, HTMLFormElementTypeId, HTMLTextAreaElementTypeId, HTMLDataListElementTypeId};
use dom::element::{HTMLInputElementTypeId, HTMLButtonElementTypeId, HTMLObjectElementTypeId, HTMLSelectElementTypeId};
use dom::event::Event;
use dom::event::{Event, Bubbles, Cancelable};
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::htmlelement::HTMLElement;
use dom::htmlinputelement::HTMLInputElement;
@@ -172,7 +172,7 @@ impl<'a> HTMLFormElementHelpers for JSRef<'a, HTMLFormElement> {
// TODO: Handle validation
let event = Event::new(&Window(*win),
"submit".to_string(),
true, true).root();
Bubbles, Cancelable).root();
let target: JSRef<EventTarget> = EventTargetCast::from_ref(self);
target.DispatchEvent(*event).ok();
if event.DefaultPrevented() {
@@ -17,7 +17,7 @@ use dom::bindings::js::{MutNullableJS, JS, JSRef, Temporary, OptionalRootedRoota
use dom::bindings::str::ByteString;
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::document::Document;
use dom::event::Event;
use dom::event::{Event, DoesNotBubble, Cancelable};
use dom::eventtarget::{EventTarget, EventTargetHelpers, XMLHttpRequestTargetTypeId};
use dom::progressevent::ProgressEvent;
use dom::urlsearchparams::URLSearchParamsHelpers;
@@ -746,7 +746,7 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> {
let global = self.global.root();
let event = Event::new(&global.root_ref(),
"readystatechange".to_string(),
false, true).root();
DoesNotBubble, Cancelable).root();
let target: JSRef<EventTarget> = EventTargetCast::from_ref(self);
target.dispatch_event_with_target(None, *event).ok();
}
@@ -19,7 +19,7 @@ use dom::bindings::utils::{wrap_for_same_compartment, pre_wrap};
use dom::document::{Document, HTMLDocument, DocumentHelpers};
use dom::element::{Element, HTMLButtonElementTypeId, HTMLInputElementTypeId};
use dom::element::{HTMLSelectElementTypeId, HTMLTextAreaElementTypeId, HTMLOptionElementTypeId};
use dom::event::Event;
use dom::event::{Event, Bubbles, DoesNotBubble, Cancelable, NotCancelable};
use dom::uievent::UIEvent;
use dom::eventtarget::{EventTarget, EventTargetHelpers};
use dom::node;
@@ -851,7 +851,7 @@ impl ScriptTask {
// We have no concept of a document loader right now, so just dispatch the
// "load" event as soon as we've finished executing all scripts parsed during
// the initial load.
let event = Event::new(&global::Window(*window), "load".to_string(), false, false).root();
let event = Event::new(&global::Window(*window), "load".to_string(), DoesNotBubble, NotCancelable).root();
let doctarget: JSRef<EventTarget> = EventTargetCast::from_ref(*document);
let wintarget: JSRef<EventTarget> = EventTargetCast::from_ref(*window);
let _ = wintarget.dispatch_event_with_target(Some(doctarget), *event);
@@ -981,7 +981,7 @@ impl ScriptTask {
let event =
Event::new(&global::Window(*window),
"click".to_string(),
true, true).root();
Bubbles, Cancelable).root();
let eventtarget: JSRef<EventTarget> = EventTargetCast::from_ref(node);
let _ = eventtarget.dispatch_event_with_target(None, *event);

18 comments on commit 5080c0d

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Oct 11, 2014

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Oct 11, 2014

merging ttaubert/servo/issue/3643-event-new-enums = 5080c0d into auto

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Oct 11, 2014

ttaubert/servo/issue/3643-event-new-enums = 5080c0d merged ok, testing candidate = b14594d

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Oct 11, 2014

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Oct 11, 2014

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Oct 11, 2014

merging ttaubert/servo/issue/3643-event-new-enums = 5080c0d into auto

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Oct 11, 2014

ttaubert/servo/issue/3643-event-new-enums = 5080c0d merged ok, testing candidate = e59d459

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Oct 11, 2014

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Oct 11, 2014

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Oct 11, 2014

merging ttaubert/servo/issue/3643-event-new-enums = 5080c0d into auto

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Oct 11, 2014

ttaubert/servo/issue/3643-event-new-enums = 5080c0d merged ok, testing candidate = 2f31630

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Oct 11, 2014

@Ms2ger

This comment has been minimized.

Copy link
Contributor

Ms2ger replied Oct 13, 2014

@bors: retry

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Oct 14, 2014

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Oct 14, 2014

merging ttaubert/servo/issue/3643-event-new-enums = 5080c0d into auto

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Oct 14, 2014

ttaubert/servo/issue/3643-event-new-enums = 5080c0d merged ok, testing candidate = 293e06f

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Oct 14, 2014

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo replied Oct 14, 2014

fast-forwarding master to auto = 293e06f

Please sign in to comment.
You can’t perform that action at this time.