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 "FrameLoaderClientQt.h"
36 #include "ChromeClientQt.h"
37 #include "ContextMenu.h"
38 #include "ContextMenuClientQt.h"
39 #include "DragClientQt.h"
40 #include "DragController.h"
42 #include "EditorClientQt.h"
45 #include "FrameLoader.h"
46 #include "FrameLoadRequest.h"
49 #include "InspectorClientQt.h"
50 #include "InspectorController.h"
51 #include "FocusController.h"
53 #include "PlatformScrollBar.h"
54 #include "PlatformKeyboardEvent.h"
55 #include "PlatformWheelEvent.h"
56 #include "ProgressTracker.h"
59 #include "HitTestResult.h"
60 #include "WindowFeatures.h"
61 #include "LocalizedStrings.h"
64 #include <QDragEnterEvent>
65 #include <QDragLeaveEvent>
66 #include <QDragMoveEvent>
68 #include <QFileDialog>
69 #include <QHttpRequestHeader>
70 #include <QInputDialog>
71 #include <QMessageBox>
72 #include <QNetworkProxy>
77 using namespace WebCore;
79 QWebPagePrivate::QWebPagePrivate(QWebPage *qq)
84 chromeClient = new ChromeClientQt(q);
85 contextMenuClient = new ContextMenuClientQt();
86 editorClient = new EditorClientQt(q);
87 page = new Page(chromeClient, contextMenuClient, editorClient,
88 new DragClientQt(q), new InspectorClientQt(q));
90 // ### should be configurable
91 page->settings()->setDefaultTextEncodingName("iso-8859-1");
93 settings = new QWebSettings(page->settings());
98 insideOpenCall = false;
100 history.d = new QWebPageHistoryPrivate(page->backForwardList());
101 memset(actions, 0, sizeof(actions));
104 QWebPagePrivate::~QWebPagePrivate()
111 QWebPage::NavigationRequestResponse QWebPagePrivate::navigationRequested(QWebFrame *frame, const QWebNetworkRequest &request, QWebPage::NavigationType type)
114 && frame == mainFrame)
115 return QWebPage::AcceptNavigationRequest;
116 return q->navigationRequested(frame, request, type);
119 void QWebPagePrivate::createMainFrame()
122 QWebFrameData frameData;
123 frameData.ownerElement = 0;
124 frameData.allowsScrolling = true;
125 frameData.marginWidth = 0;
126 frameData.marginHeight = 0;
127 mainFrame = new QWebFrame(q, &frameData);
128 mainFrame->d->frameView->setFrameGeometry(IntRect(IntPoint(0,0), q->viewportSize()));
130 emit q->frameCreated(mainFrame);
134 static QWebPage::WebAction webActionForContextMenuAction(WebCore::ContextMenuAction action)
137 case WebCore::ContextMenuItemTagOpenLink: return QWebPage::OpenLink;
138 case WebCore::ContextMenuItemTagOpenLinkInNewWindow: return QWebPage::OpenLinkInNewWindow;
139 case WebCore::ContextMenuItemTagDownloadLinkToDisk: return QWebPage::DownloadLinkToDisk;
140 case WebCore::ContextMenuItemTagCopyLinkToClipboard: return QWebPage::CopyLinkToClipboard;
141 case WebCore::ContextMenuItemTagOpenImageInNewWindow: return QWebPage::OpenImageInNewWindow;
142 case WebCore::ContextMenuItemTagDownloadImageToDisk: return QWebPage::DownloadImageToDisk;
143 case WebCore::ContextMenuItemTagCopyImageToClipboard: return QWebPage::CopyImageToClipboard;
144 case WebCore::ContextMenuItemTagOpenFrameInNewWindow: return QWebPage::OpenFrameInNewWindow;
145 case WebCore::ContextMenuItemTagCopy: return QWebPage::Copy;
146 case WebCore::ContextMenuItemTagGoBack: return QWebPage::GoBack;
147 case WebCore::ContextMenuItemTagGoForward: return QWebPage::GoForward;
148 case WebCore::ContextMenuItemTagStop: return QWebPage::Stop;
149 case WebCore::ContextMenuItemTagReload: return QWebPage::Reload;
150 case WebCore::ContextMenuItemTagCut: return QWebPage::Cut;
151 case WebCore::ContextMenuItemTagPaste: return QWebPage::Paste;
152 case WebCore::ContextMenuItemTagDefaultDirection: return QWebPage::SetTextDirectionDefault;
153 case WebCore::ContextMenuItemTagLeftToRight: return QWebPage::SetTextDirectionLeftToRight;
154 case WebCore::ContextMenuItemTagRightToLeft: return QWebPage::SetTextDirectionRightToLeft;
155 case WebCore::ContextMenuItemTagBold: return QWebPage::ToggleBold;
156 case WebCore::ContextMenuItemTagItalic: return QWebPage::ToggleItalic;
157 case WebCore::ContextMenuItemTagUnderline: return QWebPage::ToggleUnderline;
158 case WebCore::ContextMenuItemTagInspectElement: return QWebPage::InspectElement;
161 return QWebPage::NoWebAction;
164 QMenu *QWebPagePrivate::createContextMenu(const WebCore::ContextMenu *webcoreMenu, const QList<WebCore::ContextMenuItem> *items)
166 QMenu *menu = new QMenu;
167 for (int i = 0; i < items->count(); ++i) {
168 const ContextMenuItem &item = items->at(i);
169 switch (item.type()) {
170 case WebCore::ActionType: {
171 QWebPage::WebAction action = webActionForContextMenuAction(item.action());
172 QAction *a = q->action(action);
174 ContextMenuItem it(item);
175 webcoreMenu->checkOrEnableIfNeeded(it);
176 PlatformMenuItemDescription desc = it.releasePlatformDescription();
177 a->setEnabled(desc.enabled);
178 a->setChecked(desc.checked);
184 case WebCore::SeparatorType:
185 menu->addSeparator();
187 case WebCore::SubmenuType: {
188 QMenu *subMenu = createContextMenu(webcoreMenu, item.platformSubMenu());
189 if (!subMenu->actions().isEmpty()) {
190 subMenu->setTitle(item.title());
191 menu->addAction(subMenu->menuAction());
202 QWebFrame *QWebPagePrivate::frameAt(const QPoint &pos) const
204 QWebFrame *frame = mainFrame;
207 QList<QWebFrame*> children = frame->childFrames();
208 for (int i = 0; i < children.size(); ++i) {
209 if (children.at(i)->geometry().contains(pos)) {
210 frame = children.at(i);
214 if (frame->geometry().contains(pos))
219 void QWebPagePrivate::_q_webActionTriggered(bool checked)
221 QAction *a = qobject_cast<QAction *>(q->sender());
224 QWebPage::WebAction action = static_cast<QWebPage::WebAction>(a->data().toInt());
225 q->triggerAction(action, checked);
228 void QWebPagePrivate::updateAction(QWebPage::WebAction action)
230 QAction *a = actions[action];
231 if (!a || !mainFrame)
234 WebCore::FrameLoader *loader = mainFrame->d->frame->loader();
235 WebCore::Editor *editor = page->focusController()->focusedOrMainFrame()->editor();
237 bool enabled = a->isEnabled();
240 case QWebPage::GoBack:
241 enabled = loader->canGoBackOrForward(-1);
243 case QWebPage::GoForward:
244 enabled = loader->canGoBackOrForward(1);
247 enabled = loader->isLoading();
249 case QWebPage::Reload:
250 enabled = !loader->isLoading();
253 enabled = editor->canCut();
256 enabled = editor->canCopy();
258 case QWebPage::Paste:
259 enabled = editor->canPaste();
263 // those two are handled by QUndoStack
268 a->setEnabled(enabled);
271 void QWebPagePrivate::updateNavigationActions()
273 updateAction(QWebPage::GoBack);
274 updateAction(QWebPage::GoForward);
275 updateAction(QWebPage::Stop);
276 updateAction(QWebPage::Reload);
279 void QWebPagePrivate::updateEditorActions()
281 updateAction(QWebPage::Cut);
282 updateAction(QWebPage::Copy);
283 updateAction(QWebPage::Paste);
286 QWebPage::QWebPage(QObject *parent)
288 , d(new QWebPagePrivate(this))
290 setView(qobject_cast<QWidget *>(parent));
292 connect(this, SIGNAL(loadProgressChanged(int)), this, SLOT(_q_onLoadProgressChanged(int)));
295 QWebPage::~QWebPage()
297 FrameLoader *loader = d->mainFrame->d->frame->loader();
299 loader->detachFromParent();
303 QWebFrame *QWebPage::mainFrame() const
305 d->createMainFrame();
309 QWebFrame *QWebPage::currentFrame() const
311 return static_cast<WebCore::FrameLoaderClientQt *>(d->page->focusController()->focusedOrMainFrame()->loader()->client())->webFrame();
314 QWebPageHistory *QWebPage::history() const
319 void QWebPage::setView(QWidget *view)
322 setViewportSize(view ? view->size() : QSize(0, 0));
325 QWidget *QWebPage::view() const
331 void QWebPage::javaScriptConsoleMessage(const QString& message, unsigned int lineNumber, const QString& sourceID)
335 void QWebPage::javaScriptAlert(QWebFrame *frame, const QString& msg)
338 QMessageBox::information(d->view, mainFrame()->title(), msg, QMessageBox::Ok);
341 bool QWebPage::javaScriptConfirm(QWebFrame *frame, const QString& msg)
344 return 0 == QMessageBox::information(d->view, mainFrame()->title(), msg, QMessageBox::Yes, QMessageBox::No);
347 bool QWebPage::javaScriptPrompt(QWebFrame *frame, const QString& msg, const QString& defaultValue, QString* result)
351 #ifndef QT_NO_INPUTDIALOG
352 QString x = QInputDialog::getText(d->view, mainFrame()->title(), msg, QLineEdit::Normal, defaultValue, &ok);
360 QWebPage *QWebPage::createWindow()
365 QWebPage *QWebPage::createModalDialog()
370 QObject *QWebPage::createPlugin(const QString &classid, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues)
375 Q_UNUSED(paramValues)
379 static WebCore::FrameLoadRequest frameLoadRequest(const QUrl &url, WebCore::Frame *frame)
381 WebCore::ResourceRequest rr(WebCore::KURL(url.toString()),
382 frame->loader()->outgoingReferrer());
383 return WebCore::FrameLoadRequest(rr);
386 static void openNewWindow(const QUrl& url, WebCore::Frame* frame)
388 if (Page* oldPage = frame->page()) {
389 WindowFeatures features;
390 if (Page* newPage = oldPage->chrome()->createWindow(frame,
391 frameLoadRequest(url, frame), features))
392 newPage->chrome()->show();
396 void QWebPage::triggerAction(WebAction action, bool checked)
398 WebCore::Frame *frame = d->page->focusController()->focusedOrMainFrame();
399 WebCore::Editor *editor = frame->editor();
400 const char *command = 0;
404 if (QWebFrame *targetFrame = d->currentContext.targetFrame()) {
405 WTF::RefPtr<WebCore::Frame> wcFrame = targetFrame->d->frame;
406 targetFrame->d->frame->loader()->load(frameLoadRequest(d->currentContext.linkUrl(), wcFrame.get()),
407 /*lockHistory*/ false,
408 /*userGesture*/ true,
410 /*HTMLFormElement*/ 0,
412 WTF::HashMap<String, String>());
417 case OpenLinkInNewWindow:
418 openNewWindow(d->currentContext.linkUrl(), frame);
420 case OpenFrameInNewWindow:
422 case DownloadLinkToDisk:
423 case CopyLinkToClipboard:
424 editor->copyURL(WebCore::KURL(d->currentContext.linkUrl().toString()), d->currentContext.text());
426 case OpenImageInNewWindow:
427 openNewWindow(d->currentContext.imageUrl(), frame);
429 case DownloadImageToDisk:
430 case CopyImageToClipboard:
436 d->page->goForward();
439 mainFrame()->d->frame->loader()->stopForUserCancel();
442 mainFrame()->d->frame->loader()->reload();
462 command = "MoveForward";
464 case MoveToPreviousChar:
465 command = "MoveBackward";
468 command = "MoveWordForward";
470 case MoveToPreviousWord:
471 command = "MoveWordBackward";
474 command = "MoveDown";
476 case MoveToPreviousLine:
479 case MoveToStartOfLine:
480 command = "MoveToBeginningOfLine";
482 case MoveToEndOfLine:
483 command = "MoveToEndOfLine";
485 case MoveToStartOfBlock:
486 command = "MoveToBeginningOfParagraph";
488 case MoveToEndOfBlock:
489 command = "MoveToEndOfParagraph";
491 case MoveToStartOfDocument:
492 command = "MoveToBeginningOfDocument";
494 case MoveToEndOfDocument:
495 command = "MoveToEndOfDocument";
498 command = "MoveForwardAndModifySelection";
500 case SelectPreviousChar:
501 command = "MoveBackwardAndModifySelection";
504 command = "MoveWordForwardAndModifySelection";
506 case SelectPreviousWord:
507 command = "MoveWordBackwardAndModifySelection";
510 command = "MoveDownAndModifySelection";
512 case SelectPreviousLine:
513 command = "MoveUpAndModifySelection";
515 case SelectStartOfLine:
516 command = "MoveToBeginningOfLineAndModifySelection";
518 case SelectEndOfLine:
519 command = "MoveToEndOfLineAndModifySelection";
521 case SelectStartOfBlock:
522 command = "MoveToBeginningOfParagraphAndModifySelection";
524 case SelectEndOfBlock:
525 command = "MoveToEndOfParagraphAndModifySelection";
527 case SelectStartOfDocument:
528 command = "MoveToBeginningOfDocumentAndModifySelection";
530 case SelectEndOfDocument:
531 command = "MoveToEndOfDocumentAndModifySelection";
533 case DeleteStartOfWord:
534 command = "DeleteWordBackward";
536 case DeleteEndOfWord:
537 command = "DeleteWordForward";
540 case SetTextDirectionDefault:
541 editor->setBaseWritingDirection("inherit");
543 case SetTextDirectionLeftToRight:
544 editor->setBaseWritingDirection("ltr");
546 case SetTextDirectionRightToLeft:
547 editor->setBaseWritingDirection("rtl");
551 command = "ToggleBold";
554 command = "ToggleItalic";
556 case ToggleUnderline:
557 editor->toggleUnderline();
560 d->page->inspectorController()->inspect(d->currentContext.d->innerNonSharedNode.get());
567 editor->command(command).execute();
570 QSize QWebPage::viewportSize() const
572 QWebFrame *frame = mainFrame();
573 if (frame->d->frame && frame->d->frameView)
574 return frame->d->frameView->frameGeometry().size();
578 void QWebPage::setViewportSize(const QSize &size) const
580 QWebFrame *frame = mainFrame();
581 if (frame->d->frame && frame->d->frameView) {
582 frame->d->frameView->setFrameGeometry(QRect(QPoint(0, 0), size));
583 frame->d->frame->forceLayout();
584 frame->d->frame->view()->adjustViewSize();
589 QWebPage::NavigationRequestResponse QWebPage::navigationRequested(QWebFrame *frame, const QWebNetworkRequest &request, QWebPage::NavigationType type)
592 return AcceptNavigationRequest;
595 QString QWebPage::selectedText() const
597 return d->page->focusController()->focusedOrMainFrame()->selectedText();
600 QAction *QWebPage::action(WebAction action) const
602 if (action == QWebPage::NoWebAction) return 0;
603 if (d->actions[action])
604 return d->actions[action];
607 bool checkable = false;
611 text = contextMenuItemTagOpenLink();
613 case OpenLinkInNewWindow:
614 text = contextMenuItemTagOpenLinkInNewWindow();
616 case OpenFrameInNewWindow:
617 text = contextMenuItemTagOpenFrameInNewWindow();
620 case DownloadLinkToDisk:
621 text = contextMenuItemTagDownloadLinkToDisk();
623 case CopyLinkToClipboard:
624 text = contextMenuItemTagCopyLinkToClipboard();
627 case OpenImageInNewWindow:
628 text = contextMenuItemTagOpenImageInNewWindow();
630 case DownloadImageToDisk:
631 text = contextMenuItemTagDownloadImageToDisk();
633 case CopyImageToClipboard:
634 text = contextMenuItemTagCopyImageToClipboard();
638 text = contextMenuItemTagGoBack();
641 text = contextMenuItemTagGoForward();
644 text = contextMenuItemTagStop();
647 text = contextMenuItemTagReload();
651 text = contextMenuItemTagCut();
654 text = contextMenuItemTagCopy();
657 text = contextMenuItemTagPaste();
661 QAction *a = undoStack()->createUndoAction(d->q);
662 d->actions[action] = a;
666 QAction *a = undoStack()->createRedoAction(d->q);
667 d->actions[action] = a;
671 case MoveToPreviousChar:
673 case MoveToPreviousWord:
675 case MoveToPreviousLine:
676 case MoveToStartOfLine:
677 case MoveToEndOfLine:
678 case MoveToStartOfBlock:
679 case MoveToEndOfBlock:
680 case MoveToStartOfDocument:
681 case MoveToEndOfDocument:
683 case SelectPreviousChar:
685 case SelectPreviousWord:
687 case SelectPreviousLine:
688 case SelectStartOfLine:
689 case SelectEndOfLine:
690 case SelectStartOfBlock:
691 case SelectEndOfBlock:
692 case SelectStartOfDocument:
693 case SelectEndOfDocument:
694 case DeleteStartOfWord:
695 case DeleteEndOfWord:
698 case SetTextDirectionDefault:
699 text = contextMenuItemTagDefaultDirection();
701 case SetTextDirectionLeftToRight:
702 text = contextMenuItemTagLeftToRight();
705 case SetTextDirectionRightToLeft:
706 text = contextMenuItemTagRightToLeft();
711 text = contextMenuItemTagBold();
715 text = contextMenuItemTagItalic();
718 case ToggleUnderline:
719 text = contextMenuItemTagUnderline();
724 text = contextMenuItemTagInspectElement();
734 QAction *a = new QAction(d->q);
737 a->setCheckable(checkable);
739 connect(a, SIGNAL(triggered(bool)),
740 this, SLOT(_q_webActionTriggered(bool)));
742 d->actions[action] = a;
743 d->updateAction(action);
748 Returns true if the page contains unsubmitted form data.
750 bool QWebPage::isModified() const
756 QUndoStack *QWebPage::undoStack() const
759 d->undoStack = new QUndoStack(const_cast<QWebPage *>(this));
764 static inline DragOperation dropActionToDragOp(Qt::DropActions actions)
767 if (actions & Qt::CopyAction)
768 result |= DragOperationCopy;
769 if (actions & Qt::MoveAction)
770 result |= DragOperationMove;
771 if (actions & Qt::LinkAction)
772 result |= DragOperationLink;
773 return (DragOperation)result;
776 static inline Qt::DropAction dragOpToDropAction(unsigned actions)
778 Qt::DropAction result = Qt::IgnoreAction;
779 if (actions & DragOperationCopy)
780 result = Qt::CopyAction;
781 else if (actions & DragOperationMove)
782 result = Qt::MoveAction;
783 else if (actions & DragOperationLink)
784 result = Qt::LinkAction;
789 bool QWebPage::event(QEvent *ev)
791 switch (ev->type()) {
792 case QEvent::MouseMove:
793 d->mouseMoveEvent(static_cast<QMouseEvent*>(ev));
795 case QEvent::MouseButtonPress:
796 d->mousePressEvent(static_cast<QMouseEvent*>(ev));
798 case QEvent::MouseButtonDblClick:
799 d->mouseDoubleClickEvent(static_cast<QMouseEvent*>(ev));
801 case QEvent::MouseButtonRelease:
802 d->mouseReleaseEvent(static_cast<QMouseEvent*>(ev));
804 case QEvent::ContextMenu:
805 d->contextMenuEvent(static_cast<QContextMenuEvent*>(ev));
808 d->wheelEvent(static_cast<QWheelEvent*>(ev));
810 case QEvent::KeyPress:
811 d->keyPressEvent(static_cast<QKeyEvent*>(ev));
813 case QEvent::KeyRelease:
814 d->keyReleaseEvent(static_cast<QKeyEvent*>(ev));
816 case QEvent::FocusIn:
817 d->focusInEvent(static_cast<QFocusEvent*>(ev));
819 case QEvent::FocusOut:
820 d->focusOutEvent(static_cast<QFocusEvent*>(ev));
822 case QEvent::DragEnter:
823 d->dragEnterEvent(static_cast<QDragEnterEvent*>(ev));
825 case QEvent::DragLeave:
826 d->dragLeaveEvent(static_cast<QDragLeaveEvent*>(ev));
828 case QEvent::DragMove:
829 d->dragMoveEvent(static_cast<QDragMoveEvent*>(ev));
832 d->dropEvent(static_cast<QDropEvent*>(ev));
835 return QObject::event(ev);
841 void QWebPagePrivate::mouseMoveEvent(QMouseEvent *ev)
843 QWebFrame *f = currentFrame(ev->pos());
847 QWebFramePrivate *frame = f->d;
848 if (!frame->frameView)
851 frame->eventHandler->handleMouseMoveEvent(PlatformMouseEvent(ev, 0));
853 frame->horizontalScrollBar() ? frame->horizontalScrollBar()->value() : 0;
855 frame->verticalScrollBar() ? frame->verticalScrollBar()->value() : 0;
856 IntPoint pt(ev->x() + xOffset, ev->y() + yOffset);
857 WebCore::HitTestResult result = frame->eventHandler->hitTestResultAtPoint(pt, false);
858 WebCore::Element *link = result.URLElement();
859 if (link != frame->lastHoverElement) {
860 frame->lastHoverElement = link;
861 emit q->hoveringOverLink(result.absoluteLinkURL().prettyURL(), result.title(), result.textContent());
865 void QWebPagePrivate::mousePressEvent(QMouseEvent *ev)
867 frameUnderMouse = frameAt(ev->pos());
868 if (!frameUnderMouse)
871 QWebFramePrivate *frame = frameUnderMouse->d;
872 if (!frame->eventHandler)
875 frame->eventHandler->handleMousePressEvent(PlatformMouseEvent(ev, 1));
878 void QWebPagePrivate::mouseDoubleClickEvent(QMouseEvent *ev)
880 QWebFrame *f = currentFrame(ev->pos());
884 QWebFramePrivate *frame = f->d;
885 if (!frame->eventHandler)
888 frame->eventHandler->handleMousePressEvent(PlatformMouseEvent(ev, 2));
891 void QWebPagePrivate::mouseReleaseEvent(QMouseEvent *ev)
893 QWebFrame *f = currentFrame(ev->pos());
897 QWebFramePrivate *frame = f->d;
898 if (!frame->frameView)
901 frame->eventHandler->handleMouseReleaseEvent(PlatformMouseEvent(ev, 0));
906 void QWebPagePrivate::contextMenuEvent(QContextMenuEvent *ev)
908 QWebFrame *f = currentFrame(ev->pos());
912 QWebFramePrivate *frame = f->d;
913 if (!frame->eventHandler)
916 page->contextMenuController()->clearContextMenu();
917 frame->eventHandler->sendContextMenuEvent(PlatformMouseEvent(ev, 1));
918 ContextMenu *menu = page->contextMenuController()->contextMenu();
920 QWebPageContext oldContext = currentContext;
921 currentContext = QWebPageContext(menu->hitTestResult());
923 const QList<ContextMenuItem> *items = menu->platformDescription();
924 QMenu *qmenu = createContextMenu(menu, items);
926 qmenu->exec(ev->globalPos());
929 currentContext = oldContext;
932 void QWebPagePrivate::wheelEvent(QWheelEvent *ev)
934 QWebFramePrivate *frame = currentFrame(ev->pos())->d;
936 bool accepted = false;
937 if (frame->eventHandler) {
938 WebCore::PlatformWheelEvent pev(ev);
939 accepted = frame->eventHandler->handleWheelEvent(pev);
942 ev->setAccepted(accepted);
945 // if (!ev->isAccepted())
946 // QWidget::wheelEvent(ev);
949 void QWebPagePrivate::keyPressEvent(QKeyEvent *ev)
951 if (!mainFrame->d->eventHandler)
954 bool handled = false;
955 QWebFrame *frame = mainFrame;
956 WebCore::Editor *editor = frame->d->frame->editor();
957 if (editor->canEdit()) {
958 if (ev == QKeySequence::Cut) {
959 q->triggerAction(QWebPage::Cut);
961 } else if (ev == QKeySequence::Copy) {
962 q->triggerAction(QWebPage::Copy);
964 } else if (ev == QKeySequence::Paste) {
965 q->triggerAction(QWebPage::Paste);
967 } else if (ev == QKeySequence::Undo) {
968 q->triggerAction(QWebPage::Undo);
970 } else if (ev == QKeySequence::Redo) {
971 q->triggerAction(QWebPage::Redo);
973 } else if(ev == QKeySequence::MoveToNextChar) {
974 q->triggerAction(QWebPage::MoveToNextChar);
976 } else if(ev == QKeySequence::MoveToPreviousChar) {
977 q->triggerAction(QWebPage::MoveToPreviousChar);
979 } else if(ev == QKeySequence::MoveToNextWord) {
980 q->triggerAction(QWebPage::MoveToNextWord);
982 } else if(ev == QKeySequence::MoveToPreviousWord) {
983 q->triggerAction(QWebPage::MoveToPreviousWord);
985 } else if(ev == QKeySequence::MoveToNextLine) {
986 q->triggerAction(QWebPage::MoveToNextLine);
988 } else if(ev == QKeySequence::MoveToPreviousLine) {
989 q->triggerAction(QWebPage::MoveToPreviousLine);
991 // } else if(ev == QKeySequence::MoveToNextPage) {
992 // } else if(ev == QKeySequence::MoveToPreviousPage) {
993 } else if(ev == QKeySequence::MoveToStartOfLine) {
994 q->triggerAction(QWebPage::MoveToStartOfLine);
996 } else if(ev == QKeySequence::MoveToEndOfLine) {
997 q->triggerAction(QWebPage::MoveToEndOfLine);
999 } else if(ev == QKeySequence::MoveToStartOfBlock) {
1000 q->triggerAction(QWebPage::MoveToStartOfBlock);
1002 } else if(ev == QKeySequence::MoveToEndOfBlock) {
1003 q->triggerAction(QWebPage::MoveToEndOfBlock);
1005 } else if(ev == QKeySequence::MoveToStartOfDocument) {
1006 q->triggerAction(QWebPage::MoveToStartOfDocument);
1008 } else if(ev == QKeySequence::MoveToEndOfDocument) {
1009 q->triggerAction(QWebPage::MoveToEndOfDocument);
1011 } else if(ev == QKeySequence::SelectNextChar) {
1012 q->triggerAction(QWebPage::SelectNextChar);
1014 } else if(ev == QKeySequence::SelectPreviousChar) {
1015 q->triggerAction(QWebPage::SelectPreviousChar);
1017 } else if(ev == QKeySequence::SelectNextWord) {
1018 q->triggerAction(QWebPage::SelectNextWord);
1020 } else if(ev == QKeySequence::SelectPreviousWord) {
1021 q->triggerAction(QWebPage::SelectPreviousWord);
1023 } else if(ev == QKeySequence::SelectNextLine) {
1024 q->triggerAction(QWebPage::SelectNextLine);
1026 } else if(ev == QKeySequence::SelectPreviousLine) {
1027 q->triggerAction(QWebPage::SelectPreviousLine);
1029 // } else if(ev == QKeySequence::SelectNextPage) {
1030 // } else if(ev == QKeySequence::SelectPreviousPage) {
1031 } else if(ev == QKeySequence::SelectStartOfLine) {
1032 q->triggerAction(QWebPage::SelectStartOfLine);
1034 } else if(ev == QKeySequence::SelectEndOfLine) {
1035 q->triggerAction(QWebPage::SelectEndOfLine);
1037 } else if(ev == QKeySequence::SelectStartOfBlock) {
1038 q->triggerAction(QWebPage::SelectStartOfBlock);
1040 } else if(ev == QKeySequence::SelectEndOfBlock) {
1041 q->triggerAction(QWebPage::SelectEndOfBlock);
1043 } else if(ev == QKeySequence::SelectStartOfDocument) {
1044 q->triggerAction(QWebPage::SelectStartOfDocument);
1046 } else if(ev == QKeySequence::SelectEndOfDocument) {
1047 q->triggerAction(QWebPage::SelectEndOfDocument);
1049 } else if(ev == QKeySequence::DeleteStartOfWord) {
1050 q->triggerAction(QWebPage::DeleteStartOfWord);
1052 } else if(ev == QKeySequence::DeleteEndOfWord) {
1053 q->triggerAction(QWebPage::DeleteEndOfWord);
1055 // } else if(ev == QKeySequence::DeleteEndOfLine) {
1059 handled = frame->d->eventHandler->keyEvent(ev);
1062 PlatformScrollbar *h, *v;
1063 h = mainFrame->d->horizontalScrollBar();
1064 v = mainFrame->d->verticalScrollBar();
1066 if (ev == QKeySequence::MoveToNextPage) {
1068 v->setValue(v->value() + q->viewportSize().height());
1069 } else if (ev == QKeySequence::MoveToPreviousPage) {
1071 v->setValue(v->value() - q->viewportSize().height());
1073 switch (ev->key()) {
1076 v->setValue(v->value() - 10);
1080 v->setValue(v->value() + 10);
1084 h->setValue(h->value() - 10);
1088 h->setValue(h->value() + 10);
1097 ev->setAccepted(handled);
1100 void QWebPagePrivate::keyReleaseEvent(QKeyEvent *ev)
1102 if (ev->isAutoRepeat()) {
1103 ev->setAccepted(true);
1107 if (!mainFrame->d->eventHandler)
1110 bool handled = mainFrame->d->eventHandler->keyEvent(ev);
1111 ev->setAccepted(handled);
1114 void QWebPagePrivate::focusInEvent(QFocusEvent *ev)
1116 if (ev->reason() != Qt::PopupFocusReason)
1117 mainFrame->d->frame->page()->focusController()->setFocusedFrame(mainFrame->d->frame);
1119 //QWidget::focusInEvent(ev);
1122 void QWebPagePrivate::focusOutEvent(QFocusEvent *ev)
1125 //QWidget::focusOutEvent(ev);
1126 if (ev->reason() != Qt::PopupFocusReason) {
1127 mainFrame->d->frame->selectionController()->clear();
1128 mainFrame->d->frame->setIsActive(false);
1132 bool QWebPage::focusNextPrevChild(bool next)
1138 void QWebPagePrivate::dragEnterEvent(QDragEnterEvent *ev)
1140 #ifndef QT_NO_DRAGANDDROP
1141 DragData dragData(ev->mimeData(), ev->pos(), QCursor::pos(),
1142 dropActionToDragOp(ev->possibleActions()));
1143 Qt::DropAction action = dragOpToDropAction(page->dragController()->dragEntered(&dragData));
1144 ev->setDropAction(action);
1149 void QWebPagePrivate::dragLeaveEvent(QDragLeaveEvent *ev)
1151 #ifndef QT_NO_DRAGANDDROP
1152 DragData dragData(0, IntPoint(), QCursor::pos(), DragOperationNone);
1153 page->dragController()->dragExited(&dragData);
1158 void QWebPagePrivate::dragMoveEvent(QDragMoveEvent *ev)
1160 #ifndef QT_NO_DRAGANDDROP
1161 DragData dragData(ev->mimeData(), ev->pos(), QCursor::pos(),
1162 dropActionToDragOp(ev->possibleActions()));
1163 Qt::DropAction action = dragOpToDropAction(page->dragController()->dragUpdated(&dragData));
1164 ev->setDropAction(action);
1169 void QWebPagePrivate::dropEvent(QDropEvent *ev)
1171 #ifndef QT_NO_DRAGANDDROP
1172 DragData dragData(ev->mimeData(), ev->pos(), QCursor::pos(),
1173 dropActionToDragOp(ev->possibleActions()));
1174 Qt::DropAction action = dragOpToDropAction(page->dragController()->performDrag(&dragData));
1179 void QWebPage::setNetworkInterface(QWebNetworkInterface *interface)
1181 d->networkInterface = interface;
1184 QWebNetworkInterface *QWebPage::networkInterface() const
1186 if (d->networkInterface)
1187 return d->networkInterface;
1189 return QWebNetworkInterface::defaultInterface();
1192 QWebSettings *QWebPage::settings()
1197 QString QWebPage::chooseFile(QWebFrame *parentFrame, const QString& oldFile)
1199 //FIXME frame pos...
1200 #ifndef QT_NO_FILEDIALOG
1201 return QFileDialog::getOpenFileName(d->view, QString::null, oldFile);
1203 return QString::null;
1207 #ifndef QT_NO_NETWORKPROXY
1208 void QWebPage::setNetworkProxy(const QNetworkProxy& proxy)
1210 d->networkProxy = proxy;
1213 QNetworkProxy QWebPage::networkProxy() const
1215 return d->networkProxy;
1219 QString QWebPage::userAgentFor(const QUrl& url) const {
1221 return QLatin1String("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/418.9.1 (KHTML, like Gecko) Safari/419.3 Qt");
1225 void QWebPagePrivate::_q_onLoadProgressChanged(int) {
1226 m_totalBytes = page->progress()->totalPageAndResourceBytesToLoad();
1227 m_bytesReceived = page->progress()->totalBytesReceived();
1231 quint64 QWebPage::totalBytes() const {
1232 return d->m_bytesReceived;
1236 quint64 QWebPage::bytesReceived() const {
1237 return d->m_totalBytes;
1240 QWebPageContext::QWebPageContext(const WebCore::HitTestResult &hitTest)
1241 : d(new QWebPageContextPrivate)
1243 d->pos = hitTest.point();
1244 d->text = hitTest.textContent();
1245 d->linkUrl = hitTest.absoluteLinkURL().string();
1246 d->imageUrl = hitTest.absoluteImageURL().string();
1247 d->innerNonSharedNode = hitTest.innerNonSharedNode();
1248 WebCore::Image *img = hitTest.image();
1250 QPixmap *pix = img->getPixmap();
1254 WebCore::Frame *frame = hitTest.targetFrame();
1256 d->targetFrame = frame->view()->qwebframe();
1259 QWebPageContext::QWebPageContext()
1264 QWebPageContext::QWebPageContext(const QWebPageContext &other)
1268 d = new QWebPageContextPrivate(*other.d);
1271 QWebPageContext &QWebPageContext::operator=(const QWebPageContext &other)
1273 if (this != &other) {
1276 d = new QWebPageContextPrivate;
1286 QWebPageContext::~QWebPageContext()
1291 QPoint QWebPageContext::pos() const
1298 QString QWebPageContext::text() const
1305 QUrl QWebPageContext::linkUrl() const
1312 QUrl QWebPageContext::imageUrl() const
1319 QPixmap QWebPageContext::image() const
1326 QWebFrame *QWebPageContext::targetFrame() const
1330 return d->targetFrame;
1333 #include "moc_qwebpage.cpp"