diff options
| author | Andrea Diamantini <adjam7@gmail.com> | 2009-05-25 16:47:37 +0200 | 
|---|---|---|
| committer | Andrea Diamantini <adjam7@gmail.com> | 2009-05-25 16:47:37 +0200 | 
| commit | 974058301ed0911bc8bd15a957548ce0771851aa (patch) | |
| tree | 012b05f163a3c1c84d99af97db8edb614bb75394 /src | |
| parent | Fixing CMakelists.txt's (diff) | |
| download | rekonq-974058301ed0911bc8bd15a957548ce0771851aa.tar.xz | |
WebkitKDE porting.
I'm working on a big refactoring of the webview/webpage classes.
This is (obviously) a work in progress.
Perhaps ~50% of the porting..
Diffstat (limited to 'src')
| -rw-r--r-- | src/webpage.cpp | 78 | ||||
| -rw-r--r-- | src/webpage.h | 13 | ||||
| -rw-r--r-- | src/webview.cpp | 134 | ||||
| -rw-r--r-- | src/webview.h | 17 | 
4 files changed, 73 insertions, 169 deletions
diff --git a/src/webpage.cpp b/src/webpage.cpp index 51a02771..664c812b 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -66,18 +66,16 @@  WebPage::WebPage(QObject *parent)          : KWebPage(parent) -        , m_keyboardModifiers(Qt::NoModifier) -        , m_pressedButtons(Qt::NoButton)  { -    setNetworkAccessManager(Application::networkAccessManager()); -      setForwardUnsupportedContent(true); -    connect(this, SIGNAL(unsupportedContent(QNetworkReply *)), this, SLOT(handleUnsupportedContent(QNetworkReply *))); +    setNetworkAccessManager(Application::networkAccessManager());  }  bool WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type)  { + +    // TODO: implement ioslaves protocols      QString scheme = request.url().scheme();      if (scheme == QLatin1String("mailto"))      { @@ -85,7 +83,6 @@ bool WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &r          return false;      } -    WebView *webView;      switch (type)      { @@ -118,23 +115,6 @@ bool WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &r          // user activated the reload action.      case QWebPage::NavigationTypeReload:          kDebug() << "NavigationTypeReload"; - -#if QT_VERSION <= 040500 -        // HACK Ported from Arora -        // A short term hack until QtWebKit can get a reload without cache QAction -        // *FYI* currently type is never NavigationTypeReload -        // See: https://bugs.webkit.org/show_bug.cgi?id=24283 -        if (qApp->keyboardModifiers() & Qt::ShiftModifier) -        { -            kDebug() << "Arora hack"; -            QNetworkRequest newRequest(request); -            newRequest.setAttribute(QNetworkRequest::CacheLoadControlAttribute, -                                    QNetworkRequest::AlwaysNetwork); -            mainFrame()->load(request); -            return false; -        } -#endif -          break;          // should be nothing.. @@ -143,33 +123,6 @@ bool WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &r          break;      } -    if (m_keyboardModifiers & Qt::ControlModifier || m_pressedButtons == Qt::MidButton) -    { -        webView = Application::instance()->newWebView(); -        webView->setFocus(); -        webView->load(request.url()); -        m_keyboardModifiers = Qt::NoModifier; -        m_pressedButtons = Qt::NoButton; -        return false; -    } - -    if (frame == mainFrame()) -    { -        m_loadingUrl = request.url(); -        emit loadingUrl(m_loadingUrl); -    } -    else -    { -        // if frame doesn't exists (perhaps) we are pointing to a blank target.. -        if (!frame) -        { -            webView = Application::instance()->newWebView(); -            webView->setFocus(); -            webView->load(request.url()); -            return false; -        } -    } -      return QWebPage::acceptNavigationRequest(frame, request, type);  } @@ -190,7 +143,7 @@ KWebPage *WebPage::createWindow(QWebPage::WebWindowType type)  } -void WebPage::handleUnsupportedContent(QNetworkReply *reply) +void WebPage::slotHandleUnsupportedContent(QNetworkReply *reply)  {      // create convenience fake api:// protocol for KDE apidox search and Qt docs      if (reply->url().scheme() == "api") @@ -213,17 +166,18 @@ void WebPage::handleUnsupportedContent(QNetworkReply *reply)      if (reply->error() == QNetworkReply::NoError)      { -        // st iframe unwanted download fix -        if (reply->header(QNetworkRequest::ContentTypeHeader).isValid()) -        { -            KUrl srcUrl = reply->url(); -            Application::downloadManager()->newDownload(srcUrl); -        } -        else -        { -             kDebug() << "invalid content type header"; -        } -        return; +        return slotDownloadRequested(reply->request(), reply); +//         // st iframe unwanted download fix +//         if (reply->header(QNetworkRequest::ContentTypeHeader).isValid()) +//         { +//             KUrl srcUrl = reply->url(); +//             Application::downloadManager()->newDownload(srcUrl); +//         } +//         else +//         { +//              kDebug() << "invalid content type header"; +//         } +//         return;      }      // display "not found" page diff --git a/src/webpage.h b/src/webpage.h index cdb1d04f..87fd3549 100644 --- a/src/webpage.h +++ b/src/webpage.h @@ -51,11 +51,8 @@ class WebPage : public KWebPage  {      Q_OBJECT -signals: -    void loadingUrl(const QUrl &url);   // WARNING has to be QUrl!! -  public: -    WebPage(QObject *parent = 0); +    explicit WebPage(QObject *parent = 0);  protected: @@ -65,15 +62,15 @@ protected:      KWebPage *createWindow(QWebPage::WebWindowType type); -private slots: -    void handleUnsupportedContent(QNetworkReply *reply); +protected Q_SLOTS: +    virtual void slotHandleUnsupportedContent(QNetworkReply *reply);  private:      friend class WebView;      // set the webview mousepressedevent -    Qt::KeyboardModifiers m_keyboardModifiers; -    Qt::MouseButtons m_pressedButtons; +//     Qt::KeyboardModifiers m_keyboardModifiers; +//     Qt::MouseButtons m_pressedButtons;      KUrl m_loadingUrl;  }; diff --git a/src/webview.cpp b/src/webview.cpp index 92995a93..16f7b6e5 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -74,9 +74,8 @@ WebView::WebView(QWidget* parent)      connect(page(), SIGNAL(statusBarMessage(const QString&)), this, SLOT(setStatusBarText(const QString&)));      connect(this, SIGNAL(loadProgress(int)), this, SLOT(setProgress(int)));      connect(this, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished())); -    connect(page(), SIGNAL(loadingUrl(const QUrl&)),  this, SIGNAL(urlChanged(const QUrl &))); -    connect(page(), SIGNAL(downloadRequested(const QNetworkRequest &)), this, SLOT(downloadRequested(const QNetworkRequest &))); -    page()->setForwardUnsupportedContent(true); + +    connect(this, SIGNAL(openUrlInNewTab(const KUrl &)), this, SLOT(load(const KUrl &)));  } @@ -132,14 +131,13 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)      addBookmarkAction->setData(QVariant());      KMenu menu(this); -    QAction *a;      // link actions      bool linkIsEmpty = result.linkUrl().isEmpty();      if (!linkIsEmpty)      { -        a = new KAction(KIcon("tab-new"), i18n("Open Link in New &Tab"), this); -        connect(a, SIGNAL(triggered()), this, SLOT(openLinkInNewTab())); +        QAction *a = pageAction(QWebPage::OpenLinkInNewWindow); +        a->setText(i18n("Open Link in New &Tab"));          menu.addAction(a);      }      else @@ -152,10 +150,7 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)      // Developer Extras actions      if (page()->settings()->testAttribute(QWebSettings::DeveloperExtrasEnabled))      { -        a = pageAction(QWebPage::InspectElement); -        a->setIcon(KIcon("tools-report-bug")); -        a->setText(i18n("&Inspect Element")); -        menu.addAction(a); +        menu.addAction(pageAction(QWebPage::InspectElement));          menu.addSeparator();      } @@ -164,28 +159,19 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)      if (result.isContentSelected() && result.isContentEditable())      { -        a = pageAction(QWebPage::Cut); -        a->setIcon(KIcon("edit-cut")); -        a->setText(i18n("Cu&t")); -        menu.addAction(a); +        menu.addAction(pageAction(QWebPage::Cut));          b = true;      }      if (result.isContentSelected())      { -        a = pageAction(QWebPage::Copy); -        a->setIcon(KIcon("edit-copy")); -        a->setText(i18n("&Copy")); -        menu.addAction(a); +        menu.addAction(pageAction(QWebPage::Copy));          b = true;      }      if (result.isContentEditable())      { -        a = pageAction(QWebPage::Paste); -        a->setIcon(KIcon("edit-paste")); -        a->setText(i18n("&Paste")); -        menu.addAction(a); +        menu.addAction(pageAction(QWebPage::Paste));          b = true;      } @@ -197,31 +183,15 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)      // save/copy link actions      if (!linkIsEmpty)      { -        a = pageAction(QWebPage::DownloadLinkToDisk); -        a->setIcon(KIcon("folder-downloads")); -        a->setText(i18n("&Save Link As...")); -        menu.addAction(a); - -        a = pageAction(QWebPage::CopyLinkToClipboard); -        a->setIcon(KIcon("insert-link")); -        a->setText(i18n("&Copy Link Location")); -        menu.addAction(a); - +        menu.addAction(pageAction(QWebPage::DownloadLinkToDisk)); +        menu.addAction(pageAction(QWebPage::CopyLinkToClipboard));          menu.addSeparator();          if (!result.pixmap().isNull())          {              // TODO Add "View Image" && remove copy_this_image action -            a = pageAction(QWebPage::DownloadImageToDisk); -            a->setIcon(KIcon("folder-image")); -            a->setText(i18n("&Save Image As...")); -            menu.addAction(a); - -            a = pageAction(QWebPage::CopyImageToClipboard); -            a->setIcon(KIcon("insert-image")); -            a->setText(i18n("&Copy This Image")); -            menu.addAction(a); - +            menu.addAction(pageAction(QWebPage::DownloadImageToDisk)); +            menu.addAction(pageAction(QWebPage::CopyImageToClipboard));              menu.addSeparator();          }      } @@ -248,24 +218,10 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)  } -void WebView::wheelEvent(QWheelEvent *event) -{ -    if (QApplication::keyboardModifiers() & Qt::ControlModifier) -    { -        int numDegrees = event->delta() / 8; -        int numSteps = numDegrees / 15; -        setTextSizeMultiplier(textSizeMultiplier() + numSteps * 0.1); -        event->accept(); -        return; -    } -    QWebView::wheelEvent(event); -} - - -void WebView::openLinkInNewTab() -{ -    pageAction(QWebPage::OpenLinkInNewWindow)->trigger(); -} +// void WebView::openLinkInNewTab() +// { +//     pageAction(QWebPage::OpenLinkInNewWindow)->trigger(); +// }  void WebView::loadFinished() @@ -279,35 +235,35 @@ void WebView::loadFinished()  } -void WebView::mousePressEvent(QMouseEvent *event) -{ -    m_page->m_pressedButtons = event->buttons(); -    m_page->m_keyboardModifiers = event->modifiers(); -    QWebView::mousePressEvent(event); -} - - -void WebView::mouseReleaseEvent(QMouseEvent *event) -{ -    QWebView::mouseReleaseEvent(event); -    if (!event->isAccepted() && (m_page->m_pressedButtons & Qt::MidButton)) -    { -        KUrl url(QApplication::clipboard()->text(QClipboard::Selection)); -        if (!url.isEmpty() && url.isValid() && !url.scheme().isEmpty()) -        { -            setUrl(url); -        } -    } -} - - -void WebView::downloadRequested(const QNetworkRequest &request) -{ -    KUrl srcUrl = request.url(); -    QString path = ReKonfig::downloadDir() + QString("/") + srcUrl.fileName(); -    KUrl destUrl = KUrl(path); -    Application::downloadManager()->newDownload(srcUrl); -} +// void WebView::mousePressEvent(QMouseEvent *event) +// { +//     m_page->m_pressedButtons = event->buttons(); +//     m_page->m_keyboardModifiers = event->modifiers(); +//     QWebView::mousePressEvent(event); +// } +//  +//  +// void WebView::mouseReleaseEvent(QMouseEvent *event) +// { +//     QWebView::mouseReleaseEvent(event); +//     if (!event->isAccepted() && (m_page->m_pressedButtons & Qt::MidButton)) +//     { +//         KUrl url(QApplication::clipboard()->text(QClipboard::Selection)); +//         if (!url.isEmpty() && url.isValid() && !url.scheme().isEmpty()) +//         { +//             setUrl(url); +//         } +//     } +// } + + +// void WebView::downloadRequested(const QNetworkRequest &request) +// { +//     KUrl srcUrl = request.url(); +//     QString path = ReKonfig::downloadDir() + QString("/") + srcUrl.fileName(); +//     KUrl destUrl = KUrl(path); +//     Application::downloadManager()->newDownload(srcUrl); +// }  void WebView::keyPressEvent(QKeyEvent *event) diff --git a/src/webview.h b/src/webview.h index 19fd9517..ab69f799 100644 --- a/src/webview.h +++ b/src/webview.h @@ -32,6 +32,7 @@  // Qt Includes  #include <QWebPage> +#include <QWebView>  // Forward Declarations  class MainWindow; @@ -45,10 +46,6 @@ class QMouseEvent;  class QNetworkProxy;  class QNetworkReply;  class QSslError; -class WebPage; - -// Qt Includes -#include <QWebView>  class WebView : public KWebView @@ -56,7 +53,7 @@ class WebView : public KWebView      Q_OBJECT  public: -    WebView(QWidget *parent = 0); +    explicit WebView(QWidget *parent = 0);      KUrl url() const;      QString lastStatusBarText() const; @@ -71,10 +68,9 @@ signals:      void shiftCtrlTabPressed();  protected: -    void mousePressEvent(QMouseEvent *event); -    void mouseReleaseEvent(QMouseEvent *event); +//     void mousePressEvent(QMouseEvent *event); +//     void mouseReleaseEvent(QMouseEvent *event);      void contextMenuEvent(QContextMenuEvent *event); -    void wheelEvent(QWheelEvent *event);      /**      * Filters (SHIFT + ) CTRL + TAB events and emit (shift)ctrlTabPressed() @@ -89,8 +85,9 @@ private slots:      void setProgress(int progress);      void loadFinished();      void setStatusBarText(const QString &string); -    void downloadRequested(const QNetworkRequest &request); -    void openLinkInNewTab(); + +//     void downloadRequested(const QNetworkRequest &request); +//     void open   LinkInNewTab();  private:      WebPage *m_page;  | 
