Changeset 141053 in webkit


Ignore:
Timestamp:
Jan 28, 2013 10:19:10 PM (11 years ago)
Author:
aelias@chromium.org
Message:

Make page scale shrink FrameView in applyPageScaleInCompositor mode
https://bugs.webkit.org/show_bug.cgi?id=107424

Reviewed by Levi Weintraub.

If applyPageScaleFactorInCompositor is enabled (Chromium-only setting),
instead of the entire document expanding as the user pinch zooms, the
viewport shrinks instead. This patch applies the pageScaleFactor to
visibleContentRect to get this behavior, and simplifies Chromium's
resize logic to stop hiding the true viewport size from WebCore.

I verified that the scaling makes sense for all the callers of
visibleContentRect. The exceptions are clip-layer size,
layout size in non-fixed-layout mode, and text autosizing, which need
the original unscaled size. Therefore I added a new method
unscaledVisibleContentSize() to ScrollView/FrameView.

This patch also modifies Page::setPageScaleFactor to perform no
invalidates or layout when applyPageScaleFactorInCompositor is true,
and also writes pageScaleFactor into HistoryItems instead of using
frameScaleFactor.

Since all behavior changes are tied to applyPageScaleFactorInCompositor,
this patch should be a no-op for non-Chromium ports.

Source/Platform:

  • chromium/public/WebLayerTreeView.h:

(WebLayerTreeView):
(WebKit::WebLayerTreeView::adjustEventPointForPinchZoom):

Source/WebCore:

New unit tests in WebFrameTest.cpp.

  • loader/HistoryController.cpp:

(WebCore::HistoryController::saveScrollPositionAndViewStateToItem):
Use pageScaleFactor here because frameScaleFactor always returns 1
with our setting.

  • page/FrameView.cpp:

(WebCore::FrameView::visibleContentScaleFactor):
(WebCore):

  • page/FrameView.h:

(FrameView):

  • page/Page.cpp:

(WebCore::Page::setPageScaleFactor): Make setPageScaleFactor stop
invalidating/layouting as this is handled by our compositor.

  • platform/ScrollView.cpp:

(WebCore::ScrollView::unscaledVisibleContentSize): This new method
just returns the original visible rect without pageScaleFactor being
applied.
(WebCore):
(WebCore::ScrollView::visibleContentRect): This now is divided by
pageScaleFactor if our setting is active.
(WebCore::ScrollView::layoutSize):

  • platform/ScrollView.h:

(WebCore::ScrollView::visibleContentScaleFactor): Returns
pageScaleFactor if the visible rect is scaled, 1 normally.
(ScrollView):
(WebCore::ScrollView::layoutWidth):
(WebCore::ScrollView::layoutHeight):

  • rendering/RenderLayerCompositor.cpp:

(WebCore::RenderLayerCompositor::frameViewDidChangeSize):
(WebCore::RenderLayerCompositor::updateRootLayerPosition): Clip layer
should use unscaled size, because it's above the root scroll layer
on the layer tree (i.e. page scale isn't applied on it).

  • rendering/TextAutosizer.cpp:

(WebCore::TextAutosizer::processSubtree): Text autosizer should use
unscaled size, because it cares about physical screen size.

Source/WebKit/chromium:

  • src/WebViewImpl.cpp:

(WebKit::WebViewImpl::scaledSize): Returns the post page-scale size
similar to what visibleContentRect() now returns, except that it may
be at a different scale than the current one.
(WebKit::WebViewImpl::size): Back to returning density-independent
size without any tricks, not the "layoutSize()" fake viewport.
(WebKit::WebViewImpl::resize):
(WebKit::WebViewImpl::handleInputEvent): No need to apply
implTransform anymore as WebKit knows the true scroll offset; just
divide event coords by pageScaleFactor.
(WebKit::WebViewImpl::clampOffsetAtScale): Make this method support
applyPageScaleFactorInCompositor. This is used to pre-clamp scroll
offsets at a given viewport size.
(WebKit::WebViewImpl::setPageScaleFactorPreservingScrollOffset): Make
this method support applyPageScaleFactorInCompositor (don't scale
scroll offsets as they are now scale-independent).
(WebKit::WebViewImpl::setPageScaleFactor): Make this method always use
clampOffsetAtScale instead of bypassing it, since it's now supported.
Also notify the compositor to update its state.
(WebKit::WebViewImpl::contentsSize): Convenience method, removed
difference between scaled and unscaled.
(WebKit::WebViewImpl::layoutSize): This method returned the "fake"
size we used to give FrameView. Now no longer used for much.
(WebKit::WebViewImpl::computePageScaleFactorLimits):
(WebKit::WebViewImpl::didChangeContentsSize): Remove unnecessary
resize() now that we can give the true size to FrameView.
(WebKit::WebViewImpl::updateLayerTreeViewport): Use layoutSize()
directly now that FrameView no longer uses it.

  • src/WebViewImpl.h:

(WebViewImpl):

  • tests/WebFrameTest.cpp:
Location:
trunk/Source
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/Platform/ChangeLog

    r140906 r141053  
     12013-01-28  Alexandre Elias  <aelias@chromium.org>
     2
     3        Make page scale shrink FrameView in applyPageScaleInCompositor mode
     4        https://bugs.webkit.org/show_bug.cgi?id=107424
     5
     6        Reviewed by Levi Weintraub.
     7
     8        If applyPageScaleFactorInCompositor is enabled (Chromium-only setting),
     9        instead of the entire document expanding as the user pinch zooms, the
     10        viewport shrinks instead. This patch applies the pageScaleFactor to
     11        visibleContentRect to get this behavior, and simplifies Chromium's
     12        resize logic to stop hiding the true viewport size from WebCore.
     13
     14        I verified that the scaling makes sense for all the callers of
     15        visibleContentRect. The exceptions are clip-layer size,
     16        layout size in non-fixed-layout mode, and text autosizing, which need
     17        the original unscaled size. Therefore I added a new method
     18        unscaledVisibleContentSize() to ScrollView/FrameView.
     19
     20        This patch also modifies Page::setPageScaleFactor to perform no
     21        invalidates or layout when applyPageScaleFactorInCompositor is true,
     22        and also writes pageScaleFactor into HistoryItems instead of using
     23        frameScaleFactor.
     24
     25        Since all behavior changes are tied to applyPageScaleFactorInCompositor,
     26        this patch should be a no-op for non-Chromium ports.
     27
     28        * chromium/public/WebLayerTreeView.h:
     29        (WebLayerTreeView):
     30        (WebKit::WebLayerTreeView::adjustEventPointForPinchZoom):
     31
    1322013-01-26  James Simonsen  <simonjam@chromium.org>
    233
  • trunk/Source/Platform/chromium/public/WebLayerTreeView.h

    r140798 r141053  
    103103    virtual WebSize deviceViewportSize() const = 0;
    104104
    105     // Gives the corrected location for an event, accounting for the pinch-zoom transformation
    106     // in the compositor.
    107     virtual WebFloatPoint adjustEventPointForPinchZoom(const WebFloatPoint&) const = 0;
     105    // FIXME: remove this after WebKit roll
     106    virtual WebFloatPoint adjustEventPointForPinchZoom(const WebFloatPoint& p) const { return p; }
    108107
    109108    virtual void setDeviceScaleFactor(float) = 0;
  • trunk/Source/WebCore/ChangeLog

    r141050 r141053  
     12013-01-28  Alexandre Elias  <aelias@chromium.org>
     2
     3        Make page scale shrink FrameView in applyPageScaleInCompositor mode
     4        https://bugs.webkit.org/show_bug.cgi?id=107424
     5
     6        Reviewed by Levi Weintraub.
     7
     8        If applyPageScaleFactorInCompositor is enabled (Chromium-only setting),
     9        instead of the entire document expanding as the user pinch zooms, the
     10        viewport shrinks instead. This patch applies the pageScaleFactor to
     11        visibleContentRect to get this behavior, and simplifies Chromium's
     12        resize logic to stop hiding the true viewport size from WebCore.
     13
     14        I verified that the scaling makes sense for all the callers of
     15        visibleContentRect. The exceptions are clip-layer size,
     16        layout size in non-fixed-layout mode, and text autosizing, which need
     17        the original unscaled size. Therefore I added a new method
     18        unscaledVisibleContentSize() to ScrollView/FrameView.
     19
     20        This patch also modifies Page::setPageScaleFactor to perform no
     21        invalidates or layout when applyPageScaleFactorInCompositor is true,
     22        and also writes pageScaleFactor into HistoryItems instead of using
     23        frameScaleFactor.
     24
     25        Since all behavior changes are tied to applyPageScaleFactorInCompositor,
     26        this patch should be a no-op for non-Chromium ports.
     27
     28        New unit tests in WebFrameTest.cpp.
     29
     30        * loader/HistoryController.cpp:
     31        (WebCore::HistoryController::saveScrollPositionAndViewStateToItem):
     32        Use pageScaleFactor here because frameScaleFactor always returns 1
     33        with our setting.
     34        * page/FrameView.cpp:
     35        (WebCore::FrameView::visibleContentScaleFactor):
     36        (WebCore):
     37        * page/FrameView.h:
     38        (FrameView):
     39        * page/Page.cpp:
     40        (WebCore::Page::setPageScaleFactor): Make setPageScaleFactor stop
     41        invalidating/layouting as this is handled by our compositor.
     42        * platform/ScrollView.cpp:
     43        (WebCore::ScrollView::unscaledVisibleContentSize): This new method
     44        just returns the original visible rect without pageScaleFactor being
     45        applied.
     46        (WebCore):
     47        (WebCore::ScrollView::visibleContentRect): This now is divided by
     48        pageScaleFactor if our setting is active.
     49        (WebCore::ScrollView::layoutSize):
     50        * platform/ScrollView.h:
     51        (WebCore::ScrollView::visibleContentScaleFactor): Returns
     52        pageScaleFactor if the visible rect is scaled, 1 normally.
     53        (ScrollView):
     54        (WebCore::ScrollView::layoutWidth):
     55        (WebCore::ScrollView::layoutHeight):
     56        * rendering/RenderLayerCompositor.cpp:
     57        (WebCore::RenderLayerCompositor::frameViewDidChangeSize):
     58        (WebCore::RenderLayerCompositor::updateRootLayerPosition): Clip layer
     59        should use unscaled size, because it's above the root scroll layer
     60        on the layer tree (i.e. page scale isn't applied on it).
     61        * rendering/TextAutosizer.cpp:
     62        (WebCore::TextAutosizer::processSubtree): Text autosizer should use
     63        unscaled size, because it cares about physical screen size.
     64
    1652013-01-28  Geoffrey Garen  <ggaren@apple.com>
    266
  • trunk/Source/WebCore/loader/HistoryController.cpp

    r137792 r141053  
    8888        item->setScrollPoint(m_frame->view()->scrollPosition());
    8989
    90     item->setPageScaleFactor(m_frame->frameScaleFactor());
    91    
     90    Page* page = m_frame->page();
     91    if (page && page->mainFrame() == m_frame)
     92        item->setPageScaleFactor(page->pageScaleFactor());
     93
    9294    // FIXME: It would be great to work out a way to put this code in WebCore instead of calling through to the client.
    9395    m_frame->loader()->client()->saveViewStateToItem(item);
  • trunk/Source/WebCore/page/FrameView.cpp

    r141015 r141053  
    28382838}
    28392839
     2840float FrameView::visibleContentScaleFactor() const
     2841{
     2842    if (!m_frame || !m_frame->page())
     2843        return 1;
     2844
     2845    if (!m_frame->settings()->applyPageScaleFactorInCompositor() || m_frame != m_frame->page()->mainFrame())
     2846        return 1;
     2847
     2848    return m_frame->page()->pageScaleFactor();
     2849}
     2850
    28402851void FrameView::setVisibleScrollerThumbRect(const IntRect& scrollerThumb)
    28412852{
  • trunk/Source/WebCore/page/FrameView.h

    r140571 r141053  
    183183
    184184    virtual IntRect windowResizerRect() const;
     185
     186    virtual float visibleContentScaleFactor() const OVERRIDE;
    185187
    186188    virtual void setFixedVisibleContentRect(const IntRect&) OVERRIDE;
  • trunk/Source/WebCore/page/Page.cpp

    r139800 r141053  
    726726    if (scale == m_pageScaleFactor) {
    727727        if (view && (view->scrollPosition() != origin || view->delegatesScrolling())) {
    728             document->updateLayoutIgnorePendingStylesheets();
     728            if (!m_settings->applyPageScaleFactorInCompositor())
     729                document->updateLayoutIgnorePendingStylesheets();
    729730            view->setScrollPosition(origin);
    730731        }
     
    734735    m_pageScaleFactor = scale;
    735736
    736     if (document->renderer())
    737         document->renderer()->setNeedsLayout(true);
    738 
    739     document->recalcStyle(Node::Force);
    740 
    741     // Transform change on RenderView doesn't trigger repaint on non-composited contents.
    742     mainFrame()->view()->invalidateRect(IntRect(LayoutRect::infiniteRect()));
     737    if (!m_settings->applyPageScaleFactorInCompositor()) {
     738        if (document->renderer())
     739            document->renderer()->setNeedsLayout(true);
     740
     741        document->recalcStyle(Node::Force);
     742
     743        // Transform change on RenderView doesn't trigger repaint on non-composited contents.
     744        mainFrame()->view()->invalidateRect(IntRect(LayoutRect::infiniteRect()));
     745    }
    743746
    744747#if USE(ACCELERATED_COMPOSITING)
     
    747750
    748751    if (view && view->scrollPosition() != origin) {
    749         if (document->renderer() && document->renderer()->needsLayout() && view->didFirstLayout())
     752        if (!m_settings->applyPageScaleFactorInCompositor() && document->renderer() && document->renderer()->needsLayout() && view->didFirstLayout())
    750753            view->layout();
    751754        view->setScrollPosition(origin);
  • trunk/Source/WebCore/platform/ScrollView.cpp

    r141015 r141053  
    226226}
    227227
    228 #if !PLATFORM(GTK)
    229 IntRect ScrollView::visibleContentRect(bool includeScrollbars) const
     228IntSize ScrollView::unscaledVisibleContentSize(bool includeScrollbars) const
    230229{
    231230    if (platformWidget())
    232         return platformVisibleContentRect(includeScrollbars);
     231        return platformVisibleContentRect(includeScrollbars).size();
    233232
    234233    if (!m_fixedVisibleContentRect.isEmpty())
    235         return m_fixedVisibleContentRect;
     234        return m_fixedVisibleContentRect.size();
    236235
    237236    int verticalScrollbarWidth = 0;
     
    245244    }
    246245
    247     return IntRect(m_scrollOffset.width(),
    248                    m_scrollOffset.height(),
    249                    max(0, width() - verticalScrollbarWidth),
     246    return IntSize(max(0, width() - verticalScrollbarWidth),
    250247                   max(0, height() - horizontalScrollbarHeight));
    251248}
     249
     250#if !PLATFORM(GTK)
     251IntRect ScrollView::visibleContentRect(bool includeScrollbars) const
     252{
     253    if (platformWidget())
     254        return platformVisibleContentRect(includeScrollbars);
     255
     256    if (!m_fixedVisibleContentRect.isEmpty())
     257        return m_fixedVisibleContentRect;
     258
     259    FloatSize visibleContentSize = unscaledVisibleContentSize(includeScrollbars);
     260    visibleContentSize.scale(1 / visibleContentScaleFactor());
     261    return IntRect(IntPoint(m_scrollOffset), expandedIntSize(visibleContentSize));
     262}
    252263#endif
    253264
    254265IntSize ScrollView::layoutSize() const
    255266{
    256     return m_fixedLayoutSize.isEmpty() || !m_useFixedLayout ? visibleSize() : m_fixedLayoutSize;
    257 }
    258 
    259 int ScrollView::layoutWidth() const
    260 {
    261     return m_fixedLayoutSize.isEmpty() || !m_useFixedLayout ? visibleWidth() : m_fixedLayoutSize.width();
    262 }
    263 
    264 int ScrollView::layoutHeight() const
    265 {
    266     return m_fixedLayoutSize.isEmpty() || !m_useFixedLayout ? visibleHeight() : m_fixedLayoutSize.height();
     267    return m_fixedLayoutSize.isEmpty() || !m_useFixedLayout ? unscaledVisibleContentSize(false) : m_fixedLayoutSize;
    267268}
    268269
  • trunk/Source/WebCore/platform/ScrollView.h

    r139045 r141053  
    152152    virtual int visibleHeight() const OVERRIDE { return visibleContentRect().height(); }
    153153
     154    // visibleContentRect().size() is computed from unscaledVisibleContentSize() divided by the value of visibleContentScaleFactor.
     155    // visibleContentScaleFactor is usually 1, except when the setting applyPageScaleFactorInCompositor is true and the
     156    // ScrollView is the main frame; in that case, visibleContentScaleFactor is equal to the page's pageScaleFactor.
     157    // Ports that don't use pageScaleFactor can treat unscaledVisibleContentSize and visibleContentRect().size() as equivalent.
     158    IntSize unscaledVisibleContentSize(bool includeScrollbars) const;
     159    virtual float visibleContentScaleFactor() const { return 1; }
     160
    154161    // Functions for getting/setting the size webkit should use to layout the contents. By default this is the same as the visible
    155162    // content size. Explicitly setting a layout size value will cause webkit to layout the contents using this size instead.
    156163    IntSize layoutSize() const;
    157     int layoutWidth() const;
    158     int layoutHeight() const;
     164    int layoutWidth() const { return layoutSize().width(); }
     165    int layoutHeight() const { return layoutSize().height(); }
    159166    IntSize fixedLayoutSize() const;
    160167    void setFixedLayoutSize(const IntSize&);
  • trunk/Source/WebCore/rendering/RenderLayerCompositor.cpp

    r141039 r141053  
    11701170    if (m_clipLayer) {
    11711171        FrameView* frameView = m_renderView->frameView();
    1172         m_clipLayer->setSize(frameView->visibleContentRect(false /* exclude scrollbars */).size());
     1172        m_clipLayer->setSize(frameView->unscaledVisibleContentSize(false /* exclude scrollbars */));
    11731173
    11741174        frameViewDidScroll();
     
    15441544    if (m_clipLayer) {
    15451545        FrameView* frameView = m_renderView->frameView();
    1546         m_clipLayer->setSize(frameView->visibleContentRect(false /* exclude scrollbars */).size());
     1546        m_clipLayer->setSize(frameView->unscaledVisibleContentSize(false /* exclude scrollbars */));
    15471547    }
    15481548
  • trunk/Source/WebCore/rendering/TextAutosizer.cpp

    r140913 r141053  
    8585    if (windowInfo.windowSize.isEmpty()) {
    8686        bool includeScrollbars = !InspectorInstrumentation::shouldApplyScreenWidthOverride(mainFrame);
    87         windowInfo.windowSize = mainFrame->view()->visibleContentRect(includeScrollbars).size();
     87        windowInfo.windowSize = mainFrame->view()->unscaledVisibleContentSize(includeScrollbars);
    8888        if (!m_document->settings()->applyDeviceScaleFactorInCompositor())
    8989            windowInfo.windowSize.scale(1 / m_document->page()->deviceScaleFactor());
  • trunk/Source/WebKit/chromium/ChangeLog

    r141049 r141053  
     12013-01-28  Alexandre Elias  <aelias@chromium.org>
     2
     3        Make page scale shrink FrameView in applyPageScaleInCompositor mode
     4        https://bugs.webkit.org/show_bug.cgi?id=107424
     5
     6        Reviewed by Levi Weintraub.
     7
     8        If applyPageScaleFactorInCompositor is enabled (Chromium-only setting),
     9        instead of the entire document expanding as the user pinch zooms, the
     10        viewport shrinks instead. This patch applies the pageScaleFactor to
     11        visibleContentRect to get this behavior, and simplifies Chromium's
     12        resize logic to stop hiding the true viewport size from WebCore.
     13
     14        I verified that the scaling makes sense for all the callers of
     15        visibleContentRect. The exceptions are clip-layer size,
     16        layout size in non-fixed-layout mode, and text autosizing, which need
     17        the original unscaled size. Therefore I added a new method
     18        unscaledVisibleContentSize() to ScrollView/FrameView.
     19
     20        This patch also modifies Page::setPageScaleFactor to perform no
     21        invalidates or layout when applyPageScaleFactorInCompositor is true,
     22        and also writes pageScaleFactor into HistoryItems instead of using
     23        frameScaleFactor.
     24
     25        Since all behavior changes are tied to applyPageScaleFactorInCompositor,
     26        this patch should be a no-op for non-Chromium ports.
     27
     28        * src/WebViewImpl.cpp:
     29        (WebKit::WebViewImpl::scaledSize): Returns the post page-scale size
     30        similar to what visibleContentRect() now returns, except that it may
     31        be at a different scale than the current one.
     32        (WebKit::WebViewImpl::size): Back to returning density-independent
     33        size without any tricks, not the "layoutSize()" fake viewport.
     34        (WebKit::WebViewImpl::resize):
     35        (WebKit::WebViewImpl::handleInputEvent): No need to apply
     36        implTransform anymore as WebKit knows the true scroll offset; just
     37        divide event coords by pageScaleFactor.
     38        (WebKit::WebViewImpl::clampOffsetAtScale): Make this method support
     39        applyPageScaleFactorInCompositor.  This is used to pre-clamp scroll
     40        offsets at a given viewport size.
     41        (WebKit::WebViewImpl::setPageScaleFactorPreservingScrollOffset): Make
     42        this method support applyPageScaleFactorInCompositor (don't scale
     43        scroll offsets as they are now scale-independent).
     44        (WebKit::WebViewImpl::setPageScaleFactor): Make this method always use
     45        clampOffsetAtScale instead of bypassing it, since it's now supported.
     46        Also notify the compositor to update its state.
     47        (WebKit::WebViewImpl::contentsSize): Convenience method, removed
     48        difference between scaled and unscaled.
     49        (WebKit::WebViewImpl::layoutSize): This method returned the "fake"
     50        size we used to give FrameView.  Now no longer used for much.
     51        (WebKit::WebViewImpl::computePageScaleFactorLimits):
     52        (WebKit::WebViewImpl::didChangeContentsSize): Remove unnecessary
     53        resize() now that we can give the true size to FrameView.
     54        (WebKit::WebViewImpl::updateLayerTreeViewport): Use layoutSize()
     55        directly now that FrameView no longer uses it.
     56        * src/WebViewImpl.h:
     57        (WebViewImpl):
     58        * tests/WebFrameTest.cpp:
     59
    1602013-01-28  Alec Flett  <alecflett@chromium.org>
    261
  • trunk/Source/WebKit/chromium/src/WebViewImpl.cpp

    r141019 r141053  
    16271627}
    16281628
     1629IntSize WebViewImpl::scaledSize(float pageScaleFactor) const
     1630{
     1631    FloatSize scaledSize = dipSize();
     1632    scaledSize.scale(1 / pageScaleFactor);
     1633    return expandedIntSize(scaledSize);
     1634}
     1635
    16291636WebSize WebViewImpl::size()
    16301637{
    1631     if (isFixedLayoutModeEnabled() && settingsImpl()->applyPageScaleFactorInCompositor())
    1632         return layoutSize();
    1633 
    16341638    return m_size;
    16351639}
     
    16621666        WebFrameImpl* webFrame = mainFrameImpl();
    16631667        if (webFrame->frameView())
    1664             webFrame->frameView()->resize(size());
     1668            webFrame->frameView()->resize(m_size);
    16651669    }
    16661670
     
    20982102    }
    20992103
    2100     if (!m_layerTreeView)
    2101         return PageWidgetDelegate::handleInputEvent(m_page.get(), *this, inputEvent);
    2102 
    21032104    const WebInputEvent* inputEventTransformed = &inputEvent;
    2104     WebMouseEvent mouseEvent;
    2105     WebGestureEvent gestureEvent;
    2106     if (WebInputEvent::isMouseEventType(inputEvent.type)) {
    2107         mouseEvent = *static_cast<const WebMouseEvent*>(&inputEvent);
    2108 
    2109         IntPoint transformedLocation = roundedIntPoint(m_layerTreeView->adjustEventPointForPinchZoom(WebFloatPoint(mouseEvent.x, mouseEvent.y)));
    2110         mouseEvent.x = transformedLocation.x();
    2111         mouseEvent.y = transformedLocation.y();
    2112         inputEventTransformed = static_cast<const WebInputEvent*>(&mouseEvent);
    2113     } else if (WebInputEvent::isGestureEventType(inputEvent.type)) {
    2114         gestureEvent = *static_cast<const WebGestureEvent*>(&inputEvent);
    2115 
    2116         IntPoint transformedLocation = roundedIntPoint(m_layerTreeView->adjustEventPointForPinchZoom(WebFloatPoint(gestureEvent.x, gestureEvent.y)));
    2117         gestureEvent.x = transformedLocation.x();
    2118         gestureEvent.y = transformedLocation.y();
    2119         inputEventTransformed = static_cast<const WebInputEvent*>(&gestureEvent);
    2120     }
    2121 
    2122     bool handled = PageWidgetDelegate::handleInputEvent(m_page.get(), *this, *inputEventTransformed);
    2123     return handled;
     2105    if (m_page->settings()->applyPageScaleFactorInCompositor()) {
     2106        WebMouseEvent mouseEvent;
     2107        WebGestureEvent gestureEvent;
     2108        if (WebInputEvent::isMouseEventType(inputEvent.type)) {
     2109            mouseEvent = *static_cast<const WebMouseEvent*>(&inputEvent);
     2110            mouseEvent.x = mouseEvent.x / pageScaleFactor();
     2111            mouseEvent.y = mouseEvent.y / pageScaleFactor();
     2112            inputEventTransformed = static_cast<const WebInputEvent*>(&mouseEvent);
     2113        } else if (WebInputEvent::isGestureEventType(inputEvent.type)) {
     2114            gestureEvent = *static_cast<const WebGestureEvent*>(&inputEvent);
     2115            gestureEvent.x = gestureEvent.x / pageScaleFactor();
     2116            gestureEvent.y = gestureEvent.y / pageScaleFactor();
     2117            inputEventTransformed = static_cast<const WebInputEvent*>(&gestureEvent);
     2118        }
     2119    }
     2120
     2121    return PageWidgetDelegate::handleInputEvent(m_page.get(), *this, *inputEventTransformed);
    21242122}
    21252123
     
    29362934}
    29372935
    2938 WebPoint WebViewImpl::clampOffsetAtScale(const WebPoint& offset, float scale)
    2939 {
    2940     // This is the scaled content size. We need to convert it to the new scale factor.
    2941     WebSize contentSize = mainFrame()->contentsSize();
    2942     float deltaScale = scale / pageScaleFactor();
    2943     int docWidthAtNewScale = contentSize.width * deltaScale;
    2944     int docHeightAtNewScale = contentSize.height * deltaScale;
    2945     int viewWidth = m_size.width;
    2946     int viewHeight = m_size.height;
    2947 
    2948     // Enforce the maximum and minimum scroll positions at the new scale.
     2936IntPoint WebViewImpl::clampOffsetAtScale(const IntPoint& offset, float scale) const
     2937{
    29492938    IntPoint clampedOffset = offset;
    2950     clampedOffset = clampedOffset.shrunkTo(IntPoint(docWidthAtNewScale - viewWidth, docHeightAtNewScale - viewHeight));
    2951     clampedOffset.clampNegativeToZero();
     2939    if (!m_page->settings()->applyPageScaleFactorInCompositor()) {
     2940        // This is the scaled content size. We need to convert it to the new scale factor.
     2941        WebSize contentSize = contentsSize();
     2942        int docWidthAtNewScale = contentSize.width * scale;
     2943        int docHeightAtNewScale = contentSize.height * scale;
     2944        int viewWidth = m_size.width;
     2945        int viewHeight = m_size.height;
     2946
     2947        // Enforce the maximum and minimum scroll positions at the new scale.
     2948        clampedOffset = clampedOffset.shrunkTo(IntPoint(docWidthAtNewScale - viewWidth, docHeightAtNewScale - viewHeight));
     2949        clampedOffset.clampNegativeToZero();
     2950    } else {
     2951        clampedOffset = clampedOffset.shrunkTo(IntPoint(contentsSize() - scaledSize(scale)));
     2952        clampedOffset.clampNegativeToZero();
     2953    }
     2954
    29522955    return clampedOffset;
    29532956}
     
    29552958void WebViewImpl::setPageScaleFactorPreservingScrollOffset(float scaleFactor)
    29562959{
    2957     // Pick a scale factor that is within the expected limits
    29582960    scaleFactor = clampPageScaleFactorToLimits(scaleFactor);
    29592961
    2960     IntPoint scrollOffsetAtNewScale(mainFrame()->scrollOffset().width, mainFrame()->scrollOffset().height);
    2961     float deltaScale = scaleFactor / pageScaleFactor();
    2962     scrollOffsetAtNewScale.scale(deltaScale, deltaScale);
    2963 
    2964     WebPoint clampedOffsetAtNewScale = clampOffsetAtScale(scrollOffsetAtNewScale, scaleFactor);
    2965     setPageScaleFactor(scaleFactor, clampedOffsetAtNewScale);
     2962    IntPoint scrollOffset(mainFrame()->scrollOffset().width, mainFrame()->scrollOffset().height);
     2963    if (!m_page->settings()->applyPageScaleFactorInCompositor()) {
     2964        float deltaScale = scaleFactor / pageScaleFactor();
     2965        scrollOffset.scale(deltaScale, deltaScale);
     2966    }
     2967    scrollOffset = clampOffsetAtScale(scrollOffset, scaleFactor);
     2968
     2969    setPageScaleFactor(scaleFactor, scrollOffset);
    29662970}
    29672971
     
    29742978        scaleFactor = 1;
    29752979
     2980    IntPoint scrollOffset = origin;
    29762981    scaleFactor = clampPageScaleFactorToLimits(scaleFactor);
    2977     WebPoint scrollOffset;
    2978     if (!m_page->settings()->applyPageScaleFactorInCompositor()) {
    2979         // If page scale is not applied in the compositor, then the scroll offsets should
    2980         // be modified by the scale factor.
    2981         scrollOffset = clampOffsetAtScale(origin, scaleFactor);
    2982     } else {
    2983         IntPoint offset = origin;
    2984         WebSize contentSize = mainFrame()->contentsSize();
    2985         offset.shrunkTo(IntPoint(contentSize.width - m_size.width, contentSize.height - m_size.height));
    2986         offset.clampNegativeToZero();
    2987         scrollOffset = offset;
    2988     }
    2989 
    2990     page()->setPageScaleFactor(scaleFactor, scrollOffset);
     2982    scrollOffset = clampOffsetAtScale(scrollOffset, scaleFactor);
     2983
     2984    page()->setPageScaleFactor(scaleFactor, IntPoint(scrollOffset));
     2985
    29912986    m_pageScaleFactorIsSet = true;
     2987
     2988#if USE(ACCELERATED_COMPOSITING)
     2989    updateLayerTreeViewport();
     2990#endif
    29922991}
    29932992
     
    30733072}
    30743073
    3075 static IntSize unscaledContentsSize(Frame* frame)
    3076 {
     3074IntSize WebViewImpl::contentsSize() const
     3075{
     3076    Frame* frame = page()->mainFrame();
    30773077    RenderView* root = frame->contentRenderer();
    30783078    if (!root)
    30793079        return IntSize();
    3080     return root->unscaledDocumentRect().size();
     3080
     3081    return root->documentRect().size();
    30813082}
    30823083
     
    30863087        return m_size;
    30873088
    3088     IntSize contentSize = unscaledContentsSize(page()->mainFrame());
     3089    IntSize contentSize = contentsSize();
     3090
    30893091    if (fixedLayoutSize().width >= contentSize.width())
    30903092        return fixedLayoutSize();
     
    31143116    if (viewWidthNotIncludingScrollbars && view->verticalScrollbar() && !view->verticalScrollbar()->isOverlayScrollbar())
    31153117        viewWidthNotIncludingScrollbars -= view->verticalScrollbar()->width();
    3116     int unscaledContentsWidth = unscaledContentsSize(page()->mainFrame()).width();
     3118    int unscaledContentsWidth = contentsSize().width();
    31173119    if (viewWidthNotIncludingScrollbars && unscaledContentsWidth) {
    31183120        // Limit page scaling down to the document width.
     
    37663768        mayNeedLayout = computePageScaleFactorLimits();
    37673769
    3768     FrameView* view = mainFrameImpl()->frameView();
    3769     if (settingsImpl()->applyPageScaleFactorInCompositor() && view && view->visibleContentRect(true).width() != layoutSize().width()) {
    3770         view->resize(layoutSize());
    3771         mayNeedLayout = true;
    3772     }
    3773 
    37743770    // didChangeContentsSize() may be called from FrameView::layout; we need to
    37753771    // relayout to avoid triggering the assertion that needsLayout() isn't set
    37763772    // at the end of a layout.
     3773    FrameView* view = mainFrameImpl()->frameView();
    37773774    if (mayNeedLayout && view && view->needsLayout())
    37783775        view->layout();
     
    42504247
    42514248    FrameView* view = page()->mainFrame()->view();
    4252     IntRect visibleRect = view->visibleContentRect(true /* include scrollbars */);
    4253     IntPoint scroll(view->scrollX(), view->scrollY());
    4254 
    4255     m_nonCompositedContentHost->setViewport(visibleRect.size(), view->contentsSize(), scroll, view->scrollOrigin());
    4256 
    4257     IntSize layoutViewportSize = visibleRect.size();
     4249
     4250    IntSize layoutViewportSize = layoutSize();
    42584251    IntSize deviceViewportSize = m_size;
    42594252    if (m_webSettings->applyDeviceScaleFactorInCompositor())
    42604253        deviceViewportSize.scale(deviceScaleFactor());
     4254
     4255    m_nonCompositedContentHost->setViewport(deviceViewportSize, view->contentsSize(), view->scrollPosition(), view->scrollOrigin());
    42614256
    42624257    m_layerTreeView->setViewportSize(layoutViewportSize, deviceViewportSize);
  • trunk/Source/WebKit/chromium/src/WebViewImpl.h

    r141019 r141053  
    462462    WebCore::IntSize dipSize() const;
    463463    WebCore::IntSize layoutSize() const;
     464    WebCore::IntSize scaledSize(float) const;
    464465
    465466    // Set the disposition for how this webview is to be initially shown.
     
    616617    bool computePageScaleFactorLimits();
    617618    float clampPageScaleFactorToLimits(float scale);
    618     WebPoint clampOffsetAtScale(const WebPoint& offset, float scale);
     619    WebCore::IntPoint clampOffsetAtScale(const WebCore::IntPoint& offset, float scale) const;
     620    WebCore::IntSize contentsSize() const;
    619621
    620622    void resetSavedScrollAndScaleState();
  • trunk/Source/WebKit/chromium/tests/WebFrameTest.cpp

    r141019 r141053  
    3838#include "FrameView.h"
    3939#include "Range.h"
     40#include "RenderView.h"
    4041#include "ResourceError.h"
    4142#include "Settings.h"
     
    308309}
    309310
     311TEST_F(WebFrameTest, setPageScaleFactorDoesNotLayout)
     312{
     313    registerMockedHttpURLLoad("fixed_layout.html");
     314
     315    FixedLayoutTestWebViewClient client;
     316    client.m_screenInfo.deviceScaleFactor = 1;
     317    int viewportWidth = 640;
     318    int viewportHeight = 480;
     319
     320    WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout.html", true, 0, &client));
     321    webViewImpl->settings()->setApplyDeviceScaleFactorInCompositor(true);
     322    webViewImpl->settings()->setApplyPageScaleFactorInCompositor(true);
     323    webViewImpl->enableFixedLayoutMode(true);
     324    webViewImpl->settings()->setViewportEnabled(true);
     325    webViewImpl->resize(WebSize(viewportWidth, viewportHeight));
     326    webViewImpl->layout();
     327
     328    int prevLayoutCount = webViewImpl->mainFrameImpl()->frameView()->layoutCount();
     329    webViewImpl->setPageScaleFactor(3, WebPoint());
     330    EXPECT_EQ(false, webViewImpl->mainFrameImpl()->frameView()->needsLayout());
     331    EXPECT_EQ(prevLayoutCount, webViewImpl->mainFrameImpl()->frameView()->layoutCount());
     332}
     333
     334TEST_F(WebFrameTest, pageScaleFactorWrittenToHistoryItem)
     335{
     336    registerMockedHttpURLLoad("fixed_layout.html");
     337
     338    FixedLayoutTestWebViewClient client;
     339    client.m_screenInfo.deviceScaleFactor = 1;
     340    int viewportWidth = 640;
     341    int viewportHeight = 480;
     342
     343    WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout.html", true, 0, &client));
     344    webViewImpl->settings()->setApplyDeviceScaleFactorInCompositor(true);
     345    webViewImpl->settings()->setApplyPageScaleFactorInCompositor(true);
     346    webViewImpl->enableFixedLayoutMode(true);
     347    webViewImpl->settings()->setViewportEnabled(true);
     348    webViewImpl->resize(WebSize(viewportWidth, viewportHeight));
     349    webViewImpl->layout();
     350
     351    webViewImpl->setPageScaleFactor(3, WebPoint());
     352    webViewImpl->page()->mainFrame()->loader()->history()->saveDocumentAndScrollState();
     353    webViewImpl->setPageScaleFactor(1, WebPoint());
     354    webViewImpl->page()->mainFrame()->loader()->history()->restoreScrollPositionAndViewState();
     355    EXPECT_EQ(3, webViewImpl->pageScaleFactor());
     356}
     357
     358TEST_F(WebFrameTest, pageScaleFactorShrinksViewport)
     359{
     360    registerMockedHttpURLLoad("fixed_layout.html");
     361
     362    FixedLayoutTestWebViewClient client;
     363    client.m_screenInfo.deviceScaleFactor = 1;
     364    int viewportWidth = 640;
     365    int viewportHeight = 480;
     366    int viewportWidthMinusScrollbar = 640 - 15;
     367    int viewportHeightMinusScrollbar = 480 - 15;
     368
     369    WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout.html", true, 0, &client));
     370    webViewImpl->settings()->setApplyDeviceScaleFactorInCompositor(true);
     371    webViewImpl->settings()->setApplyPageScaleFactorInCompositor(true);
     372    webViewImpl->enableFixedLayoutMode(true);
     373    webViewImpl->settings()->setViewportEnabled(true);
     374    webViewImpl->resize(WebSize(viewportWidth, viewportHeight));
     375    webViewImpl->layout();
     376
     377    webViewImpl->setPageScaleFactor(2, WebPoint());
     378
     379    WebCore::IntSize unscaledSize = webViewImpl->mainFrameImpl()->frameView()->unscaledVisibleContentSize(true);
     380    EXPECT_EQ(viewportWidth, unscaledSize.width());
     381    EXPECT_EQ(viewportHeight, unscaledSize.height());
     382
     383    WebCore::IntSize unscaledSizeMinusScrollbar = webViewImpl->mainFrameImpl()->frameView()->unscaledVisibleContentSize(false);
     384    EXPECT_EQ(viewportWidthMinusScrollbar, unscaledSizeMinusScrollbar.width());
     385    EXPECT_EQ(viewportHeightMinusScrollbar, unscaledSizeMinusScrollbar.height());
     386
     387    WebCore::IntSize scaledSize = webViewImpl->mainFrameImpl()->frameView()->visibleContentRect().size();
     388    EXPECT_EQ(ceil(viewportWidthMinusScrollbar / 2.0), scaledSize.width());
     389    EXPECT_EQ(ceil(viewportHeightMinusScrollbar / 2.0), scaledSize.height());
     390}
     391
     392TEST_F(WebFrameTest, pageScaleFactorDoesNotApplyCssTransform)
     393{
     394    registerMockedHttpURLLoad("fixed_layout.html");
     395
     396    FixedLayoutTestWebViewClient client;
     397    client.m_screenInfo.deviceScaleFactor = 1;
     398    int viewportWidth = 640;
     399    int viewportHeight = 480;
     400
     401    WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout.html", true, 0, &client));
     402    webViewImpl->settings()->setApplyDeviceScaleFactorInCompositor(true);
     403    webViewImpl->settings()->setApplyPageScaleFactorInCompositor(true);
     404    webViewImpl->enableFixedLayoutMode(true);
     405    webViewImpl->settings()->setViewportEnabled(true);
     406    webViewImpl->resize(WebSize(viewportWidth, viewportHeight));
     407    webViewImpl->layout();
     408
     409    webViewImpl->setPageScaleFactor(2, WebPoint());
     410
     411    EXPECT_EQ(1, webViewImpl->page()->mainFrame()->frameScaleFactor());
     412    EXPECT_EQ(980, webViewImpl->page()->mainFrame()->contentRenderer()->unscaledDocumentRect().width());
     413    EXPECT_EQ(980, webViewImpl->mainFrameImpl()->frameView()->contentsSize().width());
     414}
    310415#endif
    311416
     
    785890    webViewImpl->applyScrollAndScale(WebSize(), 1.1f);
    786891    // 1 < textAutosizingFontScaleFactor < minimumPageScale < doubleTapZoomAlreadyLegibleScale
    787     webView->setPageScaleFactorLimits(1.2f, 4);
     892    webView->setPageScaleFactorLimits(1.0f, 4);
    788893    doubleTapZoomAlreadyLegibleScale = webViewImpl->minimumPageScaleFactor() * doubleTapZoomAlreadyLegibleRatio;
    789894    setScaleAndScrollAndLayout(webViewImpl, WebPoint(0, 0), (webViewImpl->minimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2);
Note: See TracChangeset for help on using the changeset viewer.