Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reacting to environment changes #21280

Merged
merged 1 commit into from
Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 21 additions & 1 deletion components/script/dom/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ pub struct Document {
salvageable: Cell<bool>,
/// Whether the unload event has already been fired.
fired_unload: Cell<bool>,
/// List of responsive images
responsive_images: DomRefCell<Vec<Dom<HTMLImageElement>>>,
}

#[derive(JSTraceable, MallocSizeOf)]
Expand Down Expand Up @@ -2221,6 +2223,23 @@ impl Document {
let counter = self.throw_on_dynamic_markup_insertion_counter.get();
self.throw_on_dynamic_markup_insertion_counter.set(counter - 1);
}

pub fn react_to_environment_changes(&self) {
for image in self.responsive_images.borrow().iter() {
image.react_to_environment_changes();
}
}

pub fn register_responsive_image(&self, img: &HTMLImageElement) {
self.responsive_images.borrow_mut().push(Dom::from_ref(img));
}

pub fn unregister_responsive_image(&self, img: &HTMLImageElement) {
let index = self.responsive_images.borrow().iter().position(|x| **x == *img);
if let Some(i) = index {
self.responsive_images.borrow_mut().remove(i);
}
}
}

#[derive(MallocSizeOf, PartialEq)]
Expand Down Expand Up @@ -2465,7 +2484,8 @@ impl Document {
throw_on_dynamic_markup_insertion_counter: Cell::new(0),
page_showing: Cell::new(false),
salvageable: Cell::new(true),
fired_unload: Cell::new(false)
fired_unload: Cell::new(false),
responsive_images: Default::default()
}
}

Expand Down
297 changes: 279 additions & 18 deletions components/script/dom/htmlimageelement.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions components/script/dom/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1853,6 +1853,7 @@ impl Window {
mql.Matches());
event.upcast::<Event>().fire(mql.upcast::<EventTarget>());
}
self.Document().react_to_environment_changes();
}

/// Slow down/speed up timers based on visibility.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
[basic.html]
type: testharness
[<img srcset="/images/green-256x256.png 1x" data-expect="256">]
expected: FAIL

[<img srcset="/images/green-256x256.png 1.6x" data-expect="160">]
expected: FAIL

[<img srcset="/images/green-256x256.png 2x" data-expect="128">]
expected: FAIL

[<img srcset="/images/green-256x256.png 256w" sizes="256px" data-expect="256">]
expected: FAIL

[<img srcset="/images/green-256x256.png 512w" sizes="256px" data-expect="128">]
expected: FAIL

Expand All @@ -30,3 +24,9 @@
[<img srcset="data:image/svg+xml,<svg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='-1%20-1%202%202'%20height='20'><circle%20r='1'/></svg> 2x" data-expect="10">]
expected: FAIL

[<img srcset="/images/green-256x256.png 10000x" data-expect="0">]
expected: FAIL

[<img srcset="/images/green-256x256.png 256w" sizes="0px" data-expect="0">]
expected: FAIL

Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
[viewport-change.html]
type: testharness
expected: TIMEOUT
[img (srcset 1 cand) broken image, onload, narrow]
expected: FAIL

[img (srcset 1 cand) valid image, onload, narrow]
expected: FAIL

[picture: source (max-width:500px) broken image, img valid image, resize to wide]
expected: TIMEOUT

[picture: source (max-width:500px) valid image, img valid image, resize to wide]
expected: TIMEOUT

[img (srcset 1 cand) broken image, onload, wide]
expected: FAIL

[img (srcset 1 cand) valid image, onload, wide]
expected: FAIL

[picture: source (max-width:500px) valid image, img broken image, resize to narrow]
expected: TIMEOUT

Expand Down