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

📄 renderobject.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                        break;                    case BSLeft:                        graphicsContext->drawRect(IntRect(x1, y1 + 1, third, y2 - y1 - 1));                        graphicsContext->drawRect(IntRect(x2 - third, y1 + 1, third, y2 - y1 - 1));                        break;                    case BSRight:                        graphicsContext->drawRect(IntRect(x1, y1 + 1, third, y2 - y1 - 1));                        graphicsContext->drawRect(IntRect(x2 - third, y1 + 1, third, y2 - y1 - 1));                        break;                }            } else {                int adjbw1bigthird = ((adjbw1 > 0) ? adjbw1 + 1 : adjbw1 - 1) / 3;                int adjbw2bigthird = ((adjbw2 > 0) ? adjbw2 + 1 : adjbw2 - 1) / 3;                switch (s) {                    case BSTop:                        drawLineForBoxSide(graphicsContext, x1 + max((-adjbw1 * 2 + 1) / 3, 0),                                   y1, x2 - max((-adjbw2 * 2 + 1) / 3, 0), y1 + third,                                   s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);                        drawLineForBoxSide(graphicsContext, x1 + max((adjbw1 * 2 + 1) / 3, 0),                                   y2 - third, x2 - max((adjbw2 * 2 + 1) / 3, 0), y2,                                   s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);                        break;                    case BSLeft:                        drawLineForBoxSide(graphicsContext, x1, y1 + max((-adjbw1 * 2 + 1) / 3, 0),                                   x1 + third, y2 - max((-adjbw2 * 2 + 1) / 3, 0),                                   s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);                        drawLineForBoxSide(graphicsContext, x2 - third, y1 + max((adjbw1 * 2 + 1) / 3, 0),                                   x2, y2 - max((adjbw2 * 2 + 1) / 3, 0),                                   s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);                        break;                    case BSBottom:                        drawLineForBoxSide(graphicsContext, x1 + max((adjbw1 * 2 + 1) / 3, 0),                                   y1, x2 - max((adjbw2 * 2 + 1) / 3, 0), y1 + third,                                   s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);                        drawLineForBoxSide(graphicsContext, x1 + max((-adjbw1 * 2 + 1) / 3, 0),                                   y2 - third, x2 - max((-adjbw2 * 2 + 1) / 3, 0), y2,                                   s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);                        break;                    case BSRight:                        drawLineForBoxSide(graphicsContext, x1, y1 + max((adjbw1 * 2 + 1) / 3, 0),                                   x1 + third, y2 - max(( adjbw2 * 2 + 1) / 3, 0),                                   s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);                        drawLineForBoxSide(graphicsContext, x2 - third, y1 + max((-adjbw1 * 2 + 1) / 3, 0),                                   x2, y2 - max((-adjbw2 * 2 + 1) / 3, 0),                                   s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);                        break;                    default:                        break;                }            }            break;        }        case RIDGE:        case GROOVE:        {            EBorderStyle s1;            EBorderStyle s2;            if (style == GROOVE) {                s1 = INSET;                s2 = OUTSET;            } else {                s1 = OUTSET;                s2 = INSET;            }            int adjbw1bighalf = ((adjbw1 > 0) ? adjbw1 + 1 : adjbw1 - 1) / 2;            int adjbw2bighalf = ((adjbw2 > 0) ? adjbw2 + 1 : adjbw2 - 1) / 2;            switch (s) {                case BSTop:                    drawLineForBoxSide(graphicsContext, x1 + max(-adjbw1, 0) / 2, y1, x2 - max(-adjbw2, 0) / 2, (y1 + y2 + 1) / 2,                               s, c, textcolor, s1, adjbw1bighalf, adjbw2bighalf);                    drawLineForBoxSide(graphicsContext, x1 + max(adjbw1 + 1, 0) / 2, (y1 + y2 + 1) / 2, x2 - max(adjbw2 + 1, 0) / 2, y2,                               s, c, textcolor, s2, adjbw1 / 2, adjbw2 / 2);                    break;                case BSLeft:                    drawLineForBoxSide(graphicsContext, x1, y1 + max(-adjbw1, 0) / 2, (x1 + x2 + 1) / 2, y2 - max(-adjbw2, 0) / 2,                               s, c, textcolor, s1, adjbw1bighalf, adjbw2bighalf);                    drawLineForBoxSide(graphicsContext, (x1 + x2 + 1) / 2, y1 + max(adjbw1 + 1, 0) / 2, x2, y2 - max(adjbw2 + 1, 0) / 2,                               s, c, textcolor, s2, adjbw1 / 2, adjbw2 / 2);                    break;                case BSBottom:                    drawLineForBoxSide(graphicsContext, x1 + max(adjbw1, 0) / 2, y1, x2 - max(adjbw2, 0) / 2, (y1 + y2 + 1) / 2,                               s, c, textcolor, s2, adjbw1bighalf, adjbw2bighalf);                    drawLineForBoxSide(graphicsContext, x1 + max(-adjbw1 + 1, 0) / 2, (y1 + y2 + 1) / 2, x2 - max(-adjbw2 + 1, 0) / 2, y2,                               s, c, textcolor, s1, adjbw1/2, adjbw2/2);                    break;                case BSRight:                    drawLineForBoxSide(graphicsContext, x1, y1 + max(adjbw1, 0) / 2, (x1 + x2 + 1) / 2, y2 - max(adjbw2, 0) / 2,                               s, c, textcolor, s2, adjbw1bighalf, adjbw2bighalf);                    drawLineForBoxSide(graphicsContext, (x1 + x2 + 1) / 2, y1 + max(-adjbw1 + 1, 0) / 2, x2, y2 - max(-adjbw2 + 1, 0) / 2,                               s, c, textcolor, s1, adjbw1/2, adjbw2/2);                    break;            }            break;        }        case INSET:            if (s == BSTop || s == BSLeft)                c = c.dark();            // fall through        case OUTSET:            if (style == OUTSET && (s == BSBottom || s == BSRight))                c = c.dark();            // fall through        case SOLID: {            graphicsContext->setStrokeStyle(NoStroke);            graphicsContext->setFillColor(c);            ASSERT(x2 >= x1);            ASSERT(y2 >= y1);            if (!adjbw1 && !adjbw2) {                graphicsContext->drawRect(IntRect(x1, y1, x2 - x1, y2 - y1));                return;            }            FloatPoint quad[4];            switch (s) {                case BSTop:                    quad[0] = FloatPoint(x1 + max(-adjbw1, 0), y1);                    quad[1] = FloatPoint(x1 + max(adjbw1, 0), y2);                    quad[2] = FloatPoint(x2 - max(adjbw2, 0), y2);                    quad[3] = FloatPoint(x2 - max(-adjbw2, 0), y1);                    break;                case BSBottom:                    quad[0] = FloatPoint(x1 + max(adjbw1, 0), y1);                    quad[1] = FloatPoint(x1 + max(-adjbw1, 0), y2);                    quad[2] = FloatPoint(x2 - max(-adjbw2, 0), y2);                    quad[3] = FloatPoint(x2 - max(adjbw2, 0), y1);                    break;                case BSLeft:                    quad[0] = FloatPoint(x1, y1 + max(-adjbw1, 0));                    quad[1] = FloatPoint(x1, y2 - max(-adjbw2, 0));                    quad[2] = FloatPoint(x2, y2 - max(adjbw2, 0));                    quad[3] = FloatPoint(x2, y1 + max(adjbw1, 0));                    break;                case BSRight:                    quad[0] = FloatPoint(x1, y1 + max(adjbw1, 0));                    quad[1] = FloatPoint(x1, y2 - max(adjbw2, 0));                    quad[2] = FloatPoint(x2, y2 - max(-adjbw2, 0));                    quad[3] = FloatPoint(x2, y1 + max(-adjbw1, 0));                    break;            }            graphicsContext->drawConvexPolygon(4, quad);            break;        }    }}void RenderObject::drawArcForBoxSide(GraphicsContext* graphicsContext, int x, int y, float thickness, IntSize radius,                                     int angleStart, int angleSpan, BoxSide s, Color c, const Color& textColor,                                     EBorderStyle style, bool firstCorner){    if ((style == DOUBLE && thickness / 2 < 3) || ((style == RIDGE || style == GROOVE) && thickness / 2 < 2))        style = SOLID;    if (!c.isValid()) {        if (style == INSET || style == OUTSET || style == RIDGE || style == GROOVE)            c.setRGB(238, 238, 238);        else            c = textColor;    }    switch (style) {        case BNONE:        case BHIDDEN:            return;        case DOTTED:        case DASHED:            graphicsContext->setStrokeColor(c);            graphicsContext->setStrokeStyle(style == DOTTED ? DottedStroke : DashedStroke);            graphicsContext->setStrokeThickness(thickness);            graphicsContext->strokeArc(IntRect(x, y, radius.width() * 2, radius.height() * 2), angleStart, angleSpan);            break;        case DOUBLE: {            float third = thickness / 3.0f;            float innerThird = (thickness + 1.0f) / 6.0f;            int shiftForInner = static_cast<int>(innerThird * 2.5f);            int outerY = y;            int outerHeight = radius.height() * 2;            int innerX = x + shiftForInner;            int innerY = y + shiftForInner;            int innerWidth = (radius.width() - shiftForInner) * 2;            int innerHeight = (radius.height() - shiftForInner) * 2;            if (innerThird > 1 && (s == BSTop || (firstCorner && (s == BSLeft || s == BSRight)))) {                outerHeight += 2;                innerHeight += 2;            }            graphicsContext->setStrokeStyle(SolidStroke);            graphicsContext->setStrokeColor(c);            graphicsContext->setStrokeThickness(third);            graphicsContext->strokeArc(IntRect(x, outerY, radius.width() * 2, outerHeight), angleStart, angleSpan);            graphicsContext->setStrokeThickness(innerThird > 2 ? innerThird - 1 : innerThird);            graphicsContext->strokeArc(IntRect(innerX, innerY, innerWidth, innerHeight), angleStart, angleSpan);            break;        }        case GROOVE:        case RIDGE: {            Color c2;            if ((style == RIDGE && (s == BSTop || s == BSLeft)) ||                    (style == GROOVE && (s == BSBottom || s == BSRight)))                c2 = c.dark();            else {                c2 = c;                c = c.dark();            }            graphicsContext->setStrokeStyle(SolidStroke);            graphicsContext->setStrokeColor(c);            graphicsContext->setStrokeThickness(thickness);            graphicsContext->strokeArc(IntRect(x, y, radius.width() * 2, radius.height() * 2), angleStart, angleSpan);            float halfThickness = (thickness + 1.0f) / 4.0f;            int shiftForInner = static_cast<int>(halfThickness * 1.5f);            graphicsContext->setStrokeColor(c2);            graphicsContext->setStrokeThickness(halfThickness > 2 ? halfThickness - 1 : halfThickness);            graphicsContext->strokeArc(IntRect(x + shiftForInner, y + shiftForInner, (radius.width() - shiftForInner) * 2,                                       (radius.height() - shiftForInner) * 2), angleStart, angleSpan);            break;        }        case INSET:            if (s == BSTop || s == BSLeft)                c = c.dark();        case OUTSET:            if (style == OUTSET && (s == BSBottom || s == BSRight))                c = c.dark();        case SOLID:            graphicsContext->setStrokeStyle(SolidStroke);            graphicsContext->setStrokeColor(c);            graphicsContext->setStrokeThickness(thickness);            graphicsContext->strokeArc(IntRect(x, y, radius.width() * 2, radius.height() * 2), angleStart, angleSpan);            break;    }}void RenderObject::addPDFURLRect(GraphicsContext* context, const IntRect& rect){    if (rect.isEmpty())        return;    Node* n = node();    if (!n || !n->isLink() || !n->isElementNode())        return;    const AtomicString& href = static_cast<Element*>(n)->getAttribute(hrefAttr);    if (href.isNull())        return;    context->setURLForRect(n->document()->completeURL(href), rect);}void RenderObject::paintOutline(GraphicsContext* graphicsContext, int tx, int ty, int w, int h, const RenderStyle* style){    if (!hasOutline())        return;    int ow = style->outlineWidth();    EBorderStyle os = style->outlineStyle();    Color oc = style->outlineColor();    if (!oc.isValid())        oc = style->color();    int offset = style->outlineOffset();    if (style->outlineStyleIsAuto() || hasOutlineAnnotation()) {        if (!theme()->supportsFocusRing(style)) {            // Only paint the focus ring by hand if the theme isn't able to draw the focus ring.            graphicsContext->initFocusRing(ow, offset);            addFocusRingRects(graphicsContext, tx, ty);            if (style->outlineStyleIsAuto())                graphicsContext->drawFocusRing(oc);            else                addPDFURLRect(graphicsContext, graphicsContext->focusRingBoundingRect());            graphicsContext->clearFocusRing();        }    }    if (style->outlineStyleIsAuto() || style->outlineStyle() == BNONE)        return;    tx -= offset;    ty -= offset;    w += 2 * offset;    h += 2 * offset;    if (h < 0 || w < 0)        return;    drawLineForBoxSide(graphicsContext, tx - ow, ty - ow, tx, ty + h + ow,               BSLeft, Color(oc), style->color(), os, ow, ow);    drawLineForBoxSide(graphicsContext, tx - ow, ty - ow, tx + w + ow, ty,               BSTop, Color(oc), style->color(), os, ow, ow);    drawLineForBoxSide(graphicsContext, tx + w, ty - ow, tx + w + ow, ty + h + ow,               BSRight, Color(oc), style->color(), os, ow, ow);    drawLineForBoxSide(graphicsContext, tx - ow, ty + h, tx + w + ow, ty + h + ow,               BSBottom, Color(oc), style->color(), os, ow, ow);}void RenderObject::absoluteRectsForRange(Vector<IntRect>& rects, unsigned start, unsigned end, bool){    if (!firstChild()) {        if ((isInline() || isAnonymousBlock())) {            FloatPoint absPos = localToAbsolute(FloatPoint());            absoluteRects(rects, absPos.x(), absPos.y());        }        return;    }    unsigned offset = start;    for (RenderObject* child = childAt(start); child && offset < end; child = child->nextSibling(), ++offset) {        if (child->isText() || child->isInline() || child->isAnonymousBlock()) {            FloatPoint absPos = child->localToAbsolute(FloatPoint());            child->absoluteRects(rects, absPos.x(), absPos.y());        }    }}void RenderObject::absoluteQuadsForRange(Vector<FloatQuad>& quads, unsigned start, unsigned end, bool){    if (!firstChild()) {        if (isInline() || isAnonymousBlock())            absoluteQuads(quads);        return;    }    unsigned offset = start;    for (RenderObject* child = childAt(start); child && offset < end; child = child->nextSibling(), ++offset) {        if (child->isText() || child->isInline() || child->isAnonymousBlock())            child->absoluteQuads(quads);    }}IntRect RenderObject::absoluteBoundingBoxRect(bool useTransforms){    if (useTransforms) {        Vector<FloatQuad> quads;        absoluteQuads(quads);        size_t n = quads.size();        if (!n)            return IntRect();            IntRect result = quads[0].enclosingBoundingBox();        for (size_t i = 1; i < n; ++i)            result.unite(quads[i].enclosingBoundingBox());        return result;    }    FloatPoint absPos = localToAbsolute();    Vector<IntRect> rects;    absoluteRects(rects, absPos.x(), absPos.y());

⌨️ 快捷键说明

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