Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
PIM Messagelib
Commits
0ea79a3c
Commit
0ea79a3c
authored
Mar 25, 2016
by
Laurent Montel
Browse files
improve scrolling
parent
86a21231
Changes
7
Hide whitespace changes
Inline
Side-by-side
messageviewer/src/viewer/webengine/mailwebengineview.cpp
View file @
0ea79a3c
...
...
@@ -18,6 +18,7 @@
#include
"mailwebengineview.h"
#include
"mailwebenginepage.h"
#include
"mailwebengineaccesskey.h"
#include
"webengine/webenginescript.h"
#include
"messageviewer/messageviewersettings.h"
#include
<MessageViewer/NetworkAccessManagerWebEngine>
...
...
@@ -25,6 +26,23 @@
#include
"scamdetection/scamcheckshorturl.h"
using
namespace
MessageViewer
;
template
<
typename
Arg
,
typename
R
,
typename
C
>
struct
InvokeWrapper
{
R
*
receiver
;
void
(
C
::*
memberFunction
)(
Arg
);
void
operator
()(
Arg
result
)
{
(
receiver
->*
memberFunction
)(
result
);
}
};
template
<
typename
Arg
,
typename
R
,
typename
C
>
InvokeWrapper
<
Arg
,
R
,
C
>
invoke
(
R
*
receiver
,
void
(
C
::*
memberFunction
)(
Arg
))
{
InvokeWrapper
<
Arg
,
R
,
C
>
wrapper
=
{
receiver
,
memberFunction
};
return
wrapper
;
}
class
MessageViewer
::
MailWebEngineViewPrivate
{
...
...
@@ -132,3 +150,43 @@ void MailWebEngineView::showAccessKeys()
{
d
->
mWebViewAccessKey
->
showAccessKeys
();
}
void
MailWebEngineView
::
setElementByIdVisible
(
const
QString
&
id
,
bool
visible
)
{
page
()
->
runJavaScript
(
MessageViewer
::
WebEngineScript
::
setElementByIdVisible
(
id
,
visible
));
}
bool
MailWebEngineView
::
removeAttachmentMarking
(
const
QString
&
id
)
{
#if 0
QWebElement doc = page()->mainFrame()->documentElement();
QWebElement attachmentDiv = doc.findFirst(QLatin1String("*#") + id);
if (attachmentDiv.isNull()) {
return false;
}
attachmentDiv.removeAttribute(QStringLiteral("style"));
#endif
return
true
;
}
void
MailWebEngineView
::
markAttachment
(
const
QString
&
id
,
const
QString
&
style
)
{
//TODO verify "*#" + id
page
()
->
runJavaScript
(
MessageViewer
::
WebEngineScript
::
setStyleToElement
(
QLatin1String
(
"*#"
)
+
id
,
style
));
}
void
MailWebEngineView
::
scrollToAnchor
(
const
QString
&
anchor
)
{
page
()
->
runJavaScript
(
MessageViewer
::
WebEngineScript
::
searchElementPosition
(
anchor
),
invoke
(
this
,
&
MailWebEngineView
::
handleScrollToAnchor
));
}
void
MailWebEngineView
::
handleScrollToAnchor
(
const
QVariant
&
result
)
{
if
(
result
.
isValid
())
{
const
QList
<
QVariant
>
lst
=
result
.
toList
();
if
(
lst
.
count
()
==
2
)
{
const
QPoint
pos
(
lst
.
at
(
0
).
toInt
(),
lst
.
at
(
1
).
toInt
());
page
()
->
runJavaScript
(
MessageViewer
::
WebEngineScript
::
scrollToPosition
(
pos
));
}
}
}
messageviewer/src/viewer/webengine/mailwebengineview.h
View file @
0ea79a3c
...
...
@@ -36,6 +36,10 @@ public:
void
saveMainFrameScreenshotInFile
(
const
QString
&
filename
);
void
showAccessKeys
();
void
setElementByIdVisible
(
const
QString
&
id
,
bool
visible
);
bool
removeAttachmentMarking
(
const
QString
&
id
);
void
markAttachment
(
const
QString
&
id
,
const
QString
&
style
);
void
scrollToAnchor
(
const
QString
&
anchor
);
public
Q_SLOTS
:
void
slotZoomChanged
(
qreal
zoom
);
...
...
@@ -50,6 +54,10 @@ protected:
Q_SIGNALS:
void
openUrl
(
const
QUrl
&
url
);
private
Q_SLOTS
:
void
handleScrollToAnchor
(
const
QVariant
&
result
);
private:
MailWebEngineViewPrivate
*
const
d
;
};
...
...
messageviewer/src/webengine/tests/CMakeLists.txt
View file @
0ea79a3c
...
...
@@ -41,3 +41,14 @@ add_executable(scrolladdattachmenttest ${scrolladdattachment_test_SRCS})
target_link_libraries
(
scrolladdattachmenttest
Qt5::Widgets KF5::MessageViewer Qt5::WebEngine Qt5::WebEngineWidgets KF5::XmlGui KF5::IconThemes
)
####
set
(
testmailwebengine_test_SRCS
testmailwebengine.cpp
)
add_executable
(
testmailwebengine
${
testmailwebengine_test_SRCS
}
)
target_link_libraries
(
testmailwebengine
Qt5::Widgets KF5::MessageViewer Qt5::WebEngine Qt5::WebEngineWidgets KF5::XmlGui KF5::IconThemes
)
messageviewer/src/webengine/tests/testwebenginescrolladdattachment.cpp
View file @
0ea79a3c
...
...
@@ -59,21 +59,9 @@ TestWebEngineScrollAddAttachment::TestWebEngineScrollAddAttachment(QWidget *pare
}
void
TestWebEngineScrollAddAttachment
::
handleScrollToAnchor
(
const
QVariant
&
result
)
{
qDebug
()
<<
" result "
<<
result
;
if
(
result
.
isValid
())
{
const
QList
<
QVariant
>
lst
=
result
.
toList
();
if
(
lst
.
count
()
==
2
)
{
const
QPoint
pos
(
lst
.
at
(
0
).
toInt
(),
lst
.
at
(
1
).
toInt
());
mTestWebEngine
->
page
()
->
runJavaScript
(
MessageViewer
::
WebEngineScript
::
scrollToPosition
(
pos
));
}
}
}
void
TestWebEngineScrollAddAttachment
::
slotScrollToAttachment
()
{
mTestWebEngine
->
page
()
->
runJavaScript
(
MessageViewer
::
WebEngineScript
::
searchElementPosition
(
QStringLiteral
(
"module"
)),
invoke
(
this
,
&
TestWebEngineScrollAddAttachment
::
handleScrollToAnchor
));
mTestWebEngine
->
scrollToAnchor
(
QStringLiteral
(
"module"
));
}
int
main
(
int
argc
,
char
*
argv
[])
...
...
messageviewer/src/webengine/tests/testwebenginescrolladdattachment.h
View file @
0ea79a3c
...
...
@@ -31,7 +31,6 @@ public:
private
Q_SLOTS
:
void
slotScrollToAttachment
();
void
handleScrollToAnchor
(
const
QVariant
&
result
);
private:
MessageViewer
::
MailWebEngineView
*
mTestWebEngine
;
};
...
...
messageviewer/src/webengine/webenginescript.cpp
View file @
0ea79a3c
...
...
@@ -96,6 +96,23 @@ QString WebEngineScript::findAllAnchorsAndForms()
}
QString
WebEngineScript
::
setElementByIdVisible
(
const
QString
&
elementStr
,
bool
visibility
)
{
if
(
visibility
)
{
const
QString
source
=
QString
::
fromLatin1
(
"var element = document.getElementById('%1'); "
"if (element) { "
" element.style.removeProperty( 'display' );"
"}"
).
arg
(
elementStr
);
return
source
;
}
else
{
const
QString
source
=
QString
::
fromLatin1
(
"var element = document.getElementById('%1'); "
"if (element) { "
" element.style.display =
\"
none
\"
;"
"}"
).
arg
(
elementStr
);
return
source
;
}
}
QString
WebEngineScript
::
searchElementPosition
(
const
QString
&
elementStr
)
{
const
QString
source
=
QString
::
fromLatin1
(
"var element = document.getElementById('%1'); "
...
...
@@ -113,3 +130,12 @@ QString WebEngineScript::scrollToPosition(const QPoint &pos)
qDebug
()
<<
" source "
<<
source
;
return
source
;
}
QString
WebEngineScript
::
setStyleToElement
(
const
QString
&
elementStr
,
const
QString
&
style
)
{
const
QString
source
=
QString
::
fromLatin1
(
"var element = document.getElementById('%1'); "
"if (element) { "
" element.style = '%2';"
"}"
).
arg
(
elementStr
).
arg
(
style
);
return
source
;
}
messageviewer/src/webengine/webenginescript.h
View file @
0ea79a3c
...
...
@@ -31,6 +31,8 @@ MESSAGEVIEWER_EXPORT QString findAllAnchors();
MESSAGEVIEWER_EXPORT
QString
findAllAnchorsAndForms
();
MESSAGEVIEWER_EXPORT
QString
searchElementPosition
(
const
QString
&
elementStr
);
MESSAGEVIEWER_EXPORT
QString
scrollToPosition
(
const
QPoint
&
pos
);
MESSAGEVIEWER_EXPORT
QString
setElementByIdVisible
(
const
QString
&
elementStr
,
bool
visibility
);
MESSAGEVIEWER_EXPORT
QString
setStyleToElement
(
const
QString
&
elementStr
,
const
QString
&
style
);
}
}
#endif // WEBENGINESCRIPT_H
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment