File indexing completed on 2024-05-19 05:01:22
0001 /* 0002 This file is part of the KDE project. 0003 0004 SPDX-FileCopyrightText: 2009 Dawit Alemayehu <adawit@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.1-or-later 0007 */ 0008 0009 #ifndef WEBENGINEPART_EXT_H 0010 #define WEBENGINEPART_EXT_H 0011 0012 #include "kwebenginepartlib_export.h" 0013 0014 #include "interfaces/downloaderextension.h" 0015 #include "qtwebengine6compat.h" 0016 0017 #include <QPointer> 0018 0019 #include "kf5compat.h" //For NavigationExtension 0020 #if QT_VERSION_MAJOR < 6 0021 #include <KParts/SelectorInterface> 0022 #endif 0023 0024 #include <asyncselectorinterface.h> 0025 #include <htmlextension.h> 0026 #include <htmlsettingsinterface.h> 0027 #include <textextension.h> 0028 #include <browserextension.h> 0029 0030 class QUrl; 0031 class WebEnginePart; 0032 class WebEngineView; 0033 class WebEnginePage; 0034 class QPrinter; 0035 class QJsonObject; 0036 class QWebEngineScript; 0037 0038 class KWEBENGINEPARTLIB_EXPORT WebEngineNavigationExtension : public BrowserExtension 0039 { 0040 Q_OBJECT 0041 0042 public: 0043 WebEngineNavigationExtension(WebEnginePart *parent, const QByteArray& cachedHistoryData); 0044 ~WebEngineNavigationExtension() override; 0045 0046 int xOffset() override; 0047 int yOffset() override; 0048 void saveState(QDataStream &) override; 0049 void restoreState(QDataStream &) override; 0050 void saveHistory(); 0051 0052 Q_SIGNALS: 0053 void saveUrl(const QUrl &); 0054 void saveHistory(QObject*, const QByteArray&); 0055 0056 public Q_SLOTS: 0057 void cut(); 0058 void copy(); 0059 void paste(); 0060 void print(); 0061 0062 void slotSaveDocument(); 0063 void slotSaveFullHTMLPage(); 0064 void searchProvider(); 0065 void reparseConfiguration(); 0066 void disableScrolling(); 0067 0068 void zoomIn(); 0069 void zoomOut(); 0070 void zoomNormal(); 0071 void toogleZoomTextOnly(); 0072 void toogleZoomToDPI(); 0073 void slotSelectAll(); 0074 0075 void slotSaveImageAs(); 0076 void slotSendImage(); 0077 void slotCopyImageURL(); 0078 void slotCopyImage(); 0079 void slotViewImage(); 0080 void slotBlockImage(); 0081 void slotBlockHost(); 0082 0083 void slotCopyLinkURL(); 0084 void slotCopyLinkText(); 0085 void slotSaveLinkAs(const QUrl &url); 0086 void slotCopyEmailAddress(); 0087 0088 void slotViewDocumentSource(); 0089 0090 void updateEditActions(); 0091 void updateActions(); 0092 0093 void slotPlayMedia(); 0094 void slotMuteMedia(); 0095 void slotLoopMedia(); 0096 void slotShowMediaControls(); 0097 void slotSaveMedia(); 0098 void slotCopyMedia(); 0099 void slotTextDirectionChanged(); 0100 void slotCheckSpelling(); 0101 void slotSpellCheckSelection(); 0102 void slotSpellCheckDone(const QString&); 0103 void spellCheckerCorrected(const QString&, int, const QString&); 0104 void spellCheckerMisspelling(const QString&, int); 0105 //void slotPrintRequested(QWebFrame*); 0106 void slotPrintPreview(); 0107 0108 void slotOpenSelection(); 0109 void slotLinkInTop(); 0110 0111 private Q_SLOTS: 0112 void slotHandlePagePrinted(bool result); 0113 private: 0114 WebEngineView* view(); 0115 WebEnginePage* page(); 0116 0117 QPointer<WebEnginePart> m_part; 0118 QPointer<WebEngineView> m_view; 0119 quint32 m_spellTextSelectionStart; 0120 quint32 m_spellTextSelectionEnd; 0121 QByteArray m_historyData; 0122 QPrinter *mCurrentPrinter; 0123 }; 0124 0125 /** 0126 * @internal 0127 * Implements the TextExtension interface 0128 */ 0129 class WebEngineTextExtension : public TextExtension 0130 { 0131 Q_OBJECT 0132 public: 0133 WebEngineTextExtension(WebEnginePart* part); 0134 0135 bool hasSelection() const override; 0136 QString selectedText(Format format) const override; 0137 QString completeText(Format format) const override; 0138 0139 private: 0140 WebEnginePart* part() const; 0141 }; 0142 0143 /** 0144 * @internal 0145 * Implements the HtmlExtension interface 0146 */ 0147 class WebEngineHtmlExtension : public HtmlExtension, 0148 public AsyncSelectorInterface, 0149 public HtmlSettingsInterface 0150 { 0151 Q_OBJECT 0152 Q_INTERFACES(AsyncSelectorInterface) 0153 Q_INTERFACES(HtmlSettingsInterface) 0154 0155 public: 0156 WebEngineHtmlExtension(WebEnginePart* part); 0157 0158 // HtmlExtension 0159 QUrl baseUrl() const override; 0160 bool hasSelection() const override; 0161 0162 // AsyncSelectorInterface 0163 /** 0164 * @brief The async query methods supported by the part 0165 * @return A list containing only AsyncSelectorInterface::EntireContent 0166 */ 0167 AsyncSelectorInterface::QueryMethods supportedAsyncQueryMethods() const override; 0168 void querySelectorAsync(const QString& query, AsyncSelectorInterface::QueryMethod method, SingleElementSelectorCallback& callback) override; 0169 void querySelectorAllAsync(const QString & query, AsyncSelectorInterface::QueryMethod method, MultipleElementSelectorCallback & callback) override; 0170 0171 // HtmlSettingsInterface 0172 QVariant htmlSettingsProperty(HtmlSettingsType type) const override; 0173 bool setHtmlSettingsProperty(HtmlSettingsType type, const QVariant& value) override; 0174 0175 private: 0176 WebEnginePart* part() const; 0177 0178 /** 0179 * @brief Converts the JSON array of elements returned by the javascript function `querySelectorAllToList()` in a list of KParts::SelectorInterface::Element 0180 * @param json A QVariant containing the JSON representation of the object returned by the javascript function `querySelectorAllToList()` 0181 * @return all the elements contained in @p json represented as KParts::SelectorInterface::Element 0182 */ 0183 static QList<AsyncSelectorInterface::Element> jsonToElementList(const QVariant &json); 0184 0185 /** 0186 * @brief Converts the JSON object returned by the javascript function `querySelectorToObject()` in a KParts::SelectorInterface::Element 0187 * @param json a QVariant containing the JSON representation of the object returned by the javascript function `querySelectorToObject()` 0188 * @return the element in @p json represented as KParts::SelectorInterface::Element 0189 */ 0190 static AsyncSelectorInterface::Element jsonToElement(const QVariant &json); 0191 0192 /** 0193 * @overload 0194 * @param obj the JSON object representing the element as returned by the javascript function `querySelectorToObject()` 0195 */ 0196 static AsyncSelectorInterface::Element jsonToElement(const QJsonObject &obj); 0197 }; 0198 0199 class WebEngineDownloaderExtension : public KonqInterfaces::DownloaderExtension 0200 { 0201 Q_OBJECT 0202 public: 0203 WebEngineDownloaderExtension(WebEnginePart *parent); 0204 ~WebEngineDownloaderExtension(); 0205 KonqInterfaces::DownloaderJob* downloadJob(const QUrl &url, quint32 id, QObject *parent=nullptr) override; 0206 void addDownloadRequest(QWebEngineDownloadRequest *req); 0207 KParts::ReadOnlyPart* part() const override; 0208 0209 private: 0210 QMultiHash<QUrl, QWebEngineDownloadRequest*> m_downloadRequests; 0211 }; 0212 0213 #endif // WEBENGINEPART_EXT_H