@@ -21,7 +21,7 @@ use webrender_traits::{AuxiliaryLists, PipelineId, Epoch, ScrollPolicy, ScrollLa
21
21
use webrender_traits:: { ClipRegion , ColorF , DisplayItem , StackingContext , FilterOp , MixBlendMode } ;
22
22
use webrender_traits:: { ScrollEventPhase , ScrollLayerInfo , SpecificDisplayItem , ScrollLayerState } ;
23
23
use webrender_traits:: { LayerRect , LayerPoint , LayerSize } ;
24
- use webrender_traits:: { ScrollLayerRect , as_scroll_parent_rect, ScrollLayerPixel } ;
24
+ use webrender_traits:: { ServoScrollRootId , ScrollLayerRect , as_scroll_parent_rect, ScrollLayerPixel } ;
25
25
use webrender_traits:: WorldPoint4D ;
26
26
use webrender_traits:: { LayerTransform , LayerToScrollTransform , ScrollToWorldTransform } ;
27
27
@@ -52,6 +52,7 @@ pub struct Frame {
52
52
AuxiliaryLists ,
53
53
BuildHasherDefault < FnvHasher > > ,
54
54
pub root_scroll_layer_id : Option < ScrollLayerId > ,
55
+ pending_scroll_offsets : HashMap < PipelineId , HashMap < ServoScrollRootId , LayerPoint > > ,
55
56
id : FrameId ,
56
57
debug : bool ,
57
58
frame_builder_config : FrameBuilderConfig ,
@@ -210,6 +211,7 @@ impl Frame {
210
211
pipeline_auxiliary_lists : HashMap :: with_hasher ( Default :: default ( ) ) ,
211
212
layers : HashMap :: with_hasher ( Default :: default ( ) ) ,
212
213
root_scroll_layer_id : None ,
214
+ pending_scroll_offsets : HashMap :: new ( ) ,
213
215
id : FrameId ( 0 ) ,
214
216
debug : debug,
215
217
frame_builder : None ,
@@ -295,6 +297,40 @@ impl Frame {
295
297
result
296
298
}
297
299
300
+ /// Returns true if any layers actually changed position or false otherwise.
301
+ pub fn scroll_layers ( & mut self ,
302
+ origin : Point2D < f32 > ,
303
+ pipeline_id : PipelineId ,
304
+ scroll_root_id : ServoScrollRootId )
305
+ -> bool {
306
+ let origin = LayerPoint :: new ( origin. x . max ( 0.0 ) , origin. y . max ( 0.0 ) ) ;
307
+
308
+ let mut scrolled_a_layer = false ;
309
+ let mut found_layer = false ;
310
+ for ( layer_id, layer) in self . layers . iter_mut ( ) {
311
+ if layer_id. pipeline_id != pipeline_id {
312
+ continue ;
313
+ }
314
+
315
+ match layer_id. info {
316
+ ScrollLayerInfo :: Scrollable ( _, id) if id != scroll_root_id => continue ,
317
+ ScrollLayerInfo :: Fixed => continue ,
318
+ _ => { }
319
+ }
320
+
321
+ found_layer = true ;
322
+ scrolled_a_layer |= layer. set_scroll_origin ( & origin) ;
323
+ }
324
+
325
+ if !found_layer {
326
+ let scroll_offsets =
327
+ self . pending_scroll_offsets . entry ( pipeline_id) . or_insert_with ( HashMap :: new) ;
328
+ scroll_offsets. insert ( scroll_root_id, origin) ;
329
+ }
330
+
331
+ scrolled_a_layer
332
+ }
333
+
298
334
/// Returns true if any layers actually changed position or false otherwise.
299
335
pub fn scroll ( & mut self ,
300
336
mut delta : Point2D < f32 > ,
@@ -480,6 +516,19 @@ impl Frame {
480
516
} ;
481
517
482
518
layer. finalize ( & scrolling_state) ;
519
+
520
+ let scroll_root_id = match scroll_layer_id. info {
521
+ ScrollLayerInfo :: Scrollable ( _, scroll_root_id) => scroll_root_id,
522
+ _ => continue ,
523
+ } ;
524
+
525
+
526
+ let pipeline_id = scroll_layer_id. pipeline_id ;
527
+ if let Some ( pending_offsets) = self . pending_scroll_offsets . get_mut ( & pipeline_id) {
528
+ if let Some ( ref offset) = pending_offsets. remove ( & scroll_root_id) {
529
+ layer. set_scroll_origin ( offset) ;
530
+ }
531
+ }
483
532
}
484
533
}
485
534
0 commit comments