diff options
author | Jocelyn Turcotte <jocelyn.turcotte@nokia.com> | 2010-04-06 10:36:47 (GMT) |
---|---|---|
committer | Jocelyn Turcotte <jocelyn.turcotte@nokia.com> | 2010-04-06 10:36:47 (GMT) |
commit | bb35b65bbfba82e0dd0ac306d3dab54436cdaff6 (patch) | |
tree | 8174cb262a960ff7b2e4aa8f1aaf154db71d2636 /src/3rdparty/webkit/WebKit/qt/Api/qwebview.cpp | |
parent | 4b27d0d887269583a0f76e922948f8c25e96ab88 (diff) | |
download | Qt-bb35b65bbfba82e0dd0ac306d3dab54436cdaff6.zip Qt-bb35b65bbfba82e0dd0ac306d3dab54436cdaff6.tar.gz Qt-bb35b65bbfba82e0dd0ac306d3dab54436cdaff6.tar.bz2 |
Update src/3rdparty/webkit from trunk.
Imported from 839d8709327f925aacb3b6362c06152594def97e
in branch qtwebkit-2.0 of repository
git://gitorious.org/+qtwebkit-developers/webkit/qtwebkit.git
Rubber-stamped-by: Simon Hausmann
Diffstat (limited to 'src/3rdparty/webkit/WebKit/qt/Api/qwebview.cpp')
-rw-r--r-- | src/3rdparty/webkit/WebKit/qt/Api/qwebview.cpp | 203 |
1 files changed, 137 insertions, 66 deletions
diff --git a/src/3rdparty/webkit/WebKit/qt/Api/qwebview.cpp b/src/3rdparty/webkit/WebKit/qt/Api/qwebview.cpp index 79538ff..4387f4a 100644 --- a/src/3rdparty/webkit/WebKit/qt/Api/qwebview.cpp +++ b/src/3rdparty/webkit/WebKit/qt/Api/qwebview.cpp @@ -22,10 +22,11 @@ #include "config.h" #include "qwebview.h" +#include "Page.h" #include "QWebPageClient.h" +#include "Settings.h" #include "qwebframe.h" #include "qwebpage_p.h" - #include "qbitmap.h" #include "qevent.h" #include "qpainter.h" @@ -44,6 +45,7 @@ public: } void _q_pageDestroyed(); + void unsetPageIfExists(); QWebView *view; QWebPage *page; @@ -59,96 +61,141 @@ void QWebViewPrivate::_q_pageDestroyed() #ifdef Q_WS_MAEMO_5 #include "qabstractkineticscroller.h" +#include "qapplication.h" + +// QCoreApplication::sendSpontaneousEvent() is private, hence this friend wrapper +bool qt_sendSpontaneousEvent(QObject* receiver, QEvent* ev) +{ + return QCoreApplication::sendSpontaneousEvent(receiver, ev); +} -class QWebViewKineticScroller : public QAbstractKineticScroller { +class QWebViewKineticScroller : public QObject, public QAbstractKineticScroller { public: - QWebViewKineticScroller() : QAbstractKineticScroller() {} - // remember the frame where the button was pressed + QWebViewKineticScroller() + : QObject() + , QAbstractKineticScroller() + , m_view(0) + , m_ignoreEvents(false) + { + } + + void setWidget(QWebView* widget) + { + if (m_view) { + m_view->removeEventFilter(this); + QWebFrame* frame = m_view->page()->mainFrame(); + frame->setScrollBarPolicy(Qt::Vertical, m_oldVerticalScrollBarPolicy); + frame->setScrollBarPolicy(Qt::Horizontal, m_oldHorizontalScrollBarPolicy); + } + + m_view = widget; + setParent(m_view); + if (m_view) { + QWebFrame* frame = m_view->page()->mainFrame(); + m_oldHorizontalScrollBarPolicy = frame->scrollBarPolicy(Qt::Horizontal); + m_oldVerticalScrollBarPolicy = frame->scrollBarPolicy(Qt::Vertical); + frame->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); + frame->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); + m_view->installEventFilter(this); + } + } + +protected: bool eventFilter(QObject* o, QEvent* ev) { + if (!o || m_view != o || m_ignoreEvents || !m_view->isEnabled()) + return QObject::eventFilter(o, ev); + + bool res = false; + switch (ev->type()) { case QEvent::MouseButtonPress: { + // remember the frame where the button was pressed QWebFrame* hitFrame = scrollingFrameAt(static_cast<QMouseEvent*>(ev)->pos()); if (hitFrame) m_frame = hitFrame; - break; + // fall through } + case QEvent::MouseMove: + case QEvent::MouseButtonRelease: + case QEvent::MouseButtonDblClick: + res = handleMouseEvent(static_cast<QMouseEvent*>(ev)); + break; default: break; } - return QAbstractKineticScroller::eventFilter(o, ev); + return res ? true : QObject::eventFilter(o, ev); } -protected: - QWebFrame* currentFrame() const + void cancelLeftMouseButtonPress(const QPoint& /* globalPressPos */) { - if (!m_frame.isNull()) - return m_frame.data(); - - QWebView* view = static_cast<QWebView*>(widget()); - QWebFrame* frame = view->page()->mainFrame(); - return frame; + QMouseEvent cmem(QEvent::MouseMove, QPoint(-INT_MAX, -INT_MAX), Qt::LeftButton, QApplication::mouseButtons() | Qt::LeftButton, QApplication::keyboardModifiers()); + sendEvent(m_view, &cmem); + QMouseEvent cmer(QEvent::MouseButtonRelease, QPoint(-INT_MAX, -INT_MAX), Qt::LeftButton, QApplication::mouseButtons() & ~Qt::LeftButton, QApplication::keyboardModifiers()); + sendEvent(m_view, &cmer); } - // Returns the innermost frame at the given position that can scroll. - QWebFrame* scrollingFrameAt(const QPoint& pos) const + QWebFrame* currentFrame() const { - QWebView* view = static_cast<QWebView*>(widget()); - QWebFrame* mainFrame = view->page()->mainFrame(); - QWebFrame* hitFrame = mainFrame->hitTestContent(pos).frame(); - QSize range = hitFrame->contentsSize() - hitFrame->geometry().size(); + if (m_frame) + return m_frame; - while (hitFrame && range.width() <= 1 && range.height() <= 1) - hitFrame = hitFrame->parentFrame(); + if (m_view) + return m_view->page()->mainFrame(); - return hitFrame; + return 0; } - void attachToWidget() + // Returns the innermost frame at the given position that can scroll. + QWebFrame* scrollingFrameAt(const QPoint& pos) const { - QWebView* view = static_cast<QWebView*>(widget()); - QWebFrame* mainFrame = view->page()->mainFrame(); - m_oldHorizontalScrollBarPolicy = mainFrame->scrollBarPolicy(Qt::Horizontal); - m_oldVerticalScrollBarPolicy = mainFrame->scrollBarPolicy(Qt::Vertical); - mainFrame->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); - mainFrame->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); - view->installEventFilter(this); - } + QWebFrame* hitFrame = 0; + if (m_view) { + QWebFrame* frame = m_view->page()->mainFrame(); + hitFrame = frame->hitTestContent(pos).frame(); + QSize range = hitFrame->contentsSize() - hitFrame->geometry().size(); - void removeFromWidget() - { - QWebView* view = static_cast<QWebView*>(widget()); - view->removeEventFilter(this); - QWebFrame* mainFrame = view->page()->mainFrame(); - mainFrame->setScrollBarPolicy(Qt::Vertical, m_oldVerticalScrollBarPolicy); - mainFrame->setScrollBarPolicy(Qt::Horizontal, m_oldHorizontalScrollBarPolicy); + while (hitFrame && range.width() <= 1 && range.height() <= 1) + hitFrame = hitFrame->parentFrame(); + + return hitFrame; + } } - QRect positionRange() const + QPoint maximumScrollPosition() const { - QRect r; QWebFrame* frame = currentFrame(); - r.setSize(frame->contentsSize() - frame->geometry().size()); - return r; + QSize s = frame ? frame->contentsSize() - frame->geometry().size() : QSize(0, 0); + return QPoint(qMax(0, s.width()), qMax(0, s.height())); } - QPoint position() const + QPoint scrollPosition() const { QWebFrame* frame = currentFrame(); - return frame->scrollPosition(); + return frame ? frame->scrollPosition() : QPoint(); } QSize viewportSize() const { - return static_cast<QWebView*>(widget())->page()->viewportSize(); + return m_view ? m_view->page()->viewportSize() : QSize(); } - void setPosition(const QPoint& point, const QPoint& /* overShootDelta */) + void setScrollPosition(const QPoint& point, const QPoint& /* overShootDelta */) { QWebFrame* frame = currentFrame(); - frame->setScrollPosition(point); + if (frame) + frame->setScrollPosition(point); } + void sendEvent(QWidget* w, QEvent* ev) + { + m_ignoreEvents = true; + qt_sendSpontaneousEvent(w, ev); + m_ignoreEvents = false; + } + + QWebView* m_view; + bool m_ignoreEvents; QPointer<QWebFrame> m_frame; Qt::ScrollBarPolicy m_oldVerticalScrollBarPolicy; Qt::ScrollBarPolicy m_oldHorizontalScrollBarPolicy; @@ -253,9 +300,13 @@ QWebView::QWebView(QWidget *parent) setAttribute(Qt::WA_InputMethodEnabled); #endif +#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) + setAttribute(Qt::WA_AcceptTouchEvents); +#endif #if defined(Q_WS_MAEMO_5) QAbstractKineticScroller* scroller = new QWebViewKineticScroller(); - scroller->setWidget(this); + static_cast<QWebViewKineticScroller*>(scroller)->setWidget(this); + setProperty("kineticScroller", QVariant::fromValue(scroller)); #endif setAcceptDrops(true); @@ -297,6 +348,29 @@ QWebPage *QWebView::page() const return d->page; } +void QWebViewPrivate::unsetPageIfExists() +{ + if (!page) + return; + + // if the page client is the special client constructed for + // delegating the responsibilities to a QWidget, we need + // to destroy it. + + if (page->d->client && page->d->client->isQWidgetClient()) + delete page->d->client; + + page->d->client = 0; + + // if the page was created by us, we own it and need to + // destroy it as well. + + if (page->parent() == view) + delete page; + else + page->disconnect(view); +} + /*! Makes \a page the new web page of the web view. @@ -310,14 +384,10 @@ void QWebView::setPage(QWebPage* page) { if (d->page == page) return; - if (d->page) { - d->page->d->client = 0; // unset the page client - if (d->page->parent() == this) - delete d->page; - else - d->page->disconnect(this); - } + + d->unsetPageIfExists(); d->page = page; + if (d->page) { d->page->setView(this); d->page->setPalette(palette()); @@ -345,6 +415,9 @@ void QWebView::setPage(QWebPage* page) this, SLOT(updateMicroFocus())); connect(d->page, SIGNAL(destroyed()), this, SLOT(_q_pageDestroyed())); +#if USE(ACCELERATED_COMPOSITING) + d->page->d->page->settings()->setAcceleratedCompositingEnabled(false); +#endif } setAttribute(Qt::WA_OpaquePaintEvent, d->page); update(); @@ -374,19 +447,11 @@ void QWebView::load(const QUrl &url) \sa url(), urlChanged() */ -#if QT_VERSION < 0x040400 && !defined(qdoc) -void QWebView::load(const QWebNetworkRequest &request) -#else void QWebView::load(const QNetworkRequest &request, QNetworkAccessManager::Operation operation, const QByteArray &body) -#endif { - page()->mainFrame()->load(request -#if QT_VERSION >= 0x040400 - , operation, body -#endif - ); + page()->mainFrame()->load(request, operation, body); } /*! @@ -740,7 +805,6 @@ bool QWebView::event(QEvent *e) if (e->type() == QEvent::ShortcutOverride) { d->page->event(e); #ifndef QT_NO_CURSOR -#if QT_VERSION >= 0x040400 } else if (e->type() == QEvent::CursorChange) { // An unsetCursor will set the cursor to Qt::ArrowCursor. // Thus this cursor change might be a QWidget::unsetCursor() @@ -753,6 +817,13 @@ bool QWebView::event(QEvent *e) if (cursor().shape() == Qt::ArrowCursor) d->page->d->client->resetCursor(); #endif +#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) + } else if (e->type() == QEvent::TouchBegin + || e->type() == QEvent::TouchEnd + || e->type() == QEvent::TouchUpdate) { + d->page->event(e); + if (e->isAccepted()) + return true; #endif } else if (e->type() == QEvent::Leave) d->page->event(e); |