File: kwebview_p.h

package info (click to toggle)
kde4libs 4%3A4.14.2-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 82,316 kB
  • sloc: cpp: 761,810; xml: 12,344; ansic: 6,295; java: 4,060; perl: 2,938; yacc: 2,507; python: 1,207; sh: 1,179; ruby: 337; lex: 278; makefile: 29
file content (156 lines) | stat: -rw-r--r-- 5,182 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
 * This file is part of the KDE project.
 *
 * Copyright (C) 2007 Trolltech ASA
 * Copyright (C) 2008 Urs Wolfer <uwolfer @ kde.org>
 * Copyright (C) 2008 Laurent Montel <montel@kde.org>
 * Copyright (C) 2008 Michael Howell <mhowell123@gmail.com>
 * Copyright (C) 2009 Dawit Alemayehu <adawit @ kde.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 */

#ifndef KWEBVIEW_P_H
#define KWEBVIEW_P_H

#include <QtCore/QEvent>
#include <QtGui/QClipboard>
#include <QtGui/QApplication>
#include <QtWebKit/QWebFrame>
#include <QtWebKit/QWebElement>

#include <kurl.h>
#include <kurifilter.h>

#include "kwebpage.h"

#define QL1S(x)   QLatin1String(x)

template <class T>
class KWebViewPrivate
{
public:
    KWebViewPrivate(T *parent)
    : q(parent),
      keyboardModifiers(Qt::NoModifier) ,
      pressedButtons(Qt::NoButton)
    {
    }

    bool isExternalContentAllowed()
    {
        KWebPage *webPage = qobject_cast<KWebPage*>(q->page());
        if (webPage) {
            return webPage->isExternalContentAllowed();
        }

        return false;
    }

    void setAllowExternalContent(bool allow)
    {
        KWebPage *webPage = qobject_cast<KWebPage*>(q->page());
        if (webPage) {
            webPage->setAllowExternalContent(allow);
        }
    }

    bool wheelEvent(int delta)
    {
        if (QApplication::keyboardModifiers() & Qt::ControlModifier) {
            const int numDegrees = delta / 8;
            const int numSteps = numDegrees / 15;
            q->setZoomFactor(q->zoomFactor() + numSteps * 0.1);
            return true;
        }

        return false;
    }

    bool mouseReleased(const QPoint &pos)
    {
        hitTest = q->page()->mainFrame()->hitTestContent(pos);
        const QUrl url = hitTest.linkUrl();

        if (!url.isEmpty()) {
            if ((pressedButtons & Qt::MidButton) ||
                ((pressedButtons & Qt::LeftButton) && (keyboardModifiers & Qt::ControlModifier))) {
                emit q->linkMiddleOrCtrlClicked(url);
                return true;
            }

            if ((pressedButtons & Qt::LeftButton) && (keyboardModifiers & Qt::ShiftModifier)) {
                emit q->linkShiftClicked(url);
                return true;
            }
        }

        return false;
    }

    bool handleUrlPasteFromClipboard(QEvent* event)
    {
        QWebPage *page = q->page();
        if ((pressedButtons & Qt::MidButton) && page) {

            // WORKAROUND: Let the page handle the event first so that middle clicking
            // on scroll bars does not cause navigation to a url that might have been
            // copied into the selection clipboard.
            page->event(event);
            if (event->isAccepted())
                return true;

            if (!hitTest.linkUrl().isValid() && !hitTest.isContentEditable() && !page->isModified()) {
                QString subType (QL1S("plain"));
                const QString clipboardText = QApplication::clipboard()->text(subType, QClipboard::Selection);
                if (!clipboardText.isEmpty()) {
                    KUriFilterData data (clipboardText.left(250).trimmed());
                    data.setCheckForExecutables(false); // don't allow executables...
                    if (KUriFilter::self()->filterUri(data, QStringList(QL1S("kshorturifilter")))) {
                        switch (data.uriType()) {
                        case KUriFilterData::LocalFile:
                        case KUriFilterData::LocalDir:
                        case KUriFilterData::NetProtocol:
                            emit q->selectionClipboardUrlPasted(data.uri(), QString());
#ifndef KDE_NO_DEPRECATED
                            emit q->selectionClipboardUrlPasted(data.uri());
#endif
                            return true;
                        default:
                            break;
                        }
                    } else if (KUriFilter::self()->filterSearchUri(data, KUriFilter::NormalTextFilter)) {
                        emit q->selectionClipboardUrlPasted(data.uri(), clipboardText);
#ifndef KDE_NO_DEPRECATED
                        emit q->selectionClipboardUrlPasted(data.uri());
#endif
                        return true;
                    }
                }
            }
        }

        return false;
    }

    T *q;
    Qt::KeyboardModifiers keyboardModifiers;
    Qt::MouseButtons pressedButtons;
    QWebHitTestResult hitTest;
};

#endif  // KWEBVIEW_P_H