private void layout(int width) { Rectangle rect = new Rectangle(0, 0, width, DEFAULT_HEIGHT); sharedContext.set_TempCanvas(rect); BlockBox root = BoxBuilder.createRootBox(layoutContext, doc); root.setContainingBlock(new ViewportBox(rect)); root.layout(layoutContext); this.root = root; }
LayoutContext c, BlockBox parent, List children, ChildBoxInfo info) { IdentValue parentDisplay = parent.getStyle().getIdent(CSSName.DISPLAY); IdentValue next = getNextTableNestingLevel(parentDisplay); if (next == null && parent.isAnonymous() && containsOrphanedTableContent(children)) { resolveChildTableContent(c, parent, children, info, IdentValue.TABLE_CELL); } else if (next == null || isAllProperTableNesting(parentDisplay, children)) { if (parent.isAnonymous()) { rebalanceInlineContent(children); resolveChildren(c, parent, children, info); } else { List childrenForAnonymous = new ArrayList(); IdentValue childDisplay = child.getStyle().getIdent(CSSName.DISPLAY); if (isProperTableNesting(parentDisplay, childDisplay)) { if (childrenForAnonymous.size() > 0) { createAnonymousTableContent(c, parent, next, childrenForAnonymous, childrenWithAnonymous); createAnonymousTableContent(c, parent, next, childrenForAnonymous, childrenWithAnonymous); resolveChildren(c, parent, childrenWithAnonymous, info);
private static void insertAnonymousBlocks( SharedContext c, Box parent, List children, boolean layoutRunningBlocks) { List inline = new ArrayList(); LinkedList parents = new LinkedList(); List savedParents = null; for (Iterator i = children.iterator(); i.hasNext();) { Styleable child = (Styleable) i.next(); if (child.getStyle().isLayedOutInInlineContext() && ! (layoutRunningBlocks && child.getStyle().isRunning())) { inline.add(child); if (child.getStyle().isInline()) { InlineBox iB = (InlineBox) child; if (iB.isStartsHere()) { parents.add(iB); } if (iB.isEndsHere()) { parents.removeLast(); } } } else { if (inline.size() > 0) { createAnonymousBlock(c, parent, inline, savedParents); inline = new ArrayList(); savedParents = new ArrayList(parents); } parent.addChild((Box) child); } } createAnonymousBlock(c, parent, inline, savedParents); }
public static void createChildren(LayoutContext c, BlockBox parent) { List children = new ArrayList(); ChildBoxInfo info = new ChildBoxInfo(); createChildren(c, parent, parent.getElement(), children, info, false); boolean parentIsNestingTableContent = isNestingTableContent(parent.getStyle().getIdent( CSSName.DISPLAY)); if (!parentIsNestingTableContent && !info.isContainsTableContent()) { resolveChildren(c, parent, children, info); } else { stripAllWhitespace(children); if (parentIsNestingTableContent) { resolveTableContent(c, parent, children, info); } else { resolveChildTableContent(c, parent, children, info, IdentValue.TABLE_CELL); } } }
List childrenWithAnonymous = new ArrayList(); IdentValue nextUp = getPreviousTableNestingLevel(target); for (Iterator i = children.iterator(); i.hasNext();) { Styleable styleable = (Styleable) i.next(); if (matchesTableLevel(target, styleable.getStyle().getIdent(CSSName.DISPLAY))) { childrenForAnonymous.add(styleable); } else { if (childrenForAnonymous.size() > 0) { createAnonymousTableContent(c, (BlockBox) childrenForAnonymous.get(0), nextUp, childrenForAnonymous, childrenWithAnonymous); createAnonymousTableContent(c, (BlockBox) childrenForAnonymous.get(0), nextUp, childrenForAnonymous, childrenWithAnonymous); rebalanceInlineContent(childrenWithAnonymous); info.setContainsBlockLevelContent(true); resolveChildren(c, parent, childrenWithAnonymous, info); } else { resolveChildTableContent(c, parent, childrenWithAnonymous, info, nextUp);
insertGeneratedContent(c, parent, parentStyle, "before", children, info); (blockParent.getStyle().isTable() || blockParent.getStyle().isInlineTable())) { TableBox table = (TableBox) blockParent; addColumnOrColumnGroup(c, table, element, style); if (needStartText) { needStartText = false; InlineBox iB = createInlineBox("", parent, parentStyle, null); iB.setStartsHere(true); iB.setEndsHere(false); createChildren(c, null, element, children, info, true); if (inline) { if (previousIB != null) { child = createBlockBox(style, info, false); child.setStyle(style); child.setElement(element); child = reorderTableContent(c, table); child = createInlineBox(textNode.getData(), parent, parentStyle, textNode); InlineBox iB = createInlineBox("", parent, parentStyle, null); iB.setStartsHere(needStartText); iB.setEndsHere(needEndText); children.add(iB);
private static void createAnonymousTableContent(LayoutContext c, BlockBox source, IdentValue next, List childrenForAnonymous, List childrenWithAnonymous) { ChildBoxInfo nested = lookForBlockContent(childrenForAnonymous); IdentValue anonDisplay; if (isParentInline(source) && next == IdentValue.TABLE) { anonDisplay = IdentValue.INLINE_TABLE; } else { anonDisplay = next; } CalculatedStyle anonStyle = source.getStyle().createAnonymousStyle(anonDisplay); BlockBox anonBox = createBlockBox(anonStyle, nested, false); anonBox.setStyle(anonStyle); anonBox.setAnonymous(true); // XXX Doesn't really make sense, but what to do? anonBox.setElement(source.getElement()); resolveTableContent(c, anonBox, childrenForAnonymous, nested); if (next == IdentValue.TABLE) { childrenWithAnonymous.add(reorderTableContent(c, (TableBox) anonBox)); } else { childrenWithAnonymous.add(anonBox); } }
List inlineBoxes = createGeneratedContentList( c, element, property, peName, style, CONTENT_LIST_DOCUMENT, null); BlockBox result = createBlockBox(style, info, true); result.setStyle(style); result.setInlineContent(inlineBoxes);
StylesheetInfo.USER), })); TableBox result = (TableBox)createBlockBox(tableStyle, info, false); result.setMarginAreaRoot(true); result.setStyle(tableStyle); TableSectionBox section = (TableSectionBox)createBlockBox(tableSectionStyle, info, false); section.setStyle(tableSectionStyle); section.setElement(source); if (direction == MARGIN_BOX_HORIZONTAL) { CalculatedStyle tableRowStyle = pageStyle.createAnonymousStyle(IdentValue.TABLE_ROW); row = (TableRowBox)createBlockBox(tableRowStyle, info, false); row.setStyle(tableRowStyle); row.setElement(source); CascadedStyle cellStyle = pageInfo.createMarginBoxStyle(names[i], alwaysCreate); if (cellStyle != null) { TableCellBox cell = createMarginBox(c, cellStyle, alwaysCreate); if (cell != null) { if (direction == MARGIN_BOX_VERTICAL) { CalculatedStyle tableRowStyle = pageStyle.createAnonymousStyle(IdentValue.TABLE_ROW); row = (TableRowBox)createBlockBox(tableRowStyle, info, false); row.setStyle(tableRowStyle); row.setElement(source);
private static void addColumnOrColumnGroup( LayoutContext c, TableBox table, Element e, CalculatedStyle style) { if (style.isIdent(CSSName.DISPLAY, IdentValue.TABLE_COLUMN)) { table.addStyleColumn(new TableColumn(e, style)); } else { /* style.isIdent(CSSName.DISPLAY, IdentValue.TABLE_COLUMN_GROUP) */ addColumns(c, table, new TableColumn(e, style)); } }
public void ensureChildren(LayoutContext c) { if (getChildrenContentType() == CONTENT_UNKNOWN) { BoxBuilder.createChildren(c, this); } }
private static List createGeneratedMarginBoxContent( LayoutContext c, Element element, PropertyValue property, CalculatedStyle style, ChildBoxInfo info) { List result = createGeneratedContentList( c, element, property, null, style, CONTENT_LIST_MARGIN_BOX, info); CalculatedStyle anon = style.createAnonymousStyle(IdentValue.INLINE); for (Iterator i = result.iterator(); i.hasNext();) { Styleable s = (Styleable) i.next(); if (s instanceof InlineBox) { InlineBox iB = (InlineBox)s; iB.setElement(null); iB.setStyle(anon); iB.applyTextTransform(); } } return result; }
private static void insertGeneratedContent( LayoutContext c, Element element, CalculatedStyle parentStyle, String peName, List children, ChildBoxInfo info) { CascadedStyle peStyle = c.getCss().getPseudoElementStyle(element, peName); if (peStyle != null) { PropertyDeclaration contentDecl = (PropertyDeclaration) peStyle.propertyByName(CSSName.CONTENT); PropertyDeclaration counterResetDecl = (PropertyDeclaration) peStyle.propertyByName(CSSName.COUNTER_RESET); PropertyDeclaration counterIncrDecl = (PropertyDeclaration) peStyle.propertyByName(CSSName.COUNTER_INCREMENT); CalculatedStyle calculatedStyle = null; if (contentDecl != null || counterResetDecl != null || counterIncrDecl != null) { calculatedStyle = parentStyle.deriveStyle(peStyle); if (calculatedStyle.isDisplayNone()) return; if (calculatedStyle.isIdent(CSSName.CONTENT, IdentValue.NONE)) return; if (calculatedStyle.isIdent(CSSName.CONTENT, IdentValue.NORMAL) && (peName.equals("before") || peName.equals("after"))) return; c.resolveCounters(calculatedStyle); } if (contentDecl != null) { CSSPrimitiveValue propValue = contentDecl.getValue(); children.addAll(createGeneratedContent(c, element, peName, calculatedStyle, (PropertyValue) propValue, info)); } } }
public static void createChildren(LayoutContext c, BlockBox parent) { List children = new ArrayList(); ChildBoxInfo info = new ChildBoxInfo(); createChildren(c, parent, parent.getElement(), children, info, false); boolean parentIsNestingTableContent = isNestingTableContent(parent.getStyle().getIdent( CSSName.DISPLAY)); if (!parentIsNestingTableContent && !info.isContainsTableContent()) { resolveChildren(c, parent, children, info); } else { stripAllWhitespace(children); if (parentIsNestingTableContent) { resolveTableContent(c, parent, children, info); } else { resolveChildTableContent(c, parent, children, info, IdentValue.TABLE_CELL); } } }
List childrenWithAnonymous = new ArrayList(); IdentValue nextUp = getPreviousTableNestingLevel(target); for (Iterator i = children.iterator(); i.hasNext();) { Styleable styleable = (Styleable) i.next(); if (matchesTableLevel(target, styleable.getStyle().getIdent(CSSName.DISPLAY))) { childrenForAnonymous.add(styleable); } else { if (childrenForAnonymous.size() > 0) { createAnonymousTableContent(c, (BlockBox) childrenForAnonymous.get(0), nextUp, childrenForAnonymous, childrenWithAnonymous); createAnonymousTableContent(c, (BlockBox) childrenForAnonymous.get(0), nextUp, childrenForAnonymous, childrenWithAnonymous); rebalanceInlineContent(childrenWithAnonymous); info.setContainsBlockLevelContent(true); resolveChildren(c, parent, childrenWithAnonymous, info); } else { resolveChildTableContent(c, parent, childrenWithAnonymous, info, nextUp);
insertGeneratedContent(c, parent, parentStyle, "before", children, info); blockParent.getStyle().isTable() || blockParent.getStyle().isInlineTable()) { TableBox table = (TableBox) blockParent; addColumnOrColumnGroup(c, table, element, style); if (needStartText) { needStartText = false; InlineBox iB = createInlineBox("", parent, parentStyle, null); iB.setStartsHere(true); iB.setEndsHere(false); createChildren(c, null, element, children, info, true); if (inline) { if (previousIB != null) { child = createBlockBox(style, info, false); child.setStyle(style); child.setElement(element); child = reorderTableContent(c, table); child = createInlineBox(textNode.getData(), parent, parentStyle, textNode); InlineBox iB = createInlineBox("", parent, parentStyle, null); iB.setStartsHere(needStartText); iB.setEndsHere(needEndText); children.add(iB);
private static void createAnonymousTableContent(LayoutContext c, BlockBox source, IdentValue next, List childrenForAnonymous, List childrenWithAnonymous) { ChildBoxInfo nested = lookForBlockContent(childrenForAnonymous); IdentValue anonDisplay; if (isParentInline(source) && next == IdentValue.TABLE) { anonDisplay = IdentValue.INLINE_TABLE; } else { anonDisplay = next; } CalculatedStyle anonStyle = source.getStyle().createAnonymousStyle(anonDisplay); BlockBox anonBox = createBlockBox(anonStyle, nested, false); anonBox.setStyle(anonStyle); anonBox.setAnonymous(true); // XXX Doesn't really make sense, but what to do? anonBox.setElement(source.getElement()); resolveTableContent(c, anonBox, childrenForAnonymous, nested); if (next == IdentValue.TABLE) { childrenWithAnonymous.add(reorderTableContent(c, (TableBox) anonBox)); } else { childrenWithAnonymous.add(anonBox); } }
List inlineBoxes = createGeneratedContentList( c, element, property, peName, style, CONTENT_LIST_DOCUMENT, null); BlockBox result = createBlockBox(style, info, true); result.setStyle(style); result.setInlineContent(inlineBoxes);
StylesheetInfo.USER), })); TableBox result = (TableBox)createBlockBox(tableStyle, info, false); result.setMarginAreaRoot(true); result.setStyle(tableStyle); TableSectionBox section = (TableSectionBox)createBlockBox(tableSectionStyle, info, false); section.setStyle(tableSectionStyle); section.setElement(source); if (direction == MARGIN_BOX_HORIZONTAL) { CalculatedStyle tableRowStyle = pageStyle.createAnonymousStyle(IdentValue.TABLE_ROW); row = (TableRowBox)createBlockBox(tableRowStyle, info, false); row.setStyle(tableRowStyle); row.setElement(source); CascadedStyle cellStyle = pageInfo.createMarginBoxStyle(names[i], alwaysCreate); if (cellStyle != null) { TableCellBox cell = createMarginBox(c, cellStyle, alwaysCreate); if (cell != null) { if (direction == MARGIN_BOX_VERTICAL) { CalculatedStyle tableRowStyle = pageStyle.createAnonymousStyle(IdentValue.TABLE_ROW); row = (TableRowBox)createBlockBox(tableRowStyle, info, false); row.setStyle(tableRowStyle); row.setElement(source);
private static void addColumnOrColumnGroup( LayoutContext c, TableBox table, Element e, CalculatedStyle style) { if (style.isIdent(CSSName.DISPLAY, IdentValue.TABLE_COLUMN)) { table.addStyleColumn(new TableColumn(e, style)); } else { /* style.isIdent(CSSName.DISPLAY, IdentValue.TABLE_COLUMN_GROUP) */ addColumns(c, table, new TableColumn(e, style)); } }