mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Remove ad-hoc recursion from add_child_if_necessary
This commit is contained in:
parent
4c0f8c8ac0
commit
c0b599f894
2 changed files with 30 additions and 38 deletions
|
@ -404,13 +404,20 @@ impl IOCompositor {
|
|||
new_root.extra_data.borrow_mut().unrendered_color = unrendered_color;
|
||||
|
||||
let parent_layer_id = new_root.extra_data.borrow().id;
|
||||
assert!(CompositorData::add_child_if_necessary(new_root.clone(),
|
||||
root_pipeline_id,
|
||||
parent_layer_id,
|
||||
match CompositorData::find_layer_with_layer_and_pipeline_id(new_root.clone(),
|
||||
root_pipeline_id,
|
||||
parent_layer_id) {
|
||||
Some(ref mut parent_layer) => {
|
||||
CompositorData::add_child_if_necessary(parent_layer.clone(),
|
||||
layer_id,
|
||||
Rect(Point2D(0f32, 0f32), size),
|
||||
size,
|
||||
Scrollable));
|
||||
Scrollable);
|
||||
}
|
||||
None => {
|
||||
fail!("Compositor: couldn't find parent layer");
|
||||
}
|
||||
}
|
||||
|
||||
// Release all tiles from the layer before dropping it.
|
||||
match self.scene.root {
|
||||
|
@ -429,19 +436,26 @@ impl IOCompositor {
|
|||
rect: Rect<f32>,
|
||||
scroll_policy: ScrollPolicy) {
|
||||
match self.scene.root {
|
||||
Some(ref root) => {
|
||||
let parent_layer_id = root.extra_data.borrow().id;
|
||||
let page_size = root.extra_data.borrow().page_size.unwrap();
|
||||
assert!(CompositorData::add_child_if_necessary(root.clone(),
|
||||
pipeline_id,
|
||||
parent_layer_id,
|
||||
Some(ref root_layer) => {
|
||||
let parent_layer_id = root_layer.extra_data.borrow().id;
|
||||
match CompositorData::find_layer_with_pipeline_and_layer_id(root_layer.clone(),
|
||||
pipeline_id,
|
||||
parent_layer_id) {
|
||||
Some(ref mut parent_layer) => {
|
||||
let page_size = root_layer.extra_data.borrow().page_size.unwrap();
|
||||
CompositorData::add_child_if_necessary(parent_layer.clone(),
|
||||
layer_id,
|
||||
rect,
|
||||
page_size,
|
||||
scroll_policy))
|
||||
scroll_policy);
|
||||
}
|
||||
None => {
|
||||
fail!("Compositor: couldn't find parent layer");
|
||||
}
|
||||
}
|
||||
}
|
||||
None => fail!("Compositor: Received new layer without initialized pipeline"),
|
||||
};
|
||||
None => fail!("Compositor: Received new layer without initialized pipeline")
|
||||
}
|
||||
|
||||
self.ask_for_tiles();
|
||||
}
|
||||
|
|
|
@ -146,38 +146,18 @@ impl CompositorData {
|
|||
/// Adds a child layer to the layer with the given ID and the given pipeline, if it doesn't
|
||||
/// exist yet. The child layer will have the same pipeline, tile size, memory limit, and CPU
|
||||
/// painting status as its parent.
|
||||
///
|
||||
/// Returns:
|
||||
/// * True if the layer was added;
|
||||
/// * True if the layer was not added because it already existed;
|
||||
/// * False if the layer could not be added because no suitable parent layer with the given
|
||||
/// ID and pipeline could be found.
|
||||
pub fn add_child_if_necessary(layer: Rc<Layer<CompositorData>>,
|
||||
pipeline_id: PipelineId,
|
||||
parent_layer_id: LayerId,
|
||||
child_layer_id: LayerId,
|
||||
rect: Rect<f32>,
|
||||
page_size: Size2D<f32>,
|
||||
scroll_policy: ScrollPolicy) -> bool {
|
||||
if layer.extra_data.borrow().pipeline.id != pipeline_id ||
|
||||
layer.extra_data.borrow().id != parent_layer_id {
|
||||
return layer.children().iter().any(|kid| {
|
||||
CompositorData::add_child_if_necessary(kid.clone(),
|
||||
pipeline_id,
|
||||
parent_layer_id,
|
||||
child_layer_id,
|
||||
rect,
|
||||
page_size,
|
||||
scroll_policy)
|
||||
})
|
||||
}
|
||||
|
||||
scroll_policy: ScrollPolicy) {
|
||||
// See if we've already made this child layer.
|
||||
let pipeline_id = layer.extra_data.borrow().pipeline.id;
|
||||
if layer.children().iter().any(|kid| {
|
||||
kid.extra_data.borrow().pipeline.id == pipeline_id &&
|
||||
kid.extra_data.borrow().id == child_layer_id
|
||||
}) {
|
||||
return true
|
||||
return;
|
||||
}
|
||||
|
||||
let new_compositor_data = CompositorData::new(layer.extra_data.borrow().pipeline.clone(),
|
||||
|
@ -197,8 +177,6 @@ impl CompositorData {
|
|||
|
||||
// Place the kid's layer in the container passed in.
|
||||
Layer::add_child(layer.clone(), new_kid.clone());
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
/// Move the layer's descendants that don't want scroll events and scroll by a relative
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue