2013-04-06 03:31:01 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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/. */
|
|
|
|
|
2014-05-29 04:34:06 +04:00
|
|
|
//! Servo's experimental layout system builds a tree of `Flow` and `Fragment` objects and solves
|
2013-12-06 05:44:24 +04:00
|
|
|
//! 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
|
2013-05-03 06:37:36 +04:00
|
|
|
/// inline and block layout.
|
2014-02-05 02:52:39 +04:00
|
|
|
///
|
2013-05-03 06:37:36 +04:00
|
|
|
/// Flows are interior nodes in the layout tree and correspond closely to *flow contexts* in the
|
2014-09-19 18:51:02 +04:00
|
|
|
/// CSS specification. Flows are responsible for positioning their child flow contexts and
|
|
|
|
/// fragments. Flows have purpose-specific fields, such as auxiliary line structs, out-of-flow
|
|
|
|
/// child lists, and so on.
|
2013-05-03 06:37:36 +04:00
|
|
|
///
|
|
|
|
/// Currently, the important types of flows are:
|
2014-02-05 02:52:39 +04:00
|
|
|
///
|
2013-05-08 00:44:45 +04:00
|
|
|
/// * `BlockFlow`: A flow that establishes a block context. It has several child flows, each of
|
2013-05-03 06:37:36 +04:00
|
|
|
/// which are positioned according to block formatting context rules (CSS block boxes). Block
|
2014-03-03 22:37:33 +04:00
|
|
|
/// flows also contain a single box to represent their rendered borders, padding, etc.
|
2013-12-11 06:22:10 +04:00
|
|
|
/// The BlockFlow at the root of the tree has special behavior: it stretches to the boundaries of
|
|
|
|
/// the viewport.
|
2014-02-05 02:52:39 +04:00
|
|
|
///
|
2013-05-08 00:44:45 +04:00
|
|
|
/// * `InlineFlow`: A flow that establishes an inline context. It has a flat list of child
|
2014-05-29 04:34:06 +04:00
|
|
|
/// fragments/flows that are subject to inline layout and line breaking and structs to represent
|
2013-05-03 06:37:36 +04:00
|
|
|
/// line breaks and mapping to CSS boxes, for the purpose of handling `getClientRects()` and
|
|
|
|
/// similar methods.
|
|
|
|
|
2013-10-29 00:31:44 +04:00
|
|
|
use css::node_style::StyledNode;
|
2014-07-01 16:02:50 +04:00
|
|
|
use block::BlockFlow;
|
|
|
|
use context::LayoutContext;
|
2014-11-17 02:39:27 +03:00
|
|
|
use display_list_builder::{DisplayListBuildingResult, DisplayListResult};
|
|
|
|
use display_list_builder::{NoDisplayListBuildingResult, StackingContextResult};
|
2014-07-01 16:02:50 +04:00
|
|
|
use floats::Floats;
|
2014-09-21 02:35:08 +04:00
|
|
|
use flow_list::{FlowList, FlowListIterator, MutFlowListIterator};
|
2014-07-01 16:02:50 +04:00
|
|
|
use flow_ref::FlowRef;
|
2014-11-03 22:03:37 +03:00
|
|
|
use fragment::{Fragment, FragmentBoundsIterator, TableRowFragment, TableCellFragment};
|
2014-11-13 06:48:31 +03:00
|
|
|
use incremental::{RECONSTRUCT_FLOW, REFLOW, REFLOW_OUT_OF_FLOW, RestyleDamage};
|
2014-07-01 16:02:50 +04:00
|
|
|
use inline::InlineFlow;
|
2014-07-19 00:27:23 +04:00
|
|
|
use model::{CollapsibleMargins, IntrinsicISizes, MarginCollapseInfo};
|
2014-07-01 16:02:50 +04:00
|
|
|
use parallel::FlowParallelInfo;
|
2014-10-15 01:42:32 +04:00
|
|
|
use table::{ColumnInlineSize, TableFlow};
|
2014-07-01 16:02:50 +04:00
|
|
|
use table_caption::TableCaptionFlow;
|
|
|
|
use table_cell::TableCellFlow;
|
2014-09-19 18:51:02 +04:00
|
|
|
use table_colgroup::TableColGroupFlow;
|
|
|
|
use table_row::TableRowFlow;
|
|
|
|
use table_rowgroup::TableRowGroupFlow;
|
|
|
|
use table_wrapper::TableWrapperFlow;
|
2014-07-01 16:02:50 +04:00
|
|
|
use wrapper::ThreadSafeLayoutNode;
|
2013-10-29 00:31:44 +04:00
|
|
|
|
2014-10-14 10:42:35 +04:00
|
|
|
use geom::{Point2D, Rect, Size2D};
|
2014-09-08 10:33:09 +04:00
|
|
|
use serialize::{Encoder, Encodable};
|
2014-04-04 05:01:48 +04:00
|
|
|
use servo_msg::compositor_msg::LayerId;
|
2013-12-13 05:58:21 +04:00
|
|
|
use servo_util::geometry::Au;
|
2014-07-19 00:27:23 +04:00
|
|
|
use servo_util::logical_geometry::WritingMode;
|
2014-08-27 04:07:45 +04:00
|
|
|
use servo_util::logical_geometry::{LogicalRect, LogicalSize};
|
2014-06-05 21:58:44 +04:00
|
|
|
use std::mem;
|
2014-08-27 04:07:45 +04:00
|
|
|
use std::num::Zero;
|
2014-05-07 07:37:35 +04:00
|
|
|
use std::fmt;
|
2014-04-04 05:01:48 +04:00
|
|
|
use std::iter::Zip;
|
2014-08-29 03:35:55 +04:00
|
|
|
use std::raw;
|
2014-11-13 06:48:31 +03:00
|
|
|
use std::sync::atomic::{AtomicUint, SeqCst};
|
2014-04-05 02:52:50 +04:00
|
|
|
use std::slice::MutItems;
|
2014-09-10 13:18:43 +04:00
|
|
|
use style::computed_values::{clear, float, position, text_align};
|
2014-10-31 23:39:34 +03:00
|
|
|
use style::ComputedValues;
|
|
|
|
use sync::Arc;
|
2012-11-12 07:42:44 +04:00
|
|
|
|
2013-10-29 00:31:44 +04:00
|
|
|
/// Virtual methods that make up a float context.
|
|
|
|
///
|
|
|
|
/// Note that virtual methods have a cost; we should not overuse them in Servo. Consider adding
|
|
|
|
/// methods to `ImmutableFlowUtils` or `MutableFlowUtils` before adding more methods here.
|
2014-09-21 02:35:08 +04:00
|
|
|
pub trait Flow: fmt::Show + ToString + Sync {
|
2013-10-29 00:31:44 +04:00
|
|
|
// RTTI
|
|
|
|
//
|
|
|
|
// TODO(pcwalton): Use Rust's RTTI, once that works.
|
2012-09-22 03:23:30 +04:00
|
|
|
|
2013-10-29 00:31:44 +04:00
|
|
|
/// Returns the class of flow that this is.
|
|
|
|
fn class(&self) -> FlowClass;
|
2012-09-22 03:23:30 +04:00
|
|
|
|
2014-09-08 10:33:09 +04:00
|
|
|
/// If this is a block flow, returns the underlying object, borrowed immutably. Fails
|
|
|
|
/// otherwise.
|
|
|
|
fn as_immutable_block<'a>(&'a self) -> &'a BlockFlow {
|
2014-11-13 06:48:31 +03:00
|
|
|
panic!("called as_immutable_block() on a non-block flow")
|
2014-09-08 10:33:09 +04:00
|
|
|
}
|
|
|
|
|
2013-10-29 00:31:44 +04:00
|
|
|
/// If this is a block flow, returns the underlying object. Fails otherwise.
|
|
|
|
fn as_block<'a>(&'a mut self) -> &'a mut BlockFlow {
|
2014-05-03 03:10:20 +04:00
|
|
|
debug!("called as_block() on a flow of type {}", self.class());
|
2014-11-13 06:48:31 +03:00
|
|
|
panic!("called as_block() on a non-block flow")
|
2013-10-29 00:31:44 +04:00
|
|
|
}
|
2013-08-20 23:03:52 +04:00
|
|
|
|
2013-10-29 00:31:44 +04:00
|
|
|
/// If this is an inline flow, returns the underlying object, borrowed immutably. Fails
|
|
|
|
/// otherwise.
|
|
|
|
fn as_immutable_inline<'a>(&'a self) -> &'a InlineFlow {
|
2014-11-13 06:48:31 +03:00
|
|
|
panic!("called as_immutable_inline() on a non-inline flow")
|
2013-05-22 23:57:28 +04:00
|
|
|
}
|
2013-07-16 05:03:27 +04:00
|
|
|
|
2013-10-29 00:31:44 +04:00
|
|
|
/// If this is an inline flow, returns the underlying object. Fails otherwise.
|
|
|
|
fn as_inline<'a>(&'a mut self) -> &'a mut InlineFlow {
|
2014-11-13 06:48:31 +03:00
|
|
|
panic!("called as_inline() on a non-inline flow")
|
2013-10-29 00:31:44 +04:00
|
|
|
}
|
2013-07-16 05:03:27 +04:00
|
|
|
|
servo: Merge #1973 - Support fixed-layout table and a part of anonymous table object (from june0cho:table_rebase); r=larsbergstrom,metajack
This is a rebase of #1548 on recent master.
There have been many changes since #1548 is first uploaded, so I'm creating new PR.
This PR includes:
- construction of table-* flows (table-wrapper, table-caption, table, table-rowgroup, table-row, table-cell)
- fixed-layout table calculation
- a part of anonymous table object implementation
[CSS 2.1, 17.2.1](http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes) (Step 1-1, 1-2, Step 2)
Source-Repo: https://github.com/servo/servo
Source-Revision: fd5e5cd18b41f0ce2b33fb97fb4e3d75ddbbbceb
2014-03-25 21:40:47 +04:00
|
|
|
/// If this is a table wrapper flow, returns the underlying object. Fails otherwise.
|
|
|
|
fn as_table_wrapper<'a>(&'a mut self) -> &'a mut TableWrapperFlow {
|
2014-11-13 06:48:31 +03:00
|
|
|
panic!("called as_table_wrapper() on a non-tablewrapper flow")
|
servo: Merge #1973 - Support fixed-layout table and a part of anonymous table object (from june0cho:table_rebase); r=larsbergstrom,metajack
This is a rebase of #1548 on recent master.
There have been many changes since #1548 is first uploaded, so I'm creating new PR.
This PR includes:
- construction of table-* flows (table-wrapper, table-caption, table, table-rowgroup, table-row, table-cell)
- fixed-layout table calculation
- a part of anonymous table object implementation
[CSS 2.1, 17.2.1](http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes) (Step 1-1, 1-2, Step 2)
Source-Repo: https://github.com/servo/servo
Source-Revision: fd5e5cd18b41f0ce2b33fb97fb4e3d75ddbbbceb
2014-03-25 21:40:47 +04:00
|
|
|
}
|
|
|
|
|
2014-09-20 06:50:47 +04:00
|
|
|
/// If this is a table wrapper flow, returns the underlying object, borrowed immutably. Fails
|
|
|
|
/// otherwise.
|
|
|
|
fn as_immutable_table_wrapper<'a>(&'a self) -> &'a TableWrapperFlow {
|
2014-11-13 06:48:31 +03:00
|
|
|
panic!("called as_immutable_table_wrapper() on a non-tablewrapper flow")
|
2014-09-20 06:50:47 +04:00
|
|
|
}
|
|
|
|
|
servo: Merge #1973 - Support fixed-layout table and a part of anonymous table object (from june0cho:table_rebase); r=larsbergstrom,metajack
This is a rebase of #1548 on recent master.
There have been many changes since #1548 is first uploaded, so I'm creating new PR.
This PR includes:
- construction of table-* flows (table-wrapper, table-caption, table, table-rowgroup, table-row, table-cell)
- fixed-layout table calculation
- a part of anonymous table object implementation
[CSS 2.1, 17.2.1](http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes) (Step 1-1, 1-2, Step 2)
Source-Repo: https://github.com/servo/servo
Source-Revision: fd5e5cd18b41f0ce2b33fb97fb4e3d75ddbbbceb
2014-03-25 21:40:47 +04:00
|
|
|
/// If this is a table flow, returns the underlying object. Fails otherwise.
|
|
|
|
fn as_table<'a>(&'a mut self) -> &'a mut TableFlow {
|
2014-11-13 06:48:31 +03:00
|
|
|
panic!("called as_table() on a non-table flow")
|
servo: Merge #1973 - Support fixed-layout table and a part of anonymous table object (from june0cho:table_rebase); r=larsbergstrom,metajack
This is a rebase of #1548 on recent master.
There have been many changes since #1548 is first uploaded, so I'm creating new PR.
This PR includes:
- construction of table-* flows (table-wrapper, table-caption, table, table-rowgroup, table-row, table-cell)
- fixed-layout table calculation
- a part of anonymous table object implementation
[CSS 2.1, 17.2.1](http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes) (Step 1-1, 1-2, Step 2)
Source-Repo: https://github.com/servo/servo
Source-Revision: fd5e5cd18b41f0ce2b33fb97fb4e3d75ddbbbceb
2014-03-25 21:40:47 +04:00
|
|
|
}
|
|
|
|
|
2014-09-20 06:50:47 +04:00
|
|
|
/// If this is a table flow, returns the underlying object, borrowed immutably. Fails otherwise.
|
|
|
|
fn as_immutable_table<'a>(&'a self) -> &'a TableFlow {
|
2014-11-13 06:48:31 +03:00
|
|
|
panic!("called as_table() on a non-table flow")
|
2014-09-20 06:50:47 +04:00
|
|
|
}
|
|
|
|
|
servo: Merge #1973 - Support fixed-layout table and a part of anonymous table object (from june0cho:table_rebase); r=larsbergstrom,metajack
This is a rebase of #1548 on recent master.
There have been many changes since #1548 is first uploaded, so I'm creating new PR.
This PR includes:
- construction of table-* flows (table-wrapper, table-caption, table, table-rowgroup, table-row, table-cell)
- fixed-layout table calculation
- a part of anonymous table object implementation
[CSS 2.1, 17.2.1](http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes) (Step 1-1, 1-2, Step 2)
Source-Repo: https://github.com/servo/servo
Source-Revision: fd5e5cd18b41f0ce2b33fb97fb4e3d75ddbbbceb
2014-03-25 21:40:47 +04:00
|
|
|
/// If this is a table colgroup flow, returns the underlying object. Fails otherwise.
|
|
|
|
fn as_table_colgroup<'a>(&'a mut self) -> &'a mut TableColGroupFlow {
|
2014-11-13 06:48:31 +03:00
|
|
|
panic!("called as_table_colgroup() on a non-tablecolgroup flow")
|
servo: Merge #1973 - Support fixed-layout table and a part of anonymous table object (from june0cho:table_rebase); r=larsbergstrom,metajack
This is a rebase of #1548 on recent master.
There have been many changes since #1548 is first uploaded, so I'm creating new PR.
This PR includes:
- construction of table-* flows (table-wrapper, table-caption, table, table-rowgroup, table-row, table-cell)
- fixed-layout table calculation
- a part of anonymous table object implementation
[CSS 2.1, 17.2.1](http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes) (Step 1-1, 1-2, Step 2)
Source-Repo: https://github.com/servo/servo
Source-Revision: fd5e5cd18b41f0ce2b33fb97fb4e3d75ddbbbceb
2014-03-25 21:40:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// If this is a table rowgroup flow, returns the underlying object. Fails otherwise.
|
|
|
|
fn as_table_rowgroup<'a>(&'a mut self) -> &'a mut TableRowGroupFlow {
|
2014-11-13 06:48:31 +03:00
|
|
|
panic!("called as_table_rowgroup() on a non-tablerowgroup flow")
|
servo: Merge #1973 - Support fixed-layout table and a part of anonymous table object (from june0cho:table_rebase); r=larsbergstrom,metajack
This is a rebase of #1548 on recent master.
There have been many changes since #1548 is first uploaded, so I'm creating new PR.
This PR includes:
- construction of table-* flows (table-wrapper, table-caption, table, table-rowgroup, table-row, table-cell)
- fixed-layout table calculation
- a part of anonymous table object implementation
[CSS 2.1, 17.2.1](http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes) (Step 1-1, 1-2, Step 2)
Source-Repo: https://github.com/servo/servo
Source-Revision: fd5e5cd18b41f0ce2b33fb97fb4e3d75ddbbbceb
2014-03-25 21:40:47 +04:00
|
|
|
}
|
|
|
|
|
2014-09-20 06:50:47 +04:00
|
|
|
/// If this is a table rowgroup flow, returns the underlying object, borrowed immutably. Fails
|
|
|
|
/// otherwise.
|
|
|
|
fn as_immutable_table_rowgroup<'a>(&'a self) -> &'a TableRowGroupFlow {
|
2014-11-13 06:48:31 +03:00
|
|
|
panic!("called as_table_rowgroup() on a non-tablerowgroup flow")
|
2014-09-20 06:50:47 +04:00
|
|
|
}
|
|
|
|
|
servo: Merge #1973 - Support fixed-layout table and a part of anonymous table object (from june0cho:table_rebase); r=larsbergstrom,metajack
This is a rebase of #1548 on recent master.
There have been many changes since #1548 is first uploaded, so I'm creating new PR.
This PR includes:
- construction of table-* flows (table-wrapper, table-caption, table, table-rowgroup, table-row, table-cell)
- fixed-layout table calculation
- a part of anonymous table object implementation
[CSS 2.1, 17.2.1](http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes) (Step 1-1, 1-2, Step 2)
Source-Repo: https://github.com/servo/servo
Source-Revision: fd5e5cd18b41f0ce2b33fb97fb4e3d75ddbbbceb
2014-03-25 21:40:47 +04:00
|
|
|
/// If this is a table row flow, returns the underlying object. Fails otherwise.
|
|
|
|
fn as_table_row<'a>(&'a mut self) -> &'a mut TableRowFlow {
|
2014-11-13 06:48:31 +03:00
|
|
|
panic!("called as_table_row() on a non-tablerow flow")
|
servo: Merge #1973 - Support fixed-layout table and a part of anonymous table object (from june0cho:table_rebase); r=larsbergstrom,metajack
This is a rebase of #1548 on recent master.
There have been many changes since #1548 is first uploaded, so I'm creating new PR.
This PR includes:
- construction of table-* flows (table-wrapper, table-caption, table, table-rowgroup, table-row, table-cell)
- fixed-layout table calculation
- a part of anonymous table object implementation
[CSS 2.1, 17.2.1](http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes) (Step 1-1, 1-2, Step 2)
Source-Repo: https://github.com/servo/servo
Source-Revision: fd5e5cd18b41f0ce2b33fb97fb4e3d75ddbbbceb
2014-03-25 21:40:47 +04:00
|
|
|
}
|
|
|
|
|
2014-09-20 06:50:47 +04:00
|
|
|
/// If this is a table row flow, returns the underlying object, borrowed immutably. Fails
|
|
|
|
/// otherwise.
|
|
|
|
fn as_immutable_table_row<'a>(&'a self) -> &'a TableRowFlow {
|
2014-11-13 06:48:31 +03:00
|
|
|
panic!("called as_table_row() on a non-tablerow flow")
|
2014-09-20 06:50:47 +04:00
|
|
|
}
|
|
|
|
|
servo: Merge #1973 - Support fixed-layout table and a part of anonymous table object (from june0cho:table_rebase); r=larsbergstrom,metajack
This is a rebase of #1548 on recent master.
There have been many changes since #1548 is first uploaded, so I'm creating new PR.
This PR includes:
- construction of table-* flows (table-wrapper, table-caption, table, table-rowgroup, table-row, table-cell)
- fixed-layout table calculation
- a part of anonymous table object implementation
[CSS 2.1, 17.2.1](http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes) (Step 1-1, 1-2, Step 2)
Source-Repo: https://github.com/servo/servo
Source-Revision: fd5e5cd18b41f0ce2b33fb97fb4e3d75ddbbbceb
2014-03-25 21:40:47 +04:00
|
|
|
/// If this is a table cell flow, returns the underlying object. Fails otherwise.
|
|
|
|
fn as_table_caption<'a>(&'a mut self) -> &'a mut TableCaptionFlow {
|
2014-11-13 06:48:31 +03:00
|
|
|
panic!("called as_table_caption() on a non-tablecaption flow")
|
servo: Merge #1973 - Support fixed-layout table and a part of anonymous table object (from june0cho:table_rebase); r=larsbergstrom,metajack
This is a rebase of #1548 on recent master.
There have been many changes since #1548 is first uploaded, so I'm creating new PR.
This PR includes:
- construction of table-* flows (table-wrapper, table-caption, table, table-rowgroup, table-row, table-cell)
- fixed-layout table calculation
- a part of anonymous table object implementation
[CSS 2.1, 17.2.1](http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes) (Step 1-1, 1-2, Step 2)
Source-Repo: https://github.com/servo/servo
Source-Revision: fd5e5cd18b41f0ce2b33fb97fb4e3d75ddbbbceb
2014-03-25 21:40:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// If this is a table cell flow, returns the underlying object. Fails otherwise.
|
|
|
|
fn as_table_cell<'a>(&'a mut self) -> &'a mut TableCellFlow {
|
2014-11-13 06:48:31 +03:00
|
|
|
panic!("called as_table_cell() on a non-tablecell flow")
|
servo: Merge #1973 - Support fixed-layout table and a part of anonymous table object (from june0cho:table_rebase); r=larsbergstrom,metajack
This is a rebase of #1548 on recent master.
There have been many changes since #1548 is first uploaded, so I'm creating new PR.
This PR includes:
- construction of table-* flows (table-wrapper, table-caption, table, table-rowgroup, table-row, table-cell)
- fixed-layout table calculation
- a part of anonymous table object implementation
[CSS 2.1, 17.2.1](http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes) (Step 1-1, 1-2, Step 2)
Source-Repo: https://github.com/servo/servo
Source-Revision: fd5e5cd18b41f0ce2b33fb97fb4e3d75ddbbbceb
2014-03-25 21:40:47 +04:00
|
|
|
}
|
|
|
|
|
2014-09-20 06:50:47 +04:00
|
|
|
/// If this is a table cell flow, returns the underlying object, borrowed immutably. Fails
|
|
|
|
/// otherwise.
|
|
|
|
fn as_immutable_table_cell<'a>(&'a self) -> &'a TableCellFlow {
|
2014-11-13 06:48:31 +03:00
|
|
|
panic!("called as_table_cell() on a non-tablecell flow")
|
2014-09-20 06:50:47 +04:00
|
|
|
}
|
|
|
|
|
2014-07-19 00:27:23 +04:00
|
|
|
/// If this is a table row or table rowgroup or table flow, returns column inline-sizes.
|
2014-04-04 05:01:48 +04:00
|
|
|
/// Fails otherwise.
|
2014-10-15 01:42:32 +04:00
|
|
|
fn column_inline_sizes<'a>(&'a mut self) -> &'a mut Vec<ColumnInlineSize> {
|
2014-11-13 06:48:31 +03:00
|
|
|
panic!("called column_inline_sizes() on non-table flow")
|
2014-04-04 05:01:48 +04:00
|
|
|
}
|
|
|
|
|
2013-10-29 00:31:44 +04:00
|
|
|
// Main methods
|
2013-08-09 20:42:36 +04:00
|
|
|
|
2014-07-19 00:27:23 +04:00
|
|
|
/// Pass 1 of reflow: computes minimum and preferred inline-sizes.
|
2014-05-03 03:10:20 +04:00
|
|
|
///
|
2014-10-14 04:03:40 +04:00
|
|
|
/// Recursively (bottom-up) determine the flow's minimum and preferred inline-sizes. When
|
|
|
|
/// called on this flow, all child flows have had their minimum and preferred inline-sizes set.
|
|
|
|
/// This function must decide minimum/preferred inline-sizes based on its children's inline-
|
|
|
|
/// sizes and the dimensions of any boxes it is responsible for flowing.
|
2014-10-15 00:06:36 +04:00
|
|
|
fn bubble_inline_sizes(&mut self) {
|
2014-11-13 06:48:31 +03:00
|
|
|
panic!("bubble_inline_sizes not yet implemented")
|
2013-08-09 20:42:36 +04:00
|
|
|
}
|
2013-05-22 23:57:28 +04:00
|
|
|
|
2014-07-19 00:27:23 +04:00
|
|
|
/// Pass 2 of reflow: computes inline-size.
|
2014-08-11 16:20:07 +04:00
|
|
|
fn assign_inline_sizes(&mut self, _ctx: &LayoutContext) {
|
2014-11-13 06:48:31 +03:00
|
|
|
panic!("assign_inline_sizes not yet implemented")
|
2013-10-29 00:31:44 +04:00
|
|
|
}
|
2013-05-22 23:57:28 +04:00
|
|
|
|
2014-07-19 00:27:23 +04:00
|
|
|
/// Pass 3a of reflow: computes block-size.
|
2014-08-11 16:20:07 +04:00
|
|
|
fn assign_block_size<'a>(&mut self, _ctx: &'a LayoutContext<'a>) {
|
2014-11-13 06:48:31 +03:00
|
|
|
panic!("assign_block_size not yet implemented")
|
2013-10-29 00:31:44 +04:00
|
|
|
}
|
2013-05-22 23:57:28 +04:00
|
|
|
|
2014-07-19 00:27:23 +04:00
|
|
|
/// Assigns block-sizes in-order; or, if this is a float, places the float. The default
|
2014-10-14 04:03:40 +04:00
|
|
|
/// implementation simply assigns block-sizes if this flow is impacted by floats. Returns true
|
|
|
|
/// if this child was impacted by floats or false otherwise.
|
|
|
|
fn assign_block_size_for_inorder_child_if_necessary<'a>(&mut self,
|
|
|
|
layout_context: &'a LayoutContext<'a>)
|
|
|
|
-> bool {
|
2014-05-23 04:14:24 +04:00
|
|
|
let impacted = base(&*self).flags.impacted_by_floats();
|
2014-05-03 03:10:20 +04:00
|
|
|
if impacted {
|
2014-07-19 00:27:23 +04:00
|
|
|
self.assign_block_size(layout_context);
|
2014-11-13 06:48:31 +03:00
|
|
|
mut_base(&mut *self).restyle_damage.remove(REFLOW_OUT_OF_FLOW | REFLOW);
|
2014-05-03 03:10:20 +04:00
|
|
|
}
|
|
|
|
impacted
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Phase 4 of reflow: computes absolute positions.
|
|
|
|
fn compute_absolute_position(&mut self) {
|
|
|
|
// The default implementation is a no-op.
|
|
|
|
}
|
|
|
|
|
2014-10-22 20:54:35 +04:00
|
|
|
/// Phase 5 of reflow: builds display lists.
|
|
|
|
fn build_display_list(&mut self, layout_context: &LayoutContext);
|
|
|
|
|
2014-11-03 22:03:37 +03:00
|
|
|
/// Perform an iteration of fragment bounds on this flow.
|
|
|
|
fn iterate_through_fragment_bounds(&self, iterator: &mut FragmentBoundsIterator);
|
|
|
|
|
2014-07-19 00:27:23 +04:00
|
|
|
fn compute_collapsible_block_start_margin(&mut self,
|
2014-10-14 10:42:35 +04:00
|
|
|
_layout_context: &mut LayoutContext,
|
|
|
|
_margin_collapse_info: &mut MarginCollapseInfo) {
|
2014-04-04 05:01:48 +04:00
|
|
|
// The default implementation is a no-op.
|
2013-08-20 23:03:52 +04:00
|
|
|
}
|
2013-05-22 23:57:28 +04:00
|
|
|
|
2013-11-18 23:54:00 +04:00
|
|
|
/// Marks this flow as the root flow. The default implementation is a no-op.
|
|
|
|
fn mark_as_root(&mut self) {}
|
|
|
|
|
2014-03-03 22:37:33 +04:00
|
|
|
// Note that the following functions are mostly called using static method
|
|
|
|
// dispatch, so it's ok to have them in this trait. Plus, they have
|
|
|
|
// different behaviour for different types of Flow, so they can't go into
|
|
|
|
// the Immutable / Mutable Flow Utils traits without additional casts.
|
|
|
|
|
|
|
|
/// Return true if store overflow is delayed for this flow.
|
|
|
|
///
|
|
|
|
/// Currently happens only for absolutely positioned flows.
|
|
|
|
fn is_store_overflow_delayed(&mut self) -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_root(&self) -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_float(&self) -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The 'position' property of this flow.
|
|
|
|
fn positioning(&self) -> position::T {
|
|
|
|
position::static_
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Return true if this flow has position 'fixed'.
|
|
|
|
fn is_fixed(&self) -> bool {
|
|
|
|
self.positioning() == position::fixed
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_positioned(&self) -> bool {
|
2014-11-18 21:42:32 +03:00
|
|
|
self.is_relatively_positioned() || base(self).flags.contains(IS_ABSOLUTELY_POSITIONED)
|
2014-03-03 22:37:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
fn is_relatively_positioned(&self) -> bool {
|
|
|
|
self.positioning() == position::relative
|
|
|
|
}
|
|
|
|
|
2014-10-02 05:36:25 +04:00
|
|
|
/// Return true if this is the root of an absolute flow tree.
|
2014-03-03 22:37:33 +04:00
|
|
|
fn is_root_of_absolute_flow_tree(&self) -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
2014-04-04 05:01:48 +04:00
|
|
|
/// Returns true if this is an absolute containing block.
|
|
|
|
fn is_absolute_containing_block(&self) -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
2014-10-02 05:36:25 +04:00
|
|
|
/// Updates the inline position of a child flow during the assign-height traversal. At present,
|
|
|
|
/// this is only used for absolutely-positioned inline-blocks.
|
|
|
|
fn update_late_computed_inline_position_if_necessary(&mut self, inline_position: Au);
|
|
|
|
|
|
|
|
/// Updates the block position of a child flow during the assign-height traversal. At present,
|
|
|
|
/// this is only used for absolutely-positioned inline-blocks.
|
|
|
|
fn update_late_computed_block_position_if_necessary(&mut self, block_position: Au);
|
|
|
|
|
2014-05-02 22:58:29 +04:00
|
|
|
/// Return the dimensions of the containing block generated by this flow for absolutely-
|
|
|
|
/// positioned descendants. For block flows, this is the padding box.
|
2014-07-19 00:27:23 +04:00
|
|
|
fn generated_containing_block_rect(&self) -> LogicalRect<Au> {
|
2014-11-13 06:48:31 +03:00
|
|
|
panic!("generated_containing_block_position not yet implemented for this flow")
|
2014-03-03 22:37:33 +04:00
|
|
|
}
|
|
|
|
|
2014-04-04 05:01:48 +04:00
|
|
|
/// Returns a layer ID for the given fragment.
|
|
|
|
fn layer_id(&self, fragment_id: uint) -> LayerId {
|
|
|
|
unsafe {
|
2014-06-05 21:58:44 +04:00
|
|
|
let pointer: uint = mem::transmute(self);
|
2014-04-04 05:01:48 +04:00
|
|
|
LayerId(pointer, fragment_id)
|
|
|
|
}
|
|
|
|
}
|
2014-10-31 23:39:34 +03:00
|
|
|
|
|
|
|
/// Attempts to perform incremental fixup of this flow by replacing its fragment's style with
|
|
|
|
/// the new style. This can only succeed if the flow has exactly one fragment.
|
|
|
|
fn repair_style(&mut self, new_style: &Arc<ComputedValues>);
|
2013-05-22 23:57:28 +04:00
|
|
|
}
|
|
|
|
|
2013-10-29 00:31:44 +04:00
|
|
|
// Base access
|
|
|
|
|
|
|
|
#[inline(always)]
|
2014-01-14 02:43:05 +04:00
|
|
|
pub fn base<'a>(this: &'a Flow) -> &'a BaseFlow {
|
2013-10-29 00:31:44 +04:00
|
|
|
unsafe {
|
2014-08-29 03:35:55 +04:00
|
|
|
let obj = mem::transmute::<&'a Flow, raw::TraitObject>(this);
|
|
|
|
mem::transmute::<*mut (), &'a BaseFlow>(obj.data)
|
2013-08-22 01:24:47 +04:00
|
|
|
}
|
2013-10-29 00:31:44 +04:00
|
|
|
}
|
2013-08-22 01:24:47 +04:00
|
|
|
|
2013-11-11 11:07:23 +04:00
|
|
|
/// Iterates over the children of this immutable flow.
|
2014-02-06 07:19:43 +04:00
|
|
|
pub fn imm_child_iter<'a>(flow: &'a Flow) -> FlowListIterator<'a> {
|
2013-11-11 11:07:23 +04:00
|
|
|
base(flow).children.iter()
|
|
|
|
}
|
|
|
|
|
2013-10-29 00:31:44 +04:00
|
|
|
#[inline(always)]
|
2014-01-14 02:43:05 +04:00
|
|
|
pub fn mut_base<'a>(this: &'a mut Flow) -> &'a mut BaseFlow {
|
2013-10-29 00:31:44 +04:00
|
|
|
unsafe {
|
2014-08-29 03:35:55 +04:00
|
|
|
let obj = mem::transmute::<&'a mut Flow, raw::TraitObject>(this);
|
|
|
|
mem::transmute::<*mut (), &'a mut BaseFlow>(obj.data)
|
2013-05-08 00:44:45 +04:00
|
|
|
}
|
2013-10-29 00:31:44 +04:00
|
|
|
}
|
2013-08-20 23:03:52 +04:00
|
|
|
|
2013-10-29 00:31:44 +04:00
|
|
|
/// Iterates over the children of this flow.
|
2014-02-06 07:19:43 +04:00
|
|
|
pub fn child_iter<'a>(flow: &'a mut Flow) -> MutFlowListIterator<'a> {
|
2014-09-21 02:35:08 +04:00
|
|
|
mut_base(flow).children.iter_mut()
|
2013-10-29 00:31:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
pub trait ImmutableFlowUtils {
|
|
|
|
// Convenience functions
|
|
|
|
|
|
|
|
/// Returns true if this flow is a block or a float flow.
|
|
|
|
fn is_block_like(self) -> bool;
|
|
|
|
|
servo: Merge #1973 - Support fixed-layout table and a part of anonymous table object (from june0cho:table_rebase); r=larsbergstrom,metajack
This is a rebase of #1548 on recent master.
There have been many changes since #1548 is first uploaded, so I'm creating new PR.
This PR includes:
- construction of table-* flows (table-wrapper, table-caption, table, table-rowgroup, table-row, table-cell)
- fixed-layout table calculation
- a part of anonymous table object implementation
[CSS 2.1, 17.2.1](http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes) (Step 1-1, 1-2, Step 2)
Source-Repo: https://github.com/servo/servo
Source-Revision: fd5e5cd18b41f0ce2b33fb97fb4e3d75ddbbbceb
2014-03-25 21:40:47 +04:00
|
|
|
/// Returns true if this flow is a table flow.
|
|
|
|
fn is_table(self) -> bool;
|
|
|
|
|
|
|
|
/// Returns true if this flow is a table caption flow.
|
|
|
|
fn is_table_caption(self) -> bool;
|
|
|
|
|
|
|
|
/// Returns true if this flow is a proper table child.
|
|
|
|
fn is_proper_table_child(self) -> bool;
|
|
|
|
|
|
|
|
/// Returns true if this flow is a table row flow.
|
|
|
|
fn is_table_row(self) -> bool;
|
|
|
|
|
|
|
|
/// Returns true if this flow is a table cell flow.
|
|
|
|
fn is_table_cell(self) -> bool;
|
|
|
|
|
|
|
|
/// Returns true if this flow is a table colgroup flow.
|
|
|
|
fn is_table_colgroup(self) -> bool;
|
|
|
|
|
|
|
|
/// Returns true if this flow is a table rowgroup flow.
|
|
|
|
fn is_table_rowgroup(self) -> bool;
|
|
|
|
|
|
|
|
/// Returns true if this flow is one of table-related flows.
|
|
|
|
fn is_table_kind(self) -> bool;
|
|
|
|
|
|
|
|
/// Returns true if anonymous flow is needed between this flow and child flow.
|
|
|
|
fn need_anonymous_flow(self, child: &Flow) -> bool;
|
|
|
|
|
|
|
|
/// Generates missing child flow of this flow.
|
2014-06-04 09:25:28 +04:00
|
|
|
fn generate_missing_child_flow(self, node: &ThreadSafeLayoutNode) -> FlowRef;
|
servo: Merge #1973 - Support fixed-layout table and a part of anonymous table object (from june0cho:table_rebase); r=larsbergstrom,metajack
This is a rebase of #1548 on recent master.
There have been many changes since #1548 is first uploaded, so I'm creating new PR.
This PR includes:
- construction of table-* flows (table-wrapper, table-caption, table, table-rowgroup, table-row, table-cell)
- fixed-layout table calculation
- a part of anonymous table object implementation
[CSS 2.1, 17.2.1](http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes) (Step 1-1, 1-2, Step 2)
Source-Repo: https://github.com/servo/servo
Source-Revision: fd5e5cd18b41f0ce2b33fb97fb4e3d75ddbbbceb
2014-03-25 21:40:47 +04:00
|
|
|
|
2013-10-29 00:31:44 +04:00
|
|
|
/// Returns true if this flow has no children.
|
|
|
|
fn is_leaf(self) -> bool;
|
|
|
|
|
2014-01-23 04:04:08 +04:00
|
|
|
/// Returns the number of children that this flow possesses.
|
|
|
|
fn child_count(self) -> uint;
|
|
|
|
|
2014-02-05 02:52:39 +04:00
|
|
|
/// Return true if this flow is a Block Container.
|
|
|
|
fn is_block_container(self) -> bool;
|
|
|
|
|
2014-02-19 01:17:07 +04:00
|
|
|
/// Returns true if this flow is a block flow.
|
|
|
|
fn is_block_flow(self) -> bool;
|
2013-10-29 00:31:44 +04:00
|
|
|
|
|
|
|
/// Returns true if this flow is an inline flow.
|
2014-02-19 01:17:07 +04:00
|
|
|
fn is_inline_flow(self) -> bool;
|
2013-10-29 00:31:44 +04:00
|
|
|
|
|
|
|
/// Dumps the flow tree for debugging.
|
|
|
|
fn dump(self);
|
2013-11-11 11:07:23 +04:00
|
|
|
|
|
|
|
/// Dumps the flow tree for debugging, with a prefix to indicate that we're at the given level.
|
|
|
|
fn dump_with_level(self, level: uint);
|
2013-10-29 00:31:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
pub trait MutableFlowUtils {
|
|
|
|
// Traversals
|
|
|
|
|
|
|
|
/// Traverses the tree in preorder.
|
2014-10-15 05:33:28 +04:00
|
|
|
fn traverse_preorder<T:PreorderFlowTraversal>(self, traversal: &T);
|
2013-10-29 00:31:44 +04:00
|
|
|
|
|
|
|
/// Traverses the tree in postorder.
|
2014-10-15 05:33:28 +04:00
|
|
|
fn traverse_postorder<T:PostorderFlowTraversal>(self, traversal: &T);
|
2013-10-29 00:31:44 +04:00
|
|
|
|
|
|
|
// Mutators
|
|
|
|
|
2013-10-31 23:10:32 +04:00
|
|
|
/// Computes the overflow region for this flow.
|
2014-08-11 16:20:07 +04:00
|
|
|
fn store_overflow(self, _: &LayoutContext);
|
2013-10-31 23:10:32 +04:00
|
|
|
|
2014-10-02 05:36:25 +04:00
|
|
|
/// Gathers static block-offsets bubbled up by kids.
|
|
|
|
///
|
|
|
|
/// This essentially gives us offsets of all absolutely positioned direct descendants and all
|
|
|
|
/// fixed descendants, in tree order.
|
|
|
|
///
|
|
|
|
/// This is called in a bottom-up traversal (specifically, the assign-block-size traversal).
|
|
|
|
/// So, kids have their flow origin already set. In the case of absolute flow kids, they have
|
|
|
|
/// their hypothetical box position already set.
|
2014-10-15 02:51:30 +04:00
|
|
|
fn collect_static_block_offsets_from_children(self);
|
2013-10-29 00:31:44 +04:00
|
|
|
}
|
|
|
|
|
2014-01-23 04:04:08 +04:00
|
|
|
pub trait MutableOwnedFlowUtils {
|
2014-03-03 22:37:33 +04:00
|
|
|
/// Set absolute descendants for this flow.
|
|
|
|
///
|
|
|
|
/// Set this flow as the Containing Block for all the absolute descendants.
|
2014-09-19 18:51:02 +04:00
|
|
|
fn set_absolute_descendants(&mut self, abs_descendants: AbsDescendants);
|
2014-01-23 04:04:08 +04:00
|
|
|
}
|
|
|
|
|
2014-09-08 10:33:09 +04:00
|
|
|
#[deriving(Encodable, PartialEq, Show)]
|
2013-10-29 00:31:44 +04:00
|
|
|
pub enum FlowClass {
|
|
|
|
BlockFlowClass,
|
|
|
|
InlineFlowClass,
|
servo: Merge #1973 - Support fixed-layout table and a part of anonymous table object (from june0cho:table_rebase); r=larsbergstrom,metajack
This is a rebase of #1548 on recent master.
There have been many changes since #1548 is first uploaded, so I'm creating new PR.
This PR includes:
- construction of table-* flows (table-wrapper, table-caption, table, table-rowgroup, table-row, table-cell)
- fixed-layout table calculation
- a part of anonymous table object implementation
[CSS 2.1, 17.2.1](http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes) (Step 1-1, 1-2, Step 2)
Source-Repo: https://github.com/servo/servo
Source-Revision: fd5e5cd18b41f0ce2b33fb97fb4e3d75ddbbbceb
2014-03-25 21:40:47 +04:00
|
|
|
TableWrapperFlowClass,
|
|
|
|
TableFlowClass,
|
|
|
|
TableColGroupFlowClass,
|
|
|
|
TableRowGroupFlowClass,
|
|
|
|
TableRowFlowClass,
|
|
|
|
TableCaptionFlowClass,
|
|
|
|
TableCellFlowClass,
|
2013-08-20 23:03:52 +04:00
|
|
|
}
|
2013-08-17 02:46:03 +04:00
|
|
|
|
2013-10-29 00:31:44 +04:00
|
|
|
/// A top-down traversal.
|
|
|
|
pub trait PreorderFlowTraversal {
|
|
|
|
/// The operation to perform. Return true to continue or false to stop.
|
2014-10-15 05:33:28 +04:00
|
|
|
fn process(&self, flow: &mut Flow);
|
2013-10-29 00:31:44 +04:00
|
|
|
|
2014-10-09 21:21:32 +04:00
|
|
|
/// Returns true if this node must be processed in-order. If this returns false,
|
|
|
|
/// we skip the operation for this node, but continue processing the descendants.
|
|
|
|
/// This is called *after* parent nodes are visited.
|
2014-10-15 05:33:28 +04:00
|
|
|
fn should_process(&self, _flow: &mut Flow) -> bool {
|
2014-10-09 21:21:32 +04:00
|
|
|
true
|
|
|
|
}
|
2013-10-29 00:31:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// A bottom-up traversal, with a optional in-order pass.
|
|
|
|
pub trait PostorderFlowTraversal {
|
|
|
|
/// The operation to perform. Return true to continue or false to stop.
|
2014-10-15 05:33:28 +04:00
|
|
|
fn process(&self, flow: &mut Flow);
|
2013-10-29 00:31:44 +04:00
|
|
|
|
|
|
|
/// Returns false if this node must be processed in-order. If this returns false, we skip the
|
2014-01-23 04:04:08 +04:00
|
|
|
/// operation for this node, but continue processing the ancestors. This is called *after*
|
2013-10-29 00:31:44 +04:00
|
|
|
/// child nodes are visited.
|
2014-10-15 05:33:28 +04:00
|
|
|
fn should_process(&self, _flow: &mut Flow) -> bool {
|
2013-10-29 00:31:44 +04:00
|
|
|
true
|
2013-08-17 02:46:03 +04:00
|
|
|
}
|
2013-05-08 00:44:45 +04:00
|
|
|
}
|
|
|
|
|
2014-11-18 21:42:32 +03:00
|
|
|
bitflags! {
|
|
|
|
#[doc = "Flags used in flows."]
|
|
|
|
flags FlowFlags: u16 {
|
|
|
|
// floated descendants flags
|
|
|
|
#[doc = "Whether this flow has descendants that float left in the same block formatting"]
|
|
|
|
#[doc = "context."]
|
|
|
|
const HAS_LEFT_FLOATED_DESCENDANTS = 0b0000_0000_0000_0001,
|
|
|
|
#[doc = "Whether this flow has descendants that float right in the same block formatting"]
|
|
|
|
#[doc = "context."]
|
|
|
|
const HAS_RIGHT_FLOATED_DESCENDANTS = 0b0000_0000_0000_0010,
|
|
|
|
#[doc = "Whether this flow is impacted by floats to the left in the same block formatting"]
|
|
|
|
#[doc = "context (i.e. its height depends on some prior flows with `float: left`)."]
|
|
|
|
const IMPACTED_BY_LEFT_FLOATS = 0b0000_0000_0000_0100,
|
|
|
|
#[doc = "Whether this flow is impacted by floats to the right in the same block"]
|
|
|
|
#[doc = "formatting context (i.e. its height depends on some prior flows with `float:"]
|
|
|
|
#[doc = "right`)."]
|
|
|
|
const IMPACTED_BY_RIGHT_FLOATS = 0b0000_0000_0000_1000,
|
|
|
|
|
|
|
|
// text align flags
|
|
|
|
#[doc = "Whether this flow contains a flow that has its own layer within the same absolute"]
|
|
|
|
#[doc = "containing block."]
|
|
|
|
const LAYERS_NEEDED_FOR_DESCENDANTS = 0b0000_0000_0001_0000,
|
|
|
|
#[doc = "Whether this flow must have its own layer. Even if this flag is not set, it might"]
|
|
|
|
#[doc = "get its own layer if it's deemed to be likely to overlap flows with their own"]
|
|
|
|
#[doc = "layer."]
|
|
|
|
const NEEDS_LAYER = 0b0000_0000_0010_0000,
|
|
|
|
#[doc = "Whether this flow is absolutely positioned. This is checked all over layout, so a"]
|
|
|
|
#[doc = "virtual call is too expensive."]
|
|
|
|
const IS_ABSOLUTELY_POSITIONED = 0b0000_0000_0100_0000,
|
|
|
|
#[doc = "Whether this flow clears to the left. This is checked all over layout, so a"]
|
|
|
|
#[doc = "virtual call is too expensive."]
|
|
|
|
const CLEARS_LEFT = 0b0000_0000_1000_0000,
|
|
|
|
#[doc = "Whether this flow clears to the right. This is checked all over layout, so a"]
|
|
|
|
#[doc = "virtual call is too expensive."]
|
|
|
|
const CLEARS_RIGHT = 0b0000_0001_0000_0000,
|
|
|
|
#[doc = "Whether this flow is left-floated. This is checked all over layout, so a"]
|
|
|
|
#[doc = "virtual call is too expensive."]
|
|
|
|
const FLOATS_LEFT = 0b0000_0010_0000_0000,
|
|
|
|
#[doc = "Whether this flow is right-floated. This is checked all over layout, so a"]
|
|
|
|
#[doc = "virtual call is too expensive."]
|
|
|
|
const FLOATS_RIGHT = 0b0000_0100_0000_0000,
|
|
|
|
#[doc = "Text alignment."]
|
|
|
|
const TEXT_ALIGN = 0b0000_1000_0000_0000,
|
|
|
|
}
|
|
|
|
}
|
2013-12-13 05:58:21 +04:00
|
|
|
|
2014-11-18 21:42:32 +03:00
|
|
|
// NB: If you update this field, you must update the the floated descendants flags.
|
2014-05-03 03:10:20 +04:00
|
|
|
/// The bitmask of flags that represent the `has_left_floated_descendants` and
|
|
|
|
/// `has_right_floated_descendants` fields.
|
|
|
|
|
2014-11-18 21:42:32 +03:00
|
|
|
static HAS_FLOATED_DESCENDANTS_BITMASK: FlowFlags = FlowFlags { bits: 0b0000_0011 };
|
|
|
|
|
|
|
|
// NB: If you update this field, you must update the the text align flags.
|
2013-12-17 03:25:12 +04:00
|
|
|
/// The bitmask of flags that represent the text alignment field.
|
2014-11-18 21:42:32 +03:00
|
|
|
static TEXT_ALIGN_BITMASK: FlowFlags = FlowFlags { bits: 0b0011_0000 };
|
2013-12-17 03:25:12 +04:00
|
|
|
|
|
|
|
/// The number of bits we must shift off to handle the text alignment field.
|
2014-11-18 21:42:32 +03:00
|
|
|
static TEXT_ALIGN_SHIFT: uint = 4;
|
2014-04-04 05:01:48 +04:00
|
|
|
|
2013-12-17 03:25:12 +04:00
|
|
|
impl FlowFlags {
|
2014-05-02 22:58:29 +04:00
|
|
|
/// Propagates text alignment flags from an appropriate parent flow per CSS 2.1.
|
|
|
|
///
|
|
|
|
/// FIXME(#2265, pcwalton): It would be cleaner and faster to make this a derived CSS property
|
|
|
|
/// `-servo-text-align-in-effect`.
|
|
|
|
pub fn propagate_text_alignment_from_parent(&mut self, parent_flags: FlowFlags) {
|
|
|
|
self.set_text_align_override(parent_flags);
|
|
|
|
}
|
|
|
|
|
2013-12-17 03:25:12 +04:00
|
|
|
#[inline]
|
|
|
|
pub fn text_align(self) -> text_align::T {
|
2014-11-18 21:42:32 +03:00
|
|
|
FromPrimitive::from_u16((self & TEXT_ALIGN_BITMASK).bits() >> TEXT_ALIGN_SHIFT).unwrap()
|
2013-12-17 03:25:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub fn set_text_align(&mut self, value: text_align::T) {
|
2014-11-18 21:42:32 +03:00
|
|
|
*self = (*self & !TEXT_ALIGN_BITMASK) | FlowFlags::from_bits(value as u16 << TEXT_ALIGN_SHIFT).unwrap();
|
2013-12-17 03:25:12 +04:00
|
|
|
}
|
2014-01-23 05:13:03 +04:00
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub fn set_text_align_override(&mut self, parent: FlowFlags) {
|
2014-11-18 21:42:32 +03:00
|
|
|
self.insert(parent & TEXT_ALIGN_BITMASK);
|
2014-01-23 05:13:03 +04:00
|
|
|
}
|
2014-05-03 03:10:20 +04:00
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub fn union_floated_descendants_flags(&mut self, other: FlowFlags) {
|
2014-11-18 21:42:32 +03:00
|
|
|
self.insert(other & HAS_FLOATED_DESCENDANTS_BITMASK);
|
2014-05-03 03:10:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub fn impacted_by_floats(&self) -> bool {
|
2014-11-18 21:42:32 +03:00
|
|
|
self.contains(IMPACTED_BY_LEFT_FLOATS) || self.contains(IMPACTED_BY_RIGHT_FLOATS)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub fn set(&mut self, flags: FlowFlags, value: bool) {
|
|
|
|
if value {
|
|
|
|
self.insert(flags);
|
|
|
|
} else {
|
|
|
|
self.remove(flags);
|
|
|
|
}
|
2014-05-03 03:10:20 +04:00
|
|
|
}
|
2014-10-29 05:42:38 +03:00
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub fn float_kind(&self) -> float::T {
|
2014-11-18 21:42:32 +03:00
|
|
|
if self.contains(FLOATS_LEFT) {
|
2014-10-29 05:42:38 +03:00
|
|
|
float::left
|
2014-11-18 21:42:32 +03:00
|
|
|
} else if self.contains(FLOATS_RIGHT) {
|
2014-10-29 05:42:38 +03:00
|
|
|
float::right
|
|
|
|
} else {
|
|
|
|
float::none
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub fn clears_floats(&self) -> bool {
|
2014-11-18 21:42:32 +03:00
|
|
|
self.contains(CLEARS_LEFT) || self.contains(CLEARS_RIGHT)
|
2014-10-29 05:42:38 +03:00
|
|
|
}
|
2013-12-17 03:25:12 +04:00
|
|
|
}
|
|
|
|
|
2014-03-03 22:37:33 +04:00
|
|
|
/// The Descendants of a flow.
|
|
|
|
///
|
|
|
|
/// Also, details about their position wrt this flow.
|
2014-10-15 02:51:30 +04:00
|
|
|
#[deriving(Clone)]
|
2014-03-03 22:37:33 +04:00
|
|
|
pub struct Descendants {
|
2014-06-04 09:25:28 +04:00
|
|
|
/// Links to every descendant. This must be private because it is unsafe to leak `FlowRef`s to
|
|
|
|
/// layout.
|
|
|
|
descendant_links: Vec<FlowRef>,
|
|
|
|
|
2014-10-02 05:36:25 +04:00
|
|
|
/// Static block-direction offsets of all descendants from the start of this flow box.
|
|
|
|
pub static_block_offsets: Vec<Au>,
|
2014-03-03 22:37:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Descendants {
|
|
|
|
pub fn new() -> Descendants {
|
|
|
|
Descendants {
|
2014-05-06 05:01:24 +04:00
|
|
|
descendant_links: Vec::new(),
|
2014-10-02 05:36:25 +04:00
|
|
|
static_block_offsets: Vec::new(),
|
2014-03-03 22:37:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn len(&self) -> uint {
|
|
|
|
self.descendant_links.len()
|
|
|
|
}
|
|
|
|
|
2014-10-23 04:48:31 +04:00
|
|
|
pub fn is_empty(&self) -> bool {
|
|
|
|
self.descendant_links.is_empty()
|
|
|
|
}
|
|
|
|
|
2014-06-04 09:25:28 +04:00
|
|
|
pub fn push(&mut self, given_descendant: FlowRef) {
|
2014-03-03 22:37:33 +04:00
|
|
|
self.descendant_links.push(given_descendant);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Push the given descendants on to the existing descendants.
|
|
|
|
///
|
|
|
|
/// Ignore any static y offsets, because they are None before layout.
|
2014-05-07 09:16:22 +04:00
|
|
|
pub fn push_descendants(&mut self, given_descendants: Descendants) {
|
2014-09-21 02:35:08 +04:00
|
|
|
for elem in given_descendants.descendant_links.into_iter() {
|
2014-03-03 22:37:33 +04:00
|
|
|
self.descendant_links.push(elem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Return an iterator over the descendant flows.
|
|
|
|
pub fn iter<'a>(&'a mut self) -> DescendantIter<'a> {
|
2014-06-04 09:25:28 +04:00
|
|
|
DescendantIter {
|
2014-09-21 02:35:08 +04:00
|
|
|
iter: self.descendant_links.slice_from_mut(0).iter_mut(),
|
2014-06-04 09:25:28 +04:00
|
|
|
}
|
2014-03-03 22:37:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Return an iterator over (descendant, static y offset).
|
|
|
|
pub fn iter_with_offset<'a>(&'a mut self) -> DescendantOffsetIter<'a> {
|
2014-06-04 09:25:28 +04:00
|
|
|
let descendant_iter = DescendantIter {
|
2014-09-21 02:35:08 +04:00
|
|
|
iter: self.descendant_links.slice_from_mut(0).iter_mut(),
|
2014-06-04 09:25:28 +04:00
|
|
|
};
|
2014-10-02 05:36:25 +04:00
|
|
|
descendant_iter.zip(self.static_block_offsets.slice_from_mut(0).iter_mut())
|
2014-03-03 22:37:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub type AbsDescendants = Descendants;
|
|
|
|
|
2014-06-04 09:25:28 +04:00
|
|
|
pub struct DescendantIter<'a> {
|
|
|
|
iter: MutItems<'a, FlowRef>,
|
|
|
|
}
|
|
|
|
|
2014-09-21 02:35:08 +04:00
|
|
|
impl<'a> Iterator<&'a mut Flow + 'a> for DescendantIter<'a> {
|
|
|
|
fn next(&mut self) -> Option<&'a mut Flow + 'a> {
|
2014-06-04 09:25:28 +04:00
|
|
|
match self.iter.next() {
|
|
|
|
None => None,
|
|
|
|
Some(ref mut flow) => {
|
|
|
|
unsafe {
|
2014-10-16 02:18:23 +04:00
|
|
|
let result: &'a mut Flow = mem::transmute(flow.deref_mut());
|
2014-06-04 09:25:28 +04:00
|
|
|
Some(result)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-03 22:37:33 +04:00
|
|
|
|
2014-06-04 09:25:28 +04:00
|
|
|
pub type DescendantOffsetIter<'a> = Zip<DescendantIter<'a>, MutItems<'a, Au>>;
|
2014-03-03 22:37:33 +04:00
|
|
|
|
2014-05-03 03:10:20 +04:00
|
|
|
/// Information needed to compute absolute (i.e. viewport-relative) flow positions (not to be
|
|
|
|
/// confused with absolutely-positioned flows).
|
2014-09-08 10:33:09 +04:00
|
|
|
#[deriving(Encodable)]
|
2014-05-03 03:10:20 +04:00
|
|
|
pub struct AbsolutePositionInfo {
|
|
|
|
/// The size of the containing block for relatively-positioned descendants.
|
2014-07-19 00:27:23 +04:00
|
|
|
pub relative_containing_block_size: LogicalSize<Au>,
|
2014-10-14 10:42:35 +04:00
|
|
|
|
2014-11-17 02:39:27 +03:00
|
|
|
/// The position of the absolute containing block relative to the nearest ancestor stacking
|
|
|
|
/// context. If the absolute containing block establishes the stacking context for this flow,
|
|
|
|
/// and this flow is not itself absolutely-positioned, then this is (0, 0).
|
|
|
|
pub stacking_relative_position_of_absolute_containing_block: Point2D<Au>,
|
2014-10-14 10:42:35 +04:00
|
|
|
|
2014-05-03 03:10:20 +04:00
|
|
|
/// Whether the absolute containing block forces positioned descendants to be layerized.
|
|
|
|
///
|
|
|
|
/// FIXME(pcwalton): Move into `FlowFlags`.
|
|
|
|
pub layers_needed_for_positioned_flows: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AbsolutePositionInfo {
|
2014-07-19 00:27:23 +04:00
|
|
|
pub fn new(writing_mode: WritingMode) -> AbsolutePositionInfo {
|
|
|
|
// FIXME(pcwalton): The initial relative containing block-size should be equal to the size
|
2014-05-03 03:10:20 +04:00
|
|
|
// of the root layer.
|
|
|
|
AbsolutePositionInfo {
|
2014-07-19 00:27:23 +04:00
|
|
|
relative_containing_block_size: LogicalSize::zero(writing_mode),
|
2014-11-17 02:39:27 +03:00
|
|
|
stacking_relative_position_of_absolute_containing_block: Zero::zero(),
|
2014-05-03 03:10:20 +04:00
|
|
|
layers_needed_for_positioned_flows: false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-08 00:44:45 +04:00
|
|
|
/// Data common to all flows.
|
2014-01-14 02:43:05 +04:00
|
|
|
pub struct BaseFlow {
|
2014-06-04 09:25:28 +04:00
|
|
|
/// NB: Must be the first element.
|
|
|
|
///
|
|
|
|
/// The necessity of this will disappear once we have dynamically-sized types.
|
|
|
|
ref_count: AtomicUint,
|
|
|
|
|
2014-04-28 02:52:39 +04:00
|
|
|
pub restyle_damage: RestyleDamage,
|
2013-05-03 06:37:36 +04:00
|
|
|
|
2013-12-13 05:58:21 +04:00
|
|
|
/// The children of this flow.
|
2014-04-28 02:52:39 +04:00
|
|
|
pub children: FlowList,
|
2014-09-19 18:51:02 +04:00
|
|
|
|
2014-09-26 03:48:35 +04:00
|
|
|
/// Intrinsic inline sizes for this flow.
|
2014-07-19 00:27:23 +04:00
|
|
|
pub intrinsic_inline_sizes: IntrinsicISizes,
|
2013-10-31 23:10:32 +04:00
|
|
|
|
2014-04-04 05:01:48 +04:00
|
|
|
/// The upper left corner of the box representing this flow, relative to the box representing
|
|
|
|
/// its parent flow.
|
|
|
|
///
|
|
|
|
/// For absolute flows, this represents the position with respect to its *containing block*.
|
|
|
|
///
|
|
|
|
/// This does not include margins in the block flow direction, because those can collapse. So
|
|
|
|
/// for the block direction (usually vertical), this represents the *border box*. For the
|
|
|
|
/// inline direction (usually horizontal), this represents the *margin box*.
|
2014-07-19 00:27:23 +04:00
|
|
|
pub position: LogicalRect<Au>,
|
2013-10-31 23:10:32 +04:00
|
|
|
|
|
|
|
/// The amount of overflow of this flow, relative to the containing block. Must include all the
|
|
|
|
/// pixels of all the display list items for correct invalidation.
|
2014-07-19 00:27:23 +04:00
|
|
|
pub overflow: LogicalRect<Au>,
|
2013-10-31 23:10:32 +04:00
|
|
|
|
2014-01-23 04:04:08 +04:00
|
|
|
/// Data used during parallel traversals.
|
|
|
|
///
|
|
|
|
/// TODO(pcwalton): Group with other transient data to save space.
|
2014-04-28 02:52:39 +04:00
|
|
|
pub parallel: FlowParallelInfo,
|
2014-01-23 04:04:08 +04:00
|
|
|
|
2014-02-28 00:01:49 +04:00
|
|
|
/// The floats next to this flow.
|
2014-04-28 02:52:39 +04:00
|
|
|
pub floats: Floats,
|
2014-02-28 00:01:49 +04:00
|
|
|
|
2014-04-04 05:01:48 +04:00
|
|
|
/// The collapsible margins for this flow, if any.
|
2014-04-28 02:52:39 +04:00
|
|
|
pub collapsible_margins: CollapsibleMargins,
|
2014-04-04 05:01:48 +04:00
|
|
|
|
2014-11-17 02:39:27 +03:00
|
|
|
/// The position of this flow relative to the start of the nearest ancestor stacking context.
|
|
|
|
/// This is computed during the top-down pass of display list construction.
|
|
|
|
pub stacking_relative_position: Point2D<Au>,
|
2013-12-13 05:58:21 +04:00
|
|
|
|
2014-04-04 05:01:48 +04:00
|
|
|
/// Details about descendants with position 'absolute' or 'fixed' for which we are the
|
|
|
|
/// containing block. This is in tree order. This includes any direct children.
|
2014-04-28 02:52:39 +04:00
|
|
|
pub abs_descendants: AbsDescendants,
|
2014-03-03 22:37:33 +04:00
|
|
|
|
2014-10-14 04:03:40 +04:00
|
|
|
/// The inline-size of the block container of this flow. Used for computing percentage and
|
|
|
|
/// automatic values for `width`.
|
|
|
|
pub block_container_inline_size: Au,
|
|
|
|
|
2014-09-20 10:05:55 +04:00
|
|
|
/// The block-size of the block container of this flow, if it is an explicit size (does not
|
|
|
|
/// depend on content heights). Used for computing percentage values for `height`.
|
|
|
|
pub block_container_explicit_block_size: Option<Au>,
|
|
|
|
|
2014-03-03 22:37:33 +04:00
|
|
|
/// Offset wrt the nearest positioned ancestor - aka the Containing Block
|
|
|
|
/// for any absolutely positioned elements.
|
2014-07-19 00:27:23 +04:00
|
|
|
pub absolute_static_i_offset: Au,
|
2014-05-02 22:58:29 +04:00
|
|
|
|
2014-03-03 22:37:33 +04:00
|
|
|
/// Offset wrt the Initial Containing Block.
|
2014-07-19 00:27:23 +04:00
|
|
|
pub fixed_static_i_offset: Au,
|
2014-03-03 22:37:33 +04:00
|
|
|
|
|
|
|
/// Reference to the Containing Block, if this flow is absolutely positioned.
|
2014-05-02 22:58:29 +04:00
|
|
|
pub absolute_cb: ContainingBlockLink,
|
2014-03-03 22:37:33 +04:00
|
|
|
|
2014-05-03 03:10:20 +04:00
|
|
|
/// Information needed to compute absolute (i.e. viewport-relative) flow positions (not to be
|
|
|
|
/// confused with absolutely-positioned flows).
|
|
|
|
///
|
2014-07-19 00:27:23 +04:00
|
|
|
/// FIXME(pcwalton): Merge with `absolute_static_i_offset` and `fixed_static_i_offset` above?
|
2014-05-03 03:10:20 +04:00
|
|
|
pub absolute_position_info: AbsolutePositionInfo,
|
|
|
|
|
2014-10-14 10:42:35 +04:00
|
|
|
/// The clipping rectangle for this flow and its descendants, in layer coordinates.
|
|
|
|
///
|
|
|
|
/// TODO(pcwalton): When we have `border-radius` this will need to at least support rounded
|
|
|
|
/// rectangles.
|
|
|
|
pub clip_rect: Rect<Au>,
|
|
|
|
|
2014-11-17 02:39:27 +03:00
|
|
|
/// The results of display list building for this flow.
|
|
|
|
pub display_list_building_result: DisplayListBuildingResult,
|
2014-05-03 03:10:20 +04:00
|
|
|
|
2014-10-29 02:21:48 +03:00
|
|
|
/// The writing mode for this flow.
|
|
|
|
pub writing_mode: WritingMode,
|
|
|
|
|
2014-05-02 22:58:29 +04:00
|
|
|
/// Various flags for flows, tightly packed to save space.
|
|
|
|
pub flags: FlowFlags,
|
2012-10-10 20:39:40 +04:00
|
|
|
}
|
|
|
|
|
2014-10-02 05:36:25 +04:00
|
|
|
impl fmt::Show for BaseFlow {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f,
|
2014-10-14 10:42:35 +04:00
|
|
|
"@ {}, CC {}, ADC {}",
|
2014-10-14 04:03:40 +04:00
|
|
|
self.position,
|
2014-10-02 05:36:25 +04:00
|
|
|
self.parallel.children_count.load(SeqCst),
|
2014-10-14 10:42:35 +04:00
|
|
|
self.abs_descendants.len())
|
2014-10-02 05:36:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-08 10:33:09 +04:00
|
|
|
impl<E, S: Encoder<E>> Encodable<S, E> for BaseFlow {
|
|
|
|
fn encode(&self, e: &mut S) -> Result<(), E> {
|
|
|
|
e.emit_struct("base", 0, |e| {
|
|
|
|
try!(e.emit_struct_field("id", 0, |e| self.debug_id().encode(e)))
|
2014-11-17 02:39:27 +03:00
|
|
|
try!(e.emit_struct_field("stacking_relative_position",
|
|
|
|
1,
|
|
|
|
|e| self.stacking_relative_position.encode(e)))
|
|
|
|
try!(e.emit_struct_field("intrinsic_inline_sizes",
|
|
|
|
2,
|
|
|
|
|e| self.intrinsic_inline_sizes.encode(e)))
|
2014-09-08 10:33:09 +04:00
|
|
|
try!(e.emit_struct_field("position", 3, |e| self.position.encode(e)))
|
|
|
|
e.emit_struct_field("children", 4, |e| {
|
|
|
|
e.emit_seq(self.children.len(), |e| {
|
|
|
|
for (i, c) in self.children.iter().enumerate() {
|
2014-11-13 06:48:31 +03:00
|
|
|
try!(e.emit_seq_elt(i, |e| {
|
|
|
|
try!(e.emit_struct("flow", 0, |e| {
|
|
|
|
try!(e.emit_struct_field("class", 0, |e| c.class().encode(e)))
|
|
|
|
e.emit_struct_field("data", 1, |e| {
|
|
|
|
match c.class() {
|
|
|
|
BlockFlowClass => c.as_immutable_block().encode(e),
|
|
|
|
InlineFlowClass => c.as_immutable_inline().encode(e),
|
|
|
|
TableFlowClass => c.as_immutable_table().encode(e),
|
|
|
|
TableWrapperFlowClass => c.as_immutable_table_wrapper().encode(e),
|
|
|
|
TableRowGroupFlowClass => c.as_immutable_table_rowgroup().encode(e),
|
|
|
|
TableRowFlowClass => c.as_immutable_table_row().encode(e),
|
|
|
|
TableCellFlowClass => c.as_immutable_table_cell().encode(e),
|
|
|
|
_ => { Ok(()) } // TODO: Support captions
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}))
|
|
|
|
Ok(())
|
|
|
|
}))
|
2014-09-08 10:33:09 +04:00
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-28 02:52:39 +04:00
|
|
|
#[unsafe_destructor]
|
2014-01-24 22:41:25 +04:00
|
|
|
impl Drop for BaseFlow {
|
|
|
|
fn drop(&mut self) {
|
2014-06-04 09:25:28 +04:00
|
|
|
if self.ref_count.load(SeqCst) != 0 {
|
2014-11-13 06:48:31 +03:00
|
|
|
panic!("Flow destroyed before its ref count hit zero—this is unsafe!")
|
2014-01-24 22:41:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-14 02:43:05 +04:00
|
|
|
impl BaseFlow {
|
2013-11-18 23:54:00 +04:00
|
|
|
#[inline]
|
2014-10-29 05:42:38 +03:00
|
|
|
pub fn new(node: Option<ThreadSafeLayoutNode>, writing_mode: WritingMode) -> BaseFlow {
|
2014-11-18 21:42:32 +03:00
|
|
|
let mut flags = FlowFlags::empty();
|
2014-10-29 05:42:38 +03:00
|
|
|
match node {
|
|
|
|
None => {}
|
|
|
|
Some(node) => {
|
|
|
|
let node_style = node.style();
|
|
|
|
match node_style.get_box().position {
|
|
|
|
position::absolute | position::fixed => {
|
2014-11-18 21:42:32 +03:00
|
|
|
flags.insert(IS_ABSOLUTELY_POSITIONED)
|
2014-10-29 05:42:38 +03:00
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
match node_style.get_box().float {
|
|
|
|
float::none => {}
|
2014-11-18 21:42:32 +03:00
|
|
|
float::left => flags.insert(FLOATS_LEFT),
|
|
|
|
float::right => flags.insert(FLOATS_RIGHT),
|
2014-10-29 05:42:38 +03:00
|
|
|
}
|
|
|
|
match node_style.get_box().clear {
|
|
|
|
clear::none => {}
|
2014-11-18 21:42:32 +03:00
|
|
|
clear::left => flags.insert(CLEARS_LEFT),
|
|
|
|
clear::right => flags.insert(CLEARS_RIGHT),
|
2014-10-29 05:42:38 +03:00
|
|
|
clear::both => {
|
2014-11-18 21:42:32 +03:00
|
|
|
flags.insert(CLEARS_LEFT);
|
|
|
|
flags.insert(CLEARS_RIGHT);
|
2014-10-29 05:42:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-31 23:39:34 +03:00
|
|
|
// New flows start out as fully damaged.
|
|
|
|
let mut damage = RestyleDamage::all();
|
2014-11-13 06:48:31 +03:00
|
|
|
damage.remove(RECONSTRUCT_FLOW);
|
2014-10-31 23:39:34 +03:00
|
|
|
|
2014-01-14 02:43:05 +04:00
|
|
|
BaseFlow {
|
2014-06-04 09:25:28 +04:00
|
|
|
ref_count: AtomicUint::new(1),
|
2014-10-31 23:39:34 +03:00
|
|
|
restyle_damage: damage,
|
2014-02-06 07:19:43 +04:00
|
|
|
children: FlowList::new(),
|
2014-07-19 00:27:23 +04:00
|
|
|
intrinsic_inline_sizes: IntrinsicISizes::new(),
|
|
|
|
position: LogicalRect::zero(writing_mode),
|
|
|
|
overflow: LogicalRect::zero(writing_mode),
|
2014-01-23 04:04:08 +04:00
|
|
|
parallel: FlowParallelInfo::new(),
|
2014-07-19 00:27:23 +04:00
|
|
|
floats: Floats::new(writing_mode),
|
2014-04-04 05:01:48 +04:00
|
|
|
collapsible_margins: CollapsibleMargins::new(),
|
2014-11-17 02:39:27 +03:00
|
|
|
stacking_relative_position: Zero::zero(),
|
2014-03-03 22:37:33 +04:00
|
|
|
abs_descendants: Descendants::new(),
|
2014-10-14 04:03:40 +04:00
|
|
|
absolute_static_i_offset: Au(0),
|
|
|
|
fixed_static_i_offset: Au(0),
|
|
|
|
block_container_inline_size: Au(0),
|
2014-09-20 10:05:55 +04:00
|
|
|
block_container_explicit_block_size: None,
|
2014-05-02 22:58:29 +04:00
|
|
|
absolute_cb: ContainingBlockLink::new(),
|
2014-11-17 02:39:27 +03:00
|
|
|
display_list_building_result: NoDisplayListBuildingResult,
|
2014-07-19 00:27:23 +04:00
|
|
|
absolute_position_info: AbsolutePositionInfo::new(writing_mode),
|
2014-10-14 10:42:35 +04:00
|
|
|
clip_rect: Rect(Zero::zero(), Size2D(Au(0), Au(0))),
|
2014-10-29 05:42:38 +03:00
|
|
|
flags: flags,
|
2014-07-19 00:27:23 +04:00
|
|
|
writing_mode: writing_mode,
|
2013-05-03 06:37:36 +04:00
|
|
|
}
|
2012-10-10 20:39:40 +04:00
|
|
|
}
|
2013-08-20 23:03:52 +04:00
|
|
|
|
2014-02-06 07:19:43 +04:00
|
|
|
pub fn child_iter<'a>(&'a mut self) -> MutFlowListIterator<'a> {
|
2014-09-21 02:35:08 +04:00
|
|
|
self.children.iter_mut()
|
2013-08-20 23:03:52 +04:00
|
|
|
}
|
2014-06-04 09:25:28 +04:00
|
|
|
|
|
|
|
pub unsafe fn ref_count<'a>(&'a self) -> &'a AtomicUint {
|
|
|
|
&self.ref_count
|
|
|
|
}
|
2014-09-08 10:33:09 +04:00
|
|
|
|
2014-10-17 22:15:23 +04:00
|
|
|
pub fn debug_id(&self) -> uint {
|
|
|
|
let p = self as *const _;
|
|
|
|
p as uint
|
2014-09-08 10:33:09 +04:00
|
|
|
}
|
2014-10-22 20:54:35 +04:00
|
|
|
|
2014-11-17 02:39:27 +03:00
|
|
|
/// Ensures that all display list items generated by this flow are within the flow's overflow
|
|
|
|
/// rect. This should only be used for debugging.
|
2014-10-22 20:54:35 +04:00
|
|
|
pub fn validate_display_list_geometry(&self) {
|
|
|
|
let position_with_overflow = self.position.union(&self.overflow);
|
2014-11-17 02:39:27 +03:00
|
|
|
let bounds = Rect(self.stacking_relative_position,
|
2014-10-22 20:54:35 +04:00
|
|
|
Size2D(position_with_overflow.size.inline,
|
|
|
|
position_with_overflow.size.block));
|
|
|
|
|
2014-11-17 02:39:27 +03:00
|
|
|
let all_items = match self.display_list_building_result {
|
|
|
|
NoDisplayListBuildingResult => Vec::new(),
|
|
|
|
StackingContextResult(ref stacking_context) => {
|
|
|
|
stacking_context.display_list.all_display_items()
|
|
|
|
}
|
|
|
|
DisplayListResult(ref display_list) => display_list.all_display_items(),
|
|
|
|
};
|
|
|
|
|
|
|
|
for item in all_items.iter() {
|
2014-10-22 20:54:35 +04:00
|
|
|
let paint_bounds = match item.base().bounds.intersection(&item.base().clip_rect) {
|
|
|
|
None => continue,
|
|
|
|
Some(rect) => rect,
|
|
|
|
};
|
|
|
|
|
|
|
|
if paint_bounds.is_empty() {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if bounds.union(&paint_bounds) != bounds {
|
|
|
|
error!("DisplayList item {} outside of Flow overflow ({})", item, paint_bounds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-03 22:03:37 +03:00
|
|
|
|
2014-11-17 02:39:27 +03:00
|
|
|
/// Returns the position of the given fragment relative to the start of the nearest ancestor
|
|
|
|
/// stacking context. The fragment must be a child fragment of this flow.
|
|
|
|
pub fn stacking_relative_position_of_child_fragment(&self, fragment: &Fragment)
|
|
|
|
-> Point2D<Au> {
|
2014-11-03 22:03:37 +03:00
|
|
|
let relative_offset =
|
|
|
|
fragment.relative_position(&self
|
|
|
|
.absolute_position_info
|
|
|
|
.relative_containing_block_size);
|
2014-11-17 02:39:27 +03:00
|
|
|
self.stacking_relative_position.add_size(&relative_offset.to_physical(self.writing_mode))
|
2014-11-03 22:03:37 +03:00
|
|
|
}
|
2012-10-10 20:39:40 +04:00
|
|
|
}
|
|
|
|
|
2014-09-21 02:35:08 +04:00
|
|
|
impl<'a> ImmutableFlowUtils for &'a Flow + 'a {
|
2014-09-25 20:36:33 +04:00
|
|
|
/// Returns true if this flow is a block flow.
|
2013-10-29 00:31:44 +04:00
|
|
|
fn is_block_like(self) -> bool {
|
|
|
|
match self.class() {
|
2013-12-04 03:31:15 +04:00
|
|
|
BlockFlowClass => true,
|
servo: Merge #1973 - Support fixed-layout table and a part of anonymous table object (from june0cho:table_rebase); r=larsbergstrom,metajack
This is a rebase of #1548 on recent master.
There have been many changes since #1548 is first uploaded, so I'm creating new PR.
This PR includes:
- construction of table-* flows (table-wrapper, table-caption, table, table-rowgroup, table-row, table-cell)
- fixed-layout table calculation
- a part of anonymous table object implementation
[CSS 2.1, 17.2.1](http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes) (Step 1-1, 1-2, Step 2)
Source-Repo: https://github.com/servo/servo
Source-Revision: fd5e5cd18b41f0ce2b33fb97fb4e3d75ddbbbceb
2014-03-25 21:40:47 +04:00
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns true if this flow is a proper table child.
|
|
|
|
/// 'Proper table child' is defined as table-row flow, table-rowgroup flow,
|
|
|
|
/// table-column-group flow, or table-caption flow.
|
|
|
|
fn is_proper_table_child(self) -> bool {
|
|
|
|
match self.class() {
|
|
|
|
TableRowFlowClass | TableRowGroupFlowClass |
|
|
|
|
TableColGroupFlowClass | TableCaptionFlowClass => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns true if this flow is a table row flow.
|
|
|
|
fn is_table_row(self) -> bool {
|
|
|
|
match self.class() {
|
|
|
|
TableRowFlowClass => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns true if this flow is a table cell flow.
|
|
|
|
fn is_table_cell(self) -> bool {
|
|
|
|
match self.class() {
|
|
|
|
TableCellFlowClass => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns true if this flow is a table colgroup flow.
|
|
|
|
fn is_table_colgroup(self) -> bool {
|
|
|
|
match self.class() {
|
|
|
|
TableColGroupFlowClass => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns true if this flow is a table flow.
|
|
|
|
fn is_table(self) -> bool {
|
|
|
|
match self.class() {
|
|
|
|
TableFlowClass => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns true if this flow is a table caption flow.
|
|
|
|
fn is_table_caption(self) -> bool {
|
|
|
|
match self.class() {
|
|
|
|
TableCaptionFlowClass => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns true if this flow is a table rowgroup flow.
|
|
|
|
fn is_table_rowgroup(self) -> bool {
|
|
|
|
match self.class() {
|
|
|
|
TableRowGroupFlowClass => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns true if this flow is one of table-related flows.
|
|
|
|
fn is_table_kind(self) -> bool {
|
|
|
|
match self.class() {
|
|
|
|
TableWrapperFlowClass | TableFlowClass |
|
|
|
|
TableColGroupFlowClass | TableRowGroupFlowClass |
|
|
|
|
TableRowFlowClass | TableCaptionFlowClass | TableCellFlowClass => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns true if anonymous flow is needed between this flow and child flow.
|
|
|
|
/// Spec: http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes
|
|
|
|
fn need_anonymous_flow(self, child: &Flow) -> bool {
|
|
|
|
match self.class() {
|
|
|
|
TableFlowClass => !child.is_proper_table_child(),
|
|
|
|
TableRowGroupFlowClass => !child.is_table_row(),
|
|
|
|
TableRowFlowClass => !child.is_table_cell(),
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Generates missing child flow of this flow.
|
2014-06-04 09:25:28 +04:00
|
|
|
fn generate_missing_child_flow(self, node: &ThreadSafeLayoutNode) -> FlowRef {
|
|
|
|
let flow = match self.class() {
|
servo: Merge #1973 - Support fixed-layout table and a part of anonymous table object (from june0cho:table_rebase); r=larsbergstrom,metajack
This is a rebase of #1548 on recent master.
There have been many changes since #1548 is first uploaded, so I'm creating new PR.
This PR includes:
- construction of table-* flows (table-wrapper, table-caption, table, table-rowgroup, table-row, table-cell)
- fixed-layout table calculation
- a part of anonymous table object implementation
[CSS 2.1, 17.2.1](http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes) (Step 1-1, 1-2, Step 2)
Source-Repo: https://github.com/servo/servo
Source-Revision: fd5e5cd18b41f0ce2b33fb97fb4e3d75ddbbbceb
2014-03-25 21:40:47 +04:00
|
|
|
TableFlowClass | TableRowGroupFlowClass => {
|
2014-05-29 04:34:06 +04:00
|
|
|
let fragment = Fragment::new_anonymous_table_fragment(node, TableRowFragment);
|
2014-06-04 09:25:28 +04:00
|
|
|
box TableRowFlow::from_node_and_fragment(node, fragment) as Box<Flow>
|
servo: Merge #1973 - Support fixed-layout table and a part of anonymous table object (from june0cho:table_rebase); r=larsbergstrom,metajack
This is a rebase of #1548 on recent master.
There have been many changes since #1548 is first uploaded, so I'm creating new PR.
This PR includes:
- construction of table-* flows (table-wrapper, table-caption, table, table-rowgroup, table-row, table-cell)
- fixed-layout table calculation
- a part of anonymous table object implementation
[CSS 2.1, 17.2.1](http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes) (Step 1-1, 1-2, Step 2)
Source-Repo: https://github.com/servo/servo
Source-Revision: fd5e5cd18b41f0ce2b33fb97fb4e3d75ddbbbceb
2014-03-25 21:40:47 +04:00
|
|
|
},
|
|
|
|
TableRowFlowClass => {
|
2014-05-29 04:34:06 +04:00
|
|
|
let fragment = Fragment::new_anonymous_table_fragment(node, TableCellFragment);
|
2014-06-04 09:25:28 +04:00
|
|
|
box TableCellFlow::from_node_and_fragment(node, fragment) as Box<Flow>
|
servo: Merge #1973 - Support fixed-layout table and a part of anonymous table object (from june0cho:table_rebase); r=larsbergstrom,metajack
This is a rebase of #1548 on recent master.
There have been many changes since #1548 is first uploaded, so I'm creating new PR.
This PR includes:
- construction of table-* flows (table-wrapper, table-caption, table, table-rowgroup, table-row, table-cell)
- fixed-layout table calculation
- a part of anonymous table object implementation
[CSS 2.1, 17.2.1](http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes) (Step 1-1, 1-2, Step 2)
Source-Repo: https://github.com/servo/servo
Source-Revision: fd5e5cd18b41f0ce2b33fb97fb4e3d75ddbbbceb
2014-03-25 21:40:47 +04:00
|
|
|
},
|
|
|
|
_ => {
|
2014-11-13 06:48:31 +03:00
|
|
|
panic!("no need to generate a missing child")
|
servo: Merge #1973 - Support fixed-layout table and a part of anonymous table object (from june0cho:table_rebase); r=larsbergstrom,metajack
This is a rebase of #1548 on recent master.
There have been many changes since #1548 is first uploaded, so I'm creating new PR.
This PR includes:
- construction of table-* flows (table-wrapper, table-caption, table, table-rowgroup, table-row, table-cell)
- fixed-layout table calculation
- a part of anonymous table object implementation
[CSS 2.1, 17.2.1](http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes) (Step 1-1, 1-2, Step 2)
Source-Repo: https://github.com/servo/servo
Source-Revision: fd5e5cd18b41f0ce2b33fb97fb4e3d75ddbbbceb
2014-03-25 21:40:47 +04:00
|
|
|
}
|
2014-06-04 09:25:28 +04:00
|
|
|
};
|
|
|
|
FlowRef::new(flow)
|
2013-08-09 20:42:36 +04:00
|
|
|
}
|
|
|
|
|
2013-10-29 00:31:44 +04:00
|
|
|
/// Returns true if this flow has no children.
|
|
|
|
fn is_leaf(self) -> bool {
|
|
|
|
base(self).children.len() == 0
|
2012-09-27 05:17:44 +04:00
|
|
|
}
|
|
|
|
|
2014-01-23 04:04:08 +04:00
|
|
|
/// Returns the number of children that this flow possesses.
|
|
|
|
fn child_count(self) -> uint {
|
|
|
|
base(self).children.len()
|
|
|
|
}
|
|
|
|
|
2014-02-05 02:52:39 +04:00
|
|
|
/// Return true if this flow is a Block Container.
|
|
|
|
///
|
2014-05-29 04:34:06 +04:00
|
|
|
/// Except for table fragments and replaced elements, block-level fragments (`BlockFlow`) are
|
|
|
|
/// also block container fragments.
|
2014-02-05 02:52:39 +04:00
|
|
|
/// Non-replaced inline blocks and non-replaced table cells are also block
|
|
|
|
/// containers.
|
|
|
|
fn is_block_container(self) -> bool {
|
|
|
|
match self.class() {
|
|
|
|
// TODO: Change this when inline-blocks are supported.
|
servo: Merge #1973 - Support fixed-layout table and a part of anonymous table object (from june0cho:table_rebase); r=larsbergstrom,metajack
This is a rebase of #1548 on recent master.
There have been many changes since #1548 is first uploaded, so I'm creating new PR.
This PR includes:
- construction of table-* flows (table-wrapper, table-caption, table, table-rowgroup, table-row, table-cell)
- fixed-layout table calculation
- a part of anonymous table object implementation
[CSS 2.1, 17.2.1](http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes) (Step 1-1, 1-2, Step 2)
Source-Repo: https://github.com/servo/servo
Source-Revision: fd5e5cd18b41f0ce2b33fb97fb4e3d75ddbbbceb
2014-03-25 21:40:47 +04:00
|
|
|
BlockFlowClass | TableCaptionFlowClass | TableCellFlowClass => {
|
2014-02-05 02:52:39 +04:00
|
|
|
// FIXME: Actually check the type of the node
|
|
|
|
self.child_count() != 0
|
|
|
|
}
|
servo: Merge #1973 - Support fixed-layout table and a part of anonymous table object (from june0cho:table_rebase); r=larsbergstrom,metajack
This is a rebase of #1548 on recent master.
There have been many changes since #1548 is first uploaded, so I'm creating new PR.
This PR includes:
- construction of table-* flows (table-wrapper, table-caption, table, table-rowgroup, table-row, table-cell)
- fixed-layout table calculation
- a part of anonymous table object implementation
[CSS 2.1, 17.2.1](http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes) (Step 1-1, 1-2, Step 2)
Source-Repo: https://github.com/servo/servo
Source-Revision: fd5e5cd18b41f0ce2b33fb97fb4e3d75ddbbbceb
2014-03-25 21:40:47 +04:00
|
|
|
_ => false,
|
2014-02-05 02:52:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-19 01:17:07 +04:00
|
|
|
/// Returns true if this flow is a block flow.
|
|
|
|
fn is_block_flow(self) -> bool {
|
2013-10-29 00:31:44 +04:00
|
|
|
match self.class() {
|
2014-01-14 02:43:05 +04:00
|
|
|
BlockFlowClass => true,
|
servo: Merge #1973 - Support fixed-layout table and a part of anonymous table object (from june0cho:table_rebase); r=larsbergstrom,metajack
This is a rebase of #1548 on recent master.
There have been many changes since #1548 is first uploaded, so I'm creating new PR.
This PR includes:
- construction of table-* flows (table-wrapper, table-caption, table, table-rowgroup, table-row, table-cell)
- fixed-layout table calculation
- a part of anonymous table object implementation
[CSS 2.1, 17.2.1](http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes) (Step 1-1, 1-2, Step 2)
Source-Repo: https://github.com/servo/servo
Source-Revision: fd5e5cd18b41f0ce2b33fb97fb4e3d75ddbbbceb
2014-03-25 21:40:47 +04:00
|
|
|
_ => false,
|
2013-08-20 23:03:52 +04:00
|
|
|
}
|
|
|
|
}
|
2013-08-02 02:42:26 +04:00
|
|
|
|
2014-02-19 01:17:07 +04:00
|
|
|
/// Returns true if this flow is an inline flow.
|
|
|
|
fn is_inline_flow(self) -> bool {
|
2013-10-29 00:31:44 +04:00
|
|
|
match self.class() {
|
|
|
|
InlineFlowClass => true,
|
servo: Merge #1973 - Support fixed-layout table and a part of anonymous table object (from june0cho:table_rebase); r=larsbergstrom,metajack
This is a rebase of #1548 on recent master.
There have been many changes since #1548 is first uploaded, so I'm creating new PR.
This PR includes:
- construction of table-* flows (table-wrapper, table-caption, table, table-rowgroup, table-row, table-cell)
- fixed-layout table calculation
- a part of anonymous table object implementation
[CSS 2.1, 17.2.1](http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes) (Step 1-1, 1-2, Step 2)
Source-Repo: https://github.com/servo/servo
Source-Revision: fd5e5cd18b41f0ce2b33fb97fb4e3d75ddbbbceb
2014-03-25 21:40:47 +04:00
|
|
|
_ => false,
|
2013-05-03 06:37:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-29 00:31:44 +04:00
|
|
|
/// Dumps the flow tree for debugging.
|
|
|
|
fn dump(self) {
|
2013-11-11 11:07:23 +04:00
|
|
|
self.dump_with_level(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Dumps the flow tree for debugging, with a prefix to indicate that we're at the given level.
|
|
|
|
fn dump_with_level(self, level: uint) {
|
2014-06-05 21:58:44 +04:00
|
|
|
let mut indent = String::new();
|
2013-11-11 11:07:23 +04:00
|
|
|
for _ in range(0, level) {
|
|
|
|
indent.push_str("| ")
|
|
|
|
}
|
2014-10-17 22:15:23 +04:00
|
|
|
|
2014-10-21 21:27:40 +04:00
|
|
|
println!("{}+ {}", indent, self.to_string());
|
2014-10-17 22:15:23 +04:00
|
|
|
|
2013-11-11 11:07:23 +04:00
|
|
|
for kid in imm_child_iter(self) {
|
|
|
|
kid.dump_with_level(level + 1)
|
|
|
|
}
|
2012-09-27 05:17:44 +04:00
|
|
|
}
|
2013-10-29 00:31:44 +04:00
|
|
|
}
|
2012-09-27 05:17:44 +04:00
|
|
|
|
2014-09-21 02:35:08 +04:00
|
|
|
impl<'a> MutableFlowUtils for &'a mut Flow + 'a {
|
2013-10-29 00:31:44 +04:00
|
|
|
/// Traverses the tree in preorder.
|
2014-10-15 05:33:28 +04:00
|
|
|
fn traverse_preorder<T:PreorderFlowTraversal>(self, traversal: &T) {
|
|
|
|
if traversal.should_process(self) {
|
|
|
|
traversal.process(self);
|
2012-09-27 05:17:44 +04:00
|
|
|
}
|
2012-09-22 03:23:30 +04:00
|
|
|
|
2013-10-29 00:31:44 +04:00
|
|
|
for kid in child_iter(self) {
|
2014-10-15 05:33:28 +04:00
|
|
|
kid.traverse_preorder(traversal);
|
2012-09-22 03:23:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-29 00:31:44 +04:00
|
|
|
/// Traverses the tree in postorder.
|
2014-10-15 05:33:28 +04:00
|
|
|
fn traverse_postorder<T:PostorderFlowTraversal>(self, traversal: &T) {
|
2013-10-29 00:31:44 +04:00
|
|
|
for kid in child_iter(self) {
|
2014-10-15 05:33:28 +04:00
|
|
|
kid.traverse_postorder(traversal);
|
2012-09-22 03:23:30 +04:00
|
|
|
}
|
2013-07-16 05:03:27 +04:00
|
|
|
|
2014-10-15 05:33:28 +04:00
|
|
|
if traversal.should_process(self) {
|
|
|
|
traversal.process(self)
|
2013-08-09 20:42:36 +04:00
|
|
|
}
|
2012-09-26 03:07:38 +04:00
|
|
|
}
|
|
|
|
|
2014-03-03 22:37:33 +04:00
|
|
|
/// Calculate and set overflow for current flow.
|
|
|
|
///
|
|
|
|
/// CSS Section 11.1
|
|
|
|
/// This is the union of rectangles of the flows for which we define the
|
|
|
|
/// Containing Block.
|
|
|
|
///
|
|
|
|
/// Assumption: This is called in a bottom-up traversal, so kids' overflows have
|
|
|
|
/// already been set.
|
|
|
|
/// Assumption: Absolute descendants have had their overflow calculated.
|
2014-08-11 16:20:07 +04:00
|
|
|
fn store_overflow(self, _: &LayoutContext) {
|
2013-10-31 23:10:32 +04:00
|
|
|
let my_position = mut_base(self).position;
|
|
|
|
let mut overflow = my_position;
|
2014-03-03 22:37:33 +04:00
|
|
|
|
|
|
|
if self.is_block_container() {
|
|
|
|
for kid in child_iter(self) {
|
|
|
|
if kid.is_store_overflow_delayed() {
|
|
|
|
// Absolute flows will be handled by their CB. If we are
|
|
|
|
// their CB, they will show up in `abs_descendants`.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
let mut kid_overflow = base(kid).overflow;
|
2014-07-19 00:27:23 +04:00
|
|
|
kid_overflow = kid_overflow.translate(&my_position.start);
|
2014-03-03 22:37:33 +04:00
|
|
|
overflow = overflow.union(&kid_overflow)
|
|
|
|
}
|
|
|
|
|
2014-04-04 05:01:48 +04:00
|
|
|
// FIXME(#2004, pcwalton): This is wrong for `position: fixed`.
|
2014-03-03 22:37:33 +04:00
|
|
|
for descendant_link in mut_base(self).abs_descendants.iter() {
|
2014-06-04 09:25:28 +04:00
|
|
|
let mut kid_overflow = base(descendant_link).overflow;
|
2014-07-19 00:27:23 +04:00
|
|
|
kid_overflow = kid_overflow.translate(&my_position.start);
|
2014-06-04 09:25:28 +04:00
|
|
|
overflow = overflow.union(&kid_overflow)
|
2014-03-03 22:37:33 +04:00
|
|
|
}
|
2013-10-31 23:10:32 +04:00
|
|
|
}
|
2014-03-03 22:37:33 +04:00
|
|
|
mut_base(self).overflow = overflow;
|
2013-10-31 23:10:32 +04:00
|
|
|
}
|
|
|
|
|
2014-10-02 05:36:25 +04:00
|
|
|
/// Collect and update static y-offsets bubbled up by kids.
|
|
|
|
///
|
|
|
|
/// This would essentially give us offsets of all absolutely positioned
|
|
|
|
/// direct descendants and all fixed descendants, in tree order.
|
|
|
|
///
|
|
|
|
/// Assume that this is called in a bottom-up traversal (specifically, the
|
|
|
|
/// assign-block-size traversal). So, kids have their flow origin already set.
|
|
|
|
/// In the case of absolute flow kids, they have their hypothetical box
|
|
|
|
/// position already set.
|
2014-10-15 02:51:30 +04:00
|
|
|
fn collect_static_block_offsets_from_children(self) {
|
2014-10-02 05:36:25 +04:00
|
|
|
let mut absolute_descendant_block_offsets = Vec::new();
|
2014-10-15 02:51:30 +04:00
|
|
|
for kid in mut_base(self).child_iter() {
|
2014-10-02 05:36:25 +04:00
|
|
|
let mut gives_absolute_offsets = true;
|
|
|
|
if kid.is_block_like() {
|
|
|
|
let kid_block = kid.as_block();
|
2014-11-18 21:42:32 +03:00
|
|
|
if kid_block.is_fixed() || kid_block.base.flags.contains(IS_ABSOLUTELY_POSITIONED) {
|
2014-10-02 05:36:25 +04:00
|
|
|
// It won't contribute any offsets for descendants because it would be the
|
|
|
|
// containing block for them.
|
|
|
|
gives_absolute_offsets = false;
|
|
|
|
// Give the offset for the current absolute flow alone.
|
|
|
|
absolute_descendant_block_offsets.push(
|
|
|
|
kid_block.get_hypothetical_block_start_edge());
|
|
|
|
} else if kid_block.is_positioned() {
|
|
|
|
// It won't contribute any offsets because it would be the containing block
|
|
|
|
// for the descendants.
|
|
|
|
gives_absolute_offsets = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if gives_absolute_offsets {
|
|
|
|
let kid_base = mut_base(kid);
|
|
|
|
// Avoid copying the offset vector.
|
|
|
|
let offsets = mem::replace(&mut kid_base.abs_descendants.static_block_offsets,
|
|
|
|
Vec::new());
|
|
|
|
// Consume all the static block-offsets bubbled up by kids.
|
|
|
|
for block_offset in offsets.into_iter() {
|
|
|
|
// The offsets are with respect to the kid flow's fragment. Translate them to
|
|
|
|
// that of the current flow.
|
|
|
|
absolute_descendant_block_offsets.push(
|
|
|
|
block_offset + kid_base.position.start.b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-10-15 02:51:30 +04:00
|
|
|
mut_base(self).abs_descendants.static_block_offsets = absolute_descendant_block_offsets
|
|
|
|
}
|
2012-09-22 03:23:30 +04:00
|
|
|
}
|
2013-05-03 06:37:36 +04:00
|
|
|
|
2014-06-04 09:25:28 +04:00
|
|
|
impl MutableOwnedFlowUtils for FlowRef {
|
2014-03-03 22:37:33 +04:00
|
|
|
/// Set absolute descendants for this flow.
|
|
|
|
///
|
|
|
|
/// Set yourself as the Containing Block for all the absolute descendants.
|
|
|
|
///
|
2014-06-04 09:25:28 +04:00
|
|
|
/// This is called during flow construction, so nothing else can be accessing the descendant
|
|
|
|
/// flows. This is enforced by the fact that we have a mutable `FlowRef`, which only flow
|
|
|
|
/// construction is allowed to possess.
|
2014-09-19 18:51:02 +04:00
|
|
|
fn set_absolute_descendants(&mut self, abs_descendants: AbsDescendants) {
|
2014-06-04 09:25:28 +04:00
|
|
|
let this = self.clone();
|
|
|
|
|
2014-10-16 02:18:23 +04:00
|
|
|
let block = self.as_block();
|
2014-03-03 22:37:33 +04:00
|
|
|
block.base.abs_descendants = abs_descendants;
|
|
|
|
|
|
|
|
for descendant_link in block.base.abs_descendants.iter() {
|
2014-06-04 09:25:28 +04:00
|
|
|
let base = mut_base(descendant_link);
|
|
|
|
base.absolute_cb.set(this.clone());
|
2014-03-03 22:37:33 +04:00
|
|
|
}
|
|
|
|
}
|
2014-01-23 04:04:08 +04:00
|
|
|
}
|
2014-05-02 22:58:29 +04:00
|
|
|
|
|
|
|
/// A link to a flow's containing block.
|
|
|
|
///
|
|
|
|
/// This cannot safely be a `Flow` pointer because this is a pointer *up* the tree, not *down* the
|
|
|
|
/// tree. A pointer up the tree is unsafe during layout because it can be used to access a node
|
|
|
|
/// with an immutable reference while that same node is being laid out, causing possible iterator
|
|
|
|
/// invalidation and use-after-free.
|
2014-06-04 09:25:28 +04:00
|
|
|
///
|
|
|
|
/// FIXME(pcwalton): I think this would be better with a borrow flag instead of `unsafe`.
|
2014-05-02 22:58:29 +04:00
|
|
|
pub struct ContainingBlockLink {
|
2014-06-04 09:25:28 +04:00
|
|
|
/// The pointer up to the containing block.
|
|
|
|
link: Option<FlowRef>,
|
2014-05-02 22:58:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ContainingBlockLink {
|
|
|
|
fn new() -> ContainingBlockLink {
|
|
|
|
ContainingBlockLink {
|
2014-06-04 09:25:28 +04:00
|
|
|
link: None,
|
2014-05-02 22:58:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-04 09:25:28 +04:00
|
|
|
fn set(&mut self, link: FlowRef) {
|
|
|
|
self.link = Some(link)
|
2014-05-02 22:58:29 +04:00
|
|
|
}
|
|
|
|
|
2014-06-04 09:25:28 +04:00
|
|
|
pub unsafe fn get<'a>(&'a mut self) -> &'a mut Option<FlowRef> {
|
|
|
|
&mut self.link
|
2014-05-03 03:10:20 +04:00
|
|
|
}
|
|
|
|
|
2014-05-02 22:58:29 +04:00
|
|
|
#[inline]
|
2014-07-19 00:27:23 +04:00
|
|
|
pub fn generated_containing_block_rect(&mut self) -> LogicalRect<Au> {
|
2014-06-04 09:25:28 +04:00
|
|
|
match self.link {
|
2014-11-13 06:48:31 +03:00
|
|
|
None => panic!("haven't done it"),
|
2014-10-16 02:18:23 +04:00
|
|
|
Some(ref mut link) => link.generated_containing_block_rect(),
|
2014-06-04 09:25:28 +04:00
|
|
|
}
|
2014-05-02 22:58:29 +04:00
|
|
|
}
|
|
|
|
}
|