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 19 matching lines...) Expand all Loading... | |
| 30 #include "core/rendering/GraphicsContextAnnotator.h" | 30 #include "core/rendering/GraphicsContextAnnotator.h" |
| 31 #include "core/rendering/ImageQualityController.h" | 31 #include "core/rendering/ImageQualityController.h" |
| 32 #include "core/rendering/PointerEventsHitRules.h" | 32 #include "core/rendering/PointerEventsHitRules.h" |
| 33 #include "core/rendering/RenderImageResource.h" | 33 #include "core/rendering/RenderImageResource.h" |
| 34 #include "core/rendering/svg/RenderSVGResource.h" | 34 #include "core/rendering/svg/RenderSVGResource.h" |
| 35 #include "core/rendering/svg/SVGRenderSupport.h" | 35 #include "core/rendering/svg/SVGRenderSupport.h" |
| 36 #include "core/rendering/svg/SVGRenderingContext.h" | 36 #include "core/rendering/svg/SVGRenderingContext.h" |
| 37 #include "core/rendering/svg/SVGResources.h" | 37 #include "core/rendering/svg/SVGResources.h" |
| 38 #include "core/rendering/svg/SVGResourcesCache.h" | 38 #include "core/rendering/svg/SVGResourcesCache.h" |
| 39 #include "core/svg/SVGImageElement.h" | 39 #include "core/svg/SVGImageElement.h" |
| 40 #include "platform/LengthFunctions.h" | |
| 40 #include "platform/graphics/GraphicsContextStateSaver.h" | 41 #include "platform/graphics/GraphicsContextStateSaver.h" |
| 41 | 42 |
| 42 namespace blink { | 43 namespace blink { |
| 43 | 44 |
| 44 RenderSVGImage::RenderSVGImage(SVGImageElement* impl) | 45 RenderSVGImage::RenderSVGImage(SVGImageElement* impl) |
| 45 : RenderSVGModelObject(impl) | 46 : RenderSVGModelObject(impl) |
| 46 , m_needsBoundariesUpdate(true) | 47 , m_needsBoundariesUpdate(true) |
| 47 , m_needsTransformUpdate(true) | 48 , m_needsTransformUpdate(true) |
| 48 , m_imageResource(RenderImageResource::create()) | 49 , m_imageResource(RenderImageResource::create()) |
| 49 { | 50 { |
| 50 m_imageResource->initialize(this); | 51 m_imageResource->initialize(this); |
| 51 } | 52 } |
| 52 | 53 |
| 53 RenderSVGImage::~RenderSVGImage() | 54 RenderSVGImage::~RenderSVGImage() |
| 54 { | 55 { |
| 55 } | 56 } |
| 56 | 57 |
| 57 void RenderSVGImage::destroy() | 58 void RenderSVGImage::destroy() |
| 58 { | 59 { |
| 59 ImageQualityController::remove(this); | 60 ImageQualityController::remove(this); |
| 60 m_imageResource->shutdown(); | 61 m_imageResource->shutdown(); |
| 61 RenderSVGModelObject::destroy(); | 62 RenderSVGModelObject::destroy(); |
| 62 } | 63 } |
| 63 | 64 |
| 65 static bool hasIntrinsicSize(ImageResource* imageResource) | |
| 66 { | |
| 67 if (!imageResource) | |
| 68 return false; | |
| 69 Length intrinsicWidth; | |
| 70 Length intrinsicHeight; | |
| 71 FloatSize intrinsicRatio; | |
| 72 imageResource->computeIntrinsicDimensions(intrinsicWidth, intrinsicHeight, i ntrinsicRatio); | |
| 73 if (!intrinsicWidth.isFixed() || !intrinsicHeight.isFixed()) | |
| 74 return false; | |
| 75 if (!floatValueForLength(intrinsicWidth, 0) || !floatValueForLength(intrinsi cHeight, 0)) | |
|
pdr.
2014/09/10 03:21:48
Are these checks correct when the user does want a
fs
2014/09/10 09:31:00
This could be considered a "counter-weight" to how
| |
| 76 return false; | |
| 77 return true; | |
| 78 } | |
| 79 | |
| 64 bool RenderSVGImage::updateImageViewport() | 80 bool RenderSVGImage::updateImageViewport() |
| 65 { | 81 { |
| 66 SVGImageElement* image = toSVGImageElement(element()); | 82 SVGImageElement* image = toSVGImageElement(element()); |
| 67 FloatRect oldBoundaries = m_objectBoundingBox; | 83 FloatRect oldBoundaries = m_objectBoundingBox; |
| 68 bool updatedViewport = false; | 84 bool updatedViewport = false; |
| 69 | 85 |
| 70 SVGLengthContext lengthContext(image); | 86 SVGLengthContext lengthContext(image); |
| 71 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)); | 87 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)); |
| 72 | 88 |
| 73 bool boundsChanged = oldBoundaries != m_objectBoundingBox; | 89 bool boundsChanged = oldBoundaries != m_objectBoundingBox; |
| 74 | 90 |
| 75 // Images with preserveAspectRatio=none should force non-uniform scaling. Th is can be achieved | 91 // Images with preserveAspectRatio=none should force non-uniform |
| 76 // by setting the image's container size to its intrinsic size. | 92 // scaling. This can be achieved by setting the image's container size to |
| 93 // its intrinsic size. If the image does not have an intrinsic size, set | |
| 94 // the container size to the bounds as in pAR!=none cases. | |
| 77 // See: http://www.w3.org/TR/SVG/single-page.html, 7.8 The ‘preserveAspectRa tio’ attribute. | 95 // See: http://www.w3.org/TR/SVG/single-page.html, 7.8 The ‘preserveAspectRa tio’ attribute. |
| 78 IntSize newViewportSize; | 96 IntSize newViewportSize; |
| 79 if (image->preserveAspectRatio()->currentValue()->align() == SVGPreserveAspe ctRatio::SVG_PRESERVEASPECTRATIO_NONE) { | 97 if (image->preserveAspectRatio()->currentValue()->align() == SVGPreserveAspe ctRatio::SVG_PRESERVEASPECTRATIO_NONE |
|
pdr.
2014/09/10 03:21:48
The code change here looks good but I think we can
fs
2014/09/10 09:31:00
Certainly looks better. Done.
| |
| 98 && hasIntrinsicSize(m_imageResource->cachedImage())) { | |
| 80 LayoutSize intrinsicSize = m_imageResource->intrinsicSize(style()->effec tiveZoom()); | 99 LayoutSize intrinsicSize = m_imageResource->intrinsicSize(style()->effec tiveZoom()); |
| 81 if (intrinsicSize != m_imageResource->imageSize(style()->effectiveZoom() )) { | 100 if (intrinsicSize != m_imageResource->imageSize(style()->effectiveZoom() )) { |
| 82 newViewportSize = roundedIntSize(intrinsicSize); | 101 newViewportSize = roundedIntSize(intrinsicSize); |
| 83 updatedViewport = true; | 102 updatedViewport = true; |
| 84 } | 103 } |
| 85 } else if (boundsChanged) { | 104 } else if (boundsChanged) { |
| 86 newViewportSize = enclosingIntRect(m_objectBoundingBox).size(); | 105 newViewportSize = enclosingIntRect(m_objectBoundingBox).size(); |
| 87 updatedViewport = true; | 106 updatedViewport = true; |
| 88 } | 107 } |
| 89 if (updatedViewport) | 108 if (updatedViewport) |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 | 248 |
| 230 void RenderSVGImage::addFocusRingRects(Vector<IntRect>& rects, const LayoutPoint &, const RenderLayerModelObject*) const | 249 void RenderSVGImage::addFocusRingRects(Vector<IntRect>& rects, const LayoutPoint &, const RenderLayerModelObject*) const |
| 231 { | 250 { |
| 232 // this is called from paint() after the localTransform has already been app lied | 251 // this is called from paint() after the localTransform has already been app lied |
| 233 IntRect contentRect = enclosingIntRect(paintInvalidationRectInLocalCoordinat es()); | 252 IntRect contentRect = enclosingIntRect(paintInvalidationRectInLocalCoordinat es()); |
| 234 if (!contentRect.isEmpty()) | 253 if (!contentRect.isEmpty()) |
| 235 rects.append(contentRect); | 254 rects.append(contentRect); |
| 236 } | 255 } |
| 237 | 256 |
| 238 } // namespace blink | 257 } // namespace blink |
| OLD | NEW |