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 static inline DragOperation dropActionToDragOp(Qt::DropActions actions)
82 if (actions & Qt::CopyAction)
83 result |= DragOperationCopy;
84 if (actions & Qt::MoveAction)
85 result |= DragOperationMove;
86 if (actions & Qt::LinkAction)
87 result |= DragOperationLink;
88 return (DragOperation)result;
91 static inline Qt::DropAction dragOpToDropAction(unsigned actions)
93 Qt::DropAction result = Qt::IgnoreAction;
94 if (actions & DragOperationCopy)
95 result = Qt::CopyAction;
96 else if (actions & DragOperationMove)
97 result = Qt::MoveAction;
98 else if (actions & DragOperationLink)
99 result = Qt::LinkAction;
103 QWebPagePrivate::QWebPagePrivate(QWebPage *qq)
108 chromeClient = new ChromeClientQt(q);
109 contextMenuClient = new ContextMenuClientQt();
110 editorClient = new EditorClientQt(q);
111 page = new Page(chromeClient, contextMenuClient, editorClient,
112 new DragClientQt(q), new InspectorClientQt(q));
114 // ### should be configurable
115 page->settings()->setDefaultTextEncodingName("iso-8859-1");
117 settings = new QWebSettings(page->settings());
121 networkInterface = 0;
122 insideOpenCall = false;
124 history.d = new QWebPageHistoryPrivate(page->backForwardList());
125 memset(actions, 0, sizeof(actions));
128 QWebPagePrivate::~QWebPagePrivate()
135 QWebPage::NavigationRequestResponse QWebPagePrivate::navigationRequested(QWebFrame *frame, const QWebNetworkRequest &request, QWebPage::NavigationType type)
138 && frame == mainFrame)
139 return QWebPage::AcceptNavigationRequest;
140 return q->navigationRequested(frame, request, type);
143 void QWebPagePrivate::createMainFrame()
146 QWebFrameData frameData;
147 frameData.ownerElement = 0;
148 frameData.allowsScrolling = true;
149 frameData.marginWidth = 0;
150 frameData.marginHeight = 0;
151 mainFrame = new QWebFrame(q, &frameData);
152 mainFrame->d->frameView->setFrameGeometry(IntRect(IntPoint(0,0), q->viewportSize()));
154 emit q->frameCreated(mainFrame);
158 static QWebPage::WebAction webActionForContextMenuAction(WebCore::ContextMenuAction action)
161 case WebCore::ContextMenuItemTagOpenLink: return QWebPage::OpenLink;
162 case WebCore::ContextMenuItemTagOpenLinkInNewWindow: return QWebPage::OpenLinkInNewWindow;
163 case WebCore::ContextMenuItemTagDownloadLinkToDisk: return QWebPage::DownloadLinkToDisk;
164 case WebCore::ContextMenuItemTagCopyLinkToClipboard: return QWebPage::CopyLinkToClipboard;
165 case WebCore::ContextMenuItemTagOpenImageInNewWindow: return QWebPage::OpenImageInNewWindow;
166 case WebCore::ContextMenuItemTagDownloadImageToDisk: return QWebPage::DownloadImageToDisk;
167 case WebCore::ContextMenuItemTagCopyImageToClipboard: return QWebPage::CopyImageToClipboard;
168 case WebCore::ContextMenuItemTagOpenFrameInNewWindow: return QWebPage::OpenFrameInNewWindow;
169 case WebCore::ContextMenuItemTagCopy: return QWebPage::Copy;
170 case WebCore::ContextMenuItemTagGoBack: return QWebPage::GoBack;
171 case WebCore::ContextMenuItemTagGoForward: return QWebPage::GoForward;
172 case WebCore::ContextMenuItemTagStop: return QWebPage::Stop;
173 case WebCore::ContextMenuItemTagReload: return QWebPage::Reload;
174 case WebCore::ContextMenuItemTagCut: return QWebPage::Cut;
175 case WebCore::ContextMenuItemTagPaste: return QWebPage::Paste;
176 case WebCore::ContextMenuItemTagDefaultDirection: return QWebPage::SetTextDirectionDefault;
177 case WebCore::ContextMenuItemTagLeftToRight: return QWebPage::SetTextDirectionLeftToRight;
178 case WebCore::ContextMenuItemTagRightToLeft: return QWebPage::SetTextDirectionRightToLeft;
179 case WebCore::ContextMenuItemTagBold: return QWebPage::ToggleBold;
180 case WebCore::ContextMenuItemTagItalic: return QWebPage::ToggleItalic;
181 case WebCore::ContextMenuItemTagUnderline: return QWebPage::ToggleUnderline;
182 case WebCore::ContextMenuItemTagInspectElement: return QWebPage::InspectElement;
185 return QWebPage::NoWebAction;
188 QMenu *QWebPagePrivate::createContextMenu(const WebCore::ContextMenu *webcoreMenu, const QList<WebCore::ContextMenuItem> *items)
190 QMenu *menu = new QMenu;
191 for (int i = 0; i < items->count(); ++i) {
192 const ContextMenuItem &item = items->at(i);
193 switch (item.type()) {
194 case WebCore::ActionType: {
195 QWebPage::WebAction action = webActionForContextMenuAction(item.action());
196 QAction *a = q->action(action);
198 ContextMenuItem it(item);
199 webcoreMenu->checkOrEnableIfNeeded(it);
200 PlatformMenuItemDescription desc = it.releasePlatformDescription();
201 a->setEnabled(desc.enabled);
202 a->setChecked(desc.checked);
208 case WebCore::SeparatorType:
209 menu->addSeparator();
211 case WebCore::SubmenuType: {
212 QMenu *subMenu = createContextMenu(webcoreMenu, item.platformSubMenu());
213 if (!subMenu->actions().isEmpty()) {
214 subMenu->setTitle(item.title());
215 menu->addAction(subMenu->menuAction());
226 QWebFrame *QWebPagePrivate::frameAt(const QPoint &pos) const
228 QWebFrame *frame = mainFrame;
231 QList<QWebFrame*> children = frame->childFrames();
232 for (int i = 0; i < children.size(); ++i) {
233 if (children.at(i)->geometry().contains(pos)) {
234 frame = children.at(i);
238 if (frame->geometry().contains(pos))
243 void QWebPagePrivate::_q_webActionTriggered(bool checked)
245 QAction *a = qobject_cast<QAction *>(q->sender());
248 QWebPage::WebAction action = static_cast<QWebPage::WebAction>(a->data().toInt());
249 q->triggerAction(action, checked);
252 void QWebPagePrivate::updateAction(QWebPage::WebAction action)
254 QAction *a = actions[action];
255 if (!a || !mainFrame)
258 WebCore::FrameLoader *loader = mainFrame->d->frame->loader();
259 WebCore::Editor *editor = page->focusController()->focusedOrMainFrame()->editor();
261 bool enabled = a->isEnabled();
264 case QWebPage::GoBack:
265 enabled = loader->canGoBackOrForward(-1);
267 case QWebPage::GoForward:
268 enabled = loader->canGoBackOrForward(1);
271 enabled = loader->isLoading();
273 case QWebPage::Reload:
274 enabled = !loader->isLoading();
277 enabled = editor->canCut();
280 enabled = editor->canCopy();
282 case QWebPage::Paste:
283 enabled = editor->canPaste();
287 // those two are handled by QUndoStack
292 a->setEnabled(enabled);
295 void QWebPagePrivate::updateNavigationActions()
297 updateAction(QWebPage::GoBack);
298 updateAction(QWebPage::GoForward);
299 updateAction(QWebPage::Stop);
300 updateAction(QWebPage::Reload);
303 void QWebPagePrivate::updateEditorActions()
305 updateAction(QWebPage::Cut);
306 updateAction(QWebPage::Copy);
307 updateAction(QWebPage::Paste);
310 void QWebPagePrivate::mouseMoveEvent(QMouseEvent *ev)
312 QWebFrame *f = currentFrame(ev->pos());
316 QWebFramePrivate *frame = f->d;
317 if (!frame->frameView)
320 frame->eventHandler->handleMouseMoveEvent(PlatformMouseEvent(ev, 0));
322 frame->horizontalScrollBar() ? frame->horizontalScrollBar()->value() : 0;
324 frame->verticalScrollBar() ? frame->verticalScrollBar()->value() : 0;
325 IntPoint pt(ev->x() + xOffset, ev->y() + yOffset);
326 WebCore::HitTestResult result = frame->eventHandler->hitTestResultAtPoint(pt, false);
327 WebCore::Element *link = result.URLElement();
328 if (link != frame->lastHoverElement) {
329 frame->lastHoverElement = link;
330 emit q->hoveringOverLink(result.absoluteLinkURL().prettyURL(), result.title(), result.textContent());
334 void QWebPagePrivate::mousePressEvent(QMouseEvent *ev)
336 frameUnderMouse = frameAt(ev->pos());
337 if (!frameUnderMouse)
340 QWebFramePrivate *frame = frameUnderMouse->d;
341 if (!frame->eventHandler)
344 frame->eventHandler->handleMousePressEvent(PlatformMouseEvent(ev, 1));
347 void QWebPagePrivate::mouseDoubleClickEvent(QMouseEvent *ev)
349 QWebFrame *f = currentFrame(ev->pos());
353 QWebFramePrivate *frame = f->d;
354 if (!frame->eventHandler)
357 frame->eventHandler->handleMousePressEvent(PlatformMouseEvent(ev, 2));
360 void QWebPagePrivate::mouseReleaseEvent(QMouseEvent *ev)
362 QWebFrame *f = currentFrame(ev->pos());
366 QWebFramePrivate *frame = f->d;
367 if (!frame->frameView)
370 frame->eventHandler->handleMouseReleaseEvent(PlatformMouseEvent(ev, 0));
375 void QWebPagePrivate::contextMenuEvent(QContextMenuEvent *ev)
377 QWebFrame *f = currentFrame(ev->pos());
381 QWebFramePrivate *frame = f->d;
382 if (!frame->eventHandler)
385 page->contextMenuController()->clearContextMenu();
386 frame->eventHandler->sendContextMenuEvent(PlatformMouseEvent(ev, 1));
387 ContextMenu *menu = page->contextMenuController()->contextMenu();
389 QWebPageContext oldContext = currentContext;
390 currentContext = QWebPageContext(menu->hitTestResult());
392 const QList<ContextMenuItem> *items = menu->platformDescription();
393 QMenu *qmenu = createContextMenu(menu, items);
395 qmenu->exec(ev->globalPos());
398 currentContext = oldContext;
401 void QWebPagePrivate::wheelEvent(QWheelEvent *ev)
403 QWebFramePrivate *frame = currentFrame(ev->pos())->d;
405 bool accepted = false;
406 if (frame->eventHandler) {
407 WebCore::PlatformWheelEvent pev(ev);
408 accepted = frame->eventHandler->handleWheelEvent(pev);
411 ev->setAccepted(accepted);
414 void QWebPagePrivate::keyPressEvent(QKeyEvent *ev)
416 if (!mainFrame->d->eventHandler)
419 bool handled = false;
420 QWebFrame *frame = mainFrame;
421 WebCore::Editor *editor = frame->d->frame->editor();
422 if (editor->canEdit()) {
423 if (ev == QKeySequence::Cut) {
424 q->triggerAction(QWebPage::Cut);
426 } else if (ev == QKeySequence::Copy) {
427 q->triggerAction(QWebPage::Copy);
429 } else if (ev == QKeySequence::Paste) {
430 q->triggerAction(QWebPage::Paste);
432 } else if (ev == QKeySequence::Undo) {
433 q->triggerAction(QWebPage::Undo);
435 } else if (ev == QKeySequence::Redo) {
436 q->triggerAction(QWebPage::Redo);
438 } else if(ev == QKeySequence::MoveToNextChar) {
439 q->triggerAction(QWebPage::MoveToNextChar);
441 } else if(ev == QKeySequence::MoveToPreviousChar) {
442 q->triggerAction(QWebPage::MoveToPreviousChar);
444 } else if(ev == QKeySequence::MoveToNextWord) {
445 q->triggerAction(QWebPage::MoveToNextWord);
447 } else if(ev == QKeySequence::MoveToPreviousWord) {
448 q->triggerAction(QWebPage::MoveToPreviousWord);
450 } else if(ev == QKeySequence::MoveToNextLine) {
451 q->triggerAction(QWebPage::MoveToNextLine);
453 } else if(ev == QKeySequence::MoveToPreviousLine) {
454 q->triggerAction(QWebPage::MoveToPreviousLine);
456 // } else if(ev == QKeySequence::MoveToNextPage) {
457 // } else if(ev == QKeySequence::MoveToPreviousPage) {
458 } else if(ev == QKeySequence::MoveToStartOfLine) {
459 q->triggerAction(QWebPage::MoveToStartOfLine);
461 } else if(ev == QKeySequence::MoveToEndOfLine) {
462 q->triggerAction(QWebPage::MoveToEndOfLine);
464 } else if(ev == QKeySequence::MoveToStartOfBlock) {
465 q->triggerAction(QWebPage::MoveToStartOfBlock);
467 } else if(ev == QKeySequence::MoveToEndOfBlock) {
468 q->triggerAction(QWebPage::MoveToEndOfBlock);
470 } else if(ev == QKeySequence::MoveToStartOfDocument) {
471 q->triggerAction(QWebPage::MoveToStartOfDocument);
473 } else if(ev == QKeySequence::MoveToEndOfDocument) {
474 q->triggerAction(QWebPage::MoveToEndOfDocument);
476 } else if(ev == QKeySequence::SelectNextChar) {
477 q->triggerAction(QWebPage::SelectNextChar);
479 } else if(ev == QKeySequence::SelectPreviousChar) {
480 q->triggerAction(QWebPage::SelectPreviousChar);
482 } else if(ev == QKeySequence::SelectNextWord) {
483 q->triggerAction(QWebPage::SelectNextWord);
485 } else if(ev == QKeySequence::SelectPreviousWord) {
486 q->triggerAction(QWebPage::SelectPreviousWord);
488 } else if(ev == QKeySequence::SelectNextLine) {
489 q->triggerAction(QWebPage::SelectNextLine);
491 } else if(ev == QKeySequence::SelectPreviousLine) {
492 q->triggerAction(QWebPage::SelectPreviousLine);
494 // } else if(ev == QKeySequence::SelectNextPage) {
495 // } else if(ev == QKeySequence::SelectPreviousPage) {
496 } else if(ev == QKeySequence::SelectStartOfLine) {
497 q->triggerAction(QWebPage::SelectStartOfLine);
499 } else if(ev == QKeySequence::SelectEndOfLine) {
500 q->triggerAction(QWebPage::SelectEndOfLine);
502 } else if(ev == QKeySequence::SelectStartOfBlock) {
503 q->triggerAction(QWebPage::SelectStartOfBlock);
505 } else if(ev == QKeySequence::SelectEndOfBlock) {
506 q->triggerAction(QWebPage::SelectEndOfBlock);
508 } else if(ev == QKeySequence::SelectStartOfDocument) {
509 q->triggerAction(QWebPage::SelectStartOfDocument);
511 } else if(ev == QKeySequence::SelectEndOfDocument) {
512 q->triggerAction(QWebPage::SelectEndOfDocument);
514 } else if(ev == QKeySequence::DeleteStartOfWord) {
515 q->triggerAction(QWebPage::DeleteStartOfWord);
517 } else if(ev == QKeySequence::DeleteEndOfWord) {
518 q->triggerAction(QWebPage::DeleteEndOfWord);
520 // } else if(ev == QKeySequence::DeleteEndOfLine) {
524 handled = frame->d->eventHandler->keyEvent(ev);
527 PlatformScrollbar *h, *v;
528 h = mainFrame->d->horizontalScrollBar();
529 v = mainFrame->d->verticalScrollBar();
531 if (ev == QKeySequence::MoveToNextPage) {
533 v->setValue(v->value() + q->viewportSize().height());
534 } else if (ev == QKeySequence::MoveToPreviousPage) {
536 v->setValue(v->value() - q->viewportSize().height());
541 v->setValue(v->value() - 10);
545 v->setValue(v->value() + 10);
549 h->setValue(h->value() - 10);
553 h->setValue(h->value() + 10);
562 ev->setAccepted(handled);
565 void QWebPagePrivate::keyReleaseEvent(QKeyEvent *ev)
567 if (ev->isAutoRepeat()) {
568 ev->setAccepted(true);
572 if (!mainFrame->d->eventHandler)
575 bool handled = mainFrame->d->eventHandler->keyEvent(ev);
576 ev->setAccepted(handled);
579 void QWebPagePrivate::focusInEvent(QFocusEvent *ev)
581 if (ev->reason() != Qt::PopupFocusReason)
582 mainFrame->d->frame->page()->focusController()->setFocusedFrame(mainFrame->d->frame);
585 void QWebPagePrivate::focusOutEvent(QFocusEvent *ev)
587 if (ev->reason() != Qt::PopupFocusReason) {
588 mainFrame->d->frame->selectionController()->clear();
589 mainFrame->d->frame->setIsActive(false);
593 void QWebPagePrivate::dragEnterEvent(QDragEnterEvent *ev)
595 #ifndef QT_NO_DRAGANDDROP
596 DragData dragData(ev->mimeData(), ev->pos(), QCursor::pos(),
597 dropActionToDragOp(ev->possibleActions()));
598 Qt::DropAction action = dragOpToDropAction(page->dragController()->dragEntered(&dragData));
599 ev->setDropAction(action);
604 void QWebPagePrivate::dragLeaveEvent(QDragLeaveEvent *ev)
606 #ifndef QT_NO_DRAGANDDROP
607 DragData dragData(0, IntPoint(), QCursor::pos(), DragOperationNone);
608 page->dragController()->dragExited(&dragData);
613 void QWebPagePrivate::dragMoveEvent(QDragMoveEvent *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()->dragUpdated(&dragData));
619 ev->setDropAction(action);
624 void QWebPagePrivate::dropEvent(QDropEvent *ev)
626 #ifndef QT_NO_DRAGANDDROP
627 DragData dragData(ev->mimeData(), ev->pos(), QCursor::pos(),
628 dropActionToDragOp(ev->possibleActions()));
629 Qt::DropAction action = dragOpToDropAction(page->dragController()->performDrag(&dragData));
634 QWebPage::QWebPage(QObject *parent)
636 , d(new QWebPagePrivate(this))
638 setView(qobject_cast<QWidget *>(parent));
640 connect(this, SIGNAL(loadProgressChanged(int)), this, SLOT(_q_onLoadProgressChanged(int)));
643 QWebPage::~QWebPage()
645 FrameLoader *loader = d->mainFrame->d->frame->loader();
647 loader->detachFromParent();
651 QWebFrame *QWebPage::mainFrame() const
653 d->createMainFrame();
657 QWebFrame *QWebPage::currentFrame() const
659 return static_cast<WebCore::FrameLoaderClientQt *>(d->page->focusController()->focusedOrMainFrame()->loader()->client())->webFrame();
662 QWebPageHistory *QWebPage::history() const
667 void QWebPage::setView(QWidget *view)
670 setViewportSize(view ? view->size() : QSize(0, 0));
673 QWidget *QWebPage::view() const
679 void QWebPage::javaScriptConsoleMessage(const QString& message, unsigned int lineNumber, const QString& sourceID)
683 void QWebPage::javaScriptAlert(QWebFrame *frame, const QString& msg)
686 QMessageBox::information(d->view, mainFrame()->title(), msg, QMessageBox::Ok);
689 bool QWebPage::javaScriptConfirm(QWebFrame *frame, const QString& msg)
692 return 0 == QMessageBox::information(d->view, mainFrame()->title(), msg, QMessageBox::Yes, QMessageBox::No);
695 bool QWebPage::javaScriptPrompt(QWebFrame *frame, const QString& msg, const QString& defaultValue, QString* result)
699 #ifndef QT_NO_INPUTDIALOG
700 QString x = QInputDialog::getText(d->view, mainFrame()->title(), msg, QLineEdit::Normal, defaultValue, &ok);
708 QWebPage *QWebPage::createWindow()
713 QWebPage *QWebPage::createModalDialog()
718 QObject *QWebPage::createPlugin(const QString &classid, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues)
723 Q_UNUSED(paramValues)
727 static WebCore::FrameLoadRequest frameLoadRequest(const QUrl &url, WebCore::Frame *frame)
729 WebCore::ResourceRequest rr(WebCore::KURL(url.toString()),
730 frame->loader()->outgoingReferrer());
731 return WebCore::FrameLoadRequest(rr);
734 static void openNewWindow(const QUrl& url, WebCore::Frame* frame)
736 if (Page* oldPage = frame->page()) {
737 WindowFeatures features;
738 if (Page* newPage = oldPage->chrome()->createWindow(frame,
739 frameLoadRequest(url, frame), features))
740 newPage->chrome()->show();
744 void QWebPage::triggerAction(WebAction action, bool checked)
746 WebCore::Frame *frame = d->page->focusController()->focusedOrMainFrame();
747 WebCore::Editor *editor = frame->editor();
748 const char *command = 0;
752 if (QWebFrame *targetFrame = d->currentContext.targetFrame()) {
753 WTF::RefPtr<WebCore::Frame> wcFrame = targetFrame->d->frame;
754 targetFrame->d->frame->loader()->load(frameLoadRequest(d->currentContext.linkUrl(), wcFrame.get()),
755 /*lockHistory*/ false,
756 /*userGesture*/ true,
758 /*HTMLFormElement*/ 0,
760 WTF::HashMap<String, String>());
765 case OpenLinkInNewWindow:
766 openNewWindow(d->currentContext.linkUrl(), frame);
768 case OpenFrameInNewWindow:
770 case DownloadLinkToDisk:
771 case CopyLinkToClipboard:
772 editor->copyURL(WebCore::KURL(d->currentContext.linkUrl().toString()), d->currentContext.text());
774 case OpenImageInNewWindow:
775 openNewWindow(d->currentContext.imageUrl(), frame);
777 case DownloadImageToDisk:
778 case CopyImageToClipboard:
784 d->page->goForward();
787 mainFrame()->d->frame->loader()->stopForUserCancel();
790 mainFrame()->d->frame->loader()->reload();
810 command = "MoveForward";
812 case MoveToPreviousChar:
813 command = "MoveBackward";
816 command = "MoveWordForward";
818 case MoveToPreviousWord:
819 command = "MoveWordBackward";
822 command = "MoveDown";
824 case MoveToPreviousLine:
827 case MoveToStartOfLine:
828 command = "MoveToBeginningOfLine";
830 case MoveToEndOfLine:
831 command = "MoveToEndOfLine";
833 case MoveToStartOfBlock:
834 command = "MoveToBeginningOfParagraph";
836 case MoveToEndOfBlock:
837 command = "MoveToEndOfParagraph";
839 case MoveToStartOfDocument:
840 command = "MoveToBeginningOfDocument";
842 case MoveToEndOfDocument:
843 command = "MoveToEndOfDocument";
846 command = "MoveForwardAndModifySelection";
848 case SelectPreviousChar:
849 command = "MoveBackwardAndModifySelection";
852 command = "MoveWordForwardAndModifySelection";
854 case SelectPreviousWord:
855 command = "MoveWordBackwardAndModifySelection";
858 command = "MoveDownAndModifySelection";
860 case SelectPreviousLine:
861 command = "MoveUpAndModifySelection";
863 case SelectStartOfLine:
864 command = "MoveToBeginningOfLineAndModifySelection";
866 case SelectEndOfLine:
867 command = "MoveToEndOfLineAndModifySelection";
869 case SelectStartOfBlock:
870 command = "MoveToBeginningOfParagraphAndModifySelection";
872 case SelectEndOfBlock:
873 command = "MoveToEndOfParagraphAndModifySelection";
875 case SelectStartOfDocument:
876 command = "MoveToBeginningOfDocumentAndModifySelection";
878 case SelectEndOfDocument:
879 command = "MoveToEndOfDocumentAndModifySelection";
881 case DeleteStartOfWord:
882 command = "DeleteWordBackward";
884 case DeleteEndOfWord:
885 command = "DeleteWordForward";
888 case SetTextDirectionDefault:
889 editor->setBaseWritingDirection("inherit");
891 case SetTextDirectionLeftToRight:
892 editor->setBaseWritingDirection("ltr");
894 case SetTextDirectionRightToLeft:
895 editor->setBaseWritingDirection("rtl");
899 command = "ToggleBold";
902 command = "ToggleItalic";
904 case ToggleUnderline:
905 editor->toggleUnderline();
908 d->page->inspectorController()->inspect(d->currentContext.d->innerNonSharedNode.get());
915 editor->command(command).execute();
918 QSize QWebPage::viewportSize() const
920 QWebFrame *frame = mainFrame();
921 if (frame->d->frame && frame->d->frameView)
922 return frame->d->frameView->frameGeometry().size();
926 void QWebPage::setViewportSize(const QSize &size) const
928 QWebFrame *frame = mainFrame();
929 if (frame->d->frame && frame->d->frameView) {
930 frame->d->frameView->setFrameGeometry(QRect(QPoint(0, 0), size));
931 frame->d->frame->forceLayout();
932 frame->d->frame->view()->adjustViewSize();
937 QWebPage::NavigationRequestResponse QWebPage::navigationRequested(QWebFrame *frame, const QWebNetworkRequest &request, QWebPage::NavigationType type)
940 return AcceptNavigationRequest;
943 QString QWebPage::selectedText() const
945 return d->page->focusController()->focusedOrMainFrame()->selectedText();
948 QAction *QWebPage::action(WebAction action) const
950 if (action == QWebPage::NoWebAction) return 0;
951 if (d->actions[action])
952 return d->actions[action];
955 bool checkable = false;
959 text = contextMenuItemTagOpenLink();
961 case OpenLinkInNewWindow:
962 text = contextMenuItemTagOpenLinkInNewWindow();
964 case OpenFrameInNewWindow:
965 text = contextMenuItemTagOpenFrameInNewWindow();
968 case DownloadLinkToDisk:
969 text = contextMenuItemTagDownloadLinkToDisk();
971 case CopyLinkToClipboard:
972 text = contextMenuItemTagCopyLinkToClipboard();
975 case OpenImageInNewWindow:
976 text = contextMenuItemTagOpenImageInNewWindow();
978 case DownloadImageToDisk:
979 text = contextMenuItemTagDownloadImageToDisk();
981 case CopyImageToClipboard:
982 text = contextMenuItemTagCopyImageToClipboard();
986 text = contextMenuItemTagGoBack();
989 text = contextMenuItemTagGoForward();
992 text = contextMenuItemTagStop();
995 text = contextMenuItemTagReload();
999 text = contextMenuItemTagCut();
1002 text = contextMenuItemTagCopy();
1005 text = contextMenuItemTagPaste();
1009 QAction *a = undoStack()->createUndoAction(d->q);
1010 d->actions[action] = a;
1014 QAction *a = undoStack()->createRedoAction(d->q);
1015 d->actions[action] = a;
1018 case MoveToNextChar:
1019 case MoveToPreviousChar:
1020 case MoveToNextWord:
1021 case MoveToPreviousWord:
1022 case MoveToNextLine:
1023 case MoveToPreviousLine:
1024 case MoveToStartOfLine:
1025 case MoveToEndOfLine:
1026 case MoveToStartOfBlock:
1027 case MoveToEndOfBlock:
1028 case MoveToStartOfDocument:
1029 case MoveToEndOfDocument:
1030 case SelectNextChar:
1031 case SelectPreviousChar:
1032 case SelectNextWord:
1033 case SelectPreviousWord:
1034 case SelectNextLine:
1035 case SelectPreviousLine:
1036 case SelectStartOfLine:
1037 case SelectEndOfLine:
1038 case SelectStartOfBlock:
1039 case SelectEndOfBlock:
1040 case SelectStartOfDocument:
1041 case SelectEndOfDocument:
1042 case DeleteStartOfWord:
1043 case DeleteEndOfWord:
1046 case SetTextDirectionDefault:
1047 text = contextMenuItemTagDefaultDirection();
1049 case SetTextDirectionLeftToRight:
1050 text = contextMenuItemTagLeftToRight();
1053 case SetTextDirectionRightToLeft:
1054 text = contextMenuItemTagRightToLeft();
1059 text = contextMenuItemTagBold();
1063 text = contextMenuItemTagItalic();
1066 case ToggleUnderline:
1067 text = contextMenuItemTagUnderline();
1071 case InspectElement:
1072 text = contextMenuItemTagInspectElement();
1082 QAction *a = new QAction(d->q);
1085 a->setCheckable(checkable);
1087 connect(a, SIGNAL(triggered(bool)),
1088 this, SLOT(_q_webActionTriggered(bool)));
1090 d->actions[action] = a;
1091 d->updateAction(action);
1096 Returns true if the page contains unsubmitted form data.
1098 bool QWebPage::isModified() const
1104 QUndoStack *QWebPage::undoStack() const
1107 d->undoStack = new QUndoStack(const_cast<QWebPage *>(this));
1109 return d->undoStack;
1114 bool QWebPage::event(QEvent *ev)
1116 switch (ev->type()) {
1117 case QEvent::MouseMove:
1118 d->mouseMoveEvent(static_cast<QMouseEvent*>(ev));
1120 case QEvent::MouseButtonPress:
1121 d->mousePressEvent(static_cast<QMouseEvent*>(ev));
1123 case QEvent::MouseButtonDblClick:
1124 d->mouseDoubleClickEvent(static_cast<QMouseEvent*>(ev));
1126 case QEvent::MouseButtonRelease:
1127 d->mouseReleaseEvent(static_cast<QMouseEvent*>(ev));
1129 case QEvent::ContextMenu:
1130 d->contextMenuEvent(static_cast<QContextMenuEvent*>(ev));
1133 d->wheelEvent(static_cast<QWheelEvent*>(ev));
1135 case QEvent::KeyPress:
1136 d->keyPressEvent(static_cast<QKeyEvent*>(ev));
1138 case QEvent::KeyRelease:
1139 d->keyReleaseEvent(static_cast<QKeyEvent*>(ev));
1141 case QEvent::FocusIn:
1142 d->focusInEvent(static_cast<QFocusEvent*>(ev));
1144 case QEvent::FocusOut:
1145 d->focusOutEvent(static_cast<QFocusEvent*>(ev));
1147 case QEvent::DragEnter:
1148 d->dragEnterEvent(static_cast<QDragEnterEvent*>(ev));
1150 case QEvent::DragLeave:
1151 d->dragLeaveEvent(static_cast<QDragLeaveEvent*>(ev));
1153 case QEvent::DragMove:
1154 d->dragMoveEvent(static_cast<QDragMoveEvent*>(ev));
1157 d->dropEvent(static_cast<QDropEvent*>(ev));
1160 return QObject::event(ev);
1166 bool QWebPage::focusNextPrevChild(bool next)
1172 void QWebPage::setNetworkInterface(QWebNetworkInterface *interface)
1174 d->networkInterface = interface;
1177 QWebNetworkInterface *QWebPage::networkInterface() const
1179 if (d->networkInterface)
1180 return d->networkInterface;
1182 return QWebNetworkInterface::defaultInterface();
1185 QWebSettings *QWebPage::settings()
1190 QString QWebPage::chooseFile(QWebFrame *parentFrame, const QString& oldFile)
1192 //FIXME frame pos...
1193 #ifndef QT_NO_FILEDIALOG
1194 return QFileDialog::getOpenFileName(d->view, QString::null, oldFile);
1196 return QString::null;
1200 #ifndef QT_NO_NETWORKPROXY
1201 void QWebPage::setNetworkProxy(const QNetworkProxy& proxy)
1203 d->networkProxy = proxy;
1206 QNetworkProxy QWebPage::networkProxy() const
1208 return d->networkProxy;
1212 QString QWebPage::userAgentFor(const QUrl& url) const {
1214 return QLatin1String("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/418.9.1 (KHTML, like Gecko) Safari/419.3 Qt");
1218 void QWebPagePrivate::_q_onLoadProgressChanged(int) {
1219 m_totalBytes = page->progress()->totalPageAndResourceBytesToLoad();
1220 m_bytesReceived = page->progress()->totalBytesReceived();
1224 quint64 QWebPage::totalBytes() const {
1225 return d->m_bytesReceived;
1229 quint64 QWebPage::bytesReceived() const {
1230 return d->m_totalBytes;
1233 QWebPageContext::QWebPageContext(const WebCore::HitTestResult &hitTest)
1234 : d(new QWebPageContextPrivate)
1236 d->pos = hitTest.point();
1237 d->text = hitTest.textContent();
1238 d->linkUrl = hitTest.absoluteLinkURL().string();
1239 d->imageUrl = hitTest.absoluteImageURL().string();
1240 d->innerNonSharedNode = hitTest.innerNonSharedNode();
1241 WebCore::Image *img = hitTest.image();
1243 QPixmap *pix = img->getPixmap();
1247 WebCore::Frame *frame = hitTest.targetFrame();
1249 d->targetFrame = frame->view()->qwebframe();
1252 QWebPageContext::QWebPageContext()
1257 QWebPageContext::QWebPageContext(const QWebPageContext &other)
1261 d = new QWebPageContextPrivate(*other.d);
1264 QWebPageContext &QWebPageContext::operator=(const QWebPageContext &other)
1266 if (this != &other) {
1269 d = new QWebPageContextPrivate;
1279 QWebPageContext::~QWebPageContext()
1284 QPoint QWebPageContext::pos() const
1291 QString QWebPageContext::text() const
1298 QUrl QWebPageContext::linkUrl() const
1305 QUrl QWebPageContext::imageUrl() const
1312 QPixmap QWebPageContext::image() const
1319 QWebFrame *QWebPageContext::targetFrame() const
1323 return d->targetFrame;
1326 #include "moc_qwebpage.cpp"