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>
76 #if QT_VERSION >= 0x040400
77 #include <QNetworkAccessManager>
80 using namespace WebCore;
82 static inline DragOperation dropActionToDragOp(Qt::DropActions actions)
85 if (actions & Qt::CopyAction)
86 result |= DragOperationCopy;
87 if (actions & Qt::MoveAction)
88 result |= DragOperationMove;
89 if (actions & Qt::LinkAction)
90 result |= DragOperationLink;
91 return (DragOperation)result;
94 static inline Qt::DropAction dragOpToDropAction(unsigned actions)
96 Qt::DropAction result = Qt::IgnoreAction;
97 if (actions & DragOperationCopy)
98 result = Qt::CopyAction;
99 else if (actions & DragOperationMove)
100 result = Qt::MoveAction;
101 else if (actions & DragOperationLink)
102 result = Qt::LinkAction;
106 QWebPagePrivate::QWebPagePrivate(QWebPage *qq)
111 chromeClient = new ChromeClientQt(q);
112 contextMenuClient = new ContextMenuClientQt();
113 editorClient = new EditorClientQt(q);
114 page = new Page(chromeClient, contextMenuClient, editorClient,
115 new DragClientQt(q), new InspectorClientQt(q));
117 // ### should be configurable
118 page->settings()->setDefaultTextEncodingName("iso-8859-1");
120 settings = new QWebSettings(page->settings());
124 #if QT_VERSION < 0x040400
125 networkInterface = 0;
129 insideOpenCall = false;
131 history.d = new QWebPageHistoryPrivate(page->backForwardList());
132 memset(actions, 0, sizeof(actions));
135 QWebPagePrivate::~QWebPagePrivate()
140 #if QT_VERSION >= 0x040400
141 delete networkManager;
145 #if QT_VERSION < 0x040400
146 QWebPage::NavigationRequestResponse QWebPagePrivate::navigationRequested(QWebFrame *frame, const QWebNetworkRequest &request, QWebPage::NavigationType type)
149 && frame == mainFrame)
150 return QWebPage::AcceptNavigationRequest;
151 return q->navigationRequested(frame, request, type);
154 QWebPage::NavigationRequestResponse QWebPagePrivate::navigationRequested(QWebFrame *frame, const QNetworkRequest &request, QWebPage::NavigationType type)
157 && frame == mainFrame)
158 return QWebPage::AcceptNavigationRequest;
159 return q->navigationRequested(frame, request, type);
163 void QWebPagePrivate::createMainFrame()
166 QWebFrameData frameData;
167 frameData.ownerElement = 0;
168 frameData.allowsScrolling = true;
169 frameData.marginWidth = 0;
170 frameData.marginHeight = 0;
171 mainFrame = new QWebFrame(q, &frameData);
172 mainFrame->d->frameView->setFrameGeometry(IntRect(IntPoint(0,0), q->viewportSize()));
174 emit q->frameCreated(mainFrame);
178 static QWebPage::WebAction webActionForContextMenuAction(WebCore::ContextMenuAction action)
181 case WebCore::ContextMenuItemTagOpenLink: return QWebPage::OpenLink;
182 case WebCore::ContextMenuItemTagOpenLinkInNewWindow: return QWebPage::OpenLinkInNewWindow;
183 case WebCore::ContextMenuItemTagDownloadLinkToDisk: return QWebPage::DownloadLinkToDisk;
184 case WebCore::ContextMenuItemTagCopyLinkToClipboard: return QWebPage::CopyLinkToClipboard;
185 case WebCore::ContextMenuItemTagOpenImageInNewWindow: return QWebPage::OpenImageInNewWindow;
186 case WebCore::ContextMenuItemTagDownloadImageToDisk: return QWebPage::DownloadImageToDisk;
187 case WebCore::ContextMenuItemTagCopyImageToClipboard: return QWebPage::CopyImageToClipboard;
188 case WebCore::ContextMenuItemTagOpenFrameInNewWindow: return QWebPage::OpenFrameInNewWindow;
189 case WebCore::ContextMenuItemTagCopy: return QWebPage::Copy;
190 case WebCore::ContextMenuItemTagGoBack: return QWebPage::GoBack;
191 case WebCore::ContextMenuItemTagGoForward: return QWebPage::GoForward;
192 case WebCore::ContextMenuItemTagStop: return QWebPage::Stop;
193 case WebCore::ContextMenuItemTagReload: return QWebPage::Reload;
194 case WebCore::ContextMenuItemTagCut: return QWebPage::Cut;
195 case WebCore::ContextMenuItemTagPaste: return QWebPage::Paste;
196 case WebCore::ContextMenuItemTagDefaultDirection: return QWebPage::SetTextDirectionDefault;
197 case WebCore::ContextMenuItemTagLeftToRight: return QWebPage::SetTextDirectionLeftToRight;
198 case WebCore::ContextMenuItemTagRightToLeft: return QWebPage::SetTextDirectionRightToLeft;
199 case WebCore::ContextMenuItemTagBold: return QWebPage::ToggleBold;
200 case WebCore::ContextMenuItemTagItalic: return QWebPage::ToggleItalic;
201 case WebCore::ContextMenuItemTagUnderline: return QWebPage::ToggleUnderline;
202 case WebCore::ContextMenuItemTagInspectElement: return QWebPage::InspectElement;
205 return QWebPage::NoWebAction;
208 QMenu *QWebPagePrivate::createContextMenu(const WebCore::ContextMenu *webcoreMenu, const QList<WebCore::ContextMenuItem> *items)
210 QMenu *menu = new QMenu;
211 for (int i = 0; i < items->count(); ++i) {
212 const ContextMenuItem &item = items->at(i);
213 switch (item.type()) {
214 case WebCore::ActionType: {
215 QWebPage::WebAction action = webActionForContextMenuAction(item.action());
216 QAction *a = q->action(action);
218 ContextMenuItem it(item);
219 webcoreMenu->checkOrEnableIfNeeded(it);
220 PlatformMenuItemDescription desc = it.releasePlatformDescription();
221 a->setEnabled(desc.enabled);
222 a->setChecked(desc.checked);
228 case WebCore::SeparatorType:
229 menu->addSeparator();
231 case WebCore::SubmenuType: {
232 QMenu *subMenu = createContextMenu(webcoreMenu, item.platformSubMenu());
233 if (!subMenu->actions().isEmpty()) {
234 subMenu->setTitle(item.title());
235 menu->addAction(subMenu->menuAction());
246 QWebFrame *QWebPagePrivate::frameAt(const QPoint &pos) const
248 QWebFrame *frame = mainFrame;
251 QList<QWebFrame*> children = frame->childFrames();
252 for (int i = 0; i < children.size(); ++i) {
253 if (children.at(i)->geometry().contains(pos)) {
254 frame = children.at(i);
258 if (frame->geometry().contains(pos))
263 void QWebPagePrivate::_q_webActionTriggered(bool checked)
265 QAction *a = qobject_cast<QAction *>(q->sender());
268 QWebPage::WebAction action = static_cast<QWebPage::WebAction>(a->data().toInt());
269 q->triggerAction(action, checked);
272 void QWebPagePrivate::updateAction(QWebPage::WebAction action)
274 QAction *a = actions[action];
275 if (!a || !mainFrame)
278 WebCore::FrameLoader *loader = mainFrame->d->frame->loader();
279 WebCore::Editor *editor = page->focusController()->focusedOrMainFrame()->editor();
281 bool enabled = a->isEnabled();
284 case QWebPage::GoBack:
285 enabled = loader->canGoBackOrForward(-1);
287 case QWebPage::GoForward:
288 enabled = loader->canGoBackOrForward(1);
291 enabled = loader->isLoading();
293 case QWebPage::Reload:
294 enabled = !loader->isLoading();
297 enabled = editor->canCut();
300 enabled = editor->canCopy();
302 case QWebPage::Paste:
303 enabled = editor->canPaste();
307 // those two are handled by QUndoStack
312 a->setEnabled(enabled);
315 void QWebPagePrivate::updateNavigationActions()
317 updateAction(QWebPage::GoBack);
318 updateAction(QWebPage::GoForward);
319 updateAction(QWebPage::Stop);
320 updateAction(QWebPage::Reload);
323 void QWebPagePrivate::updateEditorActions()
325 updateAction(QWebPage::Cut);
326 updateAction(QWebPage::Copy);
327 updateAction(QWebPage::Paste);
330 void QWebPagePrivate::mouseMoveEvent(QMouseEvent *ev)
332 QWebFrame *f = currentFrame(ev->pos());
336 QWebFramePrivate *frame = f->d;
337 if (!frame->frameView)
340 frame->eventHandler->handleMouseMoveEvent(PlatformMouseEvent(ev, 0));
342 frame->horizontalScrollBar() ? frame->horizontalScrollBar()->value() : 0;
344 frame->verticalScrollBar() ? frame->verticalScrollBar()->value() : 0;
345 IntPoint pt(ev->x() + xOffset, ev->y() + yOffset);
346 WebCore::HitTestResult result = frame->eventHandler->hitTestResultAtPoint(pt, false);
347 WebCore::Element *link = result.URLElement();
348 if (link != frame->lastHoverElement) {
349 frame->lastHoverElement = link;
350 emit q->hoveringOverLink(result.absoluteLinkURL().prettyURL(), result.title(), result.textContent());
354 void QWebPagePrivate::mousePressEvent(QMouseEvent *ev)
356 frameUnderMouse = frameAt(ev->pos());
357 if (!frameUnderMouse)
360 QWebFramePrivate *frame = frameUnderMouse->d;
361 if (!frame->eventHandler)
364 frame->eventHandler->handleMousePressEvent(PlatformMouseEvent(ev, 1));
367 void QWebPagePrivate::mouseDoubleClickEvent(QMouseEvent *ev)
369 QWebFrame *f = currentFrame(ev->pos());
373 QWebFramePrivate *frame = f->d;
374 if (!frame->eventHandler)
377 frame->eventHandler->handleMousePressEvent(PlatformMouseEvent(ev, 2));
380 void QWebPagePrivate::mouseReleaseEvent(QMouseEvent *ev)
382 QWebFrame *f = currentFrame(ev->pos());
386 QWebFramePrivate *frame = f->d;
387 if (!frame->frameView)
390 frame->eventHandler->handleMouseReleaseEvent(PlatformMouseEvent(ev, 0));
395 void QWebPagePrivate::contextMenuEvent(QContextMenuEvent *ev)
397 QWebFrame *f = currentFrame(ev->pos());
401 QWebFramePrivate *frame = f->d;
402 if (!frame->eventHandler)
405 page->contextMenuController()->clearContextMenu();
406 frame->eventHandler->sendContextMenuEvent(PlatformMouseEvent(ev, 1));
407 ContextMenu *menu = page->contextMenuController()->contextMenu();
409 QWebPageContext oldContext = currentContext;
410 currentContext = QWebPageContext(menu->hitTestResult());
412 const QList<ContextMenuItem> *items = menu->platformDescription();
413 QMenu *qmenu = createContextMenu(menu, items);
415 qmenu->exec(ev->globalPos());
418 currentContext = oldContext;
421 void QWebPagePrivate::wheelEvent(QWheelEvent *ev)
423 QWebFramePrivate *frame = currentFrame(ev->pos())->d;
425 bool accepted = false;
426 if (frame->eventHandler) {
427 WebCore::PlatformWheelEvent pev(ev);
428 accepted = frame->eventHandler->handleWheelEvent(pev);
431 ev->setAccepted(accepted);
434 void QWebPagePrivate::keyPressEvent(QKeyEvent *ev)
436 if (!mainFrame->d->eventHandler)
439 bool handled = false;
440 QWebFrame *frame = mainFrame;
441 WebCore::Editor *editor = frame->d->frame->editor();
442 if (editor->canEdit()) {
443 if (ev == QKeySequence::Cut) {
444 q->triggerAction(QWebPage::Cut);
446 } else if (ev == QKeySequence::Copy) {
447 q->triggerAction(QWebPage::Copy);
449 } else if (ev == QKeySequence::Paste) {
450 q->triggerAction(QWebPage::Paste);
452 } else if (ev == QKeySequence::Undo) {
453 q->triggerAction(QWebPage::Undo);
455 } else if (ev == QKeySequence::Redo) {
456 q->triggerAction(QWebPage::Redo);
458 } else if(ev == QKeySequence::MoveToNextChar) {
459 q->triggerAction(QWebPage::MoveToNextChar);
461 } else if(ev == QKeySequence::MoveToPreviousChar) {
462 q->triggerAction(QWebPage::MoveToPreviousChar);
464 } else if(ev == QKeySequence::MoveToNextWord) {
465 q->triggerAction(QWebPage::MoveToNextWord);
467 } else if(ev == QKeySequence::MoveToPreviousWord) {
468 q->triggerAction(QWebPage::MoveToPreviousWord);
470 } else if(ev == QKeySequence::MoveToNextLine) {
471 q->triggerAction(QWebPage::MoveToNextLine);
473 } else if(ev == QKeySequence::MoveToPreviousLine) {
474 q->triggerAction(QWebPage::MoveToPreviousLine);
476 // } else if(ev == QKeySequence::MoveToNextPage) {
477 // } else if(ev == QKeySequence::MoveToPreviousPage) {
478 } else if(ev == QKeySequence::MoveToStartOfLine) {
479 q->triggerAction(QWebPage::MoveToStartOfLine);
481 } else if(ev == QKeySequence::MoveToEndOfLine) {
482 q->triggerAction(QWebPage::MoveToEndOfLine);
484 } else if(ev == QKeySequence::MoveToStartOfBlock) {
485 q->triggerAction(QWebPage::MoveToStartOfBlock);
487 } else if(ev == QKeySequence::MoveToEndOfBlock) {
488 q->triggerAction(QWebPage::MoveToEndOfBlock);
490 } else if(ev == QKeySequence::MoveToStartOfDocument) {
491 q->triggerAction(QWebPage::MoveToStartOfDocument);
493 } else if(ev == QKeySequence::MoveToEndOfDocument) {
494 q->triggerAction(QWebPage::MoveToEndOfDocument);
496 } else if(ev == QKeySequence::SelectNextChar) {
497 q->triggerAction(QWebPage::SelectNextChar);
499 } else if(ev == QKeySequence::SelectPreviousChar) {
500 q->triggerAction(QWebPage::SelectPreviousChar);
502 } else if(ev == QKeySequence::SelectNextWord) {
503 q->triggerAction(QWebPage::SelectNextWord);
505 } else if(ev == QKeySequence::SelectPreviousWord) {
506 q->triggerAction(QWebPage::SelectPreviousWord);
508 } else if(ev == QKeySequence::SelectNextLine) {
509 q->triggerAction(QWebPage::SelectNextLine);
511 } else if(ev == QKeySequence::SelectPreviousLine) {
512 q->triggerAction(QWebPage::SelectPreviousLine);
514 // } else if(ev == QKeySequence::SelectNextPage) {
515 // } else if(ev == QKeySequence::SelectPreviousPage) {
516 } else if(ev == QKeySequence::SelectStartOfLine) {
517 q->triggerAction(QWebPage::SelectStartOfLine);
519 } else if(ev == QKeySequence::SelectEndOfLine) {
520 q->triggerAction(QWebPage::SelectEndOfLine);
522 } else if(ev == QKeySequence::SelectStartOfBlock) {
523 q->triggerAction(QWebPage::SelectStartOfBlock);
525 } else if(ev == QKeySequence::SelectEndOfBlock) {
526 q->triggerAction(QWebPage::SelectEndOfBlock);
528 } else if(ev == QKeySequence::SelectStartOfDocument) {
529 q->triggerAction(QWebPage::SelectStartOfDocument);
531 } else if(ev == QKeySequence::SelectEndOfDocument) {
532 q->triggerAction(QWebPage::SelectEndOfDocument);
534 } else if(ev == QKeySequence::DeleteStartOfWord) {
535 q->triggerAction(QWebPage::DeleteStartOfWord);
537 } else if(ev == QKeySequence::DeleteEndOfWord) {
538 q->triggerAction(QWebPage::DeleteEndOfWord);
540 // } else if(ev == QKeySequence::DeleteEndOfLine) {
544 handled = frame->d->eventHandler->keyEvent(ev);
547 PlatformScrollbar *h, *v;
548 h = mainFrame->d->horizontalScrollBar();
549 v = mainFrame->d->verticalScrollBar();
551 if (ev == QKeySequence::MoveToNextPage) {
553 v->setValue(v->value() + q->viewportSize().height());
554 } else if (ev == QKeySequence::MoveToPreviousPage) {
556 v->setValue(v->value() - q->viewportSize().height());
561 v->setValue(v->value() - 10);
565 v->setValue(v->value() + 10);
569 h->setValue(h->value() - 10);
573 h->setValue(h->value() + 10);
582 ev->setAccepted(handled);
585 void QWebPagePrivate::keyReleaseEvent(QKeyEvent *ev)
587 if (ev->isAutoRepeat()) {
588 ev->setAccepted(true);
592 if (!mainFrame->d->eventHandler)
595 bool handled = mainFrame->d->eventHandler->keyEvent(ev);
596 ev->setAccepted(handled);
599 void QWebPagePrivate::focusInEvent(QFocusEvent *ev)
601 if (ev->reason() != Qt::PopupFocusReason)
602 mainFrame->d->frame->page()->focusController()->setFocusedFrame(mainFrame->d->frame);
605 void QWebPagePrivate::focusOutEvent(QFocusEvent *ev)
607 if (ev->reason() != Qt::PopupFocusReason) {
608 mainFrame->d->frame->selectionController()->clear();
609 mainFrame->d->frame->setIsActive(false);
613 void QWebPagePrivate::dragEnterEvent(QDragEnterEvent *ev)
615 #ifndef QT_NO_DRAGANDDROP
616 DragData dragData(ev->mimeData(), ev->pos(), QCursor::pos(),
617 dropActionToDragOp(ev->possibleActions()));
618 Qt::DropAction action = dragOpToDropAction(page->dragController()->dragEntered(&dragData));
619 ev->setDropAction(action);
624 void QWebPagePrivate::dragLeaveEvent(QDragLeaveEvent *ev)
626 #ifndef QT_NO_DRAGANDDROP
627 DragData dragData(0, IntPoint(), QCursor::pos(), DragOperationNone);
628 page->dragController()->dragExited(&dragData);
633 void QWebPagePrivate::dragMoveEvent(QDragMoveEvent *ev)
635 #ifndef QT_NO_DRAGANDDROP
636 DragData dragData(ev->mimeData(), ev->pos(), QCursor::pos(),
637 dropActionToDragOp(ev->possibleActions()));
638 Qt::DropAction action = dragOpToDropAction(page->dragController()->dragUpdated(&dragData));
639 ev->setDropAction(action);
644 void QWebPagePrivate::dropEvent(QDropEvent *ev)
646 #ifndef QT_NO_DRAGANDDROP
647 DragData dragData(ev->mimeData(), ev->pos(), QCursor::pos(),
648 dropActionToDragOp(ev->possibleActions()));
649 Qt::DropAction action = dragOpToDropAction(page->dragController()->performDrag(&dragData));
654 QWebPage::QWebPage(QObject *parent)
656 , d(new QWebPagePrivate(this))
658 setView(qobject_cast<QWidget *>(parent));
660 connect(this, SIGNAL(loadProgressChanged(int)), this, SLOT(_q_onLoadProgressChanged(int)));
663 QWebPage::~QWebPage()
665 FrameLoader *loader = d->mainFrame->d->frame->loader();
667 loader->detachFromParent();
671 QWebFrame *QWebPage::mainFrame() const
673 d->createMainFrame();
677 QWebFrame *QWebPage::currentFrame() const
679 return static_cast<WebCore::FrameLoaderClientQt *>(d->page->focusController()->focusedOrMainFrame()->loader()->client())->webFrame();
682 QWebPageHistory *QWebPage::history() const
687 void QWebPage::setView(QWidget *view)
690 setViewportSize(view ? view->size() : QSize(0, 0));
693 QWidget *QWebPage::view() const
699 void QWebPage::javaScriptConsoleMessage(const QString& message, unsigned int lineNumber, const QString& sourceID)
703 void QWebPage::javaScriptAlert(QWebFrame *frame, const QString& msg)
706 QMessageBox::information(d->view, mainFrame()->title(), msg, QMessageBox::Ok);
709 bool QWebPage::javaScriptConfirm(QWebFrame *frame, const QString& msg)
712 return 0 == QMessageBox::information(d->view, mainFrame()->title(), msg, QMessageBox::Yes, QMessageBox::No);
715 bool QWebPage::javaScriptPrompt(QWebFrame *frame, const QString& msg, const QString& defaultValue, QString* result)
719 #ifndef QT_NO_INPUTDIALOG
720 QString x = QInputDialog::getText(d->view, mainFrame()->title(), msg, QLineEdit::Normal, defaultValue, &ok);
728 QWebPage *QWebPage::createWindow()
733 QWebPage *QWebPage::createModalDialog()
738 QObject *QWebPage::createPlugin(const QString &classid, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues)
743 Q_UNUSED(paramValues)
747 static WebCore::FrameLoadRequest frameLoadRequest(const QUrl &url, WebCore::Frame *frame)
749 WebCore::ResourceRequest rr(WebCore::KURL(url.toString()),
750 frame->loader()->outgoingReferrer());
751 return WebCore::FrameLoadRequest(rr);
754 static void openNewWindow(const QUrl& url, WebCore::Frame* frame)
756 if (Page* oldPage = frame->page()) {
757 WindowFeatures features;
758 if (Page* newPage = oldPage->chrome()->createWindow(frame,
759 frameLoadRequest(url, frame), features))
760 newPage->chrome()->show();
764 void QWebPage::triggerAction(WebAction action, bool checked)
766 WebCore::Frame *frame = d->page->focusController()->focusedOrMainFrame();
767 WebCore::Editor *editor = frame->editor();
768 const char *command = 0;
772 if (QWebFrame *targetFrame = d->currentContext.targetFrame()) {
773 WTF::RefPtr<WebCore::Frame> wcFrame = targetFrame->d->frame;
774 targetFrame->d->frame->loader()->load(frameLoadRequest(d->currentContext.linkUrl(), wcFrame.get()),
775 /*lockHistory*/ false,
776 /*userGesture*/ true,
778 /*HTMLFormElement*/ 0,
780 WTF::HashMap<String, String>());
785 case OpenLinkInNewWindow:
786 openNewWindow(d->currentContext.linkUrl(), frame);
788 case OpenFrameInNewWindow:
790 case DownloadLinkToDisk:
791 case CopyLinkToClipboard:
792 editor->copyURL(WebCore::KURL(d->currentContext.linkUrl().toString()), d->currentContext.text());
794 case OpenImageInNewWindow:
795 openNewWindow(d->currentContext.imageUrl(), frame);
797 case DownloadImageToDisk:
798 case CopyImageToClipboard:
804 d->page->goForward();
807 mainFrame()->d->frame->loader()->stopForUserCancel();
810 mainFrame()->d->frame->loader()->reload();
830 command = "MoveForward";
832 case MoveToPreviousChar:
833 command = "MoveBackward";
836 command = "MoveWordForward";
838 case MoveToPreviousWord:
839 command = "MoveWordBackward";
842 command = "MoveDown";
844 case MoveToPreviousLine:
847 case MoveToStartOfLine:
848 command = "MoveToBeginningOfLine";
850 case MoveToEndOfLine:
851 command = "MoveToEndOfLine";
853 case MoveToStartOfBlock:
854 command = "MoveToBeginningOfParagraph";
856 case MoveToEndOfBlock:
857 command = "MoveToEndOfParagraph";
859 case MoveToStartOfDocument:
860 command = "MoveToBeginningOfDocument";
862 case MoveToEndOfDocument:
863 command = "MoveToEndOfDocument";
866 command = "MoveForwardAndModifySelection";
868 case SelectPreviousChar:
869 command = "MoveBackwardAndModifySelection";
872 command = "MoveWordForwardAndModifySelection";
874 case SelectPreviousWord:
875 command = "MoveWordBackwardAndModifySelection";
878 command = "MoveDownAndModifySelection";
880 case SelectPreviousLine:
881 command = "MoveUpAndModifySelection";
883 case SelectStartOfLine:
884 command = "MoveToBeginningOfLineAndModifySelection";
886 case SelectEndOfLine:
887 command = "MoveToEndOfLineAndModifySelection";
889 case SelectStartOfBlock:
890 command = "MoveToBeginningOfParagraphAndModifySelection";
892 case SelectEndOfBlock:
893 command = "MoveToEndOfParagraphAndModifySelection";
895 case SelectStartOfDocument:
896 command = "MoveToBeginningOfDocumentAndModifySelection";
898 case SelectEndOfDocument:
899 command = "MoveToEndOfDocumentAndModifySelection";
901 case DeleteStartOfWord:
902 command = "DeleteWordBackward";
904 case DeleteEndOfWord:
905 command = "DeleteWordForward";
908 case SetTextDirectionDefault:
909 editor->setBaseWritingDirection("inherit");
911 case SetTextDirectionLeftToRight:
912 editor->setBaseWritingDirection("ltr");
914 case SetTextDirectionRightToLeft:
915 editor->setBaseWritingDirection("rtl");
919 command = "ToggleBold";
922 command = "ToggleItalic";
924 case ToggleUnderline:
925 editor->toggleUnderline();
928 d->page->inspectorController()->inspect(d->currentContext.d->innerNonSharedNode.get());
935 editor->command(command).execute();
938 QSize QWebPage::viewportSize() const
940 QWebFrame *frame = mainFrame();
941 if (frame->d->frame && frame->d->frameView)
942 return frame->d->frameView->frameGeometry().size();
946 void QWebPage::setViewportSize(const QSize &size) const
948 QWebFrame *frame = mainFrame();
949 if (frame->d->frame && frame->d->frameView) {
950 frame->d->frameView->setFrameGeometry(QRect(QPoint(0, 0), size));
951 frame->d->frame->forceLayout();
952 frame->d->frame->view()->adjustViewSize();
957 #if QT_VERSION < 0x040400
958 QWebPage::NavigationRequestResponse QWebPage::navigationRequested(QWebFrame *frame, const QWebNetworkRequest &request, QWebPage::NavigationType type)
960 QWebPage::NavigationRequestResponse QWebPage::navigationRequested(QWebFrame *frame, const QNetworkRequest &request, QWebPage::NavigationType type)
964 return AcceptNavigationRequest;
967 QString QWebPage::selectedText() const
969 return d->page->focusController()->focusedOrMainFrame()->selectedText();
972 QAction *QWebPage::action(WebAction action) const
974 if (action == QWebPage::NoWebAction) return 0;
975 if (d->actions[action])
976 return d->actions[action];
979 bool checkable = false;
983 text = contextMenuItemTagOpenLink();
985 case OpenLinkInNewWindow:
986 text = contextMenuItemTagOpenLinkInNewWindow();
988 case OpenFrameInNewWindow:
989 text = contextMenuItemTagOpenFrameInNewWindow();
992 case DownloadLinkToDisk:
993 text = contextMenuItemTagDownloadLinkToDisk();
995 case CopyLinkToClipboard:
996 text = contextMenuItemTagCopyLinkToClipboard();
999 case OpenImageInNewWindow:
1000 text = contextMenuItemTagOpenImageInNewWindow();
1002 case DownloadImageToDisk:
1003 text = contextMenuItemTagDownloadImageToDisk();
1005 case CopyImageToClipboard:
1006 text = contextMenuItemTagCopyImageToClipboard();
1010 text = contextMenuItemTagGoBack();
1013 text = contextMenuItemTagGoForward();
1016 text = contextMenuItemTagStop();
1019 text = contextMenuItemTagReload();
1023 text = contextMenuItemTagCut();
1026 text = contextMenuItemTagCopy();
1029 text = contextMenuItemTagPaste();
1033 QAction *a = undoStack()->createUndoAction(d->q);
1034 d->actions[action] = a;
1038 QAction *a = undoStack()->createRedoAction(d->q);
1039 d->actions[action] = a;
1042 case MoveToNextChar:
1043 case MoveToPreviousChar:
1044 case MoveToNextWord:
1045 case MoveToPreviousWord:
1046 case MoveToNextLine:
1047 case MoveToPreviousLine:
1048 case MoveToStartOfLine:
1049 case MoveToEndOfLine:
1050 case MoveToStartOfBlock:
1051 case MoveToEndOfBlock:
1052 case MoveToStartOfDocument:
1053 case MoveToEndOfDocument:
1054 case SelectNextChar:
1055 case SelectPreviousChar:
1056 case SelectNextWord:
1057 case SelectPreviousWord:
1058 case SelectNextLine:
1059 case SelectPreviousLine:
1060 case SelectStartOfLine:
1061 case SelectEndOfLine:
1062 case SelectStartOfBlock:
1063 case SelectEndOfBlock:
1064 case SelectStartOfDocument:
1065 case SelectEndOfDocument:
1066 case DeleteStartOfWord:
1067 case DeleteEndOfWord:
1070 case SetTextDirectionDefault:
1071 text = contextMenuItemTagDefaultDirection();
1073 case SetTextDirectionLeftToRight:
1074 text = contextMenuItemTagLeftToRight();
1077 case SetTextDirectionRightToLeft:
1078 text = contextMenuItemTagRightToLeft();
1083 text = contextMenuItemTagBold();
1087 text = contextMenuItemTagItalic();
1090 case ToggleUnderline:
1091 text = contextMenuItemTagUnderline();
1095 case InspectElement:
1096 text = contextMenuItemTagInspectElement();
1106 QAction *a = new QAction(d->q);
1109 a->setCheckable(checkable);
1111 connect(a, SIGNAL(triggered(bool)),
1112 this, SLOT(_q_webActionTriggered(bool)));
1114 d->actions[action] = a;
1115 d->updateAction(action);
1120 Returns true if the page contains unsubmitted form data.
1122 bool QWebPage::isModified() const
1128 QUndoStack *QWebPage::undoStack() const
1131 d->undoStack = new QUndoStack(const_cast<QWebPage *>(this));
1133 return d->undoStack;
1138 bool QWebPage::event(QEvent *ev)
1140 switch (ev->type()) {
1141 case QEvent::MouseMove:
1142 d->mouseMoveEvent(static_cast<QMouseEvent*>(ev));
1144 case QEvent::MouseButtonPress:
1145 d->mousePressEvent(static_cast<QMouseEvent*>(ev));
1147 case QEvent::MouseButtonDblClick:
1148 d->mouseDoubleClickEvent(static_cast<QMouseEvent*>(ev));
1150 case QEvent::MouseButtonRelease:
1151 d->mouseReleaseEvent(static_cast<QMouseEvent*>(ev));
1153 case QEvent::ContextMenu:
1154 d->contextMenuEvent(static_cast<QContextMenuEvent*>(ev));
1157 d->wheelEvent(static_cast<QWheelEvent*>(ev));
1159 case QEvent::KeyPress:
1160 d->keyPressEvent(static_cast<QKeyEvent*>(ev));
1162 case QEvent::KeyRelease:
1163 d->keyReleaseEvent(static_cast<QKeyEvent*>(ev));
1165 case QEvent::FocusIn:
1166 d->focusInEvent(static_cast<QFocusEvent*>(ev));
1168 case QEvent::FocusOut:
1169 d->focusOutEvent(static_cast<QFocusEvent*>(ev));
1171 case QEvent::DragEnter:
1172 d->dragEnterEvent(static_cast<QDragEnterEvent*>(ev));
1174 case QEvent::DragLeave:
1175 d->dragLeaveEvent(static_cast<QDragLeaveEvent*>(ev));
1177 case QEvent::DragMove:
1178 d->dragMoveEvent(static_cast<QDragMoveEvent*>(ev));
1181 d->dropEvent(static_cast<QDropEvent*>(ev));
1184 return QObject::event(ev);
1190 bool QWebPage::focusNextPrevChild(bool next)
1196 QWebSettings *QWebPage::settings()
1201 QString QWebPage::chooseFile(QWebFrame *parentFrame, const QString& oldFile)
1203 //FIXME frame pos...
1204 #ifndef QT_NO_FILEDIALOG
1205 return QFileDialog::getOpenFileName(d->view, QString::null, oldFile);
1207 return QString::null;
1211 #if QT_VERSION < 0x040400
1213 void QWebPage::setNetworkInterface(QWebNetworkInterface *interface)
1215 d->networkInterface = interface;
1218 QWebNetworkInterface *QWebPage::networkInterface() const
1220 if (d->networkInterface)
1221 return d->networkInterface;
1223 return QWebNetworkInterface::defaultInterface();
1226 #ifndef QT_NO_NETWORKPROXY
1227 void QWebPage::setNetworkProxy(const QNetworkProxy& proxy)
1229 d->networkProxy = proxy;
1232 QNetworkProxy QWebPage::networkProxy() const
1234 return d->networkProxy;
1240 void QWebPage::setNetworkAccessManager(QNetworkAccessManager *manager)
1242 if (manager == d->networkManager)
1244 delete d->networkManager;
1245 d->networkManager = manager;
1248 QNetworkAccessManager *QWebPage::networkAccessManager() const
1250 if (!d->networkManager) {
1251 QWebPage *that = const_cast<QWebPage *>(this);
1252 that->d->networkManager = new QNetworkAccessManager(that);
1254 return d->networkManager;
1259 QString QWebPage::userAgentFor(const QUrl& url) const {
1261 return QLatin1String("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/418.9.1 (KHTML, like Gecko) Safari/419.3 Qt");
1265 void QWebPagePrivate::_q_onLoadProgressChanged(int) {
1266 m_totalBytes = page->progress()->totalPageAndResourceBytesToLoad();
1267 m_bytesReceived = page->progress()->totalBytesReceived();
1271 quint64 QWebPage::totalBytes() const {
1272 return d->m_bytesReceived;
1276 quint64 QWebPage::bytesReceived() const {
1277 return d->m_totalBytes;
1280 QWebPageContext::QWebPageContext(const WebCore::HitTestResult &hitTest)
1281 : d(new QWebPageContextPrivate)
1283 d->pos = hitTest.point();
1284 d->text = hitTest.textContent();
1285 d->linkUrl = hitTest.absoluteLinkURL().string();
1286 d->imageUrl = hitTest.absoluteImageURL().string();
1287 d->innerNonSharedNode = hitTest.innerNonSharedNode();
1288 WebCore::Image *img = hitTest.image();
1290 QPixmap *pix = img->getPixmap();
1294 WebCore::Frame *frame = hitTest.targetFrame();
1296 d->targetFrame = frame->view()->qwebframe();
1299 QWebPageContext::QWebPageContext()
1304 QWebPageContext::QWebPageContext(const QWebPageContext &other)
1308 d = new QWebPageContextPrivate(*other.d);
1311 QWebPageContext &QWebPageContext::operator=(const QWebPageContext &other)
1313 if (this != &other) {
1316 d = new QWebPageContextPrivate;
1326 QWebPageContext::~QWebPageContext()
1331 QPoint QWebPageContext::pos() const
1338 QString QWebPageContext::text() const
1345 QUrl QWebPageContext::linkUrl() const
1352 QUrl QWebPageContext::imageUrl() const
1359 QPixmap QWebPageContext::image() const
1366 QWebFrame *QWebPageContext::targetFrame() const
1370 return d->targetFrame;
1373 #include "moc_qwebpage.cpp"