• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KHTML

  • sources
  • kde-4.14
  • kdelibs
  • khtml
  • svg
SVGRectElement.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3  2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
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 "config.h"
24 #include "wtf/Platform.h"
25 
26 #if ENABLE(SVG)
27 #include "SVGRectElement.h"
28 
29 #include "RenderPath.h"
30 #include "SVGLength.h"
31 #include "SVGNames.h"
32 
33 namespace WebCore {
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  kDebug() << "called with" << attr->localName() << attr->value() << endl;
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  } else if (attr->name() == SVGNames::ryAttr) {
72  setRyBaseValue(SVGLength(this, LengthModeHeight, attr->value()));
73  if (ry().value() < 0.0)
74  document()->accessSVGExtensions()->reportError("A negative value for rect <ry> is not allowed");
75  } else if (attr->name() == SVGNames::widthAttr) {
76  setWidthBaseValue(SVGLength(this, LengthModeWidth, attr->value()));
77  if (width().value() < 0.0)
78  document()->accessSVGExtensions()->reportError("A negative value for rect <width> is not allowed");
79  } else if (attr->name() == SVGNames::heightAttr) {
80  setHeightBaseValue(SVGLength(this, LengthModeHeight, attr->value()));
81  if (height().value() < 0.0)
82  document()->accessSVGExtensions()->reportError("A negative value for rect <height> is not allowed");
83  } else {
84  if (SVGTests::parseMappedAttribute(attr))
85  return;
86  if (SVGLangSpace::parseMappedAttribute(attr))
87  return;
88  if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
89  return;
90  SVGStyledTransformableElement::parseMappedAttribute(attr);
91  }
92 }
93 
94 void SVGRectElement::svgAttributeChanged(const QualifiedName& attrName)
95 {
96  SVGStyledTransformableElement::svgAttributeChanged(attrName);
97 
98  if (!renderer())
99  return;
100 
101  if (attrName == SVGNames::xAttr || attrName == SVGNames::yAttr ||
102  attrName == SVGNames::widthAttr || attrName == SVGNames::heightAttr ||
103  attrName == SVGNames::rxAttr || attrName == SVGNames::ryAttr ||
104  SVGTests::isKnownAttribute(attrName) ||
105  SVGLangSpace::isKnownAttribute(attrName) ||
106  SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
107  SVGStyledTransformableElement::isKnownAttribute(attrName))
108  renderer()->setNeedsLayout(true);
109 }
110 
111 Path SVGRectElement::toPathData() const
112 {
113  FloatRect rect(x().value(), y().value(), width().value(), height().value());
114 
115  bool hasRx = hasAttribute(SVGNames::rxAttr);
116  bool hasRy = hasAttribute(SVGNames::ryAttr);
117  if (hasRx || hasRy) {
118  float _rx = hasRx ? rx().value() : ry().value();
119  float _ry = hasRy ? ry().value() : rx().value();
120  return Path::createRoundedRectangle(rect, FloatSize(_rx, _ry));
121  }
122 
123  return Path::createRectangle(rect);
124 }
125 
126 bool SVGRectElement::hasRelativeValues() const
127 {
128  return (x().isRelative() || width().isRelative() ||
129  y().isRelative() || height().isRelative() ||
130  rx().isRelative() || ry().isRelative());
131 }
132 
133 // KHTML ElementImpl pure virtual method
134 quint32 SVGRectElement::id() const
135 {
136  return SVGNames::rectTag.id();
137 }
138 
139 }
140 
141 #endif // ENABLE(SVG)
WebCore::SVGNames::widthAttr
DOM::QualifiedName widthAttr
Definition: SVGNames.cpp:334
DOM::QualifiedName::id
unsigned id() const
Definition: QualifiedName.cpp:90
WebCore::SVGNames::rxAttr
DOM::QualifiedName rxAttr
Definition: SVGNames.cpp:272
quint32
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
SVGLength.h
WebCore::Path
khtml::Path Path
Definition: PathTraversalState.h:37
WebCore::SVGNames::rectTag
DOM::QualifiedName rectTag
Definition: SVGNames.cpp:87
SVGRectElement.h
WebCore::SVGNames::yAttr
DOM::QualifiedName yAttr
Definition: SVGNames.cpp:343
WebCore::SVGNames::heightAttr
DOM::QualifiedName heightAttr
Definition: SVGNames.cpp:186
SVGNames.h
WebCore::SVGNames::ryAttr
DOM::QualifiedName ryAttr
Definition: SVGNames.cpp:273
WebCore::SVGNames::xAttr
DOM::QualifiedName xAttr
Definition: SVGNames.cpp:338
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:26:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal