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