|
Line 0
a/Source/WebCore/rendering/svg/RenderSVGTransformableContainer.cpp_sec1
|
|
|
1 |
/* |
| 2 |
* Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> |
| 3 |
* Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> |
| 4 |
* Copyright (C) 2009 Google, Inc. |
| 5 |
* Copyright (c) 2020, 2021, 2022 Igalia S.L. |
| 6 |
* |
| 7 |
* This library is free software; you can redistribute it and/or |
| 8 |
* modify it under the terms of the GNU Library General Public |
| 9 |
* License as published by the Free Software Foundation; either |
| 10 |
* version 2 of the License, or (at your option) any later version. |
| 11 |
* |
| 12 |
* This library is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
* Library General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU Library General Public License |
| 18 |
* along with this library; see the file COPYING.LIB. If not, write to |
| 19 |
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 20 |
* Boston, MA 02110-1301, USA. |
| 21 |
*/ |
| 22 |
|
| 23 |
#include "config.h" |
| 24 |
#include "RenderSVGTransformableContainer.h" |
| 25 |
|
| 26 |
#if ENABLE(LAYER_BASED_SVG_ENGINE) |
| 27 |
#include "RenderSVGModelObjectInlines.h" |
| 28 |
#include "SVGContainerLayout.h" |
| 29 |
#include "SVGElementTypeHelpers.h" |
| 30 |
#include "SVGGElement.h" |
| 31 |
#include "SVGGraphicsElement.h" |
| 32 |
#include "SVGPathData.h" |
| 33 |
#include "SVGUseElement.h" |
| 34 |
#include <wtf/IsoMallocInlines.h> |
| 35 |
|
| 36 |
namespace WebCore { |
| 37 |
|
| 38 |
WTF_MAKE_ISO_ALLOCATED_IMPL(RenderSVGTransformableContainer); |
| 39 |
|
| 40 |
RenderSVGTransformableContainer::RenderSVGTransformableContainer(SVGGraphicsElement& element, RenderStyle&& style) |
| 41 |
: RenderSVGContainer(element, WTFMove(style)) |
| 42 |
{ |
| 43 |
} |
| 44 |
|
| 45 |
inline SVGUseElement* associatedUseElement(SVGGraphicsElement& element) |
| 46 |
{ |
| 47 |
// If we're either the renderer for a <use> element, or for any <g> element inside the shadow |
| 48 |
// tree, that was created during the use/symbol/svg expansion in SVGUseElement. These containers |
| 49 |
// need to respect the translations induced by their corresponding use elements x/y attributes. |
| 50 |
if (is<SVGUseElement>(element)) |
| 51 |
return &downcast<SVGUseElement>(element); |
| 52 |
|
| 53 |
if (element.isInShadowTree() && is<SVGGElement>(element)) { |
| 54 |
SVGElement* correspondingElement = element.correspondingElement(); |
| 55 |
if (is<SVGUseElement>(correspondingElement)) |
| 56 |
return downcast<SVGUseElement>(correspondingElement); |
| 57 |
} |
| 58 |
|
| 59 |
return nullptr; |
| 60 |
} |
| 61 |
|
| 62 |
FloatPoint RenderSVGTransformableContainer::additionalContainerTranslation() const |
| 63 |
{ |
| 64 |
if (auto* useElement = associatedUseElement(graphicsElement())) { |
| 65 |
// FIXME: [LBSE] Upstream SVGLengthContext changes |
| 66 |
// const auto& lengthContext = useElement->lengthContext(); |
| 67 |
SVGLengthContext lengthContext(useElement); |
| 68 |
return { useElement->x().value(lengthContext), useElement->y().value(lengthContext) }; |
| 69 |
} |
| 70 |
|
| 71 |
return { }; |
| 72 |
} |
| 73 |
|
| 74 |
void RenderSVGTransformableContainer::calculateViewport() |
| 75 |
{ |
| 76 |
RenderSVGContainer::calculateViewport(); |
| 77 |
|
| 78 |
// FIXME: [LBSE] Upstream SVGLengthContext changes |
| 79 |
// if (auto* useElement = associatedUseElement(graphicsElement())) |
| 80 |
// useElement->updateLengthContext(); |
| 81 |
|
| 82 |
m_supplementalLocalToParentTransform.makeIdentity(); |
| 83 |
|
| 84 |
auto translation = additionalContainerTranslation(); |
| 85 |
m_supplementalLocalToParentTransform.translate(translation.x(), translation.y()); |
| 86 |
|
| 87 |
m_didTransformToRootUpdate = m_hadTransformUpdate || SVGContainerLayout::transformToRootChanged(parent()); |
| 88 |
} |
| 89 |
|
| 90 |
void RenderSVGTransformableContainer::layoutChildren() |
| 91 |
{ |
| 92 |
RenderSVGContainer::layoutChildren(); |
| 93 |
m_didTransformToRootUpdate = false; |
| 94 |
} |
| 95 |
|
| 96 |
void RenderSVGTransformableContainer::updateFromStyle() |
| 97 |
{ |
| 98 |
RenderSVGContainer::updateFromStyle(); |
| 99 |
|
| 100 |
// FIXME: [LBSE] Upstream CSS/SVG transform support |
| 101 |
// if (associatedUseElement(graphicsElement())) |
| 102 |
// setHasSVGTransform(); |
| 103 |
} |
| 104 |
|
| 105 |
void RenderSVGTransformableContainer::applyTransform(TransformationMatrix& transform, const FloatRect& boundingBox, OptionSet<RenderStyle::TransformOperationOption> options) const |
| 106 |
{ |
| 107 |
// FIXME: [LBSE] Upstream CSS/SVG transform support |
| 108 |
RenderSVGContainer::applyTransform(transform, boundingBox, options); |
| 109 |
} |
| 110 |
|
| 111 |
void RenderSVGTransformableContainer::styleWillChange(StyleDifference diff, const RenderStyle& newStyle) |
| 112 |
{ |
| 113 |
const RenderStyle* oldStyle = hasInitializedStyle() ? &style() : nullptr; |
| 114 |
if (oldStyle && oldStyle->transform() != newStyle.transform()) |
| 115 |
setHadTransformUpdate(); |
| 116 |
RenderSVGContainer::styleWillChange(diff, newStyle); |
| 117 |
} |
| 118 |
|
| 119 |
SVGGraphicsElement& RenderSVGTransformableContainer::graphicsElement() const |
| 120 |
{ |
| 121 |
return downcast<SVGGraphicsElement>(RenderSVGContainer::element()); |
| 122 |
} |
| 123 |
|
| 124 |
} |
| 125 |
|
| 126 |
#endif // ENABLE(LAYER_BASED_SVG_ENGINE) |