darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1 | /* |
zimmermann@webkit.org | 711245f | 2010-08-03 19:39:01 +0000 | [diff] [blame] | 2 | * 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.org | 9c3caeb | 2014-07-25 09:52:25 +0000 | [diff] [blame] | 7 | * Copyright (C) 2014 Adobe Systems Incorporated. All rights reserved. |
zimmermann@webkit.org | 711245f | 2010-08-03 19:39:01 +0000 | [diff] [blame] | 8 | * |
| 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 | */ |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 24 | |
| 25 | #include "config.h" |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 26 | #include "SVGMaskElement.h" |
| 27 | |
krit@webkit.org | 0b226d6 | 2010-02-18 23:12:30 +0000 | [diff] [blame] | 28 | #include "RenderSVGResourceMasker.h" |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 29 | #include "SVGNames.h" |
zimmermann | 961374c | 2007-10-14 17:45:09 +0000 | [diff] [blame] | 30 | #include "SVGRenderSupport.h" |
weinig@apple.com | 3ba621d | 2016-11-17 23:58:03 +0000 | [diff] [blame] | 31 | #include "SVGStringList.h" |
oliver | 103fd5c | 2007-10-12 11:26:25 +0000 | [diff] [blame] | 32 | #include "SVGUnitTypes.h" |
alexis.menard@openbossa.org | e6db2f6 | 2012-04-25 15:49:08 +0000 | [diff] [blame] | 33 | #include "StyleResolver.h" |
svillar@igalia.com | 55cc6d1 | 2014-05-08 10:59:17 +0000 | [diff] [blame] | 34 | #include <wtf/NeverDestroyed.h> |
darin | 4bc83c3 | 2007-01-07 04:11:10 +0000 | [diff] [blame] | 35 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 36 | namespace WebCore { |
| 37 | |
zimmermann@webkit.org | ab0da70 | 2010-12-01 12:17:12 +0000 | [diff] [blame] | 38 | // Animated property definitions |
zimmermann@webkit.org | 94630af | 2011-05-18 15:35:36 +0000 | [diff] [blame] | 39 | DEFINE_ANIMATED_ENUMERATION(SVGMaskElement, SVGNames::maskUnitsAttr, MaskUnits, maskUnits, SVGUnitTypes::SVGUnitType) |
| 40 | DEFINE_ANIMATED_ENUMERATION(SVGMaskElement, SVGNames::maskContentUnitsAttr, MaskContentUnits, maskContentUnits, SVGUnitTypes::SVGUnitType) |
zimmermann@webkit.org | ab0da70 | 2010-12-01 12:17:12 +0000 | [diff] [blame] | 41 | DEFINE_ANIMATED_LENGTH(SVGMaskElement, SVGNames::xAttr, X, x) |
| 42 | DEFINE_ANIMATED_LENGTH(SVGMaskElement, SVGNames::yAttr, Y, y) |
| 43 | DEFINE_ANIMATED_LENGTH(SVGMaskElement, SVGNames::widthAttr, Width, width) |
| 44 | DEFINE_ANIMATED_LENGTH(SVGMaskElement, SVGNames::heightAttr, Height, height) |
zimmermann@webkit.org | e50a8b1 | 2010-12-03 09:44:21 +0000 | [diff] [blame] | 45 | DEFINE_ANIMATED_BOOLEAN(SVGMaskElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) |
zimmermann@webkit.org | ab0da70 | 2010-12-01 12:17:12 +0000 | [diff] [blame] | 46 | |
zimmermann@webkit.org | a285742 | 2011-07-09 11:26:10 +0000 | [diff] [blame] | 47 | BEGIN_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.com | 7dd31bf | 2013-08-22 21:58:09 +0000 | [diff] [blame] | 55 | REGISTER_PARENT_ANIMATED_PROPERTIES(SVGElement) |
zimmermann@webkit.org | a285742 | 2011-07-09 11:26:10 +0000 | [diff] [blame] | 56 | REGISTER_PARENT_ANIMATED_PROPERTIES(SVGTests) |
| 57 | END_REGISTER_ANIMATED_PROPERTIES |
| 58 | |
weinig@apple.com | 52e786e | 2013-09-15 18:06:06 +0000 | [diff] [blame] | 59 | inline SVGMaskElement::SVGMaskElement(const QualifiedName& tagName, Document& document) |
ch.dumez@sisa.samsung.com | 7dd31bf | 2013-08-22 21:58:09 +0000 | [diff] [blame] | 60 | : SVGElement(tagName, document) |
zimmermann@webkit.org | 8fc4539 | 2010-01-27 01:51:39 +0000 | [diff] [blame] | 61 | , 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%") |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 67 | { |
zimmermann@webkit.org | 28d98cf | 2008-07-16 23:34:53 +0000 | [diff] [blame] | 68 | // 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.org | 2551812 | 2011-05-09 13:41:55 +0000 | [diff] [blame] | 70 | ASSERT(hasTagName(SVGNames::maskTag)); |
zimmermann@webkit.org | a285742 | 2011-07-09 11:26:10 +0000 | [diff] [blame] | 71 | registerAnimatedPropertiesForSVGMaskElement(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 72 | } |
| 73 | |
weinig@apple.com | 1092357 | 2015-01-07 20:56:24 +0000 | [diff] [blame] | 74 | Ref<SVGMaskElement> SVGMaskElement::create(const QualifiedName& tagName, Document& document) |
darin@apple.com | 3cbd5cb | 2010-08-30 06:51:56 +0000 | [diff] [blame] | 75 | { |
weinig@apple.com | 1092357 | 2015-01-07 20:56:24 +0000 | [diff] [blame] | 76 | return adoptRef(*new SVGMaskElement(tagName, document)); |
darin@apple.com | 3cbd5cb | 2010-08-30 06:51:56 +0000 | [diff] [blame] | 77 | } |
| 78 | |
zimmermann@webkit.org | efff725 | 2011-05-21 06:15:40 +0000 | [diff] [blame] | 79 | bool SVGMaskElement::isSupportedAttribute(const QualifiedName& attrName) |
| 80 | { |
svillar@igalia.com | 55cc6d1 | 2014-05-08 10:59:17 +0000 | [diff] [blame] | 81 | static NeverDestroyed<HashSet<QualifiedName>> supportedAttributes; |
| 82 | if (supportedAttributes.get().isEmpty()) { |
zimmermann@webkit.org | efff725 | 2011-05-21 06:15:40 +0000 | [diff] [blame] | 83 | SVGTests::addSupportedAttributes(supportedAttributes); |
| 84 | SVGLangSpace::addSupportedAttributes(supportedAttributes); |
| 85 | SVGExternalResourcesRequired::addSupportedAttributes(supportedAttributes); |
svillar@igalia.com | 55cc6d1 | 2014-05-08 10:59:17 +0000 | [diff] [blame] | 86 | 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.org | efff725 | 2011-05-21 06:15:40 +0000 | [diff] [blame] | 92 | } |
svillar@igalia.com | 55cc6d1 | 2014-05-08 10:59:17 +0000 | [diff] [blame] | 93 | return supportedAttributes.get().contains<SVGAttributeHashTranslator>(attrName); |
zimmermann@webkit.org | efff725 | 2011-05-21 06:15:40 +0000 | [diff] [blame] | 94 | } |
| 95 | |
akling@apple.com | 43e9d04 | 2012-11-18 16:55:06 +0000 | [diff] [blame] | 96 | void SVGMaskElement::parseAttribute(const QualifiedName& name, const AtomicString& value) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 97 | { |
darin@apple.com | 74c44cc | 2015-03-29 20:40:15 +0000 | [diff] [blame] | 98 | if (name == SVGNames::maskUnitsAttr) { |
| 99 | auto propertyValue = SVGPropertyTraits<SVGUnitTypes::SVGUnitType>::fromString(value); |
zimmermann@webkit.org | 94630af | 2011-05-18 15:35:36 +0000 | [diff] [blame] | 100 | if (propertyValue > 0) |
| 101 | setMaskUnitsBaseValue(propertyValue); |
zimmermann@webkit.org | efff725 | 2011-05-21 06:15:40 +0000 | [diff] [blame] | 102 | return; |
darin@apple.com | 74c44cc | 2015-03-29 20:40:15 +0000 | [diff] [blame] | 103 | } |
| 104 | if (name == SVGNames::maskContentUnitsAttr) { |
| 105 | auto propertyValue = SVGPropertyTraits<SVGUnitTypes::SVGUnitType>::fromString(value); |
zimmermann@webkit.org | 94630af | 2011-05-18 15:35:36 +0000 | [diff] [blame] | 106 | if (propertyValue > 0) |
| 107 | setMaskContentUnitsBaseValue(propertyValue); |
zimmermann@webkit.org | efff725 | 2011-05-21 06:15:40 +0000 | [diff] [blame] | 108 | return; |
darin@apple.com | 74c44cc | 2015-03-29 20:40:15 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | SVGParsingError parseError = NoError; |
| 112 | |
| 113 | if (name == SVGNames::xAttr) |
weinig@apple.com | f786730 | 2016-11-14 21:18:41 +0000 | [diff] [blame] | 114 | setXBaseValue(SVGLengthValue::construct(LengthModeWidth, value, parseError)); |
akling@apple.com | 43e9d04 | 2012-11-18 16:55:06 +0000 | [diff] [blame] | 115 | else if (name == SVGNames::yAttr) |
weinig@apple.com | f786730 | 2016-11-14 21:18:41 +0000 | [diff] [blame] | 116 | setYBaseValue(SVGLengthValue::construct(LengthModeHeight, value, parseError)); |
akling@apple.com | 43e9d04 | 2012-11-18 16:55:06 +0000 | [diff] [blame] | 117 | else if (name == SVGNames::widthAttr) |
weinig@apple.com | f786730 | 2016-11-14 21:18:41 +0000 | [diff] [blame] | 118 | setWidthBaseValue(SVGLengthValue::construct(LengthModeWidth, value, parseError)); |
akling@apple.com | 43e9d04 | 2012-11-18 16:55:06 +0000 | [diff] [blame] | 119 | else if (name == SVGNames::heightAttr) |
weinig@apple.com | f786730 | 2016-11-14 21:18:41 +0000 | [diff] [blame] | 120 | setHeightBaseValue(SVGLengthValue::construct(LengthModeHeight, value, parseError)); |
zimmermann@webkit.org | efff725 | 2011-05-21 06:15:40 +0000 | [diff] [blame] | 121 | |
akling@apple.com | 43e9d04 | 2012-11-18 16:55:06 +0000 | [diff] [blame] | 122 | reportAttributeParsingError(parseError, name, value); |
darin@apple.com | 74c44cc | 2015-03-29 20:40:15 +0000 | [diff] [blame] | 123 | |
| 124 | SVGElement::parseAttribute(name, value); |
| 125 | SVGTests::parseAttribute(name, value); |
| 126 | SVGExternalResourcesRequired::parseAttribute(name, value); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 127 | } |
zimmermann | f10700a | 2006-12-19 14:51:13 +0000 | [diff] [blame] | 128 | |
zimmermann@webkit.org | 52b39ec | 2008-02-03 23:18:53 +0000 | [diff] [blame] | 129 | void SVGMaskElement::svgAttributeChanged(const QualifiedName& attrName) |
| 130 | { |
zimmermann@webkit.org | efff725 | 2011-05-21 06:15:40 +0000 | [diff] [blame] | 131 | if (!isSupportedAttribute(attrName)) { |
ch.dumez@sisa.samsung.com | 7dd31bf | 2013-08-22 21:58:09 +0000 | [diff] [blame] | 132 | SVGElement::svgAttributeChanged(attrName); |
zimmermann@webkit.org | efff725 | 2011-05-21 06:15:40 +0000 | [diff] [blame] | 133 | return; |
| 134 | } |
zimmermann@webkit.org | 52b39ec | 2008-02-03 23:18:53 +0000 | [diff] [blame] | 135 | |
bfulgham@apple.com | 984c94d | 2015-02-05 18:07:10 +0000 | [diff] [blame] | 136 | InstanceInvalidationGuard guard(*this); |
krit@webkit.org | 3b520fe | 2014-07-22 13:27:38 +0000 | [diff] [blame] | 137 | |
krit@webkit.org | 9c3caeb | 2014-07-25 09:52:25 +0000 | [diff] [blame] | 138 | if (attrName == SVGNames::xAttr |
| 139 | || attrName == SVGNames::yAttr |
| 140 | || attrName == SVGNames::widthAttr |
krit@webkit.org | 3b520fe | 2014-07-22 13:27:38 +0000 | [diff] [blame] | 141 | || attrName == SVGNames::heightAttr) { |
| 142 | invalidateSVGPresentationAttributeStyle(); |
| 143 | return; |
| 144 | } |
| 145 | |
zimmermann@webkit.org | efff725 | 2011-05-21 06:15:40 +0000 | [diff] [blame] | 146 | if (RenderObject* object = renderer()) |
antti@apple.com | ca2a8ff | 2013-10-04 04:04:35 +0000 | [diff] [blame] | 147 | object->setNeedsLayout(); |
zimmermann@webkit.org | 52b39ec | 2008-02-03 23:18:53 +0000 | [diff] [blame] | 148 | } |
| 149 | |
antti@apple.com | 1acee92 | 2013-09-02 15:17:50 +0000 | [diff] [blame] | 150 | void SVGMaskElement::childrenChanged(const ChildChange& change) |
zimmermann@webkit.org | 52b39ec | 2008-02-03 23:18:53 +0000 | [diff] [blame] | 151 | { |
antti@apple.com | 1acee92 | 2013-09-02 15:17:50 +0000 | [diff] [blame] | 152 | SVGElement::childrenChanged(change); |
zimmermann@webkit.org | 555112d | 2010-04-24 11:42:46 +0000 | [diff] [blame] | 153 | |
antti@apple.com | 1acee92 | 2013-09-02 15:17:50 +0000 | [diff] [blame] | 154 | if (change.source == ChildChangeSourceParser) |
zimmermann@webkit.org | b984a40 | 2010-07-29 13:50:51 +0000 | [diff] [blame] | 155 | return; |
| 156 | |
| 157 | if (RenderObject* object = renderer()) |
antti@apple.com | ca2a8ff | 2013-10-04 04:04:35 +0000 | [diff] [blame] | 158 | object->setNeedsLayout(); |
zimmermann@webkit.org | 52b39ec | 2008-02-03 23:18:53 +0000 | [diff] [blame] | 159 | } |
| 160 | |
antti@apple.com | 454418f | 2016-04-25 19:49:23 +0000 | [diff] [blame] | 161 | RenderPtr<RenderElement> SVGMaskElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 162 | { |
aestes@apple.com | 13aae08 | 2016-01-02 08:03:08 +0000 | [diff] [blame] | 163 | return createRenderer<RenderSVGResourceMasker>(*this, WTFMove(style)); |
bdakin@apple.com | 96ba2ed | 2010-02-11 03:04:38 +0000 | [diff] [blame] | 164 | } |
| 165 | |
weinig@apple.com | 3ba621d | 2016-11-17 23:58:03 +0000 | [diff] [blame] | 166 | Ref<SVGStringList> SVGMaskElement::requiredFeatures() |
| 167 | { |
| 168 | return SVGTests::requiredFeatures(*this); |
| 169 | } |
| 170 | |
| 171 | Ref<SVGStringList> SVGMaskElement::requiredExtensions() |
| 172 | { |
| 173 | return SVGTests::requiredExtensions(*this); |
| 174 | } |
| 175 | |
| 176 | Ref<SVGStringList> SVGMaskElement::systemLanguage() |
| 177 | { |
| 178 | return SVGTests::systemLanguage(*this); |
| 179 | } |
| 180 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 181 | } |