diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2018-03-06 10:49:51 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-06 10:49:51 -0500 |
commit | 94a6c2c429eb0415a277ff49fa19ae0eaefb0be9 (patch) | |
tree | 8100330dac45497bec2991cd48f864de469e26b5 /components/script/dom/document.rs | |
parent | f5037cf6219cafbc86bfaf6483b81b4ffb3496fa (diff) | |
parent | 3dd015b2d9a6c2e6652dfb438681bdd9a9f34fcb (diff) | |
download | servo-94a6c2c429eb0415a277ff49fa19ae0eaefb0be9.tar.gz servo-94a6c2c429eb0415a277ff49fa19ae0eaefb0be9.zip |
Auto merge of #20181 - fabricedesre:end-load-pageshow, r=jdm
Fire the pageshow event at the end of the page load
<!-- Please describe your changes on the following line: -->
This implements step 8 of https://html.spec.whatwg.org/multipage/parsing.html#the-end
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because I could not find a wpt test for that, which is strange. I likely missed it :(
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20181)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/document.rs')
-rw-r--r-- | components/script/dom/document.rs | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 7f3f40ea22c..49bc45b27c1 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -364,6 +364,8 @@ pub struct Document { canceller: FetchCanceller, /// https://html.spec.whatwg.org/multipage/#throw-on-dynamic-markup-insertion-counter throw_on_dynamic_markup_insertion_counter: Cell<u64>, + /// https://html.spec.whatwg.org/multipage/#page-showing + page_showing: Cell<bool>, } #[derive(JSTraceable, MallocSizeOf)] @@ -1634,7 +1636,37 @@ impl Document { ).unwrap(); // Step 8. - // TODO: pageshow event. + let document = Trusted::new(self); + if document.root().browsing_context().is_some() { + self.window.dom_manipulation_task_source().queue( + task!(fire_pageshow_event: move || { + let document = document.root(); + let window = document.window(); + if document.page_showing.get() || !window.is_alive() { + return; + } + + document.page_showing.set(true); + + let event = PageTransitionEvent::new( + window, + atom!("pageshow"), + false, // bubbles + false, // cancelable + false, // persisted + ); + let event = event.upcast::<Event>(); + event.set_trusted(true); + + // FIXME(nox): Why are errors silenced here? + let _ = window.upcast::<EventTarget>().dispatch_event_with_target( + document.upcast(), + &event, + ); + }), + self.window.upcast(), + ).unwrap(); + } // Step 9. // TODO: pending application cache download process tasks. @@ -2225,6 +2257,7 @@ impl Document { tti_window: DomRefCell::new(InteractiveWindow::new()), canceller: canceller, throw_on_dynamic_markup_insertion_counter: Cell::new(0), + page_showing: Cell::new(false), } } |