Changeset 52311 in webkit


Ignore:
Timestamp:
Dec 18, 2009 7:04:00 AM (14 years ago)
Author:
eric@webkit.org
Message:

2009-12-18 Joe Ligman <joseph.ligman@nokia.com>

Reviewed by Kenneth Rohde Christiansen.

[Qt] Add new API to QWebFrame to scrollRecursively starting with any css overflow
then checking current frame and then ancestors
https://bugs.webkit.org/show_bug.cgi?id=32668

  • Api/qwebframe.cpp: (QWebFramePrivate::scrollOverflow): (QWebFrame::scrollRecursively):
  • Api/qwebframe.h:
  • Api/qwebframe_p.h:
  • tests/qwebframe/qwebframe.qrc:
  • tests/qwebframe/testiframe.html: Added.
  • tests/qwebframe/testiframe2.html: Added.
  • tests/qwebframe/tst_qwebframe.cpp:
Location:
trunk/WebKit/qt
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/qt/Api/qwebframe.cpp

    r51698 r52311  
    362362}
    363363
     364bool QWebFramePrivate::scrollOverflow(int dx, int dy)
     365{
     366    if (!frame || !frame->document() || !frame->eventHandler())
     367        return false;
     368
     369    Node* node = frame->document()->focusedNode();
     370    if (!node)
     371        node = frame->document()->elementFromPoint(frame->eventHandler()->currentMousePosition().x(),
     372                                                   frame->eventHandler()->currentMousePosition().y());
     373    if (!node)
     374        return false;
     375
     376    RenderObject* renderer = node->renderer();
     377    if (!renderer)
     378        return false;
     379
     380    if (renderer->isListBox())
     381        return false;
     382
     383    RenderLayer* renderLayer = renderer->enclosingLayer();
     384    if (!renderLayer)
     385        return false;
     386
     387    bool scrolledHorizontal = false;
     388    bool scrolledVertical = false;
     389
     390    if (dx > 0)
     391        scrolledHorizontal = renderLayer->scroll(ScrollRight, ScrollByPixel, dx);
     392    else if (dx < 0)
     393        scrolledHorizontal = renderLayer->scroll(ScrollLeft, ScrollByPixel, qAbs(dx));
     394
     395    if (dy > 0)
     396        scrolledVertical = renderLayer->scroll(ScrollDown, ScrollByPixel, dy);
     397    else if (dy < 0)
     398        scrolledVertical = renderLayer->scroll(ScrollUp, ScrollByPixel, qAbs(dy));
     399
     400    return (scrolledHorizontal || scrolledVertical);
     401}
     402
    364403/*!
    365404    \class QWebFrame
     
    10011040
    10021041/*!
     1042  \since 4.7
     1043  Scrolls nested frames starting at this frame, \a dx pixels to the right
     1044  and \a dy pixels downward. Both \a dx and \a dy may be negative. First attempts
     1045  to scroll elements with CSS overflow followed by this frame. If this
     1046  frame doesn't scroll, attempts to scroll the parent
     1047
     1048  \sa QWebFrame::scroll
     1049*/
     1050bool QWebFrame::scrollRecursively(int dx, int dy)
     1051{
     1052    bool scrolledHorizontal = false;
     1053    bool scrolledVertical = false;
     1054    bool scrolledOverflow = d->scrollOverflow(dx, dy);
     1055
     1056    if (!scrolledOverflow) {
     1057        Frame* frame = d->frame;
     1058        if (!frame || !frame->view())
     1059            return false;
     1060
     1061        do {
     1062            IntSize scrollOffset = frame->view()->scrollOffset();
     1063            IntPoint maxScrollOffset = frame->view()->maximumScrollPosition();
     1064
     1065            if (dx > 0) // scroll right
     1066                scrolledHorizontal = scrollOffset.width() < maxScrollOffset.x();
     1067            else if (dx < 0) // scroll left
     1068                scrolledHorizontal = scrollOffset.width() > 0;
     1069
     1070            if (dy > 0) // scroll down
     1071                scrolledVertical = scrollOffset.height() < maxScrollOffset.y();
     1072            else if (dy < 0) //scroll up
     1073                scrolledVertical = scrollOffset.height() > 0;
     1074
     1075            if (scrolledHorizontal || scrolledVertical) {
     1076                frame->view()->scrollBy(IntSize(dx, dy));
     1077                return true;
     1078            }
     1079            frame = frame->tree()->parent();
     1080        } while (frame && frame->view());
     1081    }
     1082    return (scrolledHorizontal || scrolledVertical || scrolledOverflow);
     1083}
     1084
     1085/*!
    10031086  \property QWebFrame::scrollPosition
    10041087  \since 4.5
  • trunk/WebKit/qt/Api/qwebframe.h

    r51174 r52311  
    157157
    158158    void scroll(int, int);
     159    bool scrollRecursively(int, int);
    159160    QPoint scrollPosition() const;
    160161    void setScrollPosition(const QPoint &pos);
  • trunk/WebKit/qt/Api/qwebframe_p.h

    r51698 r52311  
    8686    void renderContentsLayerAbsoluteCoords(WebCore::GraphicsContext*, const QRegion& clip);
    8787
     88    bool scrollOverflow(int dx, int dy);
     89
    8890    QWebFrame *q;
    8991    Qt::ScrollBarPolicy horizontalScrollBarPolicy;
  • trunk/WebKit/qt/ChangeLog

    r52307 r52311  
     12009-12-18  Joe Ligman  <joseph.ligman@nokia.com>
     2
     3        Reviewed by Kenneth Rohde Christiansen.
     4
     5        [Qt] Add new API to QWebFrame to scrollRecursively starting with any css overflow
     6        then checking current frame and then ancestors
     7        https://bugs.webkit.org/show_bug.cgi?id=32668
     8
     9        * Api/qwebframe.cpp:
     10        (QWebFramePrivate::scrollOverflow):
     11        (QWebFrame::scrollRecursively):
     12        * Api/qwebframe.h:
     13        * Api/qwebframe_p.h:
     14        * tests/qwebframe/qwebframe.qrc:
     15        * tests/qwebframe/testiframe.html: Added.
     16        * tests/qwebframe/testiframe2.html: Added.
     17        * tests/qwebframe/tst_qwebframe.cpp:
     18
    1192009-12-18  Simon Hausmann  <simon.hausmann@nokia.com>
    220
  • trunk/WebKit/qt/tests/qwebframe/qwebframe.qrc

    r46364 r52311  
    55<file>test1.html</file>
    66<file>test2.html</file>
     7<file>testiframe.html</file>
     8<file>testiframe2.html</file>
    79</qresource>
    810</RCC>
  • trunk/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp

    r52069 r52311  
    577577    void evaluateWillCauseRepaint();
    578578    void qObjectWrapperWithSameIdentity();
     579    void scrollRecursively();
    579580
    580581private:
     
    27962797}
    27972798
     2799void tst_QWebFrame::scrollRecursively()
     2800{
     2801    // The test content is
     2802    // a nested frame set
     2803    // The main frame scrolls
     2804    // and has two children
     2805    // an iframe and a div overflow
     2806    // both scroll
     2807    QWebView webView;
     2808    QWebPage* webPage = webView.page();
     2809    QSignalSpy loadSpy(webPage, SIGNAL(loadFinished(bool)));
     2810    QUrl url = QUrl("qrc:///testiframe.html");
     2811    webPage->mainFrame()->load(url);
     2812    QTRY_COMPARE(loadSpy.count(), 1);
     2813
     2814    QList<QWebFrame*> children =  webPage->mainFrame()->childFrames();
     2815    QVERIFY(children.count() == 1);
     2816
     2817    // 1st test
     2818    // call scrollRecursively over mainframe
     2819    // verify scrolled
     2820    // verify scroll postion changed
     2821    QPoint scrollPosition(webPage->mainFrame()->scrollPosition());
     2822    QVERIFY(webPage->mainFrame()->scrollRecursively(10, 10));
     2823    QVERIFY(scrollPosition != webPage->mainFrame()->scrollPosition());
     2824
     2825    // 2nd test
     2826    // call scrollRecursively over child iframe
     2827    // verify scrolled
     2828    // verify child scroll position changed
     2829    // verify parent's scroll position did not change
     2830    scrollPosition = webPage->mainFrame()->scrollPosition();
     2831    QPoint childScrollPosition = children.at(0)->scrollPosition();
     2832    QVERIFY(children.at(0)->scrollRecursively(10, 10));
     2833    QVERIFY(scrollPosition == webPage->mainFrame()->scrollPosition());
     2834    QVERIFY(childScrollPosition != children.at(0)->scrollPosition());
     2835
     2836    // 3rd test
     2837    // call scrollRecursively over div overflow
     2838    // verify scrolled == true
     2839    // verify parent and child frame's scroll postion did not change
     2840    QWebElement div = webPage->mainFrame()->documentElement().findFirst("#content1");
     2841    QMouseEvent evpres(QEvent::MouseMove, div.geometry().center(), Qt::NoButton, Qt::NoButton, Qt::NoModifier);
     2842    webPage->event(&evpres);
     2843    scrollPosition = webPage->mainFrame()->scrollPosition();
     2844    childScrollPosition = children.at(0)->scrollPosition();
     2845    QVERIFY(webPage->mainFrame()->scrollRecursively(5, 5));
     2846    QVERIFY(childScrollPosition == children.at(0)->scrollPosition());
     2847    QVERIFY(scrollPosition == webPage->mainFrame()->scrollPosition());
     2848
     2849    // 4th test
     2850    // call scrollRecursively twice over childs iframe
     2851    // verify scrolled == true first time
     2852    // verify parent's scroll == true second time
     2853    // verify parent and childs scroll position changed
     2854    childScrollPosition = children.at(0)->scrollPosition();
     2855    QVERIFY(children.at(0)->scrollRecursively(-10, -10));
     2856    QVERIFY(childScrollPosition != children.at(0)->scrollPosition());
     2857    scrollPosition = webPage->mainFrame()->scrollPosition();
     2858    QVERIFY(children.at(0)->scrollRecursively(-10, -10));
     2859    QVERIFY(scrollPosition != webPage->mainFrame()->scrollPosition());
     2860
     2861}
     2862
    27982863QTEST_MAIN(tst_QWebFrame)
    27992864#include "tst_qwebframe.moc"
Note: See TracChangeset for help on using the changeset viewer.