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

📄 renderimage.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 2 页
字号:
            if (imageSizeChanged || width() != oldwidth || height() != oldheight) {                shouldRepaint = false;                if (!selfNeedsLayout())                    setNeedsLayout(true);            }            setWidth(oldwidth);            setHeight(oldheight);        }    }    if (shouldRepaint) {        IntRect repaintRect;        if (rect) {            // The image changed rect is in source image coordinates (pre-zooming),            // so map from the bounds of the image to the contentsBox.            repaintRect = enclosingIntRect(mapRect(*rect, FloatRect(FloatPoint(), imageSize(1.0f)), contentBoxRect()));            // Guard against too-large changed rects.            repaintRect.intersect(contentBoxRect());        } else            repaintRect = contentBoxRect();                repaintRectangle(repaintRect);    }}void RenderImage::resetAnimation(){    if (m_cachedImage) {        image()->resetAnimation();        if (!needsLayout())            repaint();    }}void RenderImage::paintReplaced(PaintInfo& paintInfo, int tx, int ty){    int cWidth = contentWidth();    int cHeight = contentHeight();    int leftBorder = borderLeft();    int topBorder = borderTop();    int leftPad = paddingLeft();    int topPad = paddingTop();    if (document()->printing() && !view()->printImages())        return;    GraphicsContext* context = paintInfo.context;    if (!hasImage() || errorOccurred()) {        if (paintInfo.phase == PaintPhaseSelection)            return;        if (cWidth > 2 && cHeight > 2) {            // Draw an outline rect where the image should be.            context->setStrokeStyle(SolidStroke);            context->setStrokeColor(Color::lightGray);            context->setFillColor(Color::transparent);            context->drawRect(IntRect(tx + leftBorder + leftPad, ty + topBorder + topPad, cWidth, cHeight));            bool errorPictureDrawn = false;            int imageX = 0;            int imageY = 0;            // When calculating the usable dimensions, exclude the pixels of            // the ouline rect so the error image/alt text doesn't draw on it.            int usableWidth = cWidth - 2;            int usableHeight = cHeight - 2;            if (errorOccurred() && !image()->isNull() && (usableWidth >= image()->width()) && (usableHeight >= image()->height())) {                // Center the error image, accounting for border and padding.                int centerX = (usableWidth - image()->width()) / 2;                if (centerX < 0)                    centerX = 0;                int centerY = (usableHeight - image()->height()) / 2;                if (centerY < 0)                    centerY = 0;                imageX = leftBorder + leftPad + centerX + 1;                imageY = topBorder + topPad + centerY + 1;                context->drawImage(image(), IntPoint(tx + imageX, ty + imageY));                errorPictureDrawn = true;            }            if (!m_altText.isEmpty()) {                String text = document()->displayStringModifiedByEncoding(m_altText);                context->setFillColor(style()->color());                int ax = tx + leftBorder + leftPad;                int ay = ty + topBorder + topPad;                const Font& font = style()->font();                int ascent = font.ascent();                // Only draw the alt text if it'll fit within the content box,                // and only if it fits above the error image.                TextRun textRun(text.characters(), text.length());                int textWidth = font.width(textRun);                if (errorPictureDrawn) {                    if (usableWidth >= textWidth && font.height() <= imageY)                        context->drawText(style()->font(), textRun, IntPoint(ax, ay + ascent));                } else if (usableWidth >= textWidth && cHeight >= font.height())                    context->drawText(style()->font(), textRun, IntPoint(ax, ay + ascent));            }        }    } else if (hasImage() && cWidth > 0 && cHeight > 0) {        Image* img = image(cWidth, cHeight);        if (!img || img->isNull())            return;#if PLATFORM(MAC)        if (style()->highlight() != nullAtom && !paintInfo.context->paintingDisabled())            paintCustomHighlight(tx - x(), ty - y(), style()->highlight(), true);#endif        IntSize contentSize(cWidth, cHeight);        bool useLowQualityScaling = RenderImageScaleObserver::shouldImagePaintAtLowQuality(this, contentSize);        IntRect rect(IntPoint(tx + leftBorder + leftPad, ty + topBorder + topPad), contentSize);        HTMLImageElement* imageElt = (node() && node()->hasTagName(imgTag)) ? static_cast<HTMLImageElement*>(node()) : 0;        CompositeOperator compositeOperator = imageElt ? imageElt->compositeOperator() : CompositeSourceOver;        context->drawImage(image(cWidth, cHeight), rect, compositeOperator, useLowQualityScaling);    }}int RenderImage::minimumReplacedHeight() const{    return errorOccurred() ? intrinsicSize().height() : 0;}HTMLMapElement* RenderImage::imageMap(){    HTMLImageElement* i = node() && node()->hasTagName(imgTag) ? static_cast<HTMLImageElement*>(node()) : 0;    return i ? i->document()->getImageMap(i->useMap()) : 0;}bool RenderImage::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, int _x, int _y, int _tx, int _ty, HitTestAction hitTestAction){    bool inside = RenderReplaced::nodeAtPoint(request, result, _x, _y, _tx, _ty, hitTestAction);    if (inside && node()) {        int tx = _tx + x();        int ty = _ty + y();                HTMLMapElement* map = imageMap();        if (map) {            // we're a client side image map            inside = map->mapMouseEvent(_x - tx, _y - ty, IntSize(contentWidth(), contentHeight()), result);            result.setInnerNonSharedNode(node());        }    }    return inside;}void RenderImage::updateAltText(){    if (!node())        return;    if (node()->hasTagName(inputTag))        m_altText = static_cast<HTMLInputElement*>(node())->altText();    else if (node()->hasTagName(imgTag))        m_altText = static_cast<HTMLImageElement*>(node())->altText();#if ENABLE(WML)    else if (node()->hasTagName(WMLNames::imgTag))        m_altText = static_cast<WMLImageElement*>(node())->altText();#endif}bool RenderImage::isWidthSpecified() const{    switch (style()->width().type()) {        case Fixed:        case Percent:            return true;        case Auto:        case Relative: // FIXME: Shouldn't this case return true?        case Static:        case Intrinsic:        case MinIntrinsic:            return false;    }    ASSERT(false);    return false;}bool RenderImage::isHeightSpecified() const{    switch (style()->height().type()) {        case Fixed:        case Percent:            return true;        case Auto:        case Relative: // FIXME: Shouldn't this case return true?        case Static:        case Intrinsic:        case MinIntrinsic:            return false;    }    ASSERT(false);    return false;}int RenderImage::calcReplacedWidth(bool includeMaxWidth) const{    if (imageHasRelativeWidth())        if (RenderObject* cb = isPositioned() ? container() : containingBlock()) {            if (cb->isBox())                setImageContainerSize(IntSize(toRenderBox(cb)->availableWidth(), toRenderBox(cb)->availableHeight()));        }    int width;    if (isWidthSpecified())        width = calcReplacedWidthUsing(style()->width());    else if (usesImageContainerSize())        width = imageSize(style()->effectiveZoom()).width();    else if (imageHasRelativeWidth())        width = 0; // If the image is relatively-sized, set the width to 0 until there is a set container size.    else        width = calcAspectRatioWidth();    int minW = calcReplacedWidthUsing(style()->minWidth());    int maxW = !includeMaxWidth || style()->maxWidth().isUndefined() ? width : calcReplacedWidthUsing(style()->maxWidth());    return max(minW, min(width, maxW));}int RenderImage::calcReplacedHeight() const{    int height;    if (isHeightSpecified())        height = calcReplacedHeightUsing(style()->height());    else if (usesImageContainerSize())        height = imageSize(style()->effectiveZoom()).height();    else if (imageHasRelativeHeight())        height = 0; // If the image is relatively-sized, set the height to 0 until there is a set container size.    else        height = calcAspectRatioHeight();    int minH = calcReplacedHeightUsing(style()->minHeight());    int maxH = style()->maxHeight().isUndefined() ? height : calcReplacedHeightUsing(style()->maxHeight());    return max(minH, min(height, maxH));}int RenderImage::calcAspectRatioWidth() const{    IntSize size = intrinsicSize();    if (!size.height())        return 0;    if (!hasImage() || errorOccurred())        return size.width(); // Don't bother scaling.    return RenderReplaced::calcReplacedHeight() * size.width() / size.height();}int RenderImage::calcAspectRatioHeight() const{    IntSize size = intrinsicSize();    if (!size.width())        return 0;    if (!hasImage() || errorOccurred())        return size.height(); // Don't bother scaling.    return RenderReplaced::calcReplacedWidth() * size.height() / size.width();}void RenderImage::calcPrefWidths(){    ASSERT(prefWidthsDirty());    int paddingAndBorders = paddingLeft() + paddingRight() + borderLeft() + borderRight();    m_maxPrefWidth = calcReplacedWidth(false) + paddingAndBorders;    if (style()->maxWidth().isFixed() && style()->maxWidth().value() != undefinedLength)        m_maxPrefWidth = min(m_maxPrefWidth, style()->maxWidth().value() + (style()->boxSizing() == CONTENT_BOX ? paddingAndBorders : 0));    if (style()->width().isPercent() || style()->height().isPercent() ||         style()->maxWidth().isPercent() || style()->maxHeight().isPercent() ||        style()->minWidth().isPercent() || style()->minHeight().isPercent())        m_minPrefWidth = 0;    else        m_minPrefWidth = m_maxPrefWidth;    setPrefWidthsDirty(false);}Image* RenderImage::nullImage(){    return Image::nullImage();}} // namespace WebCore

⌨️ 快捷键说明

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