OLD | NEW |
---|---|
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 Loading... | |
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() | |
75 { | |
76 ImageResource* cachedImage = m_imageResource->cachedImage(); | |
77 if (!cachedImage || cachedImage->errorOccurred()) | |
78 return FloatSize(); | |
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 if (styleRef().width().isAuto()) | |
88 return FloatSize(resolveWidthForRatio(m_objectBoundingBox.height(), intr insicSize), m_objectBoundingBox.height()); | |
89 | |
90 return FloatSize(); | |
fs
2016/09/14 11:31:52
This is unreachable? Maybe just assert styleRef().
Shanmuga Pandi
2016/09/14 13:15:36
Done.
| |
91 } | |
92 | |
93 bool LayoutSVGImage::updateBoundingBox() | |
65 { | 94 { |
66 FloatRect oldBoundaries = m_objectBoundingBox; | 95 FloatRect oldBoundaries = m_objectBoundingBox; |
67 | 96 |
68 SVGLengthContext lengthContext(element()); | 97 SVGLengthContext lengthContext(element()); |
69 m_objectBoundingBox = FloatRect( | 98 m_objectBoundingBox = FloatRect( |
70 lengthContext.valueForLength(styleRef().svgStyle().x(), styleRef(), SVGL engthMode::Width), | 99 lengthContext.valueForLength(styleRef().svgStyle().x(), styleRef(), SVGL engthMode::Width), |
71 lengthContext.valueForLength(styleRef().svgStyle().y(), styleRef(), SVGL engthMode::Height), | 100 lengthContext.valueForLength(styleRef().svgStyle().y(), styleRef(), SVGL engthMode::Height), |
72 lengthContext.valueForLength(styleRef().width(), styleRef(), SVGLengthMo de::Width), | 101 lengthContext.valueForLength(styleRef().width(), styleRef(), SVGLengthMo de::Width), |
73 lengthContext.valueForLength(styleRef().height(), styleRef(), SVGLengthM ode::Height)); | 102 lengthContext.valueForLength(styleRef().height(), styleRef(), SVGLengthM ode::Height)); |
103 | |
104 if (styleRef().width().isAuto() || styleRef().height().isAuto()) { | |
105 FloatSize intrinsicSize = calculateObjectSize(); | |
106 if (styleRef().width().isAuto()) | |
fs
2016/09/14 11:31:52
This branching looks redundant - couldn't this jus
Shanmuga Pandi
2016/09/14 13:15:36
Done.
| |
107 m_objectBoundingBox.setWidth(intrinsicSize.width()); | |
108 if (styleRef().height().isAuto()) | |
109 m_objectBoundingBox.setHeight(intrinsicSize.height()); | |
110 } | |
74 m_needsBoundariesUpdate |= oldBoundaries != m_objectBoundingBox; | 111 m_needsBoundariesUpdate |= oldBoundaries != m_objectBoundingBox; |
75 if (element()) | 112 if (element()) |
76 element()->setNeedsResizeObserverUpdate(); | 113 element()->setNeedsResizeObserverUpdate(); |
114 | |
115 return oldBoundaries.size() != m_objectBoundingBox.size(); | |
77 } | 116 } |
78 | 117 |
79 void LayoutSVGImage::layout() | 118 void LayoutSVGImage::layout() |
80 { | 119 { |
81 ASSERT(needsLayout()); | 120 ASSERT(needsLayout()); |
82 LayoutAnalyzer::Scope analyzer(*this); | 121 LayoutAnalyzer::Scope analyzer(*this); |
83 | 122 |
84 // Invalidate all resources of this client if our layout changed. | 123 // Invalidate all resources of this client if our layout changed. |
85 if (everHadLayout() && selfNeedsLayout()) | 124 if (everHadLayout() && selfNeedsLayout()) |
86 SVGResourcesCache::clientLayoutChanged(this); | 125 SVGResourcesCache::clientLayoutChanged(this); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 return false; | 180 return false; |
142 } | 181 } |
143 | 182 |
144 void LayoutSVGImage::imageChanged(WrappedImagePtr, const IntRect*) | 183 void LayoutSVGImage::imageChanged(WrappedImagePtr, const IntRect*) |
145 { | 184 { |
146 // Notify parent resources that we've changed. This also invalidates | 185 // Notify parent resources that we've changed. This also invalidates |
147 // references from resources (filters) that may have a cached | 186 // references from resources (filters) that may have a cached |
148 // representation of this image/layout object. | 187 // representation of this image/layout object. |
149 LayoutSVGResourceContainer::markForLayoutAndParentResourceInvalidation(this, false); | 188 LayoutSVGResourceContainer::markForLayoutAndParentResourceInvalidation(this, false); |
150 | 189 |
190 if (styleRef().width().isAuto() || styleRef().height().isAuto()) { | |
191 if (updateBoundingBox()) | |
192 setNeedsLayout(LayoutInvalidationReason::SizeChanged); | |
193 } | |
194 | |
151 setShouldDoFullPaintInvalidation(); | 195 setShouldDoFullPaintInvalidation(); |
152 } | 196 } |
153 | 197 |
154 void LayoutSVGImage::addOutlineRects(Vector<LayoutRect>& rects, const LayoutPoin t&, IncludeBlockVisualOverflowOrNot) const | 198 void LayoutSVGImage::addOutlineRects(Vector<LayoutRect>& rects, const LayoutPoin t&, IncludeBlockVisualOverflowOrNot) const |
155 { | 199 { |
156 // this is called from paint() after the localTransform has already been app lied | 200 // this is called from paint() after the localTransform has already been app lied |
157 rects.append(LayoutRect(paintInvalidationRectInLocalSVGCoordinates())); | 201 rects.append(LayoutRect(paintInvalidationRectInLocalSVGCoordinates())); |
158 } | 202 } |
159 | 203 |
160 } // namespace blink | 204 } // namespace blink |
OLD | NEW |