mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
auto merge of #801 : eschweic/servo/comp-fixed-pos, r=metajack
Some changes that need to happen for #782.
This commit is contained in:
commit
3f2969cfa8
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.
|
/// A monotonically increasing counter that keeps track of the current epoch.
|
||||||
/// add_buffer() calls that don't match the current epoch will be ignored.
|
/// add_buffer() calls that don't match the current epoch will be ignored.
|
||||||
epoch: Epoch,
|
epoch: Epoch,
|
||||||
|
/// The behavior of this layer when a scroll message is received.
|
||||||
|
scroll_behavior: ScrollBehavior,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper struct for keeping CompositorLayer children organized.
|
/// Helper struct for keeping CompositorLayer children organized.
|
||||||
|
@ -65,6 +67,16 @@ enum MaybeQuadtree {
|
||||||
NoTree(uint, Option<uint>),
|
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 {
|
impl CompositorLayer {
|
||||||
/// Creates a new CompositorLayer with an optional page size. If no page size is given,
|
/// 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.
|
/// the layer is initially hidden and initialized without a quadtree.
|
||||||
|
@ -85,6 +97,7 @@ impl CompositorLayer {
|
||||||
root_layer: @mut ContainerLayer(),
|
root_layer: @mut ContainerLayer(),
|
||||||
hidden: true,
|
hidden: true,
|
||||||
epoch: Epoch(0),
|
epoch: Epoch(0),
|
||||||
|
scroll_behavior: Scroll,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,29 +154,35 @@ impl CompositorLayer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scroll this layer!
|
// This scroll event is mine!
|
||||||
let old_origin = self.scroll_offset;
|
match self.scroll_behavior {
|
||||||
self.scroll_offset = self.scroll_offset + delta;
|
Scroll => {
|
||||||
|
// Scroll this layer!
|
||||||
// bounds checking
|
let old_origin = self.scroll_offset;
|
||||||
let page_size = match self.page_size {
|
self.scroll_offset = self.scroll_offset + delta;
|
||||||
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,
|
// bounds checking
|
||||||
self.scroll_offset.y,
|
let page_size = match self.page_size {
|
||||||
0.0));
|
Some(size) => size,
|
||||||
true
|
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
|
// Takes in a MouseWindowEvent, determines if it should be passed to children, and
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue