Skip to content

Commit

Permalink
Auto merge of #9522 - pcwalton:two-overflows, r=mbrubeck
Browse files Browse the repository at this point in the history
layout: Separate out overflow-for-scrolling from overflow-for-paint.

Closes #9484.

r? @mbrubeck

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9522)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Feb 5, 2016
2 parents b3bbea8 + 7c5b2d6 commit fb3fe3d
Show file tree
Hide file tree
Showing 17 changed files with 131 additions and 56 deletions.
4 changes: 2 additions & 2 deletions components/layout/block.rs
Expand Up @@ -43,7 +43,7 @@ use flow::{NEEDS_LAYER, PostorderFlowTraversal, PreorderFlowTraversal, Fragmenta
use flow::{self, BaseFlow, EarlyAbsolutePositionInfo, Flow, FlowClass, ForceNonfloatedFlag};
use flow_list::FlowList;
use flow_ref::FlowRef;
use fragment::{CoordinateSystem, Fragment, FragmentBorderBoxIterator, HAS_LAYER};
use fragment::{CoordinateSystem, Fragment, FragmentBorderBoxIterator, HAS_LAYER, Overflow};
use fragment::{SpecificFragmentInfo};
use gfx::display_list::{ClippingRegion, DisplayList};
use gfx_traits::LayerId;
Expand Down Expand Up @@ -2098,7 +2098,7 @@ impl Flow for BlockFlow {
self.fragment.repair_style(new_style)
}

fn compute_overflow(&self) -> Rect<Au> {
fn compute_overflow(&self) -> Overflow {
let flow_size = self.base.position.size.to_physical(self.base.writing_mode);
self.fragment.compute_overflow(&flow_size,
&self.base
Expand Down
4 changes: 2 additions & 2 deletions components/layout/display_list_builder.rs
Expand Up @@ -1218,7 +1218,7 @@ impl FragmentDisplayListBuilding for Fragment {
CoordinateSystem::Parent)
}
StackingContextCreationMode::InnerScrollWrapper => {
Rect::new(Point2D::zero(), base_flow.overflow.size)
Rect::new(Point2D::zero(), base_flow.overflow.scroll.size)
}
};
let overflow = match mode {
Expand All @@ -1228,7 +1228,7 @@ impl FragmentDisplayListBuilding for Fragment {
let border_box_offset =
border_box.translate(&-base_flow.stacking_relative_position).origin;
// Then, using that, compute our overflow region relative to our border box.
base_flow.overflow.translate(&-border_box_offset)
base_flow.overflow.paint.translate(&-border_box_offset)
}
StackingContextCreationMode::InnerScrollWrapper |
StackingContextCreationMode::OuterScrollWrapper => {
Expand Down
6 changes: 3 additions & 3 deletions components/layout/flex.rs
Expand Up @@ -10,15 +10,15 @@ use app_units::Au;
use block::BlockFlow;
use context::LayoutContext;
use display_list_builder::FlexFlowDisplayListBuilding;
use euclid::{Point2D, Rect};
use euclid::Point2D;
use floats::FloatKind;
use flow;
use flow::INLINE_POSITION_IS_STATIC;
use flow::IS_ABSOLUTELY_POSITIONED;
use flow::ImmutableFlowUtils;
use flow::{Flow, FlowClass, OpaqueFlow};
use flow::{HAS_LEFT_FLOATED_DESCENDANTS, HAS_RIGHT_FLOATED_DESCENDANTS};
use fragment::{Fragment, FragmentBorderBoxIterator};
use fragment::{Fragment, FragmentBorderBoxIterator, Overflow};
use gfx::display_list::DisplayList;
use incremental::{REFLOW, REFLOW_OUT_OF_FLOW};
use layout_debug;
Expand Down Expand Up @@ -432,7 +432,7 @@ impl Flow for FlexFlow {
self.block_flow.repair_style(new_style)
}

fn compute_overflow(&self) -> Rect<Au> {
fn compute_overflow(&self) -> Overflow {
self.block_flow.compute_overflow()
}

Expand Down
17 changes: 9 additions & 8 deletions components/layout/flow.rs
Expand Up @@ -32,7 +32,7 @@ use euclid::{Point2D, Rect, Size2D};
use floats::Floats;
use flow_list::{FlowList, FlowListIterator, MutFlowListIterator};
use flow_ref::{self, FlowRef, WeakFlowRef};
use fragment::{Fragment, FragmentBorderBoxIterator, SpecificFragmentInfo};
use fragment::{Fragment, FragmentBorderBoxIterator, Overflow, SpecificFragmentInfo};
use gfx::display_list::{ClippingRegion, DisplayList};
use gfx_traits::{LayerId, LayerType};
use incremental::{RECONSTRUCT_FLOW, REFLOW, REFLOW_OUT_OF_FLOW, REPAINT, RestyleDamage};
Expand Down Expand Up @@ -266,15 +266,16 @@ pub trait Flow: fmt::Debug + Sync + Send + 'static {
// FIXME(#2795): Get the real container size.
let container_size = Size2D::zero();
for kid in mut_base(self).children.iter_mut() {
let kid_overflow = base(kid).overflow;
let mut kid_overflow = base(kid).overflow;
let kid_position = base(kid).position.to_physical(base(kid).writing_mode,
container_size);
overflow = overflow.union(&kid_overflow.translate(&kid_position.origin))
kid_overflow.translate(&kid_position.origin);
overflow.union(&kid_overflow)
}
}
_ => {}
}
mut_base(self).overflow = overflow;
mut_base(self).overflow = overflow
}

/// Phase 4 of reflow: computes absolute positions.
Expand All @@ -286,7 +287,7 @@ pub trait Flow: fmt::Debug + Sync + Send + 'static {
fn build_display_list(&mut self, layout_context: &LayoutContext);

/// Returns the union of all overflow rects of all of this flow's fragments.
fn compute_overflow(&self) -> Rect<Au>;
fn compute_overflow(&self) -> Overflow;

/// Iterates through border boxes of all of this flow's fragments.
/// Level provides a zero based index indicating the current
Expand Down Expand Up @@ -865,7 +866,7 @@ pub struct BaseFlow {

/// The amount of overflow of this flow, relative to the containing block. Must include all the
/// pixels of all the display list items for correct invalidation.
pub overflow: Rect<Au>,
pub overflow: Overflow,

/// Data used during parallel traversals.
///
Expand Down Expand Up @@ -1078,7 +1079,7 @@ impl BaseFlow {
children: FlowList::new(),
intrinsic_inline_sizes: IntrinsicISizes::new(),
position: LogicalRect::zero(writing_mode),
overflow: Rect::zero(),
overflow: Overflow::new(),
parallel: FlowParallelInfo::new(),
floats: Floats::new(writing_mode),
collapsible_margins: CollapsibleMargins::new(),
Expand Down Expand Up @@ -1132,7 +1133,7 @@ impl BaseFlow {
let container_size = Size2D::zero();
let position_with_overflow = self.position
.to_physical(self.writing_mode, container_size)
.union(&self.overflow);
.union(&self.overflow.paint);
let bounds = Rect::new(self.stacking_relative_position, position_with_overflow.size);

let all_items = match self.display_list_building_result {
Expand Down
53 changes: 47 additions & 6 deletions components/layout/fragment.rs
Expand Up @@ -2176,7 +2176,7 @@ impl Fragment {
pub fn compute_overflow(&self,
flow_size: &Size2D<Au>,
relative_containing_block_size: &LogicalSize<Au>)
-> Rect<Au> {
-> Overflow {
let mut border_box = self.border_box.to_physical(self.style.writing_mode, *flow_size);

// Relative position can cause us to draw outside our border box.
Expand All @@ -2186,31 +2186,33 @@ impl Fragment {
let relative_position = self.relative_position(relative_containing_block_size);
border_box =
border_box.translate_by_size(&relative_position.to_physical(self.style.writing_mode));
let mut overflow = border_box;
let mut overflow = Overflow::from_rect(&border_box);

// Box shadows cause us to draw outside our border box.
for box_shadow in &self.style().get_effects().box_shadow.0 {
let offset = Point2D::new(box_shadow.offset_x, box_shadow.offset_y);
let inflation = box_shadow.spread_radius + box_shadow.blur_radius *
BLUR_INFLATION_FACTOR;
overflow = overflow.union(&border_box.translate(&offset).inflate(inflation, inflation))
overflow.paint = overflow.paint.union(&border_box.translate(&offset)
.inflate(inflation, inflation))
}

// Outlines cause us to draw outside our border box.
let outline_width = self.style.get_outline().outline_width;
if outline_width != Au(0) {
overflow = overflow.union(&border_box.inflate(outline_width, outline_width))
overflow.paint = overflow.paint.union(&border_box.inflate(outline_width,
outline_width))
}

// Include the overflow of the block flow, if any.
match self.specific {
SpecificFragmentInfo::InlineBlock(ref info) => {
let block_flow = info.flow_ref.as_block();
overflow = overflow.union(&flow::base(block_flow).overflow);
overflow.union(&flow::base(block_flow).overflow);
}
SpecificFragmentInfo::InlineAbsolute(ref info) => {
let block_flow = info.flow_ref.as_block();
overflow = overflow.union(&flow::base(block_flow).overflow);
overflow.union(&flow::base(block_flow).overflow);
}
_ => (),
}
Expand Down Expand Up @@ -2572,6 +2574,45 @@ impl WhitespaceStrippingResult {
}
}

/// The overflow area. We need two different notions of overflow: paint overflow and scrollable
/// overflow.
#[derive(Copy, Clone, Debug)]
pub struct Overflow {
pub scroll: Rect<Au>,
pub paint: Rect<Au>,
}

impl Overflow {
pub fn new() -> Overflow {
Overflow {
scroll: Rect::zero(),
paint: Rect::zero(),
}
}

pub fn from_rect(border_box: &Rect<Au>) -> Overflow {
Overflow {
scroll: *border_box,
paint: *border_box,
}
}

pub fn union(&mut self, other: &Overflow) {
self.scroll = self.scroll.union(&other.scroll);
self.paint = self.paint.union(&other.paint);
}

pub fn union_rect(&mut self, rect: &Rect<Au>) {
self.scroll = self.scroll.union(&rect);
self.paint = self.paint.union(&rect);
}

pub fn translate(&mut self, point: &Point2D<Au>) {
self.scroll = self.scroll.translate(point);
self.paint = self.paint.translate(point);
}
}

bitflags! {
flags FragmentFlags: u8 {
/// Whether this fragment has a layer.
Expand Down
12 changes: 6 additions & 6 deletions components/layout/inline.rs
Expand Up @@ -8,12 +8,13 @@ use app_units::Au;
use block::AbsoluteAssignBSizesTraversal;
use context::LayoutContext;
use display_list_builder::{FragmentDisplayListBuilding, InlineFlowDisplayListBuilding};
use euclid::{Point2D, Rect, Size2D};
use euclid::{Point2D, Size2D};
use floats::{FloatKind, Floats, PlacementInfo};
use flow::{EarlyAbsolutePositionInfo, MutableFlowUtils, OpaqueFlow};
use flow::{self, BaseFlow, Flow, FlowClass, ForceNonfloatedFlag, IS_ABSOLUTELY_POSITIONED};
use flow_ref;
use fragment::{CoordinateSystem, Fragment, FragmentBorderBoxIterator, SpecificFragmentInfo};
use fragment::{CoordinateSystem, Fragment, FragmentBorderBoxIterator, Overflow};
use fragment::{SpecificFragmentInfo};
use gfx::display_list::OpaqueNode;
use gfx::font::FontMetrics;
use gfx::font_context::FontContext;
Expand Down Expand Up @@ -1756,14 +1757,13 @@ impl Flow for InlineFlow {

fn repair_style(&mut self, _: &Arc<ComputedValues>) {}

fn compute_overflow(&self) -> Rect<Au> {
let mut overflow = Rect::zero();
fn compute_overflow(&self) -> Overflow {
let mut overflow = Overflow::new();
let flow_size = self.base.position.size.to_physical(self.base.writing_mode);
let relative_containing_block_size =
&self.base.early_absolute_position_info.relative_containing_block_size;
for fragment in &self.fragments.fragments {
overflow = overflow.union(&fragment.compute_overflow(&flow_size,
&relative_containing_block_size))
overflow.union(&fragment.compute_overflow(&flow_size, &relative_containing_block_size))
}
overflow
}
Expand Down
2 changes: 1 addition & 1 deletion components/layout/layout_thread.rs
Expand Up @@ -865,7 +865,7 @@ impl LayoutThread {
if rw_data.stylist.viewport_constraints().is_some() {
root_flow.position.size.to_physical(root_flow.writing_mode)
} else {
root_flow.overflow.size
root_flow.overflow.scroll.size
}
};
let mut display_list = box DisplayList::new();
Expand Down
7 changes: 4 additions & 3 deletions components/layout/list_item.rs
Expand Up @@ -11,10 +11,11 @@ use app_units::Au;
use block::BlockFlow;
use context::LayoutContext;
use display_list_builder::ListItemFlowDisplayListBuilding;
use euclid::{Point2D, Rect};
use euclid::Point2D;
use floats::FloatKind;
use flow::{Flow, FlowClass, OpaqueFlow};
use fragment::{CoordinateSystem, Fragment, FragmentBorderBoxIterator, GeneratedContentInfo};
use fragment::{Overflow};
use generated_content;
use gfx::display_list::DisplayList;
use incremental::RESOLVE_GENERATED_CONTENT;
Expand Down Expand Up @@ -152,14 +153,14 @@ impl Flow for ListItemFlow {
self.block_flow.repair_style(new_style)
}

fn compute_overflow(&self) -> Rect<Au> {
fn compute_overflow(&self) -> Overflow {
let mut overflow = self.block_flow.compute_overflow();
let flow_size = self.block_flow.base.position.size.to_physical(self.block_flow.base.writing_mode);
let relative_containing_block_size =
&self.block_flow.base.early_absolute_position_info.relative_containing_block_size;

for fragment in &self.marker_fragments {
overflow = overflow.union(&fragment.compute_overflow(&flow_size, &relative_containing_block_size))
overflow.union(&fragment.compute_overflow(&flow_size, &relative_containing_block_size))
}
overflow
}
Expand Down
8 changes: 4 additions & 4 deletions components/layout/multicol.rs
Expand Up @@ -9,11 +9,11 @@
use app_units::Au;
use block::BlockFlow;
use context::LayoutContext;
use euclid::{Point2D, Rect};
use euclid::Point2D;
use floats::FloatKind;
use flow::{Flow, FlowClass, OpaqueFlow, mut_base, FragmentationContext};
use flow_ref::{self, FlowRef};
use fragment::{Fragment, FragmentBorderBoxIterator};
use fragment::{Fragment, FragmentBorderBoxIterator, Overflow};
use std::cmp::{min, max};
use std::fmt;
use std::sync::Arc;
Expand Down Expand Up @@ -186,7 +186,7 @@ impl Flow for MulticolFlow {
self.block_flow.repair_style(new_style)
}

fn compute_overflow(&self) -> Rect<Au> {
fn compute_overflow(&self) -> Overflow {
self.block_flow.compute_overflow()
}

Expand Down Expand Up @@ -264,7 +264,7 @@ impl Flow for MulticolColumnFlow {
self.block_flow.repair_style(new_style)
}

fn compute_overflow(&self) -> Rect<Au> {
fn compute_overflow(&self) -> Overflow {
self.block_flow.compute_overflow()
}

Expand Down
6 changes: 3 additions & 3 deletions components/layout/table.rs
Expand Up @@ -11,10 +11,10 @@ use block::{BlockFlow, CandidateBSizeIterator, ISizeAndMarginsComputer};
use block::{ISizeConstraintInput, ISizeConstraintSolution};
use context::LayoutContext;
use display_list_builder::{BlockFlowDisplayListBuilding, BorderPaintingMode};
use euclid::{Point2D, Rect};
use euclid::Point2D;
use flow::{IMPACTED_BY_RIGHT_FLOATS, ImmutableFlowUtils, OpaqueFlow};
use flow::{self, EarlyAbsolutePositionInfo, Flow, FlowClass, IMPACTED_BY_LEFT_FLOATS};
use fragment::{Fragment, FragmentBorderBoxIterator};
use fragment::{Fragment, FragmentBorderBoxIterator, Overflow};
use gfx::display_list::DisplayList;
use incremental::{REFLOW, REFLOW_OUT_OF_FLOW};
use layout_debug;
Expand Down Expand Up @@ -536,7 +536,7 @@ impl Flow for TableFlow {
self.block_flow.repair_style(new_style)
}

fn compute_overflow(&self) -> Rect<Au> {
fn compute_overflow(&self) -> Overflow {
self.block_flow.compute_overflow()
}

Expand Down
6 changes: 3 additions & 3 deletions components/layout/table_caption.rs
Expand Up @@ -9,9 +9,9 @@
use app_units::Au;
use block::BlockFlow;
use context::LayoutContext;
use euclid::{Point2D, Rect};
use euclid::Point2D;
use flow::{Flow, FlowClass, OpaqueFlow};
use fragment::{Fragment, FragmentBorderBoxIterator};
use fragment::{Fragment, FragmentBorderBoxIterator, Overflow};
use std::fmt;
use std::sync::Arc;
use style::properties::ComputedValues;
Expand Down Expand Up @@ -83,7 +83,7 @@ impl Flow for TableCaptionFlow {
self.block_flow.repair_style(new_style)
}

fn compute_overflow(&self) -> Rect<Au> {
fn compute_overflow(&self) -> Overflow {
self.block_flow.compute_overflow()
}

Expand Down
4 changes: 2 additions & 2 deletions components/layout/table_cell.rs
Expand Up @@ -13,7 +13,7 @@ use cssparser::Color;
use display_list_builder::{BlockFlowDisplayListBuilding, BorderPaintingMode};
use euclid::{Point2D, Rect, SideOffsets2D, Size2D};
use flow::{Flow, FlowClass, OpaqueFlow};
use fragment::{Fragment, FragmentBorderBoxIterator};
use fragment::{Fragment, FragmentBorderBoxIterator, Overflow};
use gfx::display_list::DisplayList;
use layout_debug;
use model::MaybeAuto;
Expand Down Expand Up @@ -197,7 +197,7 @@ impl Flow for TableCellFlow {
self.block_flow.repair_style(new_style)
}

fn compute_overflow(&self) -> Rect<Au> {
fn compute_overflow(&self) -> Overflow {
self.block_flow.compute_overflow()
}

Expand Down

0 comments on commit fb3fe3d

Please sign in to comment.