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