2 * Copyright (C) 2010 Juha Savolainen (juha.savolainen@weego.fi)
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #include "qwkhistory.h"
28 #include <QSharedData>
31 #include "QtWebPageProxy.h"
32 #include "qwkhistory_p.h"
33 #include "WebBackForwardList.h"
34 #include <WebKit2/WKArray.h>
35 #include <WebKit2/WKRetainPtr.h>
36 #include "WKBackForwardList.h"
37 #include "WKStringQt.h"
41 using namespace WebKit;
43 QWKHistoryItemPrivate::QWKHistoryItemPrivate(WKBackForwardListItemRef listItem)
44 : m_backForwardListItem(listItem)
48 QWKHistoryItemPrivate::~QWKHistoryItemPrivate()
52 QWKHistoryItem::QWKHistoryItem(const QWKHistoryItem& other)
57 QWKHistoryItem& QWKHistoryItem::QWKHistoryItem::operator=(const QWKHistoryItem& other)
63 QWKHistoryItem::QWKHistoryItem(WKBackForwardListItemRef item)
64 : d(new QWKHistoryItemPrivate(item))
68 QWKHistoryItem::~QWKHistoryItem()
72 QString QWKHistoryItem::title() const
74 if (!d->m_backForwardListItem)
76 WKRetainPtr<WKStringRef> title(AdoptWK, WKBackForwardListItemCopyTitle(d->m_backForwardListItem.get()));
77 return WKStringCopyQString(title.get());
80 QUrl QWKHistoryItem::url() const
82 if (!d->m_backForwardListItem)
84 WKRetainPtr<WKURLRef> url(AdoptWK, WKBackForwardListItemCopyURL(d->m_backForwardListItem.get()));
85 return WKURLCopyQUrl(url.get());
88 QWKHistoryPrivate::QWKHistoryPrivate(QtWebPageProxy* page, WebKit::WebBackForwardList* list)
90 , m_backForwardList(list)
94 QWKHistory* QWKHistoryPrivate::createHistory(QtWebPageProxy* page, WebKit::WebBackForwardList* list)
96 QWKHistory* history = new QWKHistory();
97 history->d = new QWKHistoryPrivate(page, list);
101 QWKHistoryPrivate::~QWKHistoryPrivate()
105 QWKHistory::QWKHistory()
109 QWKHistory::~QWKHistory()
114 int QWKHistory::backListCount() const
116 return WKBackForwardListGetBackListCount(toAPI(d->m_backForwardList));
119 int QWKHistory::forwardListCount() const
121 return WKBackForwardListGetForwardListCount(toAPI(d->m_backForwardList));
124 int QWKHistory::count() const
126 return backListCount() + forwardListCount();
129 QWKHistoryItem QWKHistory::currentItem() const
131 WKRetainPtr<WKBackForwardListItemRef> itemRef = WKBackForwardListGetCurrentItem(toAPI(d->m_backForwardList));
132 QWKHistoryItem item(itemRef.get());
136 QWKHistoryItem QWKHistory::backItem() const
138 WKRetainPtr<WKBackForwardListItemRef> itemRef = WKBackForwardListGetBackItem(toAPI(d->m_backForwardList));
139 QWKHistoryItem item(itemRef.get());
143 QWKHistoryItem QWKHistory::forwardItem() const
145 WKRetainPtr<WKBackForwardListItemRef> itemRef = WKBackForwardListGetForwardItem(toAPI(d->m_backForwardList));
146 QWKHistoryItem item(itemRef.get());
150 QWKHistoryItem QWKHistory::itemAt(int index) const
152 WKRetainPtr<WKBackForwardListItemRef> itemRef = WKBackForwardListGetItemAtIndex(toAPI(d->m_backForwardList), index);
153 QWKHistoryItem item(itemRef.get());
157 void QWKHistory::goToItemAt(int index) const
159 WKRetainPtr<WKBackForwardListItemRef> itemRef = WKBackForwardListGetItemAtIndex(toAPI(d->m_backForwardList), index);
160 if (itemRef && d->m_page) {
161 QWKHistoryItem item(itemRef.get());
162 WKPageGoToBackForwardListItem(d->m_page->pageRef(), item.d->m_backForwardListItem.get());
166 QList<QWKHistoryItem> QWKHistory::backItems(int maxItems) const
168 WKArrayRef arrayRef = WKBackForwardListCopyBackListWithLimit(toAPI(d->m_backForwardList), maxItems);
169 int size = WKArrayGetSize(arrayRef);
170 QList<QWKHistoryItem> itemList;
171 for (int i = 0; i < size; ++i) {
172 WKTypeRef wkHistoryItem = WKArrayGetItemAtIndex(arrayRef, i);
173 WKBackForwardListItemRef itemRef = static_cast<WKBackForwardListItemRef>(wkHistoryItem);
174 QWKHistoryItem item(itemRef);
175 itemList.append(item);
180 QList<QWKHistoryItem> QWKHistory::forwardItems(int maxItems) const
182 WKArrayRef arrayRef = WKBackForwardListCopyForwardListWithLimit(toAPI(d->m_backForwardList), maxItems);
183 int size = WKArrayGetSize(arrayRef);
184 QList<QWKHistoryItem> itemList;
185 for (int i = 0; i < size; ++i) {
186 WKTypeRef wkHistoryItem = WKArrayGetItemAtIndex(arrayRef, i);
187 WKBackForwardListItemRef itemRef = static_cast<WKBackForwardListItemRef>(wkHistoryItem);
188 QWKHistoryItem item(itemRef);
189 itemList.append(item);