Skip to content

Commit

Permalink
Reacting to environment changes
Browse files Browse the repository at this point in the history
  • Loading branch information
paavininanda committed Sep 11, 2018
1 parent 73459d5 commit 2de300d
Show file tree
Hide file tree
Showing 13 changed files with 308 additions and 1,935 deletions.
22 changes: 21 additions & 1 deletion components/script/dom/document.rs
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
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
@@ -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

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

0 comments on commit 2de300d

Please sign in to comment.