Chromium Code Reviews| 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 LayoutSize RenderSVGImage::computeNonUniformScalingViewportSize() const |
| 65 { | 65 { |
| 66 // Images with preserveAspectRatio=none should force non-uniform | 66 // Note: This assumes that the 'intrinsic ratio' as returned by |
|
pdr.
2014/11/12 00:48:25
Could we document this on the Image interface inst
fs
2014/11/12 10:13:44
Done.
| |
| 67 // scaling. This can be achieved by setting the image's container size to | 67 // ImageResource::computeIntrinsicDimensions (and indirectly the same |
| 68 // its intrinsic size. If the image does not have an intrinsic size - or | 68 // method on Image) is the viewport of the image. This is not documented to |
| 69 // the intrinsic size is degenerate - set the container size to the bounds | 69 // be the case in the Image interface, but is what the current |
| 70 // as in pAR!=none cases. | 70 // implementations return. |
| 71 // See: http://www.w3.org/TR/SVG/single-page.html, 7.8 The ‘preserveAspectRa tio’ attribute. | 71 if (ImageResource* cachedImage = m_imageResource->cachedImage()) { |
| 72 if (image->preserveAspectRatio()->currentValue()->align() != SVGPreserveAspe ctRatio::SVG_PRESERVEASPECTRATIO_NONE) | 72 Length intrinsicWidth; |
| 73 return false; | 73 Length intrinsicHeight; |
| 74 ImageResource* cachedImage = m_imageResource->cachedImage(); | 74 FloatSize intrinsicRatio; |
| 75 if (!cachedImage) | 75 cachedImage->computeIntrinsicDimensions(intrinsicWidth, intrinsicHeight, intrinsicRatio); |
| 76 return false; | 76 if (!intrinsicRatio.isEmpty()) |
| 77 Length intrinsicWidth; | 77 return roundedLayoutSize(intrinsicRatio); |
| 78 Length intrinsicHeight; | 78 } |
| 79 FloatSize intrinsicRatio; | 79 return m_imageResource->intrinsicSize(style()->effectiveZoom()); |
|
pdr.
2014/11/12 00:48:25
It looks like this will end up just returning an e
fs
2014/11/12 10:13:45
Yes, true. Done.
| |
| 80 cachedImage->computeIntrinsicDimensions(intrinsicWidth, intrinsicHeight, int rinsicRatio); | |
| 81 if (!intrinsicWidth.isFixed() || !intrinsicHeight.isFixed()) | |
| 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 } | 80 } |
| 89 | 81 |
| 90 bool RenderSVGImage::updateImageViewport() | 82 bool RenderSVGImage::updateImageViewport() |
| 91 { | 83 { |
| 92 SVGImageElement* image = toSVGImageElement(element()); | 84 SVGImageElement* image = toSVGImageElement(element()); |
| 93 FloatRect oldBoundaries = m_objectBoundingBox; | 85 FloatRect oldBoundaries = m_objectBoundingBox; |
| 94 bool updatedViewport = false; | |
| 95 | 86 |
| 96 SVGLengthContext lengthContext(image); | 87 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)); | 88 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 | 89 |
| 99 bool boundsChanged = oldBoundaries != m_objectBoundingBox; | 90 bool boundsChanged = oldBoundaries != m_objectBoundingBox; |
| 100 | 91 |
| 92 // Images with preserveAspectRatio=none should force non-uniform | |
| 93 // scaling. This can be achieved by setting the image's container size to | |
| 94 // its viewport size (i.e. if a viewBox is available - use that - else use i ntrinsic size. | |
| 95 // See: http://www.w3.org/TR/SVG/single-page.html, 7.8 The ‘preserveAspectRa tio’ attribute. | |
| 101 IntSize newViewportSize; | 96 IntSize newViewportSize; |
| 102 if (forceNonUniformScaling(image)) { | 97 bool updatedViewport = false; |
| 103 LayoutSize intrinsicSize = m_imageResource->intrinsicSize(style()->effec tiveZoom()); | 98 if (image->preserveAspectRatio()->currentValue()->align() == SVGPreserveAspe ctRatio::SVG_PRESERVEASPECTRATIO_NONE) { |
|
pdr.
2014/11/12 00:48:25
Could we move the PAR_NONE check and the viewport
fs
2014/11/12 10:13:44
While it's possible to do that, you then get essen
| |
| 104 if (intrinsicSize != m_imageResource->imageSize(style()->effectiveZoom() )) { | 99 LayoutSize computedViewportSize = computeNonUniformScalingViewportSize() ; |
| 105 newViewportSize = roundedIntSize(intrinsicSize); | 100 if (computedViewportSize != m_imageResource->imageSize(style()->effectiv eZoom())) { |
| 101 newViewportSize = roundedIntSize(computedViewportSize); | |
| 106 updatedViewport = true; | 102 updatedViewport = true; |
| 107 } | 103 } |
| 108 } else if (boundsChanged) { | 104 } else if (boundsChanged) { |
| 109 newViewportSize = enclosingIntRect(m_objectBoundingBox).size(); | 105 newViewportSize = enclosingIntRect(m_objectBoundingBox).size(); |
| 110 updatedViewport = true; | 106 updatedViewport = true; |
| 111 } | 107 } |
| 112 if (updatedViewport) | 108 if (updatedViewport) |
| 113 m_imageResource->setContainerSizeForRenderer(newViewportSize); | 109 m_imageResource->setContainerSizeForRenderer(newViewportSize); |
| 114 m_needsBoundariesUpdate |= boundsChanged; | 110 m_needsBoundariesUpdate |= boundsChanged; |
| 115 return updatedViewport; | 111 return updatedViewport || boundsChanged; |
|
pdr.
2014/11/12 00:48:25
Does it make sense for the bounds to change but th
fs
2014/11/12 10:13:45
Yes, this would even be expected in the pAR=none c
| |
| 116 } | 112 } |
| 117 | 113 |
| 118 void RenderSVGImage::layout() | 114 void RenderSVGImage::layout() |
| 119 { | 115 { |
| 120 ASSERT(needsLayout()); | 116 ASSERT(needsLayout()); |
| 121 | 117 |
| 122 updateImageViewport(); | 118 updateImageViewport(); |
| 123 | 119 |
| 124 bool transformOrBoundariesUpdate = m_needsTransformUpdate || m_needsBoundari esUpdate; | 120 bool transformOrBoundariesUpdate = m_needsTransformUpdate || m_needsBoundari esUpdate; |
| 125 if (m_needsTransformUpdate) { | 121 if (m_needsTransformUpdate) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 | 194 |
| 199 void RenderSVGImage::addFocusRingRects(Vector<LayoutRect>& rects, const LayoutPo int&, const RenderLayerModelObject*) const | 195 void RenderSVGImage::addFocusRingRects(Vector<LayoutRect>& rects, const LayoutPo int&, const RenderLayerModelObject*) const |
| 200 { | 196 { |
| 201 // this is called from paint() after the localTransform has already been app lied | 197 // this is called from paint() after the localTransform has already been app lied |
| 202 LayoutRect contentRect = LayoutRect(paintInvalidationRectInLocalCoordinates( )); | 198 LayoutRect contentRect = LayoutRect(paintInvalidationRectInLocalCoordinates( )); |
| 203 if (!contentRect.isEmpty()) | 199 if (!contentRect.isEmpty()) |
| 204 rects.append(contentRect); | 200 rects.append(contentRect); |
| 205 } | 201 } |
| 206 | 202 |
| 207 } // namespace blink | 203 } // namespace blink |
| OLD | NEW |