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>
78 #include <QNetworkRequest>
81 using namespace WebCore;
83 static inline DragOperation dropActionToDragOp(Qt::DropActions actions)
86 if (actions & Qt::CopyAction)
87 result |= DragOperationCopy;
88 if (actions & Qt::MoveAction)
89 result |= DragOperationMove;
90 if (actions & Qt::LinkAction)
91 result |= DragOperationLink;
92 return (DragOperation)result;
95 static inline Qt::DropAction dragOpToDropAction(unsigned actions)
97 Qt::DropAction result = Qt::IgnoreAction;
98 if (actions & DragOperationCopy)
99 result = Qt::CopyAction;
100 else if (actions & DragOperationMove)
101 result = Qt::MoveAction;
102 else if (actions & DragOperationLink)
103 result = Qt::LinkAction;
107 QWebPagePrivate::QWebPagePrivate(QWebPage *qq)
112 chromeClient = new ChromeClientQt(q);
113 contextMenuClient = new ContextMenuClientQt();
114 editorClient = new EditorClientQt(q);
115 page = new Page(chromeClient, contextMenuClient, editorClient,
116 new DragClientQt(q), new InspectorClientQt(q));
118 // ### should be configurable
119 page->settings()->setDefaultTextEncodingName("iso-8859-1");
121 settings = new QWebSettings(page->settings());
125 #if QT_VERSION < 0x040400
126 networkInterface = 0;
130 insideOpenCall = false;
132 history.d = new QWebPageHistoryPrivate(page->backForwardList());
133 memset(actions, 0, sizeof(actions));
136 QWebPagePrivate::~QWebPagePrivate()
141 #if QT_VERSION >= 0x040400
142 delete networkManager;
146 #if QT_VERSION < 0x040400
147 QWebPage::NavigationRequestResponse QWebPagePrivate::navigationRequested(QWebFrame *frame, const QWebNetworkRequest &request, QWebPage::NavigationType type)
150 && frame == mainFrame)
151 return QWebPage::AcceptNavigationRequest;
152 return q->navigationRequested(frame, request, type);
155 QWebPage::NavigationRequestResponse QWebPagePrivate::navigationRequested(QWebFrame *frame, const QNetworkRequest &request, QWebPage::NavigationType type)
158 && frame == mainFrame)
159 return QWebPage::AcceptNavigationRequest;
160 return q->navigationRequested(frame, request, type);
164 void QWebPagePrivate::createMainFrame()
167 QWebFrameData frameData;
168 frameData.ownerElement = 0;
169 frameData.allowsScrolling = true;
170 frameData.marginWidth = 0;
171 frameData.marginHeight = 0;
172 mainFrame = new QWebFrame(q, &frameData);
173 mainFrame->d->frameView->setFrameGeometry(IntRect(IntPoint(0,0), q->viewportSize()));
175 emit q->frameCreated(mainFrame);
179 static QWebPage::WebAction webActionForContextMenuAction(WebCore::ContextMenuAction action)
182 case WebCore::ContextMenuItemTagOpenLink: return QWebPage::OpenLink;
183 case WebCore::ContextMenuItemTagOpenLinkInNewWindow: return QWebPage::OpenLinkInNewWindow;
184 case WebCore::ContextMenuItemTagDownloadLinkToDisk: return QWebPage::DownloadLinkToDisk;
185 case WebCore::ContextMenuItemTagCopyLinkToClipboard: return QWebPage::CopyLinkToClipboard;
186 case WebCore::ContextMenuItemTagOpenImageInNewWindow: return QWebPage::OpenImageInNewWindow;
187 case WebCore::ContextMenuItemTagDownloadImageToDisk: return QWebPage::DownloadImageToDisk;
188 case WebCore::ContextMenuItemTagCopyImageToClipboard: return QWebPage::CopyImageToClipboard;
189 case WebCore::ContextMenuItemTagOpenFrameInNewWindow: return QWebPage::OpenFrameInNewWindow;
190 case WebCore::ContextMenuItemTagCopy: return QWebPage::Copy;
191 case WebCore::ContextMenuItemTagGoBack: return QWebPage::GoBack;
192 case WebCore::ContextMenuItemTagGoForward: return QWebPage::GoForward;
193 case WebCore::ContextMenuItemTagStop: return QWebPage::Stop;
194 case WebCore::ContextMenuItemTagReload: return QWebPage::Reload;
195 case WebCore::ContextMenuItemTagCut: return QWebPage::Cut;
196 case WebCore::ContextMenuItemTagPaste: return QWebPage::Paste;
197 case WebCore::ContextMenuItemTagDefaultDirection: return QWebPage::SetTextDirectionDefault;
198 case WebCore::ContextMenuItemTagLeftToRight: return QWebPage::SetTextDirectionLeftToRight;
199 case WebCore::ContextMenuItemTagRightToLeft: return QWebPage::SetTextDirectionRightToLeft;
200 case WebCore::ContextMenuItemTagBold: return QWebPage::ToggleBold;
201 case WebCore::ContextMenuItemTagItalic: return QWebPage::ToggleItalic;
202 case WebCore::ContextMenuItemTagUnderline: return QWebPage::ToggleUnderline;
203 case WebCore::ContextMenuItemTagInspectElement: return QWebPage::InspectElement;
206 return QWebPage::NoWebAction;
209 QMenu *QWebPagePrivate::createContextMenu(const WebCore::ContextMenu *webcoreMenu, const QList<WebCore::ContextMenuItem> *items)
211 QMenu *menu = new QMenu;
212 for (int i = 0; i < items->count(); ++i) {
213 const ContextMenuItem &item = items->at(i);
214 switch (item.type()) {
215 case WebCore::ActionType: {
216 QWebPage::WebAction action = webActionForContextMenuAction(item.action());
217 QAction *a = q->action(action);
219 ContextMenuItem it(item);
220 webcoreMenu->checkOrEnableIfNeeded(it);
221 PlatformMenuItemDescription desc = it.releasePlatformDescription();
222 a->setEnabled(desc.enabled);
223 a->setChecked(desc.checked);
229 case WebCore::SeparatorType:
230 menu->addSeparator();
232 case WebCore::SubmenuType: {
233 QMenu *subMenu = createContextMenu(webcoreMenu, item.platformSubMenu());
234 if (!subMenu->actions().isEmpty()) {
235 subMenu->setTitle(item.title());
236 menu->addAction(subMenu->menuAction());
247 QWebFrame *QWebPagePrivate::frameAt(const QPoint &pos) const
249 QWebFrame *frame = mainFrame;
252 QList<QWebFrame*> children = frame->childFrames();
253 for (int i = 0; i < children.size(); ++i) {
254 if (children.at(i)->geometry().contains(pos)) {
255 frame = children.at(i);
259 if (frame->geometry().contains(pos))
264 void QWebPagePrivate::_q_webActionTriggered(bool checked)
266 QAction *a = qobject_cast<QAction *>(q->sender());
269 QWebPage::WebAction action = static_cast<QWebPage::WebAction>(a->data().toInt());
270 q->triggerAction(action, checked);
273 void QWebPagePrivate::updateAction(QWebPage::WebAction action)
275 QAction *a = actions[action];
276 if (!a || !mainFrame)
279 WebCore::FrameLoader *loader = mainFrame->d->frame->loader();
280 WebCore::Editor *editor = page->focusController()->focusedOrMainFrame()->editor();
282 bool enabled = a->isEnabled();
285 case QWebPage::GoBack:
286 enabled = loader->canGoBackOrForward(-1);
288 case QWebPage::GoForward:
289 enabled = loader->canGoBackOrForward(1);
292 enabled = loader->isLoading();
294 case QWebPage::Reload:
295 enabled = !loader->isLoading();
298 enabled = editor->canCut();
301 enabled = editor->canCopy();
303 case QWebPage::Paste:
304 enabled = editor->canPaste();
308 // those two are handled by QUndoStack
313 a->setEnabled(enabled);
316 void QWebPagePrivate::updateNavigationActions()
318 updateAction(QWebPage::GoBack);
319 updateAction(QWebPage::GoForward);
320 updateAction(QWebPage::Stop);
321 updateAction(QWebPage::Reload);
324 void QWebPagePrivate::updateEditorActions()
326 updateAction(QWebPage::Cut);
327 updateAction(QWebPage::Copy);
328 updateAction(QWebPage::Paste);
331 void QWebPagePrivate::mouseMoveEvent(QMouseEvent *ev)
333 QWebFrame *f = currentFrame(ev->pos());
337 QWebFramePrivate *frame = f->d;
338 if (!frame->frameView)
341 frame->eventHandler->handleMouseMoveEvent(PlatformMouseEvent(ev, 0));
343 frame->horizontalScrollBar() ? frame->horizontalScrollBar()->value() : 0;
345 frame->verticalScrollBar() ? frame->verticalScrollBar()->value() : 0;
346 IntPoint pt(ev->x() + xOffset, ev->y() + yOffset);
347 WebCore::HitTestResult result = frame->eventHandler->hitTestResultAtPoint(pt, false);
348 WebCore::Element *link = result.URLElement();
349 if (link != frame->lastHoverElement) {
350 frame->lastHoverElement = link;
351 emit q->hoveringOverLink(result.absoluteLinkURL().prettyURL(), result.title(), result.textContent());
355 void QWebPagePrivate::mousePressEvent(QMouseEvent *ev)
357 frameUnderMouse = frameAt(ev->pos());
358 if (!frameUnderMouse)
361 QWebFramePrivate *frame = frameUnderMouse->d;
362 if (!frame->eventHandler)
365 frame->eventHandler->handleMousePressEvent(PlatformMouseEvent(ev, 1));
368 void QWebPagePrivate::mouseDoubleClickEvent(QMouseEvent *ev)
370 QWebFrame *f = currentFrame(ev->pos());
374 QWebFramePrivate *frame = f->d;
375 if (!frame->eventHandler)
378 frame->eventHandler->handleMousePressEvent(PlatformMouseEvent(ev, 2));
381 void QWebPagePrivate::mouseReleaseEvent(QMouseEvent *ev)
383 QWebFrame *f = currentFrame(ev->pos());
387 QWebFramePrivate *frame = f->d;
388 if (!frame->frameView)
391 frame->eventHandler->handleMouseReleaseEvent(PlatformMouseEvent(ev, 0));
396 void QWebPagePrivate::contextMenuEvent(QContextMenuEvent *ev)
398 QWebFrame *f = currentFrame(ev->pos());
402 QWebFramePrivate *frame = f->d;
403 if (!frame->eventHandler)
406 page->contextMenuController()->clearContextMenu();
407 frame->eventHandler->sendContextMenuEvent(PlatformMouseEvent(ev, 1));
408 ContextMenu *menu = page->contextMenuController()->contextMenu();
410 QWebPageContext oldContext = currentContext;
411 currentContext = QWebPageContext(menu->hitTestResult());
413 const QList<ContextMenuItem> *items = menu->platformDescription();
414 QMenu *qmenu = createContextMenu(menu, items);
416 qmenu->exec(ev->globalPos());
419 currentContext = oldContext;
422 void QWebPagePrivate::wheelEvent(QWheelEvent *ev)
424 QWebFramePrivate *frame = currentFrame(ev->pos())->d;
426 bool accepted = false;
427 if (frame->eventHandler) {
428 WebCore::PlatformWheelEvent pev(ev);
429 accepted = frame->eventHandler->handleWheelEvent(pev);
432 ev->setAccepted(accepted);
435 void QWebPagePrivate::keyPressEvent(QKeyEvent *ev)
437 if (!mainFrame->d->eventHandler)
440 bool handled = false;
441 QWebFrame *frame = mainFrame;
442 WebCore::Editor *editor = frame->d->frame->editor();
443 if (editor->canEdit()) {
444 if (ev == QKeySequence::Cut) {
445 q->triggerAction(QWebPage::Cut);
447 } else if (ev == QKeySequence::Copy) {
448 q->triggerAction(QWebPage::Copy);
450 } else if (ev == QKeySequence::Paste) {
451 q->triggerAction(QWebPage::Paste);
453 } else if (ev == QKeySequence::Undo) {
454 q->triggerAction(QWebPage::Undo);
456 } else if (ev == QKeySequence::Redo) {
457 q->triggerAction(QWebPage::Redo);
459 } else if(ev == QKeySequence::MoveToNextChar) {
460 q->triggerAction(QWebPage::MoveToNextChar);
462 } else if(ev == QKeySequence::MoveToPreviousChar) {
463 q->triggerAction(QWebPage::MoveToPreviousChar);
465 } else if(ev == QKeySequence::MoveToNextWord) {
466 q->triggerAction(QWebPage::MoveToNextWord);
468 } else if(ev == QKeySequence::MoveToPreviousWord) {
469 q->triggerAction(QWebPage::MoveToPreviousWord);
471 } else if(ev == QKeySequence::MoveToNextLine) {
472 q->triggerAction(QWebPage::MoveToNextLine);
474 } else if(ev == QKeySequence::MoveToPreviousLine) {
475 q->triggerAction(QWebPage::MoveToPreviousLine);
477 // } else if(ev == QKeySequence::MoveToNextPage) {
478 // } else if(ev == QKeySequence::MoveToPreviousPage) {
479 } else if(ev == QKeySequence::MoveToStartOfLine) {
480 q->triggerAction(QWebPage::MoveToStartOfLine);
482 } else if(ev == QKeySequence::MoveToEndOfLine) {
483 q->triggerAction(QWebPage::MoveToEndOfLine);
485 } else if(ev == QKeySequence::MoveToStartOfBlock) {
486 q->triggerAction(QWebPage::MoveToStartOfBlock);
488 } else if(ev == QKeySequence::MoveToEndOfBlock) {
489 q->triggerAction(QWebPage::MoveToEndOfBlock);
491 } else if(ev == QKeySequence::MoveToStartOfDocument) {
492 q->triggerAction(QWebPage::MoveToStartOfDocument);
494 } else if(ev == QKeySequence::MoveToEndOfDocument) {
495 q->triggerAction(QWebPage::MoveToEndOfDocument);
497 } else if(ev == QKeySequence::SelectNextChar) {
498 q->triggerAction(QWebPage::SelectNextChar);
500 } else if(ev == QKeySequence::SelectPreviousChar) {
501 q->triggerAction(QWebPage::SelectPreviousChar);
503 } else if(ev == QKeySequence::SelectNextWord) {
504 q->triggerAction(QWebPage::SelectNextWord);
506 } else if(ev == QKeySequence::SelectPreviousWord) {
507 q->triggerAction(QWebPage::SelectPreviousWord);
509 } else if(ev == QKeySequence::SelectNextLine) {
510 q->triggerAction(QWebPage::SelectNextLine);
512 } else if(ev == QKeySequence::SelectPreviousLine) {
513 q->triggerAction(QWebPage::SelectPreviousLine);
515 // } else if(ev == QKeySequence::SelectNextPage) {
516 // } else if(ev == QKeySequence::SelectPreviousPage) {
517 } else if(ev == QKeySequence::SelectStartOfLine) {
518 q->triggerAction(QWebPage::SelectStartOfLine);
520 } else if(ev == QKeySequence::SelectEndOfLine) {
521 q->triggerAction(QWebPage::SelectEndOfLine);
523 } else if(ev == QKeySequence::SelectStartOfBlock) {
524 q->triggerAction(QWebPage::SelectStartOfBlock);
526 } else if(ev == QKeySequence::SelectEndOfBlock) {
527 q->triggerAction(QWebPage::SelectEndOfBlock);
529 } else if(ev == QKeySequence::SelectStartOfDocument) {
530 q->triggerAction(QWebPage::SelectStartOfDocument);
532 } else if(ev == QKeySequence::SelectEndOfDocument) {
533 q->triggerAction(QWebPage::SelectEndOfDocument);
535 } else if(ev == QKeySequence::DeleteStartOfWord) {
536 q->triggerAction(QWebPage::DeleteStartOfWord);
538 } else if(ev == QKeySequence::DeleteEndOfWord) {
539 q->triggerAction(QWebPage::DeleteEndOfWord);
541 // } else if(ev == QKeySequence::DeleteEndOfLine) {
545 handled = frame->d->eventHandler->keyEvent(ev);
548 PlatformScrollbar *h, *v;
549 h = mainFrame->d->horizontalScrollBar();
550 v = mainFrame->d->verticalScrollBar();
552 if (ev == QKeySequence::MoveToNextPage) {
554 v->setValue(v->value() + q->viewportSize().height());
555 } else if (ev == QKeySequence::MoveToPreviousPage) {
557 v->setValue(v->value() - q->viewportSize().height());
562 v->setValue(v->value() - 10);
566 v->setValue(v->value() + 10);
570 h->setValue(h->value() - 10);
574 h->setValue(h->value() + 10);
583 ev->setAccepted(handled);
586 void QWebPagePrivate::keyReleaseEvent(QKeyEvent *ev)
588 if (ev->isAutoRepeat()) {
589 ev->setAccepted(true);
593 if (!mainFrame->d->eventHandler)
596 bool handled = mainFrame->d->eventHandler->keyEvent(ev);
597 ev->setAccepted(handled);
600 void QWebPagePrivate::focusInEvent(QFocusEvent *ev)
602 if (ev->reason() != Qt::PopupFocusReason)
603 mainFrame->d->frame->page()->focusController()->setFocusedFrame(mainFrame->d->frame);
606 void QWebPagePrivate::focusOutEvent(QFocusEvent *ev)
608 if (ev->reason() != Qt::PopupFocusReason) {
609 mainFrame->d->frame->selectionController()->clear();
610 mainFrame->d->frame->setIsActive(false);
614 void QWebPagePrivate::dragEnterEvent(QDragEnterEvent *ev)
616 #ifndef QT_NO_DRAGANDDROP
617 DragData dragData(ev->mimeData(), ev->pos(), QCursor::pos(),
618 dropActionToDragOp(ev->possibleActions()));
619 Qt::DropAction action = dragOpToDropAction(page->dragController()->dragEntered(&dragData));
620 ev->setDropAction(action);
625 void QWebPagePrivate::dragLeaveEvent(QDragLeaveEvent *ev)
627 #ifndef QT_NO_DRAGANDDROP
628 DragData dragData(0, IntPoint(), QCursor::pos(), DragOperationNone);
629 page->dragController()->dragExited(&dragData);
634 void QWebPagePrivate::dragMoveEvent(QDragMoveEvent *ev)
636 #ifndef QT_NO_DRAGANDDROP
637 DragData dragData(ev->mimeData(), ev->pos(), QCursor::pos(),
638 dropActionToDragOp(ev->possibleActions()));
639 Qt::DropAction action = dragOpToDropAction(page->dragController()->dragUpdated(&dragData));
640 ev->setDropAction(action);
645 void QWebPagePrivate::dropEvent(QDropEvent *ev)
647 #ifndef QT_NO_DRAGANDDROP
648 DragData dragData(ev->mimeData(), ev->pos(), QCursor::pos(),
649 dropActionToDragOp(ev->possibleActions()));
650 Qt::DropAction action = dragOpToDropAction(page->dragController()->performDrag(&dragData));
655 QWebPage::QWebPage(QObject *parent)
657 , d(new QWebPagePrivate(this))
659 setView(qobject_cast<QWidget *>(parent));
661 connect(this, SIGNAL(loadProgressChanged(int)), this, SLOT(_q_onLoadProgressChanged(int)));
664 QWebPage::~QWebPage()
666 FrameLoader *loader = d->mainFrame->d->frame->loader();
668 loader->detachFromParent();
672 QWebFrame *QWebPage::mainFrame() const
674 d->createMainFrame();
678 QWebFrame *QWebPage::currentFrame() const
680 return static_cast<WebCore::FrameLoaderClientQt *>(d->page->focusController()->focusedOrMainFrame()->loader()->client())->webFrame();
683 QWebPageHistory *QWebPage::history() const
688 void QWebPage::setView(QWidget *view)
691 setViewportSize(view ? view->size() : QSize(0, 0));
694 QWidget *QWebPage::view() const
700 void QWebPage::javaScriptConsoleMessage(const QString& message, unsigned int lineNumber, const QString& sourceID)
704 void QWebPage::javaScriptAlert(QWebFrame *frame, const QString& msg)
707 QMessageBox::information(d->view, mainFrame()->title(), msg, QMessageBox::Ok);
710 bool QWebPage::javaScriptConfirm(QWebFrame *frame, const QString& msg)
713 return 0 == QMessageBox::information(d->view, mainFrame()->title(), msg, QMessageBox::Yes, QMessageBox::No);
716 bool QWebPage::javaScriptPrompt(QWebFrame *frame, const QString& msg, const QString& defaultValue, QString* result)
720 #ifndef QT_NO_INPUTDIALOG
721 QString x = QInputDialog::getText(d->view, mainFrame()->title(), msg, QLineEdit::Normal, defaultValue, &ok);
729 QWebPage *QWebPage::createWindow()
734 QWebPage *QWebPage::createModalDialog()
739 QObject *QWebPage::createPlugin(const QString &classid, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues)
744 Q_UNUSED(paramValues)
748 static WebCore::FrameLoadRequest frameLoadRequest(const QUrl &url, WebCore::Frame *frame)
750 WebCore::ResourceRequest rr(WebCore::KURL(url.toString()),
751 frame->loader()->outgoingReferrer());
752 return WebCore::FrameLoadRequest(rr);
755 static void openNewWindow(const QUrl& url, WebCore::Frame* frame)
757 if (Page* oldPage = frame->page()) {
758 WindowFeatures features;
759 if (Page* newPage = oldPage->chrome()->createWindow(frame,
760 frameLoadRequest(url, frame), features))
761 newPage->chrome()->show();
765 void QWebPage::triggerAction(WebAction action, bool checked)
767 WebCore::Frame *frame = d->page->focusController()->focusedOrMainFrame();
768 WebCore::Editor *editor = frame->editor();
769 const char *command = 0;
773 if (QWebFrame *targetFrame = d->currentContext.targetFrame()) {
774 WTF::RefPtr<WebCore::Frame> wcFrame = targetFrame->d->frame;
775 targetFrame->d->frame->loader()->load(frameLoadRequest(d->currentContext.linkUrl(), wcFrame.get()),
776 /*lockHistory*/ false,
777 /*userGesture*/ true,
779 /*HTMLFormElement*/ 0,
781 WTF::HashMap<String, String>());
786 case OpenLinkInNewWindow:
787 openNewWindow(d->currentContext.linkUrl(), frame);
789 case OpenFrameInNewWindow:
791 case DownloadLinkToDisk:
792 case CopyLinkToClipboard:
793 editor->copyURL(WebCore::KURL(d->currentContext.linkUrl().toString()), d->currentContext.text());
795 case OpenImageInNewWindow:
796 openNewWindow(d->currentContext.imageUrl(), frame);
798 case DownloadImageToDisk:
799 case CopyImageToClipboard:
805 d->page->goForward();
808 mainFrame()->d->frame->loader()->stopForUserCancel();
811 mainFrame()->d->frame->loader()->reload();
831 command = "MoveForward";
833 case MoveToPreviousChar:
834 command = "MoveBackward";
837 command = "MoveWordForward";
839 case MoveToPreviousWord:
840 command = "MoveWordBackward";
843 command = "MoveDown";
845 case MoveToPreviousLine:
848 case MoveToStartOfLine:
849 command = "MoveToBeginningOfLine";
851 case MoveToEndOfLine:
852 command = "MoveToEndOfLine";
854 case MoveToStartOfBlock:
855 command = "MoveToBeginningOfParagraph";
857 case MoveToEndOfBlock:
858 command = "MoveToEndOfParagraph";
860 case MoveToStartOfDocument:
861 command = "MoveToBeginningOfDocument";
863 case MoveToEndOfDocument:
864 command = "MoveToEndOfDocument";
867 command = "MoveForwardAndModifySelection";
869 case SelectPreviousChar:
870 command = "MoveBackwardAndModifySelection";
873 command = "MoveWordForwardAndModifySelection";
875 case SelectPreviousWord:
876 command = "MoveWordBackwardAndModifySelection";
879 command = "MoveDownAndModifySelection";
881 case SelectPreviousLine:
882 command = "MoveUpAndModifySelection";
884 case SelectStartOfLine:
885 command = "MoveToBeginningOfLineAndModifySelection";
887 case SelectEndOfLine:
888 command = "MoveToEndOfLineAndModifySelection";
890 case SelectStartOfBlock:
891 command = "MoveToBeginningOfParagraphAndModifySelection";
893 case SelectEndOfBlock:
894 command = "MoveToEndOfParagraphAndModifySelection";
896 case SelectStartOfDocument:
897 command = "MoveToBeginningOfDocumentAndModifySelection";
899 case SelectEndOfDocument:
900 command = "MoveToEndOfDocumentAndModifySelection";
902 case DeleteStartOfWord:
903 command = "DeleteWordBackward";
905 case DeleteEndOfWord:
906 command = "DeleteWordForward";
909 case SetTextDirectionDefault:
910 editor->setBaseWritingDirection("inherit");
912 case SetTextDirectionLeftToRight:
913 editor->setBaseWritingDirection("ltr");
915 case SetTextDirectionRightToLeft:
916 editor->setBaseWritingDirection("rtl");
920 command = "ToggleBold";
923 command = "ToggleItalic";
925 case ToggleUnderline:
926 editor->toggleUnderline();
929 d->page->inspectorController()->inspect(d->currentContext.d->innerNonSharedNode.get());
936 editor->command(command).execute();
939 QSize QWebPage::viewportSize() const
941 QWebFrame *frame = mainFrame();
942 if (frame->d->frame && frame->d->frameView)
943 return frame->d->frameView->frameGeometry().size();
947 void QWebPage::setViewportSize(const QSize &size) const
949 QWebFrame *frame = mainFrame();
950 if (frame->d->frame && frame->d->frameView) {
951 frame->d->frameView->setFrameGeometry(QRect(QPoint(0, 0), size));
952 frame->d->frame->forceLayout();
953 frame->d->frame->view()->adjustViewSize();
958 #if QT_VERSION < 0x040400
959 QWebPage::NavigationRequestResponse QWebPage::navigationRequested(QWebFrame *frame, const QWebNetworkRequest &request, QWebPage::NavigationType type)
961 QWebPage::NavigationRequestResponse QWebPage::navigationRequested(QWebFrame *frame, const QNetworkRequest &request, QWebPage::NavigationType type)
965 return AcceptNavigationRequest;
968 QString QWebPage::selectedText() const
970 return d->page->focusController()->focusedOrMainFrame()->selectedText();
973 QAction *QWebPage::action(WebAction action) const
975 if (action == QWebPage::NoWebAction) return 0;
976 if (d->actions[action])
977 return d->actions[action];
980 bool checkable = false;
984 text = contextMenuItemTagOpenLink();
986 case OpenLinkInNewWindow:
987 text = contextMenuItemTagOpenLinkInNewWindow();
989 case OpenFrameInNewWindow:
990 text = contextMenuItemTagOpenFrameInNewWindow();
993 case DownloadLinkToDisk:
994 text = contextMenuItemTagDownloadLinkToDisk();
996 case CopyLinkToClipboard:
997 text = contextMenuItemTagCopyLinkToClipboard();
1000 case OpenImageInNewWindow:
1001 text = contextMenuItemTagOpenImageInNewWindow();
1003 case DownloadImageToDisk:
1004 text = contextMenuItemTagDownloadImageToDisk();
1006 case CopyImageToClipboard:
1007 text = contextMenuItemTagCopyImageToClipboard();
1011 text = contextMenuItemTagGoBack();
1014 text = contextMenuItemTagGoForward();
1017 text = contextMenuItemTagStop();
1020 text = contextMenuItemTagReload();
1024 text = contextMenuItemTagCut();
1027 text = contextMenuItemTagCopy();
1030 text = contextMenuItemTagPaste();
1034 QAction *a = undoStack()->createUndoAction(d->q);
1035 d->actions[action] = a;
1039 QAction *a = undoStack()->createRedoAction(d->q);
1040 d->actions[action] = a;
1043 case MoveToNextChar:
1044 case MoveToPreviousChar:
1045 case MoveToNextWord:
1046 case MoveToPreviousWord:
1047 case MoveToNextLine:
1048 case MoveToPreviousLine:
1049 case MoveToStartOfLine:
1050 case MoveToEndOfLine:
1051 case MoveToStartOfBlock:
1052 case MoveToEndOfBlock:
1053 case MoveToStartOfDocument:
1054 case MoveToEndOfDocument:
1055 case SelectNextChar:
1056 case SelectPreviousChar:
1057 case SelectNextWord:
1058 case SelectPreviousWord:
1059 case SelectNextLine:
1060 case SelectPreviousLine:
1061 case SelectStartOfLine:
1062 case SelectEndOfLine:
1063 case SelectStartOfBlock:
1064 case SelectEndOfBlock:
1065 case SelectStartOfDocument:
1066 case SelectEndOfDocument:
1067 case DeleteStartOfWord:
1068 case DeleteEndOfWord:
1071 case SetTextDirectionDefault:
1072 text = contextMenuItemTagDefaultDirection();
1074 case SetTextDirectionLeftToRight:
1075 text = contextMenuItemTagLeftToRight();
1078 case SetTextDirectionRightToLeft:
1079 text = contextMenuItemTagRightToLeft();
1084 text = contextMenuItemTagBold();
1088 text = contextMenuItemTagItalic();
1091 case ToggleUnderline:
1092 text = contextMenuItemTagUnderline();
1096 case InspectElement:
1097 text = contextMenuItemTagInspectElement();
1107 QAction *a = new QAction(d->q);
1110 a->setCheckable(checkable);
1112 connect(a, SIGNAL(triggered(bool)),
1113 this, SLOT(_q_webActionTriggered(bool)));
1115 d->actions[action] = a;
1116 d->updateAction(action);
1121 Returns true if the page contains unsubmitted form data.
1123 bool QWebPage::isModified() const
1129 QUndoStack *QWebPage::undoStack() const
1132 d->undoStack = new QUndoStack(const_cast<QWebPage *>(this));
1134 return d->undoStack;
1139 bool QWebPage::event(QEvent *ev)
1141 switch (ev->type()) {
1142 case QEvent::MouseMove:
1143 d->mouseMoveEvent(static_cast<QMouseEvent*>(ev));
1145 case QEvent::MouseButtonPress:
1146 d->mousePressEvent(static_cast<QMouseEvent*>(ev));
1148 case QEvent::MouseButtonDblClick:
1149 d->mouseDoubleClickEvent(static_cast<QMouseEvent*>(ev));
1151 case QEvent::MouseButtonRelease:
1152 d->mouseReleaseEvent(static_cast<QMouseEvent*>(ev));
1154 case QEvent::ContextMenu:
1155 d->contextMenuEvent(static_cast<QContextMenuEvent*>(ev));
1158 d->wheelEvent(static_cast<QWheelEvent*>(ev));
1160 case QEvent::KeyPress:
1161 d->keyPressEvent(static_cast<QKeyEvent*>(ev));
1163 case QEvent::KeyRelease:
1164 d->keyReleaseEvent(static_cast<QKeyEvent*>(ev));
1166 case QEvent::FocusIn:
1167 d->focusInEvent(static_cast<QFocusEvent*>(ev));
1169 case QEvent::FocusOut:
1170 d->focusOutEvent(static_cast<QFocusEvent*>(ev));
1172 case QEvent::DragEnter:
1173 d->dragEnterEvent(static_cast<QDragEnterEvent*>(ev));
1175 case QEvent::DragLeave:
1176 d->dragLeaveEvent(static_cast<QDragLeaveEvent*>(ev));
1178 case QEvent::DragMove:
1179 d->dragMoveEvent(static_cast<QDragMoveEvent*>(ev));
1182 d->dropEvent(static_cast<QDropEvent*>(ev));
1185 return QObject::event(ev);
1191 bool QWebPage::focusNextPrevChild(bool next)
1197 QWebSettings *QWebPage::settings()
1202 QString QWebPage::chooseFile(QWebFrame *parentFrame, const QString& oldFile)
1204 //FIXME frame pos...
1205 #ifndef QT_NO_FILEDIALOG
1206 return QFileDialog::getOpenFileName(d->view, QString::null, oldFile);
1208 return QString::null;
1212 #if QT_VERSION < 0x040400
1214 void QWebPage::setNetworkInterface(QWebNetworkInterface *interface)
1216 d->networkInterface = interface;
1219 QWebNetworkInterface *QWebPage::networkInterface() const
1221 if (d->networkInterface)
1222 return d->networkInterface;
1224 return QWebNetworkInterface::defaultInterface();
1227 #ifndef QT_NO_NETWORKPROXY
1228 void QWebPage::setNetworkProxy(const QNetworkProxy& proxy)
1230 d->networkProxy = proxy;
1233 QNetworkProxy QWebPage::networkProxy() const
1235 return d->networkProxy;
1241 void QWebPage::setNetworkAccessManager(QNetworkAccessManager *manager)
1243 if (manager == d->networkManager)
1245 delete d->networkManager;
1246 d->networkManager = manager;
1249 QNetworkAccessManager *QWebPage::networkAccessManager() const
1251 if (!d->networkManager) {
1252 QWebPage *that = const_cast<QWebPage *>(this);
1253 that->d->networkManager = new QNetworkAccessManager(that);
1255 return d->networkManager;
1260 QString QWebPage::userAgentFor(const QUrl& url) const {
1262 return QLatin1String("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/418.9.1 (KHTML, like Gecko) Safari/419.3 Qt");
1266 void QWebPagePrivate::_q_onLoadProgressChanged(int) {
1267 m_totalBytes = page->progress()->totalPageAndResourceBytesToLoad();
1268 m_bytesReceived = page->progress()->totalBytesReceived();
1272 quint64 QWebPage::totalBytes() const {
1273 return d->m_bytesReceived;
1277 quint64 QWebPage::bytesReceived() const {
1278 return d->m_totalBytes;
1281 QWebPageContext::QWebPageContext(const WebCore::HitTestResult &hitTest)
1282 : d(new QWebPageContextPrivate)
1284 d->pos = hitTest.point();
1285 d->text = hitTest.textContent();
1286 d->linkUrl = hitTest.absoluteLinkURL().string();
1287 d->imageUrl = hitTest.absoluteImageURL().string();
1288 d->innerNonSharedNode = hitTest.innerNonSharedNode();
1289 WebCore::Image *img = hitTest.image();
1291 QPixmap *pix = img->getPixmap();
1295 WebCore::Frame *frame = hitTest.targetFrame();
1297 d->targetFrame = frame->view()->qwebframe();
1300 QWebPageContext::QWebPageContext()
1305 QWebPageContext::QWebPageContext(const QWebPageContext &other)
1309 d = new QWebPageContextPrivate(*other.d);
1312 QWebPageContext &QWebPageContext::operator=(const QWebPageContext &other)
1314 if (this != &other) {
1317 d = new QWebPageContextPrivate;
1327 QWebPageContext::~QWebPageContext()
1332 QPoint QWebPageContext::pos() const
1339 QString QWebPageContext::text() const
1346 QUrl QWebPageContext::linkUrl() const
1353 QUrl QWebPageContext::imageUrl() const
1360 QPixmap QWebPageContext::image() const
1367 QWebFrame *QWebPageContext::targetFrame() const
1371 return d->targetFrame;
1374 #include "moc_qwebpage.cpp"