From aa7a52c05e572a6b425d5b9335bb6a9fbf66ff7c Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Thu, 21 Nov 2019 10:14:28 -0500 Subject: [PATCH] dom: Unindent Document::set_activity. --- components/script/dom/document.rs | 117 ++++++++++++++++-------------- 1 file changed, 62 insertions(+), 55 deletions(-) diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 5a344879005..a7a56665bf1 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -506,62 +506,69 @@ impl Document { pub fn set_activity(&self, activity: DocumentActivity) { // This function should only be called on documents with a browsing context assert!(self.has_browsing_context); - // Set the document's activity level, reflow if necessary, and suspend or resume timers. - if activity != self.activity.get() { - self.activity.set(activity); - let media = ServoMedia::get().unwrap(); - let pipeline_id = self.window().pipeline_id().expect("doc with no pipeline"); - let client_context_id = - ClientContextId::build(pipeline_id.namespace_id.0, pipeline_id.index.0.get()); - if activity == DocumentActivity::FullyActive { - self.title_changed(); - self.dirty_all_nodes(); - self.window() - .reflow(ReflowGoal::Full, ReflowReason::CachedPageNeededReflow); - self.window().resume(); - media.resume(&client_context_id); - // html.spec.whatwg.org/multipage/#history-traversal - // Step 4.6 - if self.ready_state.get() == DocumentReadyState::Complete { - let document = Trusted::new(self); - self.window - .task_manager() - .dom_manipulation_task_source() - .queue( - task!(fire_pageshow_event: move || { - let document = document.root(); - let window = document.window(); - // Step 4.6.1 - if document.page_showing.get() { - return; - } - // Step 4.6.2 - document.page_showing.set(true); - // Step 4.6.4 - let event = PageTransitionEvent::new( - window, - atom!("pageshow"), - false, // bubbles - false, // cancelable - true, // persisted - ); - let event = event.upcast::(); - event.set_trusted(true); - // FIXME(nox): Why are errors silenced here? - let _ = window.upcast::().dispatch_event_with_target( - document.upcast(), - &event, - ); - }), - self.window.upcast(), - ) - .unwrap(); - } - } else { - self.window().suspend(); - media.suspend(&client_context_id); - } + if activity == self.activity.get() { + return; } + + // Set the document's activity level, reflow if necessary, and suspend or resume timers. + self.activity.set(activity); + let media = ServoMedia::get().unwrap(); + let pipeline_id = self.window().pipeline_id().expect("doc with no pipeline"); + let client_context_id = + ClientContextId::build(pipeline_id.namespace_id.0, pipeline_id.index.0.get()); + + if activity != DocumentActivity::FullyActive { + self.window().suspend(); + media.suspend(&client_context_id); + return; + } + + self.title_changed(); + self.dirty_all_nodes(); + self.window() + .reflow(ReflowGoal::Full, ReflowReason::CachedPageNeededReflow); + self.window().resume(); + media.resume(&client_context_id); + + if self.ready_state.get() != DocumentReadyState::Complete { + return; + } + + // html.spec.whatwg.org/multipage/#history-traversal + // Step 4.6 + let document = Trusted::new(self); + self.window + .task_manager() + .dom_manipulation_task_source() + .queue( + task!(fire_pageshow_event: move || { + let document = document.root(); + let window = document.window(); + // Step 4.6.1 + if document.page_showing.get() { + return; + } + // Step 4.6.2 + document.page_showing.set(true); + // Step 4.6.4 + let event = PageTransitionEvent::new( + window, + atom!("pageshow"), + false, // bubbles + false, // cancelable + true, // persisted + ); + let event = event.upcast::(); + event.set_trusted(true); + // FIXME(nox): Why are errors silenced here? + let _ = window.upcast::().dispatch_event_with_target( + document.upcast(), + &event, + ); + }), + self.window.upcast(), + ) + .unwrap(); } pub fn origin(&self) -> &MutableOrigin {