KHtml

SVGRectElement.cpp
1 /*
2  Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <[email protected]>
3  2004, 2005, 2006, 2007 Rob Buis <[email protected]>
4 
5  This file is part of the KDE project
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 
23 #include "wtf/Platform.h"
24 
25 #if ENABLE(SVG)
26 #include "SVGRectElement.h"
27 
28 #include "RenderPath.h"
29 #include "SVGLength.h"
30 #include "SVGNames.h"
31 
32 namespace WebCore
33 {
34 
35 SVGRectElement::SVGRectElement(const QualifiedName &tagName, Document *doc)
36  : SVGStyledTransformableElement(tagName, doc)
37  , SVGTests()
38  , SVGLangSpace()
39  , SVGExternalResourcesRequired()
40  , m_x(this, LengthModeWidth)
41  , m_y(this, LengthModeHeight)
42  , m_width(this, LengthModeWidth)
43  , m_height(this, LengthModeHeight)
44  , m_rx(this, LengthModeWidth)
45  , m_ry(this, LengthModeHeight)
46 {
47 }
48 
49 SVGRectElement::~SVGRectElement()
50 {
51 }
52 
53 ANIMATED_PROPERTY_DEFINITIONS(SVGRectElement, SVGLength, Length, length, X, x, SVGNames::xAttr, m_x)
54 ANIMATED_PROPERTY_DEFINITIONS(SVGRectElement, SVGLength, Length, length, Y, y, SVGNames::yAttr, m_y)
55 ANIMATED_PROPERTY_DEFINITIONS(SVGRectElement, SVGLength, Length, length, Width, width, SVGNames::widthAttr, m_width)
56 ANIMATED_PROPERTY_DEFINITIONS(SVGRectElement, SVGLength, Length, length, Height, height, SVGNames::heightAttr, m_height)
57 ANIMATED_PROPERTY_DEFINITIONS(SVGRectElement, SVGLength, Length, length, Rx, rx, SVGNames::rxAttr, m_rx)
58 ANIMATED_PROPERTY_DEFINITIONS(SVGRectElement, SVGLength, Length, length, Ry, ry, SVGNames::ryAttr, m_ry)
59 
60 void SVGRectElement::parseMappedAttribute(MappedAttribute *attr)
61 {
62  // qCDebug(KHTML_LOG) << "called with" << attr->localName() << attr->value();
63  if (attr->name() == SVGNames::xAttr) {
64  setXBaseValue(SVGLength(this, LengthModeWidth, attr->value()));
65  } else if (attr->name() == SVGNames::yAttr) {
66  setYBaseValue(SVGLength(this, LengthModeHeight, attr->value()));
67  } else if (attr->name() == SVGNames::rxAttr) {
68  setRxBaseValue(SVGLength(this, LengthModeWidth, attr->value()));
69  if (rx().value() < 0.0) {
70  document()->accessSVGExtensions()->reportError("A negative value for rect <rx> is not allowed");
71  }
72  } else if (attr->name() == SVGNames::ryAttr) {
73  setRyBaseValue(SVGLength(this, LengthModeHeight, attr->value()));
74  if (ry().value() < 0.0) {
75  document()->accessSVGExtensions()->reportError("A negative value for rect <ry> is not allowed");
76  }
77  } else if (attr->name() == SVGNames::widthAttr) {
78  setWidthBaseValue(SVGLength(this, LengthModeWidth, attr->value()));
79  if (width().value() < 0.0) {
80  document()->accessSVGExtensions()->reportError("A negative value for rect <width> is not allowed");
81  }
82  } else if (attr->name() == SVGNames::heightAttr) {
83  setHeightBaseValue(SVGLength(this, LengthModeHeight, attr->value()));
84  if (height().value() < 0.0) {
85  document()->accessSVGExtensions()->reportError("A negative value for rect <height> is not allowed");
86  }
87  } else {
88  if (SVGTests::parseMappedAttribute(attr)) {
89  return;
90  }
91  if (SVGLangSpace::parseMappedAttribute(attr)) {
92  return;
93  }
94  if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) {
95  return;
96  }
97  SVGStyledTransformableElement::parseMappedAttribute(attr);
98  }
99 }
100 
101 void SVGRectElement::svgAttributeChanged(const QualifiedName &attrName)
102 {
103  SVGStyledTransformableElement::svgAttributeChanged(attrName);
104 
105  if (!renderer()) {
106  return;
107  }
108 
109  if (attrName == SVGNames::xAttr || attrName == SVGNames::yAttr ||
110  attrName == SVGNames::widthAttr || attrName == SVGNames::heightAttr ||
111  attrName == SVGNames::rxAttr || attrName == SVGNames::ryAttr ||
112  SVGTests::isKnownAttribute(attrName) ||
113  SVGLangSpace::isKnownAttribute(attrName) ||
114  SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
115  SVGStyledTransformableElement::isKnownAttribute(attrName)) {
116  renderer()->setNeedsLayout(true);
117  }
118 }
119 
120 Path SVGRectElement::toPathData() const
121 {
122  FloatRect rect(x().value(), y().value(), width().value(), height().value());
123 
124  bool hasRx = hasAttribute(SVGNames::rxAttr);
125  bool hasRy = hasAttribute(SVGNames::ryAttr);
126  if (hasRx || hasRy) {
127  float _rx = hasRx ? rx().value() : ry().value();
128  float _ry = hasRy ? ry().value() : rx().value();
129  return Path::createRoundedRectangle(rect, FloatSize(_rx, _ry));
130  }
131 
132  return Path::createRectangle(rect);
133 }
134 
135 bool SVGRectElement::hasRelativeValues() const
136 {
137  return (x().isRelative() || width().isRelative() ||
138  y().isRelative() || height().isRelative() ||
139  rx().isRelative() || ry().isRelative());
140 }
141 
142 // KHTML ElementImpl pure virtual method
143 quint32 SVGRectElement::id() const
144 {
145  return SVGNames::rectTag.id();
146 }
147 
148 }
149 
150 #endif // ENABLE(SVG)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 22:48:10 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.