OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> |
3 * Copyright (C) 2004, 2005, 2007 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2004, 2005, 2007 Rob Buis <buis@kde.org> |
4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> | 4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> |
5 * Copyright (C) 2009 Google, Inc. | 5 * Copyright (C) 2009 Google, Inc. |
6 * | 6 * |
7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
11 * | 11 * |
12 * This library is distributed in the hope that it will be useful, | 12 * This library is distributed in the hope that it will be useful, |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Library General Public License for more details. | 15 * Library General Public License for more details. |
16 * | 16 * |
17 * You should have received a copy of the GNU Library General Public License | 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 | 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, | 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 * Boston, MA 02110-1301, USA. | 20 * Boston, MA 02110-1301, USA. |
21 */ | 21 */ |
22 | 22 |
23 #include "config.h" | 23 #include "config.h" |
24 | 24 |
25 #include "core/rendering/svg/RenderSVGViewportContainer.h" | 25 #include "core/rendering/svg/RenderSVGViewportContainer.h" |
26 | 26 |
27 #include "SVGNames.h" | 27 #include "SVGNames.h" |
28 #include "core/svg/SVGElementInstance.h" | |
29 #include "core/svg/SVGSVGElement.h" | 28 #include "core/svg/SVGSVGElement.h" |
30 #include "core/svg/SVGUseElement.h" | 29 #include "core/svg/SVGUseElement.h" |
31 #include "platform/graphics/GraphicsContext.h" | 30 #include "platform/graphics/GraphicsContext.h" |
32 | 31 |
33 namespace WebCore { | 32 namespace WebCore { |
34 | 33 |
35 RenderSVGViewportContainer::RenderSVGViewportContainer(SVGElement* node) | 34 RenderSVGViewportContainer::RenderSVGViewportContainer(SVGElement* node) |
36 : RenderSVGContainer(node) | 35 : RenderSVGContainer(node) |
37 , m_didTransformToRootUpdate(false) | 36 , m_didTransformToRootUpdate(false) |
38 , m_isLayoutSizeChanged(false) | 37 , m_isLayoutSizeChanged(false) |
(...skipping 21 matching lines...) Expand all Loading... |
60 SVGElement* element = this->element(); | 59 SVGElement* element = this->element(); |
61 ASSERT(element); | 60 ASSERT(element); |
62 if (!isSVGSVGElement(*element)) | 61 if (!isSVGSVGElement(*element)) |
63 return; | 62 return; |
64 SVGSVGElement* svg = toSVGSVGElement(element); | 63 SVGSVGElement* svg = toSVGSVGElement(element); |
65 FloatRect oldViewport = m_viewport; | 64 FloatRect oldViewport = m_viewport; |
66 | 65 |
67 SVGLengthContext lengthContext(element); | 66 SVGLengthContext lengthContext(element); |
68 m_viewport = FloatRect(svg->x()->currentValue()->value(lengthContext), svg->
y()->currentValue()->value(lengthContext), svg->width()->currentValue()->value(l
engthContext), svg->height()->currentValue()->value(lengthContext)); | 67 m_viewport = FloatRect(svg->x()->currentValue()->value(lengthContext), svg->
y()->currentValue()->value(lengthContext), svg->width()->currentValue()->value(l
engthContext), svg->height()->currentValue()->value(lengthContext)); |
69 | 68 |
70 SVGElement* correspondingElement = svg->correspondingElement(); | |
71 if (correspondingElement && svg->isInShadowTree()) { | |
72 const HashSet<SVGElementInstance*>& instances = correspondingElement->in
stancesForElement(); | |
73 ASSERT(!instances.isEmpty()); | |
74 | |
75 SVGUseElement* useElement = 0; | |
76 const HashSet<SVGElementInstance*>::const_iterator end = instances.end()
; | |
77 for (HashSet<SVGElementInstance*>::const_iterator it = instances.begin()
; it != end; ++it) { | |
78 const SVGElementInstance* instance = (*it); | |
79 ASSERT(isSVGSVGElement(instance->correspondingElement()) || isSVGSym
bolElement(instance->correspondingElement())); | |
80 if (instance->shadowTreeElement() == svg) { | |
81 ASSERT(correspondingElement == instance->correspondingElement())
; | |
82 useElement = instance->directUseElement(); | |
83 if (!useElement) | |
84 useElement = instance->correspondingUseElement(); | |
85 break; | |
86 } | |
87 } | |
88 | |
89 ASSERT(useElement); | |
90 bool isSymbolElement = isSVGSymbolElement(*correspondingElement); | |
91 | |
92 // Spec (<use> on <symbol>): This generated 'svg' will always have expli
cit values for attributes width and height. | |
93 // If attributes width and/or height are provided on the 'use' element,
then these attributes | |
94 // will be transferred to the generated 'svg'. If attributes width and/o
r height are not specified, | |
95 // the generated 'svg' element will use values of 100% for these attribu
tes. | |
96 | |
97 // Spec (<use> on <svg>): If attributes width and/or height are provided
on the 'use' element, then these | |
98 // values will override the corresponding attributes on the 'svg' in the
generated tree. | |
99 | |
100 SVGLengthContext lengthContext(element); | |
101 if (useElement->hasAttribute(SVGNames::widthAttr)) | |
102 m_viewport.setWidth(useElement->width()->currentValue()->value(lengt
hContext)); | |
103 else if (isSymbolElement && svg->hasAttribute(SVGNames::widthAttr)) { | |
104 RefPtr<SVGLength> containerWidth = SVGLength::create(LengthModeWidth
); | |
105 containerWidth->setValueAsString("100%", ASSERT_NO_EXCEPTION); | |
106 m_viewport.setWidth(containerWidth->value(lengthContext)); | |
107 } | |
108 | |
109 if (useElement->hasAttribute(SVGNames::heightAttr)) | |
110 m_viewport.setHeight(useElement->height()->currentValue()->value(len
gthContext)); | |
111 else if (isSymbolElement && svg->hasAttribute(SVGNames::heightAttr)) { | |
112 RefPtr<SVGLength> containerHeight = SVGLength::create(LengthModeHeig
ht); | |
113 containerHeight->setValueAsString("100%", ASSERT_NO_EXCEPTION); | |
114 m_viewport.setHeight(containerHeight->value(lengthContext)); | |
115 } | |
116 } | |
117 | |
118 if (oldViewport != m_viewport) { | 69 if (oldViewport != m_viewport) { |
119 setNeedsBoundariesUpdate(); | 70 setNeedsBoundariesUpdate(); |
120 setNeedsTransformUpdate(); | 71 setNeedsTransformUpdate(); |
121 } | 72 } |
122 } | 73 } |
123 | 74 |
124 bool RenderSVGViewportContainer::calculateLocalTransform() | 75 bool RenderSVGViewportContainer::calculateLocalTransform() |
125 { | 76 { |
126 m_didTransformToRootUpdate = m_needsTransformUpdate || SVGRenderSupport::tra
nsformToRootChanged(parent()); | 77 m_didTransformToRootUpdate = m_needsTransformUpdate || SVGRenderSupport::tra
nsformToRootChanged(parent()); |
127 if (!m_needsTransformUpdate) | 78 if (!m_needsTransformUpdate) |
(...skipping 28 matching lines...) Expand all Loading... |
156 { | 107 { |
157 ASSERT(element()); | 108 ASSERT(element()); |
158 // An empty viewBox disables rendering. | 109 // An empty viewBox disables rendering. |
159 if (isSVGSVGElement(*element()) && toSVGSVGElement(*element()).hasEmptyViewB
ox()) | 110 if (isSVGSVGElement(*element()) && toSVGSVGElement(*element()).hasEmptyViewB
ox()) |
160 return; | 111 return; |
161 | 112 |
162 RenderSVGContainer::paint(paintInfo, paintOffset); | 113 RenderSVGContainer::paint(paintInfo, paintOffset); |
163 } | 114 } |
164 | 115 |
165 } | 116 } |
OLD | NEW |