Skip to content

Commit

Permalink
[qtwebkit] Add experimental header component
Browse files Browse the repository at this point in the history
  • Loading branch information
Raine Makelainen committed Sep 12, 2013
1 parent e007fad commit 962f672
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 5 deletions.
16 changes: 14 additions & 2 deletions qtwebkit/Source/WebKit2/UIProcess/API/qt/qquickwebpage.cpp
Expand Up @@ -144,15 +144,27 @@ qreal QQuickWebPage::contentsScale() const
return d->contentsScale;
}

QPointF QQuickWebPage::adjustedPosition() const
{
qreal xPos = x();
qreal yPos = y();

if (d->viewportItem->experimental()->headerItem()) {
yPos -= d->viewportItem->experimental()->headerItem()->height();
}
return QPointF(xPos, yPos);
}

QTransform QQuickWebPage::transformFromItem() const
{
return transformToItem().inverted();
}

QTransform QQuickWebPage::transformToItem() const
{
qreal xPos = x();
qreal yPos = y();
QPointF pos = adjustedPosition();
qreal xPos = pos.x();
qreal yPos = pos.y();

if (d->viewportItem->experimental()->flickableViewportEnabled()) {
// Flickable moves its contentItem so we need to take that position into
Expand Down
2 changes: 2 additions & 0 deletions qtwebkit/Source/WebKit2/UIProcess/API/qt/qquickwebpage_p.h
Expand Up @@ -25,6 +25,7 @@

#include <QtCore/QSharedPointer>
#include <QtQuick/QQuickItem>
#include <QPointF>

class QQuickWebPagePrivate;
class QQuickWebView;
Expand All @@ -44,6 +45,7 @@ class QWEBKIT_EXPORT QQuickWebPage : public QQuickItem {
const QSizeF& contentsSize() const;
void setContentsScale(qreal);
qreal contentsScale() const;
QPointF adjustedPosition() const;

QTransform transformFromItem() const;
QTransform transformToItem() const;
Expand Down
72 changes: 72 additions & 0 deletions qtwebkit/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp
Expand Up @@ -61,6 +61,9 @@
#include <JavaScriptCore/JSRetainPtr.h>
#include <QDateTime>
#include <QtCore/QFile>
#include <qqmlinfo.h>
#include <QtQml/private/qqmlglobal_p.h>
#include <QtQml/QQmlContext>
#include <QtQml/QJSValue>
#include <QtQuick/QQuickView>
#include <WKOpenPanelResultListener.h>
Expand Down Expand Up @@ -271,6 +274,7 @@ QQuickWebViewPrivate::QQuickWebViewPrivate(QQuickWebView* viewport)
, filePicker(0)
, databaseQuotaDialog(0)
, colorChooser(0)
, headerComponent(0)
, m_firstFrameRendered(false)
, m_betweenLoadCommitAndFirstFrame(false)
, m_customLayoutWidth(0)
Expand Down Expand Up @@ -799,6 +803,50 @@ void QQuickWebViewPrivate::setContentPos(const QPointF& pos)
q->setContentY(pos.y());
}

void QQuickWebViewPrivate::updateHeader()
{
Q_Q(QQuickWebView);
if (!q->isComponentComplete()) {
return;
}

bool headerItemChanged = false;
if (headerItem) {
headerItem->setParentItem(0);
headerItem.reset();
headerItemChanged = true;
}

QQuickItem *item = 0;
if (headerComponent) {
QQmlContext *creationContext = headerComponent->creationContext();
QQmlContext *context = new QQmlContext(
creationContext ? creationContext : qmlContext(q));
QObject *nobj = headerComponent->beginCreate(context);
if (nobj) {
QQml_setParent_noEvent(context, nobj);
item = qobject_cast<QQuickItem *>(nobj);
if (item) {
headerItem.reset(item);
QQml_setParent_noEvent(item, q->contentItem());
headerItem->setParentItem(q->contentItem());
headerItemChanged = true;
} else {
qmlInfo(q) << "Header component must be an Item";
delete nobj;
}
} else {
qmlInfo(q) << "Creation of the header failed. Error: " << headerComponent->errors();
delete context;
}
headerComponent->completeCreate();
}

if (headerItemChanged) {
emit q->experimental()->headerItemChanged();
}
}

WebCore::IntSize QQuickWebViewPrivate::viewSize() const
{
return WebCore::IntSize(pageView->width(), pageView->height());
Expand Down Expand Up @@ -1231,6 +1279,29 @@ void QQuickWebViewExperimental::setColorChooser(QQmlComponent* colorChooser)
emit colorChooserChanged();
}

QQmlComponent *QQuickWebViewExperimental::header() const
{
Q_D(const QQuickWebView);
return d->headerComponent;
}

void QQuickWebViewExperimental::setHeader(QQmlComponent *headerComponent)
{
Q_Q(QQuickWebView);
Q_D(QQuickWebView);
if (d->headerComponent != headerComponent) {
d->headerComponent = headerComponent;
d->updateHeader();
emit headerChanged();
}
}

QQuickItem *QQuickWebViewExperimental::headerItem() const
{
Q_D(const QQuickWebView);
return d->headerItem.data();
}

QString QQuickWebViewExperimental::userAgent() const
{
Q_D(const QQuickWebView);
Expand Down Expand Up @@ -1877,6 +1948,7 @@ void QQuickWebView::componentComplete()

d->onComponentComplete();
d->updateViewportSize();
d->updateHeader();
}

void QQuickWebView::keyPressEvent(QKeyEvent* event)
Expand Down
8 changes: 8 additions & 0 deletions qtwebkit/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h
Expand Up @@ -273,6 +273,8 @@ class QWEBKIT_EXPORT QQuickWebViewExperimental : public QObject {
Q_PROPERTY(QQmlComponent* filePicker READ filePicker WRITE setFilePicker NOTIFY filePickerChanged)
Q_PROPERTY(QQmlComponent* databaseQuotaDialog READ databaseQuotaDialog WRITE setDatabaseQuotaDialog NOTIFY databaseQuotaDialogChanged)
Q_PROPERTY(QQmlComponent* colorChooser READ colorChooser WRITE setColorChooser NOTIFY colorChooserChanged)
Q_PROPERTY(QQmlComponent* header READ header WRITE setHeader NOTIFY headerChanged FINAL)
Q_PROPERTY(QQuickItem* headerItem READ headerItem NOTIFY headerItemChanged FINAL)

Q_PROPERTY(QWebPreferences* preferences READ preferences CONSTANT FINAL)
Q_PROPERTY(QWebKitTest* test READ test CONSTANT FINAL)
Expand Down Expand Up @@ -309,6 +311,10 @@ class QWEBKIT_EXPORT QQuickWebViewExperimental : public QObject {
void setDatabaseQuotaDialog(QQmlComponent*);
QQmlComponent* colorChooser() const;
void setColorChooser(QQmlComponent*);
QQmlComponent* header() const;
void setHeader(QQmlComponent*);
QQuickItem* headerItem() const;

QString userAgent() const;
void setUserAgent(const QString& userAgent);
int deviceWidth() const;
Expand Down Expand Up @@ -378,6 +384,8 @@ public Q_SLOTS:
void filePickerChanged();
void databaseQuotaDialogChanged();
void colorChooserChanged();
void headerChanged();
void headerItemChanged();
void downloadRequested(QWebDownloadItem* downloadItem);
void permissionRequested(QWebPermissionRequest* permission);
void messageReceived(const QVariantMap& message);
Expand Down
4 changes: 4 additions & 0 deletions qtwebkit/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h
Expand Up @@ -129,6 +129,8 @@ class QQuickWebViewPrivate {
QPointF contentPos() const;
void setContentPos(const QPointF&);

void updateHeader();

void updateIcon();

// PageClient.
Expand Down Expand Up @@ -175,6 +177,7 @@ class QQuickWebViewPrivate {
QScopedPointer<WebKit::QtWebPageUIClient> pageUIClient;

QScopedPointer<QQuickWebPage> pageView;
QScopedPointer<QQuickItem> headerItem;
QQuickWebView* q_ptr;
QQuickWebViewExperimental* experimental;

Expand All @@ -190,6 +193,7 @@ class QQuickWebViewPrivate {
QQmlComponent* filePicker;
QQmlComponent* databaseQuotaDialog;
QQmlComponent* colorChooser;
QQmlComponent* headerComponent;

QList<QUrl> userScripts;

Expand Down
Expand Up @@ -118,7 +118,7 @@ void PageViewportControllerClientQt::setContentRectVisiblePositionAtScale(const

// To animate the position together with the scale we multiply the position with the current scale
// and add it to the page position (displacement on the flickable contentItem because of additional items).
QPointF newPosition(m_pageItem->position() + location * itemScale);
QPointF newPosition(m_pageItem->adjustedPosition() + location * itemScale);

m_viewportItem->setContentPos(newPosition);
}
Expand Down Expand Up @@ -344,7 +344,7 @@ QRectF PageViewportControllerClientQt::nearestValidVisibleContentsRect() const

void PageViewportControllerClientQt::setViewportPosition(const FloatPoint& contentsPoint)
{
QPointF newPosition((m_pageItem->position() + QPointF(contentsPoint)) * m_pageItem->contentsScale());
QPointF newPosition((m_pageItem->adjustedPosition() + QPointF(contentsPoint)) * m_pageItem->contentsScale());
// The contentX and contentY property changes trigger a visible rect update.
m_viewportItem->setContentPos(newPosition);
}
Expand Down
2 changes: 1 addition & 1 deletion qtwebkit/Source/WebKit2/WebKit2.pri
Expand Up @@ -76,6 +76,6 @@ linux-*: {
LIBS += -lrt
}

have?(QTQUICK): QT += qml quick
have?(QTQUICK): QT += qml qml-private quick v8-private

enable?(GEOLOCATION): QT += location

0 comments on commit 962f672

Please sign in to comment.