• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

messageviewer

  • sources
  • kde-4.14
  • kdepim
  • messageviewer
  • viewer
mailwebview_webkit.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2010 Thomas McGuire <mcguire@kde.org>
3 
4  Copyright 2013 Laurent Montel <monte@kde.org>
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 #include "mailwebview.h"
23 #include "scamdetection/scamdetection.h"
24 #include "scamdetection/scamcheckshorturl.h"
25 #include "adblock/adblockblockableitemsdialog.h"
26 #include "adblock/webpage.h"
27 
28 #include <KDebug>
29 #include <KActionCollection>
30 #include <KAction>
31 
32 #include <QCoreApplication>
33 #include <QContextMenuEvent>
34 #include <QWebFrame>
35 #include <QWebElement>
36 #include <QLabel>
37 #include <QToolTip>
38 
39 #include <limits>
40 #include <cassert>
41 
42 typedef KWebView SuperClass;
43 
44 using namespace boost;
45 using namespace MessageViewer;
46 
47 static QString linkElementKey(const QWebElement& element)
48 {
49  if (element.hasAttribute(QLatin1String("href"))) {
50  const QUrl url = element.webFrame()->baseUrl().resolved(element.attribute(QLatin1String("href")));
51  QString linkKey (url.toString());
52  if (element.hasAttribute(QLatin1String("target"))) {
53  linkKey += QLatin1Char('+');
54  linkKey += element.attribute(QLatin1String("target"));
55  }
56  return linkKey;
57  }
58  return QString();
59 }
60 
61 
62 static bool isHiddenElement(const QWebElement& element)
63 {
64  // width property set to less than zero
65  if (element.hasAttribute(QLatin1String("width")) && element.attribute(QLatin1String("width")).toInt() < 1) {
66  return true;
67  }
68 
69  // height property set to less than zero
70  if (element.hasAttribute(QLatin1String("height")) && element.attribute(QLatin1String("height")).toInt() < 1) {
71  return true;
72  }
73 
74  // visibility set to 'hidden' in the element itself or its parent elements.
75  if (element.styleProperty(QLatin1String("visibility"),QWebElement::ComputedStyle).compare(QLatin1String("hidden"), Qt::CaseInsensitive) == 0) {
76  return true;
77  }
78 
79  // display set to 'none' in the element itself or its parent elements.
80  if (element.styleProperty(QLatin1String("display"),QWebElement::ComputedStyle).compare(QLatin1String("none"), Qt::CaseInsensitive) == 0) {
81  return true;
82  }
83 
84  return false;
85 }
86 
87 static bool isEditableElement(QWebPage* page)
88 {
89  const QWebFrame* frame = (page ? page->currentFrame() : 0);
90  QWebElement element = (frame ? frame->findFirstElement(QLatin1String(":focus")) : QWebElement());
91  if (!element.isNull()) {
92  const QString tagName(element.tagName());
93  if (tagName.compare(QLatin1String("textarea"), Qt::CaseInsensitive) == 0) {
94  return true;
95  }
96  const QString type(element.attribute(QLatin1String("type")).toLower());
97  if (tagName.compare(QLatin1String("input"), Qt::CaseInsensitive) == 0
98  && (type.isEmpty() || type == QLatin1String("text") || type == QLatin1String("password"))) {
99  return true;
100  }
101  if (element.evaluateJavaScript(QLatin1String("this.isContentEditable")).toBool()) {
102  return true;
103  }
104  }
105  return false;
106 }
107 
108 static void handleDuplicateLinkElements(const QWebElement& element, QHash<QString, QChar>* dupLinkList, QChar* accessKey)
109 {
110  if (element.tagName().compare(QLatin1String("A"), Qt::CaseInsensitive) == 0) {
111  const QString linkKey (linkElementKey(element));
112  // kDebug() << "LINK KEY:" << linkKey;
113  if (dupLinkList->contains(linkKey)) {
114  // kDebug() << "***** Found duplicate link element:" << linkKey << endl;
115  *accessKey = dupLinkList->value(linkKey);
116  } else if (!linkKey.isEmpty()) {
117  dupLinkList->insert(linkKey, *accessKey);
118  }
119  if (linkKey.isEmpty())
120  *accessKey = QChar();
121  }
122 }
123 
124 
125 MailWebView::MailWebView( KActionCollection *actionCollection, QWidget *parent )
126  : SuperClass( parent, false ),
127  mScamDetection(new ScamDetection),
128  mActionCollection(actionCollection)
129 {
130  setPage(new MessageViewer::WebPage(this));
131  page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks );
132  settings()->setAttribute( QWebSettings::JavascriptEnabled, false );
133  settings()->setAttribute( QWebSettings::JavaEnabled, false );
134  settings()->setAttribute( QWebSettings::PluginsEnabled, false );
135  connect( page(), SIGNAL(linkHovered(QString,QString,QString)),
136  this, SIGNAL(linkHovered(QString,QString,QString)) );
137  connect(this, SIGNAL(loadStarted()), this, SLOT(hideAccessKeys()));
138  connect(mScamDetection, SIGNAL(messageMayBeAScam()), this, SIGNAL(messageMayBeAScam()));
139  connect(page(), SIGNAL(scrollRequested(int,int,QRect)), this, SLOT(hideAccessKeys()));
140 }
141 
142 MailWebView::~MailWebView()
143 {
144  delete mScamDetection;
145 }
146 
147 bool MailWebView::event( QEvent *event )
148 {
149  if ( event->type() == QEvent::ContextMenu ) {
150  // Don't call SuperClass::event() here, it will do silly things like selecting the text
151  // under the mouse cursor, which we don't want.
152 
153  QContextMenuEvent const *contextMenuEvent = static_cast<QContextMenuEvent*>( event );
154  const QWebFrame * const frame = page()->currentFrame();
155  const QWebHitTestResult hit = frame->hitTestContent( contextMenuEvent->pos() );
156  kDebug() << "Right-clicked URL:" << hit.linkUrl();
157 
158  emit popupMenu( hit.linkUrl(), ((hit.pixmap().isNull()) ? QUrl() : hit.imageUrl()), mapToGlobal( contextMenuEvent->pos() ) );
159  event->accept();
160  return true;
161  }
162  return SuperClass::event( event );
163 }
164 
165 void MailWebView::scrollDown( int pixels )
166 {
167  QPoint point = page()->mainFrame()->scrollPosition();
168  point.ry() += pixels;
169  page()->mainFrame()->setScrollPosition( point );
170 }
171 
172 void MailWebView::scrollUp( int pixels )
173 {
174  scrollDown( -pixels );
175 }
176 
177 bool MailWebView::isScrolledToBottom() const
178 {
179  const int pos = page()->mainFrame()->scrollBarValue( Qt::Vertical );
180  const int max = page()->mainFrame()->scrollBarMaximum( Qt::Vertical );
181  return pos == max;
182 }
183 
184 void MailWebView::scrollPageDown( int percent )
185 {
186  const qint64 height = page()->viewportSize().height();
187  const qint64 current = page()->mainFrame()->scrollBarValue( Qt::Vertical );
188  // do arithmetic in higher precision, and check for overflow:
189  const qint64 newPosition = current + height * percent / 100;
190  if ( newPosition > std::numeric_limits<int>::max() )
191  kWarning() << "new position" << newPosition << "exceeds range of 'int'!";
192  page()->mainFrame()->setScrollBarValue( Qt::Vertical, newPosition );
193 }
194 
195 void MailWebView::scrollPageUp( int percent )
196 {
197  scrollPageDown( -percent );
198 }
199 
200 QString MailWebView::selectedText() const
201 {
202  //TODO HTML selection
203  /* settings()->setAttribute( QWebSettings::JavascriptEnabled, true );
204  QString textSelected = page()->currentFrame()->evaluateJavaScript(
205  "var span = document.createElement( 'SPAN' ); span.appendChild( window.getSelection().getRangeAt(0).cloneContents() );
206  ).toString();
207  settings()->setAttribute( QWebSettings::JavascriptEnabled, false );
208 
209  return textSelected;
210 */
211  return SuperClass::selectedText();
212 }
213 
214 bool MailWebView::hasVerticalScrollBar() const
215 {
216  return page()->mainFrame()->scrollBarGeometry( Qt::Vertical ).isValid();
217 }
218 
219 double MailWebView::relativePosition() const
220 {
221  if ( hasVerticalScrollBar() ) {
222  const double pos = page()->mainFrame()->scrollBarValue( Qt::Vertical );
223  const int height = page()->mainFrame()->scrollBarMaximum( Qt::Vertical );
224  return height ? pos / height : 0.0 ;
225  } else {
226  return 0.0;
227  }
228 }
229 
230 void MailWebView::scrollToRelativePosition( double pos )
231 {
232  // FIXME: This doesn't work, Qt resets the scrollbar value somewhere in the event handler.
233  // Using a singleshot timer wouldn't work either, since that introduces visible scrolling.
234  const int max = page()->mainFrame()->scrollBarMaximum( Qt::Vertical );
235  page()->currentFrame()->setScrollBarValue( Qt::Vertical, max * pos );
236 }
237 
238 void MailWebView::selectAll()
239 {
240  page()->triggerAction( QWebPage::SelectAll );
241 }
242 
243 void MailWebView::clearSelection()
244 {
245  //This is an ugly hack to remove the selection, I found no other way to do it with QWebView
246  QMouseEvent event(QEvent::MouseButtonPress, QPoint( 10, 10 ), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier );
247  QCoreApplication::sendEvent( page(), &event );
248  QMouseEvent event2(QEvent::MouseButtonRelease, QPoint( 10, 10 ), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier );
249  QCoreApplication::sendEvent( page(), &event2 );
250 }
251 
252 // Checks if the given node has a child node that is a DIV which has an ID attribute
253 // with the value specified here
254 static bool has_parent_div_with_id( const QWebElement & start, const QString & id )
255 {
256  if ( start.isNull() )
257  return false;
258 
259  if ( start.tagName().toLower() == QLatin1String("div") ) {
260  if ( start.attribute( QLatin1String("id"), QString() ) == id )
261  return true;
262  }
263 
264  return has_parent_div_with_id( start.parent(), id );
265 }
266 
267 bool MailWebView::isAttachmentInjectionPoint( const QPoint & global ) const
268 {
269  // for QTextBrowser, can be implemented as 'return false'
270  const QPoint local = page()->view()->mapFromGlobal( global );
271  const QWebHitTestResult hit = page()->currentFrame()->hitTestContent( local );
272  return has_parent_div_with_id( hit.enclosingBlockElement(), QLatin1String("attachmentInjectionPoint") );
273 }
274 
275 void MailWebView::injectAttachments( const function<QString()> & delayedHtml )
276 {
277  // for QTextBrowser, can be implemented empty
278  QWebElement doc = page()->currentFrame()->documentElement();
279  QWebElement injectionPoint = doc.findFirst( QLatin1String("*#attachmentInjectionPoint") );
280  if( injectionPoint.isNull() )
281  return;
282 
283  const QString html = delayedHtml();
284  if ( html.isEmpty() )
285  return;
286 
287  assert( injectionPoint.tagName().toLower() == QLatin1String("div") );
288  injectionPoint.setInnerXml( html );
289 }
290 
291 void MailWebView::scrollToAnchor( const QString & anchor )
292 {
293  page()->mainFrame()->scrollToAnchor(anchor);
294 }
295 
296 bool MailWebView::removeAttachmentMarking( const QString & id )
297 {
298  QWebElement doc = page()->mainFrame()->documentElement();
299  QWebElement attachmentDiv = doc.findFirst( QLatin1String("*#") + id );
300  if ( attachmentDiv.isNull() )
301  return false;
302  attachmentDiv.removeAttribute( QLatin1String("style") );
303  return true;
304 }
305 
306 void MailWebView::markAttachment( const QString & id, const QString & style )
307 {
308  QWebElement doc = page()->mainFrame()->documentElement();
309  QWebElement attachmentDiv = doc.findFirst( QLatin1String("*#") + id );
310  if ( !attachmentDiv.isNull() ) {
311  attachmentDiv.setAttribute(QLatin1String( "style"), style );
312  }
313 }
314 
315 void MailWebView::setHtml( const QString & html, const QUrl & base )
316 {
317  SuperClass::setHtml( html, base );
318 }
319 
320 QString MailWebView::htmlSource() const
321 {
322  return page()->mainFrame()->documentElement().toOuterXml();
323 }
324 
325 void MailWebView::setAllowExternalContent( bool allow )
326 {
327  SuperClass::setAllowExternalContent( allow );
328 }
329 
330 QUrl MailWebView::linkOrImageUrlAt( const QPoint & global ) const
331 {
332  const QPoint local = page()->view()->mapFromGlobal( global );
333  const QWebHitTestResult hit = page()->currentFrame()->hitTestContent( local );
334  if ( !hit.linkUrl().isEmpty() )
335  return hit.linkUrl();
336  else if ( !hit.imageUrl().isEmpty() )
337  return hit.imageUrl();
338  else
339  return QUrl();
340 }
341 
342 
343 void MailWebView::setScrollBarPolicy( Qt::Orientation orientation, Qt::ScrollBarPolicy policy )
344 {
345  page()->mainFrame()->setScrollBarPolicy( orientation, policy );
346 }
347 
348 Qt::ScrollBarPolicy MailWebView::scrollBarPolicy( Qt::Orientation orientation ) const
349 {
350  return page()->mainFrame()->scrollBarPolicy( orientation );
351 }
352 
353 
354 bool MailWebView::replaceInnerHtml( const QString & id, const function<QString()> & delayedHtml )
355 {
356  QWebElement doc = page()->currentFrame()->documentElement();
357  QWebElement tag = doc.findFirst( QLatin1String("*#") + id );
358  if ( tag.isNull() ) {
359  return false;
360  }
361  tag.setInnerXml( delayedHtml() );
362  return true;
363 }
364 
365 void MailWebView::setElementByIdVisible( const QString & id, bool visible )
366 {
367  QWebElement doc = page()->currentFrame()->documentElement();
368  QWebElement e = doc.findFirst( QLatin1String("*#") + id );
369  Q_ASSERT( !e.isNull() );
370 
371  if ( visible ) {
372  e.removeAttribute( QLatin1String("display") );
373  } else {
374  e.setStyleProperty( QLatin1String("display"), QLatin1String("none") );
375  }
376 }
377 
378 static QWebPage::FindFlags convert_flags( MailWebView::FindFlags f )
379 {
380  QWebPage::FindFlags result;
381  if ( f & MailWebView::FindWrapsAroundDocument )
382  result |= QWebPage::FindWrapsAroundDocument;
383  if ( f & MailWebView::FindBackward )
384  result |= QWebPage::FindBackward;
385  if ( f & MailWebView::FindCaseSensitively )
386  result |= QWebPage::FindCaseSensitively;
387  if ( f & MailWebView::HighlightAllOccurrences )
388  result |= QWebPage::HighlightAllOccurrences;
389  return result;
390 }
391 
392 bool MailWebView::findText( const QString & text, FindFlags flags )
393 {
394  return SuperClass::findText( text, convert_flags( flags ) );
395 }
396 
397 void MailWebView::clearFindSelection()
398 {
399  //WEBKIT: TODO: Find a way to unselect last selection
400  // http://bugreports.qt.nokia.com/browse/QTWEBKIT-80
401  SuperClass::findText( QString(), QWebPage::HighlightAllOccurrences );
402 }
403 
404 void MailWebView::keyReleaseEvent(QKeyEvent*e)
405 {
406  if (GlobalSettings::self()->accessKeyEnabled() && mAccessKeyActivated == PreActivated) {
407  // Activate only when the CTRL key is pressed and released by itself.
408  if (e->key() == Qt::Key_Control && e->modifiers() == Qt::NoModifier) {
409  showAccessKeys();
410  mAccessKeyActivated = Activated;
411  } else {
412  mAccessKeyActivated = NotActivated;
413  }
414  }
415  SuperClass::keyReleaseEvent(e);
416 }
417 
418 void MailWebView::keyPressEvent(QKeyEvent*e)
419 {
420  if (e && hasFocus()) {
421  if (GlobalSettings::self()->accessKeyEnabled()) {
422  if (mAccessKeyActivated == Activated) {
423  if (checkForAccessKey(e)) {
424  hideAccessKeys();
425  e->accept();
426  return;
427  }
428  hideAccessKeys();
429  } else if (e->key() == Qt::Key_Control && e->modifiers() == Qt::ControlModifier && !isEditableElement(page())) {
430  mAccessKeyActivated = PreActivated; // Only preactive here, it will be actually activated in key release.
431  }
432  }
433  }
434  SuperClass::keyPressEvent(e);
435 }
436 
437 void MailWebView::wheelEvent(QWheelEvent* e)
438 {
439  if (GlobalSettings::self()->accessKeyEnabled() && mAccessKeyActivated == PreActivated && (e->modifiers() & Qt::ControlModifier)) {
440  mAccessKeyActivated = NotActivated;
441  }
442  SuperClass::wheelEvent(e);
443 }
444 
445 bool MailWebView::checkForAccessKey(QKeyEvent *event)
446 {
447  if (mAccessKeyLabels.isEmpty())
448  return false;
449  QString text = event->text();
450  if (text.isEmpty())
451  return false;
452  QChar key = text.at(0).toUpper();
453  bool handled = false;
454  if (mAccessKeyNodes.contains(key)) {
455  QWebElement element = mAccessKeyNodes[key];
456  QPoint p = element.geometry().center();
457  QWebFrame *frame = element.webFrame();
458  Q_ASSERT(frame);
459  do {
460  p -= frame->scrollPosition();
461  frame = frame->parentFrame();
462  } while (frame && frame != page()->mainFrame());
463  QMouseEvent pevent(QEvent::MouseButtonPress, p, Qt::LeftButton, 0, 0);
464  QCoreApplication::sendEvent(this, &pevent);
465  QMouseEvent revent(QEvent::MouseButtonRelease, p, Qt::LeftButton, 0, 0);
466  QCoreApplication::sendEvent(this, &revent);
467  handled = true;
468  }
469  return handled;
470 }
471 
472 void MailWebView::hideAccessKeys()
473 {
474  if (!mAccessKeyLabels.isEmpty()) {
475  for (int i = 0, count = mAccessKeyLabels.count(); i < count; ++i) {
476  QLabel *label = mAccessKeyLabels[i];
477  label->hide();
478  label->deleteLater();
479  }
480  mAccessKeyLabels.clear();
481  mAccessKeyNodes.clear();
482  mDuplicateLinkElements.clear();
483  mAccessKeyActivated = NotActivated;
484  update();
485  }
486 }
487 
488 
489 void MailWebView::showAccessKeys()
490 {
491  QList<QChar> unusedKeys;
492  for (char c = 'A'; c <= 'Z'; ++c) {
493  unusedKeys << QLatin1Char(c);
494  }
495  for (char c = '0'; c <= '9'; ++c) {
496  unusedKeys << QLatin1Char(c);
497  }
498  if (mActionCollection) {
499  Q_FOREACH(QAction*act, mActionCollection->actions()) {
500  KAction *a = qobject_cast<KAction*>(act);
501  if(a) {
502  const KShortcut shortCut = a->shortcut();
503  if(!shortCut.isEmpty()) {
504  Q_FOREACH(const QChar& c, unusedKeys) {
505  if(shortCut.conflictsWith(QKeySequence(c))) {
506  unusedKeys.removeOne(c);
507  }
508  }
509  }
510  }
511  }
512  }
513 
514  QList<QWebElement> unLabeledElements;
515  QRect viewport = QRect(page()->mainFrame()->scrollPosition(), page()->viewportSize());
516  const QString selectorQuery (QLatin1String("a[href],"
517  "area,"
518  "button:not([disabled]),"
519  "input:not([disabled]):not([hidden]),"
520  "label[for],"
521  "legend,"
522  "select:not([disabled]),"
523  "textarea:not([disabled])"));
524  QList<QWebElement> result = page()->mainFrame()->findAllElements(selectorQuery).toList();
525 
526  // Priority first goes to elements with accesskey attributes
527  Q_FOREACH (const QWebElement& element, result) {
528  const QRect geometry = element.geometry();
529  if (geometry.size().isEmpty() || !viewport.contains(geometry.topLeft())) {
530  continue;
531  }
532  if (isHiddenElement(element)) {
533  continue; // Do not show access key for hidden elements...
534  }
535  const QString accessKeyAttribute (element.attribute(QLatin1String("accesskey")).toUpper());
536  if (accessKeyAttribute.isEmpty()) {
537  unLabeledElements.append(element);
538  continue;
539  }
540  QChar accessKey;
541  for (int i = 0; i < accessKeyAttribute.count(); i+=2) {
542  const QChar &possibleAccessKey = accessKeyAttribute[i];
543  if (unusedKeys.contains(possibleAccessKey)) {
544  accessKey = possibleAccessKey;
545  break;
546  }
547  }
548  if (accessKey.isNull()) {
549  unLabeledElements.append(element);
550  continue;
551  }
552 
553  handleDuplicateLinkElements(element, &mDuplicateLinkElements, &accessKey);
554  if (!accessKey.isNull()) {
555  unusedKeys.removeOne(accessKey);
556  makeAccessKeyLabel(accessKey, element);
557  }
558  }
559 
560 
561  // Pick an access key first from the letters in the text and then from the
562  // list of unused access keys
563  Q_FOREACH (const QWebElement &element, unLabeledElements) {
564  const QRect geometry = element.geometry();
565  if (unusedKeys.isEmpty()
566  || geometry.size().isEmpty()
567  || !viewport.contains(geometry.topLeft()))
568  continue;
569  QChar accessKey;
570  const QString text = element.toPlainText().toUpper();
571  for (int i = 0; i < text.count(); ++i) {
572  const QChar &c = text.at(i);
573  if (unusedKeys.contains(c)) {
574  accessKey = c;
575  break;
576  }
577  }
578  if (accessKey.isNull())
579  accessKey = unusedKeys.takeFirst();
580 
581  handleDuplicateLinkElements(element, &mDuplicateLinkElements, &accessKey);
582  if (!accessKey.isNull()) {
583  unusedKeys.removeOne(accessKey);
584  makeAccessKeyLabel(accessKey, element);
585  }
586  }
587 
588  mAccessKeyActivated = (mAccessKeyLabels.isEmpty() ? Activated : NotActivated);
589 }
590 
591 void MailWebView::makeAccessKeyLabel(const QChar &accessKey, const QWebElement &element)
592 {
593  QLabel *label = new QLabel(this);
594  QFont font (label->font());
595  font.setBold(true);
596  label->setFont(font);
597  label->setText(accessKey);
598  label->setPalette(QToolTip::palette());
599  label->setAutoFillBackground(true);
600  label->setFrameStyle(QFrame::Box | QFrame::Plain);
601  QPoint point = element.geometry().center();
602  point -= page()->mainFrame()->scrollPosition();
603  label->move(point);
604  label->show();
605  point.setX(point.x() - label->width() / 2);
606  label->move(point);
607  mAccessKeyLabels.append(label);
608  mAccessKeyNodes.insertMulti(accessKey, element);
609 }
610 
611 void MailWebView::scamCheck()
612 {
613  QWebFrame *mainFrame = page()->mainFrame();
614  mScamDetection->scanPage(mainFrame);
615 }
616 
617 void MailWebView::slotShowDetails()
618 {
619  mScamDetection->showDetails();
620 }
621 
622 void MailWebView::saveMainFrameScreenshotInFile(const QString &filename)
623 {
624  QWebFrame *frame = page()->mainFrame();
625  QImage image(frame->contentsSize(), QImage::Format_ARGB32_Premultiplied);
626  image.fill(Qt::transparent);
627 
628  QPainter painter(&image);
629  painter.setRenderHint(QPainter::Antialiasing, true);
630  painter.setRenderHint(QPainter::TextAntialiasing, true);
631  painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
632  frame->documentElement().render(&painter);
633  painter.end();
634  image.save(filename);
635 }
636 
637 void MailWebView::openBlockableItemsDialog()
638 {
639  QPointer<AdBlockBlockableItemsDialog> dlg = new AdBlockBlockableItemsDialog(this);
640  dlg->setWebFrame(page()->mainFrame());
641  if (dlg->exec()) {
642  dlg->saveFilters();
643  }
644  delete dlg;
645 }
646 
647 void MailWebView::expandUrl(const KUrl &url)
648 {
649  mScamDetection->scamCheckShortUrl()->expandedUrl(url);
650 }
651 
652 bool MailWebView::isAShortUrl(const KUrl &url) const
653 {
654  return mScamDetection->scamCheckShortUrl()->isShortUrl(url);
655 }
656 
657 #include "moc_mailwebview.cpp"
QWebFrame::parentFrame
QWebFrame * parentFrame() const
MessageViewer::ScamCheckShortUrl::expandedUrl
void expandedUrl(const KUrl &url)
Definition: scamcheckshorturl.cpp:54
convert_flags
static QWebPage::FindFlags convert_flags(MailWebView::FindFlags f)
Definition: mailwebview_webkit.cpp:378
QList::clear
void clear()
QEvent
QWebFrame::baseUrl
baseUrl
MessageViewer::WebPage
Definition: webpage.h:25
QWidget
QWebElement::setAttribute
void setAttribute(const QString &name, const QString &value)
QKeyEvent::modifiers
Qt::KeyboardModifiers modifiers() const
QRect::size
QSize size() const
QEvent::type
Type type() const
QWidget::setPalette
void setPalette(const QPalette &)
QHash::insert
iterator insert(const Key &key, const T &value)
MessageViewer::MailWebView::selectedText
QString selectedText() const
Definition: mailwebview_textbrowser.cpp:109
QPoint::ry
int & ry()
QString::toUpper
QString toUpper() const
QWebFrame
QPainter::end
bool end()
QWebFrame::documentElement
QWebElement documentElement() const
has_parent_div_with_id
static bool has_parent_div_with_id(const QWebElement &start, const QString &id)
Definition: mailwebview_webkit.cpp:254
QPainter::setRenderHint
void setRenderHint(RenderHint hint, bool on)
QWebPage::FindFlags
typedef FindFlags
QSize::isEmpty
bool isEmpty() const
QWebElement::setStyleProperty
void setStyleProperty(const QString &name, const QString &value)
MessageViewer::MailWebView::selectAll
void selectAll()
Definition: mailwebview_textbrowser.cpp:141
QChar
QFont
MessageViewer::MailWebView::relativePosition
double relativePosition() const
Definition: mailwebview_textbrowser.cpp:122
QWebElement::styleProperty
QString styleProperty(const QString &name, StyleResolveStrategy strategy) const
QPointer
QWheelEvent
QWebHitTestResult::imageUrl
QUrl imageUrl() const
QWebHitTestResult::enclosingBlockElement
QWebElement enclosingBlockElement() const
QWebHitTestResult
MessageViewer::ScamDetection
Definition: scamdetection.h:31
QPoint
QMouseEvent
QFrame::setFrameStyle
void setFrameStyle(int style)
QWebElement::tagName
QString tagName() const
QUrl::isEmpty
bool isEmpty() const
isHiddenElement
static bool isHiddenElement(const QWebElement &element)
Definition: mailwebview_webkit.cpp:62
QUrl::toString
QString toString(QFlags< QUrl::FormattingOption > options) const
MessageViewer::MailWebView::scrollUp
void scrollUp(int pixels)
Definition: mailwebview_textbrowser.cpp:80
MessageViewer::MailWebView::markAttachment
void markAttachment(const QString &id, const QString &style)
Definition: mailwebview_textbrowser.cpp:181
isEditableElement
static bool isEditableElement(QWebPage *page)
Definition: mailwebview_webkit.cpp:87
MessageViewer::ScamDetection::showDetails
void showDetails()
Definition: scamdetection.cpp:149
QWebElement::webFrame
QWebFrame * webFrame() const
QPoint::x
int x() const
MessageViewer::MailWebView::hasVerticalScrollBar
bool hasVerticalScrollBar() const
Definition: mailwebview_textbrowser.cpp:114
MessageViewer::MailWebView::scrollBarPolicy
Qt::ScrollBarPolicy scrollBarPolicy(Qt::Orientation orientation) const
Definition: mailwebview_textbrowser.cpp:234
QWebFrame::hitTestContent
QWebHitTestResult hitTestContent(const QPoint &pos) const
QWidget::width
width
QFont::setBold
void setBold(bool enable)
QRect
MessageViewer::MailWebView::FindBackward
Definition: mailwebview.h:58
QWebElement::hasAttribute
bool hasAttribute(const QString &name) const
MessageViewer::MailWebView::setHtml
void setHtml(const QString &html, const QUrl &baseUrl)
Definition: mailwebview_textbrowser.cpp:189
MessageViewer::MailWebView::event
virtual bool event(QEvent *event)
Reimplemented to catch context menu events and emit popupMenu()
Definition: mailwebview_textbrowser.cpp:55
QList::count
int count(const T &value) const
QList::append
void append(const T &value)
MessageViewer::ScamCheckShortUrl::isShortUrl
static bool isShortUrl(const KUrl &url)
Definition: scamcheckshorturl.cpp:102
MessageViewer::MailWebView::FindWrapsAroundDocument
Definition: mailwebview.h:57
QImage::fill
void fill(uint pixelValue)
QHash< QString, QChar >
MessageViewer::MailWebView::openBlockableItemsDialog
void openBlockableItemsDialog()
Definition: mailwebview_webkit.cpp:637
MessageViewer::MailWebView::clearFindSelection
void clearFindSelection()
Definition: mailwebview_textbrowser.cpp:299
MessageViewer::ScamDetection::scanPage
void scanPage(QWebFrame *frame)
Definition: scamdetection.cpp:50
MessageViewer::MailWebView::scrollToAnchor
void scrollToAnchor(const QString &anchor)
Definition: mailwebview_textbrowser.cpp:168
QContextMenuEvent
MessageViewer::MailWebView::wheelEvent
virtual void wheelEvent(QWheelEvent *e)
Definition: mailwebview_textbrowser.cpp:314
MessageViewer::MailWebView::removeAttachmentMarking
bool removeAttachmentMarking(const QString &id)
Definition: mailwebview_textbrowser.cpp:173
scamdetection.h
QWebElement::render
void render(QPainter *painter)
QWebElement
QString::toInt
int toInt(bool *ok, int base) const
QList::isEmpty
bool isEmpty() const
QPainter
MessageViewer::MailWebView::scrollToRelativePosition
void scrollToRelativePosition(double pos)
Definition: mailwebview_textbrowser.cpp:133
QString::isEmpty
bool isEmpty() const
MessageViewer::MailWebView::keyReleaseEvent
virtual void keyReleaseEvent(QKeyEvent *)
Reimplement for access key.
Definition: mailwebview_textbrowser.cpp:304
MessageViewer::GlobalSettings::self
static GlobalSettings * self()
Definition: globalsettings.cpp:34
QCoreApplication::sendEvent
bool sendEvent(QObject *receiver, QEvent *event)
webpage.h
MessageViewer::MailWebView::HighlightAllOccurrences
Definition: mailwebview.h:60
QWebElement::setInnerXml
void setInnerXml(const QString &markup)
QWebPage
MessageViewer::MailWebView::scamCheck
void scamCheck()
Definition: mailwebview_webkit.cpp:611
SuperClass
KWebView SuperClass
Definition: mailwebview_webkit.cpp:42
QWidget::move
void move(int x, int y)
MessageViewer::MailWebView::clearSelection
void clearSelection()
Definition: mailwebview_textbrowser.cpp:146
QRect::center
QPoint center() const
QObject::deleteLater
void deleteLater()
QRect::contains
bool contains(const QPoint &point, bool proper) const
QLabel::setText
void setText(const QString &)
MessageViewer::MailWebView::FindCaseSensitively
Definition: mailwebview.h:59
QString
QList
QWidget::hide
void hide()
QWebHitTestResult::linkUrl
QUrl linkUrl() const
MessageViewer::MailWebView::isAShortUrl
bool isAShortUrl(const KUrl &url) const
Definition: mailwebview_textbrowser.cpp:332
linkElementKey
static QString linkElementKey(const QWebElement &element)
Definition: mailwebview_webkit.cpp:47
adblockblockableitemsdialog.h
QWebElement::isNull
bool isNull() const
MessageViewer::AdBlockBlockableItemsDialog
Definition: adblockblockableitemsdialog.h:25
QInputEvent::modifiers
Qt::KeyboardModifiers modifiers() const
QChar::isNull
bool isNull() const
QHash::clear
void clear()
QString::toLower
QString toLower() const
QHash::value
const T value(const Key &key) const
QKeyEvent::key
int key() const
QWebElement::attribute
QString attribute(const QString &name, const QString &defaultValue) const
QEvent::accept
void accept()
QPixmap::isNull
bool isNull() const
scamcheckshorturl.h
QUrl
QLatin1Char
QWebFrame::findFirstElement
QWebElement findFirstElement(const QString &selectorQuery) const
QWidget::font
font
MessageViewer::MailWebView::slotShowDetails
void slotShowDetails()
Definition: mailwebview_textbrowser.cpp:323
QList::contains
bool contains(const T &value) const
QImage
MessageViewer::MailWebView::linkOrImageUrlAt
QUrl linkOrImageUrlAt(const QPoint &global) const
Definition: mailwebview_textbrowser.cpp:208
QWebElement::findFirst
QWebElement findFirst(const QString &selectorQuery) const
QKeyEvent
type
const char * type
Definition: bodypartformatter.cpp:192
QWebElement::toPlainText
QString toPlainText() const
QContextMenuEvent::pos
const QPoint & pos() const
MessageViewer::MailWebView::setScrollBarPolicy
void setScrollBarPolicy(Qt::Orientation orientation, Qt::ScrollBarPolicy policy)
Definition: mailwebview_textbrowser.cpp:219
MessageViewer::ScamDetection::scamCheckShortUrl
ScamCheckShortUrl * scamCheckShortUrl() const
Definition: scamdetection.cpp:45
QList::takeFirst
T takeFirst()
QChar::toUpper
QChar toUpper() const
MessageViewer::MailWebView::injectAttachments
void injectAttachments(const boost::function< QString()> &delayedHtml)
Definition: mailwebview_textbrowser.cpp:161
QLatin1String
QKeySequence
QToolTip::palette
QPalette palette()
QString::count
int count() const
QString::at
const QChar at(int position) const
QWebElement::removeAttribute
void removeAttribute(const QString &name)
QWebHitTestResult::pixmap
QPixmap pixmap() const
QAction
QWebElement::evaluateJavaScript
QVariant evaluateJavaScript(const QString &scriptSource)
mailwebview.h
MessageViewer::MailWebView::isScrolledToBottom
bool isScrolledToBottom() const
Definition: mailwebview_textbrowser.cpp:85
MessageViewer::MailWebView::popupMenu
void popupMenu(const QUrl &url, const QUrl &imageUrl, const QPoint &point)
Emitted when the user right-clicks somewhere.
MessageViewer::MailWebView::scrollPageDown
void scrollPageDown(int percent)
Definition: mailwebview_textbrowser.cpp:91
QRect::topLeft
QPoint topLeft() const
QPoint::setX
void setX(int x)
QVariant::toBool
bool toBool() const
MessageViewer::MailWebView::setElementByIdVisible
void setElementByIdVisible(const QString &id, bool visible)
Definition: mailwebview_textbrowser.cpp:261
KWebView
MessageViewer::MailWebView::setAllowExternalContent
void setAllowExternalContent(bool allow)
Definition: mailwebview_textbrowser.cpp:201
MessageViewer::MailWebView::replaceInnerHtml
bool replaceInnerHtml(const QString &id, const boost::function< QString()> &delayedHtml)
Definition: mailwebview_textbrowser.cpp:248
QWebFrame::scrollPosition
scrollPosition
QHash::contains
bool contains(const Key &key) const
QWidget::setAutoFillBackground
void setAutoFillBackground(bool enabled)
QWidget::show
void show()
handleDuplicateLinkElements
static void handleDuplicateLinkElements(const QWebElement &element, QHash< QString, QChar > *dupLinkList, QChar *accessKey)
Definition: mailwebview_webkit.cpp:108
QWebPage::currentFrame
QWebFrame * currentFrame() const
QHash::insertMulti
iterator insertMulti(const Key &key, const T &value)
QLabel
QString::compare
int compare(const QString &other) const
QWebElement::parent
QWebElement parent() const
MessageViewer::MailWebView::scrollPageUp
void scrollPageUp(int percent)
Definition: mailwebview_textbrowser.cpp:104
QWebFrame::contentsSize
contentsSize
QList::removeOne
bool removeOne(const T &value)
MessageViewer::MailWebView::saveMainFrameScreenshotInFile
void saveMainFrameScreenshotInFile(const QString &filename)
Definition: mailwebview_webkit.cpp:622
QWebElement::geometry
QRect geometry() const
MessageViewer::MailWebView::expandUrl
void expandUrl(const KUrl &url)
Definition: mailwebview_textbrowser.cpp:327
MessageViewer::MailWebView::isAttachmentInjectionPoint
bool isAttachmentInjectionPoint(const QPoint &globalPos) const
Definition: mailwebview_textbrowser.cpp:153
MessageViewer::MailWebView::htmlSource
QString htmlSource() const
Definition: mailwebview_textbrowser.cpp:196
MessageViewer::MailWebView::keyPressEvent
virtual void keyPressEvent(QKeyEvent *)
Definition: mailwebview_textbrowser.cpp:309
MessageViewer::MailWebView::findText
bool findText(const QString &test, FindFlags flags)
Definition: mailwebview_textbrowser.cpp:294
MessageViewer::MailWebView::scrollDown
void scrollDown(int pixels)
Definition: mailwebview_textbrowser.cpp:74
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:45 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

messageviewer

Skip menu "messageviewer"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal