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

Unified Diff: third_party/WebKit/Source/core/svg/SVGSVGElement.cpp

Issue 2290173005: Synthesize preserveAspectRatio='none' for non-viewBoxed <img> (Closed)
Patch Set: New baselines Created 4 years, 4 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
Index: third_party/WebKit/Source/core/svg/SVGSVGElement.cpp
diff --git a/third_party/WebKit/Source/core/svg/SVGSVGElement.cpp b/third_party/WebKit/Source/core/svg/SVGSVGElement.cpp
index 68d551d29d35d878f93c6b25ebf84467fd95ef1c..80aa89457d97d9a038f7188a390fa88bb6b1b73b 100644
--- a/third_party/WebKit/Source/core/svg/SVGSVGElement.cpp
+++ b/third_party/WebKit/Source/core/svg/SVGSVGElement.cpp
@@ -567,6 +567,13 @@ bool SVGSVGElement::selfHasRelativeLengths() const
|| m_height->currentValue()->isRelative();
}
+bool SVGSVGElement::shouldSynthesizeViewBox() const
+{
+ return layoutObject()
+ && layoutObject()->isSVGRoot()
+ && toLayoutSVGRoot(layoutObject())->isEmbeddedThroughSVGImage();
+}
+
FloatRect SVGSVGElement::currentViewBoxRect() const
davve 2016/09/01 17:46:42 I bothers me a bit that currentViewBoxRect() may r
fs 2016/09/01 17:57:24 Yeah, I noticed this too... Did feel that I should
{
if (m_useCurrentView) {
@@ -577,14 +584,33 @@ FloatRect SVGSVGElement::currentViewBoxRect() const
FloatRect useViewBox = viewBox()->currentValue()->value();
if (!useViewBox.isEmpty())
return useViewBox;
- if (!layoutObject() || !layoutObject()->isSVGRoot())
- return FloatRect();
- if (!toLayoutSVGRoot(layoutObject())->isEmbeddedThroughSVGImage())
+ if (!shouldSynthesizeViewBox())
return FloatRect();
// If no viewBox is specified but non-relative width/height values, then we
// should always synthesize a viewBox if we're embedded through a SVGImage.
- return FloatRect(FloatPoint(), FloatSize(intrinsicWidth(), intrinsicHeight()));
+ FloatSize synthesizedViewBoxSize(intrinsicWidth(), intrinsicHeight());
+ if (!hasIntrinsicWidth())
+ synthesizedViewBoxSize.setWidth(width()->currentValue()->scaleByPercentage(currentViewportSize().width()));
davve 2016/09/01 17:46:42 So a <svg .. width="50%" height="50%"> would produ
fs 2016/09/01 17:57:24 Yeah, maybe a bit odd, but I guess it could make s
+ if (!hasIntrinsicHeight())
+ synthesizedViewBoxSize.setHeight(height()->currentValue()->scaleByPercentage(currentViewportSize().height()));
+ return FloatRect(FloatPoint(), synthesizedViewBoxSize);
+}
+
+SVGPreserveAspectRatio* SVGSVGElement::currentPreserveAspectRatio() const
+{
+ if (m_useCurrentView) {
+ DCHECK(m_viewSpec);
+ return m_viewSpec->preserveAspectRatio()->currentValue();
+ }
+ if (!viewBox()->currentValue()->isValid() && shouldSynthesizeViewBox()) {
+ // If no viewBox is specified and we're embedded through SVGImage, then
+ // synthesize a pAR with the value 'none'.
+ SVGPreserveAspectRatio* synthesizedPAR = SVGPreserveAspectRatio::create();
+ synthesizedPAR->setAlign(SVGPreserveAspectRatio::kSvgPreserveaspectratioNone);
+ return synthesizedPAR;
+ }
+ return preserveAspectRatio()->currentValue();
}
FloatSize SVGSVGElement::currentViewportSize() const
@@ -631,11 +657,11 @@ float SVGSVGElement::intrinsicHeight() const
AffineTransform SVGSVGElement::viewBoxToViewTransform(float viewWidth, float viewHeight) const
{
+ AffineTransform ctm = SVGFitToViewBox::viewBoxToViewTransform(currentViewBoxRect(), currentPreserveAspectRatio(), viewWidth, viewHeight);
if (!m_useCurrentView)
- return SVGFitToViewBox::viewBoxToViewTransform(currentViewBoxRect(), preserveAspectRatio()->currentValue(), viewWidth, viewHeight);
+ return ctm;
DCHECK(m_viewSpec);
- AffineTransform ctm = SVGFitToViewBox::viewBoxToViewTransform(currentViewBoxRect(), m_viewSpec->preserveAspectRatio()->currentValue(), viewWidth, viewHeight);
SVGTransformList* transformList = m_viewSpec->transform();
if (transformList->isEmpty())
return ctm;

Powered by Google App Engine
This is Rietveld 408576698