aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2017-09-17 17:30:48 +0200
committerAnthony Ramine <n.oxyde@gmail.com>2017-09-18 02:47:07 +0200
commite9f6ea40c25758976e030872879c44726b7b97f2 (patch)
tree65a67b63515818e85b05ac409242f2d5a57b93d5
parent5412767f466861a9b0ad08b3a65744c3f3b17e09 (diff)
downloadservo-e9f6ea40c25758976e030872879c44726b7b97f2.tar.gz
servo-e9f6ea40c25758976e030872879c44726b7b97f2.zip
Use task! instead of DocumentProgressHandler
-rw-r--r--components/script/dom/document.rs114
1 files changed, 51 insertions, 63 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index 90853a28e7f..0d180ca9934 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -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 {