Index: third_party/WebKit/Source/core/svg/graphics/SVGImage.cpp |
diff --git a/third_party/WebKit/Source/core/svg/graphics/SVGImage.cpp b/third_party/WebKit/Source/core/svg/graphics/SVGImage.cpp |
index 76fde922cbf101dade18414fcb163d962847520f..229cd2b029cb7512328496dff05173e968d2a975 100644 |
--- a/third_party/WebKit/Source/core/svg/graphics/SVGImage.cpp |
+++ b/third_party/WebKit/Source/core/svg/graphics/SVGImage.cpp |
@@ -208,11 +208,25 @@ FloatSize SVGImage::calculateConcreteObjectSize(const FloatSize& defaultObjectSi |
} |
if (!intrinsicSizingInfo.aspectRatio.isEmpty()) { |
- // TODO(davve): According to the specification, the concrete object size should resolve as a |
- // contain constraint against the default object size at this stage. Until the |
- // defaultObjectSize is context sensitive - right now it's hard-coded to 300x150 - we have |
- // to preserve legacy behavior by returning the aspectRatio as the concrete object size. |
- return intrinsicSizingInfo.aspectRatio; |
+ // "A contain constraint is resolved by setting the concrete object size to the largest |
+ // rectangle that has the object's intrinsic aspect ratio and additionally has neither |
+ // width nor height larger than the constraint rectangle's width and height, respectively." |
+ float solutionWidth = resolveWidthForRatio(defaultObjectSize.height(), intrinsicSizingInfo.aspectRatio); |
+ float solutionHeight = resolveHeightForRatio(defaultObjectSize.width(), intrinsicSizingInfo.aspectRatio); |
+ if (solutionWidth <= defaultObjectSize.width()) { |
+ if (solutionHeight <= defaultObjectSize.height()) { |
+ float areaOne = solutionWidth * defaultObjectSize.height(); |
+ float areaTwo = defaultObjectSize.width() * solutionHeight; |
+ if (areaOne < areaTwo) |
+ return FloatSize(defaultObjectSize.width(), solutionHeight); |
+ return FloatSize(solutionWidth, defaultObjectSize.height()); |
+ } |
+ |
+ return FloatSize(solutionWidth, defaultObjectSize.height()); |
+ } |
+ |
+ ASSERT(solutionHeight <= defaultObjectSize.height()); |
+ return FloatSize(defaultObjectSize.width(), solutionHeight); |
} |
return defaultObjectSize; |