diff -r b0dd75e285d2 -r 0954f5dd2cd0 ginebra2/GWebPage.h --- a/ginebra2/GWebPage.h Fri May 14 15:40:36 2010 +0300 +++ b/ginebra2/GWebPage.h Tue Jun 29 00:46:29 2010 -0400 @@ -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,65 @@ #include #include #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); - } - - protected: - QWebPage *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) - : 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); - } +signals: + /// Triggered by a QContextEvent such as a long-press or right mouse button click. + void contextEvent(::WebViewEventContext *context); +#ifdef BEDROCK_TILED_BACKING_STORE +public slots: +#else +protected slots: +#endif + void onContextEvent(::WebViewEventContext *context) { emit contextEvent(context); } - private: - ChromeWidget *m_chromeWidget; // not owned - }; +protected: + QWebPage *m_page; // owned + + friend class GWebContentViewWidget; +}; + } #endif // __GINEBRA_GWEBPAGE_H__