// raw tree manipulation virtual RenderObject* removeChildNode(RenderObject*, bool fullRemove = true); virtual void appendChildNode(RenderObject*, bool fullAppend = true); virtual void insertChildNode(RenderObject* child, RenderObject* before, bool fullInsert = true); // Designed for speed. Don't waste time doing a bunch of work like layer updating and repainting when we know that our // change in parentage is not going to affect anything. virtual void moveChildNode(RenderObject*);
virtual void paint(PaintInfo&, int tx, int ty);
/* * This function should cause the Element to calculate its * width and height and the layout of its content * * when the Element calls setNeedsLayout(false), layout() is no * longer called during relayouts, as long as there is no * style sheet change. When that occurs, m_needsLayout will be * set to true and the Element receives layout() calls * again. */ virtual void layout() = 0;
三、RenderObject及子类对象的生成 1、CSSParser CSSParser类顾名思义,主要用来解析文本中各种CSS属性,并且有效的组织在一个RenderStyle对象中。 其主要方法parseValue、applyProperty的部分代码示例如下: bool CSSParser::parseValue(int propId, bool important) { ..................................................... case CSSPropertyFloat: // left | right | none | inherit + center for buggy CSS if (id == CSSValueLeft || id == CSSValueRight || id == CSSValueNone || id == CSSValueCenter) valid_primitive = true; break;
case CSSPropertyClear: // none | left | right | both | inherit if (id == CSSValueNone || id == CSSValueLeft || id == CSSValueRight|| id == CSSValueBoth) valid_primitive = true; break;
case CSSPropertyWebkitBoxAlign: if (id == CSSValueStretch || id == CSSValueStart || id == CSSValueEnd || id == CSSValueCenter || id == CSSValueBaseline) valid_primitive = true; break; ..................................................... case CSSPropertyWebkitBoxPack: if (id == CSSValueStart || id == CSSValueEnd || id == CSSValueCenter || id == CSSValueJustify) valid_primitive = true; break; .................................................... }
void CSSStyleSelector::applyProperty(int id, CSSValue *value) { case CSSPropertyOpacity: HANDLE_INHERIT_AND_INITIAL(opacity, Opacity) if (!primitiveValue || primitiveValue->primitiveType() != CSSPrimitiveValue::CSS_NUMBER) return; // Error case. // Clamp opacity to the range 0-1 m_style->setOpacity(min(1.0f, max(0.0f, primitiveValue->getFloatValue()))); return; case CSSPropertyWebkitBoxAlign: { HANDLE_INHERIT_AND_INITIAL(boxAlign, BoxAlign) if (!primitiveValue) return; EBoxAlignment boxAlignment = *primitiveValue; if (boxAlignment != BJUSTIFY) m_style->setBoxAlign(boxAlignment); return; } ................................................... }
RenderObject* Element::createRenderer(RenderArena* arena, RenderStyle* style) { if (document()->documentElement() == this && style->display() == NONE) { // Ignore display: none on root elements. Force a display of block in that case. RenderBlock* result = new (arena) RenderBlock(this); if (result) result->setAnimatableStyle(style); return result; } return RenderObject::createObject(this, style); }
switch (style->display()) {//往往在CSSStyleSelector::styleForElement或CSSStyleSelector::adjustRenderStyle时//调用setDisplay()以确定其display属性。 case NONE: break; case INLINE: o = new (arena) RenderInline(node); break; case BLOCK: o = new (arena) RenderBlock(node); break; case INLINE_BLOCK: o = new (arena) RenderBlock(node); break; case LIST_ITEM: o = new (arena) RenderListItem(node); break; case RUN_IN: case COMPACT: o = new (arena) RenderBlock(node); break; case TABLE: case INLINE_TABLE: o = new (arena) RenderTable(node); break; case TABLE_ROW_GROUP: case TABLE_HEADER_GROUP: case TABLE_FOOTER_GROUP: o = new (arena) RenderTableSection(node); break; case TABLE_ROW: o = new (arena) RenderTableRow(node); break; case TABLE_COLUMN_GROUP: case TABLE_COLUMN: o = new (arena) RenderTableCol(node); break; case TABLE_CELL: o = new (arena) RenderTableCell(node); break; case TABLE_CAPTION: o = new (arena) RenderBlock(node); break; case BOX: case INLINE_BOX: o = new (arena) RenderFlexibleBox(node); break; } return o; } 这样就不同的DOM树节点结合不同的显示属性,创建出不同的RenderObject子类对象,进而形成一个Render树。