diff options
author | Ben Murdoch <benm@google.com> | 2011-05-13 16:23:25 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2011-05-16 11:35:02 +0100 |
commit | 65f03d4f644ce73618e5f4f50dd694b26f55ae12 (patch) | |
tree | f478babb801e720de7bfaee23443ffe029f58731 /Source/WebKit2/UIProcess/API/qt | |
parent | 47de4a2fb7262c7ebdb9cd133ad2c54c187454d0 (diff) | |
download | external_webkit-65f03d4f644ce73618e5f4f50dd694b26f55ae12.zip external_webkit-65f03d4f644ce73618e5f4f50dd694b26f55ae12.tar.gz external_webkit-65f03d4f644ce73618e5f4f50dd694b26f55ae12.tar.bz2 |
Merge WebKit at r75993: Initial merge by git.
Change-Id: I602bbdc3974787a3b0450456a30a7868286921c3
Diffstat (limited to 'Source/WebKit2/UIProcess/API/qt')
17 files changed, 2603 insertions, 0 deletions
diff --git a/Source/WebKit2/UIProcess/API/qt/ClientImpl.cpp b/Source/WebKit2/UIProcess/API/qt/ClientImpl.cpp new file mode 100644 index 0000000..642e529 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/qt/ClientImpl.cpp @@ -0,0 +1,169 @@ +/* + Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "ClientImpl.h" + +#include "WebFrameProxy.h" +#include "WKAPICast.h" +#include "WKStringQt.h" +#include "WKURLQt.h" +#include <qwkpage.h> +#include <qwkpage_p.h> +#include <WKFrame.h> +#include <WKType.h> + +using namespace WebKit; + +static QWKPage* toQWKPage(const void* clientInfo) +{ + if (clientInfo) + return reinterpret_cast<QWKPage*>(const_cast<void*>(clientInfo)); + return 0; +} + +static void loadFinished(WKFrameRef frame, const void* clientInfo, bool ok) +{ + if (!WKFrameIsMainFrame(frame)) + return; + emit toQWKPage(clientInfo)->loadFinished(ok); + QWKPagePrivate::get(toQWKPage(clientInfo))->updateNavigationActions(); +} + +void qt_wk_didStartProvisionalLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo) +{ + if (!WKFrameIsMainFrame(frame)) + return; + emit toQWKPage(clientInfo)->loadStarted(); + QWKPagePrivate::get(toQWKPage(clientInfo))->updateNavigationActions(); +} + +void qt_wk_didReceiveServerRedirectForProvisionalLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo) +{ +} + +void qt_wk_didFailProvisionalLoadWithErrorForFrame(WKPageRef page, WKFrameRef frame, WKErrorRef error, WKTypeRef userData, const void* clientInfo) +{ + loadFinished(frame, clientInfo, false); +} + +void qt_wk_didCommitLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo) +{ + if (!WKFrameIsMainFrame(frame)) + return; + WebFrameProxy* wkframe = toImpl(frame); + QString urlStr(wkframe->url()); + QUrl qUrl = urlStr; + emit toQWKPage(clientInfo)->urlChanged(qUrl); + QWKPagePrivate::get(toQWKPage(clientInfo))->updateNavigationActions(); +} + +void qt_wk_didFinishDocumentLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo) +{ + // FIXME: Implement (bug #44934) +} + +void qt_wk_didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo) +{ + loadFinished(frame, clientInfo, true); +} + +void qt_wk_didFailLoadWithErrorForFrame(WKPageRef page, WKFrameRef frame, WKErrorRef error, WKTypeRef userData, const void* clientInfo) +{ + loadFinished(frame, clientInfo, false); +} + +void qt_wk_didReceiveTitleForFrame(WKPageRef page, WKStringRef title, WKFrameRef frame, WKTypeRef userData, const void* clientInfo) +{ + if (!WKFrameIsMainFrame(frame)) + return; + QString qTitle = WKStringCopyQString(title); + emit toQWKPage(clientInfo)->titleChanged(qTitle); +} + +void qt_wk_didFirstLayoutForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo) +{ + if (!WKFrameIsMainFrame(frame)) + return; + emit toQWKPage(clientInfo)->initialLayoutCompleted(); +} + +void qt_wk_didRemoveFrameFromHierarchy(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo) +{ + // FIXME: Implement (bug #46432) +} + +void qt_wk_didFirstVisuallyNonEmptyLayoutForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo) +{ + if (!WKFrameIsMainFrame(frame)) + return; + // FIXME: emit toWKView(clientInfo)->initialLayoutCompleted(); +} + +void qt_wk_didStartProgress(WKPageRef page, const void* clientInfo) +{ + emit toQWKPage(clientInfo)->loadProgress(0); +} + +void qt_wk_didChangeProgress(WKPageRef page, const void* clientInfo) +{ + emit toQWKPage(clientInfo)->loadProgress(WKPageGetEstimatedProgress(page) * 100); +} + +void qt_wk_didFinishProgress(WKPageRef page, const void* clientInfo) +{ + emit toQWKPage(clientInfo)->loadProgress(100); +} + +void qt_wk_didBecomeUnresponsive(WKPageRef page, const void* clientInfo) +{ +} + +void qt_wk_didBecomeResponsive(WKPageRef page, const void* clientInfo) +{ +} + +WKPageRef qt_wk_createNewPage(WKPageRef page, WKDictionaryRef features, WKEventModifiers modifiers, WKEventMouseButton mouseButton, const void* clientInfo) +{ + QWKPage* wkPage = toQWKPage(clientInfo); + QWKPagePrivate* d = QWKPagePrivate::get(wkPage); + QWKPage::CreateNewPageFn createNewPageFn = d->createNewPageFn; + + if (!createNewPageFn) + return 0; + + if (QWKPage* newPage = createNewPageFn(wkPage)) { + WKRetain(newPage->pageRef()); + return newPage->pageRef(); + } + + return 0; +} + +void qt_wk_showPage(WKPageRef page, const void* clientInfo) +{ +} + +void qt_wk_close(WKPageRef page, const void* clientInfo) +{ + emit toQWKPage(clientInfo)->windowCloseRequested(); +} + +void qt_wk_runJavaScriptAlert(WKPageRef page, WKStringRef alertText, WKFrameRef frame, const void* clientInfo) +{ +} diff --git a/Source/WebKit2/UIProcess/API/qt/ClientImpl.h b/Source/WebKit2/UIProcess/API/qt/ClientImpl.h new file mode 100644 index 0000000..5d8c062 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/qt/ClientImpl.h @@ -0,0 +1,58 @@ +/* + Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef DefaultClientCallbacksQt_h +#define DefaultClientCallbacksQt_h + +#include <WebKit2/WKPage.h> + +#ifdef __cplusplus +extern "C" { +#endif + +// loader client +void qt_wk_didStartProvisionalLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void* clientInfo); +void qt_wk_didReceiveServerRedirectForProvisionalLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void* clientInfo); +void qt_wk_didFailProvisionalLoadWithErrorForFrame(WKPageRef, WKFrameRef, WKErrorRef, WKTypeRef, const void* clientInfo); +void qt_wk_didCommitLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void* clientInfo); +void qt_wk_didFinishDocumentLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void* clientInfo); +void qt_wk_didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void* clientInfo); +void qt_wk_didFailLoadWithErrorForFrame(WKPageRef, WKFrameRef, WKErrorRef, WKTypeRef, const void* clientInfo); +void qt_wk_didReceiveTitleForFrame(WKPageRef, WKStringRef title, WKFrameRef, WKTypeRef, const void* clientInfo); +void qt_wk_didFirstLayoutForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void* clientInfo); +void qt_wk_didFirstVisuallyNonEmptyLayoutForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void* clientInfo); +void qt_wk_didRemoveFrameFromHierarchy(WKPageRef, WKFrameRef, WKTypeRef, const void* clientInfo); +void qt_wk_didStartProgress(WKPageRef, const void* clientInfo); +void qt_wk_didChangeProgress(WKPageRef, const void* clientInfo); +void qt_wk_didFinishProgress(WKPageRef, const void* clientInfo); +void qt_wk_didBecomeUnresponsive(WKPageRef, const void* clientInfo); +void qt_wk_didBecomeResponsive(WKPageRef, const void* clientInfo); + +// ui client +WKPageRef qt_wk_createNewPage(WKPageRef page, WKDictionaryRef features, WKEventModifiers modifiers, WKEventMouseButton mouseButton, const void *clientInfo); +void qt_wk_showPage(WKPageRef page, const void *clientInfo); +void qt_wk_close(WKPageRef page, const void *clientInfo); +void qt_wk_runJavaScriptAlert(WKPageRef page, WKStringRef alertText, WKFrameRef frame, const void* clientInfo); + +#ifdef __cplusplus +} +#endif + +#endif /* DefaultClientCallbacksQt_h */ + diff --git a/Source/WebKit2/UIProcess/API/qt/WKView.h b/Source/WebKit2/UIProcess/API/qt/WKView.h new file mode 100644 index 0000000..5bb95e8 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/qt/WKView.h @@ -0,0 +1,28 @@ +/* + Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef WKView_h +#define WKView_h + +#include <WebKit2/qgraphicswkview.h> +#include <WebKit2/qwkcontext.h> +#include <WebKit2/qwkpage.h> +#include <WebKit2/qwkpreferences.h> + +#endif /* WKView_h */ diff --git a/Source/WebKit2/UIProcess/API/qt/qgraphicswkview.cpp b/Source/WebKit2/UIProcess/API/qt/qgraphicswkview.cpp new file mode 100644 index 0000000..f01c5b2 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/qt/qgraphicswkview.cpp @@ -0,0 +1,442 @@ +/* + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this program; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "qgraphicswkview.h" + +#include "ChunkedUpdateDrawingAreaProxy.h" +#include "IntSize.h" +#include "RunLoop.h" +#include "TiledDrawingAreaProxy.h" +#include "UpdateChunk.h" +#include "WKAPICast.h" +#include "qwkpage.h" +#include "qwkpage_p.h" +#include <QApplication> +#include <QCursor> +#include <QGraphicsSceneMouseEvent> +#include <QGraphicsView> +#include <QMenu> +#include <QPainter> +#include <QScrollBar> +#include <QStyleOptionGraphicsItem> +#include <QUrl> +#include <QtDebug> +#include <WebKit2/WKRetainPtr.h> +#include <wtf/RefPtr.h> +#include <wtf/text/WTFString.h> + +using namespace WebKit; +using namespace WebCore; + +struct QGraphicsWKViewPrivate { + QGraphicsWKViewPrivate(QGraphicsWKView* view); + WKPageRef pageRef() const { return page->pageRef(); } + + void onScaleChanged(); + void commitScale(); + + QGraphicsWKView* q; + QWKPage* page; + QMenu* activeMenu; + RunLoop::Timer<QGraphicsWKViewPrivate> m_scaleCommitTimer; + bool m_isChangingScale; +}; + +QGraphicsWKView::QGraphicsWKView(QWKContext* context, BackingStoreType backingStoreType, QGraphicsItem* parent) + : QGraphicsWidget(parent) + , d(new QGraphicsWKViewPrivate(this)) +{ + setFocusPolicy(Qt::StrongFocus); + setAcceptHoverEvents(true); + + PassOwnPtr<DrawingAreaProxy> drawingAreaProxy; + + d->page = new QWKPage(context); + + switch (backingStoreType) { +#if ENABLE(TILED_BACKING_STORE) + case Tiled: + drawingAreaProxy = TiledDrawingAreaProxy::create(this, toImpl(page()->pageRef())); + connect(this, SIGNAL(scaleChanged()), this, SLOT(onScaleChanged())); + break; +#endif + case Simple: + default: + drawingAreaProxy = ChunkedUpdateDrawingAreaProxy::create(this, toImpl(page()->pageRef())); + break; + } + + d->page->d->init(this, drawingAreaProxy); + connect(d->page, SIGNAL(titleChanged(QString)), this, SIGNAL(titleChanged(QString))); + connect(d->page, SIGNAL(loadStarted()), this, SIGNAL(loadStarted())); + connect(d->page, SIGNAL(loadFinished(bool)), this, SIGNAL(loadFinished(bool))); + connect(d->page, SIGNAL(loadProgress(int)), this, SIGNAL(loadProgress(int))); + connect(d->page, SIGNAL(initialLayoutCompleted()), this, SIGNAL(initialLayoutCompleted())); + connect(d->page, SIGNAL(urlChanged(const QUrl&)), this, SIGNAL(urlChanged(const QUrl&))); + connect(d->page, SIGNAL(cursorChanged(const QCursor&)), this, SLOT(updateCursor(const QCursor&))); + connect(d->page, SIGNAL(focusNextPrevChild(bool)), this, SLOT(focusNextPrevChildCallback(bool))); + connect(d->page, SIGNAL(showContextMenu(QMenu*)), this, SLOT(showContextMenu(QMenu*))); +} + +QGraphicsWKView::~QGraphicsWKView() +{ + delete d->page; + delete d; +} + +QWKPage* QGraphicsWKView::page() const +{ + return d->page; +} + +void QGraphicsWKView::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget*) +{ + page()->d->paint(painter, option->exposedRect.toAlignedRect()); +} + +void QGraphicsWKView::setGeometry(const QRectF& rect) +{ + QSizeF oldSize = geometry().size(); + QGraphicsWidget::setGeometry(rect); + if (geometry().size() == oldSize) + return; + + // NOTE: call geometry() as setGeometry ensures that + // the geometry is within legal bounds (minimumSize, maximumSize) + page()->setViewportSize(geometry().size().toSize()); +} + +void QGraphicsWKView::load(const QUrl& url) +{ + page()->load(url); +} + +void QGraphicsWKView::setUrl(const QUrl& url) +{ + page()->setUrl(url); +} + +QUrl QGraphicsWKView::url() const +{ + return page()->url(); +} + +QString QGraphicsWKView::title() const +{ + return page()->title(); +} + +void QGraphicsWKView::triggerPageAction(QWKPage::WebAction action, bool checked) +{ + page()->triggerAction(action, checked); +} + +void QGraphicsWKView::back() +{ + page()->triggerAction(QWKPage::Back); +} + +void QGraphicsWKView::forward() +{ + page()->triggerAction(QWKPage::Forward); +} + +void QGraphicsWKView::reload() +{ + page()->triggerAction(QWKPage::Reload); +} + +void QGraphicsWKView::stop() +{ + page()->triggerAction(QWKPage::Stop); +} + +void QGraphicsWKView::updateCursor(const QCursor& cursor) +{ + setCursor(cursor); +} + +class FriendlyWidget : public QWidget +{ +public: + bool focusNextPrevChild(bool next); +}; + +void QGraphicsWKView::focusNextPrevChildCallback(bool next) +{ + if (hasFocus()) { + // find the view which has the focus: + QList<QGraphicsView*> views = scene()->views(); + const int viewCount = views.count(); + QGraphicsView* focusedView = 0; + for (int i = 0; i < viewCount; ++i) { + if (views[i]->hasFocus()) { + focusedView = views[i]; + break; + } + } + + if (focusedView) { + QWidget* window = focusedView->window(); + FriendlyWidget* friendlyWindow = static_cast<FriendlyWidget*>(window); + friendlyWindow->focusNextPrevChild(next); + } + } +} + +/*! \reimp +*/ +bool QGraphicsWKView::focusNextPrevChild(bool next) +{ + QKeyEvent ev(QEvent::KeyPress, Qt::Key_Tab, Qt::KeyboardModifiers(next ? Qt::NoModifier : Qt::ShiftModifier)); + page()->d->keyPressEvent(&ev); + return true; +} + +/*! \reimp +*/ +QVariant QGraphicsWKView::itemChange(GraphicsItemChange change, const QVariant& value) +{ + // Here so that it can be reimplemented without breaking ABI. + return QGraphicsWidget::itemChange(change, value); +} + +/*! \reimp +*/ +bool QGraphicsWKView::event(QEvent* event) +{ + QEvent::Type eventType = event->type(); + switch (eventType) { + case QEvent::TouchBegin: + case QEvent::TouchEnd: + case QEvent::TouchUpdate: + touchEvent(static_cast<QTouchEvent*>(event)); + return true; + case QEvent::Show: + page()->d->page->drawingArea()->setPageIsVisible(true); + break; + case QEvent::Hide: + page()->d->page->drawingArea()->setPageIsVisible(false); + break; + default: + break; + } + + // Here so that it can be reimplemented without breaking ABI. + return QGraphicsWidget::event(event); +} + +/*! \reimp +*/ +QSizeF QGraphicsWKView::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const +{ + if (which == Qt::PreferredSize) + return QSizeF(800, 600); + return QGraphicsWidget::sizeHint(which, constraint); +} + +/*! \reimp +*/ +QVariant QGraphicsWKView::inputMethodQuery(Qt::InputMethodQuery query) const +{ + // implement + return QVariant(); +} + +/*! \reimp +*/ +void QGraphicsWKView::keyPressEvent(QKeyEvent* ev) +{ + page()->d->keyPressEvent(ev); +} + +/*! \reimp +*/ +void QGraphicsWKView::keyReleaseEvent(QKeyEvent* ev) +{ + page()->d->keyReleaseEvent(ev); +} + +void QGraphicsWKView::hoverMoveEvent(QGraphicsSceneHoverEvent* ev) +{ + QGraphicsSceneMouseEvent me(QEvent::GraphicsSceneMouseMove); + me.setPos(ev->pos()); + me.setScreenPos(ev->screenPos()); + + page()->d->mouseMoveEvent(&me); + + if (!ev->isAccepted()) + QGraphicsItem::hoverMoveEvent(ev); +} + +void QGraphicsWKView::mouseMoveEvent(QGraphicsSceneMouseEvent* ev) +{ + page()->d->mouseMoveEvent(ev); + if (!ev->isAccepted()) + QGraphicsItem::mouseMoveEvent(ev); +} + +void QGraphicsWKView::mousePressEvent(QGraphicsSceneMouseEvent* ev) +{ + page()->d->mousePressEvent(ev); + if (!ev->isAccepted()) + QGraphicsItem::mousePressEvent(ev); +} + +void QGraphicsWKView::mouseReleaseEvent(QGraphicsSceneMouseEvent* ev) +{ + page()->d->mouseReleaseEvent(ev); + if (!ev->isAccepted()) + QGraphicsItem::mouseReleaseEvent(ev); +} + +void QGraphicsWKView::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* ev) +{ + page()->d->mouseDoubleClickEvent(ev); + if (!ev->isAccepted()) + QGraphicsItem::mouseReleaseEvent(ev); +} + +void QGraphicsWKView::wheelEvent(QGraphicsSceneWheelEvent* ev) +{ + page()->d->wheelEvent(ev); + if (!ev->isAccepted()) + QGraphicsItem::wheelEvent(ev); +} + +void QGraphicsWKView::touchEvent(QTouchEvent* ev) +{ + page()->d->touchEvent(ev); +} + +void QGraphicsWKView::focusInEvent(QFocusEvent*) +{ + page()->d->page->viewStateDidChange(WebPageProxy::ViewIsFocused | WebPageProxy::ViewWindowIsActive); +} + +void QGraphicsWKView::focusOutEvent(QFocusEvent*) +{ + page()->d->page->viewStateDidChange(WebPageProxy::ViewIsFocused | WebPageProxy::ViewWindowIsActive); +} + +void QGraphicsWKView::showContextMenu(QMenu* menu) +{ + // Remove the active menu in case this function is called twice. + if (d->activeMenu) + d->activeMenu->hide(); + + d->activeMenu = menu; + + QWidget* view = 0; + if (QGraphicsScene* myScene = scene()) { + const QList<QGraphicsView*> views = myScene->views(); + for (unsigned i = 0; i < views.size(); ++i) { + if (views.at(i) == QApplication::focusWidget()) { + view = views.at(i); + break; + } + } + if (!view) + view = views.value(0, 0); + } + if (view) + menu->setParent(view, menu->windowFlags()); + menu->exec(view->mapToGlobal(menu->pos())); + if (d->activeMenu == menu) + d->activeMenu = 0; +} + +void QGraphicsWKView::takeSnapshot(const QSize& size, const QRect& contentsRect) +{ +#if ENABLE(TILED_BACKING_STORE) + DrawingAreaProxy* drawingArea = page()->d->page->drawingArea(); + if (drawingArea->info().type != DrawingAreaInfo::Tiled) + return; + TiledDrawingAreaProxy* tiledDrawingArea = static_cast<TiledDrawingAreaProxy*>(drawingArea); + tiledDrawingArea->takeSnapshot(size, contentsRect); +#endif +} + +QGraphicsWKViewPrivate::QGraphicsWKViewPrivate(QGraphicsWKView* view) + : q(view) + , activeMenu(0) + , m_scaleCommitTimer(RunLoop::current(), this, &QGraphicsWKViewPrivate::commitScale) + , m_isChangingScale(false) +{ +} + +QRectF QGraphicsWKView::visibleRect() const +{ + if (!scene()) + return QRectF(); + + QList<QGraphicsView*> views = scene()->views(); + if (views.isEmpty()) + return QRectF(); + + QGraphicsView* graphicsView = views.at(0); + int xOffset = graphicsView->horizontalScrollBar()->value(); + int yOffset = graphicsView->verticalScrollBar()->value(); + return mapRectFromScene(QRectF(QPointF(xOffset, yOffset), graphicsView->viewport()->size())); +} + +void QGraphicsWKView::prepareScaleChange() +{ +#if ENABLE(TILED_BACKING_STORE) + ASSERT(!d->m_isChangingScale); + d->m_isChangingScale = true; + d->m_scaleCommitTimer.stop(); +#endif +} + +void QGraphicsWKView::commitScaleChange() +{ +#if ENABLE(TILED_BACKING_STORE) + ASSERT(d->m_isChangingScale); + d->m_isChangingScale = false; + d->commitScale(); +#endif +} + +void QGraphicsWKViewPrivate::onScaleChanged() +{ +#if ENABLE(TILED_BACKING_STORE) + if (!m_isChangingScale) + m_scaleCommitTimer.startOneShot(0.1); +#endif +} + +void QGraphicsWKViewPrivate::commitScale() +{ +#if ENABLE(TILED_BACKING_STORE) + DrawingAreaProxy* drawingArea = page->d->page->drawingArea(); + float newScale = q->scale(); + if (drawingArea->info().type == DrawingAreaInfo::Tiled) { + TiledDrawingAreaProxy* tiledDrawingArea = static_cast<TiledDrawingAreaProxy*>(drawingArea); + if (tiledDrawingArea->contentsScale() == newScale) + return; + tiledDrawingArea->setContentsScale(newScale); + // For now we block until complete. + tiledDrawingArea->waitUntilUpdatesComplete(); + } +#endif +} + +#include "moc_qgraphicswkview.cpp" diff --git a/Source/WebKit2/UIProcess/API/qt/qgraphicswkview.h b/Source/WebKit2/UIProcess/API/qt/qgraphicswkview.h new file mode 100644 index 0000000..caf8e0d --- /dev/null +++ b/Source/WebKit2/UIProcess/API/qt/qgraphicswkview.h @@ -0,0 +1,102 @@ +#ifndef qgraphicswkview_h +#define qgraphicswkview_h + +#include "qwebkitglobal.h" + +#include <WebKit2/WKBase.h> +#include <QGraphicsWidget> +#include "qwkpage.h" + +QT_BEGIN_NAMESPACE +class QCursor; +QT_END_NAMESPACE + +class QWKContext; +class QGraphicsWKViewPrivate; + +WKStringRef WKStringCreateWithQString(const QString& qString); +QString WKStringCopyQString(WKStringRef stringRef); + +class QWEBKIT_EXPORT QGraphicsWKView : public QGraphicsWidget { + Q_OBJECT + Q_PROPERTY(QString title READ title) + Q_PROPERTY(QUrl url READ url WRITE setUrl) + +public: + enum BackingStoreType { Simple, Tiled }; + QGraphicsWKView(QWKContext* context, BackingStoreType backingStoreType = Simple, QGraphicsItem* parent = 0); + + virtual ~QGraphicsWKView(); + + QWKPage* page() const; + + virtual void setGeometry(const QRectF&); + + void load(const QUrl&); + void setUrl(const QUrl&); + QUrl url() const; + + QString title() const; + + void triggerPageAction(QWKPage::WebAction action, bool checked = false); + + virtual void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*); + virtual QVariant itemChange(GraphicsItemChange, const QVariant&); + virtual bool event(QEvent*); + virtual QSizeF sizeHint(Qt::SizeHint, const QSizeF&) const; + virtual QVariant inputMethodQuery(Qt::InputMethodQuery) const; + + void takeSnapshot(const QSize& size, const QRect& documentRect); + + // FIXME: should not be public + virtual QRectF visibleRect() const; + + void prepareScaleChange(); + void commitScaleChange(); + +public: + Q_SIGNAL void titleChanged(const QString& title); + Q_SIGNAL void loadStarted(); + Q_SIGNAL void loadFinished(bool ok); + Q_SIGNAL void loadProgress(int progress); + Q_SIGNAL void initialLayoutCompleted(); + Q_SIGNAL void urlChanged(const QUrl&); + Q_SIGNAL void snapshotTaken(const QImage&); + +public Q_SLOTS: + void back(); + void forward(); + void reload(); + void stop(); + +protected: + virtual void keyPressEvent(QKeyEvent*); + virtual void keyReleaseEvent(QKeyEvent*); + virtual void mouseMoveEvent(QGraphicsSceneMouseEvent*); + virtual void mousePressEvent(QGraphicsSceneMouseEvent*); + virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent*); + virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent*); + virtual void wheelEvent(QGraphicsSceneWheelEvent*); + virtual void touchEvent(QTouchEvent*); + + virtual void hoverMoveEvent(QGraphicsSceneHoverEvent*); + + Q_SLOT void updateCursor(const QCursor&); + Q_SLOT void focusNextPrevChildCallback(bool next); + + virtual bool focusNextPrevChild(bool next); + virtual void focusInEvent(QFocusEvent*); + virtual void focusOutEvent(QFocusEvent*); + +private Q_SLOTS: + void showContextMenu(QMenu*); + +private: + Q_PRIVATE_SLOT(d, void onScaleChanged()); + + QGraphicsWKViewPrivate* d; + friend class QGraphicsWKViewPrivate; + friend class TiledDrawingAreaProxy; +}; + +#endif /* qgraphicswkview_h */ diff --git a/Source/WebKit2/UIProcess/API/qt/qwkcontext.cpp b/Source/WebKit2/UIProcess/API/qt/qwkcontext.cpp new file mode 100644 index 0000000..b17c100 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/qt/qwkcontext.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this program; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "qwkcontext.h" +#include "qwkcontext_p.h" + +#include "WebPlatformStrategies.h" + +using namespace WebKit; + +static inline void initializePlatformStrategiesIfNeeded() +{ + static bool initialized = false; + if (initialized) + return; + + WebPlatformStrategies::initialize(); + initialized = true; +} + +QWKContextPrivate::QWKContextPrivate(QWKContext* qq) + : q(qq) +{ + initializePlatformStrategiesIfNeeded(); +} + +QWKContextPrivate::~QWKContextPrivate() +{ +} + +QWKContext::QWKContext(QObject* parent) + : QObject(parent) + , d(new QWKContextPrivate(this)) +{ + d->context = WebContext::create(String()); +} + +QWKContext::QWKContext(WKContextRef contextRef, QObject* parent) + : QObject(parent) + , d(new QWKContextPrivate(this)) +{ + d->context = toImpl(contextRef); +} + +QWKContext::~QWKContext() +{ + delete d; +} + +#include "moc_qwkcontext.cpp" diff --git a/Source/WebKit2/UIProcess/API/qt/qwkcontext.h b/Source/WebKit2/UIProcess/API/qt/qwkcontext.h new file mode 100644 index 0000000..384d629 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/qt/qwkcontext.h @@ -0,0 +1,44 @@ +/* + Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef qwkcontext_h +#define qwkcontext_h + +#include "qwebkitglobal.h" +#include <QObject> +#include <WebKit2/WKContext.h> + +class QWKContextPrivate; + +class QWEBKIT_EXPORT QWKContext : public QObject { + Q_OBJECT +public: + QWKContext(QObject* parent = 0); + virtual ~QWKContext(); + + // Bridge from the C API + QWKContext(WKContextRef contextRef, QObject* parent = 0); + +private: + QWKContextPrivate* d; + + friend class QWKPagePrivate; +}; + +#endif /* qwkcontext_h */ diff --git a/Source/WebKit2/UIProcess/API/qt/qwkcontext_p.h b/Source/WebKit2/UIProcess/API/qt/qwkcontext_p.h new file mode 100644 index 0000000..625e87c --- /dev/null +++ b/Source/WebKit2/UIProcess/API/qt/qwkcontext_p.h @@ -0,0 +1,37 @@ +/* + Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + + +#ifndef qwkcontext_p_h +#define qwkcontext_p_h + +#include "WebContext.h" +#include <wtf/RefPtr.h> + +class QWKContextPrivate { +public: + QWKContextPrivate(QWKContext*); + ~QWKContextPrivate(); + + QWKContext* q; + + RefPtr<WebKit::WebContext> context; +}; + +#endif /* qkcontext_p_h */ diff --git a/Source/WebKit2/UIProcess/API/qt/qwkhistory.cpp b/Source/WebKit2/UIProcess/API/qt/qwkhistory.cpp new file mode 100644 index 0000000..3f424b5 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/qt/qwkhistory.cpp @@ -0,0 +1,182 @@ +/* + * Copyright (C) 2010 Juha Savolainen (juha.savolainen@weego.fi) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "config.h" +#include "qwkhistory.h" + +#include <QSharedData> +#include <QString> +#include <QUrl> +#include "qwkhistory_p.h" +#include "WebBackForwardList.h" +#include <WebKit2/WKArray.h> +#include <WebKit2/WKRetainPtr.h> +#include "WKBackForwardList.h" +#include "WKStringQt.h" +#include "WKURL.h" +#include "WKURLQt.h" + +using namespace WebKit; + +QWKHistoryItemPrivate::QWKHistoryItemPrivate(WKBackForwardListItemRef listItem) + : m_backForwardListItem(listItem) +{ +} + +QWKHistoryItemPrivate::~QWKHistoryItemPrivate() +{ +} + +QWKHistoryItem::QWKHistoryItem(const QWKHistoryItem& other) + : d(other.d) +{ +} + +QWKHistoryItem& QWKHistoryItem::QWKHistoryItem::operator=(const QWKHistoryItem& other) +{ + d = other.d; + return *this; +} + +QWKHistoryItem::QWKHistoryItem(WKBackForwardListItemRef item) + : d(new QWKHistoryItemPrivate(item)) +{ +} + +QWKHistoryItem::~QWKHistoryItem() +{ +} + +QString QWKHistoryItem::title() const +{ + if (!d->m_backForwardListItem) + return QString(); + WKRetainPtr<WKStringRef> title = WKBackForwardListItemCopyTitle(d->m_backForwardListItem.get()); + return WKStringCopyQString(title.get()); +} + +QUrl QWKHistoryItem::url() const +{ + if (!d->m_backForwardListItem) + return QUrl(); + WKRetainPtr<WKURLRef> url = WKBackForwardListItemCopyURL(d->m_backForwardListItem.get()); + return WKURLCopyQUrl(url.get()); +} + +QWKHistoryPrivate::QWKHistoryPrivate(WebKit::WebBackForwardList* list) + : m_backForwardList(list) +{ +} + +QWKHistory* QWKHistoryPrivate::createHistory(WebKit::WebBackForwardList* list) +{ + QWKHistory* history = new QWKHistory(); + history->d = new QWKHistoryPrivate(list); + return history; +} + +QWKHistoryPrivate::~QWKHistoryPrivate() +{ +} + +QWKHistory::QWKHistory() +{ +} + +QWKHistory::~QWKHistory() +{ + delete d; +} + +int QWKHistory::backListCount() const +{ + return WKBackForwardListGetBackListCount(toAPI(d->m_backForwardList)); +} + +int QWKHistory::forwardListCount() const +{ + return WKBackForwardListGetForwardListCount(toAPI(d->m_backForwardList)); +} + +int QWKHistory::count() const +{ + return backListCount() + forwardListCount(); +} + +QWKHistoryItem QWKHistory::currentItem() const +{ + WKRetainPtr<WKBackForwardListItemRef> itemRef = WKBackForwardListGetCurrentItem(toAPI(d->m_backForwardList)); + QWKHistoryItem item(itemRef.get()); + return item; +} + +QWKHistoryItem QWKHistory::backItem() const +{ + WKRetainPtr<WKBackForwardListItemRef> itemRef = WKBackForwardListGetBackItem(toAPI(d->m_backForwardList)); + QWKHistoryItem item(itemRef.get()); + return item; +} + +QWKHistoryItem QWKHistory::forwardItem() const +{ + WKRetainPtr<WKBackForwardListItemRef> itemRef = WKBackForwardListGetForwardItem(toAPI(d->m_backForwardList)); + QWKHistoryItem item(itemRef.get()); + return item; +} + +QWKHistoryItem QWKHistory::itemAt(int index) const +{ + WKRetainPtr<WKBackForwardListItemRef> itemRef = WKBackForwardListGetItemAtIndex(toAPI(d->m_backForwardList), index); + QWKHistoryItem item(itemRef.get()); + return item; +} + +QList<QWKHistoryItem> QWKHistory::backItems(int maxItems) const +{ + WKArrayRef arrayRef = WKBackForwardListCopyBackListWithLimit(toAPI(d->m_backForwardList), maxItems); + int size = WKArrayGetSize(arrayRef); + QList<QWKHistoryItem> itemList; + for (int i = 0; i < size; ++i) { + WKTypeRef wkHistoryItem = WKArrayGetItemAtIndex(arrayRef, i); + WKBackForwardListItemRef itemRef = static_cast<WKBackForwardListItemRef>(wkHistoryItem); + QWKHistoryItem item(itemRef); + itemList.append(item); + } + return itemList; +} + +QList<QWKHistoryItem> QWKHistory::forwardItems(int maxItems) const +{ + WKArrayRef arrayRef = WKBackForwardListCopyForwardListWithLimit(toAPI(d->m_backForwardList), maxItems); + int size = WKArrayGetSize(arrayRef); + QList<QWKHistoryItem> itemList; + for (int i = 0; i < size; ++i) { + WKTypeRef wkHistoryItem = WKArrayGetItemAtIndex(arrayRef, i); + WKBackForwardListItemRef itemRef = static_cast<WKBackForwardListItemRef>(wkHistoryItem); + QWKHistoryItem item(itemRef); + itemList.append(item); + } + return itemList; +} + diff --git a/Source/WebKit2/UIProcess/API/qt/qwkhistory.h b/Source/WebKit2/UIProcess/API/qt/qwkhistory.h new file mode 100644 index 0000000..81081c9 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/qt/qwkhistory.h @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2010 Juha Savolainen (juha.savolainen@weego.fi) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef qwkhistory_h +#define qwkhistory_h + +#include "qwebkitglobal.h" +#include <QObject> +#include <QSharedData> +#include "WKBackForwardListItem.h" + +class QWKHistoryPrivate; +class QWKHistoryItemPrivate; +class QUrl; +class QString; + +namespace WebKit { +class WebBackForwardList; +} + +class QWEBKIT_EXPORT QWKHistoryItem { +public: + QWKHistoryItem(const QWKHistoryItem& other); + QWKHistoryItem &operator=(const QWKHistoryItem& other); + + ~QWKHistoryItem(); + QString title() const; + QUrl url() const; + +private: + QWKHistoryItem(WKBackForwardListItemRef item); + + QExplicitlySharedDataPointer<QWKHistoryItemPrivate> d; + + friend class QWKHistory; + friend class QWKHistoryItemPrivate; +}; + +class QWEBKIT_EXPORT QWKHistory : public QObject { + Q_OBJECT +public: + int backListCount() const; + int forwardListCount() const; + int count() const; + QWKHistoryItem currentItem() const; + QWKHistoryItem backItem() const; + QWKHistoryItem forwardItem() const; + QWKHistoryItem itemAt(int index) const; + QList<QWKHistoryItem> backItems(int maxItems) const; + QList<QWKHistoryItem> forwardItems(int maxItems) const; + +private: + QWKHistory(); + ~QWKHistory(); + + QWKHistoryPrivate* d; + friend class QWKHistoryPrivate; + friend class QWKPagePrivate; +}; +#endif /* qwkhistory_h */ diff --git a/Source/WebKit2/UIProcess/API/qt/qwkhistory_p.h b/Source/WebKit2/UIProcess/API/qt/qwkhistory_p.h new file mode 100644 index 0000000..dd1d696 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/qt/qwkhistory_p.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2010 Juha Savolainen (juha.savolainen@weego.fi) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef qwkhistory_p_h +#define qwkhistory_p_h + +#include <QSharedData> +#include "qwebkitglobal.h" +#include <WebKit2/WKBase.h> +#include <WebKit2/WKRetainPtr.h> +#include <wtf/PassRefPtr.h> + +namespace WebKit { +class WebBackForwardList; +} + +class QWKHistory; + +class QWEBKIT_EXPORT QWKHistoryItemPrivate : public QSharedData { +public: + ~QWKHistoryItemPrivate(); +private: + QWKHistoryItemPrivate(WKBackForwardListItemRef listItem); + WKRetainPtr<WKBackForwardListItemRef> m_backForwardListItem; + + friend class QWKHistory; + friend class QWKHistoryItem; +}; + +class QWEBKIT_EXPORT QWKHistoryPrivate { +public: + static QWKHistory* createHistory(WebKit::WebBackForwardList* list); + +private: + QWKHistoryPrivate(WebKit::WebBackForwardList* list); + ~QWKHistoryPrivate(); + + WebKit::WebBackForwardList* m_backForwardList; + + friend class QWKHistory; +}; + +#endif /* qwkhistory_p_h */ diff --git a/Source/WebKit2/UIProcess/API/qt/qwkpage.cpp b/Source/WebKit2/UIProcess/API/qt/qwkpage.cpp new file mode 100644 index 0000000..638d9e3 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/qt/qwkpage.cpp @@ -0,0 +1,759 @@ +/* + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this program; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "qwkpage.h" +#include "qwkpage_p.h" + +#include "qwkpreferences_p.h" + +#include "ChunkedUpdateDrawingAreaProxy.h" +#include "ClientImpl.h" +#include "qgraphicswkview.h" +#include "qwkcontext.h" +#include "qwkcontext_p.h" +#include "qwkhistory.h" +#include "qwkhistory_p.h" +#include "FindIndicator.h" +#include "LocalizedStrings.h" +#include "NativeWebKeyboardEvent.h" +#include "TiledDrawingAreaProxy.h" +#include "WebContext.h" +#include "WebContextMenuProxyQt.h" +#include "WebEventFactoryQt.h" +#include "WebPopupMenuProxyQt.h" +#include "WKStringQt.h" +#include "WKURLQt.h" +#include "ViewportArguments.h" +#include <QAction> +#include <QApplication> +#include <QGraphicsSceneMouseEvent> +#include <QStyle> +#include <QTouchEvent> +#include <QtDebug> +#include <WebCore/Cursor.h> +#include <WebCore/FloatRect.h> +#include <WebKit2/WKFrame.h> +#include <WebKit2/WKPageGroup.h> +#include <WebKit2/WKRetainPtr.h> + +using namespace WebKit; +using namespace WebCore; + +static WebCore::ContextMenuAction contextMenuActionForWebAction(QWKPage::WebAction action) +{ + switch (action) { + case QWKPage::OpenLink: + return WebCore::ContextMenuItemTagOpenLink; + case QWKPage::OpenLinkInNewWindow: + return WebCore::ContextMenuItemTagOpenLinkInNewWindow; + case QWKPage::CopyLinkToClipboard: + return WebCore::ContextMenuItemTagCopyLinkToClipboard; + case QWKPage::OpenImageInNewWindow: + return WebCore::ContextMenuItemTagOpenImageInNewWindow; + case QWKPage::Cut: + return WebCore::ContextMenuItemTagCut; + case QWKPage::Copy: + return WebCore::ContextMenuItemTagCopy; + case QWKPage::Paste: + return WebCore::ContextMenuItemTagPaste; + case QWKPage::SelectAll: + return WebCore::ContextMenuItemTagSelectAll; + default: + ASSERT(false); + break; + } + return WebCore::ContextMenuItemTagNoAction; +} + +QWKPagePrivate::QWKPagePrivate(QWKPage* qq, QWKContext* c) + : q(qq) + , view(0) + , context(c) + , preferences(0) + , createNewPageFn(0) +{ + memset(actions, 0, sizeof(actions)); + page = context->d->context->createWebPage(this, 0); + history = QWKHistoryPrivate::createHistory(page->backForwardList()); +} + +QWKPagePrivate::~QWKPagePrivate() +{ + page->close(); + delete history; +} + +void QWKPagePrivate::init(QGraphicsItem* view, PassOwnPtr<DrawingAreaProxy> proxy) +{ + this->view = view; + page->setDrawingArea(proxy); + page->initializeWebPage(); +} + +void QWKPagePrivate::setCursor(const WebCore::Cursor& cursor) +{ +#ifndef QT_NO_CURSOR + emit q->cursorChanged(*cursor.platformCursor()); +#endif +} + +void QWKPagePrivate::setViewportArguments(const ViewportArguments& args) +{ + viewportArguments = args; + emit q->viewportChangeRequested(); +} + +void QWKPagePrivate::takeFocus(bool direction) +{ + emit q->focusNextPrevChild(direction); +} + +PassOwnPtr<DrawingAreaProxy> QWKPagePrivate::createDrawingAreaProxy() +{ + // FIXME: We should avoid this cast by decoupling the view from the page. + QGraphicsWKView* wkView = static_cast<QGraphicsWKView*>(view); + +#if ENABLE(TILED_BACKING_STORE) + if (page->drawingArea()->info().type == DrawingAreaInfo::Tiled) + return TiledDrawingAreaProxy::create(wkView, page.get()); +#endif + return ChunkedUpdateDrawingAreaProxy::create(wkView, page.get()); +} + +void QWKPagePrivate::setViewNeedsDisplay(const WebCore::IntRect& rect) +{ + view->update(QRect(rect)); +} + +void QWKPagePrivate::displayView() +{ + // FIXME: Implement. +} + +WebCore::IntSize QWKPagePrivate::viewSize() +{ + // FIXME: Implement. + return WebCore::IntSize(); +} + +bool QWKPagePrivate::isViewWindowActive() +{ + // FIXME: Implement. + return true; +} + +bool QWKPagePrivate::isViewFocused() +{ + // FIXME: Implement. + return true; +} + +bool QWKPagePrivate::isViewVisible() +{ + // FIXME: Implement. + return true; +} + +bool QWKPagePrivate::isViewInWindow() +{ + // FIXME: Implement. + return true; +} + +void QWKPagePrivate::pageDidRequestScroll(const IntSize& delta) +{ + emit q->scrollRequested(delta.width(), delta.height()); +} + +void QWKPagePrivate::didChangeContentsSize(const IntSize& newSize) +{ + emit q->contentsSizeChanged(QSize(newSize)); +} + +void QWKPagePrivate::toolTipChanged(const String&, const String& newTooltip) +{ + emit q->statusBarMessage(QString(newTooltip)); +} + +void QWKPagePrivate::registerEditCommand(PassRefPtr<WebEditCommandProxy>, WebPageProxy::UndoOrRedo) +{ +} + +void QWKPagePrivate::clearAllEditCommands() +{ +} + +FloatRect QWKPagePrivate::convertToDeviceSpace(const FloatRect& rect) +{ + return rect; +} + +FloatRect QWKPagePrivate::convertToUserSpace(const FloatRect& rect) +{ + return rect; +} + +void QWKPagePrivate::selectionChanged(bool, bool, bool, bool) +{ +} + +void QWKPagePrivate::didNotHandleKeyEvent(const NativeWebKeyboardEvent&) +{ +} + +PassRefPtr<WebPopupMenuProxy> QWKPagePrivate::createPopupMenuProxy(WebPageProxy*) +{ + return WebPopupMenuProxyQt::create(); +} + +PassRefPtr<WebContextMenuProxy> QWKPagePrivate::createContextMenuProxy(WebPageProxy*) +{ + return WebContextMenuProxyQt::create(q); +} + +void QWKPagePrivate::setFindIndicator(PassRefPtr<FindIndicator>, bool fadeOut) +{ +} + +void QWKPagePrivate::didCommitLoadForMainFrame(bool useCustomRepresentation) +{ +} + +void QWKPagePrivate::didFinishLoadingDataForCustomRepresentation(const CoreIPC::DataReference&) +{ +} + +void QWKPagePrivate::paint(QPainter* painter, QRect area) +{ + if (page->isValid() && page->drawingArea()) + page->drawingArea()->paint(IntRect(area), painter); + else + painter->fillRect(area, Qt::white); +} + +void QWKPagePrivate::keyPressEvent(QKeyEvent* ev) +{ + page->handleKeyboardEvent(NativeWebKeyboardEvent(ev)); +} + +void QWKPagePrivate::keyReleaseEvent(QKeyEvent* ev) +{ + page->handleKeyboardEvent(NativeWebKeyboardEvent(ev)); +} + +void QWKPagePrivate::mouseMoveEvent(QGraphicsSceneMouseEvent* ev) +{ + // For some reason mouse press results in mouse hover (which is + // converted to mouse move for WebKit). We ignore these hover + // events by comparing lastPos with newPos. + // NOTE: lastPos from the event always comes empty, so we work + // around that here. + static QPointF lastPos = QPointF(); + if (lastPos == ev->pos()) + return; + lastPos = ev->pos(); + + WebMouseEvent mouseEvent = WebEventFactory::createWebMouseEvent(ev, 0); + page->handleMouseEvent(mouseEvent); +} + +void QWKPagePrivate::mousePressEvent(QGraphicsSceneMouseEvent* ev) +{ + if (tripleClickTimer.isActive() && (ev->pos() - tripleClick).manhattanLength() < QApplication::startDragDistance()) { + WebMouseEvent mouseEvent = WebEventFactory::createWebMouseEvent(ev, 3); + page->handleMouseEvent(mouseEvent); + return; + } + + WebMouseEvent mouseEvent = WebEventFactory::createWebMouseEvent(ev, 1); + page->handleMouseEvent(mouseEvent); +} + +void QWKPagePrivate::mouseReleaseEvent(QGraphicsSceneMouseEvent* ev) +{ + WebMouseEvent mouseEvent = WebEventFactory::createWebMouseEvent(ev, 0); + page->handleMouseEvent(mouseEvent); +} + +void QWKPagePrivate::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* ev) +{ + WebMouseEvent mouseEvent = WebEventFactory::createWebMouseEvent(ev, 2); + page->handleMouseEvent(mouseEvent); + + tripleClickTimer.start(QApplication::doubleClickInterval(), q); + tripleClick = ev->pos().toPoint(); +} + +void QWKPagePrivate::wheelEvent(QGraphicsSceneWheelEvent* ev) +{ + WebWheelEvent wheelEvent = WebEventFactory::createWebWheelEvent(ev); + page->handleWheelEvent(wheelEvent); +} + +void QWKPagePrivate::setEditCommandState(const WTF::String&, bool, int) +{ +} + +void QWKPagePrivate::updateAction(QWKPage::WebAction action) +{ +#ifdef QT_NO_ACTION + Q_UNUSED(action) +#else + QAction* a = actions[action]; + if (!a) + return; + + RefPtr<WebKit::WebFrameProxy> mainFrame = page->mainFrame(); + if (!mainFrame) + return; + + bool enabled = a->isEnabled(); + bool checked = a->isChecked(); + + switch (action) { + case QWKPage::Back: + enabled = page->canGoBack(); + break; + case QWKPage::Forward: + enabled = page->canGoForward(); + break; + case QWKPage::Stop: + enabled = !(WebFrameProxy::LoadStateFinished == mainFrame->loadState()); + break; + case QWKPage::Reload: + enabled = (WebFrameProxy::LoadStateFinished == mainFrame->loadState()); + break; + default: + break; + } + + a->setEnabled(enabled); + + if (a->isCheckable()) + a->setChecked(checked); +#endif // QT_NO_ACTION +} + +void QWKPagePrivate::updateNavigationActions() +{ + updateAction(QWKPage::Back); + updateAction(QWKPage::Forward); + updateAction(QWKPage::Stop); + updateAction(QWKPage::Reload); +} + +#ifndef QT_NO_ACTION +void QWKPagePrivate::_q_webActionTriggered(bool checked) +{ + QAction* a = qobject_cast<QAction*>(q->sender()); + if (!a) + return; + QWKPage::WebAction action = static_cast<QWKPage::WebAction>(a->data().toInt()); + q->triggerAction(action, checked); +} +#endif // QT_NO_ACTION + +void QWKPagePrivate::touchEvent(QTouchEvent* event) +{ +#if ENABLE(TOUCH_EVENTS) + WebTouchEvent touchEvent = WebEventFactory::createWebTouchEvent(event); + page->handleTouchEvent(touchEvent); +#else + event->ignore(); +#endif +} + +QWKPage::QWKPage(QWKContext* context) + : d(new QWKPagePrivate(this, context)) +{ + WKPageLoaderClient loadClient = { + 0, /* version */ + this, /* clientInfo */ + qt_wk_didStartProvisionalLoadForFrame, + qt_wk_didReceiveServerRedirectForProvisionalLoadForFrame, + qt_wk_didFailProvisionalLoadWithErrorForFrame, + qt_wk_didCommitLoadForFrame, + qt_wk_didFinishDocumentLoadForFrame, + qt_wk_didFinishLoadForFrame, + qt_wk_didFailLoadWithErrorForFrame, + 0, /* didSameDocumentNavigationForFrame */ + qt_wk_didReceiveTitleForFrame, + qt_wk_didFirstLayoutForFrame, + qt_wk_didFirstVisuallyNonEmptyLayoutForFrame, + qt_wk_didRemoveFrameFromHierarchy, + 0, /* didDisplayInsecureContentForFrame */ + 0, /* didRunInsecureContentForFrame */ + 0, /* canAuthenticateAgainstProtectionSpaceInFrame */ + 0, /* didReceiveAuthenticationChallengeInFrame */ + qt_wk_didStartProgress, + qt_wk_didChangeProgress, + qt_wk_didFinishProgress, + qt_wk_didBecomeUnresponsive, + qt_wk_didBecomeResponsive, + 0, /* processDidCrash */ + 0 /* didChangeBackForwardList */ + }; + WKPageSetPageLoaderClient(pageRef(), &loadClient); + + WKPageUIClient uiClient = { + 0, /* version */ + this, /* clientInfo */ + qt_wk_createNewPage, + qt_wk_showPage, + qt_wk_close, + qt_wk_runJavaScriptAlert, + 0, /* runJavaScriptConfirm */ + 0, /* runJavaScriptPrompt */ + 0, /* setStatusText */ + 0, /* mouseDidMoveOverElement */ + 0, /* missingPluginButtonClicked */ + 0, /* didNotHandleKeyEvent */ + 0, /* toolbarsAreVisible */ + 0, /* setToolbarsAreVisible */ + 0, /* menuBarIsVisible */ + 0, /* setMenuBarIsVisible */ + 0, /* statusBarIsVisible */ + 0, /* setStatusBarIsVisible */ + 0, /* isResizable */ + 0, /* setIsResizable */ + 0, /* getWindowFrame */ + 0, /* setWindowFrame */ + 0, /* runBeforeUnloadConfirmPanel */ + 0, /* didDraw */ + 0, /* pageDidScroll */ + 0, /* exceededDatabaseQuota */ + 0, /* runOpenPanel */ + 0 /* decidePolicyForGeolocationPermissionRequest */ + }; + WKPageSetPageUIClient(pageRef(), &uiClient); +} + +QWKPage::~QWKPage() +{ + delete d; +} + +QWKPage::ViewportAttributes::ViewportAttributes() + : d(0) + , m_initialScaleFactor(-1.0) + , m_minimumScaleFactor(-1.0) + , m_maximumScaleFactor(-1.0) + , m_devicePixelRatio(-1.0) + , m_isUserScalable(true) + , m_isValid(false) +{ + +} + +QWKPage::ViewportAttributes::ViewportAttributes(const QWKPage::ViewportAttributes& other) + : d(other.d) + , m_initialScaleFactor(other.m_initialScaleFactor) + , m_minimumScaleFactor(other.m_minimumScaleFactor) + , m_maximumScaleFactor(other.m_maximumScaleFactor) + , m_devicePixelRatio(other.m_devicePixelRatio) + , m_isUserScalable(other.m_isUserScalable) + , m_isValid(other.m_isValid) + , m_size(other.m_size) +{ + +} + +QWKPage::ViewportAttributes::~ViewportAttributes() +{ + +} + +QWKPage::ViewportAttributes& QWKPage::ViewportAttributes::operator=(const QWKPage::ViewportAttributes& other) +{ + if (this != &other) { + d = other.d; + m_initialScaleFactor = other.m_initialScaleFactor; + m_minimumScaleFactor = other.m_minimumScaleFactor; + m_maximumScaleFactor = other.m_maximumScaleFactor; + m_devicePixelRatio = other.m_devicePixelRatio; + m_isUserScalable = other.m_isUserScalable; + m_isValid = other.m_isValid; + m_size = other.m_size; + } + + return *this; +} + +QWKPage::ViewportAttributes QWKPage::viewportAttributesForSize(const QSize& availableSize) const +{ + static int desktopWidth = 980; + static int deviceDPI = 160; + + ViewportAttributes result; + + if (availableSize.isEmpty()) + return result; // Returns an invalid instance. + + // FIXME: Add a way to get these data via the platform plugin and fall back + // to the size of the view. + int deviceWidth = 480; + int deviceHeight = 864; + + WebCore::ViewportAttributes conf = WebCore::computeViewportAttributes(d->viewportArguments, desktopWidth, deviceWidth, deviceHeight, deviceDPI, availableSize); + + result.m_isValid = true; + result.m_size = conf.layoutSize; + result.m_initialScaleFactor = conf.initialScale; + result.m_minimumScaleFactor = conf.minimumScale; + result.m_maximumScaleFactor = conf.maximumScale; + result.m_devicePixelRatio = conf.devicePixelRatio; + result.m_isUserScalable = conf.userScalable; + + return result; +} + +void QWKPage::setActualVisibleContentsRect(const QRect& rect) const +{ +#if ENABLE(TILED_BACKING_STORE) + d->page->setActualVisibleContentRect(rect); +#endif +} + +void QWKPage::timerEvent(QTimerEvent* ev) +{ + int timerId = ev->timerId(); + if (timerId == d->tripleClickTimer.timerId()) + d->tripleClickTimer.stop(); + else + QObject::timerEvent(ev); +} + +WKPageRef QWKPage::pageRef() const +{ + return toAPI(d->page.get()); +} + +QWKContext* QWKPage::context() const +{ + return d->context; +} + +QWKPreferences* QWKPage::preferences() const +{ + if (!d->preferences) { + WKPageGroupRef pageGroupRef = WKPageGetPageGroup(pageRef()); + d->preferences = QWKPreferencesPrivate::createPreferences(pageGroupRef); + } + + return d->preferences; +} + +void QWKPage::setCreateNewPageFunction(CreateNewPageFn function) +{ + d->createNewPageFn = function; +} + +void QWKPage::setCustomUserAgent(const QString& userAgent) +{ + WKRetainPtr<WKStringRef> wkUserAgent(WKStringCreateWithQString(userAgent)); + WKPageSetCustomUserAgent(pageRef(), wkUserAgent.get()); +} + +QString QWKPage::customUserAgent() const +{ + return WKStringCopyQString(WKPageCopyCustomUserAgent(pageRef())); +} + +void QWKPage::load(const QUrl& url) +{ + WKRetainPtr<WKURLRef> wkurl(WKURLCreateWithQUrl(url)); + WKPageLoadURL(pageRef(), wkurl.get()); +} + +void QWKPage::setUrl(const QUrl& url) +{ + load(url); +} + +QUrl QWKPage::url() const +{ + WKRetainPtr<WKFrameRef> frame = WKPageGetMainFrame(pageRef()); + if (!frame) + return QUrl(); + return WKURLCopyQUrl(WKFrameCopyURL(frame.get())); +} + +QString QWKPage::title() const +{ + return WKStringCopyQString(WKPageCopyTitle(pageRef())); +} + +void QWKPage::setViewportSize(const QSize& size) +{ + if (d->page->drawingArea()) + d->page->drawingArea()->setSize(IntSize(size)); +} + +qreal QWKPage::textZoomFactor() const +{ + return WKPageGetTextZoomFactor(pageRef()); +} + +void QWKPage::setTextZoomFactor(qreal zoomFactor) +{ + WKPageSetTextZoomFactor(pageRef(), zoomFactor); +} + +qreal QWKPage::pageZoomFactor() const +{ + return WKPageGetPageZoomFactor(pageRef()); +} + +void QWKPage::setPageZoomFactor(qreal zoomFactor) +{ + WKPageSetPageZoomFactor(pageRef(), zoomFactor); +} + +void QWKPage::setPageAndTextZoomFactors(qreal pageZoomFactor, qreal textZoomFactor) +{ + WKPageSetPageAndTextZoomFactors(pageRef(), pageZoomFactor, textZoomFactor); +} + +QWKHistory* QWKPage::history() const +{ + return d->history; +} + +void QWKPage::setResizesToContentsUsingLayoutSize(const QSize& targetLayoutSize) +{ +#if ENABLE(TILED_BACKING_STORE) + d->page->setResizesToContentsUsingLayoutSize(targetLayoutSize); +#endif +} + +#ifndef QT_NO_ACTION +void QWKPage::triggerAction(WebAction webAction, bool) +{ + switch (webAction) { + case Back: + d->page->goBack(); + return; + case Forward: + d->page->goForward(); + return; + case Stop: + d->page->stopLoading(); + return; + case Reload: + d->page->reload(/* reloadFromOrigin */ true); + return; + default: + break; + } + + QAction* qtAction = action(webAction); + WebKit::WebContextMenuItemData menuItemData(ActionType, contextMenuActionForWebAction(webAction), qtAction->text(), qtAction->isEnabled(), qtAction->isChecked()); + d->page->contextMenuItemSelected(menuItemData); +} +#endif // QT_NO_ACTION + +#ifndef QT_NO_ACTION +QAction* QWKPage::action(WebAction action) const +{ + if (action == QWKPage::NoWebAction || action >= WebActionCount) + return 0; + + if (d->actions[action]) + return d->actions[action]; + + QString text; + QIcon icon; + QStyle* style = qobject_cast<QApplication*>(QCoreApplication::instance())->style(); + bool checkable = false; + + switch (action) { + case OpenLink: + text = contextMenuItemTagOpenLink(); + break; + case OpenLinkInNewWindow: + text = contextMenuItemTagOpenLinkInNewWindow(); + break; + case CopyLinkToClipboard: + text = contextMenuItemTagCopyLinkToClipboard(); + break; + case OpenImageInNewWindow: + text = contextMenuItemTagOpenImageInNewWindow(); + break; + case Back: + text = contextMenuItemTagGoBack(); + icon = style->standardIcon(QStyle::SP_ArrowBack); + break; + case Forward: + text = contextMenuItemTagGoForward(); + icon = style->standardIcon(QStyle::SP_ArrowForward); + break; + case Stop: + text = contextMenuItemTagStop(); + icon = style->standardIcon(QStyle::SP_BrowserStop); + break; + case Reload: + text = contextMenuItemTagReload(); + icon = style->standardIcon(QStyle::SP_BrowserReload); + break; + case Cut: + text = contextMenuItemTagCut(); + break; + case Copy: + text = contextMenuItemTagCopy(); + break; + case Paste: + text = contextMenuItemTagPaste(); + break; + case SelectAll: + text = contextMenuItemTagSelectAll(); + break; + default: + return 0; + break; + } + + if (text.isEmpty()) + return 0; + + QAction* a = new QAction(d->q); + a->setText(text); + a->setData(action); + a->setCheckable(checkable); + a->setIcon(icon); + + connect(a, SIGNAL(triggered(bool)), this, SLOT(_q_webActionTriggered(bool))); + + d->actions[action] = a; + d->updateAction(action); + return a; +} +#endif // QT_NO_ACTION + +void QWKPage::findZoomableAreaForPoint(const QPoint& point) +{ + d->page->findZoomableAreaForPoint(point); +} + +void QWKPagePrivate::didFindZoomableArea(const IntRect& area) +{ + emit q->zoomableAreaFound(QRect(area)); +} + +#include "moc_qwkpage.cpp" diff --git a/Source/WebKit2/UIProcess/API/qt/qwkpage.h b/Source/WebKit2/UIProcess/API/qt/qwkpage.h new file mode 100644 index 0000000..e0bb4c3 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/qt/qwkpage.h @@ -0,0 +1,151 @@ +#ifndef qwkpage_h +#define qwkpage_h + +#include "qwebkitglobal.h" +#include <QAction> +#include <QObject> +#include <QPoint> +#include <QRect> +#include <QSize> +#include <QUrl> +#include <WebKit2/WKBase.h> +#include <WebKit2/WKPage.h> + +class QCursor; +class QGraphicsItem; +class QWKContext; +class QWKGraphicsWidget; +class QWKPreferences; +class QWKPagePrivate; +class QtViewportAttributesPrivate; +class QWKHistory; + +class QWEBKIT_EXPORT QWKPage : public QObject { + Q_OBJECT + Q_PROPERTY(QString title READ title) + Q_PROPERTY(QUrl url READ url WRITE setUrl) + +public: + enum WebAction { + NoWebAction = - 1, + + OpenLink, + OpenLinkInNewWindow, + CopyLinkToClipboard, + OpenImageInNewWindow, + + Back, + Forward, + Stop, + Reload, + + Cut, + Copy, + Paste, + SelectAll, + + WebActionCount + }; + + class ViewportAttributes { + public: + ViewportAttributes(); + ViewportAttributes(const QWKPage::ViewportAttributes& other); + + ~ViewportAttributes(); + + QWKPage::ViewportAttributes& operator=(const QWKPage::ViewportAttributes& other); + + inline qreal initialScaleFactor() const { return m_initialScaleFactor; }; + inline qreal minimumScaleFactor() const { return m_minimumScaleFactor; }; + inline qreal maximumScaleFactor() const { return m_maximumScaleFactor; }; + inline qreal devicePixelRatio() const { return m_devicePixelRatio; }; + inline bool isUserScalable() const { return m_isUserScalable; }; + inline bool isValid() const { return m_isValid; }; + inline QSize size() const { return m_size; }; + + private: + QSharedDataPointer<QtViewportAttributesPrivate> d; + qreal m_initialScaleFactor; + qreal m_minimumScaleFactor; + qreal m_maximumScaleFactor; + qreal m_devicePixelRatio; + bool m_isUserScalable; + bool m_isValid; + QSize m_size; + + friend class QWKPage; + }; + + QWKPage(QWKContext*); + virtual ~QWKPage(); + + WKPageRef pageRef() const; + + QWKPreferences* preferences() const; + + void load(const QUrl& url); + void setUrl(const QUrl& url); + QUrl url() const; + + QString title() const; + + void setViewportSize(const QSize&); + ViewportAttributes viewportAttributesForSize(const QSize& availableSize) const; + + void setActualVisibleContentsRect(const QRect& rect) const; + + void setResizesToContentsUsingLayoutSize(const QSize& targetLayoutSize); + + QAction* action(WebAction action) const; + void triggerAction(WebAction action, bool checked = false); + + typedef QWKPage* (*CreateNewPageFn)(QWKPage*); + void setCreateNewPageFunction(CreateNewPageFn function); + + void setCustomUserAgent(const QString&); + QString customUserAgent() const; + + qreal textZoomFactor() const; + qreal pageZoomFactor() const; + void setTextZoomFactor(qreal zoomFactor); + void setPageZoomFactor(qreal zoomFactor); + void setPageAndTextZoomFactors(qreal pageZoomFactor, qreal textZoomFactor); + + QWKHistory* history() const; + QWKContext* context() const; + + void findZoomableAreaForPoint(const QPoint&); + +public: + Q_SIGNAL void statusBarMessage(const QString&); + Q_SIGNAL void titleChanged(const QString&); + Q_SIGNAL void loadStarted(); + Q_SIGNAL void loadFinished(bool ok); + Q_SIGNAL void loadProgress(int progress); + Q_SIGNAL void initialLayoutCompleted(); + Q_SIGNAL void urlChanged(const QUrl&); + Q_SIGNAL void contentsSizeChanged(const QSize&); + Q_SIGNAL void scrollRequested(int dx, int dy); + Q_SIGNAL void cursorChanged(const QCursor&); + Q_SIGNAL void viewportChangeRequested(); + Q_SIGNAL void windowCloseRequested(); + Q_SIGNAL void zoomableAreaFound(const QRect&); + Q_SIGNAL void focusNextPrevChild(bool); + Q_SIGNAL void showContextMenu(QMenu*); + +protected: + void timerEvent(QTimerEvent*); + +private: +#ifndef QT_NO_ACTION + Q_PRIVATE_SLOT(d, void _q_webActionTriggered(bool checked)); +#endif + QWKPagePrivate* d; + + friend class QGraphicsWKView; + friend class QGraphicsWKViewPrivate; + friend class QWKPagePrivate; +}; + +#endif /* qwkpage_h */ diff --git a/Source/WebKit2/UIProcess/API/qt/qwkpage_p.h b/Source/WebKit2/UIProcess/API/qt/qwkpage_p.h new file mode 100644 index 0000000..85135c2 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/qt/qwkpage_p.h @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this program; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef qwkpage_p_h +#define qwkpage_p_h + +#include "DrawingAreaProxy.h" +#include "PageClient.h" +#include "qwkpage.h" +#include "WebPageProxy.h" +#include <wtf/PassOwnPtr.h> +#include <wtf/RefPtr.h> +#include <QBasicTimer> +#include <QGraphicsView> +#include <QKeyEvent> + +class QGraphicsWKView; +class QWKPreferences; + +class QWKPagePrivate : WebKit::PageClient { +public: + QWKPagePrivate(QWKPage*, QWKContext*); + ~QWKPagePrivate(); + + static QWKPagePrivate* get(QWKPage* page) { return page->d; } + + void init(QGraphicsItem*, WTF::PassOwnPtr<WebKit::DrawingAreaProxy>); + + // PageClient + virtual PassOwnPtr<WebKit::DrawingAreaProxy> createDrawingAreaProxy(); + virtual void setViewNeedsDisplay(const WebCore::IntRect&); + virtual void displayView(); + + virtual WebCore::IntSize viewSize(); + virtual bool isViewWindowActive(); + virtual bool isViewFocused(); + virtual bool isViewVisible(); + virtual bool isViewInWindow(); + +#if USE(ACCELERATED_COMPOSITING) + void pageDidEnterAcceleratedCompositing() { } + void pageDidLeaveAcceleratedCompositing() { } +#endif // USE(ACCELERATED_COMPOSITING) + virtual void pageDidRequestScroll(const WebCore::IntSize&); + virtual void processDidCrash() { } + virtual void didRelaunchProcess() { } + virtual void didChangeContentsSize(const WebCore::IntSize&); + virtual void didFindZoomableArea(const WebCore::IntRect&); + virtual void setCursor(const WebCore::Cursor&); + virtual void setViewportArguments(const WebCore::ViewportArguments&); + virtual void takeFocus(bool direction); + virtual void toolTipChanged(const WTF::String&, const WTF::String&); + virtual void registerEditCommand(PassRefPtr<WebKit::WebEditCommandProxy>, WebKit::WebPageProxy::UndoOrRedo); + virtual void clearAllEditCommands(); + virtual WebCore::FloatRect convertToDeviceSpace(const WebCore::FloatRect&); + virtual WebCore::FloatRect convertToUserSpace(const WebCore::FloatRect&); + virtual void didNotHandleKeyEvent(const WebKit::NativeWebKeyboardEvent&); + virtual void selectionChanged(bool, bool, bool, bool); + virtual PassRefPtr<WebKit::WebPopupMenuProxy> createPopupMenuProxy(WebKit::WebPageProxy*); + virtual PassRefPtr<WebKit::WebContextMenuProxy> createContextMenuProxy(WebKit::WebPageProxy*); + + virtual void setFindIndicator(PassRefPtr<WebKit::FindIndicator>, bool fadeOut); + + virtual void didCommitLoadForMainFrame(bool useCustomRepresentation); + virtual void didFinishLoadingDataForCustomRepresentation(const CoreIPC::DataReference&); + virtual double customRepresentationZoomFactor() { return 1; } + virtual void setCustomRepresentationZoomFactor(double) { } + + void paint(QPainter* painter, QRect); + + void keyPressEvent(QKeyEvent*); + void keyReleaseEvent(QKeyEvent*); + void mouseMoveEvent(QGraphicsSceneMouseEvent*); + void mousePressEvent(QGraphicsSceneMouseEvent*); + void mouseReleaseEvent(QGraphicsSceneMouseEvent*); + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent*); + void wheelEvent(QGraphicsSceneWheelEvent*); + + void updateAction(QWKPage::WebAction action); + void updateNavigationActions(); + void updateEditorActions(); + void setEditCommandState(const WTF::String&, bool, int); + + void _q_webActionTriggered(bool checked); + + void touchEvent(QTouchEvent*); + + QWKPage* q; + + QGraphicsItem* view; + QWKContext* context; + QWKHistory* history; + + QAction* actions[QWKPage::WebActionCount]; + QWKPreferences* preferences; + + RefPtr<WebKit::WebPageProxy> page; + + WebCore::ViewportArguments viewportArguments; + + QWKPage::CreateNewPageFn createNewPageFn; + + QPoint tripleClick; + QBasicTimer tripleClickTimer; +}; + +class QtViewportAttributesPrivate : public QSharedData { +public: + QtViewportAttributesPrivate(QWKPage::ViewportAttributes* qq) + : q(qq) + { } + + QWKPage::ViewportAttributes* q; +}; + + +#endif /* qkpage_p_h */ diff --git a/Source/WebKit2/UIProcess/API/qt/qwkpreferences.cpp b/Source/WebKit2/UIProcess/API/qt/qwkpreferences.cpp new file mode 100644 index 0000000..dea18aa --- /dev/null +++ b/Source/WebKit2/UIProcess/API/qt/qwkpreferences.cpp @@ -0,0 +1,185 @@ +/* + Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "qwkpreferences.h" + +#include "WKPageGroup.h" +#include "WKPreferences.h" +#include "WKStringQt.h" +#include "WKRetainPtr.h" +#include "qwkpreferences_p.h" + + +QWKPreferences* QWKPreferencesPrivate::createPreferences(WKPageGroupRef pageGroupRef) +{ + QWKPreferences* prefs = new QWKPreferences; + prefs->d->ref = WKPageGroupGetPreferences(pageGroupRef); + return prefs; +} + +QWKPreferences* QWKPreferencesPrivate::createSharedPreferences() +{ + QWKPreferences* prefs = new QWKPreferences; + prefs->d->ref = WKPreferencesCreate(); + return prefs; +} + +QWKPreferences* QWKPreferences::sharedPreferences() +{ + static QWKPreferences* instance = 0; + + if (!instance) + instance = QWKPreferencesPrivate::createSharedPreferences(); + return instance; +} + +QWKPreferences::QWKPreferences() + : d(new QWKPreferencesPrivate) +{ +} + +QWKPreferences::~QWKPreferences() +{ + delete d; +} + +void QWKPreferences::setFontFamily(FontFamily which, const QString& family) +{ + switch (which) { + case StandardFont: + WKPreferencesSetStandardFontFamily(d->ref, WKStringCreateWithQString(family)); + break; + case FixedFont: + WKPreferencesSetFixedFontFamily(d->ref, WKStringCreateWithQString(family)); + break; + case SerifFont: + WKPreferencesSetSerifFontFamily(d->ref, WKStringCreateWithQString(family)); + break; + case SansSerifFont: + WKPreferencesSetSansSerifFontFamily(d->ref, WKStringCreateWithQString(family)); + break; + case CursiveFont: + WKPreferencesSetCursiveFontFamily(d->ref, WKStringCreateWithQString(family)); + break; + case FantasyFont: + WKPreferencesSetFantasyFontFamily(d->ref, WKStringCreateWithQString(family)); + break; + default: + break; + } +} + +QString QWKPreferences::fontFamily(FontFamily which) const +{ + switch (which) { + case StandardFont: { + WKRetainPtr<WKStringRef> stringRef(AdoptWK, WKPreferencesCopyStandardFontFamily(d->ref)); + return WKStringCopyQString(stringRef.get()); + } + case FixedFont: { + WKRetainPtr<WKStringRef> stringRef(AdoptWK, WKPreferencesCopyFixedFontFamily(d->ref)); + return WKStringCopyQString(stringRef.get()); + } + case SerifFont: { + WKRetainPtr<WKStringRef> stringRef(AdoptWK, WKPreferencesCopySerifFontFamily(d->ref)); + return WKStringCopyQString(stringRef.get()); + } + case SansSerifFont: { + WKRetainPtr<WKStringRef> stringRef(AdoptWK, WKPreferencesCopySansSerifFontFamily(d->ref)); + return WKStringCopyQString(stringRef.get()); + } + case CursiveFont: { + WKRetainPtr<WKStringRef> stringRef(AdoptWK, WKPreferencesCopyCursiveFontFamily(d->ref)); + return WKStringCopyQString(stringRef.get()); + } + case FantasyFont: { + WKRetainPtr<WKStringRef> stringRef(AdoptWK, WKPreferencesCopyFantasyFontFamily(d->ref)); + return WKStringCopyQString(stringRef.get()); + } + default: + return QString(); + } +} + +bool QWKPreferences::testAttribute(WebAttribute attr) const +{ + switch (attr) { + case AutoLoadImages: + return WKPreferencesGetLoadsImagesAutomatically(d->ref); + case JavascriptEnabled: + return WKPreferencesGetJavaScriptEnabled(d->ref); + case PluginsEnabled: + return WKPreferencesGetPluginsEnabled(d->ref); + case OfflineWebApplicationCacheEnabled: + return WKPreferencesGetOfflineWebApplicationCacheEnabled(d->ref); + case LocalStorageEnabled: + return WKPreferencesGetLocalStorageEnabled(d->ref); + case XSSAuditingEnabled: + return WKPreferencesGetXSSAuditorEnabled(d->ref); + case FrameFlatteningEnabled: + return WKPreferencesGetFrameFlatteningEnabled(d->ref); + case PrivateBrowsingEnabled: + return WKPreferencesGetPrivateBrowsingEnabled(d->ref); + case DeveloperExtrasEnabled: + return WKPreferencesGetDeveloperExtrasEnabled(d->ref); + case DnsPrefetchEnabled: + return WKPreferencesGetDNSPrefetchingEnabled(d->ref); + default: + ASSERT_NOT_REACHED(); + return false; + } +} + +void QWKPreferences::setAttribute(WebAttribute attr, bool on) +{ + switch (attr) { + case AutoLoadImages: + WKPreferencesSetLoadsImagesAutomatically(d->ref, on); + break; + case JavascriptEnabled: + WKPreferencesSetJavaScriptEnabled(d->ref, on); + break; + case PluginsEnabled: + WKPreferencesSetPluginsEnabled(d->ref, on); + break; + case OfflineWebApplicationCacheEnabled: + WKPreferencesSetOfflineWebApplicationCacheEnabled(d->ref, on); + break; + case LocalStorageEnabled: + WKPreferencesSetLocalStorageEnabled(d->ref, on); + break; + case XSSAuditingEnabled: + WKPreferencesSetXSSAuditorEnabled(d->ref, on); + break; + case FrameFlatteningEnabled: + WKPreferencesSetFrameFlatteningEnabled(d->ref, on); + break; + case PrivateBrowsingEnabled: + WKPreferencesSetPrivateBrowsingEnabled(d->ref, on); + break; + case DeveloperExtrasEnabled: + WKPreferencesSetDeveloperExtrasEnabled(d->ref, on); + break; + case DnsPrefetchEnabled: + WKPreferencesSetDNSPrefetchingEnabled(d->ref, on); + break; + default: + ASSERT_NOT_REACHED(); + } +} diff --git a/Source/WebKit2/UIProcess/API/qt/qwkpreferences.h b/Source/WebKit2/UIProcess/API/qt/qwkpreferences.h new file mode 100644 index 0000000..d9f7bc0 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/qt/qwkpreferences.h @@ -0,0 +1,72 @@ +/* + Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef QWKPREFERENCES_H +#define QWKPREFERENCES_H + +#include "qwebkitglobal.h" + +class QWKPage; +class QWKPreferencesPrivate; + +class QWEBKIT_EXPORT QWKPreferences { +public: + enum FontFamily { + StandardFont, + FixedFont, + SerifFont, + SansSerifFont, + CursiveFont, + FantasyFont + }; + + enum WebAttribute { + AutoLoadImages, + JavascriptEnabled, + PluginsEnabled, + OfflineWebApplicationCacheEnabled, + LocalStorageEnabled, + XSSAuditingEnabled, + FrameFlatteningEnabled, + PrivateBrowsingEnabled, + DeveloperExtrasEnabled, + DnsPrefetchEnabled + }; + + static QWKPreferences* sharedPreferences(); + + void setFontFamily(FontFamily which, const QString& family); + QString fontFamily(FontFamily which) const; + + void setAttribute(WebAttribute attr, bool on); + bool testAttribute(WebAttribute attr) const; + +private: + Q_DISABLE_COPY(QWKPreferences) + + QWKPreferences(); + ~QWKPreferences(); + + QWKPreferencesPrivate *d; + + friend class QWKPage; + friend class QWKPreferencesPrivate; +}; + +#endif // QWKPREFERENCES_H diff --git a/Source/WebKit2/UIProcess/API/qt/qwkpreferences_p.h b/Source/WebKit2/UIProcess/API/qt/qwkpreferences_p.h new file mode 100644 index 0000000..7fe2389 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/qt/qwkpreferences_p.h @@ -0,0 +1,28 @@ +/* + Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "WKPreferences.h" + +class QWKPreferencesPrivate { +public: + static QWKPreferences* createPreferences(WKPageGroupRef); + static QWKPreferences* createSharedPreferences(); + + WKPreferencesRef ref; +}; |