Skip to content

Commit

Permalink
Make Event::new take enumerated values instead of booleans (fixes #3643)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttaubert committed Oct 11, 2014
1 parent 9dfd5e7 commit 5080c0d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
22 changes: 18 additions & 4 deletions components/script/dom/event.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
}
}

Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/htmlformelement.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/xmlhttprequest.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
6 changes: 3 additions & 3 deletions components/script/script_task.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down

18 comments on commit 5080c0d

@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.

merging ttaubert/servo/issue/3643-event-new-enums = 5080c0d 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.

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

@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.

@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 ttaubert/servo/issue/3643-event-new-enums = 5080c0d 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.

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

@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.

@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 ttaubert/servo/issue/3643-event-new-enums = 5080c0d 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.

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

@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.

@Ms2ger
Copy link
Contributor

@Ms2ger Ms2ger commented on 5080c0d Oct 13, 2014

Choose a reason for hiding this comment

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

@bors: retry

@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.

merging ttaubert/servo/issue/3643-event-new-enums = 5080c0d 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.

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

@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 = 293e06f

Please sign in to comment.