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 RenderSVGImage::destroy() | 57 void RenderSVGImage::destroy() |
58 { | 58 { |
59 ImageQualityController::remove(this); | 59 ImageQualityController::remove(this); |
60 m_imageResource->shutdown(); | 60 m_imageResource->shutdown(); |
61 RenderSVGModelObject::destroy(); | 61 RenderSVGModelObject::destroy(); |
62 } | 62 } |
63 | 63 |
64 bool RenderSVGImage::forceNonUniformScaling(SVGImageElement* image) const | 64 FloatSize RenderSVGImage::computeImageViewportSize(ImageResource& cachedImage) c
onst |
65 { | 65 { |
| 66 if (toSVGImageElement(element())->preserveAspectRatio()->currentValue()->ali
gn() != SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_NONE) |
| 67 return m_objectBoundingBox.size(); |
| 68 |
66 // Images with preserveAspectRatio=none should force non-uniform | 69 // Images with preserveAspectRatio=none should force non-uniform |
67 // scaling. This can be achieved by setting the image's container size to | 70 // scaling. This can be achieved by setting the image's container size to |
68 // its intrinsic size. If the image does not have an intrinsic size - or | 71 // its viewport size (i.e. if a viewBox is available - use that - else use i
ntrinsic size.) |
69 // the intrinsic size is degenerate - set the container size to the bounds | |
70 // as in pAR!=none cases. | |
71 // See: http://www.w3.org/TR/SVG/single-page.html, 7.8 The ‘preserveAspectRa
tio’ attribute. | 72 // See: http://www.w3.org/TR/SVG/single-page.html, 7.8 The ‘preserveAspectRa
tio’ attribute. |
72 if (image->preserveAspectRatio()->currentValue()->align() != SVGPreserveAspe
ctRatio::SVG_PRESERVEASPECTRATIO_NONE) | |
73 return false; | |
74 ImageResource* cachedImage = m_imageResource->cachedImage(); | |
75 if (!cachedImage) | |
76 return false; | |
77 Length intrinsicWidth; | 73 Length intrinsicWidth; |
78 Length intrinsicHeight; | 74 Length intrinsicHeight; |
79 FloatSize intrinsicRatio; | 75 FloatSize intrinsicRatio; |
80 cachedImage->computeIntrinsicDimensions(intrinsicWidth, intrinsicHeight, int
rinsicRatio); | 76 cachedImage.computeIntrinsicDimensions(intrinsicWidth, intrinsicHeight, intr
insicRatio); |
81 if (!intrinsicWidth.isFixed() || !intrinsicHeight.isFixed()) | 77 return intrinsicRatio; |
82 return false; | |
83 // If the viewport defined by the referenced image is zero in either | |
84 // dimension, then SVGImage will have computed an intrinsic size of 300x150. | |
85 if (!floatValueForLength(intrinsicWidth, 0) || !floatValueForLength(intrinsi
cHeight, 0)) | |
86 return false; | |
87 return true; | |
88 } | 78 } |
89 | 79 |
90 bool RenderSVGImage::updateImageViewport() | 80 bool RenderSVGImage::updateImageViewport() |
91 { | 81 { |
92 SVGImageElement* image = toSVGImageElement(element()); | 82 SVGImageElement* image = toSVGImageElement(element()); |
93 FloatRect oldBoundaries = m_objectBoundingBox; | 83 FloatRect oldBoundaries = m_objectBoundingBox; |
94 bool updatedViewport = false; | |
95 | 84 |
96 SVGLengthContext lengthContext(image); | 85 SVGLengthContext lengthContext(image); |
97 m_objectBoundingBox = FloatRect(image->x()->currentValue()->value(lengthCont
ext), image->y()->currentValue()->value(lengthContext), image->width()->currentV
alue()->value(lengthContext), image->height()->currentValue()->value(lengthConte
xt)); | 86 m_objectBoundingBox = FloatRect(image->x()->currentValue()->value(lengthCont
ext), image->y()->currentValue()->value(lengthContext), image->width()->currentV
alue()->value(lengthContext), image->height()->currentValue()->value(lengthConte
xt)); |
98 | |
99 bool boundsChanged = oldBoundaries != m_objectBoundingBox; | 87 bool boundsChanged = oldBoundaries != m_objectBoundingBox; |
100 | 88 |
101 IntSize newViewportSize; | 89 bool updatedViewport = false; |
102 if (forceNonUniformScaling(image)) { | 90 ImageResource* cachedImage = m_imageResource->cachedImage(); |
103 LayoutSize intrinsicSize = m_imageResource->intrinsicSize(style()->effec
tiveZoom()); | 91 if (cachedImage && cachedImage->usesImageContainerSize()) { |
104 if (intrinsicSize != m_imageResource->imageSize(style()->effectiveZoom()
)) { | 92 FloatSize imageViewportSize = computeImageViewportSize(*cachedImage); |
105 newViewportSize = roundedIntSize(intrinsicSize); | 93 if (imageViewportSize != m_imageResource->imageSize(style()->effectiveZo
om())) { |
| 94 m_imageResource->setContainerSizeForRenderer(roundedIntSize(imageVie
wportSize)); |
106 updatedViewport = true; | 95 updatedViewport = true; |
107 } | 96 } |
108 } else if (boundsChanged) { | |
109 newViewportSize = enclosingIntRect(m_objectBoundingBox).size(); | |
110 updatedViewport = true; | |
111 } | 97 } |
112 if (updatedViewport) | 98 |
113 m_imageResource->setContainerSizeForRenderer(newViewportSize); | |
114 m_needsBoundariesUpdate |= boundsChanged; | 99 m_needsBoundariesUpdate |= boundsChanged; |
115 return updatedViewport; | 100 return updatedViewport || boundsChanged; |
116 } | 101 } |
117 | 102 |
118 void RenderSVGImage::layout() | 103 void RenderSVGImage::layout() |
119 { | 104 { |
120 ASSERT(needsLayout()); | 105 ASSERT(needsLayout()); |
121 | 106 |
122 updateImageViewport(); | 107 updateImageViewport(); |
123 | 108 |
124 bool transformOrBoundariesUpdate = m_needsTransformUpdate || m_needsBoundari
esUpdate; | 109 bool transformOrBoundariesUpdate = m_needsTransformUpdate || m_needsBoundari
esUpdate; |
125 if (m_needsTransformUpdate) { | 110 if (m_needsTransformUpdate) { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 | 183 |
199 void RenderSVGImage::addFocusRingRects(Vector<LayoutRect>& rects, const LayoutPo
int&, const RenderLayerModelObject*) const | 184 void RenderSVGImage::addFocusRingRects(Vector<LayoutRect>& rects, const LayoutPo
int&, const RenderLayerModelObject*) const |
200 { | 185 { |
201 // this is called from paint() after the localTransform has already been app
lied | 186 // this is called from paint() after the localTransform has already been app
lied |
202 LayoutRect contentRect = LayoutRect(paintInvalidationRectInLocalCoordinates(
)); | 187 LayoutRect contentRect = LayoutRect(paintInvalidationRectInLocalCoordinates(
)); |
203 if (!contentRect.isEmpty()) | 188 if (!contentRect.isEmpty()) |
204 rects.append(contentRect); | 189 rects.append(contentRect); |
205 } | 190 } |
206 | 191 |
207 } // namespace blink | 192 } // namespace blink |
OLD | NEW |