Simplify stacking context collection

Simplify the way that stacking contexts are collected. Instead of
passing the StackingContextId down the tree, pass the parent
StackingContext itself. This will allow future patches to get more
information about the parent stacking context (such as location).

Also remove the return value of collect_stacking_contexts, which was
unused.
This commit is contained in:
Martin Robinson 2016-09-25 18:58:56 +02:00
parent ef1b594f48
commit 066775915c
16 changed files with 88 additions and 184 deletions

View file

@ -618,7 +618,7 @@ pub struct StackingContext {
pub layer_info: Option<LayerInfo>,
/// Children of this StackingContext.
children: Vec<Box<StackingContext>>,
pub children: Vec<Box<StackingContext>>,
}
impl StackingContext {
@ -654,30 +654,9 @@ impl StackingContext {
}
}
pub fn set_children(&mut self, children: Vec<Box<StackingContext>>) {
debug_assert!(self.children.is_empty());
// We need to take into account the possible transformations of the
// child stacking contexts.
for child in &children {
self.update_overflow_for_new_child(&child);
}
self.children = children;
}
pub fn add_child(&mut self, child: Box<StackingContext>) {
self.update_overflow_for_new_child(&child);
self.children.push(child);
}
pub fn add_children(&mut self, children: Vec<Box<StackingContext>>) {
if self.children.is_empty() {
return self.set_children(children);
}
for child in children {
self.add_child(child);
}
pub fn add_child(&mut self, mut child: StackingContext) {
child.update_overflow_for_all_children();
self.children.push(Box::new(child));
}
pub fn child_at_mut(&mut self, index: usize) -> &mut StackingContext {
@ -688,7 +667,8 @@ impl StackingContext {
&self.children
}
fn update_overflow_for_new_child(&mut self, child: &StackingContext) {
fn update_overflow_for_all_children(&mut self) {
for child in self.children.iter() {
if self.context_type == StackingContextType::Real &&
child.context_type == StackingContextType::Real &&
!self.scrolls_overflow_area {
@ -700,6 +680,7 @@ impl StackingContext {
self.overflow = self.overflow.union(&overflow);
}
}
}
fn overflow_rect_in_parent_space(&self) -> Rect<Au> {
// Transform this stacking context to get it into the same space as

View file

@ -44,7 +44,7 @@ use flow_ref::FlowRef;
use fragment::{CoordinateSystem, Fragment, FragmentBorderBoxIterator, HAS_LAYER, Overflow};
use fragment::SpecificFragmentInfo;
use gfx::display_list::{ClippingRegion, StackingContext};
use gfx_traits::{LayerId, StackingContextId};
use gfx_traits::LayerId;
use gfx_traits::print_tree::PrintTree;
use layout_debug;
use model::{self, IntrinsicISizes, MarginCollapseInfo};
@ -2172,11 +2172,8 @@ impl Flow for BlockFlow {
}
}
fn collect_stacking_contexts(&mut self,
parent_id: StackingContextId,
contexts: &mut Vec<Box<StackingContext>>)
-> StackingContextId {
self.collect_stacking_contexts_for_block(parent_id, contexts)
fn collect_stacking_contexts(&mut self, parent: &mut StackingContext) {
self.collect_stacking_contexts_for_block(parent);
}
fn build_display_list(&mut self, state: &mut DisplayListBuildState) {

View file

@ -292,7 +292,7 @@ pub trait FragmentDisplayListBuilding {
base_flow: &BaseFlow,
scroll_policy: ScrollPolicy,
mode: StackingContextCreationMode)
-> Box<StackingContext>;
-> StackingContext;
}
fn handle_overlapping_radii(size: &Size2D<Au>, radii: &BorderRadii<Au>) -> BorderRadii<Au> {
@ -1369,7 +1369,7 @@ impl FragmentDisplayListBuilding for Fragment {
base_flow: &BaseFlow,
scroll_policy: ScrollPolicy,
mode: StackingContextCreationMode)
-> Box<StackingContext> {
-> StackingContext {
let use_webrender = opts::get().use_webrender;
let border_box = match mode {
StackingContextCreationMode::InnerScrollWrapper => {
@ -1510,7 +1510,7 @@ impl FragmentDisplayListBuilding for Fragment {
_ => StackingContextType::Real,
};
Box::new(StackingContext::new(id,
StackingContext::new(id,
context_type,
&border_box,
&overflow,
@ -1521,7 +1521,7 @@ impl FragmentDisplayListBuilding for Fragment {
perspective,
establishes_3d_context,
scrolls_overflow_area,
layer_info))
layer_info)
}
fn adjust_clipping_region_for_children(&self,
@ -1721,25 +1721,19 @@ impl FragmentDisplayListBuilding for Fragment {
}
pub trait BlockFlowDisplayListBuilding {
fn collect_stacking_contexts_for_block(&mut self,
parent_id: StackingContextId,
contexts: &mut Vec<Box<StackingContext>>)
-> StackingContextId;
fn collect_stacking_contexts_for_block(&mut self, parent: &mut StackingContext);
fn build_display_list_for_block(&mut self,
state: &mut DisplayListBuildState,
border_painting_mode: BorderPaintingMode);
}
impl BlockFlowDisplayListBuilding for BlockFlow {
fn collect_stacking_contexts_for_block(&mut self,
parent_id: StackingContextId,
contexts: &mut Vec<Box<StackingContext>>)
-> StackingContextId {
fn collect_stacking_contexts_for_block(&mut self, parent: &mut StackingContext) {
let block_stacking_context_type = self.block_stacking_context_type();
if block_stacking_context_type == BlockStackingContextType::NonstackingContext {
self.base.stacking_context_id = parent_id;
self.base.collect_stacking_contexts_for_children(parent_id, contexts);
return parent_id;
self.base.stacking_context_id = parent.id;
self.base.collect_stacking_contexts_for_children(parent);
return;
}
let has_scrolling_overflow = self.has_scrolling_overflow();
@ -1758,9 +1752,6 @@ impl BlockFlowDisplayListBuilding for BlockFlow {
stacking_context_id
};
let mut child_contexts = Vec::new();
self.base.collect_stacking_contexts_for_children(inner_stacking_context_id,
&mut child_contexts);
if block_stacking_context_type == BlockStackingContextType::PseudoStackingContext {
let creation_mode = if self.base.flags.contains(IS_ABSOLUTELY_POSITIONED) ||
@ -1771,25 +1762,25 @@ impl BlockFlowDisplayListBuilding for BlockFlow {
StackingContextCreationMode::PseudoFloat
};
let stacking_context_index = contexts.len();
contexts.push(self.fragment.create_stacking_context(stacking_context_id,
let mut new_context = self.fragment.create_stacking_context(stacking_context_id,
&self.base,
ScrollPolicy::Scrollable,
creation_mode));
creation_mode);
self.base.collect_stacking_contexts_for_children(&mut new_context);
let new_children: Vec<Box<StackingContext>> = new_context.children.drain(..).collect();
let mut floating = vec![];
for child_context in child_contexts.into_iter() {
if child_context.context_type == StackingContextType::PseudoFloat {
// Floating.
floating.push(child_context)
let mut non_floating_children = Vec::new();
for child in new_children {
if child.context_type == StackingContextType::PseudoFloat {
new_context.children.push(child);
} else {
// Positioned.
contexts.push(child_context)
non_floating_children.push(child);
}
}
contexts[stacking_context_index].set_children(floating);
return stacking_context_id;
parent.add_child(new_context);
parent.children.append(&mut non_floating_children);
return;
}
let scroll_policy = if self.is_fixed() {
@ -1804,7 +1795,7 @@ impl BlockFlowDisplayListBuilding for BlockFlow {
&self.base,
scroll_policy,
StackingContextCreationMode::InnerScrollWrapper);
inner_stacking_context.set_children(child_contexts);
self.base.collect_stacking_contexts_for_children(&mut inner_stacking_context);
let mut outer_stacking_context = self.fragment.create_stacking_context(
stacking_context_id,
@ -1819,12 +1810,11 @@ impl BlockFlowDisplayListBuilding for BlockFlow {
&self.base,
scroll_policy,
StackingContextCreationMode::Normal);
stacking_context.set_children(child_contexts);
self.base.collect_stacking_contexts_for_children(&mut stacking_context);
stacking_context
};
contexts.push(stacking_context);
stacking_context_id
parent.add_child(stacking_context);
}
fn build_display_list_for_block(&mut self,
@ -1871,10 +1861,7 @@ impl BlockFlowDisplayListBuilding for BlockFlow {
}
pub trait InlineFlowDisplayListBuilding {
fn collect_stacking_contexts_for_inline(&mut self,
parent_id: StackingContextId,
contexts: &mut Vec<Box<StackingContext>>)
-> StackingContextId;
fn collect_stacking_contexts_for_inline(&mut self, parent: &mut StackingContext);
fn build_display_list_for_inline_fragment_at_index(&mut self,
state: &mut DisplayListBuildState,
index: usize);
@ -1882,36 +1869,32 @@ pub trait InlineFlowDisplayListBuilding {
}
impl InlineFlowDisplayListBuilding for InlineFlow {
fn collect_stacking_contexts_for_inline(&mut self,
parent_id: StackingContextId,
contexts: &mut Vec<Box<StackingContext>>)
-> StackingContextId {
self.base.stacking_context_id = parent_id;
fn collect_stacking_contexts_for_inline(&mut self, parent: &mut StackingContext) {
self.base.stacking_context_id = parent.id;
for mut fragment in self.fragments.fragments.iter_mut() {
match fragment.specific {
SpecificFragmentInfo::InlineBlock(ref mut block_flow) => {
let block_flow = flow_ref::deref_mut(&mut block_flow.flow_ref);
block_flow.collect_stacking_contexts(parent_id, contexts);
block_flow.collect_stacking_contexts(parent);
}
SpecificFragmentInfo::InlineAbsoluteHypothetical(ref mut block_flow) => {
let block_flow = flow_ref::deref_mut(&mut block_flow.flow_ref);
block_flow.collect_stacking_contexts(parent_id, contexts);
block_flow.collect_stacking_contexts(parent);
}
_ if fragment.establishes_stacking_context() => {
fragment.stacking_context_id =
StackingContextId::new_of_type(fragment.fragment_id(),
fragment.fragment_type());
contexts.push(fragment.create_stacking_context(
parent.add_child(fragment.create_stacking_context(
fragment.stacking_context_id,
&self.base,
ScrollPolicy::Scrollable,
StackingContextCreationMode::Normal));
}
_ => fragment.stacking_context_id = parent_id,
_ => fragment.stacking_context_id = parent.id,
}
}
parent_id
}
fn build_display_list_for_inline_fragment_at_index(&mut self,

View file

@ -18,7 +18,6 @@ use flow::{INLINE_POSITION_IS_STATIC, IS_ABSOLUTELY_POSITIONED};
use flow_ref::{self, FlowRef};
use fragment::{Fragment, FragmentBorderBoxIterator, Overflow};
use gfx::display_list::StackingContext;
use gfx_traits::StackingContextId;
use layout_debug;
use model::{Direction, IntrinsicISizes, MaybeAuto, MinMaxConstraint};
use model::{specified, specified_or_none};
@ -940,11 +939,8 @@ impl Flow for FlexFlow {
self.build_display_list_for_flex(state);
}
fn collect_stacking_contexts(&mut self,
parent_id: StackingContextId,
contexts: &mut Vec<Box<StackingContext>>)
-> StackingContextId {
self.block_flow.collect_stacking_contexts(parent_id, contexts)
fn collect_stacking_contexts(&mut self, parent: &mut StackingContext) {
self.block_flow.collect_stacking_contexts(parent);
}
fn repair_style(&mut self, new_style: &Arc<ServoComputedValues>) {

View file

@ -224,10 +224,7 @@ pub trait Flow: fmt::Debug + Sync + Send + 'static {
None
}
fn collect_stacking_contexts(&mut self,
_parent_id: StackingContextId,
_: &mut Vec<Box<StackingContext>>)
-> StackingContextId;
fn collect_stacking_contexts(&mut self, _parent: &mut StackingContext);
/// If this is a float, places it. The default implementation does nothing.
fn place_float_if_applicable<'a>(&mut self) {}
@ -1160,11 +1157,9 @@ impl BaseFlow {
return self as *const BaseFlow as usize;
}
pub fn collect_stacking_contexts_for_children(&mut self,
parent_id: StackingContextId,
contexts: &mut Vec<Box<StackingContext>>) {
pub fn collect_stacking_contexts_for_children(&mut self, parent: &mut StackingContext) {
for kid in self.children.iter_mut() {
kid.collect_stacking_contexts(parent_id, contexts);
kid.collect_stacking_contexts(parent);
}
}

View file

@ -20,7 +20,6 @@ use fragment::SpecificFragmentInfo;
use gfx::display_list::{OpaqueNode, StackingContext};
use gfx::font::FontMetrics;
use gfx::font_context::FontContext;
use gfx_traits::StackingContextId;
use gfx_traits::print_tree::PrintTree;
use layout_debug;
use model::IntrinsicISizesContribution;
@ -1658,11 +1657,8 @@ impl Flow for InlineFlow {
fn update_late_computed_block_position_if_necessary(&mut self, _: Au) {}
fn collect_stacking_contexts(&mut self,
parent_id: StackingContextId,
contexts: &mut Vec<Box<StackingContext>>)
-> StackingContextId {
self.collect_stacking_contexts_for_inline(parent_id, contexts)
fn collect_stacking_contexts(&mut self, parent: &mut StackingContext) {
self.collect_stacking_contexts_for_inline(parent);
}
fn build_display_list(&mut self, state: &mut DisplayListBuildState) {

View file

@ -18,7 +18,6 @@ use fragment::{CoordinateSystem, Fragment, FragmentBorderBoxIterator, GeneratedC
use fragment::Overflow;
use generated_content;
use gfx::display_list::StackingContext;
use gfx_traits::StackingContextId;
use inline::InlineMetrics;
use script_layout_interface::restyle_damage::RESOLVE_GENERATED_CONTENT;
use std::sync::Arc;
@ -148,11 +147,8 @@ impl Flow for ListItemFlow {
self.build_display_list_for_list_item(state);
}
fn collect_stacking_contexts(&mut self,
parent_id: StackingContextId,
contexts: &mut Vec<Box<StackingContext>>)
-> StackingContextId {
self.block_flow.collect_stacking_contexts(parent_id, contexts)
fn collect_stacking_contexts(&mut self, parent: &mut StackingContext) {
self.block_flow.collect_stacking_contexts(parent);
}
fn repair_style(&mut self, new_style: &Arc<ServoComputedValues>) {

View file

@ -17,7 +17,6 @@ use flow::{Flow, FlowClass, OpaqueFlow, mut_base, FragmentationContext};
use flow_ref::{self, FlowRef};
use fragment::{Fragment, FragmentBorderBoxIterator, Overflow};
use gfx::display_list::StackingContext;
use gfx_traits::StackingContextId;
use gfx_traits::print_tree::PrintTree;
use std::cmp::{min, max};
use std::fmt;
@ -186,11 +185,8 @@ impl Flow for MulticolFlow {
self.block_flow.build_display_list(state);
}
fn collect_stacking_contexts(&mut self,
parent_id: StackingContextId,
contexts: &mut Vec<Box<StackingContext>>)
-> StackingContextId {
self.block_flow.collect_stacking_contexts(parent_id, contexts)
fn collect_stacking_contexts(&mut self, parent: &mut StackingContext) {
self.block_flow.collect_stacking_contexts(parent);
}
fn repair_style(&mut self, new_style: &Arc<ServoComputedValues>) {
@ -271,11 +267,8 @@ impl Flow for MulticolColumnFlow {
self.block_flow.build_display_list(state);
}
fn collect_stacking_contexts(&mut self,
parent_id: StackingContextId,
contexts: &mut Vec<Box<StackingContext>>)
-> StackingContextId {
self.block_flow.collect_stacking_contexts(parent_id, contexts)
fn collect_stacking_contexts(&mut self, parent: &mut StackingContext) {
self.block_flow.collect_stacking_contexts(parent);
}
fn repair_style(&mut self, new_style: &Arc<ServoComputedValues>) {

View file

@ -78,10 +78,7 @@ pub fn build_display_list_for_subtree(flow_root: &mut Flow,
root_stacking_context: &mut StackingContext,
shared_layout_context: &SharedLayoutContext)
-> Vec<DisplayItem> {
let mut children = vec![];
flow_root.collect_stacking_contexts(root_stacking_context.id,
&mut children);
root_stacking_context.add_children(children);
flow_root.collect_stacking_contexts(root_stacking_context);
let mut build_display_list = BuildDisplayList {
state: DisplayListBuildState::new(shared_layout_context,
flow::base(flow_root).stacking_context_id),

View file

@ -17,7 +17,6 @@ use flow::{BaseFlow, EarlyAbsolutePositionInfo, Flow, FlowClass, ImmutableFlowUt
use flow_list::MutFlowListIterator;
use fragment::{Fragment, FragmentBorderBoxIterator, Overflow};
use gfx::display_list::StackingContext;
use gfx_traits::StackingContextId;
use gfx_traits::print_tree::PrintTree;
use layout_debug;
use model::{IntrinsicISizes, IntrinsicISizesContribution, MaybeAuto};
@ -477,11 +476,8 @@ impl Flow for TableFlow {
self.block_flow.build_display_list_for_block(state, border_painting_mode);
}
fn collect_stacking_contexts(&mut self,
parent_id: StackingContextId,
contexts: &mut Vec<Box<StackingContext>>)
-> StackingContextId {
self.block_flow.collect_stacking_contexts(parent_id, contexts)
fn collect_stacking_contexts(&mut self, parent: &mut StackingContext) {
self.block_flow.collect_stacking_contexts(parent);
}
fn repair_style(&mut self, new_style: &Arc<ServoComputedValues>) {

View file

@ -14,7 +14,6 @@ use euclid::Point2D;
use flow::{Flow, FlowClass, OpaqueFlow};
use fragment::{Fragment, FragmentBorderBoxIterator, Overflow};
use gfx::display_list::StackingContext;
use gfx_traits::StackingContextId;
use gfx_traits::print_tree::PrintTree;
use std::fmt;
use std::sync::Arc;
@ -83,11 +82,8 @@ impl Flow for TableCaptionFlow {
self.block_flow.build_display_list(state);
}
fn collect_stacking_contexts(&mut self,
parent_id: StackingContextId,
contexts: &mut Vec<Box<StackingContext>>)
-> StackingContextId {
self.block_flow.collect_stacking_contexts(parent_id, contexts)
fn collect_stacking_contexts(&mut self, parent: &mut StackingContext) {
self.block_flow.collect_stacking_contexts(parent);
}
fn repair_style(&mut self, new_style: &Arc<ServoComputedValues>) {

View file

@ -15,7 +15,6 @@ use euclid::{Point2D, Rect, SideOffsets2D, Size2D};
use flow::{self, Flow, FlowClass, OpaqueFlow};
use fragment::{Fragment, FragmentBorderBoxIterator, Overflow};
use gfx::display_list::StackingContext;
use gfx_traits::StackingContextId;
use gfx_traits::print_tree::PrintTree;
use layout_debug;
use model::MaybeAuto;
@ -237,11 +236,8 @@ impl Flow for TableCellFlow {
self.block_flow.build_display_list_for_block(state, border_painting_mode)
}
fn collect_stacking_contexts(&mut self,
parent_id: StackingContextId,
contexts: &mut Vec<Box<StackingContext>>)
-> StackingContextId {
self.block_flow.collect_stacking_contexts(parent_id, contexts)
fn collect_stacking_contexts(&mut self, parent: &mut StackingContext) {
self.block_flow.collect_stacking_contexts(parent);
}
fn repair_style(&mut self, new_style: &Arc<ServoComputedValues>) {

View file

@ -13,7 +13,6 @@ use euclid::Point2D;
use flow::{BaseFlow, Flow, FlowClass, ForceNonfloatedFlag, OpaqueFlow};
use fragment::{Fragment, FragmentBorderBoxIterator, Overflow, SpecificFragmentInfo};
use gfx::display_list::StackingContext;
use gfx_traits::StackingContextId;
use layout_debug;
use std::cmp::max;
use std::fmt;
@ -96,12 +95,7 @@ impl Flow for TableColGroupFlow {
// Table columns are invisible.
fn build_display_list(&mut self, _: &mut DisplayListBuildState) { }
fn collect_stacking_contexts(&mut self,
parent_id: StackingContextId,
_: &mut Vec<Box<StackingContext>>)
-> StackingContextId {
parent_id
}
fn collect_stacking_contexts(&mut self, _parent: &mut StackingContext) { }
fn repair_style(&mut self, _: &Arc<ServoComputedValues>) {}

View file

@ -16,7 +16,6 @@ use flow::{self, EarlyAbsolutePositionInfo, Flow, FlowClass, ImmutableFlowUtils,
use flow_list::MutFlowListIterator;
use fragment::{Fragment, FragmentBorderBoxIterator, Overflow};
use gfx::display_list::StackingContext;
use gfx_traits::StackingContextId;
use gfx_traits::print_tree::PrintTree;
use layout_debug;
use model::MaybeAuto;
@ -455,11 +454,8 @@ impl Flow for TableRowFlow {
self.block_flow.build_display_list_for_block(state, border_painting_mode);
}
fn collect_stacking_contexts(&mut self,
parent_id: StackingContextId,
contexts: &mut Vec<Box<StackingContext>>)
-> StackingContextId {
self.block_flow.collect_stacking_contexts(parent_id, contexts)
fn collect_stacking_contexts(&mut self, parent: &mut StackingContext) {
self.block_flow.collect_stacking_contexts(parent);
}
fn repair_style(&mut self, new_style: &Arc<ServoComputedValues>) {

View file

@ -14,7 +14,6 @@ use euclid::Point2D;
use flow::{Flow, FlowClass, OpaqueFlow};
use fragment::{Fragment, FragmentBorderBoxIterator, Overflow};
use gfx::display_list::StackingContext;
use gfx_traits::StackingContextId;
use gfx_traits::print_tree::PrintTree;
use layout_debug;
use rustc_serialize::{Encodable, Encoder};
@ -212,11 +211,8 @@ impl Flow for TableRowGroupFlow {
self.block_flow.build_display_list(state);
}
fn collect_stacking_contexts(&mut self,
parent_id: StackingContextId,
contexts: &mut Vec<Box<StackingContext>>)
-> StackingContextId {
self.block_flow.collect_stacking_contexts(parent_id, contexts)
fn collect_stacking_contexts(&mut self, parent: &mut StackingContext) {
self.block_flow.collect_stacking_contexts(parent);
}
fn repair_style(&mut self, new_style: &Arc<ServoComputedValues>) {

View file

@ -23,7 +23,6 @@ use floats::FloatKind;
use flow::{Flow, FlowClass, ImmutableFlowUtils, INLINE_POSITION_IS_STATIC, OpaqueFlow};
use fragment::{Fragment, FragmentBorderBoxIterator, Overflow};
use gfx::display_list::StackingContext;
use gfx_traits::StackingContextId;
use gfx_traits::print_tree::PrintTree;
use model::MaybeAuto;
use std::cmp::{max, min};
@ -445,11 +444,8 @@ impl Flow for TableWrapperFlow {
self.block_flow.build_display_list(state);
}
fn collect_stacking_contexts(&mut self,
parent_id: StackingContextId,
contexts: &mut Vec<Box<StackingContext>>)
-> StackingContextId {
self.block_flow.collect_stacking_contexts(parent_id, contexts)
fn collect_stacking_contexts(&mut self, parent: &mut StackingContext) {
self.block_flow.collect_stacking_contexts(parent);
}
fn repair_style(&mut self, new_style: &Arc<ServoComputedValues>) {