aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/document.rs
diff options
context:
space:
mode:
authorpaavininanda <paavininanda@gmail.com>2018-07-22 15:48:43 +0530
committerpaavininanda <paavininanda@gmail.com>2018-09-12 02:11:13 +0530
commit2de300d49cc90f6c2daf31e8ef8a7c0443eb0a94 (patch)
treedf3f168156609081dd8c8c429e13dbf31f787b91 /components/script/dom/document.rs
parent73459d5b3608cc9d6a9fcd97a45ecca687bf219f (diff)
downloadservo-2de300d49cc90f6c2daf31e8ef8a7c0443eb0a94.tar.gz
servo-2de300d49cc90f6c2daf31e8ef8a7c0443eb0a94.zip
Reacting to environment changes
Diffstat (limited to 'components/script/dom/document.rs')
-rw-r--r--components/script/dom/document.rs22
1 files changed, 21 insertions, 1 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index 5394089d220..61b1ddc41da 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -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()
}
}