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

KDEWebKit

  • sources
  • kde-4.14
  • kdelibs
  • kdewebkit
kwebview_p.h
Go to the documentation of this file.
1 /*
2  * This file is part of the KDE project.
3  *
4  * Copyright (C) 2007 Trolltech ASA
5  * Copyright (C) 2008 Urs Wolfer <uwolfer @ kde.org>
6  * Copyright (C) 2008 Laurent Montel <montel@kde.org>
7  * Copyright (C) 2008 Michael Howell <mhowell123@gmail.com>
8  * Copyright (C) 2009 Dawit Alemayehu <adawit @ kde.org>
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public License
21  * along with this library; see the file COPYING.LIB. If not, write to
22  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23  * Boston, MA 02110-1301, USA.
24  *
25  */
26 
27 #ifndef KWEBVIEW_P_H
28 #define KWEBVIEW_P_H
29 
30 #include <QtCore/QEvent>
31 #include <QtGui/QClipboard>
32 #include <QtGui/QApplication>
33 #include <QtWebKit/QWebFrame>
34 #include <QtWebKit/QWebElement>
35 
36 #include <kurl.h>
37 #include <kurifilter.h>
38 
39 #include "kwebpage.h"
40 
41 #define QL1S(x) QLatin1String(x)
42 
43 template <class T>
44 class KWebViewPrivate
45 {
46 public:
47  KWebViewPrivate(T *parent)
48  : q(parent),
49  keyboardModifiers(Qt::NoModifier) ,
50  pressedButtons(Qt::NoButton)
51  {
52  }
53 
54  bool isExternalContentAllowed()
55  {
56  KWebPage *webPage = qobject_cast<KWebPage*>(q->page());
57  if (webPage) {
58  return webPage->isExternalContentAllowed();
59  }
60 
61  return false;
62  }
63 
64  void setAllowExternalContent(bool allow)
65  {
66  KWebPage *webPage = qobject_cast<KWebPage*>(q->page());
67  if (webPage) {
68  webPage->setAllowExternalContent(allow);
69  }
70  }
71 
72  bool wheelEvent(int delta)
73  {
74  if (QApplication::keyboardModifiers() & Qt::ControlModifier) {
75  const int numDegrees = delta / 8;
76  const int numSteps = numDegrees / 15;
77  q->setZoomFactor(q->zoomFactor() + numSteps * 0.1);
78  return true;
79  }
80 
81  return false;
82  }
83 
84  bool mouseReleased(const QPoint &pos)
85  {
86  hitTest = q->page()->mainFrame()->hitTestContent(pos);
87  const QUrl url = hitTest.linkUrl();
88 
89  if (!url.isEmpty()) {
90  if ((pressedButtons & Qt::MidButton) ||
91  ((pressedButtons & Qt::LeftButton) && (keyboardModifiers & Qt::ControlModifier))) {
92  emit q->linkMiddleOrCtrlClicked(url);
93  return true;
94  }
95 
96  if ((pressedButtons & Qt::LeftButton) && (keyboardModifiers & Qt::ShiftModifier)) {
97  emit q->linkShiftClicked(url);
98  return true;
99  }
100  }
101 
102  return false;
103  }
104 
105  bool handleUrlPasteFromClipboard(QEvent* event)
106  {
107  QWebPage *page = q->page();
108  if ((pressedButtons & Qt::MidButton) && page) {
109 
110  // WORKAROUND: Let the page handle the event first so that middle clicking
111  // on scroll bars does not cause navigation to a url that might have been
112  // copied into the selection clipboard.
113  page->event(event);
114  if (event->isAccepted())
115  return true;
116 
117  if (!hitTest.linkUrl().isValid() && !hitTest.isContentEditable() && !page->isModified()) {
118  QString subType (QL1S("plain"));
119  const QString clipboardText = QApplication::clipboard()->text(subType, QClipboard::Selection);
120  if (!clipboardText.isEmpty()) {
121  KUriFilterData data (clipboardText.left(250).trimmed());
122  data.setCheckForExecutables(false); // don't allow executables...
123  if (KUriFilter::self()->filterUri(data, QStringList(QL1S("kshorturifilter")))) {
124  switch (data.uriType()) {
125  case KUriFilterData::LocalFile:
126  case KUriFilterData::LocalDir:
127  case KUriFilterData::NetProtocol:
128  emit q->selectionClipboardUrlPasted(data.uri(), QString());
129 #ifndef KDE_NO_DEPRECATED
130  emit q->selectionClipboardUrlPasted(data.uri());
131 #endif
132  return true;
133  default:
134  break;
135  }
136  } else if (KUriFilter::self()->filterSearchUri(data, KUriFilter::NormalTextFilter)) {
137  emit q->selectionClipboardUrlPasted(data.uri(), clipboardText);
138 #ifndef KDE_NO_DEPRECATED
139  emit q->selectionClipboardUrlPasted(data.uri());
140 #endif
141  return true;
142  }
143  }
144  }
145  }
146 
147  return false;
148  }
149 
150  T *q;
151  Qt::KeyboardModifiers keyboardModifiers;
152  Qt::MouseButtons pressedButtons;
153  QWebHitTestResult hitTest;
154 };
155 
156 #endif // KWEBVIEW_P_H
QEvent
QWebPage::isModified
bool isModified() const
kwebpage.h
QApplication::keyboardModifiers
Qt::KeyboardModifiers keyboardModifiers()
KWebViewPrivate::KWebViewPrivate
KWebViewPrivate(T *parent)
Definition: kwebview_p.h:47
kurl.h
T
#define T
KWebViewPrivate::mouseReleased
bool mouseReleased(const QPoint &pos)
Definition: kwebview_p.h:84
KWebViewPrivate::setAllowExternalContent
void setAllowExternalContent(bool allow)
Definition: kwebview_p.h:64
QWebHitTestResult
KWebViewPrivate::handleUrlPasteFromClipboard
bool handleUrlPasteFromClipboard(QEvent *event)
Definition: kwebview_p.h:105
QPoint
QUrl::isEmpty
bool isEmpty() const
kurifilter.h
QWebPage::event
virtual bool event(QEvent *ev)
KWebViewPrivate::q
T * q
Definition: kwebview_p.h:150
KWebViewPrivate
Definition: kgraphicswebview.h:34
KWebViewPrivate::hitTest
QWebHitTestResult hitTest
Definition: kwebview_p.h:153
QEvent::isAccepted
bool isAccepted() const
KWebPage::isExternalContentAllowed
bool isExternalContentAllowed() const
Whether access to remote content is permitted.
Definition: kwebpage.cpp:290
QApplication::clipboard
QClipboard * clipboard()
QWebHitTestResult::isContentEditable
bool isContentEditable() const
QString::isEmpty
bool isEmpty() const
QString::trimmed
QString trimmed() const
QWebPage
QString
QWebHitTestResult::linkUrl
QUrl linkUrl() const
QStringList
KUriFilterData
KUriFilter::self
static KUriFilter * self()
QUrl
KWebPage::setAllowExternalContent
void setAllowExternalContent(bool allow)
Set whether to allow remote content.
Definition: kwebpage.cpp:303
KUriFilter::NormalTextFilter
QClipboard::text
QString text(Mode mode) const
QUrl::isValid
bool isValid() const
Qt::MouseButtons
typedef MouseButtons
KWebViewPrivate::isExternalContentAllowed
bool isExternalContentAllowed()
Definition: kwebview_p.h:54
KWebViewPrivate::pressedButtons
Qt::MouseButtons pressedButtons
Definition: kwebview_p.h:152
KUriFilterData::LocalFile
KWebPage
An enhanced QWebPage that provides integration into the KDE environment.
Definition: kwebpage.h:75
KUriFilterData::NetProtocol
QString::left
QString left(int n) const
KWebViewPrivate::keyboardModifiers
Qt::KeyboardModifiers keyboardModifiers
Definition: kwebview_p.h:151
KWebViewPrivate::wheelEvent
bool wheelEvent(int delta)
Definition: kwebview_p.h:72
KUriFilter::filterSearchUri
bool filterSearchUri(KUriFilterData &data)
QL1S
#define QL1S(x)
Definition: kwebview_p.h:41
KUriFilterData::LocalDir
KUriFilterData::setCheckForExecutables
void setCheckForExecutables(bool check)
Qt::KeyboardModifiers
typedef KeyboardModifiers
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:26:06 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEWebKit

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • 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

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal