Modified: trunk/LayoutTests/svg/custom/anchor-on-use-expected.svg (168326 => 168327)
--- trunk/LayoutTests/svg/custom/anchor-on-use-expected.svg 2014-05-05 23:24:09 UTC (rev 168326)
+++ trunk/LayoutTests/svg/custom/anchor-on-use-expected.svg 2014-05-05 23:35:38 UTC (rev 168327)
@@ -1,4 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
- <image x="0" y="0" width="503" height="410" xlink:href=""
+ <image x="50%" y="0" transform="translate(-251,0)" width="503" height="410" xlink:href=""
</svg>
Modified: trunk/Source/WebCore/ChangeLog (168326 => 168327)
--- trunk/Source/WebCore/ChangeLog 2014-05-05 23:24:09 UTC (rev 168326)
+++ trunk/Source/WebCore/ChangeLog 2014-05-05 23:35:38 UTC (rev 168327)
@@ -1,3 +1,30 @@
+2014-05-05 Benjamin Poulain <benja...@webkit.org>
+
+ Clean up Image Document and tweak the layout and viewport
+ https://bugs.webkit.org/show_bug.cgi?id=132552
+
+ Reviewed by Sam Weinig.
+
+ The #ifdef in every function was making quite a mess. A lot of that code does
+ not make sense on iOS.
+
+ This patch make a clean split between mouse related stuff and iOS.
+
+ Also:
+ -Change the viewport to be only width based, and avoid scaling in portrait.
+ -Center the image horizontally in the view.
+
+ * html/ImageDocument.cpp:
+ (WebCore::ImageDocument::ImageDocument):
+ (WebCore::ImageDocument::createDocumentStructure):
+ (WebCore::ImageDocument::imageUpdated):
+ (WebCore::ImageDocument::scale):
+ (WebCore::ImageDocument::resizeImageToFit):
+ (WebCore::ImageDocument::imageFitsInWindow):
+ (WebCore::ImageDocument::windowSizeChanged):
+ (WebCore::ImageDocument::imageClicked):
+ * html/ImageDocument.h:
+
2014-05-05 Beth Dakin <bda...@apple.com>
Need a delegate that informs the UI process when the page's pin state changes
Modified: trunk/Source/WebCore/html/ImageDocument.cpp (168326 => 168327)
--- trunk/Source/WebCore/html/ImageDocument.cpp 2014-05-05 23:24:09 UTC (rev 168326)
+++ trunk/Source/WebCore/html/ImageDocument.cpp 2014-05-05 23:35:38 UTC (rev 168327)
@@ -26,6 +26,7 @@
#include "ImageDocument.h"
#include "CachedImage.h"
+#include "Chrome.h"
#include "DocumentLoader.h"
#include "EventListener.h"
#include "EventNames.h"
@@ -50,6 +51,7 @@
using namespace HTMLNames;
+#if !PLATFORM(IOS)
class ImageEventListener final : public EventListener {
public:
static PassRefPtr<ImageEventListener> create(ImageDocument& document) { return adoptRef(new ImageEventListener(document)); }
@@ -66,7 +68,8 @@
ImageDocument& m_document;
};
-
+#endif
+
class ImageDocumentParser final : public RawDataDocumentParser {
public:
static PassRefPtr<ImageDocumentParser> create(ImageDocument& document)
@@ -191,7 +194,9 @@
: HTMLDocument(&frame, url, ImageDocumentClass)
, m_imageElement(nullptr)
, m_imageSizeIsKnown(false)
+#if !PLATFORM(IOS)
, m_didShrinkImage(false)
+#endif
, m_shouldShrinkImage(frame.settings().shrinksStandaloneImagesToFit() && frame.isMainFrame())
{
setCompatibilityMode(QuirksMode);
@@ -216,32 +221,57 @@
rootElement->appendChild(body);
RefPtr<ImageDocumentElement> imageElement = ImageDocumentElement::create(*this);
- imageElement->setAttribute(styleAttr, "-webkit-user-select: none");
+ if (m_shouldShrinkImage)
+ imageElement->setAttribute(styleAttr, "-webkit-user-select:none; display:block; margin:auto;");
+ else
+ imageElement->setAttribute(styleAttr, "-webkit-user-select:none;");
imageElement->setLoadManually(true);
imageElement->setSrc(url().string());
body->appendChild(imageElement);
if (m_shouldShrinkImage) {
+#if PLATFORM(IOS)
+ // Set the viewport to be in device pixels (rather than the default of 980).
+ processViewport(ASCIILiteral("width=device-width"), ViewportArguments::ImageDocument);
+#else
RefPtr<EventListener> listener = ImageEventListener::create(*this);
if (DOMWindow* window = this->domWindow())
window->addEventListener("resize", listener, false);
imageElement->addEventListener("click", listener.release(), false);
-
-#if PLATFORM(IOS)
- // Set the viewport to be in device pixels (rather than the default of 980).
- processViewport(ASCIILiteral("width=device-width"), ViewportArguments::ImageDocument);
#endif
}
m_imageElement = imageElement.get();
}
-float ImageDocument::scale()
+void ImageDocument::imageUpdated()
{
+ ASSERT(m_imageElement);
+
+ if (m_imageSizeIsKnown)
+ return;
+
+ LayoutSize imageSize = this->imageSize();
+ if (imageSize.isEmpty())
+ return;
+
+ m_imageSizeIsKnown = true;
+
+ if (m_shouldShrinkImage) {
#if PLATFORM(IOS)
- // On iOS big images are subsampled to make them smaller. So, don't resize them.
- return 1;
+ FloatSize screenSize = page()->chrome().screenSize();
+ if (imageSize.width() > screenSize.width())
+ processViewport(String::format("width=%u", static_cast<unsigned>(imageSize.width().toInt())), ViewportArguments::ImageDocument);
#else
+ // Call windowSizeChanged for its side effect of sizing the image.
+ windowSizeChanged();
+#endif
+ }
+}
+
+#if !PLATFORM(IOS)
+float ImageDocument::scale()
+{
if (!m_imageElement)
return 1;
@@ -255,14 +285,10 @@
float heightScale = view->height() / imageSize.height().toFloat();
return std::min(widthScale, heightScale);
-#endif
}
void ImageDocument::resizeImageToFit()
{
-#if PLATFORM(IOS)
- // On iOS big images are subsampled to make them smaller. So, don't resize them.
-#else
if (!m_imageElement)
return;
@@ -273,57 +299,8 @@
m_imageElement->setHeight(static_cast<int>(imageSize.height() * scale));
m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueWebkitZoomIn);
-#endif
}
-void ImageDocument::imageClicked(int x, int y)
-{
-#if PLATFORM(IOS)
- // On iOS big images are subsampled to make them smaller. So, don't resize them.
- UNUSED_PARAM(x);
- UNUSED_PARAM(y);
-#else
- if (!m_imageSizeIsKnown || imageFitsInWindow())
- return;
-
- m_shouldShrinkImage = !m_shouldShrinkImage;
-
- if (m_shouldShrinkImage) {
- // Call windowSizeChanged for its side effect of sizing the image.
- windowSizeChanged();
- } else {
- restoreImageSize();
-
- updateLayout();
-
- float scale = this->scale();
-
- int scrollX = static_cast<int>(x / scale - view()->width() / 2.0f);
- int scrollY = static_cast<int>(y / scale - view()->height() / 2.0f);
-
- view()->setScrollPosition(IntPoint(scrollX, scrollY));
- }
-#endif
-}
-
-void ImageDocument::imageUpdated()
-{
- ASSERT(m_imageElement);
-
- if (m_imageSizeIsKnown)
- return;
-
- if (imageSize().isEmpty())
- return;
-
- m_imageSizeIsKnown = true;
-
- if (m_shouldShrinkImage) {
- // Call windowSizeChanged for its side effect of sizing the image.
- windowSizeChanged();
- }
-}
-
void ImageDocument::restoreImageSize()
{
if (!m_imageElement || !m_imageSizeIsKnown)
@@ -351,14 +328,11 @@
return true;
LayoutSize imageSize = this->imageSize();
-#if PLATFORM(IOS)
- LayoutSize windowSize = view->contentsToScreen(view->visibleContentRect()).size();
-#else
LayoutSize windowSize = LayoutSize(view->width(), view->height());
-#endif
return imageSize.width() <= windowSize.width() && imageSize.height() <= windowSize.height();
}
+
void ImageDocument::windowSizeChanged()
{
if (!m_imageElement || !m_imageSizeIsKnown)
@@ -366,20 +340,6 @@
bool fitsInWindow = imageFitsInWindow();
-#if PLATFORM(IOS)
- if (fitsInWindow)
- return;
-
- LayoutSize imageSize = this->imageSize();
- LayoutRect visibleScreenSize = view()->contentsToScreen(view()->visibleContentRect());
-
- float widthScale = static_cast<float>(visibleScreenSize.width()) / imageSize.width();
- float heightScale = static_cast<float>(visibleScreenSize.height()) / imageSize.height();
- if (widthScale < heightScale)
- processViewport(String::format("width=%d", imageSize.width().toInt()), ViewportArguments::ImageDocument);
- else
- processViewport(String::format("width=%d", static_cast<int>(1.0f + (1.0f - heightScale)) * imageSize.width().toInt()), ViewportArguments::ImageDocument);
-#else
// If the image has been explicitly zoomed in, restore the cursor if the image fits
// and set it to a zoom out cursor if the image doesn't fit
if (!m_shouldShrinkImage) {
@@ -404,9 +364,32 @@
m_didShrinkImage = true;
}
}
-#endif
}
+void ImageDocument::imageClicked(int x, int y)
+{
+ if (!m_imageSizeIsKnown || imageFitsInWindow())
+ return;
+
+ m_shouldShrinkImage = !m_shouldShrinkImage;
+
+ if (m_shouldShrinkImage) {
+ // Call windowSizeChanged for its side effect of sizing the image.
+ windowSizeChanged();
+ } else {
+ restoreImageSize();
+
+ updateLayout();
+
+ float scale = this->scale();
+
+ int scrollX = static_cast<int>(x / scale - view()->width() / 2.0f);
+ int scrollY = static_cast<int>(y / scale - view()->height() / 2.0f);
+
+ view()->setScrollPosition(IntPoint(scrollX, scrollY));
+ }
+}
+
void ImageEventListener::handleEvent(ScriptExecutionContext*, Event* event)
{
if (event->type() == eventNames().resizeEvent)
@@ -422,6 +405,7 @@
// All ImageEventListener objects compare as equal; OK since there is only one per document.
return other.type() == ImageEventListenerType;
}
+#endif
// --------
Modified: trunk/Source/WebCore/html/ImageDocument.h (168326 => 168327)
--- trunk/Source/WebCore/html/ImageDocument.h 2014-05-05 23:24:09 UTC (rev 168326)
+++ trunk/Source/WebCore/html/ImageDocument.h 2014-05-05 23:35:38 UTC (rev 168327)
@@ -46,8 +46,10 @@
void disconnectImageElement() { m_imageElement = nullptr; }
+#if !PLATFORM(IOS)
void windowSizeChanged();
void imageClicked(int x, int y);
+#endif
private:
ImageDocument(Frame&, const URL&);
@@ -57,10 +59,12 @@
LayoutSize imageSize();
void createDocumentStructure();
+#if !PLATFORM(IOS)
void resizeImageToFit();
void restoreImageSize();
bool imageFitsInWindow();
float scale();
+#endif
void imageUpdated();
@@ -69,8 +73,10 @@
// Whether enough of the image has been loaded to determine its size.
bool m_imageSizeIsKnown;
+#if !PLATFORM(IOS)
// Whether the image is shrunk to fit or not.
bool m_didShrinkImage;
+#endif
// Whether the image should be shrunk or not.
bool m_shouldShrinkImage;