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

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

Issue 2230963002: SVG Image intrinsic size should be used if css style size is 'auto' (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Align with review comments Created 4 years, 3 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/LayoutSVGImage.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) 2006 Alexander Kellett <lypanov@kde.org> 2 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org>
3 * Copyright (C) 2006 Apple Computer, Inc. 3 * Copyright (C) 2006 Apple Computer, Inc.
4 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> 4 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
5 * Copyright (C) 2007, 2008, 2009 Rob Buis <buis@kde.org> 5 * Copyright (C) 2007, 2008, 2009 Rob Buis <buis@kde.org>
6 * Copyright (C) 2009 Google, Inc. 6 * Copyright (C) 2009 Google, Inc.
7 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> 7 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
8 * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com> 8 * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com>
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 { 54 {
55 } 55 }
56 56
57 void LayoutSVGImage::willBeDestroyed() 57 void LayoutSVGImage::willBeDestroyed()
58 { 58 {
59 ImageQualityController::remove(*this); 59 ImageQualityController::remove(*this);
60 m_imageResource->shutdown(); 60 m_imageResource->shutdown();
61 LayoutSVGModelObject::willBeDestroyed(); 61 LayoutSVGModelObject::willBeDestroyed();
62 } 62 }
63 63
64 void LayoutSVGImage::updateBoundingBox() 64 static float resolveWidthForRatio(float height, const FloatSize& intrinsicRatio)
65 {
66 return height * intrinsicRatio.width() / intrinsicRatio.height();
67 }
68
69 static float resolveHeightForRatio(float width, const FloatSize& intrinsicRatio)
70 {
71 return width * intrinsicRatio.height() / intrinsicRatio.width();
72 }
73
74 FloatSize LayoutSVGImage::calculateObjectSize() const
75 {
76 ImageResource* cachedImage = m_imageResource->cachedImage();
77 if (!cachedImage || cachedImage->errorOccurred())
78 return m_objectBoundingBox.size();
79
80 FloatSize intrinsicSize = FloatSize(cachedImage->getImage()->size());
81 if (styleRef().width().isAuto() && styleRef().height().isAuto())
82 return intrinsicSize;
83
84 if (styleRef().height().isAuto())
85 return FloatSize(m_objectBoundingBox.width(), resolveHeightForRatio(m_ob jectBoundingBox.width(), intrinsicSize));
86
87 DCHECK(styleRef().width().isAuto());
88 return FloatSize(resolveWidthForRatio(m_objectBoundingBox.height(), intrinsi cSize), m_objectBoundingBox.height());
89 }
90
91 bool LayoutSVGImage::updateBoundingBox()
davve 2016/09/14 14:13:17 Having updateBoundingBox() both set a member varia
fs 2016/09/14 14:37:11 IIRC we have a bug on file to shift some of this s
davve 2016/09/15 12:34:43 s/no-up/no-op/. Sorry about that. After some more
65 { 92 {
66 FloatRect oldBoundaries = m_objectBoundingBox; 93 FloatRect oldBoundaries = m_objectBoundingBox;
67 94
68 SVGLengthContext lengthContext(element()); 95 SVGLengthContext lengthContext(element());
69 m_objectBoundingBox = FloatRect( 96 m_objectBoundingBox = FloatRect(
70 lengthContext.valueForLength(styleRef().svgStyle().x(), styleRef(), SVGL engthMode::Width), 97 lengthContext.valueForLength(styleRef().svgStyle().x(), styleRef(), SVGL engthMode::Width),
71 lengthContext.valueForLength(styleRef().svgStyle().y(), styleRef(), SVGL engthMode::Height), 98 lengthContext.valueForLength(styleRef().svgStyle().y(), styleRef(), SVGL engthMode::Height),
72 lengthContext.valueForLength(styleRef().width(), styleRef(), SVGLengthMo de::Width), 99 lengthContext.valueForLength(styleRef().width(), styleRef(), SVGLengthMo de::Width),
73 lengthContext.valueForLength(styleRef().height(), styleRef(), SVGLengthM ode::Height)); 100 lengthContext.valueForLength(styleRef().height(), styleRef(), SVGLengthM ode::Height));
101
102 if (styleRef().width().isAuto() || styleRef().height().isAuto())
103 m_objectBoundingBox.setSize(calculateObjectSize());
104
74 m_needsBoundariesUpdate |= oldBoundaries != m_objectBoundingBox; 105 m_needsBoundariesUpdate |= oldBoundaries != m_objectBoundingBox;
75 if (element()) 106 if (element())
76 element()->setNeedsResizeObserverUpdate(); 107 element()->setNeedsResizeObserverUpdate();
108
109 return oldBoundaries.size() != m_objectBoundingBox.size();
77 } 110 }
78 111
79 void LayoutSVGImage::layout() 112 void LayoutSVGImage::layout()
80 { 113 {
81 ASSERT(needsLayout()); 114 ASSERT(needsLayout());
82 LayoutAnalyzer::Scope analyzer(*this); 115 LayoutAnalyzer::Scope analyzer(*this);
83 116
84 // Invalidate all resources of this client if our layout changed. 117 // Invalidate all resources of this client if our layout changed.
85 if (everHadLayout() && selfNeedsLayout()) 118 if (everHadLayout() && selfNeedsLayout())
86 SVGResourcesCache::clientLayoutChanged(this); 119 SVGResourcesCache::clientLayoutChanged(this);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 return false; 174 return false;
142 } 175 }
143 176
144 void LayoutSVGImage::imageChanged(WrappedImagePtr, const IntRect*) 177 void LayoutSVGImage::imageChanged(WrappedImagePtr, const IntRect*)
145 { 178 {
146 // Notify parent resources that we've changed. This also invalidates 179 // Notify parent resources that we've changed. This also invalidates
147 // references from resources (filters) that may have a cached 180 // references from resources (filters) that may have a cached
148 // representation of this image/layout object. 181 // representation of this image/layout object.
149 LayoutSVGResourceContainer::markForLayoutAndParentResourceInvalidation(this, false); 182 LayoutSVGResourceContainer::markForLayoutAndParentResourceInvalidation(this, false);
150 183
184 if (styleRef().width().isAuto() || styleRef().height().isAuto()) {
185 if (updateBoundingBox())
186 setNeedsLayout(LayoutInvalidationReason::SizeChanged);
187 }
188
151 setShouldDoFullPaintInvalidation(); 189 setShouldDoFullPaintInvalidation();
152 } 190 }
153 191
154 void LayoutSVGImage::addOutlineRects(Vector<LayoutRect>& rects, const LayoutPoin t&, IncludeBlockVisualOverflowOrNot) const 192 void LayoutSVGImage::addOutlineRects(Vector<LayoutRect>& rects, const LayoutPoin t&, IncludeBlockVisualOverflowOrNot) const
155 { 193 {
156 // this is called from paint() after the localTransform has already been app lied 194 // this is called from paint() after the localTransform has already been app lied
157 rects.append(LayoutRect(paintInvalidationRectInLocalSVGCoordinates())); 195 rects.append(LayoutRect(paintInvalidationRectInLocalSVGCoordinates()));
158 } 196 }
159 197
160 } // namespace blink 198 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/svg/LayoutSVGImage.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698