This source file includes following definitions.
- m_imageResource
- updateImageViewport
- layout
- paint
- paintForeground
- invalidateBufferedForeground
- nodeAtFloatPoint
- imageChanged
- addFocusRingRects
#include "config.h"
#include "core/rendering/svg/RenderSVGImage.h"
#include "core/rendering/GraphicsContextAnnotator.h"
#include "core/rendering/ImageQualityController.h"
#include "core/rendering/LayoutRectRecorder.h"
#include "core/rendering/LayoutRepainter.h"
#include "core/rendering/PointerEventsHitRules.h"
#include "core/rendering/RenderImageResource.h"
#include "core/rendering/svg/RenderSVGResource.h"
#include "core/rendering/svg/SVGRenderingContext.h"
#include "core/rendering/svg/SVGResources.h"
#include "core/rendering/svg/SVGResourcesCache.h"
#include "core/svg/SVGImageElement.h"
#include "platform/graphics/GraphicsContextStateSaver.h"
namespace WebCore {
RenderSVGImage::RenderSVGImage(SVGImageElement* impl)
: RenderSVGModelObject(impl)
, m_needsBoundariesUpdate(true)
, m_needsTransformUpdate(true)
, m_imageResource(RenderImageResource::create())
{
m_imageResource->initialize(this);
}
RenderSVGImage::~RenderSVGImage()
{
ImageQualityController::remove(this);
m_imageResource->shutdown();
}
bool RenderSVGImage::updateImageViewport()
{
SVGImageElement* image = toSVGImageElement(element());
FloatRect oldBoundaries = m_objectBoundingBox;
bool updatedViewport = false;
SVGLengthContext lengthContext(image);
m_objectBoundingBox = FloatRect(image->x()->currentValue()->value(lengthContext), image->y()->currentValue()->value(lengthContext), image->width()->currentValue()->value(lengthContext), image->height()->currentValue()->value(lengthContext));
if (image->preserveAspectRatio()->currentValue()->align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_NONE) {
if (ImageResource* cachedImage = m_imageResource->cachedImage()) {
LayoutSize intrinsicSize = cachedImage->imageSizeForRenderer(0, style()->effectiveZoom());
if (intrinsicSize != m_imageResource->imageSize(style()->effectiveZoom())) {
m_imageResource->setContainerSizeForRenderer(roundedIntSize(intrinsicSize));
updatedViewport = true;
}
}
}
if (oldBoundaries != m_objectBoundingBox) {
if (!updatedViewport)
m_imageResource->setContainerSizeForRenderer(enclosingIntRect(m_objectBoundingBox).size());
updatedViewport = true;
m_needsBoundariesUpdate = true;
}
return updatedViewport;
}
void RenderSVGImage::layout()
{
ASSERT(needsLayout());
LayoutRectRecorder recorder(*this);
LayoutRepainter repainter(*this, SVGRenderSupport::checkForSVGRepaintDuringLayout(this) && selfNeedsLayout());
updateImageViewport();
bool transformOrBoundariesUpdate = m_needsTransformUpdate || m_needsBoundariesUpdate;
if (m_needsTransformUpdate) {
m_localTransform = toSVGImageElement(element())->animatedLocalTransform();
m_needsTransformUpdate = false;
}
if (m_needsBoundariesUpdate) {
m_repaintBoundingBox = m_objectBoundingBox;
SVGRenderSupport::intersectRepaintRectWithResources(this, m_repaintBoundingBox);
m_needsBoundariesUpdate = false;
}
if (everHadLayout() && selfNeedsLayout())
SVGResourcesCache::clientLayoutChanged(this);
if (transformOrBoundariesUpdate)
RenderSVGModelObject::setNeedsBoundariesUpdate();
repainter.repaintAfterLayout();
clearNeedsLayout();
}
void RenderSVGImage::paint(PaintInfo& paintInfo, const LayoutPoint&)
{
ANNOTATE_GRAPHICS_CONTEXT(paintInfo, this);
if (paintInfo.context->paintingDisabled() || style()->visibility() == HIDDEN || !m_imageResource->hasImage())
return;
FloatRect boundingBox = repaintRectInLocalCoordinates();
if (!SVGRenderSupport::paintInfoIntersectsRepaintRect(boundingBox, m_localTransform, paintInfo))
return;
PaintInfo childPaintInfo(paintInfo);
bool drawsOutline = style()->outlineWidth() && (childPaintInfo.phase == PaintPhaseOutline || childPaintInfo.phase == PaintPhaseSelfOutline);
if (drawsOutline || childPaintInfo.phase == PaintPhaseForeground) {
GraphicsContextStateSaver stateSaver(*childPaintInfo.context, false);
if (!m_localTransform.isIdentity()) {
stateSaver.save();
childPaintInfo.applyTransform(m_localTransform, false);
}
if (childPaintInfo.phase == PaintPhaseForeground && !m_objectBoundingBox.isEmpty()) {
SVGRenderingContext renderingContext(this, childPaintInfo, stateSaver.saved() ?
SVGRenderingContext::DontSaveGraphicsContext : SVGRenderingContext::SaveGraphicsContext);
if (renderingContext.isRenderingPrepared()) {
if (style()->svgStyle()->bufferedRendering() == BR_STATIC && renderingContext.bufferForeground(m_bufferedForeground))
return;
paintForeground(childPaintInfo);
}
}
if (drawsOutline)
paintOutline(childPaintInfo, IntRect(boundingBox));
}
}
void RenderSVGImage::paintForeground(PaintInfo& paintInfo)
{
RefPtr<Image> image = m_imageResource->image();
FloatRect destRect = m_objectBoundingBox;
FloatRect srcRect(0, 0, image->width(), image->height());
SVGImageElement* imageElement = toSVGImageElement(element());
imageElement->preserveAspectRatio()->currentValue()->transformRect(destRect, srcRect);
InterpolationQuality interpolationQuality = InterpolationDefault;
if (style()->svgStyle()->bufferedRendering() != BR_STATIC)
interpolationQuality = ImageQualityController::imageQualityController()->chooseInterpolationQuality(paintInfo.context, this, image.get(), image.get(), LayoutSize(destRect.size()));
InterpolationQuality previousInterpolationQuality = paintInfo.context->imageInterpolationQuality();
paintInfo.context->setImageInterpolationQuality(interpolationQuality);
paintInfo.context->drawImage(image.get(), destRect, srcRect, CompositeSourceOver);
paintInfo.context->setImageInterpolationQuality(previousInterpolationQuality);
}
void RenderSVGImage::invalidateBufferedForeground()
{
m_bufferedForeground.clear();
}
bool RenderSVGImage::nodeAtFloatPoint(const HitTestRequest& request, HitTestResult& result, const FloatPoint& pointInParent, HitTestAction hitTestAction)
{
if (hitTestAction != HitTestForeground)
return false;
PointerEventsHitRules hitRules(PointerEventsHitRules::SVG_IMAGE_HITTESTING, request, style()->pointerEvents());
bool isVisible = (style()->visibility() == VISIBLE);
if (isVisible || !hitRules.requireVisible) {
FloatPoint localPoint = localToParentTransform().inverse().mapPoint(pointInParent);
if (!SVGRenderSupport::pointInClippingArea(this, localPoint))
return false;
if (hitRules.canHitFill || hitRules.canHitBoundingBox) {
if (m_objectBoundingBox.contains(localPoint)) {
updateHitTestResult(result, roundedLayoutPoint(localPoint));
return true;
}
}
}
return false;
}
void RenderSVGImage::imageChanged(WrappedImagePtr, const IntRect*)
{
if (SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject(this))
resources->removeClientFromCache(this);
RenderSVGResource::markForLayoutAndParentResourceInvalidation(this, false);
m_objectBoundingBox = FloatRect();
updateImageViewport();
invalidateBufferedForeground();
repaint();
}
void RenderSVGImage::addFocusRingRects(Vector<IntRect>& rects, const LayoutPoint&, const RenderLayerModelObject*)
{
IntRect contentRect = enclosingIntRect(repaintRectInLocalCoordinates());
if (!contentRect.isEmpty())
rects.append(contentRect);
}
}