@@ -149,6 +149,9 @@ pub struct BaseDocument {
149149
150150 pub changed : HashSet < usize > ,
151151
152+ // All image nodes.
153+ image_nodes : HashSet < usize > ,
154+
152155 /// A map from control node ID's to their associated forms node ID's
153156 pub controls_to_form : HashMap < usize , usize > ,
154157
@@ -237,6 +240,7 @@ impl BaseDocument {
237240 focus_node_id : None ,
238241 active_node_id : None ,
239242 changed : HashSet :: new ( ) ,
243+ image_nodes : HashSet :: new ( ) ,
240244 controls_to_form : HashMap :: new ( ) ,
241245 net_provider : Arc :: new ( DummyNetProvider ) ,
242246 navigation_provider : Arc :: new ( DummyNavigationProvider { } ) ,
@@ -395,6 +399,11 @@ impl BaseDocument {
395399
396400 // Mark the new node as changed.
397401 self . changed . insert ( id) ;
402+
403+ if self . is_img_node ( id) {
404+ self . image_nodes . insert ( id) ;
405+ }
406+
398407 id
399408 }
400409
@@ -489,6 +498,7 @@ impl BaseDocument {
489498 pub fn remove_and_drop_node ( & mut self , node_id : usize ) -> Option < Node > {
490499 fn remove_node_ignoring_parent ( doc : & mut BaseDocument , node_id : usize ) -> Option < Node > {
491500 let node = doc. nodes . try_remove ( node_id) ;
501+ doc. image_nodes . remove ( & node_id) ;
492502 if let Some ( node) = & node {
493503 for & child in & node. children {
494504 remove_node_ignoring_parent ( doc, child) ;
@@ -606,10 +616,13 @@ impl BaseDocument {
606616
607617 match kind {
608618 ImageType :: Image => {
609- node. element_data_mut ( ) . unwrap ( ) . node_specific_data =
610- NodeSpecificData :: Image ( Box :: new ( ImageData :: Raster (
611- RasterImageData :: new ( width, height, image_data) ,
619+ if let NodeSpecificData :: Image ( context) =
620+ & mut node. element_data_mut ( ) . unwrap ( ) . node_specific_data
621+ {
622+ context. data = Some ( ImageData :: Raster ( RasterImageData :: new (
623+ width, height, image_data,
612624 ) ) ) ;
625+ }
613626
614627 // Clear layout cache
615628 node. cache . clear ( ) ;
@@ -632,8 +645,11 @@ impl BaseDocument {
632645
633646 match kind {
634647 ImageType :: Image => {
635- node. element_data_mut ( ) . unwrap ( ) . node_specific_data =
636- NodeSpecificData :: Image ( Box :: new ( ImageData :: Svg ( tree) ) ) ;
648+ if let NodeSpecificData :: Image ( context) =
649+ & mut node. element_data_mut ( ) . unwrap ( ) . node_specific_data
650+ {
651+ context. data = Some ( ImageData :: Svg ( tree) ) ;
652+ }
637653
638654 // Clear layout cache
639655 node. cache . clear ( ) ;
@@ -1006,6 +1022,7 @@ impl BaseDocument {
10061022 pub fn set_viewport ( & mut self , viewport : Viewport ) {
10071023 self . viewport = viewport;
10081024 self . set_stylist_device ( make_device ( & self . viewport ) ) ;
1025+ self . environment_changes ( ) ;
10091026 }
10101027
10111028 pub fn get_viewport ( & self ) -> Viewport {
@@ -1230,6 +1247,9 @@ impl BaseDocument {
12301247 chain
12311248 }
12321249
1250+ /// Used to determine whether a document matches a media query string,
1251+ /// and to monitor a document to detect when it matches (or stops matching) that media query.
1252+ ///
12331253 /// https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia
12341254 pub fn match_media ( & self , media_query_string : & str ) -> bool {
12351255 let mut input = cssparser:: ParserInput :: new ( media_query_string) ;
@@ -1255,6 +1275,13 @@ impl BaseDocument {
12551275 let media_list = MediaList :: parse ( & context, & mut parser) ;
12561276 media_list. evaluate ( self . stylist . device ( ) , quirks_mode)
12571277 }
1278+
1279+ fn environment_changes ( & mut self ) {
1280+ let image_nodes = self . image_nodes . clone ( ) ;
1281+ for node_id in image_nodes. into_iter ( ) {
1282+ self . environment_changes_with_image ( node_id) ;
1283+ }
1284+ }
12581285}
12591286
12601287impl AsRef < BaseDocument > for BaseDocument {
0 commit comments