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 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 25 | #include "core/rendering/svg/RenderSVGRect.h" |
| 26 | #include "core/rendering/svg/RenderSVGResource.h" |
| 27 | #include "core/svg/SVGElementInstance.h" |
| 28 | #include "core/svg/SVGLength.h" |
| 29 | |
| 30 | namespace WebCore { |
| 31 | |
| 32 | // Animated property definitions |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 33 | BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGRectElement) |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 34 | REGISTER_PARENT_ANIMATED_PROPERTIES(SVGGraphicsElement) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 35 | END_REGISTER_ANIMATED_PROPERTIES |
| 36 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 37 | inline SVGRectElement::SVGRectElement(Document& document) |
| 38 | : SVGGeometryElement(SVGNames::rectTag, document) |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame^] | 39 | , m_x(SVGAnimatedLength::create(this, SVGNames::xAttr, SVGLength::create(LengthModeWidth))) |
| 40 | , m_y(SVGAnimatedLength::create(this, SVGNames::yAttr, SVGLength::create(LengthModeHeight))) |
| 41 | , m_width(SVGAnimatedLength::create(this, SVGNames::widthAttr, SVGLength::create(LengthModeWidth))) |
| 42 | , m_height(SVGAnimatedLength::create(this, SVGNames::heightAttr, SVGLength::create(LengthModeHeight))) |
| 43 | , m_rx(SVGAnimatedLength::create(this, SVGNames::rxAttr, SVGLength::create(LengthModeWidth))) |
| 44 | , m_ry(SVGAnimatedLength::create(this, SVGNames::ryAttr, SVGLength::create(LengthModeHeight))) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 45 | { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 46 | ScriptWrappable::init(this); |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame^] | 47 | |
| 48 | addToPropertyMap(m_x); |
| 49 | addToPropertyMap(m_y); |
| 50 | addToPropertyMap(m_width); |
| 51 | addToPropertyMap(m_height); |
| 52 | addToPropertyMap(m_rx); |
| 53 | addToPropertyMap(m_ry); |
| 54 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 55 | registerAnimatedPropertiesForSVGRectElement(); |
| 56 | } |
| 57 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 58 | PassRefPtr<SVGRectElement> SVGRectElement::create(Document& document) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 59 | { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 60 | return adoptRef(new SVGRectElement(document)); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | bool SVGRectElement::isSupportedAttribute(const QualifiedName& attrName) |
| 64 | { |
| 65 | DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ()); |
| 66 | if (supportedAttributes.isEmpty()) { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 67 | supportedAttributes.add(SVGNames::xAttr); |
| 68 | supportedAttributes.add(SVGNames::yAttr); |
| 69 | supportedAttributes.add(SVGNames::widthAttr); |
| 70 | supportedAttributes.add(SVGNames::heightAttr); |
| 71 | supportedAttributes.add(SVGNames::rxAttr); |
| 72 | supportedAttributes.add(SVGNames::ryAttr); |
| 73 | } |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 74 | return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | void SVGRectElement::parseAttribute(const QualifiedName& name, const AtomicString& value) |
| 78 | { |
| 79 | SVGParsingError parseError = NoError; |
| 80 | |
| 81 | if (!isSupportedAttribute(name)) |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 82 | SVGGeometryElement::parseAttribute(name, value); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 83 | else if (name == SVGNames::xAttr) |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame^] | 84 | m_x->setBaseValueAsString(value, AllowNegativeLengths, parseError); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 85 | else if (name == SVGNames::yAttr) |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame^] | 86 | m_y->setBaseValueAsString(value, AllowNegativeLengths, parseError); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 87 | else if (name == SVGNames::rxAttr) |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame^] | 88 | m_rx->setBaseValueAsString(value, ForbidNegativeLengths, parseError); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 89 | else if (name == SVGNames::ryAttr) |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame^] | 90 | m_ry->setBaseValueAsString(value, ForbidNegativeLengths, parseError); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 91 | else if (name == SVGNames::widthAttr) |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame^] | 92 | m_width->setBaseValueAsString(value, ForbidNegativeLengths, parseError); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 93 | else if (name == SVGNames::heightAttr) |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame^] | 94 | m_height->setBaseValueAsString(value, ForbidNegativeLengths, parseError); |
| 95 | else |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 96 | ASSERT_NOT_REACHED(); |
| 97 | |
| 98 | reportAttributeParsingError(parseError, name, value); |
| 99 | } |
| 100 | |
| 101 | void SVGRectElement::svgAttributeChanged(const QualifiedName& attrName) |
| 102 | { |
| 103 | if (!isSupportedAttribute(attrName)) { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 104 | SVGGeometryElement::svgAttributeChanged(attrName); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 105 | return; |
| 106 | } |
| 107 | |
| 108 | SVGElementInstance::InvalidationGuard invalidationGuard(this); |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 109 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 110 | bool isLengthAttribute = attrName == SVGNames::xAttr |
| 111 | || attrName == SVGNames::yAttr |
| 112 | || attrName == SVGNames::widthAttr |
| 113 | || attrName == SVGNames::heightAttr |
| 114 | || attrName == SVGNames::rxAttr |
| 115 | || attrName == SVGNames::ryAttr; |
| 116 | |
| 117 | if (isLengthAttribute) |
| 118 | updateRelativeLengthsInformation(); |
| 119 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 120 | RenderSVGShape* renderer = toRenderSVGShape(this->renderer()); |
| 121 | if (!renderer) |
| 122 | return; |
| 123 | |
| 124 | if (isLengthAttribute) { |
| 125 | renderer->setNeedsShapeUpdate(); |
| 126 | RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); |
| 127 | return; |
| 128 | } |
| 129 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 130 | ASSERT_NOT_REACHED(); |
| 131 | } |
| 132 | |
| 133 | bool SVGRectElement::selfHasRelativeLengths() const |
| 134 | { |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame^] | 135 | return m_x->currentValue()->isRelative() |
| 136 | || m_y->currentValue()->isRelative() |
| 137 | || m_width->currentValue()->isRelative() |
| 138 | || m_height->currentValue()->isRelative() |
| 139 | || m_rx->currentValue()->isRelative() |
| 140 | || m_ry->currentValue()->isRelative(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 141 | } |
| 142 | |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 143 | RenderObject* SVGRectElement::createRenderer(RenderStyle*) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 144 | { |
Torne (Richard Coles) | f5e4ad5 | 2013-08-05 13:57:57 +0100 | [diff] [blame] | 145 | return new RenderSVGRect(this); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | } |