Lines 1-391
Link Here
|
1 |
/* |
1 |
/* |
2 |
Copyright (C) 2016-2018 Laurent Montel <montel@kde.org> |
2 |
Copyright (C) 2016-2018 Laurent Montel <montel@kde.org> |
3 |
|
3 |
|
4 |
This library is free software; you can redistribute it and/or |
4 |
This library is free software; you can redistribute it and/or |
5 |
modify it under the terms of the GNU Library General Public |
5 |
modify it under the terms of the GNU Library General Public |
6 |
License as published by the Free Software Foundation; either |
6 |
License as published by the Free Software Foundation; either |
7 |
version 2 of the License, or (at your option) any later version. |
7 |
version 2 of the License, or (at your option) any later version. |
8 |
|
8 |
|
9 |
This library is distributed in the hope that it will be useful, |
9 |
This library is distributed in the hope that it will be useful, |
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 |
Library General Public License for more details. |
12 |
Library General Public License for more details. |
13 |
|
13 |
|
14 |
You should have received a copy of the GNU Library General Public License |
14 |
You should have received a copy of the GNU Library General Public License |
15 |
along with this library; see the file COPYING.LIB. If not, write to |
15 |
along with this library; see the file COPYING.LIB. If not, write to |
16 |
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
16 |
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 |
Boston, MA 02110-1301, USA. |
17 |
Boston, MA 02110-1301, USA. |
18 |
*/ |
18 |
*/ |
19 |
#include "mailwebengineview.h" |
19 |
#include "mailwebengineview.h" |
20 |
#include "mailwebenginepage.h" |
20 |
#include "mailwebenginepage.h" |
21 |
#include "webengineviewer/webengineaccesskey.h" |
21 |
#include "webengineviewer/webengineaccesskey.h" |
22 |
#include "webengineviewer/webenginescript.h" |
22 |
#include "webengineviewer/webenginescript.h" |
23 |
#include "messageviewer/messageviewersettings.h" |
23 |
#include "messageviewer/messageviewersettings.h" |
24 |
#include "../urlhandlermanager.h" |
24 |
#include "../urlhandlermanager.h" |
25 |
#include "loadexternalreferencesurlinterceptor/loadexternalreferencesurlinterceptor.h" |
25 |
#include "loadexternalreferencesurlinterceptor/loadexternalreferencesurlinterceptor.h" |
26 |
#include "blockexternalresourcesurlinterceptor/blockexternalresourcesurlinterceptor.h" |
26 |
#include "blockexternalresourcesurlinterceptor/blockexternalresourcesurlinterceptor.h" |
27 |
#include "blockmailtrackingurlinterceptor/blockmailtrackingurlinterceptor.h" |
27 |
#include "blockmailtrackingurlinterceptor/blockmailtrackingurlinterceptor.h" |
28 |
#include "cidreferencesurlinterceptor/cidreferencesurlinterceptor.h" |
28 |
#include "cidreferencesurlinterceptor/cidreferencesurlinterceptor.h" |
29 |
#include <WebEngineViewer/InterceptorManager> |
29 |
#include <WebEngineViewer/InterceptorManager> |
30 |
#include <WebEngineViewer/WebEngineManageScript> |
30 |
#include <WebEngineViewer/WebEngineManageScript> |
31 |
|
31 |
|
32 |
#include "scamdetection/scamdetectionwebengine.h" |
32 |
#include "scamdetection/scamdetectionwebengine.h" |
33 |
#include "scamdetection/scamcheckshorturl.h" |
33 |
#include "scamdetection/scamcheckshorturl.h" |
34 |
#include <QContextMenuEvent> |
34 |
#include <QContextMenuEvent> |
35 |
#include <WebEngineViewer/WebHitTest> |
35 |
#include <WebEngineViewer/WebHitTest> |
36 |
|
36 |
|
37 |
#include <QWebEngineProfile> |
|
|
38 |
#include <QPrinter> |
37 |
#include <QPrinter> |
39 |
|
38 |
|
40 |
#include <WebEngineViewer/WebHitTestResult> |
39 |
#include <WebEngineViewer/WebHitTestResult> |
41 |
|
40 |
|
42 |
using namespace MessageViewer; |
41 |
using namespace MessageViewer; |
43 |
template<typename Arg, typename R, typename C> |
42 |
template<typename Arg, typename R, typename C> |
44 |
struct InvokeWrapper { |
43 |
struct InvokeWrapper { |
45 |
R *receiver; |
44 |
R *receiver; |
46 |
void (C::*memberFunction)(Arg); |
45 |
void (C::*memberFunction)(Arg); |
47 |
void operator()(Arg result) |
46 |
void operator()(Arg result) |
48 |
{ |
47 |
{ |
49 |
(receiver->*memberFunction)(result); |
48 |
(receiver->*memberFunction)(result); |
50 |
} |
49 |
} |
51 |
}; |
50 |
}; |
52 |
|
51 |
|
53 |
template<typename Arg, typename R, typename C> |
52 |
template<typename Arg, typename R, typename C> |
54 |
|
53 |
|
55 |
InvokeWrapper<Arg, R, C> invoke(R *receiver, void (C::*memberFunction)(Arg)) |
54 |
InvokeWrapper<Arg, R, C> invoke(R *receiver, void (C::*memberFunction)(Arg)) |
56 |
{ |
55 |
{ |
57 |
InvokeWrapper<Arg, R, C> wrapper = {receiver, memberFunction}; |
56 |
InvokeWrapper<Arg, R, C> wrapper = {receiver, memberFunction}; |
58 |
return wrapper; |
57 |
return wrapper; |
59 |
} |
58 |
} |
60 |
|
59 |
|
61 |
class MessageViewer::MailWebEngineViewPrivate |
60 |
class MessageViewer::MailWebEngineViewPrivate |
62 |
{ |
61 |
{ |
63 |
public: |
62 |
public: |
64 |
MailWebEngineViewPrivate() |
63 |
MailWebEngineViewPrivate() |
65 |
{ |
64 |
{ |
66 |
} |
65 |
} |
67 |
|
66 |
|
68 |
QUrl mHoveredUrl; |
67 |
QUrl mHoveredUrl; |
69 |
QPoint mLastClickPosition; |
68 |
QPoint mLastClickPosition; |
70 |
ScamDetectionWebEngine *mScamDetection = nullptr; |
69 |
ScamDetectionWebEngine *mScamDetection = nullptr; |
71 |
WebEngineViewer::WebEngineAccessKey *mWebViewAccessKey = nullptr; |
70 |
WebEngineViewer::WebEngineAccessKey *mWebViewAccessKey = nullptr; |
72 |
MessageViewer::LoadExternalReferencesUrlInterceptor *mExternalReference = nullptr; |
71 |
MessageViewer::LoadExternalReferencesUrlInterceptor *mExternalReference = nullptr; |
73 |
MailWebEnginePage *mPageEngine = nullptr; |
72 |
MailWebEnginePage *mPageEngine = nullptr; |
74 |
WebEngineViewer::InterceptorManager *mNetworkAccessManager = nullptr; |
73 |
WebEngineViewer::InterceptorManager *mNetworkAccessManager = nullptr; |
75 |
MessageViewer::ViewerPrivate *mViewer = nullptr; |
74 |
MessageViewer::ViewerPrivate *mViewer = nullptr; |
76 |
MessageViewer::BlockMailTrackingUrlInterceptor *mBlockMailTrackingUrl = nullptr; |
75 |
MessageViewer::BlockMailTrackingUrlInterceptor *mBlockMailTrackingUrl = nullptr; |
77 |
bool mCanStartDrag = false; |
76 |
bool mCanStartDrag = false; |
78 |
}; |
77 |
}; |
79 |
|
78 |
|
80 |
MailWebEngineView::MailWebEngineView(KActionCollection *ac, QWidget *parent) |
79 |
MailWebEngineView::MailWebEngineView(KActionCollection *ac, QWidget *parent) |
81 |
: WebEngineViewer::WebEngineView(parent) |
80 |
: WebEngineViewer::WebEngineView(parent) |
82 |
, d(new MessageViewer::MailWebEngineViewPrivate) |
81 |
, d(new MessageViewer::MailWebEngineViewPrivate) |
83 |
{ |
82 |
{ |
84 |
d->mPageEngine = new MailWebEnginePage(new QWebEngineProfile(this), this); |
83 |
d->mPageEngine = new MailWebEnginePage(this); |
85 |
setPage(d->mPageEngine); |
84 |
setPage(d->mPageEngine); |
86 |
d->mWebViewAccessKey = new WebEngineViewer::WebEngineAccessKey(this, this); |
85 |
d->mWebViewAccessKey = new WebEngineViewer::WebEngineAccessKey(this, this); |
87 |
d->mWebViewAccessKey->setActionCollection(ac); |
86 |
d->mWebViewAccessKey->setActionCollection(ac); |
88 |
d->mScamDetection = new ScamDetectionWebEngine(this); |
87 |
d->mScamDetection = new ScamDetectionWebEngine(this); |
89 |
connect(d->mScamDetection, &ScamDetectionWebEngine::messageMayBeAScam, this, |
88 |
connect(d->mScamDetection, &ScamDetectionWebEngine::messageMayBeAScam, this, |
90 |
&MailWebEngineView::messageMayBeAScam); |
89 |
&MailWebEngineView::messageMayBeAScam); |
91 |
connect(d->mWebViewAccessKey, &WebEngineViewer::WebEngineAccessKey::openUrl, this, |
90 |
connect(d->mWebViewAccessKey, &WebEngineViewer::WebEngineAccessKey::openUrl, this, |
92 |
&MailWebEngineView::openUrl); |
91 |
&MailWebEngineView::openUrl); |
93 |
connect(this, &MailWebEngineView::loadFinished, this, &MailWebEngineView::slotLoadFinished); |
92 |
connect(this, &MailWebEngineView::loadFinished, this, &MailWebEngineView::slotLoadFinished); |
94 |
|
93 |
|
95 |
d->mNetworkAccessManager = new WebEngineViewer::InterceptorManager(this, ac, this); |
94 |
d->mNetworkAccessManager = new WebEngineViewer::InterceptorManager(this, ac, this); |
96 |
d->mExternalReference = new MessageViewer::LoadExternalReferencesUrlInterceptor(this); |
95 |
d->mExternalReference = new MessageViewer::LoadExternalReferencesUrlInterceptor(this); |
97 |
d->mNetworkAccessManager->addInterceptor(d->mExternalReference); |
96 |
d->mNetworkAccessManager->addInterceptor(d->mExternalReference); |
98 |
MessageViewer::CidReferencesUrlInterceptor *cidReference |
97 |
MessageViewer::CidReferencesUrlInterceptor *cidReference |
99 |
= new MessageViewer::CidReferencesUrlInterceptor(this); |
98 |
= new MessageViewer::CidReferencesUrlInterceptor(this); |
100 |
d->mNetworkAccessManager->addInterceptor(cidReference); |
99 |
d->mNetworkAccessManager->addInterceptor(cidReference); |
101 |
MessageViewer::BlockExternalResourcesUrlInterceptor *blockExternalUrl |
100 |
MessageViewer::BlockExternalResourcesUrlInterceptor *blockExternalUrl |
102 |
= new MessageViewer::BlockExternalResourcesUrlInterceptor(this); |
101 |
= new MessageViewer::BlockExternalResourcesUrlInterceptor(this); |
103 |
connect(blockExternalUrl, &BlockExternalResourcesUrlInterceptor::formSubmittedForbidden, this, |
102 |
connect(blockExternalUrl, &BlockExternalResourcesUrlInterceptor::formSubmittedForbidden, this, |
104 |
&MailWebEngineView::formSubmittedForbidden); |
103 |
&MailWebEngineView::formSubmittedForbidden); |
105 |
d->mNetworkAccessManager->addInterceptor(blockExternalUrl); |
104 |
d->mNetworkAccessManager->addInterceptor(blockExternalUrl); |
106 |
|
105 |
|
107 |
d->mBlockMailTrackingUrl |
106 |
d->mBlockMailTrackingUrl |
108 |
= new MessageViewer::BlockMailTrackingUrlInterceptor(this); |
107 |
= new MessageViewer::BlockMailTrackingUrlInterceptor(this); |
109 |
connect(d->mBlockMailTrackingUrl, &BlockMailTrackingUrlInterceptor::mailTrackingFound, this, |
108 |
connect(d->mBlockMailTrackingUrl, &BlockMailTrackingUrlInterceptor::mailTrackingFound, this, |
110 |
&MailWebEngineView::mailTrackingFound); |
109 |
&MailWebEngineView::mailTrackingFound); |
111 |
|
110 |
|
112 |
setFocusPolicy(Qt::WheelFocus); |
111 |
setFocusPolicy(Qt::WheelFocus); |
113 |
connect(d->mPageEngine, &MailWebEnginePage::urlClicked, this, &MailWebEngineView::openUrl); |
112 |
connect(d->mPageEngine, &MailWebEnginePage::urlClicked, this, &MailWebEngineView::openUrl); |
114 |
connect( |
113 |
connect( |
115 |
page(), &QWebEnginePage::scrollPositionChanged, d->mWebViewAccessKey, |
114 |
page(), &QWebEnginePage::scrollPositionChanged, d->mWebViewAccessKey, |
116 |
&WebEngineViewer::WebEngineAccessKey::hideAccessKeys); |
115 |
&WebEngineViewer::WebEngineAccessKey::hideAccessKeys); |
117 |
initializeScripts(); |
116 |
initializeScripts(); |
118 |
} |
117 |
} |
119 |
|
118 |
|
120 |
MailWebEngineView::~MailWebEngineView() |
119 |
MailWebEngineView::~MailWebEngineView() |
121 |
{ |
120 |
{ |
122 |
delete d; |
121 |
delete d; |
123 |
} |
122 |
} |
124 |
|
123 |
|
125 |
void MailWebEngineView::readConfig() |
124 |
void MailWebEngineView::readConfig() |
126 |
{ |
125 |
{ |
127 |
if (MessageViewer::MessageViewerSettings::self()->mailTrackingUrlEnabled()) { |
126 |
if (MessageViewer::MessageViewerSettings::self()->mailTrackingUrlEnabled()) { |
128 |
d->mNetworkAccessManager->addInterceptor(d->mBlockMailTrackingUrl); |
127 |
d->mNetworkAccessManager->addInterceptor(d->mBlockMailTrackingUrl); |
129 |
} else { |
128 |
} else { |
130 |
d->mNetworkAccessManager->removeInterceptor(d->mBlockMailTrackingUrl); |
129 |
d->mNetworkAccessManager->removeInterceptor(d->mBlockMailTrackingUrl); |
131 |
} |
130 |
} |
132 |
} |
131 |
} |
133 |
|
132 |
|
134 |
void MailWebEngineView::setLinkHovered(const QUrl &url) |
133 |
void MailWebEngineView::setLinkHovered(const QUrl &url) |
135 |
{ |
134 |
{ |
136 |
//TODO we need to detect image url too. |
135 |
//TODO we need to detect image url too. |
137 |
d->mHoveredUrl = url; |
136 |
d->mHoveredUrl = url; |
138 |
} |
137 |
} |
139 |
|
138 |
|
140 |
void MailWebEngineView::runJavaScriptInWordId(const QString &script) |
139 |
void MailWebEngineView::runJavaScriptInWordId(const QString &script) |
141 |
{ |
140 |
{ |
142 |
page()->runJavaScript(script, WebEngineViewer::WebEngineManageScript::scriptWordId()); |
141 |
page()->runJavaScript(script, WebEngineViewer::WebEngineManageScript::scriptWordId()); |
143 |
} |
142 |
} |
144 |
|
143 |
|
145 |
void MailWebEngineView::setViewer(MessageViewer::ViewerPrivate *viewer) |
144 |
void MailWebEngineView::setViewer(MessageViewer::ViewerPrivate *viewer) |
146 |
{ |
145 |
{ |
147 |
d->mViewer = viewer; |
146 |
d->mViewer = viewer; |
148 |
} |
147 |
} |
149 |
|
148 |
|
150 |
void MailWebEngineView::initializeScripts() |
149 |
void MailWebEngineView::initializeScripts() |
151 |
{ |
150 |
{ |
152 |
initializeJQueryScript(); |
151 |
initializeJQueryScript(); |
153 |
} |
152 |
} |
154 |
|
153 |
|
155 |
void MailWebEngineView::contextMenuEvent(QContextMenuEvent *e) |
154 |
void MailWebEngineView::contextMenuEvent(QContextMenuEvent *e) |
156 |
{ |
155 |
{ |
157 |
WebEngineViewer::WebHitTest *webHit = d->mPageEngine->hitTestContent(e->pos()); |
156 |
WebEngineViewer::WebHitTest *webHit = d->mPageEngine->hitTestContent(e->pos()); |
158 |
connect(webHit, &WebEngineViewer::WebHitTest::finished, this, |
157 |
connect(webHit, &WebEngineViewer::WebHitTest::finished, this, |
159 |
&MailWebEngineView::slotWebHitFinished); |
158 |
&MailWebEngineView::slotWebHitFinished); |
160 |
} |
159 |
} |
161 |
|
160 |
|
162 |
void MailWebEngineView::slotWebHitFinished(const WebEngineViewer::WebHitTestResult &result) |
161 |
void MailWebEngineView::slotWebHitFinished(const WebEngineViewer::WebHitTestResult &result) |
163 |
{ |
162 |
{ |
164 |
Q_EMIT popupMenu(result); |
163 |
Q_EMIT popupMenu(result); |
165 |
} |
164 |
} |
166 |
|
165 |
|
167 |
void MailWebEngineView::scrollUp(int pixels) |
166 |
void MailWebEngineView::scrollUp(int pixels) |
168 |
{ |
167 |
{ |
169 |
runJavaScriptInWordId(WebEngineViewer::WebEngineScript::scrollUp(pixels)); |
168 |
runJavaScriptInWordId(WebEngineViewer::WebEngineScript::scrollUp(pixels)); |
170 |
} |
169 |
} |
171 |
|
170 |
|
172 |
void MailWebEngineView::scrollDown(int pixels) |
171 |
void MailWebEngineView::scrollDown(int pixels) |
173 |
{ |
172 |
{ |
174 |
runJavaScriptInWordId(WebEngineViewer::WebEngineScript::scrollDown(pixels)); |
173 |
runJavaScriptInWordId(WebEngineViewer::WebEngineScript::scrollDown(pixels)); |
175 |
} |
174 |
} |
176 |
|
175 |
|
177 |
void MailWebEngineView::selectAll() |
176 |
void MailWebEngineView::selectAll() |
178 |
{ |
177 |
{ |
179 |
page()->triggerAction(QWebEnginePage::SelectAll); |
178 |
page()->triggerAction(QWebEnginePage::SelectAll); |
180 |
} |
179 |
} |
181 |
|
180 |
|
182 |
void MailWebEngineView::slotZoomChanged(qreal zoom) |
181 |
void MailWebEngineView::slotZoomChanged(qreal zoom) |
183 |
{ |
182 |
{ |
184 |
setZoomFactor(zoom); |
183 |
setZoomFactor(zoom); |
185 |
} |
184 |
} |
186 |
|
185 |
|
187 |
void MailWebEngineView::scamCheck() |
186 |
void MailWebEngineView::scamCheck() |
188 |
{ |
187 |
{ |
189 |
d->mScamDetection->scanPage(page()); |
188 |
d->mScamDetection->scanPage(page()); |
190 |
} |
189 |
} |
191 |
|
190 |
|
192 |
void MailWebEngineView::slotShowDetails() |
191 |
void MailWebEngineView::slotShowDetails() |
193 |
{ |
192 |
{ |
194 |
d->mScamDetection->showDetails(); |
193 |
d->mScamDetection->showDetails(); |
195 |
} |
194 |
} |
196 |
|
195 |
|
197 |
void MailWebEngineView::forwardKeyReleaseEvent(QKeyEvent *e) |
196 |
void MailWebEngineView::forwardKeyReleaseEvent(QKeyEvent *e) |
198 |
{ |
197 |
{ |
199 |
if (MessageViewer::MessageViewerSettings::self()->accessKeyEnabled()) { |
198 |
if (MessageViewer::MessageViewerSettings::self()->accessKeyEnabled()) { |
200 |
d->mWebViewAccessKey->keyReleaseEvent(e); |
199 |
d->mWebViewAccessKey->keyReleaseEvent(e); |
201 |
} |
200 |
} |
202 |
} |
201 |
} |
203 |
|
202 |
|
204 |
void MailWebEngineView::forwardMousePressEvent(QMouseEvent *event) |
203 |
void MailWebEngineView::forwardMousePressEvent(QMouseEvent *event) |
205 |
{ |
204 |
{ |
206 |
if (d->mViewer && !d->mHoveredUrl.isEmpty()) { |
205 |
if (d->mViewer && !d->mHoveredUrl.isEmpty()) { |
207 |
if (event->button() == Qt::LeftButton && (event->modifiers() & Qt::ShiftModifier)) { |
206 |
if (event->button() == Qt::LeftButton && (event->modifiers() & Qt::ShiftModifier)) { |
208 |
// special processing for shift+click |
207 |
// special processing for shift+click |
209 |
if (URLHandlerManager::instance()->handleShiftClick(d->mHoveredUrl, d->mViewer)) { |
208 |
if (URLHandlerManager::instance()->handleShiftClick(d->mHoveredUrl, d->mViewer)) { |
210 |
event->accept(); |
209 |
event->accept(); |
211 |
return; |
210 |
return; |
212 |
} |
211 |
} |
213 |
} |
212 |
} |
214 |
if (event->button() == Qt::LeftButton) { |
213 |
if (event->button() == Qt::LeftButton) { |
215 |
d->mCanStartDrag = URLHandlerManager::instance()->willHandleDrag(d->mHoveredUrl, |
214 |
d->mCanStartDrag = URLHandlerManager::instance()->willHandleDrag(d->mHoveredUrl, |
216 |
d->mViewer); |
215 |
d->mViewer); |
217 |
d->mLastClickPosition = event->pos(); |
216 |
d->mLastClickPosition = event->pos(); |
218 |
} |
217 |
} |
219 |
} |
218 |
} |
220 |
} |
219 |
} |
221 |
|
220 |
|
222 |
void MailWebEngineView::forwardMouseMoveEvent(QMouseEvent *event) |
221 |
void MailWebEngineView::forwardMouseMoveEvent(QMouseEvent *event) |
223 |
{ |
222 |
{ |
224 |
if (d->mViewer && !d->mHoveredUrl.isEmpty()) { |
223 |
if (d->mViewer && !d->mHoveredUrl.isEmpty()) { |
225 |
// If we are potentially handling a drag, deal with that. |
224 |
// If we are potentially handling a drag, deal with that. |
226 |
if (d->mCanStartDrag && (event->buttons() & Qt::LeftButton)) { |
225 |
if (d->mCanStartDrag && (event->buttons() & Qt::LeftButton)) { |
227 |
if ((d->mLastClickPosition - event->pos()).manhattanLength() |
226 |
if ((d->mLastClickPosition - event->pos()).manhattanLength() |
228 |
> QApplication::startDragDistance()) { |
227 |
> QApplication::startDragDistance()) { |
229 |
if (URLHandlerManager::instance()->handleDrag(d->mHoveredUrl, d->mViewer)) { |
228 |
if (URLHandlerManager::instance()->handleDrag(d->mHoveredUrl, d->mViewer)) { |
230 |
// If the URL handler manager started a drag, don't handle this in the future |
229 |
// If the URL handler manager started a drag, don't handle this in the future |
231 |
d->mCanStartDrag = false; |
230 |
d->mCanStartDrag = false; |
232 |
} |
231 |
} |
233 |
} |
232 |
} |
234 |
event->accept(); |
233 |
event->accept(); |
235 |
} |
234 |
} |
236 |
} |
235 |
} |
237 |
} |
236 |
} |
238 |
|
237 |
|
239 |
void MailWebEngineView::forwardMouseReleaseEvent(QMouseEvent *event) |
238 |
void MailWebEngineView::forwardMouseReleaseEvent(QMouseEvent *event) |
240 |
{ |
239 |
{ |
241 |
Q_UNUSED(event); |
240 |
Q_UNUSED(event); |
242 |
d->mCanStartDrag = false; |
241 |
d->mCanStartDrag = false; |
243 |
} |
242 |
} |
244 |
|
243 |
|
245 |
void MailWebEngineView::forwardKeyPressEvent(QKeyEvent *e) |
244 |
void MailWebEngineView::forwardKeyPressEvent(QKeyEvent *e) |
246 |
{ |
245 |
{ |
247 |
if (e && hasFocus()) { |
246 |
if (e && hasFocus()) { |
248 |
if (MessageViewer::MessageViewerSettings::self()->accessKeyEnabled()) { |
247 |
if (MessageViewer::MessageViewerSettings::self()->accessKeyEnabled()) { |
249 |
d->mWebViewAccessKey->keyPressEvent(e); |
248 |
d->mWebViewAccessKey->keyPressEvent(e); |
250 |
} |
249 |
} |
251 |
} |
250 |
} |
252 |
} |
251 |
} |
253 |
|
252 |
|
254 |
void MailWebEngineView::forwardWheelEvent(QWheelEvent *e) |
253 |
void MailWebEngineView::forwardWheelEvent(QWheelEvent *e) |
255 |
{ |
254 |
{ |
256 |
if (MessageViewer::MessageViewerSettings::self()->accessKeyEnabled()) { |
255 |
if (MessageViewer::MessageViewerSettings::self()->accessKeyEnabled()) { |
257 |
d->mWebViewAccessKey->wheelEvent(e); |
256 |
d->mWebViewAccessKey->wheelEvent(e); |
258 |
} |
257 |
} |
259 |
if (QApplication::keyboardModifiers() & Qt::ControlModifier) { |
258 |
if (QApplication::keyboardModifiers() & Qt::ControlModifier) { |
260 |
const int numDegrees = e->delta() / 8; |
259 |
const int numDegrees = e->delta() / 8; |
261 |
const int numSteps = numDegrees / 15; |
260 |
const int numSteps = numDegrees / 15; |
262 |
Q_EMIT wheelZoomChanged(numSteps); |
261 |
Q_EMIT wheelZoomChanged(numSteps); |
263 |
e->accept(); |
262 |
e->accept(); |
264 |
} |
263 |
} |
265 |
} |
264 |
} |
266 |
|
265 |
|
267 |
void MailWebEngineView::resizeEvent(QResizeEvent *e) |
266 |
void MailWebEngineView::resizeEvent(QResizeEvent *e) |
268 |
{ |
267 |
{ |
269 |
if (MessageViewer::MessageViewerSettings::self()->accessKeyEnabled()) { |
268 |
if (MessageViewer::MessageViewerSettings::self()->accessKeyEnabled()) { |
270 |
d->mWebViewAccessKey->resizeEvent(e); |
269 |
d->mWebViewAccessKey->resizeEvent(e); |
271 |
} |
270 |
} |
272 |
QWebEngineView::resizeEvent(e); |
271 |
QWebEngineView::resizeEvent(e); |
273 |
} |
272 |
} |
274 |
|
273 |
|
275 |
void MailWebEngineView::saveMainFrameScreenshotInFile(const QString &filename) |
274 |
void MailWebEngineView::saveMainFrameScreenshotInFile(const QString &filename) |
276 |
{ |
275 |
{ |
277 |
//TODO need to verify it |
276 |
//TODO need to verify it |
278 |
QImage image(size(), QImage::Format_ARGB32_Premultiplied); |
277 |
QImage image(size(), QImage::Format_ARGB32_Premultiplied); |
279 |
image.fill(Qt::transparent); |
278 |
image.fill(Qt::transparent); |
280 |
|
279 |
|
281 |
QPainter painter(&image); |
280 |
QPainter painter(&image); |
282 |
painter.setRenderHint(QPainter::Antialiasing, true); |
281 |
painter.setRenderHint(QPainter::Antialiasing, true); |
283 |
painter.setRenderHint(QPainter::TextAntialiasing, true); |
282 |
painter.setRenderHint(QPainter::TextAntialiasing, true); |
284 |
painter.setRenderHint(QPainter::SmoothPixmapTransform, true); |
283 |
painter.setRenderHint(QPainter::SmoothPixmapTransform, true); |
285 |
render(&painter); |
284 |
render(&painter); |
286 |
painter.end(); |
285 |
painter.end(); |
287 |
image.save(filename); |
286 |
image.save(filename); |
288 |
} |
287 |
} |
289 |
|
288 |
|
290 |
void MailWebEngineView::showAccessKeys() |
289 |
void MailWebEngineView::showAccessKeys() |
291 |
{ |
290 |
{ |
292 |
d->mWebViewAccessKey->showAccessKeys(); |
291 |
d->mWebViewAccessKey->showAccessKeys(); |
293 |
} |
292 |
} |
294 |
|
293 |
|
295 |
void MailWebEngineView::hideAccessKeys() |
294 |
void MailWebEngineView::hideAccessKeys() |
296 |
{ |
295 |
{ |
297 |
d->mWebViewAccessKey->hideAccessKeys(); |
296 |
d->mWebViewAccessKey->hideAccessKeys(); |
298 |
} |
297 |
} |
299 |
|
298 |
|
300 |
void MailWebEngineView::isScrolledToBottom() |
299 |
void MailWebEngineView::isScrolledToBottom() |
301 |
{ |
300 |
{ |
302 |
page()->runJavaScript(WebEngineViewer::WebEngineScript::isScrolledToBottom(), |
301 |
page()->runJavaScript(WebEngineViewer::WebEngineScript::isScrolledToBottom(), |
303 |
WebEngineViewer::WebEngineManageScript::scriptWordId(), |
302 |
WebEngineViewer::WebEngineManageScript::scriptWordId(), |
304 |
invoke(this, &MailWebEngineView::handleIsScrolledToBottom)); |
303 |
invoke(this, &MailWebEngineView::handleIsScrolledToBottom)); |
305 |
} |
304 |
} |
306 |
|
305 |
|
307 |
void MailWebEngineView::setElementByIdVisible(const QString &id, bool visible) |
306 |
void MailWebEngineView::setElementByIdVisible(const QString &id, bool visible) |
308 |
{ |
307 |
{ |
309 |
runJavaScriptInWordId(WebEngineViewer::WebEngineScript::setElementByIdVisible(id, visible)); |
308 |
runJavaScriptInWordId(WebEngineViewer::WebEngineScript::setElementByIdVisible(id, visible)); |
310 |
} |
309 |
} |
311 |
|
310 |
|
312 |
void MailWebEngineView::removeAttachmentMarking(const QString &id) |
311 |
void MailWebEngineView::removeAttachmentMarking(const QString &id) |
313 |
{ |
312 |
{ |
314 |
runJavaScriptInWordId(WebEngineViewer::WebEngineScript::removeStyleToElement(id)); |
313 |
runJavaScriptInWordId(WebEngineViewer::WebEngineScript::removeStyleToElement(id)); |
315 |
} |
314 |
} |
316 |
|
315 |
|
317 |
void MailWebEngineView::markAttachment(const QString &id, const QString &style) |
316 |
void MailWebEngineView::markAttachment(const QString &id, const QString &style) |
318 |
{ |
317 |
{ |
319 |
runJavaScriptInWordId(WebEngineViewer::WebEngineScript::setStyleToElement(id, style)); |
318 |
runJavaScriptInWordId(WebEngineViewer::WebEngineScript::setStyleToElement(id, style)); |
320 |
} |
319 |
} |
321 |
|
320 |
|
322 |
void MailWebEngineView::scrollToAnchor(const QString &anchor) |
321 |
void MailWebEngineView::scrollToAnchor(const QString &anchor) |
323 |
{ |
322 |
{ |
324 |
page()->runJavaScript(WebEngineViewer::WebEngineScript::searchElementPosition(anchor), |
323 |
page()->runJavaScript(WebEngineViewer::WebEngineScript::searchElementPosition(anchor), |
325 |
WebEngineViewer::WebEngineManageScript::scriptWordId(), |
324 |
WebEngineViewer::WebEngineManageScript::scriptWordId(), |
326 |
invoke(this, &MailWebEngineView::handleScrollToAnchor)); |
325 |
invoke(this, &MailWebEngineView::handleScrollToAnchor)); |
327 |
} |
326 |
} |
328 |
|
327 |
|
329 |
void MailWebEngineView::handleIsScrolledToBottom(const QVariant &result) |
328 |
void MailWebEngineView::handleIsScrolledToBottom(const QVariant &result) |
330 |
{ |
329 |
{ |
331 |
bool scrolledToBottomResult = false; |
330 |
bool scrolledToBottomResult = false; |
332 |
if (result.isValid()) { |
331 |
if (result.isValid()) { |
333 |
scrolledToBottomResult = result.toBool(); |
332 |
scrolledToBottomResult = result.toBool(); |
334 |
} |
333 |
} |
335 |
Q_EMIT pageIsScrolledToBottom(scrolledToBottomResult); |
334 |
Q_EMIT pageIsScrolledToBottom(scrolledToBottomResult); |
336 |
} |
335 |
} |
337 |
|
336 |
|
338 |
void MailWebEngineView::handleScrollToAnchor(const QVariant &result) |
337 |
void MailWebEngineView::handleScrollToAnchor(const QVariant &result) |
339 |
{ |
338 |
{ |
340 |
if (result.isValid()) { |
339 |
if (result.isValid()) { |
341 |
const QList<QVariant> lst = result.toList(); |
340 |
const QList<QVariant> lst = result.toList(); |
342 |
if (lst.count() == 2) { |
341 |
if (lst.count() == 2) { |
343 |
const QPoint pos(lst.at(0).toInt(), lst.at(1).toInt()); |
342 |
const QPoint pos(lst.at(0).toInt(), lst.at(1).toInt()); |
344 |
runJavaScriptInWordId(WebEngineViewer::WebEngineScript::scrollToPosition(pos)); |
343 |
runJavaScriptInWordId(WebEngineViewer::WebEngineScript::scrollToPosition(pos)); |
345 |
} |
344 |
} |
346 |
} |
345 |
} |
347 |
} |
346 |
} |
348 |
|
347 |
|
349 |
void MailWebEngineView::scrollPageDown(int percent) |
348 |
void MailWebEngineView::scrollPageDown(int percent) |
350 |
{ |
349 |
{ |
351 |
runJavaScriptInWordId(WebEngineViewer::WebEngineScript::scrollPercentage(percent)); |
350 |
runJavaScriptInWordId(WebEngineViewer::WebEngineScript::scrollPercentage(percent)); |
352 |
} |
351 |
} |
353 |
|
352 |
|
354 |
void MailWebEngineView::scrollPageUp(int percent) |
353 |
void MailWebEngineView::scrollPageUp(int percent) |
355 |
{ |
354 |
{ |
356 |
scrollPageDown(-percent); |
355 |
scrollPageDown(-percent); |
357 |
} |
356 |
} |
358 |
|
357 |
|
359 |
void MailWebEngineView::scrollToRelativePosition(qreal pos) |
358 |
void MailWebEngineView::scrollToRelativePosition(qreal pos) |
360 |
{ |
359 |
{ |
361 |
runJavaScriptInWordId(WebEngineViewer::WebEngineScript::scrollToRelativePosition(pos)); |
360 |
runJavaScriptInWordId(WebEngineViewer::WebEngineScript::scrollToRelativePosition(pos)); |
362 |
} |
361 |
} |
363 |
|
362 |
|
364 |
void MailWebEngineView::setAllowExternalContent(bool b) |
363 |
void MailWebEngineView::setAllowExternalContent(bool b) |
365 |
{ |
364 |
{ |
366 |
if (d->mExternalReference->allowExternalContent() != b) { |
365 |
if (d->mExternalReference->allowExternalContent() != b) { |
367 |
d->mExternalReference->setAllowExternalContent(b); |
366 |
d->mExternalReference->setAllowExternalContent(b); |
368 |
reload(); |
367 |
reload(); |
369 |
} |
368 |
} |
370 |
} |
369 |
} |
371 |
|
370 |
|
372 |
QList<QAction *> MailWebEngineView::interceptorUrlActions( |
371 |
QList<QAction *> MailWebEngineView::interceptorUrlActions( |
373 |
const WebEngineViewer::WebHitTestResult &result) const |
372 |
const WebEngineViewer::WebHitTestResult &result) const |
374 |
{ |
373 |
{ |
375 |
return d->mNetworkAccessManager->interceptorUrlActions(result); |
374 |
return d->mNetworkAccessManager->interceptorUrlActions(result); |
376 |
} |
375 |
} |
377 |
|
376 |
|
378 |
void MailWebEngineView::slotLoadFinished() |
377 |
void MailWebEngineView::slotLoadFinished() |
379 |
{ |
378 |
{ |
380 |
scamCheck(); |
379 |
scamCheck(); |
381 |
} |
380 |
} |
382 |
|
381 |
|
383 |
void MailWebEngineView::setPrintElementBackground(bool printElementBackground) |
382 |
void MailWebEngineView::setPrintElementBackground(bool printElementBackground) |
384 |
{ |
383 |
{ |
385 |
d->mPageEngine->setPrintElementBackground(printElementBackground); |
384 |
d->mPageEngine->setPrintElementBackground(printElementBackground); |
386 |
} |
385 |
} |
387 |
|
386 |
|
388 |
bool MailWebEngineView::execPrintPreviewPage(QPrinter *printer, int timeout) |
387 |
bool MailWebEngineView::execPrintPreviewPage(QPrinter *printer, int timeout) |
389 |
{ |
388 |
{ |
390 |
return d->mPageEngine->execPrintPreviewPage(printer, timeout); |
389 |
return d->mPageEngine->execPrintPreviewPage(printer, timeout); |
391 |
} |
390 |
} |