auto merge of #801 : eschweic/servo/comp-fixed-pos, r=metajack

Some changes that need to happen for #782.
This commit is contained in:
bors-servo 2013-08-27 15:09:58 -07:00
commit 3f2969cfa8

View file

@ -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!
let old_origin = self.scroll_offset;
self.scroll_offset = self.scroll_offset + delta;
// bounds checking // bounds checking
let page_size = match self.page_size { let page_size = match self.page_size {
Some(size) => size, Some(size) => size,
None => fail!("CompositorLayer: tried to scroll with no page size set"), None => fail!("CompositorLayer: tried to scroll with no page size set"),
}; };
let min_x = (window_size.width - page_size.width).min(&0.0); 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); 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); 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); self.scroll_offset.y = self.scroll_offset.y.clamp(&min_y, &0.0);
// check to see if we scrolled // check to see if we scrolled
if old_origin - self.scroll_offset == Point2D(0f32, 0f32) { if old_origin - self.scroll_offset == Point2D(0f32, 0f32) {
return false; 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.
} }
self.root_layer.common.set_transform(identity().translate(self.scroll_offset.x,
self.scroll_offset.y,
0.0));
true
} }
// 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