1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
/*
* Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
* Copyright (C) 2004, 2005, 2006, 2007, 2008 Rob Buis <buis@kde.org>
* Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
* Copyright (C) 2022, 2023, 2024 Igalia S.L.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "RenderSVGResourceMarker.h"
#include "Element.h"
#include "ElementIterator.h"
#include "FloatPoint.h"
#include "Image.h"
#include "ImageBuffer.h"
#include "IntRect.h"
#include "RenderLayer.h"
#include "RenderLayerInlines.h"
#include "RenderSVGModelObjectInlines.h"
#include "RenderSVGResourceMarkerInlines.h"
#include "SVGElementTypeHelpers.h"
#include "SVGGraphicsElement.h"
#include "SVGLengthContext.h"
#include "SVGRenderStyle.h"
#include <wtf/TZoneMallocInlines.h>
namespace WebCore {
WTF_MAKE_TZONE_OR_ISO_ALLOCATED_IMPL(RenderSVGResourceMarker);
RenderSVGResourceMarker::RenderSVGResourceMarker(SVGMarkerElement& element, RenderStyle&& style)
: RenderSVGResourceContainer(Type::SVGResourceMarker, element, WTFMove(style))
{
}
RenderSVGResourceMarker::~RenderSVGResourceMarker() = default;
void RenderSVGResourceMarker::invalidateMarker()
{
// Repainting all clients is sufficient to handle invalidation.
repaintAllClients();
}
FloatRect RenderSVGResourceMarker::computeViewport() const
{
Ref useMarkerElement = markerElement();
SVGLengthContext lengthContext(useMarkerElement.ptr());
return { 0, 0, useMarkerElement->markerWidth().value(lengthContext), useMarkerElement->markerHeight().value(lengthContext) };
}
bool RenderSVGResourceMarker::updateLayoutSizeIfNeeded()
{
auto previousViewportSize = viewportSize();
m_viewport = computeViewport();
return selfNeedsLayout() || previousViewportSize != viewportSize();
}
void RenderSVGResourceMarker::layout()
{
// RenderSVGResourceContainer inherits from RenderSVGHiddenContainer which has a no-op layout() implementation.
// Markers are always painted indirectly, but their children need to be laid out such as they would be regular
// children of a SVG container element, thus skip RenderSVGHiddenContainer::layout() and use RenderSVGContainer::layout().
RenderSVGContainer::layout();
}
void RenderSVGResourceMarker::updateFromStyle()
{
RenderSVGContainer::updateFromStyle();
if (SVGRenderSupport::isOverflowHidden(*this))
setHasNonVisibleOverflow();
}
void RenderSVGResourceMarker::updateLayerTransform()
{
ASSERT(hasLayer());
// First update the supplemental layer transform.
Ref useMarkerElement = markerElement();
auto viewportSize = this->viewportSize();
m_supplementalLayerTransform.makeIdentity();
if (useMarkerElement->hasAttribute(SVGNames::viewBoxAttr)) {
// An empty viewBox disables the rendering -- dirty the visible descendant status!
if (useMarkerElement->hasEmptyViewBox())
layer()->dirtyVisibleContentStatus();
else if (auto viewBoxTransform = useMarkerElement->viewBoxToViewTransform(viewportSize.width(), viewportSize.height()); !viewBoxTransform.isIdentity())
m_supplementalLayerTransform = viewBoxTransform;
}
// After updating the supplemental layer transform we're able to use it in RenderLayerModelObjects::updateLayerTransform().
RenderSVGContainer::updateLayerTransform();
}
void RenderSVGResourceMarker::applyTransform(TransformationMatrix& transform, const RenderStyle& style, const FloatRect& boundingBox, OptionSet<RenderStyle::TransformOperationOption> options) const
{
// This code resembles RenderLayerModelObject::applySVGTransform(), but supporting non-SVGGraphicsElement derived elements,
// such as SVGMarkerElement, that do not allow user-specified transformations (no SMIL, no SVG/CSS transformations) - only
// the marker-induced transformations when applying markers to path elements.
FloatPoint3D originTranslate;
if (options.contains(RenderStyle::TransformOperationOption::TransformOrigin) && !m_supplementalLayerTransform.isIdentityOrTranslation())
originTranslate = style.computeTransformOrigin(boundingBox);
style.applyTransformOrigin(transform, originTranslate);
transform.multiplyAffineTransform(m_supplementalLayerTransform);
style.unapplyTransformOrigin(transform, originTranslate);
}
LayoutRect RenderSVGResourceMarker::overflowClipRect(const LayoutPoint& location, OverlayScrollbarSizeRelevancy, PaintPhase) const
{
Ref useMarkerElement = markerElement();
auto clipRect = enclosingLayoutRect(viewport());
if (useMarkerElement->hasAttribute(SVGNames::viewBoxAttr)) {
if (useMarkerElement->hasEmptyViewBox())
return { };
if (!m_supplementalLayerTransform.isIdentity())
clipRect = enclosingLayoutRect(m_supplementalLayerTransform.inverse().value_or(AffineTransform { }).mapRect(viewport()));
}
clipRect.moveBy(location);
return clipRect;
}
AffineTransform RenderSVGResourceMarker::markerTransformation(const FloatPoint& origin, float autoAngle, float strokeWidth) const
{
AffineTransform transform;
transform.translate(origin);
transform.rotate(angle().value_or(autoAngle));
// The 'referencePoint()' coordinate maps to SVGs refX/refY, given in coordinates relative to the viewport established by the marker
auto mappedOrigin = m_supplementalLayerTransform.mapPoint(referencePoint());
if (markerUnits() == SVGMarkerUnitsStrokeWidth)
transform.scaleNonUniform(strokeWidth, strokeWidth);
transform.translate(-mappedOrigin);
return transform;
}
FloatRect RenderSVGResourceMarker::computeMarkerBoundingBox(const SVGBoundingBoxComputation::DecorationOptions& options, const AffineTransform& markerTransformation) const
{
SVGBoundingBoxComputation boundingBoxComputation(*this);
auto boundingBox = boundingBoxComputation.computeDecoratedBoundingBox(options);
// Map repaint rect into parent coordinate space, in which the marker boundaries have to be evaluated
return markerTransformation.mapRect(m_supplementalLayerTransform.mapRect(boundingBox));
}
}
|