Don't let base layers override root layer size

Base layers (the background layer of each frame) shouldn't override the
size of their root layers. This allows base layers to scroll inside
root layer frames. This does mean that when determining the maximum
scroll position, we need to look at the size of scrolling root children
though.
This commit is contained in:
Martin Robinson 2014-09-23 16:46:13 -07:00
parent e01c5cd863
commit f346a215f3
3 changed files with 17 additions and 4 deletions

View file

@ -500,7 +500,7 @@ impl IOCompositor {
let need_new_root_layer = !self.update_layer_if_exists(layer_properties);
if need_new_root_layer {
let root_layer = self.find_pipeline_root_layer(layer_properties.pipeline_id);
CompositorData::update_layer(root_layer.clone(), layer_properties);
CompositorData::update_layer_except_size(root_layer.clone(), layer_properties);
let root_layer_pipeline = root_layer.extra_data.borrow().pipeline.clone();
let first_child = CompositorData::new_layer(root_layer_pipeline.clone(),

View file

@ -72,14 +72,17 @@ impl CompositorData {
tile_size, new_compositor_data))
}
pub fn update_layer(layer: Rc<Layer<CompositorData>>, layer_properties: LayerProperties) {
pub fn update_layer_except_size(layer: Rc<Layer<CompositorData>>,
layer_properties: LayerProperties) {
layer.extra_data.borrow_mut().epoch = layer_properties.epoch;
layer.extra_data.borrow_mut().scroll_policy = layer_properties.scroll_policy;
layer.extra_data.borrow_mut().background_color = layer_properties.background_color;
layer.contents_changed();
}
pub fn update_layer(layer: Rc<Layer<CompositorData>>, layer_properties: LayerProperties) {
let size: TypedSize2D<DevicePixel, f32> = Size2D::from_untyped(&layer_properties.rect.size);
layer.resize(size);
layer.contents_changed();
// Call scroll for bounds checking if the page shrunk. Use (-1, -1) as the
// cursor position to make sure the scroll isn't propagated downwards. The
@ -89,6 +92,7 @@ impl CompositorData {
TypedPoint2D(-1f32, -1f32),
size,
ScaleFactor(1.0) /* scene_scale */);
CompositorData::update_layer_except_size(layer, layer_properties);
}
pub fn find_layer_with_pipeline_and_layer_id(layer: Rc<Layer<CompositorData>>,

View file

@ -8,6 +8,7 @@ use windowing::MouseWindowMouseUpEvent;
use geom::length::Length;
use geom::point::{Point2D, TypedPoint2D};
use geom::rect::Rect;
use geom::scale_factor::ScaleFactor;
use geom::size::TypedSize2D;
use layers::geometry::DevicePixel;
@ -86,12 +87,20 @@ pub fn handle_scroll_event(layer: Rc<Layer<CompositorData>>,
scale)
}
pub fn calculate_content_size_for_layer(layer: Rc<Layer<CompositorData>>)
-> TypedSize2D<DevicePixel, f32> {
layer.children().iter().fold(Rect::zero(),
|unioned_rect, child_rect| {
unioned_rect.union(&*child_rect.bounds.borrow())
}).size
}
pub fn clamp_scroll_offset_and_scroll_layer(layer: Rc<Layer<CompositorData>>,
new_offset: TypedPoint2D<DevicePixel, f32>,
window_size: TypedSize2D<DevicePixel, f32>,
scale: ScaleFactor<PagePx, DevicePixel, f32>)
-> ScrollEventResult {
let layer_size = layer.bounds.borrow().size;
let layer_size = calculate_content_size_for_layer(layer.clone());
let min_x = (window_size.width - layer_size.width).get().min(0.0);
let min_y = (window_size.height - layer_size.height).get().min(0.0);
let new_offset : TypedPoint2D<DevicePixel, f32> =