Changed to PlatformMouseEvent constructor to allow construction from a QContextMenuEvent.
[WebKit-https.git] / WebKit / qt / Api / qwebpage.cpp
1 /*
2     Copyright (C) 2007 Trolltech ASA
3     Copyright (C) 2007 Staikos Computing Services Inc.
4     Copyright (C) 2007 Apple Inc.
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     This class provides all functionality needed for loading images, style sheets and html
22     pages from the web. It has a memory cache for these objects.
23 */
24 #include "config.h"
25 #include "qwebpage.h"
26 #include "qwebframe.h"
27 #include "qwebpage_p.h"
28 #include "qwebframe_p.h"
29 #include "qwebnetworkinterface.h"
30 #include "qwebpagehistory.h"
31 #include "qwebpagehistory_p.h"
32 #include "qwebsettings.h"
33
34 #include "Frame.h"
35 #include "ChromeClientQt.h"
36 #include "ContextMenuClientQt.h"
37 #include "DragClientQt.h"
38 #include "DragController.h"
39 #include "DragData.h"
40 #include "EditorClientQt.h"
41 #include "Settings.h"
42 #include "Page.h"
43 #include "FrameLoader.h"
44 #include "KURL.h"
45 #include "Image.h"
46 #include "IconDatabase.h"
47 #include "InspectorClientQt.h"
48 #include "FocusController.h"
49 #include "Editor.h"
50 #include "PlatformScrollBar.h"
51 #include "PlatformKeyboardEvent.h"
52 #include "PlatformWheelEvent.h"
53 #include "ProgressTracker.h"
54 #include "HitTestResult.h"
55
56 #include <QDebug>
57 #include <QDragEnterEvent>
58 #include <QDragLeaveEvent>
59 #include <QDragMoveEvent>
60 #include <QDropEvent>
61 #include <QFileDialog>
62 #include <QHttpRequestHeader>
63 #include <QInputDialog>
64 #include <QMessageBox>
65 #include <QNetworkProxy>
66 #include <QUndoStack>
67 #include <QUrl>
68 #include <QPainter>
69
70 using namespace WebCore;
71
72 QWebPagePrivate::QWebPagePrivate(QWebPage *qq)
73     : q(qq)
74     , modified(false)
75 {
76     q->setMouseTracking(true);
77     q->setFocusPolicy(Qt::ClickFocus);
78     chromeClient = new ChromeClientQt(q);
79     contextMenuClient = new ContextMenuClientQt();
80     editorClient = new EditorClientQt(q);
81     page = new Page(chromeClient, contextMenuClient, editorClient,
82                     new DragClientQt(q), new InspectorClientQt());
83
84     undoStack = 0;
85     mainFrame = 0;
86     networkInterface = 0;
87     insideOpenCall = false;
88
89     history.d = new QWebPageHistoryPrivate(page->backForwardList());
90 }
91
92 QWebPagePrivate::~QWebPagePrivate()
93 {
94     delete undoStack;
95     delete page;
96 }
97
98 QWebPage::NavigationRequestResponse QWebPagePrivate::navigationRequested(QWebFrame *frame, const QWebNetworkRequest &request, QWebPage::NavigationType type)
99 {
100     if (insideOpenCall
101         && frame == mainFrame)
102         return QWebPage::AcceptNavigationRequest;
103     return q->navigationRequested(frame, request, type);
104 }
105
106 void QWebPagePrivate::createMainFrame()
107 {
108     if (!mainFrame) {
109         QWebFrameData frameData;
110         frameData.ownerElement = 0;
111         frameData.allowsScrolling = true;
112         frameData.marginWidth = 0;
113         frameData.marginHeight = 0;
114         mainFrame = new QWebFrame(q, &frameData);
115         QObject::connect(mainFrame, SIGNAL(titleChanged(const QString&)),
116                 q, SIGNAL(titleChanged(const QString&)));
117         QObject::connect(mainFrame, SIGNAL(hoveringOverLink(const QString&, const QString&)),
118                 q, SIGNAL(hoveringOverLink(const QString&, const QString&)));
119         
120         mainFrame->d->frameView->setFrameGeometry(q->geometry());
121
122         emit q->frameCreated(mainFrame);
123     }
124 }
125
126 QWebFrame *QWebPagePrivate::frameAt(const QPoint &pos) const
127 {
128     QWebFrame *frame = mainFrame;
129
130 redo:
131     QList<QWebFrame*> children = frame->childFrames();
132     for (int i = 0; i < children.size(); ++i) {
133         if (children.at(i)->geometry().contains(pos)) {
134             frame = children.at(i);
135             goto redo;
136         }
137     }
138     if (frame->geometry().contains(pos))
139         return frame;
140     return 0;
141 }
142
143 QWebPage::QWebPage(QWidget *parent)
144     : QWidget(parent)
145     , d(new QWebPagePrivate(this))
146 {
147     setSettings(QWebSettings::global());
148     QPalette pal = palette();
149     pal.setBrush(QPalette::Background, Qt::white);
150
151     setAttribute(Qt::WA_OpaquePaintEvent);
152
153     setPalette(pal);
154     setAcceptDrops(true);
155     connect(this, SIGNAL(loadProgressChanged(int)), this, SLOT(_q_onLoadProgressChanged(int)));
156 }
157
158 QWebPage::~QWebPage()
159 {
160     FrameLoader *loader = d->mainFrame->d->frame->loader();
161     if (loader)
162         loader->detachFromParent();
163     delete d;
164 }
165
166 void QWebPage::open(const QUrl &url)
167 {
168     open(QWebNetworkRequest(url));
169 }
170
171 void QWebPage::open(const QWebNetworkRequest &req)
172 {
173     d->insideOpenCall = true;
174
175     QUrl url = req.url();
176     QHttpRequestHeader httpHeader = req.httpHeader();
177     QByteArray postData = req.postData();
178
179     WebCore::ResourceRequest request(KURL(url.toString()));
180
181     QString method = httpHeader.method();
182     if (!method.isEmpty())
183         request.setHTTPMethod(method);
184
185     QList<QPair<QString, QString> > values = httpHeader.values();
186     for (int i = 0; i < values.size(); ++i) {
187         const QPair<QString, QString> &val = values.at(i);
188         request.addHTTPHeaderField(val.first, val.second);
189     }
190
191     if (!postData.isEmpty()) {
192         WTF::RefPtr<WebCore::FormData> formData = new WebCore::FormData(postData.constData(), postData.size());
193         request.setHTTPBody(formData);
194     }
195
196     mainFrame()->d->frame->loader()->load(request);
197     d->insideOpenCall = false;
198 }
199
200 QUrl QWebPage::url() const
201 {
202     return QUrl((QString)mainFrame()->d->frame->loader()->url().url());
203 }
204
205 QString QWebPage::title() const
206 {
207     return mainFrame()->title();
208 }
209
210 QWebFrame *QWebPage::mainFrame() const
211 {
212     d->createMainFrame();
213     return d->mainFrame;
214 }
215
216 QSize QWebPage::sizeHint() const
217 {
218     return QSize(800, 600);
219 }
220
221 void QWebPage::stop()
222 {
223     FrameLoader *f = mainFrame()->d->frame->loader();
224     f->stopForUserCancel();
225 }
226
227 QWebPageHistory *QWebPage::history() const
228 {
229     return &d->history;
230 }
231
232 void QWebPage::goBack()
233 {
234     d->page->goBack();
235 }
236
237 void QWebPage::goForward()
238 {
239     d->page->goForward();
240 }
241
242 void QWebPage::goToHistoryItem(const QWebHistoryItem &item)
243 {
244     d->page->goToItem(item.d->item, FrameLoadTypeIndexedBackForward);
245 }
246
247 void QWebPage::javaScriptConsoleMessage(const QString& message, unsigned int lineNumber, const QString& sourceID)
248 {
249 }
250
251 void QWebPage::javaScriptAlert(QWebFrame *frame, const QString& msg)
252 {
253     //FIXME frame pos...
254     QMessageBox::information(this, title(), msg, QMessageBox::Ok);
255 }
256
257 bool QWebPage::javaScriptConfirm(QWebFrame *frame, const QString& msg)
258 {
259     //FIXME frame pos...
260     return 0 == QMessageBox::information(this, title(), msg, QMessageBox::Yes, QMessageBox::No);
261 }
262
263 bool QWebPage::javaScriptPrompt(QWebFrame *frame, const QString& msg, const QString& defaultValue, QString* result)
264 {
265     //FIXME frame pos...
266     bool ok = false;
267 #ifndef QT_NO_INPUTDIALOG
268     QString x = QInputDialog::getText(this, title(), msg, QLineEdit::Normal, defaultValue, &ok);
269     if (ok && result) {
270         *result = x;
271     }
272 #endif
273     return ok;
274 }
275
276 QWebPage *QWebPage::createWindow()
277 {
278     return 0;
279 }
280
281 QWebPage *QWebPage::createModalDialog()
282 {
283     return 0;
284 }
285
286 QObject *QWebPage::createPlugin(const QString &classid, const QUrl &url, const QStringList &paramNames, const QStringList &paramValues)
287 {
288     Q_UNUSED(classid)
289     Q_UNUSED(url)
290     Q_UNUSED(paramNames)
291     Q_UNUSED(paramValues)
292     return 0;
293 }
294
295 QWebPage::NavigationRequestResponse QWebPage::navigationRequested(QWebFrame *frame, const QWebNetworkRequest &request, QWebPage::NavigationType type)
296 {
297     Q_UNUSED(request)
298     return AcceptNavigationRequest;
299 }
300
301 void QWebPage::setWindowGeometry(const QRect& geom)
302 {
303     Q_UNUSED(geom)
304 }
305
306 bool QWebPage::canCut() const
307 {
308     return d->page->focusController()->focusedOrMainFrame()->editor()->canCut();
309 }
310
311 bool QWebPage::canCopy() const
312 {
313     return d->page->focusController()->focusedOrMainFrame()->editor()->canCopy();
314 }
315
316 bool QWebPage::canPaste() const
317 {
318     return d->page->focusController()->focusedOrMainFrame()->editor()->canPaste();
319 }
320
321 void QWebPage::cut()
322 {
323     d->page->focusController()->focusedOrMainFrame()->editor()->cut();
324 }
325
326 void QWebPage::copy()
327 {
328     d->page->focusController()->focusedOrMainFrame()->editor()->copy();
329 }
330
331 void QWebPage::paste()
332 {
333     d->page->focusController()->focusedOrMainFrame()->editor()->paste();
334 }
335
336 /*!
337   Returns true if the page contains unsubmitted form data.
338 */
339 bool QWebPage::isModified() const
340 {
341     return d->modified;
342 }
343
344
345 QUndoStack *QWebPage::undoStack()
346 {
347     if (!d->undoStack)
348         d->undoStack = new QUndoStack(this);
349
350     return d->undoStack;
351 }
352
353 static inline DragOperation dropActionToDragOp(Qt::DropActions actions)
354 {
355     unsigned result = 0;
356     if (actions & Qt::CopyAction)
357         result |= DragOperationCopy;
358     if (actions & Qt::MoveAction)
359         result |= DragOperationMove;
360     if (actions & Qt::LinkAction)
361         result |= DragOperationLink;
362     return (DragOperation)result;    
363 }
364
365 static inline Qt::DropAction dragOpToDropAction(unsigned actions)
366 {
367     Qt::DropAction result = Qt::IgnoreAction;
368     if (actions & DragOperationCopy)
369         result = Qt::CopyAction;
370     else if (actions & DragOperationMove)
371         result = Qt::MoveAction;
372     else if (actions & DragOperationLink)
373         result = Qt::LinkAction;
374     return result;    
375 }
376
377 void QWebPage::resizeEvent(QResizeEvent *e)
378 {
379     QWidget::resizeEvent(e);
380     if (mainFrame()->d->frame && mainFrame()->d->frameView) {
381         mainFrame()->d->frameView->setFrameGeometry(rect());
382         mainFrame()->d->frame->forceLayout();
383         mainFrame()->d->frame->view()->adjustViewSize();
384     }
385 }
386
387 void QWebPage::paintEvent(QPaintEvent *ev)
388 {
389 #ifdef QWEBKIT_TIME_RENDERING
390     QTime time;
391     time.start();
392 #endif
393
394     QPainter p(this);
395
396     QVector<QRect> vector = ev->region().rects();
397     if (!vector.isEmpty()) {
398         for (int i = 0; i < vector.size(); ++i) {
399             mainFrame()->render(&p, vector.at(i));
400         }
401     } else {
402         mainFrame()->render(&p, ev->rect());
403     }
404
405 #ifdef    QWEBKIT_TIME_RENDERING
406     int elapsed = time.elapsed();
407     qDebug()<<"paint event on "<<ev->region()<<", took to render =  "<<elapsed;
408 #endif
409 }
410
411 void QWebPage::mouseMoveEvent(QMouseEvent *ev)
412 {
413     QWebFramePrivate *frame = d->currentFrame(ev->pos())->d;
414     if (!frame->frameView)
415         return;
416
417     frame->eventHandler->handleMouseMoveEvent(PlatformMouseEvent(ev, 0));
418     const int xOffset =
419         frame->horizontalScrollBar() ? frame->horizontalScrollBar()->value() : 0;
420     const int yOffset =
421         frame->verticalScrollBar() ? frame->verticalScrollBar()->value() : 0;
422     IntPoint pt(ev->x() + xOffset, ev->y() + yOffset);
423     WebCore::HitTestResult result = frame->eventHandler->hitTestResultAtPoint(pt, false);
424     WebCore::Element *link = result.URLElement();
425     if (link != frame->lastHoverElement) {
426         frame->lastHoverElement = link;
427         emit hoveringOverLink(result.absoluteLinkURL().prettyURL(), result.title());
428     }
429 }
430
431 void QWebPage::mousePressEvent(QMouseEvent *ev)
432 {
433     d->frameUnderMouse = d->frameAt(ev->pos());
434     QWebFramePrivate *frame = d->frameUnderMouse->d;
435     if (!frame->eventHandler)
436         return;
437
438     frame->eventHandler->handleMousePressEvent(PlatformMouseEvent(ev, 1));
439
440     //FIXME need to keep track of subframe focus for key events!
441     frame->page->setFocus();
442 }
443
444 void QWebPage::mouseDoubleClickEvent(QMouseEvent *ev)
445 {
446     QWebFramePrivate *frame = d->currentFrame(ev->pos())->d;
447     if (!frame->eventHandler)
448         return;
449
450     frame->eventHandler->handleMousePressEvent(PlatformMouseEvent(ev, 2));
451
452     //FIXME need to keep track of subframe focus for key events!
453     frame->page->setFocus();
454 }
455
456 void QWebPage::mouseReleaseEvent(QMouseEvent *ev)
457 {
458     QWebFramePrivate *frame = d->currentFrame(ev->pos())->d;
459     if (frame->frameView) {
460         frame->eventHandler->handleMouseReleaseEvent(PlatformMouseEvent(ev, 0));
461
462         //FIXME need to keep track of subframe focus for key events!
463         frame->page->setFocus();
464     }
465     d->frameUnderMouse = 0;
466 }
467
468 void QWebPage::contextMenuEvent(QContextMenuEvent *ev)
469 {
470     QWebFramePrivate *frame = d->currentFrame(ev->pos())->d;
471     if (frame->eventHandler)
472         frame->eventHandler->sendContextMenuEvent(PlatformMouseEvent(ev, 1));
473 }
474
475 void QWebPage::wheelEvent(QWheelEvent *ev)
476 {
477     QWebFramePrivate *frame = d->currentFrame(ev->pos())->d;
478
479     bool accepted = false;
480     if (frame->eventHandler) {
481         WebCore::PlatformWheelEvent pev(ev);
482         accepted = frame->eventHandler->handleWheelEvent(pev);
483     }
484
485     ev->setAccepted(accepted);
486
487     //FIXME need to keep track of subframe focus for key events!
488     frame->page->setFocus();
489
490     if (!ev->isAccepted())
491         QWidget::wheelEvent(ev);
492 }
493
494 void QWebPage::keyPressEvent(QKeyEvent *ev)
495 {
496     if (!mainFrame()->d->eventHandler)
497         return;
498
499     bool handled = false;
500     QWebFrame *frame = mainFrame();
501     WebCore::Editor *editor = frame->d->frame->editor();
502     if (editor->canEdit()) {
503         const char *command = 0;
504         if (ev == QKeySequence::Cut) {
505             editor->cut();
506             handled = true;
507         } else if (ev == QKeySequence::Copy) {
508             editor->copy();
509             handled = true;
510         } else if (ev == QKeySequence::Paste) {
511             editor->paste();
512             handled = true;
513         } else if (ev == QKeySequence::Undo) {
514             editor->undo();
515             handled = true;
516         } else if (ev == QKeySequence::Redo) {
517             editor->redo();
518             handled = true;
519         } else if(ev == QKeySequence::MoveToNextChar) {
520             command = "MoveForward";
521         } else if(ev == QKeySequence::MoveToPreviousChar) {
522             command = "MoveBackward";
523         } else if(ev == QKeySequence::MoveToNextWord) {
524             command = "MoveWordForward";
525         } else if(ev == QKeySequence::MoveToPreviousWord) {
526             command = "MoveWordBackward";
527         } else if(ev == QKeySequence::MoveToNextLine) {
528             command = "MoveDown";
529         } else if(ev == QKeySequence::MoveToPreviousLine) {
530             command = "MoveUp";
531 //             } else if(ev == QKeySequence::MoveToNextPage) {
532 //             } else if(ev == QKeySequence::MoveToPreviousPage) {
533         } else if(ev == QKeySequence::MoveToStartOfLine) {
534             command = "MoveToBeginningOfLine";
535         } else if(ev == QKeySequence::MoveToEndOfLine) {
536             command = "MoveToEndOfLine";
537         } else if(ev == QKeySequence::MoveToStartOfBlock) {
538             command = "MoveToBeginningOfParagraph";
539         } else if(ev == QKeySequence::MoveToEndOfBlock) {
540             command = "MoveToEndOfParagraph";
541         } else if(ev == QKeySequence::MoveToStartOfDocument) {
542             command = "MoveToBeginningOfDocument";
543         } else if(ev == QKeySequence::MoveToEndOfDocument) {
544             command = "MoveToEndOfDocument";
545         } else if(ev == QKeySequence::SelectNextChar) {
546             command = "MoveForwardAndModifySelection";
547         } else if(ev == QKeySequence::SelectPreviousChar) {
548             command = "MoveBackwardAndModifySelection";
549         } else if(ev == QKeySequence::SelectNextWord) {
550             command = "MoveWordForwardAndModifySelection";
551         } else if(ev == QKeySequence::SelectPreviousWord) {
552             command = "MoveWordBackwardAndModifySelection";
553         } else if(ev == QKeySequence::SelectNextLine) {
554             command = "MoveDownAndModifySelection";
555         } else if(ev == QKeySequence::SelectPreviousLine) {
556             command = "MoveUpAndModifySelection";
557 //             } else if(ev == QKeySequence::SelectNextPage) {
558 //             } else if(ev == QKeySequence::SelectPreviousPage) {
559         } else if(ev == QKeySequence::SelectStartOfLine) {
560             command = "MoveToBeginningOfLineAndModifySelection";
561         } else if(ev == QKeySequence::SelectEndOfLine) {
562             command = "MoveToEndOfLineAndModifySelection";
563         } else if(ev == QKeySequence::SelectStartOfBlock) {
564             command = "MoveToBeginningOfParagraphAndModifySelection";
565         } else if(ev == QKeySequence::SelectEndOfBlock) {
566             command = "MoveToEndOfParagraphAndModifySelection";
567         } else if(ev == QKeySequence::SelectStartOfDocument) {
568             command = "MoveToBeginningOfDocumentAndModifySelection";
569         } else if(ev == QKeySequence::SelectEndOfDocument) {
570             command = "MoveToEndOfDocumentAndModifySelection";
571         } else if(ev == QKeySequence::DeleteStartOfWord) {
572             command = "DeleteWordBackward";
573         } else if(ev == QKeySequence::DeleteEndOfWord) {
574             command = "DeleteWordForward";
575 //             } else if(ev == QKeySequence::DeleteEndOfLine) {
576         }
577         if (command) {
578             editor->execCommand(command);
579             handled = true;
580         }
581     }
582     if (!handled) 
583         handled = frame->d->eventHandler->keyEvent(ev);
584     if (!handled) {
585         handled = true;
586         PlatformScrollbar *h, *v;
587         h = mainFrame()->d->horizontalScrollBar();
588         v = mainFrame()->d->verticalScrollBar();
589
590         if (ev == QKeySequence::MoveToNextPage) {
591             if (v)
592                 v->setValue(v->value() + height());
593         } else if (ev == QKeySequence::MoveToPreviousPage) {
594             if (v)
595                 v->setValue(v->value() - height());
596         } else {
597             switch (ev->key()) {
598             case Qt::Key_Up:
599                 if (v)
600                     v->setValue(v->value() - 10);
601                 break;
602             case Qt::Key_Down:
603                 if (v)
604                     v->setValue(v->value() + 10);
605                 break;
606             case Qt::Key_Left:
607                 if (h)
608                     h->setValue(h->value() - 10);
609                 break;
610             case Qt::Key_Right:
611                 if (h)
612                     h->setValue(h->value() + 10);
613                 break;
614             default:
615                 handled = false;
616                 break;
617             }
618         }
619     }
620
621     ev->setAccepted(handled);
622 }
623
624 void QWebPage::keyReleaseEvent(QKeyEvent *ev)
625 {
626     if (ev->isAutoRepeat()) {
627         ev->setAccepted(true);
628         return;
629     }
630
631     if (!mainFrame()->d->eventHandler)
632         return;
633
634     bool handled = mainFrame()->d->eventHandler->keyEvent(ev);
635     ev->setAccepted(handled);
636 }
637
638 void QWebPage::focusInEvent(QFocusEvent *ev)
639 {
640     if (ev->reason() != Qt::PopupFocusReason) 
641         mainFrame()->d->frame->page()->focusController()->setFocusedFrame(mainFrame()->d->frame);
642     QWidget::focusInEvent(ev);
643 }
644
645 void QWebPage::focusOutEvent(QFocusEvent *ev)
646 {
647     QWidget::focusOutEvent(ev);
648     if (ev->reason() != Qt::PopupFocusReason) {
649         mainFrame()->d->frame->selectionController()->clear();
650         mainFrame()->d->frame->setIsActive(false);
651     }
652 }
653
654 bool QWebPage::focusNextPrevChild(bool next)
655 {
656     Q_UNUSED(next)
657     return false;
658 }
659
660 void QWebPage::dragEnterEvent(QDragEnterEvent *ev)
661 {
662 #ifndef QT_NO_DRAGANDDROP
663     DragData dragData(ev->mimeData(), ev->pos(), QCursor::pos(), 
664                       dropActionToDragOp(ev->possibleActions()));
665     Qt::DropAction action = dragOpToDropAction(d->page->dragController()->dragEntered(&dragData));
666     ev->setDropAction(action);
667     ev->accept();
668 #endif
669 }
670
671 void QWebPage::dragLeaveEvent(QDragLeaveEvent *ev)
672 {
673 #ifndef QT_NO_DRAGANDDROP
674     DragData dragData(0, IntPoint(), QCursor::pos(), DragOperationNone);
675     d->page->dragController()->dragExited(&dragData);
676     ev->accept();
677 #endif
678 }
679
680 void QWebPage::dragMoveEvent(QDragMoveEvent *ev)
681 {
682 #ifndef QT_NO_DRAGANDDROP
683     DragData dragData(ev->mimeData(), ev->pos(), QCursor::pos(), 
684                       dropActionToDragOp(ev->possibleActions()));
685     Qt::DropAction action = dragOpToDropAction(d->page->dragController()->dragUpdated(&dragData));
686     ev->setDropAction(action);
687     ev->accept();
688 #endif
689 }
690
691 void QWebPage::dropEvent(QDropEvent *ev)
692 {
693 #ifndef QT_NO_DRAGANDDROP
694     DragData dragData(ev->mimeData(), ev->pos(), QCursor::pos(), 
695                       dropActionToDragOp(ev->possibleActions()));
696     Qt::DropAction action = dragOpToDropAction(d->page->dragController()->performDrag(&dragData));
697     ev->accept();
698 #endif
699 }
700
701 void QWebPage::setNetworkInterface(QWebNetworkInterface *interface)
702 {
703     d->networkInterface = interface;
704 }
705
706 QWebNetworkInterface *QWebPage::networkInterface() const
707 {
708     if (d->networkInterface)
709         return d->networkInterface;
710     else
711         return QWebNetworkInterface::defaultInterface();
712 }
713
714 QPixmap QWebPage::icon() const
715 {
716     Image* image = iconDatabase()->iconForPageURL(url().toString(), IntSize(16, 16));
717     if (!image || image->isNull()) {
718         image = iconDatabase()->defaultIcon(IntSize(16, 16));
719     }
720
721     if (!image) {
722         return QPixmap();
723     }
724
725     QPixmap *icon = image->getPixmap();
726     if (!icon) {
727         return QPixmap();
728     }
729     return *icon;
730 }
731
732 void QWebPage::setSettings(const QWebSettings &settings)
733 {
734     WebCore::Settings *wSettings = d->page->settings();
735
736     wSettings->setStandardFontFamily(
737         settings.fontFamily(QWebSettings::StandardFont));
738     wSettings->setFixedFontFamily(
739         settings.fontFamily(QWebSettings::FixedFont));
740     wSettings->setSerifFontFamily(
741         settings.fontFamily(QWebSettings::SerifFont));
742     wSettings->setSansSerifFontFamily(
743         settings.fontFamily(QWebSettings::SansSerifFont));
744     wSettings->setCursiveFontFamily(
745         settings.fontFamily(QWebSettings::CursiveFont));
746     wSettings->setFantasyFontFamily(
747         settings.fontFamily(QWebSettings::FantasyFont));
748
749     wSettings->setMinimumFontSize(settings.minimumFontSize());
750     wSettings->setMinimumLogicalFontSize(settings.minimumLogicalFontSize());
751     wSettings->setDefaultFontSize(settings.defaultFontSize());
752     wSettings->setDefaultFixedFontSize(settings.defaultFixedFontSize());
753
754     wSettings->setLoadsImagesAutomatically(
755         settings.testAttribute(QWebSettings::AutoLoadImages));
756     wSettings->setJavaScriptEnabled(
757         settings.testAttribute(QWebSettings::JavascriptEnabled));
758     wSettings->setJavaScriptCanOpenWindowsAutomatically(
759         settings.testAttribute(QWebSettings::JavascriptCanOpenWindows));
760     wSettings->setJavaEnabled(
761         settings.testAttribute(QWebSettings::JavaEnabled));
762     wSettings->setPluginsEnabled(
763         settings.testAttribute(QWebSettings::PluginsEnabled));
764     wSettings->setPrivateBrowsingEnabled(
765         settings.testAttribute(QWebSettings::PrivateBrowsingEnabled));
766
767     wSettings->setUserStyleSheetLocation(KURL(settings.userStyleSheetLocation()));
768
769     // ### should be configurable
770     wSettings->setDefaultTextEncodingName("iso-8859-1");
771     wSettings->setDOMPasteAllowed(true);
772 }
773
774 QWebSettings QWebPage::settings() const
775 {
776     QWebSettings settings;
777     WebCore::Settings *wSettings = d->page->settings();
778
779     settings.setFontFamily(QWebSettings::StandardFont,
780                            wSettings->standardFontFamily());
781     settings.setFontFamily(QWebSettings::FixedFont,
782                            wSettings->fixedFontFamily());
783     settings.setFontFamily(QWebSettings::SerifFont,
784                            wSettings->serifFontFamily());
785     settings.setFontFamily(QWebSettings::SansSerifFont,
786                            wSettings->sansSerifFontFamily());
787     settings.setFontFamily(QWebSettings::CursiveFont,
788                            wSettings->cursiveFontFamily());
789     settings.setFontFamily(QWebSettings::FantasyFont,
790                            wSettings->fantasyFontFamily());
791
792     settings.setMinimumFontSize(wSettings->minimumFontSize());
793     settings.setMinimumLogicalFontSize(wSettings->minimumLogicalFontSize());
794     settings.setDefaultFontSize(wSettings->defaultFontSize());
795     settings.setDefaultFixedFontSize(wSettings->defaultFixedFontSize());
796
797     settings.setAttribute(QWebSettings::AutoLoadImages,
798                           wSettings->loadsImagesAutomatically());
799     settings.setAttribute(QWebSettings::JavascriptEnabled,
800                           wSettings->isJavaScriptEnabled());
801     settings.setAttribute(QWebSettings::JavascriptCanOpenWindows,
802                           wSettings->JavaScriptCanOpenWindowsAutomatically());
803     settings.setAttribute(QWebSettings::JavaEnabled,
804                           wSettings->isJavaEnabled());
805     settings.setAttribute(QWebSettings::PluginsEnabled,
806                           wSettings->arePluginsEnabled());
807     settings.setAttribute(QWebSettings::PrivateBrowsingEnabled,
808                           wSettings->privateBrowsingEnabled());
809
810     settings.setUserStyleSheetLocation(
811         wSettings->userStyleSheetLocation().url());
812
813     return settings;
814 }
815
816 QString QWebPage::chooseFile(QWebFrame *parentFrame, const QString& oldFile)
817 {
818     //FIXME frame pos...
819 #ifndef QT_NO_FILEDIALOG
820     return QFileDialog::getOpenFileName(this, QString::null, oldFile);
821 #else
822     return QString::null;
823 #endif
824 }
825
826 #ifndef QT_NO_NETWORKPROXY
827 void QWebPage::setNetworkProxy(const QNetworkProxy& proxy)
828 {
829     d->networkProxy = proxy;
830 }
831
832 QNetworkProxy QWebPage::networkProxy() const
833 {
834     return d->networkProxy;
835 }
836 #endif
837
838 QString QWebPage::userAgentStringForUrl(const QUrl& forUrl) const {
839     Q_UNUSED(forUrl)
840     return QLatin1String("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/418.9.1 (KHTML, like Gecko) Safari/419.3 Qt");
841 }
842
843
844 void QWebPagePrivate::_q_onLoadProgressChanged(int) {
845     m_totalBytes = page->progress()->totalPageAndResourceBytesToLoad();
846     m_bytesReceived = page->progress()->totalBytesReceived();
847 }
848
849
850 quint64 QWebPage::totalBytes() const {
851     return d->m_bytesReceived;
852 }
853
854
855 quint64 QWebPage::bytesReceived() const {
856     return d->m_totalBytes;
857 }
858
859 #include "moc_qwebpage.cpp"