Skip to content
Permalink
Browse files

Remove the global argument to EventTarget::{fire_event, fire_simple_e…

…vent}.
  • Loading branch information
Ms2ger committed Feb 8, 2016
1 parent 4c4df37 commit 5317af1e19833e29db735ecd2df507b72851d7f7
@@ -550,8 +550,7 @@ impl Document {

self.ready_state.set(state);

self.upcast::<EventTarget>().fire_simple_event("readystatechange",
GlobalRef::Window(&self.window));
self.upcast::<EventTarget>().fire_simple_event("readystatechange");
}

/// Return whether scripting is enabled or not
@@ -1357,8 +1356,7 @@ impl Document {
let doctarget = self.upcast::<EventTarget>();
let _ = doctarget.fire_event("DOMContentLoaded",
EventBubbles::Bubbles,
EventCancelable::NotCancelable,
GlobalRef::Window(self.window()));
EventCancelable::NotCancelable);

self.window().reflow(ReflowGoal::ForDisplay,
ReflowQueryType::NoQuery,
@@ -1693,14 +1691,17 @@ impl DocumentMethods for Document {

// https://html.spec.whatwg.org/multipage/#dom-document-hasfocus
fn HasFocus(&self) -> bool {
let target = self; // Step 1.
// Step 1.
let target = self;
let browsing_context = self.window.browsing_context();
let browsing_context = browsing_context.as_ref();

match browsing_context {
Some(browsing_context) => {
let condidate = browsing_context.active_document(); // Step 2.
if condidate.node.get_unique_id() == target.node.get_unique_id() { // Step 3.
// Step 2.
let candidate = browsing_context.active_document();
// Step 3.
if candidate == target {
true
} else {
false //TODO Step 4.
@@ -11,7 +11,6 @@ use dom::bindings::codegen::Bindings::EventListenerBinding::EventListener;
use dom::bindings::codegen::Bindings::EventTargetBinding::EventTargetMethods;
use dom::bindings::codegen::UnionTypes::EventOrString;
use dom::bindings::error::{Error, Fallible, report_pending_exception};
use dom::bindings::global::GlobalRef;
use dom::bindings::inheritance::{Castable, EventTargetTypeId};
use dom::bindings::js::Root;
use dom::bindings::reflector::{Reflectable, Reflector};
@@ -331,17 +330,18 @@ impl EventTarget {
}

// https://html.spec.whatwg.org/multipage/#fire-a-simple-event
pub fn fire_simple_event(&self, name: &str, win: GlobalRef) -> Root<Event> {
pub fn fire_simple_event(&self, name: &str) -> Root<Event> {
self.fire_event(name, EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable, win)
EventCancelable::NotCancelable)
}

// https://dom.spec.whatwg.org/#concept-event-fire
pub fn fire_event(&self, name: &str,
bubbles: EventBubbles,
cancelable: EventCancelable,
win: GlobalRef) -> Root<Event> {
let event = Event::new(win, Atom::from(name), bubbles, cancelable);
cancelable: EventCancelable)
-> Root<Event> {
let global = self.global();
let event = Event::new(global.r(), Atom::from(name), bubbles, cancelable);

event.fire(self);

@@ -5,7 +5,6 @@
use dom::attr::Attr;
use dom::bindings::codegen::Bindings::HTMLDetailsElementBinding;
use dom::bindings::codegen::Bindings::HTMLDetailsElementBinding::HTMLDetailsElementMethods;
use dom::bindings::global::GlobalRef;
use dom::bindings::inheritance::Castable;
use dom::bindings::js::Root;
use dom::bindings::refcounted::Trusted;
@@ -97,11 +96,8 @@ impl ToggleEventRunnable {
impl Runnable for ToggleEventRunnable {
fn handler(self: Box<ToggleEventRunnable>) {
let target = self.element.root();
let window = window_from_node(target.upcast::<Node>());

if target.check_toggle_count(self.toggle_number) {
target.upcast::<EventTarget>()
.fire_simple_event("toggle", GlobalRef::Window(window.r()));
target.upcast::<EventTarget>().fire_simple_event("toggle");
}
}
}
@@ -11,7 +11,6 @@ use dom::bindings::codegen::Bindings::HTMLFormElementBinding::HTMLFormElementMet
use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods;
use dom::bindings::codegen::Bindings::HTMLTextAreaElementBinding::HTMLTextAreaElementMethods;
use dom::bindings::conversions::DerivedFrom;
use dom::bindings::global::GlobalRef;
use dom::bindings::inheritance::{Castable, ElementTypeId, HTMLElementTypeId, NodeTypeId};
use dom::bindings::js::{JS, MutNullableHeap, Root};
use dom::bindings::reflector::Reflectable;
@@ -228,7 +227,6 @@ impl HTMLFormElement {
pub fn submit(&self, submit_method_flag: SubmittedFrom, submitter: FormSubmitter) {
// Step 1
let doc = document_from_node(self);
let win = window_from_node(self);
let base = doc.url();
// TODO: Handle browsing contexts
// Step 4
@@ -237,8 +235,7 @@ impl HTMLFormElement {
{
if self.interactive_validation().is_err() {
// TODO: Implement event handlers on all form control elements
self.upcast::<EventTarget>()
.fire_simple_event("invalid", GlobalRef::Window(win.r()));
self.upcast::<EventTarget>().fire_simple_event("invalid");
return;
}
}
@@ -247,8 +244,7 @@ impl HTMLFormElement {
let event = self.upcast::<EventTarget>()
.fire_event("submit",
EventBubbles::Bubbles,
EventCancelable::Cancelable,
GlobalRef::Window(win.r()));
EventCancelable::Cancelable);
if event.DefaultPrevented() {
return;
}
@@ -302,6 +298,7 @@ impl HTMLFormElement {
}

// This is wrong. https://html.spec.whatwg.org/multipage/#planned-navigation
let win = window_from_node(self);
win.main_thread_script_chan().send(MainThreadScriptMsg::Navigate(
win.pipeline(), load_data)).unwrap();
}
@@ -341,13 +338,11 @@ impl HTMLFormElement {
// Step 4
if invalid_controls.is_empty() { return Ok(()); }
// Step 5-6
let win = window_from_node(self);
let unhandled_invalid_controls = invalid_controls.into_iter().filter_map(|field| {
let event = field.as_event_target()
.fire_event("invalid",
EventBubbles::DoesNotBubble,
EventCancelable::Cancelable,
GlobalRef::Window(win.r()));
EventCancelable::Cancelable);
if !event.DefaultPrevented() { return Some(field); }
None
}).collect::<Vec<FormSubmittableElement>>();
@@ -469,12 +464,10 @@ impl HTMLFormElement {
self.marked_for_reset.set(true);
}

let win = window_from_node(self);
let event = self.upcast::<EventTarget>()
.fire_event("reset",
EventBubbles::Bubbles,
EventCancelable::Cancelable,
GlobalRef::Window(win.r()));
EventCancelable::Cancelable);
if event.DefaultPrevented() {
return;
}
@@ -210,10 +210,10 @@ impl HTMLIFrameElement {
// TODO Step 3 - set child document `mut iframe load` flag

// Step 4
let window = window_from_node(self);
self.upcast::<EventTarget>().fire_simple_event("load", GlobalRef::Window(window.r()));
self.upcast::<EventTarget>().fire_simple_event("load");
// TODO Step 5 - unset child document `mut iframe load` flag

let window = window_from_node(self);
window.reflow(ReflowGoal::ForDisplay,
ReflowQueryType::NoQuery,
ReflowReason::IFrameLoadEvent);
@@ -82,11 +82,12 @@ impl Runnable for ImageResponseHandlerRunnable {
document.content_changed(element.upcast(), NodeDamage::OtherNodeDamage);

// Fire image.onload
let window = window_from_node(document.r());
if trigger_image_load {
element.upcast::<EventTarget>().fire_simple_event("load", GlobalRef::Window(window.r()));
element.upcast::<EventTarget>().fire_simple_event("load");
}

// Trigger reflow
let window = window_from_node(document.r());
window.add_pending_reflow();
}
}
@@ -866,17 +866,13 @@ impl Activatable for HTMLInputElement {
// https://html.spec.whatwg.org/multipage/#checkbox-state-(type=checkbox):activation-behavior
// https://html.spec.whatwg.org/multipage/#radio-button-state-(type=radio):activation-behavior
if self.mutable() {
let win = window_from_node(self);
let target = self.upcast::<EventTarget>();

target.fire_event("input",
EventBubbles::Bubbles,
EventCancelable::NotCancelable,
GlobalRef::Window(win.r()));
EventCancelable::NotCancelable);
target.fire_event("change",
EventBubbles::Bubbles,
EventCancelable::NotCancelable,
GlobalRef::Window(win.r()));
EventCancelable::NotCancelable);
}
},
_ => ()
@@ -487,7 +487,7 @@ impl Runnable for ConnectionEstablishedTask {
// Step 5: Cookies.

// Step 6.
ws.upcast().fire_simple_event("open", global.r());
ws.upcast().fire_simple_event("open");
}
}

@@ -537,8 +537,7 @@ impl Runnable for CloseTask {
if self.failed {
ws.upcast().fire_event("error",
EventBubbles::DoesNotBubble,
EventCancelable::Cancelable,
global.r());
EventCancelable::Cancelable);
}

// Step 3.
@@ -122,8 +122,7 @@ impl Worker {

pub fn dispatch_simple_error(address: TrustedWorkerAddress) {
let worker = address.root();
let global = worker.r().global();
worker.upcast().fire_simple_event("error", global.r());
worker.upcast().fire_simple_event("error");
}

pub fn handle_error_message(address: TrustedWorkerAddress, message: DOMString,

0 comments on commit 5317af1

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