📄 render_block.cpp
字号:
bool inlineFlow = isInlineFlow(); bool isPrinting = (i.p->device()->devType() == QInternal::Printer); // 1. paint background, borders etc if (!inlineFlow && (paintAction == PaintActionElementBackground || paintAction == PaintActionChildBackground) && shouldPaintBackgroundOrBorder() && style()->visibility() == VISIBLE) { paintBoxDecorations(i, _tx, _ty); } // We're done. We don't bother painting any children. if (paintAction == PaintActionElementBackground) return; // We don't paint our own background, but we do let the kids paint their backgrounds. if (paintAction == PaintActionChildBackgrounds) paintAction = PaintActionChildBackground; PaintInfo paintInfo(i.p, i.r, paintAction, paintingRootForChildren(i)); paintLineBoxBackgroundBorder(paintInfo, _tx, _ty); // 2. paint contents int scrolledX = _tx; int scrolledY = _ty; if (hasOverflowClip()) m_layer->subtractScrollOffset(scrolledX, scrolledY); paintLineBoxDecorations(paintInfo, scrolledX, scrolledY); // Underline/overline for (RenderObject *child = firstChild(); child; child = child->nextSibling()) { // Check for page-break-before: always, and if it's set, break and bail. if (isPrinting && !childrenInline() && child->style()->pageBreakBefore() == PBALWAYS && inRootBlockContext() && (_ty + child->yPos()) > i.r.y() && (_ty + child->yPos()) < i.r.y() + i.r.height()) { canvas()->setBestTruncatedAt(_ty + child->yPos(), this, true); return; } if (!child->layer() && !child->isFloating()) child->paint(paintInfo, scrolledX, scrolledY); // Check for page-break-after: always, and if it's set, break and bail. if (isPrinting && !childrenInline() && child->style()->pageBreakAfter() == PBALWAYS && inRootBlockContext() && (_ty + child->yPos() + child->height()) > i.r.y() && (_ty + child->yPos() + child->height()) < i.r.y() + i.r.height()) { canvas()->setBestTruncatedAt(_ty + child->yPos() + child->height() + child->collapsedMarginBottom(), this, true); return; } } paintLineBoxDecorations(paintInfo, scrolledX, scrolledY, true); // Strike-through paintEllipsisBoxes(paintInfo, scrolledX, scrolledY); // 3. paint floats. if (!inlineFlow && (paintAction == PaintActionFloat || paintAction == PaintActionSelection)) paintFloats(paintInfo, scrolledX, scrolledY, paintAction == PaintActionSelection); // 4. paint outline. if (!inlineFlow && paintAction == PaintActionOutline && style()->outlineWidth() && style()->visibility() == VISIBLE) paintOutline(i.p, _tx, _ty, width(), height(), style()); // 5. paint caret. /* If the caret's node's render object's containing block is this block, and the paint action is PaintActionForeground, then paint the caret. */ if (paintAction == PaintActionForeground) { const Selection &s = document()->part()->selection(); NodeImpl *baseNode = s.base().node(); RenderObject *renderer = baseNode ? baseNode->renderer() : 0; if (renderer && renderer->containingBlock() == this && baseNode->isContentEditable()) { document()->part()->paintCaret(i.p, i.r); document()->part()->paintDragCaret(i.p, i.r); } } #ifdef BOX_DEBUG if ( style() && style()->visibility() == VISIBLE ) { if(isAnonymous()) outlineBox(i.p, _tx, _ty, "green"); if(isFloating()) outlineBox(i.p, _tx, _ty, "yellow"); else outlineBox(i.p, _tx, _ty); }#endif}void RenderBlock::paintFloats(PaintInfo& i, int _tx, int _ty, bool paintSelection){ if (!m_floatingObjects) return; FloatingObject* r; QPtrListIterator<FloatingObject> it(*m_floatingObjects); for ( ; (r = it.current()); ++it) { // Only paint the object if our noPaint flag isn't set. if (!r->noPaint && !r->node->layer()) { PaintInfo info(i.p, i.r, paintSelection ? PaintActionSelection : PaintActionElementBackground, i.paintingRoot); int tx = _tx + r->left - r->node->xPos() + r->node->marginLeft(); int ty = _ty + r->startY - r->node->yPos() + r->node->marginTop(); r->node->paint(info, tx, ty); if (!paintSelection) { info.phase = PaintActionChildBackgrounds; r->node->paint(info, tx, ty); info.phase = PaintActionFloat; r->node->paint(info, tx, ty); info.phase = PaintActionForeground; r->node->paint(info, tx, ty); info.phase = PaintActionOutline; r->node->paint(info, tx, ty); } } }}void RenderBlock::paintEllipsisBoxes(PaintInfo& i, int _tx, int _ty){ if (!shouldPaintWithinRoot(i) || !firstLineBox()) return; if (style()->visibility() == VISIBLE && i.phase == PaintActionForeground) { // We can check the first box and last box and avoid painting if we don't // intersect. int yPos = _ty + firstLineBox()->yPos();; int h = lastLineBox()->yPos() + lastLineBox()->height() - firstLineBox()->yPos(); if( (yPos >= i.r.y() + i.r.height()) || (yPos + h <= i.r.y())) return; // See if our boxes intersect with the dirty rect. If so, then we paint // them. Note that boxes can easily overlap, so we can't make any assumptions // based off positions of our first line box or our last line box. if (!isInlineFlow()) { for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) { yPos = _ty + curr->yPos(); h = curr->height(); if (curr->ellipsisBox() && (yPos < i.r.y() + i.r.height()) && (yPos + h > i.r.y())) curr->paintEllipsisBox(i, _tx, _ty); } } }}void RenderBlock::insertPositionedObject(RenderObject *o){ // Create the list of special objects if we don't aleady have one if (!m_positionedObjects) { m_positionedObjects = new QPtrList<RenderObject>; m_positionedObjects->setAutoDelete(false); } else { // Don't insert the object again if it's already in the list QPtrListIterator<RenderObject> it(*m_positionedObjects); RenderObject* f; while ( (f = it.current()) ) { if (f == o) return; ++it; } } m_positionedObjects->append(o);}void RenderBlock::removePositionedObject(RenderObject *o){ if (m_positionedObjects) { QPtrListIterator<RenderObject> it(*m_positionedObjects); while (it.current()) { if (it.current() == o) m_positionedObjects->removeRef(it.current()); ++it; } }}void RenderBlock::insertFloatingObject(RenderObject *o){ // Create the list of special objects if we don't aleady have one if (!m_floatingObjects) { m_floatingObjects = new QPtrList<FloatingObject>; m_floatingObjects->setAutoDelete(true); } else { // Don't insert the object again if it's already in the list QPtrListIterator<FloatingObject> it(*m_floatingObjects); FloatingObject* f; while ( (f = it.current()) ) { if (f->node == o) return; ++it; } } // Create the special object entry & append it to the list FloatingObject *newObj; if (o->isFloating()) { // floating object o->layoutIfNeeded(); if(o->style()->floating() == FLEFT) newObj = new FloatingObject(FloatingObject::FloatLeft); else newObj = new FloatingObject(FloatingObject::FloatRight); newObj->startY = -1; newObj->endY = -1; newObj->width = o->width() + o->marginLeft() + o->marginRight(); } else { // We should never get here, as insertFloatingObject() should only ever be called with floating // objects. KHTMLAssert(false); newObj = 0; // keep gcc's uninitialized variable warnings happy } newObj->node = o; m_floatingObjects->append(newObj);}void RenderBlock::removeFloatingObject(RenderObject *o){ if (m_floatingObjects) { QPtrListIterator<FloatingObject> it(*m_floatingObjects); while (it.current()) { if (it.current()->node == o) m_floatingObjects->removeRef(it.current()); ++it; } }}void RenderBlock::positionNewFloats(){ if(!m_floatingObjects) return; FloatingObject *f = m_floatingObjects->getLast(); if(!f || f->startY != -1) return; FloatingObject *lastFloat; while(1) { lastFloat = m_floatingObjects->prev(); if (!lastFloat || lastFloat->startY != -1) { m_floatingObjects->next(); break; } f = lastFloat; } int y = m_height; // the float can not start above the y position of the last positioned float. if(lastFloat && lastFloat->startY > y) y = lastFloat->startY; while(f) { //skip elements copied from elsewhere and positioned elements if (f->node->containingBlock()!=this) { f = m_floatingObjects->next(); continue; } RenderObject *o = f->node; int _height = o->height() + o->marginTop() + o->marginBottom(); int ro = rightOffset(); // Constant part of right offset. int lo = leftOffset(); // Constat part of left offset. int fwidth = f->width; // The width we look for. //kdDebug( 6040 ) << " Object width: " << fwidth << " available width: " << ro - lo << endl; if (ro - lo < fwidth) fwidth = ro - lo; // Never look for more than what will be available. int oldChildX = o->xPos(); int oldChildY = o->yPos(); if ( o->style()->clear() & CLEFT ) y = kMax( leftBottom(), y ); if ( o->style()->clear() & CRIGHT ) y = kMax( rightBottom(), y ); if (o->style()->floating() == FLEFT) { int heightRemainingLeft = 1; int heightRemainingRight = 1; int fx = leftRelOffset(y,lo, false, &heightRemainingLeft); while (rightRelOffset(y,ro, false, &heightRemainingRight)-fx < fwidth) { y += kMin( heightRemainingLeft, heightRemainingRight ); fx = leftRelOffset(y,lo, false, &heightRemainingLeft); } if (fx<0) fx=0; f->left = fx; //kdDebug( 6040 ) << "positioning left aligned float at (" << fx + o->marginLeft() << "/" << y + o->marginTop() << ") fx=" << fx << endl; o->setPos(fx + o->marginLeft(), y + o->marginTop()); } else { int heightRemainingLeft = 1; int heightRemainingRight = 1; int fx = rightRelOffset(y,ro, false, &heightRemainingRight); while (fx - leftRelOffset(y,lo, false, &heightRemainingLeft) < fwidth) { y += kMin(heightRemainingLeft, heightRemainingRight); fx = rightRelOffset(y,ro, false, &heightRemainingRight); } if (fx<f->width) fx=f->width; f->left = fx - f->width;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -