Auto merge of #21280 - paavininanda:Update_the_image_data, r=jdm

Reacting to environment changes

<!-- Please describe your changes on the following line: -->

---
<!-- 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
- [x] These changes fix a subset of #11416

<!-- Either: -->
- [x] These changes do not require tests because they will be added when the complete responsive images is complete

<!-- 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/21280)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-09-12 10:47:13 -04:00 committed by GitHub
commit 9a83ab6297
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 308 additions and 1935 deletions

View file

@ -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()
}
}