diff options
author | Steve Block <steveblock@google.com> | 2010-02-02 14:57:50 +0000 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2010-02-04 15:06:55 +0000 |
commit | d0825bca7fe65beaee391d30da42e937db621564 (patch) | |
tree | 7461c49eb5844ffd1f35d1ba2c8b7584c1620823 /WebCore/rendering/RenderSVGImage.cpp | |
parent | 3db770bd97c5a59b6c7574ca80a39e5a51c1defd (diff) | |
download | external_webkit-d0825bca7fe65beaee391d30da42e937db621564.zip external_webkit-d0825bca7fe65beaee391d30da42e937db621564.tar.gz external_webkit-d0825bca7fe65beaee391d30da42e937db621564.tar.bz2 |
Merge webkit.org at r54127 : Initial merge by git
Change-Id: Ib661abb595522f50ea406f72d3a0ce17f7193c82
Diffstat (limited to 'WebCore/rendering/RenderSVGImage.cpp')
-rw-r--r-- | WebCore/rendering/RenderSVGImage.cpp | 124 |
1 files changed, 35 insertions, 89 deletions
diff --git a/WebCore/rendering/RenderSVGImage.cpp b/WebCore/rendering/RenderSVGImage.cpp index 41a1a10..c8fb132 100644 --- a/WebCore/rendering/RenderSVGImage.cpp +++ b/WebCore/rendering/RenderSVGImage.cpp @@ -4,6 +4,7 @@ Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> Copyright (C) 2007, 2008, 2009 Rob Buis <buis@kde.org> Copyright (C) 2009, Google, Inc. + Copyright (C) 2009 Dirk Schulze <krit@webkit.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -47,81 +48,6 @@ RenderSVGImage::RenderSVGImage(SVGImageElement* impl) { } -void RenderSVGImage::adjustRectsForAspectRatio(FloatRect& destRect, FloatRect& srcRect, SVGPreserveAspectRatio* aspectRatio) -{ - float origDestWidth = destRect.width(); - float origDestHeight = destRect.height(); - if (aspectRatio->meetOrSlice() == SVGPreserveAspectRatio::SVG_MEETORSLICE_MEET) { - float widthToHeightMultiplier = srcRect.height() / srcRect.width(); - if (origDestHeight > (origDestWidth * widthToHeightMultiplier)) { - destRect.setHeight(origDestWidth * widthToHeightMultiplier); - switch (aspectRatio->align()) { - case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMID: - case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID: - case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID: - destRect.setY(destRect.y() + origDestHeight / 2.0f - destRect.height() / 2.0f); - break; - case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMAX: - case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX: - case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX: - destRect.setY(destRect.y() + origDestHeight - destRect.height()); - break; - } - } - if (origDestWidth > (origDestHeight / widthToHeightMultiplier)) { - destRect.setWidth(origDestHeight / widthToHeightMultiplier); - switch (aspectRatio->align()) { - case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMIN: - case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID: - case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX: - destRect.setX(destRect.x() + origDestWidth / 2.0f - destRect.width() / 2.0f); - break; - case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMIN: - case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID: - case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX: - destRect.setX(destRect.x() + origDestWidth - destRect.width()); - break; - } - } - } else if (aspectRatio->meetOrSlice() == SVGPreserveAspectRatio::SVG_MEETORSLICE_SLICE) { - float widthToHeightMultiplier = srcRect.height() / srcRect.width(); - // if the destination height is less than the height of the image we'll be drawing - if (origDestHeight < (origDestWidth * widthToHeightMultiplier)) { - float destToSrcMultiplier = srcRect.width() / destRect.width(); - srcRect.setHeight(destRect.height() * destToSrcMultiplier); - switch (aspectRatio->align()) { - case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMID: - case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID: - case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID: - srcRect.setY(destRect.y() + image()->height() / 2.0f - srcRect.height() / 2.0f); - break; - case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMAX: - case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX: - case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX: - srcRect.setY(destRect.y() + image()->height() - srcRect.height()); - break; - } - } - // if the destination width is less than the width of the image we'll be drawing - if (origDestWidth < (origDestHeight / widthToHeightMultiplier)) { - float destToSrcMultiplier = srcRect.height() / destRect.height(); - srcRect.setWidth(destRect.width() * destToSrcMultiplier); - switch (aspectRatio->align()) { - case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMIN: - case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID: - case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX: - srcRect.setX(destRect.x() + image()->width() / 2.0f - srcRect.width() / 2.0f); - break; - case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMIN: - case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID: - case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX: - srcRect.setX(destRect.x() + image()->width() - srcRect.width()); - break; - } - } - } -} - void RenderSVGImage::layout() { ASSERT(needsLayout()); @@ -138,6 +64,7 @@ void RenderSVGImage::layout() calcHeight(); m_localBounds = FloatRect(image->x().value(image), image->y().value(image), image->width().value(image), image->height().value(image)); + m_cachedLocalRepaintRect = FloatRect(); repainter.repaintAfterLayout(); @@ -157,16 +84,16 @@ void RenderSVGImage::paint(PaintInfo& paintInfo, int, int) PaintInfo savedInfo(paintInfo); - prepareToRenderSVGContent(this, paintInfo, m_localBounds, filter); + if (prepareToRenderSVGContent(this, paintInfo, m_localBounds, filter)) { + FloatRect destRect = m_localBounds; + FloatRect srcRect(0, 0, image()->width(), image()->height()); - FloatRect destRect = m_localBounds; - FloatRect srcRect(0, 0, image()->width(), image()->height()); + SVGImageElement* imageElt = static_cast<SVGImageElement*>(node()); + if (imageElt->preserveAspectRatio().align() != SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_NONE) + imageElt->preserveAspectRatio().transformRect(destRect, srcRect); - SVGImageElement* imageElt = static_cast<SVGImageElement*>(node()); - if (imageElt->preserveAspectRatio()->align() != SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_NONE) - adjustRectsForAspectRatio(destRect, srcRect, imageElt->preserveAspectRatio()); - - paintInfo.context->drawImage(image(), DeviceColorSpace, destRect, srcRect); + paintInfo.context->drawImage(image(), DeviceColorSpace, destRect, srcRect); + } finishRenderSVGContent(this, paintInfo, filter, savedInfo.context); } @@ -212,12 +139,29 @@ FloatRect RenderSVGImage::objectBoundingBox() const FloatRect RenderSVGImage::repaintRectInLocalCoordinates() const { - FloatRect repaintRect = m_localBounds; + // If we already have a cached repaint rect, return that + if (!m_cachedLocalRepaintRect.isEmpty()) + return m_cachedLocalRepaintRect; + + m_cachedLocalRepaintRect = m_localBounds; + + // FIXME: We need to be careful here. We assume that there is no filter, + // clipper or masker if the rects are empty. + FloatRect rect = filterBoundingBoxForRenderer(this); + if (!rect.isEmpty()) + m_cachedLocalRepaintRect = rect; + + rect = clipperBoundingBoxForRenderer(this); + if (!rect.isEmpty()) + m_cachedLocalRepaintRect.intersect(rect); + + rect = maskerBoundingBoxForRenderer(this); + if (!rect.isEmpty()) + m_cachedLocalRepaintRect.intersect(rect); - // Filters can paint outside the image content - repaintRect.unite(filterBoundingBoxForRenderer(this)); + style()->svgStyle()->inflateForShadow(m_cachedLocalRepaintRect); - return repaintRect; + return m_cachedLocalRepaintRect; } void RenderSVGImage::imageChanged(WrappedImagePtr image, const IntRect* rect) @@ -233,6 +177,7 @@ IntRect RenderSVGImage::clippedOverflowRectForRepaint(RenderBoxModelObject* repa void RenderSVGImage::computeRectForRepaint(RenderBoxModelObject* repaintContainer, IntRect& repaintRect, bool fixed) { + style()->svgStyle()->inflateForShadow(repaintRect); SVGRenderBase::computeRectForRepaint(this, repaintContainer, repaintRect, fixed); } @@ -241,11 +186,12 @@ void RenderSVGImage::mapLocalToContainer(RenderBoxModelObject* repaintContainer, SVGRenderBase::mapLocalToContainer(this, repaintContainer, fixed, useTransforms, transformState); } -void RenderSVGImage::addFocusRingRects(GraphicsContext* graphicsContext, int, int) +void RenderSVGImage::addFocusRingRects(Vector<IntRect>& rects, int, int) { // this is called from paint() after the localTransform has already been applied IntRect contentRect = enclosingIntRect(repaintRectInLocalCoordinates()); - graphicsContext->addFocusRingRect(contentRect); + if (!contentRect.isEmpty()) + rects.append(contentRect); } void RenderSVGImage::absoluteRects(Vector<IntRect>& rects, int, int) |