Changeset 168327 in webkit


Ignore:
Timestamp:
May 5, 2014 4:35:38 PM (10 years ago)
Author:
benjamin@webkit.org
Message:

Clean up Image Document and tweak the layout and viewport
https://bugs.webkit.org/show_bug.cgi?id=132552

Source/WebCore:
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:

Tools:
Reviewed by Anders Carlsson.

  • DumpRenderTree/mac/DumpRenderTree.mm:

(resetWebPreferencesToConsistentValues):
Update the default settings to have something consistent with WebKit2.

LayoutTests:
Reviewed by Anders Carlsson.

  • svg/custom/anchor-on-use-expected.svg:
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r168322 r168327  
     12014-05-05  Benjamin Poulain  <benjamin@webkit.org>
     2
     3        Clean up Image Document and tweak the layout and viewport
     4        https://bugs.webkit.org/show_bug.cgi?id=132552
     5
     6        Reviewed by Anders Carlsson.
     7
     8        * svg/custom/anchor-on-use-expected.svg:
     9
    1102014-05-05  Christophe Dumez  <ch.dumez@samsung.com>
    211
  • trunk/LayoutTests/svg/custom/anchor-on-use-expected.svg

    r114750 r168327  
    11<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    2     <image x="0" y="0" width="503" height="410" xlink:href="resources/green-checker.png"/>
     2    <image x="50%" y="0" transform="translate(-251,0)" width="503" height="410" xlink:href="resources/green-checker.png"/>
    33</svg>
    44
  • trunk/Source/WebCore/ChangeLog

    r168325 r168327  
     12014-05-05  Benjamin Poulain  <benjamin@webkit.org>
     2
     3        Clean up Image Document and tweak the layout and viewport
     4        https://bugs.webkit.org/show_bug.cgi?id=132552
     5
     6        Reviewed by Sam Weinig.
     7
     8        The #ifdef in every function was making quite a mess. A lot of that code does
     9        not make sense on iOS.
     10
     11        This patch make a clean split between mouse related stuff and iOS.
     12
     13        Also:
     14        -Change the viewport to be only width based, and avoid scaling in portrait.
     15        -Center the image horizontally in the view.
     16
     17        * html/ImageDocument.cpp:
     18        (WebCore::ImageDocument::ImageDocument):
     19        (WebCore::ImageDocument::createDocumentStructure):
     20        (WebCore::ImageDocument::imageUpdated):
     21        (WebCore::ImageDocument::scale):
     22        (WebCore::ImageDocument::resizeImageToFit):
     23        (WebCore::ImageDocument::imageFitsInWindow):
     24        (WebCore::ImageDocument::windowSizeChanged):
     25        (WebCore::ImageDocument::imageClicked):
     26        * html/ImageDocument.h:
     27
    1282014-05-05  Beth Dakin  <bdakin@apple.com>
    229
  • trunk/Source/WebCore/html/ImageDocument.cpp

    r168316 r168327  
    2727
    2828#include "CachedImage.h"
     29#include "Chrome.h"
    2930#include "DocumentLoader.h"
    3031#include "EventListener.h"
     
    5152using namespace HTMLNames;
    5253
     54#if !PLATFORM(IOS)
    5355class ImageEventListener final : public EventListener {
    5456public:
     
    6769    ImageDocument& m_document;
    6870};
    69    
     71#endif
     72
    7073class ImageDocumentParser final : public RawDataDocumentParser {
    7174public:
     
    192195    , m_imageElement(nullptr)
    193196    , m_imageSizeIsKnown(false)
     197#if !PLATFORM(IOS)
    194198    , m_didShrinkImage(false)
     199#endif
    195200    , m_shouldShrinkImage(frame.settings().shrinksStandaloneImagesToFit() && frame.isMainFrame())
    196201{
     
    217222   
    218223    RefPtr<ImageDocumentElement> imageElement = ImageDocumentElement::create(*this);
    219     imageElement->setAttribute(styleAttr, "-webkit-user-select: none");       
     224    if (m_shouldShrinkImage)
     225        imageElement->setAttribute(styleAttr, "-webkit-user-select:none; display:block; margin:auto;");
     226    else
     227        imageElement->setAttribute(styleAttr, "-webkit-user-select:none;");
    220228    imageElement->setLoadManually(true);
    221229    imageElement->setSrc(url().string());
     
    223231   
    224232    if (m_shouldShrinkImage) {
     233#if PLATFORM(IOS)
     234        // Set the viewport to be in device pixels (rather than the default of 980).
     235        processViewport(ASCIILiteral("width=device-width"), ViewportArguments::ImageDocument);
     236#else
    225237        RefPtr<EventListener> listener = ImageEventListener::create(*this);
    226238        if (DOMWindow* window = this->domWindow())
    227239            window->addEventListener("resize", listener, false);
    228240        imageElement->addEventListener("click", listener.release(), false);
    229 
     241#endif
     242    }
     243
     244    m_imageElement = imageElement.get();
     245}
     246
     247void ImageDocument::imageUpdated()
     248{
     249    ASSERT(m_imageElement);
     250
     251    if (m_imageSizeIsKnown)
     252        return;
     253
     254    LayoutSize imageSize = this->imageSize();
     255    if (imageSize.isEmpty())
     256        return;
     257
     258    m_imageSizeIsKnown = true;
     259
     260    if (m_shouldShrinkImage) {
    230261#if PLATFORM(IOS)
    231         // Set the viewport to be in device pixels (rather than the default of 980).
    232         processViewport(ASCIILiteral("width=device-width"), ViewportArguments::ImageDocument);
     262        FloatSize screenSize = page()->chrome().screenSize();
     263        if (imageSize.width() > screenSize.width())
     264            processViewport(String::format("width=%u", static_cast<unsigned>(imageSize.width().toInt())), ViewportArguments::ImageDocument);
     265#else
     266        // Call windowSizeChanged for its side effect of sizing the image.
     267        windowSizeChanged();
    233268#endif
    234269    }
    235 
    236     m_imageElement = imageElement.get();
    237 }
    238 
     270}
     271
     272#if !PLATFORM(IOS)
    239273float ImageDocument::scale()
    240274{
    241 #if PLATFORM(IOS)
    242     // On iOS big images are subsampled to make them smaller. So, don't resize them.
    243     return 1;
    244 #else
    245275    if (!m_imageElement)
    246276        return 1;
     
    256286
    257287    return std::min(widthScale, heightScale);
    258 #endif
    259288}
    260289
    261290void ImageDocument::resizeImageToFit()
    262291{
    263 #if PLATFORM(IOS)
    264     // On iOS big images are subsampled to make them smaller. So, don't resize them.
    265 #else
    266292    if (!m_imageElement)
    267293        return;
     
    274300
    275301    m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueWebkitZoomIn);
    276 #endif
    277 }
    278 
    279 void ImageDocument::imageClicked(int x, int y)
    280 {
    281 #if PLATFORM(IOS)
    282     // On iOS big images are subsampled to make them smaller. So, don't resize them.
    283     UNUSED_PARAM(x);
    284     UNUSED_PARAM(y);
    285 #else
    286     if (!m_imageSizeIsKnown || imageFitsInWindow())
    287         return;
    288 
    289     m_shouldShrinkImage = !m_shouldShrinkImage;
    290 
    291     if (m_shouldShrinkImage) {
    292         // Call windowSizeChanged for its side effect of sizing the image.
    293         windowSizeChanged();
    294     } else {
    295         restoreImageSize();
    296 
    297         updateLayout();
    298 
    299         float scale = this->scale();
    300 
    301         int scrollX = static_cast<int>(x / scale - view()->width() / 2.0f);
    302         int scrollY = static_cast<int>(y / scale - view()->height() / 2.0f);
    303 
    304         view()->setScrollPosition(IntPoint(scrollX, scrollY));
    305     }
    306 #endif
    307 }
    308 
    309 void ImageDocument::imageUpdated()
    310 {
    311     ASSERT(m_imageElement);
    312    
    313     if (m_imageSizeIsKnown)
    314         return;
    315 
    316     if (imageSize().isEmpty())
    317         return;
    318    
    319     m_imageSizeIsKnown = true;
    320 
    321     if (m_shouldShrinkImage) {
    322         // Call windowSizeChanged for its side effect of sizing the image.
    323         windowSizeChanged();
    324     }
    325302}
    326303
     
    352329
    353330    LayoutSize imageSize = this->imageSize();
    354 #if PLATFORM(IOS)
    355     LayoutSize windowSize = view->contentsToScreen(view->visibleContentRect()).size();
    356 #else
    357331    LayoutSize windowSize = LayoutSize(view->width(), view->height());
    358 #endif
    359332    return imageSize.width() <= windowSize.width() && imageSize.height() <= windowSize.height();
    360333}
    361334
     335
    362336void ImageDocument::windowSizeChanged()
    363337{
     
    367341    bool fitsInWindow = imageFitsInWindow();
    368342
    369 #if PLATFORM(IOS)
    370     if (fitsInWindow)
    371         return;
    372 
    373     LayoutSize imageSize = this->imageSize();
    374     LayoutRect visibleScreenSize = view()->contentsToScreen(view()->visibleContentRect());
    375 
    376     float widthScale = static_cast<float>(visibleScreenSize.width()) / imageSize.width();
    377     float heightScale = static_cast<float>(visibleScreenSize.height()) / imageSize.height();
    378     if (widthScale < heightScale)
    379         processViewport(String::format("width=%d", imageSize.width().toInt()), ViewportArguments::ImageDocument);
    380     else
    381         processViewport(String::format("width=%d", static_cast<int>(1.0f + (1.0f - heightScale)) * imageSize.width().toInt()), ViewportArguments::ImageDocument);
    382 #else
    383343    // If the image has been explicitly zoomed in, restore the cursor if the image fits
    384344    // and set it to a zoom out cursor if the image doesn't fit
     
    405365        }
    406366    }
    407 #endif
     367}
     368
     369void ImageDocument::imageClicked(int x, int y)
     370{
     371    if (!m_imageSizeIsKnown || imageFitsInWindow())
     372        return;
     373
     374    m_shouldShrinkImage = !m_shouldShrinkImage;
     375
     376    if (m_shouldShrinkImage) {
     377        // Call windowSizeChanged for its side effect of sizing the image.
     378        windowSizeChanged();
     379    } else {
     380        restoreImageSize();
     381
     382        updateLayout();
     383
     384        float scale = this->scale();
     385
     386        int scrollX = static_cast<int>(x / scale - view()->width() / 2.0f);
     387        int scrollY = static_cast<int>(y / scale - view()->height() / 2.0f);
     388
     389        view()->setScrollPosition(IntPoint(scrollX, scrollY));
     390    }
    408391}
    409392
     
    423406    return other.type() == ImageEventListenerType;
    424407}
     408#endif
    425409
    426410// --------
  • trunk/Source/WebCore/html/ImageDocument.h

    r168316 r168327  
    4747    void disconnectImageElement() { m_imageElement = nullptr; }
    4848
     49#if !PLATFORM(IOS)
    4950    void windowSizeChanged();
    5051    void imageClicked(int x, int y);
     52#endif
    5153
    5254private:
     
    5860
    5961    void createDocumentStructure();
     62#if !PLATFORM(IOS)
    6063    void resizeImageToFit();
    6164    void restoreImageSize();
    6265    bool imageFitsInWindow();
    6366    float scale();
     67#endif
    6468
    6569    void imageUpdated();
     
    7074    bool m_imageSizeIsKnown;
    7175
     76#if !PLATFORM(IOS)
    7277    // Whether the image is shrunk to fit or not.
    7378    bool m_didShrinkImage;
     79#endif
    7480
    7581    // Whether the image should be shrunk or not.
  • trunk/Tools/ChangeLog

    r168304 r168327  
     12014-05-05  Benjamin Poulain  <benjamin@webkit.org>
     2
     3        Clean up Image Document and tweak the layout and viewport
     4        https://bugs.webkit.org/show_bug.cgi?id=132552
     5
     6        Reviewed by Anders Carlsson.
     7
     8        * DumpRenderTree/mac/DumpRenderTree.mm:
     9        (resetWebPreferencesToConsistentValues):
     10        Update the default settings to have something consistent with WebKit2.
     11
    1122014-05-05  Martin Robinson  <mrobinson@igalia.com>
    213
  • trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm

    r168044 r168327  
    840840    [preferences setPrivateBrowsingEnabled:NO];
    841841    [preferences setAuthorAndUserStylesEnabled:YES];
     842    [preferences setShrinksStandaloneImagesToFit:YES];
    842843    [preferences setJavaScriptCanOpenWindowsAutomatically:YES];
    843844    [preferences setJavaScriptCanAccessClipboard:YES];
Note: See TracChangeset for help on using the changeset viewer.