Convert usages of Box in type identifiers to Fragment

This commit is contained in:
Brendan Zabarauskas 2014-05-27 15:52:41 -07:00
parent a578943b3c
commit c5fced4390
13 changed files with 364 additions and 369 deletions

View file

@ -12,7 +12,7 @@
//! //!
//! CB: Containing Block of the current flow. //! CB: Containing Block of the current flow.
use layout::box_::{Box, ImageBox, ScannedTextBox}; use layout::box_::{Fragment, ImageFragment, ScannedTextFragment};
use layout::construct::FlowConstructor; use layout::construct::FlowConstructor;
use layout::context::LayoutContext; use layout::context::LayoutContext;
use layout::floats::{ClearBoth, ClearLeft, ClearRight, FloatKind, Floats, PlacementInfo}; use layout::floats::{ClearBoth, ClearLeft, ClearRight, FloatKind, Floats, PlacementInfo};
@ -41,7 +41,6 @@ use servo_util::geometry;
use std::fmt; use std::fmt;
use std::mem; use std::mem;
use std::num::Zero; use std::num::Zero;
use std::owned;
use style::computed_values::{LPA_Auto, LPA_Length, LPA_Percentage, LPN_Length, LPN_None}; use style::computed_values::{LPA_Auto, LPA_Length, LPA_Percentage, LPN_Length, LPN_None};
use style::computed_values::{LPN_Percentage, LP_Length, LP_Percentage, display, float, overflow}; use style::computed_values::{LPN_Percentage, LP_Length, LP_Percentage, display, float, overflow};
use sync::Arc; use sync::Arc;
@ -490,7 +489,7 @@ pub struct BlockFlow {
pub base: BaseFlow, pub base: BaseFlow,
/// The associated box. /// The associated box.
pub box_: Box, pub box_: Fragment,
/// TODO: is_root should be a bit field to conserve memory. /// TODO: is_root should be a bit field to conserve memory.
/// Whether this block flow is the root flow. /// Whether this block flow is the root flow.
@ -504,14 +503,14 @@ pub struct BlockFlow {
previous_float_width: Option<Au>, previous_float_width: Option<Au>,
/// Additional floating flow members. /// Additional floating flow members.
pub float: Option<owned::Box<FloatedBlockInfo>> pub float: Option<Box<FloatedBlockInfo>>
} }
impl BlockFlow { impl BlockFlow {
pub fn from_node(constructor: &mut FlowConstructor, node: &ThreadSafeLayoutNode) -> BlockFlow { pub fn from_node(constructor: &mut FlowConstructor, node: &ThreadSafeLayoutNode) -> BlockFlow {
BlockFlow { BlockFlow {
base: BaseFlow::new((*node).clone()), base: BaseFlow::new((*node).clone()),
box_: Box::new(constructor, node), box_: Fragment::new(constructor, node),
is_root: false, is_root: false,
static_y_offset: Au::new(0), static_y_offset: Au::new(0),
previous_float_width: None, previous_float_width: None,
@ -519,7 +518,7 @@ impl BlockFlow {
} }
} }
pub fn from_node_and_box(node: &ThreadSafeLayoutNode, box_: Box) -> BlockFlow { pub fn from_node_and_box(node: &ThreadSafeLayoutNode, box_: Fragment) -> BlockFlow {
BlockFlow { BlockFlow {
base: BaseFlow::new((*node).clone()), base: BaseFlow::new((*node).clone()),
box_: box_, box_: box_,
@ -536,7 +535,7 @@ impl BlockFlow {
-> BlockFlow { -> BlockFlow {
BlockFlow { BlockFlow {
base: BaseFlow::new((*node).clone()), base: BaseFlow::new((*node).clone()),
box_: Box::new(constructor, node), box_: Fragment::new(constructor, node),
is_root: false, is_root: false,
static_y_offset: Au::new(0), static_y_offset: Au::new(0),
previous_float_width: None, previous_float_width: None,
@ -602,7 +601,7 @@ impl BlockFlow {
} }
/// Return this flow's box. /// Return this flow's box.
pub fn box_<'a>(&'a mut self) -> &'a mut Box { pub fn box_<'a>(&'a mut self) -> &'a mut Fragment {
&mut self.box_ &mut self.box_
} }
@ -705,7 +704,7 @@ impl BlockFlow {
/// image boxes. /// image boxes.
fn is_replaced_content(&self) -> bool { fn is_replaced_content(&self) -> bool {
match self.box_.specific { match self.box_.specific {
ScannedTextBox(_) | ImageBox(_) => true, ScannedTextFragment(_) | ImageFragment(_) => true,
_ => false, _ => false,
} }
} }
@ -1203,11 +1202,11 @@ impl BlockFlow {
let available_height = containing_block_height - self.box_.border_padding.vertical(); let available_height = containing_block_height - self.box_.border_padding.vertical();
if self.is_replaced_content() { if self.is_replaced_content() {
// Calculate used value of height just like we do for inline replaced elements. // Calculate used value of height just like we do for inline replaced elements.
// TODO: Pass in the containing block height when Box's // TODO: Pass in the containing block height when Fragment's
// assign-height can handle it correctly. // assign-height can handle it correctly.
self.box_.assign_replaced_height_if_necessary(); self.box_.assign_replaced_height_if_necessary();
// TODO: Right now, this content height value includes the // TODO: Right now, this content height value includes the
// margin because of erroneous height calculation in Box_. // margin because of erroneous height calculation in box_.
// Check this when that has been fixed. // Check this when that has been fixed.
let height_used_val = self.box_.border_box.size.height; let height_used_val = self.box_.border_box.size.height;
solution = Some(HeightConstraintSolution::solve_vertical_constraints_abs_replaced( solution = Some(HeightConstraintSolution::solve_vertical_constraints_abs_replaced(
@ -1289,7 +1288,7 @@ impl BlockFlow {
self.base.layers.push_back(new_layer) self.base.layers.push_back(new_layer)
} }
/// Return the top outer edge of the Hypothetical Box for an absolute flow. /// Return the top outer edge of the Hypothetical Fragment for an absolute flow.
/// ///
/// This is wrt its parent flow box. /// This is wrt its parent flow box.
/// ///
@ -1404,7 +1403,7 @@ impl BlockFlow {
display::table_cell | display::table_caption | display::inline_block => { display::table_cell | display::table_caption | display::inline_block => {
OtherFormattingContext OtherFormattingContext
} }
_ if style.get_box().position == position::static_ && _ if style.get_box().position == position::static_ &&
style.get_box().overflow != overflow::visible => { style.get_box().overflow != overflow::visible => {
BlockFormattingContext BlockFormattingContext
} }

View file

@ -44,7 +44,6 @@ use std::from_str::FromStr;
use std::iter::AdditiveIterator; use std::iter::AdditiveIterator;
use std::mem; use std::mem;
use std::num::Zero; use std::num::Zero;
use std::owned;
use style::{ComputedValues, TElement, TNode, cascade_anonymous}; use style::{ComputedValues, TElement, TNode, cascade_anonymous};
use style::computed_values::{LengthOrPercentageOrAuto, overflow, LPA_Auto, background_attachment}; use style::computed_values::{LengthOrPercentageOrAuto, overflow, LPA_Auto, background_attachment};
use style::computed_values::{background_repeat, border_style, clear, position, text_align}; use style::computed_values::{background_repeat, border_style, clear, position, text_align};
@ -64,7 +63,7 @@ use url::Url;
/// positioned as if it were a block box, but its children are positioned according to inline /// positioned as if it were a block box, but its children are positioned according to inline
/// flow. /// flow.
/// ///
/// A `GenericBox` is an empty box that contributes only borders, margins, padding, and /// A `GenericFragment` is an empty box that contributes only borders, margins, padding, and
/// backgrounds. It is analogous to a CSS nonreplaced content box. /// backgrounds. It is analogous to a CSS nonreplaced content box.
/// ///
/// A box's type influences how its styles are interpreted during layout. For example, replaced /// A box's type influences how its styles are interpreted during layout. For example, replaced
@ -73,8 +72,8 @@ use url::Url;
/// ///
/// FIXME(#2260, pcwalton): This can be slimmed down some. /// FIXME(#2260, pcwalton): This can be slimmed down some.
#[deriving(Clone)] #[deriving(Clone)]
pub struct Box { pub struct Fragment {
/// An opaque reference to the DOM node that this `Box` originates from. /// An opaque reference to the DOM node that this `Fragment` originates from.
pub node: OpaqueNode, pub node: OpaqueNode,
/// The CSS style of this box. /// The CSS style of this box.
@ -92,7 +91,7 @@ pub struct Box {
pub margin: SideOffsets2D<Au>, pub margin: SideOffsets2D<Au>,
/// Info specific to the kind of box. Keep this enum small. /// Info specific to the kind of box. Keep this enum small.
pub specific: SpecificBoxInfo, pub specific: SpecificFragmentInfo,
/// New-line chracter(\n)'s positions(relative, not absolute) /// New-line chracter(\n)'s positions(relative, not absolute)
/// ///
@ -102,22 +101,22 @@ pub struct Box {
/// Info specific to the kind of box. Keep this enum small. /// Info specific to the kind of box. Keep this enum small.
#[deriving(Clone)] #[deriving(Clone)]
pub enum SpecificBoxInfo { pub enum SpecificFragmentInfo {
GenericBox, GenericFragment,
ImageBox(ImageBoxInfo), ImageFragment(ImageFragmentInfo),
IframeBox(IframeBoxInfo), IframeFragment(IframeFragmentInfo),
ScannedTextBox(ScannedTextBoxInfo), ScannedTextFragment(ScannedTextFragmentInfo),
TableBox, TableFragment,
TableCellBox, TableCellFragment,
TableColumnBox(TableColumnBoxInfo), TableColumnFragment(TableColumnFragmentInfo),
TableRowBox, TableRowFragment,
TableWrapperBox, TableWrapperFragment,
UnscannedTextBox(UnscannedTextBoxInfo), UnscannedTextFragment(UnscannedTextFragmentInfo),
} }
/// A box that represents a replaced content image and its accompanying borders, shadows, etc. /// A box that represents a replaced content image and its accompanying borders, shadows, etc.
#[deriving(Clone)] #[deriving(Clone)]
pub struct ImageBoxInfo { pub struct ImageFragmentInfo {
/// The image held within this box. /// The image held within this box.
pub image: ImageHolder, pub image: ImageHolder,
pub computed_width: Option<Au>, pub computed_width: Option<Au>,
@ -126,7 +125,7 @@ pub struct ImageBoxInfo {
pub dom_height: Option<Au>, pub dom_height: Option<Au>,
} }
impl ImageBoxInfo { impl ImageFragmentInfo {
/// Creates a new image box from the given URL and local image cache. /// Creates a new image box from the given URL and local image cache.
/// ///
/// FIXME(pcwalton): The fact that image boxes store the cache in the box makes little sense to /// FIXME(pcwalton): The fact that image boxes store the cache in the box makes little sense to
@ -134,7 +133,7 @@ impl ImageBoxInfo {
pub fn new(node: &ThreadSafeLayoutNode, pub fn new(node: &ThreadSafeLayoutNode,
image_url: Url, image_url: Url,
local_image_cache: LocalImageCacheHandle) local_image_cache: LocalImageCacheHandle)
-> ImageBoxInfo { -> ImageFragmentInfo {
fn convert_length(node: &ThreadSafeLayoutNode, name: &str) -> Option<Au> { fn convert_length(node: &ThreadSafeLayoutNode, name: &str) -> Option<Au> {
let element = node.as_element(); let element = node.as_element();
element.get_attr(&namespace::Null, name).and_then(|string| { element.get_attr(&namespace::Null, name).and_then(|string| {
@ -143,7 +142,7 @@ impl ImageBoxInfo {
}).and_then(|pixels| Some(Au::from_px(pixels))) }).and_then(|pixels| Some(Au::from_px(pixels)))
} }
ImageBoxInfo { ImageFragmentInfo {
image: ImageHolder::new(image_url, local_image_cache), image: ImageHolder::new(image_url, local_image_cache),
computed_width: None, computed_width: None,
computed_height: None, computed_height: None,
@ -200,18 +199,18 @@ impl ImageBoxInfo {
/// A box that represents an inline frame (iframe). This stores the pipeline ID so that the size /// A box that represents an inline frame (iframe). This stores the pipeline ID so that the size
/// of this iframe can be communicated via the constellation to the iframe's own layout task. /// of this iframe can be communicated via the constellation to the iframe's own layout task.
#[deriving(Clone)] #[deriving(Clone)]
pub struct IframeBoxInfo { pub struct IframeFragmentInfo {
/// The pipeline ID of this iframe. /// The pipeline ID of this iframe.
pub pipeline_id: PipelineId, pub pipeline_id: PipelineId,
/// The subpage ID of this iframe. /// The subpage ID of this iframe.
pub subpage_id: SubpageId, pub subpage_id: SubpageId,
} }
impl IframeBoxInfo { impl IframeFragmentInfo {
/// Creates the information specific to an iframe box. /// Creates the information specific to an iframe box.
pub fn new(node: &ThreadSafeLayoutNode) -> IframeBoxInfo { pub fn new(node: &ThreadSafeLayoutNode) -> IframeFragmentInfo {
let (pipeline_id, subpage_id) = node.iframe_pipeline_and_subpage_ids(); let (pipeline_id, subpage_id) = node.iframe_pipeline_and_subpage_ids();
IframeBoxInfo { IframeFragmentInfo {
pipeline_id: pipeline_id, pipeline_id: pipeline_id,
subpage_id: subpage_id, subpage_id: subpage_id,
} }
@ -223,18 +222,18 @@ impl IframeBoxInfo {
/// DOM text node. Split text boxes are implemented by referring to subsets of a single `TextRun` /// DOM text node. Split text boxes are implemented by referring to subsets of a single `TextRun`
/// object. /// object.
#[deriving(Clone)] #[deriving(Clone)]
pub struct ScannedTextBoxInfo { pub struct ScannedTextFragmentInfo {
/// The text run that this represents. /// The text run that this represents.
pub run: Arc<owned::Box<TextRun>>, pub run: Arc<Box<TextRun>>,
/// The range within the above text run that this represents. /// The range within the above text run that this represents.
pub range: Range<CharIndex>, pub range: Range<CharIndex>,
} }
impl ScannedTextBoxInfo { impl ScannedTextFragmentInfo {
/// Creates the information specific to a scanned text box from a range and a text run. /// Creates the information specific to a scanned text box from a range and a text run.
pub fn new(run: Arc<owned::Box<TextRun>>, range: Range<CharIndex>) -> ScannedTextBoxInfo { pub fn new(run: Arc<Box<TextRun>>, range: Range<CharIndex>) -> ScannedTextFragmentInfo {
ScannedTextBoxInfo { ScannedTextFragmentInfo {
run: run, run: run,
range: range, range: range,
} }
@ -250,7 +249,7 @@ pub struct SplitInfo {
} }
impl SplitInfo { impl SplitInfo {
fn new(range: Range<CharIndex>, info: &ScannedTextBoxInfo) -> SplitInfo { fn new(range: Range<CharIndex>, info: &ScannedTextFragmentInfo) -> SplitInfo {
SplitInfo { SplitInfo {
range: range, range: range,
width: info.run.advance_for_range(&range), width: info.run.advance_for_range(&range),
@ -261,24 +260,24 @@ impl SplitInfo {
/// Data for an unscanned text box. Unscanned text boxes are the results of flow construction that /// Data for an unscanned text box. Unscanned text boxes are the results of flow construction that
/// have not yet had their width determined. /// have not yet had their width determined.
#[deriving(Clone)] #[deriving(Clone)]
pub struct UnscannedTextBoxInfo { pub struct UnscannedTextFragmentInfo {
/// The text inside the box. /// The text inside the box.
pub text: ~str, pub text: ~str,
} }
impl UnscannedTextBoxInfo { impl UnscannedTextFragmentInfo {
/// Creates a new instance of `UnscannedTextBoxInfo` from the given DOM node. /// Creates a new instance of `UnscannedTextFragmentInfo` from the given DOM node.
pub fn new(node: &ThreadSafeLayoutNode) -> UnscannedTextBoxInfo { pub fn new(node: &ThreadSafeLayoutNode) -> UnscannedTextFragmentInfo {
// FIXME(pcwalton): Don't copy text; atomically reference count it instead. // FIXME(pcwalton): Don't copy text; atomically reference count it instead.
UnscannedTextBoxInfo { UnscannedTextFragmentInfo {
text: node.text(), text: node.text(),
} }
} }
/// Creates a new instance of `UnscannedTextBoxInfo` from the given text. /// Creates a new instance of `UnscannedTextFragmentInfo` from the given text.
#[inline] #[inline]
pub fn from_text(text: ~str) -> UnscannedTextBoxInfo { pub fn from_text(text: ~str) -> UnscannedTextFragmentInfo {
UnscannedTextBoxInfo { UnscannedTextFragmentInfo {
text: text, text: text,
} }
} }
@ -286,14 +285,14 @@ impl UnscannedTextBoxInfo {
/// A box that represents a table column. /// A box that represents a table column.
#[deriving(Clone)] #[deriving(Clone)]
pub struct TableColumnBoxInfo { pub struct TableColumnFragmentInfo {
/// the number of columns a <col> element should span /// the number of columns a <col> element should span
pub span: Option<int>, pub span: Option<int>,
} }
impl TableColumnBoxInfo { impl TableColumnFragmentInfo {
/// Create the information specific to an table column box. /// Create the information specific to an table column box.
pub fn new(node: &ThreadSafeLayoutNode) -> TableColumnBoxInfo { pub fn new(node: &ThreadSafeLayoutNode) -> TableColumnFragmentInfo {
let span = { let span = {
let element = node.as_element(); let element = node.as_element();
element.get_attr(&namespace::Null, "span").and_then(|string| { element.get_attr(&namespace::Null, "span").and_then(|string| {
@ -301,22 +300,22 @@ impl TableColumnBoxInfo {
n n
}) })
}; };
TableColumnBoxInfo { TableColumnFragmentInfo {
span: span, span: span,
} }
} }
} }
impl Box { impl Fragment {
/// Constructs a new `Box` instance for the given node. /// Constructs a new `Fragment` instance for the given node.
/// ///
/// Arguments: /// Arguments:
/// ///
/// * `constructor`: The flow constructor. /// * `constructor`: The flow constructor.
/// ///
/// * `node`: The node to create a box for. /// * `node`: The node to create a box for.
pub fn new(constructor: &mut FlowConstructor, node: &ThreadSafeLayoutNode) -> Box { pub fn new(constructor: &mut FlowConstructor, node: &ThreadSafeLayoutNode) -> Fragment {
Box { Fragment {
node: OpaqueNodeMethods::from_thread_safe_layout_node(node), node: OpaqueNodeMethods::from_thread_safe_layout_node(node),
style: node.style().clone(), style: node.style().clone(),
border_box: Rect::zero(), border_box: Rect::zero(),
@ -327,9 +326,9 @@ impl Box {
} }
} }
/// Constructs a new `Box` instance from a specific info. /// Constructs a new `Fragment` instance from a specific info.
pub fn new_from_specific_info(node: &ThreadSafeLayoutNode, specific: SpecificBoxInfo) -> Box { pub fn new_from_specific_info(node: &ThreadSafeLayoutNode, specific: SpecificFragmentInfo) -> Fragment {
Box { Fragment {
node: OpaqueNodeMethods::from_thread_safe_layout_node(node), node: OpaqueNodeMethods::from_thread_safe_layout_node(node),
style: node.style().clone(), style: node.style().clone(),
border_box: Rect::zero(), border_box: Rect::zero(),
@ -340,8 +339,8 @@ impl Box {
} }
} }
/// Constructs a new `Box` instance for an anonymous table object. /// Constructs a new `Fragment` instance for an anonymous table object.
pub fn new_anonymous_table_box(node: &ThreadSafeLayoutNode, specific: SpecificBoxInfo) -> Box { pub fn new_anonymous_table_box(node: &ThreadSafeLayoutNode, specific: SpecificFragmentInfo) -> Fragment {
// CSS 2.1 § 17.2.1 This is for non-inherited properties on anonymous table boxes // CSS 2.1 § 17.2.1 This is for non-inherited properties on anonymous table boxes
// example: // example:
// //
@ -349,10 +348,10 @@ impl Box {
// Foo // Foo
// </div> // </div>
// //
// Anonymous table boxes, TableRowBox and TableCellBox, are generated around `Foo`, but it shouldn't inherit the border. // Anonymous table boxes, TableRowFragment and TableCellFragment, are generated around `Foo`, but it shouldn't inherit the border.
let node_style = cascade_anonymous(&**node.style()); let node_style = cascade_anonymous(&**node.style());
Box { Fragment {
node: OpaqueNodeMethods::from_thread_safe_layout_node(node), node: OpaqueNodeMethods::from_thread_safe_layout_node(node),
style: Arc::new(node_style), style: Arc::new(node_style),
border_box: Rect::zero(), border_box: Rect::zero(),
@ -363,12 +362,12 @@ impl Box {
} }
} }
/// Constructs a new `Box` instance from an opaque node. /// Constructs a new `Fragment` instance from an opaque node.
pub fn from_opaque_node_and_style(node: OpaqueNode, pub fn from_opaque_node_and_style(node: OpaqueNode,
style: Arc<ComputedValues>, style: Arc<ComputedValues>,
specific: SpecificBoxInfo) specific: SpecificFragmentInfo)
-> Box { -> Fragment {
Box { Fragment {
node: node, node: node,
style: style, style: style,
border_box: Rect::zero(), border_box: Rect::zero(),
@ -389,8 +388,8 @@ impl Box {
/// Transforms this box into another box of the given type, with the given size, preserving all /// Transforms this box into another box of the given type, with the given size, preserving all
/// the other data. /// the other data.
pub fn transform(&self, size: Size2D<Au>, specific: SpecificBoxInfo) -> Box { pub fn transform(&self, size: Size2D<Au>, specific: SpecificFragmentInfo) -> Fragment {
Box { Fragment {
node: self.node, node: self.node,
style: self.style.clone(), style: self.style.clone(),
border_box: Rect(self.border_box.origin, size), border_box: Rect(self.border_box.origin, size),
@ -405,11 +404,11 @@ impl Box {
/// replaced elements. /// replaced elements.
fn style_specified_intrinsic_width(&self) -> IntrinsicWidths { fn style_specified_intrinsic_width(&self) -> IntrinsicWidths {
let (use_margins, use_padding) = match self.specific { let (use_margins, use_padding) = match self.specific {
GenericBox | IframeBox(_) | ImageBox(_) => (true, true), GenericFragment | IframeFragment(_) | ImageFragment(_) => (true, true),
TableBox | TableCellBox => (false, true), TableFragment | TableCellFragment => (false, true),
TableWrapperBox => (true, false), TableWrapperFragment => (true, false),
TableRowBox => (false, false), TableRowFragment => (false, false),
ScannedTextBox(_) | TableColumnBox(_) | UnscannedTextBox(_) => { ScannedTextFragment(_) | TableColumnFragment(_) | UnscannedTextFragment(_) => {
// Styles are irrelevant for these kinds of boxes. // Styles are irrelevant for these kinds of boxes.
return IntrinsicWidths::new() return IntrinsicWidths::new()
} }
@ -471,7 +470,7 @@ impl Box {
// Compute vertical margins. Note that this value will be ignored by layout if the style // Compute vertical margins. Note that this value will be ignored by layout if the style
// specifies `auto`. // specifies `auto`.
match self.specific { match self.specific {
TableBox | TableCellBox | TableRowBox | TableColumnBox(_) => { TableFragment | TableCellFragment | TableRowFragment | TableColumnFragment(_) => {
self.margin.top = Au(0); self.margin.top = Au(0);
self.margin.bottom = Au(0) self.margin.bottom = Au(0)
} }
@ -496,7 +495,7 @@ impl Box {
// Compute padding. // Compute padding.
let padding = match self.specific { let padding = match self.specific {
TableColumnBox(_) | TableRowBox | TableWrapperBox => Zero::zero(), TableColumnFragment(_) | TableRowFragment | TableWrapperFragment => Zero::zero(),
_ => { _ => {
match inline_fragment_context { match inline_fragment_context {
None => model::padding_from_style(self.style(), containing_block_width), None => model::padding_from_style(self.style(), containing_block_width),
@ -621,9 +620,9 @@ impl Box {
/// inlines. /// inlines.
pub fn left_offset(&self) -> Au { pub fn left_offset(&self) -> Au {
match self.specific { match self.specific {
TableWrapperBox => self.margin.left, TableWrapperFragment => self.margin.left,
TableBox | TableCellBox | TableRowBox => self.border_padding.left, TableFragment | TableCellFragment | TableRowFragment => self.border_padding.left,
TableColumnBox(_) => Au(0), TableColumnFragment(_) => Au(0),
_ => self.margin.left + self.border_padding.left, _ => self.margin.left + self.border_padding.left,
} }
} }
@ -631,7 +630,7 @@ impl Box {
/// Returns true if this element can be split. This is true for text boxes. /// Returns true if this element can be split. This is true for text boxes.
pub fn can_split(&self) -> bool { pub fn can_split(&self) -> bool {
match self.specific { match self.specific {
ScannedTextBox(..) => true, ScannedTextFragment(..) => true,
_ => false, _ => false,
} }
} }
@ -782,7 +781,7 @@ impl Box {
fn build_debug_borders_around_text_boxes(&self, fn build_debug_borders_around_text_boxes(&self,
display_list: &mut DisplayList, display_list: &mut DisplayList,
flow_origin: Point2D<Au>, flow_origin: Point2D<Au>,
text_box: &ScannedTextBoxInfo) { text_box: &ScannedTextFragmentInfo) {
let box_bounds = self.border_box; let box_bounds = self.border_box;
let absolute_box_bounds = box_bounds.translate(&flow_origin); let absolute_box_bounds = box_bounds.translate(&flow_origin);
@ -844,14 +843,14 @@ impl Box {
background_and_border_level: BackgroundAndBorderLevel, background_and_border_level: BackgroundAndBorderLevel,
inline_fragment_context: Option<InlineFragmentContext>) inline_fragment_context: Option<InlineFragmentContext>)
-> ChildDisplayListAccumulator { -> ChildDisplayListAccumulator {
// Box position wrt to the owning flow. // Fragment position wrt to the owning flow.
let box_bounds = self.border_box; let box_bounds = self.border_box;
let absolute_box_bounds = box_bounds.translate(&flow_origin); let absolute_box_bounds = box_bounds.translate(&flow_origin);
debug!("Box::build_display_list at rel={}, abs={}: {}", debug!("Fragment::build_display_list at rel={}, abs={}: {}",
box_bounds, box_bounds,
absolute_box_bounds, absolute_box_bounds,
self); self);
debug!("Box::build_display_list: dirty={}, flow_origin={}", debug!("Fragment::build_display_list: dirty={}, flow_origin={}",
layout_context.dirty, layout_context.dirty,
flow_origin); flow_origin);
@ -864,11 +863,11 @@ impl Box {
} }
if !absolute_box_bounds.intersects(&layout_context.dirty) { if !absolute_box_bounds.intersects(&layout_context.dirty) {
debug!("Box::build_display_list: Did not intersect..."); debug!("Fragment::build_display_list: Did not intersect...");
return accumulator return accumulator
} }
debug!("Box::build_display_list: intersected. Adding display item..."); debug!("Fragment::build_display_list: intersected. Adding display item...");
{ {
let level = let level =
@ -895,9 +894,9 @@ impl Box {
// Add a clip, if applicable. // Add a clip, if applicable.
match self.specific { match self.specific {
UnscannedTextBox(_) => fail!("Shouldn't see unscanned boxes here."), UnscannedTextFragment(_) => fail!("Shouldn't see unscanned boxes here."),
TableColumnBox(_) => fail!("Shouldn't see table column boxes here."), TableColumnFragment(_) => fail!("Shouldn't see table column boxes here."),
ScannedTextBox(ref text_box) => { ScannedTextFragment(ref text_box) => {
// Compute text color. // Compute text color.
let text_color = self.style().get_color().color.to_gfx_color(); let text_color = self.style().get_color().color.to_gfx_color();
@ -934,13 +933,13 @@ impl Box {
flow_origin, flow_origin,
text_box)) text_box))
}, },
GenericBox | IframeBox(..) | TableBox | TableCellBox | TableRowBox | GenericFragment | IframeFragment(..) | TableFragment | TableCellFragment | TableRowFragment |
TableWrapperBox => { TableWrapperFragment => {
// FIXME(pcwalton): This is a bit of an abuse of the logging infrastructure. We // FIXME(pcwalton): This is a bit of an abuse of the logging infrastructure. We
// should have a real `SERVO_DEBUG` system. // should have a real `SERVO_DEBUG` system.
debug!("{:?}", self.build_debug_borders_around_box(display_list, flow_origin)) debug!("{:?}", self.build_debug_borders_around_box(display_list, flow_origin))
}, },
ImageBox(_) => { ImageFragment(_) => {
let mut bounds = absolute_box_bounds.clone(); let mut bounds = absolute_box_bounds.clone();
bounds.origin.x = bounds.origin.x + self.border_padding.left; bounds.origin.x = bounds.origin.x + self.border_padding.left;
bounds.origin.y = bounds.origin.y + self.border_padding.top; bounds.origin.y = bounds.origin.y + self.border_padding.top;
@ -948,7 +947,7 @@ impl Box {
bounds.size.height = bounds.size.height - self.border_padding.vertical(); bounds.size.height = bounds.size.height - self.border_padding.vertical();
match self.specific { match self.specific {
ImageBox(ref image_box) => { ImageFragment(ref image_box) => {
let image_ref = &image_box.image; let image_ref = &image_box.image;
match image_ref.get_image_if_present() { match image_ref.get_image_if_present() {
Some(image) => { Some(image) => {
@ -993,7 +992,7 @@ impl Box {
// layout for the iframe only needs to know size, and origin is only relevant if the // layout for the iframe only needs to know size, and origin is only relevant if the
// iframe is actually going to be displayed. // iframe is actually going to be displayed.
match self.specific { match self.specific {
IframeBox(ref iframe_box) => { IframeFragment(ref iframe_box) => {
self.finalize_position_and_size_of_iframe(iframe_box, flow_origin, layout_context) self.finalize_position_and_size_of_iframe(iframe_box, flow_origin, layout_context)
} }
_ => {} _ => {}
@ -1008,14 +1007,14 @@ impl Box {
let mut result = self.style_specified_intrinsic_width(); let mut result = self.style_specified_intrinsic_width();
match self.specific { match self.specific {
GenericBox | IframeBox(_) | TableBox | TableCellBox | TableColumnBox(_) | TableRowBox | GenericFragment | IframeFragment(_) | TableFragment | TableCellFragment | TableColumnFragment(_) | TableRowFragment |
TableWrapperBox => {} TableWrapperFragment => {}
ImageBox(ref mut image_box_info) => { ImageFragment(ref mut image_box_info) => {
let image_width = image_box_info.image_width(); let image_width = image_box_info.image_width();
result.minimum_width = geometry::max(result.minimum_width, image_width); result.minimum_width = geometry::max(result.minimum_width, image_width);
result.preferred_width = geometry::max(result.preferred_width, image_width); result.preferred_width = geometry::max(result.preferred_width, image_width);
} }
ScannedTextBox(ref text_box_info) => { ScannedTextFragment(ref text_box_info) => {
let range = &text_box_info.range; let range = &text_box_info.range;
let min_line_width = text_box_info.run.min_width_for_range(range); let min_line_width = text_box_info.run.min_width_for_range(range);
@ -1028,7 +1027,7 @@ impl Box {
result.minimum_width = geometry::max(result.minimum_width, min_line_width); result.minimum_width = geometry::max(result.minimum_width, min_line_width);
result.preferred_width = geometry::max(result.preferred_width, max_line_width); result.preferred_width = geometry::max(result.preferred_width, max_line_width);
} }
UnscannedTextBox(..) => fail!("Unscanned text boxes should have been scanned by now!"), UnscannedTextFragment(..) => fail!("Unscanned text boxes should have been scanned by now!"),
} }
// Take borders and padding for parent inline boxes into account, if necessary. // Take borders and padding for parent inline boxes into account, if necessary.
@ -1048,33 +1047,33 @@ impl Box {
} }
/// TODO: What exactly does this function return? Why is it Au(0) for GenericBox? /// TODO: What exactly does this function return? Why is it Au(0) for GenericFragment?
pub fn content_width(&self) -> Au { pub fn content_width(&self) -> Au {
match self.specific { match self.specific {
GenericBox | IframeBox(_) | TableBox | TableCellBox | TableRowBox | GenericFragment | IframeFragment(_) | TableFragment | TableCellFragment | TableRowFragment |
TableWrapperBox => Au(0), TableWrapperFragment => Au(0),
ImageBox(ref image_box_info) => { ImageFragment(ref image_box_info) => {
image_box_info.computed_width() image_box_info.computed_width()
} }
ScannedTextBox(ref text_box_info) => { ScannedTextFragment(ref text_box_info) => {
let (range, run) = (&text_box_info.range, &text_box_info.run); let (range, run) = (&text_box_info.range, &text_box_info.run);
let text_bounds = run.metrics_for_range(range).bounding_box; let text_bounds = run.metrics_for_range(range).bounding_box;
text_bounds.size.width text_bounds.size.width
} }
TableColumnBox(_) => fail!("Table column boxes do not have width"), TableColumnFragment(_) => fail!("Table column boxes do not have width"),
UnscannedTextBox(_) => fail!("Unscanned text boxes should have been scanned by now!"), UnscannedTextFragment(_) => fail!("Unscanned text boxes should have been scanned by now!"),
} }
} }
/// Returns, and computes, the height of this box. /// Returns, and computes, the height of this box.
pub fn content_height(&self) -> Au { pub fn content_height(&self) -> Au {
match self.specific { match self.specific {
GenericBox | IframeBox(_) | TableBox | TableCellBox | TableRowBox | GenericFragment | IframeFragment(_) | TableFragment | TableCellFragment | TableRowFragment |
TableWrapperBox => Au(0), TableWrapperFragment => Au(0),
ImageBox(ref image_box_info) => { ImageFragment(ref image_box_info) => {
image_box_info.computed_height() image_box_info.computed_height()
} }
ScannedTextBox(ref text_box_info) => { ScannedTextFragment(ref text_box_info) => {
// Compute the height based on the line-height and font size. // Compute the height based on the line-height and font size.
// //
// FIXME(pcwalton): Shouldn't we use the value of the `font-size` property below // FIXME(pcwalton): Shouldn't we use the value of the `font-size` property below
@ -1084,8 +1083,8 @@ impl Box {
let em_size = text_bounds.size.height; let em_size = text_bounds.size.height;
self.calculate_line_height(em_size) self.calculate_line_height(em_size)
} }
TableColumnBox(_) => fail!("Table column boxes do not have height"), TableColumnFragment(_) => fail!("Table column boxes do not have height"),
UnscannedTextBox(_) => fail!("Unscanned text boxes should have been scanned by now!"), UnscannedTextFragment(_) => fail!("Unscanned text boxes should have been scanned by now!"),
} }
} }
@ -1112,13 +1111,13 @@ impl Box {
// TODO(bjz): The text run should be removed in the future, but it is currently needed for // TODO(bjz): The text run should be removed in the future, but it is currently needed for
// the current method of box splitting in the `inline::try_append_*` functions. // the current method of box splitting in the `inline::try_append_*` functions.
pub fn find_split_info_by_new_line(&self) pub fn find_split_info_by_new_line(&self)
-> Option<(SplitInfo, Option<SplitInfo>, Arc<owned::Box<TextRun>> /* TODO(bjz): remove */)> { -> Option<(SplitInfo, Option<SplitInfo>, Arc<Box<TextRun>> /* TODO(bjz): remove */)> {
match self.specific { match self.specific {
GenericBox | IframeBox(_) | ImageBox(_) | TableBox | TableCellBox | GenericFragment | IframeFragment(_) | ImageFragment(_) | TableFragment | TableCellFragment |
TableRowBox | TableWrapperBox => None, TableRowFragment | TableWrapperFragment => None,
TableColumnBox(_) => fail!("Table column boxes do not need to split"), TableColumnFragment(_) => fail!("Table column boxes do not need to split"),
UnscannedTextBox(_) => fail!("Unscanned text boxes should have been scanned by now!"), UnscannedTextFragment(_) => fail!("Unscanned text boxes should have been scanned by now!"),
ScannedTextBox(ref text_box_info) => { ScannedTextFragment(ref text_box_info) => {
let mut new_line_pos = self.new_line_pos.clone(); let mut new_line_pos = self.new_line_pos.clone();
let cur_new_line_pos = new_line_pos.shift().unwrap(); let cur_new_line_pos = new_line_pos.shift().unwrap();
@ -1152,13 +1151,13 @@ impl Box {
// TODO(bjz): The text run should be removed in the future, but it is currently needed for // TODO(bjz): The text run should be removed in the future, but it is currently needed for
// the current method of box splitting in the `inline::try_append_*` functions. // the current method of box splitting in the `inline::try_append_*` functions.
pub fn find_split_info_for_width(&self, start: CharIndex, max_width: Au, starts_line: bool) pub fn find_split_info_for_width(&self, start: CharIndex, max_width: Au, starts_line: bool)
-> Option<(Option<SplitInfo>, Option<SplitInfo>, Arc<owned::Box<TextRun>> /* TODO(bjz): remove */)> { -> Option<(Option<SplitInfo>, Option<SplitInfo>, Arc<Box<TextRun>> /* TODO(bjz): remove */)> {
match self.specific { match self.specific {
GenericBox | IframeBox(_) | ImageBox(_) | TableBox | TableCellBox | GenericFragment | IframeFragment(_) | ImageFragment(_) | TableFragment | TableCellFragment |
TableRowBox | TableWrapperBox => None, TableRowFragment | TableWrapperFragment => None,
TableColumnBox(_) => fail!("Table column boxes do not have width"), TableColumnFragment(_) => fail!("Table column boxes do not have width"),
UnscannedTextBox(_) => fail!("Unscanned text boxes should have been scanned by now!"), UnscannedTextFragment(_) => fail!("Unscanned text boxes should have been scanned by now!"),
ScannedTextBox(ref text_box_info) => { ScannedTextFragment(ref text_box_info) => {
let mut pieces_processed_count: uint = 0; let mut pieces_processed_count: uint = 0;
let mut remaining_width: Au = max_width; let mut remaining_width: Au = max_width;
let mut left_range = Range::new(text_box_info.range.begin() + start, CharIndex(0)); let mut left_range = Range::new(text_box_info.range.begin() + start, CharIndex(0));
@ -1249,7 +1248,7 @@ impl Box {
/// Returns true if this box is an unscanned text box that consists entirely of whitespace. /// Returns true if this box is an unscanned text box that consists entirely of whitespace.
pub fn is_whitespace_only(&self) -> bool { pub fn is_whitespace_only(&self) -> bool {
match self.specific { match self.specific {
UnscannedTextBox(ref text_box_info) => is_whitespace(text_box_info.text), UnscannedTextFragment(ref text_box_info) => is_whitespace(text_box_info.text),
_ => false, _ => false,
} }
} }
@ -1261,11 +1260,11 @@ impl Box {
inline_fragment_context: inline_fragment_context:
Option<InlineFragmentContext>) { Option<InlineFragmentContext>) {
match self.specific { match self.specific {
GenericBox | IframeBox(_) | TableBox | TableCellBox | TableRowBox | GenericFragment | IframeFragment(_) | TableFragment | TableCellFragment | TableRowFragment |
TableWrapperBox => return, TableWrapperFragment => return,
TableColumnBox(_) => fail!("Table column boxes do not have width"), TableColumnFragment(_) => fail!("Table column boxes do not have width"),
UnscannedTextBox(_) => fail!("Unscanned text boxes should have been scanned by now!"), UnscannedTextFragment(_) => fail!("Unscanned text boxes should have been scanned by now!"),
ImageBox(_) | ScannedTextBox(_) => {} ImageFragment(_) | ScannedTextFragment(_) => {}
}; };
self.compute_border_padding_margins(container_width, inline_fragment_context); self.compute_border_padding_margins(container_width, inline_fragment_context);
@ -1275,17 +1274,17 @@ impl Box {
let noncontent_width = self.border_padding.horizontal(); let noncontent_width = self.border_padding.horizontal();
match self.specific { match self.specific {
ScannedTextBox(_) => { ScannedTextFragment(_) => {
// Scanned text boxes will have already had their content widths assigned by this // Scanned text boxes will have already had their content widths assigned by this
// point. // point.
self.border_box.size.width = self.border_box.size.width + noncontent_width self.border_box.size.width = self.border_box.size.width + noncontent_width
} }
ImageBox(ref mut image_box_info) => { ImageFragment(ref mut image_box_info) => {
// TODO(ksh8281): compute border,margin // TODO(ksh8281): compute border,margin
let width = ImageBoxInfo::style_length(style_width, let width = ImageFragmentInfo::style_length(style_width,
image_box_info.dom_width, image_box_info.dom_width,
container_width); container_width);
let height = ImageBoxInfo::style_length(style_height, let height = ImageFragmentInfo::style_length(style_height,
image_box_info.dom_height, image_box_info.dom_height,
Au(0)); Au(0));
@ -1312,11 +1311,11 @@ impl Box {
/// Ideally, this should follow CSS 2.1 § 10.6.2. /// Ideally, this should follow CSS 2.1 § 10.6.2.
pub fn assign_replaced_height_if_necessary(&mut self) { pub fn assign_replaced_height_if_necessary(&mut self) {
match self.specific { match self.specific {
GenericBox | IframeBox(_) | TableBox | TableCellBox | TableRowBox | GenericFragment | IframeFragment(_) | TableFragment | TableCellFragment | TableRowFragment |
TableWrapperBox => return, TableWrapperFragment => return,
TableColumnBox(_) => fail!("Table column boxes do not have height"), TableColumnFragment(_) => fail!("Table column boxes do not have height"),
UnscannedTextBox(_) => fail!("Unscanned text boxes should have been scanned by now!"), UnscannedTextFragment(_) => fail!("Unscanned text boxes should have been scanned by now!"),
ImageBox(_) | ScannedTextBox(_) => {} ImageFragment(_) | ScannedTextFragment(_) => {}
} }
let style_width = self.style().get_box().width; let style_width = self.style().get_box().width;
@ -1324,12 +1323,12 @@ impl Box {
let noncontent_height = self.border_padding.vertical(); let noncontent_height = self.border_padding.vertical();
match self.specific { match self.specific {
ImageBox(ref mut image_box_info) => { ImageFragment(ref mut image_box_info) => {
// TODO(ksh8281): compute border,margin,padding // TODO(ksh8281): compute border,margin,padding
let width = image_box_info.computed_width(); let width = image_box_info.computed_width();
// FIXME(ksh8281): we shouldn't assign height this way // FIXME(ksh8281): we shouldn't assign height this way
// we don't know about size of parent's height // we don't know about size of parent's height
let height = ImageBoxInfo::style_length(style_height, let height = ImageFragmentInfo::style_length(style_height,
image_box_info.dom_height, image_box_info.dom_height,
Au(0)); Au(0));
@ -1350,7 +1349,7 @@ impl Box {
image_box_info.computed_height = Some(height); image_box_info.computed_height = Some(height);
self.border_box.size.height = height + noncontent_height self.border_box.size.height = height + noncontent_height
} }
ScannedTextBox(_) => { ScannedTextFragment(_) => {
// Scanned text boxes' content heights are calculated by the text run scanner // Scanned text boxes' content heights are calculated by the text run scanner
// during flow construction. // during flow construction.
self.border_box.size.height = self.border_box.size.height + noncontent_height self.border_box.size.height = self.border_box.size.height + noncontent_height
@ -1363,7 +1362,7 @@ impl Box {
/// used in an inline formatting context. See CSS 2.1 § 10.8.1. /// used in an inline formatting context. See CSS 2.1 § 10.8.1.
pub fn inline_metrics(&self) -> InlineMetrics { pub fn inline_metrics(&self) -> InlineMetrics {
match self.specific { match self.specific {
ImageBox(ref image_box_info) => { ImageFragment(ref image_box_info) => {
let computed_height = image_box_info.computed_height(); let computed_height = image_box_info.computed_height();
InlineMetrics { InlineMetrics {
height_above_baseline: computed_height + self.border_padding.vertical(), height_above_baseline: computed_height + self.border_padding.vertical(),
@ -1371,7 +1370,7 @@ impl Box {
ascent: computed_height + self.border_padding.bottom, ascent: computed_height + self.border_padding.bottom,
} }
} }
ScannedTextBox(ref text_box) => { ScannedTextFragment(ref text_box) => {
// See CSS 2.1 § 10.8.1. // See CSS 2.1 § 10.8.1.
let font_size = self.style().get_font().font_size; let font_size = self.style().get_font().font_size;
let line_height = self.calculate_line_height(font_size); let line_height = self.calculate_line_height(font_size);
@ -1388,9 +1387,9 @@ impl Box {
} }
/// Returns true if this box can merge with another adjacent box or false otherwise. /// Returns true if this box can merge with another adjacent box or false otherwise.
pub fn can_merge_with_box(&self, other: &Box) -> bool { pub fn can_merge_with_box(&self, other: &Fragment) -> bool {
match (&self.specific, &other.specific) { match (&self.specific, &other.specific) {
(&UnscannedTextBox(_), &UnscannedTextBox(_)) => { (&UnscannedTextFragment(_), &UnscannedTextFragment(_)) => {
self.font_style() == other.font_style() && self.font_style() == other.font_style() &&
self.text_decoration() == other.text_decoration() self.text_decoration() == other.text_decoration()
} }
@ -1424,7 +1423,7 @@ impl Box {
/// guide inlining. /// guide inlining.
#[inline(never)] #[inline(never)]
fn finalize_position_and_size_of_iframe(&self, fn finalize_position_and_size_of_iframe(&self,
iframe_box: &IframeBoxInfo, iframe_box: &IframeFragmentInfo,
offset: Point2D<Au>, offset: Point2D<Au>,
layout_context: &LayoutContext) { layout_context: &LayoutContext) {
let left = offset.x + self.margin.left + self.border_padding.left; let left = offset.x + self.margin.left + self.border_padding.left;
@ -1444,21 +1443,21 @@ impl Box {
} }
} }
impl fmt::Show for Box { impl fmt::Show for Fragment {
/// Outputs a debugging string describing this box. /// Outputs a debugging string describing this box.
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f.buf, "({} ", try!(write!(f.buf, "({} ",
match self.specific { match self.specific {
GenericBox => "GenericBox", GenericFragment => "GenericFragment",
IframeBox(_) => "IframeBox", IframeFragment(_) => "IframeFragment",
ImageBox(_) => "ImageBox", ImageFragment(_) => "ImageFragment",
ScannedTextBox(_) => "ScannedTextBox", ScannedTextFragment(_) => "ScannedTextFragment",
TableBox => "TableBox", TableFragment => "TableFragment",
TableCellBox => "TableCellBox", TableCellFragment => "TableCellFragment",
TableColumnBox(_) => "TableColumnBox", TableColumnFragment(_) => "TableColumnFragment",
TableRowBox => "TableRowBox", TableRowFragment => "TableRowFragment",
TableWrapperBox => "TableWrapperBox", TableWrapperFragment => "TableWrapperFragment",
UnscannedTextBox(_) => "UnscannedTextBox", UnscannedTextFragment(_) => "UnscannedTextFragment",
})); }));
try!(self.side_offsets_debug_fmt("bp", self.border_padding, f)); try!(self.side_offsets_debug_fmt("bp", self.border_padding, f));
try!(write!(f.buf, " ")); try!(write!(f.buf, " "));
@ -1469,7 +1468,7 @@ impl fmt::Show for Box {
/// An object that accumulates display lists of child flows, applying a clipping rect if necessary. /// An object that accumulates display lists of child flows, applying a clipping rect if necessary.
pub struct ChildDisplayListAccumulator { pub struct ChildDisplayListAccumulator {
clip_display_item: Option<owned::Box<ClipDisplayItem>>, clip_display_item: Option<Box<ClipDisplayItem>>,
} }
impl ChildDisplayListAccumulator { impl ChildDisplayListAccumulator {

View file

@ -22,15 +22,15 @@
use css::node_style::StyledNode; use css::node_style::StyledNode;
use layout::block::BlockFlow; use layout::block::BlockFlow;
use layout::box_::{Box, GenericBox, IframeBox, IframeBoxInfo, ImageBox, ImageBoxInfo}; use layout::box_::{Fragment, GenericFragment, IframeFragment, IframeFragmentInfo, ImageFragment, ImageFragmentInfo};
use layout::box_::{SpecificBoxInfo, TableBox, TableCellBox, TableColumnBox, TableColumnBoxInfo}; use layout::box_::{SpecificFragmentInfo, TableFragment, TableCellFragment, TableColumnFragment, TableColumnFragmentInfo};
use layout::box_::{TableRowBox, TableWrapperBox, UnscannedTextBox, UnscannedTextBoxInfo}; use layout::box_::{TableRowFragment, TableWrapperFragment, UnscannedTextFragment, UnscannedTextFragmentInfo};
use layout::context::LayoutContext; use layout::context::LayoutContext;
use layout::floats::FloatKind; use layout::floats::FloatKind;
use layout::flow::{Flow, ImmutableFlowUtils, MutableOwnedFlowUtils}; use layout::flow::{Flow, ImmutableFlowUtils, MutableOwnedFlowUtils};
use layout::flow::{Descendants, AbsDescendants}; use layout::flow::{Descendants, AbsDescendants};
use layout::flow_list::{Rawlink}; use layout::flow_list::{Rawlink};
use layout::inline::{FragmentIndex, InlineBoxes, InlineFlow}; use layout::inline::{FragmentIndex, InlineFragments, InlineFlow};
use layout::table_wrapper::TableWrapperFlow; use layout::table_wrapper::TableWrapperFlow;
use layout::table::TableFlow; use layout::table::TableFlow;
use layout::table_caption::TableCaptionFlow; use layout::table_caption::TableCaptionFlow;
@ -60,7 +60,6 @@ use servo_util::range::Range;
use servo_util::str::is_whitespace; use servo_util::str::is_whitespace;
use servo_util::url::{is_image_data, parse_url}; use servo_util::url::{is_image_data, parse_url};
use std::mem; use std::mem;
use std::owned;
use style::ComputedValues; use style::ComputedValues;
use style::computed_values::{display, position, float, white_space}; use style::computed_values::{display, position, float, white_space};
use sync::Arc; use sync::Arc;
@ -75,7 +74,7 @@ pub enum ConstructionResult {
/// This node contributed a flow at the proper position in the tree. /// This node contributed a flow at the proper position in the tree.
/// Nothing more needs to be done for this node. It has bubbled up fixed /// Nothing more needs to be done for this node. It has bubbled up fixed
/// and absolute descendant flows that have a CB above it. /// and absolute descendant flows that have a CB above it.
FlowConstructionResult(owned::Box<Flow:Share>, AbsDescendants), FlowConstructionResult(Box<Flow:Share>, AbsDescendants),
/// This node contributed some object or objects that will be needed to construct a proper flow /// This node contributed some object or objects that will be needed to construct a proper flow
/// later up the tree, but these objects have not yet found their home. /// later up the tree, but these objects have not yet found their home.
@ -97,34 +96,34 @@ impl ConstructionResult {
/// attached to. /// attached to.
pub enum ConstructionItem { pub enum ConstructionItem {
/// Inline boxes and associated {ib} splits that have not yet found flows. /// Inline boxes and associated {ib} splits that have not yet found flows.
InlineBoxesConstructionItem(InlineBoxesConstructionResult), InlineFragmentsConstructionItem(InlineFragmentsConstructionResult),
/// Potentially ignorable whitespace. /// Potentially ignorable whitespace.
WhitespaceConstructionItem(OpaqueNode, Arc<ComputedValues>), WhitespaceConstructionItem(OpaqueNode, Arc<ComputedValues>),
/// TableColumn Box /// TableColumn Fragment
TableColumnBoxConstructionItem(Box), TableColumnFragmentConstructionItem(Fragment),
} }
impl ConstructionItem { impl ConstructionItem {
fn destroy(&mut self) { fn destroy(&mut self) {
match *self { match *self {
InlineBoxesConstructionItem(ref mut result) => { InlineFragmentsConstructionItem(ref mut result) => {
for split in result.splits.mut_iter() { for split in result.splits.mut_iter() {
split.destroy() split.destroy()
} }
} }
WhitespaceConstructionItem(..) => {} WhitespaceConstructionItem(..) => {}
TableColumnBoxConstructionItem(_) => {} TableColumnFragmentConstructionItem(_) => {}
} }
} }
} }
/// Represents inline boxes and {ib} splits that are bubbling up from an inline. /// Represents inline boxes and {ib} splits that are bubbling up from an inline.
pub struct InlineBoxesConstructionResult { pub struct InlineFragmentsConstructionResult {
/// Any {ib} splits that we're bubbling up. /// Any {ib} splits that we're bubbling up.
pub splits: Vec<InlineBlockSplit>, pub splits: Vec<InlineBlockSplit>,
/// Any boxes that succeed the {ib} splits. /// Any boxes that succeed the {ib} splits.
pub boxes: InlineBoxes, pub boxes: InlineFragments,
/// Any absolute descendants that we're bubbling up. /// Any absolute descendants that we're bubbling up.
pub abs_descendants: AbsDescendants, pub abs_descendants: AbsDescendants,
@ -141,7 +140,7 @@ pub struct InlineBoxesConstructionResult {
/// ///
/// The resulting `ConstructionItem` for the outer `span` will be: /// The resulting `ConstructionItem` for the outer `span` will be:
/// ///
/// InlineBoxesConstructionItem(Some(~[ /// InlineFragmentsConstructionItem(Some(~[
/// InlineBlockSplit { /// InlineBlockSplit {
/// predecessor_boxes: ~[ /// predecessor_boxes: ~[
/// A /// A
@ -154,10 +153,10 @@ pub struct InlineBoxesConstructionResult {
/// ]) /// ])
pub struct InlineBlockSplit { pub struct InlineBlockSplit {
/// The inline boxes that precede the flow. /// The inline boxes that precede the flow.
pub predecessors: InlineBoxes, pub predecessors: InlineFragments,
/// The flow that caused this {ib} split. /// The flow that caused this {ib} split.
pub flow: owned::Box<Flow:Share>, pub flow: Box<Flow:Share>,
} }
impl InlineBlockSplit { impl InlineBlockSplit {
@ -167,34 +166,34 @@ impl InlineBlockSplit {
} }
/// Holds inline boxes that we're gathering for children of an inline node. /// Holds inline boxes that we're gathering for children of an inline node.
struct InlineBoxAccumulator { struct InlineFragmentsAccumulator {
/// The list of boxes. /// The list of boxes.
boxes: InlineBoxes, boxes: InlineFragments,
/// Whether we've created a range to enclose all the boxes. This will be true if the outer node /// Whether we've created a range to enclose all the boxes. This will be true if the outer node
/// is an inline and false otherwise. /// is an inline and false otherwise.
has_enclosing_range: bool, has_enclosing_range: bool,
} }
impl InlineBoxAccumulator { impl InlineFragmentsAccumulator {
fn new() -> InlineBoxAccumulator { fn new() -> InlineFragmentsAccumulator {
InlineBoxAccumulator { InlineFragmentsAccumulator {
boxes: InlineBoxes::new(), boxes: InlineFragments::new(),
has_enclosing_range: false, has_enclosing_range: false,
} }
} }
fn from_inline_node(node: &ThreadSafeLayoutNode) -> InlineBoxAccumulator { fn from_inline_node(node: &ThreadSafeLayoutNode) -> InlineFragmentsAccumulator {
let mut boxes = InlineBoxes::new(); let mut boxes = InlineFragments::new();
boxes.map.push(node.style().clone(), Range::empty()); boxes.map.push(node.style().clone(), Range::empty());
InlineBoxAccumulator { InlineFragmentsAccumulator {
boxes: boxes, boxes: boxes,
has_enclosing_range: true, has_enclosing_range: true,
} }
} }
fn finish(self) -> InlineBoxes { fn finish(self) -> InlineFragments {
let InlineBoxAccumulator { let InlineFragmentsAccumulator {
boxes: mut boxes, boxes: mut boxes,
has_enclosing_range has_enclosing_range
} = self; } = self;
@ -223,12 +222,12 @@ pub struct FlowConstructor<'a> {
/// ///
/// FIXME(pcwalton): This is pretty bogus and is basically just a workaround for libgreen /// FIXME(pcwalton): This is pretty bogus and is basically just a workaround for libgreen
/// having slow TLS. /// having slow TLS.
pub font_context: Option<owned::Box<FontContext>>, pub font_context: Option<Box<FontContext>>,
} }
impl<'a> FlowConstructor<'a> { impl<'a> FlowConstructor<'a> {
/// Creates a new flow constructor. /// Creates a new flow constructor.
pub fn new(layout_context: &'a mut LayoutContext, font_context: Option<owned::Box<FontContext>>) pub fn new(layout_context: &'a mut LayoutContext, font_context: Option<Box<FontContext>>)
-> FlowConstructor<'a> { -> FlowConstructor<'a> {
FlowConstructor { FlowConstructor {
layout_context: layout_context, layout_context: layout_context,
@ -247,7 +246,7 @@ impl<'a> FlowConstructor<'a> {
} }
/// Destroys this flow constructor and retrieves the font context. /// Destroys this flow constructor and retrieves the font context.
pub fn unwrap_font_context(self) -> Option<owned::Box<FontContext>> { pub fn unwrap_font_context(self) -> Option<Box<FontContext>> {
let FlowConstructor { let FlowConstructor {
font_context, font_context,
.. ..
@ -255,43 +254,43 @@ impl<'a> FlowConstructor<'a> {
font_context font_context
} }
/// Builds the `ImageBoxInfo` for the given image. This is out of line to guide inlining. /// Builds the `ImageFragmentInfo` for the given image. This is out of line to guide inlining.
fn build_box_info_for_image(&mut self, node: &ThreadSafeLayoutNode, url: Option<Url>) fn build_box_info_for_image(&mut self, node: &ThreadSafeLayoutNode, url: Option<Url>)
-> SpecificBoxInfo { -> SpecificFragmentInfo {
match url { match url {
None => GenericBox, None => GenericFragment,
Some(url) => { Some(url) => {
// FIXME(pcwalton): The fact that image boxes store the cache within them makes // FIXME(pcwalton): The fact that image boxes store the cache within them makes
// little sense to me. // little sense to me.
ImageBox(ImageBoxInfo::new(node, url, self.layout_context.image_cache.clone())) ImageFragment(ImageFragmentInfo::new(node, url, self.layout_context.image_cache.clone()))
} }
} }
} }
/// Builds specific `Box` info for the given node. /// Builds specific `Fragment` info for the given node.
pub fn build_specific_box_info_for_node(&mut self, node: &ThreadSafeLayoutNode) pub fn build_specific_box_info_for_node(&mut self, node: &ThreadSafeLayoutNode)
-> SpecificBoxInfo { -> SpecificFragmentInfo {
match node.type_id() { match node.type_id() {
Some(ElementNodeTypeId(HTMLImageElementTypeId)) => { Some(ElementNodeTypeId(HTMLImageElementTypeId)) => {
self.build_box_info_for_image(node, node.image_url()) self.build_box_info_for_image(node, node.image_url())
} }
Some(ElementNodeTypeId(HTMLIFrameElementTypeId)) => { Some(ElementNodeTypeId(HTMLIFrameElementTypeId)) => {
IframeBox(IframeBoxInfo::new(node)) IframeFragment(IframeFragmentInfo::new(node))
} }
Some(ElementNodeTypeId(HTMLObjectElementTypeId)) => { Some(ElementNodeTypeId(HTMLObjectElementTypeId)) => {
let data = node.get_object_data(&self.layout_context.url); let data = node.get_object_data(&self.layout_context.url);
self.build_box_info_for_image(node, data) self.build_box_info_for_image(node, data)
} }
Some(ElementNodeTypeId(HTMLTableElementTypeId)) => TableWrapperBox, Some(ElementNodeTypeId(HTMLTableElementTypeId)) => TableWrapperFragment,
Some(ElementNodeTypeId(HTMLTableColElementTypeId)) => { Some(ElementNodeTypeId(HTMLTableColElementTypeId)) => {
TableColumnBox(TableColumnBoxInfo::new(node)) TableColumnFragment(TableColumnFragmentInfo::new(node))
} }
Some(ElementNodeTypeId(HTMLTableDataCellElementTypeId)) | Some(ElementNodeTypeId(HTMLTableDataCellElementTypeId)) |
Some(ElementNodeTypeId(HTMLTableHeaderCellElementTypeId)) => TableCellBox, Some(ElementNodeTypeId(HTMLTableHeaderCellElementTypeId)) => TableCellFragment,
Some(ElementNodeTypeId(HTMLTableRowElementTypeId)) | Some(ElementNodeTypeId(HTMLTableRowElementTypeId)) |
Some(ElementNodeTypeId(HTMLTableSectionElementTypeId)) => TableRowBox, Some(ElementNodeTypeId(HTMLTableSectionElementTypeId)) => TableRowFragment,
None | Some(TextNodeTypeId) => UnscannedTextBox(UnscannedTextBoxInfo::new(node)), None | Some(TextNodeTypeId) => UnscannedTextFragment(UnscannedTextFragmentInfo::new(node)),
_ => GenericBox, _ => GenericFragment,
} }
} }
@ -302,9 +301,9 @@ impl<'a> FlowConstructor<'a> {
/// otherwise. /// otherwise.
#[inline(always)] #[inline(always)]
fn flush_inline_boxes_to_flow_or_list(&mut self, fn flush_inline_boxes_to_flow_or_list(&mut self,
box_accumulator: InlineBoxAccumulator, box_accumulator: InlineFragmentsAccumulator,
flow: &mut owned::Box<Flow:Share>, flow: &mut Box<Flow:Share>,
flow_list: &mut Vec<owned::Box<Flow:Share>>, flow_list: &mut Vec<Box<Flow:Share>>,
whitespace_stripping: WhitespaceStrippingMode, whitespace_stripping: WhitespaceStrippingMode,
node: &ThreadSafeLayoutNode) { node: &ThreadSafeLayoutNode) {
let mut boxes = box_accumulator.finish(); let mut boxes = box_accumulator.finish();
@ -330,7 +329,7 @@ impl<'a> FlowConstructor<'a> {
let mut inline_flow = box InlineFlow::from_boxes((*node).clone(), boxes); let mut inline_flow = box InlineFlow::from_boxes((*node).clone(), boxes);
inline_flow.compute_minimum_ascent_and_descent(self.font_context(), &**node.style()); inline_flow.compute_minimum_ascent_and_descent(self.font_context(), &**node.style());
let mut inline_flow = inline_flow as owned::Box<Flow:Share>; let mut inline_flow = inline_flow as Box<Flow:Share>;
TextRunScanner::new().scan_for_runs(self.font_context(), inline_flow); TextRunScanner::new().scan_for_runs(self.font_context(), inline_flow);
inline_flow.finish(self.layout_context); inline_flow.finish(self.layout_context);
@ -342,13 +341,13 @@ impl<'a> FlowConstructor<'a> {
} }
fn build_block_flow_using_children_construction_result(&mut self, fn build_block_flow_using_children_construction_result(&mut self,
flow: &mut owned::Box<Flow:Share>, flow: &mut Box<Flow:Share>,
consecutive_siblings: consecutive_siblings:
&mut Vec<owned::Box<Flow:Share>>, &mut Vec<Box<Flow:Share>>,
node: &ThreadSafeLayoutNode, node: &ThreadSafeLayoutNode,
kid: ThreadSafeLayoutNode, kid: ThreadSafeLayoutNode,
inline_box_accumulator: inline_box_accumulator:
&mut InlineBoxAccumulator, &mut InlineFragmentsAccumulator,
abs_descendants: &mut Descendants, abs_descendants: &mut Descendants,
first_box: &mut bool) { first_box: &mut bool) {
match kid.swap_out_construction_result() { match kid.swap_out_construction_result() {
@ -377,7 +376,7 @@ impl<'a> FlowConstructor<'a> {
debug!("flushing {} inline box(es) to flow A", debug!("flushing {} inline box(es) to flow A",
inline_box_accumulator.boxes.len()); inline_box_accumulator.boxes.len());
self.flush_inline_boxes_to_flow_or_list( self.flush_inline_boxes_to_flow_or_list(
mem::replace(inline_box_accumulator, InlineBoxAccumulator::new()), mem::replace(inline_box_accumulator, InlineFragmentsAccumulator::new()),
flow, flow,
consecutive_siblings, consecutive_siblings,
whitespace_stripping, whitespace_stripping,
@ -392,8 +391,8 @@ impl<'a> FlowConstructor<'a> {
} }
abs_descendants.push_descendants(kid_abs_descendants); abs_descendants.push_descendants(kid_abs_descendants);
} }
ConstructionItemConstructionResult(InlineBoxesConstructionItem( ConstructionItemConstructionResult(InlineFragmentsConstructionItem(
InlineBoxesConstructionResult { InlineFragmentsConstructionResult {
splits: splits, splits: splits,
boxes: successor_boxes, boxes: successor_boxes,
abs_descendants: kid_abs_descendants, abs_descendants: kid_abs_descendants,
@ -422,7 +421,7 @@ impl<'a> FlowConstructor<'a> {
inline_box_accumulator.boxes.len()); inline_box_accumulator.boxes.len());
self.flush_inline_boxes_to_flow_or_list( self.flush_inline_boxes_to_flow_or_list(
mem::replace(inline_box_accumulator, mem::replace(inline_box_accumulator,
InlineBoxAccumulator::new()), InlineFragmentsAccumulator::new()),
flow, flow,
consecutive_siblings, consecutive_siblings,
whitespace_stripping, whitespace_stripping,
@ -444,7 +443,7 @@ impl<'a> FlowConstructor<'a> {
ConstructionItemConstructionResult(WhitespaceConstructionItem(..)) => { ConstructionItemConstructionResult(WhitespaceConstructionItem(..)) => {
// Nothing to do here. // Nothing to do here.
} }
ConstructionItemConstructionResult(TableColumnBoxConstructionItem(_)) => { ConstructionItemConstructionResult(TableColumnFragmentConstructionItem(_)) => {
// TODO: Implement anonymous table objects for missing parents // TODO: Implement anonymous table objects for missing parents
// CSS 2.1 § 17.2.1, step 3-2 // CSS 2.1 § 17.2.1, step 3-2
} }
@ -459,11 +458,11 @@ impl<'a> FlowConstructor<'a> {
/// Also, deal with the absolute and fixed descendants bubbled up by /// Also, deal with the absolute and fixed descendants bubbled up by
/// children nodes. /// children nodes.
fn build_flow_using_children(&mut self, fn build_flow_using_children(&mut self,
mut flow: owned::Box<Flow:Share>, mut flow: Box<Flow:Share>,
node: &ThreadSafeLayoutNode) node: &ThreadSafeLayoutNode)
-> ConstructionResult { -> ConstructionResult {
// Gather up boxes for the inline flows we might need to create. // Gather up boxes for the inline flows we might need to create.
let mut inline_box_accumulator = InlineBoxAccumulator::new(); let mut inline_box_accumulator = InlineFragmentsAccumulator::new();
let mut consecutive_siblings = vec!(); let mut consecutive_siblings = vec!();
let mut first_box = true; let mut first_box = true;
@ -517,7 +516,7 @@ impl<'a> FlowConstructor<'a> {
/// other `BlockFlow`s or `InlineFlow`s underneath it, depending on whether {ib} splits needed /// other `BlockFlow`s or `InlineFlow`s underneath it, depending on whether {ib} splits needed
/// to happen. /// to happen.
fn build_flow_for_block(&mut self, node: &ThreadSafeLayoutNode) -> ConstructionResult { fn build_flow_for_block(&mut self, node: &ThreadSafeLayoutNode) -> ConstructionResult {
let flow = box BlockFlow::from_node(self, node) as owned::Box<Flow:Share>; let flow = box BlockFlow::from_node(self, node) as Box<Flow:Share>;
self.build_flow_using_children(flow, node) self.build_flow_using_children(flow, node)
} }
@ -525,17 +524,17 @@ impl<'a> FlowConstructor<'a> {
/// a `BlockFlow` underneath it. /// a `BlockFlow` underneath it.
fn build_flow_for_floated_block(&mut self, node: &ThreadSafeLayoutNode, float_kind: FloatKind) fn build_flow_for_floated_block(&mut self, node: &ThreadSafeLayoutNode, float_kind: FloatKind)
-> ConstructionResult { -> ConstructionResult {
let flow = box BlockFlow::float_from_node(self, node, float_kind) as owned::Box<Flow:Share>; let flow = box BlockFlow::float_from_node(self, node, float_kind) as Box<Flow:Share>;
self.build_flow_using_children(flow, node) self.build_flow_using_children(flow, node)
} }
/// Concatenates the boxes of kids, adding in our own borders/padding/margins if necessary. /// Concatenates the boxes of kids, adding in our own borders/padding/margins if necessary.
/// Returns the `InlineBoxesConstructionResult`, if any. There will be no /// Returns the `InlineFragmentsConstructionResult`, if any. There will be no
/// `InlineBoxesConstructionResult` if this node consisted entirely of ignorable whitespace. /// `InlineFragmentsConstructionResult` if this node consisted entirely of ignorable whitespace.
fn build_boxes_for_nonreplaced_inline_content(&mut self, node: &ThreadSafeLayoutNode) fn build_boxes_for_nonreplaced_inline_content(&mut self, node: &ThreadSafeLayoutNode)
-> ConstructionResult { -> ConstructionResult {
let mut opt_inline_block_splits: Vec<InlineBlockSplit> = Vec::new(); let mut opt_inline_block_splits: Vec<InlineBlockSplit> = Vec::new();
let mut box_accumulator = InlineBoxAccumulator::from_inline_node(node); let mut box_accumulator = InlineFragmentsAccumulator::from_inline_node(node);
let mut abs_descendants = Descendants::new(); let mut abs_descendants = Descendants::new();
// Concatenate all the boxes of our kids, creating {ib} splits as necessary. // Concatenate all the boxes of our kids, creating {ib} splits as necessary.
@ -551,14 +550,14 @@ impl<'a> FlowConstructor<'a> {
let split = InlineBlockSplit { let split = InlineBlockSplit {
predecessors: predecessors:
mem::replace(&mut box_accumulator, mem::replace(&mut box_accumulator,
InlineBoxAccumulator::from_inline_node(node)).finish(), InlineFragmentsAccumulator::from_inline_node(node)).finish(),
flow: flow, flow: flow,
}; };
opt_inline_block_splits.push(split); opt_inline_block_splits.push(split);
abs_descendants.push_descendants(kid_abs_descendants); abs_descendants.push_descendants(kid_abs_descendants);
} }
ConstructionItemConstructionResult(InlineBoxesConstructionItem( ConstructionItemConstructionResult(InlineFragmentsConstructionItem(
InlineBoxesConstructionResult { InlineFragmentsConstructionResult {
splits: splits, splits: splits,
boxes: successors, boxes: successors,
abs_descendants: kid_abs_descendants, abs_descendants: kid_abs_descendants,
@ -575,7 +574,7 @@ impl<'a> FlowConstructor<'a> {
let split = InlineBlockSplit { let split = InlineBlockSplit {
predecessors: predecessors:
mem::replace(&mut box_accumulator, mem::replace(&mut box_accumulator,
InlineBoxAccumulator::from_inline_node(node)) InlineFragmentsAccumulator::from_inline_node(node))
.finish(), .finish(),
flow: kid_flow, flow: kid_flow,
}; };
@ -590,13 +589,13 @@ impl<'a> FlowConstructor<'a> {
whitespace_style)) whitespace_style))
=> { => {
// Instantiate the whitespace box. // Instantiate the whitespace box.
let box_info = UnscannedTextBox(UnscannedTextBoxInfo::from_text(" ".to_owned())); let box_info = UnscannedTextFragment(UnscannedTextFragmentInfo::from_text(" ".to_owned()));
let fragment = Box::from_opaque_node_and_style(whitespace_node, let fragment = Fragment::from_opaque_node_and_style(whitespace_node,
whitespace_style.clone(), whitespace_style.clone(),
box_info); box_info);
box_accumulator.boxes.push(fragment, whitespace_style) box_accumulator.boxes.push(fragment, whitespace_style)
} }
ConstructionItemConstructionResult(TableColumnBoxConstructionItem(_)) => { ConstructionItemConstructionResult(TableColumnFragmentConstructionItem(_)) => {
// TODO: Implement anonymous table objects for missing parents // TODO: Implement anonymous table objects for missing parents
// CSS 2.1 § 17.2.1, step 3-2 // CSS 2.1 § 17.2.1, step 3-2
} }
@ -606,7 +605,7 @@ impl<'a> FlowConstructor<'a> {
// Finally, make a new construction result. // Finally, make a new construction result.
if opt_inline_block_splits.len() > 0 || box_accumulator.boxes.len() > 0 if opt_inline_block_splits.len() > 0 || box_accumulator.boxes.len() > 0
|| abs_descendants.len() > 0 { || abs_descendants.len() > 0 {
let construction_item = InlineBoxesConstructionItem(InlineBoxesConstructionResult { let construction_item = InlineFragmentsConstructionItem(InlineFragmentsConstructionResult {
splits: opt_inline_block_splits, splits: opt_inline_block_splits,
boxes: box_accumulator.finish(), boxes: box_accumulator.finish(),
abs_descendants: abs_descendants, abs_descendants: abs_descendants,
@ -617,8 +616,8 @@ impl<'a> FlowConstructor<'a> {
} }
} }
/// Creates an `InlineBoxesConstructionResult` for replaced content. Replaced content doesn't /// Creates an `InlineFragmentsConstructionResult` for replaced content. Replaced content doesn't
/// render its children, so this just nukes a child's boxes and creates a `Box`. /// render its children, so this just nukes a child's boxes and creates a `Fragment`.
fn build_boxes_for_replaced_inline_content(&mut self, node: &ThreadSafeLayoutNode) fn build_boxes_for_replaced_inline_content(&mut self, node: &ThreadSafeLayoutNode)
-> ConstructionResult { -> ConstructionResult {
for kid in node.children() { for kid in node.children() {
@ -635,10 +634,10 @@ impl<'a> FlowConstructor<'a> {
node.style().clone())) node.style().clone()))
} }
let mut boxes = InlineBoxes::new(); let mut boxes = InlineFragments::new();
boxes.push(Box::new(self, node), node.style().clone()); boxes.push(Fragment::new(self, node), node.style().clone());
let construction_item = InlineBoxesConstructionItem(InlineBoxesConstructionResult { let construction_item = InlineFragmentsConstructionItem(InlineFragmentsConstructionResult {
splits: Vec::new(), splits: Vec::new(),
boxes: boxes, boxes: boxes,
abs_descendants: Descendants::new(), abs_descendants: Descendants::new(),
@ -647,7 +646,7 @@ impl<'a> FlowConstructor<'a> {
} }
/// Builds one or more boxes for a node with `display: inline`. This yields an /// Builds one or more boxes for a node with `display: inline`. This yields an
/// `InlineBoxesConstructionResult`. /// `InlineFragmentsConstructionResult`.
fn build_boxes_for_inline(&mut self, node: &ThreadSafeLayoutNode) -> ConstructionResult { fn build_boxes_for_inline(&mut self, node: &ThreadSafeLayoutNode) -> ConstructionResult {
// Is this node replaced content? // Is this node replaced content?
if !node.is_replaced_content() { if !node.is_replaced_content() {
@ -661,7 +660,7 @@ impl<'a> FlowConstructor<'a> {
/// TableCaptionFlow is populated underneath TableWrapperFlow /// TableCaptionFlow is populated underneath TableWrapperFlow
fn place_table_caption_under_table_wrapper(&mut self, fn place_table_caption_under_table_wrapper(&mut self,
table_wrapper_flow: &mut owned::Box<Flow:Share>, table_wrapper_flow: &mut Box<Flow:Share>,
node: &ThreadSafeLayoutNode) { node: &ThreadSafeLayoutNode) {
for kid in node.children() { for kid in node.children() {
match kid.swap_out_construction_result() { match kid.swap_out_construction_result() {
@ -678,8 +677,8 @@ impl<'a> FlowConstructor<'a> {
/// Generates an anonymous table flow according to CSS 2.1 § 17.2.1, step 2. /// Generates an anonymous table flow according to CSS 2.1 § 17.2.1, step 2.
/// If necessary, generate recursively another anonymous table flow. /// If necessary, generate recursively another anonymous table flow.
fn generate_anonymous_missing_child(&mut self, fn generate_anonymous_missing_child(&mut self,
child_flows: Vec<owned::Box<Flow:Share>>, child_flows: Vec<Box<Flow:Share>>,
flow: &mut owned::Box<Flow:Share>, flow: &mut Box<Flow:Share>,
node: &ThreadSafeLayoutNode) { node: &ThreadSafeLayoutNode) {
let mut anonymous_flow = flow.generate_missing_child_flow(node); let mut anonymous_flow = flow.generate_missing_child_flow(node);
let mut consecutive_siblings = vec!(); let mut consecutive_siblings = vec!();
@ -705,11 +704,11 @@ impl<'a> FlowConstructor<'a> {
/// Builds a flow for a node with `display: table`. This yields a `TableWrapperFlow` with possibly /// Builds a flow for a node with `display: table`. This yields a `TableWrapperFlow` with possibly
/// other `TableCaptionFlow`s or `TableFlow`s underneath it. /// other `TableCaptionFlow`s or `TableFlow`s underneath it.
fn build_flow_for_table_wrapper(&mut self, node: &ThreadSafeLayoutNode) -> ConstructionResult { fn build_flow_for_table_wrapper(&mut self, node: &ThreadSafeLayoutNode) -> ConstructionResult {
let box_ = Box::new_from_specific_info(node, TableWrapperBox); let box_ = Fragment::new_from_specific_info(node, TableWrapperFragment);
let mut wrapper_flow = box TableWrapperFlow::from_node_and_box(node, box_) as owned::Box<Flow:Share>; let mut wrapper_flow = box TableWrapperFlow::from_node_and_box(node, box_) as Box<Flow:Share>;
let table_box_ = Box::new_from_specific_info(node, TableBox); let table_box_ = Fragment::new_from_specific_info(node, TableFragment);
let table_flow = box TableFlow::from_node_and_box(node, table_box_) as owned::Box<Flow:Share>; let table_flow = box TableFlow::from_node_and_box(node, table_box_) as Box<Flow:Share>;
// We first populate the TableFlow with other flows than TableCaptionFlow. // We first populate the TableFlow with other flows than TableCaptionFlow.
// We then populate the TableWrapperFlow with TableCaptionFlow, and attach // We then populate the TableWrapperFlow with TableCaptionFlow, and attach
@ -755,31 +754,31 @@ impl<'a> FlowConstructor<'a> {
/// Builds a flow for a node with `display: table-caption`. This yields a `TableCaptionFlow` /// Builds a flow for a node with `display: table-caption`. This yields a `TableCaptionFlow`
/// with possibly other `BlockFlow`s or `InlineFlow`s underneath it. /// with possibly other `BlockFlow`s or `InlineFlow`s underneath it.
fn build_flow_for_table_caption(&mut self, node: &ThreadSafeLayoutNode) -> ConstructionResult { fn build_flow_for_table_caption(&mut self, node: &ThreadSafeLayoutNode) -> ConstructionResult {
let flow = box TableCaptionFlow::from_node(self, node) as owned::Box<Flow:Share>; let flow = box TableCaptionFlow::from_node(self, node) as Box<Flow:Share>;
self.build_flow_using_children(flow, node) self.build_flow_using_children(flow, node)
} }
/// Builds a flow for a node with `display: table-row-group`. This yields a `TableRowGroupFlow` /// Builds a flow for a node with `display: table-row-group`. This yields a `TableRowGroupFlow`
/// with possibly other `TableRowFlow`s underneath it. /// with possibly other `TableRowFlow`s underneath it.
fn build_flow_for_table_rowgroup(&mut self, node: &ThreadSafeLayoutNode) -> ConstructionResult { fn build_flow_for_table_rowgroup(&mut self, node: &ThreadSafeLayoutNode) -> ConstructionResult {
let box_ = Box::new_from_specific_info(node, TableRowBox); let box_ = Fragment::new_from_specific_info(node, TableRowFragment);
let flow = box TableRowGroupFlow::from_node_and_box(node, box_) as owned::Box<Flow:Share>; let flow = box TableRowGroupFlow::from_node_and_box(node, box_) as Box<Flow:Share>;
self.build_flow_using_children(flow, node) self.build_flow_using_children(flow, node)
} }
/// Builds a flow for a node with `display: table-row`. This yields a `TableRowFlow` with /// Builds a flow for a node with `display: table-row`. This yields a `TableRowFlow` with
/// possibly other `TableCellFlow`s underneath it. /// possibly other `TableCellFlow`s underneath it.
fn build_flow_for_table_row(&mut self, node: &ThreadSafeLayoutNode) -> ConstructionResult { fn build_flow_for_table_row(&mut self, node: &ThreadSafeLayoutNode) -> ConstructionResult {
let box_ = Box::new_from_specific_info(node, TableRowBox); let box_ = Fragment::new_from_specific_info(node, TableRowFragment);
let flow = box TableRowFlow::from_node_and_box(node, box_) as owned::Box<Flow:Share>; let flow = box TableRowFlow::from_node_and_box(node, box_) as Box<Flow:Share>;
self.build_flow_using_children(flow, node) self.build_flow_using_children(flow, node)
} }
/// Builds a flow for a node with `display: table-cell`. This yields a `TableCellFlow` with /// Builds a flow for a node with `display: table-cell`. This yields a `TableCellFlow` with
/// possibly other `BlockFlow`s or `InlineFlow`s underneath it. /// possibly other `BlockFlow`s or `InlineFlow`s underneath it.
fn build_flow_for_table_cell(&mut self, node: &ThreadSafeLayoutNode) -> ConstructionResult { fn build_flow_for_table_cell(&mut self, node: &ThreadSafeLayoutNode) -> ConstructionResult {
let box_ = Box::new_from_specific_info(node, TableCellBox); let box_ = Fragment::new_from_specific_info(node, TableCellFragment);
let flow = box TableCellFlow::from_node_and_box(node, box_) as owned::Box<Flow:Share>; let flow = box TableCellFlow::from_node_and_box(node, box_) as Box<Flow:Share>;
self.build_flow_using_children(flow, node) self.build_flow_using_children(flow, node)
} }
@ -790,9 +789,9 @@ impl<'a> FlowConstructor<'a> {
kid.set_flow_construction_result(NoConstructionResult) kid.set_flow_construction_result(NoConstructionResult)
} }
let specific = TableColumnBox(TableColumnBoxInfo::new(node)); let specific = TableColumnFragment(TableColumnFragmentInfo::new(node));
let construction_item = TableColumnBoxConstructionItem( let construction_item = TableColumnFragmentConstructionItem(
Box::new_from_specific_info(node, specific) Fragment::new_from_specific_info(node, specific)
); );
ConstructionItemConstructionResult(construction_item) ConstructionItemConstructionResult(construction_item)
} }
@ -800,26 +799,25 @@ impl<'a> FlowConstructor<'a> {
/// Builds a flow for a node with `display: table-column-group`. /// Builds a flow for a node with `display: table-column-group`.
/// This yields a `TableColGroupFlow`. /// This yields a `TableColGroupFlow`.
fn build_flow_for_table_colgroup(&mut self, node: &ThreadSafeLayoutNode) -> ConstructionResult { fn build_flow_for_table_colgroup(&mut self, node: &ThreadSafeLayoutNode) -> ConstructionResult {
let box_ = Box::new_from_specific_info(node, let box_ = Fragment::new_from_specific_info(node,
TableColumnBox(TableColumnBoxInfo::new(node))); TableColumnFragment(TableColumnFragmentInfo::new(node)));
let mut col_boxes = vec!(); let mut col_boxes = vec!();
for kid in node.children() { for kid in node.children() {
// CSS 2.1 § 17.2.1. Treat all non-column child boxes of `table-column-group` // CSS 2.1 § 17.2.1. Treat all non-column child boxes of `table-column-group`
// as `display: none`. // as `display: none`.
match kid.swap_out_construction_result() { match kid.swap_out_construction_result() {
ConstructionItemConstructionResult(TableColumnBoxConstructionItem(box_)) => { ConstructionItemConstructionResult(TableColumnFragmentConstructionItem(box_)) => {
col_boxes.push(box_); col_boxes.push(box_);
} }
_ => {} _ => {}
} }
} }
if col_boxes.is_empty() { if col_boxes.is_empty() {
debug!("add TableColumnBox for empty colgroup"); debug!("add TableColumnFragment for empty colgroup");
let specific = TableColumnBox(TableColumnBoxInfo::new(node)); let specific = TableColumnFragment(TableColumnFragmentInfo::new(node));
col_boxes.push( Box::new_from_specific_info(node, specific) ); col_boxes.push(Fragment::new_from_specific_info(node, specific));
} }
let mut flow = box TableColGroupFlow::from_node_and_boxes(node, box_, col_boxes) as let mut flow = box TableColGroupFlow::from_node_and_boxes(node, box_, col_boxes) as Box<Flow:Share>;
owned::Box<Flow:Share>;
flow.finish(self.layout_context); flow.finish(self.layout_context);
FlowConstructionResult(flow, Descendants::new()) FlowConstructionResult(flow, Descendants::new())
@ -1087,15 +1085,15 @@ impl<'ln> ObjectElement for ThreadSafeLayoutNode<'ln> {
} }
/// Strips ignorable whitespace from the start of a list of boxes. /// Strips ignorable whitespace from the start of a list of boxes.
fn strip_ignorable_whitespace_from_start(boxes: &mut InlineBoxes) { fn strip_ignorable_whitespace_from_start(boxes: &mut InlineFragments) {
if boxes.len() == 0 { if boxes.len() == 0 {
return return
} }
let InlineBoxes { let InlineFragments {
boxes: old_boxes, boxes: old_boxes,
map: mut map map: mut map
} = mem::replace(boxes, InlineBoxes::new()); } = mem::replace(boxes, InlineFragments::new());
// FIXME(#2264, pcwalton): This is slow because vector shift is broken. :( // FIXME(#2264, pcwalton): This is slow because vector shift is broken. :(
let mut found_nonwhitespace = false; let mut found_nonwhitespace = false;
@ -1111,22 +1109,22 @@ fn strip_ignorable_whitespace_from_start(boxes: &mut InlineBoxes) {
} }
map.fixup(old_boxes.as_slice(), new_boxes.as_slice()); map.fixup(old_boxes.as_slice(), new_boxes.as_slice());
*boxes = InlineBoxes { *boxes = InlineFragments {
boxes: new_boxes, boxes: new_boxes,
map: map, map: map,
} }
} }
/// Strips ignorable whitespace from the end of a list of boxes. /// Strips ignorable whitespace from the end of a list of boxes.
fn strip_ignorable_whitespace_from_end(boxes: &mut InlineBoxes) { fn strip_ignorable_whitespace_from_end(boxes: &mut InlineFragments) {
if boxes.len() == 0 { if boxes.len() == 0 {
return return
} }
let InlineBoxes { let InlineFragments {
boxes: old_boxes, boxes: old_boxes,
map: mut map map: mut map
} = mem::replace(boxes, InlineBoxes::new()); } = mem::replace(boxes, InlineFragments::new());
let mut new_boxes = old_boxes.clone(); let mut new_boxes = old_boxes.clone();
while new_boxes.len() > 0 && new_boxes.as_slice().last().get_ref().is_whitespace_only() { while new_boxes.len() > 0 && new_boxes.as_slice().last().get_ref().is_whitespace_only() {
@ -1135,7 +1133,7 @@ fn strip_ignorable_whitespace_from_end(boxes: &mut InlineBoxes) {
} }
map.fixup(old_boxes.as_slice(), new_boxes.as_slice()); map.fixup(old_boxes.as_slice(), new_boxes.as_slice());
*boxes = InlineBoxes { *boxes = InlineFragments {
boxes: new_boxes, boxes: new_boxes,
map: map, map: map,
} }

View file

@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//! Servo's experimental layout system builds a tree of `Flow` and `Box` objects and solves //! Servo's experimental layout system builds a tree of `Flow` and `Fragment` objects and solves
//! layout constraints to obtain positions and display attributes of tree nodes. Positions are //! layout constraints to obtain positions and display attributes of tree nodes. Positions are
//! computed in several tree traversals driven by the fundamental data dependencies required by //! computed in several tree traversals driven by the fundamental data dependencies required by
/// inline and block layout. /// inline and block layout.
@ -27,7 +27,7 @@
use css::node_style::StyledNode; use css::node_style::StyledNode;
use layout::block::BlockFlow; use layout::block::BlockFlow;
use layout::box_::{Box, TableRowBox, TableCellBox}; use layout::box_::{Fragment, TableRowFragment, TableCellFragment};
use layout::context::LayoutContext; use layout::context::LayoutContext;
use layout::floats::Floats; use layout::floats::Floats;
use layout::flow_list::{FlowList, Link, Rawlink, FlowListIterator, MutFlowListIterator}; use layout::flow_list::{FlowList, Link, Rawlink, FlowListIterator, MutFlowListIterator};
@ -58,7 +58,6 @@ use std::cast;
use std::fmt; use std::fmt;
use std::iter::Zip; use std::iter::Zip;
use std::num::Zero; use std::num::Zero;
use std::owned;
use std::sync::atomics::Relaxed; use std::sync::atomics::Relaxed;
use std::slice::MutItems; use std::slice::MutItems;
use style::computed_values::{clear, position, text_align}; use style::computed_values::{clear, position, text_align};
@ -338,7 +337,7 @@ pub trait ImmutableFlowUtils {
fn need_anonymous_flow(self, child: &Flow) -> bool; fn need_anonymous_flow(self, child: &Flow) -> bool;
/// Generates missing child flow of this flow. /// Generates missing child flow of this flow.
fn generate_missing_child_flow(self, node: &ThreadSafeLayoutNode) -> owned::Box<Flow:Share>; fn generate_missing_child_flow(self, node: &ThreadSafeLayoutNode) -> Box<Flow:Share>;
/// Returns true if this flow has no children. /// Returns true if this flow has no children.
fn is_leaf(self) -> bool; fn is_leaf(self) -> bool;
@ -392,7 +391,7 @@ pub trait MutableFlowUtils {
pub trait MutableOwnedFlowUtils { pub trait MutableOwnedFlowUtils {
/// Adds a new flow as a child of this flow. Removes the flow from the given leaf set if /// Adds a new flow as a child of this flow. Removes the flow from the given leaf set if
/// it's present. /// it's present.
fn add_new_child(&mut self, new_child: owned::Box<Flow:Share>); fn add_new_child(&mut self, new_child: Box<Flow:Share>);
/// Finishes a flow. Once a flow is finished, no more child flows or boxes may be added to it. /// Finishes a flow. Once a flow is finished, no more child flows or boxes may be added to it.
/// This will normally run the bubble-widths (minimum and preferred -- i.e. intrinsic -- width) /// This will normally run the bubble-widths (minimum and preferred -- i.e. intrinsic -- width)
@ -842,15 +841,15 @@ impl<'a> ImmutableFlowUtils for &'a Flow {
} }
/// Generates missing child flow of this flow. /// Generates missing child flow of this flow.
fn generate_missing_child_flow(self, node: &ThreadSafeLayoutNode) -> owned::Box<Flow:Share> { fn generate_missing_child_flow(self, node: &ThreadSafeLayoutNode) -> Box<Flow:Share> {
match self.class() { match self.class() {
TableFlowClass | TableRowGroupFlowClass => { TableFlowClass | TableRowGroupFlowClass => {
let box_ = Box::new_anonymous_table_box(node, TableRowBox); let box_ = Fragment::new_anonymous_table_box(node, TableRowFragment);
box TableRowFlow::from_node_and_box(node, box_) as owned::Box<Flow:Share> box TableRowFlow::from_node_and_box(node, box_) as Box<Flow:Share>
}, },
TableRowFlowClass => { TableRowFlowClass => {
let box_ = Box::new_anonymous_table_box(node, TableCellBox); let box_ = Fragment::new_anonymous_table_box(node, TableCellFragment);
box TableCellFlow::from_node_and_box(node, box_) as owned::Box<Flow:Share> box TableCellFlow::from_node_and_box(node, box_) as Box<Flow:Share>
}, },
_ => { _ => {
fail!("no need to generate a missing child") fail!("no need to generate a missing child")
@ -1052,9 +1051,9 @@ impl<'a> MutableFlowUtils for &'a mut Flow {
} }
} }
impl MutableOwnedFlowUtils for owned::Box<Flow:Share> { impl MutableOwnedFlowUtils for Box<Flow:Share> {
/// Adds a new flow as a child of this flow. Fails if this flow is marked as a leaf. /// Adds a new flow as a child of this flow. Fails if this flow is marked as a leaf.
fn add_new_child(&mut self, mut new_child: owned::Box<Flow:Share>) { fn add_new_child(&mut self, mut new_child: Box<Flow:Share>) {
{ {
let kid_base = mut_base(new_child); let kid_base = mut_base(new_child);
kid_base.parallel.parent = parallel::mut_owned_flow_to_unsafe_flow(self); kid_base.parallel.parent = parallel::mut_owned_flow_to_unsafe_flow(self);

View file

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use css::node_style::StyledNode; use css::node_style::StyledNode;
use layout::box_::{Box, ScannedTextBox, ScannedTextBoxInfo, SplitInfo}; use layout::box_::{Fragment, ScannedTextFragment, ScannedTextFragmentInfo, SplitInfo};
use layout::context::LayoutContext; use layout::context::LayoutContext;
use layout::floats::{FloatLeft, Floats, PlacementInfo}; use layout::floats::{FloatLeft, Floats, PlacementInfo};
use layout::flow::{BaseFlow, FlowClass, Flow, InlineFlowClass}; use layout::flow::{BaseFlow, FlowClass, Flow, InlineFlowClass};
@ -36,7 +36,7 @@ use sync::Arc;
/// Lineboxes are represented as offsets into the child list, rather than /// Lineboxes are represented as offsets into the child list, rather than
/// as an object that "owns" boxes. Choosing a different set of line /// as an object that "owns" boxes. Choosing a different set of line
/// breaks requires a new list of offsets, and possibly some splitting and /// breaks requires a new list of offsets, and possibly some splitting and
/// merging of TextBoxes. /// merging of TextFragments.
/// ///
/// A similar list will keep track of the mapping between CSS boxes and /// A similar list will keep track of the mapping between CSS boxes and
/// the corresponding boxes in the inline flow. /// the corresponding boxes in the inline flow.
@ -201,8 +201,8 @@ pub fn each_char_index(range: &Range<LineIndices>) -> EachIndex<int, CharIndex>
struct LineboxScanner { struct LineboxScanner {
pub floats: Floats, pub floats: Floats,
pub new_boxes: Vec<Box>, pub new_boxes: Vec<Fragment>,
pub work_list: RingBuf<Box>, pub work_list: RingBuf<Fragment>,
pub pending_line: LineBox, pub pending_line: LineBox,
pub lines: Vec<LineBox>, pub lines: Vec<LineBox>,
pub cur_y: Au, pub cur_y: Au,
@ -246,10 +246,10 @@ impl LineboxScanner {
self.reset_scanner(); self.reset_scanner();
// Swap out temporarily. // Swap out temporarily.
let InlineBoxes { let InlineFragments {
boxes: old_boxes, boxes: old_boxes,
map: mut map map: mut map
} = mem::replace(&mut flow.boxes, InlineBoxes::new()); } = mem::replace(&mut flow.boxes, InlineFragments::new());
let mut old_box_iter = old_boxes.iter(); let mut old_box_iter = old_boxes.iter();
loop { loop {
@ -276,7 +276,7 @@ impl LineboxScanner {
}; };
if !box_was_appended { if !box_was_appended {
debug!("LineboxScanner: Box wasn't appended, because line {:u} was full.", debug!("LineboxScanner: Fragment wasn't appended, because line {:u} was full.",
self.lines.len()); self.lines.len());
self.flush_current_line(); self.flush_current_line();
} else { } else {
@ -291,7 +291,7 @@ impl LineboxScanner {
} }
map.fixup(old_boxes.as_slice(), self.new_boxes.as_slice()); map.fixup(old_boxes.as_slice(), self.new_boxes.as_slice());
flow.boxes = InlineBoxes { flow.boxes = InlineFragments {
boxes: mem::replace(&mut self.new_boxes, Vec::new()), boxes: mem::replace(&mut self.new_boxes, Vec::new()),
map: map, map: map,
}; };
@ -312,7 +312,7 @@ impl LineboxScanner {
// FIXME(eatkinson): this assumes that the tallest box in the line determines the line height // FIXME(eatkinson): this assumes that the tallest box in the line determines the line height
// This might not be the case with some weird text fonts. // This might not be the case with some weird text fonts.
fn new_height_for_line(&self, new_box: &Box) -> Au { fn new_height_for_line(&self, new_box: &Fragment) -> Au {
let box_height = new_box.content_height(); let box_height = new_box.content_height();
if box_height > self.pending_line.bounds.size.height { if box_height > self.pending_line.bounds.size.height {
box_height box_height
@ -324,7 +324,7 @@ impl LineboxScanner {
/// Computes the position of a line that has only the provided box. Returns the bounding rect /// Computes the position of a line that has only the provided box. Returns the bounding rect
/// of the line's green zone (whose origin coincides with the line's origin) and the actual /// of the line's green zone (whose origin coincides with the line's origin) and the actual
/// width of the first box after splitting. /// width of the first box after splitting.
fn initial_line_placement(&self, first_box: &Box, ceiling: Au, flow: &mut InlineFlow) fn initial_line_placement(&self, first_box: &Fragment, ceiling: Au, flow: &mut InlineFlow)
-> (Rect<Au>, Au) { -> (Rect<Au>, Au) {
debug!("LineboxScanner: Trying to place first box of line {}", self.lines.len()); debug!("LineboxScanner: Trying to place first box of line {}", self.lines.len());
@ -386,7 +386,7 @@ impl LineboxScanner {
/// ///
/// Returns false if and only if we should break the line. /// Returns false if and only if we should break the line.
fn avoid_floats(&mut self, fn avoid_floats(&mut self,
in_box: Box, in_box: Fragment,
flow: &mut InlineFlow, flow: &mut InlineFlow,
new_height: Au, new_height: Au,
line_is_empty: bool) line_is_empty: bool)
@ -417,7 +417,7 @@ impl LineboxScanner {
false false
} }
fn try_append_to_line_by_new_line(&mut self, in_box: Box) -> bool { fn try_append_to_line_by_new_line(&mut self, in_box: Fragment) -> bool {
if in_box.new_line_pos.len() == 0 { if in_box.new_line_pos.len() == 0 {
debug!("LineboxScanner: Did not find a new-line character, so pushing the box to \ debug!("LineboxScanner: Did not find a new-line character, so pushing the box to \
the line without splitting."); the line without splitting.");
@ -429,8 +429,8 @@ impl LineboxScanner {
Some((left, right, run)) => { Some((left, right, run)) => {
// TODO(bjz): Remove box splitting // TODO(bjz): Remove box splitting
let split_box = |split: SplitInfo| { let split_box = |split: SplitInfo| {
let info = ScannedTextBoxInfo::new(run.clone(), split.range); let info = ScannedTextFragmentInfo::new(run.clone(), split.range);
let specific = ScannedTextBox(info); let specific = ScannedTextFragment(info);
let size = Size2D(split.width, in_box.border_box.size.height); let size = Size2D(split.width, in_box.border_box.size.height);
in_box.transform(size, specific) in_box.transform(size, specific)
}; };
@ -459,7 +459,7 @@ impl LineboxScanner {
/// Tries to append the given box to the line, splitting it if necessary. Returns false only if /// Tries to append the given box to the line, splitting it if necessary. Returns false only if
/// we should break the line. /// we should break the line.
fn try_append_to_line(&mut self, in_box: Box, flow: &mut InlineFlow) -> bool { fn try_append_to_line(&mut self, in_box: Fragment, flow: &mut InlineFlow) -> bool {
let line_is_empty = self.pending_line.range.length() == num::zero(); let line_is_empty = self.pending_line.range.length() == num::zero();
if line_is_empty { if line_is_empty {
let (line_bounds, _) = self.initial_line_placement(&in_box, self.cur_y, flow); let (line_bounds, _) = self.initial_line_placement(&in_box, self.cur_y, flow);
@ -513,8 +513,8 @@ impl LineboxScanner {
match split.map(|(left, right, run)| { match split.map(|(left, right, run)| {
// TODO(bjz): Remove box splitting // TODO(bjz): Remove box splitting
let split_box = |split: SplitInfo| { let split_box = |split: SplitInfo| {
let info = ScannedTextBoxInfo::new(run.clone(), split.range); let info = ScannedTextFragmentInfo::new(run.clone(), split.range);
let specific = ScannedTextBox(info); let specific = ScannedTextFragment(info);
let size = Size2D(split.width, in_box.border_box.size.height); let size = Size2D(split.width, in_box.border_box.size.height);
in_box.transform(size, specific) in_box.transform(size, specific)
}; };
@ -553,7 +553,7 @@ impl LineboxScanner {
} }
// An unconditional push // An unconditional push
fn push_box_to_line(&mut self, box_: Box) { fn push_box_to_line(&mut self, box_: Fragment) {
debug!("LineboxScanner: Pushing box {} to line {:u}", box_.debug_id(), self.lines.len()); debug!("LineboxScanner: Pushing box {} to line {:u}", box_.debug_id(), self.lines.len());
if self.pending_line.range.length() == num::zero() { if self.pending_line.range.length() == num::zero() {
@ -579,14 +579,14 @@ impl LineboxScanner {
} }
/// Iterator over boxes. /// Iterator over boxes.
pub struct BoxIterator<'a> { pub struct FragmentIterator<'a> {
iter: Enumerate<Items<'a,Box>>, iter: Enumerate<Items<'a,Fragment>>,
map: &'a InlineFragmentMap, map: &'a InlineFragmentMap,
} }
impl<'a> Iterator<(&'a Box, InlineFragmentContext<'a>)> for BoxIterator<'a> { impl<'a> Iterator<(&'a Fragment, InlineFragmentContext<'a>)> for FragmentIterator<'a> {
#[inline] #[inline]
fn next(&mut self) -> Option<(&'a Box, InlineFragmentContext<'a>)> { fn next(&mut self) -> Option<(&'a Fragment, InlineFragmentContext<'a>)> {
match self.iter.next() { match self.iter.next() {
None => None, None => None,
Some((i, fragment)) => Some(( Some((i, fragment)) => Some((
@ -598,14 +598,14 @@ impl<'a> Iterator<(&'a Box, InlineFragmentContext<'a>)> for BoxIterator<'a> {
} }
/// Mutable iterator over boxes. /// Mutable iterator over boxes.
pub struct MutBoxIterator<'a> { pub struct MutFragmentIterator<'a> {
iter: Enumerate<MutItems<'a,Box>>, iter: Enumerate<MutItems<'a,Fragment>>,
map: &'a InlineFragmentMap, map: &'a InlineFragmentMap,
} }
impl<'a> Iterator<(&'a mut Box, InlineFragmentContext<'a>)> for MutBoxIterator<'a> { impl<'a> Iterator<(&'a mut Fragment, InlineFragmentContext<'a>)> for MutFragmentIterator<'a> {
#[inline] #[inline]
fn next(&mut self) -> Option<(&'a mut Box, InlineFragmentContext<'a>)> { fn next(&mut self) -> Option<(&'a mut Fragment, InlineFragmentContext<'a>)> {
match self.iter.next() { match self.iter.next() {
None => None, None => None,
Some((i, fragment)) => Some(( Some((i, fragment)) => Some((
@ -617,17 +617,17 @@ impl<'a> Iterator<(&'a mut Box, InlineFragmentContext<'a>)> for MutBoxIterator<'
} }
/// Represents a list of inline boxes, including element ranges. /// Represents a list of inline boxes, including element ranges.
pub struct InlineBoxes { pub struct InlineFragments {
/// The boxes themselves. /// The boxes themselves.
pub boxes: Vec<Box>, pub boxes: Vec<Fragment>,
/// Tracks the elements that made up the boxes above. /// Tracks the elements that made up the boxes above.
pub map: InlineFragmentMap, pub map: InlineFragmentMap,
} }
impl InlineBoxes { impl InlineFragments {
/// Creates an empty set of inline boxes. /// Creates an empty set of inline boxes.
pub fn new() -> InlineBoxes { pub fn new() -> InlineFragments {
InlineBoxes { InlineFragments {
boxes: Vec::new(), boxes: Vec::new(),
map: InlineFragmentMap::new(), map: InlineFragmentMap::new(),
} }
@ -644,14 +644,14 @@ impl InlineBoxes {
} }
/// Pushes a new inline box. /// Pushes a new inline box.
pub fn push(&mut self, fragment: Box, style: Arc<ComputedValues>) { pub fn push(&mut self, fragment: Fragment, style: Arc<ComputedValues>) {
self.map.push(style, Range::new(FragmentIndex(self.boxes.len() as int), FragmentIndex(1))); self.map.push(style, Range::new(FragmentIndex(self.boxes.len() as int), FragmentIndex(1)));
self.boxes.push(fragment) self.boxes.push(fragment)
} }
/// Merges another set of inline boxes with this one. /// Merges another set of inline boxes with this one.
pub fn push_all(&mut self, other: InlineBoxes) { pub fn push_all(&mut self, other: InlineFragments) {
let InlineBoxes { let InlineFragments {
boxes: other_boxes, boxes: other_boxes,
map: other_map map: other_map
} = other; } = other;
@ -661,8 +661,8 @@ impl InlineBoxes {
} }
/// Returns an iterator that iterates over all boxes along with the appropriate context. /// Returns an iterator that iterates over all boxes along with the appropriate context.
pub fn iter<'a>(&'a self) -> BoxIterator<'a> { pub fn iter<'a>(&'a self) -> FragmentIterator<'a> {
BoxIterator { FragmentIterator {
iter: self.boxes.as_slice().iter().enumerate(), iter: self.boxes.as_slice().iter().enumerate(),
map: &self.map, map: &self.map,
} }
@ -670,20 +670,20 @@ impl InlineBoxes {
/// Returns an iterator that iterates over all boxes along with the appropriate context and /// Returns an iterator that iterates over all boxes along with the appropriate context and
/// allows those boxes to be mutated. /// allows those boxes to be mutated.
pub fn mut_iter<'a>(&'a mut self) -> MutBoxIterator<'a> { pub fn mut_iter<'a>(&'a mut self) -> MutFragmentIterator<'a> {
MutBoxIterator { MutFragmentIterator {
iter: self.boxes.as_mut_slice().mut_iter().enumerate(), iter: self.boxes.as_mut_slice().mut_iter().enumerate(),
map: &self.map, map: &self.map,
} }
} }
/// A convenience function to return the box at a given index. /// A convenience function to return the box at a given index.
pub fn get<'a>(&'a self, index: uint) -> &'a Box { pub fn get<'a>(&'a self, index: uint) -> &'a Fragment {
self.boxes.get(index) self.boxes.get(index)
} }
/// A convenience function to return a mutable reference to the box at a given index. /// A convenience function to return a mutable reference to the box at a given index.
pub fn get_mut<'a>(&'a mut self, index: uint) -> &'a mut Box { pub fn get_mut<'a>(&'a mut self, index: uint) -> &'a mut Fragment {
self.boxes.get_mut(index) self.boxes.get_mut(index)
} }
} }
@ -694,7 +694,7 @@ pub struct InlineFlow {
pub base: BaseFlow, pub base: BaseFlow,
/// A vector of all inline fragments. Several fragments may correspond to one node/element. /// A vector of all inline fragments. Several fragments may correspond to one node/element.
pub boxes: InlineBoxes, pub boxes: InlineFragments,
/// A vector of ranges into boxes that represents line positions. These ranges are disjoint and /// A vector of ranges into boxes that represents line positions. These ranges are disjoint and
/// are the result of inline layout. This also includes some metadata used for positioning /// are the result of inline layout. This also includes some metadata used for positioning
@ -711,7 +711,7 @@ pub struct InlineFlow {
} }
impl InlineFlow { impl InlineFlow {
pub fn from_boxes(node: ThreadSafeLayoutNode, boxes: InlineBoxes) -> InlineFlow { pub fn from_boxes(node: ThreadSafeLayoutNode, boxes: InlineFragments) -> InlineFlow {
InlineFlow { InlineFlow {
base: BaseFlow::new(node), base: BaseFlow::new(node),
boxes: boxes, boxes: boxes,
@ -755,7 +755,7 @@ impl InlineFlow {
/// ///
/// The extra boolean is set if and only if `biggest_top` and/or `biggest_bottom` were updated. /// The extra boolean is set if and only if `biggest_top` and/or `biggest_bottom` were updated.
/// That is, if the box has a `top` or `bottom` value, true is returned. /// That is, if the box has a `top` or `bottom` value, true is returned.
fn distance_from_baseline(fragment: &Box, fn distance_from_baseline(fragment: &Fragment,
ascent: Au, ascent: Au,
parent_text_top: Au, parent_text_top: Au,
parent_text_bottom: Au, parent_text_bottom: Au,
@ -822,7 +822,7 @@ impl InlineFlow {
} }
/// Sets box X positions based on alignment for one line. /// Sets box X positions based on alignment for one line.
fn set_horizontal_box_positions(boxes: &mut InlineBoxes, fn set_horizontal_box_positions(boxes: &mut InlineFragments,
line: &LineBox, line: &LineBox,
linebox_align: text_align::T) { linebox_align: text_align::T) {
// Figure out how much width we have. // Figure out how much width we have.
@ -901,7 +901,7 @@ impl Flow for InlineFlow {
fn assign_widths(&mut self, _: &mut LayoutContext) { fn assign_widths(&mut self, _: &mut LayoutContext) {
// Initialize content box widths if they haven't been initialized already. // Initialize content box widths if they haven't been initialized already.
// //
// TODO: Combine this with `LineboxScanner`'s walk in the box list, or put this into `Box`. // TODO: Combine this with `LineboxScanner`'s walk in the box list, or put this into `Fragment`.
debug!("InlineFlow::assign_widths: floats in: {:?}", self.base.floats); debug!("InlineFlow::assign_widths: floats in: {:?}", self.base.floats);
@ -919,7 +919,7 @@ impl Flow for InlineFlow {
// There are no child contexts, so stop here. // There are no child contexts, so stop here.
// TODO(Issue #225): once there are 'inline-block' elements, this won't be // TODO(Issue #225): once there are 'inline-block' elements, this won't be
// true. In that case, set the InlineBlockBox's width to the // true. In that case, set the InlineBlockFragment's width to the
// shrink-to-fit width, perform inline flow, and set the block // shrink-to-fit width, perform inline flow, and set the block
// flow context's width as the assigned width of the // flow context's width as the assigned width of the
// 'inline-block' box that created this flow before recursing. // 'inline-block' box that created this flow before recursing.
@ -1226,7 +1226,7 @@ impl InlineFragmentMap {
/// i.e. if `old_boxes` contained less info than the entire range of boxes. See /// i.e. if `old_boxes` contained less info than the entire range of boxes. See
/// `layout::construct::strip_ignorable_whitespace_from_start` for an example of some code that /// `layout::construct::strip_ignorable_whitespace_from_start` for an example of some code that
/// needlessly has to clone boxes. /// needlessly has to clone boxes.
pub fn fixup(&mut self, old_fragments: &[Box], new_fragments: &[Box]) { pub fn fixup(&mut self, old_fragments: &[Fragment], new_fragments: &[Fragment]) {
// TODO(pcwalton): Post Rust upgrade, use `with_capacity` here. // TODO(pcwalton): Post Rust upgrade, use `with_capacity` here.
let old_list = mem::replace(&mut self.list, Vec::new()); let old_list = mem::replace(&mut self.list, Vec::new());
let mut worklist = Vec::new(); // FIXME(#2269, pcwalton): was smallvec4 let mut worklist = Vec::new(); // FIXME(#2269, pcwalton): was smallvec4

View file

@ -4,7 +4,7 @@
//! Borders, padding, and margins. //! Borders, padding, and margins.
use layout::box_::Box; use layout::box_::Fragment;
use computed = style::computed_values; use computed = style::computed_values;
use geom::SideOffsets2D; use geom::SideOffsets2D;
@ -98,7 +98,7 @@ impl MarginCollapseInfo {
} }
pub fn initialize_top_margin(&mut self, pub fn initialize_top_margin(&mut self,
fragment: &Box, fragment: &Fragment,
can_collapse_top_margin_with_kids: bool) { can_collapse_top_margin_with_kids: bool) {
if !can_collapse_top_margin_with_kids { if !can_collapse_top_margin_with_kids {
self.state = AccumulatingMarginIn self.state = AccumulatingMarginIn
@ -108,7 +108,7 @@ impl MarginCollapseInfo {
} }
pub fn finish_and_compute_collapsible_margins(mut self, pub fn finish_and_compute_collapsible_margins(mut self,
fragment: &Box, fragment: &Fragment,
can_collapse_bottom_margin_with_kids: bool) can_collapse_bottom_margin_with_kids: bool)
-> (CollapsibleMargins, Au) { -> (CollapsibleMargins, Au) {
let state = match self.state { let state = match self.state {

View file

@ -4,7 +4,7 @@
//! CSS table formatting contexts. //! CSS table formatting contexts.
use layout::box_::Box; use layout::box_::Fragment;
use layout::block::{BlockFlow, MarginsMayNotCollapse, WidthAndMarginsComputer}; use layout::block::{BlockFlow, MarginsMayNotCollapse, WidthAndMarginsComputer};
use layout::block::{WidthConstraintInput, WidthConstraintSolution}; use layout::block::{WidthConstraintInput, WidthConstraintSolution};
use layout::construct::FlowConstructor; use layout::construct::FlowConstructor;
@ -40,7 +40,7 @@ pub struct TableFlow {
impl TableFlow { impl TableFlow {
pub fn from_node_and_box(node: &ThreadSafeLayoutNode, pub fn from_node_and_box(node: &ThreadSafeLayoutNode,
box_: Box) box_: Fragment)
-> TableFlow { -> TableFlow {
let mut block_flow = BlockFlow::from_node_and_box(node, box_); let mut block_flow = BlockFlow::from_node_and_box(node, box_);
let table_layout = if block_flow.box_().style().get_table().table_layout == let table_layout = if block_flow.box_().style().get_table().table_layout ==

View file

@ -4,7 +4,7 @@
//! CSS table formatting contexts. //! CSS table formatting contexts.
use layout::box_::Box; use layout::box_::Fragment;
use layout::block::{BlockFlow, MarginsMayNotCollapse, WidthAndMarginsComputer}; use layout::block::{BlockFlow, MarginsMayNotCollapse, WidthAndMarginsComputer};
use layout::context::LayoutContext; use layout::context::LayoutContext;
use layout::flow::{TableCellFlowClass, FlowClass, Flow}; use layout::flow::{TableCellFlowClass, FlowClass, Flow};
@ -22,17 +22,17 @@ pub struct TableCellFlow {
} }
impl TableCellFlow { impl TableCellFlow {
pub fn from_node_and_box(node: &ThreadSafeLayoutNode, box_: Box) -> TableCellFlow { pub fn from_node_and_box(node: &ThreadSafeLayoutNode, box_: Fragment) -> TableCellFlow {
TableCellFlow { TableCellFlow {
block_flow: BlockFlow::from_node_and_box(node, box_) block_flow: BlockFlow::from_node_and_box(node, box_)
} }
} }
pub fn box_<'a>(&'a mut self) -> &'a Box { pub fn box_<'a>(&'a mut self) -> &'a Fragment {
&self.block_flow.box_ &self.block_flow.box_
} }
pub fn mut_box<'a>(&'a mut self) -> &'a mut Box { pub fn mut_box<'a>(&'a mut self) -> &'a mut Fragment {
&mut self.block_flow.box_ &mut self.block_flow.box_
} }

View file

@ -4,7 +4,7 @@
//! CSS table formatting contexts. //! CSS table formatting contexts.
use layout::box_::{Box, TableColumnBox}; use layout::box_::{Fragment, TableColumnFragment};
use layout::context::LayoutContext; use layout::context::LayoutContext;
use layout::flow::{BaseFlow, TableColGroupFlowClass, FlowClass, Flow}; use layout::flow::{BaseFlow, TableColGroupFlowClass, FlowClass, Flow};
use layout::model::{MaybeAuto}; use layout::model::{MaybeAuto};
@ -19,10 +19,10 @@ pub struct TableColGroupFlow {
pub base: BaseFlow, pub base: BaseFlow,
/// The associated box. /// The associated box.
pub box_: Option<Box>, pub box_: Option<Fragment>,
/// The table column boxes /// The table column boxes
pub cols: Vec<Box>, pub cols: Vec<Fragment>,
/// The specified widths of table columns /// The specified widths of table columns
pub widths: Vec<Au>, pub widths: Vec<Au>,
@ -30,8 +30,8 @@ pub struct TableColGroupFlow {
impl TableColGroupFlow { impl TableColGroupFlow {
pub fn from_node_and_boxes(node: &ThreadSafeLayoutNode, pub fn from_node_and_boxes(node: &ThreadSafeLayoutNode,
box_: Box, box_: Fragment,
boxes: Vec<Box>) -> TableColGroupFlow { boxes: Vec<Fragment>) -> TableColGroupFlow {
TableColGroupFlow { TableColGroupFlow {
base: BaseFlow::new((*node).clone()), base: BaseFlow::new((*node).clone()),
box_: Some(box_), box_: Some(box_),
@ -57,7 +57,7 @@ impl Flow for TableColGroupFlow {
Au::new(0)).specified_or_zero(); Au::new(0)).specified_or_zero();
let span: int = match box_.specific { let span: int = match box_.specific {
TableColumnBox(col_box) => col_box.span.unwrap_or(1), TableColumnFragment(col_box) => col_box.span.unwrap_or(1),
_ => fail!("Other box come out in TableColGroupFlow. {:?}", box_.specific) _ => fail!("Other box come out in TableColGroupFlow. {:?}", box_.specific)
}; };
for _ in range(0, span) { for _ in range(0, span) {

View file

@ -4,7 +4,7 @@
//! CSS table formatting contexts. //! CSS table formatting contexts.
use layout::box_::Box; use layout::box_::Fragment;
use layout::block::BlockFlow; use layout::block::BlockFlow;
use layout::block::WidthAndMarginsComputer; use layout::block::WidthAndMarginsComputer;
use layout::construct::FlowConstructor; use layout::construct::FlowConstructor;
@ -35,7 +35,7 @@ pub struct TableRowFlow {
impl TableRowFlow { impl TableRowFlow {
pub fn from_node_and_box(node: &ThreadSafeLayoutNode, pub fn from_node_and_box(node: &ThreadSafeLayoutNode,
box_: Box) box_: Fragment)
-> TableRowFlow { -> TableRowFlow {
TableRowFlow { TableRowFlow {
block_flow: BlockFlow::from_node_and_box(node, box_), block_flow: BlockFlow::from_node_and_box(node, box_),
@ -56,7 +56,7 @@ impl TableRowFlow {
} }
} }
pub fn box_<'a>(&'a mut self) -> &'a Box { pub fn box_<'a>(&'a mut self) -> &'a Fragment {
&self.block_flow.box_ &self.block_flow.box_
} }

View file

@ -4,7 +4,7 @@
//! CSS table formatting contexts. //! CSS table formatting contexts.
use layout::box_::Box; use layout::box_::Fragment;
use layout::block::BlockFlow; use layout::block::BlockFlow;
use layout::block::WidthAndMarginsComputer; use layout::block::WidthAndMarginsComputer;
use layout::construct::FlowConstructor; use layout::construct::FlowConstructor;
@ -34,7 +34,7 @@ pub struct TableRowGroupFlow {
impl TableRowGroupFlow { impl TableRowGroupFlow {
pub fn from_node_and_box(node: &ThreadSafeLayoutNode, pub fn from_node_and_box(node: &ThreadSafeLayoutNode,
box_: Box) box_: Fragment)
-> TableRowGroupFlow { -> TableRowGroupFlow {
TableRowGroupFlow { TableRowGroupFlow {
block_flow: BlockFlow::from_node_and_box(node, box_), block_flow: BlockFlow::from_node_and_box(node, box_),
@ -55,7 +55,7 @@ impl TableRowGroupFlow {
} }
} }
pub fn box_<'a>(&'a mut self) -> &'a Box { pub fn box_<'a>(&'a mut self) -> &'a Fragment {
&self.block_flow.box_ &self.block_flow.box_
} }

View file

@ -4,7 +4,7 @@
//! CSS table formatting contexts. //! CSS table formatting contexts.
use layout::box_::Box; use layout::box_::Fragment;
use layout::block::{BlockFlow, MarginsMayNotCollapse, WidthAndMarginsComputer}; use layout::block::{BlockFlow, MarginsMayNotCollapse, WidthAndMarginsComputer};
use layout::block::{WidthConstraintInput, WidthConstraintSolution}; use layout::block::{WidthConstraintInput, WidthConstraintSolution};
use layout::construct::FlowConstructor; use layout::construct::FlowConstructor;
@ -37,7 +37,7 @@ pub struct TableWrapperFlow {
impl TableWrapperFlow { impl TableWrapperFlow {
pub fn from_node_and_box(node: &ThreadSafeLayoutNode, pub fn from_node_and_box(node: &ThreadSafeLayoutNode,
box_: Box) box_: Fragment)
-> TableWrapperFlow { -> TableWrapperFlow {
let mut block_flow = BlockFlow::from_node_and_box(node, box_); let mut block_flow = BlockFlow::from_node_and_box(node, box_);
let table_layout = if block_flow.box_().style().get_table().table_layout == let table_layout = if block_flow.box_().style().get_table().table_layout ==

View file

@ -4,9 +4,9 @@
//! Text layout. //! Text layout.
use layout::box_::{Box, ScannedTextBox, ScannedTextBoxInfo, UnscannedTextBox}; use layout::box_::{Fragment, ScannedTextFragment, ScannedTextFragmentInfo, UnscannedTextFragment};
use layout::flow::Flow; use layout::flow::Flow;
use layout::inline::InlineBoxes; use layout::inline::InlineFragments;
use gfx::font::{FontMetrics, FontStyle}; use gfx::font::{FontMetrics, FontStyle};
use gfx::font_context::FontContext; use gfx::font_context::FontContext;
@ -25,12 +25,12 @@ struct NewLinePositions {
} }
// A helper function. // A helper function.
fn can_coalesce_text_nodes(boxes: &[Box], left_i: uint, right_i: uint) -> bool { fn can_coalesce_text_nodes(boxes: &[Fragment], left_i: uint, right_i: uint) -> bool {
assert!(left_i != right_i); assert!(left_i != right_i);
boxes[left_i].can_merge_with_box(&boxes[right_i]) boxes[left_i].can_merge_with_box(&boxes[right_i])
} }
/// A stack-allocated object for scanning an inline flow into `TextRun`-containing `TextBox`es. /// A stack-allocated object for scanning an inline flow into `TextRun`-containing `TextFragment`es.
pub struct TextRunScanner { pub struct TextRunScanner {
pub clump: Range<CharIndex>, pub clump: Range<CharIndex>,
} }
@ -48,10 +48,10 @@ impl TextRunScanner {
debug!("TextRunScanner: scanning {:u} boxes for text runs...", inline.boxes.len()); debug!("TextRunScanner: scanning {:u} boxes for text runs...", inline.boxes.len());
} }
let InlineBoxes { let InlineFragments {
boxes: old_boxes, boxes: old_boxes,
map: mut map map: mut map
} = mem::replace(&mut flow.as_inline().boxes, InlineBoxes::new()); } = mem::replace(&mut flow.as_inline().boxes, InlineFragments::new());
let mut last_whitespace = true; let mut last_whitespace = true;
let mut new_boxes = Vec::new(); let mut new_boxes = Vec::new();
@ -79,7 +79,7 @@ impl TextRunScanner {
// Swap out the old and new box list of the flow. // Swap out the old and new box list of the flow.
map.fixup(old_boxes.as_slice(), new_boxes.as_slice()); map.fixup(old_boxes.as_slice(), new_boxes.as_slice());
flow.as_inline().boxes = InlineBoxes { flow.as_inline().boxes = InlineFragments {
boxes: new_boxes, boxes: new_boxes,
map: map, map: map,
} }
@ -96,8 +96,8 @@ impl TextRunScanner {
/// with some smaller stub. /// with some smaller stub.
pub fn flush_clump_to_list(&mut self, pub fn flush_clump_to_list(&mut self,
font_context: &mut FontContext, font_context: &mut FontContext,
in_boxes: &[Box], in_boxes: &[Fragment],
out_boxes: &mut Vec<Box>, out_boxes: &mut Vec<Fragment>,
last_whitespace: bool) last_whitespace: bool)
-> bool { -> bool {
assert!(self.clump.length() > CharIndex(0)); assert!(self.clump.length() > CharIndex(0));
@ -106,7 +106,7 @@ impl TextRunScanner {
let is_singleton = self.clump.length() == CharIndex(1); let is_singleton = self.clump.length() == CharIndex(1);
let is_text_clump = match in_boxes[self.clump.begin().to_uint()].specific { let is_text_clump = match in_boxes[self.clump.begin().to_uint()].specific {
UnscannedTextBox(_) => true, UnscannedTextFragment(_) => true,
_ => false, _ => false,
}; };
@ -124,7 +124,7 @@ impl TextRunScanner {
(true, true) => { (true, true) => {
let old_box = &in_boxes[self.clump.begin().to_uint()]; let old_box = &in_boxes[self.clump.begin().to_uint()];
let text = match old_box.specific { let text = match old_box.specific {
UnscannedTextBox(ref text_box_info) => &text_box_info.text, UnscannedTextFragment(ref text_box_info) => &text_box_info.text,
_ => fail!("Expected an unscanned text box!"), _ => fail!("Expected an unscanned text box!"),
}; };
@ -159,9 +159,9 @@ impl TextRunScanner {
*text); *text);
let range = Range::new(CharIndex(0), run.char_len()); let range = Range::new(CharIndex(0), run.char_len());
let new_metrics = run.metrics_for_range(&range); let new_metrics = run.metrics_for_range(&range);
let new_text_box_info = ScannedTextBoxInfo::new(Arc::new(run), range); let new_text_box_info = ScannedTextFragmentInfo::new(Arc::new(run), range);
let mut new_box = old_box.transform(new_metrics.bounding_box.size, let mut new_box = old_box.transform(new_metrics.bounding_box.size,
ScannedTextBox(new_text_box_info)); ScannedTextFragment(new_text_box_info));
new_box.new_line_pos = new_line_pos; new_box.new_line_pos = new_line_pos;
out_boxes.push(new_box) out_boxes.push(new_box)
} }
@ -191,7 +191,7 @@ impl TextRunScanner {
// be compressed correctly with respect to the text run. // be compressed correctly with respect to the text run.
let idx = CharIndex(i as int) + self.clump.begin(); let idx = CharIndex(i as int) + self.clump.begin();
let in_box = match in_boxes[idx.to_uint()].specific { let in_box = match in_boxes[idx.to_uint()].specific {
UnscannedTextBox(ref text_box_info) => &text_box_info.text, UnscannedTextFragment(ref text_box_info) => &text_box_info.text,
_ => fail!("Expected an unscanned text box!"), _ => fail!("Expected an unscanned text box!"),
}; };
@ -243,10 +243,10 @@ impl TextRunScanner {
continue continue
} }
let new_text_box_info = ScannedTextBoxInfo::new(run.get_ref().clone(), *range); let new_text_box_info = ScannedTextFragmentInfo::new(run.get_ref().clone(), *range);
let new_metrics = new_text_box_info.run.metrics_for_range(range); let new_metrics = new_text_box_info.run.metrics_for_range(range);
let mut new_box = in_boxes[i.to_uint()].transform(new_metrics.bounding_box.size, let mut new_box = in_boxes[i.to_uint()].transform(new_metrics.bounding_box.size,
ScannedTextBox(new_text_box_info)); ScannedTextFragment(new_text_box_info));
new_box.new_line_pos = new_line_positions.get(logical_offset.to_uint()).new_line_pos.clone(); new_box.new_line_pos = new_line_positions.get(logical_offset.to_uint()).new_line_pos.clone();
out_boxes.push(new_box) out_boxes.push(new_box)
} }