Class BoxBuilder


  • public class BoxBuilder
    extends java.lang.Object
    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.
    • Constructor Detail

      • BoxBuilder

        public BoxBuilder()
    • Method Detail

      • splitParagraphs

        private static void splitParagraphs​(LayoutContext c,
                                            org.w3c.dom.Document document)
        Split the document into paragraphs for use in analyzing bi-directional text runs.
        Parameters:
        c -
        document -
      • createRootBox

        public static BlockBox createRootBox​(LayoutContext c,
                                             org.w3c.dom.Document document)
      • isInsertedBoxIgnored

        private static boolean isInsertedBoxIgnored​(org.w3c.dom.Element element)
      • isAllProperTableNesting

        private static boolean isAllProperTableNesting​(IdentValue parentDisplay,
                                                       java.util.List<Styleable> children)
      • resolveChildTableContent

        private static void resolveChildTableContent​(LayoutContext c,
                                                     BlockBox parent,
                                                     java.util.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. 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. consecutive td elements will be wrapped in an anonymous tr, then a tbody, and finally a table).
      • matchesTableLevel

        private static boolean matchesTableLevel​(IdentValue target,
                                                 IdentValue value)
      • rebalanceInlineContent

        private static void rebalanceInlineContent​(java.util.List<Styleable> content)
        Makes sure that any InlineBox in content both starts and ends within content. 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

        private static void stripAllWhitespace​(java.util.List<Styleable> content)
      • resolveTableContent

        private static void resolveTableContent​(LayoutContext c,
                                                BlockBox parent,
                                                java.util.List<Styleable> children,
                                                BoxBuilder.ChildBoxInfo info)
        Handles the situation when our current parent is table related. If everything is properly nested (e.g. a tr contains only td elements), nothing is done. Otherwise anonymous boxes are inserted to ensure the integrity of the table model.
      • isTableRowOrRowGroup

        private static boolean isTableRowOrRowGroup​(Styleable child)
      • containsOrphanedTableContent

        private static boolean containsOrphanedTableContent​(java.util.List<Styleable> children)
      • isParentInline

        private static boolean isParentInline​(BlockBox box)
      • reorderTableContent

        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. 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.
      • getNextTableNestingLevel

        private static IdentValue getNextTableNestingLevel​(IdentValue display)
      • getPreviousTableNestingLevel

        private static IdentValue getPreviousTableNestingLevel​(IdentValue display)
      • isProperTableNesting

        private static boolean isProperTableNesting​(IdentValue parent,
                                                    IdentValue child)
      • isNestingTableContent

        private static boolean isNestingTableContent​(IdentValue display)
      • isAttrFunction

        private static boolean isAttrFunction​(FSFunction function)
      • isElementFunction

        public static boolean isElementFunction​(FSFunction function)
      • getAttributeValue

        private static java.lang.String getAttributeValue​(FSFunction attrFunc,
                                                          org.w3c.dom.Element e)
      • createFootnoteTarget

        private static org.w3c.dom.Element createFootnoteTarget​(LayoutContext c,
                                                                org.w3c.dom.Element parent)
        Creates an element with id for the footnote-marker pseudo element so we can link to it from the footnote-call pseduo element.

        See createFootnoteCallAnchor(LayoutContext, Element)
      • createFootnoteCallAnchor

        private static org.w3c.dom.Element createFootnoteCallAnchor​(LayoutContext c,
                                                                    org.w3c.dom.Element parent)
        Used to create the anchor element to link to the footnote body for the footnote-call pseudo element.

        See createFootnoteTarget(LayoutContext, Element)
      • createGeneratedContent

        private static java.util.List<Styleable> createGeneratedContent​(LayoutContext c,
                                                                        org.w3c.dom.Element element,
                                                                        java.lang.String peName,
                                                                        CalculatedStyle style,
                                                                        PropertyValue property,
                                                                        BoxBuilder.ChildBoxInfo info)
        Creates generated content boxes for pseudo elements such as ::before.
        Parameters:
        element - The containing element where the pseudo element appears. For span::before the element would be a span.
        peName - Examples include before, after, footnote-call and footnote-marker.
        style - The child style for this pseudo element. For span::before this would include all the styles set explicitly on ::before as well as those that inherit from span following the cascade rules.
        property - The values of the content CSS property.
        info - In/out param. Whether the resultant box(es) contain block level content.
        Returns:
        The generated box(es). Typically one BlockBox or multiple inline boxes.
      • createInlineBox

        private static InlineBox createInlineBox​(java.lang.String text,
                                                 org.w3c.dom.Element parent,
                                                 CalculatedStyle parentStyle,
                                                 org.w3c.dom.Text node)
      • logInvalidFootnoteStyle

        private static void logInvalidFootnoteStyle​(LayoutContext c,
                                                    org.w3c.dom.Element element,
                                                    CalculatedStyle style)
      • isValidFootnotePseudo

        private static boolean isValidFootnotePseudo​(CalculatedStyle style)
      • logInvalidFootnotePseudo

        private static void logInvalidFootnotePseudo​(java.lang.String peName,
                                                     CalculatedStyle style)
      • isGeneratedElement

        private static boolean isGeneratedElement​(org.w3c.dom.Element element)
        Don't output elements that have been artificially created to support footnotes and content property images.
      • createFootnoteBody

        private static BlockBox createFootnoteBody​(LayoutContext c,
                                                   org.w3c.dom.Element element,
                                                   CalculatedStyle style)
        Creates the footnote body to put at the bottom of the page inside a page's footnote area.
      • resolveElementCounters

        private static void resolveElementCounters​(LayoutContext c,
                                                   org.w3c.dom.Node working,
                                                   org.w3c.dom.Element element,
                                                   CalculatedStyle style)
      • doBidi

        private static InlineBox doBidi​(LayoutContext c,
                                        org.w3c.dom.Text textNode,
                                        org.w3c.dom.Element parent,
                                        CalculatedStyle parentStyle,
                                        InlineBox previousIB,
                                        java.util.List<Styleable> children)
        Attempts to divide a Text node further into directional text runs, either LTR or RTL.
        Parameters:
        c -
        textNode -
        parent -
        parentStyle -
        Returns:
        the previousIB.
      • insertAnonymousBlocks

        private static void insertAnonymousBlocks​(SharedContext c,
                                                  Box parent,
                                                  java.util.List<Styleable> children,
                                                  boolean layoutRunningBlocks)
      • createAnonymousBlock

        private static void createAnonymousBlock​(SharedContext c,
                                                 Box parent,
                                                 java.util.List<Styleable> inline,
                                                 java.util.List<InlineBox> savedParents)