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