OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> |
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Rob Buis <buis@kde.org> |
4 * Copyright (C) 2007 Apple Inc. All rights reserved. | 4 * Copyright (C) 2007 Apple Inc. All rights reserved. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 namespace WebCore { | 63 namespace WebCore { |
64 | 64 |
65 // Animated property definitions | 65 // Animated property definitions |
66 | 66 |
67 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGSVGElement) | 67 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGSVGElement) |
68 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGGraphicsElement) | 68 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGGraphicsElement) |
69 END_REGISTER_ANIMATED_PROPERTIES | 69 END_REGISTER_ANIMATED_PROPERTIES |
70 | 70 |
71 inline SVGSVGElement::SVGSVGElement(Document& doc) | 71 inline SVGSVGElement::SVGSVGElement(Document& doc) |
72 : SVGGraphicsElement(SVGNames::svgTag, doc) | 72 : SVGGraphicsElement(SVGNames::svgTag, doc) |
| 73 , SVGFitToViewBox(this) |
73 , m_x(SVGAnimatedLength::create(this, SVGNames::xAttr, SVGLength::create(Len
gthModeWidth))) | 74 , m_x(SVGAnimatedLength::create(this, SVGNames::xAttr, SVGLength::create(Len
gthModeWidth))) |
74 , m_y(SVGAnimatedLength::create(this, SVGNames::yAttr, SVGLength::create(Len
gthModeHeight))) | 75 , m_y(SVGAnimatedLength::create(this, SVGNames::yAttr, SVGLength::create(Len
gthModeHeight))) |
75 , m_width(SVGAnimatedLength::create(this, SVGNames::widthAttr, SVGLength::cr
eate(LengthModeWidth))) | 76 , m_width(SVGAnimatedLength::create(this, SVGNames::widthAttr, SVGLength::cr
eate(LengthModeWidth))) |
76 , m_height(SVGAnimatedLength::create(this, SVGNames::heightAttr, SVGLength::
create(LengthModeHeight))) | 77 , m_height(SVGAnimatedLength::create(this, SVGNames::heightAttr, SVGLength::
create(LengthModeHeight))) |
77 , m_viewBox(SVGAnimatedRect::create(this, SVGNames::viewBoxAttr)) | |
78 , m_preserveAspectRatio(SVGAnimatedPreserveAspectRatio::create(this, SVGName
s::preserveAspectRatioAttr, SVGPreserveAspectRatio::create())) | |
79 , m_useCurrentView(false) | 78 , m_useCurrentView(false) |
80 , m_zoomAndPan(SVGZoomAndPanMagnify) | 79 , m_zoomAndPan(SVGZoomAndPanMagnify) |
81 , m_timeContainer(SMILTimeContainer::create(this)) | 80 , m_timeContainer(SMILTimeContainer::create(this)) |
82 , m_translation(SVGPoint::create()) | 81 , m_translation(SVGPoint::create()) |
83 { | 82 { |
84 ScriptWrappable::init(this); | 83 ScriptWrappable::init(this); |
85 | 84 |
86 m_width->setDefaultValueAsString("100%"); | 85 m_width->setDefaultValueAsString("100%"); |
87 m_height->setDefaultValueAsString("100%"); | 86 m_height->setDefaultValueAsString("100%"); |
88 | 87 |
89 addToPropertyMap(m_x); | 88 addToPropertyMap(m_x); |
90 addToPropertyMap(m_y); | 89 addToPropertyMap(m_y); |
91 addToPropertyMap(m_width); | 90 addToPropertyMap(m_width); |
92 addToPropertyMap(m_height); | 91 addToPropertyMap(m_height); |
93 addToPropertyMap(m_viewBox); | |
94 addToPropertyMap(m_preserveAspectRatio); | |
95 registerAnimatedPropertiesForSVGSVGElement(); | 92 registerAnimatedPropertiesForSVGSVGElement(); |
96 | 93 |
97 UseCounter::count(doc, UseCounter::SVGSVGElement); | 94 UseCounter::count(doc, UseCounter::SVGSVGElement); |
98 } | 95 } |
99 | 96 |
100 PassRefPtr<SVGSVGElement> SVGSVGElement::create(Document& document) | 97 PassRefPtr<SVGSVGElement> SVGSVGElement::create(Document& document) |
101 { | 98 { |
102 return adoptRef(new SVGSVGElement(document)); | 99 return adoptRef(new SVGSVGElement(document)); |
103 } | 100 } |
104 | 101 |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 else if (name == HTMLNames::onerrorAttr) | 274 else if (name == HTMLNames::onerrorAttr) |
278 document().setWindowAttributeEventListener(EventTypeNames::error, create
AttributeEventListener(document().frame(), name, value)); | 275 document().setWindowAttributeEventListener(EventTypeNames::error, create
AttributeEventListener(document().frame(), name, value)); |
279 else if (name == SVGNames::xAttr) | 276 else if (name == SVGNames::xAttr) |
280 m_x->setBaseValueAsString(value, AllowNegativeLengths, parseError); | 277 m_x->setBaseValueAsString(value, AllowNegativeLengths, parseError); |
281 else if (name == SVGNames::yAttr) | 278 else if (name == SVGNames::yAttr) |
282 m_y->setBaseValueAsString(value, AllowNegativeLengths, parseError); | 279 m_y->setBaseValueAsString(value, AllowNegativeLengths, parseError); |
283 else if (name == SVGNames::widthAttr) | 280 else if (name == SVGNames::widthAttr) |
284 m_width->setBaseValueAsString(value, ForbidNegativeLengths, parseError); | 281 m_width->setBaseValueAsString(value, ForbidNegativeLengths, parseError); |
285 else if (name == SVGNames::heightAttr) | 282 else if (name == SVGNames::heightAttr) |
286 m_height->setBaseValueAsString(value, ForbidNegativeLengths, parseError)
; | 283 m_height->setBaseValueAsString(value, ForbidNegativeLengths, parseError)
; |
287 else if (SVGFitToViewBox::parseAttribute(this, name, value) | 284 else if (SVGFitToViewBox::parseAttribute(name, value, document(), parseError
) |
288 || SVGZoomAndPan::parseAttribute(this, name, value)) { | 285 || SVGZoomAndPan::parseAttribute(this, name, value)) { |
289 } else | 286 } else |
290 SVGGraphicsElement::parseAttribute(name, value); | 287 SVGGraphicsElement::parseAttribute(name, value); |
291 | 288 |
292 reportAttributeParsingError(parseError, name, value); | 289 reportAttributeParsingError(parseError, name, value); |
293 } | 290 } |
294 | 291 |
295 void SVGSVGElement::svgAttributeChanged(const QualifiedName& attrName) | 292 void SVGSVGElement::svgAttributeChanged(const QualifiedName& attrName) |
296 { | 293 { |
297 bool updateRelativeLengthsOrViewBox = false; | 294 bool updateRelativeLengthsOrViewBox = false; |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 || m_width->currentValue()->isRelative() | 549 || m_width->currentValue()->isRelative() |
553 || m_height->currentValue()->isRelative() | 550 || m_height->currentValue()->isRelative() |
554 || hasAttribute(SVGNames::viewBoxAttr); | 551 || hasAttribute(SVGNames::viewBoxAttr); |
555 } | 552 } |
556 | 553 |
557 FloatRect SVGSVGElement::currentViewBoxRect() const | 554 FloatRect SVGSVGElement::currentViewBoxRect() const |
558 { | 555 { |
559 if (m_useCurrentView) | 556 if (m_useCurrentView) |
560 return m_viewSpec ? m_viewSpec->viewBox()->currentValue()->value() : Flo
atRect(); | 557 return m_viewSpec ? m_viewSpec->viewBox()->currentValue()->value() : Flo
atRect(); |
561 | 558 |
562 FloatRect useViewBox = m_viewBox->currentValue()->value(); | 559 FloatRect useViewBox = viewBox()->currentValue()->value(); |
563 if (!useViewBox.isEmpty()) | 560 if (!useViewBox.isEmpty()) |
564 return useViewBox; | 561 return useViewBox; |
565 if (!renderer() || !renderer()->isSVGRoot()) | 562 if (!renderer() || !renderer()->isSVGRoot()) |
566 return FloatRect(); | 563 return FloatRect(); |
567 if (!toRenderSVGRoot(renderer())->isEmbeddedThroughSVGImage()) | 564 if (!toRenderSVGRoot(renderer())->isEmbeddedThroughSVGImage()) |
568 return FloatRect(); | 565 return FloatRect(); |
569 | 566 |
570 Length intrinsicWidth = this->intrinsicWidth(); | 567 Length intrinsicWidth = this->intrinsicWidth(); |
571 Length intrinsicHeight = this->intrinsicHeight(); | 568 Length intrinsicHeight = this->intrinsicHeight(); |
572 if (!intrinsicWidth.isFixed() || !intrinsicHeight.isFixed()) | 569 if (!intrinsicWidth.isFixed() || !intrinsicHeight.isFixed()) |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 return Length(m_height->currentValue()->value(lengthContext), Fixed); | 665 return Length(m_height->currentValue()->value(lengthContext), Fixed); |
669 } | 666 } |
670 | 667 |
671 ASSERT(renderer()); | 668 ASSERT(renderer()); |
672 return renderer()->style()->height(); | 669 return renderer()->style()->height(); |
673 } | 670 } |
674 | 671 |
675 AffineTransform SVGSVGElement::viewBoxToViewTransform(float viewWidth, float vie
wHeight) const | 672 AffineTransform SVGSVGElement::viewBoxToViewTransform(float viewWidth, float vie
wHeight) const |
676 { | 673 { |
677 if (!m_useCurrentView || !m_viewSpec) | 674 if (!m_useCurrentView || !m_viewSpec) |
678 return SVGFitToViewBox::viewBoxToViewTransform(currentViewBoxRect(), m_p
reserveAspectRatio->currentValue(), viewWidth, viewHeight); | 675 return SVGFitToViewBox::viewBoxToViewTransform(currentViewBoxRect(), pre
serveAspectRatio()->currentValue(), viewWidth, viewHeight); |
679 | 676 |
680 AffineTransform ctm = SVGFitToViewBox::viewBoxToViewTransform(currentViewBox
Rect(), m_viewSpec->preserveAspectRatio()->currentValue(), viewWidth, viewHeight
); | 677 AffineTransform ctm = SVGFitToViewBox::viewBoxToViewTransform(currentViewBox
Rect(), m_viewSpec->preserveAspectRatio()->currentValue(), viewWidth, viewHeight
); |
681 const SVGTransformList& transformList = m_viewSpec->transformBaseValue(); | 678 const SVGTransformList& transformList = m_viewSpec->transformBaseValue(); |
682 if (transformList.isEmpty()) | 679 if (transformList.isEmpty()) |
683 return ctm; | 680 return ctm; |
684 | 681 |
685 AffineTransform transform; | 682 AffineTransform transform; |
686 if (transformList.concatenate(transform)) | 683 if (transformList.concatenate(transform)) |
687 ctm *= transform; | 684 ctm *= transform; |
688 | 685 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 } | 739 } |
743 | 740 |
744 void SVGSVGElement::inheritViewAttributes(SVGViewElement* viewElement) | 741 void SVGSVGElement::inheritViewAttributes(SVGViewElement* viewElement) |
745 { | 742 { |
746 SVGViewSpec* view = currentView(); | 743 SVGViewSpec* view = currentView(); |
747 m_useCurrentView = true; | 744 m_useCurrentView = true; |
748 | 745 |
749 if (viewElement->hasAttribute(SVGNames::viewBoxAttr)) | 746 if (viewElement->hasAttribute(SVGNames::viewBoxAttr)) |
750 view->viewBox()->baseValue()->setValue(viewElement->viewBox()->currentVa
lue()->value()); | 747 view->viewBox()->baseValue()->setValue(viewElement->viewBox()->currentVa
lue()->value()); |
751 else | 748 else |
752 view->viewBox()->baseValue()->setValue(m_viewBox->currentValue()->value(
)); | 749 view->viewBox()->baseValue()->setValue(viewBox()->currentValue()->value(
)); |
753 | 750 |
754 if (viewElement->hasAttribute(SVGNames::preserveAspectRatioAttr)) { | 751 if (viewElement->hasAttribute(SVGNames::preserveAspectRatioAttr)) { |
755 view->preserveAspectRatio()->baseValue()->setAlign(viewElement->preserve
AspectRatio()->currentValue()->align()); | 752 view->preserveAspectRatio()->baseValue()->setAlign(viewElement->preserve
AspectRatio()->currentValue()->align()); |
756 view->preserveAspectRatio()->baseValue()->setMeetOrSlice(viewElement->pr
eserveAspectRatio()->currentValue()->meetOrSlice()); | 753 view->preserveAspectRatio()->baseValue()->setMeetOrSlice(viewElement->pr
eserveAspectRatio()->currentValue()->meetOrSlice()); |
757 } else { | 754 } else { |
758 view->preserveAspectRatio()->baseValue()->setAlign(m_preserveAspectRatio
->currentValue()->align()); | 755 view->preserveAspectRatio()->baseValue()->setAlign(preserveAspectRatio()
->currentValue()->align()); |
759 view->preserveAspectRatio()->baseValue()->setMeetOrSlice(m_preserveAspec
tRatio->currentValue()->meetOrSlice()); | 756 view->preserveAspectRatio()->baseValue()->setMeetOrSlice(preserveAspectR
atio()->currentValue()->meetOrSlice()); |
760 } | 757 } |
761 | 758 |
762 if (viewElement->hasAttribute(SVGNames::zoomAndPanAttr)) | 759 if (viewElement->hasAttribute(SVGNames::zoomAndPanAttr)) |
763 view->setZoomAndPanBaseValue(viewElement->zoomAndPan()); | 760 view->setZoomAndPanBaseValue(viewElement->zoomAndPan()); |
764 else | 761 else |
765 view->setZoomAndPanBaseValue(zoomAndPan()); | 762 view->setZoomAndPanBaseValue(zoomAndPan()); |
766 } | 763 } |
767 | 764 |
768 // getElementById on SVGSVGElement is restricted to only the child subtree defin
ed by the <svg> element. | 765 // getElementById on SVGSVGElement is restricted to only the child subtree defin
ed by the <svg> element. |
769 // See http://www.w3.org/TR/SVG11/struct.html#InterfaceSVGSVGElement | 766 // See http://www.w3.org/TR/SVG11/struct.html#InterfaceSVGSVGElement |
(...skipping 10 matching lines...) Expand all Loading... |
780 continue; | 777 continue; |
781 | 778 |
782 Element* element = toElement(node); | 779 Element* element = toElement(node); |
783 if (element->getIdAttribute() == id) | 780 if (element->getIdAttribute() == id) |
784 return element; | 781 return element; |
785 } | 782 } |
786 return 0; | 783 return 0; |
787 } | 784 } |
788 | 785 |
789 } | 786 } |
OLD | NEW |