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
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Reacting to environment changes

  • Loading branch information
paavininanda committed Sep 11, 2018
commit 2de300d49cc90f6c2daf31e8ef8a7c0443eb0a94
@@ -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)]
@@ -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)]
@@ -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()
}
}

Large diffs are not rendered by default.

@@ -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.
@@ -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

@@ -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

@@ -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

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.