mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Only create scrolling overflow regions when necessary
Only create scroll roots for overflow regions when the overflow region is actually larger than the container size. This prevents creating scrolling roots for elements that do not have overflow scroll as a side-effect of the way their height and width is defined. For example, tables should never respect overflow:scroll since their height and width should always be large enough to prevent overflow. This also decreases the size and complexity of the display list in many other circumstances. As part of this change, transformed overflow calculation is moved from display list construction to layout. This should mean that overflow is handled more accurately earlier. Fixes #14574.
This commit is contained in:
parent
14aa666a5a
commit
44b24de60f
10 changed files with 139 additions and 63 deletions
|
@ -128,14 +128,7 @@ impl<'a> DisplayListBuildState<'a> {
|
|||
|
||||
fn add_stacking_context(&mut self,
|
||||
parent_id: StackingContextId,
|
||||
mut stacking_context: StackingContext) {
|
||||
self.update_overflow_for_stacking_context(&mut stacking_context);
|
||||
self.add_stacking_context_without_calcuating_overflow(parent_id, stacking_context);
|
||||
}
|
||||
|
||||
fn add_stacking_context_without_calcuating_overflow(&mut self,
|
||||
parent_id: StackingContextId,
|
||||
stacking_context: StackingContext) {
|
||||
stacking_context: StackingContext) {
|
||||
let contexts = self.stacking_context_children.entry(parent_id).or_insert(Vec::new());
|
||||
contexts.push(stacking_context);
|
||||
}
|
||||
|
@ -194,24 +187,6 @@ impl<'a> DisplayListBuildState<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn update_overflow_for_stacking_context(&mut self, stacking_context: &mut StackingContext) {
|
||||
if stacking_context.context_type != StackingContextType::Real {
|
||||
return;
|
||||
}
|
||||
|
||||
let children = self.stacking_context_children.get_mut(&stacking_context.id);
|
||||
if let Some(children) = children {
|
||||
for child in children {
|
||||
if child.context_type == StackingContextType::Real {
|
||||
// This child might be transformed, so we need to take into account
|
||||
// its transformed overflow rect too, but at the correct position.
|
||||
let overflow = child.overflow_rect_in_parent_space();
|
||||
stacking_context.overflow = stacking_context.overflow.union(&overflow);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn to_display_list_for_stacking_context(&mut self,
|
||||
list: &mut Vec<DisplayItem>,
|
||||
stacking_context: StackingContext,
|
||||
|
@ -1842,12 +1817,10 @@ impl BlockFlowDisplayListBuilding for BlockFlow {
|
|||
}
|
||||
|
||||
fn collect_scroll_root_for_block(&mut self, state: &mut DisplayListBuildState) -> ScrollRootId {
|
||||
if !self.has_scrolling_overflow() {
|
||||
if !self.style_permits_scrolling_overflow() {
|
||||
return state.current_scroll_root_id;
|
||||
}
|
||||
|
||||
let scroll_root_id = ScrollRootId::new_of_type(self.fragment.node.id() as usize,
|
||||
self.fragment.fragment_type());
|
||||
let coordinate_system = if self.fragment.establishes_stacking_context() {
|
||||
CoordinateSystem::Own
|
||||
} else {
|
||||
|
@ -1859,13 +1832,24 @@ impl BlockFlowDisplayListBuilding for BlockFlow {
|
|||
&self.base.early_absolute_position_info.relative_containing_block_size,
|
||||
self.base.early_absolute_position_info.relative_containing_block_mode,
|
||||
coordinate_system);
|
||||
let clip = self.fragment.stacking_relative_content_box(&border_box);
|
||||
|
||||
let has_scrolling_overflow = self.base.overflow.scroll.origin != Point2D::zero() ||
|
||||
self.base.overflow.scroll.size.width > clip.size.width ||
|
||||
self.base.overflow.scroll.size.height > clip.size.height;
|
||||
self.mark_scrolling_overflow(has_scrolling_overflow);
|
||||
if !has_scrolling_overflow {
|
||||
return state.current_scroll_root_id;
|
||||
}
|
||||
|
||||
let scroll_root_id = ScrollRootId::new_of_type(self.fragment.node.id() as usize,
|
||||
self.fragment.fragment_type());
|
||||
let parent_scroll_root_id = state.current_scroll_root_id;
|
||||
state.add_scroll_root(
|
||||
ScrollRoot {
|
||||
id: scroll_root_id,
|
||||
parent_id: parent_scroll_root_id,
|
||||
clip: self.fragment.stacking_relative_content_box(&border_box),
|
||||
clip: clip,
|
||||
size: self.base.overflow.scroll.size,
|
||||
}
|
||||
);
|
||||
|
@ -1898,10 +1882,9 @@ impl BlockFlowDisplayListBuilding for BlockFlow {
|
|||
state.stacking_context_children.remove(&stacking_context_id).unwrap_or_else(Vec::new);
|
||||
for child in new_children {
|
||||
if child.context_type == StackingContextType::PseudoFloat {
|
||||
state.add_stacking_context_without_calcuating_overflow(stacking_context_id, child);
|
||||
state.add_stacking_context(stacking_context_id, child);
|
||||
} else {
|
||||
state.add_stacking_context_without_calcuating_overflow(parent_stacking_context_id,
|
||||
child);
|
||||
state.add_stacking_context(parent_stacking_context_id, child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1942,9 +1925,7 @@ impl BlockFlowDisplayListBuilding for BlockFlow {
|
|||
DisplayListSection::BlockBackgroundsAndBorders
|
||||
};
|
||||
|
||||
if self.has_scrolling_overflow() {
|
||||
state.processing_scroll_root_element = true;
|
||||
}
|
||||
state.processing_scroll_root_element = self.has_scrolling_overflow();
|
||||
|
||||
// Add the box that starts the block context.
|
||||
self.fragment
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue