Skip to content

Commit

Permalink
Initial compositor support for position:fixed elements
Browse files Browse the repository at this point in the history
  • Loading branch information
eschweic committed Aug 27, 2013
1 parent 5647ca6 commit e84c127
Showing 1 changed file with 41 additions and 22 deletions.
63 changes: 41 additions & 22 deletions src/components/main/compositing/compositor_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -85,6 +97,7 @@ impl CompositorLayer {
root_layer: @mut ContainerLayer(),
hidden: true,
epoch: Epoch(0),
scroll_behavior: Scroll,
}
}

Expand Down Expand Up @@ -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
Expand Down

5 comments on commit e84c127

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from metajack
at eschweic@e84c127

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging eschweic/servo/comp-fixed-pos = e84c127 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eschweic/servo/comp-fixed-pos = e84c127 merged ok, testing candidate = 3f2969c

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 3f2969c

Please sign in to comment.