Chromium Code Reviews| Index: third_party/WebKit/Source/core/layout/svg/LayoutSVGImage.cpp |
| diff --git a/third_party/WebKit/Source/core/layout/svg/LayoutSVGImage.cpp b/third_party/WebKit/Source/core/layout/svg/LayoutSVGImage.cpp |
| index c49dccecaca90366e94c3ee6f092369eece6e2ff..eaff9b12a3679d0731192412c384b994528182c4 100644 |
| --- a/third_party/WebKit/Source/core/layout/svg/LayoutSVGImage.cpp |
| +++ b/third_party/WebKit/Source/core/layout/svg/LayoutSVGImage.cpp |
| @@ -61,7 +61,36 @@ void LayoutSVGImage::willBeDestroyed() |
| LayoutSVGModelObject::willBeDestroyed(); |
| } |
| -void LayoutSVGImage::updateBoundingBox() |
| +static float resolveWidthForRatio(float height, const FloatSize& intrinsicRatio) |
| +{ |
| + return height * intrinsicRatio.width() / intrinsicRatio.height(); |
| +} |
| + |
| +static float resolveHeightForRatio(float width, const FloatSize& intrinsicRatio) |
| +{ |
| + return width * intrinsicRatio.height() / intrinsicRatio.width(); |
| +} |
| + |
| +FloatSize LayoutSVGImage::calculateObjectSize() |
| +{ |
| + ImageResource* cachedImage = m_imageResource->cachedImage(); |
| + if (!cachedImage || cachedImage->errorOccurred()) |
| + return FloatSize(); |
| + |
| + FloatSize intrinsicSize = FloatSize(cachedImage->getImage()->size()); |
| + if (styleRef().width().isAuto() && styleRef().height().isAuto()) |
| + return intrinsicSize; |
| + |
| + if (styleRef().height().isAuto()) |
| + return FloatSize(m_objectBoundingBox.width(), resolveHeightForRatio(m_objectBoundingBox.width(), intrinsicSize)); |
| + |
| + if (styleRef().width().isAuto()) |
| + return FloatSize(resolveWidthForRatio(m_objectBoundingBox.height(), intrinsicSize), m_objectBoundingBox.height()); |
| + |
| + return FloatSize(); |
|
fs
2016/09/14 11:31:52
This is unreachable? Maybe just assert styleRef().
Shanmuga Pandi
2016/09/14 13:15:36
Done.
|
| +} |
| + |
| +bool LayoutSVGImage::updateBoundingBox() |
| { |
| FloatRect oldBoundaries = m_objectBoundingBox; |
| @@ -71,9 +100,19 @@ void LayoutSVGImage::updateBoundingBox() |
| lengthContext.valueForLength(styleRef().svgStyle().y(), styleRef(), SVGLengthMode::Height), |
| lengthContext.valueForLength(styleRef().width(), styleRef(), SVGLengthMode::Width), |
| lengthContext.valueForLength(styleRef().height(), styleRef(), SVGLengthMode::Height)); |
| + |
| + if (styleRef().width().isAuto() || styleRef().height().isAuto()) { |
| + FloatSize intrinsicSize = calculateObjectSize(); |
| + if (styleRef().width().isAuto()) |
|
fs
2016/09/14 11:31:52
This branching looks redundant - couldn't this jus
Shanmuga Pandi
2016/09/14 13:15:36
Done.
|
| + m_objectBoundingBox.setWidth(intrinsicSize.width()); |
| + if (styleRef().height().isAuto()) |
| + m_objectBoundingBox.setHeight(intrinsicSize.height()); |
| + } |
| m_needsBoundariesUpdate |= oldBoundaries != m_objectBoundingBox; |
| if (element()) |
| element()->setNeedsResizeObserverUpdate(); |
| + |
| + return oldBoundaries.size() != m_objectBoundingBox.size(); |
| } |
| void LayoutSVGImage::layout() |
| @@ -148,6 +187,11 @@ void LayoutSVGImage::imageChanged(WrappedImagePtr, const IntRect*) |
| // representation of this image/layout object. |
| LayoutSVGResourceContainer::markForLayoutAndParentResourceInvalidation(this, false); |
| + if (styleRef().width().isAuto() || styleRef().height().isAuto()) { |
| + if (updateBoundingBox()) |
| + setNeedsLayout(LayoutInvalidationReason::SizeChanged); |
| + } |
| + |
| setShouldDoFullPaintInvalidation(); |
| } |