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
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
What type of direct child content this block box contains.private static class
static class
Nested classes/interfaces inherited from class com.openhtmltopdf.render.Box
Box.ChildIteratorOfType<T>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private BlockBox.ContentType
private int
private boolean
private CascadedStyle
private CascadedStyle
private FloatedBoxData
private boolean
private boolean
private int
private MarkerData
private int
private boolean
private int
private boolean
private boolean
private BlockBox.MarginCollapseResult
private PersistentBFC
private ReplacedElement
private Box
private boolean
protected static final int
static final int
static final int
static final int
Fields inherited from class com.openhtmltopdf.render.Box
CHILDREN_FLUX, DONE, DUMP_LAYOUT, DUMP_RENDER, FLUX, LINE_SEPARATOR, NOTHING
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
private void
protected void
appendPositioningInfo
(StringBuilder result) private void
private void
int
void
void
protected void
calcChildPaintingInfo
(CssContext c, PaintingInfo result, boolean useCache) private void
void
protected void
calcDimensions
(LayoutContext c, int cssWidth) private int
private void
protected int
void
int
protected void
calcLayoutHeight
(LayoutContext c, BorderPropertySet border, RectPropertySet margin, RectPropertySet padding) Oh oh! Up to this method height is used to track content height.private void
calcMinMaxCSSMinMaxWidth
(LayoutContext c, RectPropertySet margin, BorderPropertySet border, RectPropertySet padding) void
private void
private void
private int
private int
private int
private void
boolean
protected void
Checks if this box established a block formatting context and if so removes the last bfc from the stack.protected void
Checks if this box establishes a block formatting context and if so creates one and pushes it to the stack of bfcs.protected boolean
checkPushLayer
(LayoutContext c, CalculatedStyle style) private void
collapseBottomMargin
(LayoutContext c, boolean calculationRoot, BlockBox.MarginCollapseResult result) private void
protected void
private void
collapseTopMargin
(LayoutContext c, boolean calculationRoot, BlockBox.MarginCollapseResult result) copyOf()
void
private void
Creates the replaced element as required.dump
(LayoutContext c, String indent, int which) void
private LineBox
private LineBox
private void
findLastNthLineBox
(int count) int
findOffset
(Box box) protected int
int
private int
protected int
protected int
private int
private int
private int
private int
protected int
protected int
getCSSWidth
(CssContext c, boolean shrinkingToFit) protected String
int
int
int
protected BlockBox
getNextCollapsableSibling
(BlockBox.MarginCollapseResult collapsedMargin) protected int
getPaintingClipEdge
(CssContext cssCtx) void
initStaticPos
(LayoutContext c, BlockBox parent, int childOffset) protected boolean
boolean
boolean
boolean
boolean
private boolean
protected boolean
boolean
boolean
boolean
isInline()
protected boolean
boolean
boolean
protected boolean
protected boolean
boolean
boolean
private boolean
boolean
private boolean
private boolean
boolean
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.boolean
protected boolean
boolean
private boolean
private void
void
void
layout
(LayoutContext c, int contentStart) protected void
layoutChildren
(LayoutContext c, int contentStart) protected void
layoutInlineChildren
(LayoutContext c, int contentStart, int breakAtLine, boolean tryAgain) private MarkerData.GlyphMarker
makeGlyphMarker
(StrutMetrics strutMetrics) private MarkerData.ImageMarker
makeImageMarker
(LayoutContext c, StrutMetrics structMetrics, String image) private MarkerData.TextMarker
makeTextMarker
(LayoutContext c, IdentValue listStyle) void
void
void
void
positionAbsolute
(CssContext cssCtx, int direction) void
protected void
propagateExtraSpace
(LayoutContext c, ContentLimitContainer parentContainer, ContentLimitContainer currentContainer, int extraTop, int extraBottom) private void
void
Responsible for resetting the state of the box before a repeat call tolayout(LayoutContext)
or other layout methods.protected void
resolveAutoMargins
(LayoutContext c, int cssWidth, RectPropertySet padding, BorderPropertySet border) 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.void
setBottomMarginCalculated
(boolean bottomMarginCalculated) void
setChildrenContentType
(BlockBox.ContentType contentType) protected void
setChildrenHeight
(int childrenHeight) private void
setCollapsedBottomMargin
(LayoutContext c, RectPropertySet margin, BlockBox.MarginCollapseResult collapsedMargin) protected void
setDimensionsCalculated
(boolean dimensionsCalculated) void
setElement
(Element element) void
setFirstLetterStyle
(CascadedStyle firstLetterStyle) void
setFirstLineStyle
(CascadedStyle firstLineStyle) void
setFloatedBoxData
(FloatedBoxData floatedBoxData) void
setFromCaptionedTable
(boolean fromTable) void
setInlineContent
(List<Styleable> inlineContent) Inline content is created by the box builder.void
setListCounter
(int listCounter) void
setMarkerData
(MarkerData markerData) protected void
setMaxWidth
(int maxWidth) protected void
setMinMaxCalculated
(boolean minMaxCalculated) protected void
setMinWidth
(int minWidth) void
setNeedPageClear
(boolean needPageClear) protected void
setNeedShrinkToFitCalculatation
(boolean needShrinkToFitCalculatation) void
setPersistentBFC
(PersistentBFC persistentBFC) void
setReplacedElement
(ReplacedElement replacedElement) void
setStaticEquivalent
(Box staticEquivalent) void
setTopMarginCalculated
(boolean topMarginCalculated) boolean
private void
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.void
void
styleText
(LayoutContext c, CalculatedStyle style) toString()
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 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
-
_listCounter
private int _listCounter -
_persistentBFC
-
_staticEquivalent
-
_needPageClear
private boolean _needPageClear -
_replacedElement
-
_childrenContentType
-
_inlineContent
-
_topMarginCalculated
private boolean _topMarginCalculated -
_bottomMarginCalculated
private boolean _bottomMarginCalculated -
_pendingCollapseCalculation
-
_minWidth
private int _minWidth -
_maxWidth
private int _maxWidth -
_minMaxCalculated
private boolean _minMaxCalculated -
_dimensionsCalculated
private boolean _dimensionsCalculated -
_needShrinkToFitCalculatation
private boolean _needShrinkToFitCalculatation -
_firstLineStyle
-
_firstLetterStyle
-
_floatedBoxData
-
_childrenHeight
private int _childrenHeight -
_fromCaptionedTable
private boolean _fromCaptionedTable -
_isReplaced
private boolean _isReplaced
-
-
Constructor Details
-
BlockBox
public BlockBox()
-
-
Method Details
-
setElement
- Specified by:
setElement
in interfaceStyleable
- Overrides:
setElement
in classBox
-
copyOf
-
getExtraBoxDescription
-
toString
-
appendPositioningInfo
-
dump
-
isListItem
public boolean isListItem() -
paintListMarker
-
getPaintingClipEdge
- Overrides:
getPaintingClipEdge
in classBox
-
paintInline
- Specified by:
paintInline
in interfaceInlinePaintable
-
isInline
public boolean isInline() -
getLineBox
-
paintDebugOutline
-
getMarkerData
-
setMarkerData
-
createMarkerData
-
makeGlyphMarker
-
makeImageMarker
private MarkerData.ImageMarker makeImageMarker(LayoutContext c, StrutMetrics structMetrics, String image) -
makeTextMarker
-
getListCounter
public int getListCounter() -
setListCounter
public void setListCounter(int listCounter) -
getPersistentBFC
-
setPersistentBFC
-
getStaticEquivalent
-
setStaticEquivalent
-
shouldBeReplaced
public boolean shouldBeReplaced() -
isReplaced
public boolean isReplaced() -
calcCanvasLocation
public void calcCanvasLocation()- Specified by:
calcCanvasLocation
in classBox
-
calcInitialFloatedCanvasLocation
-
calcChildLocations
public void calcChildLocations()- Overrides:
calcChildLocations
in classBox
-
isNeedPageClear
public boolean isNeedPageClear() -
setNeedPageClear
public void setNeedPageClear(boolean needPageClear) -
alignToStaticEquivalent
private void alignToStaticEquivalent() -
positionAbsolute
-
isPageBreakNeededBecauseOfMinHeight
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
-
getReplacedElement
-
setReplacedElement
-
reset
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
-
calcPinnedHeight
-
resolveAutoMargins
protected void resolveAutoMargins(LayoutContext c, int cssWidth, RectPropertySet padding, BorderPropertySet border) -
calcEffPageRelativeWidth
-
createReplaced
Creates the replaced element as required. This method should be idempotent. -
sizeReplacedElement
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
-
calcDimensions
-
calcClearance
-
calcExtraPageClearance
-
addBoxID
-
layout
-
layout
-
checkPushLayer
-
checkPopBfc
Checks if this box established a block formatting context and if so removes the last bfc from the stack. See alsocheckPushBfc(LayoutContext)
-
checkPushBfc
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
-
applyCSSMinMaxWidth
-
applyCSSMinMaxHeight
-
ensureChildren
-
layoutChildren
-
layoutInlineChildren
protected void layoutInlineChildren(LayoutContext c, int contentStart, int breakAtLine, boolean tryAgain) -
justifyText
-
satisfyWidowsAndOrphans
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
-
setChildrenContentType
-
getInlineContent
-
setInlineContent
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
-
setCollapsedBottomMargin
private void setCollapsedBottomMargin(LayoutContext c, RectPropertySet margin, BlockBox.MarginCollapseResult collapsedMargin) -
getNextCollapsableSibling
-
collapseTopMargin
private void collapseTopMargin(LayoutContext c, boolean calculationRoot, BlockBox.MarginCollapseResult result) -
collapseBottomMargin
private void collapseBottomMargin(LayoutContext c, boolean calculationRoot, BlockBox.MarginCollapseResult result) -
isNoTopPaddingOrBorder
-
isNoBottomPaddingOrBorder
-
collapseEmptySubtreeMargins
-
isVerticalMarginsAdjoin
-
isTopMarginCalculated
public boolean isTopMarginCalculated() -
setTopMarginCalculated
public void setTopMarginCalculated(boolean topMarginCalculated) -
isBottomMarginCalculated
public boolean isBottomMarginCalculated() -
setBottomMarginCalculated
public void setBottomMarginCalculated(boolean bottomMarginCalculated) -
getCSSWidth
-
getCSSWidth
-
getCSSFitToWidth
-
getCSSHeight
-
isAutoHeight
public boolean isAutoHeight() -
getCSSMinWidth
-
getCSSMaxWidth
-
getCSSMinHeight
-
getCSSMaxHeight
-
getContainingBlockCSSHeight
-
calcShrinkToFitWidth
-
getAvailableWidth
-
isFixedWidthAdvisoryOnly
protected boolean isFixedWidthAdvisoryOnly() -
recalcMargin
-
calcMinMaxWidth
-
calcMinMaxCSSMinMaxWidth
private void calcMinMaxCSSMinMaxWidth(LayoutContext c, RectPropertySet margin, BorderPropertySet border, RectPropertySet padding) -
calcMinMaxWidthBlockChildren
-
calcMinMaxWidthInlineChildren
-
getMaxWidth
public int getMaxWidth() -
setMaxWidth
protected void setMaxWidth(int maxWidth) -
getMinWidth
public int getMinWidth() -
setMinWidth
protected void setMinWidth(int minWidth) -
styleText
-
styleText
-
calcChildPaintingInfo
- Overrides:
calcChildPaintingInfo
in classBox
-
getFirstLetterStyle
-
setFirstLetterStyle
-
getFirstLineStyle
-
setFirstLineStyle
-
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
-
calcBaseline
-
calcInitialBreakAtLine
-
isCurrentBreakAtLineContext
-
calcBreakAtLineContext
-
calcInlineBaseline
-
findOffset
-
findLastNthLineBox
-
findLastLineBox
-
findLastLineBox
-
findFirstLineBox
-
isNeedsKeepWithInline
-
isFloated
public boolean isFloated() -
getFloatedBoxData
-
setFloatedBoxData
-
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
- Overrides:
getDocumentParent
in classBox
-
isContainsInlineContent
-
checkPageContext
-
isNeedsClipOnPaint
-
propagateExtraSpace
protected void propagateExtraSpace(LayoutContext c, ContentLimitContainer parentContainer, ContentLimitContainer currentContainer, int extraTop, int extraBottom)
-