25#include <wtf/Platform.h>
32#include "css/csshelper.h"
43#include "RenderSVGRoot.h"
61using namespace SVGNames;
63SVGSVGElement::SVGSVGElement(
const QualifiedName& tagName, Document* doc)
64 : SVGStyledLocatableElement(tagName, doc)
67 , SVGExternalResourcesRequired()
70 , m_x(this, LengthModeWidth)
71 , m_y(this, LengthModeHeight)
72 , m_width(this, LengthModeWidth)
73 , m_height(this, LengthModeHeight)
74 , m_useCurrentView(false)
78 setWidthBaseValue(SVGLength(
this, LengthModeWidth,
"100%"));
79 setHeightBaseValue(SVGLength(
this, LengthModeHeight,
"100%"));
83SVGSVGElement::~SVGSVGElement()
91ANIMATED_PROPERTY_DEFINITIONS(SVGSVGElement, SVGLength, Length, length,
X, x, SVGNames::xAttr, m_x)
92ANIMATED_PROPERTY_DEFINITIONS(SVGSVGElement, SVGLength, Length, length, Y, y, SVGNames::yAttr, m_y)
93ANIMATED_PROPERTY_DEFINITIONS(SVGSVGElement, SVGLength, Length, length, Width, width, SVGNames::widthAttr, m_width)
94ANIMATED_PROPERTY_DEFINITIONS(SVGSVGElement, SVGLength, Length, length, Height, height, SVGNames::heightAttr, m_height)
96DOMString SVGSVGElement::contentScriptType()
const
99 DOMString n = getAttribute(contentScriptTypeAttr);
103void SVGSVGElement::setContentScriptType(
const DOMString& type)
105 setAttribute(SVGNames::contentScriptTypeAttr, type);
108DOMString SVGSVGElement::contentStyleType()
const
111 const DOMString n = getAttribute(contentStyleTypeAttr);
115void SVGSVGElement::setContentStyleType(
const DOMString& type)
117 setAttribute(SVGNames::contentStyleTypeAttr, type);
120bool SVGSVGElement::hasSetContainerSize()
const
125 return isOutermostSVG() && document()->part()->parentPart();
128IntSize SVGSVGElement::containerSize()
const
131 return IntSize(v->visibleWidth(), v->visibleHeight());
133 return IntSize(300, 150);
136FloatRect SVGSVGElement::viewport()
const
140 if (!isOutermostSVG()) {
144 float w = width().value();
145 float h = height().value();
146 AffineTransform viewBox = viewBoxToViewTransform(w, h);
149 viewBox.map(_x, _y, &_x, &_y);
150 viewBox.map(w, h, &wDouble, &hDouble);
151 return FloatRect::narrowPrecision(_x, _y, wDouble, hDouble);
154int SVGSVGElement::relativeWidthValue()
const
156 SVGLength w = width();
157 if (w.unitType() != LengthTypePercentage)
160 return static_cast<int>(w.valueAsPercentage() * containerSize().width());
163int SVGSVGElement::relativeHeightValue()
const
165 SVGLength h = height();
166 if (h.unitType() != LengthTypePercentage)
169 return static_cast<int>(h.valueAsPercentage() * containerSize().height());
172float SVGSVGElement::pixelUnitToMillimeterX()
const
175 return (2.54f / cssPixelsPerInch) * 10.0f;
178float SVGSVGElement::pixelUnitToMillimeterY()
const
181 return (2.54f / cssPixelsPerInch) * 10.0f;
184float SVGSVGElement::screenPixelToMillimeterX()
const
186 return pixelUnitToMillimeterX();
189float SVGSVGElement::screenPixelToMillimeterY()
const
191 return pixelUnitToMillimeterY();
194bool SVGSVGElement::useCurrentView()
const
196 return m_useCurrentView;
199void SVGSVGElement::setUseCurrentView(
bool currentView)
201 m_useCurrentView = currentView;
204SVGViewSpec* SVGSVGElement::currentView()
const
207 m_viewSpec.set(
new SVGViewSpec(
this));
209 return m_viewSpec.get();
212float SVGSVGElement::currentScale()
const
219void SVGSVGElement::setCurrentScale(
float scale)
226FloatPoint SVGSVGElement::currentTranslate()
const
228 return m_translation;
231void SVGSVGElement::setCurrentTranslate(
const FloatPoint &translation)
233 m_translation = translation;
234 if (parentNode() == document() && document()->renderer())
235 document()->renderer()->repaint();
238void SVGSVGElement::addSVGWindowEventListener(
const AtomicString& eventType,
const Attribute* attr)
243 RefPtr<EventListener> listener = document()->accessSVGExtensions()->
244 createSVGEventListener(attr->localName().string(), attr->value(),
this);
248void SVGSVGElement::parseMappedAttribute(MappedAttribute* attr)
250 kDebug() <<
"parse attribute: " << attr->localName() << attr->value() << endl;
251 if (!nearestViewportElement()) {
266 if (attr->name() == SVGNames::xAttr)
267 setXBaseValue(SVGLength(
this, LengthModeWidth, attr->value()));
268 else if (attr->name() == SVGNames::yAttr)
269 setYBaseValue(SVGLength(
this, LengthModeHeight, attr->value()));
270 else if (attr->name() == SVGNames::widthAttr) {
271 kDebug() <<
"set width" << attr->value() << endl;
272 setWidthBaseValue(SVGLength(
this, LengthModeWidth, attr->value()));
273 addCSSProperty(attr, CSSPropertyWidth, attr->value());
276 }
else if (attr->name() == SVGNames::heightAttr) {
277 kDebug() <<
"set height" << attr->value() << endl;
278 setHeightBaseValue(SVGLength(
this, LengthModeHeight, attr->value()));
279 addCSSProperty(attr, CSSPropertyHeight, attr->value());
294 SVGStyledLocatableElement::parseMappedAttribute(attr);
298void SVGSVGElement::svgAttributeChanged(
const QualifiedName& attrName)
300 SVGStyledElement::svgAttributeChanged(attrName);
316unsigned long SVGSVGElement::suspendRedraw(
unsigned long )
322void SVGSVGElement::unsuspendRedraw(
unsigned long , ExceptionCode& )
328void SVGSVGElement::unsuspendRedrawAll()
333void SVGSVGElement::forceRedraw()
338DOM::NodeListImpl* SVGSVGElement::getIntersectionList(
const FloatRect& rect, SVGElement*)
345DOM::NodeListImpl* SVGSVGElement::getEnclosureList(
const FloatRect& rect, SVGElement*)
352bool SVGSVGElement::checkIntersection(SVGElement* element,
const FloatRect& rect)
358 return rect.intersects(getBBox());
361bool SVGSVGElement::checkEnclosure(SVGElement* element,
const FloatRect& rect)
367 return rect.contains(getBBox());
370void SVGSVGElement::deselectAll()
375float SVGSVGElement::createSVGNumber()
380SVGLength SVGSVGElement::createSVGLength()
385SVGAngle* SVGSVGElement::createSVGAngle()
387 return new SVGAngle();
390FloatPoint SVGSVGElement::createSVGPoint()
395AffineTransform SVGSVGElement::createSVGMatrix()
397 return AffineTransform();
400FloatRect SVGSVGElement::createSVGRect()
405SVGTransform SVGSVGElement::createSVGTransform()
407 return SVGTransform();
410SVGTransform SVGSVGElement::createSVGTransformFromMatrix(
const AffineTransform& matrix)
412 return SVGTransform(matrix);
415AffineTransform SVGSVGElement::getCTM()
const
418 if (!isOutermostSVG())
419 mat.translate(x().value(), y().value());
421 if (attributes()->getNamedItem(SVGNames::viewBoxAttr)) {
422 AffineTransform viewBox = viewBoxToViewTransform(width().value(), height().value());
429AffineTransform SVGSVGElement::getScreenCTM()
const
460 return AffineTransform();
463RenderObject* SVGSVGElement::createRenderer(RenderArena* arena, RenderStyle*)
465 kDebug() <<
"create RenderSVGRoot from <svg> element" << endl;
466 return new (arena) RenderSVGRoot(
this);
473void SVGSVGElement::insertedIntoDocument()
475 document()->accessSVGExtensions()->addTimeContainer(
this);
476 SVGStyledLocatableElement::insertedIntoDocument();
479void SVGSVGElement::removedFromDocument()
481 document()->accessSVGExtensions()->removeTimeContainer(
this);
482 SVGStyledLocatableElement::removedFromDocument();
485void SVGSVGElement::pauseAnimations()
491void SVGSVGElement::unpauseAnimations()
497bool SVGSVGElement::animationsPaused()
const
504float SVGSVGElement::getCurrentTime()
const
511void SVGSVGElement::setCurrentTime(
float )
516bool SVGSVGElement::hasRelativeValues()
const
518 return (x().isRelative() || width().isRelative() ||
519 y().isRelative() || height().isRelative());
522bool SVGSVGElement::isOutermostSVG()
const
525 return !parentNode()->isSVGElement();
528AffineTransform SVGSVGElement::viewBoxToViewTransform(
float viewWidth,
float viewHeight)
const
530 FloatRect viewBoxRect;
531 if (useCurrentView()) {
533 viewBoxRect = currentView()->viewBox();
535 viewBoxRect = viewBox();
536 if (!viewBoxRect.width() || !viewBoxRect.height())
537 return AffineTransform();
539 AffineTransform ctm = preserveAspectRatio()->getCTM(viewBoxRect.x(),
540 viewBoxRect.y(), viewBoxRect.width(), viewBoxRect.height(),
541 0, 0, viewWidth, viewHeight);
543 if (useCurrentView() && currentView())
544 return currentView()->transform()->concatenate().matrix() * ctm;
568void SVGSVGElement::willSaveToCache()
573void SVGSVGElement::willRestoreFromCache()
579quint32 SVGSVGElement::id()
const {
return SVGNames::svgTag.id(); }
Renders and displays HTML in a QScrollArea.
QString defaultValue(const QString &t)