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

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

Issue 1685353004: Clean up Image::computeIntrinsicDimensions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nits 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
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
51 LayoutSVGRoot::LayoutSVGRoot(SVGElement* node) 42 LayoutSVGRoot::LayoutSVGRoot(SVGElement* node)
52 : LayoutReplaced(node) 43 : LayoutReplaced(node)
53 , m_objectBoundingBoxValid(false) 44 , m_objectBoundingBoxValid(false)
54 , m_isLayoutSizeChanged(false) 45 , m_isLayoutSizeChanged(false)
55 , m_needsBoundariesOrTransformUpdate(true) 46 , m_needsBoundariesOrTransformUpdate(true)
56 , m_hasBoxDecorationBackground(false) 47 , m_hasBoxDecorationBackground(false)
57 , m_hasNonIsolatedBlendingDescendants(false) 48 , m_hasNonIsolatedBlendingDescendants(false)
58 , m_hasNonIsolatedBlendingDescendantsDirty(false) 49 , m_hasNonIsolatedBlendingDescendantsDirty(false)
59 { 50 {
60 SVGSVGElement* svg = toSVGSVGElement(node); 51 SVGSVGElement* svg = toSVGSVGElement(node);
61 ASSERT(svg); 52 ASSERT(svg);
62 53
63 LayoutSize intrinsicSize(calculateIntrinsicSize(*svg)); 54 LayoutSize intrinsicSize(svg->intrinsicWidth(), svg->intrinsicHeight());
64 if (!svg->hasIntrinsicWidth()) 55 if (!svg->hasIntrinsicWidth())
65 intrinsicSize.setWidth(LayoutUnit(defaultWidth)); 56 intrinsicSize.setWidth(LayoutUnit(defaultWidth));
66 if (!svg->hasIntrinsicHeight()) 57 if (!svg->hasIntrinsicHeight())
67 intrinsicSize.setHeight(LayoutUnit(defaultHeight)); 58 intrinsicSize.setHeight(LayoutUnit(defaultHeight));
68 setIntrinsicSize(intrinsicSize); 59 setIntrinsicSize(intrinsicSize);
69 } 60 }
70 61
71 LayoutSVGRoot::~LayoutSVGRoot() 62 LayoutSVGRoot::~LayoutSVGRoot()
72 { 63 {
73 } 64 }
74 65
75 void LayoutSVGRoot::computeIntrinsicSizingInfo(IntrinsicSizingInfo& intrinsicSiz ingInfo) const 66 void LayoutSVGRoot::computeIntrinsicSizingInfo(IntrinsicSizingInfo& intrinsicSiz ingInfo) const
76 { 67 {
77 // https://www.w3.org/TR/SVG/coords.html#IntrinsicSizing 68 // https://www.w3.org/TR/SVG/coords.html#IntrinsicSizing
78 69
79 SVGSVGElement* svg = toSVGSVGElement(node()); 70 SVGSVGElement* svg = toSVGSVGElement(node());
80 ASSERT(svg); 71 ASSERT(svg);
81 72
82 intrinsicSizingInfo.size = calculateIntrinsicSize(*svg); 73 intrinsicSizingInfo.size = FloatSize(svg->intrinsicWidth(), svg->intrinsicHe ight());
83 intrinsicSizingInfo.hasWidth = svg->hasIntrinsicWidth(); 74 intrinsicSizingInfo.hasWidth = svg->hasIntrinsicWidth();
84 intrinsicSizingInfo.hasHeight = svg->hasIntrinsicHeight(); 75 intrinsicSizingInfo.hasHeight = svg->hasIntrinsicHeight();
85 76
86 if (!intrinsicSizingInfo.size.isEmpty()) { 77 if (!intrinsicSizingInfo.size.isEmpty()) {
87 intrinsicSizingInfo.aspectRatio = intrinsicSizingInfo.size.width() / sta tic_cast<double>(intrinsicSizingInfo.size.height()); 78 intrinsicSizingInfo.aspectRatio = intrinsicSizingInfo.size.width() / sta tic_cast<double>(intrinsicSizingInfo.size.height());
88 } else { 79 } else {
89 FloatSize viewBoxSize = svg->viewBox()->currentValue()->value().size(); 80 FloatSize viewBoxSize = svg->viewBox()->currentValue()->value().size();
90 if (!viewBoxSize.isEmpty()) { 81 if (!viewBoxSize.isEmpty()) {
91 // The viewBox can only yield an intrinsic ratio, not an intrinsic s ize. 82 // The viewBox can only yield an intrinsic ratio, not an intrinsic s ize.
92 intrinsicSizingInfo.aspectRatio = viewBoxSize.width() / static_cast< double>(viewBoxSize.height()); 83 intrinsicSizingInfo.aspectRatio = viewBoxSize.width() / static_cast< double>(viewBoxSize.height());
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 updateHitTestResult(result, pointInBorderBox); 395 updateHitTestResult(result, pointInBorderBox);
405 if (result.addNodeToListBasedTestResult(node(), locationInContainer, boundsRect) == StopHitTesting) 396 if (result.addNodeToListBasedTestResult(node(), locationInContainer, boundsRect) == StopHitTesting)
406 return true; 397 return true;
407 } 398 }
408 } 399 }
409 400
410 return false; 401 return false;
411 } 402 }
412 403
413 } // namespace blink 404 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698