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

Unified Diff: third_party/WebKit/Source/core/svg/graphics/SVGImage.cpp

Issue 1756763004: Merge image sizing algorithms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unused variable 'styleImage' in release Created 4 years, 9 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/svg/graphics/SVGImage.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/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 b1141564d2424c0a8a97b91a158ab1d1b222863c..aaccff3a99f7516d92b398f7d484a43982bbf4e2 100644
--- a/third_party/WebKit/Source/core/svg/graphics/SVGImage.cpp
+++ b/third_party/WebKit/Source/core/svg/graphics/SVGImage.cpp
@@ -155,7 +155,7 @@ IntSize SVGImage::containerSize() const
ASSERT(layoutObject->style()->effectiveZoom() == 1);
// No set container size; use concrete object size.
- return m_concreteObjectSize;
+ return m_intrinsicSize;
}
static float resolveWidthForRatio(float height, const FloatSize& intrinsicRatio)
@@ -168,7 +168,7 @@ static float resolveHeightForRatio(float width, const FloatSize& intrinsicRatio)
return width * intrinsicRatio.height() / intrinsicRatio.width();
}
-FloatSize SVGImage::calculateConcreteObjectSize(const FloatSize& defaultObjectSize) const
+FloatSize SVGImage::concreteObjectSize(const FloatSize& defaultObjectSize) const
{
SVGSVGElement* svg = svgRootElement(m_page.get());
if (!svg)
@@ -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;
@@ -535,7 +549,7 @@ bool SVGImage::dataChanged(bool allDataReceived)
AtomicString("UTF-8", AtomicString::ConstructFromLiteral), KURL(), ForceSynchronousLoad)));
// Set the concrete object size before a container size is available.
- m_concreteObjectSize = roundedIntSize(calculateConcreteObjectSize(FloatSize(300, 150)));
+ m_intrinsicSize = roundedIntSize(concreteObjectSize(FloatSize(300, 150)));
}
return m_page;
« no previous file with comments | « third_party/WebKit/Source/core/svg/graphics/SVGImage.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698