Package org.xhtmlrenderer.layout
Class BoxBuilder
java.lang.Object
org.xhtmlrenderer.layout.BoxBuilder
This class is responsible for creating the box tree from the DOM. This is
mostly just a one-to-one translation from the
Element
to an
InlineBox
or a BlockBox
(or some subclass of
BlockBox
), but the tree is reorganized according to the CSS rules.
This includes inserting anonymous block and inline boxes, anonymous table
content, and :before
and :after
content. White
space is also normalized at this point. Table columns and table column groups
are added to the table which owns them, but are not created as regular boxes.
Floated and absolutely positioned content is always treated as inline
content for purposes of inserting anonymous block boxes and calculating
the kind of content contained in a given block box.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
static enum
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
private static final int
private static final org.slf4j.Logger
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
addColumnOrColumnGroup
(LayoutContext c, TableBox table, Element e, CalculatedStyle style) private static void
addColumns
(LayoutContext c, TableBox table, TableColumn parent) private static boolean
containsOrphanedTableContent
(List<Styleable> children) private static void
private static void
createAnonymousTableContent
(LayoutContext c, BlockBox source, IdentValue next, List<Styleable> childrenForAnonymous, List<Styleable> childrenWithAnonymous) private static BlockBox
createBlockBox
(Element source, CalculatedStyle style, BoxBuilder.ChildBoxInfo info, boolean generated, boolean anonymous) static void
createChildren
(LayoutContext c, BlockBox parent) private static void
createChildren
(LayoutContext c, BlockBox blockParent, Element parent, List<Styleable> children, BoxBuilder.ChildBoxInfo info, boolean inline) createGeneratedContent
(LayoutContext c, Element element, String peName, CalculatedStyle style, PropertyValue property, BoxBuilder.ChildBoxInfo info) createGeneratedContentList
(LayoutContext c, Element element, PropertyValue propValue, @Nullable String peName, CalculatedStyle style, int mode, @Nullable BoxBuilder.ChildBoxInfo info) createGeneratedMarginBoxContent
(LayoutContext c, Element element, PropertyValue property, CalculatedStyle style, BoxBuilder.ChildBoxInfo info) private static InlineBox
createInlineBox
(String text, Element parent, CalculatedStyle parentStyle, @Nullable Text node) private static @Nullable TableCellBox
createMarginBox
(LayoutContext c, CascadedStyle cascadedStyle, boolean alwaysCreate) static @Nullable TableBox
createMarginTable
(LayoutContext c, PageInfo pageInfo, MarginBoxName[] names, int height, BoxBuilder.MarginDirection direction) static BlockBox
createRootBox
(LayoutContext c, Document document) private static String
getAttributeValue
(FSFunction attrFunc, Element e) private static @Nullable IdentValue
getNextTableNestingLevel
(IdentValue display) private static @Nullable IdentValue
getPreviousTableNestingLevel
(IdentValue display) static @Nullable BlockBox
getRunningBlock
(LayoutContext c, PropertyValue value) private static void
insertAnonymousBlocks
(Box parent, List<Styleable> children, boolean layoutRunningBlocks) private static void
insertGeneratedContent
(LayoutContext c, Element element, CalculatedStyle parentStyle, String peName, List<Styleable> children, BoxBuilder.ChildBoxInfo info) private static boolean
isAllProperTableNesting
(IdentValue parentDisplay, List<Styleable> children) private static boolean
isAttrFunction
(FSFunction function) static boolean
isElementFunction
(FSFunction function) private static boolean
isNestingTableContent
(IdentValue display) private static boolean
isParentInline
(BlockBox box) private static boolean
isProperTableNesting
(IdentValue parent, IdentValue child) private static BoxBuilder.ChildBoxInfo
lookForBlockContent
(List<Styleable> styleables) private static @Nullable CounterFunction
makeCounterFunction
(FSFunction function, LayoutContext c, CalculatedStyle style) private static boolean
matchesTableLevel
(IdentValue target, IdentValue value) private static @Nullable Integer
parseAttribute
(Node node, String attributeName) private static @Nullable Integer
parseStartIndex
(Node node) private static void
rebalanceInlineContent
(List<Styleable> content) Makes sure that anyInlineBox
incontent
both starts and ends withincontent
.private static BlockBox
reorderTableContent
(LayoutContext c, TableBox table) Reorganizes a table so that the header is the first row group and the footer the last.private static void
resolveChildren
(BlockBox owner, List<Styleable> children, BoxBuilder.ChildBoxInfo info) private static void
resolveChildTableContent
(LayoutContext c, BlockBox parent, List<Styleable> children, BoxBuilder.ChildBoxInfo info, IdentValue target) Handles the situation when we find table content, but our parent is not table related.private static void
resolveTableContent
(LayoutContext c, BlockBox parent, List<Styleable> children, BoxBuilder.ChildBoxInfo info) Handles the situation when our current parent is table related.private static void
stripAllWhitespace
(List<Styleable> content)
-
Field Details
-
log
private static final org.slf4j.Logger log -
CONTENT_LIST_DOCUMENT
private static final int CONTENT_LIST_DOCUMENT- See Also:
-
CONTENT_LIST_MARGIN_BOX
private static final int CONTENT_LIST_MARGIN_BOX- See Also:
-
-
Constructor Details
-
BoxBuilder
public BoxBuilder()
-
-
Method Details
-
createRootBox
-
createChildren
-
createMarginTable
public static @Nullable TableBox createMarginTable(LayoutContext c, PageInfo pageInfo, MarginBoxName[] names, int height, BoxBuilder.MarginDirection direction) -
createMarginBox
private static @Nullable TableCellBox createMarginBox(LayoutContext c, CascadedStyle cascadedStyle, boolean alwaysCreate) -
resolveChildren
private static void resolveChildren(BlockBox owner, List<Styleable> children, BoxBuilder.ChildBoxInfo info) -
isAllProperTableNesting
-
resolveChildTableContent
private static void resolveChildTableContent(LayoutContext c, BlockBox parent, List<Styleable> children, BoxBuilder.ChildBoxInfo info, IdentValue target) Handles the situation when we find table content, but our parent is not table related. For example,div
->td</td>
. Anonymous tables are then constructed by repeatedly pulling together consecutive same-table-level siblings and wrapping them in the next highest table level (e.g. consecutivetd
elements will be wrapped in an anonymoustr
, then atbody
, and finally atable
). -
matchesTableLevel
-
rebalanceInlineContent
Makes sure that anyInlineBox
incontent
both starts and ends withincontent
. Used to ensure that it is always possible to construct anonymous blocks once an element's children has been distributed among anonymous table objects. -
stripAllWhitespace
-
resolveTableContent
private static void resolveTableContent(LayoutContext c, BlockBox parent, List<Styleable> children, BoxBuilder.ChildBoxInfo info) Handles the situation when our current parent is table related. If everything is properly nested (e.g. atr
contains onlytd
elements), nothing is done. Otherwise, anonymous boxes are inserted to ensure the integrity of the table model. -
containsOrphanedTableContent
-
isParentInline
-
createAnonymousTableContent
private static void createAnonymousTableContent(LayoutContext c, BlockBox source, IdentValue next, List<Styleable> childrenForAnonymous, List<Styleable> childrenWithAnonymous) -
reorderTableContent
Reorganizes a table so that the header is the first row group and the footer the last. If the table has caption boxes, they will be pulled out and added to an anonymous block box along with the table itself. If not, the table is returned. -
lookForBlockContent
-
getNextTableNestingLevel
-
getPreviousTableNestingLevel
-
isProperTableNesting
-
isNestingTableContent
-
isAttrFunction
-
isElementFunction
-
makeCounterFunction
private static @Nullable CounterFunction makeCounterFunction(FSFunction function, LayoutContext c, CalculatedStyle style) -
getAttributeValue
-
createGeneratedContentList
@CheckReturnValue private static List<Styleable> createGeneratedContentList(LayoutContext c, Element element, PropertyValue propValue, @Nullable String peName, CalculatedStyle style, int mode, @Nullable BoxBuilder.ChildBoxInfo info) -
getRunningBlock
@CheckReturnValue public static @Nullable BlockBox getRunningBlock(LayoutContext c, PropertyValue value) -
insertGeneratedContent
private static void insertGeneratedContent(LayoutContext c, Element element, CalculatedStyle parentStyle, String peName, List<Styleable> children, BoxBuilder.ChildBoxInfo info) -
createGeneratedContent
private static List<Styleable> createGeneratedContent(LayoutContext c, Element element, String peName, CalculatedStyle style, PropertyValue property, BoxBuilder.ChildBoxInfo info) -
createGeneratedMarginBoxContent
private static List<Styleable> createGeneratedMarginBoxContent(LayoutContext c, Element element, PropertyValue property, CalculatedStyle style, BoxBuilder.ChildBoxInfo info) -
createBlockBox
private static BlockBox createBlockBox(Element source, CalculatedStyle style, BoxBuilder.ChildBoxInfo info, boolean generated, boolean anonymous) -
addColumns
-
addColumnOrColumnGroup
private static void addColumnOrColumnGroup(LayoutContext c, TableBox table, Element e, CalculatedStyle style) -
createInlineBox
private static InlineBox createInlineBox(String text, Element parent, CalculatedStyle parentStyle, @Nullable Text node) -
createChildren
private static void createChildren(LayoutContext c, BlockBox blockParent, Element parent, List<Styleable> children, BoxBuilder.ChildBoxInfo info, boolean inline) -
parseStartIndex
-
parseAttribute
-
insertAnonymousBlocks
-
createAnonymousBlock
-