@@ -156,6 +156,9 @@ pub struct BaseDocument {
156156
157157 pub changed : HashSet < usize > ,
158158
159+ // All image nodes.
160+ image_nodes : HashSet < usize > ,
161+
159162 /// A map from control node ID's to their associated forms node ID's
160163 pub controls_to_form : HashMap < usize , usize > ,
161164
@@ -248,6 +251,7 @@ impl BaseDocument {
248251 active_node_id : None ,
249252 mousedown_node_id : None ,
250253 changed : HashSet :: new ( ) ,
254+ image_nodes : HashSet :: new ( ) ,
251255 controls_to_form : HashMap :: new ( ) ,
252256 net_provider : Arc :: new ( DummyNetProvider ) ,
253257 navigation_provider : Arc :: new ( DummyNavigationProvider ) ,
@@ -411,6 +415,11 @@ impl BaseDocument {
411415
412416 // Mark the new node as changed.
413417 self . changed . insert ( id) ;
418+
419+ if self . is_img_node ( id) {
420+ self . image_nodes . insert ( id) ;
421+ }
422+
414423 id
415424 }
416425
@@ -505,6 +514,7 @@ impl BaseDocument {
505514 pub fn remove_and_drop_node ( & mut self , node_id : usize ) -> Option < Node > {
506515 fn remove_node_ignoring_parent ( doc : & mut BaseDocument , node_id : usize ) -> Option < Node > {
507516 let node = doc. nodes . try_remove ( node_id) ;
517+ doc. image_nodes . remove ( & node_id) ;
508518 if let Some ( node) = & node {
509519 for & child in & node. children {
510520 remove_node_ignoring_parent ( doc, child) ;
@@ -622,10 +632,13 @@ impl BaseDocument {
622632
623633 match kind {
624634 ImageType :: Image => {
625- node. element_data_mut ( ) . unwrap ( ) . node_specific_data =
626- NodeSpecificData :: Image ( Box :: new ( ImageData :: Raster (
627- RasterImageData :: new ( width, height, image_data) ,
635+ if let NodeSpecificData :: Image ( context) =
636+ & mut node. element_data_mut ( ) . unwrap ( ) . node_specific_data
637+ {
638+ context. data = Some ( ImageData :: Raster ( RasterImageData :: new (
639+ width, height, image_data,
628640 ) ) ) ;
641+ }
629642
630643 // Clear layout cache
631644 node. cache . clear ( ) ;
@@ -648,8 +661,11 @@ impl BaseDocument {
648661
649662 match kind {
650663 ImageType :: Image => {
651- node. element_data_mut ( ) . unwrap ( ) . node_specific_data =
652- NodeSpecificData :: Image ( Box :: new ( ImageData :: Svg ( tree) ) ) ;
664+ if let NodeSpecificData :: Image ( context) =
665+ & mut node. element_data_mut ( ) . unwrap ( ) . node_specific_data
666+ {
667+ context. data = Some ( ImageData :: Svg ( tree) ) ;
668+ }
653669
654670 // Clear layout cache
655671 node. cache . clear ( ) ;
@@ -1033,6 +1049,7 @@ impl BaseDocument {
10331049 self . viewport = viewport;
10341050 self . set_stylist_device ( make_device ( & self . viewport ) ) ;
10351051 self . scroll_viewport_by ( 0.0 , 0.0 ) ; // Clamp scroll offset
1052+ self . environment_changes ( ) ;
10361053 }
10371054
10381055 pub fn viewport ( & self ) -> & Viewport {
@@ -1285,6 +1302,9 @@ impl BaseDocument {
12851302 chain
12861303 }
12871304
1305+ /// Used to determine whether a document matches a media query string,
1306+ /// and to monitor a document to detect when it matches (or stops matching) that media query.
1307+ ///
12881308 /// https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia
12891309 pub fn match_media ( & self , media_query_string : & str ) -> bool {
12901310 let mut input = cssparser:: ParserInput :: new ( media_query_string) ;
@@ -1310,6 +1330,13 @@ impl BaseDocument {
13101330 let media_list = MediaList :: parse ( & context, & mut parser) ;
13111331 media_list. evaluate ( self . stylist . device ( ) , quirks_mode)
13121332 }
1333+
1334+ fn environment_changes ( & mut self ) {
1335+ let image_nodes = self . image_nodes . clone ( ) ;
1336+ for node_id in image_nodes. into_iter ( ) {
1337+ self . environment_changes_with_image ( node_id) ;
1338+ }
1339+ }
13131340}
13141341
13151342impl AsRef < BaseDocument > for BaseDocument {
0 commit comments