2 Copyright (C) 2007 Trolltech ASA
3 Copyright (C) 2007 Staikos Computing Services Inc.
4 Copyright (C) 2007 Apple Inc.
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.
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.
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.
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.
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"
35 #include "ChromeClientQt.h"
36 #include "ContextMenu.h"
37 #include "ContextMenuClientQt.h"
38 #include "DragClientQt.h"
39 #include "DragController.h"
41 #include "EditorClientQt.h"
44 #include "FrameLoader.h"
45 #include "FrameLoadRequest.h"
48 #include "IconDatabase.h"
49 #include "InspectorClientQt.h"
50 #include "FocusController.h"
52 #include "PlatformScrollBar.h"
53 #include "PlatformKeyboardEvent.h"
54 #include "PlatformWheelEvent.h"
55 #include "ProgressTracker.h"
58 #include "HitTestResult.h"
59 #include "LocalizedStrings.h"
62 #include <QDragEnterEvent>
63 #include <QDragLeaveEvent>
64 #include <QDragMoveEvent>
66 #include <QFileDialog>
67 #include <QHttpRequestHeader>
68 #include <QInputDialog>
69 #include <QMessageBox>
70 #include <QNetworkProxy>
75 using namespace WebCore;
77 QWebPagePrivate::QWebPagePrivate(QWebPage *qq)
81 q->setMouseTracking(true);
82 q->setFocusPolicy(Qt::ClickFocus);
83 chromeClient = new ChromeClientQt(q);
84 contextMenuClient = new ContextMenuClientQt();
85 editorClient = new EditorClientQt(q);
86 page = new Page(chromeClient, contextMenuClient, editorClient,
87 new DragClientQt(q), new InspectorClientQt());
89 // ### should be configurable
90 page->settings()->setDefaultTextEncodingName("iso-8859-1");
92 settings = new QWebSettings(page->settings());
97 insideOpenCall = false;
99 history.d = new QWebPageHistoryPrivate(page->backForwardList());
100 memset(actions, 0, sizeof(actions));
103 QWebPagePrivate::~QWebPagePrivate()
110 QWebPage::NavigationRequestResponse QWebPagePrivate::navigationRequested(QWebFrame *frame, const QWebNetworkRequest &request, QWebPage::NavigationType type)
113 && frame == mainFrame)
114 return QWebPage::AcceptNavigationRequest;
115 return q->navigationRequested(frame, request, type);
118 void QWebPagePrivate::createMainFrame()
121 QWebFrameData frameData;
122 frameData.ownerElement = 0;
123 frameData.allowsScrolling = true;
124 frameData.marginWidth = 0;
125 frameData.marginHeight = 0;
126 mainFrame = new QWebFrame(q, &frameData);
127 QObject::connect(mainFrame, SIGNAL(titleChanged(const QString&)),
128 q, SIGNAL(titleChanged(const QString&)));
129 QObject::connect(mainFrame, SIGNAL(hoveringOverLink(const QString&, const QString&)),
130 q, SIGNAL(hoveringOverLink(const QString&, const QString&)));
132 mainFrame->d->frameView->setFrameGeometry(q->geometry());
134 emit q->frameCreated(mainFrame);
138 static QWebPage::WebAction webActionForContextMenuAction(WebCore::ContextMenuAction action)
141 case WebCore::ContextMenuItemTagOpenLink: return QWebPage::OpenLink;
142 case WebCore::ContextMenuItemTagOpenLinkInNewWindow: return QWebPage::OpenLinkInNewWindow;
143 case WebCore::ContextMenuItemTagDownloadLinkToDisk: return QWebPage::DownloadLinkToDisk;
144 case WebCore::ContextMenuItemTagCopyLinkToClipboard: return QWebPage::CopyLinkToClipboard;
145 case WebCore::ContextMenuItemTagOpenImageInNewWindow: return QWebPage::OpenImageInNewWindow;
146 case WebCore::ContextMenuItemTagDownloadImageToDisk: return QWebPage::DownloadImageToDisk;
147 case WebCore::ContextMenuItemTagCopyImageToClipboard: return QWebPage::CopyImageToClipboard;
148 case WebCore::ContextMenuItemTagOpenFrameInNewWindow: return QWebPage::OpenFrameInNewWindow;
149 case WebCore::ContextMenuItemTagCopy: return QWebPage::Copy;
150 case WebCore::ContextMenuItemTagGoBack: return QWebPage::GoBack;
151 case WebCore::ContextMenuItemTagGoForward: return QWebPage::GoForward;
152 case WebCore::ContextMenuItemTagStop: return QWebPage::Stop;
153 case WebCore::ContextMenuItemTagReload: return QWebPage::Reload;
154 case WebCore::ContextMenuItemTagCut: return QWebPage::Cut;
155 case WebCore::ContextMenuItemTagPaste: return QWebPage::Paste;
158 return QWebPage::NoWebAction;
161 QMenu *QWebPagePrivate::createContextMenu(QList<WebCore::ContextMenuItem> *items)
163 QMenu *menu = new QMenu;
164 for (int i = 0; i < items->count(); ++i) {
165 const ContextMenuItem &item = items->at(i);
166 switch (item.type()) {
167 case WebCore::ActionType: {
168 QWebPage::WebAction action = webActionForContextMenuAction(item.action());
169 QAction *a = q->action(action);
174 case WebCore::SeparatorType:
175 menu->addSeparator();
177 case WebCore::SubmenuType: {
178 QMenu *subMenu = createContextMenu(item.platformSubMenu());
179 subMenu->setTitle(item.title());
180 menu->addAction(subMenu->menuAction());
188 QWebFrame *QWebPagePrivate::frameAt(const QPoint &pos) const
190 QWebFrame *frame = mainFrame;
193 QList<QWebFrame*> children = frame->childFrames();
194 for (int i = 0; i < children.size(); ++i) {
195 if (children.at(i)->geometry().contains(pos)) {
196 frame = children.at(i);
200 if (frame->geometry().contains(pos))
205 void QWebPagePrivate::_q_webActionTriggered(bool checked)
207 QAction *a = qobject_cast<QAction *>(q->sender());
210 QWebPage::WebAction action = static_cast<QWebPage::WebAction>(a->data().toInt());
211 q->triggerAction(action, checked);
214 void QWebPagePrivate::updateAction(QWebPage::WebAction action)
216 QAction *a = actions[action];
217 if (!a || !mainFrame)
220 WebCore::FrameLoader *loader = mainFrame->d->frame->loader();
221 WebCore::Editor *editor = page->focusController()->focusedOrMainFrame()->editor();
223 bool enabled = a->isEnabled();
226 case QWebPage::GoBack:
227 enabled = loader->canGoBackOrForward(-1);
229 case QWebPage::GoForward:
230 enabled = loader->canGoBackOrForward(1);
233 enabled = loader->isLoading();
235 case QWebPage::Reload:
236 enabled = !loader->isLoading();
239 enabled = editor->canCut();
242 enabled = editor->canCopy();
244 case QWebPage::Paste:
245 enabled = editor->canPaste();
249 // those two are handled by QUndoStack
254 a->setEnabled(enabled);
257 void QWebPagePrivate::updateNavigationActions()
259 updateAction(QWebPage::GoBack);
260 updateAction(QWebPage::GoForward);
261 updateAction(QWebPage::Stop);
262 updateAction(QWebPage::Reload);
265 void QWebPagePrivate::updateEditorActions()
267 updateAction(QWebPage::Cut);
268 updateAction(QWebPage::Copy);
269 updateAction(QWebPage::Paste);
272 QWebPage::QWebPage(QWidget *parent)
274 , d(new QWebPagePrivate(this))
277 QPalette pal = palette();
278 pal.setBrush(QPalette::Background, Qt::white);
280 setAttribute(Qt::WA_OpaquePaintEvent);
283 setAcceptDrops(true);
284 connect(this, SIGNAL(loadProgressChanged(int)), this, SLOT(_q_onLoadProgressChanged(int)));
287 QWebPage::~QWebPage()
289 FrameLoader *loader = d->mainFrame->d->frame->loader();
291 loader->detachFromParent();
295 void QWebPage::open(const QUrl &url)
297 open(QWebNetworkRequest(url));
300 void QWebPage::open(const QWebNetworkRequest &req)
302 d->insideOpenCall = true;
304 QUrl url = req.url();
305 QHttpRequestHeader httpHeader = req.httpHeader();
306 QByteArray postData = req.postData();
308 WebCore::ResourceRequest request(KURL(url.toString()));
310 QString method = httpHeader.method();
311 if (!method.isEmpty())
312 request.setHTTPMethod(method);
314 QList<QPair<QString, QString> > values = httpHeader.values();
315 for (int i = 0; i < values.size(); ++i) {
316 const QPair<QString, QString> &val = values.at(i);
317 request.addHTTPHeaderField(val.first, val.second);
320 if (!postData.isEmpty()) {
321 WTF::RefPtr<WebCore::FormData> formData = new WebCore::FormData(postData.constData(), postData.size());
322 request.setHTTPBody(formData);
325 mainFrame()->d->frame->loader()->load(request);
326 d->insideOpenCall = false;
329 QUrl QWebPage::url() const
331 return QUrl((QString)mainFrame()->d->frame->loader()->url().url());
334 QString QWebPage::title() const
336 return mainFrame()->title();
339 QWebFrame *QWebPage::mainFrame() const
341 d->createMainFrame();
345 QSize QWebPage::sizeHint() const
347 return QSize(800, 600);
350 void QWebPage::stop()
355 QWebPageHistory *QWebPage::history() const
360 void QWebPage::javaScriptConsoleMessage(const QString& message, unsigned int lineNumber, const QString& sourceID)
364 void QWebPage::javaScriptAlert(QWebFrame *frame, const QString& msg)
367 QMessageBox::information(this, title(), msg, QMessageBox::Ok);
370 bool QWebPage::javaScriptConfirm(QWebFrame *frame, const QString& msg)
373 return 0 == QMessageBox::information(this, title(), msg, QMessageBox::Yes, QMessageBox::No);
376 bool QWebPage::javaScriptPrompt(QWebFrame *frame, const QString& msg, const QString& defaultValue, QString* result)
380 #ifndef QT_NO_INPUTDIALOG
381 QString x = QInputDialog::getText(this, title(), msg, QLineEdit::Normal, defaultValue, &ok);
389 QWebPage *QWebPage::createWindow()
394 QWebPage *QWebPage::createModalDialog()
399 QObject *QWebPage::createPlugin(const QString &classid, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues)
404 Q_UNUSED(paramValues)
408 static WebCore::FrameLoadRequest frameLoadRequest(const QUrl &url, WebCore::Frame *frame)
410 WebCore::ResourceRequest rr(WebCore::KURL(url.toString()),
411 frame->loader()->outgoingReferrer());
412 return WebCore::FrameLoadRequest(rr);
415 static void openNewWindow(const QUrl& url, WebCore::Frame* frame)
417 if (Page* oldPage = frame->page())
418 if (Page* newPage = oldPage->chrome()->createWindow(frame,
419 frameLoadRequest(url, frame)))
420 newPage->chrome()->show();
423 void QWebPage::triggerAction(WebAction action, bool checked)
425 WebCore::Frame *frame = d->page->focusController()->focusedOrMainFrame();
426 WebCore::Editor *editor = frame->editor();
427 const char *command = 0;
431 if (QWebFrame *targetFrame = d->currentContext.targetFrame()) {
432 WTF::RefPtr<WebCore::Frame> wcFrame = targetFrame->d->frame;
433 targetFrame->d->frame->loader()->load(frameLoadRequest(d->currentContext.linkUrl(), wcFrame.get()),
434 /*lockHistory*/ false,
435 /*userGesture*/ true,
437 /*HTMLFormElement*/ 0,
439 WTF::HashMap<String, String>());
444 case OpenLinkInNewWindow:
445 openNewWindow(d->currentContext.linkUrl(), frame);
447 case OpenFrameInNewWindow:
449 case DownloadLinkToDisk:
450 case CopyLinkToClipboard:
451 editor->copyURL(WebCore::KURL(d->currentContext.linkUrl().toString()), d->currentContext.text());
453 case OpenImageInNewWindow:
454 openNewWindow(d->currentContext.imageUrl(), frame);
456 case DownloadImageToDisk:
457 case CopyImageToClipboard:
463 d->page->goForward();
466 mainFrame()->d->frame->loader()->stopForUserCancel();
469 mainFrame()->d->frame->loader()->reload();
489 command = "MoveForward";
491 case MoveToPreviousChar:
492 command = "MoveBackward";
495 command = "MoveWordForward";
497 case MoveToPreviousWord:
498 command = "MoveWordBackward";
501 command = "MoveDown";
503 case MoveToPreviousLine:
506 case MoveToStartOfLine:
507 command = "MoveToBeginningOfLine";
509 case MoveToEndOfLine:
510 command = "MoveToEndOfLine";
512 case MoveToStartOfBlock:
513 command = "MoveToBeginningOfParagraph";
515 case MoveToEndOfBlock:
516 command = "MoveToEndOfParagraph";
518 case MoveToStartOfDocument:
519 command = "MoveToBeginningOfDocument";
521 case MoveToEndOfDocument:
522 command = "MoveToEndOfDocument";
525 command = "MoveForwardAndModifySelection";
527 case SelectPreviousChar:
528 command = "MoveBackwardAndModifySelection";
531 command = "MoveWordForwardAndModifySelection";
533 case SelectPreviousWord:
534 command = "MoveWordBackwardAndModifySelection";
537 command = "MoveDownAndModifySelection";
539 case SelectPreviousLine:
540 command = "MoveUpAndModifySelection";
542 case SelectStartOfLine:
543 command = "MoveToBeginningOfLineAndModifySelection";
545 case SelectEndOfLine:
546 command = "MoveToEndOfLineAndModifySelection";
548 case SelectStartOfBlock:
549 command = "MoveToBeginningOfParagraphAndModifySelection";
551 case SelectEndOfBlock:
552 command = "MoveToEndOfParagraphAndModifySelection";
554 case SelectStartOfDocument:
555 command = "MoveToBeginningOfDocumentAndModifySelection";
557 case SelectEndOfDocument:
558 command = "MoveToEndOfDocumentAndModifySelection";
560 case DeleteStartOfWord:
561 command = "DeleteWordBackward";
563 case DeleteEndOfWord:
564 command = "DeleteWordForward";
571 editor->execCommand(command);
574 QWebPage::NavigationRequestResponse QWebPage::navigationRequested(QWebFrame *frame, const QWebNetworkRequest &request, QWebPage::NavigationType type)
577 return AcceptNavigationRequest;
580 QString QWebPage::selectedText() const
582 return d->page->focusController()->focusedOrMainFrame()->selectedText();
585 QAction *QWebPage::action(WebAction action) const
587 if (action == QWebPage::NoWebAction) return 0;
588 if (d->actions[action])
589 return d->actions[action];
595 text = contextMenuItemTagOpenLink();
597 case OpenLinkInNewWindow:
598 text = contextMenuItemTagOpenLinkInNewWindow();
600 case OpenFrameInNewWindow:
601 text = contextMenuItemTagOpenFrameInNewWindow();
604 case DownloadLinkToDisk:
605 text = contextMenuItemTagDownloadLinkToDisk();
607 case CopyLinkToClipboard:
608 text = contextMenuItemTagCopyLinkToClipboard();
611 case OpenImageInNewWindow:
612 text = contextMenuItemTagOpenImageInNewWindow();
614 case DownloadImageToDisk:
615 text = contextMenuItemTagDownloadImageToDisk();
617 case CopyImageToClipboard:
618 text = contextMenuItemTagCopyImageToClipboard();
622 text = contextMenuItemTagGoBack();
625 text = contextMenuItemTagGoForward();
628 text = contextMenuItemTagStop();
631 text = contextMenuItemTagReload();
635 text = contextMenuItemTagCut();
638 text = contextMenuItemTagCopy();
641 text = contextMenuItemTagPaste();
645 QAction *a = undoStack()->createUndoAction(d->q);
646 d->actions[action] = a;
650 QAction *a = undoStack()->createRedoAction(d->q);
651 d->actions[action] = a;
655 case MoveToPreviousChar:
657 case MoveToPreviousWord:
659 case MoveToPreviousLine:
660 case MoveToStartOfLine:
661 case MoveToEndOfLine:
662 case MoveToStartOfBlock:
663 case MoveToEndOfBlock:
664 case MoveToStartOfDocument:
665 case MoveToEndOfDocument:
667 case SelectPreviousChar:
669 case SelectPreviousWord:
671 case SelectPreviousLine:
672 case SelectStartOfLine:
673 case SelectEndOfLine:
674 case SelectStartOfBlock:
675 case SelectEndOfBlock:
676 case SelectStartOfDocument:
677 case SelectEndOfDocument:
678 case DeleteStartOfWord:
679 case DeleteEndOfWord:
689 QAction *a = new QAction(d->q);
693 connect(a, SIGNAL(triggered(bool)),
694 this, SLOT(_q_webActionTriggered(bool)));
696 d->actions[action] = a;
697 d->updateAction(action);
702 Returns true if the page contains unsubmitted form data.
704 bool QWebPage::isModified() const
710 QUndoStack *QWebPage::undoStack() const
713 d->undoStack = new QUndoStack(const_cast<QWebPage *>(this));
718 static inline DragOperation dropActionToDragOp(Qt::DropActions actions)
721 if (actions & Qt::CopyAction)
722 result |= DragOperationCopy;
723 if (actions & Qt::MoveAction)
724 result |= DragOperationMove;
725 if (actions & Qt::LinkAction)
726 result |= DragOperationLink;
727 return (DragOperation)result;
730 static inline Qt::DropAction dragOpToDropAction(unsigned actions)
732 Qt::DropAction result = Qt::IgnoreAction;
733 if (actions & DragOperationCopy)
734 result = Qt::CopyAction;
735 else if (actions & DragOperationMove)
736 result = Qt::MoveAction;
737 else if (actions & DragOperationLink)
738 result = Qt::LinkAction;
742 void QWebPage::resizeEvent(QResizeEvent *e)
744 QWidget::resizeEvent(e);
745 if (mainFrame()->d->frame && mainFrame()->d->frameView) {
746 mainFrame()->d->frameView->setFrameGeometry(rect());
747 mainFrame()->d->frame->forceLayout();
748 mainFrame()->d->frame->view()->adjustViewSize();
752 void QWebPage::paintEvent(QPaintEvent *ev)
754 #ifdef QWEBKIT_TIME_RENDERING
761 QVector<QRect> vector = ev->region().rects();
762 if (!vector.isEmpty()) {
763 for (int i = 0; i < vector.size(); ++i) {
764 mainFrame()->render(&p, vector.at(i));
767 mainFrame()->render(&p, ev->rect());
770 #ifdef QWEBKIT_TIME_RENDERING
771 int elapsed = time.elapsed();
772 qDebug()<<"paint event on "<<ev->region()<<", took to render = "<<elapsed;
776 void QWebPage::mouseMoveEvent(QMouseEvent *ev)
778 QWebFramePrivate *frame = d->currentFrame(ev->pos())->d;
779 if (!frame->frameView)
782 frame->eventHandler->handleMouseMoveEvent(PlatformMouseEvent(ev, 0));
784 frame->horizontalScrollBar() ? frame->horizontalScrollBar()->value() : 0;
786 frame->verticalScrollBar() ? frame->verticalScrollBar()->value() : 0;
787 IntPoint pt(ev->x() + xOffset, ev->y() + yOffset);
788 WebCore::HitTestResult result = frame->eventHandler->hitTestResultAtPoint(pt, false);
789 WebCore::Element *link = result.URLElement();
790 if (link != frame->lastHoverElement) {
791 frame->lastHoverElement = link;
792 emit hoveringOverLink(result.absoluteLinkURL().prettyURL(), result.title());
796 void QWebPage::mousePressEvent(QMouseEvent *ev)
798 d->frameUnderMouse = d->frameAt(ev->pos());
799 QWebFramePrivate *frame = d->frameUnderMouse->d;
800 if (!frame->eventHandler)
803 frame->eventHandler->handleMousePressEvent(PlatformMouseEvent(ev, 1));
805 //FIXME need to keep track of subframe focus for key events!
806 frame->page->setFocus();
809 void QWebPage::mouseDoubleClickEvent(QMouseEvent *ev)
811 QWebFramePrivate *frame = d->currentFrame(ev->pos())->d;
812 if (!frame->eventHandler)
815 frame->eventHandler->handleMousePressEvent(PlatformMouseEvent(ev, 2));
817 //FIXME need to keep track of subframe focus for key events!
818 frame->page->setFocus();
821 void QWebPage::mouseReleaseEvent(QMouseEvent *ev)
823 QWebFramePrivate *frame = d->currentFrame(ev->pos())->d;
824 if (frame->frameView) {
825 frame->eventHandler->handleMouseReleaseEvent(PlatformMouseEvent(ev, 0));
827 //FIXME need to keep track of subframe focus for key events!
828 frame->page->setFocus();
830 d->frameUnderMouse = 0;
833 void QWebPage::contextMenuEvent(QContextMenuEvent *ev)
835 QWebFramePrivate *frame = d->currentFrame(ev->pos())->d;
836 if (!frame->eventHandler)
838 d->page->contextMenuController()->clearContextMenu();
839 frame->eventHandler->sendContextMenuEvent(PlatformMouseEvent(ev, 1));
840 ContextMenu *menu = d->page->contextMenuController()->contextMenu();
842 QWebPageContext oldContext = d->currentContext;
843 d->currentContext = QWebPageContext(menu->hitTestResult());
845 QList<ContextMenuItem> *items = menu->platformDescription();
846 QMenu *qmenu = d->createContextMenu(items);
848 qmenu->exec(ev->globalPos());
851 d->currentContext = oldContext;
854 void QWebPage::wheelEvent(QWheelEvent *ev)
856 QWebFramePrivate *frame = d->currentFrame(ev->pos())->d;
858 bool accepted = false;
859 if (frame->eventHandler) {
860 WebCore::PlatformWheelEvent pev(ev);
861 accepted = frame->eventHandler->handleWheelEvent(pev);
864 ev->setAccepted(accepted);
866 //FIXME need to keep track of subframe focus for key events!
867 frame->page->setFocus();
869 if (!ev->isAccepted())
870 QWidget::wheelEvent(ev);
873 void QWebPage::keyPressEvent(QKeyEvent *ev)
875 if (!mainFrame()->d->eventHandler)
878 bool handled = false;
879 QWebFrame *frame = mainFrame();
880 WebCore::Editor *editor = frame->d->frame->editor();
881 if (editor->canEdit()) {
882 if (ev == QKeySequence::Cut) {
885 } else if (ev == QKeySequence::Copy) {
888 } else if (ev == QKeySequence::Paste) {
889 triggerAction(Paste);
891 } else if (ev == QKeySequence::Undo) {
894 } else if (ev == QKeySequence::Redo) {
897 } else if(ev == QKeySequence::MoveToNextChar) {
898 triggerAction(MoveToNextChar);
900 } else if(ev == QKeySequence::MoveToPreviousChar) {
901 triggerAction(MoveToPreviousChar);
903 } else if(ev == QKeySequence::MoveToNextWord) {
904 triggerAction(MoveToNextWord);
906 } else if(ev == QKeySequence::MoveToPreviousWord) {
907 triggerAction(MoveToPreviousWord);
909 } else if(ev == QKeySequence::MoveToNextLine) {
910 triggerAction(MoveToNextLine);
912 } else if(ev == QKeySequence::MoveToPreviousLine) {
913 triggerAction(MoveToPreviousLine);
915 // } else if(ev == QKeySequence::MoveToNextPage) {
916 // } else if(ev == QKeySequence::MoveToPreviousPage) {
917 } else if(ev == QKeySequence::MoveToStartOfLine) {
918 triggerAction(MoveToStartOfLine);
920 } else if(ev == QKeySequence::MoveToEndOfLine) {
921 triggerAction(MoveToEndOfLine);
923 } else if(ev == QKeySequence::MoveToStartOfBlock) {
924 triggerAction(MoveToStartOfBlock);
926 } else if(ev == QKeySequence::MoveToEndOfBlock) {
927 triggerAction(MoveToEndOfBlock);
929 } else if(ev == QKeySequence::MoveToStartOfDocument) {
930 triggerAction(MoveToStartOfDocument);
932 } else if(ev == QKeySequence::MoveToEndOfDocument) {
933 triggerAction(MoveToEndOfDocument);
935 } else if(ev == QKeySequence::SelectNextChar) {
936 triggerAction(SelectNextChar);
938 } else if(ev == QKeySequence::SelectPreviousChar) {
939 triggerAction(SelectPreviousChar);
941 } else if(ev == QKeySequence::SelectNextWord) {
942 triggerAction(SelectNextWord);
944 } else if(ev == QKeySequence::SelectPreviousWord) {
945 triggerAction(SelectPreviousWord);
947 } else if(ev == QKeySequence::SelectNextLine) {
948 triggerAction(SelectNextLine);
950 } else if(ev == QKeySequence::SelectPreviousLine) {
951 triggerAction(SelectPreviousLine);
953 // } else if(ev == QKeySequence::SelectNextPage) {
954 // } else if(ev == QKeySequence::SelectPreviousPage) {
955 } else if(ev == QKeySequence::SelectStartOfLine) {
956 triggerAction(SelectStartOfLine);
958 } else if(ev == QKeySequence::SelectEndOfLine) {
959 triggerAction(SelectEndOfLine);
961 } else if(ev == QKeySequence::SelectStartOfBlock) {
962 triggerAction(SelectStartOfBlock);
964 } else if(ev == QKeySequence::SelectEndOfBlock) {
965 triggerAction(SelectEndOfBlock);
967 } else if(ev == QKeySequence::SelectStartOfDocument) {
968 triggerAction(SelectStartOfDocument);
970 } else if(ev == QKeySequence::SelectEndOfDocument) {
971 triggerAction(SelectEndOfDocument);
973 } else if(ev == QKeySequence::DeleteStartOfWord) {
974 triggerAction(DeleteStartOfWord);
976 } else if(ev == QKeySequence::DeleteEndOfWord) {
977 triggerAction(DeleteEndOfWord);
979 // } else if(ev == QKeySequence::DeleteEndOfLine) {
983 handled = frame->d->eventHandler->keyEvent(ev);
986 PlatformScrollbar *h, *v;
987 h = mainFrame()->d->horizontalScrollBar();
988 v = mainFrame()->d->verticalScrollBar();
990 if (ev == QKeySequence::MoveToNextPage) {
992 v->setValue(v->value() + height());
993 } else if (ev == QKeySequence::MoveToPreviousPage) {
995 v->setValue(v->value() - height());
1000 v->setValue(v->value() - 10);
1004 v->setValue(v->value() + 10);
1008 h->setValue(h->value() - 10);
1012 h->setValue(h->value() + 10);
1021 ev->setAccepted(handled);
1024 void QWebPage::keyReleaseEvent(QKeyEvent *ev)
1026 if (ev->isAutoRepeat()) {
1027 ev->setAccepted(true);
1031 if (!mainFrame()->d->eventHandler)
1034 bool handled = mainFrame()->d->eventHandler->keyEvent(ev);
1035 ev->setAccepted(handled);
1038 void QWebPage::focusInEvent(QFocusEvent *ev)
1040 if (ev->reason() != Qt::PopupFocusReason)
1041 mainFrame()->d->frame->page()->focusController()->setFocusedFrame(mainFrame()->d->frame);
1042 QWidget::focusInEvent(ev);
1045 void QWebPage::focusOutEvent(QFocusEvent *ev)
1047 QWidget::focusOutEvent(ev);
1048 if (ev->reason() != Qt::PopupFocusReason) {
1049 mainFrame()->d->frame->selectionController()->clear();
1050 mainFrame()->d->frame->setIsActive(false);
1054 bool QWebPage::focusNextPrevChild(bool next)
1060 void QWebPage::dragEnterEvent(QDragEnterEvent *ev)
1062 #ifndef QT_NO_DRAGANDDROP
1063 DragData dragData(ev->mimeData(), ev->pos(), QCursor::pos(),
1064 dropActionToDragOp(ev->possibleActions()));
1065 Qt::DropAction action = dragOpToDropAction(d->page->dragController()->dragEntered(&dragData));
1066 ev->setDropAction(action);
1071 void QWebPage::dragLeaveEvent(QDragLeaveEvent *ev)
1073 #ifndef QT_NO_DRAGANDDROP
1074 DragData dragData(0, IntPoint(), QCursor::pos(), DragOperationNone);
1075 d->page->dragController()->dragExited(&dragData);
1080 void QWebPage::dragMoveEvent(QDragMoveEvent *ev)
1082 #ifndef QT_NO_DRAGANDDROP
1083 DragData dragData(ev->mimeData(), ev->pos(), QCursor::pos(),
1084 dropActionToDragOp(ev->possibleActions()));
1085 Qt::DropAction action = dragOpToDropAction(d->page->dragController()->dragUpdated(&dragData));
1086 ev->setDropAction(action);
1091 void QWebPage::dropEvent(QDropEvent *ev)
1093 #ifndef QT_NO_DRAGANDDROP
1094 DragData dragData(ev->mimeData(), ev->pos(), QCursor::pos(),
1095 dropActionToDragOp(ev->possibleActions()));
1096 Qt::DropAction action = dragOpToDropAction(d->page->dragController()->performDrag(&dragData));
1101 void QWebPage::setNetworkInterface(QWebNetworkInterface *interface)
1103 d->networkInterface = interface;
1106 QWebNetworkInterface *QWebPage::networkInterface() const
1108 if (d->networkInterface)
1109 return d->networkInterface;
1111 return QWebNetworkInterface::defaultInterface();
1114 QPixmap QWebPage::icon() const
1116 Image* image = iconDatabase()->iconForPageURL(url().toString(), IntSize(16, 16));
1117 if (!image || image->isNull()) {
1118 image = iconDatabase()->defaultIcon(IntSize(16, 16));
1125 QPixmap *icon = image->getPixmap();
1132 QWebSettings *QWebPage::settings()
1137 QString QWebPage::chooseFile(QWebFrame *parentFrame, const QString& oldFile)
1139 //FIXME frame pos...
1140 #ifndef QT_NO_FILEDIALOG
1141 return QFileDialog::getOpenFileName(this, QString::null, oldFile);
1143 return QString::null;
1147 #ifndef QT_NO_NETWORKPROXY
1148 void QWebPage::setNetworkProxy(const QNetworkProxy& proxy)
1150 d->networkProxy = proxy;
1153 QNetworkProxy QWebPage::networkProxy() const
1155 return d->networkProxy;
1159 QString QWebPage::userAgentFor(const QUrl& url) const {
1161 return QLatin1String("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/418.9.1 (KHTML, like Gecko) Safari/419.3 Qt");
1165 void QWebPagePrivate::_q_onLoadProgressChanged(int) {
1166 m_totalBytes = page->progress()->totalPageAndResourceBytesToLoad();
1167 m_bytesReceived = page->progress()->totalBytesReceived();
1171 quint64 QWebPage::totalBytes() const {
1172 return d->m_bytesReceived;
1176 quint64 QWebPage::bytesReceived() const {
1177 return d->m_totalBytes;
1180 QWebPageContext::QWebPageContext(const WebCore::HitTestResult &hitTest)
1181 : d(new QWebPageContextPrivate)
1183 d->pos = hitTest.point();
1184 d->text = hitTest.textContent();
1185 d->linkUrl = hitTest.absoluteLinkURL().url();
1186 d->imageUrl = hitTest.absoluteImageURL().url();
1187 WebCore::Image *img = hitTest.image();
1189 QPixmap *pix = img->getPixmap();
1193 WebCore::Frame *frame = hitTest.targetFrame();
1195 d->targetFrame = frame->view()->qwebframe();
1198 QWebPageContext::QWebPageContext()
1203 QWebPageContext::QWebPageContext(const QWebPageContext &other)
1207 d = new QWebPageContextPrivate(*other.d);
1210 QWebPageContext &QWebPageContext::operator=(const QWebPageContext &other)
1212 if (this != &other) {
1215 d = new QWebPageContextPrivate;
1225 QWebPageContext::~QWebPageContext()
1230 QPoint QWebPageContext::pos() const
1237 QString QWebPageContext::text() const
1244 QUrl QWebPageContext::linkUrl() const
1251 QUrl QWebPageContext::imageUrl() const
1258 QPixmap QWebPageContext::image() const
1265 QWebFrame *QWebPageContext::targetFrame() const
1269 return d->targetFrame;
1272 #include "moc_qwebpage.cpp"