📄 render_object.cpp
字号:
static_cast<const RenderBox*>(this)->relativePositionOffset(x, y); } RenderObject* offsetPar = offsetParent(); for( RenderObject* curr = parent(); curr && curr != offsetPar; curr = curr->parent() ) x += curr->xPos(); if ( offsetPar && offsetPar->isBody() && style()->htmlHacks() ) x += offsetPar->xPos(); return x;}int RenderObject::offsetTop() const{ if ( isPositioned() ) return yPos(); if ( isBody() && style()->htmlHacks() ) return 0; int y = yPos(); if (isRelPositioned()) { int x = 0; static_cast<const RenderBox*>(this)->relativePositionOffset(x, y); } RenderObject* offsetPar = offsetParent(); for( RenderObject* curr = parent(); curr && curr != offsetPar; curr = curr->parent() ) y += curr->yPos(); if ( offsetPar && offsetPar->isBody() && style()->htmlHacks() ) y += offsetPar->yPos(); return y;}RenderObject* RenderObject::offsetParent() const{ bool skipTables = isPositioned() || isRelPositioned(); bool strict = !style()->htmlHacks(); RenderObject* curr = parent(); while (curr && !curr->isPositioned() && !curr->isRelPositioned() && !(strict && skipTables ? curr->isRoot() : curr->isBody())) { if (!skipTables && (curr->isTableCell() || curr->isTable())) break; curr = curr->parent(); } return curr;}// IE extensions.// clientWidth and clientHeight represent the interior of an objectshort RenderObject::clientWidth() const{ return width() - borderLeft() - borderRight() - (layer() ? layer()->verticalScrollbarWidth() : 0);}int RenderObject::clientHeight() const{ return height() - borderTop() - borderBottom() - (layer() ? layer()->horizontalScrollbarHeight() : 0);}// scrollWidth/scrollHeight is the size including the overflow areashort RenderObject::scrollWidth() const{ return (style()->hidesOverflow() && layer()) ? layer()->scrollWidth() : overflowWidth();}int RenderObject::scrollHeight() const{ return (style()->hidesOverflow() && layer()) ? layer()->scrollHeight() : overflowHeight();}bool RenderObject::hasStaticX() const{ return (style()->left().isVariable() && style()->right().isVariable()) || style()->left().isStatic() || style()->right().isStatic();}bool RenderObject::hasStaticY() const{ return (style()->top().isVariable() && style()->bottom().isVariable()) || style()->top().isStatic();}void RenderObject::setPixmap(const QPixmap&, const QRect& /*r*/, CachedImage* image){ //repaint bg when it finished loading if(image && parent() && style() && style()->backgroundImage() == image && image->valid_rect().size() == image->pixmap_size() ) { isBody() ? canvas()->repaint() : repaint(); }}void RenderObject::setNeedsLayout(bool b, bool markParents){ bool alreadyNeededLayout = m_needsLayout; m_needsLayout = b; if (b) { if (!alreadyNeededLayout && markParents) { dirtyFormattingContext( false ); markContainingBlocksForLayout(); } } else { m_posChildNeedsLayout = false; m_normalChildNeedsLayout = false; }}void RenderObject::setChildNeedsLayout(bool b, bool markParents){ bool alreadyNeededLayout = m_normalChildNeedsLayout; m_normalChildNeedsLayout = b; if (b) { if (!alreadyNeededLayout && markParents) markContainingBlocksForLayout(); } else { m_posChildNeedsLayout = false; m_normalChildNeedsLayout = false; }}void RenderObject::markContainingBlocksForLayout(){ RenderObject *o = container(); RenderObject *last = this; while (o) { if (!last->isText() && (last->style()->position() == FIXED || last->style()->position() == ABSOLUTE)) { if (o->m_posChildNeedsLayout) return; o->m_posChildNeedsLayout = true; } else { if (o->m_normalChildNeedsLayout) return; o->m_normalChildNeedsLayout = true; } last = o; o = o->container(); } last->scheduleRelayout();}RenderBlock *RenderObject::containingBlock() const{ if(isTableCell()) return static_cast<RenderBlock*>( parent()->parent()->parent() ); if (isCanvas()) return const_cast<RenderBlock*>( static_cast<const RenderBlock*>(this) ); RenderObject *o = parent(); if(m_style->position() == FIXED) { while ( o && !o->isCanvas() ) o = o->parent(); } else if(m_style->position() == ABSOLUTE) { while (o && ( o->style()->position() == STATIC || ( o->isInline() && !o->isReplaced() ) ) && !o->isCanvas()) o = o->parent(); } else { while(o && ( ( o->isInline() && !o->isReplaced() ) || o->isTableRow() || o->isTableSection() || o->isTableCol() || o->isFrameSet() ) ) o = o->parent(); } // this is just to make sure we return a valid element. // the case below should never happen... if(!o || !o->isRenderBlock()) { if(!isCanvas()) {#ifndef NDEBUG kdDebug( 6040 ) << this << ": " << renderName() << "(RenderObject): No containingBlock!" << endl; kdDebug( 6040 ) << kdBacktrace() << endl; const RenderObject* p = this; while (p->parent()) p = p->parent(); p->printTree();#endif } return 0L; } return static_cast<RenderBlock*>( o );}short RenderObject::containingBlockWidth() const{ // ### return containingBlock()->contentWidth();}int RenderObject::containingBlockHeight() const{ // ### return containingBlock()->contentHeight();}bool RenderObject::sizesToMaxWidth() const{ // Marquees in WinIE are like a mixture of blocks and inline-blocks. They size as though they're blocks, // but they allow text to sit on the same line as the marquee. if (isFloating() || isCompact() || (isInlineBlockOrInlineTable() && !isHTMLMarquee()) || (element() && (element()->id() == ID_BUTTON || element()->id() == ID_LEGEND))) return true; // Children of a horizontal marquee do not fill the container by default. // FIXME: Need to deal with MAUTO value properly. It could be vertical. if (parent()->style()->overflow() == OMARQUEE) { EMarqueeDirection dir = parent()->style()->marqueeDirection(); if (dir == MAUTO || dir == MFORWARD || dir == MBACKWARD || dir == MLEFT || dir == MRIGHT) return true; }#ifdef APPLE_CHANGES // ### what the heck is a flexbox? // Flexible horizontal boxes lay out children at their maxwidths. Also vertical boxes // that don't stretch their kids lay out their children at their maxwidths. if (parent()->isFlexibleBox() && (parent()->style()->boxOrient() == HORIZONTAL || parent()->style()->boxAlign() != BSTRETCH)) return true;#endif return false;}// from Mozilla's nsCSSColorUtils.cppstatic int brightness(int red, int green, int blue){ int intensity = (red + green + blue) / 3; int luminosity = ((RED_LUMINOSITY * red) / 100) + ((GREEN_LUMINOSITY * green) / 100) + ((BLUE_LUMINOSITY * blue) / 100); return ((intensity * INTENSITY_FACTOR) + (luminosity * LUMINOSITY_FACTOR)) / 100;}static void calc3DColor(QColor &color, bool darken){ int rb = color.red(); int gb = color.green(); int bb = color.blue(); int brightness_ = brightness(rb,gb,bb); int f0, f1; if (brightness_ < COLOR_DARK_THRESHOLD) { f0 = COLOR_DARK_BS_FACTOR; f1 = COLOR_DARK_TS_FACTOR; } else if (brightness_ > COLOR_LIGHT_THRESHOLD) { f0 = COLOR_LITE_BS_FACTOR; f1 = COLOR_LITE_TS_FACTOR; } else { f0 = COLOR_DARK_BS_FACTOR + (brightness_ * (COLOR_LITE_BS_FACTOR - COLOR_DARK_BS_FACTOR) / MAX_COLOR); f1 = COLOR_DARK_TS_FACTOR + (brightness_ * (COLOR_LITE_TS_FACTOR - COLOR_DARK_TS_FACTOR) / MAX_COLOR); } if (darken) { int r = rb - (f0 * rb / 100); int g = gb - (f0 * gb / 100); int b = bb - (f0 * bb / 100); if ((r == rb) && (g == gb) && (b == bb)) color = (color == Qt::black) ? DARK_GRAY : Qt::black; else color.setRgb(r, g, b); } else { int r = kMin(rb + (f1 * (MAX_COLOR - rb) / 100), 255); int g = kMin(gb + (f1 * (MAX_COLOR - gb) / 100), 255); int b = kMin(bb + (f1 * (MAX_COLOR - bb) / 100), 255); if ((r == rb) && (g == gb) && (b == bb)) color = (color == Qt::white) ? LIGHT_GRAY : Qt::white; else color.setRgb(r, g, b); }}void RenderObject::drawBorder(QPainter *p, int x1, int y1, int x2, int y2, BorderSide s, QColor c, const QColor& textcolor, EBorderStyle style, int adjbw1, int adjbw2, bool invalidisInvert){ int width = (s==BSTop||s==BSBottom?y2-y1:x2-x1); if(style == DOUBLE && width < 3) style = SOLID; if(!c.isValid()) { if(invalidisInvert) { p->setRasterOp(Qt::XorROP); c = Qt::white; } else { if(style == INSET || style == OUTSET || style == RIDGE || style == GROOVE) c = Qt::white; else c = textcolor; } } switch(style) { case BNATIVE: case BNONE: case BHIDDEN: // should not happen if(invalidisInvert && p->rasterOp() == Qt::XorROP) p->setRasterOp(Qt::CopyROP); return; case DOTTED: if ( width == 1 ) { // workaround Qt brokenness p->setPen(QPen(c, width, Qt::SolidLine)); switch(s) { case BSBottom: case BSTop: for ( ; x1 < x2; x1 += 2 ) p->drawPoint( x1, y1 ); break; case BSRight: case BSLeft: for ( ; y1 < y2; y1 += 2 ) p->drawPoint( x1, y1 ); } break; } p->setPen(QPen(c, width, Qt::DotLine)); /* nobreak; */ case DASHED: if(style == DASHED) p->setPen(QPen(c, width == 1 ? 0 : width, width == 1 ? Qt::DotLine : Qt::DashLine)); if (width > 0) switch(s) { case BSBottom: case BSTop: p->drawLine(x1, (y1+y2)/2, x2, (y1+y2)/2); break; case BSRight: case BSLeft: p->drawLine((x1+x2)/2, y1, (x1+x2)/2, y2); break; } break; case DOUBLE: { int third = (width+1)/3; if (adjbw1 == 0 && adjbw2 == 0) { p->setPen(Qt::NoPen); p->setBrush(c); switch(s) { case BSTop: case BSBottom: p->drawRect(x1, y1 , x2-x1, third); p->drawRect(x1, y2-third, x2-x1, third); break; case BSLeft: p->drawRect(x1 , y1+1, third, y2-y1-1); p->drawRect(x2-third, y1+1, third, y2-y1-1); break; case BSRight: p->drawRect(x1 , y1+1, third, y2-y1-1); p->drawRect(x2-third, y1+1, third, y2-y1-1); break; } } else { int adjbw1bigthird; if (adjbw1>0) adjbw1bigthird = adjbw1+1; else adjbw1bigthird = adjbw1 - 1; adjbw1bigthird /= 3; int adjbw2bigthird; if (adjbw2>0) adjbw2bigthird = adjbw2 + 1; else adjbw2bigthird = adjbw2 - 1; adjbw2bigthird /= 3;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -