@@ -149,6 +149,9 @@ pub struct BaseDocument {
149
149
150
150
pub changed : HashSet < usize > ,
151
151
152
+ // All image nodes.
153
+ image_nodes : HashSet < usize > ,
154
+
152
155
/// A map from control node ID's to their associated forms node ID's
153
156
pub controls_to_form : HashMap < usize , usize > ,
154
157
@@ -237,6 +240,7 @@ impl BaseDocument {
237
240
focus_node_id : None ,
238
241
active_node_id : None ,
239
242
changed : HashSet :: new ( ) ,
243
+ image_nodes : HashSet :: new ( ) ,
240
244
controls_to_form : HashMap :: new ( ) ,
241
245
net_provider : Arc :: new ( DummyNetProvider ) ,
242
246
navigation_provider : Arc :: new ( DummyNavigationProvider { } ) ,
@@ -395,6 +399,11 @@ impl BaseDocument {
395
399
396
400
// Mark the new node as changed.
397
401
self . changed . insert ( id) ;
402
+
403
+ if self . is_img_node ( id) {
404
+ self . image_nodes . insert ( id) ;
405
+ }
406
+
398
407
id
399
408
}
400
409
@@ -489,6 +498,7 @@ impl BaseDocument {
489
498
pub fn remove_and_drop_node ( & mut self , node_id : usize ) -> Option < Node > {
490
499
fn remove_node_ignoring_parent ( doc : & mut BaseDocument , node_id : usize ) -> Option < Node > {
491
500
let node = doc. nodes . try_remove ( node_id) ;
501
+ doc. image_nodes . remove ( & node_id) ;
492
502
if let Some ( node) = & node {
493
503
for & child in & node. children {
494
504
remove_node_ignoring_parent ( doc, child) ;
@@ -606,10 +616,13 @@ impl BaseDocument {
606
616
607
617
match kind {
608
618
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,
612
624
) ) ) ;
625
+ }
613
626
614
627
// Clear layout cache
615
628
node. cache . clear ( ) ;
@@ -632,8 +645,11 @@ impl BaseDocument {
632
645
633
646
match kind {
634
647
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
+ }
637
653
638
654
// Clear layout cache
639
655
node. cache . clear ( ) ;
@@ -1006,6 +1022,7 @@ impl BaseDocument {
1006
1022
pub fn set_viewport ( & mut self , viewport : Viewport ) {
1007
1023
self . viewport = viewport;
1008
1024
self . set_stylist_device ( make_device ( & self . viewport ) ) ;
1025
+ self . environment_changes ( ) ;
1009
1026
}
1010
1027
1011
1028
pub fn get_viewport ( & self ) -> Viewport {
@@ -1230,6 +1247,9 @@ impl BaseDocument {
1230
1247
chain
1231
1248
}
1232
1249
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
+ ///
1233
1253
/// https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia
1234
1254
pub fn match_media ( & self , media_query_string : & str ) -> bool {
1235
1255
let mut input = cssparser:: ParserInput :: new ( media_query_string) ;
@@ -1255,6 +1275,13 @@ impl BaseDocument {
1255
1275
let media_list = MediaList :: parse ( & context, & mut parser) ;
1256
1276
media_list. evaluate ( self . stylist . device ( ) , quirks_mode)
1257
1277
}
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
+ }
1258
1285
}
1259
1286
1260
1287
impl AsRef < BaseDocument > for BaseDocument {
0 commit comments