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

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

Issue 1604993003: Set intrinsic size for inline SVG earlier (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Avoid isEmpty(). Set individual width/height values. Add test for this. Created 4 years, 11 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/LayoutSVGRoot.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/LayoutSVGRoot.cpp
diff --git a/third_party/WebKit/Source/core/layout/svg/LayoutSVGRoot.cpp b/third_party/WebKit/Source/core/layout/svg/LayoutSVGRoot.cpp
index fbe5909f7a0917a37e843ac9a56c9a385ae59861..8fe95c6749666c7e9cfb965c6028aa6eba615be0 100644
--- a/third_party/WebKit/Source/core/layout/svg/LayoutSVGRoot.cpp
+++ b/third_party/WebKit/Source/core/layout/svg/LayoutSVGRoot.cpp
@@ -48,29 +48,30 @@ LayoutSVGRoot::LayoutSVGRoot(SVGElement* node)
, m_hasNonIsolatedBlendingDescendants(false)
, m_hasNonIsolatedBlendingDescendantsDirty(false)
{
+ LayoutSize intrinsicSize(calculateIntrinsicSize());
+ if (!intrinsicSize.width())
+ intrinsicSize.setWidth(defaultWidth);
+ if (!intrinsicSize.height())
+ intrinsicSize.setHeight(defaultHeight);
+ setIntrinsicSize(intrinsicSize);
}
LayoutSVGRoot::~LayoutSVGRoot()
{
}
-void LayoutSVGRoot::computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio) const
+FloatSize LayoutSVGRoot::calculateIntrinsicSize() const
{
- // Spec: http://www.w3.org/TR/SVG/coords.html#IntrinsicSizing
- // SVG needs to specify how to calculate some intrinsic sizing properties to enable inclusion within other languages.
- // The intrinsic width and height of the viewport of SVG content must be determined from the 'width' and 'height' attributes.
SVGSVGElement* svg = toSVGSVGElement(node());
ASSERT(svg);
- // The intrinsic aspect ratio of the viewport of SVG content is necessary for example, when including SVG from an 'object'
- // element in HTML styled with CSS. It is possible (indeed, common) for an SVG graphic to have an intrinsic aspect ratio but
- // not to have an intrinsic width or height. The intrinsic aspect ratio must be calculated based upon the following rules:
- // - The aspect ratio is calculated by dividing a width by a height.
- // - If the 'width' and 'height' of the rootmost 'svg' element are both specified with unit identifiers (in, mm, cm, pt, pc,
- // px, em, ex) or in user units, then the aspect ratio is calculated from the 'width' and 'height' attributes after
- // resolving both values to user units.
- intrinsicSize.setWidth(floatValueForLength(svg->intrinsicWidth(), 0));
- intrinsicSize.setHeight(floatValueForLength(svg->intrinsicHeight(), 0));
+ return FloatSize(floatValueForLength(svg->intrinsicWidth(), 0), floatValueForLength(svg->intrinsicHeight(), 0));
+}
+
+void LayoutSVGRoot::computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio) const
+{
+ // https://www.w3.org/TR/SVG/coords.html#IntrinsicSizing
+ intrinsicSize = calculateIntrinsicSize();
if (!isHorizontalWritingMode())
intrinsicSize = intrinsicSize.transposedSize();
@@ -78,10 +79,9 @@ void LayoutSVGRoot::computeIntrinsicRatioInformation(FloatSize& intrinsicSize, d
if (!intrinsicSize.isEmpty()) {
intrinsicRatio = intrinsicSize.width() / static_cast<double>(intrinsicSize.height());
} else {
- // - If either/both of the 'width' and 'height' of the rootmost 'svg' element are in percentage units (or omitted), the
- // aspect ratio is calculated from the width and height values of the 'viewBox' specified for the current SVG document
- // fragment. If the 'viewBox' is not correctly specified, or set to 'none', the intrinsic aspect ratio cannot be
- // calculated and is considered unspecified.
+ SVGSVGElement* svg = toSVGSVGElement(node());
+ ASSERT(svg);
+
FloatSize viewBoxSize = svg->viewBox()->currentValue()->value().size();
if (!viewBoxSize.isEmpty()) {
// The viewBox can only yield an intrinsic ratio, not an intrinsic size.
« no previous file with comments | « third_party/WebKit/Source/core/layout/svg/LayoutSVGRoot.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698