Class BlockBox

java.lang.Object
com.openhtmltopdf.render.Box
com.openhtmltopdf.render.BlockBox
All Implemented Interfaces:
InlinePaintable, Styleable, DisplayListItem
Direct Known Subclasses:
AnonymousBlockBox, FlowingColumnBox, FlowingColumnContainerBox, MarginBox, TableBox, TableCellBox, TableRowBox, TableSectionBox, ViewportBox

public class BlockBox extends Box implements InlinePaintable
A block box as defined in the CSS spec. It also provides a base class for other kinds of block content (for example table rows or cells). See BlockBox.ContentType
  • Field Details

    • POSITION_VERTICALLY

      public static final int POSITION_VERTICALLY
      See Also:
    • POSITION_HORIZONTALLY

      public static final int POSITION_HORIZONTALLY
      See Also:
    • POSITION_BOTH

      public static final int POSITION_BOTH
      See Also:
    • NO_BASELINE

      protected static final int NO_BASELINE
      See Also:
    • _markerData

      private MarkerData _markerData
    • _listCounter

      private int _listCounter
    • _persistentBFC

      private PersistentBFC _persistentBFC
    • _staticEquivalent

      private Box _staticEquivalent
    • _needPageClear

      private boolean _needPageClear
    • _replacedElement

      private ReplacedElement _replacedElement
    • _childrenContentType

      private BlockBox.ContentType _childrenContentType
    • _inlineContent

      private List<Styleable> _inlineContent
    • _topMarginCalculated

      private boolean _topMarginCalculated
    • _bottomMarginCalculated

      private boolean _bottomMarginCalculated
    • _pendingCollapseCalculation

      private BlockBox.MarginCollapseResult _pendingCollapseCalculation
    • _minWidth

      private int _minWidth
    • _maxWidth

      private int _maxWidth
    • _minMaxCalculated

      private boolean _minMaxCalculated
    • _dimensionsCalculated

      private boolean _dimensionsCalculated
    • _needShrinkToFitCalculatation

      private boolean _needShrinkToFitCalculatation
    • _firstLineStyle

      private CascadedStyle _firstLineStyle
    • _firstLetterStyle

      private CascadedStyle _firstLetterStyle
    • _floatedBoxData

      private FloatedBoxData _floatedBoxData
    • _childrenHeight

      private int _childrenHeight
    • _fromCaptionedTable

      private boolean _fromCaptionedTable
    • _isReplaced

      private boolean _isReplaced
  • Constructor Details

    • BlockBox

      public BlockBox()
  • Method Details

    • setElement

      public void setElement(Element element)
      Specified by:
      setElement in interface Styleable
      Overrides:
      setElement in class Box
    • copyOf

      public BlockBox copyOf()
    • getExtraBoxDescription

      protected String getExtraBoxDescription()
    • toString

      public String toString()
      Overrides:
      toString in class Box
    • appendPositioningInfo

      protected void appendPositioningInfo(StringBuilder result)
    • dump

      public String dump(LayoutContext c, String indent, int which)
      Specified by:
      dump in class Box
    • isListItem

      public boolean isListItem()
    • paintListMarker

      public void paintListMarker(RenderingContext c)
    • getPaintingClipEdge

      public Rectangle getPaintingClipEdge(CssContext cssCtx)
      Overrides:
      getPaintingClipEdge in class Box
    • paintInline

      public void paintInline(RenderingContext c)
      Specified by:
      paintInline in interface InlinePaintable
    • isInline

      public boolean isInline()
    • getLineBox

      public LineBox getLineBox()
    • paintDebugOutline

      public void paintDebugOutline(RenderingContext c)
    • getMarkerData

      public MarkerData getMarkerData()
    • setMarkerData

      public void setMarkerData(MarkerData markerData)
    • createMarkerData

      public void createMarkerData(LayoutContext c)
    • makeGlyphMarker

      private MarkerData.GlyphMarker makeGlyphMarker(StrutMetrics strutMetrics)
    • makeImageMarker

      private MarkerData.ImageMarker makeImageMarker(LayoutContext c, StrutMetrics structMetrics, String image)
    • makeTextMarker

      private MarkerData.TextMarker makeTextMarker(LayoutContext c, IdentValue listStyle)
    • getListCounter

      public int getListCounter()
    • setListCounter

      public void setListCounter(int listCounter)
    • getPersistentBFC

      public PersistentBFC getPersistentBFC()
    • setPersistentBFC

      public void setPersistentBFC(PersistentBFC persistentBFC)
    • getStaticEquivalent

      public Box getStaticEquivalent()
    • setStaticEquivalent

      public void setStaticEquivalent(Box staticEquivalent)
    • shouldBeReplaced

      public boolean shouldBeReplaced()
    • isReplaced

      public boolean isReplaced()
    • calcCanvasLocation

      public void calcCanvasLocation()
      Specified by:
      calcCanvasLocation in class Box
    • calcInitialFloatedCanvasLocation

      public void calcInitialFloatedCanvasLocation(LayoutContext c)
    • calcChildLocations

      public void calcChildLocations()
      Overrides:
      calcChildLocations in class Box
    • isNeedPageClear

      public boolean isNeedPageClear()
    • setNeedPageClear

      public void setNeedPageClear(boolean needPageClear)
    • alignToStaticEquivalent

      private void alignToStaticEquivalent()
    • positionAbsolute

      public void positionAbsolute(CssContext cssCtx, int direction)
    • isPageBreakNeededBecauseOfMinHeight

      public boolean isPageBreakNeededBecauseOfMinHeight(LayoutContext context)
      Using the css: -fs-page-break-min-height: 5cm; on a block element you can force a pagebreak before this block, if not enough space (e.g. 5cm in this case) is remaining on the current page for the block.
      Returns:
      true if a pagebreak is needed before this block because there is not enough space left on the current page.
    • positionAbsoluteOnPage

      public void positionAbsoluteOnPage(LayoutContext c)
    • getReplacedElement

      public ReplacedElement getReplacedElement()
    • setReplacedElement

      public void setReplacedElement(ReplacedElement replacedElement)
    • reset

      public void reset(LayoutContext c)
      Description copied from class: Box
      Responsible for resetting the state of the box before a repeat call to layout(LayoutContext) or other layout methods.

      Any layout operation that is not idempotent MUST be reset in this method. Layout may be called several times on the one box.
      Overrides:
      reset in class Box
    • calcPinnedContentWidth

      private int calcPinnedContentWidth(CssContext c)
    • calcPinnedHeight

      private int calcPinnedHeight(CssContext c)
    • resolveAutoMargins

      protected void resolveAutoMargins(LayoutContext c, int cssWidth, RectPropertySet padding, BorderPropertySet border)
    • calcEffPageRelativeWidth

      private int calcEffPageRelativeWidth(LayoutContext c)
    • createReplaced

      private void createReplaced(LayoutContext c)
      Creates the replaced element as required. This method should be idempotent.
    • sizeReplacedElement

      private void sizeReplacedElement(LayoutContext c, ReplacedElement re)
      Size a replaced element taking into account size properties including min/max, border-box/content-box and the natural size/aspect ratio of the replaced object. This method may be called multiple times so must be idempotent.
    • calcDimensions

      public void calcDimensions(LayoutContext c)
    • calcDimensions

      protected void calcDimensions(LayoutContext c, int cssWidth)
    • calcClearance

      private void calcClearance(LayoutContext c)
    • calcExtraPageClearance

      private void calcExtraPageClearance(LayoutContext c)
    • addBoxID

      protected void addBoxID(LayoutContext c)
    • layout

      public void layout(LayoutContext c)
    • layout

      public void layout(LayoutContext c, int contentStart)
    • checkPushLayer

      protected boolean checkPushLayer(LayoutContext c, CalculatedStyle style)
    • checkPopBfc

      protected void checkPopBfc(LayoutContext c)
      Checks if this box established a block formatting context and if so removes the last bfc from the stack. See also checkPushBfc(LayoutContext)
    • checkPushBfc

      protected void checkPushBfc(LayoutContext c)
      Checks if this box establishes a block formatting context and if so creates one and pushes it to the stack of bfcs. See also checkPopBfc(LayoutContext)
    • isAllowHeightToShrink

      protected boolean isAllowHeightToShrink()
    • getPageClearance

      protected int getPageClearance()
    • calcLayoutHeight

      protected void calcLayoutHeight(LayoutContext c, BorderPropertySet border, RectPropertySet margin, RectPropertySet padding)
      Oh oh! Up to this method height is used to track content height. After this method it is used to track total layout height!
    • calcShrinkToFitWidthIfNeeded

      private void calcShrinkToFitWidthIfNeeded(LayoutContext c)
    • applyCSSMinMaxWidth

      private void applyCSSMinMaxWidth(CssContext c)
    • applyCSSMinMaxHeight

      private void applyCSSMinMaxHeight(CssContext c)
    • ensureChildren

      public void ensureChildren(LayoutContext c)
    • layoutChildren

      protected void layoutChildren(LayoutContext c, int contentStart)
    • layoutInlineChildren

      protected void layoutInlineChildren(LayoutContext c, int contentStart, int breakAtLine, boolean tryAgain)
    • justifyText

      private void justifyText(LayoutContext c)
    • satisfyWidowsAndOrphans

      private void satisfyWidowsAndOrphans(LayoutContext c, int contentStart, boolean tryAgain)
      TERMINOLOGY: Orphans refers to the number of lines of content in this box before the first page break. Widows refers to the number of lines of content on the last page.

      METHOD AIM: This method aims (but can not guarantee) to satisfy the orphans and widows CSS properties. Each of these provide a number specifying a minimum number of content lines.

      HOW: By inserting page breaks, either before this box or between certain lines in this box.

      PREREQUISITES: That the content of this box is CONTENT_INLINE and layout has been done on this box. This means that the children of this box will consist entirely of LineBox objects.
    • getChildrenContentType

      public BlockBox.ContentType getChildrenContentType()
    • setChildrenContentType

      public void setChildrenContentType(BlockBox.ContentType contentType)
    • getInlineContent

      public List<Styleable> getInlineContent()
    • setInlineContent

      public void setInlineContent(List<Styleable> inlineContent)
      Inline content is created by the box builder. It is important to note that the inline content here is stored in the pre-layout state. Ie. It has not been flowed out into LineBox and InlineLayoutBox objects but is stored as InlineBox and block boxes that are laid out inline such as inline-block and inline-table.

      During layout inline-content is laid out into lines and so on but the inline content is left untouched so as to be able to run layout multiple times to satisfy constraints.

      This method should be called with setChildrenContentType(ContentType) set to BlockBox.ContentType.INLINE as block boxes can not contain mixed content.
    • isSkipWhenCollapsingMargins

      protected boolean isSkipWhenCollapsingMargins()
    • isMayCollapseMarginsWithChildren

      protected boolean isMayCollapseMarginsWithChildren()
    • collapseMargins

      protected void collapseMargins(LayoutContext c)
    • setCollapsedBottomMargin

      private void setCollapsedBottomMargin(LayoutContext c, RectPropertySet margin, BlockBox.MarginCollapseResult collapsedMargin)
    • getNextCollapsableSibling

      protected BlockBox getNextCollapsableSibling(BlockBox.MarginCollapseResult collapsedMargin)
    • collapseTopMargin

      private void collapseTopMargin(LayoutContext c, boolean calculationRoot, BlockBox.MarginCollapseResult result)
    • collapseBottomMargin

      private void collapseBottomMargin(LayoutContext c, boolean calculationRoot, BlockBox.MarginCollapseResult result)
    • isNoTopPaddingOrBorder

      private boolean isNoTopPaddingOrBorder(LayoutContext c)
    • isNoBottomPaddingOrBorder

      private boolean isNoBottomPaddingOrBorder(LayoutContext c)
    • collapseEmptySubtreeMargins

      private void collapseEmptySubtreeMargins(LayoutContext c, BlockBox.MarginCollapseResult result)
    • isVerticalMarginsAdjoin

      private boolean isVerticalMarginsAdjoin(LayoutContext c)
    • isTopMarginCalculated

      public boolean isTopMarginCalculated()
    • setTopMarginCalculated

      public void setTopMarginCalculated(boolean topMarginCalculated)
    • isBottomMarginCalculated

      public boolean isBottomMarginCalculated()
    • setBottomMarginCalculated

      public void setBottomMarginCalculated(boolean bottomMarginCalculated)
    • getCSSWidth

      protected int getCSSWidth(CssContext c)
    • getCSSWidth

      protected int getCSSWidth(CssContext c, boolean shrinkingToFit)
    • getCSSFitToWidth

      protected int getCSSFitToWidth(CssContext c)
    • getCSSHeight

      protected int getCSSHeight(CssContext c)
    • isAutoHeight

      public boolean isAutoHeight()
    • getCSSMinWidth

      private int getCSSMinWidth(CssContext c)
    • getCSSMaxWidth

      private int getCSSMaxWidth(CssContext c)
    • getCSSMinHeight

      private int getCSSMinHeight(CssContext c)
    • getCSSMaxHeight

      private int getCSSMaxHeight(CssContext c)
    • getContainingBlockCSSHeight

      private int getContainingBlockCSSHeight(CssContext c)
    • calcShrinkToFitWidth

      private int calcShrinkToFitWidth(LayoutContext c)
    • getAvailableWidth

      protected int getAvailableWidth(LayoutContext c)
    • isFixedWidthAdvisoryOnly

      protected boolean isFixedWidthAdvisoryOnly()
    • recalcMargin

      private void recalcMargin(LayoutContext c)
    • calcMinMaxWidth

      public void calcMinMaxWidth(LayoutContext c)
    • calcMinMaxCSSMinMaxWidth

      private void calcMinMaxCSSMinMaxWidth(LayoutContext c, RectPropertySet margin, BorderPropertySet border, RectPropertySet padding)
    • calcMinMaxWidthBlockChildren

      private void calcMinMaxWidthBlockChildren(LayoutContext c)
    • calcMinMaxWidthInlineChildren

      private void calcMinMaxWidthInlineChildren(LayoutContext c)
    • getMaxWidth

      public int getMaxWidth()
    • setMaxWidth

      protected void setMaxWidth(int maxWidth)
    • getMinWidth

      public int getMinWidth()
    • setMinWidth

      protected void setMinWidth(int minWidth)
    • styleText

      public void styleText(LayoutContext c)
    • styleText

      public void styleText(LayoutContext c, CalculatedStyle style)
    • calcChildPaintingInfo

      protected void calcChildPaintingInfo(CssContext c, PaintingInfo result, boolean useCache)
      Overrides:
      calcChildPaintingInfo in class Box
    • getFirstLetterStyle

      public CascadedStyle getFirstLetterStyle()
    • setFirstLetterStyle

      public void setFirstLetterStyle(CascadedStyle firstLetterStyle)
    • getFirstLineStyle

      public CascadedStyle getFirstLineStyle()
    • setFirstLineStyle

      public void setFirstLineStyle(CascadedStyle firstLineStyle)
    • isMinMaxCalculated

      protected boolean isMinMaxCalculated()
    • setMinMaxCalculated

      protected void setMinMaxCalculated(boolean minMaxCalculated)
    • setDimensionsCalculated

      protected void setDimensionsCalculated(boolean dimensionsCalculated)
    • isDimensionsCalculated

      private boolean isDimensionsCalculated()
    • setNeedShrinkToFitCalculatation

      protected void setNeedShrinkToFitCalculatation(boolean needShrinkToFitCalculatation)
    • isNeedShrinkToFitCalculatation

      private boolean isNeedShrinkToFitCalculatation()
    • initStaticPos

      public void initStaticPos(LayoutContext c, BlockBox parent, int childOffset)
    • calcBaseline

      public int calcBaseline(LayoutContext c)
    • calcInitialBreakAtLine

      protected int calcInitialBreakAtLine(LayoutContext c)
    • isCurrentBreakAtLineContext

      public boolean isCurrentBreakAtLineContext(LayoutContext c)
    • calcBreakAtLineContext

      public BreakAtLineContext calcBreakAtLineContext(LayoutContext c)
    • calcInlineBaseline

      public int calcInlineBaseline(CssContext c)
    • findOffset

      public int findOffset(Box box)
    • findLastNthLineBox

      public LineBox findLastNthLineBox(int count)
    • findLastLineBox

      private void findLastLineBox(BlockBox.LastLineBoxContext context)
    • findLastLineBox

      private LineBox findLastLineBox()
    • findFirstLineBox

      private LineBox findFirstLineBox()
    • isNeedsKeepWithInline

      public boolean isNeedsKeepWithInline(LayoutContext c)
    • isFloated

      public boolean isFloated()
    • getFloatedBoxData

      public FloatedBoxData getFloatedBoxData()
    • setFloatedBoxData

      public void setFloatedBoxData(FloatedBoxData floatedBoxData)
    • getChildrenHeight

      public int getChildrenHeight()
    • setChildrenHeight

      protected void setChildrenHeight(int childrenHeight)
    • isFromCaptionedTable

      public boolean isFromCaptionedTable()
    • setFromCaptionedTable

      public void setFromCaptionedTable(boolean fromTable)
    • isInlineBlock

      protected boolean isInlineBlock()
      Overrides:
      isInlineBlock in class Box
    • isInMainFlow

      public boolean isInMainFlow()
    • getDocumentParent

      public Box getDocumentParent()
      Overrides:
      getDocumentParent in class Box
    • isContainsInlineContent

      public boolean isContainsInlineContent(LayoutContext c)
    • checkPageContext

      public boolean checkPageContext(LayoutContext c)
    • isNeedsClipOnPaint

      public boolean isNeedsClipOnPaint(CssContext c)
    • propagateExtraSpace

      protected void propagateExtraSpace(LayoutContext c, ContentLimitContainer parentContainer, ContentLimitContainer currentContainer, int extraTop, int extraBottom)