• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

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 #define QL1S(x)   QLatin1String(x)
00040 
00041 template <class T>
00042 class KWebViewPrivate
00043 {
00044 public:
00045     KWebViewPrivate(T *parent)
00046     : q(parent),
00047       keyboardModifiers(Qt::NoModifier) ,
00048       pressedButtons(Qt::NoButton)
00049     {
00050     }
00051 
00052     bool isExternalContentAllowed()
00053     {
00054         KWebPage *webPage = qobject_cast<KWebPage*>(q->page());
00055         if (webPage) {
00056             return webPage->isExternalContentAllowed();
00057         }
00058 
00059         return false;
00060     }
00061 
00062     void setAllowExternalContent(bool allow)
00063     {
00064         KWebPage *webPage = qobject_cast<KWebPage*>(q->page());
00065         if (webPage) {
00066             webPage->setAllowExternalContent(allow);
00067         }
00068     }
00069 
00070     bool wheelEvent(int delta)
00071     {
00072         if (QApplication::keyboardModifiers() & Qt::ControlModifier) {
00073             const int numDegrees = delta / 8;
00074             const int numSteps = numDegrees / 15;
00075             q->setZoomFactor(q->zoomFactor() + numSteps * 0.1);
00076             return true;
00077         }
00078 
00079         return false;
00080     }
00081 
00082     bool mouseReleased(const QPoint &pos)
00083     {
00084         hitTest = q->page()->mainFrame()->hitTestContent(pos);
00085         const QUrl url = hitTest.linkUrl();
00086 
00087         if (!url.isEmpty()) {
00088             if ((pressedButtons & Qt::MidButton) ||
00089                 ((pressedButtons & Qt::LeftButton) && (keyboardModifiers & Qt::ControlModifier))) {
00090                 emit q->linkMiddleOrCtrlClicked(url);
00091                 return true;
00092             }
00093 
00094             if ((pressedButtons & Qt::LeftButton) && (keyboardModifiers & Qt::ShiftModifier)) {
00095                 emit q->linkShiftClicked(url);
00096                 return true;
00097             }
00098         }
00099 
00100         return false;
00101     }
00102 
00103     bool handleUrlPasteFromClipboard(QEvent* event)
00104     {
00105         QWebPage *page = q->page();
00106         if ((pressedButtons & Qt::MidButton) && page) {
00107 
00108             // WORKAROUND: Let the page handle the event first so that middle clicking
00109             // on scroll bars does not cause navigation to a url that might have been
00110             // copied into the selection clipboard.
00111             page->event(event);
00112             if (event->isAccepted())
00113                 return true;
00114 
00115             if (!hitTest.linkUrl().isValid() && !hitTest.isContentEditable() && !page->isModified()) {
00116                 QString subType (QLatin1String("plain"));
00117                 const QString clipboardText = QApplication::clipboard()->text(subType, QClipboard::Selection);
00118                 if (!clipboardText.isEmpty()) {
00119                     KUriFilterData data (clipboardText.left(250).trimmed());
00120                     data.setCheckForExecutables(false); // don't allow executables...
00121                     if (KUriFilter::self()->filterUri(data, QStringList(QL1S("kshorturifilter")))) {
00122                         switch (data.uriType()) {
00123                         case KUriFilterData::LocalFile:
00124                         case KUriFilterData::LocalDir:
00125                         case KUriFilterData::NetProtocol:
00126                             emit q->selectionClipboardUrlPasted(data.uri(), QString());
00127 #ifndef KDE_NO_DEPRECATED
00128                             emit q->selectionClipboardUrlPasted(data.uri());
00129 #endif
00130                             return true;
00131                         default:
00132                             break;
00133                         }
00134                     } else if (KUriFilter::self()->filterUri(data, QStringList(QL1S("kuriikwsfilter")))) {
00135                         emit q->selectionClipboardUrlPasted(data.uri(), clipboardText);
00136 #ifndef KDE_NO_DEPRECATED
00137                         emit q->selectionClipboardUrlPasted(data.uri());
00138 #endif
00139                         return true;
00140                     }
00141                 }
00142             }
00143         }
00144 
00145         return false;
00146     }
00147 
00148     T *q;
00149     Qt::KeyboardModifiers keyboardModifiers;
00150     Qt::MouseButtons pressedButtons;
00151     QWebHitTestResult hitTest;
00152 };
00153 
00154 #endif  // KWEBVIEW_P_H

KDEWebKit

Skip menu "KDEWebKit"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal