Package com.openhtmltopdf.render
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). SeeBlockBox.ContentType
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BlockBox.ContentType
What type of direct child content this block box contains.private static class
BlockBox.LastLineBoxContext
static class
BlockBox.MarginCollapseResult
-
Nested classes/interfaces inherited from class com.openhtmltopdf.render.Box
Box.ChildIteratorOfType<T>
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
_bottomMarginCalculated
private BlockBox.ContentType
_childrenContentType
private int
_childrenHeight
private boolean
_dimensionsCalculated
private CascadedStyle
_firstLetterStyle
private CascadedStyle
_firstLineStyle
private FloatedBoxData
_floatedBoxData
private boolean
_fromCaptionedTable
private java.util.List<Styleable>
_inlineContent
private boolean
_isReplaced
private int
_listCounter
private MarkerData
_markerData
private int
_maxWidth
private boolean
_minMaxCalculated
private int
_minWidth
private boolean
_needPageClear
private boolean
_needShrinkToFitCalculatation
private BlockBox.MarginCollapseResult
_pendingCollapseCalculation
private PersistentBFC
_persistentBFC
private ReplacedElement
_replacedElement
private Box
_staticEquivalent
private boolean
_topMarginCalculated
protected static int
NO_BASELINE
static int
POSITION_BOTH
static int
POSITION_HORIZONTALLY
static int
POSITION_VERTICALLY
-
Fields inherited from class com.openhtmltopdf.render.Box
CHILDREN_FLUX, DONE, DUMP_LAYOUT, DUMP_RENDER, FLUX, LINE_SEPARATOR, NOTHING
-
-
Constructor Summary
Constructors Constructor Description BlockBox()
-
Method Summary
-
Methods inherited from class com.openhtmltopdf.render.Box
addAllChildren, addChild, addChildForLayout, analyzePageBreaks, ancestors, ancestorsWhile, calcPaintingInfo, collectText, connectChildrenToCurrentLayer, crossesPageBreak, detach, dumpBoxes, exportPageBoxText, exportText, find, findAncestor, findColumnBreakOpportunities, forcePageBreakAfter, forcePageBreakBefore, forcePageBreakBefore, getAbsoluteClipBox, getAbsX, getAbsY, getAccessibilityObject, getBorder, getBorderBox, getBorderBoxHeight, getBorderBoxWidth, getBorderEdge, getBorderSides, getBoxDimensions, getChild, getChildCount, getChildIterator, getChildIteratorOfType, getChildren, getChildrenClipEdge, getClipBox, getContainingBlock, getContainingBlockWidth, getContainingLayer, getContentAreaEdge, getContentWidth, getEffBackgroundColor, getEffectiveWidth, getElement, getElementBoxes, getHeight, getIndex, getLayer, getLeftMBP, getMargin, getMarginBorderPadding, getMarginEdge, getMarginEdge, getNext, getNextSibling, getPadding, getPaddingEdge, getPaddingWidth, getPaintingBorderEdge, getPaintingInfo, getPaintingPaddingEdge, getParent, getParentClipBox, getPrevious, getPreviousSibling, getPseudoElementOrClass, getRelativeOffset, getRightMBP, getState, getStyle, getStyleMargin, getStyleMargin, getTx, getTy, getWidth, getX, getY, hasNonTextContent, hasRootElementBackground, initContainingLayer, intersects, isAnonymous, isBody, isContainedInMarginBox, isFirstChild, isInDocumentFlow, isInitialContainingBlock, isMarginAreaRoot, isRoot, isStyled, isTerminalColumnBreak, moveIfGreater, paintBackground, paintBorder, paintRootElementBackground, positionRelative, removeAllChildren, removeChild, removeChild, resetChildren, resetChildren, resetTopMargin, rootBox, setAbsX, setAbsY, setAccessiblityObject, setAnonymous, setBorderBoxHeight, setBorderBoxWidth, setBoxDimensions, setContainingBlock, setContainingLayer, setContentWidth, setHeight, setIndex, setLayer, setLeftMBP, setMarginBottom, setMarginLeft, setMarginRight, setMarginTop, setParent, setPseudoElementOrClass, setRelativeOffset, setRightMBP, setState, setStyle, setTx, setTy, setX, setY, stateToString
-
-
-
-
Field Detail
-
POSITION_VERTICALLY
public static final int POSITION_VERTICALLY
- See Also:
- Constant Field Values
-
POSITION_HORIZONTALLY
public static final int POSITION_HORIZONTALLY
- See Also:
- Constant Field Values
-
POSITION_BOTH
public static final int POSITION_BOTH
- See Also:
- Constant Field Values
-
NO_BASELINE
protected static final int NO_BASELINE
- See Also:
- Constant Field Values
-
_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 java.util.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
-
-
Method Detail
-
setElement
public void setElement(org.w3c.dom.Element element)
- Specified by:
setElement
in interfaceStyleable
- Overrides:
setElement
in classBox
-
copyOf
public BlockBox copyOf()
-
getExtraBoxDescription
protected java.lang.String getExtraBoxDescription()
-
appendPositioningInfo
protected void appendPositioningInfo(java.lang.StringBuilder result)
-
dump
public java.lang.String dump(LayoutContext c, java.lang.String indent, int which)
-
isListItem
public boolean isListItem()
-
paintListMarker
public void paintListMarker(RenderingContext c)
-
getPaintingClipEdge
public java.awt.Rectangle getPaintingClipEdge(CssContext cssCtx)
- Overrides:
getPaintingClipEdge
in classBox
-
paintInline
public void paintInline(RenderingContext c)
- Specified by:
paintInline
in interfaceInlinePaintable
-
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, java.lang.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 classBox
-
calcInitialFloatedCanvasLocation
public void calcInitialFloatedCanvasLocation(LayoutContext c)
-
calcChildLocations
public void calcChildLocations()
- Overrides:
calcChildLocations
in classBox
-
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 tolayout(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.
-
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 alsocheckPushBfc(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 alsocheckPopBfc(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 theorphans
andwidows
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 isCONTENT_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 java.util.List<Styleable> getInlineContent()
-
setInlineContent
public void setInlineContent(java.util.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 intoLineBox
andInlineLayoutBox
objects but is stored asInlineBox
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 withsetChildrenContentType(ContentType)
set toBlockBox.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 classBox
-
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 classBox
-
isInMainFlow
public boolean isInMainFlow()
-
getDocumentParent
public Box getDocumentParent()
- Overrides:
getDocumentParent
in classBox
-
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)
-
-