layout: Eliminate the virtual is_float() in favor of the flow flags

This commit is contained in:
Patrick Walton 2014-11-05 10:06:28 -08:00
parent f5c6146de0
commit be36fcd3b1
4 changed files with 20 additions and 26 deletions

View file

@ -639,7 +639,7 @@ impl BlockFlow {
} else { } else {
AbsoluteNonReplacedType AbsoluteNonReplacedType
} }
} else if self.is_float() { } else if self.base.flags.is_float() {
if self.is_replaced_content() { if self.is_replaced_content() {
FloatReplacedType FloatReplacedType
} else { } else {
@ -877,7 +877,7 @@ impl BlockFlow {
// Assign block-size now for the child if it was impacted by floats and we couldn't // Assign block-size now for the child if it was impacted by floats and we couldn't
// before. // before.
flow::mut_base(kid).floats = floats.clone(); flow::mut_base(kid).floats = floats.clone();
if kid.is_float() { if flow::base(kid).flags.is_float() {
flow::mut_base(kid).position.start.b = cur_b; flow::mut_base(kid).position.start.b = cur_b;
{ {
let kid_block = kid.as_block(); let kid_block = kid.as_block();
@ -1225,7 +1225,7 @@ impl BlockFlow {
pub fn propagate_and_compute_used_inline_size(&mut self, layout_context: &LayoutContext) { pub fn propagate_and_compute_used_inline_size(&mut self, layout_context: &LayoutContext) {
let containing_block_inline_size = self.base.block_container_inline_size; let containing_block_inline_size = self.base.block_container_inline_size;
self.compute_used_inline_size(layout_context, containing_block_inline_size); self.compute_used_inline_size(layout_context, containing_block_inline_size);
if self.is_float() { if self.base.flags.is_float() {
self.float.as_mut().unwrap().containing_inline_size = containing_block_inline_size; self.float.as_mut().unwrap().containing_inline_size = containing_block_inline_size;
} }
} }
@ -1547,7 +1547,7 @@ impl Flow for BlockFlow {
} }
debug!("assign_inline_sizes({}): assigning inline_size for flow", debug!("assign_inline_sizes({}): assigning inline_size for flow",
if self.is_float() { if self.base.flags.is_float() {
"float" "float"
} else { } else {
"block" "block"
@ -1612,7 +1612,7 @@ impl Flow for BlockFlow {
fn assign_block_size_for_inorder_child_if_necessary<'a>(&mut self, fn assign_block_size_for_inorder_child_if_necessary<'a>(&mut self,
layout_context: &'a LayoutContext<'a>) layout_context: &'a LayoutContext<'a>)
-> bool { -> bool {
if self.is_float() { if self.base.flags.is_float() {
self.place_float(); self.place_float();
return true return true
} }
@ -1655,7 +1655,7 @@ impl Flow for BlockFlow {
if !self.base.flags.contains(IS_ABSOLUTELY_POSITIONED) { if !self.base.flags.contains(IS_ABSOLUTELY_POSITIONED) {
self.base.position.size.block = self.fragment.border_box.size.block; self.base.position.size.block = self.fragment.border_box.size.block;
} }
} else if self.is_root() || self.is_float() || self.is_inline_block() { } else if self.is_root() || self.base.flags.is_float() || self.is_inline_block() {
// Root element margins should never be collapsed according to CSS § 8.3.1. // Root element margins should never be collapsed according to CSS § 8.3.1.
debug!("assign_block_size: assigning block_size for root flow"); debug!("assign_block_size: assigning block_size for root flow");
self.assign_block_size_block_base(ctx, MarginsMayNotCollapse); self.assign_block_size_block_base(ctx, MarginsMayNotCollapse);
@ -1772,10 +1772,6 @@ impl Flow for BlockFlow {
self.flags.contains(IS_ROOT) self.flags.contains(IS_ROOT)
} }
fn is_float(&self) -> bool {
self.float.is_some()
}
/// The 'position' property of this flow. /// The 'position' property of this flow.
fn positioning(&self) -> position::T { fn positioning(&self) -> position::T {
self.fragment.style.get_box().position self.fragment.style.get_box().position
@ -1822,7 +1818,7 @@ impl Flow for BlockFlow {
} }
fn build_display_list(&mut self, layout_context: &LayoutContext) { fn build_display_list(&mut self, layout_context: &LayoutContext) {
if self.is_float() { if self.base.flags.is_float() {
// TODO(#2009, pcwalton): This is a pseudo-stacking context. We need to merge `z-index: // TODO(#2009, pcwalton): This is a pseudo-stacking context. We need to merge `z-index:
// auto` kids into the parent stacking context, when that is supported. // auto` kids into the parent stacking context, when that is supported.
self.build_display_list_for_floating_block(layout_context) self.build_display_list_for_floating_block(layout_context)

View file

@ -241,10 +241,6 @@ pub trait Flow: fmt::Show + ToString + Sync {
false false
} }
fn is_float(&self) -> bool {
false
}
/// The 'position' property of this flow. /// The 'position' property of this flow.
fn positioning(&self) -> position::T { fn positioning(&self) -> position::T {
position::static_ position::static_
@ -570,6 +566,11 @@ impl FlowFlags {
} }
} }
#[inline]
pub fn is_float(&self) -> bool {
self.floats_left() || self.floats_right()
}
#[inline] #[inline]
pub fn clears_floats(&self) -> bool { pub fn clears_floats(&self) -> bool {
self.contains(CLEARS_LEFT) || self.contains(CLEARS_RIGHT) self.contains(CLEARS_LEFT) || self.contains(CLEARS_RIGHT)

View file

@ -1116,7 +1116,8 @@ impl Flow for InlineFlow {
// Assign block sizes for any inline-block descendants. // Assign block sizes for any inline-block descendants.
for kid in self.base.child_iter() { for kid in self.base.child_iter() {
if flow::base(kid).flags.contains(IS_ABSOLUTELY_POSITIONED) || kid.is_float() { if flow::base(kid).flags.contains(IS_ABSOLUTELY_POSITIONED) ||
flow::base(kid).flags.is_float() {
continue continue
} }
kid.assign_block_size_for_inorder_child_if_necessary(layout_context); kid.assign_block_size_for_inorder_child_if_necessary(layout_context);

View file

@ -191,7 +191,7 @@ impl TableWrapperFlow {
layout_context: &LayoutContext, layout_context: &LayoutContext,
parent_flow_inline_size: Au) { parent_flow_inline_size: Au) {
// Delegate to the appropriate inline size computer to find the constraint inputs. // Delegate to the appropriate inline size computer to find the constraint inputs.
let input = if self.is_float() { let input = if self.block_flow.base.flags.is_float() {
FloatNonReplaced.compute_inline_size_constraint_inputs(&mut self.block_flow, FloatNonReplaced.compute_inline_size_constraint_inputs(&mut self.block_flow,
parent_flow_inline_size, parent_flow_inline_size,
layout_context) layout_context)
@ -202,7 +202,7 @@ impl TableWrapperFlow {
}; };
// Delegate to the appropriate inline size computer to write the constraint solutions in. // Delegate to the appropriate inline size computer to write the constraint solutions in.
if self.is_float() { if self.block_flow.base.flags.is_float() {
let solution = FloatNonReplaced.solve_inline_size_constraints(&mut self.block_flow, let solution = FloatNonReplaced.solve_inline_size_constraints(&mut self.block_flow,
&input); &input);
FloatNonReplaced.set_inline_size_constraint_solutions(&mut self.block_flow, solution); FloatNonReplaced.set_inline_size_constraint_solutions(&mut self.block_flow, solution);
@ -221,10 +221,6 @@ impl Flow for TableWrapperFlow {
TableWrapperFlowClass TableWrapperFlowClass
} }
fn is_float(&self) -> bool {
self.block_flow.is_float()
}
fn as_table_wrapper<'a>(&'a mut self) -> &'a mut TableWrapperFlow { fn as_table_wrapper<'a>(&'a mut self) -> &'a mut TableWrapperFlow {
self self
} }
@ -251,7 +247,7 @@ impl Flow for TableWrapperFlow {
fn assign_inline_sizes(&mut self, layout_context: &LayoutContext) { fn assign_inline_sizes(&mut self, layout_context: &LayoutContext) {
debug!("assign_inline_sizes({}): assigning inline_size for flow", debug!("assign_inline_sizes({}): assigning inline_size for flow",
if self.is_float() { if self.block_flow.base.flags.is_float() {
"floated table_wrapper" "floated table_wrapper"
} else { } else {
"table_wrapper" "table_wrapper"
@ -267,7 +263,7 @@ impl Flow for TableWrapperFlow {
// Our inline-size was set to the inline-size of the containing block by the flow's parent. // Our inline-size was set to the inline-size of the containing block by the flow's parent.
// Now compute the real value. // Now compute the real value.
let containing_block_inline_size = self.block_flow.base.block_container_inline_size; let containing_block_inline_size = self.block_flow.base.block_container_inline_size;
if self.is_float() { if self.block_flow.base.flags.is_float() {
self.block_flow.float.as_mut().unwrap().containing_inline_size = self.block_flow.float.as_mut().unwrap().containing_inline_size =
containing_block_inline_size; containing_block_inline_size;
} }
@ -308,7 +304,7 @@ impl Flow for TableWrapperFlow {
fn assign_block_size_for_inorder_child_if_necessary<'a>(&mut self, fn assign_block_size_for_inorder_child_if_necessary<'a>(&mut self,
layout_context: &'a LayoutContext<'a>) layout_context: &'a LayoutContext<'a>)
-> bool { -> bool {
if self.block_flow.is_float() { if self.block_flow.base.flags.is_float() {
self.block_flow.place_float(); self.block_flow.place_float();
return true return true
} }
@ -343,7 +339,7 @@ impl Flow for TableWrapperFlow {
impl fmt::Show for TableWrapperFlow { impl fmt::Show for TableWrapperFlow {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if self.is_float() { if self.block_flow.base.flags.is_float() {
write!(f, "TableWrapperFlow(Float): {}", self.block_flow.fragment) write!(f, "TableWrapperFlow(Float): {}", self.block_flow.fragment)
} else { } else {
write!(f, "TableWrapperFlow: {}", self.block_flow.fragment) write!(f, "TableWrapperFlow: {}", self.block_flow.fragment)