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

messageviewer

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

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