Use task! instead of DocumentProgressHandler

This commit is contained in:
Anthony Ramine 2017-09-17 17:30:48 +02:00
parent 5412767f46
commit e9f6ea40c2

View file

@ -142,7 +142,6 @@ use style::shared_lock::{SharedRwLock as StyleSharedRwLock, SharedRwLockReadGuar
use style::str::{HTML_SPACE_CHARACTERS, split_html_space_chars, str_join};
use style::stylesheet_set::StylesheetSet;
use style::stylesheets::{Stylesheet, StylesheetContents, Origin, OriginSet};
use task::Task;
use task_source::TaskSource;
use time;
use timers::OneshotTimerCallback;
@ -1715,8 +1714,57 @@ impl Document {
// The rest will ever run only once per document.
// Step 7.
debug!("Document loads are complete.");
let handler = box DocumentProgressHandler::new(Trusted::new(self));
self.window.dom_manipulation_task_source().queue(handler, self.window.upcast()).unwrap();
let document = Trusted::new(self);
self.window.dom_manipulation_task_source().queue(
box task!(fire_load_event: move || {
let document = document.root();
let window = document.window();
if !window.is_alive() {
return;
}
// Step 7.1.
document.set_ready_state(DocumentReadyState::Complete);
// Step 7.2.
if document.browsing_context().is_none() {
return;
}
let event = Event::new(
window.upcast(),
atom!("load"),
EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable,
);
event.set_trusted(true);
// http://w3c.github.io/navigation-timing/#widl-PerformanceNavigationTiming-loadEventStart
update_with_current_time_ms(&document.load_event_start);
debug!("About to dispatch load for {:?}", document.url());
// FIXME(nox): Why are errors silenced here?
let _ = window.upcast::<EventTarget>().dispatch_event_with_target(
document.upcast(),
&event,
);
// http://w3c.github.io/navigation-timing/#widl-PerformanceNavigationTiming-loadEventEnd
update_with_current_time_ms(&document.load_event_end);
window.reflow(
ReflowGoal::ForDisplay,
ReflowQueryType::NoQuery,
ReflowReason::DocumentLoaded,
);
document.notify_constellation_load();
if let Some(fragment) = document.url().fragment() {
document.check_and_scroll_fragment(fragment);
}
}),
self.window.upcast(),
).unwrap();
// Step 8.
// TODO: pageshow event.
@ -3971,66 +4019,6 @@ pub fn determine_policy_for_token(token: &str) -> Option<ReferrerPolicy> {
}
}
pub struct DocumentProgressHandler {
addr: Trusted<Document>
}
impl DocumentProgressHandler {
pub fn new(addr: Trusted<Document>) -> DocumentProgressHandler {
DocumentProgressHandler {
addr: addr
}
}
fn set_ready_state_complete(&self) {
let document = self.addr.root();
document.set_ready_state(DocumentReadyState::Complete);
}
fn dispatch_load(&self) {
let document = self.addr.root();
if document.browsing_context().is_none() {
return;
}
let window = document.window();
let event = Event::new(window.upcast(),
atom!("load"),
EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable);
let wintarget = window.upcast::<EventTarget>();
event.set_trusted(true);
// http://w3c.github.io/navigation-timing/#widl-PerformanceNavigationTiming-loadEventStart
update_with_current_time_ms(&document.load_event_start);
debug!("About to dispatch load for {:?}", document.url());
let _ = wintarget.dispatch_event_with_target(document.upcast(), &event);
// http://w3c.github.io/navigation-timing/#widl-PerformanceNavigationTiming-loadEventEnd
update_with_current_time_ms(&document.load_event_end);
window.reflow(ReflowGoal::ForDisplay,
ReflowQueryType::NoQuery,
ReflowReason::DocumentLoaded);
document.notify_constellation_load();
}
}
impl Task for DocumentProgressHandler {
fn run(self: Box<Self>) {
let document = self.addr.root();
let window = document.window();
if window.is_alive() {
self.set_ready_state_complete();
self.dispatch_load();
if let Some(fragment) = document.url().fragment() {
document.check_and_scroll_fragment(fragment);
}
}
}
}
/// Specifies the type of focus event that is sent to a pipeline
#[derive(Clone, Copy, PartialEq)]
pub enum FocusType {