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

KDEWebKit

  • 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
43template <class T>
44class KWebViewPrivate
45{
46public:
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
KUriFilterData
KUriFilterData::uri
KUrl uri() const
KUriFilterData::NetProtocol
NetProtocol
KUriFilterData::LocalFile
LocalFile
KUriFilterData::LocalDir
LocalDir
KUriFilterData::uriType
UriTypes uriType() const
KUriFilterData::setCheckForExecutables
void setCheckForExecutables(bool check)
KUriFilter::NormalTextFilter
NormalTextFilter
KUriFilter::self
static KUriFilter * self()
KWebPage
An enhanced QWebPage that provides integration into the KDE environment.
Definition: kwebpage.h:76
KWebPage::setAllowExternalContent
void setAllowExternalContent(bool allow)
Set whether to allow remote content.
Definition: kwebpage.cpp:303
KWebPage::isExternalContentAllowed
bool isExternalContentAllowed() const
Whether access to remote content is permitted.
Definition: kwebpage.cpp:290
KWebViewPrivate
Definition: kwebview_p.h:45
KWebViewPrivate::mouseReleased
bool mouseReleased(const QPoint &pos)
Definition: kwebview_p.h:84
KWebViewPrivate::wheelEvent
bool wheelEvent(int delta)
Definition: kwebview_p.h:72
KWebViewPrivate::q
T * q
Definition: kwebview_p.h:150
KWebViewPrivate::isExternalContentAllowed
bool isExternalContentAllowed()
Definition: kwebview_p.h:54
KWebViewPrivate::KWebViewPrivate
KWebViewPrivate(T *parent)
Definition: kwebview_p.h:47
KWebViewPrivate::keyboardModifiers
Qt::KeyboardModifiers keyboardModifiers
Definition: kwebview_p.h:151
KWebViewPrivate::handleUrlPasteFromClipboard
bool handleUrlPasteFromClipboard(QEvent *event)
Definition: kwebview_p.h:105
KWebViewPrivate::pressedButtons
Qt::MouseButtons pressedButtons
Definition: kwebview_p.h:152
KWebViewPrivate::hitTest
QWebHitTestResult hitTest
Definition: kwebview_p.h:153
KWebViewPrivate::setAllowExternalContent
void setAllowExternalContent(bool allow)
Definition: kwebview_p.h:64
QUrl
QWebHitTestResult
QWebPage
T
#define T
kurifilter.h
kurl.h
kwebpage.h
QL1S
#define QL1S(x)
Definition: kwebview_p.h:41
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 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
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