File indexing completed on 2024-03-24 15:32:24

0001 /* This file is part of the KDE project
0002  *
0003  * Copyright (C) 2000-2003 Simon Hausmann <hausmann@kde.org>
0004  *               2001-2003 George Staikos <staikos@kde.org>
0005  *               2001-2003 Laurent Montel <montel@kde.org>
0006  *               2001-2003 Dirk Mueller <mueller@kde.org>
0007  *               2001-2003 Waldo Bastian <bastian@kde.org>
0008  *               2001-2003 David Faure <faure@kde.org>
0009  *               2001-2003 Daniel Naber <dnaber@kde.org>
0010  *
0011  * This library is free software; you can redistribute it and/or
0012  * modify it under the terms of the GNU Library General Public
0013  * License as published by the Free Software Foundation; either
0014  * version 2 of the License, or (at your option) any later version.
0015  *
0016  * This library is distributed in the hope that it will be useful,
0017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0019  * Library General Public License for more details.
0020  *
0021  * You should have received a copy of the GNU Library General Public License
0022  * along with this library; see the file COPYING.LIB.  If not, write to
0023  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0024  * Boston, MA 02110-1301, USA.
0025  */
0026 
0027 #ifndef __khtml_ext_h__
0028 #define __khtml_ext_h__
0029 
0030 #include "khtml_part.h"
0031 
0032 #include <QPointer>
0033 
0034 #include <kselectaction.h>
0035 #include <kparts/textextension.h>
0036 #include <kparts/htmlextension.h>
0037 #include <kparts/selectorinterface.h>
0038 #include <kparts/htmlsettingsinterface.h>
0039 #include <kio/global.h>
0040 
0041 /**
0042  * This is the BrowserExtension for a KHTMLPart document. Please see the KParts documentation for
0043  * more information about the BrowserExtension.
0044  */
0045 class KHTMLPartBrowserExtension : public KParts::BrowserExtension
0046 {
0047     Q_OBJECT
0048     friend class KHTMLPart;
0049     friend class KHTMLView;
0050 public:
0051     KHTMLPartBrowserExtension(KHTMLPart *parent);
0052 
0053     int xOffset() override;
0054     int yOffset() override;
0055 
0056     void saveState(QDataStream &stream) override;
0057     void restoreState(QDataStream &stream) override;
0058 
0059     // internal
0060     void editableWidgetFocused(QWidget *widget);
0061     void editableWidgetBlurred(QWidget *widget);
0062 
0063     void setExtensionProxy(KParts::BrowserExtension *proxyExtension);
0064 
0065 public Q_SLOTS:
0066     void cut();
0067     void copy();
0068     void paste();
0069     void searchProvider();
0070     void reparseConfiguration();
0071     void print();
0072     void disableScrolling();
0073 
0074     // internal . updates the state of the cut/copt/paste action based
0075     // on whether data is available in the clipboard
0076     void updateEditActions();
0077 
0078 private Q_SLOTS:
0079     // connected to a frame's browserextensions enableAction signal
0080     void extensionProxyActionEnabled(const char *action, bool enable);
0081     void extensionProxyEditableWidgetFocused();
0082     void extensionProxyEditableWidgetBlurred();
0083 
0084 Q_SIGNALS:
0085     void editableWidgetFocused();
0086     void editableWidgetBlurred();
0087 private:
0088     void callExtensionProxyMethod(const char *method);
0089 
0090     KHTMLPart *m_part;
0091     QPointer<QWidget> m_editableFormWidget;
0092     QPointer<KParts::BrowserExtension> m_extensionProxy;
0093     bool m_connectedToClipboard;
0094 };
0095 
0096 class KHTMLPartBrowserHostExtension : public KParts::BrowserHostExtension
0097 {
0098 public:
0099     KHTMLPartBrowserHostExtension(KHTMLPart *part);
0100     virtual ~KHTMLPartBrowserHostExtension();
0101 
0102     QStringList frameNames() const override;
0103 
0104     const QList<KParts::ReadOnlyPart *> frames() const override;
0105 
0106     BrowserHostExtension *findFrameParent(KParts::ReadOnlyPart *callingPart, const QString &frame) override;
0107 
0108     bool openUrlInFrame(const QUrl &url, const KParts::OpenUrlArguments &arguments, const KParts::BrowserArguments &browserArguments) override;
0109 
0110 private:
0111     KHTMLPart *m_part;
0112 };
0113 
0114 /**
0115  * @internal
0116  * INTERNAL class. *NOT* part of the public API.
0117  */
0118 class KHTMLPopupGUIClient : public QObject
0119 {
0120     Q_OBJECT
0121 public:
0122     KHTMLPopupGUIClient(KHTMLPart *khtml, const QUrl &url);
0123     virtual ~KHTMLPopupGUIClient();
0124 
0125     KParts::BrowserExtension::ActionGroupMap actionGroups() const;
0126 
0127     static void saveURL(QWidget *parent, const QString &caption, const QUrl &url,
0128                         const QMap<QString, QString> &metaData = KIO::MetaData(),
0129                         const QString &filter = QString(), long cacheId = 0,
0130                         const QString &suggestedFilename = QString());
0131 
0132     static void saveURL(QWidget *parent, const QUrl &url, const QUrl &destination,
0133                         const QMap<QString, QString> &metaData = KIO::MetaData(),
0134                         long cacheId = 0);
0135 
0136     static QString selectedTextAsOneLine(KHTMLPart *part);
0137 
0138 private Q_SLOTS:
0139     void slotSaveLinkAs();
0140     void slotSaveImageAs();
0141     void slotCopyLinkLocation();
0142     void slotSendImage();
0143     void slotStopAnimations();
0144     void slotCopyImageLocation();
0145     void slotCopyImage();
0146     void slotViewImage();
0147     void slotReloadFrame();
0148     void slotFrameInWindow();
0149     void slotFrameInTop();
0150     void slotFrameInTab();
0151     void slotBlockImage();
0152     void slotBlockHost();
0153     void slotBlockIFrame();
0154     void openSelection();
0155 
0156 private:
0157     void addSearchActions(QList<QAction *> &editActions);
0158 
0159     class KHTMLPopupGUIClientPrivate;
0160     KHTMLPopupGUIClientPrivate *const d;
0161 };
0162 
0163 class KHTMLZoomFactorAction : public KSelectAction
0164 {
0165     Q_OBJECT
0166 public:
0167     KHTMLZoomFactorAction(KHTMLPart *part, bool direction, const QString &iconName, const QString &text, QObject *parent);
0168     virtual ~KHTMLZoomFactorAction();
0169 
0170 protected Q_SLOTS:
0171     void slotTriggered(QAction *action);
0172 private:
0173     void init(KHTMLPart *part, bool direction);
0174 private:
0175     bool m_direction;
0176     KHTMLPart *m_part;
0177 };
0178 
0179 /**
0180  * @internal
0181  * Implements the TextExtension interface
0182  */
0183 class KHTMLTextExtension : public KParts::TextExtension
0184 {
0185     Q_OBJECT
0186 public:
0187     KHTMLTextExtension(KHTMLPart *part);
0188 
0189     bool hasSelection() const override;
0190     QString selectedText(Format format) const override;
0191     QString completeText(Format format) const override;
0192 
0193     KHTMLPart *part() const;
0194 };
0195 
0196 /**
0197  * @internal
0198  * Implements the HtmlExtension interface
0199  */
0200 class KHTMLHtmlExtension : public KParts::HtmlExtension,
0201     public KParts::SelectorInterface,
0202     public KParts::HtmlSettingsInterface
0203 {
0204     Q_OBJECT
0205     Q_INTERFACES(KParts::SelectorInterface)
0206     Q_INTERFACES(KParts::HtmlSettingsInterface)
0207 
0208 public:
0209     KHTMLHtmlExtension(KHTMLPart *part);
0210 
0211     // HtmlExtension
0212     QUrl baseUrl() const override;
0213     bool hasSelection() const override;
0214 
0215     // SelectorInterface
0216     QueryMethods supportedQueryMethods() const override;
0217     Element querySelector(const QString &query, QueryMethod method) const override;
0218     QList<Element> querySelectorAll(const QString &query, QueryMethod method) const override;
0219 
0220     // SettingsInterface
0221     QVariant htmlSettingsProperty(HtmlSettingsType type) const override;
0222     bool setHtmlSettingsProperty(HtmlSettingsType type, const QVariant &value) override;
0223 
0224     KHTMLPart *part() const;
0225 };
0226 
0227 #endif