auto merge of #1310 : pcwalton/servo/refactor, r=pcwalton

Here are some refactorings. They depend on #1309, so need to wait for r+ on that first.

r? @metajack
This commit is contained in:
bors-servo 2014-01-13 14:43:05 -08:00
commit fc76107a92
4 changed files with 27 additions and 91 deletions

View file

@ -7,7 +7,7 @@
use layout::box_::Box;
use layout::context::LayoutContext;
use layout::display_list_builder::{DisplayListBuilder, ExtraDisplayListData};
use layout::flow::{BlockFlowClass, FlowClass, Flow, FlowData, ImmutableFlowUtils};
use layout::flow::{BaseFlow, BlockFlowClass, FlowClass, Flow, ImmutableFlowUtils};
use layout::flow;
use layout::model::{MaybeAuto, Specified, Auto, specified_or_none, specified};
use layout::float_context::{FloatContext, PlacementInfo, Invalid, FloatType};
@ -50,7 +50,7 @@ impl FloatedBlockInfo {
/// A block formatting context.
pub struct BlockFlow {
/// Data common to all flows.
base: FlowData,
base: BaseFlow,
/// The associated box.
box_: Option<Box>,
@ -63,7 +63,7 @@ pub struct BlockFlow {
}
impl BlockFlow {
pub fn new(base: FlowData) -> BlockFlow {
pub fn new(base: BaseFlow) -> BlockFlow {
BlockFlow {
base: base,
box_: None,
@ -72,7 +72,7 @@ impl BlockFlow {
}
}
pub fn from_box(base: FlowData, box_: Box) -> BlockFlow {
pub fn from_box(base: BaseFlow, box_: Box) -> BlockFlow {
BlockFlow {
base: base,
box_: Some(box_),
@ -81,7 +81,7 @@ impl BlockFlow {
}
}
pub fn float_from_box(base: FlowData, float_type: FloatType, box_: Box) -> BlockFlow {
pub fn float_from_box(base: BaseFlow, float_type: FloatType, box_: Box) -> BlockFlow {
BlockFlow {
base: base,
box_: Some(box_),
@ -90,7 +90,7 @@ impl BlockFlow {
}
}
pub fn new_root(base: FlowData) -> BlockFlow {
pub fn new_root(base: BaseFlow) -> BlockFlow {
BlockFlow {
base: base,
box_: None,
@ -99,7 +99,7 @@ impl BlockFlow {
}
}
pub fn new_float(base: FlowData, float_type: FloatType) -> BlockFlow {
pub fn new_float(base: BaseFlow, float_type: FloatType) -> BlockFlow {
BlockFlow {
base: base,
box_: None,

View file

@ -26,7 +26,7 @@ use layout::box_::{Box, GenericBox, IframeBox, IframeBoxInfo, ImageBox, ImageBox
use layout::box_::{UnscannedTextBox, UnscannedTextBoxInfo};
use layout::context::LayoutContext;
use layout::float_context::FloatType;
use layout::flow::{Flow, FlowData, MutableFlowUtils};
use layout::flow::{BaseFlow, Flow, MutableFlowUtils};
use layout::inline::InlineFlow;
use layout::text::TextRunScanner;
use layout::util::LayoutDataAccess;
@ -234,7 +234,7 @@ impl<'fc> FlowConstructor<'fc> {
#[inline(always)]
fn flush_inline_boxes_to_flow(&mut self, boxes: ~[Box], flow: &mut ~Flow, node: LayoutNode) {
if boxes.len() > 0 {
let inline_base = FlowData::new(self.next_flow_id(), node);
let inline_base = BaseFlow::new(self.next_flow_id(), node);
let mut inline_flow = ~InlineFlow::from_boxes(inline_base, boxes) as ~Flow;
TextRunScanner::new().scan_for_runs(self.layout_context, inline_flow);
flow.add_new_child(inline_flow)
@ -344,7 +344,7 @@ impl<'fc> FlowConstructor<'fc> {
/// other `BlockFlow`s or `InlineFlow`s underneath it, depending on whether {ib} splits needed
/// to happen.
fn build_flow_for_block(&mut self, node: LayoutNode) -> ~Flow {
let base = FlowData::new(self.next_flow_id(), node);
let base = BaseFlow::new(self.next_flow_id(), node);
let box_ = self.build_box_for_node(node);
let mut flow = ~BlockFlow::from_box(base, box_) as ~Flow;
self.build_children_of_block_flow(&mut flow, node);
@ -355,7 +355,7 @@ impl<'fc> FlowConstructor<'fc> {
/// a `BlockFlow` underneath it.
fn build_flow_for_floated_block(&mut self, node: LayoutNode, float_type: FloatType)
-> ~Flow {
let base = FlowData::new(self.next_flow_id(), node);
let base = BaseFlow::new(self.next_flow_id(), node);
let box_ = self.build_box_for_node(node);
let mut flow = ~BlockFlow::float_from_box(base, float_type, box_) as ~Flow;
self.build_children_of_block_flow(&mut flow, node);

View file

@ -119,9 +119,9 @@ pub trait Flow {
// Base access
#[inline(always)]
pub fn base<'a>(this: &'a Flow) -> &'a FlowData {
pub fn base<'a>(this: &'a Flow) -> &'a BaseFlow {
unsafe {
let (_, ptr): (uint, &FlowData) = cast::transmute(this);
let (_, ptr): (uint, &BaseFlow) = cast::transmute(this);
ptr
}
}
@ -132,9 +132,9 @@ pub fn imm_child_iter<'a>(flow: &'a Flow) -> DListIterator<'a,~Flow> {
}
#[inline(always)]
pub fn mut_base<'a>(this: &'a mut Flow) -> &'a mut FlowData {
pub fn mut_base<'a>(this: &'a mut Flow) -> &'a mut BaseFlow {
unsafe {
let (_, ptr): (uint, &mut FlowData) = cast::transmute(this);
let (_, ptr): (uint, &mut BaseFlow) = cast::transmute(this);
ptr
}
}
@ -210,67 +210,8 @@ pub trait MutableFlowUtils {
}
pub enum FlowClass {
AbsoluteFlowClass,
BlockFlowClass,
InlineBlockFlowClass,
InlineFlowClass,
TableFlowClass,
}
// Miscellaneous flows that are not yet implemented.
pub struct AbsoluteFlow {
base: FlowData,
}
impl AbsoluteFlow {
pub fn new(base: FlowData) -> AbsoluteFlow {
AbsoluteFlow {
base: base,
}
}
}
impl Flow for AbsoluteFlow {
fn class(&self) -> FlowClass {
AbsoluteFlowClass
}
}
pub struct InlineBlockFlow {
base: FlowData,
}
impl InlineBlockFlow {
pub fn new(base: FlowData) -> InlineBlockFlow {
InlineBlockFlow {
base: base,
}
}
}
impl Flow for InlineBlockFlow {
fn class(&self) -> FlowClass {
InlineBlockFlowClass
}
}
pub struct TableFlow {
base: FlowData,
}
impl TableFlow {
pub fn new(base: FlowData) -> TableFlow {
TableFlow {
base: base,
}
}
}
impl Flow for TableFlow {
fn class(&self) -> FlowClass {
TableFlowClass
}
}
/// A top-down traversal.
@ -378,10 +319,7 @@ impl FlowFlags {
}
/// Data common to all flows.
///
/// FIXME: We need a naming convention for pseudo-inheritance like this. How about
/// `CommonFlowInfo`?
pub struct FlowData {
pub struct BaseFlow {
restyle_damage: RestyleDamage,
/// The children of this flow.
@ -430,11 +368,11 @@ impl Iterator<@Box> for BoxIterator {
}
}
impl FlowData {
impl BaseFlow {
#[inline]
pub fn new(id: int, node: LayoutNode) -> FlowData {
pub fn new(id: int, node: LayoutNode) -> BaseFlow {
let style = node.style();
FlowData {
BaseFlow {
restyle_damage: node.restyle_damage(),
children: DList::new(),
@ -464,7 +402,7 @@ impl<'a> ImmutableFlowUtils for &'a Flow {
fn is_block_like(self) -> bool {
match self.class() {
BlockFlowClass => true,
AbsoluteFlowClass | InlineBlockFlowClass | InlineFlowClass | TableFlowClass => false,
InlineFlowClass => false,
}
}
@ -476,8 +414,8 @@ impl<'a> ImmutableFlowUtils for &'a Flow {
/// Returns true if this flow is a block flow, an inline-block flow, or a float flow.
fn starts_block_flow(self) -> bool {
match self.class() {
BlockFlowClass | InlineBlockFlowClass => true,
AbsoluteFlowClass | InlineFlowClass | TableFlowClass => false,
BlockFlowClass => true,
InlineFlowClass => false,
}
}
@ -485,8 +423,7 @@ impl<'a> ImmutableFlowUtils for &'a Flow {
fn starts_inline_flow(self) -> bool {
match self.class() {
InlineFlowClass => true,
AbsoluteFlowClass | BlockFlowClass | InlineBlockFlowClass |
TableFlowClass => false,
BlockFlowClass => false,
}
}
@ -593,7 +530,6 @@ impl<'a> MutableFlowUtils for &'a mut Flow {
match self.class() {
BlockFlowClass => self.as_block().build_display_list_block(builder, dirty, list),
InlineFlowClass => self.as_inline().build_display_list_inline(builder, dirty, list),
_ => fail!("Tried to build_display_list_recurse of flow: {:?}", self),
};
if list.with_mut(|list| list.list.len() == 0) {

View file

@ -7,7 +7,7 @@ use layout::box_::{Box, CannotSplit, GenericBox, IframeBox, ImageBox, ScannedTex
use layout::box_::{SplitDidNotFit, UnscannedTextBox};
use layout::context::LayoutContext;
use layout::display_list_builder::{DisplayListBuilder, ExtraDisplayListData};
use layout::flow::{FlowClass, Flow, FlowData, InlineFlowClass};
use layout::flow::{BaseFlow, FlowClass, Flow, InlineFlowClass};
use layout::flow;
use layout::float_context::FloatContext;
use layout::util::ElementMapping;
@ -419,7 +419,7 @@ impl LineboxScanner {
pub struct InlineFlow {
/// Data common to all flows.
base: FlowData,
base: BaseFlow,
/// A vector of all inline render boxes. Several boxes may correspond to one node/element.
boxes: ~[Box],
@ -436,7 +436,7 @@ pub struct InlineFlow {
}
impl InlineFlow {
pub fn new(base: FlowData) -> InlineFlow {
pub fn new(base: BaseFlow) -> InlineFlow {
InlineFlow {
base: base,
boxes: ~[],
@ -445,7 +445,7 @@ impl InlineFlow {
}
}
pub fn from_boxes(base: FlowData, boxes: ~[Box]) -> InlineFlow {
pub fn from_boxes(base: BaseFlow, boxes: ~[Box]) -> InlineFlow {
InlineFlow {
base: base,
boxes: boxes,