Remove unused variable movedSectionLogicalTop from table layout code.
[chromium-blink-merge.git] / third_party / WebKit / Source / core / svg / SVGRectElement.cpp
blobc5afe4f4f8f58b0aa1e217dfe7d1d8ef8111ce01
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>
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.
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.
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.
21 #include "config.h"
22 #include "core/svg/SVGRectElement.h"
24 #include "core/layout/svg/LayoutSVGRect.h"
25 #include "core/svg/SVGLength.h"
27 namespace blink {
29 inline SVGRectElement::SVGRectElement(Document& document)
30 : SVGGeometryElement(SVGNames::rectTag, document)
31 , m_x(SVGAnimatedLength::create(this, SVGNames::xAttr, SVGLength::create(SVGLengthMode::Width), AllowNegativeLengths))
32 , m_y(SVGAnimatedLength::create(this, SVGNames::yAttr, SVGLength::create(SVGLengthMode::Height), AllowNegativeLengths))
33 , m_width(SVGAnimatedLength::create(this, SVGNames::widthAttr, SVGLength::create(SVGLengthMode::Width), ForbidNegativeLengths))
34 , m_height(SVGAnimatedLength::create(this, SVGNames::heightAttr, SVGLength::create(SVGLengthMode::Height), ForbidNegativeLengths))
35 , m_rx(SVGAnimatedLength::create(this, SVGNames::rxAttr, SVGLength::create(SVGLengthMode::Width), ForbidNegativeLengths))
36 , m_ry(SVGAnimatedLength::create(this, SVGNames::ryAttr, SVGLength::create(SVGLengthMode::Height), ForbidNegativeLengths))
38 addToPropertyMap(m_x);
39 addToPropertyMap(m_y);
40 addToPropertyMap(m_width);
41 addToPropertyMap(m_height);
42 addToPropertyMap(m_rx);
43 addToPropertyMap(m_ry);
46 DEFINE_TRACE(SVGRectElement)
48 visitor->trace(m_x);
49 visitor->trace(m_y);
50 visitor->trace(m_width);
51 visitor->trace(m_height);
52 visitor->trace(m_rx);
53 visitor->trace(m_ry);
54 SVGGeometryElement::trace(visitor);
57 DEFINE_NODE_FACTORY(SVGRectElement)
59 Path SVGRectElement::asPath() const
61 Path path;
63 SVGLengthContext lengthContext(this);
64 ASSERT(layoutObject());
65 const ComputedStyle& style = layoutObject()->styleRef();
66 const SVGComputedStyle& svgStyle = style.svgStyle();
68 float width = lengthContext.valueForLength(style.width(), style, SVGLengthMode::Width);
69 if (width < 0)
70 return path;
71 float height = lengthContext.valueForLength(style.height(), style, SVGLengthMode::Height);
72 if (height < 0)
73 return path;
74 if (!width && !height)
75 return path;
77 float x = lengthContext.valueForLength(svgStyle.x(), style, SVGLengthMode::Width);
78 float y = lengthContext.valueForLength(svgStyle.y(), style, SVGLengthMode::Height);
79 float rx = lengthContext.valueForLength(svgStyle.rx(), style, SVGLengthMode::Width);
80 float ry = lengthContext.valueForLength(svgStyle.ry(), style, SVGLengthMode::Height);
81 bool hasRx = rx > 0;
82 bool hasRy = ry > 0;
83 if (hasRx || hasRy) {
84 if (!hasRx)
85 rx = ry;
86 else if (!hasRy)
87 ry = rx;
89 path.addRoundedRect(FloatRect(x, y, width, height), FloatSize(rx, ry));
90 return path;
93 path.addRect(FloatRect(x, y, width, height));
94 return path;
97 bool SVGRectElement::isPresentationAttribute(const QualifiedName& attrName) const
99 if (attrName == SVGNames::xAttr || attrName == SVGNames::yAttr
100 || attrName == SVGNames::widthAttr || attrName == SVGNames::heightAttr
101 || attrName == SVGNames::rxAttr || attrName == SVGNames::ryAttr)
102 return true;
103 return SVGGeometryElement::isPresentationAttribute(attrName);
106 bool SVGRectElement::isPresentationAttributeWithSVGDOM(const QualifiedName& attrName) const
108 if (attrName == SVGNames::xAttr || attrName == SVGNames::yAttr
109 || attrName == SVGNames::widthAttr || attrName == SVGNames::heightAttr
110 || attrName == SVGNames::rxAttr || attrName == SVGNames::ryAttr)
111 return true;
112 return SVGGeometryElement::isPresentationAttributeWithSVGDOM(attrName);
115 void SVGRectElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStylePropertySet* style)
117 RefPtrWillBeRawPtr<SVGAnimatedPropertyBase> property = propertyFromAttribute(name);
118 if (property == m_x)
119 addSVGLengthPropertyToPresentationAttributeStyle(style, CSSPropertyX, *m_x->currentValue());
120 else if (property == m_y)
121 addSVGLengthPropertyToPresentationAttributeStyle(style, CSSPropertyY, *m_y->currentValue());
122 else if (property == m_width)
123 addSVGLengthPropertyToPresentationAttributeStyle(style, CSSPropertyWidth, *m_width->currentValue());
124 else if (property == m_height)
125 addSVGLengthPropertyToPresentationAttributeStyle(style, CSSPropertyHeight, *m_height->currentValue());
126 else if (property == m_rx)
127 addSVGLengthPropertyToPresentationAttributeStyle(style, CSSPropertyRx, *m_rx->currentValue());
128 else if (property == m_ry)
129 addSVGLengthPropertyToPresentationAttributeStyle(style, CSSPropertyRy, *m_ry->currentValue());
130 else
131 SVGGeometryElement::collectStyleForPresentationAttribute(name, value, style);
134 void SVGRectElement::svgAttributeChanged(const QualifiedName& attrName)
136 if (attrName == SVGNames::xAttr || attrName == SVGNames::yAttr
137 || attrName == SVGNames::widthAttr || attrName == SVGNames::heightAttr
138 || attrName == SVGNames::rxAttr || attrName == SVGNames::ryAttr) {
139 SVGElement::InvalidationGuard invalidationGuard(this);
141 invalidateSVGPresentationAttributeStyle();
142 setNeedsStyleRecalc(LocalStyleChange,
143 StyleChangeReasonForTracing::fromAttribute(attrName));
144 updateRelativeLengthsInformation();
146 LayoutSVGShape* layoutObject = toLayoutSVGShape(this->layoutObject());
147 if (!layoutObject)
148 return;
150 layoutObject->setNeedsShapeUpdate();
151 markForLayoutAndParentResourceInvalidation(layoutObject);
153 return;
156 SVGGeometryElement::svgAttributeChanged(attrName);
159 bool SVGRectElement::selfHasRelativeLengths() const
161 return m_x->currentValue()->isRelative()
162 || m_y->currentValue()->isRelative()
163 || m_width->currentValue()->isRelative()
164 || m_height->currentValue()->isRelative()
165 || m_rx->currentValue()->isRelative()
166 || m_ry->currentValue()->isRelative();
169 LayoutObject* SVGRectElement::createLayoutObject(const ComputedStyle&)
171 return new LayoutSVGRect(this);
174 } // namespace blink