Title: [89605] trunk/Source/WebKit2
Revision
89605
Author
[email protected]
Date
2011-06-23 12:54:25 -0700 (Thu, 23 Jun 2011)

Log Message

2011-06-23 Jamie Cooley  <[email protected]>

        Reviewed by Andreas Kling.

        [Qt][WK2] Qt port needs load-from-history implementation
        https://bugs.webkit.org/show_bug.cgi?id=57784

        Created "random access" BackForwardHistory public API method,
        QWKHistory::goToItemAt(int)

        * UIProcess/API/qt/qwkhistory.cpp:
        (QWKHistoryItem::QWKHistoryItem::itemRef):
        Added access method to fetch WKBackForwardListRef

        (QWKHistoryPrivate::QWKHistoryPrivate):
        (QWKHistoryPrivate::createHistory):
        Updated createHistory method and QWKHistoryPrivate constructor to take a pointer
        to the owning QWKPage in addition to the WebBackForwardList. This will be saved so that the
        new API can ask the page to load a HistoryItem.

        (QWKHistory::goToItemAt):
        New Public API. Like QWKHistory::itemAt, callee gives an integer.
        <0 means jump back to that item, 0 means the current item, >0 means jump forwards.
        If an out-of-range index is given, the function silently fails.
        This will invoke WKPageGoToBackForwardListItem.

        * UIProcess/API/qt/qwkhistory.h:
        * UIProcess/API/qt/qwkhistory_p.h:
        * UIProcess/API/qt/qwkpage.cpp:
        (QWKPagePrivate::QWKPagePrivate):
        Update instantiation of QWKHistory to include QWKPage.

        * UIProcess/API/qt/tests/qwkhistory/tst_qwkhistory.cpp:
        (tst_QWKHistory::historyForwardBackTest_data):
        (tst_QWKHistory::historyForwardBackTest):
        Add test content for the new API

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (89604 => 89605)


--- trunk/Source/WebKit2/ChangeLog	2011-06-23 19:53:41 UTC (rev 89604)
+++ trunk/Source/WebKit2/ChangeLog	2011-06-23 19:54:25 UTC (rev 89605)
@@ -1,3 +1,40 @@
+2011-06-23 Jamie Cooley  <[email protected]>
+
+        Reviewed by Andreas Kling.
+
+        [Qt][WK2] Qt port needs load-from-history implementation
+        https://bugs.webkit.org/show_bug.cgi?id=57784
+ 
+        Created "random access" BackForwardHistory public API method,
+        QWKHistory::goToItemAt(int)
+
+        * UIProcess/API/qt/qwkhistory.cpp:
+        (QWKHistoryItem::QWKHistoryItem::itemRef):
+        Added access method to fetch WKBackForwardListRef
+
+        (QWKHistoryPrivate::QWKHistoryPrivate):
+        (QWKHistoryPrivate::createHistory):
+        Updated createHistory method and QWKHistoryPrivate constructor to take a pointer
+        to the owning QWKPage in addition to the WebBackForwardList. This will be saved so that the
+        new API can ask the page to load a HistoryItem.
+
+        (QWKHistory::goToItemAt):
+        New Public API. Like QWKHistory::itemAt, callee gives an integer.
+        <0 means jump back to that item, 0 means the current item, >0 means jump forwards.
+        If an out-of-range index is given, the function silently fails.
+        This will invoke WKPageGoToBackForwardListItem.
+
+        * UIProcess/API/qt/qwkhistory.h:
+        * UIProcess/API/qt/qwkhistory_p.h:
+        * UIProcess/API/qt/qwkpage.cpp:
+        (QWKPagePrivate::QWKPagePrivate):
+        Update instantiation of QWKHistory to include QWKPage.
+
+        * UIProcess/API/qt/tests/qwkhistory/tst_qwkhistory.cpp:
+        (tst_QWKHistory::historyForwardBackTest_data):
+        (tst_QWKHistory::historyForwardBackTest):
+        Add test content for the new API
+
 2011-06-23  Yael Aharon  <[email protected]>
 
         Reviewed by Andreas Kling.

Modified: trunk/Source/WebKit2/UIProcess/API/qt/qwkhistory.cpp (89604 => 89605)


--- trunk/Source/WebKit2/UIProcess/API/qt/qwkhistory.cpp	2011-06-23 19:53:41 UTC (rev 89604)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qwkhistory.cpp	2011-06-23 19:54:25 UTC (rev 89605)
@@ -29,6 +29,7 @@
 #include <QString>
 #include <QUrl>
 #include "qwkhistory_p.h"
+#include "qwkpage_p.h"
 #include "WebBackForwardList.h"
 #include <WebKit2/WKArray.h>
 #include <WebKit2/WKRetainPtr.h>
@@ -84,15 +85,16 @@
     return WKURLCopyQUrl(url.get());
 }
 
-QWKHistoryPrivate::QWKHistoryPrivate(WebKit::WebBackForwardList* list)
-    : m_backForwardList(list)
+QWKHistoryPrivate::QWKHistoryPrivate(QWKPage* page, WebKit::WebBackForwardList* list)
+    : m_page(page)
+    , m_backForwardList(list)
 {
 }
 
-QWKHistory* QWKHistoryPrivate::createHistory(WebKit::WebBackForwardList* list)
+QWKHistory* QWKHistoryPrivate::createHistory(QWKPage* page, WebKit::WebBackForwardList* list)
 {
     QWKHistory* history = new QWKHistory();
-    history->d = new QWKHistoryPrivate(list);
+    history->d = new QWKHistoryPrivate(page, list);
     return history;
 }
 
@@ -152,6 +154,15 @@
     return item;
 }
 
+void QWKHistory::goToItemAt(int index) const
+{
+    WKRetainPtr<WKBackForwardListItemRef> itemRef = WKBackForwardListGetItemAtIndex(toAPI(d->m_backForwardList), index);
+    if (itemRef && d->m_page) {
+        QWKHistoryItem item(itemRef.get());
+        WKPageGoToBackForwardListItem(d->m_page->pageRef(), item.d->m_backForwardListItem.get());
+    }
+}
+
 QList<QWKHistoryItem> QWKHistory::backItems(int maxItems) const
 {
     WKArrayRef arrayRef = WKBackForwardListCopyBackListWithLimit(toAPI(d->m_backForwardList), maxItems);

Modified: trunk/Source/WebKit2/UIProcess/API/qt/qwkhistory.h (89604 => 89605)


--- trunk/Source/WebKit2/UIProcess/API/qt/qwkhistory.h	2011-06-23 19:53:41 UTC (rev 89604)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qwkhistory.h	2011-06-23 19:54:25 UTC (rev 89605)
@@ -67,6 +67,7 @@
     QWKHistoryItem backItem() const;
     QWKHistoryItem forwardItem() const;
     QWKHistoryItem itemAt(int index) const;
+    void goToItemAt(int index) const;
     QList<QWKHistoryItem> backItems(int maxItems) const;
     QList<QWKHistoryItem> forwardItems(int maxItems) const;
 

Modified: trunk/Source/WebKit2/UIProcess/API/qt/qwkhistory_p.h (89604 => 89605)


--- trunk/Source/WebKit2/UIProcess/API/qt/qwkhistory_p.h	2011-06-23 19:53:41 UTC (rev 89604)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qwkhistory_p.h	2011-06-23 19:54:25 UTC (rev 89605)
@@ -36,6 +36,7 @@
 }
 
 class QWKHistory;
+class QWKPage;
 
 class QWEBKIT_EXPORT QWKHistoryItemPrivate : public QSharedData {
 public:
@@ -50,12 +51,13 @@
 
 class QWEBKIT_EXPORT QWKHistoryPrivate {
 public:
-    static QWKHistory* createHistory(WebKit::WebBackForwardList* list);
+    static QWKHistory* createHistory(QWKPage*, WebKit::WebBackForwardList*);
 
 private:
-    QWKHistoryPrivate(WebKit::WebBackForwardList* list);
+    QWKHistoryPrivate(QWKPage*, WebKit::WebBackForwardList*);
     ~QWKHistoryPrivate();
 
+    QWKPage* m_page;
     WebKit::WebBackForwardList* m_backForwardList;
 
     friend class QWKHistory;

Modified: trunk/Source/WebKit2/UIProcess/API/qt/qwkpage.cpp (89604 => 89605)


--- trunk/Source/WebKit2/UIProcess/API/qt/qwkpage.cpp	2011-06-23 19:53:41 UTC (rev 89604)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qwkpage.cpp	2011-06-23 19:54:25 UTC (rev 89605)
@@ -147,7 +147,7 @@
 {
     memset(actions, 0, sizeof(actions));
     page = context->d->context->createWebPage(this, toImpl(pageGroupRef));
-    history = QWKHistoryPrivate::createHistory(page->backForwardList());
+    history = QWKHistoryPrivate::createHistory(q, page->backForwardList());
 }
 
 QWKPagePrivate::~QWKPagePrivate()

Modified: trunk/Source/WebKit2/UIProcess/API/qt/tests/qwkhistory/tst_qwkhistory.cpp (89604 => 89605)


--- trunk/Source/WebKit2/UIProcess/API/qt/tests/qwkhistory/tst_qwkhistory.cpp	2011-06-23 19:53:41 UTC (rev 89604)
+++ trunk/Source/WebKit2/UIProcess/API/qt/tests/qwkhistory/tst_qwkhistory.cpp	2011-06-23 19:54:25 UTC (rev 89605)
@@ -28,6 +28,8 @@
 #include <qwkhistory.h>
 #include <qwkpage.h>
 
+#define TEST_HISTORY_ACTION_RANGE 10
+
 class TestHistoryItem {
 public:
     TestHistoryItem(const QString& title, const QString& filename);
@@ -70,8 +72,10 @@
     QWKPage* m_page;
     QWKHistory* m_history;
 
+    // Enumerate TestHistoryActions starting at 10 so that other integers
+    // can be used at will to test random access
     enum TestHistoryActions {
-        TestNone,
+        TestNone = TEST_HISTORY_ACTION_RANGE,
         TestLoad,
         TestBack,
         TestFwd
@@ -151,6 +155,31 @@
     QTest::newRow("(a) [b c d]") <<
         int(TestBack) << expectedBackList << expectedBackList.takeLast() << expectedForwardList << true;
 
+    // Test random access and related edge cases
+    QTest::newRow("random (a) [b c d]") <<
+        0 << expectedBackList << m_testItemA.data() << expectedForwardList << true;
+    expectedBackList << m_testItemA.data() << expectedForwardList.takeFirst();
+    QTest::newRow("random [a b] (c) [d]") <<
+        2 << expectedBackList << expectedForwardList.takeFirst() << expectedForwardList << true;
+
+    QTest::newRow("random [a b] (c) [d]") <<
+        2 << expectedBackList << m_testItemC.data() << expectedForwardList << false;
+
+    expectedBackList << m_testItemC.data();
+    QTest::newRow("random [a b c] (d)") <<
+        1 << expectedBackList << expectedForwardList.takeFirst() << expectedForwardList << true;
+
+    QTest::newRow("random [a b c] (d)") <<
+        1 << expectedBackList << m_testItemD.data() << expectedForwardList << false;
+
+    expectedForwardList << m_testItemB.data() << m_testItemC.data() << m_testItemD.data();
+    expectedBackList.clear();
+    QTest::newRow("random (a) [b c d]") <<
+        -3 << expectedBackList << m_testItemA.data() << expectedForwardList << true;
+
+    QTest::newRow("random (a) [b c d]") <<
+        -1 << expectedBackList << m_testItemA.data() << expectedForwardList << false;
+
     // "Branch" the forward list away from where it was by loading a new item. Forward list
     // is now cleared, back list should be as expected.
     expectedBackList.clear();
@@ -195,7 +224,11 @@
         m_page->triggerAction(QWKPage::Forward);
         break;
     default:
-        QFAIL("undefined test case action");
+        // allow test data to pass in indices between defined enum range
+        if ((command > -TEST_HISTORY_ACTION_RANGE) && (command < TEST_HISTORY_ACTION_RANGE))
+            m_history->goToItemAt(command);
+        else
+            QFAIL("undefined test case action");
         break;
     }
     
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to