Changeset 28637 in webkit
- Timestamp:
- Dec 11, 2007 7:23:35 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 30 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r28629 r28637 1 2007-12-11 Beth Dakin <bdakin@apple.com> 2 3 Reviewed by Darin. 4 5 Tests for <rdar://problem/5641255> SVGs with width and height 100% 6 fail to render when used as background images 7 8 * fast/backgrounds/resources/balloon.svg: Added. 9 * fast/backgrounds/resources/eyes.svg: Added. 10 * fast/backgrounds/resources/hearts.svg: Added. 11 * fast/backgrounds/resources/linguistics.svg: Added. 12 * fast/backgrounds/resources/map.svg: Added. 13 * fast/backgrounds/resources/mouse-repel.svg: Added. 14 * fast/backgrounds/svg-as-background-1.html: Added. 15 * fast/backgrounds/svg-as-background-2.html: Added. 16 * fast/backgrounds/svg-as-background-3.html: Added. 17 * fast/backgrounds/svg-as-background-4.html: Added. 18 * fast/backgrounds/svg-as-background-5.html: Added. 19 * fast/backgrounds/svg-as-background-6.html: Added. 20 * platform/mac/fast/backgrounds/svg-as-background-1-expected.checksum: Added. 21 * platform/mac/fast/backgrounds/svg-as-background-1-expected.png: Added. 22 * platform/mac/fast/backgrounds/svg-as-background-1-expected.txt: Added. 23 * platform/mac/fast/backgrounds/svg-as-background-2-expected.checksum: Added. 24 * platform/mac/fast/backgrounds/svg-as-background-2-expected.png: Added. 25 * platform/mac/fast/backgrounds/svg-as-background-2-expected.txt: Added. 26 * platform/mac/fast/backgrounds/svg-as-background-3-expected.checksum: Added. 27 * platform/mac/fast/backgrounds/svg-as-background-3-expected.png: Added. 28 * platform/mac/fast/backgrounds/svg-as-background-3-expected.txt: Added. 29 * platform/mac/fast/backgrounds/svg-as-background-4-expected.checksum: Added. 30 * platform/mac/fast/backgrounds/svg-as-background-4-expected.png: Added. 31 * platform/mac/fast/backgrounds/svg-as-background-4-expected.txt: Added. 32 * platform/mac/fast/backgrounds/svg-as-background-5-expected.checksum: Added. 33 * platform/mac/fast/backgrounds/svg-as-background-5-expected.png: Added. 34 * platform/mac/fast/backgrounds/svg-as-background-5-expected.txt: Added. 35 * platform/mac/fast/backgrounds/svg-as-background-6-expected.checksum: Added. 36 * platform/mac/fast/backgrounds/svg-as-background-6-expected.png: Added. 37 * platform/mac/fast/backgrounds/svg-as-background-6-expected.txt: Added. 38 1 39 2007-12-11 Nikolas Zimmermann <zimmermann@kde.org> 2 40 -
trunk/WebCore/ChangeLog
r28631 r28637 1 2007-12-11 Beth Dakin <bdakin@apple.com> 2 3 Reviewed by Darin. 4 5 Fix for <rdar://problem/5641255> SVGs with width and height 100% 6 fail to render when used as background images 7 8 CachedImage now has a setImageContainerSize function. It is only 9 needed for SVG right now. 10 * loader/CachedImage.cpp: 11 (WebCore::CachedImage::setImageContainerSize): 12 * loader/CachedImage.h: 13 14 Relatively sized SVGs have no intrinsic size. Because this call is 15 low-level enough that we cannot pass in the container size and get 16 the real size of the SVG, we need to know if it has relative 17 dimensions, and if so, we need to get the size from scaledTileSize. 18 * platform/graphics/Image.cpp: 19 (WebCore::Image::drawTiled): 20 * platform/graphics/Image.h: 21 (WebCore::Image::setContainerSize): 22 (WebCore::Image::hasRelativeWidth): 23 (WebCore::Image::hasRelativeHeight): 24 25 Re-factored calculateBackgroundSize a bit so that it returns an 26 IntSize. Made it a member function so that it can send m_width and 27 m_height along to setImageContainerSize. 28 * rendering/RenderBox.cpp: 29 (WebCore::RenderBox::calculateBackgroundSize): 30 (WebCore::RenderBox::calculateBackgroundImageGeometry): 31 * rendering/RenderBox.h: 32 33 Need to account for relatively sized SVGs in calcViewport() 34 * rendering/RenderSVGRoot.cpp: 35 (WebCore::RenderSVGRoot::calcViewport): 36 37 Added new member variables to store the size of the SVG container. 38 relativeWidthValue() and relativeHeightValue() use the stored SVG 39 container size to correctly calculate the width and height of a 40 relatively sized SVG. 41 * svg/SVGSVGElement.cpp: 42 (WebCore::SVGSVGElement::SVGSVGElement): 43 (WebCore::SVGSVGElement::setContainerSize): 44 (WebCore::SVGSVGElement::relativeWidthValue): 45 (WebCore::SVGSVGElement::relativeHeightValue): 46 * svg/SVGSVGElement.h: 47 (WebCore::SVGSVGElement::containerSize): 48 49 Re-factored size calculations to use the size of the container. 50 * svg/graphics/SVGImage.cpp: 51 (WebCore::SVGImage::setContainerSize): 52 (WebCore::SVGImage::size): 53 (WebCore::SVGImage::hasRelativeWidth): 54 (WebCore::SVGImage::hasRelativeHeight): 55 * svg/graphics/SVGImage.h: 56 1 57 2007-12-11 Darin Adler <darin@apple.com> 2 58 -
trunk/WebCore/loader/CachedImage.cpp
r28568 r28637 112 112 113 113 return nullImage(); 114 } 115 116 void CachedImage::setImageContainerSize(const IntSize& containerSize) 117 { 118 if (m_image) 119 m_image->setContainerSize(containerSize); 114 120 } 115 121 -
trunk/WebCore/loader/CachedImage.h
r25754 r28637 47 47 bool canRender() const { return !errorOccurred() && imageSize().width() > 0 && imageSize().height() > 0; } 48 48 49 void setImageContainerSize(const IntSize&); 50 49 51 IntSize imageSize() const; // returns the size of the complete image 50 52 IntRect imageRect() const; // The size of the image. -
trunk/WebCore/platform/graphics/Image.cpp
r27060 r28637 128 128 129 129 FloatSize intrinsicTileSize = size(); 130 if (hasRelativeWidth()) 131 intrinsicTileSize.setWidth(scaledTileSize.width()); 132 if (hasRelativeHeight()) 133 intrinsicTileSize.setHeight(scaledTileSize.height()); 134 130 135 FloatSize scale(scaledTileSize.width() / intrinsicTileSize.width(), 131 136 scaledTileSize.height() / intrinsicTileSize.height()); -
trunk/WebCore/platform/graphics/Image.h
r25674 r28637 81 81 bool isNull() const; 82 82 83 // These are ony used for SVGImage right now 84 virtual void setContainerSize(const IntSize&) { } 85 virtual bool hasRelativeWidth() const { return false; } 86 virtual bool hasRelativeHeight() const { return false; } 87 83 88 virtual IntSize size() const = 0; 84 89 IntRect rect() const; -
trunk/WebCore/rendering/RenderBox.cpp
r28299 r28637 418 418 } 419 419 420 static void cacluateBackgroundSize(const BackgroundLayer* bgLayer, int& scaledWidth, int& scaledHeight) 420 IntSize RenderBox::calculateBackgroundSize(const BackgroundLayer* bgLayer, int scaledWidth, int scaledHeight) const 421 421 { 422 422 CachedImage* bg = bgLayer->backgroundImage(); 423 423 424 424 if (bgLayer->isBackgroundSizeSet()) { 425 int w = scaledWidth; 426 int h = scaledHeight; 425 427 Length bgWidth = bgLayer->backgroundSize().width; 426 428 Length bgHeight = bgLayer->backgroundSize().height; 427 429 428 430 if (bgWidth.isPercent()) 429 scaledWidth= bgWidth.calcValue(scaledWidth);431 w = bgWidth.calcValue(scaledWidth); 430 432 else if (bgWidth.isFixed()) 431 scaledWidth= bgWidth.value();433 w = bgWidth.value(); 432 434 else if (bgWidth.isAuto()) { 433 435 // If the width is auto and the height is not, we have to use the appropriate … … 435 437 if (bgHeight.isPercent()) { 436 438 int scaledH = bgHeight.calcValue(scaledHeight); 437 scaledWidth= bg->imageSize().width() * scaledH / bg->imageSize().height();439 w = bg->imageSize().width() * scaledH / bg->imageSize().height(); 438 440 } else if (bgHeight.isFixed()) 439 scaledWidth= bg->imageSize().width() * bgHeight.value() / bg->imageSize().height();441 w = bg->imageSize().width() * bgHeight.value() / bg->imageSize().height(); 440 442 } 441 443 442 444 if (bgHeight.isPercent()) 443 scaledHeight= bgHeight.calcValue(scaledHeight);445 h = bgHeight.calcValue(scaledHeight); 444 446 else if (bgHeight.isFixed()) 445 scaledHeight= bgHeight.value();447 h = bgHeight.value(); 446 448 else if (bgHeight.isAuto()) { 447 449 // If the height is auto and the width is not, we have to use the appropriate 448 450 // scale to maintain our aspect ratio. 449 451 if (bgWidth.isPercent()) 450 scaledHeight= bg->imageSize().height() * scaledWidth / bg->imageSize().width();452 h = bg->imageSize().height() * scaledWidth / bg->imageSize().width(); 451 453 else if (bgWidth.isFixed()) 452 scaledHeight= bg->imageSize().height() * bgWidth.value() / bg->imageSize().width();454 h = bg->imageSize().height() * bgWidth.value() / bg->imageSize().width(); 453 455 else if (bgWidth.isAuto()) { 454 456 // If both width and height are auto, we just want to use the image's 455 457 // intrinsic size. 456 scaledWidth= bg->imageSize().width();457 scaledHeight= bg->imageSize().height();458 w = bg->imageSize().width(); 459 h = bg->imageSize().height(); 458 460 } 459 461 } 460 scaledWidth = max(1, scaledWidth); 461 scaledHeight = max(1, scaledHeight); 462 return IntSize(max(1, w), max(1, h)); 462 463 } else { 463 scaledWidth = bg->imageSize().width();464 scaledHeight = bg->imageSize().height();464 bg->setImageContainerSize(IntSize(m_width, m_height)); 465 return bg->imageSize(); 465 466 } 466 467 } … … 562 563 int cw; 563 564 int ch; 564 int scaledImageWidth = pw; 565 int scaledImageHeight = ph;566 567 cacluateBackgroundSize(bgLayer, scaledImageWidth, scaledImageHeight);565 566 IntSize scaledImageSize = calculateBackgroundSize(bgLayer, pw, ph); 567 int scaledImageWidth = scaledImageSize.width(); 568 int scaledImageHeight = scaledImageSize.height(); 568 569 569 570 EBackgroundRepeat backgroundRepeat = bgLayer->backgroundRepeat(); -
trunk/WebCore/rendering/RenderBox.h
r28226 r28637 144 144 virtual void paintBackgroundExtended(GraphicsContext*, const Color&, const BackgroundLayer*, int clipY, int clipHeight, 145 145 int tx, int ty, int width, int height, bool includeLeftEdge = true, bool includeRightEdge = true); 146 IntSize calculateBackgroundSize(const BackgroundLayer*, int scaledWidth, int scaledHeight) const; 146 147 147 148 virtual int staticX() const; -
trunk/WebCore/rendering/RenderSVGRoot.cpp
r28568 r28637 136 136 return; 137 137 138 // Be sure that our viewport size, didn't depend on ourselves! 139 // If that is true, we have a null viewport() here, and need to recalculate. 140 if (viewport().isEmpty()) 141 calcViewport(); 138 calcViewport(); 142 139 143 140 SVGSVGElement* svg = static_cast<SVGSVGElement*>(element()); … … 198 195 return; 199 196 200 float w = svg->width().value(); 201 float h = svg->height().value(); 197 float w, h; 198 SVGLength width = svg->width(); 199 if (width.unitType() == LengthTypePercentage && svg->relativeWidthValue() > 0) 200 w = svg->relativeWidthValue(); 201 else 202 w = width.value(); 203 204 SVGLength height = svg->height(); 205 if (height.unitType() == LengthTypePercentage && svg->relativeHeightValue() > 0) 206 h = svg->relativeHeightValue(); 207 else 208 h = height.value(); 209 202 210 m_viewport = FloatRect(0, 0, w, h); 203 211 } -
trunk/WebCore/svg/SVGSVGElement.cpp
r26571 r28637 72 72 , m_timeScheduler(new TimeScheduler(doc)) 73 73 , m_viewSpec(0) 74 , m_containerSize(300, 150) 74 75 { 75 76 setWidthBaseValue(SVGLength(this, LengthModeWidth, "100%")); … … 132 133 viewBox.map(w, h, &wDouble, &hDouble); 133 134 return FloatRect::narrowPrecision(_x, _y, wDouble, hDouble); 135 } 136 137 int SVGSVGElement::relativeWidthValue() const 138 { 139 SVGLength w = width(); 140 if (w.unitType() != LengthTypePercentage) 141 return 0; 142 143 return static_cast<int>(w.valueAsPercentage() * m_containerSize.width()); 144 } 145 146 int SVGSVGElement::relativeHeightValue() const 147 { 148 SVGLength h = height(); 149 if (h.unitType() != LengthTypePercentage) 150 return 0; 151 152 return static_cast<int>(h.valueAsPercentage() * m_containerSize.height()); 134 153 } 135 154 -
trunk/WebCore/svg/SVGSVGElement.h
r26571 r28637 26 26 #if ENABLE(SVG) 27 27 28 #include "IntSize.h" 28 29 #include "SVGExternalResourcesRequired.h" 29 30 #include "SVGFitToViewBox.h" … … 64 65 65 66 FloatRect viewport() const; 67 68 void setContainerSize(const IntSize& containerSize) { m_containerSize = containerSize; } 69 IntSize containerSize() const { return m_containerSize; } 70 int relativeWidthValue() const; 71 int relativeHeightValue() const; 66 72 67 73 float pixelUnitToMillimeterX() const; … … 154 160 FloatPoint m_translation; 155 161 mutable OwnPtr<SVGViewSpec> m_viewSpec; 162 IntSize m_containerSize; 156 163 }; 157 164 -
trunk/WebCore/svg/graphics/SVGImage.cpp
r28319 r28637 65 65 } 66 66 67 void SVGImage::setContainerSize(const IntSize& containerSize) 68 { 69 if (containerSize.width() <= 0 || containerSize.height() <= 0) 70 return; 71 72 SVGSVGElement* rootElement = static_cast<SVGDocument*>(m_frame->document())->rootElement(); 73 if (!rootElement) 74 return; 75 76 rootElement->setContainerSize(containerSize); 77 } 78 67 79 IntSize SVGImage::size() const 68 80 { 69 IntSize defaultSize(300, 150);70 // FIXME: Eventually we'll be passed in the dest size and can scale against that71 IntSize destSize = defaultSize;72 73 81 if (!m_frame || !m_frame->document()) 74 82 return IntSize(); … … 76 84 SVGSVGElement* rootElement = static_cast<SVGDocument*>(m_frame->document())->rootElement(); 77 85 if (!rootElement) 78 return defaultSize;86 return IntSize(); 79 87 80 88 SVGLength width = rootElement->width(); … … 82 90 83 91 IntSize svgSize; 84 if (width.unitType() == LengthTypePercentage) 85 svgSize.setWidth( static_cast<int>(width.valueAsPercentage() * destSize.width()));92 if (width.unitType() == LengthTypePercentage) 93 svgSize.setWidth(rootElement->relativeWidthValue()); 86 94 else 87 95 svgSize.setWidth(static_cast<int>(width.value())); 88 if (height.unitType() == LengthTypePercentage) 89 svgSize.setHeight(static_cast<int>(height.valueAsPercentage() * destSize.height())); 96 97 if (height.unitType() == LengthTypePercentage) 98 svgSize.setHeight(rootElement->relativeHeightValue()); 90 99 else 91 100 svgSize.setHeight(static_cast<int>(height.value())); 92 101 93 102 return svgSize; 103 } 104 105 bool SVGImage::hasRelativeWidth() const 106 { 107 SVGSVGElement* rootElement = static_cast<SVGDocument*>(m_frame->document())->rootElement(); 108 if (!rootElement) 109 return false; 110 111 return rootElement->width().unitType() == LengthTypePercentage; 112 } 113 114 bool SVGImage::hasRelativeHeight() const 115 { 116 SVGSVGElement* rootElement = static_cast<SVGDocument*>(m_frame->document())->rootElement(); 117 if (!rootElement) 118 return false; 119 120 return rootElement->height().unitType() == LengthTypePercentage; 94 121 } 95 122 -
trunk/WebCore/svg/graphics/SVGImage.h
r28319 r28637 45 45 SVGImage(ImageObserver*); 46 46 ~SVGImage(); 47 47 48 virtual void setContainerSize(const IntSize&); 49 virtual bool hasRelativeWidth() const; 50 virtual bool hasRelativeHeight() const; 51 48 52 virtual IntSize size() const; 49 53
Note: See TracChangeset
for help on using the changeset viewer.