1 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net> 2 3 This file is part of the Trojita Qt IMAP e-mail client, 4 http://trojita.flaska.net/ 5 6 This program is free software; you can redistribute it and/or 7 modify it under the terms of the GNU General Public License as 8 published by the Free Software Foundation; either version 2 of 9 the License or (at your option) version 3 or any later version 10 accepted by the membership of KDE e.V. (or its successor approved 11 by the membership of KDE e.V.), which shall act as a proxy 12 defined in Section 14 of version 3 of the license. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program. If not, see <http://www.gnu.org/licenses/>. 21 */ 22 #ifndef EMBEDDEDWEBVIEW_H 23 #define EMBEDDEDWEBVIEW_H 24 25 #include <QWebPluginFactory> 26 #include <QWebView> 27 28 namespace Gui 29 { 30 31 32 /** @short An embeddable QWebView with some safety checks and modified resizing 33 34 This class configures the QWebView in such a way that it will prevent certain 35 dangerous (or unexpected, in the context of a MUA) features from being invoked. 36 37 Another function is to configure the QWebView in such a way that it resizes 38 itself to show all required contents. 39 40 Note that you still have to provide a proper eventFilter in the parent widget 41 (and register it for use). 42 43 @see Gui::MessageView 44 45 */ 46 class EmbeddedWebView: public QWebView 47 { 48 Q_OBJECT 49 public: 50 enum class ColorScheme { 51 /** @short System's color scheme, but let the content override this */ 52 System, 53 /** @short System's color scheme adjusted towards a compromise for reasonable contrats on funny backgrounds */ 54 AdjustedSystem, 55 /** @short Use boring black-text-on-white-background */ 56 BlackOnWhite, 57 }; 58 59 EmbeddedWebView(QWidget *parent, QNetworkAccessManager *networkManager); 60 QSize sizeHint() const; 61 QWidget *scrollParent() const; 62 void setStaticWidth(int staticWidth); 63 int staticWidth() const; 64 std::map<ColorScheme, QString> supportedColorSchemes() const; 65 public slots: 66 void setColorScheme(const ColorScheme colorScheme); 67 protected: 68 void changeEvent(QEvent *e); 69 bool eventFilter(QObject *o, QEvent *e); 70 void mouseMoveEvent(QMouseEvent *e); 71 void mouseReleaseEvent(QMouseEvent *e); 72 void showEvent(QShowEvent *se); 73 void addCustomStylesheet(const QString &css); 74 void constrainSize(); 75 private: 76 void findScrollParent(); 77 private slots: 78 void autoScroll(); 79 void slotLinkClicked(const QUrl &url); 80 void handlePageLoadFinished(); 81 private: 82 QWidget *m_scrollParent; 83 int m_scrollParentPadding; 84 int m_resizeInProgress; 85 QTimer *m_autoScrollTimer; 86 QTimer *m_sizeContrainTimer; 87 int m_autoScrollPixels; 88 int m_staticWidth; 89 QString m_customCss; 90 protected: 91 ColorScheme m_colorScheme; 92 }; 93 94 class ErrorCheckingPage: public QWebPage 95 { 96 Q_OBJECT 97 public: 98 explicit ErrorCheckingPage(QObject *parent); 99 100 virtual bool extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output); 101 virtual bool supportsExtension(Extension extension) const; 102 }; 103 104 } 105 106 #endif // EMBEDDEDWEBVIEW_H 107