2011-02-05 Anders Carlsson <andersca@apple.com>
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 Feb 2011 22:28:02 +0000 (22:28 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 Feb 2011 22:28:02 +0000 (22:28 +0000)
        Reviewed by Darin Adler.

        Need a way to resize and scroll the page at the same time
        https://bugs.webkit.org/show_bug.cgi?id=53814
        <rdar://problem/8498008>

        Export a function needed by WebKit2.

        * WebCore.exp.in:
2011-02-05  Anders Carlsson  <andersca@apple.com>

        Reviewed by Darin Adler.

        Need a way to resize and scroll the page at the same time
        https://bugs.webkit.org/show_bug.cgi?id=53814
        <rdar://problem/8498008>

        Add -[WKView setFrame:andScrollBy:].

        * UIProcess/API/mac/WKView.h:
        * UIProcess/API/mac/WKView.mm:
        (-[WKView setFrame:andScrollBy:]):
        Stash away the scroll offset and call setFrame:.

        (-[WKView _switchToDrawingAreaTypeIfNecessary:DrawingAreaInfo::]):
        (-[WKView _setDrawingAreaSize:]):
        * UIProcess/API/qt/qwkpage.cpp:
        (QWKPage::setViewportSize):
        DrawingAreaProxy::setSize now takes a scroll offset.

        * UIProcess/DrawingAreaProxy.cpp:
        (WebKit::DrawingAreaProxy::setSize):
        This now takes a scroll offset and stores it in m_scrollOffset.

        * UIProcess/DrawingAreaProxy.h:
        * UIProcess/DrawingAreaProxyImpl.cpp:
        (WebKit::DrawingAreaProxyImpl::sendSetSize):
        Send along the scroll offset and set it back to zero.

        * UIProcess/LayerBackedDrawingAreaProxy.cpp:
        (WebKit::LayerBackedDrawingAreaProxy::didSetSize):
        * UIProcess/TiledDrawingAreaProxy.cpp:
        (WebKit::TiledDrawingAreaProxy::didSetSize):
        * UIProcess/win/WebView.cpp:
        (WebKit::WebView::onSizeEvent):
        (WebKit::WebView::switchToDrawingAreaTypeIfNecessary):
        DrawingAreaProxy::setSize now takes a scroll offset.

        * WebProcess/WebPage/DrawingArea.h:
        (WebKit::DrawingArea::setSize):
        Add a scrollOffset parameter.

        * WebProcess/WebPage/DrawingArea.messages.in:
        Add a scroll offset parameter to the SetSize message.

        * WebProcess/WebPage/DrawingAreaImpl.cpp:
        (WebKit::DrawingAreaImpl::setSize):
        Call WebPage::scrollMainFrameIfNotAtMaxScrollPosition.

        * WebProcess/WebPage/DrawingAreaImpl.h:
        * WebProcess/WebPage/WebPage.cpp:
        (WebKit::WebPage::scrollMainFrameIfNotAtMaxScrollPosition):
        Compute a scroll offset and call setScrollPosition on the main frame view.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@77751 268f45cc-cd09-0410-ab3c-d52691b4dbfc

18 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/mac/WKView.h
Source/WebKit2/UIProcess/API/mac/WKView.mm
Source/WebKit2/UIProcess/API/qt/qwkpage.cpp
Source/WebKit2/UIProcess/DrawingAreaProxy.cpp
Source/WebKit2/UIProcess/DrawingAreaProxy.h
Source/WebKit2/UIProcess/DrawingAreaProxyImpl.cpp
Source/WebKit2/UIProcess/LayerBackedDrawingAreaProxy.cpp
Source/WebKit2/UIProcess/TiledDrawingAreaProxy.cpp
Source/WebKit2/UIProcess/win/WebView.cpp
Source/WebKit2/WebProcess/WebPage/DrawingArea.h
Source/WebKit2/WebProcess/WebPage/DrawingArea.messages.in
Source/WebKit2/WebProcess/WebPage/DrawingAreaImpl.cpp
Source/WebKit2/WebProcess/WebPage/DrawingAreaImpl.h
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h

index 853ba5dd36ab94ded979228bb315be621fed99df..f68c792ca3de0f7c70b14ce92290ac764c5e1ba4 100644 (file)
@@ -1,3 +1,15 @@
+2011-02-05  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Darin Adler.
+
+        Need a way to resize and scroll the page at the same time
+        https://bugs.webkit.org/show_bug.cgi?id=53814
+        <rdar://problem/8498008>
+
+        Export a function needed by WebKit2.
+
+        * WebCore.exp.in:
+
 2011-02-05  Patrick Gansterer  <paroga@webkit.org>
 
         Reviewed by Alexey Proskuryakov.
index 637afbd2d548ce878333d34ca1d4c78eb447580e..8e5789be07dca26342ea85545476f1718d40797b 100644 (file)
@@ -870,6 +870,7 @@ __ZN7WebCore9FrameView14setNeedsLayoutEv
 __ZN7WebCore9FrameView14setTransparentEb
 __ZN7WebCore9FrameView15setMarginHeightEi
 __ZN7WebCore9FrameView16setPaintBehaviorEj
+__ZN7WebCore9FrameView17setScrollPositionERKNS_8IntPointE
 __ZN7WebCore9FrameView18updateControlTintsEv
 __ZN7WebCore9FrameView20enterCompositingModeEv
 __ZN7WebCore9FrameView21flushDeferredRepaintsEv
index 3fdc413ea95202e6b35aae249590d7fc6069515b..41ebb56494bf76729c3444a7be7fcff93a9d1836 100644 (file)
@@ -1,3 +1,58 @@
+2011-02-05  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Darin Adler.
+
+        Need a way to resize and scroll the page at the same time
+        https://bugs.webkit.org/show_bug.cgi?id=53814
+        <rdar://problem/8498008>
+
+        Add -[WKView setFrame:andScrollBy:].
+
+        * UIProcess/API/mac/WKView.h:
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView setFrame:andScrollBy:]):
+        Stash away the scroll offset and call setFrame:.
+
+        (-[WKView _switchToDrawingAreaTypeIfNecessary:DrawingAreaInfo::]):
+        (-[WKView _setDrawingAreaSize:]):
+        * UIProcess/API/qt/qwkpage.cpp:
+        (QWKPage::setViewportSize):
+        DrawingAreaProxy::setSize now takes a scroll offset.
+
+        * UIProcess/DrawingAreaProxy.cpp:
+        (WebKit::DrawingAreaProxy::setSize):
+        This now takes a scroll offset and stores it in m_scrollOffset.
+
+        * UIProcess/DrawingAreaProxy.h:
+        * UIProcess/DrawingAreaProxyImpl.cpp:
+        (WebKit::DrawingAreaProxyImpl::sendSetSize):
+        Send along the scroll offset and set it back to zero.
+
+        * UIProcess/LayerBackedDrawingAreaProxy.cpp:
+        (WebKit::LayerBackedDrawingAreaProxy::didSetSize):
+        * UIProcess/TiledDrawingAreaProxy.cpp:
+        (WebKit::TiledDrawingAreaProxy::didSetSize):
+        * UIProcess/win/WebView.cpp:
+        (WebKit::WebView::onSizeEvent):
+        (WebKit::WebView::switchToDrawingAreaTypeIfNecessary):
+        DrawingAreaProxy::setSize now takes a scroll offset.
+        
+        * WebProcess/WebPage/DrawingArea.h:
+        (WebKit::DrawingArea::setSize):
+        Add a scrollOffset parameter.
+
+        * WebProcess/WebPage/DrawingArea.messages.in:
+        Add a scroll offset parameter to the SetSize message.
+
+        * WebProcess/WebPage/DrawingAreaImpl.cpp:
+        (WebKit::DrawingAreaImpl::setSize):
+        Call WebPage::scrollMainFrameIfNotAtMaxScrollPosition.
+
+        * WebProcess/WebPage/DrawingAreaImpl.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::scrollMainFrameIfNotAtMaxScrollPosition):
+        Compute a scroll offset and call setScrollPosition on the main frame view.
+
 2011-02-04  Brian Weinstein  <bweinstein@apple.com>
 
         Reviewed by Maciej Stachowiak.
index 5fb0d4694b3f416ec6eaaf8edf92132c173a073e..8c1826c6a8384b9d80ecb4474b6d4d19832a12ef 100644 (file)
@@ -40,6 +40,8 @@ WK_EXPORT
 - (NSPrintOperation *)printOperationWithPrintInfo:(NSPrintInfo *)printInfo forFrame:(WKFrameRef)frameRef;
 - (BOOL)canChangeFrameLayout:(WKFrameRef)frameRef;
 
+- (void)setFrame:(NSRect)rect andScrollBy:(NSSize)offset;
+
 @property(readonly) WKPageRef pageRef;
 
 @property BOOL drawsBackground;
index c8aabffb5914d090de6b8e3e3d131ef6770ecca5..45e797124c46bfd9f80e0c75aeef97c379a3046c 100644 (file)
@@ -128,6 +128,8 @@ typedef HashMap<String, ValidationVector> ValidationMap;
     NSEvent *_keyDownEventBeingResent;
     Vector<KeypressCommand> _commandsList;
 
+    NSSize _resizeScrollOffset;
+
     // The identifier of the plug-in we want to send complex text input to, or 0 if there is none.
     uint64_t _pluginComplexTextInputIdentifier;
 
@@ -304,6 +306,14 @@ static bool useNewDrawingArea()
 #endif
 }
 
+- (void)setFrame:(NSRect)rect andScrollBy:(NSSize)offset
+{
+    ASSERT(NSEqualSizes(_data->_resizeScrollOffset, NSZeroSize));
+
+    _data->_resizeScrollOffset = offset;
+    [self setFrame:rect];
+}
+
 - (void)setFrameSize:(NSSize)size
 {
     [super setFrameSize:size];
@@ -1852,7 +1862,7 @@ static void drawPageBackground(CGContextRef context, WebPageProxy* page, const I
         }
     }
 
-    newDrawingArea->setSize(IntSize([self frame].size));
+    newDrawingArea->setSize(IntSize([self frame].size), IntSize());
 
     _data->_page->drawingArea()->detachCompositingContext();
     _data->_page->setDrawingArea(newDrawingArea.release());
@@ -1991,7 +2001,8 @@ static void drawPageBackground(CGContextRef context, WebPageProxy* page, const I
     if (!_data->_page->drawingArea())
         return;
     
-    _data->_page->drawingArea()->setSize(IntSize(size));
+    _data->_page->drawingArea()->setSize(IntSize(size), IntSize(_data->_resizeScrollOffset));
+    _data->_resizeScrollOffset = NSZeroSize;
 }
 
 @end
index 0d192d69554e822d40b1f47750b1aada0448d079..16e1cdde73deded0a9fb356f20417d7f301613e5 100644 (file)
@@ -644,7 +644,7 @@ QString QWKPage::title() const
 void QWKPage::setViewportSize(const QSize& size)
 {
     if (d->page->drawingArea())
-        d->page->drawingArea()->setSize(IntSize(size));
+        d->page->drawingArea()->setSize(IntSize(size), IntSize());
 }
 
 qreal QWKPage::textZoomFactor() const
index 1be9554c1c5a729b159210b1d0d33387113a4694..3d1f1aabbe1d881094f23b9073a2bb5adb8dd03b 100644 (file)
@@ -48,12 +48,13 @@ DrawingAreaInfo::Identifier DrawingAreaProxy::nextIdentifier()
     return ++nextID;
 }
 
-void DrawingAreaProxy::setSize(const IntSize& size)
+void DrawingAreaProxy::setSize(const IntSize& size, const IntSize& scrollOffset)
 { 
-    if (m_size == size)
+    if (m_size == size && scrollOffset.isZero())
         return;
 
     m_size = size;
+    m_scrollOffset += scrollOffset;
     sizeDidChange();
 }
 
index 2bc5423a2f3fb712573ee2c5ec939ac932504aa3..bd6f90cde0a687629a08c0ef129d770a5bbc0ca6 100644 (file)
@@ -83,7 +83,7 @@ public:
     const DrawingAreaInfo& info() const { return m_info; }
 
     const WebCore::IntSize& size() const { return m_size; }
-    void setSize(const WebCore::IntSize&);
+    void setSize(const WebCore::IntSize&, const WebCore::IntSize& scrollOffset);
 
 protected:
     explicit DrawingAreaProxy(DrawingAreaInfo::Type, WebPageProxy*);
@@ -92,6 +92,7 @@ protected:
     WebPageProxy* m_webPageProxy;
 
     WebCore::IntSize m_size;
+    WebCore::IntSize m_scrollOffset;
 
 private:
     // CoreIPC message handlers.
index 5924a41d4d06c3dbf52f3407510826fe08a331b9..dc8a087b5811c2b7d3a190cea638a73c988041e6 100644 (file)
@@ -225,7 +225,8 @@ void DrawingAreaProxyImpl::sendSetSize()
         return;
 
     m_isWaitingForDidSetSize = true;
-    m_webPageProxy->process()->send(Messages::DrawingArea::SetSize(m_size), m_webPageProxy->pageID());
+    m_webPageProxy->process()->send(Messages::DrawingArea::SetSize(m_size, m_scrollOffset), m_webPageProxy->pageID());
+    m_scrollOffset = IntSize();
 
     if (!m_layerTreeContext.isEmpty()) {
         // Wait for the DidSetSize message. Normally we don this in DrawingAreaProxyImpl::paint, but that
index fc514b83a1ac4a93056680cbc8ac7f6777197b70..2d38aa424928f0b6e55089d69adc9e9e443734f8 100644 (file)
@@ -118,7 +118,7 @@ void LayerBackedDrawingAreaProxy::didSetSize(const IntSize& size)
     m_isWaitingForDidSetFrameNotification = false;
 
     if (size != m_lastSetViewSize)
-        setSize(m_lastSetViewSize);
+        setSize(m_lastSetViewSize, IntSize());
 }
 
 void LayerBackedDrawingAreaProxy::update()
index 3a5fcb22fb5b3276a9fd08de82c82ab9e84c54a0..97349eb304c2bd328a33693ec6bbe65b41095282 100644 (file)
@@ -115,7 +115,7 @@ void TiledDrawingAreaProxy::didSetSize(const IntSize& viewSize)
     m_isWaitingForDidSetFrameNotification = false;
 
     if (viewSize != m_lastSetViewSize)
-        setSize(m_lastSetViewSize);
+        setSize(m_lastSetViewSize, IntSize());
 
     WebPageProxy* page = this->page();
     page->process()->responsivenessTimer()->stop();
index 4313b81f782f2b2284fa61f56549058f0785fc65..fc73d9a295a1376b33cf916a44fda83bf285e9ca 100644 (file)
@@ -434,7 +434,7 @@ LRESULT WebView::onSizeEvent(HWND, UINT, WPARAM, LPARAM lParam, bool& handled)
     int height = HIWORD(lParam);
 
     if (m_page->drawingArea())
-        m_page->drawingArea()->setSize(IntSize(width, height));
+        m_page->drawingArea()->setSize(IntSize(width, height), IntSize());
 
     handled = true;
     return 0;
@@ -1133,7 +1133,7 @@ void WebView::switchToDrawingAreaTypeIfNecessary(DrawingAreaInfo::Type type)
     }
 
     if (m_page->drawingArea())
-        newDrawingArea->setSize(m_page->drawingArea()->size());
+        newDrawingArea->setSize(m_page->drawingArea()->size(), IntSize());
 
     m_page->drawingArea()->detachCompositingContext();
     m_page->setDrawingArea(newDrawingArea.release());
index 8c41390d9450d3297b1876c6ccc432b7b1828a4a..247c156c4389cc29b988f64e2dfad7683d306b36 100644 (file)
@@ -80,7 +80,7 @@ protected:
 private:
     // CoreIPC message handlers.
     // FIXME: These should be pure virtual.
-    virtual void setSize(const WebCore::IntSize&) { }
+    virtual void setSize(const WebCore::IntSize& size, const WebCore::IntSize& scrollOffset) { }
     virtual void didUpdate() { }
     virtual void suspendPainting() { }
     virtual void resumePainting() { }
index 682ef5af7c70655f84a054b20725550a9f17a93e..ec09e18c61cb24ef7fba17b5f15ad542c5c53fe3 100644 (file)
@@ -21,7 +21,7 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 messages -> DrawingArea {
-    SetSize(WebCore::IntSize size)
+    SetSize(WebCore::IntSize size, WebCore::IntSize scrollOffset)
     DidUpdate()
     SuspendPainting()
     ResumePainting()
index acfd633da672b5cdf1aaf80dc3140a0ff3ab3c55..dd840b7b99d381c31d7c3d7a63d70f81bb28e928 100644 (file)
@@ -171,7 +171,7 @@ void DrawingAreaImpl::didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID
 {
 }
 
-void DrawingAreaImpl::setSize(const IntSize& size)
+void DrawingAreaImpl::setSize(const WebCore::IntSize& size, const WebCore::IntSize& scrollOffset)
 {
     ASSERT(!m_inSetSize);
     m_inSetSize = true;
@@ -181,6 +181,7 @@ void DrawingAreaImpl::setSize(const IntSize& size)
 
     m_webPage->setSize(size);
     m_webPage->layoutIfNeeded();
+    m_webPage->scrollMainFrameIfNotAtMaxScrollPosition(scrollOffset);
 
     UpdateInfo updateInfo;
     LayerTreeContext layerTreeContext;
index 5074eac03418419c1ebe3613443fbee169ff1445..7d57318d55e76616587d1402277f8f9ddc8ce323 100644 (file)
@@ -55,7 +55,7 @@ private:
     virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
 
     // CoreIPC message handlers.
-    virtual void setSize(const WebCore::IntSize&);
+    virtual void setSize(const WebCore::IntSize&, const WebCore::IntSize& scrollOffset);
     virtual void didUpdate();
     virtual void suspendPainting();
     virtual void resumePainting();
index cadf1923f21f597e739eec4649f25a3e30924668..9e843336ae1b6caa2a07f0cc9193e159fce7b155 100644 (file)
@@ -560,6 +560,27 @@ void WebPage::resizeToContentsIfNeeded()
 }
 #endif
 
+void WebPage::scrollMainFrameIfNotAtMaxScrollPosition(const IntSize& scrollOffset)
+{
+    Frame* frame = m_page->mainFrame();
+
+    IntPoint scrollPosition = frame->view()->scrollPosition();
+    IntPoint maximumScrollPosition = frame->view()->maximumScrollPosition();
+
+    // If the current scroll position in a direction is the max scroll position 
+    // we don't want to scroll at all.
+    IntSize newScrollOffset;
+    if (scrollPosition.x() < maximumScrollPosition.x())
+        newScrollOffset.setWidth(scrollOffset.width());
+    if (scrollPosition.y() < maximumScrollPosition.y())
+        newScrollOffset.setHeight(scrollOffset.height());
+
+    if (newScrollOffset.isZero())
+        return;
+
+    frame->view()->setScrollPosition(frame->view()->scrollPosition() + newScrollOffset);
+}
+
 void WebPage::drawRect(GraphicsContext& graphicsContext, const IntRect& rect)
 {
     graphicsContext.save();
index 1ac47c0b326188ce3b98d6c0c064564f1c61d6a2..21a059d237ddd81cd2a18684f775b3c631cc7375 100644 (file)
@@ -129,6 +129,8 @@ public:
 
     WebPageGroupProxy* pageGroup() const { return m_pageGroup.get(); }
 
+    void scrollMainFrameIfNotAtMaxScrollPosition(const WebCore::IntSize& scrollOffset);
+
 #if ENABLE(INSPECTOR)
     WebInspector* inspector();
 #endif