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
|
/*
* Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
* Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org>
* Copyright (C) 2005 Oliver Hunt <oliver@nerget.com>
* Copyright (C) 2018-2019 Apple Inc. All rights reserved.
*
* 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 "SVGFELightElement.h"
#include "ElementChildIteratorInlines.h"
#include "LegacyRenderSVGResource.h"
#include "NodeName.h"
#include "RenderObject.h"
#include "SVGElementTypeHelpers.h"
#include "SVGFEDiffuseLightingElement.h"
#include "SVGFEDistantLightElement.h"
#include "SVGFEPointLightElement.h"
#include "SVGFESpecularLightingElement.h"
#include "SVGFESpotLightElement.h"
#include "SVGFilterElement.h"
#include "SVGFilterPrimitiveStandardAttributes.h"
#include "SVGNames.h"
#include <wtf/TZoneMallocInlines.h>
namespace WebCore {
WTF_MAKE_TZONE_OR_ISO_ALLOCATED_IMPL(SVGFELightElement);
SVGFELightElement::SVGFELightElement(const QualifiedName& tagName, Document& document)
: SVGElement(tagName, document, makeUniqueRef<PropertyRegistry>(*this))
{
static std::once_flag onceFlag;
std::call_once(onceFlag, [] {
PropertyRegistry::registerProperty<SVGNames::azimuthAttr, &SVGFELightElement::m_azimuth>();
PropertyRegistry::registerProperty<SVGNames::elevationAttr, &SVGFELightElement::m_elevation>();
PropertyRegistry::registerProperty<SVGNames::xAttr, &SVGFELightElement::m_x>();
PropertyRegistry::registerProperty<SVGNames::yAttr, &SVGFELightElement::m_y>();
PropertyRegistry::registerProperty<SVGNames::zAttr, &SVGFELightElement::m_z>();
PropertyRegistry::registerProperty<SVGNames::pointsAtXAttr, &SVGFELightElement::m_pointsAtX>();
PropertyRegistry::registerProperty<SVGNames::pointsAtYAttr, &SVGFELightElement::m_pointsAtY>();
PropertyRegistry::registerProperty<SVGNames::pointsAtZAttr, &SVGFELightElement::m_pointsAtZ>();
PropertyRegistry::registerProperty<SVGNames::specularExponentAttr, &SVGFELightElement::m_specularExponent>();
PropertyRegistry::registerProperty<SVGNames::limitingConeAngleAttr, &SVGFELightElement::m_limitingConeAngle>();
});
}
SVGFELightElement* SVGFELightElement::findLightElement(const SVGElement* svgElement)
{
for (auto& child : childrenOfType<SVGElement>(*svgElement)) {
if (is<SVGFEDistantLightElement>(child) || is<SVGFEPointLightElement>(child) || is<SVGFESpotLightElement>(child))
return static_cast<SVGFELightElement*>(const_cast<SVGElement*>(&child));
}
return nullptr;
}
void SVGFELightElement::attributeChanged(const QualifiedName& name, const AtomString& oldValue, const AtomString& newValue, AttributeModificationReason attributeModificationReason)
{
switch (name.nodeName()) {
case AttributeNames::azimuthAttr:
Ref { m_azimuth }->setBaseValInternal(newValue.toFloat());
break;
case AttributeNames::elevationAttr:
Ref { m_elevation }->setBaseValInternal(newValue.toFloat());
break;
case AttributeNames::xAttr:
Ref { m_x }->setBaseValInternal(newValue.toFloat());
break;
case AttributeNames::yAttr:
Ref { m_y }->setBaseValInternal(newValue.toFloat());
break;
case AttributeNames::zAttr:
Ref { m_z }->setBaseValInternal(newValue.toFloat());
break;
case AttributeNames::pointsAtXAttr:
Ref { m_pointsAtX }->setBaseValInternal(newValue.toFloat());
break;
case AttributeNames::pointsAtYAttr:
Ref { m_pointsAtY }->setBaseValInternal(newValue.toFloat());
break;
case AttributeNames::pointsAtZAttr:
Ref { m_pointsAtZ }->setBaseValInternal(newValue.toFloat());
break;
case AttributeNames::specularExponentAttr:
Ref { m_specularExponent }->setBaseValInternal(newValue.toFloat());
break;
case AttributeNames::limitingConeAngleAttr:
Ref { m_limitingConeAngle }->setBaseValInternal(newValue.toFloat());
break;
default:
break;
}
SVGElement::attributeChanged(name, oldValue, newValue, attributeModificationReason);
}
void SVGFELightElement::svgAttributeChanged(const QualifiedName& attrName)
{
if (PropertyRegistry::isKnownAttribute(attrName)) {
ASSERT(attrName == SVGNames::azimuthAttr || attrName == SVGNames::elevationAttr || attrName == SVGNames::xAttr || attrName == SVGNames::yAttr
|| attrName == SVGNames::zAttr || attrName == SVGNames::pointsAtXAttr || attrName == SVGNames::pointsAtYAttr || attrName == SVGNames::pointsAtZAttr
|| attrName == SVGNames::specularExponentAttr || attrName == SVGNames::limitingConeAngleAttr);
RefPtr parent = parentElement();
if (!parent)
return;
CheckedPtr renderer = parent->renderer();
if (!renderer || !renderer->isRenderOrLegacyRenderSVGResourceFilterPrimitive())
return;
if (auto* lightingElement = dynamicDowncast<SVGFEDiffuseLightingElement>(*parent)) {
InstanceInvalidationGuard guard(*this);
lightingElement->lightElementAttributeChanged(this, attrName);
} else if (auto* lightingElement = dynamicDowncast<SVGFESpecularLightingElement>(*parent)) {
InstanceInvalidationGuard guard(*this);
lightingElement->lightElementAttributeChanged(this, attrName);
}
return;
}
SVGElement::svgAttributeChanged(attrName);
}
void SVGFELightElement::childrenChanged(const ChildChange& change)
{
SVGElement::childrenChanged(change);
if (change.source == ChildChange::Source::Parser)
return;
SVGFilterPrimitiveStandardAttributes::invalidateFilterPrimitiveParent(this);
}
}
|