--- a/ginebra2/GWebPage.h Fri May 14 15:40:36 2010 +0300
+++ b/ginebra2/GWebPage.h Wed Jun 23 17:59:43 2010 +0300
@@ -1,21 +1,24 @@
/*
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
-* This component and the accompanying materials are made available
-* under the terms of "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License as published by
+* the Free Software Foundation, version 2.1 of the License.
*
-* Initial Contributors:
-* Nokia Corporation - initial contribution.
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License for more details.
*
-* Contributors:
+* You should have received a copy of the GNU Lesser General Public License
+* along with this program. If not,
+* see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
*
-* Description:
+* Description:
*
*/
-
#ifndef __GINEBRA_GWEBPAGE_H__
#define __GINEBRA_GWEBPAGE_H__
@@ -23,94 +26,104 @@
#include <QWebPage>
#include <QWebFrame>
#include "ChromeWidget.h"
+#include "WebViewEventContext.h"
namespace GVA {
- // ------------------------------
- // Simple wrapper class for QWebPage to allow interception of javascript errors.
- class WebPageWrapper : public QWebPage {
- public:
- WebPageWrapper(QObject *parent, const QString &prefix)
- : QWebPage(parent),
- m_prefix(prefix) {
- qDebug() << "WebPageWrapper::WebPageWrapper";
- }
+// ------------------------------
+// Simple wrapper class for QWebPage to allow interception of javascript errors.
+class WebPageWrapper : public QWebPage {
+public:
+ WebPageWrapper(QObject *parent, const QString &prefix);
+
+ // Called when javascript errors are hit in the chrome page.
+ virtual void javaScriptConsoleMessage(const QString & message, int lineNumber, const QString & sourceID);
+
+ QString m_prefix;
+};
+
+// ------------------------------
- // Called when javascript errors are hit in the chrome page.
- virtual void javaScriptConsoleMessage(const QString & message, int lineNumber, const QString & sourceID) {
- qDebug() << m_prefix << ":";
- qDebug() << (const char*)QString("===\t%2:%3 %4")
- .arg(sourceID)
- .arg(lineNumber)
- .arg(message).toAscii();
- }
- QString m_prefix;
- };
- // ------------------------------
+class GWebPage : public QObject {
+ Q_OBJECT
+public:
+ GWebPage(QWebPage *page) {
+ m_page = page; // take ownership
+ }
+
+ virtual ~GWebPage() {
+ delete m_page;
+ }
- class GWebPage : public QObject {
- Q_OBJECT
- public:
- GWebPage(QWebPage *page) {
- m_page = page;
- }
+ Q_PROPERTY(QString name READ objectName) // JS API
+ Q_PROPERTY(QString title READ getTitle) // JS API
+ QString getTitle() {
+ return m_page->mainFrame()->title();
+ }
- Q_PROPERTY(QString name READ objectName) // JS API
- Q_PROPERTY(QString title READ getTitle) // JS API
- QString getTitle() {
- return m_page->mainFrame()->title();
- }
+ QWebPage *page() { return m_page; }
+ operator QWebPage *() { return m_page; }
- QWebPage *page() { return m_page; }
- operator QWebPage *() { return m_page; }
-
- void dump() {
+ void dump() {
qDebug() << "GWebPage::dump: " << this;
qDebug() << " page=" << (m_page ? m_page : 0);
- }
+ }
+
+signals:
+ /// Triggered by a QContextEvent such as a long-press or right mouse button click.
+ void contextEvent(::WebViewEventContext *context);
- protected:
- QWebPage *m_page;
- };
+protected slots:
+ void onContextEvent(::WebViewEventContext *context) { emit contextEvent(context); }
+
+protected:
+ QWebPage *m_page; // owned
+
+ friend class GWebContentViewWidget;
+};
- // ------------------------------
- /*! \ingroup JavascriptAPI
- * \brief A content view that has full access to the Javascript APIs.
- *
- * Example code to load an HTML file into a super page:
- * \code
- * window.views.WebView.createSuperPage("BookmarkView", true);
- * window.views.WebView.BookmarkView.load("./chrome/BookmarkView.html");
- * \endcode
- */
- class GSuperWebPage : public GWebPage {
- Q_OBJECT
- public:
- GSuperWebPage(WebPageWrapper *page, ChromeWidget *chromeWidget)
- : GWebPage(page),
- m_chromeWidget(chromeWidget)
- {
- if(!m_page) {
- m_page = new WebPageWrapper(this, "Superpage javascript error");
- }
- qDebug() << "GSuperWebPage::GSuperWebPage: page=" << GWebPage::page();
- connect(GWebPage::page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(onJavaScriptWindowObjectCleared()));
- }
- public slots:
- void load(const QString &url) { // JS API
- qDebug() << "GSuperWebPage::load: " << url;
- page()->mainFrame()->load(url);
- }
- private slots:
- void onJavaScriptWindowObjectCleared() {
- qDebug() << "GSuperWebPage::onJavaScriptWindowObjectCleared: " << objectName();
- if(m_chromeWidget)
- m_chromeWidget->exportJSObjectsToPage(m_page);
- }
+// ------------------------------
+/*! \ingroup JavascriptAPI
+* \brief A content view that has full access to the Javascript APIs.
+*
+* Example code to load an HTML file into a super page:
+* \code
+* window.views.WebView.createSuperPage("BookmarkView", true);
+* window.views.WebView.BookmarkView.load("./chrome/BookmarkView.html");
+* \endcode
+*/
+class GSuperWebPage : public GWebPage {
+ Q_OBJECT
+public:
+ GSuperWebPage(WebPageWrapper *page, ChromeWidget *chromeWidget);
+
+public slots:
+ void load(const QString &url);
- private:
- ChromeWidget *m_chromeWidget; // not owned
- };
+signals:
+ /*!
+ * Triggered by the javascript code within the superpage when it wants a context menu to be displayed by
+ * the chrome's javascript.
+ *
+ * The normal chain of events is:
+ * \li User executes a long-press (or RMB click).
+ * \li Qt sends QContextMenuEvent from QWebView.
+ * \li GWebContentViewWidget::contextMenuEvent is called, which passes the event to the superpage
+ * (if one is currently displayed).
+ * \li The superpage emits \c contextEvent().
+ * \li The context event handler in the superpage's javascript determines what was clicked on
+ * and emits \c showContextMenu() from the superpage.
+ * \li Javascript \c showContextMenu signal handler in the chrome is called which then displays the context menu.
+ */
+ void showContextMenu(QVariant obj);
+
+private slots:
+ void onJavaScriptWindowObjectCleared();
+
+private:
+ ChromeWidget *m_chromeWidget; // not owned
+};
+
}
#endif // __GINEBRA_GWEBPAGE_H__