• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2     Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
3     Copyright (C) 2008 Holger Hans Peter Freyther
4 
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Library General Public
7     License as published by the Free Software Foundation; either
8     version 2 of the License, or (at your option) any later version.
9 
10     This library is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13     Library General Public License for more details.
14 
15     You should have received a copy of the GNU Library General Public License
16     along with this library; see the file COPYING.LIB.  If not, write to
17     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18     Boston, MA 02110-1301, USA.
19 */
20 
21 #include "config.h"
22 #include "qwebview.h"
23 #include "qwebframe.h"
24 #include "qwebpage_p.h"
25 
26 #include "qbitmap.h"
27 #include "qevent.h"
28 #include "qpainter.h"
29 #include "qprinter.h"
30 
31 class QWebViewPrivate
32 {
33 public:
QWebViewPrivate(QWebView * view)34     QWebViewPrivate(QWebView *view)
35         : view(view)
36         , page(0)
37 #ifndef QT_NO_CURSOR
38         , cursorSetByWebCore(false)
39         , usesWebCoreCursor(true)
40 #endif
41     {}
42 
43     QWebView *view;
44     QWebPage *page;
45 
46 
47 #ifndef QT_NO_CURSOR
48     /*
49      * We keep track of if we have called setCursor and if the CursorChange
50      * event is sent due our setCursor call and if we currently use the WebCore
51      * Cursor and use it to decide if we can update to another WebCore Cursor.
52      */
53     bool cursorSetByWebCore;
54     bool usesWebCoreCursor;
55 
setCursor(const QCursor & newCursor)56     void setCursor(const QCursor& newCursor)
57     {
58         webCoreCursor = newCursor;
59 
60         if (usesWebCoreCursor) {
61             cursorSetByWebCore = true;
62             view->setCursor(webCoreCursor);
63         }
64     }
65 
66     QCursor webCoreCursor;
67 #endif
68 };
69 
70 /*!
71     \class QWebView
72     \since 4.4
73     \brief The QWebView class provides a widget that is used to view and edit
74     web documents.
75     \ingroup advanced
76 
77     QWebView is the main widget component of the QtWebKit web browsing module.
78     It can be used in various applications to display web content live from the
79     Internet.
80 
81     The image below shows QWebView previewed in \QD with the Trolltech website.
82 
83     \image qwebview-url.png
84 
85     A web site can be loaded onto QWebView with the load() function. Like all
86     Qt Widgets, the show() function must be invoked in order to display
87     QWebView. The snippet below illustrates this:
88 
89     \snippet doc/src/snippets/webkit/simple/main.cpp Using QWebView
90 
91     Alternatively, setUrl() can also be used to load a web site. If you have
92     the HTML content readily available, you can use setHtml() instead.
93 
94     The loadStarted() signal is emitted when the view begins loading. The
95     loadProgress() signal, on the other hand, is emitted whenever an element of
96     the web view completes loading, such as an embedded image, a script, etc.
97     Finally, the loadFinished() signal is emitted when the view has loaded
98     completely. It's argument - either \c true or \c false - indicates
99     load success or failure.
100 
101     The page() function returns a pointer to the web page object. See
102     \l{Elements of QWebView} for an explanation of how the web page
103     is related to the view. To modify your web view's settings, you can access
104     the QWebSettings object with the settings() function. With QWebSettings,
105     you can change the default fonts, enable or disable features such as
106     JavaScript and plugins.
107 
108     The title of an HTML document can be accessed with the title() property.
109     Additionally, a web site may also specify an icon, which can be accessed
110     using the icon() property. If the title or the icon changes, the corresponding
111     titleChanged() and iconChanged() signals will be emitted. The
112     textSizeMultiplier() property can be used to change the overall size of
113     the text displayed in the web view.
114 
115     If you require a custom context menu, you can implement it by reimplementing
116     \l{QWidget::}{contextMenuEvent()} and populating your QMenu with the actions
117     obtained from pageAction(). More functionality such as reloading the view,
118     copying selected text to the clipboard, or pasting into the view, is also
119     encapsulated within the QAction objects returned by pageAction(). These
120     actions can be programmatically triggered using triggerPageAction().
121     Alternatively, the actions can be added to a toolbar or a menu directly.
122     QWebView maintains the state of the returned actions but allows
123     modification of action properties such as \l{QAction::}{text} or
124     \l{QAction::}{icon}.
125 
126     A QWebView can be printed onto a QPrinter using the print() function.
127     This function is marked as a slot and can be conveniently connected to
128     \l{QPrintPreviewDialog}'s \l{QPrintPreviewDialog::}{paintRequested()}
129     signal.
130 
131     If you want to provide support for web sites that allow the user to open
132     new windows, such as pop-up windows, you can subclass QWebView and
133     reimplement the createWindow() function.
134 
135     \section1 Elements of QWebView
136 
137     QWebView consists of other objects such as QWebFrame and QWebPage. The
138     flowchart below shows these elements are related.
139 
140     \image qwebview-diagram.png
141 
142     \note It is possible to use QWebPage and QWebFrame, without using QWebView,
143     if you do not require QWidget attributes. Nevertheless, QtWebKit depends
144     on QtGui, so you should use a QApplication instead of QCoreApplication.
145 
146     \sa {Previewer Example}, {Browser}
147 */
148 
149 /*!
150     Constructs an empty QWebView with parent \a parent.
151 
152     \sa load()
153 */
QWebView(QWidget * parent)154 QWebView::QWebView(QWidget *parent)
155     : QWidget(parent)
156 {
157     d = new QWebViewPrivate(this);
158 
159 #if !defined(Q_WS_QWS)
160     setAttribute(Qt::WA_InputMethodEnabled);
161 #endif
162 
163     setAcceptDrops(true);
164 
165     setMouseTracking(true);
166     setFocusPolicy(Qt::WheelFocus);
167 }
168 
169 /*!
170     Destroys the web view.
171 */
~QWebView()172 QWebView::~QWebView()
173 {
174     if (d->page)
175         d->page->d->view = 0;
176 
177     if (d->page && d->page->parent() == this)
178         delete d->page;
179     delete d;
180 }
181 
182 /*!
183     Returns a pointer to the underlying web page.
184 
185     \sa setPage()
186 */
page() const187 QWebPage *QWebView::page() const
188 {
189     if (!d->page) {
190         QWebView *that = const_cast<QWebView *>(this);
191         that->setPage(new QWebPage(that));
192     }
193     return d->page;
194 }
195 
196 /*!
197     Makes \a page the new web page of the web view.
198 
199     The parent QObject of the provided page remains the owner
200     of the object. If the current document is a child of the web
201     view, it will be deleted.
202 
203     \sa page()
204 */
setPage(QWebPage * page)205 void QWebView::setPage(QWebPage *page)
206 {
207     if (d->page == page)
208         return;
209     if (d->page) {
210         if (d->page->parent() == this) {
211             delete d->page;
212         } else {
213             d->page->disconnect(this);
214         }
215     }
216     d->page = page;
217     if (d->page) {
218         d->page->setView(this);
219         d->page->setPalette(palette());
220         // #### connect signals
221         QWebFrame *mainFrame = d->page->mainFrame();
222         connect(mainFrame, SIGNAL(titleChanged(const QString&)),
223                 this, SIGNAL(titleChanged(const QString&)));
224         connect(mainFrame, SIGNAL(iconChanged()),
225                 this, SIGNAL(iconChanged()));
226         connect(mainFrame, SIGNAL(urlChanged(const QUrl &)),
227                 this, SIGNAL(urlChanged(const QUrl &)));
228 
229         connect(d->page, SIGNAL(loadStarted()),
230                 this, SIGNAL(loadStarted()));
231         connect(d->page, SIGNAL(loadProgress(int)),
232                 this, SIGNAL(loadProgress(int)));
233         connect(d->page, SIGNAL(loadFinished(bool)),
234                 this, SIGNAL(loadFinished(bool)));
235         connect(d->page, SIGNAL(statusBarMessage(const QString &)),
236                 this, SIGNAL(statusBarMessage(const QString &)));
237         connect(d->page, SIGNAL(linkClicked(const QUrl &)),
238                 this, SIGNAL(linkClicked(const QUrl &)));
239 
240         connect(d->page, SIGNAL(microFocusChanged()),
241                 this, SLOT(updateMicroFocus()));
242     }
243     setAttribute(Qt::WA_OpaquePaintEvent, d->page);
244     update();
245 }
246 
247 /*!
248     Loads the specified \a url and displays it.
249 
250     \note The view remains the same until enough data has arrived to display the new \a url.
251 
252     \sa setUrl(), url(), urlChanged()
253 */
load(const QUrl & url)254 void QWebView::load(const QUrl &url)
255 {
256     page()->mainFrame()->load(url);
257 }
258 
259 /*!
260     \fn void QWebView::load(const QNetworkRequest &request, QNetworkAccessManager::Operation operation, const QByteArray &body)
261 
262     Loads a network request, \a request, using the method specified in \a operation.
263 
264     \a body is optional and is only used for POST operations.
265 
266     \note The view remains the same until enough data has arrived to display the new url.
267 
268     \sa url(), urlChanged()
269 */
270 
271 #if QT_VERSION < 0x040400 && !defined(qdoc)
load(const QWebNetworkRequest & request)272 void QWebView::load(const QWebNetworkRequest &request)
273 #else
274 void QWebView::load(const QNetworkRequest &request,
275                     QNetworkAccessManager::Operation operation,
276                     const QByteArray &body)
277 #endif
278 {
279     page()->mainFrame()->load(request
280 #if QT_VERSION >= 0x040400
281                               , operation, body
282 #endif
283                              );
284 }
285 
286 /*!
287     Sets the content of the web view to the specified \a html.
288 
289     External objects such as stylesheets or images referenced in the HTML
290     document are located relative to \a baseUrl.
291 
292     When using this method, WebKit assumes that external resources such as
293     JavaScript programs or style sheets are encoded in UTF-8 unless otherwise
294     specified. For example, the encoding of an external script can be specified
295     through the charset attribute of the HTML script tag. Alternatively, the
296     encoding can also be specified by the web server.
297 
298     \sa load(), setContent(), QWebFrame::toHtml()
299 */
setHtml(const QString & html,const QUrl & baseUrl)300 void QWebView::setHtml(const QString &html, const QUrl &baseUrl)
301 {
302     page()->mainFrame()->setHtml(html, baseUrl);
303 }
304 
305 /*!
306     Sets the content of the web view to the specified content \a data. If the \a mimeType argument
307     is empty it is currently assumed that the content is HTML but in future versions we may introduce
308     auto-detection.
309 
310     External objects referenced in the content are located relative to \a baseUrl.
311 
312     \sa load(), setHtml(), QWebFrame::toHtml()
313 */
setContent(const QByteArray & data,const QString & mimeType,const QUrl & baseUrl)314 void QWebView::setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl)
315 {
316     page()->mainFrame()->setContent(data, mimeType, baseUrl);
317 }
318 
319 /*!
320     Returns a pointer to the view's history of navigated web pages.
321 
322     It is equivalent to
323 
324     \snippet doc/src/snippets/code/src_3rdparty_webkit_WebKit_qt_Api_qwebview.cpp 0
325 */
history() const326 QWebHistory *QWebView::history() const
327 {
328     return page()->history();
329 }
330 
331 /*!
332     Returns a pointer to the view/page specific settings object.
333 
334     It is equivalent to
335 
336     \snippet doc/src/snippets/code/src_3rdparty_webkit_WebKit_qt_Api_qwebview.cpp 1
337 
338     \sa QWebSettings::globalSettings()
339 */
settings() const340 QWebSettings *QWebView::settings() const
341 {
342     return page()->settings();
343 }
344 
345 /*!
346     \property QWebView::title
347     \brief the title of the web page currently viewed
348 
349     By default, this property contains an empty string.
350 
351     \sa titleChanged()
352 */
title() const353 QString QWebView::title() const
354 {
355     if (d->page)
356         return d->page->mainFrame()->title();
357     return QString();
358 }
359 
360 /*!
361     \property QWebView::url
362     \brief the url of the web page currently viewed
363 
364     Setting this property clears the view and loads the URL.
365 
366     By default, this property contains an empty, invalid URL.
367 
368     \sa load(), urlChanged()
369 */
370 
setUrl(const QUrl & url)371 void QWebView::setUrl(const QUrl &url)
372 {
373     page()->mainFrame()->setUrl(url);
374 }
375 
url() const376 QUrl QWebView::url() const
377 {
378     if (d->page)
379         return d->page->mainFrame()->url();
380     return QUrl();
381 }
382 
383 /*!
384     \property QWebView::icon
385     \brief the icon associated with the web page currently viewed
386 
387     By default, this property contains a null icon.
388 
389     \sa iconChanged(), QWebSettings::iconForUrl()
390 */
icon() const391 QIcon QWebView::icon() const
392 {
393     if (d->page)
394         return d->page->mainFrame()->icon();
395     return QIcon();
396 }
397 
398 /*!
399     \property QWebView::selectedText
400     \brief the text currently selected
401 
402     By default, this property contains an empty string.
403 
404     \sa findText(), selectionChanged()
405 */
selectedText() const406 QString QWebView::selectedText() const
407 {
408     if (d->page)
409         return d->page->selectedText();
410     return QString();
411 }
412 
413 /*!
414     Returns a pointer to a QAction that encapsulates the specified web action \a action.
415 */
pageAction(QWebPage::WebAction action) const416 QAction *QWebView::pageAction(QWebPage::WebAction action) const
417 {
418     return page()->action(action);
419 }
420 
421 /*!
422     Triggers the specified \a action. If it is a checkable action the specified
423     \a checked state is assumed.
424 
425     The following example triggers the copy action and therefore copies any
426     selected text to the clipboard.
427 
428     \snippet doc/src/snippets/code/src_3rdparty_webkit_WebKit_qt_Api_qwebview.cpp 2
429 
430     \sa pageAction()
431 */
triggerPageAction(QWebPage::WebAction action,bool checked)432 void QWebView::triggerPageAction(QWebPage::WebAction action, bool checked)
433 {
434     page()->triggerAction(action, checked);
435 }
436 
437 /*!
438     \property QWebView::modified
439     \brief whether the document was modified by the user
440 
441     Parts of HTML documents can be editable for example through the
442     \c{contenteditable} attribute on HTML elements.
443 
444     By default, this property is false.
445 */
isModified() const446 bool QWebView::isModified() const
447 {
448     if (d->page)
449         return d->page->isModified();
450     return false;
451 }
452 
453 /*
454 Qt::TextInteractionFlags QWebView::textInteractionFlags() const
455 {
456     // ### FIXME (add to page)
457     return Qt::TextInteractionFlags();
458 }
459 */
460 
461 /*
462     \property QWebView::textInteractionFlags
463     \brief how the view should handle user input
464 
465     Specifies how the user can interact with the text on the page.
466 */
467 
468 /*
469 void QWebView::setTextInteractionFlags(Qt::TextInteractionFlags flags)
470 {
471     Q_UNUSED(flags)
472     // ### FIXME (add to page)
473 }
474 */
475 
476 /*!
477     \reimp
478 */
sizeHint() const479 QSize QWebView::sizeHint() const
480 {
481     return QSize(800, 600); // ####...
482 }
483 
484 /*!
485     \property QWebView::zoomFactor
486     \since 4.5
487     \brief the zoom factor for the view
488 */
489 
setZoomFactor(qreal factor)490 void QWebView::setZoomFactor(qreal factor)
491 {
492     page()->mainFrame()->setZoomFactor(factor);
493 }
494 
zoomFactor() const495 qreal QWebView::zoomFactor() const
496 {
497     return page()->mainFrame()->zoomFactor();
498 }
499 
500 /*!
501   \property QWebView::textSizeMultiplier
502   \brief the scaling factor for all text in the frame
503   \obsolete
504 
505   Use setZoomFactor instead, in combination with the
506   ZoomTextOnly attribute in QWebSettings.
507 
508   \note Setting this property also enables the
509   ZoomTextOnly attribute in QWebSettings.
510 
511   By default, this property contains a value of 1.0.
512 */
513 
514 /*!
515     Sets the value of the multiplier used to scale the text in a Web page to
516     the \a factor specified.
517 */
setTextSizeMultiplier(qreal factor)518 void QWebView::setTextSizeMultiplier(qreal factor)
519 {
520     page()->mainFrame()->setTextSizeMultiplier(factor);
521 }
522 
523 /*!
524     Returns the value of the multiplier used to scale the text in a Web page.
525 */
textSizeMultiplier() const526 qreal QWebView::textSizeMultiplier() const
527 {
528     return page()->mainFrame()->textSizeMultiplier();
529 }
530 
531 /*!
532     Finds the next occurrence of the string, \a subString, in the page, using
533     the given \a options. Returns true of \a subString was found and selects
534     the match visually; otherwise returns false.
535 
536     \sa selectedText(), selectionChanged()
537 */
findText(const QString & subString,QWebPage::FindFlags options)538 bool QWebView::findText(const QString &subString, QWebPage::FindFlags options)
539 {
540     if (d->page)
541         return d->page->findText(subString, options);
542     return false;
543 }
544 
545 /*! \reimp
546 */
event(QEvent * e)547 bool QWebView::event(QEvent *e)
548 {
549     if (d->page) {
550 #ifndef QT_NO_CONTEXTMENU
551         if (e->type() == QEvent::ContextMenu) {
552             if (!isEnabled())
553                 return false;
554             QContextMenuEvent *event = static_cast<QContextMenuEvent *>(e);
555             if (d->page->swallowContextMenuEvent(event)) {
556                 e->accept();
557                 return true;
558             }
559             d->page->updatePositionDependentActions(event->pos());
560         } else
561 #endif // QT_NO_CONTEXTMENU
562         if (e->type() == QEvent::ShortcutOverride) {
563             d->page->event(e);
564 #ifndef QT_NO_CURSOR
565         } else if (e->type() == static_cast<QEvent::Type>(WebCore::SetCursorEvent::EventType)) {
566             d->setCursor(static_cast<WebCore::SetCursorEvent*>(e)->cursor());
567 #if QT_VERSION >= 0x040400
568         } else if (e->type() == QEvent::CursorChange) {
569             // Okay we might use the WebCore Cursor now.
570             d->usesWebCoreCursor = d->cursorSetByWebCore;
571             d->cursorSetByWebCore = false;
572 
573             // Go back to the WebCore Cursor. QWidget::unsetCursor is appromixated with this
574             if (!d->usesWebCoreCursor && cursor().shape() == Qt::ArrowCursor) {
575                 d->usesWebCoreCursor = true;
576                 d->setCursor(d->webCoreCursor);
577             }
578 #endif
579 #endif
580         } else if (e->type() == QEvent::Leave) {
581             d->page->event(e);
582         }
583     }
584 
585     return QWidget::event(e);
586 }
587 
588 /*!
589     Prints the main frame to the given \a printer.
590 
591     \sa QWebFrame::print(), QPrintPreviewDialog
592 */
print(QPrinter * printer) const593 void QWebView::print(QPrinter *printer) const
594 {
595 #ifndef QT_NO_PRINTER
596     page()->mainFrame()->print(printer);
597 #endif
598 }
599 
600 /*!
601     Convenience slot that stops loading the document.
602 
603     It is equivalent to
604 
605     \snippet doc/src/snippets/code/src_3rdparty_webkit_WebKit_qt_Api_qwebview.cpp 3
606 
607     \sa reload(), pageAction(), loadFinished()
608 */
stop()609 void QWebView::stop()
610 {
611     if (d->page)
612         d->page->triggerAction(QWebPage::Stop);
613 }
614 
615 /*!
616     Convenience slot that loads the previous document in the list of documents
617     built by navigating links. Does nothing if there is no previous document.
618 
619     It is equivalent to
620 
621     \snippet doc/src/snippets/code/src_3rdparty_webkit_WebKit_qt_Api_qwebview.cpp 4
622 
623     \sa forward(), pageAction()
624 */
back()625 void QWebView::back()
626 {
627     if (d->page)
628         d->page->triggerAction(QWebPage::Back);
629 }
630 
631 /*!
632     Convenience slot that loads the next document in the list of documents
633     built by navigating links. Does nothing if there is no next document.
634 
635     It is equivalent to
636 
637     \snippet doc/src/snippets/code/src_3rdparty_webkit_WebKit_qt_Api_qwebview.cpp 5
638 
639     \sa back(), pageAction()
640 */
forward()641 void QWebView::forward()
642 {
643     if (d->page)
644         d->page->triggerAction(QWebPage::Forward);
645 }
646 
647 /*!
648     Reloads the current document.
649 
650     \sa stop(), pageAction(), loadStarted()
651 */
reload()652 void QWebView::reload()
653 {
654     if (d->page)
655         d->page->triggerAction(QWebPage::Reload);
656 }
657 
658 /*! \reimp
659 */
resizeEvent(QResizeEvent * e)660 void QWebView::resizeEvent(QResizeEvent *e)
661 {
662     if (d->page)
663         d->page->setViewportSize(e->size());
664 }
665 
666 /*! \reimp
667 */
paintEvent(QPaintEvent * ev)668 void QWebView::paintEvent(QPaintEvent *ev)
669 {
670     if (!d->page)
671         return;
672 #ifdef QWEBKIT_TIME_RENDERING
673     QTime time;
674     time.start();
675 #endif
676 
677     QWebFrame *frame = d->page->mainFrame();
678     QPainter p(this);
679 
680     frame->render(&p, ev->region());
681 
682 #ifdef    QWEBKIT_TIME_RENDERING
683     int elapsed = time.elapsed();
684     qDebug()<<"paint event on "<<ev->region()<<", took to render =  "<<elapsed;
685 #endif
686 }
687 
688 /*!
689     This function is called whenever WebKit wants to create a new window of the given \a type, for example as a result of
690     a JavaScript request to open a document in a new window.
691 
692     \sa QWebPage::createWindow()
693 */
createWindow(QWebPage::WebWindowType type)694 QWebView *QWebView::createWindow(QWebPage::WebWindowType type)
695 {
696     Q_UNUSED(type)
697     return 0;
698 }
699 
700 /*! \reimp
701 */
mouseMoveEvent(QMouseEvent * ev)702 void QWebView::mouseMoveEvent(QMouseEvent* ev)
703 {
704     if (d->page) {
705         const bool accepted = ev->isAccepted();
706         d->page->event(ev);
707         ev->setAccepted(accepted);
708     }
709 }
710 
711 /*! \reimp
712 */
mousePressEvent(QMouseEvent * ev)713 void QWebView::mousePressEvent(QMouseEvent* ev)
714 {
715     if (d->page) {
716         const bool accepted = ev->isAccepted();
717         d->page->event(ev);
718         ev->setAccepted(accepted);
719     }
720 }
721 
722 /*! \reimp
723 */
mouseDoubleClickEvent(QMouseEvent * ev)724 void QWebView::mouseDoubleClickEvent(QMouseEvent* ev)
725 {
726     if (d->page) {
727         const bool accepted = ev->isAccepted();
728         d->page->event(ev);
729         ev->setAccepted(accepted);
730     }
731 }
732 
733 /*! \reimp
734 */
mouseReleaseEvent(QMouseEvent * ev)735 void QWebView::mouseReleaseEvent(QMouseEvent* ev)
736 {
737     if (d->page) {
738         const bool accepted = ev->isAccepted();
739         d->page->event(ev);
740         ev->setAccepted(accepted);
741     }
742 }
743 
744 #ifndef QT_NO_CONTEXTMENU
745 /*! \reimp
746 */
contextMenuEvent(QContextMenuEvent * ev)747 void QWebView::contextMenuEvent(QContextMenuEvent* ev)
748 {
749     if (d->page) {
750         const bool accepted = ev->isAccepted();
751         d->page->event(ev);
752         ev->setAccepted(accepted);
753     }
754 }
755 #endif // QT_NO_CONTEXTMENU
756 
757 #ifndef QT_NO_WHEELEVENT
758 /*! \reimp
759 */
wheelEvent(QWheelEvent * ev)760 void QWebView::wheelEvent(QWheelEvent* ev)
761 {
762     if (d->page) {
763         const bool accepted = ev->isAccepted();
764         d->page->event(ev);
765         ev->setAccepted(accepted);
766     }
767 }
768 #endif // QT_NO_WHEELEVENT
769 
770 /*! \reimp
771 */
keyPressEvent(QKeyEvent * ev)772 void QWebView::keyPressEvent(QKeyEvent* ev)
773 {
774     if (d->page)
775         d->page->event(ev);
776     if (!ev->isAccepted())
777         QWidget::keyPressEvent(ev);
778 }
779 
780 /*! \reimp
781 */
keyReleaseEvent(QKeyEvent * ev)782 void QWebView::keyReleaseEvent(QKeyEvent* ev)
783 {
784     if (d->page)
785         d->page->event(ev);
786     if (!ev->isAccepted())
787         QWidget::keyReleaseEvent(ev);
788 }
789 
790 /*! \reimp
791 */
focusInEvent(QFocusEvent * ev)792 void QWebView::focusInEvent(QFocusEvent* ev)
793 {
794     if (d->page)
795         d->page->event(ev);
796     else
797         QWidget::focusInEvent(ev);
798 }
799 
800 /*! \reimp
801 */
focusOutEvent(QFocusEvent * ev)802 void QWebView::focusOutEvent(QFocusEvent* ev)
803 {
804     if (d->page)
805         d->page->event(ev);
806     else
807         QWidget::focusOutEvent(ev);
808 }
809 
810 /*! \reimp
811 */
dragEnterEvent(QDragEnterEvent * ev)812 void QWebView::dragEnterEvent(QDragEnterEvent* ev)
813 {
814 #ifndef QT_NO_DRAGANDDROP
815     if (d->page)
816         d->page->event(ev);
817 #endif
818 }
819 
820 /*! \reimp
821 */
dragLeaveEvent(QDragLeaveEvent * ev)822 void QWebView::dragLeaveEvent(QDragLeaveEvent* ev)
823 {
824 #ifndef QT_NO_DRAGANDDROP
825     if (d->page)
826         d->page->event(ev);
827 #endif
828 }
829 
830 /*! \reimp
831 */
dragMoveEvent(QDragMoveEvent * ev)832 void QWebView::dragMoveEvent(QDragMoveEvent* ev)
833 {
834 #ifndef QT_NO_DRAGANDDROP
835     if (d->page)
836         d->page->event(ev);
837 #endif
838 }
839 
840 /*! \reimp
841 */
dropEvent(QDropEvent * ev)842 void QWebView::dropEvent(QDropEvent* ev)
843 {
844 #ifndef QT_NO_DRAGANDDROP
845     if (d->page)
846         d->page->event(ev);
847 #endif
848 }
849 
850 /*! \reimp
851 */
focusNextPrevChild(bool next)852 bool QWebView::focusNextPrevChild(bool next)
853 {
854     if (d->page && d->page->focusNextPrevChild(next))
855         return true;
856     return QWidget::focusNextPrevChild(next);
857 }
858 
859 /*!\reimp
860 */
inputMethodQuery(Qt::InputMethodQuery property) const861 QVariant QWebView::inputMethodQuery(Qt::InputMethodQuery property) const
862 {
863     if (d->page)
864         return d->page->inputMethodQuery(property);
865     return QVariant();
866 }
867 
868 /*!\reimp
869 */
inputMethodEvent(QInputMethodEvent * e)870 void QWebView::inputMethodEvent(QInputMethodEvent *e)
871 {
872     if (d->page)
873        d->page->event(e);
874 }
875 
876 /*!\reimp
877 */
changeEvent(QEvent * e)878 void QWebView::changeEvent(QEvent *e)
879 {
880     if (d->page && e->type() == QEvent::PaletteChange) {
881         d->page->setPalette(palette());
882     }
883     QWidget::changeEvent(e);
884 }
885 
886 /*!
887     \fn void QWebView::titleChanged(const QString &title)
888 
889     This signal is emitted whenever the \a title of the main frame changes.
890 
891     \sa title()
892 */
893 
894 /*!
895     \fn void QWebView::urlChanged(const QUrl &url)
896 
897     This signal is emitted when the \a url of the view changes.
898 
899     \sa url(), load()
900 */
901 
902 /*!
903     \fn void QWebView::statusBarMessage(const QString& text)
904 
905     This signal is emitted when the statusbar \a text is changed by the page.
906 */
907 
908 /*!
909     \fn void QWebView::iconChanged()
910 
911     This signal is emitted whenever the icon of the page is loaded or changes.
912 
913     \sa icon()
914 */
915 
916 /*!
917     \fn void QWebView::loadStarted()
918 
919     This signal is emitted when a new load of the page is started.
920 
921     \sa loadProgress(), loadFinished()
922 */
923 
924 /*!
925     \fn void QWebView::loadFinished(bool ok)
926 
927     This signal is emitted when a load of the page is finished.
928     \a ok will indicate whether the load was successful or any error occurred.
929 
930     \sa loadStarted()
931 */
932 
933 /*!
934     \fn void QWebView::selectionChanged()
935 
936     This signal is emitted whenever the selection changes.
937 
938     \sa selectedText()
939 */
940 
941 /*!
942     \fn void QWebView::loadProgress(int progress)
943 
944     This signal is emitted every time an element in the web page
945     completes loading and the overall loading progress advances.
946 
947     This signal tracks the progress of all child frames.
948 
949     The current value is provided by \a progress and scales from 0 to 100,
950     which is the default range of QProgressBar.
951 
952     \sa loadStarted(), loadFinished()
953 */
954 
955 /*!
956     \fn void QWebView::linkClicked(const QUrl &url)
957 
958     This signal is emitted whenever the user clicks on a link and the page's linkDelegationPolicy
959     property is set to delegate the link handling for the specified \a url.
960 
961     \sa QWebPage::linkDelegationPolicy()
962 */
963