blob: f7a4180dfa651059d5d482dd0ce33427029e18ce [file] [log] [blame]
darinb9481ed2006-03-20 02:57:59 +00001/*
zimmermann@webkit.org711245f2010-08-03 19:39:01 +00002 * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
4 * Copyright (C) 2005 Alexander Kellett <lypanov@kde.org>
5 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
6 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
krit@webkit.org9c3caeb2014-07-25 09:52:25 +00007 * Copyright (C) 2014 Adobe Systems Incorporated. All rights reserved.
zimmermann@webkit.org711245f2010-08-03 19:39:01 +00008 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
18 *
19 * You should have received a copy of the GNU Library General Public License
20 * along with this library; see the file COPYING.LIB. If not, write to
21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
23 */
darinb9481ed2006-03-20 02:57:59 +000024
25#include "config.h"
darinb9481ed2006-03-20 02:57:59 +000026#include "SVGMaskElement.h"
27
krit@webkit.org0b226d62010-02-18 23:12:30 +000028#include "RenderSVGResourceMasker.h"
darinb9481ed2006-03-20 02:57:59 +000029#include "SVGNames.h"
zimmermann961374c2007-10-14 17:45:09 +000030#include "SVGRenderSupport.h"
weinig@apple.com3ba621d2016-11-17 23:58:03 +000031#include "SVGStringList.h"
oliver103fd5c2007-10-12 11:26:25 +000032#include "SVGUnitTypes.h"
alexis.menard@openbossa.orge6db2f62012-04-25 15:49:08 +000033#include "StyleResolver.h"
svillar@igalia.com55cc6d12014-05-08 10:59:17 +000034#include <wtf/NeverDestroyed.h>
darin4bc83c32007-01-07 04:11:10 +000035
darinb9481ed2006-03-20 02:57:59 +000036namespace WebCore {
37
zimmermann@webkit.orgab0da702010-12-01 12:17:12 +000038// Animated property definitions
zimmermann@webkit.org94630af2011-05-18 15:35:36 +000039DEFINE_ANIMATED_ENUMERATION(SVGMaskElement, SVGNames::maskUnitsAttr, MaskUnits, maskUnits, SVGUnitTypes::SVGUnitType)
40DEFINE_ANIMATED_ENUMERATION(SVGMaskElement, SVGNames::maskContentUnitsAttr, MaskContentUnits, maskContentUnits, SVGUnitTypes::SVGUnitType)
zimmermann@webkit.orgab0da702010-12-01 12:17:12 +000041DEFINE_ANIMATED_LENGTH(SVGMaskElement, SVGNames::xAttr, X, x)
42DEFINE_ANIMATED_LENGTH(SVGMaskElement, SVGNames::yAttr, Y, y)
43DEFINE_ANIMATED_LENGTH(SVGMaskElement, SVGNames::widthAttr, Width, width)
44DEFINE_ANIMATED_LENGTH(SVGMaskElement, SVGNames::heightAttr, Height, height)
zimmermann@webkit.orge50a8b12010-12-03 09:44:21 +000045DEFINE_ANIMATED_BOOLEAN(SVGMaskElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired)
zimmermann@webkit.orgab0da702010-12-01 12:17:12 +000046
zimmermann@webkit.orga2857422011-07-09 11:26:10 +000047BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGMaskElement)
48 REGISTER_LOCAL_ANIMATED_PROPERTY(maskUnits)
49 REGISTER_LOCAL_ANIMATED_PROPERTY(maskContentUnits)
50 REGISTER_LOCAL_ANIMATED_PROPERTY(x)
51 REGISTER_LOCAL_ANIMATED_PROPERTY(y)
52 REGISTER_LOCAL_ANIMATED_PROPERTY(width)
53 REGISTER_LOCAL_ANIMATED_PROPERTY(height)
54 REGISTER_LOCAL_ANIMATED_PROPERTY(externalResourcesRequired)
ch.dumez@sisa.samsung.com7dd31bf2013-08-22 21:58:09 +000055 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGElement)
zimmermann@webkit.orga2857422011-07-09 11:26:10 +000056 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGTests)
57END_REGISTER_ANIMATED_PROPERTIES
58
weinig@apple.com52e786e2013-09-15 18:06:06 +000059inline SVGMaskElement::SVGMaskElement(const QualifiedName& tagName, Document& document)
ch.dumez@sisa.samsung.com7dd31bf2013-08-22 21:58:09 +000060 : SVGElement(tagName, document)
zimmermann@webkit.org8fc45392010-01-27 01:51:39 +000061 , m_maskUnits(SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX)
62 , m_maskContentUnits(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE)
63 , m_x(LengthModeWidth, "-10%")
64 , m_y(LengthModeHeight, "-10%")
65 , m_width(LengthModeWidth, "120%")
66 , m_height(LengthModeHeight, "120%")
darinb9481ed2006-03-20 02:57:59 +000067{
zimmermann@webkit.org28d98cf2008-07-16 23:34:53 +000068 // Spec: If the x/y attribute is not specified, the effect is as if a value of "-10%" were specified.
69 // Spec: If the width/height attribute is not specified, the effect is as if a value of "120%" were specified.
rwlbuis@webkit.org25518122011-05-09 13:41:55 +000070 ASSERT(hasTagName(SVGNames::maskTag));
zimmermann@webkit.orga2857422011-07-09 11:26:10 +000071 registerAnimatedPropertiesForSVGMaskElement();
darinb9481ed2006-03-20 02:57:59 +000072}
73
weinig@apple.com10923572015-01-07 20:56:24 +000074Ref<SVGMaskElement> SVGMaskElement::create(const QualifiedName& tagName, Document& document)
darin@apple.com3cbd5cb2010-08-30 06:51:56 +000075{
weinig@apple.com10923572015-01-07 20:56:24 +000076 return adoptRef(*new SVGMaskElement(tagName, document));
darin@apple.com3cbd5cb2010-08-30 06:51:56 +000077}
78
zimmermann@webkit.orgefff7252011-05-21 06:15:40 +000079bool SVGMaskElement::isSupportedAttribute(const QualifiedName& attrName)
80{
svillar@igalia.com55cc6d12014-05-08 10:59:17 +000081 static NeverDestroyed<HashSet<QualifiedName>> supportedAttributes;
82 if (supportedAttributes.get().isEmpty()) {
zimmermann@webkit.orgefff7252011-05-21 06:15:40 +000083 SVGTests::addSupportedAttributes(supportedAttributes);
84 SVGLangSpace::addSupportedAttributes(supportedAttributes);
85 SVGExternalResourcesRequired::addSupportedAttributes(supportedAttributes);
svillar@igalia.com55cc6d12014-05-08 10:59:17 +000086 supportedAttributes.get().add(SVGNames::maskUnitsAttr);
87 supportedAttributes.get().add(SVGNames::maskContentUnitsAttr);
88 supportedAttributes.get().add(SVGNames::xAttr);
89 supportedAttributes.get().add(SVGNames::yAttr);
90 supportedAttributes.get().add(SVGNames::widthAttr);
91 supportedAttributes.get().add(SVGNames::heightAttr);
zimmermann@webkit.orgefff7252011-05-21 06:15:40 +000092 }
svillar@igalia.com55cc6d12014-05-08 10:59:17 +000093 return supportedAttributes.get().contains<SVGAttributeHashTranslator>(attrName);
zimmermann@webkit.orgefff7252011-05-21 06:15:40 +000094}
95
akling@apple.com43e9d042012-11-18 16:55:06 +000096void SVGMaskElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
darinb9481ed2006-03-20 02:57:59 +000097{
darin@apple.com74c44cc2015-03-29 20:40:15 +000098 if (name == SVGNames::maskUnitsAttr) {
99 auto propertyValue = SVGPropertyTraits<SVGUnitTypes::SVGUnitType>::fromString(value);
zimmermann@webkit.org94630af2011-05-18 15:35:36 +0000100 if (propertyValue > 0)
101 setMaskUnitsBaseValue(propertyValue);
zimmermann@webkit.orgefff7252011-05-21 06:15:40 +0000102 return;
darin@apple.com74c44cc2015-03-29 20:40:15 +0000103 }
104 if (name == SVGNames::maskContentUnitsAttr) {
105 auto propertyValue = SVGPropertyTraits<SVGUnitTypes::SVGUnitType>::fromString(value);
zimmermann@webkit.org94630af2011-05-18 15:35:36 +0000106 if (propertyValue > 0)
107 setMaskContentUnitsBaseValue(propertyValue);
zimmermann@webkit.orgefff7252011-05-21 06:15:40 +0000108 return;
darin@apple.com74c44cc2015-03-29 20:40:15 +0000109 }
110
111 SVGParsingError parseError = NoError;
112
113 if (name == SVGNames::xAttr)
weinig@apple.comf7867302016-11-14 21:18:41 +0000114 setXBaseValue(SVGLengthValue::construct(LengthModeWidth, value, parseError));
akling@apple.com43e9d042012-11-18 16:55:06 +0000115 else if (name == SVGNames::yAttr)
weinig@apple.comf7867302016-11-14 21:18:41 +0000116 setYBaseValue(SVGLengthValue::construct(LengthModeHeight, value, parseError));
akling@apple.com43e9d042012-11-18 16:55:06 +0000117 else if (name == SVGNames::widthAttr)
weinig@apple.comf7867302016-11-14 21:18:41 +0000118 setWidthBaseValue(SVGLengthValue::construct(LengthModeWidth, value, parseError));
akling@apple.com43e9d042012-11-18 16:55:06 +0000119 else if (name == SVGNames::heightAttr)
weinig@apple.comf7867302016-11-14 21:18:41 +0000120 setHeightBaseValue(SVGLengthValue::construct(LengthModeHeight, value, parseError));
zimmermann@webkit.orgefff7252011-05-21 06:15:40 +0000121
akling@apple.com43e9d042012-11-18 16:55:06 +0000122 reportAttributeParsingError(parseError, name, value);
darin@apple.com74c44cc2015-03-29 20:40:15 +0000123
124 SVGElement::parseAttribute(name, value);
125 SVGTests::parseAttribute(name, value);
126 SVGExternalResourcesRequired::parseAttribute(name, value);
darinb9481ed2006-03-20 02:57:59 +0000127}
zimmermannf10700a2006-12-19 14:51:13 +0000128
zimmermann@webkit.org52b39ec2008-02-03 23:18:53 +0000129void SVGMaskElement::svgAttributeChanged(const QualifiedName& attrName)
130{
zimmermann@webkit.orgefff7252011-05-21 06:15:40 +0000131 if (!isSupportedAttribute(attrName)) {
ch.dumez@sisa.samsung.com7dd31bf2013-08-22 21:58:09 +0000132 SVGElement::svgAttributeChanged(attrName);
zimmermann@webkit.orgefff7252011-05-21 06:15:40 +0000133 return;
134 }
zimmermann@webkit.org52b39ec2008-02-03 23:18:53 +0000135
bfulgham@apple.com984c94d2015-02-05 18:07:10 +0000136 InstanceInvalidationGuard guard(*this);
krit@webkit.org3b520fe2014-07-22 13:27:38 +0000137
krit@webkit.org9c3caeb2014-07-25 09:52:25 +0000138 if (attrName == SVGNames::xAttr
139 || attrName == SVGNames::yAttr
140 || attrName == SVGNames::widthAttr
krit@webkit.org3b520fe2014-07-22 13:27:38 +0000141 || attrName == SVGNames::heightAttr) {
142 invalidateSVGPresentationAttributeStyle();
143 return;
144 }
145
zimmermann@webkit.orgefff7252011-05-21 06:15:40 +0000146 if (RenderObject* object = renderer())
antti@apple.comca2a8ff2013-10-04 04:04:35 +0000147 object->setNeedsLayout();
zimmermann@webkit.org52b39ec2008-02-03 23:18:53 +0000148}
149
antti@apple.com1acee922013-09-02 15:17:50 +0000150void SVGMaskElement::childrenChanged(const ChildChange& change)
zimmermann@webkit.org52b39ec2008-02-03 23:18:53 +0000151{
antti@apple.com1acee922013-09-02 15:17:50 +0000152 SVGElement::childrenChanged(change);
zimmermann@webkit.org555112d2010-04-24 11:42:46 +0000153
antti@apple.com1acee922013-09-02 15:17:50 +0000154 if (change.source == ChildChangeSourceParser)
zimmermann@webkit.orgb984a402010-07-29 13:50:51 +0000155 return;
156
157 if (RenderObject* object = renderer())
antti@apple.comca2a8ff2013-10-04 04:04:35 +0000158 object->setNeedsLayout();
zimmermann@webkit.org52b39ec2008-02-03 23:18:53 +0000159}
160
antti@apple.com454418f2016-04-25 19:49:23 +0000161RenderPtr<RenderElement> SVGMaskElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&)
darinb9481ed2006-03-20 02:57:59 +0000162{
aestes@apple.com13aae082016-01-02 08:03:08 +0000163 return createRenderer<RenderSVGResourceMasker>(*this, WTFMove(style));
bdakin@apple.com96ba2ed2010-02-11 03:04:38 +0000164}
165
weinig@apple.com3ba621d2016-11-17 23:58:03 +0000166Ref<SVGStringList> SVGMaskElement::requiredFeatures()
167{
168 return SVGTests::requiredFeatures(*this);
169}
170
171Ref<SVGStringList> SVGMaskElement::requiredExtensions()
172{
173 return SVGTests::requiredExtensions(*this);
174}
175
176Ref<SVGStringList> SVGMaskElement::systemLanguage()
177{
178 return SVGTests::systemLanguage(*this);
179}
180
darinb9481ed2006-03-20 02:57:59 +0000181}