Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Unified Diff: third_party/WebKit/Source/core/layout/svg/LayoutSVGImage.cpp

Issue 2230963002: SVG Image intrinsic size should be used if css style size is 'auto' (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Align with review comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/layout/svg/LayoutSVGImage.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..559f139258643eecd9dc643f9d08666911ff49ad 100644
--- a/third_party/WebKit/Source/core/layout/svg/LayoutSVGImage.cpp
+++ b/third_party/WebKit/Source/core/layout/svg/LayoutSVGImage.cpp
@@ -61,7 +61,34 @@ 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() const
+{
+ ImageResource* cachedImage = m_imageResource->cachedImage();
+ if (!cachedImage || cachedImage->errorOccurred())
+ return m_objectBoundingBox.size();
+
+ 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));
+
+ DCHECK(styleRef().width().isAuto());
+ return FloatSize(resolveWidthForRatio(m_objectBoundingBox.height(), intrinsicSize), m_objectBoundingBox.height());
+}
+
+bool LayoutSVGImage::updateBoundingBox()
davve 2016/09/14 14:13:17 Having updateBoundingBox() both set a member varia
fs 2016/09/14 14:37:11 IIRC we have a bug on file to shift some of this s
davve 2016/09/15 12:34:43 s/no-up/no-op/. Sorry about that. After some more
{
FloatRect oldBoundaries = m_objectBoundingBox;
@@ -71,9 +98,15 @@ 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())
+ m_objectBoundingBox.setSize(calculateObjectSize());
+
m_needsBoundariesUpdate |= oldBoundaries != m_objectBoundingBox;
if (element())
element()->setNeedsResizeObserverUpdate();
+
+ return oldBoundaries.size() != m_objectBoundingBox.size();
}
void LayoutSVGImage::layout()
@@ -148,6 +181,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();
}
« no previous file with comments | « third_party/WebKit/Source/core/layout/svg/LayoutSVGImage.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698