mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Initial compositor support for position:fixed elements
This commit is contained in:
parent
5647ca6966
commit
e84c127400
1 changed files with 41 additions and 22 deletions
|
@ -47,6 +47,8 @@ pub struct CompositorLayer {
|
|||
/// A monotonically increasing counter that keeps track of the current epoch.
|
||||
/// add_buffer() calls that don't match the current epoch will be ignored.
|
||||
epoch: Epoch,
|
||||
/// The behavior of this layer when a scroll message is received.
|
||||
scroll_behavior: ScrollBehavior,
|
||||
}
|
||||
|
||||
/// Helper struct for keeping CompositorLayer children organized.
|
||||
|
@ -65,6 +67,16 @@ enum MaybeQuadtree {
|
|||
NoTree(uint, Option<uint>),
|
||||
}
|
||||
|
||||
/// Determines the behavior of the layer when a scroll message is recieved.
|
||||
enum ScrollBehavior {
|
||||
/// Normal scrolling behavior.
|
||||
Scroll,
|
||||
/// Scrolling messages targeted at this layer are ignored, but can be
|
||||
/// passed on to child layers.
|
||||
FixedPosition,
|
||||
}
|
||||
|
||||
|
||||
impl CompositorLayer {
|
||||
/// Creates a new CompositorLayer with an optional page size. If no page size is given,
|
||||
/// the layer is initially hidden and initialized without a quadtree.
|
||||
|
@ -85,6 +97,7 @@ impl CompositorLayer {
|
|||
root_layer: @mut ContainerLayer(),
|
||||
hidden: true,
|
||||
epoch: Epoch(0),
|
||||
scroll_behavior: Scroll,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,29 +154,35 @@ impl CompositorLayer {
|
|||
}
|
||||
}
|
||||
|
||||
// Scroll this layer!
|
||||
let old_origin = self.scroll_offset;
|
||||
self.scroll_offset = self.scroll_offset + delta;
|
||||
|
||||
// bounds checking
|
||||
let page_size = match self.page_size {
|
||||
Some(size) => size,
|
||||
None => fail!("CompositorLayer: tried to scroll with no page size set"),
|
||||
};
|
||||
let min_x = (window_size.width - page_size.width).min(&0.0);
|
||||
self.scroll_offset.x = self.scroll_offset.x.clamp(&min_x, &0.0);
|
||||
let min_y = (window_size.height - page_size.height).min(&0.0);
|
||||
self.scroll_offset.y = self.scroll_offset.y.clamp(&min_y, &0.0);
|
||||
|
||||
// check to see if we scrolled
|
||||
if old_origin - self.scroll_offset == Point2D(0f32, 0f32) {
|
||||
return false;
|
||||
}
|
||||
// This scroll event is mine!
|
||||
match self.scroll_behavior {
|
||||
Scroll => {
|
||||
// Scroll this layer!
|
||||
let old_origin = self.scroll_offset;
|
||||
self.scroll_offset = self.scroll_offset + delta;
|
||||
|
||||
self.root_layer.common.set_transform(identity().translate(self.scroll_offset.x,
|
||||
self.scroll_offset.y,
|
||||
0.0));
|
||||
true
|
||||
// bounds checking
|
||||
let page_size = match self.page_size {
|
||||
Some(size) => size,
|
||||
None => fail!("CompositorLayer: tried to scroll with no page size set"),
|
||||
};
|
||||
let min_x = (window_size.width - page_size.width).min(&0.0);
|
||||
self.scroll_offset.x = self.scroll_offset.x.clamp(&min_x, &0.0);
|
||||
let min_y = (window_size.height - page_size.height).min(&0.0);
|
||||
self.scroll_offset.y = self.scroll_offset.y.clamp(&min_y, &0.0);
|
||||
|
||||
// check to see if we scrolled
|
||||
if old_origin - self.scroll_offset == Point2D(0f32, 0f32) {
|
||||
return false;
|
||||
}
|
||||
|
||||
self.root_layer.common.set_transform(identity().translate(self.scroll_offset.x,
|
||||
self.scroll_offset.y,
|
||||
0.0));
|
||||
true
|
||||
}
|
||||
FixedPosition => false, // Ignore this scroll event.
|
||||
}
|
||||
}
|
||||
|
||||
// Takes in a MouseWindowEvent, determines if it should be passed to children, and
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue