Use task! for the details notification steps

This commit is contained in:
Anthony Ramine 2017-09-17 23:25:56 +02:00
parent b3e27509b7
commit 915a4f8385

View file

@ -17,7 +17,6 @@ use dom::virtualmethods::VirtualMethods;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use html5ever::{LocalName, Prefix}; use html5ever::{LocalName, Prefix};
use std::cell::Cell; use std::cell::Cell;
use task::Task;
use task_source::TaskSource; use task_source::TaskSource;
#[dom_struct] #[dom_struct]
@ -45,10 +44,6 @@ impl HTMLDetailsElement {
document, document,
HTMLDetailsElementBinding::Wrap) HTMLDetailsElementBinding::Wrap)
} }
pub fn check_toggle_count(&self, number: u32) -> bool {
number == self.toggle_counter.get()
}
} }
impl HTMLDetailsElementMethods for HTMLDetailsElement { impl HTMLDetailsElementMethods for HTMLDetailsElement {
@ -72,27 +67,17 @@ impl VirtualMethods for HTMLDetailsElement {
self.toggle_counter.set(counter); self.toggle_counter.set(counter);
let window = window_from_node(self); let window = window_from_node(self);
let task_source = window.dom_manipulation_task_source(); let this = Trusted::new(self);
let details = Trusted::new(self); // FIXME(nox): Why are errors silenced here?
let task = box DetailsNotificationTask { let _ = window.dom_manipulation_task_source().queue(
element: details, box task!(details_notification_task_steps: move || {
toggle_number: counter let this = this.root();
}; if counter == this.toggle_counter.get() {
let _ = task_source.queue(task, window.upcast()); this.upcast::<EventTarget>().fire_event(atom!("toggle"));
} }
} }),
} window.upcast(),
);
pub struct DetailsNotificationTask {
element: Trusted<HTMLDetailsElement>,
toggle_number: u32
}
impl Task for DetailsNotificationTask {
fn run(self: Box<Self>) {
let target = self.element.root();
if target.check_toggle_count(self.toggle_number) {
target.upcast::<EventTarget>().fire_event(atom!("toggle"));
} }
} }
} }