0008-WebCore-html-ImageDocument.cpp-Enhance-Image-Viewer.patch (3210B)
- From 577a193afca81b7c367e84737efd39901f0cb136 Mon Sep 17 00:00:00 2001
- From: "Haelwenn (lanodan) Monnier" <contact@hacktivis.me>
- Date: Wed, 13 Mar 2019 07:55:17 +0100
- Subject: [PATCH 8/8] WebCore/html/ImageDocument.cpp: Enhance Image Viewer
- The following chances allows to center the image when viewed and avoids
- setting the now useless width/height attributes.
- ---
- Source/WebCore/html/ImageDocument.cpp | 24 ++++++++++--------------
- 1 file changed, 10 insertions(+), 14 deletions(-)
- diff --git a/Source/WebCore/html/ImageDocument.cpp b/Source/WebCore/html/ImageDocument.cpp
- index 0518ff867d..cd2a0c67aa 100644
- --- a/Source/WebCore/html/ImageDocument.cpp
- +++ b/Source/WebCore/html/ImageDocument.cpp
- @@ -226,16 +226,17 @@ void ImageDocument::createDocumentStructure()
- rootElement->appendChild(head);
- auto body = HTMLBodyElement::create(*this);
- - body->setAttribute(styleAttr, "margin: 0px");
- + body->setAttribute(styleAttr, "margin: 0; display: flex;");
- if (MIMETypeRegistry::isPDFMIMEType(document().loader()->responseMIMEType()))
- body->setInlineStyleProperty(CSSPropertyBackgroundColor, "white");
- rootElement->appendChild(body);
- auto imageElement = ImageDocumentElement::create(*this);
- - if (m_shouldShrinkImage)
- - imageElement->setAttribute(styleAttr, "-webkit-user-select:none; display:block; margin:auto;");
- - else
- - imageElement->setAttribute(styleAttr, "-webkit-user-select:none;");
- + //imageElement->setAttribute(styleAttr, "-webkit-user-select:none; display:block; margin:auto; object-fit:contain;");
- + imageElement->setInlineStyleProperty(CSSPropertyWebkitUserSelect, "none");
- + imageElement->setInlineStyleProperty(CSSPropertyDisplay, "block");
- + imageElement->setInlineStyleProperty(CSSPropertyMargin, "auto");
- + imageElement->setInlineStyleProperty(CSSPropertyObjectFit, "contain");
- imageElement->setLoadManually(true);
- imageElement->setSrc(url().string());
- imageElement->cachedImage()->setResponse(loader()->response());
- @@ -307,13 +308,9 @@ void ImageDocument::resizeImageToFit()
- if (!m_imageElement)
- return;
- - LayoutSize imageSize = this->imageSize();
- -
- - float scale = this->scale();
- - m_imageElement->setWidth(static_cast<int>(imageSize.width() * scale));
- - m_imageElement->setHeight(static_cast<int>(imageSize.height() * scale));
- -
- m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueZoomIn);
- + m_imageElement->setInlineStyleProperty(CSSPropertyMaxWidth, "100%");
- + m_imageElement->setInlineStyleProperty(CSSPropertyMaxHeight, "100%");
- }
- void ImageDocument::restoreImageSize()
- @@ -321,9 +318,8 @@ void ImageDocument::restoreImageSize()
- if (!m_imageElement || !m_imageSizeIsKnown)
- return;
- - LayoutSize imageSize = this->imageSize();
- - m_imageElement->setWidth(imageSize.width().toUnsigned());
- - m_imageElement->setHeight(imageSize.height().toUnsigned());
- + m_imageElement->removeInlineStyleProperty(CSSPropertyMaxWidth);
- + m_imageElement->removeInlineStyleProperty(CSSPropertyMaxHeight);
- if (imageFitsInWindow())
- m_imageElement->removeInlineStyleProperty(CSSPropertyCursor);
- --
- 2.19.2