summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2009-08-28 06:50:06 (GMT)
committerMartin Jones <martin.jones@nokia.com>2009-08-28 06:50:06 (GMT)
commitab643ba4d2193352302d237ae36e1246b5399176 (patch)
tree095cb3db01be9c169a5e602f767f610490ca9696
parent67ca33d53ff805ca33ba775524086a89cb975df9 (diff)
parent797162603f35af1f67dd5a7c35c7004eef1828a9 (diff)
downloadQt-ab643ba4d2193352302d237ae36e1246b5399176.zip
Qt-ab643ba4d2193352302d237ae36e1246b5399176.tar.gz
Qt-ab643ba4d2193352302d237ae36e1246b5399176.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Conflicts: src/declarative/QmlChanges.txt
-rw-r--r--demos/declarative/webbrowser/webbrowser.qml38
-rw-r--r--examples/declarative/webview/autosize.qml10
-rw-r--r--examples/declarative/webview/evalandattach.qml1
-rw-r--r--examples/declarative/webview/newwindows.html3
-rw-r--r--examples/declarative/webview/newwindows.qml28
-rw-r--r--src/declarative/QmlChanges.txt8
-rw-r--r--src/declarative/fx/qfxwebview.cpp555
-rw-r--r--src/declarative/fx/qfxwebview.h83
-rw-r--r--src/declarative/util/qmlanimation.cpp14
9 files changed, 463 insertions, 277 deletions
diff --git a/demos/declarative/webbrowser/webbrowser.qml b/demos/declarative/webbrowser/webbrowser.qml
index 126fa87..278bc43 100644
--- a/demos/declarative/webbrowser/webbrowser.qml
+++ b/demos/declarative/webbrowser/webbrowser.qml
@@ -17,10 +17,10 @@ Item {
function zoomOut() {
WebBrowser.state = "ZoomedOut";
}
- function toggleZoom() {
+ function toggleZoom(x,y) {
if(WebBrowser.state == "ZoomedOut") {
- Flick.centerX = MyWebView.mouseX;
- Flick.centerY = MyWebView.mouseY;
+ Flick.centerX = x
+ Flick.centerY = y
WebBrowser.state = "Normal";
} else {
zoomOut();
@@ -135,9 +135,9 @@ Item {
text: WebBrowser.urlString
label: "url:"
- onConfirmed: { print ('OnConfirmed: '+EditUrl.text); WebBrowser.urlString = EditUrl.text; print (EditUrl.text); MyWebView.focus=true }
+ onConfirmed: { WebBrowser.urlString = EditUrl.text; MyWebView.focus=true }
onCancelled: { MyWebView.focus=true }
- onStartEdit: { print (EditUrl.text); MyWebView.focus=false }
+ onStartEdit: { MyWebView.focus=false }
anchors.left: UrlBox.left
anchors.right: UrlBox.right
@@ -188,20 +188,36 @@ Item {
WebView {
id: MyWebView
- cacheSize: 4000000
+ pixelCacheSize: 4000000
- url: WebBrowser.urlString
+ Script {
+ function fixUrl(url)
+ {
+ if (url == "") return url
+ if (url[0] == "/") return "file://"+url
+ if (url.indexOf(":")<0) {
+ if (url.indexOf(".")<0 || url.indexOf(" ")>=0) {
+ // Fall back to a search engine; hard-code Wikipedia
+ return "http://en.wikipedia.org/w/index.php?search="+url
+ } else {
+ return "http://"+url
+ }
+ }
+ return url
+ }
+ }
+
+ url: fixUrl(WebBrowser.urlString)
smooth: !Flick.moving
fillColor: "white"
focus: true
- interactive: true
- idealWidth: Flick.width
- idealHeight: Flick.height/scale
+ preferredWidth: Flick.width
+ preferredHeight: Flick.height/scale
scale: (width > 0) ? Flick.width/width*zoomedOut+(1-zoomedOut) : 1
onUrlChanged: { if (url != null) { WebBrowser.urlString = url.toString(); } }
- onDoubleClick: { toggleZoom() }
+ onDoubleClick: { toggleZoom(clickX,clickY) }
property real zoomedOut : 1
}
diff --git a/examples/declarative/webview/autosize.qml b/examples/declarative/webview/autosize.qml
index 13004a8..dbd94e1 100644
--- a/examples/declarative/webview/autosize.qml
+++ b/examples/declarative/webview/autosize.qml
@@ -1,7 +1,7 @@
import Qt 4.6
// The WebView size is determined by the width, height,
-// idealWidth, and idealHeight properties.
+// preferredWidth, and preferredHeight properties.
Rectangle {
id: Rect
color: "white"
@@ -34,16 +34,16 @@ Rectangle {
}
}
WebView {
- idealWidth: Rect.width/2
- html: "The idealWidth is half."
+ preferredWidth: Rect.width/2
+ html: "The preferredWidth is half."
Rectangle {
color: "#10000000"
anchors.fill: parent
}
}
WebView {
- idealWidth: Rect.width/2
- html: "The_idealWidth_is_half."
+ preferredWidth: Rect.width/2
+ html: "The_preferredWidth_is_half."
Rectangle {
color: "#10000000"
anchors.fill: parent
diff --git a/examples/declarative/webview/evalandattach.qml b/examples/declarative/webview/evalandattach.qml
index bf7f25e..e755819 100644
--- a/examples/declarative/webview/evalandattach.qml
+++ b/examples/declarative/webview/evalandattach.qml
@@ -35,7 +35,6 @@ Item {
anchors.left: parent.left
anchors.right: parent.right
focus: true
- interactive: true
settings.pluginsEnabled: true
javaScriptWindowObjects: [
Object {
diff --git a/examples/declarative/webview/newwindows.html b/examples/declarative/webview/newwindows.html
new file mode 100644
index 0000000..f169599
--- /dev/null
+++ b/examples/declarative/webview/newwindows.html
@@ -0,0 +1,3 @@
+<h1>Multiple windows...</h1>
+
+<a target="_blank" href="newwindows.html">Popup!</a>
diff --git a/examples/declarative/webview/newwindows.qml b/examples/declarative/webview/newwindows.qml
new file mode 100644
index 0000000..9ff902e2
--- /dev/null
+++ b/examples/declarative/webview/newwindows.qml
@@ -0,0 +1,28 @@
+// Demonstrates opening new WebViews from HTML
+//
+// Note that to open windows from JavaScript, you will need to
+// allow it on WebView with settings.javascriptCanOpenWindows: true
+
+import Qt 4.6
+
+Row {
+ id: Pages
+ height: 200
+ resources: [
+ Component {
+ id: WebViewPage
+ Rectangle {
+ width: WV.width
+ height: WV.height
+ WebView {
+ id: WV
+ newWindowComponent: WebViewPage
+ newWindowParent: Pages
+ url: "newwindows.html"
+ }
+ }
+ }
+ ]
+ width: 500
+ ComponentInstance { component: WebViewPage }
+}
diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt
index e760037..069bf49 100644
--- a/src/declarative/QmlChanges.txt
+++ b/src/declarative/QmlChanges.txt
@@ -47,17 +47,25 @@ Flickable: yPosition -> viewportY
Flickable: xVelocity -> horizontalVelocity
Flickable: yVelocity -> verticalVelocity
Flickable: velocityDecay -> reportedVelocitySmoothing
+WebView: idealWidth -> preferredWidth
+WebView: idealHeight -> preferredHeight
+WebView: status -> statusText
+WebView: mouseX -> clickX (parameter to onDoubleClick)
+WebView: mouseY -> clickY (parameter to onDoubleClick)
+WebView: cacheSize -> pixelCacheSize
Additions:
MouseRegion: add "acceptedButtons" property
MouseRegion: add "hoverEnabled" property
MouseRegion: add "pressedButtons" property
Timer: add start() and stop() slots
+WebView: add newWindowComponent and newWindowParent properties
Deletions:
Column/VerticalPositioner: lost "margins" property
Row/HorizontalPositioner: lost "margins" property
Grid/Positioner/Layout: lost "margins" property
+WebView: lost "interactive" property (always true now)
Other Changes:
Drag: axis becomes an enum with values "XAxis", "YAxis", "XandYAxis"
diff --git a/src/declarative/fx/qfxwebview.cpp b/src/declarative/fx/qfxwebview.cpp
index d3ce00c..b150ca0 100644
--- a/src/declarative/fx/qfxwebview.cpp
+++ b/src/declarative/fx/qfxwebview.cpp
@@ -51,6 +51,7 @@
#include <QtWebKit/QWebPage>
#include <QtWebKit/QWebFrame>
#include <QtWebKit/QWebElement>
+#include <QtWebKit/QWebSettings>
#include "qml.h"
#include "qmlengine.h"
@@ -62,25 +63,24 @@
QT_BEGIN_NAMESPACE
QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,WebView,QFxWebView)
+QML_DEFINE_NOCREATE_TYPE(QAction)
static const int MAX_DOUBLECLICK_TIME=500; // XXX need better gesture system
class QFxWebSettings : public QObject {
Q_OBJECT
- /*
- ### Add these
- StandardFont,
- FixedFont,
- SerifFont,
- SansSerifFont,
- CursiveFont,
- FantasyFont
-
- MinimumFontSize,
- MinimumLogicalFontSize,
- DefaultFontSize,
- DefaultFixedFontSize
- */
+
+ Q_PROPERTY(QString standardFontFamily READ standardFontFamily WRITE setStandardFontFamily)
+ Q_PROPERTY(QString fixedFontFamily READ fixedFontFamily WRITE setFixedFontFamily)
+ Q_PROPERTY(QString serifFontFamily READ serifFontFamily WRITE setSerifFontFamily)
+ Q_PROPERTY(QString sansSerifFontFamily READ sansSerifFontFamily WRITE setSansSerifFontFamily)
+ Q_PROPERTY(QString cursiveFontFamily READ cursiveFontFamily WRITE setCursiveFontFamily)
+ Q_PROPERTY(QString fantasyFontFamily READ fantasyFontFamily WRITE setFantasyFontFamily)
+
+ Q_PROPERTY(int minimumFontSize READ minimumFontSize WRITE setMinimumFontSize)
+ Q_PROPERTY(int minimumLogicalFontSize READ minimumLogicalFontSize WRITE setMinimumLogicalFontSize)
+ Q_PROPERTY(int defaultFontSize READ defaultFontSize WRITE setDefaultFontSize)
+ Q_PROPERTY(int defaultFixedFontSize READ defaultFixedFontSize WRITE setDefaultFixedFontSize)
Q_PROPERTY(bool autoLoadImages READ autoLoadImages WRITE setAutoLoadImages)
Q_PROPERTY(bool javascriptEnabled READ javascriptEnabled WRITE setJavascriptEnabled)
@@ -96,10 +96,33 @@ class QFxWebSettings : public QObject {
Q_PROPERTY(bool offlineStorageDatabaseEnabled READ offlineStorageDatabaseEnabled WRITE setOfflineStorageDatabaseEnabled)
Q_PROPERTY(bool offlineWebApplicationCacheEnabled READ offlineWebApplicationCacheEnabled WRITE setOfflineWebApplicationCacheEnabled)
Q_PROPERTY(bool localStorageDatabaseEnabled READ localStorageDatabaseEnabled WRITE setLocalStorageDatabaseEnabled)
+ Q_PROPERTY(bool localContentCanAccessRemoteUrls READ localContentCanAccessRemoteUrls WRITE setLocalContentCanAccessRemoteUrls)
public:
QFxWebSettings() {}
+ QString standardFontFamily() const { return s->fontFamily(QWebSettings::StandardFont); }
+ void setStandardFontFamily(const QString& f) { s->setFontFamily(QWebSettings::StandardFont,f); }
+ QString fixedFontFamily() const { return s->fontFamily(QWebSettings::FixedFont); }
+ void setFixedFontFamily(const QString& f) { s->setFontFamily(QWebSettings::FixedFont,f); }
+ QString serifFontFamily() const { return s->fontFamily(QWebSettings::SerifFont); }
+ void setSerifFontFamily(const QString& f) { s->setFontFamily(QWebSettings::SerifFont,f); }
+ QString sansSerifFontFamily() const { return s->fontFamily(QWebSettings::SansSerifFont); }
+ void setSansSerifFontFamily(const QString& f) { s->setFontFamily(QWebSettings::SansSerifFont,f); }
+ QString cursiveFontFamily() const { return s->fontFamily(QWebSettings::CursiveFont); }
+ void setCursiveFontFamily(const QString& f) { s->setFontFamily(QWebSettings::CursiveFont,f); }
+ QString fantasyFontFamily() const { return s->fontFamily(QWebSettings::FantasyFont); }
+ void setFantasyFontFamily(const QString& f) { s->setFontFamily(QWebSettings::FantasyFont,f); }
+
+ int minimumFontSize() const { return s->fontSize(QWebSettings::MinimumFontSize); }
+ void setMinimumFontSize(int size) { s->setFontSize(QWebSettings::MinimumFontSize,size); }
+ int minimumLogicalFontSize() const { return s->fontSize(QWebSettings::MinimumLogicalFontSize); }
+ void setMinimumLogicalFontSize(int size) { s->setFontSize(QWebSettings::MinimumLogicalFontSize,size); }
+ int defaultFontSize() const { return s->fontSize(QWebSettings::DefaultFontSize); }
+ void setDefaultFontSize(int size) { s->setFontSize(QWebSettings::DefaultFontSize,size); }
+ int defaultFixedFontSize() const { return s->fontSize(QWebSettings::DefaultFixedFontSize); }
+ void setDefaultFixedFontSize(int size) { s->setFontSize(QWebSettings::DefaultFixedFontSize,size); }
+
bool autoLoadImages() const { return s->testAttribute(QWebSettings::AutoLoadImages); }
void setAutoLoadImages(bool on) { s->setAttribute(QWebSettings::AutoLoadImages, on); }
bool javascriptEnabled() const { return s->testAttribute(QWebSettings::JavascriptEnabled); }
@@ -128,6 +151,8 @@ public:
void setOfflineWebApplicationCacheEnabled(bool on) { s->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, on); }
bool localStorageDatabaseEnabled() const { return s->testAttribute(QWebSettings::LocalStorageDatabaseEnabled); }
void setLocalStorageDatabaseEnabled(bool on) { s->setAttribute(QWebSettings::LocalStorageDatabaseEnabled, on); }
+ bool localContentCanAccessRemoteUrls() const { return s->testAttribute(QWebSettings::LocalContentCanAccessRemoteUrls); }
+ void setLocalContentCanAccessRemoteUrls(bool on) { s->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls, on); }
QWebSettings *s;
};
@@ -141,26 +166,28 @@ class QFxWebViewPrivate : public QFxPaintedItemPrivate
public:
QFxWebViewPrivate()
- : QFxPaintedItemPrivate(), page(0), idealwidth(0), idealheight(0), interactive(true), lastPress(0), lastRelease(0), mouseX(0), mouseY(0),
- progress(1.0), pending(PendingNone), windowObjects(this)
+ : QFxPaintedItemPrivate(), page(0), idealwidth(0), idealheight(0),
+ progress(1.0), status(QFxWebView::Null), pending(PendingNone),
+ newWindowComponent(0), newWindowParent(0),
+ windowObjects(this)
{
}
+ QUrl url; // page url might be different if it has not loaded yet
QWebPage *page;
int idealwidth;
int idealheight;
- bool interactive;
- QMouseEvent *lastPress, *lastRelease;
- int mouseX, mouseY;
qreal progress;
- QBasicTimer dcTimer;
- QString statusBarMessage;
+ QFxWebView::Status status;
+ QString statusText;
enum { PendingNone, PendingUrl, PendingHtml, PendingContent } pending;
QUrl pending_url;
QString pending_string;
QByteArray pending_data;
mutable QFxWebSettings settings;
+ QmlComponent *newWindowComponent;
+ QFxItem *newWindowParent;
void updateWindowObjects();
class WindowObjectList : public QmlConcreteList<QObject *>
@@ -188,12 +215,12 @@ public:
dynamically adjust to a size appropriate for the content.
This width may be large (eg. 980) for typical online web pages.
- If the idealWidth is set, the width will be this amount or larger,
- usually laying out the web content to fit the idealWidth.
+ If the preferredWidth is set, the width will be this amount or larger,
+ usually laying out the web content to fit the preferredWidth.
- If the idealHeight is set, the height will be this amount or larger.
+ If the preferredHeight is set, the height will be this amount or larger.
Due to WebKit limitations, the height may be more than necessary
- if the idealHeight is changed after the content is loaded.
+ if the preferredHeight is changed after the content is loaded.
\qml
WebView {
@@ -278,9 +305,18 @@ void QFxWebView::componentComplete()
d->updateWindowObjects();
}
+QFxWebView::Status QFxWebView::status() const
+{
+ Q_D(const QFxWebView);
+ return d->status;
+}
+
+
/*!
\qmlproperty real WebView::progress
This property holds the progress of loading the current URL, from 0 to 1.
+
+ \sa onLoadFinished() onLoadFailed()
*/
qreal QFxWebView::progress() const
{
@@ -288,6 +324,16 @@ qreal QFxWebView::progress() const
return d->progress;
}
+void QFxWebView::doLoadStarted()
+{
+ Q_D(QFxWebView);
+ if (!d->url.isEmpty()) {
+ d->status = Loading;
+ emit statusChanged(d->status);
+ }
+ emit loadStarted();
+}
+
void QFxWebView::doLoadProgress(int p)
{
Q_D(QFxWebView);
@@ -298,116 +344,114 @@ void QFxWebView::doLoadProgress(int p)
emit progressChanged();
}
+void QFxWebView::pageUrlChanged()
+{
+ Q_D(QFxWebView);
+ if ((d->url.isEmpty() && page()->mainFrame()->url() != QUrl(QLatin1String("about:blank")))
+ || d->url != page()->mainFrame()->url())
+ {
+ d->url = page()->mainFrame()->url();
+ if (d->url == QUrl(QLatin1String("about:blank")))
+ d->url = QUrl();
+ emit urlChanged();
+ }
+}
+
void QFxWebView::doLoadFinished(bool ok)
{
- // XXX bug 232556 - pages with no title never get this signal
+ Q_D(QFxWebView);
if (title().isEmpty())
- emit urlChanged();
+ pageUrlChanged(); // XXX bug 232556 - pages with no title never get urlChanged()
if (ok) {
+ d->status = d->url.isEmpty() ? Null : Ready;
emit loadFinished();
} else {
+ d->status = Error;
emit loadFailed();
}
+ emit statusChanged(d->status);
}
/*!
\qmlproperty url WebView::url
- This property holds the URL to the page displayed in this item.
+ This property holds the URL to the page displayed in this item. It can be set,
+ but also can change spontaneously (eg. because of network redirection).
- Note that after this property is set, it may take some time
- before the change is notified, as this only happens when
- loading of the URL successfully starts.
+ If the url is empty, the page is blank.
+
+ The url is always absolute (QML will resolve relative URL strings in the context
+ of the containing QML document).
*/
QUrl QFxWebView::url() const
{
- return page()->mainFrame()->url();
+ Q_D(const QFxWebView);
+ return d->url;
}
void QFxWebView::setUrl(const QUrl &url)
{
- if (url.isEmpty()) {
- // Make absolute.
- setUrl(QUrl("about:blank"));
- return;
- }
-
Q_D(QFxWebView);
- if (url == page()->mainFrame()->url())
+ if (url == d->url)
return;
- page()->setViewportSize(QSize(
- d->idealwidth>0 ? d->idealwidth : width(),
- d->idealheight>0 ? d->idealheight : height()));
+ if (isComponentComplete()) {
+ d->url = url;
+ page()->setViewportSize(QSize(
+ d->idealwidth>0 ? d->idealwidth : width(),
+ d->idealheight>0 ? d->idealheight : height()));
- Q_ASSERT(!url.isRelative());
+ QUrl seturl = url;
+ if (seturl.isEmpty())
+ seturl = QUrl(QLatin1String("about:blank"));
- if (isComponentComplete())
- page()->mainFrame()->load(url);
- else {
+ Q_ASSERT(!seturl.isRelative());
+
+ page()->mainFrame()->load(seturl);
+
+ emit urlChanged();
+ } else {
d->pending = d->PendingUrl;
d->pending_url = url;
}
-
- // emit urlChanged() - not until actually loaded
}
/*!
- \qmlproperty int WebView::idealWidth
+ \qmlproperty int WebView::preferredWidth
This property holds the ideal width for displaying the current URL.
*/
-int QFxWebView::idealWidth() const
+int QFxWebView::preferredWidth() const
{
Q_D(const QFxWebView);
return d->idealwidth;
}
-void QFxWebView::setIdealWidth(int iw)
+void QFxWebView::setPreferredWidth(int iw)
{
Q_D(QFxWebView);
if (d->idealwidth == iw) return;
d->idealwidth = iw;
expandToWebPage();
- emit idealWidthChanged();
+ emit preferredWidthChanged();
}
/*!
- \qmlproperty int WebView::idealHeight
+ \qmlproperty int WebView::preferredHeight
This property holds the ideal height for displaying the current URL.
*/
-int QFxWebView::idealHeight() const
+int QFxWebView::preferredHeight() const
{
Q_D(const QFxWebView);
return d->idealheight;
}
-void QFxWebView::setIdealHeight(int ih)
+void QFxWebView::setPreferredHeight(int ih)
{
Q_D(QFxWebView);
if (d->idealheight == ih) return;
d->idealheight = ih;
expandToWebPage();
- emit idealHeightChanged();
-}
-
-/*!
- \qmlproperty bool WebView::interactive
-
- This property controls whether the item responds to mouse and
- key events.
-*/
-bool QFxWebView::interactive() const
-{
- Q_D(const QFxWebView);
- return d->interactive;
-}
-
-void QFxWebView::setInteractive(bool i)
-{
- Q_D(QFxWebView);
- if (d->interactive == i) return;
- d->interactive = i;
- emit interactiveChanged();
+ emit preferredHeightChanged();
}
/*!
@@ -464,19 +508,19 @@ void QFxWebView::paintPage(const QRect& r)
}
/*!
- \qmlproperty int WebView::cacheSize
+ \qmlproperty int WebView::pixelCacheSize
This property holds the maximum number of pixels of image cache to
allow. The default is 0.1 megapixels. The cache will not be larger
than the (unscaled) size of the WebView.
*/
-int QFxWebView::cacheSize() const
+int QFxWebView::pixelCacheSize() const
{
Q_D(const QFxWebView);
return d->max_imagecache_size;
}
-void QFxWebView::setCacheSize(int pixels)
+void QFxWebView::setPixelCacheSize(int pixels)
{
Q_D(QFxWebView);
if (pixels < d->max_imagecache_size) {
@@ -612,85 +656,38 @@ static QMouseEvent *sceneHoverMoveEventToMouseEvent(QGraphicsSceneHoverEvent *e)
}
-void QFxWebView::timerEvent(QTimerEvent *event)
-{
- Q_D(QFxWebView);
- if (event->timerId() ==d->dcTimer.timerId()) {
- d->dcTimer.stop();
- if (d->lastPress) {
- page()->event(d->lastPress);
- delete d->lastPress;
- d->lastPress = 0;
- }
- if (d->lastRelease) {
- page()->event(d->lastRelease);
- delete d->lastRelease;
- d->lastRelease = 0;
- }
- }
-}
-
-int QFxWebView::mouseX() const
-{
- Q_D(const QFxWebView);
- if (d->lastPress)
- return d->lastPress->x();
- if (d->lastRelease)
- return d->lastRelease->x();
- return d->mouseX;
-}
+/*!
+ \qmlsignal WebView::onDoubleClick(clickx,clicky)
-int QFxWebView::mouseY() const
-{
- Q_D(const QFxWebView);
- if (d->lastPress)
- return d->lastPress->y();
- if (d->lastRelease)
- return d->lastRelease->y();
- return d->mouseY;
-}
+ The WebView does not pass double-click events to the engine, but rather
+ emits this signals.
+*/
void QFxWebView::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
QMouseEvent *me = sceneMouseEventToMouseEvent(event);
- Q_D(QFxWebView);
- d->dcTimer.stop();
- delete d->lastPress;
- delete d->lastRelease;
- d->lastPress = 0;
- d->lastRelease = 0;
- d->mouseX = me->x();
- d->mouseY = me->y();
- emit doubleClick();
- d->mouseX = 0;
- d->mouseY = 0;
+ emit doubleClick(me->x(),me->y());
delete me;
}
void QFxWebView::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
- Q_D(QFxWebView);
- if (d->interactive) {
- setFocus (true);
- QMouseEvent *me = sceneMouseEventToMouseEvent(event);
- if (d->lastPress) delete d->lastPress;
- d->lastPress = me;
- page()->event(me);
- event->setAccepted(
- /*
- It is not correct to send the press event upwards, if it is not accepted by WebKit
- e.g. push button does not work, if done so as QGraphicsScene will not send the release event at all to WebKit
- Might be a bug in WebKit, though
- */
+ setFocus (true);
+ QMouseEvent *me = sceneMouseEventToMouseEvent(event);
+ page()->event(me);
+ event->setAccepted(
+/*
+ It is not correct to send the press event upwards, if it is not accepted by WebKit
+ e.g. push button does not work, if done so as QGraphicsScene will not send the release event at all to WebKit
+ Might be a bug in WebKit, though
+ */
#if 1 //QT_VERSION <= 0x040500 // XXX see bug 230835
- true
+ true
#else
- me->isAccepted()
+ me->isAccepted()
#endif
- );
- } else {
- event->setAccepted(false);
- }
+ );
+ delete me;
if (!event->isAccepted()) {
QFxPaintedItem::mousePressEvent(event);
}
@@ -698,27 +695,20 @@ void QFxWebView::mousePressEvent(QGraphicsSceneMouseEvent *event)
void QFxWebView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
- Q_D(QFxWebView);
- if (d->interactive) {
- QMouseEvent *me = sceneMouseEventToMouseEvent(event);
- if (d->lastRelease) delete d->lastRelease;
- d->lastRelease = me;
- page()->event(me);
- d->dcTimer.start(MAX_DOUBLECLICK_TIME,this);
- event->setAccepted(
- /*
- It is not correct to send the press event upwards, if it is not accepted by WebKit
- e.g. push button does not work, if done so as QGraphicsScene will not send all the events to WebKit
- */
+ QMouseEvent *me = sceneMouseEventToMouseEvent(event);
+ page()->event(me);
+ event->setAccepted(
+/*
+ It is not correct to send the press event upwards, if it is not accepted by WebKit
+ e.g. push button does not work, if done so as QGraphicsScene will not send all the events to WebKit
+ */
#if 1 //QT_VERSION <= 0x040500 // XXX see bug 230835
- true
+ true
#else
- me->isAccepted()
+ me->isAccepted()
#endif
- );
- } else {
- event->setAccepted(false);
- }
+ );
+ delete me;
if (!event->isAccepted()) {
QFxPaintedItem::mouseReleaseEvent(event);
}
@@ -726,86 +716,67 @@ void QFxWebView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
void QFxWebView::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
- Q_D(const QFxWebView);
- if (d->interactive && !d->dcTimer.isActive()) {
- QMouseEvent *me = sceneMouseEventToMouseEvent(event);
- page()->event(me);
- event->setAccepted(
- /*
- It is not correct to send the press event upwards, if it is not accepted by WebKit
- e.g. push button does not work, if done so as QGraphicsScene will not send the release event at all to WebKit
- Might be a bug in WebKit, though
- */
+ QMouseEvent *me = sceneMouseEventToMouseEvent(event);
+ page()->event(me);
+ event->setAccepted(
+/*
+ It is not correct to send the press event upwards, if it is not accepted by WebKit
+ e.g. push button does not work, if done so as QGraphicsScene will not send the release event at all to WebKit
+ Might be a bug in WebKit, though
+ */
#if 1 // QT_VERSION <= 0x040500 // XXX see bug 230835
- true
+ true
#else
- me->isAccepted()
+ me->isAccepted()
#endif
- );
- delete me;
- } else {
- event->setAccepted(false);
- }
+ );
+ delete me;
if (!event->isAccepted())
QFxPaintedItem::mouseMoveEvent(event);
}
void QFxWebView::hoverMoveEvent (QGraphicsSceneHoverEvent * event)
{
- Q_D(const QFxWebView);
- if (d->interactive) {
- QMouseEvent *me = sceneHoverMoveEventToMouseEvent(event);
- page()->event(me);
- event->setAccepted(
+ QMouseEvent *me = sceneHoverMoveEventToMouseEvent(event);
+ page()->event(me);
+ event->setAccepted(
#if QT_VERSION <= 0x040500 // XXX see bug 230835
- true
+ true
#else
- me->isAccepted()
+ me->isAccepted()
#endif
- );
- delete me;
- }
- else {
- event->setAccepted(false);
- }
+ );
+ delete me;
if (!event->isAccepted())
QFxPaintedItem::hoverMoveEvent(event);
}
void QFxWebView::keyPressEvent(QKeyEvent* event)
{
- Q_D(const QFxWebView);
- if (d->interactive)
- page()->event(event);
+ page()->event(event);
if (!event->isAccepted())
QFxPaintedItem::keyPressEvent(event);
}
void QFxWebView::keyReleaseEvent(QKeyEvent* event)
{
- Q_D(const QFxWebView);
- if (d->interactive)
- page()->event(event);
+ page()->event(event);
if (!event->isAccepted())
QFxPaintedItem::keyReleaseEvent(event);
}
bool QFxWebView::sceneEvent(QEvent *event)
{
- Q_D(const QFxWebView);
-
- if (d->interactive) {
- if (event->type() == QEvent::KeyPress) {
- QKeyEvent *k = static_cast<QKeyEvent *>(event);
- if (k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) {
- if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) { //### Add MetaModifier?
- page()->event(event);
- if (event->isAccepted())
- return true;
- }
+ if (event->type() == QEvent::KeyPress) {
+ QKeyEvent *k = static_cast<QKeyEvent *>(event);
+ if (k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) {
+ if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) { //### Add MetaModifier?
+ page()->event(event);
+ if (event->isAccepted())
+ return true;
}
}
- }
+ }
return QFxPaintedItem::sceneEvent(event);
}
@@ -909,11 +880,17 @@ qreal QFxWebView::zoomFactor() const
return page()->mainFrame()->zoomFactor();
}
-void QFxWebView::setStatusBarMessage(const QString& s)
+/*!
+ \qmlproperty string WebView::statusText
+
+ This property is the current status suggested by the current web page. In a web browser,
+ such status is often shown in some kind of status bar.
+*/
+void QFxWebView::setStatusText(const QString& s)
{
Q_D(QFxWebView);
- d->statusBarMessage = s;
- emit statusChanged();
+ d->statusText = s;
+ emit statusTextChanged();
}
void QFxWebView::windowObjectCleared()
@@ -922,10 +899,10 @@ void QFxWebView::windowObjectCleared()
d->updateWindowObjects();
}
-QString QFxWebView::status() const
+QString QFxWebView::statusText() const
{
Q_D(const QFxWebView);
- return d->statusBarMessage;
+ return d->statusText;
}
QWebPage *QFxWebView::page() const
@@ -955,6 +932,18 @@ QWebPage *QFxWebView::page() const
// The QObject interface to settings().
/*!
+ \qmlproperty string WebView::settings.standardFontFamily
+ \qmlproperty string WebView::settings.fixedFontFamily
+ \qmlproperty string WebView::settings.serifFontFamily
+ \qmlproperty string WebView::settings.sansSerifFontFamily
+ \qmlproperty string WebView::settings.cursiveFontFamily
+ \qmlproperty string WebView::settings.fantasyFontFamily
+
+ \qmlproperty int WebView::settings.minimumFontSize
+ \qmlproperty int WebView::settings.minimumLogicalFontSize
+ \qmlproperty int WebView::settings.defaultFontSize
+ \qmlproperty int WebView::settings.defaultFixedFontSize
+
\qmlproperty bool WebView::settings.autoLoadImages
\qmlproperty bool WebView::settings.javascriptEnabled
\qmlproperty bool WebView::settings.javaEnabled
@@ -969,14 +958,16 @@ QWebPage *QFxWebView::page() const
\qmlproperty bool WebView::settings.offlineStorageDatabaseEnabled
\qmlproperty bool WebView::settings.offlineWebApplicationCacheEnabled
\qmlproperty bool WebView::settings.localStorageDatabaseEnabled
+ \qmlproperty bool WebView::settings.localContentCanAccessRemoteUrls
These properties give access to the settings controlling the web view.
- See QWebSettings for the list of sub-properties.
+ See QWebSettings for details of these properties.
\qml
WebView {
settings.pluginsEnabled: true
+ settings.standardFontFamily: "Arial"
...
}
\endqml
@@ -1007,18 +998,45 @@ void QFxWebView::setPage(QWebPage *page)
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,SIGNAL(urlChanged()));
+ 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(iconChanged()), this, SIGNAL(iconChanged()));
- connect(d->page,SIGNAL(loadStarted()),this,SIGNAL(loadStarted()));
+ connect(d->page,SIGNAL(loadStarted()),this,SLOT(doLoadStarted()));
connect(d->page,SIGNAL(loadProgress(int)),this,SLOT(doLoadProgress(int)));
connect(d->page,SIGNAL(loadFinished(bool)),this,SLOT(doLoadFinished(bool)));
- connect(d->page,SIGNAL(statusBarMessage(QString)),this,SLOT(setStatusBarMessage(QString)));
+ connect(d->page,SIGNAL(statusBarMessage(QString)),this,SLOT(setStatusText(QString)));
connect(d->page->mainFrame(),SIGNAL(javaScriptWindowObjectCleared()),this,SLOT(windowObjectCleared()));
}
+/*!
+ \qmlsignal WebView::onLoadStarted()
+
+ This handler is called when the web engine begins loading
+ a page.
+
+ \sa progress onLoadFinished() onLoadFailed()
+*/
+
+/*!
+ \qmlsignal WebView::onLoadFinished()
+
+ This handler is called when the web engine finishes loading
+ a page, including any component content.
+
+ \sa progress onLoadFailed()
+*/
+
+/*!
+ \qmlsignal WebView::onLoadFailed()
+
+ This handler is called when the web engine fails loading
+ a page or any component content.
+
+ \sa progress onLoadFinished()
+*/
+
void QFxWebView::load(const QNetworkRequest &request,
QNetworkAccessManager::Operation operation,
const QByteArray &body)
@@ -1085,6 +1103,95 @@ QWebSettings *QFxWebView::settings() const
return page()->settings();
}
+QFxWebView *QFxWebView::createWindow(QWebPage::WebWindowType type)
+{
+ Q_D(QFxWebView);
+ switch (type) {
+ case QWebPage::WebBrowserWindow: {
+ if (!d->newWindowComponent && d->newWindowParent)
+ qWarning("WebView::newWindowComponent not set - WebView::newWindowParent ignored");
+ else if (d->newWindowComponent && !d->newWindowParent)
+ qWarning("WebView::newWindowParent not set - WebView::newWindowComponent ignored");
+ else if (d->newWindowComponent && d->newWindowParent) {
+ QFxWebView *webview = 0;
+ QmlContext *windowContext = new QmlContext(qmlContext(this));
+
+ QObject *nobj = d->newWindowComponent->create(windowContext);
+ if (nobj) {
+ windowContext->setParent(nobj);
+ QFxItem *item = qobject_cast<QFxItem *>(nobj);
+ if (!item) {
+ delete nobj;
+ } else {
+ webview = item->findChild<QFxWebView*>();
+ if (!webview) {
+ delete item;
+ } else {
+ item->setParent(d->newWindowParent);
+ }
+ }
+ } else {
+ delete windowContext;
+ }
+
+ return webview;
+ }
+ }
+ break;
+ case QWebPage::WebModalDialog: {
+ // Not supported
+ }
+ }
+ return 0;
+}
+
+/*!
+ \qmlproperty component WebView::newWindowComponent
+
+ This property holds the component to use for new windows.
+ The component must have a WebView somewhere in its structure.
+
+ When the web engine requests a new window, it will be an instance of
+ this component.
+
+ The parent of the new window is set by newWindowParent. It must be set.
+*/
+QmlComponent *QFxWebView::newWindowComponent() const
+{
+ Q_D(const QFxWebView);
+ return d->newWindowComponent;
+}
+
+void QFxWebView::setNewWindowComponent(QmlComponent *newWindow)
+{
+ Q_D(QFxWebView);
+ delete d->newWindowComponent;
+ d->newWindowComponent = newWindow;
+}
+
+
+/*!
+ \qmlproperty item WebView::newWindowParent
+
+ The parent item for new windows.
+
+ \sa newWindowComponent
+*/
+QFxItem *QFxWebView::newWindowParent() const
+{
+ Q_D(const QFxWebView);
+ return d->newWindowParent;
+}
+
+void QFxWebView::setNewWindowParent(QFxItem *parent)
+{
+ Q_D(QFxWebView);
+ delete d->newWindowParent;
+ d->newWindowParent = parent;
+}
+
+
+
/*!
\internal
\class QFxWebPage
@@ -1192,6 +1299,14 @@ QObject *QFxWebPage::createPlugin(const QString &, const QUrl &url, const QStrin
return new QWidget_Dummy_Plugin(comp,viewItem(),paramNames,paramValues);
}
+QWebPage *QFxWebPage::createWindow(WebWindowType type)
+{
+ QFxWebView *newView = viewItem()->createWindow(type);
+ if (newView)
+ return newView->page();
+ return 0;
+}
+
QT_END_NAMESPACE
#include "qfxwebview.moc"
diff --git a/src/declarative/fx/qfxwebview.h b/src/declarative/fx/qfxwebview.h
index ef40912..f084d61 100644
--- a/src/declarative/fx/qfxwebview.h
+++ b/src/declarative/fx/qfxwebview.h
@@ -69,6 +69,8 @@ public:
~QFxWebPage();
protected:
QObject *createPlugin(const QString &classid, const QUrl &url, const QStringList &paramNames, const QStringList &paramValues);
+ QWebPage *createWindow(WebWindowType type);
+
private:
QFxWebView *viewItem();
};
@@ -77,7 +79,6 @@ private:
class QFxWebViewAttached;
class QFxWebSettings;
-//### TODO: new web "windows" (popups)
//### TODO: browser plugins
//### TODO: smart zooming using e.g. DIV
@@ -85,35 +86,35 @@ class Q_DECLARATIVE_EXPORT QFxWebView : public QFxPaintedItem
{
Q_OBJECT
+ Q_ENUMS(Status)
+
Q_PROPERTY(QString title READ title NOTIFY titleChanged)
Q_PROPERTY(QPixmap icon READ icon NOTIFY iconChanged)
Q_PROPERTY(qreal textSizeMultiplier READ textSizeMultiplier WRITE setTextSizeMultiplier DESIGNABLE false)
Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged)
- Q_PROPERTY(QString status READ status NOTIFY statusChanged) //### statusText
-
- Q_PROPERTY(int mouseX READ mouseX) //### remove and find way to handle double clicking
- Q_PROPERTY(int mouseY READ mouseY)
+ Q_PROPERTY(QString statusText READ statusText NOTIFY statusTextChanged)
Q_PROPERTY(QString html READ html WRITE setHtml)
- Q_PROPERTY(int idealWidth READ idealWidth WRITE setIdealWidth NOTIFY idealWidthChanged) //### widthHint
- Q_PROPERTY(int idealHeight READ idealHeight WRITE setIdealHeight NOTIFY idealHeightChanged) //### heightHint
- Q_PROPERTY(int cacheSize READ cacheSize WRITE setCacheSize) //### remove
- Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged) //### change immediately
+ Q_PROPERTY(int preferredWidth READ preferredWidth WRITE setPreferredWidth NOTIFY preferredWidthChanged)
+ Q_PROPERTY(int preferredHeight READ preferredHeight WRITE setPreferredHeight NOTIFY preferredHeightChanged)
+ Q_PROPERTY(int pixelCacheSize READ pixelCacheSize WRITE setPixelCacheSize)
+ Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged)
Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged)
- //### status
+ Q_PROPERTY(Status status READ status NOTIFY statusChanged)
- Q_PROPERTY(bool interactive READ interactive WRITE setInteractive NOTIFY interactiveChanged) //### Really needed here??
-
- Q_PROPERTY(QObject* reload READ reloadAction CONSTANT) //### QAction
- Q_PROPERTY(QObject* back READ backAction CONSTANT) //### QAction
- Q_PROPERTY(QObject* forward READ forwardAction CONSTANT) //### QAction
- Q_PROPERTY(QObject* stop READ stopAction CONSTANT) //### QAction
+ Q_PROPERTY(QAction* reload READ reloadAction CONSTANT)
+ Q_PROPERTY(QAction* back READ backAction CONSTANT)
+ Q_PROPERTY(QAction* forward READ forwardAction CONSTANT)
+ Q_PROPERTY(QAction* stop READ stopAction CONSTANT)
Q_PROPERTY(QFxWebSettings* settings READ settingsObject CONSTANT)
Q_PROPERTY(QmlList<QObject *>* javaScriptWindowObjects READ javaScriptWindowObjects CONSTANT)
+ Q_PROPERTY(QmlComponent* newWindowComponent READ newWindowComponent WRITE setNewWindowComponent)
+ Q_PROPERTY(QFxItem* newWindowParent READ newWindowParent WRITE setNewWindowParent)
+
public:
QFxWebView(QFxItem *parent=0);
~QFxWebView();
@@ -131,19 +132,15 @@ public:
qreal zoomFactor() const;
void setZoomFactor(qreal);
- bool interactive() const;
- void setInteractive(bool);
-
- int mouseX() const;
- int mouseY() const;
-
- int idealWidth() const;
- void setIdealWidth(int);
- int idealHeight() const;
- void setIdealHeight(int);
-
+ int preferredWidth() const;
+ void setPreferredWidth(int);
+ int preferredHeight() const;
+ void setPreferredHeight(int);
+ enum Status { Null, Ready, Loading, Error };
+ Status status() const;
qreal progress() const;
+ QString statusText() const;
QAction *reloadAction() const;
QAction *backAction() const;
@@ -166,32 +163,34 @@ public:
QWebSettings *settings() const;
QFxWebSettings *settingsObject() const;
- QString status() const;
-
- int cacheSize() const;
- void setCacheSize(int pixels);
+ int pixelCacheSize() const;
+ void setPixelCacheSize(int pixels);
QmlList<QObject *> *javaScriptWindowObjects();
static QFxWebViewAttached *qmlAttachedProperties(QObject *);
+ QmlComponent *newWindowComponent() const;
+ void setNewWindowComponent(QmlComponent *newWindow);
+ QFxItem *newWindowParent() const;
+ void setNewWindowParent(QFxItem *newWindow);
+
Q_SIGNALS:
- void idealWidthChanged();
- void idealHeightChanged();
+ void preferredWidthChanged();
+ void preferredHeightChanged();
void urlChanged();
- void interactiveChanged();
void progressChanged();
+ void statusChanged(Status);
void titleChanged(const QString&);
void iconChanged();
- void statusChanged();
+ void statusTextChanged();
void zoomFactorChanged();
- void loadStarted(); //### document with \qmlsignal
+ void loadStarted();
void loadFinished();
void loadFailed();
- void singleClick();
- void doubleClick();
+ void doubleClick(int clickX, int clickY);
public Q_SLOTS:
QVariant evaluateJavaScript(const QString&);
@@ -199,10 +198,12 @@ public Q_SLOTS:
private Q_SLOTS:
void expandToWebPage();
void paintPage(const QRect&);
+ void doLoadStarted();
void doLoadProgress(int p);
void doLoadFinished(bool ok);
- void setStatusBarMessage(const QString&);
+ void setStatusText(const QString&);
void windowObjectCleared();
+ void pageUrlChanged();
protected:
QFxWebView(QFxWebViewPrivate &dd, QFxItem *parent);
@@ -216,22 +217,24 @@ protected:
void hoverMoveEvent (QGraphicsSceneHoverEvent * event);
void keyPressEvent(QKeyEvent* event);
void keyReleaseEvent(QKeyEvent* event);
- void timerEvent(QTimerEvent *event);
virtual void geometryChanged(const QRectF &newGeometry,
const QRectF &oldGeometry);
virtual void focusChanged(bool);
virtual bool sceneEvent(QEvent *event);
+ QFxWebView *createWindow(QWebPage::WebWindowType type);
private:
void init();
virtual void componentComplete();
Q_DISABLE_COPY(QFxWebView)
Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxWebView)
+ friend class QFxWebPage;
};
QT_END_NAMESPACE
QML_DECLARE_TYPE(QFxWebView)
+QML_DECLARE_TYPE(QAction)
QT_END_HEADER
diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp
index c535045..02b747f 100644
--- a/src/declarative/util/qmlanimation.cpp
+++ b/src/declarative/util/qmlanimation.cpp
@@ -1168,6 +1168,8 @@ void QmlParentAction::transition(QmlStateActions &actions,
QmlParentActionData *data = new QmlParentActionData;
+ bool explicitMatchFound = false;
+
for (int ii = 0; ii < actions.count(); ++ii) {
Action &action = actions[ii];
@@ -1182,6 +1184,7 @@ void QmlParentAction::transition(QmlStateActions &actions,
myAction.event = pc;
data->pc = pc;
data->actions << myAction;
+ if (d->target) explicitMatchFound = true;
break; //only match one
} else {
action.actionDone = true;
@@ -1190,6 +1193,17 @@ void QmlParentAction::transition(QmlStateActions &actions,
}
}
+ if (!explicitMatchFound && d->pcTarget && d->pcParent) {
+ data->reverse = false;
+ Action myAction;
+ QmlParentChange *pc = new QmlParentChange;
+ pc->setObject(d->pcTarget);
+ pc->setParent(d->pcParent);
+ myAction.event = pc;
+ data->pc = pc;
+ data->actions << myAction;
+ }
+
if (data->actions.count()) {
d->cpa->setAnimAction(data, QAbstractAnimation::DeleteWhenStopped);
} else {