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

KHTML

  • khtml
  • svg
SVGForeignObjectElement.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2006 Apple Computer, Inc.
3 (C) 2008 Nikolas Zimmermann <zimmermann@kde.org>
4
5 This file is part of the WebKit 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
25#if ENABLE(SVG) && ENABLE(SVG_FOREIGN_OBJECT)
26#include "SVGForeignObjectElement.h"
27
28#include "CSSPropertyNames.h"
29#include "RenderForeignObject.h"
30#include "SVGNames.h"
31#include "SVGLength.h"
32
33#include <wtf/Assertions.h>
34
35namespace WebCore {
36
37SVGForeignObjectElement::SVGForeignObjectElement(const QualifiedName& tagName, Document *doc)
38 : SVGStyledTransformableElement(tagName, doc)
39 , SVGTests()
40 , SVGLangSpace()
41 , SVGExternalResourcesRequired()
42 , m_x(this, LengthModeWidth)
43 , m_y(this, LengthModeHeight)
44 , m_width(this, LengthModeWidth)
45 , m_height(this, LengthModeHeight)
46{
47}
48
49SVGForeignObjectElement::~SVGForeignObjectElement()
50{
51}
52
53ANIMATED_PROPERTY_DEFINITIONS(SVGForeignObjectElement, SVGLength, Length, length, X, x, SVGNames::xAttr, m_x)
54ANIMATED_PROPERTY_DEFINITIONS(SVGForeignObjectElement, SVGLength, Length, length, Y, y, SVGNames::yAttr, m_y)
55ANIMATED_PROPERTY_DEFINITIONS(SVGForeignObjectElement, SVGLength, Length, length, Width, width, SVGNames::widthAttr, m_width)
56ANIMATED_PROPERTY_DEFINITIONS(SVGForeignObjectElement, SVGLength, Length, length, Height, height, SVGNames::heightAttr, m_height)
57
58void SVGForeignObjectElement::parseMappedAttribute(MappedAttribute* attr)
59{
60 const AtomicString& value = attr->value();
61 if (attr->name() == SVGNames::xAttr)
62 setXBaseValue(SVGLength(this, LengthModeWidth, value));
63 else if (attr->name() == SVGNames::yAttr)
64 setYBaseValue(SVGLength(this, LengthModeHeight, value));
65 else if (attr->name() == SVGNames::widthAttr)
66 setWidthBaseValue(SVGLength(this, LengthModeWidth, value));
67 else if (attr->name() == SVGNames::heightAttr)
68 setHeightBaseValue(SVGLength(this, LengthModeHeight, value));
69 else {
70 if (SVGTests::parseMappedAttribute(attr))
71 return;
72 if (SVGLangSpace::parseMappedAttribute(attr))
73 return;
74 if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
75 return;
76 SVGStyledTransformableElement::parseMappedAttribute(attr);
77 }
78}
79
80// TODO: Move this function in some SVG*Element base class, as SVGSVGElement / SVGImageElement will need the same logic!
81
82// This function mimics addCSSProperty and StyledElement::attributeChanged.
83// In HTML code, you'd always call addCSSProperty from your derived parseMappedAttribute()
84// function - though in SVG code we need to move this logic into svgAttributeChanged, in
85// order to support SVG DOM changes (which don't use the parseMappedAttribute/attributeChanged).
86// If we'd ignore SVG DOM, we could use _exactly_ the same logic as HTML.
87static inline void addCSSPropertyAndNotifyAttributeMap(StyledElement* element, const QualifiedName& name, int cssProperty, const String& value)
88{
89 ASSERT(element);
90
91 if (!element)
92 return;
93
94 NamedMappedAttrMap* attrs = element->mappedAttributes();
95 ASSERT(attrs);
96
97 if (!attrs)
98 return;
99
100 MappedAttribute* mappedAttr = attrs->getAttributeItem(name);
101 if (!mappedAttr)
102 return;
103
104 // This logic is only meant to be used for entries that have to be parsed and are mapped to eNone. Assert that.
105 MappedAttributeEntry entry;
106 bool needToParse = element->mapToEntry(mappedAttr->name(), entry);
107
108 ASSERT(needToParse);
109 ASSERT(entry == eNone);
110
111 if (!needToParse || entry != eNone)
112 return;
113
114 if (mappedAttr->decl()) {
115 mappedAttr->setDecl(0);
116 attrs->declRemoved();
117 }
118
119 element->setChanged();
120 element->addCSSProperty(mappedAttr, cssProperty, value);
121
122 if (CSSMappedAttributeDeclaration* decl = mappedAttr->decl()) {
123 // Add the decl to the table in the appropriate spot.
124 element->setMappedAttributeDecl(entry, mappedAttr, decl);
125
126 decl->setMappedState(entry, mappedAttr->name(), mappedAttr->value());
127 decl->setParent(0);
128 decl->setNode(0);
129
130 attrs->declAdded();
131 }
132}
133
134void SVGForeignObjectElement::svgAttributeChanged(const QualifiedName& attrName)
135{
136 SVGStyledTransformableElement::svgAttributeChanged(attrName);
137
138 if (attrName == SVGNames::widthAttr) {
139 addCSSPropertyAndNotifyAttributeMap(this, attrName, CSSPropertyWidth, width().valueAsString());
140 return;
141 } else if (attrName == SVGNames::heightAttr) {
142 addCSSPropertyAndNotifyAttributeMap(this, attrName, CSSPropertyHeight, height().valueAsString());
143 return;
144 }
145
146 if (!renderer())
147 return;
148
149 if (attrName == SVGNames::xAttr || attrName == SVGNames::yAttr ||
150 SVGTests::isKnownAttribute(attrName) ||
151 SVGLangSpace::isKnownAttribute(attrName) ||
152 SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
153 SVGStyledTransformableElement::isKnownAttribute(attrName))
154 renderer()->setNeedsLayout(true);
155}
156
157RenderObject* SVGForeignObjectElement::createRenderer(RenderArena* arena, RenderStyle* style)
158{
159 return new (arena) RenderForeignObject(this);
160}
161
162bool SVGForeignObjectElement::childShouldCreateRenderer(Node* child) const
163{
164 // Skip over SVG rules which disallow non-SVG kids
165 return StyledElement::childShouldCreateRenderer(child);
166}
167
168} // namespace WebCore
169
170#endif // ENABLE(SVG) && ENABLE(SVG_FOREIGN_OBJECT)
SVGForeignObjectElement.h
SVGLength.h
SVGNames.h
WebCore
Definition: CSSHelper.h:7
X
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 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
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