KDEWebKit
kwebview_p.h
Go to the documentation of this file.
00001 /* 00002 * This file is part of the KDE project. 00003 * 00004 * Copyright (C) 2007 Trolltech ASA 00005 * Copyright (C) 2008 Urs Wolfer <uwolfer @ kde.org> 00006 * Copyright (C) 2008 Laurent Montel <montel@kde.org> 00007 * Copyright (C) 2008 Michael Howell <mhowell123@gmail.com> 00008 * Copyright (C) 2009 Dawit Alemayehu <adawit @ kde.org> 00009 * 00010 * This library is free software; you can redistribute it and/or 00011 * modify it under the terms of the GNU Library General Public 00012 * License as published by the Free Software Foundation; either 00013 * version 2 of the License, or (at your option) any later version. 00014 * 00015 * This library is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 * Library General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU Library General Public License 00021 * along with this library; see the file COPYING.LIB. If not, write to 00022 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00023 * Boston, MA 02110-1301, USA. 00024 * 00025 */ 00026 00027 #ifndef KWEBVIEW_P_H 00028 #define KWEBVIEW_P_H 00029 00030 #include <QtCore/QEvent> 00031 #include <QtGui/QClipboard> 00032 #include <QtGui/QApplication> 00033 #include <QtWebKit/QWebFrame> 00034 #include <QtWebKit/QWebElement> 00035 00036 #include <kurl.h> 00037 #include <kurifilter.h> 00038 00039 #include "kwebpage.h" 00040 00041 #define QL1S(x) QLatin1String(x) 00042 00043 template <class T> 00044 class KWebViewPrivate 00045 { 00046 public: 00047 KWebViewPrivate(T *parent) 00048 : q(parent), 00049 keyboardModifiers(Qt::NoModifier) , 00050 pressedButtons(Qt::NoButton) 00051 { 00052 } 00053 00054 bool isExternalContentAllowed() 00055 { 00056 KWebPage *webPage = qobject_cast<KWebPage*>(q->page()); 00057 if (webPage) { 00058 return webPage->isExternalContentAllowed(); 00059 } 00060 00061 return false; 00062 } 00063 00064 void setAllowExternalContent(bool allow) 00065 { 00066 KWebPage *webPage = qobject_cast<KWebPage*>(q->page()); 00067 if (webPage) { 00068 webPage->setAllowExternalContent(allow); 00069 } 00070 } 00071 00072 bool wheelEvent(int delta) 00073 { 00074 if (QApplication::keyboardModifiers() & Qt::ControlModifier) { 00075 const int numDegrees = delta / 8; 00076 const int numSteps = numDegrees / 15; 00077 q->setZoomFactor(q->zoomFactor() + numSteps * 0.1); 00078 return true; 00079 } 00080 00081 return false; 00082 } 00083 00084 bool mouseReleased(const QPoint &pos) 00085 { 00086 hitTest = q->page()->mainFrame()->hitTestContent(pos); 00087 const QUrl url = hitTest.linkUrl(); 00088 00089 if (!url.isEmpty()) { 00090 if ((pressedButtons & Qt::MidButton) || 00091 ((pressedButtons & Qt::LeftButton) && (keyboardModifiers & Qt::ControlModifier))) { 00092 emit q->linkMiddleOrCtrlClicked(url); 00093 return true; 00094 } 00095 00096 if ((pressedButtons & Qt::LeftButton) && (keyboardModifiers & Qt::ShiftModifier)) { 00097 emit q->linkShiftClicked(url); 00098 return true; 00099 } 00100 } 00101 00102 return false; 00103 } 00104 00105 bool handleUrlPasteFromClipboard(QEvent* event) 00106 { 00107 QWebPage *page = q->page(); 00108 if ((pressedButtons & Qt::MidButton) && page) { 00109 00110 // WORKAROUND: Let the page handle the event first so that middle clicking 00111 // on scroll bars does not cause navigation to a url that might have been 00112 // copied into the selection clipboard. 00113 page->event(event); 00114 if (event->isAccepted()) 00115 return true; 00116 00117 if (!hitTest.linkUrl().isValid() && !hitTest.isContentEditable() && !page->isModified()) { 00118 QString subType (QL1S("plain")); 00119 const QString clipboardText = QApplication::clipboard()->text(subType, QClipboard::Selection); 00120 if (!clipboardText.isEmpty()) { 00121 KUriFilterData data (clipboardText.left(250).trimmed()); 00122 data.setCheckForExecutables(false); // don't allow executables... 00123 if (KUriFilter::self()->filterUri(data, QStringList(QL1S("kshorturifilter")))) { 00124 switch (data.uriType()) { 00125 case KUriFilterData::LocalFile: 00126 case KUriFilterData::LocalDir: 00127 case KUriFilterData::NetProtocol: 00128 emit q->selectionClipboardUrlPasted(data.uri(), QString()); 00129 #ifndef KDE_NO_DEPRECATED 00130 emit q->selectionClipboardUrlPasted(data.uri()); 00131 #endif 00132 return true; 00133 default: 00134 break; 00135 } 00136 } else if (KUriFilter::self()->filterSearchUri(data, KUriFilter::NormalTextFilter)) { 00137 emit q->selectionClipboardUrlPasted(data.uri(), clipboardText); 00138 #ifndef KDE_NO_DEPRECATED 00139 emit q->selectionClipboardUrlPasted(data.uri()); 00140 #endif 00141 return true; 00142 } 00143 } 00144 } 00145 } 00146 00147 return false; 00148 } 00149 00150 T *q; 00151 Qt::KeyboardModifiers keyboardModifiers; 00152 Qt::MouseButtons pressedButtons; 00153 QWebHitTestResult hitTest; 00154 }; 00155 00156 #endif // KWEBVIEW_P_H
KDE 4.7 API Reference