| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 { | 56 { |
| 57 } | 57 } |
| 58 | 58 |
| 59 void LayoutSVGImage::willBeDestroyed() | 59 void LayoutSVGImage::willBeDestroyed() |
| 60 { | 60 { |
| 61 ImageQualityController::remove(this); | 61 ImageQualityController::remove(this); |
| 62 m_imageResource->shutdown(); | 62 m_imageResource->shutdown(); |
| 63 LayoutSVGModelObject::willBeDestroyed(); | 63 LayoutSVGModelObject::willBeDestroyed(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 FloatSize LayoutSVGImage::computeImageViewportSize(ImageResource& cachedImage) c
onst | |
| 67 { | |
| 68 if (toSVGImageElement(element())->preserveAspectRatio()->currentValue()->ali
gn() != SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_NONE) | |
| 69 return m_objectBoundingBox.size(); | |
| 70 | |
| 71 // Images with preserveAspectRatio=none should force non-uniform | |
| 72 // scaling. This can be achieved by setting the image's container size to | |
| 73 // its viewport size (i.e. if a viewBox is available - use that - else use i
ntrinsic size.) | |
| 74 // See: http://www.w3.org/TR/SVG/single-page.html, 7.8 The 'preserveAspectRa
tio' attribute. | |
| 75 Length intrinsicWidth; | |
| 76 Length intrinsicHeight; | |
| 77 FloatSize intrinsicRatio; | |
| 78 cachedImage.computeIntrinsicDimensions(intrinsicWidth, intrinsicHeight, intr
insicRatio); | |
| 79 return intrinsicRatio; | |
| 80 } | |
| 81 | |
| 82 static bool containerSizeIsSetForLayoutObject(ImageResource& cachedImage, const
LayoutObject* layoutObject) | |
| 83 { | |
| 84 const Image* image = cachedImage.image(); | |
| 85 // If a container size has been specified for this layoutObject, then | |
| 86 // imageForLayoutObject() will return the SVGImageForContainer while image() | |
| 87 // will return the underlying SVGImage. | |
| 88 return !image->isSVGImage() || image != cachedImage.imageForLayoutObject(lay
outObject); | |
| 89 } | |
| 90 | |
| 91 void LayoutSVGImage::updateImageContainerSize() | |
| 92 { | |
| 93 ImageResource* cachedImage = m_imageResource->cachedImage(); | |
| 94 if (!cachedImage || !cachedImage->usesImageContainerSize()) | |
| 95 return; | |
| 96 FloatSize imageViewportSize = computeImageViewportSize(*cachedImage); | |
| 97 if (LayoutSize(imageViewportSize) != m_imageResource->imageSize(styleRef().e
ffectiveZoom()) | |
| 98 || !containerSizeIsSetForLayoutObject(*cachedImage, this)) { | |
| 99 m_imageResource->setContainerSizeForLayoutObject(roundedIntSize(imageVie
wportSize)); | |
| 100 } | |
| 101 } | |
| 102 | |
| 103 void LayoutSVGImage::updateBoundingBox() | 66 void LayoutSVGImage::updateBoundingBox() |
| 104 { | 67 { |
| 105 FloatRect oldBoundaries = m_objectBoundingBox; | 68 FloatRect oldBoundaries = m_objectBoundingBox; |
| 106 | 69 |
| 107 SVGLengthContext lengthContext(element()); | 70 SVGLengthContext lengthContext(element()); |
| 108 m_objectBoundingBox = FloatRect( | 71 m_objectBoundingBox = FloatRect( |
| 109 lengthContext.valueForLength(styleRef().svgStyle().x(), styleRef(), SVGL
engthMode::Width), | 72 lengthContext.valueForLength(styleRef().svgStyle().x(), styleRef(), SVGL
engthMode::Width), |
| 110 lengthContext.valueForLength(styleRef().svgStyle().y(), styleRef(), SVGL
engthMode::Height), | 73 lengthContext.valueForLength(styleRef().svgStyle().y(), styleRef(), SVGL
engthMode::Height), |
| 111 lengthContext.valueForLength(styleRef().width(), styleRef(), SVGLengthMo
de::Width), | 74 lengthContext.valueForLength(styleRef().width(), styleRef(), SVGLengthMo
de::Width), |
| 112 lengthContext.valueForLength(styleRef().height(), styleRef(), SVGLengthM
ode::Height)); | 75 lengthContext.valueForLength(styleRef().height(), styleRef(), SVGLengthM
ode::Height)); |
| 113 m_needsBoundariesUpdate |= oldBoundaries != m_objectBoundingBox; | 76 m_needsBoundariesUpdate |= oldBoundaries != m_objectBoundingBox; |
| 114 } | 77 } |
| 115 | 78 |
| 116 void LayoutSVGImage::layout() | 79 void LayoutSVGImage::layout() |
| 117 { | 80 { |
| 118 ASSERT(needsLayout()); | 81 ASSERT(needsLayout()); |
| 119 LayoutAnalyzer::Scope analyzer(*this); | 82 LayoutAnalyzer::Scope analyzer(*this); |
| 120 | 83 |
| 121 updateBoundingBox(); | 84 updateBoundingBox(); |
| 122 updateImageContainerSize(); | |
| 123 | 85 |
| 124 bool transformOrBoundariesUpdate = m_needsTransformUpdate || m_needsBoundari
esUpdate; | 86 bool transformOrBoundariesUpdate = m_needsTransformUpdate || m_needsBoundari
esUpdate; |
| 125 if (m_needsTransformUpdate) { | 87 if (m_needsTransformUpdate) { |
| 126 m_localTransform = toSVGImageElement(element())->calculateAnimatedLocalT
ransform(); | 88 m_localTransform = toSVGImageElement(element())->calculateAnimatedLocalT
ransform(); |
| 127 m_needsTransformUpdate = false; | 89 m_needsTransformUpdate = false; |
| 128 } | 90 } |
| 129 | 91 |
| 130 if (m_needsBoundariesUpdate) { | 92 if (m_needsBoundariesUpdate) { |
| 131 m_bufferedForeground.clear(); | 93 m_bufferedForeground.clear(); |
| 132 | 94 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 return false; | 140 return false; |
| 179 } | 141 } |
| 180 | 142 |
| 181 void LayoutSVGImage::imageChanged(WrappedImagePtr, const IntRect*) | 143 void LayoutSVGImage::imageChanged(WrappedImagePtr, const IntRect*) |
| 182 { | 144 { |
| 183 // Notify parent resources that we've changed. This also invalidates | 145 // Notify parent resources that we've changed. This also invalidates |
| 184 // references from resources (filters) that may have a cached | 146 // references from resources (filters) that may have a cached |
| 185 // representation of this image/layout object. | 147 // representation of this image/layout object. |
| 186 LayoutSVGResourceContainer::markForLayoutAndParentResourceInvalidation(this,
false); | 148 LayoutSVGResourceContainer::markForLayoutAndParentResourceInvalidation(this,
false); |
| 187 | 149 |
| 188 // Update the SVGImageCache sizeAndScales entry in case image loading finish
ed after layout. | |
| 189 // (https://bugs.webkit.org/show_bug.cgi?id=99489) | |
| 190 updateImageContainerSize(); | |
| 191 | |
| 192 m_bufferedForeground.clear(); | 150 m_bufferedForeground.clear(); |
| 193 | 151 |
| 194 setShouldDoFullPaintInvalidation(); | 152 setShouldDoFullPaintInvalidation(); |
| 195 } | 153 } |
| 196 | 154 |
| 197 void LayoutSVGImage::addOutlineRects(Vector<LayoutRect>& rects, const LayoutPoin
t&, IncludeBlockVisualOverflowOrNot) const | 155 void LayoutSVGImage::addOutlineRects(Vector<LayoutRect>& rects, const LayoutPoin
t&, IncludeBlockVisualOverflowOrNot) const |
| 198 { | 156 { |
| 199 // this is called from paint() after the localTransform has already been app
lied | 157 // this is called from paint() after the localTransform has already been app
lied |
| 200 rects.append(LayoutRect(paintInvalidationRectInLocalCoordinates())); | 158 rects.append(LayoutRect(paintInvalidationRectInLocalCoordinates())); |
| 201 } | 159 } |
| 202 | 160 |
| 203 } // namespace blink | 161 } // namespace blink |
| OLD | NEW |