Diff
Modified: trunk/Source/WebCore/ChangeLog (97726 => 97727)
--- trunk/Source/WebCore/ChangeLog 2011-10-18 08:04:38 UTC (rev 97726)
+++ trunk/Source/WebCore/ChangeLog 2011-10-18 08:39:18 UTC (rev 97727)
@@ -1,3 +1,44 @@
+2011-10-18 Nikolas Zimmermann <[email protected]>
+
+ Prepare SVGImage intrinsic size negotiation: Add intrinsic size & ratio calculation functionality to Image
+ https://bugs.webkit.org/show_bug.cgi?id=70314
+
+ Reviewed by Antti Koivisto.
+
+ Add a "void computeIntrinsicDimension(Length& intrinsicWidth, Lengt& intrinsicHeight, FloatSize& intrinsicRatio)" helper method
+ to Image/GeneratedImage/SVGImage and make it accessible through StyleImage.
+
+ For a regular Image the intrinsicWidth/Height contains just a Length(size().width(), Fixed). In contrary SVGImages pass on the
+ style()->width()/height() values from the render style of the RenderSVGRoot renderer. These information are needed to implement
+ the size negotiation between embedded SVG images and the embedder.
+
+ No new tests, as this new functionality is not yet used.
+
+ * loader/cache/CachedImage.cpp:
+ (WebCore::CachedImage::computeIntrinsicDimensions):
+ * loader/cache/CachedImage.h:
+ * platform/graphics/GeneratedImage.cpp:
+ (WebCore::GeneratedImage::computeIntrinsicDimensions):
+ * platform/graphics/GeneratedImage.h:
+ * platform/graphics/Image.cpp:
+ (WebCore::Image::computeIntrinsicDimensions):
+ * platform/graphics/Image.h:
+ * platform/graphics/cg/PDFDocumentImage.cpp:
+ (WebCore::PDFDocumentImage::computeIntrinsicDimensions):
+ * platform/graphics/cg/PDFDocumentImage.h:
+ * rendering/style/StyleCachedImage.cpp:
+ (WebCore::StyleCachedImage::computeIntrinsicDimensions):
+ * rendering/style/StyleCachedImage.h:
+ * rendering/style/StyleGeneratedImage.cpp:
+ (WebCore::StyleGeneratedImage::computeIntrinsicDimensions):
+ * rendering/style/StyleGeneratedImage.h:
+ * rendering/style/StyleImage.h:
+ * rendering/style/StylePendingImage.h:
+ (WebCore::StylePendingImage::computeIntrinsicDimensions):
+ * svg/graphics/SVGImage.cpp:
+ (WebCore::SVGImage::computeIntrinsicDimensions):
+ * svg/graphics/SVGImage.h:
+
2011-10-17 Alexander Pavlov <[email protected]>
Web Inspector: [Chromium] Different dimensions are reported for elements onscreen and in the Metrics pane
Modified: trunk/Source/WebCore/loader/cache/CachedImage.cpp (97726 => 97727)
--- trunk/Source/WebCore/loader/cache/CachedImage.cpp 2011-10-18 08:04:38 UTC (rev 97726)
+++ trunk/Source/WebCore/loader/cache/CachedImage.cpp 2011-10-18 08:39:18 UTC (rev 97727)
@@ -241,6 +241,12 @@
return IntSize(width, height);
}
+void CachedImage::computeIntrinsicDimensions(const RenderObject* renderer, Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio)
+{
+ if (Image* image = lookupImageForRenderer(renderer))
+ image->computeIntrinsicDimensions(intrinsicWidth, intrinsicHeight, intrinsicRatio);
+}
+
void CachedImage::notifyObservers(const IntRect* changeRect)
{
CachedResourceClientWalker<CachedImageClient> w(m_clients);
Modified: trunk/Source/WebCore/loader/cache/CachedImage.h (97726 => 97727)
--- trunk/Source/WebCore/loader/cache/CachedImage.h 2011-10-18 08:04:38 UTC (rev 97726)
+++ trunk/Source/WebCore/loader/cache/CachedImage.h 2011-10-18 08:39:18 UTC (rev 97727)
@@ -34,6 +34,8 @@
namespace WebCore {
class CachedResourceLoader;
+class Length;
+class FloatSize;
class MemoryCache;
class RenderObject;
@@ -64,6 +66,7 @@
// This method takes a zoom multiplier that can be used to increase the natural size of the image by the zoom.
IntSize imageSizeForRenderer(const RenderObject*, float multiplier); // returns the size of the complete image.
+ void computeIntrinsicDimensions(const RenderObject*, Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio);
virtual void didAddClient(CachedResourceClient*);
Modified: trunk/Source/WebCore/platform/graphics/GeneratedImage.cpp (97726 => 97727)
--- trunk/Source/WebCore/platform/graphics/GeneratedImage.cpp 2011-10-18 08:04:38 UTC (rev 97726)
+++ trunk/Source/WebCore/platform/graphics/GeneratedImage.cpp 2011-10-18 08:39:18 UTC (rev 97727)
@@ -29,9 +29,8 @@
#include "FloatRect.h"
#include "GraphicsContext.h"
#include "ImageBuffer.h"
+#include "Length.h"
-using namespace std;
-
namespace WebCore {
void GeneratedImage::draw(GraphicsContext* context, const FloatRect& dstRect, const FloatRect& srcRect, ColorSpace, CompositeOperator compositeOp)
@@ -67,4 +66,10 @@
imageBuffer->drawPattern(context, adjustedSrcRect, patternTransform, phase, styleColorSpace, compositeOp, destRect);
}
+void GeneratedImage::computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio)
+{
+ Image::computeIntrinsicDimensions(intrinsicWidth, intrinsicHeight, intrinsicRatio);
+ intrinsicRatio = FloatSize();
}
+
+}
Modified: trunk/Source/WebCore/platform/graphics/GeneratedImage.h (97726 => 97727)
--- trunk/Source/WebCore/platform/graphics/GeneratedImage.h 2011-10-18 08:04:38 UTC (rev 97726)
+++ trunk/Source/WebCore/platform/graphics/GeneratedImage.h 2011-10-18 08:39:18 UTC (rev 97727)
@@ -44,11 +44,11 @@
virtual bool hasSingleSecurityOrigin() const { return true; }
- // These are only used for SVGGeneratedImage right now
virtual void setContainerSize(const IntSize& size) { m_size = size; }
virtual bool usesContainerSize() const { return true; }
virtual bool hasRelativeWidth() const { return true; }
virtual bool hasRelativeHeight() const { return true; }
+ virtual void computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio);
virtual IntSize size() const { return m_size; }
Modified: trunk/Source/WebCore/platform/graphics/Image.cpp (97726 => 97727)
--- trunk/Source/WebCore/platform/graphics/Image.cpp 2011-10-18 08:04:38 UTC (rev 97726)
+++ trunk/Source/WebCore/platform/graphics/Image.cpp 2011-10-18 08:39:18 UTC (rev 97727)
@@ -31,6 +31,7 @@
#include "BitmapImage.h"
#include "GraphicsContext.h"
#include "IntRect.h"
+#include "Length.h"
#include "MIMETypeRegistry.h"
#include "SharedBuffer.h"
#include <math.h>
@@ -166,5 +167,11 @@
startAnimation();
}
+void Image::computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio)
+{
+ intrinsicRatio = size();
+ intrinsicWidth = Length(intrinsicRatio.width(), Fixed);
+ intrinsicHeight = Length(intrinsicRatio.height(), Fixed);
+}
}
Modified: trunk/Source/WebCore/platform/graphics/Image.h (97726 => 97727)
--- trunk/Source/WebCore/platform/graphics/Image.h 2011-10-18 08:04:38 UTC (rev 97726)
+++ trunk/Source/WebCore/platform/graphics/Image.h 2011-10-18 08:39:18 UTC (rev 97727)
@@ -71,6 +71,7 @@
class FloatRect;
class FloatSize;
class GraphicsContext;
+class Length;
class SharedBuffer;
// This class gets notified when an image creates or destroys decoded frames and when it advances animation frames.
@@ -98,11 +99,11 @@
static Image* nullImage();
bool isNull() const { return size().isEmpty(); }
- // These are only used for SVGImage right now
virtual void setContainerSize(const IntSize&) { }
virtual bool usesContainerSize() const { return false; }
virtual bool hasRelativeWidth() const { return false; }
virtual bool hasRelativeHeight() const { return false; }
+ virtual void computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio);
virtual IntSize size() const = 0;
IntRect rect() const { return IntRect(IntPoint(), size()); }
Modified: trunk/Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp (97726 => 97727)
--- trunk/Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp 2011-10-18 08:04:38 UTC (rev 97726)
+++ trunk/Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp 2011-10-18 08:39:18 UTC (rev 97727)
@@ -31,6 +31,7 @@
#include "GraphicsContext.h"
#include "ImageObserver.h"
+#include "Length.h"
#include "SharedBuffer.h"
#include <CoreGraphics/CGContext.h>
#include <CoreGraphics/CGPDFDocument.h>
@@ -75,6 +76,13 @@
return IntSize((int)(fabsf(rotWidth) + 0.5f), (int)(fabsf(rotHeight) + 0.5f));
}
+void PDFDocumentImage::computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio)
+{
+ // FIXME: If we want size negotiation with PDF documents as-image, this is the place to implement it (https://bugs.webkit.org/show_bug.cgi?id=12095).
+ Image::computeIntrinsicDimensions(intrinsicWidth, intrinsicHeight, intrinsicRatio);
+ intrinsicRatio = FloatSize();
+}
+
bool PDFDocumentImage::dataChanged(bool allDataReceived)
{
if (allDataReceived && !m_document) {
Modified: trunk/Source/WebCore/platform/graphics/cg/PDFDocumentImage.h (97726 => 97727)
--- trunk/Source/WebCore/platform/graphics/cg/PDFDocumentImage.h 2011-10-18 08:04:38 UTC (rev 97726)
+++ trunk/Source/WebCore/platform/graphics/cg/PDFDocumentImage.h 2011-10-18 08:39:18 UTC (rev 97727)
@@ -59,6 +59,7 @@
virtual void destroyDecodedData(bool /*destroyAll*/ = true) { }
virtual unsigned decodedSize() const { return 0; }
+ virtual void computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio);
virtual IntSize size() const;
PDFDocumentImage();
Modified: trunk/Source/WebCore/rendering/style/StyleCachedImage.cpp (97726 => 97727)
--- trunk/Source/WebCore/rendering/style/StyleCachedImage.cpp 2011-10-18 08:04:38 UTC (rev 97726)
+++ trunk/Source/WebCore/rendering/style/StyleCachedImage.cpp 2011-10-18 08:39:18 UTC (rev 97727)
@@ -64,6 +64,11 @@
return m_image->imageHasRelativeHeight();
}
+void StyleCachedImage::computeIntrinsicDimensions(const RenderObject* renderer, Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio)
+{
+ m_image->computeIntrinsicDimensions(renderer, intrinsicWidth, intrinsicHeight, intrinsicRatio);
+}
+
bool StyleCachedImage::usesImageContainerSize() const
{
return m_image->usesImageContainerSize();
Modified: trunk/Source/WebCore/rendering/style/StyleCachedImage.h (97726 => 97727)
--- trunk/Source/WebCore/rendering/style/StyleCachedImage.h 2011-10-18 08:04:38 UTC (rev 97726)
+++ trunk/Source/WebCore/rendering/style/StyleCachedImage.h 2011-10-18 08:39:18 UTC (rev 97727)
@@ -46,6 +46,7 @@
virtual IntSize imageSize(const RenderObject*, float multiplier) const;
virtual bool imageHasRelativeWidth() const;
virtual bool imageHasRelativeHeight() const;
+ virtual void computeIntrinsicDimensions(const RenderObject*, Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio);
virtual bool usesImageContainerSize() const;
virtual void setContainerSizeForRenderer(const RenderObject*, const IntSize&);
virtual void addClient(RenderObject*);
Modified: trunk/Source/WebCore/rendering/style/StyleGeneratedImage.cpp (97726 => 97727)
--- trunk/Source/WebCore/rendering/style/StyleGeneratedImage.cpp 2011-10-18 08:04:38 UTC (rev 97726)
+++ trunk/Source/WebCore/rendering/style/StyleGeneratedImage.cpp 2011-10-18 08:39:18 UTC (rev 97727)
@@ -58,6 +58,14 @@
return m_containerSize;
}
+void StyleGeneratedImage::computeIntrinsicDimensions(const RenderObject* renderer, Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio)
+{
+ IntSize size = imageSize(renderer, 1);
+ intrinsicWidth = Length(size.width(), Fixed);
+ intrinsicHeight = Length(size.height(), Fixed);
+ intrinsicRatio = size;
+}
+
void StyleGeneratedImage::addClient(RenderObject* renderer)
{
m_generator->addClient(renderer, IntSize());
Modified: trunk/Source/WebCore/rendering/style/StyleGeneratedImage.h (97726 => 97727)
--- trunk/Source/WebCore/rendering/style/StyleGeneratedImage.h 2011-10-18 08:04:38 UTC (rev 97726)
+++ trunk/Source/WebCore/rendering/style/StyleGeneratedImage.h 2011-10-18 08:39:18 UTC (rev 97727)
@@ -45,6 +45,7 @@
virtual IntSize imageSize(const RenderObject*, float multiplier) const;
virtual bool imageHasRelativeWidth() const { return !m_fixedSize; }
virtual bool imageHasRelativeHeight() const { return !m_fixedSize; }
+ virtual void computeIntrinsicDimensions(const RenderObject*, Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio);
virtual bool usesImageContainerSize() const { return !m_fixedSize; }
virtual void setContainerSizeForRenderer(const RenderObject*, const IntSize& containerSize) { m_containerSize = containerSize; }
virtual void addClient(RenderObject*);
Modified: trunk/Source/WebCore/rendering/style/StyleImage.h (97726 => 97727)
--- trunk/Source/WebCore/rendering/style/StyleImage.h 2011-10-18 08:04:38 UTC (rev 97726)
+++ trunk/Source/WebCore/rendering/style/StyleImage.h 2011-10-18 08:39:18 UTC (rev 97727)
@@ -53,6 +53,7 @@
virtual bool isLoaded() const { return true; }
virtual bool errorOccurred() const { return false; }
virtual IntSize imageSize(const RenderObject*, float multiplier) const = 0;
+ virtual void computeIntrinsicDimensions(const RenderObject*, Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio) = 0;
virtual bool imageHasRelativeWidth() const = 0;
virtual bool imageHasRelativeHeight() const = 0;
virtual bool usesImageContainerSize() const = 0;
Modified: trunk/Source/WebCore/rendering/style/StylePendingImage.h (97726 => 97727)
--- trunk/Source/WebCore/rendering/style/StylePendingImage.h 2011-10-18 08:04:38 UTC (rev 97726)
+++ trunk/Source/WebCore/rendering/style/StylePendingImage.h 2011-10-18 08:39:18 UTC (rev 97727)
@@ -47,6 +47,7 @@
virtual IntSize imageSize(const RenderObject*, float /*multiplier*/) const { return IntSize(); }
virtual bool imageHasRelativeWidth() const { return false; }
virtual bool imageHasRelativeHeight() const { return false; }
+ virtual void computeIntrinsicDimensions(const RenderObject*, Length& /* intrinsicWidth */ , Length& /* intrinsicHeight */, FloatSize& /* intrinsicRatio */) { }
virtual bool usesImageContainerSize() const { return false; }
virtual void setContainerSizeForRenderer(const RenderObject*, const IntSize&) { }
virtual void addClient(RenderObject*) { }
Modified: trunk/Source/WebCore/svg/graphics/SVGImage.cpp (97726 => 97727)
--- trunk/Source/WebCore/svg/graphics/SVGImage.cpp 2011-10-18 08:04:38 UTC (rev 97726)
+++ trunk/Source/WebCore/svg/graphics/SVGImage.cpp 2011-10-18 08:39:18 UTC (rev 97727)
@@ -213,6 +213,24 @@
imageObserver()->didDraw(this);
}
+void SVGImage::computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio)
+{
+ if (!m_page)
+ return;
+ Frame* frame = m_page->mainFrame();
+ SVGSVGElement* rootElement = static_cast<SVGDocument*>(frame->document())->rootElement();
+ if (!rootElement)
+ return;
+ RenderBox* renderer = toRenderBox(rootElement->renderer());
+ if (!renderer)
+ return;
+
+ intrinsicWidth = renderer->style()->width();
+ intrinsicHeight = renderer->style()->height();
+ // FIXME: Add intrinsicRatio calculation from webkit.org/b/47156.
+ intrinsicRatio = FloatSize();
+}
+
NativeImagePtr SVGImage::nativeImageForCurrentFrame()
{
// FIXME: In order to support dynamic SVGs we need to have a way to invalidate this
Modified: trunk/Source/WebCore/svg/graphics/SVGImage.h (97726 => 97727)
--- trunk/Source/WebCore/svg/graphics/SVGImage.h 2011-10-18 08:04:38 UTC (rev 97726)
+++ trunk/Source/WebCore/svg/graphics/SVGImage.h 2011-10-18 08:39:18 UTC (rev 97727)
@@ -55,6 +55,7 @@
virtual bool usesContainerSize() const;
virtual bool hasRelativeWidth() const;
virtual bool hasRelativeHeight() const;
+ virtual void computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio);
virtual IntSize size() const;