mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
layout: Promote absolute positioning, floatedness, and clearance into
flags to avoid virtual calls. These were showing up really high in the maze solver profile.
This commit is contained in:
parent
c20bb66aef
commit
587cf98209
7 changed files with 156 additions and 133 deletions
|
@ -29,6 +29,7 @@
|
|||
|
||||
use construct::FlowConstructor;
|
||||
use context::LayoutContext;
|
||||
use css::node_style::StyledNode;
|
||||
use display_list_builder::{BlockFlowDisplayListBuilding, FragmentDisplayListBuilding};
|
||||
use floats::{ClearBoth, ClearLeft, ClearRight, FloatKind, FloatLeft, Floats, PlacementInfo};
|
||||
use flow::{BaseFlow, BlockFlowClass, FlowClass, Flow, ImmutableFlowUtils};
|
||||
|
@ -51,8 +52,8 @@ use servo_util::opts;
|
|||
use std::cmp::{max, min};
|
||||
use std::fmt;
|
||||
use style::computed_values::{LPA_Auto, LPA_Length, LPA_Percentage, LPN_Length, LPN_None};
|
||||
use style::computed_values::{LPN_Percentage, LP_Length, LP_Percentage, box_sizing, clear};
|
||||
use style::computed_values::{display, float, overflow, position};
|
||||
use style::computed_values::{LPN_Percentage, LP_Length, LP_Percentage, box_sizing, display, float};
|
||||
use style::computed_values::{overflow, position};
|
||||
|
||||
/// Information specific to floated blocks.
|
||||
#[deriving(Clone, Encodable)]
|
||||
|
@ -462,7 +463,7 @@ impl<'a> PostorderFlowTraversal for AbsoluteStoreOverflowTraversal<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
enum BlockType {
|
||||
pub enum BlockType {
|
||||
BlockReplacedType,
|
||||
BlockNonReplacedType,
|
||||
AbsoluteReplacedType,
|
||||
|
@ -550,8 +551,9 @@ impl<'a,E,S> Encodable<S,E> for BlockFlowFlags where S: Encoder<E> {
|
|||
|
||||
impl BlockFlow {
|
||||
pub fn from_node(constructor: &mut FlowConstructor, node: &ThreadSafeLayoutNode) -> BlockFlow {
|
||||
let writing_mode = node.style().writing_mode;
|
||||
BlockFlow {
|
||||
base: BaseFlow::new((*node).clone()),
|
||||
base: BaseFlow::new(Some((*node).clone()), writing_mode),
|
||||
fragment: Fragment::new(constructor, node),
|
||||
static_b_offset: Au::new(0),
|
||||
inline_size_of_preceding_left_floats: Au(0),
|
||||
|
@ -562,8 +564,9 @@ impl BlockFlow {
|
|||
}
|
||||
|
||||
pub fn from_node_and_fragment(node: &ThreadSafeLayoutNode, fragment: Fragment) -> BlockFlow {
|
||||
let writing_mode = node.style().writing_mode;
|
||||
BlockFlow {
|
||||
base: BaseFlow::new((*node).clone()),
|
||||
base: BaseFlow::new(Some((*node).clone()), writing_mode),
|
||||
fragment: fragment,
|
||||
static_b_offset: Au::new(0),
|
||||
inline_size_of_preceding_left_floats: Au(0),
|
||||
|
@ -577,14 +580,14 @@ impl BlockFlow {
|
|||
node: &ThreadSafeLayoutNode,
|
||||
float_kind: FloatKind)
|
||||
-> BlockFlow {
|
||||
let base = BaseFlow::new((*node).clone());
|
||||
let writing_mode = node.style().writing_mode;
|
||||
BlockFlow {
|
||||
base: BaseFlow::new(Some((*node).clone()), writing_mode),
|
||||
fragment: Fragment::new(constructor, node),
|
||||
static_b_offset: Au::new(0),
|
||||
inline_size_of_preceding_left_floats: Au(0),
|
||||
inline_size_of_preceding_right_floats: Au(0),
|
||||
float: Some(box FloatedBlockInfo::new(float_kind)),
|
||||
base: base,
|
||||
flags: BlockFlowFlags::empty(),
|
||||
}
|
||||
}
|
||||
|
@ -593,14 +596,14 @@ impl BlockFlow {
|
|||
fragment: Fragment,
|
||||
float_kind: FloatKind)
|
||||
-> BlockFlow {
|
||||
let base = BaseFlow::new((*node).clone());
|
||||
let writing_mode = node.style().writing_mode;
|
||||
BlockFlow {
|
||||
base: BaseFlow::new(Some((*node).clone()), writing_mode),
|
||||
fragment: fragment,
|
||||
static_b_offset: Au::new(0),
|
||||
inline_size_of_preceding_left_floats: Au(0),
|
||||
inline_size_of_preceding_right_floats: Au(0),
|
||||
float: Some(box FloatedBlockInfo::new(float_kind)),
|
||||
base: base,
|
||||
flags: BlockFlowFlags::empty(),
|
||||
}
|
||||
}
|
||||
|
@ -609,8 +612,8 @@ impl BlockFlow {
|
|||
///
|
||||
/// This determines the algorithm used to calculate inline-size, block-size, and the
|
||||
/// relevant margins for this Block.
|
||||
fn block_type(&self) -> BlockType {
|
||||
if self.is_absolutely_positioned() {
|
||||
pub fn block_type(&self) -> BlockType {
|
||||
if self.base.flags.is_absolutely_positioned() {
|
||||
if self.is_replaced_content() {
|
||||
AbsoluteReplacedType
|
||||
} else {
|
||||
|
@ -686,7 +689,7 @@ impl BlockFlow {
|
|||
/// reference the CB.
|
||||
#[inline]
|
||||
pub fn containing_block_size(&mut self, viewport_size: Size2D<Au>) -> LogicalSize<Au> {
|
||||
debug_assert!(self.is_absolutely_positioned());
|
||||
debug_assert!(self.base.flags.is_absolutely_positioned());
|
||||
if self.is_fixed() {
|
||||
// Initial containing block is the CB for the root
|
||||
LogicalSize::from_physical(self.base.writing_mode, viewport_size)
|
||||
|
@ -813,7 +816,8 @@ impl BlockFlow {
|
|||
|
||||
// Absolute positioning establishes a block formatting context. Don't propagate floats
|
||||
// in or out. (But do propagate them between kids.)
|
||||
if self.is_absolutely_positioned() || margins_may_collapse != MarginsMayCollapse {
|
||||
if self.base.flags.is_absolutely_positioned() ||
|
||||
margins_may_collapse != MarginsMayCollapse {
|
||||
self.base.floats = Floats::new(self.fragment.style.writing_mode);
|
||||
}
|
||||
|
||||
|
@ -827,7 +831,7 @@ impl BlockFlow {
|
|||
|
||||
let can_collapse_block_start_margin_with_kids =
|
||||
margins_may_collapse == MarginsMayCollapse &&
|
||||
!self.is_absolutely_positioned() &&
|
||||
!self.base.flags.is_absolutely_positioned() &&
|
||||
self.fragment.border_padding.block_start == Au(0);
|
||||
margin_collapse_info.initialize_block_start_margin(
|
||||
&self.fragment,
|
||||
|
@ -837,7 +841,7 @@ impl BlockFlow {
|
|||
let mut floats = self.base.floats.clone();
|
||||
let mut layers_needed_for_descendants = false;
|
||||
for kid in self.base.child_iter() {
|
||||
if kid.is_absolutely_positioned() {
|
||||
if flow::base(kid).flags.is_absolutely_positioned() {
|
||||
// Assume that the *hypothetical box* for an absolute flow starts immediately after
|
||||
// the block-end border edge of the previous flow.
|
||||
flow::mut_base(kid).position.start.b = cur_b;
|
||||
|
@ -877,7 +881,7 @@ impl BlockFlow {
|
|||
// with margin collapse. Possibly the right thing to do is to lay out the block again
|
||||
// in this rare case. (Note that WebKit can lay blocks out twice; this may be related,
|
||||
// although I haven't looked into it closely.)
|
||||
if kid.float_clearance() != clear::none {
|
||||
if flow::base(kid).flags.clears_floats() {
|
||||
flow::mut_base(kid).floats = Floats::new(self.fragment.style.writing_mode)
|
||||
}
|
||||
|
||||
|
@ -894,11 +898,12 @@ impl BlockFlow {
|
|||
translate_including_floats(&mut cur_b, delta, &mut floats);
|
||||
|
||||
// Clear past the floats that came in, if necessary.
|
||||
let clearance = match kid.float_clearance() {
|
||||
clear::none => Au(0),
|
||||
clear::left => floats.clearance(ClearLeft),
|
||||
clear::right => floats.clearance(ClearRight),
|
||||
clear::both => floats.clearance(ClearBoth),
|
||||
let clearance = match (flow::base(kid).flags.clears_left(),
|
||||
flow::base(kid).flags.clears_right()) {
|
||||
(false, false) => Au(0),
|
||||
(true, false) => floats.clearance(ClearLeft),
|
||||
(false, true) => floats.clearance(ClearRight),
|
||||
(true, true) => floats.clearance(ClearBoth),
|
||||
};
|
||||
translate_including_floats(&mut cur_b, clearance, &mut floats);
|
||||
|
||||
|
@ -933,7 +938,7 @@ impl BlockFlow {
|
|||
// Add in our block-end margin and compute our collapsible margins.
|
||||
let can_collapse_block_end_margin_with_kids =
|
||||
margins_may_collapse == MarginsMayCollapse &&
|
||||
!self.is_absolutely_positioned() &&
|
||||
!self.base.flags.is_absolutely_positioned() &&
|
||||
self.fragment.border_padding.block_end == Au(0);
|
||||
let (collapsible_margins, delta) =
|
||||
margin_collapse_info.finish_and_compute_collapsible_margins(
|
||||
|
@ -955,13 +960,13 @@ impl BlockFlow {
|
|||
}
|
||||
|
||||
if is_root || self.formatting_context_type() != NonformattingContext ||
|
||||
self.is_absolutely_positioned() {
|
||||
self.base.flags.is_absolutely_positioned() {
|
||||
// The content block-size includes all the floats per CSS 2.1 § 10.6.7. The easiest way
|
||||
// to handle this is to just treat this as clearance.
|
||||
block_size = block_size + floats.clearance(ClearBoth);
|
||||
}
|
||||
|
||||
if self.is_absolutely_positioned() {
|
||||
if self.base.flags.is_absolutely_positioned() {
|
||||
// Fixed position layers get layers.
|
||||
if self.is_fixed() {
|
||||
self.base.flags.set_needs_layer(true)
|
||||
|
@ -1251,7 +1256,7 @@ impl BlockFlow {
|
|||
kid_base.fixed_static_i_offset = fixed_static_i_offset;
|
||||
}
|
||||
|
||||
match kid.float_kind() {
|
||||
match flow::base(kid).flags.float_kind() {
|
||||
float::none => {}
|
||||
float::left => {
|
||||
inline_size_of_preceding_left_floats = inline_size_of_preceding_left_floats +
|
||||
|
@ -1269,22 +1274,13 @@ impl BlockFlow {
|
|||
flow::mut_base(kid).block_container_inline_size = content_inline_size;
|
||||
|
||||
// Determine float impaction.
|
||||
match kid.float_clearance() {
|
||||
clear::none => {}
|
||||
clear::left => {
|
||||
inline_start_floats_impact_child = false;
|
||||
inline_size_of_preceding_left_floats = Au(0);
|
||||
}
|
||||
clear::right => {
|
||||
inline_end_floats_impact_child = false;
|
||||
inline_size_of_preceding_right_floats = Au(0);
|
||||
}
|
||||
clear::both => {
|
||||
inline_start_floats_impact_child = false;
|
||||
inline_end_floats_impact_child = false;
|
||||
inline_size_of_preceding_left_floats = Au(0);
|
||||
inline_size_of_preceding_right_floats = Au(0);
|
||||
}
|
||||
if flow::base(kid).flags.clears_left() {
|
||||
inline_start_floats_impact_child = false;
|
||||
inline_size_of_preceding_left_floats = Au(0);
|
||||
}
|
||||
if flow::base(kid).flags.clears_right() {
|
||||
inline_end_floats_impact_child = false;
|
||||
inline_size_of_preceding_right_floats = Au(0);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -1406,15 +1402,6 @@ impl Flow for BlockFlow {
|
|||
self
|
||||
}
|
||||
|
||||
/// Returns the direction that this flow clears floats in, if any.
|
||||
fn float_clearance(&self) -> clear::T {
|
||||
self.fragment.style().get_box().clear
|
||||
}
|
||||
|
||||
fn float_kind(&self) -> float::T {
|
||||
self.fragment.style().get_box().float
|
||||
}
|
||||
|
||||
/// Pass 1 of reflow: computes minimum and preferred inline-sizes.
|
||||
///
|
||||
/// Recursively (bottom-up) determine the flow's minimum and preferred inline-sizes. When
|
||||
|
@ -1441,9 +1428,9 @@ impl Flow for BlockFlow {
|
|||
let mut left_float_width = Au(0);
|
||||
let mut right_float_width = Au(0);
|
||||
for kid in self.base.child_iter() {
|
||||
let is_absolutely_positioned = kid.is_absolutely_positioned();
|
||||
let float_kind = kid.float_kind();
|
||||
let is_absolutely_positioned = flow::base(kid).flags.is_absolutely_positioned();
|
||||
let child_base = flow::mut_base(kid);
|
||||
let float_kind = child_base.flags.float_kind();
|
||||
if !is_absolutely_positioned && !fixed_width {
|
||||
computation.content_intrinsic_sizes.minimum_inline_size =
|
||||
max(computation.content_intrinsic_sizes.minimum_inline_size,
|
||||
|
@ -1615,7 +1602,7 @@ impl Flow for BlockFlow {
|
|||
self.base.clip_rect = MAX_RECT;
|
||||
}
|
||||
|
||||
if self.is_absolutely_positioned() {
|
||||
if self.base.flags.is_absolutely_positioned() {
|
||||
let position_start = self.base.position.start.to_physical(self.base.writing_mode,
|
||||
container_size);
|
||||
self.base.absolute_position_info.absolute_containing_block_position =
|
||||
|
@ -1662,7 +1649,7 @@ impl Flow for BlockFlow {
|
|||
// Process children.
|
||||
let writing_mode = self.base.writing_mode;
|
||||
for kid in self.base.child_iter() {
|
||||
if !kid.is_absolutely_positioned() {
|
||||
if !flow::base(kid).flags.is_absolutely_positioned() {
|
||||
let kid_base = flow::mut_base(kid);
|
||||
kid_base.abs_position =
|
||||
this_position +
|
||||
|
@ -1688,7 +1675,7 @@ impl Flow for BlockFlow {
|
|||
///
|
||||
/// Currently happens only for absolutely positioned flows.
|
||||
fn is_store_overflow_delayed(&mut self) -> bool {
|
||||
self.is_absolutely_positioned()
|
||||
self.base.flags.is_absolutely_positioned()
|
||||
}
|
||||
|
||||
fn is_root(&self) -> bool {
|
||||
|
@ -1729,7 +1716,7 @@ impl Flow for BlockFlow {
|
|||
}
|
||||
|
||||
fn update_late_computed_inline_position_if_necessary(&mut self, inline_position: Au) {
|
||||
if self.is_absolutely_positioned() &&
|
||||
if self.base.flags.is_absolutely_positioned() &&
|
||||
self.fragment.style().logical_position().inline_start == LPA_Auto &&
|
||||
self.fragment.style().logical_position().inline_end == LPA_Auto {
|
||||
self.base.position.start.i = inline_position
|
||||
|
@ -1737,7 +1724,7 @@ impl Flow for BlockFlow {
|
|||
}
|
||||
|
||||
fn update_late_computed_block_position_if_necessary(&mut self, block_position: Au) {
|
||||
if self.is_absolutely_positioned() &&
|
||||
if self.base.flags.is_absolutely_positioned() &&
|
||||
self.fragment.style().logical_position().block_start == LPA_Auto &&
|
||||
self.fragment.style().logical_position().block_end == LPA_Auto {
|
||||
self.base.position.start.b = block_position
|
||||
|
@ -1749,7 +1736,7 @@ impl Flow for BlockFlow {
|
|||
// 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.
|
||||
self.build_display_list_for_floating_block(layout_context)
|
||||
} else if self.is_absolutely_positioned() {
|
||||
} else if self.base.flags.is_absolutely_positioned() {
|
||||
self.build_display_list_for_absolutely_positioned_block(layout_context)
|
||||
} else {
|
||||
self.build_display_list_for_block(layout_context, BlockLevel)
|
||||
|
|
|
@ -336,9 +336,8 @@ impl<'a> FlowConstructor<'a> {
|
|||
// remain. In that case the inline flow will compute its ascent and descent to be zero.
|
||||
let fragments = TextRunScanner::new().scan_for_runs(self.layout_context.font_context(),
|
||||
fragments);
|
||||
|
||||
let mut inline_flow_ref = FlowRef::new(box InlineFlow::from_fragments((*node).clone(),
|
||||
fragments));
|
||||
let mut inline_flow_ref =
|
||||
FlowRef::new(box InlineFlow::from_fragments(fragments, node.style().writing_mode));
|
||||
|
||||
// Add all the inline-block fragments as children of the inline flow.
|
||||
for inline_block_flow in inline_block_flows.iter() {
|
||||
|
@ -530,7 +529,7 @@ impl<'a> FlowConstructor<'a> {
|
|||
|
||||
// Set up the absolute descendants.
|
||||
let is_positioned = flow.as_block().is_positioned();
|
||||
let is_absolutely_positioned = flow.as_block().is_absolutely_positioned();
|
||||
let is_absolutely_positioned = flow::base(&*flow).flags.is_absolutely_positioned();
|
||||
if is_positioned {
|
||||
// This is the containing block for all the absolute descendants.
|
||||
flow.set_absolute_descendants(abs_descendants);
|
||||
|
@ -845,7 +844,7 @@ impl<'a> FlowConstructor<'a> {
|
|||
wrapper_flow.finish();
|
||||
let is_positioned = wrapper_flow.as_block().is_positioned();
|
||||
let is_fixed_positioned = wrapper_flow.as_block().is_fixed();
|
||||
let is_absolutely_positioned = wrapper_flow.as_block().is_absolutely_positioned();
|
||||
let is_absolutely_positioned = flow::base(&*wrapper_flow).flags.is_absolutely_positioned();
|
||||
if is_positioned {
|
||||
// This is the containing block for all the absolute descendants.
|
||||
wrapper_flow.set_absolute_descendants(abs_descendants);
|
||||
|
|
|
@ -632,7 +632,7 @@ impl BlockFlowDisplayListBuilding for BlockFlow {
|
|||
|
||||
self.base.layers = DList::new();
|
||||
for kid in self.base.children.iter_mut() {
|
||||
if kid.is_absolutely_positioned() {
|
||||
if flow::base(kid).flags.is_absolutely_positioned() {
|
||||
// All absolute flows will be handled by their containing block.
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -211,15 +211,6 @@ pub trait Flow: fmt::Show + ToString + Sync {
|
|||
/// Phase 5 of reflow: builds display lists.
|
||||
fn build_display_list(&mut self, layout_context: &LayoutContext);
|
||||
|
||||
/// Returns the direction that this flow clears floats in, if any.
|
||||
fn float_clearance(&self) -> clear::T {
|
||||
clear::none
|
||||
}
|
||||
|
||||
fn float_kind(&self) -> float::T {
|
||||
float::none
|
||||
}
|
||||
|
||||
fn compute_collapsible_block_start_margin(&mut self,
|
||||
_layout_context: &mut LayoutContext,
|
||||
_margin_collapse_info: &mut MarginCollapseInfo) {
|
||||
|
@ -260,17 +251,13 @@ pub trait Flow: fmt::Show + ToString + Sync {
|
|||
}
|
||||
|
||||
fn is_positioned(&self) -> bool {
|
||||
self.is_relatively_positioned() || self.is_absolutely_positioned()
|
||||
self.is_relatively_positioned() || base(self).flags.is_absolutely_positioned()
|
||||
}
|
||||
|
||||
fn is_relatively_positioned(&self) -> bool {
|
||||
self.positioning() == position::relative
|
||||
}
|
||||
|
||||
fn is_absolutely_positioned(&self) -> bool {
|
||||
self.positioning() == position::absolute || self.is_fixed()
|
||||
}
|
||||
|
||||
/// Return true if this is the root of an absolute flow tree.
|
||||
fn is_root_of_absolute_flow_tree(&self) -> bool {
|
||||
false
|
||||
|
@ -485,48 +472,77 @@ pub trait PostorderFlowTraversal {
|
|||
|
||||
/// Flags used in flows, tightly packed to save space.
|
||||
#[deriving(Clone, Encodable)]
|
||||
pub struct FlowFlags(pub u8);
|
||||
pub struct FlowFlags(pub u16);
|
||||
|
||||
/// The bitmask of flags that represent the `has_left_floated_descendants` and
|
||||
/// `has_right_floated_descendants` fields.
|
||||
///
|
||||
/// NB: If you update this field, you must update the bitfields below.
|
||||
static HAS_FLOATED_DESCENDANTS_BITMASK: u8 = 0b0000_0011;
|
||||
static HAS_FLOATED_DESCENDANTS_BITMASK: u16 = 0b0000_0000_0000_0011;
|
||||
|
||||
// Whether this flow has descendants that float left in the same block formatting context.
|
||||
bitfield!(FlowFlags, has_left_floated_descendants, set_has_left_floated_descendants, 0b0000_0001)
|
||||
bitfield!(FlowFlags,
|
||||
has_left_floated_descendants,
|
||||
set_has_left_floated_descendants,
|
||||
0b0000_0000_0000_0001)
|
||||
|
||||
// Whether this flow has descendants that float right in the same block formatting context.
|
||||
bitfield!(FlowFlags, has_right_floated_descendants, set_has_right_floated_descendants, 0b0000_0010)
|
||||
bitfield!(FlowFlags,
|
||||
has_right_floated_descendants,
|
||||
set_has_right_floated_descendants,
|
||||
0b0000_0000_0000_0010)
|
||||
|
||||
// Whether this flow is impacted by floats to the left in the same block formatting context (i.e.
|
||||
// its block-size depends on some prior flows with `float: left`).
|
||||
bitfield!(FlowFlags, impacted_by_left_floats, set_impacted_by_left_floats, 0b0000_0100)
|
||||
bitfield!(FlowFlags,
|
||||
impacted_by_left_floats,
|
||||
set_impacted_by_left_floats,
|
||||
0b0000_0000_0000_0100)
|
||||
|
||||
// Whether this flow is impacted by floats to the right in the same block formatting context (i.e.
|
||||
// its block-size depends on some prior flows with `float: right`).
|
||||
bitfield!(FlowFlags, impacted_by_right_floats, set_impacted_by_right_floats, 0b0000_1000)
|
||||
bitfield!(FlowFlags, impacted_by_right_floats, set_impacted_by_right_floats, 0b0000_0000_0000_1000)
|
||||
|
||||
/// The bitmask of flags that represent the text alignment field.
|
||||
///
|
||||
/// NB: If you update this field, you must update the bitfields below.
|
||||
static TEXT_ALIGN_BITMASK: u8 = 0b0011_0000;
|
||||
static TEXT_ALIGN_BITMASK: u16 = 0b0000_0000_0011_0000;
|
||||
|
||||
/// The number of bits we must shift off to handle the text alignment field.
|
||||
///
|
||||
/// NB: If you update this field, you must update the bitfields below.
|
||||
static TEXT_ALIGN_SHIFT: u8 = 4;
|
||||
static TEXT_ALIGN_SHIFT: u16 = 4;
|
||||
|
||||
// Whether this flow contains a flow that has its own layer within the same absolute containing
|
||||
// block.
|
||||
bitfield!(FlowFlags,
|
||||
layers_needed_for_descendants,
|
||||
set_layers_needed_for_descendants,
|
||||
0b0100_0000)
|
||||
0b0000_0000_0100_0000)
|
||||
|
||||
// Whether this flow must have its own layer. Even if this flag is not set, it might get its own
|
||||
// layer if it's deemed to be likely to overlap flows with their own layer.
|
||||
bitfield!(FlowFlags, needs_layer, set_needs_layer, 0b1000_0000)
|
||||
bitfield!(FlowFlags, needs_layer, set_needs_layer, 0b0000_0000_1000_0000)
|
||||
|
||||
// Whether this flow is absolutely positioned. This is checked all over layout, so a virtual call
|
||||
// is too expensive.
|
||||
bitfield!(FlowFlags, is_absolutely_positioned, set_is_absolutely_positioned, 0b0000_0001_0000_0000)
|
||||
|
||||
// Whether this flow is left-floated. This is checked all over layout, so a virtual call is too
|
||||
// expensive.
|
||||
bitfield!(FlowFlags, floats_left, set_floats_left, 0b0000_0010_0000_0000)
|
||||
|
||||
// Whether this flow is right-floated. This is checked all over layout, so a virtual call is too
|
||||
// expensive.
|
||||
bitfield!(FlowFlags, floats_right, set_floats_right, 0b0000_0100_0000_0000)
|
||||
|
||||
// Whether this flow clears to the left. This is checked all over layout, so a virtual call is too
|
||||
// expensive.
|
||||
bitfield!(FlowFlags, clears_left, set_clears_left, 0b0000_1000_0000_0000)
|
||||
|
||||
// Whether this flow clears to the right. This is checked all over layout, so a virtual call is too
|
||||
// expensive.
|
||||
bitfield!(FlowFlags, clears_right, set_clears_right, 0b0001_0000_0000_0000)
|
||||
|
||||
impl FlowFlags {
|
||||
/// Creates a new set of flow flags.
|
||||
|
@ -545,13 +561,13 @@ impl FlowFlags {
|
|||
#[inline]
|
||||
pub fn text_align(self) -> text_align::T {
|
||||
let FlowFlags(ff) = self;
|
||||
FromPrimitive::from_u8((ff & TEXT_ALIGN_BITMASK) >> TEXT_ALIGN_SHIFT as uint).unwrap()
|
||||
FromPrimitive::from_u16((ff & TEXT_ALIGN_BITMASK) >> TEXT_ALIGN_SHIFT as uint).unwrap()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_text_align(&mut self, value: text_align::T) {
|
||||
let FlowFlags(ff) = *self;
|
||||
*self = FlowFlags((ff & !TEXT_ALIGN_BITMASK) | ((value as u8) << TEXT_ALIGN_SHIFT as uint))
|
||||
*self = FlowFlags((ff & !TEXT_ALIGN_BITMASK) | ((value as u16) << TEXT_ALIGN_SHIFT as uint))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -572,6 +588,22 @@ impl FlowFlags {
|
|||
pub fn impacted_by_floats(&self) -> bool {
|
||||
self.impacted_by_left_floats() || self.impacted_by_right_floats()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn float_kind(&self) -> float::T {
|
||||
if self.floats_left() {
|
||||
float::left
|
||||
} else if self.floats_right() {
|
||||
float::right
|
||||
} else {
|
||||
float::none
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn clears_floats(&self) -> bool {
|
||||
self.clears_left() || self.clears_right()
|
||||
}
|
||||
}
|
||||
|
||||
/// The Descendants of a flow.
|
||||
|
@ -813,15 +845,39 @@ impl Drop for BaseFlow {
|
|||
|
||||
impl BaseFlow {
|
||||
#[inline]
|
||||
pub fn new(node: ThreadSafeLayoutNode) -> BaseFlow {
|
||||
let writing_mode = node.style().writing_mode;
|
||||
pub fn new(node: Option<ThreadSafeLayoutNode>, writing_mode: WritingMode) -> BaseFlow {
|
||||
let mut flags = FlowFlags::new();
|
||||
match node {
|
||||
None => {}
|
||||
Some(node) => {
|
||||
let node_style = node.style();
|
||||
match node_style.get_box().position {
|
||||
position::absolute | position::fixed => {
|
||||
flags.set_is_absolutely_positioned(true)
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
match node_style.get_box().float {
|
||||
float::none => {}
|
||||
float::left => flags.set_floats_left(true),
|
||||
float::right => flags.set_floats_right(true),
|
||||
}
|
||||
match node_style.get_box().clear {
|
||||
clear::none => {}
|
||||
clear::left => flags.set_clears_left(true),
|
||||
clear::right => flags.set_clears_right(true),
|
||||
clear::both => {
|
||||
flags.set_clears_left(true);
|
||||
flags.set_clears_right(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BaseFlow {
|
||||
ref_count: AtomicUint::new(1),
|
||||
|
||||
restyle_damage: node.restyle_damage(),
|
||||
|
||||
restyle_damage: RestyleDamage::all(),
|
||||
children: FlowList::new(),
|
||||
|
||||
intrinsic_inline_sizes: IntrinsicISizes::new(),
|
||||
position: LogicalRect::zero(writing_mode),
|
||||
overflow: LogicalRect::zero(writing_mode),
|
||||
|
@ -839,8 +895,7 @@ impl BaseFlow {
|
|||
layers: DList::new(),
|
||||
absolute_position_info: AbsolutePositionInfo::new(writing_mode),
|
||||
clip_rect: Rect(Zero::zero(), Size2D(Au(0), Au(0))),
|
||||
|
||||
flags: FlowFlags::new(),
|
||||
flags: flags,
|
||||
writing_mode: writing_mode,
|
||||
}
|
||||
}
|
||||
|
@ -1124,7 +1179,7 @@ impl<'a> MutableFlowUtils for &'a mut Flow + 'a {
|
|||
let mut gives_absolute_offsets = true;
|
||||
if kid.is_block_like() {
|
||||
let kid_block = kid.as_block();
|
||||
if kid_block.is_fixed() || kid_block.is_absolutely_positioned() {
|
||||
if kid_block.is_fixed() || kid_block.base.flags.is_absolutely_positioned() {
|
||||
// It won't contribute any offsets for descendants because it would be the
|
||||
// containing block for them.
|
||||
gives_absolute_offsets = false;
|
||||
|
@ -1162,28 +1217,17 @@ impl<'a> MutableFlowUtils for &'a mut Flow + 'a {
|
|||
}
|
||||
|
||||
fn doit(flow: &mut Flow, down: RestyleDamage, dirty_floats: &mut DirtyFloats) -> RestyleDamage {
|
||||
match flow.float_clearance() {
|
||||
clear::none => {}
|
||||
clear::left => {
|
||||
(*dirty_floats).left = false;
|
||||
}
|
||||
clear::right => {
|
||||
(*dirty_floats).right = false;
|
||||
}
|
||||
clear::both => {
|
||||
(*dirty_floats).left = false;
|
||||
(*dirty_floats).right = false;
|
||||
}
|
||||
if base(flow).flags.clears_left() {
|
||||
dirty_floats.left = false;
|
||||
}
|
||||
if base(flow).flags.clears_right() {
|
||||
dirty_floats.right = false;
|
||||
}
|
||||
|
||||
match flow.float_kind() {
|
||||
float::none => {}
|
||||
float::left => {
|
||||
(*dirty_floats).left = true;
|
||||
}
|
||||
float::right => {
|
||||
(*dirty_floats).right = true;
|
||||
}
|
||||
if base(flow).flags.floats_left() {
|
||||
(*dirty_floats).left = true;
|
||||
} else if base(flow).flags.floats_right() {
|
||||
(*dirty_floats).right = true;
|
||||
}
|
||||
|
||||
let mut my_damage = mut_base(flow).restyle_damage;
|
||||
|
|
|
@ -15,7 +15,6 @@ use fragment::{ScannedTextFragment, ScannedTextFragmentInfo, SplitInfo};
|
|||
use layout_debug;
|
||||
use model::IntrinsicISizesContribution;
|
||||
use text;
|
||||
use wrapper::ThreadSafeLayoutNode;
|
||||
|
||||
use collections::{Deque, RingBuf};
|
||||
use geom::{Rect, Size2D};
|
||||
|
@ -24,7 +23,7 @@ use gfx::font::FontMetrics;
|
|||
use gfx::font_context::FontContext;
|
||||
use gfx::text::glyph::CharIndex;
|
||||
use servo_util::geometry::Au;
|
||||
use servo_util::logical_geometry::{LogicalRect, LogicalSize};
|
||||
use servo_util::logical_geometry::{LogicalRect, LogicalSize, WritingMode};
|
||||
use servo_util::opts;
|
||||
use servo_util::range::{IntRangeIndex, Range, RangeIndex};
|
||||
use servo_util::arc_ptr_eq;
|
||||
|
@ -702,9 +701,9 @@ pub struct InlineFlow {
|
|||
}
|
||||
|
||||
impl InlineFlow {
|
||||
pub fn from_fragments(node: ThreadSafeLayoutNode, fragments: InlineFragments) -> InlineFlow {
|
||||
pub fn from_fragments(fragments: InlineFragments, writing_mode: WritingMode) -> InlineFlow {
|
||||
InlineFlow {
|
||||
base: BaseFlow::new(node),
|
||||
base: BaseFlow::new(None, writing_mode),
|
||||
fragments: fragments,
|
||||
lines: Vec::new(),
|
||||
minimum_block_size_above_baseline: Au(0),
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#![deny(unsafe_block)]
|
||||
|
||||
use context::LayoutContext;
|
||||
use css::node_style::StyledNode;
|
||||
use flow::{BaseFlow, TableColGroupFlowClass, FlowClass, Flow};
|
||||
use fragment::{Fragment, TableColumnFragment};
|
||||
use layout_debug;
|
||||
|
@ -39,8 +40,9 @@ impl TableColGroupFlow {
|
|||
fragment: Fragment,
|
||||
fragments: Vec<Fragment>)
|
||||
-> TableColGroupFlow {
|
||||
let writing_mode = node.style().writing_mode;
|
||||
TableColGroupFlow {
|
||||
base: BaseFlow::new((*node).clone()),
|
||||
base: BaseFlow::new(Some((*node).clone()), writing_mode),
|
||||
fragment: Some(fragment),
|
||||
cols: fragments,
|
||||
inline_sizes: vec!(),
|
||||
|
|
|
@ -27,7 +27,7 @@ use servo_util::geometry::Au;
|
|||
use std::cmp::{max, min};
|
||||
use std::fmt;
|
||||
use style::CSSFloat;
|
||||
use style::computed_values::{clear, float, table_layout};
|
||||
use style::computed_values::table_layout;
|
||||
|
||||
#[deriving(Encodable)]
|
||||
pub enum TableLayout {
|
||||
|
@ -235,14 +235,6 @@ impl Flow for TableWrapperFlow {
|
|||
&mut self.block_flow
|
||||
}
|
||||
|
||||
fn float_clearance(&self) -> clear::T {
|
||||
self.block_flow.float_clearance()
|
||||
}
|
||||
|
||||
fn float_kind(&self) -> float::T {
|
||||
self.block_flow.float_kind()
|
||||
}
|
||||
|
||||
fn bubble_inline_sizes(&mut self) {
|
||||
// Get the column inline-sizes info from the table flow.
|
||||
for kid in self.block_flow.base.child_iter() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue