File indexing completed on 2025-03-09 04:54:40

0001 /*
0002    SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 #include "messageviewer_export.h"
0009 #include <WebEngineViewer/BlockTrackingUrlInterceptor>
0010 #include <WebEngineViewer/WebEngineView>
0011 class QPrinter;
0012 class KActionCollection;
0013 namespace WebEngineViewer
0014 {
0015 class WebHitTestResult;
0016 }
0017 namespace MessageViewer
0018 {
0019 class ViewerPrivate;
0020 class MailWebEngineViewPrivate;
0021 /**
0022  * @brief The MailWebEngineView class
0023  * @author Laurent Montel <montel@kde.org>
0024  */
0025 class MESSAGEVIEWER_EXPORT MailWebEngineView : public WebEngineViewer::WebEngineView
0026 {
0027     Q_OBJECT
0028 public:
0029     explicit MailWebEngineView(KActionCollection *ac, QWidget *parent = nullptr);
0030     ~MailWebEngineView() override;
0031 
0032     void scrollUp(int pixels);
0033     void scrollDown(int pixels);
0034 
0035     void selectAll();
0036     void scamCheck();
0037 
0038     void saveMainFrameScreenshotInFile(const QString &filename);
0039     void showAccessKeys();
0040     void hideAccessKeys();
0041     void isScrolledToBottom();
0042 
0043     void setElementByIdVisible(const QString &id, bool visible);
0044     void removeAttachmentMarking(const QString &id);
0045     void markAttachment(const QString &id, const QString &style);
0046     void scrollToAnchor(const QString &anchor);
0047     void scrollPageDown(int percent);
0048     void scrollPageUp(int percent);
0049 
0050     void scrollToRelativePosition(qreal pos);
0051 
0052     void setAllowExternalContent(bool b);
0053 
0054     [[nodiscard]] QList<QAction *> interceptorUrlActions(const WebEngineViewer::WebHitTestResult &result) const;
0055 
0056     void setPrintElementBackground(bool printElementBackground);
0057 
0058     void setLinkHovered(const QUrl &url);
0059     void setViewer(MessageViewer::ViewerPrivate *viewer);
0060     void readConfig();
0061 
0062     static void initializeCustomScheme();
0063     void printPreviewPage(QPrinter *printer);
0064 public Q_SLOTS:
0065     void slotZoomChanged(qreal zoom);
0066     void slotShowDetails();
0067 
0068 protected:
0069     void forwardWheelEvent(QWheelEvent *event) override;
0070     void forwardKeyPressEvent(QKeyEvent *event) override;
0071     void forwardKeyReleaseEvent(QKeyEvent *event) override;
0072     void forwardMousePressEvent(QMouseEvent *event) override;
0073     void forwardMouseMoveEvent(QMouseEvent *event) override;
0074     void forwardMouseReleaseEvent(QMouseEvent *event) override;
0075 
0076     void resizeEvent(QResizeEvent *e) override;
0077 
0078     void contextMenuEvent(QContextMenuEvent *e) override;
0079 Q_SIGNALS:
0080     void wheelZoomChanged(int numSteps);
0081     void openUrl(const QUrl &url);
0082     void urlBlocked(const QUrl &url);
0083     void messageMayBeAScam();
0084     void formSubmittedForbidden();
0085     /// Emitted when the user right-clicks somewhere
0086     void popupMenu(const WebEngineViewer::WebHitTestResult &result);
0087     void pageIsScrolledToBottom(bool);
0088 
0089 private Q_SLOTS:
0090     MESSAGEVIEWER_NO_EXPORT void handleScrollToAnchor(const QVariant &result);
0091     MESSAGEVIEWER_NO_EXPORT void handleIsScrolledToBottom(const QVariant &result);
0092 
0093     MESSAGEVIEWER_NO_EXPORT void slotWebHitFinished(const WebEngineViewer::WebHitTestResult &result);
0094     MESSAGEVIEWER_NO_EXPORT void slotLoadFinished();
0095 
0096 private:
0097     MESSAGEVIEWER_NO_EXPORT void runJavaScriptInWordId(const QString &script);
0098     std::unique_ptr<MailWebEngineViewPrivate> const d;
0099 };
0100 }