From c5fced4390a7ad46e3eccfae48073ed820a840b6 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Tue, 27 May 2014 15:52:41 -0700 Subject: [PATCH] Convert usages of `Box` in type identifiers to `Fragment` --- src/components/main/layout/block.rs | 25 +- src/components/main/layout/box_.rs | 297 +++++++++---------- src/components/main/layout/construct.rs | 216 +++++++------- src/components/main/layout/flow.rs | 23 +- src/components/main/layout/inline.rs | 94 +++--- src/components/main/layout/model.rs | 6 +- src/components/main/layout/table.rs | 4 +- src/components/main/layout/table_cell.rs | 8 +- src/components/main/layout/table_colgroup.rs | 12 +- src/components/main/layout/table_row.rs | 6 +- src/components/main/layout/table_rowgroup.rs | 6 +- src/components/main/layout/table_wrapper.rs | 4 +- src/components/main/layout/text.rs | 32 +- 13 files changed, 364 insertions(+), 369 deletions(-) diff --git a/src/components/main/layout/block.rs b/src/components/main/layout/block.rs index 7d7415a941a..a69f839d8e9 100644 --- a/src/components/main/layout/block.rs +++ b/src/components/main/layout/block.rs @@ -12,7 +12,7 @@ //! //! 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::context::LayoutContext; use layout::floats::{ClearBoth, ClearLeft, ClearRight, FloatKind, Floats, PlacementInfo}; @@ -41,7 +41,6 @@ use servo_util::geometry; use std::fmt; use std::mem; 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::{LPN_Percentage, LP_Length, LP_Percentage, display, float, overflow}; use sync::Arc; @@ -490,7 +489,7 @@ pub struct BlockFlow { pub base: BaseFlow, /// The associated box. - pub box_: Box, + pub box_: Fragment, /// TODO: is_root should be a bit field to conserve memory. /// Whether this block flow is the root flow. @@ -504,14 +503,14 @@ pub struct BlockFlow { previous_float_width: Option, /// Additional floating flow members. - pub float: Option> + pub float: Option> } impl BlockFlow { pub fn from_node(constructor: &mut FlowConstructor, node: &ThreadSafeLayoutNode) -> BlockFlow { BlockFlow { base: BaseFlow::new((*node).clone()), - box_: Box::new(constructor, node), + box_: Fragment::new(constructor, node), is_root: false, static_y_offset: Au::new(0), 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 { base: BaseFlow::new((*node).clone()), box_: box_, @@ -536,7 +535,7 @@ impl BlockFlow { -> BlockFlow { BlockFlow { base: BaseFlow::new((*node).clone()), - box_: Box::new(constructor, node), + box_: Fragment::new(constructor, node), is_root: false, static_y_offset: Au::new(0), previous_float_width: None, @@ -602,7 +601,7 @@ impl BlockFlow { } /// 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_ } @@ -705,7 +704,7 @@ impl BlockFlow { /// image boxes. fn is_replaced_content(&self) -> bool { match self.box_.specific { - ScannedTextBox(_) | ImageBox(_) => true, + ScannedTextFragment(_) | ImageFragment(_) => true, _ => false, } } @@ -1203,11 +1202,11 @@ impl BlockFlow { let available_height = containing_block_height - self.box_.border_padding.vertical(); if self.is_replaced_content() { // 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. self.box_.assign_replaced_height_if_necessary(); // 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. let height_used_val = self.box_.border_box.size.height; solution = Some(HeightConstraintSolution::solve_vertical_constraints_abs_replaced( @@ -1289,7 +1288,7 @@ impl BlockFlow { 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. /// @@ -1404,7 +1403,7 @@ impl BlockFlow { display::table_cell | display::table_caption | display::inline_block => { OtherFormattingContext } - _ if style.get_box().position == position::static_ && + _ if style.get_box().position == position::static_ && style.get_box().overflow != overflow::visible => { BlockFormattingContext } diff --git a/src/components/main/layout/box_.rs b/src/components/main/layout/box_.rs index d9d05c78e46..bb7aebb4e30 100644 --- a/src/components/main/layout/box_.rs +++ b/src/components/main/layout/box_.rs @@ -44,7 +44,6 @@ use std::from_str::FromStr; use std::iter::AdditiveIterator; use std::mem; use std::num::Zero; -use std::owned; use style::{ComputedValues, TElement, TNode, cascade_anonymous}; use style::computed_values::{LengthOrPercentageOrAuto, overflow, LPA_Auto, background_attachment}; 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 /// 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. /// /// 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. #[deriving(Clone)] -pub struct Box { - /// An opaque reference to the DOM node that this `Box` originates from. +pub struct Fragment { + /// An opaque reference to the DOM node that this `Fragment` originates from. pub node: OpaqueNode, /// The CSS style of this box. @@ -92,7 +91,7 @@ pub struct Box { pub margin: SideOffsets2D, /// 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) /// @@ -102,22 +101,22 @@ pub struct Box { /// Info specific to the kind of box. Keep this enum small. #[deriving(Clone)] -pub enum SpecificBoxInfo { - GenericBox, - ImageBox(ImageBoxInfo), - IframeBox(IframeBoxInfo), - ScannedTextBox(ScannedTextBoxInfo), - TableBox, - TableCellBox, - TableColumnBox(TableColumnBoxInfo), - TableRowBox, - TableWrapperBox, - UnscannedTextBox(UnscannedTextBoxInfo), +pub enum SpecificFragmentInfo { + GenericFragment, + ImageFragment(ImageFragmentInfo), + IframeFragment(IframeFragmentInfo), + ScannedTextFragment(ScannedTextFragmentInfo), + TableFragment, + TableCellFragment, + TableColumnFragment(TableColumnFragmentInfo), + TableRowFragment, + TableWrapperFragment, + UnscannedTextFragment(UnscannedTextFragmentInfo), } /// A box that represents a replaced content image and its accompanying borders, shadows, etc. #[deriving(Clone)] -pub struct ImageBoxInfo { +pub struct ImageFragmentInfo { /// The image held within this box. pub image: ImageHolder, pub computed_width: Option, @@ -126,7 +125,7 @@ pub struct ImageBoxInfo { pub dom_height: Option, } -impl ImageBoxInfo { +impl ImageFragmentInfo { /// 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 @@ -134,7 +133,7 @@ impl ImageBoxInfo { pub fn new(node: &ThreadSafeLayoutNode, image_url: Url, local_image_cache: LocalImageCacheHandle) - -> ImageBoxInfo { + -> ImageFragmentInfo { fn convert_length(node: &ThreadSafeLayoutNode, name: &str) -> Option { let element = node.as_element(); element.get_attr(&namespace::Null, name).and_then(|string| { @@ -143,7 +142,7 @@ impl ImageBoxInfo { }).and_then(|pixels| Some(Au::from_px(pixels))) } - ImageBoxInfo { + ImageFragmentInfo { image: ImageHolder::new(image_url, local_image_cache), computed_width: 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 /// of this iframe can be communicated via the constellation to the iframe's own layout task. #[deriving(Clone)] -pub struct IframeBoxInfo { +pub struct IframeFragmentInfo { /// The pipeline ID of this iframe. pub pipeline_id: PipelineId, /// The subpage ID of this iframe. pub subpage_id: SubpageId, } -impl IframeBoxInfo { +impl IframeFragmentInfo { /// 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(); - IframeBoxInfo { + IframeFragmentInfo { pipeline_id: pipeline_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` /// object. #[deriving(Clone)] -pub struct ScannedTextBoxInfo { +pub struct ScannedTextFragmentInfo { /// The text run that this represents. - pub run: Arc>, + pub run: Arc>, /// The range within the above text run that this represents. pub range: Range, } -impl ScannedTextBoxInfo { +impl ScannedTextFragmentInfo { /// Creates the information specific to a scanned text box from a range and a text run. - pub fn new(run: Arc>, range: Range) -> ScannedTextBoxInfo { - ScannedTextBoxInfo { + pub fn new(run: Arc>, range: Range) -> ScannedTextFragmentInfo { + ScannedTextFragmentInfo { run: run, range: range, } @@ -250,7 +249,7 @@ pub struct SplitInfo { } impl SplitInfo { - fn new(range: Range, info: &ScannedTextBoxInfo) -> SplitInfo { + fn new(range: Range, info: &ScannedTextFragmentInfo) -> SplitInfo { SplitInfo { 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 /// have not yet had their width determined. #[deriving(Clone)] -pub struct UnscannedTextBoxInfo { +pub struct UnscannedTextFragmentInfo { /// The text inside the box. pub text: ~str, } -impl UnscannedTextBoxInfo { - /// Creates a new instance of `UnscannedTextBoxInfo` from the given DOM node. - pub fn new(node: &ThreadSafeLayoutNode) -> UnscannedTextBoxInfo { +impl UnscannedTextFragmentInfo { + /// Creates a new instance of `UnscannedTextFragmentInfo` from the given DOM node. + pub fn new(node: &ThreadSafeLayoutNode) -> UnscannedTextFragmentInfo { // FIXME(pcwalton): Don't copy text; atomically reference count it instead. - UnscannedTextBoxInfo { + UnscannedTextFragmentInfo { text: node.text(), } } - /// Creates a new instance of `UnscannedTextBoxInfo` from the given text. + /// Creates a new instance of `UnscannedTextFragmentInfo` from the given text. #[inline] - pub fn from_text(text: ~str) -> UnscannedTextBoxInfo { - UnscannedTextBoxInfo { + pub fn from_text(text: ~str) -> UnscannedTextFragmentInfo { + UnscannedTextFragmentInfo { text: text, } } @@ -286,14 +285,14 @@ impl UnscannedTextBoxInfo { /// A box that represents a table column. #[deriving(Clone)] -pub struct TableColumnBoxInfo { +pub struct TableColumnFragmentInfo { /// the number of columns a element should span pub span: Option, } -impl TableColumnBoxInfo { +impl TableColumnFragmentInfo { /// Create the information specific to an table column box. - pub fn new(node: &ThreadSafeLayoutNode) -> TableColumnBoxInfo { + pub fn new(node: &ThreadSafeLayoutNode) -> TableColumnFragmentInfo { let span = { let element = node.as_element(); element.get_attr(&namespace::Null, "span").and_then(|string| { @@ -301,22 +300,22 @@ impl TableColumnBoxInfo { n }) }; - TableColumnBoxInfo { + TableColumnFragmentInfo { span: span, } } } -impl Box { - /// Constructs a new `Box` instance for the given node. +impl Fragment { + /// Constructs a new `Fragment` instance for the given node. /// /// Arguments: /// /// * `constructor`: The flow constructor. /// /// * `node`: The node to create a box for. - pub fn new(constructor: &mut FlowConstructor, node: &ThreadSafeLayoutNode) -> Box { - Box { + pub fn new(constructor: &mut FlowConstructor, node: &ThreadSafeLayoutNode) -> Fragment { + Fragment { node: OpaqueNodeMethods::from_thread_safe_layout_node(node), style: node.style().clone(), border_box: Rect::zero(), @@ -327,9 +326,9 @@ impl Box { } } - /// Constructs a new `Box` instance from a specific info. - pub fn new_from_specific_info(node: &ThreadSafeLayoutNode, specific: SpecificBoxInfo) -> Box { - Box { + /// Constructs a new `Fragment` instance from a specific info. + pub fn new_from_specific_info(node: &ThreadSafeLayoutNode, specific: SpecificFragmentInfo) -> Fragment { + Fragment { node: OpaqueNodeMethods::from_thread_safe_layout_node(node), style: node.style().clone(), border_box: Rect::zero(), @@ -340,8 +339,8 @@ impl Box { } } - /// Constructs a new `Box` instance for an anonymous table object. - pub fn new_anonymous_table_box(node: &ThreadSafeLayoutNode, specific: SpecificBoxInfo) -> Box { + /// Constructs a new `Fragment` instance for an anonymous table object. + 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 // example: // @@ -349,10 +348,10 @@ impl Box { // Foo // // - // 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()); - Box { + Fragment { node: OpaqueNodeMethods::from_thread_safe_layout_node(node), style: Arc::new(node_style), 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, style: Arc, - specific: SpecificBoxInfo) - -> Box { - Box { + specific: SpecificFragmentInfo) + -> Fragment { + Fragment { node: node, style: style, 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 /// the other data. - pub fn transform(&self, size: Size2D, specific: SpecificBoxInfo) -> Box { - Box { + pub fn transform(&self, size: Size2D, specific: SpecificFragmentInfo) -> Fragment { + Fragment { node: self.node, style: self.style.clone(), border_box: Rect(self.border_box.origin, size), @@ -405,11 +404,11 @@ impl Box { /// replaced elements. fn style_specified_intrinsic_width(&self) -> IntrinsicWidths { let (use_margins, use_padding) = match self.specific { - GenericBox | IframeBox(_) | ImageBox(_) => (true, true), - TableBox | TableCellBox => (false, true), - TableWrapperBox => (true, false), - TableRowBox => (false, false), - ScannedTextBox(_) | TableColumnBox(_) | UnscannedTextBox(_) => { + GenericFragment | IframeFragment(_) | ImageFragment(_) => (true, true), + TableFragment | TableCellFragment => (false, true), + TableWrapperFragment => (true, false), + TableRowFragment => (false, false), + ScannedTextFragment(_) | TableColumnFragment(_) | UnscannedTextFragment(_) => { // Styles are irrelevant for these kinds of boxes. return IntrinsicWidths::new() } @@ -471,7 +470,7 @@ impl Box { // Compute vertical margins. Note that this value will be ignored by layout if the style // specifies `auto`. match self.specific { - TableBox | TableCellBox | TableRowBox | TableColumnBox(_) => { + TableFragment | TableCellFragment | TableRowFragment | TableColumnFragment(_) => { self.margin.top = Au(0); self.margin.bottom = Au(0) } @@ -496,7 +495,7 @@ impl Box { // Compute padding. let padding = match self.specific { - TableColumnBox(_) | TableRowBox | TableWrapperBox => Zero::zero(), + TableColumnFragment(_) | TableRowFragment | TableWrapperFragment => Zero::zero(), _ => { match inline_fragment_context { None => model::padding_from_style(self.style(), containing_block_width), @@ -621,9 +620,9 @@ impl Box { /// inlines. pub fn left_offset(&self) -> Au { match self.specific { - TableWrapperBox => self.margin.left, - TableBox | TableCellBox | TableRowBox => self.border_padding.left, - TableColumnBox(_) => Au(0), + TableWrapperFragment => self.margin.left, + TableFragment | TableCellFragment | TableRowFragment => self.border_padding.left, + TableColumnFragment(_) => Au(0), _ => 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. pub fn can_split(&self) -> bool { match self.specific { - ScannedTextBox(..) => true, + ScannedTextFragment(..) => true, _ => false, } } @@ -782,7 +781,7 @@ impl Box { fn build_debug_borders_around_text_boxes(&self, display_list: &mut DisplayList, flow_origin: Point2D, - text_box: &ScannedTextBoxInfo) { + text_box: &ScannedTextFragmentInfo) { let box_bounds = self.border_box; let absolute_box_bounds = box_bounds.translate(&flow_origin); @@ -844,14 +843,14 @@ impl Box { background_and_border_level: BackgroundAndBorderLevel, inline_fragment_context: Option) -> ChildDisplayListAccumulator { - // Box position wrt to the owning flow. + // Fragment position wrt to the owning flow. let box_bounds = self.border_box; 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, absolute_box_bounds, self); - debug!("Box::build_display_list: dirty={}, flow_origin={}", + debug!("Fragment::build_display_list: dirty={}, flow_origin={}", layout_context.dirty, flow_origin); @@ -864,11 +863,11 @@ impl Box { } 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 } - debug!("Box::build_display_list: intersected. Adding display item..."); + debug!("Fragment::build_display_list: intersected. Adding display item..."); { let level = @@ -895,9 +894,9 @@ impl Box { // Add a clip, if applicable. match self.specific { - UnscannedTextBox(_) => fail!("Shouldn't see unscanned boxes here."), - TableColumnBox(_) => fail!("Shouldn't see table column boxes here."), - ScannedTextBox(ref text_box) => { + UnscannedTextFragment(_) => fail!("Shouldn't see unscanned boxes here."), + TableColumnFragment(_) => fail!("Shouldn't see table column boxes here."), + ScannedTextFragment(ref text_box) => { // Compute text color. let text_color = self.style().get_color().color.to_gfx_color(); @@ -934,13 +933,13 @@ impl Box { flow_origin, text_box)) }, - GenericBox | IframeBox(..) | TableBox | TableCellBox | TableRowBox | - TableWrapperBox => { + GenericFragment | IframeFragment(..) | TableFragment | TableCellFragment | TableRowFragment | + TableWrapperFragment => { // FIXME(pcwalton): This is a bit of an abuse of the logging infrastructure. We // should have a real `SERVO_DEBUG` system. debug!("{:?}", self.build_debug_borders_around_box(display_list, flow_origin)) }, - ImageBox(_) => { + ImageFragment(_) => { let mut bounds = absolute_box_bounds.clone(); bounds.origin.x = bounds.origin.x + self.border_padding.left; 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(); match self.specific { - ImageBox(ref image_box) => { + ImageFragment(ref image_box) => { let image_ref = &image_box.image; match image_ref.get_image_if_present() { Some(image) => { @@ -993,7 +992,7 @@ impl Box { // layout for the iframe only needs to know size, and origin is only relevant if the // iframe is actually going to be displayed. match self.specific { - IframeBox(ref iframe_box) => { + IframeFragment(ref iframe_box) => { 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(); match self.specific { - GenericBox | IframeBox(_) | TableBox | TableCellBox | TableColumnBox(_) | TableRowBox | - TableWrapperBox => {} - ImageBox(ref mut image_box_info) => { + GenericFragment | IframeFragment(_) | TableFragment | TableCellFragment | TableColumnFragment(_) | TableRowFragment | + TableWrapperFragment => {} + ImageFragment(ref mut image_box_info) => { let image_width = image_box_info.image_width(); result.minimum_width = geometry::max(result.minimum_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 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.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. @@ -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 { match self.specific { - GenericBox | IframeBox(_) | TableBox | TableCellBox | TableRowBox | - TableWrapperBox => Au(0), - ImageBox(ref image_box_info) => { + GenericFragment | IframeFragment(_) | TableFragment | TableCellFragment | TableRowFragment | + TableWrapperFragment => Au(0), + ImageFragment(ref image_box_info) => { 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 text_bounds = run.metrics_for_range(range).bounding_box; text_bounds.size.width } - TableColumnBox(_) => fail!("Table column boxes do not have width"), - UnscannedTextBox(_) => fail!("Unscanned text boxes should have been scanned by now!"), + TableColumnFragment(_) => fail!("Table column boxes do not have width"), + UnscannedTextFragment(_) => fail!("Unscanned text boxes should have been scanned by now!"), } } /// Returns, and computes, the height of this box. pub fn content_height(&self) -> Au { match self.specific { - GenericBox | IframeBox(_) | TableBox | TableCellBox | TableRowBox | - TableWrapperBox => Au(0), - ImageBox(ref image_box_info) => { + GenericFragment | IframeFragment(_) | TableFragment | TableCellFragment | TableRowFragment | + TableWrapperFragment => Au(0), + ImageFragment(ref image_box_info) => { 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. // // 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; self.calculate_line_height(em_size) } - TableColumnBox(_) => fail!("Table column boxes do not have height"), - UnscannedTextBox(_) => fail!("Unscanned text boxes should have been scanned by now!"), + TableColumnFragment(_) => fail!("Table column boxes do not have height"), + 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 // the current method of box splitting in the `inline::try_append_*` functions. pub fn find_split_info_by_new_line(&self) - -> Option<(SplitInfo, Option, Arc> /* TODO(bjz): remove */)> { + -> Option<(SplitInfo, Option, Arc> /* TODO(bjz): remove */)> { match self.specific { - GenericBox | IframeBox(_) | ImageBox(_) | TableBox | TableCellBox | - TableRowBox | TableWrapperBox => None, - TableColumnBox(_) => fail!("Table column boxes do not need to split"), - UnscannedTextBox(_) => fail!("Unscanned text boxes should have been scanned by now!"), - ScannedTextBox(ref text_box_info) => { + GenericFragment | IframeFragment(_) | ImageFragment(_) | TableFragment | TableCellFragment | + TableRowFragment | TableWrapperFragment => None, + TableColumnFragment(_) => fail!("Table column boxes do not need to split"), + UnscannedTextFragment(_) => fail!("Unscanned text boxes should have been scanned by now!"), + ScannedTextFragment(ref text_box_info) => { let mut new_line_pos = self.new_line_pos.clone(); 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 // 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) - -> Option<(Option, Option, Arc> /* TODO(bjz): remove */)> { + -> Option<(Option, Option, Arc> /* TODO(bjz): remove */)> { match self.specific { - GenericBox | IframeBox(_) | ImageBox(_) | TableBox | TableCellBox | - TableRowBox | TableWrapperBox => None, - TableColumnBox(_) => fail!("Table column boxes do not have width"), - UnscannedTextBox(_) => fail!("Unscanned text boxes should have been scanned by now!"), - ScannedTextBox(ref text_box_info) => { + GenericFragment | IframeFragment(_) | ImageFragment(_) | TableFragment | TableCellFragment | + TableRowFragment | TableWrapperFragment => None, + TableColumnFragment(_) => fail!("Table column boxes do not have width"), + UnscannedTextFragment(_) => fail!("Unscanned text boxes should have been scanned by now!"), + ScannedTextFragment(ref text_box_info) => { let mut pieces_processed_count: uint = 0; let mut remaining_width: Au = max_width; 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. pub fn is_whitespace_only(&self) -> bool { 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, } } @@ -1261,11 +1260,11 @@ impl Box { inline_fragment_context: Option) { match self.specific { - GenericBox | IframeBox(_) | TableBox | TableCellBox | TableRowBox | - TableWrapperBox => return, - TableColumnBox(_) => fail!("Table column boxes do not have width"), - UnscannedTextBox(_) => fail!("Unscanned text boxes should have been scanned by now!"), - ImageBox(_) | ScannedTextBox(_) => {} + GenericFragment | IframeFragment(_) | TableFragment | TableCellFragment | TableRowFragment | + TableWrapperFragment => return, + TableColumnFragment(_) => fail!("Table column boxes do not have width"), + UnscannedTextFragment(_) => fail!("Unscanned text boxes should have been scanned by now!"), + ImageFragment(_) | ScannedTextFragment(_) => {} }; self.compute_border_padding_margins(container_width, inline_fragment_context); @@ -1275,17 +1274,17 @@ impl Box { let noncontent_width = self.border_padding.horizontal(); match self.specific { - ScannedTextBox(_) => { + ScannedTextFragment(_) => { // Scanned text boxes will have already had their content widths assigned by this // point. 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 - let width = ImageBoxInfo::style_length(style_width, + let width = ImageFragmentInfo::style_length(style_width, image_box_info.dom_width, container_width); - let height = ImageBoxInfo::style_length(style_height, + let height = ImageFragmentInfo::style_length(style_height, image_box_info.dom_height, Au(0)); @@ -1312,11 +1311,11 @@ impl Box { /// Ideally, this should follow CSS 2.1 § 10.6.2. pub fn assign_replaced_height_if_necessary(&mut self) { match self.specific { - GenericBox | IframeBox(_) | TableBox | TableCellBox | TableRowBox | - TableWrapperBox => return, - TableColumnBox(_) => fail!("Table column boxes do not have height"), - UnscannedTextBox(_) => fail!("Unscanned text boxes should have been scanned by now!"), - ImageBox(_) | ScannedTextBox(_) => {} + GenericFragment | IframeFragment(_) | TableFragment | TableCellFragment | TableRowFragment | + TableWrapperFragment => return, + TableColumnFragment(_) => fail!("Table column boxes do not have height"), + UnscannedTextFragment(_) => fail!("Unscanned text boxes should have been scanned by now!"), + ImageFragment(_) | ScannedTextFragment(_) => {} } let style_width = self.style().get_box().width; @@ -1324,12 +1323,12 @@ impl Box { let noncontent_height = self.border_padding.vertical(); match self.specific { - ImageBox(ref mut image_box_info) => { + ImageFragment(ref mut image_box_info) => { // TODO(ksh8281): compute border,margin,padding let width = image_box_info.computed_width(); // FIXME(ksh8281): we shouldn't assign height this way // 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, Au(0)); @@ -1350,7 +1349,7 @@ impl Box { image_box_info.computed_height = Some(height); self.border_box.size.height = height + noncontent_height } - ScannedTextBox(_) => { + ScannedTextFragment(_) => { // Scanned text boxes' content heights are calculated by the text run scanner // during flow construction. 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. pub fn inline_metrics(&self) -> InlineMetrics { match self.specific { - ImageBox(ref image_box_info) => { + ImageFragment(ref image_box_info) => { let computed_height = image_box_info.computed_height(); InlineMetrics { height_above_baseline: computed_height + self.border_padding.vertical(), @@ -1371,7 +1370,7 @@ impl Box { ascent: computed_height + self.border_padding.bottom, } } - ScannedTextBox(ref text_box) => { + ScannedTextFragment(ref text_box) => { // See CSS 2.1 § 10.8.1. let font_size = self.style().get_font().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. - 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) { - (&UnscannedTextBox(_), &UnscannedTextBox(_)) => { + (&UnscannedTextFragment(_), &UnscannedTextFragment(_)) => { self.font_style() == other.font_style() && self.text_decoration() == other.text_decoration() } @@ -1424,7 +1423,7 @@ impl Box { /// guide inlining. #[inline(never)] fn finalize_position_and_size_of_iframe(&self, - iframe_box: &IframeBoxInfo, + iframe_box: &IframeFragmentInfo, offset: Point2D, layout_context: &LayoutContext) { 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. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { try!(write!(f.buf, "({} ", match self.specific { - GenericBox => "GenericBox", - IframeBox(_) => "IframeBox", - ImageBox(_) => "ImageBox", - ScannedTextBox(_) => "ScannedTextBox", - TableBox => "TableBox", - TableCellBox => "TableCellBox", - TableColumnBox(_) => "TableColumnBox", - TableRowBox => "TableRowBox", - TableWrapperBox => "TableWrapperBox", - UnscannedTextBox(_) => "UnscannedTextBox", + GenericFragment => "GenericFragment", + IframeFragment(_) => "IframeFragment", + ImageFragment(_) => "ImageFragment", + ScannedTextFragment(_) => "ScannedTextFragment", + TableFragment => "TableFragment", + TableCellFragment => "TableCellFragment", + TableColumnFragment(_) => "TableColumnFragment", + TableRowFragment => "TableRowFragment", + TableWrapperFragment => "TableWrapperFragment", + UnscannedTextFragment(_) => "UnscannedTextFragment", })); try!(self.side_offsets_debug_fmt("bp", self.border_padding, f)); 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. pub struct ChildDisplayListAccumulator { - clip_display_item: Option>, + clip_display_item: Option>, } impl ChildDisplayListAccumulator { diff --git a/src/components/main/layout/construct.rs b/src/components/main/layout/construct.rs index 902a86d288a..e5e732fe59a 100644 --- a/src/components/main/layout/construct.rs +++ b/src/components/main/layout/construct.rs @@ -22,15 +22,15 @@ use css::node_style::StyledNode; use layout::block::BlockFlow; -use layout::box_::{Box, GenericBox, IframeBox, IframeBoxInfo, ImageBox, ImageBoxInfo}; -use layout::box_::{SpecificBoxInfo, TableBox, TableCellBox, TableColumnBox, TableColumnBoxInfo}; -use layout::box_::{TableRowBox, TableWrapperBox, UnscannedTextBox, UnscannedTextBoxInfo}; +use layout::box_::{Fragment, GenericFragment, IframeFragment, IframeFragmentInfo, ImageFragment, ImageFragmentInfo}; +use layout::box_::{SpecificFragmentInfo, TableFragment, TableCellFragment, TableColumnFragment, TableColumnFragmentInfo}; +use layout::box_::{TableRowFragment, TableWrapperFragment, UnscannedTextFragment, UnscannedTextFragmentInfo}; use layout::context::LayoutContext; use layout::floats::FloatKind; use layout::flow::{Flow, ImmutableFlowUtils, MutableOwnedFlowUtils}; use layout::flow::{Descendants, AbsDescendants}; 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::TableFlow; use layout::table_caption::TableCaptionFlow; @@ -60,7 +60,6 @@ use servo_util::range::Range; use servo_util::str::is_whitespace; use servo_util::url::{is_image_data, parse_url}; use std::mem; -use std::owned; use style::ComputedValues; use style::computed_values::{display, position, float, white_space}; use sync::Arc; @@ -75,7 +74,7 @@ pub enum ConstructionResult { /// 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 /// and absolute descendant flows that have a CB above it. - FlowConstructionResult(owned::Box, AbsDescendants), + FlowConstructionResult(Box, AbsDescendants), /// 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. @@ -97,34 +96,34 @@ impl ConstructionResult { /// attached to. pub enum ConstructionItem { /// Inline boxes and associated {ib} splits that have not yet found flows. - InlineBoxesConstructionItem(InlineBoxesConstructionResult), + InlineFragmentsConstructionItem(InlineFragmentsConstructionResult), /// Potentially ignorable whitespace. WhitespaceConstructionItem(OpaqueNode, Arc), - /// TableColumn Box - TableColumnBoxConstructionItem(Box), + /// TableColumn Fragment + TableColumnFragmentConstructionItem(Fragment), } impl ConstructionItem { fn destroy(&mut self) { match *self { - InlineBoxesConstructionItem(ref mut result) => { + InlineFragmentsConstructionItem(ref mut result) => { for split in result.splits.mut_iter() { split.destroy() } } WhitespaceConstructionItem(..) => {} - TableColumnBoxConstructionItem(_) => {} + TableColumnFragmentConstructionItem(_) => {} } } } /// 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. pub splits: Vec, /// Any boxes that succeed the {ib} splits. - pub boxes: InlineBoxes, + pub boxes: InlineFragments, /// Any absolute descendants that we're bubbling up. pub abs_descendants: AbsDescendants, @@ -141,7 +140,7 @@ pub struct InlineBoxesConstructionResult { /// /// The resulting `ConstructionItem` for the outer `span` will be: /// -/// InlineBoxesConstructionItem(Some(~[ +/// InlineFragmentsConstructionItem(Some(~[ /// InlineBlockSplit { /// predecessor_boxes: ~[ /// A @@ -154,10 +153,10 @@ pub struct InlineBoxesConstructionResult { /// ]) pub struct InlineBlockSplit { /// The inline boxes that precede the flow. - pub predecessors: InlineBoxes, + pub predecessors: InlineFragments, /// The flow that caused this {ib} split. - pub flow: owned::Box, + pub flow: Box, } impl InlineBlockSplit { @@ -167,34 +166,34 @@ impl InlineBlockSplit { } /// Holds inline boxes that we're gathering for children of an inline node. -struct InlineBoxAccumulator { +struct InlineFragmentsAccumulator { /// 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 /// is an inline and false otherwise. has_enclosing_range: bool, } -impl InlineBoxAccumulator { - fn new() -> InlineBoxAccumulator { - InlineBoxAccumulator { - boxes: InlineBoxes::new(), +impl InlineFragmentsAccumulator { + fn new() -> InlineFragmentsAccumulator { + InlineFragmentsAccumulator { + boxes: InlineFragments::new(), has_enclosing_range: false, } } - fn from_inline_node(node: &ThreadSafeLayoutNode) -> InlineBoxAccumulator { - let mut boxes = InlineBoxes::new(); + fn from_inline_node(node: &ThreadSafeLayoutNode) -> InlineFragmentsAccumulator { + let mut boxes = InlineFragments::new(); boxes.map.push(node.style().clone(), Range::empty()); - InlineBoxAccumulator { + InlineFragmentsAccumulator { boxes: boxes, has_enclosing_range: true, } } - fn finish(self) -> InlineBoxes { - let InlineBoxAccumulator { + fn finish(self) -> InlineFragments { + let InlineFragmentsAccumulator { boxes: mut boxes, has_enclosing_range } = self; @@ -223,12 +222,12 @@ pub struct FlowConstructor<'a> { /// /// FIXME(pcwalton): This is pretty bogus and is basically just a workaround for libgreen /// having slow TLS. - pub font_context: Option>, + pub font_context: Option>, } impl<'a> FlowConstructor<'a> { /// Creates a new flow constructor. - pub fn new(layout_context: &'a mut LayoutContext, font_context: Option>) + pub fn new(layout_context: &'a mut LayoutContext, font_context: Option>) -> FlowConstructor<'a> { FlowConstructor { layout_context: layout_context, @@ -247,7 +246,7 @@ impl<'a> FlowConstructor<'a> { } /// Destroys this flow constructor and retrieves the font context. - pub fn unwrap_font_context(self) -> Option> { + pub fn unwrap_font_context(self) -> Option> { let FlowConstructor { font_context, .. @@ -255,43 +254,43 @@ impl<'a> FlowConstructor<'a> { 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) - -> SpecificBoxInfo { + -> SpecificFragmentInfo { match url { - None => GenericBox, + None => GenericFragment, Some(url) => { // FIXME(pcwalton): The fact that image boxes store the cache within them makes // 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) - -> SpecificBoxInfo { + -> SpecificFragmentInfo { match node.type_id() { Some(ElementNodeTypeId(HTMLImageElementTypeId)) => { self.build_box_info_for_image(node, node.image_url()) } Some(ElementNodeTypeId(HTMLIFrameElementTypeId)) => { - IframeBox(IframeBoxInfo::new(node)) + IframeFragment(IframeFragmentInfo::new(node)) } Some(ElementNodeTypeId(HTMLObjectElementTypeId)) => { let data = node.get_object_data(&self.layout_context.url); self.build_box_info_for_image(node, data) } - Some(ElementNodeTypeId(HTMLTableElementTypeId)) => TableWrapperBox, + Some(ElementNodeTypeId(HTMLTableElementTypeId)) => TableWrapperFragment, Some(ElementNodeTypeId(HTMLTableColElementTypeId)) => { - TableColumnBox(TableColumnBoxInfo::new(node)) + TableColumnFragment(TableColumnFragmentInfo::new(node)) } Some(ElementNodeTypeId(HTMLTableDataCellElementTypeId)) | - Some(ElementNodeTypeId(HTMLTableHeaderCellElementTypeId)) => TableCellBox, + Some(ElementNodeTypeId(HTMLTableHeaderCellElementTypeId)) => TableCellFragment, Some(ElementNodeTypeId(HTMLTableRowElementTypeId)) | - Some(ElementNodeTypeId(HTMLTableSectionElementTypeId)) => TableRowBox, - None | Some(TextNodeTypeId) => UnscannedTextBox(UnscannedTextBoxInfo::new(node)), - _ => GenericBox, + Some(ElementNodeTypeId(HTMLTableSectionElementTypeId)) => TableRowFragment, + None | Some(TextNodeTypeId) => UnscannedTextFragment(UnscannedTextFragmentInfo::new(node)), + _ => GenericFragment, } } @@ -302,9 +301,9 @@ impl<'a> FlowConstructor<'a> { /// otherwise. #[inline(always)] fn flush_inline_boxes_to_flow_or_list(&mut self, - box_accumulator: InlineBoxAccumulator, - flow: &mut owned::Box, - flow_list: &mut Vec>, + box_accumulator: InlineFragmentsAccumulator, + flow: &mut Box, + flow_list: &mut Vec>, whitespace_stripping: WhitespaceStrippingMode, node: &ThreadSafeLayoutNode) { 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); inline_flow.compute_minimum_ascent_and_descent(self.font_context(), &**node.style()); - let mut inline_flow = inline_flow as owned::Box; + let mut inline_flow = inline_flow as Box; TextRunScanner::new().scan_for_runs(self.font_context(), inline_flow); inline_flow.finish(self.layout_context); @@ -342,13 +341,13 @@ impl<'a> FlowConstructor<'a> { } fn build_block_flow_using_children_construction_result(&mut self, - flow: &mut owned::Box, + flow: &mut Box, consecutive_siblings: - &mut Vec>, + &mut Vec>, node: &ThreadSafeLayoutNode, kid: ThreadSafeLayoutNode, inline_box_accumulator: - &mut InlineBoxAccumulator, + &mut InlineFragmentsAccumulator, abs_descendants: &mut Descendants, first_box: &mut bool) { match kid.swap_out_construction_result() { @@ -377,7 +376,7 @@ impl<'a> FlowConstructor<'a> { debug!("flushing {} inline box(es) to flow A", inline_box_accumulator.boxes.len()); self.flush_inline_boxes_to_flow_or_list( - mem::replace(inline_box_accumulator, InlineBoxAccumulator::new()), + mem::replace(inline_box_accumulator, InlineFragmentsAccumulator::new()), flow, consecutive_siblings, whitespace_stripping, @@ -392,8 +391,8 @@ impl<'a> FlowConstructor<'a> { } abs_descendants.push_descendants(kid_abs_descendants); } - ConstructionItemConstructionResult(InlineBoxesConstructionItem( - InlineBoxesConstructionResult { + ConstructionItemConstructionResult(InlineFragmentsConstructionItem( + InlineFragmentsConstructionResult { splits: splits, boxes: successor_boxes, abs_descendants: kid_abs_descendants, @@ -422,7 +421,7 @@ impl<'a> FlowConstructor<'a> { inline_box_accumulator.boxes.len()); self.flush_inline_boxes_to_flow_or_list( mem::replace(inline_box_accumulator, - InlineBoxAccumulator::new()), + InlineFragmentsAccumulator::new()), flow, consecutive_siblings, whitespace_stripping, @@ -444,7 +443,7 @@ impl<'a> FlowConstructor<'a> { ConstructionItemConstructionResult(WhitespaceConstructionItem(..)) => { // Nothing to do here. } - ConstructionItemConstructionResult(TableColumnBoxConstructionItem(_)) => { + ConstructionItemConstructionResult(TableColumnFragmentConstructionItem(_)) => { // TODO: Implement anonymous table objects for missing parents // 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 /// children nodes. fn build_flow_using_children(&mut self, - mut flow: owned::Box, + mut flow: Box, node: &ThreadSafeLayoutNode) -> ConstructionResult { // 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 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 /// to happen. fn build_flow_for_block(&mut self, node: &ThreadSafeLayoutNode) -> ConstructionResult { - let flow = box BlockFlow::from_node(self, node) as owned::Box; + let flow = box BlockFlow::from_node(self, node) as Box; self.build_flow_using_children(flow, node) } @@ -525,17 +524,17 @@ impl<'a> FlowConstructor<'a> { /// a `BlockFlow` underneath it. fn build_flow_for_floated_block(&mut self, node: &ThreadSafeLayoutNode, float_kind: FloatKind) -> ConstructionResult { - let flow = box BlockFlow::float_from_node(self, node, float_kind) as owned::Box; + let flow = box BlockFlow::float_from_node(self, node, float_kind) as Box; self.build_flow_using_children(flow, node) } /// Concatenates the boxes of kids, adding in our own borders/padding/margins if necessary. - /// Returns the `InlineBoxesConstructionResult`, if any. There will be no - /// `InlineBoxesConstructionResult` if this node consisted entirely of ignorable whitespace. + /// Returns the `InlineFragmentsConstructionResult`, if any. There will be no + /// `InlineFragmentsConstructionResult` if this node consisted entirely of ignorable whitespace. fn build_boxes_for_nonreplaced_inline_content(&mut self, node: &ThreadSafeLayoutNode) -> ConstructionResult { let mut opt_inline_block_splits: Vec = 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(); // Concatenate all the boxes of our kids, creating {ib} splits as necessary. @@ -551,14 +550,14 @@ impl<'a> FlowConstructor<'a> { let split = InlineBlockSplit { predecessors: mem::replace(&mut box_accumulator, - InlineBoxAccumulator::from_inline_node(node)).finish(), + InlineFragmentsAccumulator::from_inline_node(node)).finish(), flow: flow, }; opt_inline_block_splits.push(split); abs_descendants.push_descendants(kid_abs_descendants); } - ConstructionItemConstructionResult(InlineBoxesConstructionItem( - InlineBoxesConstructionResult { + ConstructionItemConstructionResult(InlineFragmentsConstructionItem( + InlineFragmentsConstructionResult { splits: splits, boxes: successors, abs_descendants: kid_abs_descendants, @@ -575,7 +574,7 @@ impl<'a> FlowConstructor<'a> { let split = InlineBlockSplit { predecessors: mem::replace(&mut box_accumulator, - InlineBoxAccumulator::from_inline_node(node)) + InlineFragmentsAccumulator::from_inline_node(node)) .finish(), flow: kid_flow, }; @@ -590,13 +589,13 @@ impl<'a> FlowConstructor<'a> { whitespace_style)) => { // Instantiate the whitespace box. - let box_info = UnscannedTextBox(UnscannedTextBoxInfo::from_text(" ".to_owned())); - let fragment = Box::from_opaque_node_and_style(whitespace_node, + let box_info = UnscannedTextFragment(UnscannedTextFragmentInfo::from_text(" ".to_owned())); + let fragment = Fragment::from_opaque_node_and_style(whitespace_node, whitespace_style.clone(), box_info); box_accumulator.boxes.push(fragment, whitespace_style) } - ConstructionItemConstructionResult(TableColumnBoxConstructionItem(_)) => { + ConstructionItemConstructionResult(TableColumnFragmentConstructionItem(_)) => { // TODO: Implement anonymous table objects for missing parents // CSS 2.1 § 17.2.1, step 3-2 } @@ -606,7 +605,7 @@ impl<'a> FlowConstructor<'a> { // Finally, make a new construction result. if opt_inline_block_splits.len() > 0 || box_accumulator.boxes.len() > 0 || abs_descendants.len() > 0 { - let construction_item = InlineBoxesConstructionItem(InlineBoxesConstructionResult { + let construction_item = InlineFragmentsConstructionItem(InlineFragmentsConstructionResult { splits: opt_inline_block_splits, boxes: box_accumulator.finish(), abs_descendants: abs_descendants, @@ -617,8 +616,8 @@ impl<'a> FlowConstructor<'a> { } } - /// Creates an `InlineBoxesConstructionResult` for replaced content. Replaced content doesn't - /// render its children, so this just nukes a child's boxes and creates a `Box`. + /// Creates an `InlineFragmentsConstructionResult` for replaced content. Replaced content doesn't + /// 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) -> ConstructionResult { for kid in node.children() { @@ -635,10 +634,10 @@ impl<'a> FlowConstructor<'a> { node.style().clone())) } - let mut boxes = InlineBoxes::new(); - boxes.push(Box::new(self, node), node.style().clone()); + let mut boxes = InlineFragments::new(); + boxes.push(Fragment::new(self, node), node.style().clone()); - let construction_item = InlineBoxesConstructionItem(InlineBoxesConstructionResult { + let construction_item = InlineFragmentsConstructionItem(InlineFragmentsConstructionResult { splits: Vec::new(), boxes: boxes, 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 - /// `InlineBoxesConstructionResult`. + /// `InlineFragmentsConstructionResult`. fn build_boxes_for_inline(&mut self, node: &ThreadSafeLayoutNode) -> ConstructionResult { // Is this node replaced content? if !node.is_replaced_content() { @@ -661,7 +660,7 @@ impl<'a> FlowConstructor<'a> { /// TableCaptionFlow is populated underneath TableWrapperFlow fn place_table_caption_under_table_wrapper(&mut self, - table_wrapper_flow: &mut owned::Box, + table_wrapper_flow: &mut Box, node: &ThreadSafeLayoutNode) { for kid in node.children() { 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. /// If necessary, generate recursively another anonymous table flow. fn generate_anonymous_missing_child(&mut self, - child_flows: Vec>, - flow: &mut owned::Box, + child_flows: Vec>, + flow: &mut Box, node: &ThreadSafeLayoutNode) { let mut anonymous_flow = flow.generate_missing_child_flow(node); 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 /// other `TableCaptionFlow`s or `TableFlow`s underneath it. fn build_flow_for_table_wrapper(&mut self, node: &ThreadSafeLayoutNode) -> ConstructionResult { - let box_ = Box::new_from_specific_info(node, TableWrapperBox); - let mut wrapper_flow = box TableWrapperFlow::from_node_and_box(node, box_) as owned::Box; + let box_ = Fragment::new_from_specific_info(node, TableWrapperFragment); + let mut wrapper_flow = box TableWrapperFlow::from_node_and_box(node, box_) as Box; - let table_box_ = Box::new_from_specific_info(node, TableBox); - let table_flow = box TableFlow::from_node_and_box(node, table_box_) as owned::Box; + let table_box_ = Fragment::new_from_specific_info(node, TableFragment); + let table_flow = box TableFlow::from_node_and_box(node, table_box_) as Box; // We first populate the TableFlow with other flows than TableCaptionFlow. // 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` /// with possibly other `BlockFlow`s or `InlineFlow`s underneath it. fn build_flow_for_table_caption(&mut self, node: &ThreadSafeLayoutNode) -> ConstructionResult { - let flow = box TableCaptionFlow::from_node(self, node) as owned::Box; + let flow = box TableCaptionFlow::from_node(self, node) as Box; self.build_flow_using_children(flow, node) } /// Builds a flow for a node with `display: table-row-group`. This yields a `TableRowGroupFlow` /// with possibly other `TableRowFlow`s underneath it. fn build_flow_for_table_rowgroup(&mut self, node: &ThreadSafeLayoutNode) -> ConstructionResult { - let box_ = Box::new_from_specific_info(node, TableRowBox); - let flow = box TableRowGroupFlow::from_node_and_box(node, box_) as owned::Box; + let box_ = Fragment::new_from_specific_info(node, TableRowFragment); + let flow = box TableRowGroupFlow::from_node_and_box(node, box_) as Box; self.build_flow_using_children(flow, node) } /// Builds a flow for a node with `display: table-row`. This yields a `TableRowFlow` with /// possibly other `TableCellFlow`s underneath it. fn build_flow_for_table_row(&mut self, node: &ThreadSafeLayoutNode) -> ConstructionResult { - let box_ = Box::new_from_specific_info(node, TableRowBox); - let flow = box TableRowFlow::from_node_and_box(node, box_) as owned::Box; + let box_ = Fragment::new_from_specific_info(node, TableRowFragment); + let flow = box TableRowFlow::from_node_and_box(node, box_) as Box; self.build_flow_using_children(flow, node) } /// Builds a flow for a node with `display: table-cell`. This yields a `TableCellFlow` with /// possibly other `BlockFlow`s or `InlineFlow`s underneath it. fn build_flow_for_table_cell(&mut self, node: &ThreadSafeLayoutNode) -> ConstructionResult { - let box_ = Box::new_from_specific_info(node, TableCellBox); - let flow = box TableCellFlow::from_node_and_box(node, box_) as owned::Box; + let box_ = Fragment::new_from_specific_info(node, TableCellFragment); + let flow = box TableCellFlow::from_node_and_box(node, box_) as Box; self.build_flow_using_children(flow, node) } @@ -790,9 +789,9 @@ impl<'a> FlowConstructor<'a> { kid.set_flow_construction_result(NoConstructionResult) } - let specific = TableColumnBox(TableColumnBoxInfo::new(node)); - let construction_item = TableColumnBoxConstructionItem( - Box::new_from_specific_info(node, specific) + let specific = TableColumnFragment(TableColumnFragmentInfo::new(node)); + let construction_item = TableColumnFragmentConstructionItem( + Fragment::new_from_specific_info(node, specific) ); ConstructionItemConstructionResult(construction_item) } @@ -800,26 +799,25 @@ impl<'a> FlowConstructor<'a> { /// Builds a flow for a node with `display: table-column-group`. /// This yields a `TableColGroupFlow`. fn build_flow_for_table_colgroup(&mut self, node: &ThreadSafeLayoutNode) -> ConstructionResult { - let box_ = Box::new_from_specific_info(node, - TableColumnBox(TableColumnBoxInfo::new(node))); + let box_ = Fragment::new_from_specific_info(node, + TableColumnFragment(TableColumnFragmentInfo::new(node))); let mut col_boxes = vec!(); for kid in node.children() { // CSS 2.1 § 17.2.1. Treat all non-column child boxes of `table-column-group` // as `display: none`. match kid.swap_out_construction_result() { - ConstructionItemConstructionResult(TableColumnBoxConstructionItem(box_)) => { + ConstructionItemConstructionResult(TableColumnFragmentConstructionItem(box_)) => { col_boxes.push(box_); } _ => {} } } if col_boxes.is_empty() { - debug!("add TableColumnBox for empty colgroup"); - let specific = TableColumnBox(TableColumnBoxInfo::new(node)); - col_boxes.push( Box::new_from_specific_info(node, specific) ); + debug!("add TableColumnFragment for empty colgroup"); + let specific = TableColumnFragment(TableColumnFragmentInfo::new(node)); + col_boxes.push(Fragment::new_from_specific_info(node, specific)); } - let mut flow = box TableColGroupFlow::from_node_and_boxes(node, box_, col_boxes) as - owned::Box; + let mut flow = box TableColGroupFlow::from_node_and_boxes(node, box_, col_boxes) as Box; flow.finish(self.layout_context); 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. -fn strip_ignorable_whitespace_from_start(boxes: &mut InlineBoxes) { +fn strip_ignorable_whitespace_from_start(boxes: &mut InlineFragments) { if boxes.len() == 0 { return } - let InlineBoxes { + let InlineFragments { boxes: old_boxes, map: mut map - } = mem::replace(boxes, InlineBoxes::new()); + } = mem::replace(boxes, InlineFragments::new()); // FIXME(#2264, pcwalton): This is slow because vector shift is broken. :( 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()); - *boxes = InlineBoxes { + *boxes = InlineFragments { boxes: new_boxes, map: map, } } /// 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 { return } - let InlineBoxes { + let InlineFragments { boxes: old_boxes, map: mut map - } = mem::replace(boxes, InlineBoxes::new()); + } = mem::replace(boxes, InlineFragments::new()); let mut new_boxes = old_boxes.clone(); 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()); - *boxes = InlineBoxes { + *boxes = InlineFragments { boxes: new_boxes, map: map, } diff --git a/src/components/main/layout/flow.rs b/src/components/main/layout/flow.rs index c5f882bf8cd..0e3538063f2 100644 --- a/src/components/main/layout/flow.rs +++ b/src/components/main/layout/flow.rs @@ -2,7 +2,7 @@ * 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/. */ -//! 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 //! computed in several tree traversals driven by the fundamental data dependencies required by /// inline and block layout. @@ -27,7 +27,7 @@ use css::node_style::StyledNode; use layout::block::BlockFlow; -use layout::box_::{Box, TableRowBox, TableCellBox}; +use layout::box_::{Fragment, TableRowFragment, TableCellFragment}; use layout::context::LayoutContext; use layout::floats::Floats; use layout::flow_list::{FlowList, Link, Rawlink, FlowListIterator, MutFlowListIterator}; @@ -58,7 +58,6 @@ use std::cast; use std::fmt; use std::iter::Zip; use std::num::Zero; -use std::owned; use std::sync::atomics::Relaxed; use std::slice::MutItems; use style::computed_values::{clear, position, text_align}; @@ -338,7 +337,7 @@ pub trait ImmutableFlowUtils { fn need_anonymous_flow(self, child: &Flow) -> bool; /// Generates missing child flow of this flow. - fn generate_missing_child_flow(self, node: &ThreadSafeLayoutNode) -> owned::Box; + fn generate_missing_child_flow(self, node: &ThreadSafeLayoutNode) -> Box; /// Returns true if this flow has no children. fn is_leaf(self) -> bool; @@ -392,7 +391,7 @@ pub trait MutableFlowUtils { pub trait MutableOwnedFlowUtils { /// Adds a new flow as a child of this flow. Removes the flow from the given leaf set if /// it's present. - fn add_new_child(&mut self, new_child: owned::Box); + fn add_new_child(&mut self, new_child: Box); /// 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) @@ -842,15 +841,15 @@ impl<'a> ImmutableFlowUtils for &'a Flow { } /// Generates missing child flow of this flow. - fn generate_missing_child_flow(self, node: &ThreadSafeLayoutNode) -> owned::Box { + fn generate_missing_child_flow(self, node: &ThreadSafeLayoutNode) -> Box { match self.class() { TableFlowClass | TableRowGroupFlowClass => { - let box_ = Box::new_anonymous_table_box(node, TableRowBox); - box TableRowFlow::from_node_and_box(node, box_) as owned::Box + let box_ = Fragment::new_anonymous_table_box(node, TableRowFragment); + box TableRowFlow::from_node_and_box(node, box_) as Box }, TableRowFlowClass => { - let box_ = Box::new_anonymous_table_box(node, TableCellBox); - box TableCellFlow::from_node_and_box(node, box_) as owned::Box + let box_ = Fragment::new_anonymous_table_box(node, TableCellFragment); + box TableCellFlow::from_node_and_box(node, box_) as Box }, _ => { fail!("no need to generate a missing child") @@ -1052,9 +1051,9 @@ impl<'a> MutableFlowUtils for &'a mut Flow { } } -impl MutableOwnedFlowUtils for owned::Box { +impl MutableOwnedFlowUtils for Box { /// 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) { + fn add_new_child(&mut self, mut new_child: Box) { { let kid_base = mut_base(new_child); kid_base.parallel.parent = parallel::mut_owned_flow_to_unsafe_flow(self); diff --git a/src/components/main/layout/inline.rs b/src/components/main/layout/inline.rs index e394be4c206..a92047bec8d 100644 --- a/src/components/main/layout/inline.rs +++ b/src/components/main/layout/inline.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 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::floats::{FloatLeft, Floats, PlacementInfo}; 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 /// as an object that "owns" boxes. Choosing a different set of line /// 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 /// the corresponding boxes in the inline flow. @@ -201,8 +201,8 @@ pub fn each_char_index(range: &Range) -> EachIndex struct LineboxScanner { pub floats: Floats, - pub new_boxes: Vec, - pub work_list: RingBuf, + pub new_boxes: Vec, + pub work_list: RingBuf, pub pending_line: LineBox, pub lines: Vec, pub cur_y: Au, @@ -246,10 +246,10 @@ impl LineboxScanner { self.reset_scanner(); // Swap out temporarily. - let InlineBoxes { + let InlineFragments { boxes: old_boxes, 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(); loop { @@ -276,7 +276,7 @@ impl LineboxScanner { }; 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.flush_current_line(); } else { @@ -291,7 +291,7 @@ impl LineboxScanner { } 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()), map: map, }; @@ -312,7 +312,7 @@ impl LineboxScanner { // 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. - 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(); if box_height > self.pending_line.bounds.size.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 /// of the line's green zone (whose origin coincides with the line's origin) and the actual /// 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) { 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. fn avoid_floats(&mut self, - in_box: Box, + in_box: Fragment, flow: &mut InlineFlow, new_height: Au, line_is_empty: bool) @@ -417,7 +417,7 @@ impl LineboxScanner { 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 { debug!("LineboxScanner: Did not find a new-line character, so pushing the box to \ the line without splitting."); @@ -429,8 +429,8 @@ impl LineboxScanner { Some((left, right, run)) => { // TODO(bjz): Remove box splitting let split_box = |split: SplitInfo| { - let info = ScannedTextBoxInfo::new(run.clone(), split.range); - let specific = ScannedTextBox(info); + let info = ScannedTextFragmentInfo::new(run.clone(), split.range); + let specific = ScannedTextFragment(info); let size = Size2D(split.width, in_box.border_box.size.height); 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 /// 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(); if line_is_empty { 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)| { // TODO(bjz): Remove box splitting let split_box = |split: SplitInfo| { - let info = ScannedTextBoxInfo::new(run.clone(), split.range); - let specific = ScannedTextBox(info); + let info = ScannedTextFragmentInfo::new(run.clone(), split.range); + let specific = ScannedTextFragment(info); let size = Size2D(split.width, in_box.border_box.size.height); in_box.transform(size, specific) }; @@ -553,7 +553,7 @@ impl LineboxScanner { } // 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()); if self.pending_line.range.length() == num::zero() { @@ -579,14 +579,14 @@ impl LineboxScanner { } /// Iterator over boxes. -pub struct BoxIterator<'a> { - iter: Enumerate>, +pub struct FragmentIterator<'a> { + iter: Enumerate>, map: &'a InlineFragmentMap, } -impl<'a> Iterator<(&'a Box, InlineFragmentContext<'a>)> for BoxIterator<'a> { +impl<'a> Iterator<(&'a Fragment, InlineFragmentContext<'a>)> for FragmentIterator<'a> { #[inline] - fn next(&mut self) -> Option<(&'a Box, InlineFragmentContext<'a>)> { + fn next(&mut self) -> Option<(&'a Fragment, InlineFragmentContext<'a>)> { match self.iter.next() { None => None, Some((i, fragment)) => Some(( @@ -598,14 +598,14 @@ impl<'a> Iterator<(&'a Box, InlineFragmentContext<'a>)> for BoxIterator<'a> { } /// Mutable iterator over boxes. -pub struct MutBoxIterator<'a> { - iter: Enumerate>, +pub struct MutFragmentIterator<'a> { + iter: Enumerate>, 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] - fn next(&mut self) -> Option<(&'a mut Box, InlineFragmentContext<'a>)> { + fn next(&mut self) -> Option<(&'a mut Fragment, InlineFragmentContext<'a>)> { match self.iter.next() { None => None, 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. -pub struct InlineBoxes { +pub struct InlineFragments { /// The boxes themselves. - pub boxes: Vec, + pub boxes: Vec, /// Tracks the elements that made up the boxes above. pub map: InlineFragmentMap, } -impl InlineBoxes { +impl InlineFragments { /// Creates an empty set of inline boxes. - pub fn new() -> InlineBoxes { - InlineBoxes { + pub fn new() -> InlineFragments { + InlineFragments { boxes: Vec::new(), map: InlineFragmentMap::new(), } @@ -644,14 +644,14 @@ impl InlineBoxes { } /// Pushes a new inline box. - pub fn push(&mut self, fragment: Box, style: Arc) { + pub fn push(&mut self, fragment: Fragment, style: Arc) { self.map.push(style, Range::new(FragmentIndex(self.boxes.len() as int), FragmentIndex(1))); self.boxes.push(fragment) } /// Merges another set of inline boxes with this one. - pub fn push_all(&mut self, other: InlineBoxes) { - let InlineBoxes { + pub fn push_all(&mut self, other: InlineFragments) { + let InlineFragments { boxes: other_boxes, map: other_map } = other; @@ -661,8 +661,8 @@ impl InlineBoxes { } /// Returns an iterator that iterates over all boxes along with the appropriate context. - pub fn iter<'a>(&'a self) -> BoxIterator<'a> { - BoxIterator { + pub fn iter<'a>(&'a self) -> FragmentIterator<'a> { + FragmentIterator { iter: self.boxes.as_slice().iter().enumerate(), map: &self.map, } @@ -670,20 +670,20 @@ impl InlineBoxes { /// Returns an iterator that iterates over all boxes along with the appropriate context and /// allows those boxes to be mutated. - pub fn mut_iter<'a>(&'a mut self) -> MutBoxIterator<'a> { - MutBoxIterator { + pub fn mut_iter<'a>(&'a mut self) -> MutFragmentIterator<'a> { + MutFragmentIterator { iter: self.boxes.as_mut_slice().mut_iter().enumerate(), map: &self.map, } } /// 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) } /// 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) } } @@ -694,7 +694,7 @@ pub struct InlineFlow { pub base: BaseFlow, /// 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 /// are the result of inline layout. This also includes some metadata used for positioning @@ -711,7 +711,7 @@ pub struct InlineFlow { } impl InlineFlow { - pub fn from_boxes(node: ThreadSafeLayoutNode, boxes: InlineBoxes) -> InlineFlow { + pub fn from_boxes(node: ThreadSafeLayoutNode, boxes: InlineFragments) -> InlineFlow { InlineFlow { base: BaseFlow::new(node), 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. /// 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, parent_text_top: Au, parent_text_bottom: Au, @@ -822,7 +822,7 @@ impl InlineFlow { } /// 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, linebox_align: text_align::T) { // Figure out how much width we have. @@ -901,7 +901,7 @@ impl Flow for InlineFlow { fn assign_widths(&mut self, _: &mut LayoutContext) { // 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); @@ -919,7 +919,7 @@ impl Flow for InlineFlow { // There are no child contexts, so stop here. // 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 // flow context's width as the assigned width of the // '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 /// `layout::construct::strip_ignorable_whitespace_from_start` for an example of some code that /// 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. let old_list = mem::replace(&mut self.list, Vec::new()); let mut worklist = Vec::new(); // FIXME(#2269, pcwalton): was smallvec4 diff --git a/src/components/main/layout/model.rs b/src/components/main/layout/model.rs index c790ba3b4f6..499c99339e5 100644 --- a/src/components/main/layout/model.rs +++ b/src/components/main/layout/model.rs @@ -4,7 +4,7 @@ //! Borders, padding, and margins. -use layout::box_::Box; +use layout::box_::Fragment; use computed = style::computed_values; use geom::SideOffsets2D; @@ -98,7 +98,7 @@ impl MarginCollapseInfo { } pub fn initialize_top_margin(&mut self, - fragment: &Box, + fragment: &Fragment, can_collapse_top_margin_with_kids: bool) { if !can_collapse_top_margin_with_kids { self.state = AccumulatingMarginIn @@ -108,7 +108,7 @@ impl MarginCollapseInfo { } pub fn finish_and_compute_collapsible_margins(mut self, - fragment: &Box, + fragment: &Fragment, can_collapse_bottom_margin_with_kids: bool) -> (CollapsibleMargins, Au) { let state = match self.state { diff --git a/src/components/main/layout/table.rs b/src/components/main/layout/table.rs index 5f5d8c8b343..5d90b64d701 100644 --- a/src/components/main/layout/table.rs +++ b/src/components/main/layout/table.rs @@ -4,7 +4,7 @@ //! CSS table formatting contexts. -use layout::box_::Box; +use layout::box_::Fragment; use layout::block::{BlockFlow, MarginsMayNotCollapse, WidthAndMarginsComputer}; use layout::block::{WidthConstraintInput, WidthConstraintSolution}; use layout::construct::FlowConstructor; @@ -40,7 +40,7 @@ pub struct TableFlow { impl TableFlow { pub fn from_node_and_box(node: &ThreadSafeLayoutNode, - box_: Box) + box_: Fragment) -> TableFlow { let mut block_flow = BlockFlow::from_node_and_box(node, box_); let table_layout = if block_flow.box_().style().get_table().table_layout == diff --git a/src/components/main/layout/table_cell.rs b/src/components/main/layout/table_cell.rs index 1d8714f1831..d48f2a19c42 100644 --- a/src/components/main/layout/table_cell.rs +++ b/src/components/main/layout/table_cell.rs @@ -4,7 +4,7 @@ //! CSS table formatting contexts. -use layout::box_::Box; +use layout::box_::Fragment; use layout::block::{BlockFlow, MarginsMayNotCollapse, WidthAndMarginsComputer}; use layout::context::LayoutContext; use layout::flow::{TableCellFlowClass, FlowClass, Flow}; @@ -22,17 +22,17 @@ pub struct 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 { 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_ } - 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_ } diff --git a/src/components/main/layout/table_colgroup.rs b/src/components/main/layout/table_colgroup.rs index 99c0659d109..77188ea1926 100644 --- a/src/components/main/layout/table_colgroup.rs +++ b/src/components/main/layout/table_colgroup.rs @@ -4,7 +4,7 @@ //! CSS table formatting contexts. -use layout::box_::{Box, TableColumnBox}; +use layout::box_::{Fragment, TableColumnFragment}; use layout::context::LayoutContext; use layout::flow::{BaseFlow, TableColGroupFlowClass, FlowClass, Flow}; use layout::model::{MaybeAuto}; @@ -19,10 +19,10 @@ pub struct TableColGroupFlow { pub base: BaseFlow, /// The associated box. - pub box_: Option, + pub box_: Option, /// The table column boxes - pub cols: Vec, + pub cols: Vec, /// The specified widths of table columns pub widths: Vec, @@ -30,8 +30,8 @@ pub struct TableColGroupFlow { impl TableColGroupFlow { pub fn from_node_and_boxes(node: &ThreadSafeLayoutNode, - box_: Box, - boxes: Vec) -> TableColGroupFlow { + box_: Fragment, + boxes: Vec) -> TableColGroupFlow { TableColGroupFlow { base: BaseFlow::new((*node).clone()), box_: Some(box_), @@ -57,7 +57,7 @@ impl Flow for TableColGroupFlow { Au::new(0)).specified_or_zero(); 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) }; for _ in range(0, span) { diff --git a/src/components/main/layout/table_row.rs b/src/components/main/layout/table_row.rs index ab1e2d22134..95efd34f53f 100644 --- a/src/components/main/layout/table_row.rs +++ b/src/components/main/layout/table_row.rs @@ -4,7 +4,7 @@ //! CSS table formatting contexts. -use layout::box_::Box; +use layout::box_::Fragment; use layout::block::BlockFlow; use layout::block::WidthAndMarginsComputer; use layout::construct::FlowConstructor; @@ -35,7 +35,7 @@ pub struct TableRowFlow { impl TableRowFlow { pub fn from_node_and_box(node: &ThreadSafeLayoutNode, - box_: Box) + box_: Fragment) -> TableRowFlow { TableRowFlow { 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_ } diff --git a/src/components/main/layout/table_rowgroup.rs b/src/components/main/layout/table_rowgroup.rs index 794a7d12493..b92f3bc0ccf 100644 --- a/src/components/main/layout/table_rowgroup.rs +++ b/src/components/main/layout/table_rowgroup.rs @@ -4,7 +4,7 @@ //! CSS table formatting contexts. -use layout::box_::Box; +use layout::box_::Fragment; use layout::block::BlockFlow; use layout::block::WidthAndMarginsComputer; use layout::construct::FlowConstructor; @@ -34,7 +34,7 @@ pub struct TableRowGroupFlow { impl TableRowGroupFlow { pub fn from_node_and_box(node: &ThreadSafeLayoutNode, - box_: Box) + box_: Fragment) -> TableRowGroupFlow { TableRowGroupFlow { 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_ } diff --git a/src/components/main/layout/table_wrapper.rs b/src/components/main/layout/table_wrapper.rs index 767b8afc8fd..f4d721d4435 100644 --- a/src/components/main/layout/table_wrapper.rs +++ b/src/components/main/layout/table_wrapper.rs @@ -4,7 +4,7 @@ //! CSS table formatting contexts. -use layout::box_::Box; +use layout::box_::Fragment; use layout::block::{BlockFlow, MarginsMayNotCollapse, WidthAndMarginsComputer}; use layout::block::{WidthConstraintInput, WidthConstraintSolution}; use layout::construct::FlowConstructor; @@ -37,7 +37,7 @@ pub struct TableWrapperFlow { impl TableWrapperFlow { pub fn from_node_and_box(node: &ThreadSafeLayoutNode, - box_: Box) + box_: Fragment) -> TableWrapperFlow { let mut block_flow = BlockFlow::from_node_and_box(node, box_); let table_layout = if block_flow.box_().style().get_table().table_layout == diff --git a/src/components/main/layout/text.rs b/src/components/main/layout/text.rs index 11f92d8d61b..4dd3fae53f0 100644 --- a/src/components/main/layout/text.rs +++ b/src/components/main/layout/text.rs @@ -4,9 +4,9 @@ //! Text layout. -use layout::box_::{Box, ScannedTextBox, ScannedTextBoxInfo, UnscannedTextBox}; +use layout::box_::{Fragment, ScannedTextFragment, ScannedTextFragmentInfo, UnscannedTextFragment}; use layout::flow::Flow; -use layout::inline::InlineBoxes; +use layout::inline::InlineFragments; use gfx::font::{FontMetrics, FontStyle}; use gfx::font_context::FontContext; @@ -25,12 +25,12 @@ struct NewLinePositions { } // 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); 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 clump: Range, } @@ -48,10 +48,10 @@ impl TextRunScanner { debug!("TextRunScanner: scanning {:u} boxes for text runs...", inline.boxes.len()); } - let InlineBoxes { + let InlineFragments { boxes: old_boxes, 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 new_boxes = Vec::new(); @@ -79,7 +79,7 @@ impl TextRunScanner { // Swap out the old and new box list of the flow. map.fixup(old_boxes.as_slice(), new_boxes.as_slice()); - flow.as_inline().boxes = InlineBoxes { + flow.as_inline().boxes = InlineFragments { boxes: new_boxes, map: map, } @@ -96,8 +96,8 @@ impl TextRunScanner { /// with some smaller stub. pub fn flush_clump_to_list(&mut self, font_context: &mut FontContext, - in_boxes: &[Box], - out_boxes: &mut Vec, + in_boxes: &[Fragment], + out_boxes: &mut Vec, last_whitespace: bool) -> bool { assert!(self.clump.length() > CharIndex(0)); @@ -106,7 +106,7 @@ impl TextRunScanner { let is_singleton = self.clump.length() == CharIndex(1); let is_text_clump = match in_boxes[self.clump.begin().to_uint()].specific { - UnscannedTextBox(_) => true, + UnscannedTextFragment(_) => true, _ => false, }; @@ -124,7 +124,7 @@ impl TextRunScanner { (true, true) => { let old_box = &in_boxes[self.clump.begin().to_uint()]; 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!"), }; @@ -159,9 +159,9 @@ impl TextRunScanner { *text); let range = Range::new(CharIndex(0), run.char_len()); 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, - ScannedTextBox(new_text_box_info)); + ScannedTextFragment(new_text_box_info)); new_box.new_line_pos = new_line_pos; out_boxes.push(new_box) } @@ -191,7 +191,7 @@ impl TextRunScanner { // be compressed correctly with respect to the text run. let idx = CharIndex(i as int) + self.clump.begin(); 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!"), }; @@ -243,10 +243,10 @@ impl TextRunScanner { 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 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(); out_boxes.push(new_box) }