⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 100196 in webkit


Ignore:
Timestamp:
Nov 14, 2011, 2:47:05 PM (15 years ago)
Author:
fsamuel@chromium.org
Message:

[Chromium] setPageScaleFactor and associated methods should take scaling limits into account
https://bugs.webkit.org/show_bug.cgi?id=72176

Source/WebKit/chromium:

Reviewed by Darin Fisher.

A couple of changes:

  1. setPageScaleFactorLimits now affects the behavior of other scaling methods including setPageScaleFactor.
  2. setPageScaleFactorPreservingScrollOffset introduced that scales the scroll offset along with the page, preserving the scroll position within the page bounds.
  • public/WebView.h:
  • src/WebViewImpl.cpp:

(WebKit::WebViewImpl::WebViewImpl):
(WebKit::WebViewImpl::computePageScaleFactorWithinLimits):
(WebKit::WebViewImpl::clampOffsetAtScale):
(WebKit::WebViewImpl::setPageScaleFactorPreservingScrollOffset):
(WebKit::WebViewImpl::setPageScaleFactor):
(WebKit::WebViewImpl::setPageScaleFactorLimits):
(WebKit::WebViewImpl::applyScrollAndScale):

  • src/WebViewImpl.h:

LayoutTests:

Reviewed by Darin Fisher.

Rebaselined some tests that broke because we now clamp pageScaleFactor to 0.25 (these test at 0.2).

Since this is a Chromium only change, the new baselines are only for Chromium.

  • platform/chromium-linux/fast/repaint/scale-page-shrink-expected.png:
  • platform/chromium-linux/fast/repaint/scale-page-shrink-expected.txt: Added.
  • platform/chromium/fast/repaint/background-scaling-expected.png: Copied from LayoutTests/platform/chromium-linux/fast/repaint/scale-page-shrink-expected.png.
  • platform/chromium/fast/repaint/background-scaling-expected.txt: Added.
Location:
trunk
Files:
2 added
6 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r100193 r100196  
     12011-11-14  Fady Samuel  <fsamuel@chromium.org>
     2
     3        [Chromium] setPageScaleFactor and associated methods should take scaling limits into account
     4        https://bugs.webkit.org/show_bug.cgi?id=72176
     5
     6        Reviewed by Darin Fisher.
     7
     8        Rebaselined some tests that broke because we now clamp pageScaleFactor to 0.25 (these test at 0.2).
     9
     10        Since this is a Chromium only change, the new baselines are only for Chromium.
     11
     12        * platform/chromium-linux/fast/repaint/scale-page-shrink-expected.png:
     13        * platform/chromium-linux/fast/repaint/scale-page-shrink-expected.txt: Added.
     14        * platform/chromium/fast/repaint/background-scaling-expected.png: Copied from LayoutTests/platform/chromium-linux/fast/repaint/scale-page-shrink-expected.png.
     15        * platform/chromium/fast/repaint/background-scaling-expected.txt: Added.
     16
    1172011-11-14  Robert Hogan  <robert@webkit.org>
    218
  • trunk/Source/WebKit/chromium/ChangeLog

    r100194 r100196  
     12011-11-14  Fady Samuel  <fsamuel@chromium.org>
     2
     3        [Chromium] setPageScaleFactor and associated methods should take scaling limits into account
     4        https://bugs.webkit.org/show_bug.cgi?id=72176
     5
     6        Reviewed by Darin Fisher.
     7 
     8        A couple of changes:
     9 
     10        1. setPageScaleFactorLimits now affects the behavior of other scaling methods
     11           including setPageScaleFactor.
     12        2. setPageScaleFactorPreservingScrollOffset introduced that scales the scroll offset
     13           along with the page, preserving the scroll position within the page bounds.
     14 
     15
     16        * public/WebView.h:
     17        * src/WebViewImpl.cpp:
     18        (WebKit::WebViewImpl::WebViewImpl):
     19        (WebKit::WebViewImpl::computePageScaleFactorWithinLimits):
     20        (WebKit::WebViewImpl::clampOffsetAtScale):
     21        (WebKit::WebViewImpl::setPageScaleFactorPreservingScrollOffset):
     22        (WebKit::WebViewImpl::setPageScaleFactor):
     23        (WebKit::WebViewImpl::setPageScaleFactorLimits):
     24        (WebKit::WebViewImpl::applyScrollAndScale):
     25        * src/WebViewImpl.h:
     26
    1272011-11-14  Vincent Scheib  <scheib@chromium.org>
    228
  • trunk/Source/WebKit/chromium/public/WebView.h

    r99774 r100196  
    6262    WEBKIT_EXPORT static const double minTextSizeMultiplier;
    6363    WEBKIT_EXPORT static const double maxTextSizeMultiplier;
     64    WEBKIT_EXPORT static const float minPageScaleFactor;
     65    WEBKIT_EXPORT static const float maxPageScaleFactor;
    6466
    6567    // Controls the time that user scripts injected into the document run.
     
    208210    WEBKIT_EXPORT static double zoomFactorToZoomLevel(double factor);
    209211
     212    // Gets the scale factor of the page, where 1.0 is the normal size, > 1.0
     213    // is scaled up, < 1.0 is scaled down.
     214    virtual float pageScaleFactor() const = 0;
     215
     216    // Scales the page and the scroll offset by a given factor, while ensuring
     217    // that the new scroll position does not go beyond the edge of the page.
     218    virtual void setPageScaleFactorPreservingScrollOffset(float) = 0;
     219
     220    // Scales a page by a factor of scaleFactor and then sets a scroll position to (x, y).
     221    // setPageScaleFactor() magnifies and shrinks a page without affecting layout.
     222    // On the other hand, zooming affects layout of the page.
     223    virtual void setPageScaleFactor(float scaleFactor, const WebPoint& origin) = 0;
     224
    210225    // PageScaleFactor will be force-clamped between minPageScale and maxPageScale
    211226    // (and these values will persist until setPageScaleFactorLimits is called
    212227    // again).
    213228    virtual void setPageScaleFactorLimits(float minPageScale, float maxPageScale) = 0;
    214 
    215     // Gets the scale factor of the page, where 1.0 is the normal size, > 1.0
    216     // is scaled up, < 1.0 is scaled down.
    217     virtual float pageScaleFactor() const = 0;
    218 
    219     // Scales a page by a factor of scaleFactor and then sets a scroll position to (x, y).
    220     // setPageScaleFactor() magnifies and shrinks a page without affecting layout.
    221     // On the other hand, zooming affects layout of the page.
    222     virtual void setPageScaleFactor(float scaleFactor, const WebPoint& origin) = 0;
    223229
    224230    // The ratio of the current device's screen DPI to the target device's screen DPI.
  • trunk/Source/WebKit/chromium/src/WebViewImpl.cpp

    r100099 r100196  
    200200const double WebView::minTextSizeMultiplier = 0.5;
    201201const double WebView::maxTextSizeMultiplier = 3.0;
     202const float WebView::minPageScaleFactor = 0.25;
     203const float WebView::maxPageScaleFactor = 4.0;
    202204
    203205
     
    339341    , m_minimumZoomLevel(zoomFactorToZoomLevel(minTextSizeMultiplier))
    340342    , m_maximumZoomLevel(zoomFactorToZoomLevel(maxTextSizeMultiplier))
     343    , m_minimumPageScaleFactor(minPageScaleFactor)
     344    , m_maximumPageScaleFactor(maxPageScaleFactor)
    341345    , m_contextMenuAllowed(false)
    342346    , m_doingDragAndDrop(false)
     
    18531857}
    18541858
     1859float WebViewImpl::computePageScaleFactorWithinLimits(float scaleFactor)
     1860{
     1861    return min(max(scaleFactor, m_minimumPageScaleFactor), m_maximumPageScaleFactor);
     1862}
     1863
     1864WebPoint WebViewImpl::clampOffsetAtScale(const WebPoint& offset, float scale)
     1865{
     1866    // This is the scaled content size. We need to convert it to the new scale factor.
     1867    WebSize contentSize = mainFrame()->contentsSize();
     1868    float deltaScale = scale / pageScaleFactor();
     1869    int docWidthAtNewScale = contentSize.width * deltaScale;
     1870    int docHeightAtNewScale = contentSize.height * deltaScale;
     1871    int viewWidth = m_size.width;
     1872    int viewHeight = m_size.height;
     1873
     1874    // Enforce the maximum and minimum scroll positions at the new scale.
     1875    IntPoint clampedOffset = offset;
     1876    clampedOffset.clampNegativeToZero();
     1877    clampedOffset = clampedOffset.shrunkTo(IntPoint(docWidthAtNewScale - viewWidth, docHeightAtNewScale - viewHeight));
     1878    return clampedOffset;
     1879}
     1880
     1881void WebViewImpl::setPageScaleFactorPreservingScrollOffset(float scaleFactor)
     1882{
     1883    // Pick a scale factor that is within the expected limits
     1884    scaleFactor = computePageScaleFactorWithinLimits(scaleFactor);
     1885    if (scaleFactor == pageScaleFactor())
     1886        return;
     1887
     1888    IntPoint scrollOffsetAtNewScale(mainFrame()->scrollOffset().width, mainFrame()->scrollOffset().height);
     1889    float deltaScale = scaleFactor / pageScaleFactor();
     1890    scrollOffsetAtNewScale.scale(deltaScale, deltaScale);
     1891
     1892    WebPoint clampedOffsetAtNewScale = clampOffsetAtScale(scrollOffsetAtNewScale, scaleFactor);
     1893    setPageScaleFactor(scaleFactor, clampedOffsetAtNewScale);
     1894}
     1895
    18551896void WebViewImpl::setPageScaleFactor(float scaleFactor, const WebPoint& origin)
    18561897{
     
    18581899        return;
    18591900
     1901    if (!scaleFactor)
     1902        scaleFactor = 1;
     1903
     1904    scaleFactor = computePageScaleFactorWithinLimits(scaleFactor);
    18601905    page()->setPageScaleFactor(scaleFactor, origin);
    18611906}
     
    19111956void WebViewImpl::setPageScaleFactorLimits(float minPageScale, float maxPageScale)
    19121957{
     1958    m_minimumPageScaleFactor = min(max(minPageScale, minPageScaleFactor), maxPageScaleFactor) * deviceScaleFactor();
     1959    m_maximumPageScaleFactor = max(min(maxPageScale, maxPageScaleFactor), minPageScaleFactor) * deviceScaleFactor();
     1960
     1961    // Limit page scaling down to the document width.
     1962    int viewWidth = m_size.width;
     1963    int unscaledContentWidth = mainFrame()->contentsSize().width / pageScaleFactor();
     1964    m_minimumPageScaleFactor = max(m_minimumPageScaleFactor,  static_cast<float>(viewWidth) / unscaledContentWidth);
     1965    ASSERT(minPageScale <= maxPageScale);
    19131966#if USE(ACCELERATED_COMPOSITING)
    1914     m_layerTreeHost->setPageScaleFactorLimits(minPageScale, maxPageScale);
     1967    if (m_layerTreeHost)
     1968        m_layerTreeHost->setPageScaleFactorLimits(m_minimumPageScaleFactor, m_maximumPageScaleFactor);
    19151969#endif
    19161970}
     
    27312785    float oldScale = pageScaleFactor();
    27322786    if (!oldScale)
    2733         oldScale = 1.0f;
     2787        oldScale = 1;
    27342788
    27352789    if (!scaleFactor || oldScale == scaleFactor)
  • trunk/Source/WebKit/chromium/src/WebViewImpl.h

    r99774 r100196  
    159159                                   double maximumZoomLevel);
    160160    virtual float pageScaleFactor() const;
     161    virtual void setPageScaleFactorPreservingScrollOffset(float);
    161162    virtual void setPageScaleFactor(float scaleFactor, const WebPoint& origin);
    162163    virtual void setPageScaleFactorLimits(float minPageScale, float maxPageScale);
     
    418419
    419420private:
     421    float computePageScaleFactorWithinLimits(float scale);
     422    WebPoint clampOffsetAtScale(const WebPoint& offset, float scale);
     423
    420424    friend class WebView;  // So WebView::Create can call our constructor
    421425    friend class WTF::RefCounted<WebViewImpl>;
     
    513517
    514518    double m_maximumZoomLevel;
     519
     520    float m_minimumPageScaleFactor;
     521
     522    float m_maximumPageScaleFactor;
    515523
    516524    bool m_contextMenuAllowed;
Note: See TracChangeset for help on using the changeset viewer.