History support on platform Qt. r=lars
authorzack <zack@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Jan 2007 13:13:48 +0000 (13:13 +0000)
committerzack <zack@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Jan 2007 13:13:48 +0000 (13:13 +0000)
We might switch to a model but for now this is ok.

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

WebCore/ChangeLog
WebCore/WebCore.pro
WebKitQt/Api/qwebpage.cpp
WebKitQt/Api/qwebpage.h
WebKitQt/Api/qwebpagehistory.cpp [new file with mode: 0644]
WebKitQt/Api/qwebpagehistory.h [new file with mode: 0644]
WebKitQt/Api/qwebpagehistory_p.h [new file with mode: 0644]
WebKitQt/ChangeLog

index d3d51a0..70ff783 100644 (file)
@@ -1,3 +1,11 @@
+2007-01-26  Zack Rusin  <zrusin@trolltech.com>
+
+        Reviewed by Lars
+
+        Add history related classes to the project file.
+
+        * WebCore.pro:
+
 2007-01-26  Zack Rusin  <zack@kde.org>
 
         Reviewed by Lars
index 83315b4..aeee74c 100644 (file)
@@ -687,7 +687,8 @@ SOURCES += \
     ../WebKitQt/WebCoreSupport/ContextMenuClientQt.cpp \
     ../WebKitQt/WebCoreSupport/DragClientQt.cpp \
     ../WebKitQt/Api/qwebpage.cpp \
-    ../WebKitQt/Api/qwebframe.cpp
+    ../WebKitQt/Api/qwebframe.cpp \
+    ../WebKitQt/Api/qwebpagehistory.cpp
 
 contains(DEFINES, XPATH_SUPPORT=1) {
     FEATURE_DEFINES_JAVASCRIPT += XPATH_SUPPORT
index 0858d03..6acc72c 100644 (file)
@@ -24,6 +24,8 @@
 #include "qwebframe.h"
 #include "qwebpage_p.h"
 #include "qwebframe_p.h"
+#include "qwebpagehistory.h"
+#include "qwebpagehistory_p.h"
 
 #include <qurl.h>
 
@@ -125,5 +127,27 @@ QSize QWebPage::sizeHint() const
     return QSize(800, 600);
 }
 
+QWebPageHistory QWebPage::history() const
+{
+    WebCore::BackForwardList *lst = d->page->backForwardList();
+    QWebPageHistoryPrivate *priv = new QWebPageHistoryPrivate(lst);
+    return QWebPageHistory(priv);
+}
+
+void QWebPage::goBack()
+{
+    d->page->goBack();
+}
+
+void QWebPage::goForward()
+{
+    d->page->goForward();
+}
+
+void QWebPage::goToHistoryItem(const QWebHistoryItem &item)
+{
+    d->page->goToItem(item.d->item, FrameLoadTypeIndexedBackForward);
+}
+
 #include "qwebpage.moc"
 
index b633e68..5330313 100644 (file)
@@ -23,6 +23,8 @@
 #ifndef QWEBPAGE_H
 #define QWEBPAGE_H
 
+#include "qwebpagehistory.h"
+
 #include <qwidget.h>
 class QWebFrame;
 class QUrl;
@@ -46,9 +48,15 @@ public:
 
 
     QWebFrame *mainFrame() const;
-    
+
+    QWebPageHistory history() const;
+
     QSize sizeHint() const;
 
+public slots:
+    void goBack();
+    void goForward();
+    void goToHistoryItem(const QWebHistoryItem &item);
 signals:
     /**
      * Signal is emitted when load is started on one of the child
diff --git a/WebKitQt/Api/qwebpagehistory.cpp b/WebKitQt/Api/qwebpagehistory.cpp
new file mode 100644 (file)
index 0000000..03dd3c0
--- /dev/null
@@ -0,0 +1,145 @@
+#include "qwebpagehistory.h"
+#include "qwebpagehistory_p.h"
+
+#include "DeprecatedString.h"
+#include "PlatformString.h"
+#include "Image.h"
+
+#include <QSharedData>
+
+QWebHistoryItem::~QWebHistoryItem()
+{
+}
+
+QUrl QWebHistoryItem::originalUrl() const
+{
+    return QUrl(d->item->originalURL().url());
+}
+
+
+QUrl QWebHistoryItem::currentUrl() const
+{
+    return QUrl(d->item->url().url());
+}
+
+
+QString QWebHistoryItem::title() const
+{
+    return d->item->title();
+}
+
+
+QDateTime QWebHistoryItem::lastVisited() const
+{
+    //FIXME : this will be wrong unless we correctly set lastVisitedTime ourselves
+    return QDateTime::fromTime_t((uint)d->item->lastVisitedTime());
+}
+
+
+QPixmap QWebHistoryItem::icon() const
+{
+    return *d->item->icon()->getPixmap();
+}
+
+
+QWebHistoryItem::QWebHistoryItem(QWebHistoryItemPrivate *priv)
+{
+    d = priv;
+}
+
+QWebPageHistory::QWebPageHistory(QWebPageHistoryPrivate *priv)
+{
+    d = priv;
+}
+
+QWebHistoryItem QWebPageHistory::itemAtIndex(int i) const
+{
+    WebCore::HistoryItem *item = d->lst->itemAtIndex(i);
+
+    QWebHistoryItemPrivate *priv = new QWebHistoryItemPrivate(item);
+    return QWebHistoryItem(priv);
+}
+
+QWebPageHistory::QWebPageHistory(const QWebPageHistory &other)
+{
+    d = other.d;
+}
+
+QWebPageHistory::~QWebPageHistory()
+{
+}
+
+QList<QWebHistoryItem> QWebPageHistory::items() const
+{
+    const WebCore::HistoryItemVector &items = d->lst->entries();
+
+    QList<QWebHistoryItem> ret;
+    for (int i = 0; i < items.size(); ++i) {
+        QWebHistoryItemPrivate *priv = new QWebHistoryItemPrivate(items[i].get());
+        ret.append(QWebHistoryItem(priv));
+    }
+    return ret;
+}
+
+QList<QWebHistoryItem> QWebPageHistory::backItems(int maxItems) const
+{
+    WebCore::HistoryItemVector items(maxItems);
+    d->lst->backListWithLimit(maxItems, items);
+
+    QList<QWebHistoryItem> ret;
+    for (int i = 0; i < items.size(); ++i) {
+        QWebHistoryItemPrivate *priv = new QWebHistoryItemPrivate(items[i].get());
+        ret.append(QWebHistoryItem(priv));
+    }
+    return ret;
+}
+
+QList<QWebHistoryItem> QWebPageHistory::forwardItems(int maxItems) const
+{
+    WebCore::HistoryItemVector items(maxItems);
+    d->lst->forwardListWithLimit(maxItems, items);
+
+    QList<QWebHistoryItem> ret;
+    for (int i = 0; i < items.size(); ++i) {
+        QWebHistoryItemPrivate *priv = new QWebHistoryItemPrivate(items[i].get());
+        ret.append(QWebHistoryItem(priv));
+    }
+    return ret;
+}
+
+void QWebPageHistory::goBack()
+{
+    d->lst->goBack();
+}
+
+void QWebPageHistory::goForward()
+{
+    d->lst->goBack();
+}
+
+void QWebPageHistory::goToItem(QWebHistoryItem *item)
+{
+    d->lst->goToItem(item->d->item);
+}
+
+QWebHistoryItem QWebPageHistory::backItem() const
+{
+    WebCore::HistoryItem *i = d->lst->backItem();
+    QWebHistoryItemPrivate *priv = new QWebHistoryItemPrivate(i);
+    return QWebHistoryItem(priv);
+}
+
+QWebHistoryItem QWebPageHistory::currentItem() const
+{
+    WebCore::HistoryItem *i = d->lst->currentItem();
+    QWebHistoryItemPrivate *priv = new QWebHistoryItemPrivate(i);
+    return QWebHistoryItem(priv);
+}
+
+QWebHistoryItem QWebPageHistory::forwardItem() const
+{
+    WebCore::HistoryItem *i = d->lst->forwardItem();
+    QWebHistoryItemPrivate *priv = new QWebHistoryItemPrivate(i);
+    return QWebHistoryItem(priv);
+}
+
diff --git a/WebKitQt/Api/qwebpagehistory.h b/WebKitQt/Api/qwebpagehistory.h
new file mode 100644 (file)
index 0000000..0fa6adb
--- /dev/null
@@ -0,0 +1,62 @@
+#ifndef QWEBPAGEHISTORY_H
+#define QWEBPAGEHISTORY_H
+
+#include <QUrl>
+#include <QString>
+#include <QIcon>
+#include <QDateTime>
+#include <QSharedData>
+
+class QWebPage;
+
+class QWebHistoryItemPrivate;
+class QWebHistoryItem
+{
+public:
+    ~QWebHistoryItem();
+
+    QWebHistoryItem *parent() const;
+    QList<QWebHistoryItem*> children() const;
+
+    QUrl originalUrl() const;
+    QUrl currentUrl() const;
+
+    QString title() const;
+    QDateTime lastVisited() const;
+
+    QPixmap icon() const;
+
+    QWebHistoryItem(QWebHistoryItemPrivate *priv);
+private:
+    friend class QWebPageHistory;
+    friend class QWebPage;
+    QExplicitlySharedDataPointer<QWebHistoryItemPrivate> d;
+};
+
+class QWebPageHistoryPrivate;
+class QWebPageHistory
+{
+public:
+    QWebPageHistory(const QWebPageHistory &other);
+    ~QWebPageHistory();
+    
+    QList<QWebHistoryItem> items() const;
+    QList<QWebHistoryItem> backItems(int maxItems) const;
+    QList<QWebHistoryItem> forwardItems(int maxItems) const;
+
+    void goBack();
+    void goForward();
+    void goToItem(QWebHistoryItem *item);
+
+    QWebHistoryItem backItem() const;
+    QWebHistoryItem currentItem() const;
+    QWebHistoryItem forwardItem() const;
+    QWebHistoryItem itemAtIndex(int i) const;
+
+    
+    QWebPageHistory(QWebPageHistoryPrivate *priv);
+private:
+    QExplicitlySharedDataPointer<QWebPageHistoryPrivate> d;
+};
+
+#endif
diff --git a/WebKitQt/Api/qwebpagehistory_p.h b/WebKitQt/Api/qwebpagehistory_p.h
new file mode 100644 (file)
index 0000000..f8b4f30
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef QWEBPAGEHISTORY_P_H
+#define QWEBPAGEHISTORY_P_H
+
+#include "BackForwardList.h"
+#include "HistoryItem.h"
+
+class QWebHistoryItemPrivate : public QSharedData
+{
+public:
+    QWebHistoryItemPrivate(WebCore::HistoryItem *i)
+    {
+        i->ref();
+        item = i;
+    }
+    ~QWebHistoryItemPrivate()
+    {
+        item->deref();
+    }
+    
+    WebCore::HistoryItem *item;
+};
+
+class QWebPageHistoryPrivate : public QSharedData
+{
+public:
+    QWebPageHistoryPrivate(WebCore::BackForwardList *l)
+    {
+        l->ref();
+        lst = l;
+    }
+    ~QWebPageHistoryPrivate()
+    {
+        lst->deref();
+    }
+    WebCore::BackForwardList *lst;
+};
+
+
+#endif
index f8289ee..6092b64 100644 (file)
@@ -1,3 +1,42 @@
+2007-01-26  Zack Rusin  <zrusin@trolltech.com>
+
+        Reviewed by Lars
+
+        Implement history support on platform Qt.
+
+        * Api/qwebpage.cpp:
+        (QWebPage::history):
+        (QWebPage::goBack):
+        (QWebPage::goForward):
+        (QWebPage::goToHistoryItem):
+        * Api/qwebpage.h:
+        * Api/qwebpagehistory.cpp: Added.
+        (QWebHistoryItem::~QWebHistoryItem):
+        (QWebHistoryItem::originalUrl):
+        (QWebHistoryItem::currentUrl):
+        (QWebHistoryItem::title):
+        (QWebHistoryItem::lastVisited):
+        (QWebHistoryItem::icon):
+        (QWebHistoryItem::QWebHistoryItem):
+        (QWebPageHistory::QWebPageHistory):
+        (QWebPageHistory::itemAtIndex):
+        (QWebPageHistory::~QWebPageHistory):
+        (QWebPageHistory::items):
+        (QWebPageHistory::backItems):
+        (QWebPageHistory::forwardItems):
+        (QWebPageHistory::goBack):
+        (QWebPageHistory::goForward):
+        (QWebPageHistory::goToItem):
+        (QWebPageHistory::backItem):
+        (QWebPageHistory::currentItem):
+        (QWebPageHistory::forwardItem):
+        * Api/qwebpagehistory.h: Added.
+        * Api/qwebpagehistory_p.h: Added.
+        (QWebHistoryItemPrivate::QWebHistoryItemPrivate):
+        (QWebHistoryItemPrivate::~QWebHistoryItemPrivate):
+        (QWebPageHistoryPrivate::QWebPageHistoryPrivate):
+        (QWebPageHistoryPrivate::~QWebPageHistoryPrivate):
+
 2007-01-26  Lars Knoll <lars@trolltech.com>
 
         Get rid of FrameQtClient. It's unused since we moved over