Changeset 52311 in webkit
- Timestamp:
- Dec 18, 2009 7:04:00 AM (14 years ago)
- Location:
- trunk/WebKit/qt
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebKit/qt/Api/qwebframe.cpp
r51698 r52311 362 362 } 363 363 364 bool 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 364 403 /*! 365 404 \class QWebFrame … … 1001 1040 1002 1041 /*! 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 */ 1050 bool 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 /*! 1003 1086 \property QWebFrame::scrollPosition 1004 1087 \since 4.5 -
trunk/WebKit/qt/Api/qwebframe.h
r51174 r52311 157 157 158 158 void scroll(int, int); 159 bool scrollRecursively(int, int); 159 160 QPoint scrollPosition() const; 160 161 void setScrollPosition(const QPoint &pos); -
trunk/WebKit/qt/Api/qwebframe_p.h
r51698 r52311 86 86 void renderContentsLayerAbsoluteCoords(WebCore::GraphicsContext*, const QRegion& clip); 87 87 88 bool scrollOverflow(int dx, int dy); 89 88 90 QWebFrame *q; 89 91 Qt::ScrollBarPolicy horizontalScrollBarPolicy; -
trunk/WebKit/qt/ChangeLog
r52307 r52311 1 2009-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 1 19 2009-12-18 Simon Hausmann <simon.hausmann@nokia.com> 2 20 -
trunk/WebKit/qt/tests/qwebframe/qwebframe.qrc
r46364 r52311 5 5 <file>test1.html</file> 6 6 <file>test2.html</file> 7 <file>testiframe.html</file> 8 <file>testiframe2.html</file> 7 9 </qresource> 8 10 </RCC> -
trunk/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp
r52069 r52311 577 577 void evaluateWillCauseRepaint(); 578 578 void qObjectWrapperWithSameIdentity(); 579 void scrollRecursively(); 579 580 580 581 private: … … 2796 2797 } 2797 2798 2799 void 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 2798 2863 QTEST_MAIN(tst_QWebFrame) 2799 2864 #include "tst_qwebframe.moc"
Note: See TracChangeset
for help on using the changeset viewer.