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