Auto merge of #14979 - mrobinson:scroll-roots-when-necessary, r=emilio

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.

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #14574 (github issue number if applicable).

<!-- Either: -->
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14979)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-01-17 07:18:42 -08:00 committed by GitHub
commit 3ab514302f
10 changed files with 139 additions and 63 deletions

View file

@ -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,
@ -1847,12 +1822,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 {
@ -1864,13 +1837,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,
}
);
@ -1903,10 +1887,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);
}
}
}
@ -1947,9 +1930,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