summaryrefslogtreecommitdiffstats
path: root/WebCore/svg/graphics/SVGImage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/svg/graphics/SVGImage.cpp')
-rw-r--r--WebCore/svg/graphics/SVGImage.cpp66
1 files changed, 43 insertions, 23 deletions
diff --git a/WebCore/svg/graphics/SVGImage.cpp b/WebCore/svg/graphics/SVGImage.cpp
index 348df4f..6608c9e 100644
--- a/WebCore/svg/graphics/SVGImage.cpp
+++ b/WebCore/svg/graphics/SVGImage.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006 Eric Seidel (eric@webkit.org)
+ * Copyright (C) 2006 Eric Seidel <eric@webkit.org>
* Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -11,10 +11,10 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
@@ -70,7 +70,7 @@ private:
m_image = 0;
}
- virtual void repaint(const IntRect& r, bool, bool, bool)
+ virtual void invalidateContentsAndWindow(const IntRect& r, bool)
{
if (m_image && m_image->imageObserver())
m_image->imageObserver()->changedInRect(m_image, r);
@@ -186,13 +186,22 @@ void SVGImage::draw(GraphicsContext* context, const FloatRect& dstRect, const Fl
context->clip(enclosingIntRect(dstRect));
if (compositeOp != CompositeSourceOver)
context->beginTransparencyLayer(1);
- context->translate(dstRect.location().x(), dstRect.location().y());
- context->scale(FloatSize(dstRect.width() / srcRect.width(), dstRect.height() / srcRect.height()));
+
+ FloatSize scale(dstRect.width() / srcRect.width(), dstRect.height() / srcRect.height());
+
+ // We can only draw the entire frame, clipped to the rect we want. So compute where the top left
+ // of the image would be if we were drawing without clipping, and translate accordingly.
+ FloatSize topLeftOffset(srcRect.location().x() * scale.width(), srcRect.location().y() * scale.height());
+ FloatPoint destOffset = dstRect.location() - topLeftOffset;
+
+ context->translate(destOffset.x(), destOffset.y());
+ context->scale(scale);
view->resize(size());
if (view->needsLayout())
view->layout();
+
view->paint(context, IntRect(0, 0, view->width(), view->height()));
if (compositeOp != CompositeSourceOver)
@@ -212,12 +221,13 @@ NativeImagePtr SVGImage::nativeImageForCurrentFrame()
if (!m_frameCache) {
if (!m_page)
return 0;
- m_frameCache = ImageBuffer::create(size());
- if (!m_frameCache) // failed to allocate image
+ OwnPtr<ImageBuffer> buffer = ImageBuffer::create(size());
+ if (!buffer) // failed to allocate image
return 0;
- renderSubtreeToImage(m_frameCache.get(), m_page->mainFrame()->contentRenderer());
+ draw(buffer->context(), rect(), rect(), DeviceColorSpace, CompositeSourceOver);
+ m_frameCache = buffer->copyImage();
}
- return m_frameCache->image()->nativeImageForCurrentFrame();
+ return m_frameCache->nativeImageForCurrentFrame();
}
bool SVGImage::dataChanged(bool allDataReceived)
@@ -228,25 +238,34 @@ bool SVGImage::dataChanged(bool allDataReceived)
if (allDataReceived) {
static FrameLoaderClient* dummyFrameLoaderClient = new EmptyFrameLoaderClient;
- static EditorClient* dummyEditorClient = new EmptyEditorClient;
+
+ Page::PageClients pageClients;
+ m_chromeClient.set(new SVGImageChromeClient(this));
+ pageClients.chromeClient = m_chromeClient.get();
#if ENABLE(CONTEXT_MENUS)
static ContextMenuClient* dummyContextMenuClient = new EmptyContextMenuClient;
-#else
- static ContextMenuClient* dummyContextMenuClient = 0;
+ pageClients.contextMenuClient = dummyContextMenuClient;
#endif
+ static EditorClient* dummyEditorClient = new EmptyEditorClient;
+ pageClients.editorClient = dummyEditorClient;
#if ENABLE(DRAG_SUPPORT)
static DragClient* dummyDragClient = new EmptyDragClient;
-#else
- static DragClient* dummyDragClient = 0;
+ pageClients.dragClient = dummyDragClient;
#endif
static InspectorClient* dummyInspectorClient = new EmptyInspectorClient;
+ pageClients.inspectorClient = dummyInspectorClient;
+#if ENABLE(DEVICE_ORIENTATION)
+ static DeviceMotionClient* dummyDeviceMotionClient = new EmptyDeviceMotionClient;
+ pageClients.deviceMotionClient = dummyDeviceMotionClient;
+ static DeviceOrientationClient* dummyDeviceOrientationClient = new EmptyDeviceOrientationClient;
+ pageClients.deviceOrientationClient = dummyDeviceOrientationClient;
+#endif
- m_chromeClient.set(new SVGImageChromeClient(this));
-
// FIXME: If this SVG ends up loading itself, we might leak the world.
// The comment said that the Cache code does not know about CachedImages
// holding Frames and won't know to break the cycle. But
- m_page.set(new Page(m_chromeClient.get(), dummyContextMenuClient, dummyEditorClient, dummyDragClient, dummyInspectorClient, 0, 0));
+ m_page.set(new Page(pageClients));
+ m_page->settings()->setMediaEnabled(false);
m_page->settings()->setJavaScriptEnabled(false);
m_page->settings()->setPluginsEnabled(false);
@@ -255,13 +274,14 @@ bool SVGImage::dataChanged(bool allDataReceived)
frame->init();
ResourceRequest fakeRequest(KURL(ParsedURLString, ""));
FrameLoader* loader = frame->loader();
+ loader->setForcedSandboxFlags(SandboxAll);
loader->load(fakeRequest, false); // Make sure the DocumentLoader is created
loader->policyChecker()->cancelCheck(); // cancel any policy checks
- loader->commitProvisionalLoad(0);
- loader->setResponseMIMEType("image/svg+xml");
- loader->begin(KURL()); // create the empty document
- loader->write(data()->data(), data()->size());
- loader->end();
+ loader->commitProvisionalLoad();
+ loader->writer()->setMIMEType("image/svg+xml");
+ loader->writer()->begin(KURL()); // create the empty document
+ loader->writer()->addData(data()->data(), data()->size());
+ loader->writer()->end();
frame->view()->setTransparent(true); // SVG Images are transparent.
}