2 Copyright (C) 2008, 2009, 2012 Nokia Corporation and/or its subsidiary(-ies)
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.
25 #include "DefaultFullScreenVideoHandler.h"
26 #include "InitWebKitQt.h"
27 #include "InspectorClientQt.h"
28 #include "InspectorClientWebPage.h"
29 #include "InspectorServerQt.h"
30 #include "PageClientQt.h"
31 #include "QGraphicsWidgetPluginImpl.h"
32 #include "QWebUndoCommand.h"
33 #include "QWidgetPluginImpl.h"
34 #include "QtFallbackWebPopup.h"
35 #include "QtPlatformPlugin.h"
36 #include "UndoStepQt.h"
37 #include "WebEventConversion.h"
39 #include "qwebframe.h"
40 #include "qwebframe_p.h"
41 #include "qwebhistory.h"
42 #include "qwebinspector.h"
43 #include "qwebinspector_p.h"
44 #include "qwebkitplatformplugin.h"
45 #include "qwebpage_p.h"
46 #include "qwebsettings.h"
50 #include <QApplication>
51 #include <QBasicTimer>
54 #include <QColorDialog>
56 #include <QDesktopWidget>
57 #include <QDragEnterEvent>
58 #include <QDragLeaveEvent>
59 #include <QDragMoveEvent>
61 #include <QFileDialog>
62 #include <QGestureEvent>
63 #include <QInputDialog>
66 #include <QMessageBox>
67 #include <QNetworkAccessManager>
68 #include <QNetworkProxy>
69 #include <QNetworkRequest>
74 #if USE(QT_MOBILITY_SYSTEMINFO)
75 #include <qsysteminfo.h>
77 #include <QSystemTrayIcon>
78 #include <QTextCharFormat>
80 #include <QTouchEvent>
87 using namespace WebCore;
89 // Lookup table mapping QWebPage::WebActions to the associated Editor commands
90 static const char* editorCommandWebActions[] =
94 0, // OpenLinkInNewWindow,
95 0, // OpenFrameInNewWindow,
97 0, // DownloadLinkToDisk,
98 0, // CopyLinkToClipboard,
100 0, // OpenImageInNewWindow,
101 0, // DownloadImageToDisk,
102 0, // CopyImageToClipboard,
115 "MoveForward", // MoveToNextChar,
116 "MoveBackward", // MoveToPreviousChar,
117 "MoveWordForward", // MoveToNextWord,
118 "MoveWordBackward", // MoveToPreviousWord,
119 "MoveDown", // MoveToNextLine,
120 "MoveUp", // MoveToPreviousLine,
121 "MoveToBeginningOfLine", // MoveToStartOfLine,
122 "MoveToEndOfLine", // MoveToEndOfLine,
123 "MoveToBeginningOfParagraph", // MoveToStartOfBlock,
124 "MoveToEndOfParagraph", // MoveToEndOfBlock,
125 "MoveToBeginningOfDocument", // MoveToStartOfDocument,
126 "MoveToEndOfDocument", // MoveToEndOfDocument,
127 "MoveForwardAndModifySelection", // SelectNextChar,
128 "MoveBackwardAndModifySelection", // SelectPreviousChar,
129 "MoveWordForwardAndModifySelection", // SelectNextWord,
130 "MoveWordBackwardAndModifySelection", // SelectPreviousWord,
131 "MoveDownAndModifySelection", // SelectNextLine,
132 "MoveUpAndModifySelection", // SelectPreviousLine,
133 "MoveToBeginningOfLineAndModifySelection", // SelectStartOfLine,
134 "MoveToEndOfLineAndModifySelection", // SelectEndOfLine,
135 "MoveToBeginningOfParagraphAndModifySelection", // SelectStartOfBlock,
136 "MoveToEndOfParagraphAndModifySelection", // SelectEndOfBlock,
137 "MoveToBeginningOfDocumentAndModifySelection", // SelectStartOfDocument,
138 "MoveToEndOfDocumentAndModifySelection", // SelectEndOfDocument,
139 "DeleteWordBackward", // DeleteStartOfWord,
140 "DeleteWordForward", // DeleteEndOfWord,
142 0, // SetTextDirectionDefault,
143 0, // SetTextDirectionLeftToRight,
144 0, // SetTextDirectionRightToLeft,
146 "ToggleBold", // ToggleBold,
147 "ToggleItalic", // ToggleItalic,
148 "ToggleUnderline", // ToggleUnderline,
150 0, // InspectElement,
152 "InsertNewline", // InsertParagraphSeparator
153 "InsertLineBreak", // InsertLineSeparator
155 "SelectAll", // SelectAll
156 0, // ReloadAndBypassCache,
158 "PasteAndMatchStyle", // PasteAndMatchStyle
159 "RemoveFormat", // RemoveFormat
160 "Strikethrough", // ToggleStrikethrough,
161 "Subscript", // ToggleSubscript
162 "Superscript", // ToggleSuperscript
163 "InsertUnorderedList", // InsertUnorderedList
164 "InsertOrderedList", // InsertOrderedList
166 "Outdent", // Outdent,
168 "AlignCenter", // AlignCenter,
169 "AlignJustified", // AlignJustified,
170 "AlignLeft", // AlignLeft,
171 "AlignRight", // AlignRight,
173 0, // StopScheduledPageRefresh,
175 0, // CopyImageUrlToClipboard,
177 0, // OpenLinkInThisWindow,
182 // Lookup the appropriate editor command to use for WebAction \a action
183 const char* QWebPagePrivate::editorCommandForWebActions(QWebPage::WebAction action)
185 if ((action > QWebPage::NoWebAction) && (action < int(sizeof(editorCommandWebActions) / sizeof(const char*))))
186 return editorCommandWebActions[action];
190 QWebPagePrivate::QWebPagePrivate(QWebPage *qq)
192 #ifndef QT_NO_UNDOSTACK
195 , linkPolicy(QWebPage::DontDelegateLinks)
196 , m_viewportSize(QSize(0, 0))
197 , useFixedLayout(false)
198 , inspectorFrontend(0)
200 , inspectorIsInternalOnly(false)
201 , m_lastDropAction(Qt::IgnoreAction)
203 WebKit::initializeWebKitWidgets();
204 initializeWebCorePage();
205 memset(actions, 0, sizeof(actions));
207 #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
208 addNotificationPresenterClient();
209 #ifndef QT_NO_SYSTEMTRAYICON
210 if (!hasSystemTrayIcon())
211 setSystemTrayIcon(new QSystemTrayIcon);
212 #endif // QT_NO_SYSTEMTRAYICON
213 #endif // ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
216 QWebPagePrivate::~QWebPagePrivate()
218 #ifndef QT_NO_CONTEXTMENU
219 delete currentContextMenu.data();
221 #ifndef QT_NO_UNDOSTACK
227 // If the inspector is ours, delete it, otherwise just detach from it.
228 if (inspectorIsInternalOnly)
231 inspector->setPage(0);
233 // Explicitly destruct the WebCore page at this point when the
234 // QWebPagePrivate / QWebPageAdapater vtables are still intact,
235 // in order for various destruction callbacks out of WebCore to
240 void QWebPagePrivate::show()
244 view->window()->show();
247 void QWebPagePrivate::setFocus()
254 void QWebPagePrivate::unfocus()
261 void QWebPagePrivate::setWindowRect(const QRect &rect)
263 emit q->geometryChangeRequested(rect);
266 QSize QWebPagePrivate::viewportSize() const
268 return q->viewportSize();
271 QWebPageAdapter *QWebPagePrivate::createWindow(bool dialog)
273 QWebPage *newPage = q->createWindow(dialog ? QWebPage::WebModalDialog : QWebPage::WebBrowserWindow);
276 // Make sure the main frame exists, as WebCore expects it when returning from this ChromeClient::createWindow()
277 newPage->d->createMainFrame();
281 void QWebPagePrivate::javaScriptConsoleMessage(const QString &message, int lineNumber, const QString &sourceID)
283 q->javaScriptConsoleMessage(message, lineNumber, sourceID);
286 void QWebPagePrivate::javaScriptAlert(QWebFrameAdapter* frame, const QString& msg)
288 q->javaScriptAlert(QWebFramePrivate::kit(frame), msg);
291 bool QWebPagePrivate::javaScriptConfirm(QWebFrameAdapter* frame, const QString& msg)
293 return q->javaScriptConfirm(QWebFramePrivate::kit(frame), msg);
296 bool QWebPagePrivate::javaScriptPrompt(QWebFrameAdapter *frame, const QString &msg, const QString &defaultValue, QString *result)
298 return q->javaScriptPrompt(QWebFramePrivate::kit(frame), msg, defaultValue, result);
301 bool QWebPagePrivate::shouldInterruptJavaScript()
303 return q->shouldInterruptJavaScript();
306 void QWebPagePrivate::printRequested(QWebFrameAdapter *frame)
308 emit q->printRequested(QWebFramePrivate::kit(frame));
311 void QWebPagePrivate::databaseQuotaExceeded(QWebFrameAdapter* frame, const QString& databaseName)
313 emit q->databaseQuotaExceeded(QWebFramePrivate::kit(frame), databaseName);
316 void QWebPagePrivate::applicationCacheQuotaExceeded(QWebSecurityOrigin *origin, quint64 defaultOriginQuota, quint64 c)
318 emit q->applicationCacheQuotaExceeded(origin, defaultOriginQuota, c);
321 void QWebPagePrivate::setToolTip(const QString &tip)
323 #ifndef QT_NO_TOOLTIP
328 view->setToolTip(QString());
329 QToolTip::hideText();
331 QString dtip = QLatin1String("<p>") + QString(tip).toHtmlEscaped() + QLatin1String("</p>");
332 view->setToolTip(dtip);
339 #if USE(QT_MULTIMEDIA)
340 QWebFullScreenVideoHandler *QWebPagePrivate::createFullScreenVideoHandler()
342 return new WebKit::DefaultFullScreenVideoHandler;
346 QWebFrameAdapter *QWebPagePrivate::mainFrameAdapter()
348 return q->mainFrame()->d;
351 QStringList QWebPagePrivate::chooseFiles(QWebFrameAdapter *frame, bool allowMultiple, const QStringList &suggestedFileNames)
353 if (allowMultiple && q->supportsExtension(QWebPage::ChooseMultipleFilesExtension)) {
354 QWebPage::ChooseMultipleFilesExtensionOption option;
355 option.parentFrame = QWebFramePrivate::kit(frame);
356 option.suggestedFileNames = suggestedFileNames;
358 QWebPage::ChooseMultipleFilesExtensionReturn output;
359 q->extension(QWebPage::ChooseMultipleFilesExtension, &option, &output);
361 return output.fileNames;
365 QString suggestedFile;
366 if (!suggestedFileNames.isEmpty())
367 suggestedFile = suggestedFileNames.first();
368 QString file = q->chooseFile(QWebFramePrivate::kit(frame), suggestedFile);
374 bool QWebPagePrivate::acceptNavigationRequest(QWebFrameAdapter *frameAdapter, const QNetworkRequest &request, int type)
376 QWebFrame *frame = frameAdapter ? QWebFramePrivate::kit(frameAdapter): 0;
378 && frame == mainFrame.data())
380 return q->acceptNavigationRequest(frame, request, QWebPage::NavigationType(type));
383 void QWebPagePrivate::emitRestoreFrameStateRequested(QWebFrameAdapter *frame)
385 emit q->restoreFrameStateRequested(QWebFramePrivate::kit(frame));
388 void QWebPagePrivate::emitSaveFrameStateRequested(QWebFrameAdapter *frame, QWebHistoryItem *item)
390 emit q->saveFrameStateRequested(QWebFramePrivate::kit(frame), item);
393 void QWebPagePrivate::emitDownloadRequested(const QNetworkRequest &request)
395 emit q->downloadRequested(request);
398 void QWebPagePrivate::emitFrameCreated(QWebFrameAdapter *frame)
400 emit q->frameCreated(QWebFramePrivate::kit(frame));
403 bool QWebPagePrivate::errorPageExtension(QWebPageAdapter::ErrorPageOption *opt, QWebPageAdapter::ErrorPageReturn *out)
405 QWebPage::ErrorPageExtensionOption option;
406 if (opt->domain == QLatin1String("QtNetwork"))
407 option.domain = QWebPage::QtNetwork;
408 else if (opt->domain == QLatin1String("HTTP"))
409 option.domain = QWebPage::Http;
410 else if (opt->domain == QLatin1String("WebKit"))
411 option.domain = QWebPage::WebKit;
414 option.url = opt->url;
415 option.frame = QWebFramePrivate::kit(opt->frame);
416 option.error = opt->error;
417 option.errorString = opt->errorString;
418 QWebPage::ErrorPageExtensionReturn output;
419 if (!q->extension(QWebPage::ErrorPageExtension, &option, &output))
421 out->baseUrl = output.baseUrl;
422 out->content = output.content;
423 out->contentType = output.contentType;
424 out->encoding = output.encoding;
428 QtPluginWidgetAdapter *QWebPagePrivate::createPlugin(const QString &classid, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues)
430 QObject *widget = q->createPlugin(classid, url, paramNames, paramValues);
431 return adapterForWidget(widget);
434 QtPluginWidgetAdapter *QWebPagePrivate::adapterForWidget(QObject *object) const
436 if (QWidget *widget = qobject_cast<QWidget*>(object))
437 return new QWidgetPluginImpl(widget);
438 if (QGraphicsWidget *widget = qobject_cast<QGraphicsWidget*>(object))
439 return new QGraphicsWidgetPluginImpl(widget);
443 void QWebPagePrivate::createMainFrame()
446 mainFrame = new QWebFrame(q);
447 emit q->frameCreated(mainFrame.data());
451 #define MAP_WEB_ACTION_FROM_ADAPTER_EQUIVALENT(Name, Value) \
452 case QWebPageAdapter::Name: return QWebPage::Name
454 static QWebPage::WebAction webActionForAdapterMenuAction(QWebPageAdapter::MenuAction action)
457 FOR_EACH_MAPPED_MENU_ACTION(MAP_WEB_ACTION_FROM_ADAPTER_EQUIVALENT, SEMICOLON_SEPARATOR);
458 #if ENABLE(INSPECTOR)
459 case QWebPageAdapter::InspectElement: return QWebPage::InspectElement;
462 ASSERT_NOT_REACHED();
465 return QWebPage::NoWebAction;
468 #define MAP_ADAPTER_ACTION_FROM_WEBACTION_EQUIVALENT(Name, Value) \
469 case QWebPage::Name: return QWebPageAdapter::Name
471 static QWebPageAdapter::MenuAction adapterMenuActionForWebAction(QWebPage::WebAction action)
474 FOR_EACH_MAPPED_MENU_ACTION(MAP_ADAPTER_ACTION_FROM_WEBACTION_EQUIVALENT, SEMICOLON_SEPARATOR);
475 #if ENABLE(INSPECTOR)
476 case QWebPage::InspectElement: return QWebPageAdapter::InspectElement;
479 ASSERT_NOT_REACHED();
482 return QWebPageAdapter::NoAction;
485 #ifndef QT_NO_CONTEXTMENU
486 typedef QWebPageAdapter::MenuItemDescription MenuItem;
487 QMenu *createContextMenu(QWebPage* page, const QList<MenuItem>& items, QBitArray *visitedWebActions)
492 QMenu* menu = new QMenu(page->view());
493 for (int i = 0; i < items.count(); ++i) {
494 const MenuItem &item = items.at(i);
496 case MenuItem::Action: {
497 QWebPage::WebAction action = webActionForAdapterMenuAction(item.action);
498 QAction *a = page->action(action);
500 a->setEnabled(item.traits & MenuItem::Enabled);
501 a->setCheckable(item.traits & MenuItem::Checkable);
502 a->setChecked(item.traits & MenuItem::Checked);
505 visitedWebActions->setBit(action);
509 case MenuItem::Separator:
510 menu->addSeparator();
512 case MenuItem::SubMenu: {
513 QMenu *subMenu = createContextMenu(page, item.subMenu, visitedWebActions);
516 bool anyEnabledAction = false;
518 QList<QAction *> actions = subMenu->actions();
519 for (int i = 0; i < actions.count(); ++i) {
520 if (actions.at(i)->isVisible())
521 anyEnabledAction |= actions.at(i)->isEnabled();
524 // don't show sub-menus with just disabled actions
525 if (anyEnabledAction) {
526 subMenu->setTitle(item.subMenuTitle);
527 menu->addAction(subMenu->menuAction());
536 #endif // QT_NO_CONTEXTMENU
538 void QWebPagePrivate::createAndSetCurrentContextMenu(const QList<MenuItemDescription>& items, QBitArray* visitedWebActions)
540 #ifndef QT_NO_CONTEXTMENU
541 delete currentContextMenu.data();
543 currentContextMenu = createContextMenu(q, items, visitedWebActions);
545 Q_UNUSED(menuDescription);
546 Q_UNUSED(visitedWebActions);
547 #endif // QT_NO_CONTEXTMENU
551 void QWebPagePrivate::_q_webActionTriggered(bool checked)
553 QAction *a = qobject_cast<QAction *>(q->sender());
556 QWebPage::WebAction action = static_cast<QWebPage::WebAction>(a->data().toInt());
557 q->triggerAction(action, checked);
559 #endif // QT_NO_ACTION
561 void QWebPagePrivate::updateAction(QWebPage::WebAction action)
566 QAction *a = actions[action];
567 if (!a || !mainFrame)
570 bool enabled = a->isEnabled();
571 bool checked = a->isChecked();
573 QWebPageAdapter::MenuAction mappedAction = QWebPageAdapter::NoAction;
574 const char* commandName = 0;
578 case QWebPage::Forward:
580 case QWebPage::Reload:
581 case QWebPage::SetTextDirectionDefault:
582 case QWebPage::SetTextDirectionLeftToRight:
583 case QWebPage::SetTextDirectionRightToLeft:
584 mappedAction = adapterMenuActionForWebAction(action);
586 case QWebPage::ReloadAndBypassCache: // Manual mapping
587 mappedAction = QWebPageAdapter::Reload;
589 #ifndef QT_NO_UNDOSTACK
592 // those two are handled by QUndoStack
594 #endif // QT_NO_UNDOSTACK
595 case QWebPage::SelectAll: // editor command is always enabled
598 // see if it's an editor command
599 commandName = editorCommandForWebActions(action);
603 if (mappedAction != QWebPageAdapter::NoAction || commandName)
604 updateActionInternal(mappedAction, commandName, &enabled, &checked);
606 a->setEnabled(enabled);
608 if (a->isCheckable())
609 a->setChecked(checked);
610 #endif // QT_NO_ACTION
613 void QWebPagePrivate::updateNavigationActions()
615 updateAction(QWebPage::Back);
616 updateAction(QWebPage::Forward);
617 updateAction(QWebPage::Stop);
618 updateAction(QWebPage::Reload);
619 updateAction(QWebPage::ReloadAndBypassCache);
622 QObject *QWebPagePrivate::inspectorHandle()
624 return getOrCreateInspector();
627 void QWebPagePrivate::setInspectorFrontend(QObject* frontend)
629 inspectorFrontend = qobject_cast<QWidget*>(frontend);
631 inspector->d->setFrontend(frontend);
634 void QWebPagePrivate::setInspectorWindowTitle(const QString& title)
637 inspector->setWindowTitle(title);
640 void QWebPagePrivate::createWebInspector(QObject** inspectorView, QWebPageAdapter** inspectorPage)
642 QWebPage* page = new WebKit::InspectorClientWebPage;
643 *inspectorView = page->view();
644 *inspectorPage = page->d;
648 static QStringList iterateContextMenu(QMenu* menu)
651 return QStringList();
654 QList<QAction *> actions = menu->actions();
655 for (int i = 0; i < actions.count(); ++i) {
656 if (actions.at(i)->isSeparator())
657 items << QLatin1String("<separator>");
659 items << actions.at(i)->text();
660 if (actions.at(i)->menu())
661 items << iterateContextMenu(actions.at(i)->menu());
667 QStringList QWebPagePrivate::menuActionsAsText()
670 return iterateContextMenu(currentContextMenu.data());
672 return QStringList();
676 void QWebPagePrivate::emitViewportChangeRequested()
678 emit q->viewportChangeRequested();
681 void QWebPagePrivate::updateEditorActions()
683 updateAction(QWebPage::Cut);
684 updateAction(QWebPage::Copy);
685 updateAction(QWebPage::Paste);
686 updateAction(QWebPage::MoveToNextChar);
687 updateAction(QWebPage::MoveToPreviousChar);
688 updateAction(QWebPage::MoveToNextWord);
689 updateAction(QWebPage::MoveToPreviousWord);
690 updateAction(QWebPage::MoveToNextLine);
691 updateAction(QWebPage::MoveToPreviousLine);
692 updateAction(QWebPage::MoveToStartOfLine);
693 updateAction(QWebPage::MoveToEndOfLine);
694 updateAction(QWebPage::MoveToStartOfBlock);
695 updateAction(QWebPage::MoveToEndOfBlock);
696 updateAction(QWebPage::MoveToStartOfDocument);
697 updateAction(QWebPage::MoveToEndOfDocument);
698 updateAction(QWebPage::SelectNextChar);
699 updateAction(QWebPage::SelectPreviousChar);
700 updateAction(QWebPage::SelectNextWord);
701 updateAction(QWebPage::SelectPreviousWord);
702 updateAction(QWebPage::SelectNextLine);
703 updateAction(QWebPage::SelectPreviousLine);
704 updateAction(QWebPage::SelectStartOfLine);
705 updateAction(QWebPage::SelectEndOfLine);
706 updateAction(QWebPage::SelectStartOfBlock);
707 updateAction(QWebPage::SelectEndOfBlock);
708 updateAction(QWebPage::SelectStartOfDocument);
709 updateAction(QWebPage::SelectEndOfDocument);
710 updateAction(QWebPage::DeleteStartOfWord);
711 updateAction(QWebPage::DeleteEndOfWord);
712 updateAction(QWebPage::SetTextDirectionDefault);
713 updateAction(QWebPage::SetTextDirectionLeftToRight);
714 updateAction(QWebPage::SetTextDirectionRightToLeft);
715 updateAction(QWebPage::ToggleBold);
716 updateAction(QWebPage::ToggleItalic);
717 updateAction(QWebPage::ToggleUnderline);
718 updateAction(QWebPage::InsertParagraphSeparator);
719 updateAction(QWebPage::InsertLineSeparator);
720 updateAction(QWebPage::PasteAndMatchStyle);
721 updateAction(QWebPage::RemoveFormat);
722 updateAction(QWebPage::ToggleStrikethrough);
723 updateAction(QWebPage::ToggleSubscript);
724 updateAction(QWebPage::ToggleSuperscript);
725 updateAction(QWebPage::InsertUnorderedList);
726 updateAction(QWebPage::InsertOrderedList);
727 updateAction(QWebPage::Indent);
728 updateAction(QWebPage::Outdent);
729 updateAction(QWebPage::AlignCenter);
730 updateAction(QWebPage::AlignJustified);
731 updateAction(QWebPage::AlignLeft);
732 updateAction(QWebPage::AlignRight);
735 void QWebPagePrivate::timerEvent(QTimerEvent *ev)
737 int timerId = ev->timerId();
738 if (timerId == tripleClickTimer.timerId())
739 tripleClickTimer.stop();
744 bool QWebPagePrivate::requestSoftwareInputPanel() const
746 return QStyle::RequestSoftwareInputPanel(client->style()->styleHint(QStyle::SH_RequestSoftwareInputPanel)) == QStyle::RSIP_OnMouseClick;
749 #ifndef QT_NO_CONTEXTMENU
750 void QWebPagePrivate::contextMenuEvent(const QPoint& globalPos)
752 QMenu *menu = q->createStandardContextMenu();
754 menu->exec(globalPos);
758 #endif // QT_NO_CONTEXTMENU
762 This function creates the standard context menu which is shown when
763 the user clicks on the web page with the right mouse button. It is
764 called from the default contextMenuEvent() handler. The popup menu's
765 ownership is transferred to the caller.
767 QMenu *QWebPage::createStandardContextMenu()
769 #ifndef QT_NO_CONTEXTMENU
770 QMenu* menu = d->currentContextMenu.data();
771 d->currentContextMenu = 0;
778 #ifndef QT_NO_SHORTCUT
779 QWebPage::WebAction QWebPagePrivate::editorActionForKeyEvent(QKeyEvent* event)
782 QKeySequence::StandardKey standardKey;
783 QWebPage::WebAction action;
784 } editorActions[] = {
785 { QKeySequence::Cut, QWebPage::Cut },
786 { QKeySequence::Copy, QWebPage::Copy },
787 { QKeySequence::Paste, QWebPage::Paste },
788 { QKeySequence::Undo, QWebPage::Undo },
789 { QKeySequence::Redo, QWebPage::Redo },
790 { QKeySequence::MoveToNextChar, QWebPage::MoveToNextChar },
791 { QKeySequence::MoveToPreviousChar, QWebPage::MoveToPreviousChar },
792 { QKeySequence::MoveToNextWord, QWebPage::MoveToNextWord },
793 { QKeySequence::MoveToPreviousWord, QWebPage::MoveToPreviousWord },
794 { QKeySequence::MoveToNextLine, QWebPage::MoveToNextLine },
795 { QKeySequence::MoveToPreviousLine, QWebPage::MoveToPreviousLine },
796 { QKeySequence::MoveToStartOfLine, QWebPage::MoveToStartOfLine },
797 { QKeySequence::MoveToEndOfLine, QWebPage::MoveToEndOfLine },
798 { QKeySequence::MoveToStartOfBlock, QWebPage::MoveToStartOfBlock },
799 { QKeySequence::MoveToEndOfBlock, QWebPage::MoveToEndOfBlock },
800 { QKeySequence::MoveToStartOfDocument, QWebPage::MoveToStartOfDocument },
801 { QKeySequence::MoveToEndOfDocument, QWebPage::MoveToEndOfDocument },
802 { QKeySequence::SelectNextChar, QWebPage::SelectNextChar },
803 { QKeySequence::SelectPreviousChar, QWebPage::SelectPreviousChar },
804 { QKeySequence::SelectNextWord, QWebPage::SelectNextWord },
805 { QKeySequence::SelectPreviousWord, QWebPage::SelectPreviousWord },
806 { QKeySequence::SelectNextLine, QWebPage::SelectNextLine },
807 { QKeySequence::SelectPreviousLine, QWebPage::SelectPreviousLine },
808 { QKeySequence::SelectStartOfLine, QWebPage::SelectStartOfLine },
809 { QKeySequence::SelectEndOfLine, QWebPage::SelectEndOfLine },
810 { QKeySequence::SelectStartOfBlock, QWebPage::SelectStartOfBlock },
811 { QKeySequence::SelectEndOfBlock, QWebPage::SelectEndOfBlock },
812 { QKeySequence::SelectStartOfDocument, QWebPage::SelectStartOfDocument },
813 { QKeySequence::SelectEndOfDocument, QWebPage::SelectEndOfDocument },
814 { QKeySequence::DeleteStartOfWord, QWebPage::DeleteStartOfWord },
815 { QKeySequence::DeleteEndOfWord, QWebPage::DeleteEndOfWord },
816 { QKeySequence::InsertParagraphSeparator, QWebPage::InsertParagraphSeparator },
817 { QKeySequence::InsertLineSeparator, QWebPage::InsertLineSeparator },
818 { QKeySequence::SelectAll, QWebPage::SelectAll },
819 { QKeySequence::UnknownKey, QWebPage::NoWebAction }
822 for (int i = 0; editorActions[i].standardKey != QKeySequence::UnknownKey; ++i)
823 if (event == editorActions[i].standardKey)
824 return editorActions[i].action;
826 return QWebPage::NoWebAction;
828 #endif // QT_NO_SHORTCUT
830 void QWebPagePrivate::keyPressEvent(QKeyEvent *ev)
832 // we forward the key event to WebCore first to handle potential DOM
833 // defined event handlers and later on end up in EditorClientQt::handleKeyboardEvent
834 // to trigger editor commands via triggerAction().
835 bool handled = handleKeyEvent(ev);
838 handled = handleScrolling(ev);
844 q->triggerAction(QWebPage::Back);
846 case Qt::Key_Forward:
847 q->triggerAction(QWebPage::Forward);
850 q->triggerAction(QWebPage::Stop);
852 case Qt::Key_Refresh:
853 q->triggerAction(QWebPage::Reload);
861 ev->setAccepted(handled);
864 void QWebPagePrivate::keyReleaseEvent(QKeyEvent *ev)
866 if (ev->isAutoRepeat()) {
867 ev->setAccepted(true);
871 bool handled = handleKeyEvent(ev);
872 ev->setAccepted(handled);
876 void QWebPagePrivate::dragEnterEvent(T* ev)
878 #ifndef QT_NO_DRAGANDDROP
879 Qt::DropAction action = dragEntered(ev->mimeData(), QPointF(ev->pos()).toPoint(), ev->possibleActions());
880 ev->setDropAction(action);
881 ev->acceptProposedAction();
886 void QWebPagePrivate::dragMoveEvent(T *ev)
888 #ifndef QT_NO_DRAGANDDROP
889 m_lastDropAction = dragUpdated(ev->mimeData(), QPointF(ev->pos()).toPoint(), ev->possibleActions());
890 ev->setDropAction(m_lastDropAction);
891 if (m_lastDropAction != Qt::IgnoreAction)
897 void QWebPagePrivate::dropEvent(T *ev)
899 #ifndef QT_NO_DRAGANDDROP
900 if (performDrag(ev->mimeData(), QPointF(ev->pos()).toPoint(), ev->possibleActions())) {
901 ev->setDropAction(m_lastDropAction);
907 void QWebPagePrivate::leaveEvent(QEvent*)
909 // Fake a mouse move event just outside of the widget, since all
910 // the interesting mouse-out behavior like invalidating scrollbars
911 // is handled by the WebKit event handler's mouseMoved function.
912 QMouseEvent fakeEvent(QEvent::MouseMove, QCursor::pos(), Qt::NoButton, Qt::NoButton, Qt::NoModifier);
913 mouseMoveEvent(&fakeEvent);
917 \property QWebPage::palette
918 \brief the page's palette
920 The base brush of the palette is used to draw the background of the main frame.
922 By default, this property contains the application's default palette.
924 void QWebPage::setPalette(const QPalette &pal)
927 if (!d->mainFrame || !d->mainFrame.data()->d->hasView())
930 QBrush brush = pal.brush(QPalette::Base);
931 QColor backgroundColor = brush.style() == Qt::SolidPattern ? brush.color() : QColor();
932 d->mainFrame.data()->d->updateBackgroundRecursively(backgroundColor);
935 QPalette QWebPage::palette() const
940 void QWebPagePrivate::shortcutOverrideEvent(QKeyEvent* event)
942 if (handleShortcutOverrideEvent(event))
944 #ifndef QT_NO_SHORTCUT
945 if (editorActionForKeyEvent(event) != QWebPage::NoWebAction)
951 bool QWebPagePrivate::gestureEvent(QGestureEvent* event)
953 QWebFrameAdapter* frame = mainFrame.data()->d;
954 if (!frame->hasView())
956 // QGestureEvents can contain updates for multiple gestures.
957 bool handled = false;
958 #if ENABLE(GESTURE_EVENTS)
959 // QGestureEvent lives in Widgets, we'll need a dummy struct to mule the info it contains to the "other side"
960 QGestureEventFacade gestureFacade;
962 QGesture* gesture = event->gesture(Qt::TapGesture);
963 // Beware that gestures send by DumpRenderTree will have state Qt::NoGesture,
964 // due to not originating from a GestureRecognizer.
965 if (gesture && (gesture->state() == Qt::GestureStarted || gesture->state() == Qt::NoGesture)) {
966 gestureFacade.type = Qt::TapGesture;
967 QPointF globalPos = static_cast<const QTapGesture*>(gesture)->position();
968 gestureFacade.globalPos = globalPos.toPoint();
969 gestureFacade.pos = event->widget()->mapFromGlobal(globalPos.toPoint());
970 frame->handleGestureEvent(&gestureFacade);
973 gesture = event->gesture(Qt::TapAndHoldGesture);
974 if (gesture && (gesture->state() == Qt::GestureStarted || gesture->state() == Qt::NoGesture)) {
975 gestureFacade.type = Qt::TapAndHoldGesture;
976 QPointF globalPos = static_cast<const QTapAndHoldGesture*>(gesture)->position();
977 gestureFacade.globalPos = globalPos.toPoint();
978 gestureFacade.pos = event->widget()->mapFromGlobal(globalPos.toPoint());
979 frame->handleGestureEvent(&gestureFacade);
982 #endif // ENABLE(GESTURE_EVENTS)
984 event->setAccepted(handled);
989 This method is used by the input method to query a set of properties of the page
990 to be able to support complex input method operations as support for surrounding
991 text and reconversions.
993 \a property specifies which property is queried.
995 \sa QWidget::inputMethodEvent(), QInputMethodEvent, QInputContext
997 QVariant QWebPage::inputMethodQuery(Qt::InputMethodQuery property) const
999 return d->inputMethodQuery(property);
1005 void QWebPagePrivate::setInspector(QWebInspector* insp)
1008 inspector->d->setFrontend(0);
1012 // Give inspector frontend web view if previously created
1013 if (inspector && inspectorFrontend)
1014 inspector->d->setFrontend(inspectorFrontend);
1019 Returns the inspector and creates it if it wasn't created yet.
1020 The instance created here will not be available through QWebPage's API.
1022 QWebInspector* QWebPagePrivate::getOrCreateInspector()
1024 #if ENABLE(INSPECTOR)
1026 QWebInspector* insp = new QWebInspector;
1028 inspectorIsInternalOnly = true;
1030 Q_ASSERT(inspector); // Associated through QWebInspector::setPage(q)
1037 \enum QWebPage::FindFlag
1039 This enum describes the options available to the findText() function. The options
1040 can be OR-ed together from the following list:
1042 \value FindBackward Searches backwards instead of forwards.
1043 \value FindCaseSensitively By default findText() works case insensitive. Specifying this option
1044 changes the behaviour to a case sensitive find operation.
1045 \value FindWrapsAroundDocument Makes findText() restart from the beginning of the document if the end
1046 was reached and the text was not found.
1047 \value HighlightAllOccurrences Highlights all existing occurrences of a specific string.
1048 (This value was introduced in 4.6.)
1049 \value FindAtWordBeginningsOnly Searches for the sub-string only at the beginnings of words.
1050 (This value was introduced in 5.2.)
1051 \value TreatMedialCapitalAsWordBeginning Treats a capital letter occurring anywhere in the middle of a word
1052 as the beginning of a new word.
1053 (This value was introduced in 5.2.)
1054 \value FindBeginsInSelection Begin searching inside the text selection first.
1055 (This value was introduced in 5.2.)
1059 \enum QWebPage::VisibilityState
1061 This enum defines visibility states that a webpage can take.
1063 \value VisibilityStateVisible The webpage is at least partially visible at on at least one screen.
1064 \value VisibilityStateHidden The webpage is not visible at all on any screen.
1065 \value VisibilityStatePrerender The webpage is loaded off-screen and is not visible.
1066 \value VisibilityStateUnloaded The webpage is unloading its content.
1067 More information about this values can be found at \l{ http://www.w3.org/TR/page-visibility/#dom-document-visibilitystate}{W3C Recommendation: Page Visibility: visibilityState attribute}.
1069 \sa QWebPage::visibilityState
1073 \enum QWebPage::LinkDelegationPolicy
1075 This enum defines the delegation policies a webpage can have when activating links and emitting
1076 the linkClicked() signal.
1078 \value DontDelegateLinks No links are delegated. Instead, QWebPage tries to handle them all.
1079 \value DelegateExternalLinks When activating links that point to documents not stored on the
1080 local filesystem or an equivalent - such as the Qt resource system - then linkClicked() is emitted.
1081 \value DelegateAllLinks Whenever a link is activated the linkClicked() signal is emitted.
1083 \sa QWebPage::linkDelegationPolicy
1087 \enum QWebPage::NavigationType
1089 This enum describes the types of navigation available when browsing through hyperlinked
1092 \value NavigationTypeLinkClicked The user clicked on a link or pressed return on a focused link.
1093 \value NavigationTypeFormSubmitted The user activated a submit button for an HTML form.
1094 \value NavigationTypeBackOrForward Navigation to a previously shown document in the back or forward history is requested.
1095 \value NavigationTypeReload The user activated the reload action.
1096 \value NavigationTypeFormResubmitted An HTML form was submitted a second time.
1097 \value NavigationTypeOther A navigation to another document using a method not listed above.
1099 \sa acceptNavigationRequest()
1103 \enum QWebPage::WebAction
1105 This enum describes the types of action which can be performed on the web page.
1107 Actions only have an effect when they are applicable. The availability of
1108 actions can be be determined by checking \l{QAction::}{isEnabled()} on the
1109 action returned by action().
1111 One method of enabling the text editing, cursor movement, and text selection actions
1112 is by setting \l contentEditable to true.
1114 \value NoWebAction No action is triggered.
1115 \value OpenLink Open the current link.
1116 \value OpenLinkInNewWindow Open the current link in a new window.
1117 \value OpenLinkInThisWindow Open the current link without opening a new window. Used on links that would default to opening in another frame or a new window. (Added in Qt 5.0)
1118 \value OpenFrameInNewWindow Replicate the current frame in a new window.
1119 \value DownloadLinkToDisk Download the current link to the disk.
1120 \value CopyLinkToClipboard Copy the current link to the clipboard.
1121 \value OpenImageInNewWindow Open the highlighted image in a new window.
1122 \value DownloadImageToDisk Download the highlighted image to the disk.
1123 \value CopyImageToClipboard Copy the highlighted image to the clipboard. (Added in Qt 4.8)
1124 \value CopyImageUrlToClipboard Copy the highlighted image's URL to the clipboard.
1125 \value Back Navigate back in the history of navigated links.
1126 \value Forward Navigate forward in the history of navigated links.
1127 \value Stop Stop loading the current page.
1128 \value StopScheduledPageRefresh Stop all pending page refresh/redirect requests. (Added in Qt 4.7)
1129 \value Reload Reload the current page.
1130 \value ReloadAndBypassCache Reload the current page, but do not use any local cache. (Added in Qt 4.6)
1131 \value Cut Cut the content currently selected into the clipboard.
1132 \value Copy Copy the content currently selected into the clipboard.
1133 \value Paste Paste content from the clipboard.
1134 \value Undo Undo the last editing action.
1135 \value Redo Redo the last editing action.
1136 \value MoveToNextChar Move the cursor to the next character.
1137 \value MoveToPreviousChar Move the cursor to the previous character.
1138 \value MoveToNextWord Move the cursor to the next word.
1139 \value MoveToPreviousWord Move the cursor to the previous word.
1140 \value MoveToNextLine Move the cursor to the next line.
1141 \value MoveToPreviousLine Move the cursor to the previous line.
1142 \value MoveToStartOfLine Move the cursor to the start of the line.
1143 \value MoveToEndOfLine Move the cursor to the end of the line.
1144 \value MoveToStartOfBlock Move the cursor to the start of the block.
1145 \value MoveToEndOfBlock Move the cursor to the end of the block.
1146 \value MoveToStartOfDocument Move the cursor to the start of the document.
1147 \value MoveToEndOfDocument Move the cursor to the end of the document.
1148 \value SelectNextChar Select to the next character.
1149 \value SelectPreviousChar Select to the previous character.
1150 \value SelectNextWord Select to the next word.
1151 \value SelectPreviousWord Select to the previous word.
1152 \value SelectNextLine Select to the next line.
1153 \value SelectPreviousLine Select to the previous line.
1154 \value SelectStartOfLine Select to the start of the line.
1155 \value SelectEndOfLine Select to the end of the line.
1156 \value SelectStartOfBlock Select to the start of the block.
1157 \value SelectEndOfBlock Select to the end of the block.
1158 \value SelectStartOfDocument Select to the start of the document.
1159 \value SelectEndOfDocument Select to the end of the document.
1160 \value DeleteStartOfWord Delete to the start of the word.
1161 \value DeleteEndOfWord Delete to the end of the word.
1162 \value SetTextDirectionDefault Set the text direction to the default direction.
1163 \value SetTextDirectionLeftToRight Set the text direction to left-to-right.
1164 \value SetTextDirectionRightToLeft Set the text direction to right-to-left.
1165 \value ToggleBold Toggle the formatting between bold and normal weight.
1166 \value ToggleItalic Toggle the formatting between italic and normal style.
1167 \value ToggleUnderline Toggle underlining.
1168 \value InspectElement Show the Web Inspector with the currently highlighted HTML element.
1169 \value InsertParagraphSeparator Insert a new paragraph.
1170 \value InsertLineSeparator Insert a new line.
1171 \value SelectAll Selects all content.
1172 \value PasteAndMatchStyle Paste content from the clipboard with current style. (Added in Qt 4.6)
1173 \value RemoveFormat Removes formatting and style. (Added in Qt 4.6)
1174 \value ToggleStrikethrough Toggle the formatting between strikethrough and normal style. (Added in Qt 4.6)
1175 \value ToggleSubscript Toggle the formatting between subscript and baseline. (Added in Qt 4.6)
1176 \value ToggleSuperscript Toggle the formatting between supercript and baseline. (Added in Qt 4.6)
1177 \value InsertUnorderedList Toggles the selection between an ordered list and a normal block. (Added in Qt 4.6)
1178 \value InsertOrderedList Toggles the selection between an ordered list and a normal block. (Added in Qt 4.6)
1179 \value Indent Increases the indentation of the currently selected format block by one increment. (Added in Qt 4.6)
1180 \value Outdent Decreases the indentation of the currently selected format block by one increment. (Added in Qt 4.6)
1181 \value AlignCenter Applies center alignment to content. (Added in Qt 4.6)
1182 \value AlignJustified Applies full justification to content. (Added in Qt 4.6)
1183 \value AlignLeft Applies left justification to content. (Added in Qt 4.6)
1184 \value AlignRight Applies right justification to content. (Added in Qt 4.6)
1187 \omitvalue WebActionCount
1192 \enum QWebPage::WebWindowType
1194 This enum describes the types of window that can be created by the createWindow() function.
1196 \value WebBrowserWindow The window is a regular web browser window.
1197 \value WebModalDialog The window acts as modal dialog.
1202 \class QWebPage::ViewportAttributes
1204 \brief The QWebPage::ViewportAttributes class describes hints that can be applied to a viewport.
1206 QWebPage::ViewportAttributes provides a description of a viewport, such as viewport geometry,
1207 initial scale factor with limits, plus information about whether a user should be able
1208 to scale the contents in the viewport or not, ie. by zooming.
1210 ViewportAttributes can be set by a web author using the viewport meta tag extension, documented
1211 at \l{http://developer.apple.com/safari/library/documentation/appleapplications/reference/safariwebcontent/usingtheviewport/usingtheviewport.html}{Safari Reference Library: Using the Viewport Meta Tag}.
1213 All values might not be set, as such when dealing with the hints, the developer needs to
1214 check whether the values are valid. Negative values denote an invalid qreal value.
1220 Constructs an empty QWebPage::ViewportAttributes.
1222 QWebPage::ViewportAttributes::ViewportAttributes()
1224 , m_initialScaleFactor(-1.0)
1225 , m_minimumScaleFactor(-1.0)
1226 , m_maximumScaleFactor(-1.0)
1227 , m_devicePixelRatio(-1.0)
1228 , m_isUserScalable(true)
1235 Constructs a QWebPage::ViewportAttributes which is a copy from \a other .
1237 QWebPage::ViewportAttributes::ViewportAttributes(const QWebPage::ViewportAttributes& other)
1239 , m_initialScaleFactor(other.m_initialScaleFactor)
1240 , m_minimumScaleFactor(other.m_minimumScaleFactor)
1241 , m_maximumScaleFactor(other.m_maximumScaleFactor)
1242 , m_devicePixelRatio(other.m_devicePixelRatio)
1243 , m_isUserScalable(other.m_isUserScalable)
1244 , m_isValid(other.m_isValid)
1245 , m_size(other.m_size)
1251 Destroys the QWebPage::ViewportAttributes.
1253 QWebPage::ViewportAttributes::~ViewportAttributes()
1259 Assigns the given QWebPage::ViewportAttributes to this viewport hints and returns a
1262 QWebPage::ViewportAttributes& QWebPage::ViewportAttributes::operator=(const QWebPage::ViewportAttributes& other)
1264 if (this != &other) {
1266 m_initialScaleFactor = other.m_initialScaleFactor;
1267 m_minimumScaleFactor = other.m_minimumScaleFactor;
1268 m_maximumScaleFactor = other.m_maximumScaleFactor;
1269 m_isUserScalable = other.m_isUserScalable;
1270 m_isValid = other.m_isValid;
1271 m_size = other.m_size;
1277 /*! \fn inline bool QWebPage::ViewportAttributes::isValid() const
1278 Returns whether this is a valid ViewportAttributes or not.
1280 An invalid ViewportAttributes will have an empty QSize, negative values for scale factors and
1281 true for the boolean isUserScalable.
1284 /*! \fn inline QSize QWebPage::ViewportAttributes::size() const
1285 Returns the size of the viewport.
1288 /*! \fn inline qreal QWebPage::ViewportAttributes::initialScaleFactor() const
1289 Returns the initial scale of the viewport as a multiplier.
1292 /*! \fn inline qreal QWebPage::ViewportAttributes::minimumScaleFactor() const
1293 Returns the minimum scale value of the viewport as a multiplier.
1296 /*! \fn inline qreal QWebPage::ViewportAttributes::maximumScaleFactor() const
1297 Returns the maximum scale value of the viewport as a multiplier.
1300 /*! \fn inline bool QWebPage::ViewportAttributes::isUserScalable() const
1301 Determines whether or not the scale can be modified by the user.
1308 \brief The QWebPage class provides an object to view and edit web documents.
1312 QWebPage holds a main frame responsible for web content, settings, the history
1313 of navigated links and actions. This class can be used, together with QWebFrame,
1314 to provide functionality like QWebView in a widget-less environment.
1316 QWebPage's API is very similar to QWebView, as you are still provided with
1317 common functions like action() (known as
1318 \l{QWebView::pageAction()}{pageAction}() in QWebView), triggerAction(),
1319 findText() and settings(). More QWebView-like functions can be found in the
1320 main frame of QWebPage, obtained via the mainFrame() function. For example,
1321 the \l{QWebFrame::load()}{load}(), \l{QWebFrame::setUrl()}{setUrl}() and
1322 \l{QWebFrame::setHtml()}{setHtml}() functions for QWebPage can be accessed
1325 The loadStarted() signal is emitted when the page begins to load.The
1326 loadProgress() signal, on the other hand, is emitted whenever an element
1327 of the web page completes loading, such as an embedded image, a script,
1328 etc. Finally, the loadFinished() signal is emitted when the page contents
1329 are loaded completely, independent of script execution or page rendering.
1330 Its argument, either true or false, indicates whether or not the load
1331 operation succeeded.
1333 \section1 Using QWebPage in a Widget-less Environment
1335 Before you begin painting a QWebPage object, you need to set the size of
1336 the viewport by calling setViewportSize(). Then, you invoke the main
1337 frame's render function (QWebFrame::render()). An example of this
1338 is shown in the code snippet below.
1340 Suppose we have a \c Thumbnail class as follows:
1342 \snippet webkitsnippets/webpage/main.cpp 0
1344 The \c Thumbnail's constructor takes in a \a url. We connect our QWebPage
1345 object's \l{QWebPage::}{loadFinished()} signal to our private slot,
1348 \snippet webkitsnippets/webpage/main.cpp 1
1350 The \c render() function shows how we can paint a thumbnail using a
1353 \snippet webkitsnippets/webpage/main.cpp 2
1355 We begin by setting the \l{QWebPage::viewportSize()}{viewportSize} and
1356 then we instantiate a QImage object, \c image, with the same size as our
1357 \l{QWebPage::viewportSize()}{viewportSize}. This image is then sent
1358 as a parameter to \c painter. Next, we render the contents of the main
1359 frame and its subframes into \c painter. Finally, we save the scaled image.
1365 Constructs an empty QWebPage with parent \a parent.
1367 QWebPage::QWebPage(QObject *parent)
1369 , d(new QWebPagePrivate(this))
1371 setView(qobject_cast<QWidget*>(parent));
1373 connect(this, SIGNAL(loadProgress(int)), this, SLOT(_q_onLoadProgressChanged(int)));
1375 connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()), this, SLOT(_q_cleanupLeakMessages()));
1380 Destroys the web page.
1382 QWebPage::~QWebPage()
1388 Returns the main frame of the page.
1390 The main frame provides access to the hierarchy of sub-frames and is also needed if you
1391 want to explicitly render a web page into a given painter.
1395 QWebFrame *QWebPage::mainFrame() const
1397 d->createMainFrame();
1398 return d->mainFrame.data();
1402 Returns the frame currently active.
1404 \sa mainFrame(), frameCreated()
1406 QWebFrame *QWebPage::currentFrame() const
1408 d->createMainFrame();
1409 return qobject_cast<QWebFrame*>(d->currentFrame());
1416 Returns the frame at the given point \a pos, or 0 if there is no frame at
1419 \sa mainFrame(), currentFrame()
1421 QWebFrame* QWebPage::frameAt(const QPoint& pos) const
1423 QWebFrame* webFrame = mainFrame();
1424 if (!webFrame->geometry().contains(pos))
1426 QWebHitTestResult hitTestResult = webFrame->hitTestContent(pos);
1427 return hitTestResult.frame();
1431 Returns a pointer to the view's history of navigated web pages.
1433 QWebHistory *QWebPage::history() const
1435 d->createMainFrame();
1440 Sets the \a view that is associated with the web page.
1444 void QWebPage::setView(QWidget* view)
1446 if (this->view() == view)
1450 setViewportSize(view ? view->size() : QSize(0, 0));
1452 // If we have no client, we install a special client delegating
1453 // the responsibility to the QWidget. This is the code path
1454 // handling a.o. the "legacy" QWebView.
1456 // If such a special delegate already exist, we substitute the view.
1459 if (d->client->isQWidgetClient())
1460 static_cast<PageClientQWidget*>(d->client.data())->view = view;
1465 d->client.reset(new PageClientQWidget(view, this));
1469 Returns the view widget that is associated with the web page.
1473 QWidget *QWebPage::view() const
1475 return d->view.data();
1479 This function is called whenever a JavaScript program tries to print a \a message to the web browser's console.
1481 For example in case of evaluation errors the source URL may be provided in \a sourceID as well as the \a lineNumber.
1483 The default implementation prints nothing.
1485 void QWebPage::javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID)
1489 // Catch plugin logDestroy message for LayoutTests/plugins/open-and-close-window-with-plugin.html
1490 // At this point DRT's WebPage has already been destroyed
1491 if (QWebPageAdapter::drtRun) {
1492 if (message == QLatin1String("PLUGIN: NPP_Destroy")) {
1493 fprintf(stdout, "CONSOLE MESSAGE: ");
1495 fprintf(stdout, "line %d: ", lineNumber);
1496 fprintf(stdout, "%s\n", message.toUtf8().constData());
1502 This function is called whenever a JavaScript program running inside \a frame calls the alert() function with
1505 The default implementation shows the message, \a msg, with QMessageBox::information.
1507 void QWebPage::javaScriptAlert(QWebFrame *frame, const QString& msg)
1510 #ifndef QT_NO_MESSAGEBOX
1511 QMessageBox box(view());
1512 box.setWindowTitle(tr("JavaScript Alert - %1").arg(mainFrame()->url().host()));
1513 box.setTextFormat(Qt::PlainText);
1515 box.setStandardButtons(QMessageBox::Ok);
1521 This function is called whenever a JavaScript program running inside \a frame calls the confirm() function
1522 with the message, \a msg. Returns true if the user confirms the message; otherwise returns false.
1524 The default implementation executes the query using QMessageBox::information with QMessageBox::Ok and QMessageBox::Cancel buttons.
1526 bool QWebPage::javaScriptConfirm(QWebFrame *frame, const QString& msg)
1529 #ifdef QT_NO_MESSAGEBOX
1532 QMessageBox box(view());
1533 box.setWindowTitle(tr("JavaScript Confirm - %1").arg(mainFrame()->url().host()));
1534 box.setTextFormat(Qt::PlainText);
1536 box.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
1537 return QMessageBox::Ok == box.exec();
1542 This function is called whenever a JavaScript program running inside \a frame tries to prompt the user for input.
1543 The program may provide an optional message, \a msg, as well as a default value for the input in \a defaultValue.
1545 If the prompt was cancelled by the user the implementation should return false; otherwise the
1546 result should be written to \a result and true should be returned. If the prompt was not cancelled by the
1547 user, the implementation should return true and the result string must not be null.
1549 The default implementation uses QInputDialog::getText().
1551 bool QWebPage::javaScriptPrompt(QWebFrame *frame, const QString& msg, const QString& defaultValue, QString* result)
1555 #ifndef QT_NO_INPUTDIALOG
1557 QInputDialog dlg(view());
1558 dlg.setWindowTitle(tr("JavaScript Prompt - %1").arg(mainFrame()->url().host()));
1560 // Hack to force the dialog's QLabel into plain text mode
1561 // prevents https://bugs.webkit.org/show_bug.cgi?id=34429
1562 QLabel* label = dlg.findChild<QLabel*>();
1564 label->setTextFormat(Qt::PlainText);
1566 // double the &'s because single & will underline the following character
1567 // (Accelerator mnemonics)
1568 QString escMsg(msg);
1569 escMsg.replace(QChar::fromLatin1('&'), QLatin1String("&&"));
1570 dlg.setLabelText(escMsg);
1572 dlg.setTextEchoMode(QLineEdit::Normal);
1573 dlg.setTextValue(defaultValue);
1578 *result = dlg.textValue();
1584 \fn bool QWebPage::shouldInterruptJavaScript()
1586 This function is called when a JavaScript program is running for a long period of time.
1588 If the user wanted to stop the JavaScript the implementation should return true; otherwise false.
1590 The default implementation executes the query using QMessageBox::information with QMessageBox::Yes and QMessageBox::No buttons.
1592 bool QWebPage::shouldInterruptJavaScript()
1594 #ifdef QT_NO_MESSAGEBOX
1597 return QMessageBox::Yes == QMessageBox::information(view(), tr("JavaScript Problem - %1").arg(mainFrame()->url().host()), tr("The script on this page appears to have a problem. Do you want to stop the script?"), QMessageBox::Yes, QMessageBox::No);
1601 void QWebPage::setFeaturePermission(QWebFrame* frame, Feature feature, PermissionPolicy policy)
1603 #if !ENABLE(NOTIFICATIONS) && !ENABLE(LEGACY_NOTIFICATIONS) && !ENABLE(GEOLOCATION)
1609 #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
1610 if (policy != PermissionUnknown)
1611 d->setNotificationsAllowedForFrame(frame->d, (policy == PermissionGrantedByUser));
1615 #if ENABLE(GEOLOCATION) && HAVE(QTLOCATION)
1616 if (policy != PermissionUnknown)
1617 d->setGeolocationEnabledForFrame(frame->d, (policy == PermissionGrantedByUser));
1627 This function is called whenever WebKit wants to create a new window of the given \a type, for
1628 example when a JavaScript program requests to open a document in a new window.
1630 If the new window can be created, the new window's QWebPage is returned; otherwise a null pointer is returned.
1632 If the view associated with the web page is a QWebView object, then the default implementation forwards
1633 the request to QWebView's createWindow() function; otherwise it returns a null pointer.
1635 If \a type is WebModalDialog, the application must call setWindowModality(Qt::ApplicationModal) on the new window.
1637 \note In the cases when the window creation is being triggered by JavaScript, apart from
1638 reimplementing this method application must also set the JavaScriptCanOpenWindows attribute
1639 of QWebSettings to true in order for it to get called.
1641 \sa acceptNavigationRequest(), QWebView::createWindow()
1643 QWebPage *QWebPage::createWindow(WebWindowType type)
1645 QWebView *webView = qobject_cast<QWebView*>(view());
1647 QWebView *newView = webView->createWindow(type);
1649 return newView->page();
1655 This function is called whenever WebKit encounters a HTML object element with type "application/x-qt-plugin". It is
1656 called regardless of the value of QWebSettings::PluginsEnabled. The \a classid, \a url, \a paramNames and \a paramValues
1657 correspond to the HTML object element attributes and child elements to configure the embeddable object.
1659 QObject *QWebPage::createPlugin(const QString &classid, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues)
1663 Q_UNUSED(paramNames);
1664 Q_UNUSED(paramValues);
1669 * Returns the list of all content types supported by QWebPage.
1671 QStringList QWebPage::supportedContentTypes() const
1673 return d->supportedContentTypes();
1677 * Returns true if QWebPage can handle the given \a mimeType; otherwise, returns false.
1679 bool QWebPage::supportsContentType(const QString& mimeType) const
1681 return d->supportsContentType(mimeType);
1684 static void collectChildFrames(QWebFrame* frame, QList<QWebFrame*>& list)
1686 list << frame->childFrames();
1687 QListIterator<QWebFrame*> it(frame->childFrames());
1688 while (it.hasNext())
1689 collectChildFrames(it.next(), list);
1693 This function can be called to trigger the specified \a action.
1694 It is also called by Qt WebKit if the user triggers the action, for example
1695 through a context menu item.
1697 If \a action is a checkable action then \a checked specified whether the action
1702 void QWebPage::triggerAction(WebAction action, bool)
1704 const char *command = 0;
1705 QWebPageAdapter::MenuAction mappedAction = QWebPageAdapter::NoAction;
1706 QWebHitTestResultPrivate* hitTestResult = d->hitTestResult.d;
1710 case OpenLinkInNewWindow:
1711 case OpenLinkInThisWindow:
1712 case OpenFrameInNewWindow:
1713 case CopyLinkToClipboard:
1714 case OpenImageInNewWindow:
1715 case DownloadImageToDisk:
1716 case DownloadLinkToDisk:
1721 case SetTextDirectionDefault:
1722 case SetTextDirectionLeftToRight:
1723 case SetTextDirectionRightToLeft:
1724 mappedAction = adapterMenuActionForWebAction(action);
1726 case ReloadAndBypassCache: // Manual mapping
1727 mappedAction = QWebPageAdapter::Reload;
1729 #ifndef QT_NO_CLIPBOARD
1730 case CopyImageToClipboard:
1731 QApplication::clipboard()->setPixmap(d->hitTestResult.pixmap());
1733 case CopyImageUrlToClipboard:
1734 QApplication::clipboard()->setText(d->hitTestResult.imageUrl().toString());
1737 case InspectElement: {
1738 #if ENABLE(INSPECTOR)
1739 if (!d->hitTestResult.isNull()) {
1740 d->getOrCreateInspector(); // Make sure the inspector is created
1741 d->inspector->show(); // The inspector is expected to be shown on inspection
1742 mappedAction = QWebPageAdapter::InspectElement;
1747 case StopScheduledPageRefresh: {
1748 QWebFrame* topFrame = mainFrame();
1749 topFrame->d->cancelLoad();
1750 QList<QWebFrame*> childFrames;
1751 collectChildFrames(topFrame, childFrames);
1752 QListIterator<QWebFrame*> it(childFrames);
1753 while (it.hasNext())
1754 it.next()->d->cancelLoad();
1758 command = QWebPagePrivate::editorCommandForWebActions(action);
1761 if (command || mappedAction != QWebPageAdapter::NoAction)
1762 d->triggerAction(mappedAction, hitTestResult, command, /*endToEndReload*/ action == ReloadAndBypassCache);
1766 QColor QWebPagePrivate::colorSelectionRequested(const QColor &selectedColor)
1768 QColor ret = selectedColor;
1769 #ifndef QT_NO_COLORDIALOG
1770 ret = QColorDialog::getColor(selectedColor, q->view());
1772 ret = selectedColor;
1777 QWebSelectMethod *QWebPagePrivate::createSelectPopup()
1779 return new QtFallbackWebPopup(this);
1782 QRect QWebPagePrivate::viewRectRelativeToWindow()
1785 QWidget* ownerWidget= client.isNull() ? 0 : qobject_cast<QWidget*>(client->ownerWidget());
1788 QWidget* topLevelWidget = ownerWidget->window();
1790 QPoint topLeftCorner = ownerWidget->mapFrom(topLevelWidget, QPoint(0, 0));
1791 return QRect(topLeftCorner, ownerWidget->size());
1794 void QWebPagePrivate::geolocationPermissionRequested(QWebFrameAdapter* frame)
1796 emit q->featurePermissionRequested(QWebFramePrivate::kit(frame), QWebPage::Geolocation);
1799 void QWebPagePrivate::geolocationPermissionRequestCancelled(QWebFrameAdapter* frame)
1801 emit q->featurePermissionRequestCanceled(QWebFramePrivate::kit(frame), QWebPage::Geolocation);
1804 void QWebPagePrivate::notificationsPermissionRequested(QWebFrameAdapter* frame)
1806 emit q->featurePermissionRequested(QWebFramePrivate::kit(frame), QWebPage::Notifications);
1809 void QWebPagePrivate::notificationsPermissionRequestCancelled(QWebFrameAdapter* frame)
1811 emit q->featurePermissionRequestCanceled(QWebFramePrivate::kit(frame), QWebPage::Notifications);
1814 void QWebPagePrivate::respondToChangedContents()
1816 updateEditorActions();
1818 emit q->contentsChanged();
1821 void QWebPagePrivate::respondToChangedSelection()
1823 updateEditorActions();
1824 emit q->selectionChanged();
1827 void QWebPagePrivate::microFocusChanged()
1829 emit q->microFocusChanged();
1832 void QWebPagePrivate::triggerCopyAction()
1834 q->triggerAction(QWebPage::Copy);
1837 void QWebPagePrivate::triggerActionForKeyEvent(QKeyEvent* event)
1839 QWebPage::WebAction action = editorActionForKeyEvent(event);
1840 q->triggerAction(action);
1843 void QWebPagePrivate::clearUndoStack()
1845 #ifndef QT_NO_UNDOSTACK
1851 bool QWebPagePrivate::canUndo() const
1853 #ifndef QT_NO_UNDOSTACK
1856 return undoStack->canUndo();
1862 bool QWebPagePrivate::canRedo() const
1864 #ifndef QT_NO_UNDOSTACK
1867 return undoStack->canRedo();
1873 void QWebPagePrivate::undo()
1875 #ifndef QT_NO_UNDOSTACK
1881 void QWebPagePrivate::redo()
1883 #ifndef QT_NO_UNDOSTACK
1889 void QWebPagePrivate::createUndoStep(QSharedPointer<UndoStepQt> step)
1891 #ifndef QT_NO_UNDOSTACK
1892 // Call undoStack() getter first to ensure stack is created
1893 // if it doesn't exist yet.
1894 q->undoStack()->push(new QWebUndoCommand(step));
1898 const char *QWebPagePrivate::editorCommandForKeyEvent(QKeyEvent* event)
1900 QWebPage::WebAction action = editorActionForKeyEvent(event);
1901 return editorCommandForWebActions(action);
1904 QSize QWebPage::viewportSize() const
1906 if (d->mainFrame && d->mainFrame.data()->d->hasView())
1907 return d->mainFrame.data()->d->frameRect().size();
1909 return d->m_viewportSize;
1913 \property QWebPage::viewportSize
1914 \brief the size of the viewport
1916 The size affects for example the visibility of scrollbars
1917 if the document is larger than the viewport.
1919 By default, for a newly-created Web page, this property contains a size with
1920 zero width and height.
1922 \sa QWebFrame::render(), preferredContentsSize
1924 void QWebPage::setViewportSize(const QSize &size) const
1926 d->m_viewportSize = size;
1928 QWebFrameAdapter* mainFrame = d->mainFrameAdapter();
1929 if (!mainFrame->hasView())
1932 mainFrame->setViewportSize(size);
1935 static int getintenv(const char* variable)
1938 int value = qgetenv(variable).toInt(&ok);
1939 return (ok) ? value : -1;
1942 static QSize queryDeviceSizeForScreenContainingWidget(const QWidget* widget)
1944 QDesktopWidget* desktop = QApplication::desktop();
1951 // Returns the available geometry of the screen which contains widget.
1952 // NOTE: this must be the the full screen size including any fixed status areas etc.
1953 size = desktop->availableGeometry(widget).size();
1955 size = desktop->availableGeometry().size();
1957 // This must be in portrait mode, adjust if not.
1958 if (size.width() > size.height()) {
1959 int width = size.width();
1960 size.setWidth(size.height());
1961 size.setHeight(width);
1968 Computes the optimal viewport configuration given the \a availableSize, when
1969 user interface components are disregarded.
1971 The configuration is also dependent on the device screen size which is obtained
1972 automatically. For testing purposes the size can be overridden by setting two
1973 environment variables QTWEBKIT_DEVICE_WIDTH and QTWEBKIT_DEVICE_HEIGHT, which
1974 both needs to be set.
1976 The ViewportAttributes includes a pixel density ratio, which will also be exposed to
1977 the web author though the -webkit-pixel-ratio media feature. This is the ratio
1978 between 1 density-independent pixel (DPI) and physical pixels.
1980 A density-independent pixel is equivalent to one physical pixel on a 160 DPI screen,
1981 so on our platform assumes that as the baseline density.
1983 The conversion of DIP units to screen pixels is quite simple:
1985 pixels = DIPs * (density / 160).
1987 Thus, on a 240 DPI screen, 1 DIPs would equal 1.5 physical pixels.
1989 An invalid instance will be returned in the case an empty size is passed to the
1992 \note The density is automatically obtained from the DPI of the screen where the page
1993 is being shown, but as many X11 servers are reporting wrong DPI, it is possible to
1994 override it using QX11Info::setAppDpiY().
1997 QWebPage::ViewportAttributes QWebPage::viewportAttributesForSize(const QSize& availableSize) const
1999 ViewportAttributes result;
2001 if (availableSize.isEmpty())
2002 return result; // Returns an invalid instance.
2004 QSize deviceSize(getintenv("QTWEBKIT_DEVICE_WIDTH"), getintenv("QTWEBKIT_DEVICE_HEIGHT"));
2006 // Both environment variables need to be set - or they will be ignored.
2007 if (deviceSize.isNull())
2008 deviceSize = queryDeviceSizeForScreenContainingWidget(view());
2009 QWebPageAdapter::ViewportAttributes attr = d->viewportAttributesForSize(availableSize, deviceSize);
2011 result.m_isValid = true;
2012 result.m_size = attr.size;
2013 result.m_initialScaleFactor = attr.initialScaleFactor;
2014 result.m_minimumScaleFactor = attr.minimumScaleFactor;
2015 result.m_maximumScaleFactor = attr.maximumScaleFactor;
2016 result.m_devicePixelRatio = attr.devicePixelRatio;
2017 result.m_isUserScalable = attr.isUserScalable;
2022 QSize QWebPage::preferredContentsSize() const
2024 QWebFrameAdapter* mainFrame = d->mainFrame ? d->mainFrame->d : 0;
2026 if (mainFrame && mainFrame->hasView())
2027 customSize = mainFrame->customLayoutSize();
2029 return customSize.isNull() ? d->fixedLayoutSize : customSize;
2033 \property QWebPage::preferredContentsSize
2035 \brief a custom size used for laying out the page contents.
2037 By default all pages are laid out using the viewport of the page as the base.
2039 As pages mostly are designed for desktop usage, they often do not layout properly
2040 on small devices as the contents require a certain view width. For this reason
2041 it is common to use a different layout size and then scale the contents to fit
2042 within the actual view.
2044 If this property is set to a valid size, this size is used for all layout needs
2045 instead of the size of the viewport.
2047 Setting an invalid size, makes the page fall back to using the viewport size for layout.
2051 void QWebPage::setPreferredContentsSize(const QSize& size) const
2053 // FIXME: Rename this method to setCustomLayoutSize
2055 d->fixedLayoutSize = size;
2057 QWebFrameAdapter* mainFrame = d->mainFrameAdapter();
2058 if (!mainFrame->hasView())
2061 mainFrame->setCustomLayoutSize(size);
2065 This function is to be called after any (animated) scroll/pan has ended, in the case the application handles the
2066 scrolling/panning of the web contents. This is commonly used in combination with tiling where is it common for
2067 the application to pan the actual view, which then resizes itself to the size of the contents.
2069 \note Calling this function makes WebKit stop trying to calculate the visibleContentRect. To turn that on
2070 again, call this method with an empty rect.
2072 \sa QGraphicsWebView::resizesToContents, QWebSettings::TiledBackingStoreEnabled
2074 void QWebPage::setActualVisibleContentRect(const QRect& rect) const
2076 QWebFrameAdapter* mainFrame = d->mainFrameAdapter();
2077 if (!mainFrame->hasView())
2080 mainFrame->setFixedVisibleContentRect(rect);
2084 \fn bool QWebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, QWebPage::NavigationType type)
2086 This function is called whenever WebKit requests to navigate \a frame to the resource specified by \a request by means of
2087 the specified navigation type \a type.
2089 If \a frame is a null pointer then navigation to a new window is requested. If the request is
2090 accepted createWindow() will be called.
2092 The default implementation interprets the page's linkDelegationPolicy and emits linkClicked accordingly or returns true
2093 to let QWebPage handle the navigation itself.
2097 bool QWebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, QWebPage::NavigationType type)
2100 if (type == NavigationTypeLinkClicked) {
2101 switch (d->linkPolicy) {
2102 case DontDelegateLinks:
2105 case DelegateExternalLinks:
2106 if (QWebPageAdapter::treatSchemeAsLocal(request.url().scheme()))
2108 emit linkClicked(request.url());
2111 case DelegateAllLinks:
2112 emit linkClicked(request.url());
2120 \property QWebPage::hasSelection
2121 \brief whether this page contains selected content or not.
2123 \sa selectionChanged()
2125 bool QWebPage::hasSelection() const
2127 d->createMainFrame();
2128 return d->hasSelection();
2132 \property QWebPage::selectedText
2133 \brief the text currently selected
2135 By default, this property contains an empty string.
2137 \sa selectionChanged(), selectedHtml()
2139 QString QWebPage::selectedText() const
2141 d->createMainFrame();
2142 return d->selectedText();
2147 \property QWebPage::selectedHtml
2148 \brief the HTML currently selected
2150 By default, this property contains an empty string.
2152 \sa selectionChanged(), selectedText()
2154 QString QWebPage::selectedHtml() const
2156 d->createMainFrame();
2157 return d->selectedHtml();
2160 #ifndef QT_NO_ACTION
2162 Returns a QAction for the specified WebAction \a action.
2164 The action is owned by the QWebPage but you can customize the look by
2165 changing its properties.
2167 QWebPage also takes care of implementing the action, so that upon
2168 triggering the corresponding action is performed on the page.
2172 QAction *QWebPage::action(WebAction action) const
2174 if (action == QWebPage::NoWebAction)
2176 if (d->actions[action])
2177 return d->actions[action];
2181 QStyle *style = d->client ? d->client->style() : qApp->style();
2182 bool checkable = false;
2183 QWebPageAdapter::MenuAction mappedAction = QWebPageAdapter::NoAction;
2186 // to be fetched from LocalizedStringsQt via the page adapter
2188 case OpenLinkInNewWindow:
2189 case OpenFrameInNewWindow:
2190 case OpenLinkInThisWindow:
2191 case DownloadLinkToDisk:
2192 case CopyLinkToClipboard:
2193 case OpenImageInNewWindow:
2194 case DownloadImageToDisk:
2195 case CopyImageToClipboard:
2196 case CopyImageUrlToClipboard:
2201 case SetTextDirectionDefault:
2202 case SetTextDirectionLeftToRight:
2203 case SetTextDirectionRightToLeft:
2206 case ToggleUnderline:
2207 mappedAction = adapterMenuActionForWebAction(action);
2209 case InspectElement:
2210 #if ENABLE(INSPECTOR)
2211 mappedAction = QWebPageAdapter::InspectElement;
2215 // icon needed as well, map by hand.
2217 mappedAction = QWebPageAdapter::Back;
2218 icon = style->standardIcon(QStyle::SP_ArrowBack);
2221 mappedAction = QWebPageAdapter::Forward;
2222 icon = style->standardIcon(QStyle::SP_ArrowForward);
2225 mappedAction = QWebPageAdapter::Stop;
2226 icon = style->standardIcon(QStyle::SP_BrowserStop);
2229 mappedAction = QWebPageAdapter::Reload;
2230 icon = style->standardIcon(QStyle::SP_BrowserReload);
2233 #ifndef QT_NO_UNDOSTACK
2235 QAction *a = undoStack()->createUndoAction(d->q);
2236 d->actions[action] = a;
2240 QAction *a = undoStack()->createRedoAction(d->q);
2241 d->actions[action] = a;
2244 #endif // QT_NO_UNDOSTACK
2246 case MoveToNextChar:
2247 text = tr("Move the cursor to the next character");
2249 case MoveToPreviousChar:
2250 text = tr("Move the cursor to the previous character");
2252 case MoveToNextWord:
2253 text = tr("Move the cursor to the next word");
2255 case MoveToPreviousWord:
2256 text = tr("Move the cursor to the previous word");
2258 case MoveToNextLine:
2259 text = tr("Move the cursor to the next line");
2261 case MoveToPreviousLine:
2262 text = tr("Move the cursor to the previous line");
2264 case MoveToStartOfLine:
2265 text = tr("Move the cursor to the start of the line");
2267 case MoveToEndOfLine:
2268 text = tr("Move the cursor to the end of the line");
2270 case MoveToStartOfBlock:
2271 text = tr("Move the cursor to the start of the block");
2273 case MoveToEndOfBlock:
2274 text = tr("Move the cursor to the end of the block");
2276 case MoveToStartOfDocument:
2277 text = tr("Move the cursor to the start of the document");
2279 case MoveToEndOfDocument:
2280 text = tr("Move the cursor to the end of the document");
2282 case SelectNextChar:
2283 text = tr("Select to the next character");
2285 case SelectPreviousChar:
2286 text = tr("Select to the previous character");
2288 case SelectNextWord:
2289 text = tr("Select to the next word");
2291 case SelectPreviousWord:
2292 text = tr("Select to the previous word");
2294 case SelectNextLine:
2295 text = tr("Select to the next line");
2297 case SelectPreviousLine:
2298 text = tr("Select to the previous line");
2300 case SelectStartOfLine:
2301 text = tr("Select to the start of the line");
2303 case SelectEndOfLine:
2304 text = tr("Select to the end of the line");
2306 case SelectStartOfBlock:
2307 text = tr("Select to the start of the block");
2309 case SelectEndOfBlock:
2310 text = tr("Select to the end of the block");
2312 case SelectStartOfDocument:
2313 text = tr("Select to the start of the document");
2315 case SelectEndOfDocument:
2316 text = tr("Select to the end of the document");
2318 case DeleteStartOfWord:
2319 text = tr("Delete to the start of the word");
2321 case DeleteEndOfWord:
2322 text = tr("Delete to the end of the word");
2325 case InsertParagraphSeparator:
2326 text = tr("Insert a new paragraph");
2328 case InsertLineSeparator:
2329 text = tr("Insert a new line");
2332 case PasteAndMatchStyle:
2333 text = tr("Paste and Match Style");
2336 text = tr("Remove formatting");
2339 case ToggleStrikethrough:
2340 text = tr("Strikethrough");
2343 case ToggleSubscript:
2344 text = tr("Subscript");
2347 case ToggleSuperscript:
2348 text = tr("Superscript");
2351 case InsertUnorderedList:
2352 text = tr("Insert Bulleted List");
2355 case InsertOrderedList:
2356 text = tr("Insert Numbered List");
2360 text = tr("Indent");
2363 text = tr("Outdent");
2366 text = tr("Center");
2368 case AlignJustified:
2369 text = tr("Justify");
2372 text = tr("Align Left");
2375 text = tr("Align Right");
2382 if (mappedAction != QWebPageAdapter::NoAction)
2383 text = d->contextMenuItemTagForAction(mappedAction, &checkable);
2388 QAction *a = new QAction(d->q);
2391 a->setCheckable(checkable);
2394 connect(a, SIGNAL(triggered(bool)),
2395 this, SLOT(_q_webActionTriggered(bool)));
2397 d->actions[action] = a;
2398 d->updateAction(action);
2401 #endif // QT_NO_ACTION
2404 \property QWebPage::modified
2405 \brief whether the page contains unsubmitted form data, or the contents have been changed.
2407 By default, this property is false.
2409 \sa contentsChanged(), contentEditable, undoStack()
2411 bool QWebPage::isModified() const
2413 #ifdef QT_NO_UNDOSTACK
2418 return d->undoStack->canUndo();
2419 #endif // QT_NO_UNDOSTACK
2422 #ifndef QT_NO_UNDOSTACK
2424 Returns a pointer to the undo stack used for editable content.
2428 QUndoStack *QWebPage::undoStack() const
2431 d->undoStack = new QUndoStack(const_cast<QWebPage *>(this));
2433 return d->undoStack;
2435 #endif // QT_NO_UNDOSTACK
2439 bool QWebPage::event(QEvent *ev)
2441 switch (ev->type()) {
2443 d->timerEvent(static_cast<QTimerEvent*>(ev));
2445 case QEvent::MouseMove:
2446 d->mouseMoveEvent(static_cast<QMouseEvent*>(ev));
2448 case QEvent::MouseButtonPress:
2449 d->mousePressEvent(static_cast<QMouseEvent*>(ev));
2451 case QEvent::MouseButtonDblClick:
2452 d->mouseDoubleClickEvent(static_cast<QMouseEvent*>(ev));
2454 case QEvent::MouseButtonRelease:
2455 d->mouseReleaseEvent(static_cast<QMouseEvent*>(ev));
2457 #if !defined(QT_NO_GRAPHICSVIEW)
2458 case QEvent::GraphicsSceneMouseMove: {
2459 QGraphicsSceneMouseEvent *gsEv = static_cast<QGraphicsSceneMouseEvent*>(ev);
2460 QMouseEvent dummyEvent(QEvent::MouseMove, gsEv->pos(), gsEv->screenPos(), gsEv->button(), gsEv->buttons(), gsEv->modifiers());
2461 d->mouseMoveEvent(&dummyEvent);
2462 ev->setAccepted(dummyEvent.isAccepted());
2465 case QEvent::GraphicsSceneMouseRelease: {
2466 QGraphicsSceneMouseEvent *gsEv = static_cast<QGraphicsSceneMouseEvent*>(ev);
2467 QMouseEvent dummyEvent(QEvent::MouseButtonRelease, gsEv->pos(), gsEv->screenPos(), gsEv->button(), gsEv->buttons(), gsEv->modifiers());
2468 d->adjustPointForClicking(&dummyEvent);
2469 d->mouseReleaseEvent(&dummyEvent);
2470 ev->setAccepted(dummyEvent.isAccepted());
2473 case QEvent::GraphicsSceneMousePress: {
2474 QGraphicsSceneMouseEvent *gsEv = static_cast<QGraphicsSceneMouseEvent*>(ev);
2475 QMouseEvent dummyEvent(QEvent::MouseButtonPress, gsEv->pos(), gsEv->screenPos(), gsEv->button(), gsEv->buttons(), gsEv->modifiers());
2476 d->adjustPointForClicking(&dummyEvent);
2477 d->mousePressEvent(&dummyEvent);
2478 ev->setAccepted(dummyEvent.isAccepted());
2481 case QEvent::GraphicsSceneMouseDoubleClick: {
2482 QGraphicsSceneMouseEvent *gsEv = static_cast<QGraphicsSceneMouseEvent*>(ev);
2483 QMouseEvent dummyEvent(QEvent::MouseButtonDblClick, gsEv->pos(), gsEv->screenPos(), gsEv->button(), gsEv->buttons(), gsEv->modifiers());
2484 d->adjustPointForClicking(&dummyEvent);
2485 d->mouseDoubleClickEvent(&dummyEvent);
2486 ev->setAccepted(dummyEvent.isAccepted());
2490 #ifndef QT_NO_CONTEXTMENU
2491 case QEvent::ContextMenu:
2492 d->contextMenuEvent(static_cast<QContextMenuEvent*>(ev)->globalPos());
2494 #if !defined(QT_NO_GRAPHICSVIEW)
2495 case QEvent::GraphicsSceneContextMenu:
2496 d->contextMenuEvent(static_cast<QGraphicsSceneContextMenuEvent*>(ev)->screenPos());
2500 #ifndef QT_NO_WHEELEVENT
2502 d->wheelEvent(static_cast<QWheelEvent*>(ev), QApplication::wheelScrollLines());
2504 #if !defined(QT_NO_GRAPHICSVIEW)
2505 case QEvent::GraphicsSceneWheel: {
2506 QGraphicsSceneWheelEvent *gsEv = static_cast<QGraphicsSceneWheelEvent*>(ev);
2507 QWheelEvent dummyEvent(gsEv->pos(), gsEv->screenPos(), gsEv->delta(), gsEv->buttons(), gsEv->modifiers(), gsEv->orientation());
2508 d->wheelEvent(&dummyEvent, QApplication::wheelScrollLines());
2509 ev->setAccepted(dummyEvent.isAccepted());
2514 case QEvent::KeyPress:
2515 d->keyPressEvent(static_cast<QKeyEvent*>(ev));
2517 case QEvent::KeyRelease:
2518 d->keyReleaseEvent(static_cast<QKeyEvent*>(ev));
2520 case QEvent::FocusIn:
2521 d->focusInEvent(static_cast<QFocusEvent*>(ev));
2523 case QEvent::FocusOut:
2524 d->focusOutEvent(static_cast<QFocusEvent*>(ev));
2526 #ifndef QT_NO_DRAGANDDROP
2527 case QEvent::DragEnter:
2528 d->dragEnterEvent(static_cast<QDragEnterEvent*>(ev));
2530 case QEvent::DragLeave:
2531 d->dragLeaveEvent();
2534 case QEvent::DragMove:
2535 d->dragMoveEvent(static_cast<QDragMoveEvent*>(ev));
2538 d->dropEvent(static_cast<QDropEvent*>(ev));
2540 #if !defined(QT_NO_GRAPHICSVIEW)
2541 case QEvent::GraphicsSceneDragEnter:
2542 d->dragEnterEvent(static_cast<QGraphicsSceneDragDropEvent*>(ev));
2544 case QEvent::GraphicsSceneDragMove:
2545 d->dragMoveEvent(static_cast<QGraphicsSceneDragDropEvent*>(ev));
2547 case QEvent::GraphicsSceneDragLeave:
2548 d->dragLeaveEvent();
2551 case QEvent::GraphicsSceneDrop:
2552 d->dropEvent(static_cast<QGraphicsSceneDragDropEvent*>(ev));
2557 case QEvent::InputMethod:
2558 d->inputMethodEvent(static_cast<QInputMethodEvent*>(ev));
2560 case QEvent::ShortcutOverride:
2561 d->shortcutOverrideEvent(static_cast<QKeyEvent*>(ev));
2566 case QEvent::TouchBegin:
2567 case QEvent::TouchUpdate:
2568 case QEvent::TouchEnd:
2569 case QEvent::TouchCancel:
2570 // Return whether the default action was cancelled in the JS event handler
2571 return d->touchEvent(static_cast<QTouchEvent*>(ev));
2572 #ifndef QT_NO_GESTURES
2573 case QEvent::Gesture:
2574 d->gestureEvent(static_cast<QGestureEvent*>(ev));
2577 #ifndef QT_NO_PROPERTIES
2578 case QEvent::DynamicPropertyChange:
2579 d->dynamicPropertyChangeEvent(this, static_cast<QDynamicPropertyChangeEvent*>(ev));
2583 return QObject::event(ev);
2590 Similar to QWidget::focusNextPrevChild() it focuses the next focusable web element
2591 if \a next is true; otherwise the previous element is focused.
2593 Returns true if it can find a new focusable element, or false if it can't.
2595 bool QWebPage::focusNextPrevChild(bool next)
2597 QKeyEvent ev(QEvent::KeyPress, Qt::Key_Tab, Qt::KeyboardModifiers(next ? Qt::NoModifier : Qt::ShiftModifier));
2598 d->keyPressEvent(&ev);
2599 return d->hasFocusedNode();
2603 \property QWebPage::contentEditable
2604 \brief whether the content in this QWebPage is editable or not
2607 If this property is enabled the contents of the page can be edited by the user through a visible
2608 cursor. If disabled (the default) only HTML elements in the web page with their
2609 \c{contenteditable} attribute set are editable.
2611 \sa modified, contentsChanged(), WebAction
2613 void QWebPage::setContentEditable(bool editable)
2615 if (isContentEditable() != editable) {
2616 d->setContentEditable(editable);
2617 d->updateEditorActions();
2621 bool QWebPage::isContentEditable() const
2623 return d->isContentEditable();
2627 \property QWebPage::forwardUnsupportedContent
2628 \brief whether QWebPage should forward unsupported content
2630 If enabled, the unsupportedContent() signal is emitted with a network reply that
2631 can be used to read the content.
2633 If disabled, the download of such content is aborted immediately.
2635 By default unsupported content is not forwarded.
2638 void QWebPage::setForwardUnsupportedContent(bool forward)
2640 d->forwardUnsupportedContent = forward;
2643 bool QWebPage::forwardUnsupportedContent() const
2645 return d->forwardUnsupportedContent;
2649 \property QWebPage::linkDelegationPolicy
2650 \brief how QWebPage should delegate the handling of links through the
2651 linkClicked() signal
2653 The default is to delegate no links.
2656 void QWebPage::setLinkDelegationPolicy(LinkDelegationPolicy policy)
2658 d->linkPolicy = policy;
2661 QWebPage::LinkDelegationPolicy QWebPage::linkDelegationPolicy() const
2663 return d->linkPolicy;
2666 #ifndef QT_NO_CONTEXTMENU
2668 bool QWebPagePrivate::handleScrollbarContextMenuEvent(QContextMenuEvent* event, bool horizontal, QWebPageAdapter::ScrollDirection* direction, QWebPageAdapter::ScrollGranularity* granularity)
2670 if (!QApplication::style()->styleHint(QStyle::SH_ScrollBar_ContextMenu))
2674 QAction* actScrollHere = menu.addAction(QCoreApplication::translate("QWebPage", "Scroll here"));
2675 menu.addSeparator();
2677 QAction* actScrollTop = menu.addAction(horizontal ? QCoreApplication::translate("QWebPage", "Left edge") : QCoreApplication::translate("QWebPage", "Top"));
2678 QAction* actScrollBottom = menu.addAction(horizontal ? QCoreApplication::translate("QWebPage", "Right edge") : QCoreApplication::translate("QWebPage", "Bottom"));
2679 menu.addSeparator();
2681 QAction* actPageUp = menu.addAction(horizontal ? QCoreApplication::translate("QWebPage", "Page left") : QCoreApplication::translate("QWebPage", "Page up"));
2682 QAction* actPageDown = menu.addAction(horizontal ? QCoreApplication::translate("QWebPage", "Page right") : QCoreApplication::translate("QWebPage", "Page down"));
2683 menu.addSeparator();
2685 QAction* actScrollUp = menu.addAction(horizontal ? QCoreApplication::translate("QWebPage", "Scroll left") : QCoreApplication::translate("QWebPage", "Scroll up"));
2686 QAction* actScrollDown = menu.addAction(horizontal ? QCoreApplication::translate("QWebPage", "Scroll right") : QCoreApplication::translate("QWebPage", "Scroll down"));
2688 QAction* actionSelected = menu.exec(event->globalPos());
2690 if (actionSelected == actScrollHere)
2692 if (actionSelected == actScrollTop) {
2693 *direction = horizontal ? ScrollLeft : ScrollUp;
2694 *granularity = ScrollByDocument;
2695 } else if (actionSelected == actScrollBottom) {
2696 *direction =horizontal ? ScrollRight : ScrollDown;
2697 *granularity = ScrollByDocument;
2698 } else if (actionSelected == actPageUp) {
2699 *direction = horizontal ? ScrollLeft : ScrollUp;
2700 *granularity = ScrollByPage;
2701 } else if (actionSelected == actPageDown) {
2702 *direction =horizontal ? ScrollRight : ScrollDown;
2703 *granularity = ScrollByPage;
2704 } else if (actionSelected == actScrollUp) {
2705 *direction = horizontal ? ScrollLeft : ScrollUp;
2706 *granularity = ScrollByLine;
2707 } else if (actionSelected == actScrollDown) {
2708 *direction =horizontal ? ScrollRight : ScrollDown;
2709 *granularity = ScrollByLine;
2715 Filters the context menu event, \a event, through handlers for scrollbars and
2716 custom event handlers in the web page. Returns true if the event was handled;
2719 A web page may swallow a context menu event through a custom event handler, allowing for context
2720 menus to be implemented in HTML/JavaScript. This is used by \l{http://maps.google.com/}{Google
2723 bool QWebPage::swallowContextMenuEvent(QContextMenuEvent *event)
2725 QWebFrame* webFrame = frameAt(event->pos());
2726 return d->swallowContextMenuEvent(event, webFrame ? webFrame->d : 0);
2728 #endif // QT_NO_CONTEXTMENU
2731 Updates the page's actions depending on the position \a pos. For example if \a pos is over an image
2732 element the CopyImageToClipboard action is enabled.
2734 void QWebPage::updatePositionDependentActions(const QPoint &pos)
2736 #ifndef QT_NO_ACTION
2737 // First we disable all actions, but keep track of which ones were originally enabled.
2738 QBitArray originallyEnabledWebActions(QWebPage::WebActionCount);
2739 for (int i = QWebPageAdapter::NoAction + 1; i < QWebPageAdapter::ActionCount; ++i) {
2740 QWebPage::WebAction action = webActionForAdapterMenuAction(QWebPageAdapter::MenuAction(i));
2741 if (QAction *a = this->action(action)) {
2742 originallyEnabledWebActions.setBit(action, a->isEnabled());
2743 a->setEnabled(false);
2746 #endif // QT_NO_ACTION
2748 QBitArray visitedWebActions(QWebPage::WebActionCount);
2749 d->createMainFrame();
2750 // Then we let updatePositionDependantMenuActions() enable the actions that are put into the menu
2751 QWebHitTestResultPrivate* result = d->updatePositionDependentMenuActions(pos, &visitedWebActions);
2753 d->hitTestResult = QWebHitTestResult();
2755 d->hitTestResult = QWebHitTestResult(result);
2757 #ifndef QT_NO_ACTION
2758 // Finally, we restore the original enablement for the actions that were not put into the menu.
2759 originallyEnabledWebActions &= ~visitedWebActions; // Mask out visited actions (they're part of the menu)
2760 for (int i = 0; i < QWebPage::WebActionCount; ++i) {
2761 if (originallyEnabledWebActions.at(i)) {
2762 if (QAction *a = this->action(QWebPage::WebAction(i)))
2763 a->setEnabled(true);
2766 #endif // QT_NO_ACTION
2768 // This whole process ensures that any actions put into to the context menu has the right
2769 // enablement, while also keeping the correct enablement for actions that were left out of
2777 \enum QWebPage::Extension
2779 This enum describes the types of extensions that the page can support. Before using these extensions, you
2780 should verify that the extension is supported by calling supportsExtension().
2782 \value ChooseMultipleFilesExtension Whether the web page supports multiple file selection.
2783 This extension is invoked when the web content requests one or more file names, for example
2784 as a result of the user clicking on a "file upload" button in a HTML form where multiple
2785 file selection is allowed.
2787 \value ErrorPageExtension Whether the web page can provide an error page when loading fails.
2788 (introduced in Qt 4.6)
2790 \sa ChooseMultipleFilesExtensionOption, ChooseMultipleFilesExtensionReturn, ErrorPageExtensionOption, ErrorPageExtensionReturn
2794 \enum QWebPage::ErrorDomain
2797 This enum describes the domain of an ErrorPageExtensionOption object (i.e. the layer in which the error occurred).
2799 \value QtNetwork The error occurred in the QtNetwork layer; the error code is of type QNetworkReply::NetworkError.
2800 \value Http The error occurred in the HTTP layer; the error code is a HTTP status code (see QNetworkRequest::HttpStatusCodeAttribute).
2801 \value WebKit The error is an internal WebKit error.
2805 \class QWebPage::ExtensionOption
2807 \brief The ExtensionOption class provides an extended input argument to QWebPage's extension support.
2811 \sa QWebPage::extension(), QWebPage::ExtensionReturn
2816 \class QWebPage::ExtensionReturn
2818 \brief The ExtensionReturn class provides an output result from a QWebPage's extension.
2822 \sa QWebPage::extension(), QWebPage::ExtensionOption
2826 \class QWebPage::ErrorPageExtensionOption
2828 \brief The ErrorPageExtensionOption class describes the option
2829 for the error page extension.
2833 The ErrorPageExtensionOption class holds the \a url for which an error occurred as well as
2834 the associated \a frame.
2836 The error itself is reported by an error \a domain, the \a error code as well as \a errorString.
2838 \sa QWebPage::extension(), QWebPage::ErrorPageExtensionReturn
2842 \variable QWebPage::ErrorPageExtensionOption::url
2843 \brief the url for which an error occurred
2847 \variable QWebPage::ErrorPageExtensionOption::frame
2848 \brief the frame associated with the error
2852 \variable QWebPage::ErrorPageExtensionOption::domain
2853 \brief the domain that reported the error
2857 \variable QWebPage::ErrorPageExtensionOption::error
2858 \brief the error code. Interpretation of the value depends on the \a domain
2859 \sa QWebPage::ErrorDomain
2863 \variable QWebPage::ErrorPageExtensionOption::errorString
2864 \brief a string that describes the error
2868 \class QWebPage::ErrorPageExtensionReturn
2870 \brief The ErrorPageExtensionReturn describes the error page, which will be shown for the
2871 frame for which the error occured.
2875 The ErrorPageExtensionReturn class holds the data needed for creating an error page. Some are
2876 optional such as \a contentType, which defaults to "text/html", as well as the \a encoding, which
2877 is assumed to be UTF-8 if not indicated otherwise.
2879 The error page is stored in the \a content byte array, as HTML content. In order to convert a
2880 QString to a byte array, the QString::toUtf8() method can be used.
2882 External objects such as stylesheets or images referenced in the HTML are located relative to
2885 \sa QWebPage::extension(), QWebPage::ErrorPageExtensionOption, QString::toUtf8()
2889 \fn QWebPage::ErrorPageExtensionReturn::ErrorPageExtensionReturn()
2891 Constructs a new error page object.
2896 \variable QWebPage::ErrorPageExtensionReturn::contentType
2897 \brief the error page's content type
2901 \variable QWebPage::ErrorPageExtensionReturn::encoding
2902 \brief the error page encoding
2906 \variable QWebPage::ErrorPageExtensionReturn::baseUrl
2909 External objects such as stylesheets or images referenced in the HTML are located relative to this url.
2913 \variable QWebPage::ErrorPageExtensionReturn::content
2914 \brief the HTML content of the error page
2918 \class QWebPage::ChooseMultipleFilesExtensionOption
2920 \brief The ChooseMultipleFilesExtensionOption class describes the option
2921 for the multiple files selection extension.
2925 The ChooseMultipleFilesExtensionOption class holds the frame originating the request
2926 and the suggested filenames which might be provided.
2928 \sa QWebPage::extension(), QWebPage::chooseFile(), QWebPage::ChooseMultipleFilesExtensionReturn
2932 \variable QWebPage::ChooseMultipleFilesExtensionOption::parentFrame
2933 \brief The frame in which the request originated
2937 \variable QWebPage::ChooseMultipleFilesExtensionOption::suggestedFileNames
2938 \brief The suggested filenames
2942 \variable QWebPage::ChooseMultipleFilesExtensionReturn::fileNames
2943 \brief The selected filenames
2947 \class QWebPage::ChooseMultipleFilesExtensionReturn
2949 \brief The ChooseMultipleFilesExtensionReturn describes the return value
2950 for the multiple files selection extension.
2954 The ChooseMultipleFilesExtensionReturn class holds the filenames selected by the user
2955 when the extension is invoked.
2957 \sa QWebPage::extension(), QWebPage::ChooseMultipleFilesExtensionOption
2961 This virtual function can be reimplemented in a QWebPage subclass to provide support for extensions. The \a option
2962 argument is provided as input to the extension; the output results can be stored in \a output.
2964 The behavior of this function is determined by \a extension. The \a option
2965 and \a output values are typically casted to the corresponding types (for
2966 example, ChooseMultipleFilesExtensionOption and
2967 ChooseMultipleFilesExtensionReturn for ChooseMultipleFilesExtension).
2969 You can call supportsExtension() to check if an extension is supported by the page.
2971 Returns true if the extension was called successfully; otherwise returns false.
2973 \sa supportsExtension(), Extension
2975 bool QWebPage::extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output)
2977 #ifndef QT_NO_FILEDIALOG
2978 if (extension == ChooseMultipleFilesExtension) {
2979 // FIXME: do not ignore suggestedFiles
2980 QStringList suggestedFiles = static_cast<const ChooseMultipleFilesExtensionOption*>(option)->suggestedFileNames;
2981 QStringList names = QFileDialog::getOpenFileNames(view(), QString::null);
2982 static_cast<ChooseMultipleFilesExtensionReturn*>(output)->fileNames = names;
2991 This virtual function returns true if the web page supports \a extension; otherwise false is returned.
2995 bool QWebPage::supportsExtension(Extension extension) const
2997 #ifndef QT_NO_FILEDIALOG
2998 return extension == ChooseMultipleFilesExtension;
3000 Q_UNUSED(extension);
3008 QWebPageAdapter *QWebPage::handle() const
3014 Finds the specified string, \a subString, in the page, using the given \a options.
3016 If the HighlightAllOccurrences flag is passed, the function will highlight all occurrences
3017 that exist in the page. All subsequent calls will extend the highlight, rather than
3018 replace it, with occurrences of the new string.
3020 If the HighlightAllOccurrences flag is not passed, the function will select an occurrence
3021 and all subsequent calls will replace the current occurrence with the next one.
3023 To clear the selection, just pass an empty string.
3025 Returns true if \a subString was found; otherwise returns false.
3027 bool QWebPage::findText(const QString &subString, FindFlags options)
3029 return d->findText(subString, static_cast<QWebPageAdapter::FindFlag>(options.operator int()));
3033 Returns a pointer to the page's settings object.
3035 \sa QWebSettings::globalSettings()
3037 QWebSettings *QWebPage::settings() const
3043 This function is called when the web content requests a file name, for example
3044 as a result of the user clicking on a "file upload" button in a HTML form.
3046 A suggested filename may be provided in \a suggestedFile. The frame originating the
3047 request is provided as \a parentFrame.
3049 \sa ChooseMultipleFilesExtension
3051 QString QWebPage::chooseFile(QWebFrame *parentFrame, const QString& suggestedFile)
3053 Q_UNUSED(parentFrame);
3054 #ifndef QT_NO_FILEDIALOG
3055 return QFileDialog::getOpenFileName(view(), QString::null, suggestedFile);
3057 return QString::null;
3062 Sets the QNetworkAccessManager \a manager responsible for serving network requests for this
3065 \note It is currently not supported to change the network access manager after the
3066 QWebPage has used it. The results of doing this are undefined.
3068 \sa networkAccessManager()
3070 void QWebPage::setNetworkAccessManager(QNetworkAccessManager *manager)
3072 d->setNetworkAccessManager(manager);
3076 Returns the QNetworkAccessManager that is responsible for serving network
3077 requests for this QWebPage.
3079 \sa setNetworkAccessManager()
3081 QNetworkAccessManager *QWebPage::networkAccessManager() const
3083 return d->networkAccessManager();
3087 Sets the QWebPluginFactory \a factory responsible for creating plugins embedded into this
3090 Note: The plugin factory is only used if the QWebSettings::PluginsEnabled attribute is enabled.
3094 void QWebPage::setPluginFactory(QWebPluginFactory *factory)
3096 d->pluginFactory = factory;
3100 Returns the QWebPluginFactory that is responsible for creating plugins embedded into
3101 this QWebPage. If no plugin factory is installed a null pointer is returned.
3103 \sa setPluginFactory()
3105 QWebPluginFactory *QWebPage::pluginFactory() const
3107 return d->pluginFactory;
3111 This function is called when a user agent for HTTP requests is needed. You can reimplement this
3112 function to dynamically return different user agents for different URLs, based on the \a url parameter.
3114 The default implementation returns the following value:
3116 "Mozilla/5.0 (%Platform%%Security%%Subplatform%) AppleWebKit/%WebKitVersion% (KHTML, like Gecko) %AppVersion Safari/%WebKitVersion%"
3118 In this string the following values are replaced at run-time:
3120 \li %Platform% expands to the windowing system followed by "; " if it is not Windows (e.g. "X11; ").
3121 \li %Security% expands to "N; " if SSL is disabled.
3122 \li %Subplatform% expands to the operating system version (e.g. "Windows NT 6.1" or "Intel Mac OS X 10.5").
3123 \li %WebKitVersion% is the version of WebKit the application was compiled against.
3124 \li %AppVersion% expands to QCoreApplication::applicationName()/QCoreApplication::applicationVersion() if they're set; otherwise defaulting to Qt and the current Qt version.
3127 QString QWebPage::userAgentForUrl(const QUrl&) const
3129 return QWebPageAdapter::defaultUserAgentString();
3134 Returns the total number of bytes that were received from the network to render the current page,
3135 including extra content such as embedded images.
3139 quint64 QWebPage::totalBytes() const
3141 return d->m_totalBytes;
3146 Returns the number of bytes that were received from the network to render the current page.
3148 \sa totalBytes(), loadProgress()
3150 quint64 QWebPage::bytesReceived() const
3152 return d->m_bytesReceived;
3157 \property QWebPage::visibilityState
3158 \brief the page's visibility state
3160 This property should be changed by Qt applications who want to notify the JavaScript application
3161 that the visibility state has changed (e.g. by reimplementing QWidget::setVisible).
3162 The visibility state will be updated with the \a state parameter value only if it's different from the previous set.
3163 Then, HTML DOM Document Object attributes 'hidden' and 'visibilityState'
3164 will be updated to the correct value and a 'visiblitychange' event will be fired.
3165 More information about this HTML5 API can be found at \l{http://www.w3.org/TR/page-visibility/}{W3C Recommendation: Page Visibility}.
3167 By default, this property is set to VisibilityStateVisible.
3169 void QWebPage::setVisibilityState(VisibilityState state)
3171 d->setVisibilityState(static_cast<QWebPageAdapter::VisibilityState>(state));
3174 QWebPage::VisibilityState QWebPage::visibilityState() const
3176 return static_cast<VisibilityState>(d->visibilityState());
3182 \fn void QWebPage::viewportChangeRequested()
3184 Page authors can provide the supplied values by using the viewport meta tag. More information
3185 about this can be found at \l{http://developer.apple.com/safari/library/documentation/appleapplications/reference/safariwebcontent/usingtheviewport/usingtheviewport.html}{Safari Reference Library: Using the Viewport Meta Tag}.
3187 \sa QWebPage::ViewportAttributes, setPreferredContentsSize(), QGraphicsWebView::setScale()
3191 \fn void QWebPage::loadStarted()
3193 This signal is emitted when a page starts loading content.
3199 \fn void QWebPage::loadProgress(int progress)
3201 This signal is emitted when the global progress status changes.
3202 The current value is provided by \a progress and scales from 0 to 100,
3203 which is the default range of QProgressBar.
3204 It accumulates changes from all the child frames.
3210 \fn void QWebPage::loadFinished(bool ok)
3212 This signal is emitted when the page finishes loading content. This signal
3213 is independant of script execution or page rendering.
3214 \a ok will indicate whether the load was successful or any error occurred.
3216 \sa loadStarted(), ErrorPageExtension
3220 \fn void QWebPage::linkHovered(const QString &link, const QString &title, const QString &textContent)
3222 This signal is emitted when the mouse hovers over a link.
3224 \a link contains the link url.
3225 \a title is the link element's title, if it is specified in the markup.
3226 \a textContent provides text within the link element, e.g., text inside an HTML anchor tag.
3228 When the mouse leaves the link element the signal is emitted with empty parameters.
3234 \fn void QWebPage::statusBarMessage(const QString& text)
3236 This signal is emitted when the statusbar \a text is changed by the page.
3240 \fn void QWebPage::frameCreated(QWebFrame *frame)
3242 This signal is emitted whenever the page creates a new \a frame.
3248 \fn void QWebPage::selectionChanged()
3250 This signal is emitted whenever the selection changes, either interactively
3251 or programmatically (e.g. by calling triggerAction() with a selection action).
3257 \fn void QWebPage::contentsChanged()
3260 This signal is emitted whenever the text in form elements changes
3261 as well as other editable content.
3263 \sa contentEditable, modified, QWebFrame::toHtml(), QWebFrame::toPlainText()
3267 \fn void QWebPage::geometryChangeRequested(const QRect& geom)
3269 This signal is emitted whenever the document wants to change the position and size of the
3270 page to \a geom. This can happen for example through JavaScript.
3274 \fn void QWebPage::repaintRequested(const QRect& dirtyRect)
3276 This signal is emitted whenever this QWebPage should be updated. It's useful
3277 when rendering a QWebPage without a QWebView or QGraphicsWebView.
3278 \a dirtyRect contains the area that needs to be updated. To paint the QWebPage get
3279 the mainFrame() and call the render(QPainter*, const QRegion&) method with the
3280 \a dirtyRect as the second parameter.
3287 \fn void QWebPage::scrollRequested(int dx, int dy, const QRect& rectToScroll)
3289 This signal is emitted whenever the content given by \a rectToScroll needs
3290 to be scrolled \a dx and \a dy downwards and no view was set.
3296 \fn void QWebPage::windowCloseRequested()
3298 This signal is emitted whenever the page requests the web browser window to be closed,
3299 for example through the JavaScript \c{window.close()} call.
3303 \fn void QWebPage::printRequested(QWebFrame *frame)
3305 This signal is emitted whenever the page requests the web browser to print \a frame,
3306 for example through the JavaScript \c{window.print()} call.
3308 \sa QWebFrame::print(), QPrintPreviewDialog
3312 \fn void QWebPage::unsupportedContent(QNetworkReply *reply)
3314 This signal is emitted when WebKit cannot handle a link the user navigated to or a
3315 web server's response includes a "Content-Disposition" header with the 'attachment'
3316 directive. If "Content-Disposition" is present in \a reply, the web server is indicating
3317 that the client should prompt the user to save the content regardless of content-type.
3318 See RFC 2616 sections 19.5.1 for details about Content-Disposition.
3320 At signal emission time the meta-data of the QNetworkReply \a reply is available.
3322 \note The receiving slot is responsible for deleting the QNetworkReply \a reply.
3324 \note This signal is only emitted if the forwardUnsupportedContent property is set to true.
3326 \sa downloadRequested()
3330 \fn void QWebPage::downloadRequested(const QNetworkRequest &request)
3332 This signal is emitted when the user decides to download a link. The url of
3333 the link as well as additional meta-information is contained in \a request.
3335 \sa unsupportedContent()
3339 \fn void QWebPage::microFocusChanged()
3341 This signal is emitted when for example the position of the cursor in an editable form
3342 element changes. It is used to inform input methods about the new on-screen position where
3343 the user is able to enter text. This signal is usually connected to the
3344 QWidget::updateMicroFocus() slot.
3348 \fn void QWebPage::linkClicked(const QUrl &url)
3350 This signal is emitted whenever the user clicks on a link and the page's linkDelegationPolicy
3351 property is set to delegate the link handling for the specified \a url.
3353 By default no links are delegated and are handled by QWebPage instead.
3355 \note This signal possibly won't be emitted for clicked links which use
3356 JavaScript to trigger navigation.
3362 \fn void QWebPage::toolBarVisibilityChangeRequested(bool visible)
3364 This signal is emitted whenever the visibility of the toolbar in a web browser
3365 window that hosts QWebPage should be changed to \a visible.
3369 \fn void QWebPage::statusBarVisibilityChangeRequested(bool visible)
3371 This signal is emitted whenever the visibility of the statusbar in a web browser
3372 window that hosts QWebPage should be changed to \a visible.
3376 \fn void QWebPage::menuBarVisibilityChangeRequested(bool visible)
3378 This signal is emitted whenever the visibility of the menubar in a web browser
3379 window that hosts QWebPage should be changed to \a visible.
3383 \fn void QWebPage::databaseQuotaExceeded(QWebFrame* frame, QString databaseName);
3386 This signal is emitted whenever the web site shown in \a frame is asking to store data
3387 to the database \a databaseName and the quota allocated to that web site is exceeded.
3392 \fn void QWebPage::applicationCacheQuotaExceeded(QWebSecurityOrigin* origin, quint64 defaultOriginQuota, quint64 totalSpaceNeeded);
3394 This signal is emitted whenever the web site is asking to store data to the application cache
3395 database databaseName and the quota allocated to that web site is exceeded.
3401 \fn void QWebPage::saveFrameStateRequested(QWebFrame* frame, QWebHistoryItem* item);
3403 This signal is emitted shortly before the history of navigated pages
3404 in \a frame is changed, for example when navigating back in the history.
3406 The provided QWebHistoryItem, \a item, holds the history entry of the frame before
3409 A potential use-case for this signal is to store custom data in
3410 the QWebHistoryItem associated to the frame, using QWebHistoryItem::setUserData().
3415 \fn void QWebPage::restoreFrameStateRequested(QWebFrame* frame);
3417 This signal is emitted when the load of \a frame is finished and the application may now update its state accordingly.
3421 \fn QWebPagePrivate* QWebPage::handle() const
3425 #include "moc_qwebpage.cpp"