summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2010-05-14 07:59:52 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2010-05-14 07:59:52 (GMT)
commitb70dd15c635990306bab35e440d7b561cac7c67e (patch)
treeb77966b6e81063257cff343bc61ba9c0dc4cb9b3 /src
parentb915d0aa46599f707df4db6eb33965602a2d7422 (diff)
parentd9ab23c190de774ea093652060981e14ac5aeaf8 (diff)
downloadQt-b70dd15c635990306bab35e440d7b561cac7c67e.zip
Qt-b70dd15c635990306bab35e440d7b561cac7c67e.tar.gz
Qt-b70dd15c635990306bab35e440d7b561cac7c67e.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/qt-qml: Qt.include() support in worker scripts Only add "include" property in non-workerscript threads Missing files from 645b9ee9dd6e0576542cc61872ecedb408ca8a89 Reduce the chance of AnchorAnimation animating geometry changes it Add Qt.include() method for scoped inclusion of JavaScript files Fix crash in ParentAnimation. Revert "Fix crash in ParentAnimation." Symbian build fix to declarative auto and benchmark tests Revert "Use raster graphicssystem for qml.app on OS X." Fix crash in ParentAnimation. Minor declarative webview tweaks Removed dependency of QDeclarativeWebView to private Qt (Declarative) API Note that you need to unset a flag to create a visual item Follow-up on Flickable changes. ListModel::get() should return undefined if bad index specified Add an example spinner. Fix crash on remote content. Dates and variants are not considered nested objects
Diffstat (limited to 'src')
-rw-r--r--src/declarative/QmlChanges.txt5
-rw-r--r--src/declarative/graphicsitems/qdeclarativeflickable.cpp80
-rw-r--r--src/declarative/graphicsitems/qdeclarativeflickable_p.h16
-rw-r--r--src/declarative/graphicsitems/qdeclarativegridview.cpp19
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem.cpp5
-rw-r--r--src/declarative/graphicsitems/qdeclarativelistview.cpp18
-rw-r--r--src/declarative/graphicsitems/qdeclarativepath.cpp4
-rw-r--r--src/declarative/graphicsitems/qdeclarativepathview.cpp33
-rw-r--r--src/declarative/graphicsitems/qdeclarativepathview_p.h4
-rw-r--r--src/declarative/qml/qdeclarativecompositetypemanager.cpp4
-rw-r--r--src/declarative/qml/qdeclarativecontext.cpp4
-rw-r--r--src/declarative/qml/qdeclarativecontextscriptclass.cpp46
-rw-r--r--src/declarative/qml/qdeclarativecontextscriptclass_p.h4
-rw-r--r--src/declarative/qml/qdeclarativeengine.cpp6
-rw-r--r--src/declarative/qml/qdeclarativeglobalscriptclass_p.h1
-rw-r--r--src/declarative/qml/qdeclarativeinclude.cpp316
-rw-r--r--src/declarative/qml/qdeclarativeinclude_p.h115
-rw-r--r--src/declarative/qml/qdeclarativeworkerscript.cpp6
-rw-r--r--src/declarative/qml/qml.pri2
-rw-r--r--src/declarative/util/qdeclarativeanimation.cpp14
-rw-r--r--src/declarative/util/qdeclarativelistmodel.cpp31
-rw-r--r--src/declarative/util/qdeclarativepropertychanges.cpp4
-rw-r--r--src/declarative/util/qdeclarativestate.cpp3
-rw-r--r--src/declarative/util/qdeclarativestate_p.h1
-rw-r--r--src/declarative/util/qdeclarativestateoperations.cpp16
-rw-r--r--src/declarative/util/qdeclarativestateoperations_p.h3
-rw-r--r--src/imports/webkit/qdeclarativewebview.cpp244
-rw-r--r--src/imports/webkit/qdeclarativewebview_p.h32
28 files changed, 789 insertions, 247 deletions
diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt
index 9ab3f08..604c14c 100644
--- a/src/declarative/QmlChanges.txt
+++ b/src/declarative/QmlChanges.txt
@@ -3,10 +3,9 @@ The changes below are pre Qt 4.7.0 RC
Flickable:
- overShoot is replaced by boundsBehavior enumeration
- - flicking is replaced by flickingHorizontally and flickingVertically
- - moving is replaced by movingHorizontally and movingVertically
+ - flickingHorizontally and flickingVertically properties added
+ - movingHorizontally and movingVertically properties added
- flickDirection is renamed flickableDirection
- - onMovementStarted, onMovementEnded, onFlickStarted and onFlickEnded signals removed
Component: isReady, isLoading, isError and isNull properties removed, use
status property instead
QList<QObject*> models no longer provide properties in model object. The
diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp
index a7a8983..a03a51d 100644
--- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp
@@ -230,13 +230,17 @@ void QDeclarativeFlickablePrivate::flick(AxisData &data, qreal minExtent, qreal
timeline.callback(QDeclarativeTimeLineCallback(&data.move, fixupCallback, this));
if (!flickingHorizontally && q->xflick()) {
flickingHorizontally = true;
- emit q->flickingChanged(); // deprecated
+ emit q->flickingChanged();
emit q->flickingHorizontallyChanged();
+ if (!flickingVertically)
+ emit q->flickStarted();
}
if (!flickingVertically && q->yflick()) {
flickingVertically = true;
- emit q->flickingChanged(); // deprecated
+ emit q->flickingChanged();
emit q->flickingVerticallyChanged();
+ if (!flickingHorizontally)
+ emit q->flickStarted();
}
} else {
timeline.reset(data.move);
@@ -365,6 +369,37 @@ void QDeclarativeFlickablePrivate::updateBeginningEnd()
*/
/*!
+ \qmlsignal Flickable::onMovementStarted()
+
+ This handler is called when the view begins moving due to user
+ interaction.
+*/
+
+/*!
+ \qmlsignal Flickable::onMovementEnded()
+
+ This handler is called when the view stops moving due to user
+ interaction. If a flick was generated, this handler will
+ be triggered once the flick stops. If a flick was not
+ generated, the handler will be triggered when the
+ user stops dragging - i.e. a mouse or touch release.
+*/
+
+/*!
+ \qmlsignal Flickable::onFlickStarted()
+
+ This handler is called when the view is flicked. A flick
+ starts from the point that the mouse or touch is released,
+ while still in motion.
+*/
+
+/*!
+ \qmlsignal Flickable::onFlickEnded()
+
+ This handler is called when the view stops moving due to a flick.
+*/
+
+/*!
\qmlproperty real Flickable::visibleArea.xPosition
\qmlproperty real Flickable::visibleArea.widthRatio
\qmlproperty real Flickable::visibleArea.yPosition
@@ -474,9 +509,10 @@ void QDeclarativeFlickable::setInteractive(bool interactive)
d->vTime = d->timeline.time();
d->flickingHorizontally = false;
d->flickingVertically = false;
- emit flickingChanged(); // deprecated
+ emit flickingChanged();
emit flickingHorizontallyChanged();
emit flickingVerticallyChanged();
+ emit flickEnded();
}
emit interactiveChanged();
}
@@ -799,8 +835,10 @@ void QDeclarativeFlickable::wheelEvent(QGraphicsSceneWheelEvent *event)
d->vData.velocity = qMin(event->delta() - d->vData.smoothVelocity.value(), qreal(-250.0));
d->flickingVertically = false;
d->flickY(d->vData.velocity);
- if (d->flickingVertically)
+ if (d->flickingVertically) {
+ d->vMoved = true;
movementStarting();
+ }
event->accept();
} else if (xflick()) {
if (event->delta() > 0)
@@ -809,8 +847,10 @@ void QDeclarativeFlickable::wheelEvent(QGraphicsSceneWheelEvent *event)
d->hData.velocity = qMin(event->delta() - d->hData.smoothVelocity.value(), qreal(-250.0));
d->flickingHorizontally = false;
d->flickX(d->hData.velocity);
- if (d->flickingHorizontally)
+ if (d->flickingHorizontally) {
+ d->hMoved = true;
movementStarting();
+ }
event->accept();
} else {
QDeclarativeItem::wheelEvent(event);
@@ -1269,11 +1309,11 @@ void QDeclarativeFlickable::setFlickDeceleration(qreal deceleration)
bool QDeclarativeFlickable::isFlicking() const
{
Q_D(const QDeclarativeFlickable);
- qmlInfo(this) << "'flicking' is deprecated. Please use 'flickingHorizontally' and 'flickingVertically' instead.";
return d->flickingHorizontally || d->flickingVertically;
}
/*!
+ \qmlproperty bool Flickable::flicking
\qmlproperty bool Flickable::flickingHorizontally
\qmlproperty bool Flickable::flickingVertically
@@ -1322,11 +1362,11 @@ void QDeclarativeFlickable::setPressDelay(int delay)
bool QDeclarativeFlickable::isMoving() const
{
Q_D(const QDeclarativeFlickable);
- qmlInfo(this) << "'moving' is deprecated. Please use 'movingHorizontally' or 'movingVertically' instead.";
return d->movingHorizontally || d->movingVertically;
}
/*!
+ \qmlproperty bool Flickable::moving
\qmlproperty bool Flickable::movingHorizontally
\qmlproperty bool Flickable::movingVertically
@@ -1350,13 +1390,17 @@ void QDeclarativeFlickable::movementStarting()
Q_D(QDeclarativeFlickable);
if (d->hMoved && !d->movingHorizontally) {
d->movingHorizontally = true;
- emit movingChanged(); // deprecated
+ emit movingChanged();
emit movingHorizontallyChanged();
+ if (!d->movingVertically)
+ emit movementStarted();
}
- if (d->vMoved && !d->movingVertically) {
+ else if (d->vMoved && !d->movingVertically) {
d->movingVertically = true;
- emit movingChanged(); // deprecated
+ emit movingChanged();
emit movingVerticallyChanged();
+ if (!d->movingHorizontally)
+ emit movementStarted();
}
}
@@ -1365,25 +1409,33 @@ void QDeclarativeFlickable::movementEnding()
Q_D(QDeclarativeFlickable);
if (d->flickingHorizontally) {
d->flickingHorizontally = false;
- emit flickingChanged(); // deprecated
+ emit flickingChanged();
emit flickingHorizontallyChanged();
+ if (!d->flickingVertically)
+ emit flickEnded();
}
if (d->flickingVertically) {
d->flickingVertically = false;
- emit flickingChanged(); // deprecated
+ emit flickingChanged();
emit flickingVerticallyChanged();
+ if (!d->flickingHorizontally)
+ emit flickEnded();
}
if (d->movingHorizontally) {
d->movingHorizontally = false;
d->hMoved = false;
- emit movingChanged(); // deprecated
+ emit movingChanged();
emit movingHorizontallyChanged();
+ if (!d->movingVertically)
+ emit movementEnded();
}
if (d->movingVertically) {
d->movingVertically = false;
d->vMoved = false;
- emit movingChanged(); // deprecated
+ emit movingChanged();
emit movingVerticallyChanged();
+ if (!d->movingHorizontally)
+ emit movementEnded();
}
d->hData.smoothVelocity.setValue(0);
d->vData.smoothVelocity.setValue(0);
diff --git a/src/declarative/graphicsitems/qdeclarativeflickable_p.h b/src/declarative/graphicsitems/qdeclarativeflickable_p.h
index 7944e2b..05887b8 100644
--- a/src/declarative/graphicsitems/qdeclarativeflickable_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeflickable_p.h
@@ -68,10 +68,10 @@ class Q_DECLARATIVE_EXPORT QDeclarativeFlickable : public QDeclarativeItem
Q_PROPERTY(BoundsBehavior boundsBehavior READ boundsBehavior WRITE setBoundsBehavior NOTIFY boundsBehaviorChanged)
Q_PROPERTY(qreal maximumFlickVelocity READ maximumFlickVelocity WRITE setMaximumFlickVelocity NOTIFY maximumFlickVelocityChanged)
Q_PROPERTY(qreal flickDeceleration READ flickDeceleration WRITE setFlickDeceleration NOTIFY flickDecelerationChanged)
- Q_PROPERTY(bool moving READ isMoving NOTIFY movingChanged) // deprecated
+ Q_PROPERTY(bool moving READ isMoving NOTIFY movingChanged)
Q_PROPERTY(bool movingHorizontally READ isMovingHorizontally NOTIFY movingHorizontallyChanged)
Q_PROPERTY(bool movingVertically READ isMovingVertically NOTIFY movingVerticallyChanged)
- Q_PROPERTY(bool flicking READ isFlicking NOTIFY flickingChanged) // deprecated
+ Q_PROPERTY(bool flicking READ isFlicking NOTIFY flickingChanged)
Q_PROPERTY(bool flickingHorizontally READ isFlickingHorizontally NOTIFY flickingHorizontallyChanged)
Q_PROPERTY(bool flickingVertically READ isFlickingVertically NOTIFY flickingVerticallyChanged)
Q_PROPERTY(FlickableDirection flickDirection READ flickDirection WRITE setFlickDirection NOTIFY flickableDirectionChanged) // deprecated
@@ -120,10 +120,10 @@ public:
qreal contentY() const;
void setContentY(qreal pos);
- bool isMoving() const; // deprecated
+ bool isMoving() const;
bool isMovingHorizontally() const;
bool isMovingVertically() const;
- bool isFlicking() const; // deprecated
+ bool isFlicking() const;
bool isFlickingHorizontally() const;
bool isFlickingVertically() const;
@@ -160,10 +160,10 @@ Q_SIGNALS:
void contentHeightChanged();
void contentXChanged();
void contentYChanged();
- void movingChanged(); // deprecated
+ void movingChanged();
void movingHorizontallyChanged();
void movingVerticallyChanged();
- void flickingChanged(); // deprecated
+ void flickingChanged();
void flickingHorizontallyChanged();
void flickingVerticallyChanged();
void horizontalVelocityChanged();
@@ -177,6 +177,10 @@ Q_SIGNALS:
void maximumFlickVelocityChanged();
void flickDecelerationChanged();
void pressDelayChanged();
+ void movementStarted();
+ void movementEnded();
+ void flickStarted();
+ void flickEnded();
protected:
virtual bool sceneEventFilter(QGraphicsItem *, QEvent *);
diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp
index 396acd0..fe78c84 100644
--- a/src/declarative/graphicsitems/qdeclarativegridview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp
@@ -347,8 +347,7 @@ public:
void QDeclarativeGridViewPrivate::init()
{
Q_Q(QDeclarativeGridView);
- QObject::connect(q, SIGNAL(movingHorizontallyChanged()), q, SLOT(animStopped()));
- QObject::connect(q, SIGNAL(movingVerticallyChanged()), q, SLOT(animStopped()));
+ QObject::connect(q, SIGNAL(movementEnded()), q, SLOT(animStopped()));
q->setFlag(QGraphicsItem::ItemIsFocusScope);
q->setFlickableDirection(QDeclarativeFlickable::VerticalFlick);
addItemChangeListener(this, Geometry);
@@ -878,13 +877,15 @@ void QDeclarativeGridViewPrivate::flick(AxisData &data, qreal minExtent, qreal m
timeline.callback(QDeclarativeTimeLineCallback(&data.move, fixupCallback, this));
if (!flickingHorizontally && q->xflick()) {
flickingHorizontally = true;
- emit q->flickingChanged(); // deprecated
+ emit q->flickingChanged();
emit q->flickingHorizontallyChanged();
+ emit q->flickStarted();
}
if (!flickingVertically && q->yflick()) {
flickingVertically = true;
- emit q->flickingChanged(); // deprecated
+ emit q->flickingChanged();
emit q->flickingVerticallyChanged();
+ emit q->flickStarted();
}
} else {
timeline.reset(data.move);
@@ -2311,13 +2312,9 @@ void QDeclarativeGridView::destroyingItem(QDeclarativeItem *item)
void QDeclarativeGridView::animStopped()
{
Q_D(QDeclarativeGridView);
- if ((!d->movingVertically && d->flow == QDeclarativeGridView::LeftToRight)
- || (!d->movingHorizontally && d->flow == QDeclarativeGridView::TopToBottom))
- {
- d->bufferMode = QDeclarativeGridViewPrivate::NoBuffer;
- if (d->haveHighlightRange && d->highlightRange == QDeclarativeGridView::StrictlyEnforceRange)
- d->updateHighlight();
- }
+ d->bufferMode = QDeclarativeGridViewPrivate::NoBuffer;
+ if (d->haveHighlightRange && d->highlightRange == QDeclarativeGridView::StrictlyEnforceRange)
+ d->updateHighlight();
}
void QDeclarativeGridView::refill()
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp
index 9433ba0..f251ba1 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp
@@ -1194,7 +1194,10 @@ QDeclarativeKeysAttached *QDeclarativeKeysAttached::qmlAttachedProperties(QObjec
width and height, \l {anchor-layout}{anchoring} and key handling.
You can subclass QDeclarativeItem to provide your own custom visual item that inherits
- these features.
+ these features. Note that, because it does not draw anything, QDeclarativeItem sets the
+ QGraphicsItem::ItemHasNoContents flag. If you subclass QDeclarativeItem to create a visual
+ item, you will need to unset this flag.
+
*/
/*!
diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp
index 20106cb..46e9ce3 100644
--- a/src/declarative/graphicsitems/qdeclarativelistview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp
@@ -525,8 +525,7 @@ void QDeclarativeListViewPrivate::init()
Q_Q(QDeclarativeListView);
q->setFlag(QGraphicsItem::ItemIsFocusScope);
addItemChangeListener(this, Geometry);
- QObject::connect(q, SIGNAL(movingHorizontallyChanged()), q, SLOT(animStopped()));
- QObject::connect(q, SIGNAL(movingVerticallyChanged()), q, SLOT(animStopped()));
+ QObject::connect(q, SIGNAL(movementEnded()), q, SLOT(animStopped()));
q->setFlickableDirection(QDeclarativeFlickable::VerticalFlick);
::memset(sectionCache, 0, sizeof(QDeclarativeItem*) * sectionCacheSize);
}
@@ -1260,13 +1259,15 @@ void QDeclarativeListViewPrivate::flick(AxisData &data, qreal minExtent, qreal m
timeline.callback(QDeclarativeTimeLineCallback(&data.move, fixupCallback, this));
if (!flickingHorizontally && q->xflick()) {
flickingHorizontally = true;
- emit q->flickingChanged(); // deprecated
+ emit q->flickingChanged();
emit q->flickingHorizontallyChanged();
+ emit q->flickStarted();
}
if (!flickingVertically && q->yflick()) {
flickingVertically = true;
- emit q->flickingChanged(); // deprecated
+ emit q->flickingChanged();
emit q->flickingVerticallyChanged();
+ emit q->flickStarted();
}
correctFlick = true;
} else {
@@ -2890,12 +2891,9 @@ void QDeclarativeListView::destroyingItem(QDeclarativeItem *item)
void QDeclarativeListView::animStopped()
{
Q_D(QDeclarativeListView);
- if ((!d->movingVertically && d->orient == QDeclarativeListView::Vertical) || (!d->movingHorizontally && d->orient == QDeclarativeListView::Horizontal))
- {
- d->bufferMode = QDeclarativeListViewPrivate::NoBuffer;
- if (d->haveHighlightRange && d->highlightRange == QDeclarativeListView::StrictlyEnforceRange)
- d->updateHighlight();
- }
+ d->bufferMode = QDeclarativeListViewPrivate::NoBuffer;
+ if (d->haveHighlightRange && d->highlightRange == QDeclarativeListView::StrictlyEnforceRange)
+ d->updateHighlight();
}
QDeclarativeListViewAttached *QDeclarativeListView::qmlAttachedProperties(QObject *obj)
diff --git a/src/declarative/graphicsitems/qdeclarativepath.cpp b/src/declarative/graphicsitems/qdeclarativepath.cpp
index 3d0df87..2d08c7c 100644
--- a/src/declarative/graphicsitems/qdeclarativepath.cpp
+++ b/src/declarative/graphicsitems/qdeclarativepath.cpp
@@ -377,7 +377,9 @@ void QDeclarativePath::createPointCache() const
{
Q_D(const QDeclarativePath);
qreal pathLength = d->_path.length();
- const int points = int(pathLength*2);
+ // more points means less jitter between items as they move along the
+ // path, but takes longer to generate
+ const int points = int(pathLength*5);
const int lastElement = d->_path.elementCount() - 1;
d->_pointCache.resize(points+1);
diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp
index 503d096..207cc25 100644
--- a/src/declarative/graphicsitems/qdeclarativepathview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp
@@ -49,6 +49,7 @@
#include <qlistmodelinterface_p.h>
#include <QGraphicsSceneEvent>
+#include <qmath.h>
#include <math.h>
QT_BEGIN_NAMESPACE
@@ -279,8 +280,8 @@ void QDeclarativePathViewPrivate::updateItem(QDeclarativeItem *item, qreal perce
att->setValue(attr.toUtf8(), path->attributeAt(attr, percent));
}
QPointF pf = path->pointAt(percent);
- item->setX(pf.x() - item->width()*item->scale()/2);
- item->setY(pf.y() - item->height()*item->scale()/2);
+ item->setX(qRound(pf.x() - item->width()*item->scale()/2));
+ item->setY(qRound(pf.y() - item->height()*item->scale()/2));
}
void QDeclarativePathViewPrivate::regenerate()
@@ -527,6 +528,33 @@ void QDeclarativePathView::setCurrentIndex(int idx)
}
/*!
+ \qmlmethod PathView::incrementCurrentIndex()
+
+ Increments the current index.
+*/
+void QDeclarativePathView::incrementCurrentIndex()
+{
+ setCurrentIndex(currentIndex()+1);
+}
+
+
+/*!
+ \qmlmethod PathView::decrementCurrentIndex()
+
+ Decrements the current index.
+*/
+void QDeclarativePathView::decrementCurrentIndex()
+{
+ Q_D(QDeclarativePathView);
+ if (d->model && d->model->count()) {
+ int idx = currentIndex()-1;
+ if (idx < 0)
+ idx = d->model->count() - 1;
+ setCurrentIndex(idx);
+ }
+}
+
+/*!
\qmlproperty real PathView::offset
The offset specifies how far along the path the items are from their initial positions.
@@ -1312,6 +1340,7 @@ int QDeclarativePathViewPrivate::calcCurrentIndex()
if (offset < 0)
offset += model->count();
current = qRound(qAbs(qmlMod(model->count() - offset, model->count())));
+ current = current % model->count();
}
return current;
diff --git a/src/declarative/graphicsitems/qdeclarativepathview_p.h b/src/declarative/graphicsitems/qdeclarativepathview_p.h
index 85f47fd..349a01c 100644
--- a/src/declarative/graphicsitems/qdeclarativepathview_p.h
+++ b/src/declarative/graphicsitems/qdeclarativepathview_p.h
@@ -132,6 +132,10 @@ public:
static QDeclarativePathViewAttached *qmlAttachedProperties(QObject *);
+public Q_SLOTS:
+ void incrementCurrentIndex();
+ void decrementCurrentIndex();
+
Q_SIGNALS:
void currentIndexChanged();
void offsetChanged();
diff --git a/src/declarative/qml/qdeclarativecompositetypemanager.cpp b/src/declarative/qml/qdeclarativecompositetypemanager.cpp
index b43b4d0..e4405f7 100644
--- a/src/declarative/qml/qdeclarativecompositetypemanager.cpp
+++ b/src/declarative/qml/qdeclarativecompositetypemanager.cpp
@@ -514,7 +514,9 @@ void QDeclarativeCompositeTypeManager::checkComplete(QDeclarativeCompositeTypeDa
unit->errors = u->errors;
doComplete(unit);
return;
- } else if (u->status == QDeclarativeCompositeTypeData::Waiting) {
+ } else if (u->status == QDeclarativeCompositeTypeData::Waiting
+ || u->status == QDeclarativeCompositeTypeData::WaitingResources)
+ {
waiting++;
}
}
diff --git a/src/declarative/qml/qdeclarativecontext.cpp b/src/declarative/qml/qdeclarativecontext.cpp
index b61b8cb..6a13f15 100644
--- a/src/declarative/qml/qdeclarativecontext.cpp
+++ b/src/declarative/qml/qdeclarativecontext.cpp
@@ -659,7 +659,7 @@ void QDeclarativeContextData::addImportedScript(const QDeclarativeParser::Object
if (iter == enginePriv->m_sharedScriptImports.end()) {
QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine);
- scriptContext->pushScope(enginePriv->contextClass->newContext(0, 0));
+ scriptContext->pushScope(enginePriv->contextClass->newUrlContext(url));
scriptContext->pushScope(enginePriv->globalClass->globalObject());
QScriptValue scope = scriptEngine->newObject();
@@ -685,7 +685,7 @@ void QDeclarativeContextData::addImportedScript(const QDeclarativeParser::Object
QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine);
- scriptContext->pushScope(enginePriv->contextClass->newContext(this, 0));
+ scriptContext->pushScope(enginePriv->contextClass->newUrlContext(this, 0, url));
scriptContext->pushScope(enginePriv->globalClass->globalObject());
QScriptValue scope = scriptEngine->newObject();
diff --git a/src/declarative/qml/qdeclarativecontextscriptclass.cpp b/src/declarative/qml/qdeclarativecontextscriptclass.cpp
index 1336a1a..1ebedbb 100644
--- a/src/declarative/qml/qdeclarativecontextscriptclass.cpp
+++ b/src/declarative/qml/qdeclarativecontextscriptclass.cpp
@@ -51,11 +51,13 @@ QT_BEGIN_NAMESPACE
struct ContextData : public QScriptDeclarativeClass::Object {
ContextData() : overrideObject(0), isSharedContext(true) {}
- ContextData(QDeclarativeContextData *c, QObject *o) : context(c), scopeObject(o), overrideObject(0), isSharedContext(false) {}
+ ContextData(QDeclarativeContextData *c, QObject *o)
+ : context(c), scopeObject(o), overrideObject(0), isSharedContext(false), isUrlContext(false) {}
QDeclarativeGuardedContextData context;
QDeclarativeGuard<QObject> scopeObject;
QObject *overrideObject;
- bool isSharedContext;
+ bool isSharedContext:1;
+ bool isUrlContext:1;
QDeclarativeContextData *getContext(QDeclarativeEngine *engine) {
if (isSharedContext) {
@@ -74,6 +76,18 @@ struct ContextData : public QScriptDeclarativeClass::Object {
}
};
+struct UrlContextData : public ContextData {
+ UrlContextData(QDeclarativeContextData *c, QObject *o, const QString &u)
+ : ContextData(c, o), url(u) {
+ isUrlContext = true;
+ }
+ UrlContextData(const QString &u)
+ : ContextData(0, 0), url(u) {
+ isUrlContext = true;
+ }
+ QString url;
+};
+
/*
The QDeclarativeContextScriptClass handles property access for a QDeclarativeContext
via QtScript.
@@ -95,6 +109,21 @@ QScriptValue QDeclarativeContextScriptClass::newContext(QDeclarativeContextData
return newObject(scriptEngine, this, new ContextData(context, scopeObject));
}
+QScriptValue QDeclarativeContextScriptClass::newUrlContext(QDeclarativeContextData *context, QObject *scopeObject,
+ const QString &url)
+{
+ QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
+
+ return newObject(scriptEngine, this, new UrlContextData(context, scopeObject, url));
+}
+
+QScriptValue QDeclarativeContextScriptClass::newUrlContext(const QString &url)
+{
+ QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
+
+ return newObject(scriptEngine, this, new UrlContextData(url));
+}
+
QScriptValue QDeclarativeContextScriptClass::newSharedContext()
{
QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
@@ -111,6 +140,19 @@ QDeclarativeContextData *QDeclarativeContextScriptClass::contextFromValue(const
return data->getContext(engine);
}
+QUrl QDeclarativeContextScriptClass::urlFromValue(const QScriptValue &v)
+{
+ if (scriptClass(v) != this)
+ return QUrl();
+
+ ContextData *data = (ContextData *)object(v);
+ if (data->isUrlContext) {
+ return QUrl(static_cast<UrlContextData *>(data)->url);
+ } else {
+ return QUrl();
+ }
+}
+
QObject *QDeclarativeContextScriptClass::setOverrideObject(QScriptValue &v, QObject *override)
{
if (scriptClass(v) != this)
diff --git a/src/declarative/qml/qdeclarativecontextscriptclass_p.h b/src/declarative/qml/qdeclarativecontextscriptclass_p.h
index 1936d38..1215b00 100644
--- a/src/declarative/qml/qdeclarativecontextscriptclass_p.h
+++ b/src/declarative/qml/qdeclarativecontextscriptclass_p.h
@@ -68,9 +68,13 @@ public:
~QDeclarativeContextScriptClass();
QScriptValue newContext(QDeclarativeContextData *, QObject * = 0);
+ QScriptValue newUrlContext(QDeclarativeContextData *, QObject *, const QString &);
+ QScriptValue newUrlContext(const QString &);
QScriptValue newSharedContext();
QDeclarativeContextData *contextFromValue(const QScriptValue &);
+ QUrl urlFromValue(const QScriptValue &);
+
QObject *setOverrideObject(QScriptValue &, QObject *);
protected:
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp
index 94e6771..2c89abd 100644
--- a/src/declarative/qml/qdeclarativeengine.cpp
+++ b/src/declarative/qml/qdeclarativeengine.cpp
@@ -67,6 +67,7 @@
#include "qdeclarativeextensioninterface.h"
#include "private/qdeclarativelist_p.h"
#include "private/qdeclarativetypenamecache_p.h"
+#include "private/qdeclarativeinclude_p.h"
#include <QtCore/qmetaobject.h>
#include <QScriptClass>
@@ -204,6 +205,11 @@ QDeclarativeScriptEngine::QDeclarativeScriptEngine(QDeclarativeEnginePrivate *pr
// XXX used to add Qt.Sound class.
//types
+ if (mainthread)
+ qtObject.setProperty(QLatin1String("include"), newFunction(QDeclarativeInclude::include, 2));
+ else
+ qtObject.setProperty(QLatin1String("include"), newFunction(QDeclarativeInclude::worker_include, 2));
+
qtObject.setProperty(QLatin1String("isQtObject"), newFunction(QDeclarativeEnginePrivate::isQtObject, 1));
qtObject.setProperty(QLatin1String("rgba"), newFunction(QDeclarativeEnginePrivate::rgba, 4));
qtObject.setProperty(QLatin1String("hsla"), newFunction(QDeclarativeEnginePrivate::hsla, 4));
diff --git a/src/declarative/qml/qdeclarativeglobalscriptclass_p.h b/src/declarative/qml/qdeclarativeglobalscriptclass_p.h
index 1b34aee..7690edd 100644
--- a/src/declarative/qml/qdeclarativeglobalscriptclass_p.h
+++ b/src/declarative/qml/qdeclarativeglobalscriptclass_p.h
@@ -76,6 +76,7 @@ public:
void explicitSetProperty(const QString &, const QScriptValue &);
const QScriptValue &globalObject() const { return m_globalObject; }
+
const QSet<QString> &illegalNames() const { return m_illegalNames; }
private:
diff --git a/src/declarative/qml/qdeclarativeinclude.cpp b/src/declarative/qml/qdeclarativeinclude.cpp
new file mode 100644
index 0000000..97220f1
--- /dev/null
+++ b/src/declarative/qml/qdeclarativeinclude.cpp
@@ -0,0 +1,316 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qdeclarativeinclude_p.h"
+
+#include <QtScript/qscriptengine>
+#include <QtNetwork/qnetworkrequest.h>
+#include <QtNetwork/qnetworkreply.h>
+#include <QtCore/qfile.h>
+
+#include <private/qdeclarativeengine_p.h>
+#include <private/qdeclarativeglobalscriptclass_p.h>
+
+QT_BEGIN_NAMESPACE
+
+QDeclarativeInclude::QDeclarativeInclude(const QUrl &url,
+ QDeclarativeEngine *engine,
+ QScriptContext *ctxt)
+: QObject(engine), m_engine(engine), m_network(0), m_reply(0), m_url(url), m_redirectCount(0)
+{
+ QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
+ m_context = ep->contextClass->contextFromValue(QScriptDeclarativeClass::scopeChainValue(ctxt, -3));
+
+ m_scope[0] = QScriptDeclarativeClass::scopeChainValue(ctxt, -4);
+ m_scope[1] = QScriptDeclarativeClass::scopeChainValue(ctxt, -5);
+
+ m_scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
+ m_network = QDeclarativeScriptEngine::get(m_scriptEngine)->networkAccessManager();
+
+ m_result = resultValue(m_scriptEngine);
+
+ QNetworkRequest request;
+ request.setUrl(url);
+
+ m_reply = m_network->get(request);
+ QObject::connect(m_reply, SIGNAL(finished()), this, SLOT(finished()));
+}
+
+QDeclarativeInclude::~QDeclarativeInclude()
+{
+ delete m_reply;
+}
+
+QScriptValue QDeclarativeInclude::resultValue(QScriptEngine *engine, Status status)
+{
+ QScriptValue result = engine->newObject();
+ result.setProperty(QLatin1String("OK"), QScriptValue(engine, Ok));
+ result.setProperty(QLatin1String("LOADING"), QScriptValue(engine, Loading));
+ result.setProperty(QLatin1String("NETWORK_ERROR"), QScriptValue(engine, NetworkError));
+ result.setProperty(QLatin1String("EXCEPTION"), QScriptValue(engine, Exception));
+
+ result.setProperty(QLatin1String("status"), QScriptValue(engine, status));
+ return result;
+}
+
+QScriptValue QDeclarativeInclude::result() const
+{
+ return m_result;
+}
+
+void QDeclarativeInclude::setCallback(const QScriptValue &c)
+{
+ m_callback = c;
+}
+
+QScriptValue QDeclarativeInclude::callback() const
+{
+ return m_callback;
+}
+
+#define INCLUDE_MAXIMUM_REDIRECT_RECURSION 15
+void QDeclarativeInclude::finished()
+{
+ m_redirectCount++;
+
+ if (m_redirectCount < INCLUDE_MAXIMUM_REDIRECT_RECURSION) {
+ QVariant redirect = m_reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
+ if (redirect.isValid()) {
+ m_url = m_url.resolved(redirect.toUrl());
+ delete m_reply;
+
+ QNetworkRequest request;
+ request.setUrl(m_url);
+
+ m_reply = m_network->get(request);
+ QObject::connect(m_reply, SIGNAL(finished()), this, SLOT(finished()));
+ return;
+ }
+ }
+
+ if (m_reply->error() == QNetworkReply::NoError) {
+ QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(m_engine);
+
+ QByteArray data = m_reply->readAll();
+
+ QString code = QString::fromUtf8(data);
+
+ QString urlString = m_url.toString();
+ QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(m_scriptEngine);
+ scriptContext->pushScope(ep->contextClass->newUrlContext(m_context, 0, urlString));
+ scriptContext->pushScope(m_scope[0]);
+
+ scriptContext->pushScope(m_scope[1]);
+ scriptContext->setActivationObject(m_scope[1]);
+
+ m_scriptEngine->evaluate(code, urlString, 1);
+
+ m_scriptEngine->popContext();
+
+ if (m_scriptEngine->hasUncaughtException()) {
+ m_result.setProperty(QLatin1String("status"), QScriptValue(m_scriptEngine, Exception));
+ m_result.setProperty(QLatin1String("exception"), m_scriptEngine->uncaughtException());
+ m_scriptEngine->clearExceptions();
+ } else {
+ m_result.setProperty(QLatin1String("status"), QScriptValue(m_scriptEngine, Ok));
+ }
+ } else {
+ m_result.setProperty(QLatin1String("status"), QScriptValue(m_scriptEngine, NetworkError));
+ }
+
+ callback(m_scriptEngine, m_callback, m_result);
+
+ disconnect();
+ deleteLater();
+}
+
+void QDeclarativeInclude::callback(QScriptEngine *engine, QScriptValue &callback, QScriptValue &status)
+{
+ if (callback.isValid()) {
+ QScriptValue args = engine->newArray(1);
+ args.setProperty(0, status);
+ callback.call(QScriptValue(), args);
+ }
+}
+
+static QString toLocalFileOrQrc(const QUrl& url)
+{
+ if (url.scheme() == QLatin1String("qrc")) {
+ if (url.authority().isEmpty())
+ return QLatin1Char(':') + url.path();
+ return QString();
+ }
+ return url.toLocalFile();
+}
+
+QScriptValue QDeclarativeInclude::include(QScriptContext *ctxt, QScriptEngine *engine)
+{
+ if (ctxt->argumentCount() == 0)
+ return engine->undefinedValue();
+
+ QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
+
+ QUrl contextUrl = ep->contextClass->urlFromValue(QScriptDeclarativeClass::scopeChainValue(ctxt, -3));
+ if (contextUrl.isEmpty())
+ return ctxt->throwError(QLatin1String("Qt.include(): Can only be called from JavaScript files"));
+
+ QString urlString = ctxt->argument(0).toString();
+ QUrl url(ctxt->argument(0).toString());
+ if (url.isRelative()) {
+ url = QUrl(contextUrl).resolved(url);
+ urlString = url.toString();
+ }
+
+ QString localFile = toLocalFileOrQrc(url);
+
+ QScriptValue func = ctxt->argument(1);
+ if (!func.isFunction())
+ func = QScriptValue();
+
+ QScriptValue result;
+ if (localFile.isEmpty()) {
+ QDeclarativeInclude *i =
+ new QDeclarativeInclude(url, QDeclarativeEnginePrivate::getEngine(engine), ctxt);
+
+ if (func.isValid())
+ i->setCallback(func);
+
+ result = i->result();
+ } else {
+
+ QFile f(localFile);
+ if (f.open(QIODevice::ReadOnly)) {
+ QByteArray data = f.readAll();
+ QString code = QString::fromUtf8(data);
+
+ QDeclarativeContextData *context =
+ ep->contextClass->contextFromValue(QScriptDeclarativeClass::scopeChainValue(ctxt, -3));
+
+ QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(engine);
+ scriptContext->pushScope(ep->contextClass->newUrlContext(context, 0, urlString));
+ scriptContext->pushScope(ep->globalClass->globalObject());
+ QScriptValue scope = QScriptDeclarativeClass::scopeChainValue(ctxt, -5);
+ scriptContext->pushScope(scope);
+ scriptContext->setActivationObject(scope);
+
+ engine->evaluate(code, urlString, 1);
+
+ engine->popContext();
+
+ if (engine->hasUncaughtException()) {
+ result = resultValue(engine, Exception);
+ result.setProperty(QLatin1String("exception"), engine->uncaughtException());
+ engine->clearExceptions();
+ } else {
+ result = resultValue(engine, Ok);
+ }
+ callback(engine, func, result);
+ } else {
+ result = resultValue(engine, NetworkError);
+ callback(engine, func, result);
+ }
+ }
+
+ return result;
+}
+
+QScriptValue QDeclarativeInclude::worker_include(QScriptContext *ctxt, QScriptEngine *engine)
+{
+ if (ctxt->argumentCount() == 0)
+ return engine->undefinedValue();
+
+ QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
+
+ QString urlString = ctxt->argument(0).toString();
+ QUrl url(ctxt->argument(0).toString());
+ if (url.isRelative()) {
+ QString contextUrl = QScriptDeclarativeClass::scopeChainValue(ctxt, -3).data().toString();
+ Q_ASSERT(!contextUrl.isEmpty());
+
+ url = QUrl(contextUrl).resolved(url);
+ urlString = url.toString();
+ }
+
+ QString localFile = toLocalFileOrQrc(url);
+
+ QScriptValue func = ctxt->argument(1);
+ if (!func.isFunction())
+ func = QScriptValue();
+
+ QScriptValue result;
+ if (!localFile.isEmpty()) {
+
+ QFile f(localFile);
+ if (f.open(QIODevice::ReadOnly)) {
+ QByteArray data = f.readAll();
+ QString code = QString::fromUtf8(data);
+
+ QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(engine);
+ QScriptValue urlContext = engine->newObject();
+ urlContext.setData(QScriptValue(engine, urlString));
+ scriptContext->pushScope(urlContext);
+
+ QScriptValue scope = QScriptDeclarativeClass::scopeChainValue(ctxt, -4);
+ scriptContext->pushScope(scope);
+ scriptContext->setActivationObject(scope);
+
+ engine->evaluate(code, urlString, 1);
+
+ engine->popContext();
+
+ if (engine->hasUncaughtException()) {
+ result = resultValue(engine, Exception);
+ result.setProperty(QLatin1String("exception"), engine->uncaughtException());
+ engine->clearExceptions();
+ } else {
+ result = resultValue(engine, Ok);
+ }
+ callback(engine, func, result);
+ } else {
+ result = resultValue(engine, NetworkError);
+ callback(engine, func, result);
+ }
+ }
+
+ return result;
+}
+
+QT_END_NAMESPACE
diff --git a/src/declarative/qml/qdeclarativeinclude_p.h b/src/declarative/qml/qdeclarativeinclude_p.h
new file mode 100644
index 0000000..3124374
--- /dev/null
+++ b/src/declarative/qml/qdeclarativeinclude_p.h
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QDECLARATIVEINCLUDE_P_H
+#define QDECLARATIVEINCLUDE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qobject.h>
+#include <QtCore/qurl.h>
+#include <QtScript/qscriptvalue.h>
+
+#include <private/qdeclarativecontext_p.h>
+#include <private/qdeclarativeguard_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QDeclarativeEngine;
+class QScriptContext;
+class QScriptEngine;
+class QNetworkAccessManager;
+class QNetworkReply;
+class QDeclarativeInclude : public QObject
+{
+ Q_OBJECT
+public:
+ enum Status {
+ Ok = 0,
+ Loading = 1,
+ NetworkError = 2,
+ Exception = 3
+ };
+
+ QDeclarativeInclude(const QUrl &, QDeclarativeEngine *, QScriptContext *ctxt);
+ ~QDeclarativeInclude();
+
+ void setCallback(const QScriptValue &);
+ QScriptValue callback() const;
+
+ QScriptValue result() const;
+
+ static QScriptValue resultValue(QScriptEngine *, Status status = Loading);
+ static void callback(QScriptEngine *, QScriptValue &callback, QScriptValue &status);
+
+ static QScriptValue include(QScriptContext *ctxt, QScriptEngine *engine);
+ static QScriptValue worker_include(QScriptContext *ctxt, QScriptEngine *engine);
+
+public slots:
+ void finished();
+
+private:
+ QDeclarativeEngine *m_engine;
+ QScriptEngine *m_scriptEngine;
+ QNetworkAccessManager *m_network;
+ QDeclarativeGuard<QNetworkReply> m_reply;
+
+ QUrl m_url;
+ int m_redirectCount;
+ QScriptValue m_callback;
+ QScriptValue m_result;
+ QDeclarativeGuardedContextData m_context;
+ QScriptValue m_scope[2];
+};
+
+QT_END_NAMESPACE
+
+#endif // QDECLARATIVEINCLUDE_P_H
+
diff --git a/src/declarative/qml/qdeclarativeworkerscript.cpp b/src/declarative/qml/qdeclarativeworkerscript.cpp
index c55998f..4b687a9 100644
--- a/src/declarative/qml/qdeclarativeworkerscript.cpp
+++ b/src/declarative/qml/qdeclarativeworkerscript.cpp
@@ -289,7 +289,11 @@ void QDeclarativeWorkerScriptEnginePrivate::processLoad(int id, const QUrl &url)
QScriptValue activation = getWorker(id);
- QScriptContext *ctxt = workerEngine->pushContext();
+ QScriptContext *ctxt = QScriptDeclarativeClass::pushCleanContext(workerEngine);
+ QScriptValue urlContext = workerEngine->newObject();
+ urlContext.setData(QScriptValue(workerEngine, fileName));
+ ctxt->pushScope(urlContext);
+ ctxt->pushScope(activation);
ctxt->setActivationObject(activation);
workerEngine->baseUrl = url;
diff --git a/src/declarative/qml/qml.pri b/src/declarative/qml/qml.pri
index dab9767..12f9794 100644
--- a/src/declarative/qml/qml.pri
+++ b/src/declarative/qml/qml.pri
@@ -9,6 +9,7 @@ SOURCES += \
$$PWD/qdeclarativeproperty.cpp \
$$PWD/qdeclarativecomponent.cpp \
$$PWD/qdeclarativecontext.cpp \
+ $$PWD/qdeclarativeinclude.cpp \
$$PWD/qdeclarativecustomparser.cpp \
$$PWD/qdeclarativepropertyvaluesource.cpp \
$$PWD/qdeclarativepropertyvalueinterceptor.cpp \
@@ -92,6 +93,7 @@ HEADERS += \
$$PWD/qdeclarativeinfo.h \
$$PWD/qdeclarativeproperty_p.h \
$$PWD/qdeclarativecontext_p.h \
+ $$PWD/qdeclarativeinclude_p.h \
$$PWD/qdeclarativecompositetypedata_p.h \
$$PWD/qdeclarativecompositetypemanager_p.h \
$$PWD/qdeclarativelist.h \
diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp
index 0f7c946..67440b6 100644
--- a/src/declarative/util/qdeclarativeanimation.cpp
+++ b/src/declarative/util/qdeclarativeanimation.cpp
@@ -2536,13 +2536,13 @@ void QDeclarativeParentAnimation::transition(QDeclarativeStateActions &actions,
viaData->pc << vpc;
viaData->actions << myAction;
QDeclarativeAction dummyAction;
- QDeclarativeAction &xAction = pc->xIsSet() ? actions[++i] : dummyAction;
- QDeclarativeAction &yAction = pc->yIsSet() ? actions[++i] : dummyAction;
- QDeclarativeAction &sAction = pc->scaleIsSet() ? actions[++i] : dummyAction;
- QDeclarativeAction &rAction = pc->rotationIsSet() ? actions[++i] : dummyAction;
+ QDeclarativeAction &xAction = pc->xIsSet() && i < actions.size()-1 ? actions[++i] : dummyAction;
+ QDeclarativeAction &yAction = pc->yIsSet() && i < actions.size()-1 ? actions[++i] : dummyAction;
+ QDeclarativeAction &sAction = pc->scaleIsSet() && i < actions.size()-1 ? actions[++i] : dummyAction;
+ QDeclarativeAction &rAction = pc->rotationIsSet() && i < actions.size()-1 ? actions[++i] : dummyAction;
bool forward = (direction == QDeclarativeAbstractAnimation::Forward);
QDeclarativeItem *target = pc->object();
- QDeclarativeItem *targetParent = forward ? pc->parent() : pc->originalParent();
+ QDeclarativeItem *targetParent = action.reverseEvent ? pc->originalParent() : pc->parent();
//### this mirrors the logic in QDeclarativeParentChange.
bool ok;
@@ -2583,9 +2583,9 @@ void QDeclarativeParentAnimation::transition(QDeclarativeStateActions &actions,
if (ok && target->transformOrigin() != QDeclarativeItem::TopLeft) {
qreal w = target->width();
qreal h = target->height();
- if (pc->widthIsSet())
+ if (pc->widthIsSet() && i < actions.size() - 1)
w = actions[++i].toValue.toReal();
- if (pc->heightIsSet())
+ if (pc->heightIsSet() && i < actions.size() - 1)
h = actions[++i].toValue.toReal();
const QPointF &transformOrigin
= d->computeTransformOrigin(target->transformOrigin(), w,h);
diff --git a/src/declarative/util/qdeclarativelistmodel.cpp b/src/declarative/util/qdeclarativelistmodel.cpp
index 0985a6b..a8e1be8 100644
--- a/src/declarative/util/qdeclarativelistmodel.cpp
+++ b/src/declarative/util/qdeclarativelistmodel.cpp
@@ -537,10 +537,9 @@ void QDeclarativeListModel::append(const QScriptValue& valuemap)
*/
QScriptValue QDeclarativeListModel::get(int index) const
{
- if (index >= count() || index < 0) {
+ // the internal flat/nested class takes care of return value for bad index
+ if (index >= count() || index < 0)
qmlInfo(this) << tr("get: index %1 out of range").arg(index);
- return 0;
- }
return m_flat ? m_flat->get(index) : m_nested->get(index);
}
@@ -930,13 +929,14 @@ bool FlatListModel::insert(int index, const QScriptValue &value)
QScriptValue FlatListModel::get(int index) const
{
- Q_ASSERT(index >= 0 && index < m_values.count());
-
QScriptEngine *scriptEngine = m_scriptEngine ? m_scriptEngine : QDeclarativeEnginePrivate::getScriptEngine(qmlEngine(m_listModel));
- if (!scriptEngine)
+ if (!scriptEngine)
return 0;
+ if (index < 0 || index >= m_values.count())
+ return scriptEngine->undefinedValue();
+
QScriptValue rv = scriptEngine->newObject();
QHash<int, QVariant> row = m_values.at(index);
@@ -999,7 +999,8 @@ bool FlatListModel::addValue(const QScriptValue &value, QHash<int, QVariant> *ro
QScriptValueIterator it(value);
while (it.hasNext()) {
it.next();
- if (it.value().isObject()) {
+ QScriptValue value = it.value();
+ if (!value.isVariant() && !value.isRegExp() && !value.isDate() && value.isObject()) {
qmlInfo(m_listModel) << "Cannot add nested list values when modifying or after modification from a worker script";
return false;
}
@@ -1182,13 +1183,21 @@ bool NestedListModel::append(const QScriptValue& valuemap)
}
QScriptValue NestedListModel::get(int index) const
-{
- ModelNode *node = qvariant_cast<ModelNode *>(_root->values.at(index));
- if (!node)
- return 0;
+{
QDeclarativeEngine *eng = qmlEngine(m_listModel);
if (!eng)
return 0;
+
+ if (index < 0 || index >= count()) {
+ QScriptEngine *seng = QDeclarativeEnginePrivate::getScriptEngine(eng);
+ if (seng)
+ return seng->undefinedValue();
+ return 0;
+ }
+
+ ModelNode *node = qvariant_cast<ModelNode *>(_root->values.at(index));
+ if (!node)
+ return 0;
return QDeclarativeEnginePrivate::qmlScriptObject(node->object(this), eng);
}
diff --git a/src/declarative/util/qdeclarativepropertychanges.cpp b/src/declarative/util/qdeclarativepropertychanges.cpp
index a22c756..12fef36 100644
--- a/src/declarative/util/qdeclarativepropertychanges.cpp
+++ b/src/declarative/util/qdeclarativepropertychanges.cpp
@@ -179,7 +179,7 @@ public:
reverseExpression = rewindExpression;
}
- virtual void copyOriginals(QDeclarativeActionEvent *other)
+ /*virtual void copyOriginals(QDeclarativeActionEvent *other)
{
QDeclarativeReplaceSignalHandler *rsh = static_cast<QDeclarativeReplaceSignalHandler*>(other);
saveCurrentValues();
@@ -190,7 +190,7 @@ public:
ownedExpression = rsh->ownedExpression;
rsh->ownedExpression = 0;
}
- }
+ }*/
virtual void rewind() {
ownedExpression = QDeclarativePropertyPrivate::setSignalExpression(property, rewindExpression);
diff --git a/src/declarative/util/qdeclarativestate.cpp b/src/declarative/util/qdeclarativestate.cpp
index ea209aa..b5f7900 100644
--- a/src/declarative/util/qdeclarativestate.cpp
+++ b/src/declarative/util/qdeclarativestate.cpp
@@ -390,12 +390,13 @@ void QDeclarativeState::apply(QDeclarativeStateGroup *group, QDeclarativeTransit
if (action.event->override(event)) {
found = true;
- if (action.event != d->revertList.at(jj).event) {
+ if (action.event != d->revertList.at(jj).event && action.event->needsCopy()) {
action.event->copyOriginals(d->revertList.at(jj).event);
QDeclarativeSimpleAction r(action);
additionalReverts << r;
d->revertList.removeAt(jj);
+ --jj;
} else if (action.event->isRewindable()) //###why needed?
action.event->saveCurrentValues();
diff --git a/src/declarative/util/qdeclarativestate_p.h b/src/declarative/util/qdeclarativestate_p.h
index 0ba67b0..25715c6 100644
--- a/src/declarative/util/qdeclarativestate_p.h
+++ b/src/declarative/util/qdeclarativestate_p.h
@@ -96,6 +96,7 @@ public:
virtual bool isReversable();
virtual void reverse(Reason reason = ActualChange);
virtual void saveOriginals() {}
+ virtual bool needsCopy() { return false; }
virtual void copyOriginals(QDeclarativeActionEvent *) {}
virtual bool isRewindable() { return isReversable(); }
diff --git a/src/declarative/util/qdeclarativestateoperations.cpp b/src/declarative/util/qdeclarativestateoperations.cpp
index a93a25d..0326f6d 100644
--- a/src/declarative/util/qdeclarativestateoperations.cpp
+++ b/src/declarative/util/qdeclarativestateoperations.cpp
@@ -408,7 +408,7 @@ void QDeclarativeParentChange::saveOriginals()
d->origStackBefore = d->rewindStackBefore;
}
-void QDeclarativeParentChange::copyOriginals(QDeclarativeActionEvent *other)
+/*void QDeclarativeParentChange::copyOriginals(QDeclarativeActionEvent *other)
{
Q_D(QDeclarativeParentChange);
QDeclarativeParentChange *pc = static_cast<QDeclarativeParentChange*>(other);
@@ -417,7 +417,7 @@ void QDeclarativeParentChange::copyOriginals(QDeclarativeActionEvent *other)
d->origStackBefore = pc->d_func()->rewindStackBefore;
saveCurrentValues();
-}
+}*/
void QDeclarativeParentChange::execute(Reason)
{
@@ -1241,24 +1241,28 @@ QList<QDeclarativeAction> QDeclarativeAnchorChanges::additionalActions()
Q_D(QDeclarativeAnchorChanges);
QList<QDeclarativeAction> extra;
+ QDeclarativeAnchors::Anchors combined = d->anchorSet->d_func()->usedAnchors | d->anchorSet->d_func()->resetAnchors;
+ bool hChange = combined & QDeclarativeAnchors::Horizontal_Mask;
+ bool vChange = combined & QDeclarativeAnchors::Vertical_Mask;
+
if (d->target) {
QDeclarativeAction a;
- if (d->fromX != d->toX) {
+ if (hChange && d->fromX != d->toX) {
a.property = QDeclarativeProperty(d->target, QLatin1String("x"));
a.toValue = d->toX;
extra << a;
}
- if (d->fromY != d->toY) {
+ if (vChange && d->fromY != d->toY) {
a.property = QDeclarativeProperty(d->target, QLatin1String("y"));
a.toValue = d->toY;
extra << a;
}
- if (d->fromWidth != d->toWidth) {
+ if (hChange && d->fromWidth != d->toWidth) {
a.property = QDeclarativeProperty(d->target, QLatin1String("width"));
a.toValue = d->toWidth;
extra << a;
}
- if (d->fromHeight != d->toHeight) {
+ if (vChange && d->fromHeight != d->toHeight) {
a.property = QDeclarativeProperty(d->target, QLatin1String("height"));
a.toValue = d->toHeight;
extra << a;
diff --git a/src/declarative/util/qdeclarativestateoperations_p.h b/src/declarative/util/qdeclarativestateoperations_p.h
index e22c1e2..21a86f5 100644
--- a/src/declarative/util/qdeclarativestateoperations_p.h
+++ b/src/declarative/util/qdeclarativestateoperations_p.h
@@ -107,7 +107,7 @@ public:
virtual ActionList actions();
virtual void saveOriginals();
- virtual void copyOriginals(QDeclarativeActionEvent*);
+ //virtual void copyOriginals(QDeclarativeActionEvent*);
virtual void execute(Reason reason = ActualChange);
virtual bool isReversable();
virtual void reverse(Reason reason = ActualChange);
@@ -277,6 +277,7 @@ public:
virtual bool override(QDeclarativeActionEvent*other);
virtual bool changesBindings();
virtual void saveOriginals();
+ virtual bool needsCopy() { return true; }
virtual void copyOriginals(QDeclarativeActionEvent*);
virtual void clearBindings();
virtual void rewind();
diff --git a/src/imports/webkit/qdeclarativewebview.cpp b/src/imports/webkit/qdeclarativewebview.cpp
index 9571470..36a25f6 100644
--- a/src/imports/webkit/qdeclarativewebview.cpp
+++ b/src/imports/webkit/qdeclarativewebview.cpp
@@ -42,11 +42,9 @@
#include "qdeclarativewebview_p.h"
#include "qdeclarativewebview_p_p.h"
-#include <private/qdeclarativepainteditem_p_p.h>
-
#include <qdeclarative.h>
#include <qdeclarativeengine.h>
-#include <private/qdeclarativestate_p.h>
+#include <qdeclarativecontext.h>
#include <QDebug>
#include <QPen>
@@ -61,29 +59,29 @@
#include <QtWebKit/QWebFrame>
#include <QtWebKit/QWebElement>
#include <QtWebKit/QWebSettings>
-#include <private/qlistmodelinterface_p.h>
QT_BEGIN_NAMESPACE
static const int MAX_DOUBLECLICK_TIME=500; // XXX need better gesture system
-class QDeclarativeWebViewPrivate : public QDeclarativePaintedItemPrivate
+class QDeclarativeWebViewPrivate
{
- Q_DECLARE_PUBLIC(QDeclarativeWebView)
-
public:
- QDeclarativeWebViewPrivate()
- : QDeclarativePaintedItemPrivate(), page(0), preferredwidth(0), preferredheight(0),
+ QDeclarativeWebViewPrivate(QDeclarativeWebView* qq)
+ : q(qq), page(0), preferredwidth(0), preferredheight(0),
progress(1.0), status(QDeclarativeWebView::Null), pending(PendingNone),
newWindowComponent(0), newWindowParent(0),
pressTime(400),
rendering(true)
{
+ QObject::connect(q, SIGNAL(focusChanged(bool)), q, SLOT(propagateFocusToWebPage(bool)));
}
- void focusChanged(bool);
+
+ QDeclarativeWebView *q;
QUrl url; // page url might be different if it has not loaded yet
QWebPage *page;
+ QGraphicsWebView* view;
int preferredwidth, preferredheight;
qreal progress;
@@ -101,7 +99,6 @@ public:
QPoint pressPoint;
int pressTime; // milliseconds before it's a "hold"
-
static void windowObjects_append(QDeclarativeListProperty<QObject> *prop, QObject *o) {
static_cast<QDeclarativeWebViewPrivate *>(prop->data)->windowObjects.append(o);
static_cast<QDeclarativeWebViewPrivate *>(prop->data)->updateWindowObjects();
@@ -129,6 +126,9 @@ public:
dynamically adjust to a size appropriate for the content.
This width may be large for typical online web pages.
+ If the width or height is explictly set, the rendered website
+ will be clipped, not scaled, to fit into the set dimensions.
+
If the preferredWidth is set, the width will be this amount or larger,
usually laying out the web content to fit the preferredWidth.
@@ -137,8 +137,8 @@ public:
WebView {
url: "http://www.nokia.com"
- width: 490
- height: 400
+ preferredWidth: 490
+ preferredHeight: 400
scale: 0.5
smooth: false
smoothCache: true
@@ -169,34 +169,39 @@ public:
*/
QDeclarativeWebView::QDeclarativeWebView(QDeclarativeItem *parent)
- : QDeclarativePaintedItem(*(new QDeclarativeWebViewPrivate), parent)
+ : QDeclarativeItem(parent)
{
init();
}
QDeclarativeWebView::~QDeclarativeWebView()
{
- Q_D(QDeclarativeWebView);
delete d->page;
+ delete d;
}
void QDeclarativeWebView::init()
{
- Q_D(QDeclarativeWebView);
+ d = new QDeclarativeWebViewPrivate(this);
QWebSettings::enablePersistentStorage();
setAcceptHoverEvents(true);
setAcceptedMouseButtons(Qt::LeftButton);
- setFlag(QGraphicsItem::ItemHasNoContents, false);
+ setFlag(QGraphicsItem::ItemHasNoContents, true);
+ setClip(true);
d->page = 0;
+ d->view = new QGraphicsWebView(this);
+ d->view->setResizesToContents(true);
+ d->view->setFlag(QGraphicsItem::ItemStacksBehindParent, true);
+ connect(d->view, SIGNAL(geometryChanged()), this, SLOT(updateDeclarativeWebViewSize()));
+ connect(d->view, SIGNAL(scaleChanged()), this, SIGNAL(contentsScaleChanged()));
}
void QDeclarativeWebView::componentComplete()
{
- QDeclarativePaintedItem::componentComplete();
- Q_D(QDeclarativeWebView);
+ QDeclarativeItem::componentComplete();
switch (d->pending) {
case QDeclarativeWebViewPrivate::PendingUrl:
setUrl(d->pending_url);
@@ -216,7 +221,6 @@ void QDeclarativeWebView::componentComplete()
QDeclarativeWebView::Status QDeclarativeWebView::status() const
{
- Q_D(const QDeclarativeWebView);
return d->status;
}
@@ -230,13 +234,11 @@ QDeclarativeWebView::Status QDeclarativeWebView::status() const
*/
qreal QDeclarativeWebView::progress() const
{
- Q_D(const QDeclarativeWebView);
return d->progress;
}
void QDeclarativeWebView::doLoadStarted()
{
- Q_D(QDeclarativeWebView);
if (!d->url.isEmpty()) {
d->status = Loading;
@@ -247,7 +249,6 @@ void QDeclarativeWebView::doLoadStarted()
void QDeclarativeWebView::doLoadProgress(int p)
{
- Q_D(QDeclarativeWebView);
if (d->progress == p/100.0)
return;
d->progress = p/100.0;
@@ -256,12 +257,7 @@ void QDeclarativeWebView::doLoadProgress(int p)
void QDeclarativeWebView::pageUrlChanged()
{
- Q_D(QDeclarativeWebView);
-
- page()->setViewportSize(QSize(
- d->preferredwidth>0 ? d->preferredwidth : width(),
- d->preferredheight>0 ? d->preferredheight : height()));
- expandToWebPage();
+ updateContentsSize();
if ((d->url.isEmpty() && page()->mainFrame()->url() != QUrl(QLatin1String("about:blank")))
|| (d->url != page()->mainFrame()->url() && !page()->mainFrame()->url().isEmpty()))
@@ -275,7 +271,6 @@ void QDeclarativeWebView::pageUrlChanged()
void QDeclarativeWebView::doLoadFinished(bool ok)
{
- Q_D(QDeclarativeWebView);
if (title().isEmpty())
pageUrlChanged(); // XXX bug 232556 - pages with no title never get urlChanged()
@@ -302,21 +297,17 @@ void QDeclarativeWebView::doLoadFinished(bool ok)
*/
QUrl QDeclarativeWebView::url() const
{
- Q_D(const QDeclarativeWebView);
return d->url;
}
void QDeclarativeWebView::setUrl(const QUrl &url)
{
- Q_D(QDeclarativeWebView);
if (url == d->url)
return;
if (isComponentComplete()) {
d->url = url;
- page()->setViewportSize(QSize(
- d->preferredwidth>0 ? d->preferredwidth : width(),
- d->preferredheight>0 ? d->preferredheight : height()));
+ updateContentsSize();
QUrl seturl = url;
if (seturl.isEmpty())
seturl = QUrl(QLatin1String("about:blank"));
@@ -338,16 +329,14 @@ void QDeclarativeWebView::setUrl(const QUrl &url)
*/
int QDeclarativeWebView::preferredWidth() const
{
- Q_D(const QDeclarativeWebView);
return d->preferredwidth;
}
void QDeclarativeWebView::setPreferredWidth(int iw)
{
- Q_D(QDeclarativeWebView);
if (d->preferredwidth == iw) return;
d->preferredwidth = iw;
- //expandToWebPage();
+ updateContentsSize();
emit preferredWidthChanged();
}
@@ -358,14 +347,14 @@ void QDeclarativeWebView::setPreferredWidth(int iw)
*/
int QDeclarativeWebView::preferredHeight() const
{
- Q_D(const QDeclarativeWebView);
return d->preferredheight;
}
+
void QDeclarativeWebView::setPreferredHeight(int ih)
{
- Q_D(QDeclarativeWebView);
if (d->preferredheight == ih) return;
d->preferredheight = ih;
+ updateContentsSize();
emit preferredHeightChanged();
}
@@ -383,55 +372,45 @@ QVariant QDeclarativeWebView::evaluateJavaScript(const QString &scriptSource)
return this->page()->mainFrame()->evaluateJavaScript(scriptSource);
}
-void QDeclarativeWebViewPrivate::focusChanged(bool hasFocus)
+void QDeclarativeWebView::propagateFocusToWebPage(bool hasFocus)
{
- Q_Q(QDeclarativeWebView);
QFocusEvent e(hasFocus ? QEvent::FocusIn : QEvent::FocusOut);
- q->page()->event(&e);
- QDeclarativeItemPrivate::focusChanged(hasFocus);
+ page()->event(&e);
}
-void QDeclarativeWebView::initialLayout()
+void QDeclarativeWebView::updateDeclarativeWebViewSize()
{
- // nothing useful to do at this point
+ QSizeF size = d->view->geometry().size() * contentsScale();
+ setImplicitWidth(size.width());
+ setImplicitHeight(size.height());
}
-void QDeclarativeWebView::noteContentsSizeChanged(const QSize&)
+void QDeclarativeWebView::initialLayout()
{
- expandToWebPage();
+ // nothing useful to do at this point
}
-void QDeclarativeWebView::expandToWebPage()
+void QDeclarativeWebView::updateContentsSize()
{
- Q_D(QDeclarativeWebView);
- QSize cs = page()->mainFrame()->contentsSize();
- if (cs.width() < d->preferredwidth)
- cs.setWidth(d->preferredwidth);
- if (cs.height() < d->preferredheight)
- cs.setHeight(d->preferredheight);
- if (widthValid())
- cs.setWidth(width());
- if (heightValid())
- cs.setHeight(height());
- if (cs != page()->viewportSize()) {
- page()->setViewportSize(cs);
- }
- if (cs != contentsSize())
- setContentsSize(cs);
+ if (d->page)
+ d->page->setPreferredContentsSize(QSize(
+ d->preferredwidth>0 ? d->preferredwidth : width(),
+ d->preferredheight>0 ? d->preferredheight : height()));
}
void QDeclarativeWebView::geometryChanged(const QRectF &newGeometry,
const QRectF &oldGeometry)
{
- if (newGeometry.size() != oldGeometry.size())
- expandToWebPage();
- QDeclarativePaintedItem::geometryChanged(newGeometry, oldGeometry);
-}
-
-void QDeclarativeWebView::paintPage(const QRect& r)
-{
- dirtyCache(r);
- update();
+ if (newGeometry.size() != oldGeometry.size() && d->page) {
+ QSize cs = d->page->preferredContentsSize();
+ if (widthValid())
+ cs.setWidth(width());
+ if (heightValid())
+ cs.setHeight(height());
+ if (cs != d->page->preferredContentsSize())
+ d->page->setPreferredContentsSize(cs);
+ }
+ QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
}
/*!
@@ -473,7 +452,6 @@ void QDeclarativeWebView::paintPage(const QRect& r)
*/
QDeclarativeListProperty<QObject> QDeclarativeWebView::javaScriptWindowObjects()
{
- Q_D(QDeclarativeWebView);
return QDeclarativeListProperty<QObject>(this, d, &QDeclarativeWebViewPrivate::windowObjects_append);
}
@@ -484,8 +462,7 @@ QDeclarativeWebViewAttached *QDeclarativeWebView::qmlAttachedProperties(QObject
void QDeclarativeWebViewPrivate::updateWindowObjects()
{
- Q_Q(QDeclarativeWebView);
- if (!q->isComponentComplete() || !page)
+ if (!q->isComponentCompletePublic() || !page)
return;
for (int ii = 0; ii < windowObjects.count(); ++ii) {
@@ -499,29 +476,17 @@ void QDeclarativeWebViewPrivate::updateWindowObjects()
bool QDeclarativeWebView::renderingEnabled() const
{
- Q_D(const QDeclarativeWebView);
return d->rendering;
}
void QDeclarativeWebView::setRenderingEnabled(bool enabled)
{
- Q_D(QDeclarativeWebView);
if (d->rendering == enabled)
return;
d->rendering = enabled;
emit renderingEnabledChanged();
- setCacheFrozen(!enabled);
- if (enabled)
- clearCache();
-}
-
-
-void QDeclarativeWebView::drawContents(QPainter *p, const QRect &r)
-{
- Q_D(QDeclarativeWebView);
- if (d->rendering)
- page()->mainFrame()->render(p,r);
+ d->view->setTiledBackingStoreFrozen(!enabled);
}
QMouseEvent *QDeclarativeWebView::sceneMouseEventToMouseEvent(QGraphicsSceneMouseEvent *e)
@@ -556,7 +521,6 @@ QMouseEvent *QDeclarativeWebView::sceneHoverMoveEventToMouseEvent(QGraphicsScene
return me;
}
-
/*!
\qmlsignal WebView::onDoubleClick(clickx,clicky)
@@ -588,7 +552,6 @@ void QDeclarativeWebView::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
*/
bool QDeclarativeWebView::heuristicZoom(int clickX, int clickY, qreal maxzoom)
{
- Q_D(QDeclarativeWebView);
if (contentsScale() >= maxzoom/zoomFactor())
return false;
qreal ozf = contentsScale();
@@ -617,13 +580,11 @@ bool QDeclarativeWebView::heuristicZoom(int clickX, int clickY, qreal maxzoom)
*/
int QDeclarativeWebView::pressGrabTime() const
{
- Q_D(const QDeclarativeWebView);
return d->pressTime;
}
void QDeclarativeWebView::setPressGrabTime(int ms)
{
- Q_D(QDeclarativeWebView);
if (d->pressTime == ms)
return;
d->pressTime = ms;
@@ -632,8 +593,6 @@ void QDeclarativeWebView::setPressGrabTime(int ms)
void QDeclarativeWebView::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
- Q_D(QDeclarativeWebView);
-
setFocus (true);
QMouseEvent *me = sceneMouseEventToMouseEvent(event);
@@ -661,14 +620,12 @@ void QDeclarativeWebView::mousePressEvent(QGraphicsSceneMouseEvent *event)
);
delete me;
if (!event->isAccepted()) {
- QDeclarativePaintedItem::mousePressEvent(event);
+ QDeclarativeItem::mousePressEvent(event);
}
}
void QDeclarativeWebView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
- Q_D(QDeclarativeWebView);
-
QMouseEvent *me = sceneMouseEventToMouseEvent(event);
page()->event(me);
d->pressTimer.stop();
@@ -685,7 +642,7 @@ void QDeclarativeWebView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
);
delete me;
if (!event->isAccepted()) {
- QDeclarativePaintedItem::mouseReleaseEvent(event);
+ QDeclarativeItem::mouseReleaseEvent(event);
}
setKeepMouseGrab(false);
ungrabMouse();
@@ -693,7 +650,6 @@ void QDeclarativeWebView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
void QDeclarativeWebView::timerEvent(QTimerEvent *event)
{
- Q_D(QDeclarativeWebView);
if (event->timerId() == d->pressTimer.timerId()) {
d->pressTimer.stop();
grabMouse();
@@ -703,8 +659,6 @@ void QDeclarativeWebView::timerEvent(QTimerEvent *event)
void QDeclarativeWebView::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
- Q_D(QDeclarativeWebView);
-
QMouseEvent *me = sceneMouseEventToMouseEvent(event);
if (d->pressTimer.isActive()) {
if ((me->pos() - d->pressPoint).manhattanLength() > QApplication::startDragDistance()) {
@@ -728,9 +682,9 @@ void QDeclarativeWebView::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
}
delete me;
if (!event->isAccepted())
- QDeclarativePaintedItem::mouseMoveEvent(event);
-
+ QDeclarativeItem::mouseMoveEvent(event);
}
+
void QDeclarativeWebView::hoverMoveEvent (QGraphicsSceneHoverEvent * event)
{
QMouseEvent *me = sceneHoverMoveEventToMouseEvent(event);
@@ -744,21 +698,7 @@ void QDeclarativeWebView::hoverMoveEvent (QGraphicsSceneHoverEvent * event)
);
delete me;
if (!event->isAccepted())
- QDeclarativePaintedItem::hoverMoveEvent(event);
-}
-
-void QDeclarativeWebView::keyPressEvent(QKeyEvent* event)
-{
- page()->event(event);
- if (!event->isAccepted())
- QDeclarativePaintedItem::keyPressEvent(event);
-}
-
-void QDeclarativeWebView::keyReleaseEvent(QKeyEvent* event)
-{
- page()->event(event);
- if (!event->isAccepted())
- QDeclarativePaintedItem::keyReleaseEvent(event);
+ QDeclarativeItem::hoverMoveEvent(event);
}
bool QDeclarativeWebView::sceneEvent(QEvent *event)
@@ -773,7 +713,7 @@ bool QDeclarativeWebView::sceneEvent(QEvent *event)
}
}
}
- return QDeclarativePaintedItem::sceneEvent(event);
+ return QDeclarativeItem::sceneEvent(event);
}
@@ -842,15 +782,11 @@ QPixmap QDeclarativeWebView::icon() const
*/
void QDeclarativeWebView::setZoomFactor(qreal factor)
{
- Q_D(QDeclarativeWebView);
if (factor == page()->mainFrame()->zoomFactor())
return;
page()->mainFrame()->setZoomFactor(factor);
- page()->setViewportSize(QSize(
- d->preferredwidth>0 ? d->preferredwidth*factor : width()*factor,
- d->preferredheight>0 ? d->preferredheight*factor : height()*factor));
- expandToWebPage();
+ updateContentsSize();
emit zoomFactorChanged();
}
@@ -868,37 +804,27 @@ qreal QDeclarativeWebView::zoomFactor() const
*/
void QDeclarativeWebView::setStatusText(const QString& s)
{
- Q_D(QDeclarativeWebView);
d->statusText = s;
emit statusTextChanged();
}
void QDeclarativeWebView::windowObjectCleared()
{
- Q_D(QDeclarativeWebView);
d->updateWindowObjects();
}
QString QDeclarativeWebView::statusText() const
{
- Q_D(const QDeclarativeWebView);
return d->statusText;
}
QWebPage *QDeclarativeWebView::page() const
{
- Q_D(const QDeclarativeWebView);
if (!d->page) {
QDeclarativeWebView *self = const_cast<QDeclarativeWebView*>(this);
QWebPage *wp = new QDeclarativeWebPage(self);
- // QML items don't default to having a background,
- // even though most we pages will set one anyway.
- QPalette pal = QApplication::palette();
- pal.setBrush(QPalette::Base, QColor::fromRgbF(0, 0, 0, 0));
- wp->setPalette(pal);
-
wp->setNetworkAccessManager(qmlEngine(this)->networkAccessManager());
self->setPage(wp);
@@ -954,14 +880,12 @@ QWebPage *QDeclarativeWebView::page() const
*/
QDeclarativeWebSettings *QDeclarativeWebView::settingsObject() const
{
- Q_D(const QDeclarativeWebView);
d->settings.s = page()->settings();
return &d->settings;
}
void QDeclarativeWebView::setPage(QWebPage *page)
{
- Q_D(QDeclarativeWebView);
if (d->page == page)
return;
if (d->page) {
@@ -972,18 +896,15 @@ void QDeclarativeWebView::setPage(QWebPage *page)
}
}
d->page = page;
- d->page->setViewportSize(QSize(
- d->preferredwidth>0 ? d->preferredwidth : width(),
- d->preferredheight>0 ? d->preferredheight : height()));
+ updateContentsSize();
d->page->mainFrame()->setScrollBarPolicy(Qt::Horizontal,Qt::ScrollBarAlwaysOff);
d->page->mainFrame()->setScrollBarPolicy(Qt::Vertical,Qt::ScrollBarAlwaysOff);
- connect(d->page,SIGNAL(repaintRequested(QRect)),this,SLOT(paintPage(QRect)));
connect(d->page->mainFrame(),SIGNAL(urlChanged(QUrl)),this,SLOT(pageUrlChanged()));
connect(d->page->mainFrame(), SIGNAL(titleChanged(QString)), this, SIGNAL(titleChanged(QString)));
connect(d->page->mainFrame(), SIGNAL(titleChanged(QString)), this, SIGNAL(iconChanged()));
connect(d->page->mainFrame(), SIGNAL(iconChanged()), this, SIGNAL(iconChanged()));
- connect(d->page->mainFrame(), SIGNAL(contentsSizeChanged(QSize)), this, SLOT(noteContentsSizeChanged(QSize)));
connect(d->page->mainFrame(), SIGNAL(initialLayoutCompleted()), this, SLOT(initialLayout()));
+ connect(d->page->mainFrame(), SIGNAL(contentsSizeChanged(QSize)), this, SIGNAL(contentsSizeChanged(QSize)));
connect(d->page,SIGNAL(loadStarted()),this,SLOT(doLoadStarted()));
connect(d->page,SIGNAL(loadProgress(int)),this,SLOT(doLoadProgress(int)));
@@ -991,6 +912,10 @@ void QDeclarativeWebView::setPage(QWebPage *page)
connect(d->page,SIGNAL(statusBarMessage(QString)),this,SLOT(setStatusText(QString)));
connect(d->page->mainFrame(),SIGNAL(javaScriptWindowObjectCleared()),this,SLOT(windowObjectCleared()));
+
+ d->page->settings()->setAttribute(QWebSettings::TiledBackingStoreEnabled, true);
+
+ d->view->setPage(page);
}
/*!
@@ -1045,10 +970,7 @@ QString QDeclarativeWebView::html() const
*/
void QDeclarativeWebView::setHtml(const QString &html, const QUrl &baseUrl)
{
- Q_D(QDeclarativeWebView);
- page()->setViewportSize(QSize(
- d->preferredwidth>0 ? d->preferredwidth : width(),
- d->preferredheight>0 ? d->preferredheight : height()));
+ updateContentsSize();
if (isComponentComplete())
page()->mainFrame()->setHtml(html, baseUrl);
else {
@@ -1061,10 +983,7 @@ void QDeclarativeWebView::setHtml(const QString &html, const QUrl &baseUrl)
void QDeclarativeWebView::setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl)
{
- Q_D(QDeclarativeWebView);
- page()->setViewportSize(QSize(
- d->preferredwidth>0 ? d->preferredwidth : width(),
- d->preferredheight>0 ? d->preferredheight : height()));
+ updateContentsSize();
if (isComponentComplete())
page()->mainFrame()->setContent(data,mimeType,qmlContext(this)->resolvedUrl(baseUrl));
@@ -1088,7 +1007,6 @@ QWebSettings *QDeclarativeWebView::settings() const
QDeclarativeWebView *QDeclarativeWebView::createWindow(QWebPage::WebWindowType type)
{
- Q_D(QDeclarativeWebView);
switch (type) {
case QWebPage::WebBrowserWindow: {
if (!d->newWindowComponent && d->newWindowParent)
@@ -1142,13 +1060,11 @@ QDeclarativeWebView *QDeclarativeWebView::createWindow(QWebPage::WebWindowType t
*/
QDeclarativeComponent *QDeclarativeWebView::newWindowComponent() const
{
- Q_D(const QDeclarativeWebView);
return d->newWindowComponent;
}
void QDeclarativeWebView::setNewWindowComponent(QDeclarativeComponent *newWindow)
{
- Q_D(QDeclarativeWebView);
if (newWindow == d->newWindowComponent)
return;
d->newWindowComponent = newWindow;
@@ -1165,13 +1081,11 @@ void QDeclarativeWebView::setNewWindowComponent(QDeclarativeComponent *newWindow
*/
QDeclarativeItem *QDeclarativeWebView::newWindowParent() const
{
- Q_D(const QDeclarativeWebView);
return d->newWindowParent;
}
void QDeclarativeWebView::setNewWindowParent(QDeclarativeItem *parent)
{
- Q_D(QDeclarativeWebView);
if (parent == d->newWindowParent)
return;
if (d->newWindowParent && parent) {
@@ -1184,6 +1098,25 @@ void QDeclarativeWebView::setNewWindowParent(QDeclarativeItem *parent)
emit newWindowParentChanged();
}
+QSize QDeclarativeWebView::contentsSize() const
+{
+ return d->page->mainFrame()->contentsSize() * contentsScale();
+}
+
+qreal QDeclarativeWebView::contentsScale() const
+{
+ return d->view->scale();
+}
+
+void QDeclarativeWebView::setContentsScale(qreal scale)
+{
+ if (scale == d->view->scale())
+ return;
+ d->view->setScale(scale);
+ updateDeclarativeWebViewSize();
+ emit contentsScaleChanged();
+}
+
/*!
Returns the area of the largest element at position (\a x,\a y) that is no larger
than \a maxwidth by \a maxheight pixels.
@@ -1280,3 +1213,4 @@ QWebPage *QDeclarativeWebPage::createWindow(WebWindowType type)
}
QT_END_NAMESPACE
+
diff --git a/src/imports/webkit/qdeclarativewebview_p.h b/src/imports/webkit/qdeclarativewebview_p.h
index 81581d8..87bd938 100644
--- a/src/imports/webkit/qdeclarativewebview_p.h
+++ b/src/imports/webkit/qdeclarativewebview_p.h
@@ -42,12 +42,13 @@
#ifndef QDECLARATIVEWEBVIEW_H
#define QDECLARATIVEWEBVIEW_H
-#include <private/qdeclarativepainteditem_p.h>
+#include <qdeclarativeitem.h>
#include <QtGui/QAction>
#include <QtCore/QUrl>
#include <QtNetwork/qnetworkaccessmanager.h>
#include <QtWebKit/QWebPage>
+#include <QtWebKit/QGraphicsWebView>
QT_BEGIN_HEADER
@@ -61,6 +62,7 @@ class QDeclarativeWebSettings;
class QDeclarativeWebViewPrivate;
class QNetworkRequest;
class QDeclarativeWebView;
+class QDeclarativeWebViewPrivate;
class QDeclarativeWebPage : public QWebPage
{
@@ -85,7 +87,7 @@ class QDeclarativeWebViewAttached;
//### TODO: browser plugins
-class QDeclarativeWebView : public QDeclarativePaintedItem
+class QDeclarativeWebView : public QDeclarativeItem
{
Q_OBJECT
@@ -120,6 +122,9 @@ class QDeclarativeWebView : public QDeclarativePaintedItem
Q_PROPERTY(bool renderingEnabled READ renderingEnabled WRITE setRenderingEnabled NOTIFY renderingEnabledChanged)
+ Q_PROPERTY(QSize contentsSize READ contentsSize NOTIFY contentsSizeChanged)
+ Q_PROPERTY(qreal contentsScale READ contentsScale WRITE setContentsScale NOTIFY contentsScaleChanged)
+
public:
QDeclarativeWebView(QDeclarativeItem *parent=0);
~QDeclarativeWebView();
@@ -182,6 +187,13 @@ public:
QDeclarativeItem *newWindowParent() const;
void setNewWindowParent(QDeclarativeItem *newWindow);
+ bool isComponentCompletePublic() const { return isComponentComplete(); }
+
+ QSize contentsSize() const;
+
+ void setContentsScale(qreal scale);
+ qreal contentsScale() const;
+
Q_SIGNALS:
void preferredWidthChanged();
void preferredHeightChanged();
@@ -197,6 +209,8 @@ Q_SIGNALS:
void newWindowComponentChanged();
void newWindowParentChanged();
void renderingEnabledChanged();
+ void contentsSizeChanged(const QSize&);
+ void contentsScaleChanged();
void loadStarted();
void loadFinished();
@@ -212,38 +226,36 @@ public Q_SLOTS:
QVariant evaluateJavaScript(const QString&);
private Q_SLOTS:
- void expandToWebPage();
- void paintPage(const QRect&);
void doLoadStarted();
void doLoadProgress(int p);
void doLoadFinished(bool ok);
void setStatusText(const QString&);
void windowObjectCleared();
void pageUrlChanged();
- void noteContentsSizeChanged(const QSize&);
void initialLayout();
-protected:
- void drawContents(QPainter *, const QRect &);
+ void propagateFocusToWebPage(bool);
+ void updateDeclarativeWebViewSize();
+
+protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
void timerEvent(QTimerEvent *event);
void hoverMoveEvent (QGraphicsSceneHoverEvent * event);
- void keyPressEvent(QKeyEvent* event);
- void keyReleaseEvent(QKeyEvent* event);
virtual void geometryChanged(const QRectF &newGeometry,
const QRectF &oldGeometry);
virtual bool sceneEvent(QEvent *event);
QDeclarativeWebView *createWindow(QWebPage::WebWindowType type);
private:
+ void updateContentsSize();
void init();
virtual void componentComplete();
Q_DISABLE_COPY(QDeclarativeWebView)
- Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeWebView)
+ QDeclarativeWebViewPrivate* d;
QMouseEvent *sceneMouseEventToMouseEvent(QGraphicsSceneMouseEvent *);
QMouseEvent *sceneHoverMoveEventToMouseEvent(QGraphicsSceneHoverEvent *);
friend class QDeclarativeWebPage;