Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1 | /* |
| 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 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Library General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Library General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Library General Public License |
| 16 | * along with this library; see the file COPYING.LIB. If not, write to |
| 17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 | * Boston, MA 02110-1301, USA. |
| 19 | */ |
| 20 | |
| 21 | #include "config.h" |
| 22 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 23 | #include "core/svg/SVGRectElement.h" |
| 24 | |
| 25 | #include "SVGNames.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 26 | #include "core/rendering/svg/RenderSVGRect.h" |
| 27 | #include "core/rendering/svg/RenderSVGResource.h" |
| 28 | #include "core/svg/SVGElementInstance.h" |
| 29 | #include "core/svg/SVGLength.h" |
| 30 | |
| 31 | namespace WebCore { |
| 32 | |
| 33 | // Animated property definitions |
| 34 | DEFINE_ANIMATED_LENGTH(SVGRectElement, SVGNames::xAttr, X, x) |
| 35 | DEFINE_ANIMATED_LENGTH(SVGRectElement, SVGNames::yAttr, Y, y) |
| 36 | DEFINE_ANIMATED_LENGTH(SVGRectElement, SVGNames::widthAttr, Width, width) |
| 37 | DEFINE_ANIMATED_LENGTH(SVGRectElement, SVGNames::heightAttr, Height, height) |
| 38 | DEFINE_ANIMATED_LENGTH(SVGRectElement, SVGNames::rxAttr, Rx, rx) |
| 39 | DEFINE_ANIMATED_LENGTH(SVGRectElement, SVGNames::ryAttr, Ry, ry) |
| 40 | DEFINE_ANIMATED_BOOLEAN(SVGRectElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) |
| 41 | |
| 42 | BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGRectElement) |
| 43 | REGISTER_LOCAL_ANIMATED_PROPERTY(x) |
| 44 | REGISTER_LOCAL_ANIMATED_PROPERTY(y) |
| 45 | REGISTER_LOCAL_ANIMATED_PROPERTY(width) |
| 46 | REGISTER_LOCAL_ANIMATED_PROPERTY(height) |
| 47 | REGISTER_LOCAL_ANIMATED_PROPERTY(rx) |
| 48 | REGISTER_LOCAL_ANIMATED_PROPERTY(ry) |
| 49 | REGISTER_LOCAL_ANIMATED_PROPERTY(externalResourcesRequired) |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 50 | REGISTER_PARENT_ANIMATED_PROPERTIES(SVGGraphicsElement) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 51 | END_REGISTER_ANIMATED_PROPERTIES |
| 52 | |
| 53 | inline SVGRectElement::SVGRectElement(const QualifiedName& tagName, Document* document) |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 54 | : SVGGraphicsElement(tagName, document) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 55 | , m_x(LengthModeWidth) |
| 56 | , m_y(LengthModeHeight) |
| 57 | , m_width(LengthModeWidth) |
| 58 | , m_height(LengthModeHeight) |
| 59 | , m_rx(LengthModeWidth) |
| 60 | , m_ry(LengthModeHeight) |
| 61 | { |
| 62 | ASSERT(hasTagName(SVGNames::rectTag)); |
| 63 | ScriptWrappable::init(this); |
| 64 | registerAnimatedPropertiesForSVGRectElement(); |
| 65 | } |
| 66 | |
| 67 | PassRefPtr<SVGRectElement> SVGRectElement::create(const QualifiedName& tagName, Document* document) |
| 68 | { |
| 69 | return adoptRef(new SVGRectElement(tagName, document)); |
| 70 | } |
| 71 | |
| 72 | bool SVGRectElement::isSupportedAttribute(const QualifiedName& attrName) |
| 73 | { |
| 74 | DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ()); |
| 75 | if (supportedAttributes.isEmpty()) { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 76 | SVGLangSpace::addSupportedAttributes(supportedAttributes); |
| 77 | SVGExternalResourcesRequired::addSupportedAttributes(supportedAttributes); |
| 78 | supportedAttributes.add(SVGNames::xAttr); |
| 79 | supportedAttributes.add(SVGNames::yAttr); |
| 80 | supportedAttributes.add(SVGNames::widthAttr); |
| 81 | supportedAttributes.add(SVGNames::heightAttr); |
| 82 | supportedAttributes.add(SVGNames::rxAttr); |
| 83 | supportedAttributes.add(SVGNames::ryAttr); |
| 84 | } |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 85 | return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | void SVGRectElement::parseAttribute(const QualifiedName& name, const AtomicString& value) |
| 89 | { |
| 90 | SVGParsingError parseError = NoError; |
| 91 | |
| 92 | if (!isSupportedAttribute(name)) |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 93 | SVGGraphicsElement::parseAttribute(name, value); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 94 | else if (name == SVGNames::xAttr) |
| 95 | setXBaseValue(SVGLength::construct(LengthModeWidth, value, parseError)); |
| 96 | else if (name == SVGNames::yAttr) |
| 97 | setYBaseValue(SVGLength::construct(LengthModeHeight, value, parseError)); |
| 98 | else if (name == SVGNames::rxAttr) |
| 99 | setRxBaseValue(SVGLength::construct(LengthModeWidth, value, parseError, ForbidNegativeLengths)); |
| 100 | else if (name == SVGNames::ryAttr) |
| 101 | setRyBaseValue(SVGLength::construct(LengthModeHeight, value, parseError, ForbidNegativeLengths)); |
| 102 | else if (name == SVGNames::widthAttr) |
| 103 | setWidthBaseValue(SVGLength::construct(LengthModeWidth, value, parseError, ForbidNegativeLengths)); |
| 104 | else if (name == SVGNames::heightAttr) |
| 105 | setHeightBaseValue(SVGLength::construct(LengthModeHeight, value, parseError, ForbidNegativeLengths)); |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 106 | else if (SVGLangSpace::parseAttribute(name, value) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 107 | || SVGExternalResourcesRequired::parseAttribute(name, value)) { |
| 108 | } else |
| 109 | ASSERT_NOT_REACHED(); |
| 110 | |
| 111 | reportAttributeParsingError(parseError, name, value); |
| 112 | } |
| 113 | |
| 114 | void SVGRectElement::svgAttributeChanged(const QualifiedName& attrName) |
| 115 | { |
| 116 | if (!isSupportedAttribute(attrName)) { |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 117 | SVGGraphicsElement::svgAttributeChanged(attrName); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 118 | return; |
| 119 | } |
| 120 | |
| 121 | SVGElementInstance::InvalidationGuard invalidationGuard(this); |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 122 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 123 | bool isLengthAttribute = attrName == SVGNames::xAttr |
| 124 | || attrName == SVGNames::yAttr |
| 125 | || attrName == SVGNames::widthAttr |
| 126 | || attrName == SVGNames::heightAttr |
| 127 | || attrName == SVGNames::rxAttr |
| 128 | || attrName == SVGNames::ryAttr; |
| 129 | |
| 130 | if (isLengthAttribute) |
| 131 | updateRelativeLengthsInformation(); |
| 132 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 133 | RenderSVGShape* renderer = toRenderSVGShape(this->renderer()); |
| 134 | if (!renderer) |
| 135 | return; |
| 136 | |
| 137 | if (isLengthAttribute) { |
| 138 | renderer->setNeedsShapeUpdate(); |
| 139 | RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); |
| 140 | return; |
| 141 | } |
| 142 | |
| 143 | if (SVGLangSpace::isKnownAttribute(attrName) || SVGExternalResourcesRequired::isKnownAttribute(attrName)) { |
| 144 | RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); |
| 145 | return; |
| 146 | } |
| 147 | |
| 148 | ASSERT_NOT_REACHED(); |
| 149 | } |
| 150 | |
| 151 | bool SVGRectElement::selfHasRelativeLengths() const |
| 152 | { |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 153 | return xCurrentValue().isRelative() |
| 154 | || yCurrentValue().isRelative() |
| 155 | || widthCurrentValue().isRelative() |
| 156 | || heightCurrentValue().isRelative() |
| 157 | || rxCurrentValue().isRelative() |
| 158 | || ryCurrentValue().isRelative(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 159 | } |
| 160 | |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 161 | RenderObject* SVGRectElement::createRenderer(RenderStyle*) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 162 | { |
Torne (Richard Coles) | f5e4ad5 | 2013-08-05 13:57:57 +0100 | [diff] [blame^] | 163 | return new RenderSVGRect(this); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | } |