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, 2008, 2009 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2004, 2005, 2007, 2008, 2009 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 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 6 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "core/rendering/LayoutRepainter.h" | 31 #include "core/rendering/LayoutRepainter.h" |
32 #include "core/rendering/RenderPart.h" | 32 #include "core/rendering/RenderPart.h" |
33 #include "core/rendering/RenderView.h" | 33 #include "core/rendering/RenderView.h" |
34 #include "core/rendering/svg/RenderSVGResourceContainer.h" | 34 #include "core/rendering/svg/RenderSVGResourceContainer.h" |
35 #include "core/rendering/svg/SVGRenderingContext.h" | 35 #include "core/rendering/svg/SVGRenderingContext.h" |
36 #include "core/rendering/svg/SVGResources.h" | 36 #include "core/rendering/svg/SVGResources.h" |
37 #include "core/rendering/svg/SVGResourcesCache.h" | 37 #include "core/rendering/svg/SVGResourcesCache.h" |
38 #include "core/svg/SVGElement.h" | 38 #include "core/svg/SVGElement.h" |
39 #include "core/svg/SVGSVGElement.h" | 39 #include "core/svg/SVGSVGElement.h" |
40 #include "core/svg/graphics/SVGImage.h" | 40 #include "core/svg/graphics/SVGImage.h" |
| 41 #include "platform/LengthFunctions.h" |
41 #include "platform/graphics/GraphicsContext.h" | 42 #include "platform/graphics/GraphicsContext.h" |
42 | 43 |
43 using namespace std; | 44 using namespace std; |
44 | 45 |
45 namespace WebCore { | 46 namespace WebCore { |
46 | 47 |
47 RenderSVGRoot::RenderSVGRoot(SVGElement* node) | 48 RenderSVGRoot::RenderSVGRoot(SVGElement* node) |
48 : RenderReplaced(node) | 49 : RenderReplaced(node) |
49 , m_objectBoundingBoxValid(false) | 50 , m_objectBoundingBoxValid(false) |
50 , m_isLayoutSizeChanged(false) | 51 , m_isLayoutSizeChanged(false) |
(...skipping 21 matching lines...) Expand all Loading... |
72 | 73 |
73 // The intrinsic aspect ratio of the viewport of SVG content is necessary fo
r example, when including SVG from an ‘object’ | 74 // The intrinsic aspect ratio of the viewport of SVG content is necessary fo
r example, when including SVG from an ‘object’ |
74 // element in HTML styled with CSS. It is possible (indeed, common) for an S
VG graphic to have an intrinsic aspect ratio but | 75 // element in HTML styled with CSS. It is possible (indeed, common) for an S
VG graphic to have an intrinsic aspect ratio but |
75 // not to have an intrinsic width or height. The intrinsic aspect ratio must
be calculated based upon the following rules: | 76 // not to have an intrinsic width or height. The intrinsic aspect ratio must
be calculated based upon the following rules: |
76 // - The aspect ratio is calculated by dividing a width by a height. | 77 // - The aspect ratio is calculated by dividing a width by a height. |
77 // - If the ‘width’ and ‘height’ of the rootmost ‘svg’ element are both spec
ified with unit identifiers (in, mm, cm, pt, pc, | 78 // - If the ‘width’ and ‘height’ of the rootmost ‘svg’ element are both spec
ified with unit identifiers (in, mm, cm, pt, pc, |
78 // px, em, ex) or in user units, then the aspect ratio is calculated from
the ‘width’ and ‘height’ attributes after | 79 // px, em, ex) or in user units, then the aspect ratio is calculated from
the ‘width’ and ‘height’ attributes after |
79 // resolving both values to user units. | 80 // resolving both values to user units. |
80 if (intrinsicWidthAttribute.isFixed() || intrinsicHeightAttribute.isFixed())
{ | 81 if (intrinsicWidthAttribute.isFixed() || intrinsicHeightAttribute.isFixed())
{ |
81 if (intrinsicWidthAttribute.isFixed()) | 82 if (intrinsicWidthAttribute.isFixed()) |
82 intrinsicSize.setWidth(floatValueForLength(intrinsicWidthAttribute,
0, 0)); | 83 intrinsicSize.setWidth(floatValueForLength(intrinsicWidthAttribute,
0)); |
83 if (intrinsicHeightAttribute.isFixed()) | 84 if (intrinsicHeightAttribute.isFixed()) |
84 intrinsicSize.setHeight(floatValueForLength(intrinsicHeightAttribute
, 0, 0)); | 85 intrinsicSize.setHeight(floatValueForLength(intrinsicHeightAttribute
, 0)); |
85 if (!intrinsicSize.isEmpty()) | 86 if (!intrinsicSize.isEmpty()) |
86 intrinsicRatio = intrinsicSize.width() / static_cast<double>(intrins
icSize.height()); | 87 intrinsicRatio = intrinsicSize.width() / static_cast<double>(intrins
icSize.height()); |
87 return; | 88 return; |
88 } | 89 } |
89 | 90 |
90 // - If either/both of the ‘width’ and ‘height’ of the rootmost ‘svg’ elemen
t are in percentage units (or omitted), the | 91 // - If either/both of the ‘width’ and ‘height’ of the rootmost ‘svg’ elemen
t are in percentage units (or omitted), the |
91 // aspect ratio is calculated from the width and height values of the ‘vie
wBox’ specified for the current SVG document | 92 // aspect ratio is calculated from the width and height values of the ‘vie
wBox’ specified for the current SVG document |
92 // fragment. If the ‘viewBox’ is not correctly specified, or set to 'none'
, the intrinsic aspect ratio cannot be | 93 // fragment. If the ‘viewBox’ is not correctly specified, or set to 'none'
, the intrinsic aspect ratio cannot be |
93 // calculated and is considered unspecified. | 94 // calculated and is considered unspecified. |
94 intrinsicSize = svg->viewBoxCurrentValue().size(); | 95 intrinsicSize = svg->viewBoxCurrentValue().size(); |
(...skipping 26 matching lines...) Expand all Loading... |
121 if (!frame) | 122 if (!frame) |
122 return false; | 123 return false; |
123 | 124 |
124 // If our frame has an owner renderer, we're embedded through eg. object/emb
ed/iframe, | 125 // If our frame has an owner renderer, we're embedded through eg. object/emb
ed/iframe, |
125 // but we only negotiate if we're in an SVG document. | 126 // but we only negotiate if we're in an SVG document. |
126 if (!frame->ownerRenderer()) | 127 if (!frame->ownerRenderer()) |
127 return false; | 128 return false; |
128 return frame->document()->isSVGDocument(); | 129 return frame->document()->isSVGDocument(); |
129 } | 130 } |
130 | 131 |
131 static inline LayoutUnit resolveLengthAttributeForSVG(const Length& length, floa
t scale, float maxSize, RenderView* renderView) | 132 static inline LayoutUnit resolveLengthAttributeForSVG(const Length& length, floa
t scale, float maxSize) |
132 { | 133 { |
133 return static_cast<LayoutUnit>(valueForLength(length, maxSize, renderView) *
(length.isFixed() ? scale : 1)); | 134 return static_cast<LayoutUnit>(valueForLength(length, maxSize) * (length.isF
ixed() ? scale : 1)); |
134 } | 135 } |
135 | 136 |
136 LayoutUnit RenderSVGRoot::computeReplacedLogicalWidth(ShouldComputePreferred sho
uldComputePreferred) const | 137 LayoutUnit RenderSVGRoot::computeReplacedLogicalWidth(ShouldComputePreferred sho
uldComputePreferred) const |
137 { | 138 { |
138 SVGSVGElement* svg = toSVGSVGElement(node()); | 139 SVGSVGElement* svg = toSVGSVGElement(node()); |
139 ASSERT(svg); | 140 ASSERT(svg); |
140 | 141 |
141 // When we're embedded through SVGImage (border-image/background-image/<html
:img>/...) we're forced to resize to a specific size. | 142 // When we're embedded through SVGImage (border-image/background-image/<html
:img>/...) we're forced to resize to a specific size. |
142 if (!m_containerSize.isEmpty()) | 143 if (!m_containerSize.isEmpty()) |
143 return m_containerSize.width(); | 144 return m_containerSize.width(); |
144 | 145 |
145 if (style()->logicalWidth().isSpecified() || style()->logicalMaxWidth().isSp
ecified()) | 146 if (style()->logicalWidth().isSpecified() || style()->logicalMaxWidth().isSp
ecified()) |
146 return RenderReplaced::computeReplacedLogicalWidth(shouldComputePreferre
d); | 147 return RenderReplaced::computeReplacedLogicalWidth(shouldComputePreferre
d); |
147 | 148 |
148 if (svg->widthAttributeEstablishesViewport()) | 149 if (svg->widthAttributeEstablishesViewport()) |
149 return resolveLengthAttributeForSVG(svg->intrinsicWidth(SVGSVGElement::I
gnoreCSSProperties), style()->effectiveZoom(), containingBlock()->availableLogic
alWidth(), view()); | 150 return resolveLengthAttributeForSVG(svg->intrinsicWidth(SVGSVGElement::I
gnoreCSSProperties), style()->effectiveZoom(), containingBlock()->availableLogic
alWidth()); |
150 | 151 |
151 // SVG embedded through object/embed/iframe. | 152 // SVG embedded through object/embed/iframe. |
152 if (isEmbeddedThroughFrameContainingSVGDocument()) | 153 if (isEmbeddedThroughFrameContainingSVGDocument()) |
153 return document().frame()->ownerRenderer()->availableLogicalWidth(); | 154 return document().frame()->ownerRenderer()->availableLogicalWidth(); |
154 | 155 |
155 // SVG embedded via SVGImage (background-image/border-image/etc) / Inline SV
G. | 156 // SVG embedded via SVGImage (background-image/border-image/etc) / Inline SV
G. |
156 return RenderReplaced::computeReplacedLogicalWidth(shouldComputePreferred); | 157 return RenderReplaced::computeReplacedLogicalWidth(shouldComputePreferred); |
157 } | 158 } |
158 | 159 |
159 LayoutUnit RenderSVGRoot::computeReplacedLogicalHeight() const | 160 LayoutUnit RenderSVGRoot::computeReplacedLogicalHeight() const |
(...skipping 13 matching lines...) Expand all Loading... |
173 if (height.isPercent()) { | 174 if (height.isPercent()) { |
174 RenderBlock* cb = containingBlock(); | 175 RenderBlock* cb = containingBlock(); |
175 ASSERT(cb); | 176 ASSERT(cb); |
176 while (cb->isAnonymous()) { | 177 while (cb->isAnonymous()) { |
177 cb = cb->containingBlock(); | 178 cb = cb->containingBlock(); |
178 cb->addPercentHeightDescendant(const_cast<RenderSVGRoot*>(this))
; | 179 cb->addPercentHeightDescendant(const_cast<RenderSVGRoot*>(this))
; |
179 } | 180 } |
180 } else | 181 } else |
181 RenderBlock::removePercentHeightDescendant(const_cast<RenderSVGRoot*
>(this)); | 182 RenderBlock::removePercentHeightDescendant(const_cast<RenderSVGRoot*
>(this)); |
182 | 183 |
183 return resolveLengthAttributeForSVG(height, style()->effectiveZoom(), co
ntainingBlock()->availableLogicalHeight(IncludeMarginBorderPadding), view()); | 184 return resolveLengthAttributeForSVG(height, style()->effectiveZoom(), co
ntainingBlock()->availableLogicalHeight(IncludeMarginBorderPadding)); |
184 } | 185 } |
185 | 186 |
186 // SVG embedded through object/embed/iframe. | 187 // SVG embedded through object/embed/iframe. |
187 if (isEmbeddedThroughFrameContainingSVGDocument()) | 188 if (isEmbeddedThroughFrameContainingSVGDocument()) |
188 return document().frame()->ownerRenderer()->availableLogicalHeight(Inclu
deMarginBorderPadding); | 189 return document().frame()->ownerRenderer()->availableLogicalHeight(Inclu
deMarginBorderPadding); |
189 | 190 |
190 // SVG embedded via SVGImage (background-image/border-image/etc) / Inline SV
G. | 191 // SVG embedded via SVGImage (background-image/border-image/etc) / Inline SV
G. |
191 return RenderReplaced::computeReplacedLogicalHeight(); | 192 return RenderReplaced::computeReplacedLogicalHeight(); |
192 } | 193 } |
193 | 194 |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 | 446 |
446 bool RenderSVGRoot::hasRelativeLogicalHeight() const | 447 bool RenderSVGRoot::hasRelativeLogicalHeight() const |
447 { | 448 { |
448 SVGSVGElement* svg = toSVGSVGElement(node()); | 449 SVGSVGElement* svg = toSVGSVGElement(node()); |
449 ASSERT(svg); | 450 ASSERT(svg); |
450 | 451 |
451 return svg->intrinsicHeight(SVGSVGElement::IgnoreCSSProperties).isPercent(); | 452 return svg->intrinsicHeight(SVGSVGElement::IgnoreCSSProperties).isPercent(); |
452 } | 453 } |
453 | 454 |
454 } | 455 } |
OLD | NEW |