@@ -156,6 +156,9 @@ pub struct BaseDocument {
156
156
157
157
pub changed : HashSet < usize > ,
158
158
159
+ // All image nodes.
160
+ image_nodes : HashSet < usize > ,
161
+
159
162
/// A map from control node ID's to their associated forms node ID's
160
163
pub controls_to_form : HashMap < usize , usize > ,
161
164
@@ -248,6 +251,7 @@ impl BaseDocument {
248
251
active_node_id : None ,
249
252
mousedown_node_id : None ,
250
253
changed : HashSet :: new ( ) ,
254
+ image_nodes : HashSet :: new ( ) ,
251
255
controls_to_form : HashMap :: new ( ) ,
252
256
net_provider : Arc :: new ( DummyNetProvider ) ,
253
257
navigation_provider : Arc :: new ( DummyNavigationProvider ) ,
@@ -411,6 +415,11 @@ impl BaseDocument {
411
415
412
416
// Mark the new node as changed.
413
417
self . changed . insert ( id) ;
418
+
419
+ if self . is_img_node ( id) {
420
+ self . image_nodes . insert ( id) ;
421
+ }
422
+
414
423
id
415
424
}
416
425
@@ -505,6 +514,7 @@ impl BaseDocument {
505
514
pub fn remove_and_drop_node ( & mut self , node_id : usize ) -> Option < Node > {
506
515
fn remove_node_ignoring_parent ( doc : & mut BaseDocument , node_id : usize ) -> Option < Node > {
507
516
let node = doc. nodes . try_remove ( node_id) ;
517
+ doc. image_nodes . remove ( & node_id) ;
508
518
if let Some ( node) = & node {
509
519
for & child in & node. children {
510
520
remove_node_ignoring_parent ( doc, child) ;
@@ -622,10 +632,13 @@ impl BaseDocument {
622
632
623
633
match kind {
624
634
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,
628
640
) ) ) ;
641
+ }
629
642
630
643
// Clear layout cache
631
644
node. cache . clear ( ) ;
@@ -648,8 +661,11 @@ impl BaseDocument {
648
661
649
662
match kind {
650
663
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
+ }
653
669
654
670
// Clear layout cache
655
671
node. cache . clear ( ) ;
@@ -1033,6 +1049,7 @@ impl BaseDocument {
1033
1049
self . viewport = viewport;
1034
1050
self . set_stylist_device ( make_device ( & self . viewport ) ) ;
1035
1051
self . scroll_viewport_by ( 0.0 , 0.0 ) ; // Clamp scroll offset
1052
+ self . environment_changes ( ) ;
1036
1053
}
1037
1054
1038
1055
pub fn viewport ( & self ) -> & Viewport {
@@ -1285,6 +1302,9 @@ impl BaseDocument {
1285
1302
chain
1286
1303
}
1287
1304
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
+ ///
1288
1308
/// https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia
1289
1309
pub fn match_media ( & self , media_query_string : & str ) -> bool {
1290
1310
let mut input = cssparser:: ParserInput :: new ( media_query_string) ;
@@ -1310,6 +1330,13 @@ impl BaseDocument {
1310
1330
let media_list = MediaList :: parse ( & context, & mut parser) ;
1311
1331
media_list. evaluate ( self . stylist . device ( ) , quirks_mode)
1312
1332
}
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
+ }
1313
1340
}
1314
1341
1315
1342
impl AsRef < BaseDocument > for BaseDocument {
0 commit comments