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

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

Issue 1679743006: Expand IntrinsicSizingInfo for SVG (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@propagate-whether-svg-has
Patch Set: Zero means zero Created 4 years, 10 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2007, 2008, 2009 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005, 2007, 2008, 2009 Rob Buis <buis@kde.org>
4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> 4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
5 * Copyright (C) 2009 Google, Inc. 5 * Copyright (C) 2009 Google, Inc.
6 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 6 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 21 matching lines...) Expand all
32 #include "core/layout/svg/SVGResourcesCache.h" 32 #include "core/layout/svg/SVGResourcesCache.h"
33 #include "core/paint/PaintLayer.h" 33 #include "core/paint/PaintLayer.h"
34 #include "core/paint/SVGRootPainter.h" 34 #include "core/paint/SVGRootPainter.h"
35 #include "core/svg/SVGElement.h" 35 #include "core/svg/SVGElement.h"
36 #include "core/svg/SVGSVGElement.h" 36 #include "core/svg/SVGSVGElement.h"
37 #include "core/svg/graphics/SVGImage.h" 37 #include "core/svg/graphics/SVGImage.h"
38 #include "platform/LengthFunctions.h" 38 #include "platform/LengthFunctions.h"
39 39
40 namespace blink { 40 namespace blink {
41 41
42 namespace {
43
44 FloatSize calculateIntrinsicSize(const SVGSVGElement& svg)
45 {
46 return FloatSize(floatValueForLength(svg.intrinsicWidth(), 0), floatValueFor Length(svg.intrinsicHeight(), 0));
47 }
48
49 } // namespace
50
42 LayoutSVGRoot::LayoutSVGRoot(SVGElement* node) 51 LayoutSVGRoot::LayoutSVGRoot(SVGElement* node)
43 : LayoutReplaced(node) 52 : LayoutReplaced(node)
44 , m_objectBoundingBoxValid(false) 53 , m_objectBoundingBoxValid(false)
45 , m_isLayoutSizeChanged(false) 54 , m_isLayoutSizeChanged(false)
46 , m_needsBoundariesOrTransformUpdate(true) 55 , m_needsBoundariesOrTransformUpdate(true)
47 , m_hasBoxDecorationBackground(false) 56 , m_hasBoxDecorationBackground(false)
48 , m_hasNonIsolatedBlendingDescendants(false) 57 , m_hasNonIsolatedBlendingDescendants(false)
49 , m_hasNonIsolatedBlendingDescendantsDirty(false) 58 , m_hasNonIsolatedBlendingDescendantsDirty(false)
50 { 59 {
51 LayoutSize intrinsicSize(calculateIntrinsicSize()); 60 SVGSVGElement* svg = toSVGSVGElement(node);
52 if (!intrinsicSize.width()) 61 ASSERT(svg);
62
63 LayoutSize intrinsicSize(calculateIntrinsicSize(*svg));
64 if (!svg->hasIntrinsicWidth())
53 intrinsicSize.setWidth(LayoutUnit(defaultWidth)); 65 intrinsicSize.setWidth(LayoutUnit(defaultWidth));
54 if (!intrinsicSize.height()) 66 if (!svg->hasIntrinsicHeight())
55 intrinsicSize.setHeight(LayoutUnit(defaultHeight)); 67 intrinsicSize.setHeight(LayoutUnit(defaultHeight));
56 setIntrinsicSize(intrinsicSize); 68 setIntrinsicSize(intrinsicSize);
57 } 69 }
58 70
59 LayoutSVGRoot::~LayoutSVGRoot() 71 LayoutSVGRoot::~LayoutSVGRoot()
60 { 72 {
61 } 73 }
62 74
63 FloatSize LayoutSVGRoot::calculateIntrinsicSize() const
64 {
65 SVGSVGElement* svg = toSVGSVGElement(node());
66 ASSERT(svg);
67
68 return FloatSize(floatValueForLength(svg->intrinsicWidth(), 0), floatValueFo rLength(svg->intrinsicHeight(), 0));
69 }
70
71 void LayoutSVGRoot::computeIntrinsicSizingInfo(IntrinsicSizingInfo& intrinsicSiz ingInfo) const 75 void LayoutSVGRoot::computeIntrinsicSizingInfo(IntrinsicSizingInfo& intrinsicSiz ingInfo) const
72 { 76 {
73 // https://www.w3.org/TR/SVG/coords.html#IntrinsicSizing 77 // https://www.w3.org/TR/SVG/coords.html#IntrinsicSizing
74 intrinsicSizingInfo.size = calculateIntrinsicSize();
75 78
76 if (!isHorizontalWritingMode()) 79 SVGSVGElement* svg = toSVGSVGElement(node());
77 intrinsicSizingInfo.size = intrinsicSizingInfo.size.transposedSize(); 80 ASSERT(svg);
81
82 intrinsicSizingInfo.size = calculateIntrinsicSize(*svg);
83 intrinsicSizingInfo.hasWidth = svg->hasIntrinsicWidth();
84 intrinsicSizingInfo.hasHeight = svg->hasIntrinsicHeight();
78 85
79 if (!intrinsicSizingInfo.size.isEmpty()) { 86 if (!intrinsicSizingInfo.size.isEmpty()) {
80 intrinsicSizingInfo.aspectRatio = intrinsicSizingInfo.size.width() / sta tic_cast<double>(intrinsicSizingInfo.size.height()); 87 intrinsicSizingInfo.aspectRatio = intrinsicSizingInfo.size.width() / sta tic_cast<double>(intrinsicSizingInfo.size.height());
81 } else { 88 } else {
82 SVGSVGElement* svg = toSVGSVGElement(node());
83 ASSERT(svg);
84
85 FloatSize viewBoxSize = svg->viewBox()->currentValue()->value().size(); 89 FloatSize viewBoxSize = svg->viewBox()->currentValue()->value().size();
86 if (!viewBoxSize.isEmpty()) { 90 if (!viewBoxSize.isEmpty()) {
87 // The viewBox can only yield an intrinsic ratio, not an intrinsic s ize. 91 // The viewBox can only yield an intrinsic ratio, not an intrinsic s ize.
88 intrinsicSizingInfo.aspectRatio = viewBoxSize.width() / static_cast< double>(viewBoxSize.height()); 92 intrinsicSizingInfo.aspectRatio = viewBoxSize.width() / static_cast< double>(viewBoxSize.height());
89 if (!isHorizontalWritingMode())
90 intrinsicSizingInfo.aspectRatio = 1 / intrinsicSizingInfo.aspect Ratio;
91 } 93 }
92 } 94 }
95
96 if (!isHorizontalWritingMode())
97 intrinsicSizingInfo.transpose();
93 } 98 }
94 99
95 bool LayoutSVGRoot::isEmbeddedThroughSVGImage() const 100 bool LayoutSVGRoot::isEmbeddedThroughSVGImage() const
96 { 101 {
97 return SVGImage::isInSVGImage(toSVGSVGElement(node())); 102 return SVGImage::isInSVGImage(toSVGSVGElement(node()));
98 } 103 }
99 104
100 bool LayoutSVGRoot::isEmbeddedThroughFrameContainingSVGDocument() const 105 bool LayoutSVGRoot::isEmbeddedThroughFrameContainingSVGDocument() const
101 { 106 {
102 if (!node()) 107 if (!node())
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 updateHitTestResult(result, pointInBorderBox); 404 updateHitTestResult(result, pointInBorderBox);
400 if (result.addNodeToListBasedTestResult(node(), locationInContainer, boundsRect) == StopHitTesting) 405 if (result.addNodeToListBasedTestResult(node(), locationInContainer, boundsRect) == StopHitTesting)
401 return true; 406 return true;
402 } 407 }
403 } 408 }
404 409
405 return false; 410 return false;
406 } 411 }
407 412
408 } // namespace blink 413 } // namespace blink
OLDNEW
« 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