⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 renderbox.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    FloatQuad absOutlineQuad = localToAbsoluteQuad(FloatRect(box));    box = absOutlineQuad.enclosingBoundingBox();    // FIXME: layoutDelta needs to be applied in parts before/after transforms and    // repaint containers. https://bugs.webkit.org/show_bug.cgi?id=23308    box.move(view()->layoutDelta());    return box;}void RenderBox::addFocusRingRects(GraphicsContext* graphicsContext, int tx, int ty){    graphicsContext->addFocusRingRect(IntRect(tx, ty, width(), height()));}IntRect RenderBox::reflectionBox() const{    IntRect result;    if (!style()->boxReflect())        return result;    IntRect box = borderBoxRect();    result = box;    switch (style()->boxReflect()->direction()) {        case ReflectionBelow:            result.move(0, box.height() + reflectionOffset());            break;        case ReflectionAbove:            result.move(0, -box.height() - reflectionOffset());            break;        case ReflectionLeft:            result.move(-box.width() - reflectionOffset(), 0);            break;        case ReflectionRight:            result.move(box.width() + reflectionOffset(), 0);            break;    }    return result;}int RenderBox::reflectionOffset() const{    if (!style()->boxReflect())        return 0;    if (style()->boxReflect()->direction() == ReflectionLeft || style()->boxReflect()->direction() == ReflectionRight)        return style()->boxReflect()->offset().calcValue(borderBoxRect().width());    return style()->boxReflect()->offset().calcValue(borderBoxRect().height());}IntRect RenderBox::reflectedRect(const IntRect& r) const{    if (!style()->boxReflect())        return IntRect();    IntRect box = borderBoxRect();    IntRect result = r;    switch (style()->boxReflect()->direction()) {        case ReflectionBelow:            result.setY(box.bottom() + reflectionOffset() + (box.bottom() - r.bottom()));            break;        case ReflectionAbove:            result.setY(box.y() - reflectionOffset() - box.height() + (box.bottom() - r.bottom()));            break;        case ReflectionLeft:            result.setX(box.x() - reflectionOffset() - box.width() + (box.right() - r.right()));            break;        case ReflectionRight:            result.setX(box.right() + reflectionOffset() + (box.right() - r.right()));            break;    }    return result;}int RenderBox::verticalScrollbarWidth() const{    return includeVerticalScrollbarSize() ? layer()->verticalScrollbarWidth() : 0;}int RenderBox::horizontalScrollbarHeight() const{    return includeHorizontalScrollbarSize() ? layer()->horizontalScrollbarHeight() : 0;}bool RenderBox::scroll(ScrollDirection direction, ScrollGranularity granularity, float multiplier){    RenderLayer* l = layer();    if (l && l->scroll(direction, granularity, multiplier))        return true;    RenderBlock* b = containingBlock();    if (b && !b->isRenderView())        return b->scroll(direction, granularity, multiplier);    return false;}    bool RenderBox::canBeProgramaticallyScrolled(bool) const{    return (hasOverflowClip() && (scrollsOverflow() || (node() && node()->isContentEditable()))) || (node() && node()->isDocumentNode());}void RenderBox::autoscroll(){    if (layer())        layer()->autoscroll();}void RenderBox::panScroll(const IntPoint& source){    if (layer())        layer()->panScrollFromPoint(source);}int RenderBox::minPrefWidth() const{    if (prefWidthsDirty())        const_cast<RenderBox*>(this)->calcPrefWidths();            return m_minPrefWidth;}int RenderBox::maxPrefWidth() const{    if (prefWidthsDirty())        const_cast<RenderBox*>(this)->calcPrefWidths();            return m_maxPrefWidth;}int RenderBox::overrideSize() const{    if (!hasOverrideSize())        return -1;    return gOverrideSizeMap->get(this);}void RenderBox::setOverrideSize(int s){    if (s == -1) {        if (hasOverrideSize()) {            setHasOverrideSize(false);            gOverrideSizeMap->remove(this);        }    } else {        if (!gOverrideSizeMap)            gOverrideSizeMap = new OverrideSizeMap();        setHasOverrideSize(true);        gOverrideSizeMap->set(this, s);    }}int RenderBox::overrideWidth() const{    return hasOverrideSize() ? overrideSize() : width();}int RenderBox::overrideHeight() const{    return hasOverrideSize() ? overrideSize() : height();}int RenderBox::calcBorderBoxWidth(int width) const{    int bordersPlusPadding = borderLeft() + borderRight() + paddingLeft() + paddingRight();    if (style()->boxSizing() == CONTENT_BOX)        return width + bordersPlusPadding;    return max(width, bordersPlusPadding);}int RenderBox::calcBorderBoxHeight(int height) const{    int bordersPlusPadding = borderTop() + borderBottom() + paddingTop() + paddingBottom();    if (style()->boxSizing() == CONTENT_BOX)        return height + bordersPlusPadding;    return max(height, bordersPlusPadding);}int RenderBox::calcContentBoxWidth(int width) const{    if (style()->boxSizing() == BORDER_BOX)        width -= (borderLeft() + borderRight() + paddingLeft() + paddingRight());    return max(0, width);}int RenderBox::calcContentBoxHeight(int height) const{    if (style()->boxSizing() == BORDER_BOX)        height -= (borderTop() + borderBottom() + paddingTop() + paddingBottom());    return max(0, height);}// Hit Testingbool RenderBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, int xPos, int yPos, int tx, int ty, HitTestAction action){    tx += x();    ty += y();    // Check kids first.    for (RenderObject* child = lastChild(); child; child = child->previousSibling()) {        if (!child->hasLayer() && child->nodeAtPoint(request, result, xPos, yPos, tx, ty, action)) {            updateHitTestResult(result, IntPoint(xPos - tx, yPos - ty));            return true;        }    }    // Check our bounds next. For this purpose always assume that we can only be hit in the    // foreground phase (which is true for replaced elements like images).    if (visibleToHitTesting() && action == HitTestForeground && IntRect(tx, ty, width(), height()).contains(xPos, yPos)) {        updateHitTestResult(result, IntPoint(xPos - tx, yPos - ty));        return true;    }    return false;}// --------------------- painting stuff -------------------------------void RenderBox::paint(PaintInfo& paintInfo, int tx, int ty){    tx += x();    ty += y();    // default implementation. Just pass paint through to the children    PaintInfo childInfo(paintInfo);    childInfo.paintingRoot = paintingRootForChildren(paintInfo);    for (RenderObject* child = firstChild(); child; child = child->nextSibling())        child->paint(childInfo, tx, ty);}void RenderBox::paintRootBoxDecorations(PaintInfo& paintInfo, int tx, int ty){    const FillLayer* bgLayer = style()->backgroundLayers();    Color bgColor = style()->backgroundColor();    if (!style()->hasBackground() && node() && node()->hasTagName(HTMLNames::htmlTag)) {        // Locate the <body> element using the DOM.  This is easier than trying        // to crawl around a render tree with potential :before/:after content and        // anonymous blocks created by inline <body> tags etc.  We can locate the <body>        // render object very easily via the DOM.        HTMLElement* body = document()->body();        RenderObject* bodyObject = (body && body->hasLocalName(bodyTag)) ? body->renderer() : 0;        if (bodyObject) {            bgLayer = bodyObject->style()->backgroundLayers();            bgColor = bodyObject->style()->backgroundColor();        }    }    int w = width();    int h = height();    int rw;    int rh;    if (view()->frameView()) {        rw = view()->frameView()->contentsWidth();        rh = view()->frameView()->contentsHeight();    } else {        rw = view()->width();        rh = view()->height();    }    // CSS2 14.2:    // The background of the box generated by the root element covers the entire canvas including    // its margins.    int bx = tx - marginLeft();    int by = ty - marginTop();    int bw = max(w + marginLeft() + marginRight() + borderLeft() + borderRight(), rw);    int bh = max(h + marginTop() + marginBottom() + borderTop() + borderBottom(), rh);    int my = max(by, paintInfo.rect.y());    paintFillLayers(paintInfo, bgColor, bgLayer, my, paintInfo.rect.height(), bx, by, bw, bh);    if (style()->hasBorder() && style()->display() != INLINE)        paintBorder(paintInfo.context, tx, ty, w, h, style());}void RenderBox::paintBoxDecorations(PaintInfo& paintInfo, int tx, int ty){    if (!shouldPaintWithinRoot(paintInfo))        return;    if (isRoot()) {        paintRootBoxDecorations(paintInfo, tx, ty);        return;    }    int w = width();    int h = height();    // border-fit can adjust where we paint our border and background.  If set, we snugly fit our line box descendants.  (The iChat    // balloon layout is an example of this).    borderFitAdjust(tx, w);    int my = max(ty, paintInfo.rect.y());    int mh;    if (ty < paintInfo.rect.y())        mh = max(0, h - (paintInfo.rect.y() - ty));    else        mh = min(paintInfo.rect.height(), h);    // FIXME: Should eventually give the theme control over whether the box shadow should paint, since controls could have    // custom shadows of their own.    paintBoxShadow(paintInfo.context, tx, ty, w, h, style());    // If we have a native theme appearance, paint that before painting our background.    // The theme will tell us whether or not we should also paint the CSS background.    bool themePainted = style()->hasAppearance() && !theme()->paint(this, paintInfo, IntRect(tx, ty, w, h));    if (!themePainted) {        // The <body> only paints its background if the root element has defined a background        // independent of the body.  Go through the DOM to get to the root element's render object,        // since the root could be inline and wrapped in an anonymous block.        if (!isBody() || document()->documentElement()->renderer()->style()->hasBackground())            paintFillLayers(paintInfo, style()->backgroundColor(), style()->backgroundLayers(), my, mh, tx, ty, w, h);        if (style()->hasAppearance())            theme()->paintDecorations(this, paintInfo, IntRect(tx, ty, w, h));    }    // The theme will tell us whether or not we should also paint the CSS border.    if ((!style()->hasAppearance() || (!themePainted && theme()->paintBorderOnly(this, paintInfo, IntRect(tx, ty, w, h)))) && style()->hasBorder())        paintBorder(paintInfo.context, tx, ty, w, h, style());}void RenderBox::paintMask(PaintInfo& paintInfo, int tx, int ty){    if (!shouldPaintWithinRoot(paintInfo) || style()->visibility() != VISIBLE || paintInfo.phase != PaintPhaseMask)        return;    int w = width();    int h = height();    // border-fit can adjust where we paint our border and background.  If set, we snugly fit our line box descendants.  (The iChat    // balloon layout is an example of this).    borderFitAdjust(tx, w);    int my = max(ty, paintInfo.rect.y());    int mh;    if (ty < paintInfo.rect.y())        mh = max(0, h - (paintInfo.rect.y() - ty));    else        mh = min(paintInfo.rect.height(), h);    paintMaskImages(paintInfo, my, mh, tx, ty, w, h);}void RenderBox::paintMaskImages(const PaintInfo& paintInfo, int my, int mh, int tx, int ty, int w, int h){    // Figure out if we need to push a transparency layer to render our mask.    bool pushTransparencyLayer = false;    StyleImage* maskBoxImage = style()->maskBoxImage().image();    if ((maskBoxImage && style()->maskLayers()->hasImage()) || style()->maskLayers()->next())

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -