#include "config.h"
#include "qwebpage.h"
#include "qwebview.h"
#include "qwebframe.h"
#include "qwebpage_p.h"
#include "qwebframe_p.h"
#include "qwebhistory.h"
#include "qwebhistory_p.h"
#include "qwebsettings.h"
#include "Frame.h"
#include "FrameTree.h"
#include "FrameLoader.h"
#include "FrameLoaderClientQt.h"
#include "FrameView.h"
#include "FormState.h"
#include "ChromeClientQt.h"
#include "ContextMenu.h"
#include "ContextMenuClientQt.h"
#include "DocumentLoader.h"
#include "DragClientQt.h"
#include "DragController.h"
#include "DragData.h"
#include "EditorClientQt.h"
#include "SecurityOrigin.h"
#include "Settings.h"
#include "Page.h"
#include "Pasteboard.h"
#include "FrameLoader.h"
#include "FrameLoadRequest.h"
#include "KURL.h"
#include "Logging.h"
#include "Image.h"
#include "InspectorClientQt.h"
#include "InspectorController.h"
#include "FocusController.h"
#include "Editor.h"
#include "Scrollbar.h"
#include "PlatformKeyboardEvent.h"
#include "PlatformWheelEvent.h"
#include "ProgressTracker.h"
#include "RefPtr.h"
#include "HashMap.h"
#include "HTMLFormElement.h"
#include "HitTestResult.h"
#include "WindowFeatures.h"
#include "LocalizedStrings.h"
#include "Cache.h"
#include "runtime/InitializeThreading.h"
#include <QApplication>
#include <QBasicTimer>
#include <QBitArray>
#include <QDebug>
#include <QDragEnterEvent>
#include <QDragLeaveEvent>
#include <QDragMoveEvent>
#include <QDropEvent>
#include <QFileDialog>
#include <QHttpRequestHeader>
#include <QInputDialog>
#include <QLocale>
#include <QMessageBox>
#include <QNetworkProxy>
#include <QUndoStack>
#include <QUrl>
#include <QPainter>
#include <QClipboard>
#include <QSslSocket>
#include <QStyle>
#include <QSysInfo>
#if QT_VERSION >= 0x040400
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#else
#include "qwebnetworkinterface.h"
#endif
using namespace WebCore;
bool QWebPagePrivate::drtRun = false;
void QWEBKIT_EXPORT qt_drt_run(bool b)
{
QWebPagePrivate::drtRun = b;
}
void QWEBKIT_EXPORT qt_webpage_setGroupName(QWebPage* page, const QString& groupName)
{
page->handle()->page->setGroupName(groupName);
}
QString QWEBKIT_EXPORT qt_webpage_groupName(QWebPage* page)
{
return page->handle()->page->groupName();
}
static const char* editorCommandWebActions[] =
{
0,
0, 0,
0, 0,
0, 0, 0,
0, 0, 0, 0,
"Cut", "Copy", "Paste",
"Undo", "Redo", "MoveForward", "MoveBackward", "MoveWordForward", "MoveWordBackward", "MoveDown", "MoveUp", "MoveToBeginningOfLine", "MoveToEndOfLine", "MoveToBeginningOfParagraph", "MoveToEndOfParagraph", "MoveToBeginningOfDocument", "MoveToEndOfDocument", "MoveForwardAndModifySelection", "MoveBackwardAndModifySelection", "MoveWordForwardAndModifySelection", "MoveWordBackwardAndModifySelection", "MoveDownAndModifySelection", "MoveUpAndModifySelection", "MoveToBeginningOfLineAndModifySelection", "MoveToEndOfLineAndModifySelection", "MoveToBeginningOfParagraphAndModifySelection", "MoveToEndOfParagraphAndModifySelection", "MoveToBeginningOfDocumentAndModifySelection", "MoveToEndOfDocumentAndModifySelection", "DeleteWordBackward", "DeleteWordForward",
0, 0, 0,
"ToggleBold", "ToggleItalic", "ToggleUnderline",
0,
"InsertNewline", "InsertLineBreak",
"SelectAll",
"PasteAndMatchStyle", "RemoveFormat", "Strikethrough", "Subscript", "Superscript", "InsertUnorderedList", "InsertOrderedList", "Indent", "Outdent",
"AlignCenter", "AlignJustified", "AlignLeft", "AlignRight",
0 };
const char* QWebPagePrivate::editorCommandForWebActions(QWebPage::WebAction action)
{
if ((action > QWebPage::NoWebAction) && (action < int(sizeof(editorCommandWebActions) / sizeof(const char*))))
return editorCommandWebActions[action];
return 0;
}
#ifndef QT_NO_CURSOR
SetCursorEvent::SetCursorEvent(const QCursor& cursor)
: QEvent(static_cast<QEvent::Type>(EventType))
, m_cursor(cursor)
{}
QCursor SetCursorEvent::cursor() const
{
return m_cursor;
}
#endif
#define WEBKIT_VERSION "527+"
static inline DragOperation dropActionToDragOp(Qt::DropActions actions)
{
unsigned result = 0;
if (actions & Qt::CopyAction)
result |= DragOperationCopy;
if (actions & Qt::MoveAction)
result |= DragOperationMove;
if (actions & Qt::LinkAction)
result |= DragOperationLink;
return (DragOperation)result;
}
static inline Qt::DropAction dragOpToDropAction(unsigned actions)
{
Qt::DropAction result = Qt::IgnoreAction;
if (actions & DragOperationCopy)
result = Qt::CopyAction;
else if (actions & DragOperationMove)
result = Qt::MoveAction;
else if (actions & DragOperationLink)
result = Qt::LinkAction;
return result;
}
QWebPagePrivate::QWebPagePrivate(QWebPage *qq)
: q(qq)
, view(0)
, viewportSize(QSize(0,0))
{
WebCore::InitializeLoggingChannelsIfNecessary();
JSC::initializeThreading();
WebCore::FrameLoader::setLocalLoadPolicy(WebCore::FrameLoader::AllowLocalLoadsForLocalAndSubstituteData);
chromeClient = new ChromeClientQt(q);
contextMenuClient = new ContextMenuClientQt();
editorClient = new EditorClientQt(q);
page = new Page(chromeClient, contextMenuClient, editorClient,
new DragClientQt(q), new InspectorClientQt(q));
page->settings()->setDefaultTextEncodingName("iso-8859-1");
settings = new QWebSettings(page->settings());
#ifndef QT_NO_UNDOSTACK
undoStack = 0;
#endif
mainFrame = 0;
#if QT_VERSION < 0x040400
networkInterface = 0;
#else
networkManager = 0;
#endif
pluginFactory = 0;
insideOpenCall = false;
forwardUnsupportedContent = false;
editable = false;
useFixedLayout = false;
linkPolicy = QWebPage::DontDelegateLinks;
#ifndef QT_NO_CONTEXTMENU
currentContextMenu = 0;
#endif
history.d = new QWebHistoryPrivate(page->backForwardList());
memset(actions, 0, sizeof(actions));
}
QWebPagePrivate::~QWebPagePrivate()
{
#ifndef QT_NO_CONTEXTMENU
delete currentContextMenu;
#endif
#ifndef QT_NO_UNDOSTACK
delete undoStack;
#endif
delete settings;
delete page;
}
#if QT_VERSION < 0x040400
bool QWebPagePrivate::acceptNavigationRequest(QWebFrame *frame, const QWebNetworkRequest &request, QWebPage::NavigationType type)
{
if (insideOpenCall
&& frame == mainFrame)
return true;
return q->acceptNavigationRequest(frame, request, type);
}
#else
bool QWebPagePrivate::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, QWebPage::NavigationType type)
{
if (insideOpenCall
&& frame == mainFrame)
return true;
return q->acceptNavigationRequest(frame, request, type);
}
#endif
void QWebPagePrivate::createMainFrame()
{
if (!mainFrame) {
QWebFrameData frameData;
frameData.ownerElement = 0;
frameData.allowsScrolling = true;
frameData.marginWidth = 0;
frameData.marginHeight = 0;
mainFrame = new QWebFrame(q, &frameData);
emit q->frameCreated(mainFrame);
}
}
static QWebPage::WebAction webActionForContextMenuAction(WebCore::ContextMenuAction action)
{
switch (action) {
case WebCore::ContextMenuItemTagOpenLink: return QWebPage::OpenLink;
case WebCore::ContextMenuItemTagOpenLinkInNewWindow: return QWebPage::OpenLinkInNewWindow;
case WebCore::ContextMenuItemTagDownloadLinkToDisk: return QWebPage::DownloadLinkToDisk;
case WebCore::ContextMenuItemTagCopyLinkToClipboard: return QWebPage::CopyLinkToClipboard;
case WebCore::ContextMenuItemTagOpenImageInNewWindow: return QWebPage::OpenImageInNewWindow;
case WebCore::ContextMenuItemTagDownloadImageToDisk: return QWebPage::DownloadImageToDisk;
case WebCore::ContextMenuItemTagCopyImageToClipboard: return QWebPage::CopyImageToClipboard;
case WebCore::ContextMenuItemTagOpenFrameInNewWindow: return QWebPage::OpenFrameInNewWindow;
case WebCore::ContextMenuItemTagCopy: return QWebPage::Copy;
case WebCore::ContextMenuItemTagGoBack: return QWebPage::Back;
case WebCore::ContextMenuItemTagGoForward: return QWebPage::Forward;
case WebCore::ContextMenuItemTagStop: return QWebPage::Stop;
case WebCore::ContextMenuItemTagReload: return QWebPage::Reload;
case WebCore::ContextMenuItemTagCut: return QWebPage::Cut;
case WebCore::ContextMenuItemTagPaste: return QWebPage::Paste;
case WebCore::ContextMenuItemTagDefaultDirection: return QWebPage::SetTextDirectionDefault;
case WebCore::ContextMenuItemTagLeftToRight: return QWebPage::SetTextDirectionLeftToRight;
case WebCore::ContextMenuItemTagRightToLeft: return QWebPage::SetTextDirectionRightToLeft;
case WebCore::ContextMenuItemTagBold: return QWebPage::ToggleBold;
case WebCore::ContextMenuItemTagItalic: return QWebPage::ToggleItalic;
case WebCore::ContextMenuItemTagUnderline: return QWebPage::ToggleUnderline;
case WebCore::ContextMenuItemTagInspectElement: return QWebPage::InspectElement;
default: break;
}
return QWebPage::NoWebAction;
}
#ifndef QT_NO_CONTEXTMENU
QMenu *QWebPagePrivate::createContextMenu(const WebCore::ContextMenu *webcoreMenu,
const QList<WebCore::ContextMenuItem> *items, QBitArray *visitedWebActions)
{
QMenu* menu = new QMenu(view);
for (int i = 0; i < items->count(); ++i) {
const ContextMenuItem &item = items->at(i);
switch (item.type()) {
case WebCore::CheckableActionType:
case WebCore::ActionType: {
QWebPage::WebAction action = webActionForContextMenuAction(item.action());
QAction *a = q->action(action);
if (a) {
ContextMenuItem it(item);
webcoreMenu->checkOrEnableIfNeeded(it);
PlatformMenuItemDescription desc = it.releasePlatformDescription();
a->setEnabled(desc.enabled);
a->setChecked(desc.checked);
a->setCheckable(item.type() == WebCore::CheckableActionType);
menu->addAction(a);
visitedWebActions->setBit(action);
}
break;
}
case WebCore::SeparatorType:
menu->addSeparator();
break;
case WebCore::SubmenuType: {
QMenu *subMenu = createContextMenu(webcoreMenu, item.platformSubMenu(), visitedWebActions);
bool anyEnabledAction = false;
QList<QAction *> actions = subMenu->actions();
for (int i = 0; i < actions.count(); ++i) {
if (actions.at(i)->isVisible())
anyEnabledAction |= actions.at(i)->isEnabled();
}
if (anyEnabledAction) {
subMenu->setTitle(item.title());
menu->addAction(subMenu->menuAction());
} else {
delete subMenu;
}
break;
}
}
}
return menu;
}
#endif // QT_NO_CONTEXTMENU
void QWebPagePrivate::_q_webActionTriggered(bool checked)
{
QAction *a = qobject_cast<QAction *>(q->sender());
if (!a)
return;
QWebPage::WebAction action = static_cast<QWebPage::WebAction>(a->data().toInt());
q->triggerAction(action, checked);
}
#ifndef NDEBUG
void QWebPagePrivate::_q_cleanupLeakMessages()
{
cache()->setCapacities(0, 0, 0);
}
#endif
void QWebPagePrivate::updateAction(QWebPage::WebAction action)
{
QAction *a = actions[action];
if (!a || !mainFrame)
return;
WebCore::FrameLoader *loader = mainFrame->d->frame->loader();
WebCore::Editor *editor = page->focusController()->focusedOrMainFrame()->editor();
bool enabled = a->isEnabled();
bool checked = a->isChecked();
switch (action) {
case QWebPage::Back:
enabled = loader->canGoBackOrForward(-1);
break;
case QWebPage::Forward:
enabled = loader->canGoBackOrForward(1);
break;
case QWebPage::Stop:
enabled = loader->isLoading();
break;
case QWebPage::Reload:
enabled = !loader->isLoading();
break;
#ifndef QT_NO_UNDOSTACK
case QWebPage::Undo:
case QWebPage::Redo:
break;
#endif // QT_NO_UNDOSTACK
case QWebPage::SelectAll: break;
case QWebPage::SetTextDirectionDefault:
case QWebPage::SetTextDirectionLeftToRight:
case QWebPage::SetTextDirectionRightToLeft:
enabled = editor->canEdit();
checked = false;
break;
default: {
const char* commandName = editorCommandForWebActions(action);
if (commandName) {
Editor::Command command = editor->command(commandName);
enabled = command.isEnabled();
if (enabled)
checked = command.state() != FalseTriState;
else
checked = false;
}
break;
}
}
a->setEnabled(enabled);
if (a->isCheckable())
a->setChecked(checked);
}
void QWebPagePrivate::updateNavigationActions()
{
updateAction(QWebPage::Back);
updateAction(QWebPage::Forward);
updateAction(QWebPage::Stop);
updateAction(QWebPage::Reload);
}
void QWebPagePrivate::updateEditorActions()
{
updateAction(QWebPage::Cut);
updateAction(QWebPage::Copy);
updateAction(QWebPage::Paste);
updateAction(QWebPage::MoveToNextChar);
updateAction(QWebPage::MoveToPreviousChar);
updateAction(QWebPage::MoveToNextWord);
updateAction(QWebPage::MoveToPreviousWord);
updateAction(QWebPage::MoveToNextLine);
updateAction(QWebPage::MoveToPreviousLine);
updateAction(QWebPage::MoveToStartOfLine);
updateAction(QWebPage::MoveToEndOfLine);
updateAction(QWebPage::MoveToStartOfBlock);
updateAction(QWebPage::MoveToEndOfBlock);
updateAction(QWebPage::MoveToStartOfDocument);
updateAction(QWebPage::MoveToEndOfDocument);
updateAction(QWebPage::SelectNextChar);
updateAction(QWebPage::SelectPreviousChar);
updateAction(QWebPage::SelectNextWord);
updateAction(QWebPage::SelectPreviousWord);
updateAction(QWebPage::SelectNextLine);
updateAction(QWebPage::SelectPreviousLine);
updateAction(QWebPage::SelectStartOfLine);
updateAction(QWebPage::SelectEndOfLine);
updateAction(QWebPage::SelectStartOfBlock);
updateAction(QWebPage::SelectEndOfBlock);
updateAction(QWebPage::SelectStartOfDocument);
updateAction(QWebPage::SelectEndOfDocument);
updateAction(QWebPage::DeleteStartOfWord);
updateAction(QWebPage::DeleteEndOfWord);
updateAction(QWebPage::SetTextDirectionDefault);
updateAction(QWebPage::SetTextDirectionLeftToRight);
updateAction(QWebPage::SetTextDirectionRightToLeft);
updateAction(QWebPage::ToggleBold);
updateAction(QWebPage::ToggleItalic);
updateAction(QWebPage::ToggleUnderline);
updateAction(QWebPage::InsertParagraphSeparator);
updateAction(QWebPage::InsertLineSeparator);
updateAction(QWebPage::PasteAndMatchStyle);
updateAction(QWebPage::RemoveFormat);
updateAction(QWebPage::ToggleStrikethrough);
updateAction(QWebPage::ToggleSubscript);
updateAction(QWebPage::ToggleSuperscript);
updateAction(QWebPage::InsertUnorderedList);
updateAction(QWebPage::InsertOrderedList);
updateAction(QWebPage::Indent);
updateAction(QWebPage::Outdent);
updateAction(QWebPage::AlignCenter);
updateAction(QWebPage::AlignJustified);
updateAction(QWebPage::AlignLeft);
updateAction(QWebPage::AlignRight);
}
void QWebPagePrivate::timerEvent(QTimerEvent *ev)
{
int timerId = ev->timerId();
if (timerId == tripleClickTimer.timerId())
tripleClickTimer.stop();
else
q->QObject::timerEvent(ev);
}
void QWebPagePrivate::mouseMoveEvent(QMouseEvent *ev)
{
WebCore::Frame* frame = QWebFramePrivate::core(mainFrame);
if (!frame->view())
return;
bool accepted = frame->eventHandler()->mouseMoved(PlatformMouseEvent(ev, 0));
ev->setAccepted(accepted);
}
void QWebPagePrivate::mousePressEvent(QMouseEvent *ev)
{
WebCore::Frame* frame = QWebFramePrivate::core(mainFrame);
if (!frame->view())
return;
if (tripleClickTimer.isActive()
&& (ev->pos() - tripleClick).manhattanLength()
< QApplication::startDragDistance()) {
mouseTripleClickEvent(ev);
return;
}
bool accepted = false;
PlatformMouseEvent mev(ev, 1);
if (mev.button() != NoButton)
accepted = frame->eventHandler()->handleMousePressEvent(mev);
ev->setAccepted(accepted);
}
void QWebPagePrivate::mouseDoubleClickEvent(QMouseEvent *ev)
{
WebCore::Frame* frame = QWebFramePrivate::core(mainFrame);
if (!frame->view())
return;
bool accepted = false;
PlatformMouseEvent mev(ev, 2);
if (mev.button() != NoButton)
accepted = frame->eventHandler()->handleMousePressEvent(mev);
ev->setAccepted(accepted);
tripleClickTimer.start(QApplication::doubleClickInterval(), q);
tripleClick = ev->pos();
}
void QWebPagePrivate::mouseTripleClickEvent(QMouseEvent *ev)
{
WebCore::Frame* frame = QWebFramePrivate::core(mainFrame);
if (!frame->view())
return;
bool accepted = false;
PlatformMouseEvent mev(ev, 3);
if (mev.button() != NoButton)
accepted = frame->eventHandler()->handleMousePressEvent(mev);
ev->setAccepted(accepted);
}
void QWebPagePrivate::mouseReleaseEvent(QMouseEvent *ev)
{
WebCore::Frame* frame = QWebFramePrivate::core(mainFrame);
if (!frame->view())
return;
bool accepted = false;
PlatformMouseEvent mev(ev, 0);
if (mev.button() != NoButton)
accepted = frame->eventHandler()->handleMouseReleaseEvent(mev);
ev->setAccepted(accepted);
#ifndef QT_NO_CLIPBOARD
if (QApplication::clipboard()->supportsSelection()) {
bool oldSelectionMode = Pasteboard::generalPasteboard()->isSelectionMode();
Pasteboard::generalPasteboard()->setSelectionMode(true);
WebCore::Frame* focusFrame = page->focusController()->focusedOrMainFrame();
if (ev->button() == Qt::LeftButton) {
if(focusFrame && (focusFrame->editor()->canCopy() || focusFrame->editor()->canDHTMLCopy())) {
focusFrame->editor()->copy();
ev->setAccepted(true);
}
} else if (ev->button() == Qt::MidButton) {
if(focusFrame && (focusFrame->editor()->canPaste() || focusFrame->editor()->canDHTMLPaste())) {
focusFrame->editor()->paste();
ev->setAccepted(true);
}
}
Pasteboard::generalPasteboard()->setSelectionMode(oldSelectionMode);
}
#endif
}
#ifndef QT_NO_CONTEXTMENU
void QWebPagePrivate::contextMenuEvent(QContextMenuEvent *ev)
{
QMenu *menu = q->createStandardContextMenu();
if (menu) {
menu->exec(ev->globalPos());
delete menu;
}
}
#endif // QT_NO_CONTEXTMENU
QMenu *QWebPage::createStandardContextMenu()
{
#ifndef QT_NO_CONTEXTMENU
QMenu *menu = d->currentContextMenu;
d->currentContextMenu = 0;
return menu;
#else
return 0;
#endif
}
#ifndef QT_NO_WHEELEVENT
void QWebPagePrivate::wheelEvent(QWheelEvent *ev)
{
WebCore::Frame* frame = QWebFramePrivate::core(mainFrame);
if (!frame->view())
return;
WebCore::PlatformWheelEvent pev(ev);
bool accepted = frame->eventHandler()->handleWheelEvent(pev);
ev->setAccepted(accepted);
}
#endif // QT_NO_WHEELEVENT
#ifndef QT_NO_SHORTCUT
QWebPage::WebAction QWebPagePrivate::editorActionForKeyEvent(QKeyEvent* event)
{
static struct {
QKeySequence::StandardKey standardKey;
QWebPage::WebAction action;
} editorActions[] = {
{ QKeySequence::Cut, QWebPage::Cut },
{ QKeySequence::Copy, QWebPage::Copy },
{ QKeySequence::Paste, QWebPage::Paste },
{ QKeySequence::Undo, QWebPage::Undo },
{ QKeySequence::Redo, QWebPage::Redo },
{ QKeySequence::MoveToNextChar, QWebPage::MoveToNextChar },
{ QKeySequence::MoveToPreviousChar, QWebPage::MoveToPreviousChar },
{ QKeySequence::MoveToNextWord, QWebPage::MoveToNextWord },
{ QKeySequence::MoveToPreviousWord, QWebPage::MoveToPreviousWord },
{ QKeySequence::MoveToNextLine, QWebPage::MoveToNextLine },
{ QKeySequence::MoveToPreviousLine, QWebPage::MoveToPreviousLine },
{ QKeySequence::MoveToStartOfLine, QWebPage::MoveToStartOfLine },
{ QKeySequence::MoveToEndOfLine, QWebPage::MoveToEndOfLine },
{ QKeySequence::MoveToStartOfBlock, QWebPage::MoveToStartOfBlock },
{ QKeySequence::MoveToEndOfBlock, QWebPage::MoveToEndOfBlock },
{ QKeySequence::MoveToStartOfDocument, QWebPage::MoveToStartOfDocument },
{ QKeySequence::MoveToEndOfDocument, QWebPage::MoveToEndOfDocument },
{ QKeySequence::SelectNextChar, QWebPage::SelectNextChar },
{ QKeySequence::SelectPreviousChar, QWebPage::SelectPreviousChar },
{ QKeySequence::SelectNextWord, QWebPage::SelectNextWord },
{ QKeySequence::SelectPreviousWord, QWebPage::SelectPreviousWord },
{ QKeySequence::SelectNextLine, QWebPage::SelectNextLine },
{ QKeySequence::SelectPreviousLine, QWebPage::SelectPreviousLine },
{ QKeySequence::SelectStartOfLine, QWebPage::SelectStartOfLine },
{ QKeySequence::SelectEndOfLine, QWebPage::SelectEndOfLine },
{ QKeySequence::SelectStartOfBlock, QWebPage::SelectStartOfBlock },
{ QKeySequence::SelectEndOfBlock, QWebPage::SelectEndOfBlock },
{ QKeySequence::SelectStartOfDocument, QWebPage::SelectStartOfDocument },
{ QKeySequence::SelectEndOfDocument, QWebPage::SelectEndOfDocument },
{ QKeySequence::DeleteStartOfWord, QWebPage::DeleteStartOfWord },
{ QKeySequence::DeleteEndOfWord, QWebPage::DeleteEndOfWord },
#if QT_VERSION >= 0x040500
{ QKeySequence::InsertParagraphSeparator, QWebPage::InsertParagraphSeparator },
{ QKeySequence::InsertLineSeparator, QWebPage::InsertLineSeparator },
#endif
{ QKeySequence::SelectAll, QWebPage::SelectAll },
{ QKeySequence::UnknownKey, QWebPage::NoWebAction }
};
for (int i = 0; editorActions[i].standardKey != QKeySequence::UnknownKey; ++i)
if (event == editorActions[i].standardKey)
return editorActions[i].action;
return QWebPage::NoWebAction;
}
#endif // QT_NO_SHORTCUT
void QWebPagePrivate::keyPressEvent(QKeyEvent *ev)
{
bool handled = false;
WebCore::Frame* frame = page->focusController()->focusedOrMainFrame();
WebCore::Editor* editor = frame->editor();
if (!handled)
handled = frame->eventHandler()->keyEvent(ev);
if (!handled) {
handled = true;
QFont defaultFont;
if (view)
defaultFont = view->font();
QFontMetrics fm(defaultFont);
int fontHeight = fm.height();
if (!handleScrolling(ev, frame)) {
switch (ev->key()) {
case Qt::Key_Back:
q->triggerAction(QWebPage::Back);
break;
case Qt::Key_Forward:
q->triggerAction(QWebPage::Forward);
break;
case Qt::Key_Stop:
q->triggerAction(QWebPage::Stop);
break;
case Qt::Key_Refresh:
q->triggerAction(QWebPage::Reload);
break;
case Qt::Key_Backspace:
if (ev->modifiers() == Qt::ShiftModifier)
q->triggerAction(QWebPage::Forward);
else
q->triggerAction(QWebPage::Back);
break;
default:
handled = false;
break;
}
}
}
ev->setAccepted(handled);
}
void QWebPagePrivate::keyReleaseEvent(QKeyEvent *ev)
{
if (ev->isAutoRepeat()) {
ev->setAccepted(true);
return;
}
WebCore::Frame* frame = page->focusController()->focusedOrMainFrame();
bool handled = frame->eventHandler()->keyEvent(ev);
ev->setAccepted(handled);
}
void QWebPagePrivate::focusInEvent(QFocusEvent *ev)
{
FocusController *focusController = page->focusController();
Frame *frame = focusController->focusedFrame();
focusController->setActive(true);
if (frame) {
focusController->setFocused(true);
} else {
focusController->setFocusedFrame(QWebFramePrivate::core(mainFrame));
}
}
void QWebPagePrivate::focusOutEvent(QFocusEvent *ev)
{
FocusController *focusController = page->focusController();
focusController->setActive(false);
focusController->setFocused(false);
}
void QWebPagePrivate::dragEnterEvent(QDragEnterEvent *ev)
{
#ifndef QT_NO_DRAGANDDROP
DragData dragData(ev->mimeData(), ev->pos(), QCursor::pos(),
dropActionToDragOp(ev->possibleActions()));
Qt::DropAction action = dragOpToDropAction(page->dragController()->dragEntered(&dragData));
ev->setDropAction(action);
if (action != Qt::IgnoreAction)
ev->accept();
#endif
}
void QWebPagePrivate::dragLeaveEvent(QDragLeaveEvent *ev)
{
#ifndef QT_NO_DRAGANDDROP
DragData dragData(0, IntPoint(), QCursor::pos(), DragOperationNone);
page->dragController()->dragExited(&dragData);
ev->accept();
#endif
}
void QWebPagePrivate::dragMoveEvent(QDragMoveEvent *ev)
{
#ifndef QT_NO_DRAGANDDROP
DragData dragData(ev->mimeData(), ev->pos(), QCursor::pos(),
dropActionToDragOp(ev->possibleActions()));
Qt::DropAction action = dragOpToDropAction(page->dragController()->dragUpdated(&dragData));
ev->setDropAction(action);
if (action != Qt::IgnoreAction)
ev->accept();
#endif
}
void QWebPagePrivate::dropEvent(QDropEvent *ev)
{
#ifndef QT_NO_DRAGANDDROP
DragData dragData(ev->mimeData(), ev->pos(), QCursor::pos(),
dropActionToDragOp(ev->possibleActions()));
Qt::DropAction action = dragOpToDropAction(page->dragController()->performDrag(&dragData));
if (action != Qt::IgnoreAction)
ev->accept();
#endif
}
void QWebPagePrivate::leaveEvent(QEvent *ev)
{
QMouseEvent fakeEvent(QEvent::MouseMove, QCursor::pos(), Qt::NoButton, Qt::NoButton, Qt::NoModifier);
mouseMoveEvent(&fakeEvent);
}
void QWebPage::setPalette(const QPalette &pal)
{
d->palette = pal;
if (!d->mainFrame || !d->mainFrame->d->frame->view())
return;
QBrush brush = pal.brush(QPalette::Base);
QColor backgroundColor = brush.style() == Qt::SolidPattern ? brush.color() : QColor();
QWebFramePrivate::core(d->mainFrame)->view()->updateBackgroundRecursively(backgroundColor, !backgroundColor.alpha());
}
QPalette QWebPage::palette() const
{
return d->palette;
}
void QWebPagePrivate::inputMethodEvent(QInputMethodEvent *ev)
{
WebCore::Frame *frame = page->focusController()->focusedOrMainFrame();
WebCore::Editor *editor = frame->editor();
if (!editor->canEdit()) {
ev->ignore();
return;
}
if (!ev->commitString().isEmpty())
editor->confirmComposition(ev->commitString());
else {
QString preedit = ev->preeditString();
Vector<CompositionUnderline> underlines;
underlines.append(CompositionUnderline(0, preedit.length(), Color(0,0,0), false));
editor->setComposition(preedit, underlines, preedit.length(), 0);
}
ev->accept();
}
void QWebPagePrivate::shortcutOverrideEvent(QKeyEvent* event)
{
WebCore::Frame* frame = page->focusController()->focusedOrMainFrame();
WebCore::Editor* editor = frame->editor();
if (editor->canEdit()) {
if (event->modifiers() == Qt::NoModifier
|| event->modifiers() == Qt::ShiftModifier
|| event->modifiers() == Qt::KeypadModifier) {
if (event->key() < Qt::Key_Escape) {
event->accept();
} else {
switch (event->key()) {
case Qt::Key_Return:
case Qt::Key_Enter:
case Qt::Key_Delete:
case Qt::Key_Home:
case Qt::Key_End:
case Qt::Key_Backspace:
case Qt::Key_Left:
case Qt::Key_Right:
case Qt::Key_Up:
case Qt::Key_Down:
case Qt::Key_Tab:
event->accept();
default:
break;
}
}
}
#ifndef QT_NO_SHORTCUT
else if (editorActionForKeyEvent(event) != QWebPage::NoWebAction) {
event->accept();
}
#endif
}
}
bool QWebPagePrivate::handleScrolling(QKeyEvent *ev, Frame *frame)
{
ScrollDirection direction;
ScrollGranularity granularity;
#ifndef QT_NO_SHORTCUT
if (ev == QKeySequence::MoveToNextPage
|| (ev->key() == Qt::Key_Space && !(ev->modifiers() & Qt::ShiftModifier))) {
granularity = ScrollByPage;
direction = ScrollDown;
} else if (ev == QKeySequence::MoveToPreviousPage
|| (ev->key() == Qt::Key_Space) && (ev->modifiers() & Qt::ShiftModifier)) {
granularity = ScrollByPage;
direction = ScrollUp;
} else
#endif // QT_NO_SHORTCUT
if (ev->key() == Qt::Key_Up && ev->modifiers() & Qt::ControlModifier
|| ev->key() == Qt::Key_Home) {
granularity = ScrollByDocument;
direction = ScrollUp;
} else if (ev->key() == Qt::Key_Down && ev->modifiers() & Qt::ControlModifier
|| ev->key() == Qt::Key_End) {
granularity = ScrollByDocument;
direction = ScrollDown;
} else {
switch (ev->key()) {
case Qt::Key_Up:
granularity = ScrollByLine;
direction = ScrollUp;
break;
case Qt::Key_Down:
granularity = ScrollByLine;
direction = ScrollDown;
break;
case Qt::Key_Left:
granularity = ScrollByLine;
direction = ScrollLeft;
break;
case Qt::Key_Right:
granularity = ScrollByLine;
direction = ScrollRight;
break;
default:
return false;
}
}
return frame->eventHandler()->scrollRecursively(direction, granularity);
}
QVariant QWebPage::inputMethodQuery(Qt::InputMethodQuery property) const
{
switch(property) {
case Qt::ImMicroFocus: {
Frame *frame = d->page->focusController()->focusedFrame();
if (frame) {
return QVariant(frame->selection()->absoluteCaretBounds());
}
return QVariant();
}
case Qt::ImFont: {
QWebView *webView = qobject_cast<QWebView *>(d->view);
if (webView)
return QVariant(webView->font());
return QVariant();
}
case Qt::ImCursorPosition: {
Frame *frame = d->page->focusController()->focusedFrame();
if (frame) {
VisibleSelection selection = frame->selection()->selection();
if (selection.isCaret()) {
return QVariant(selection.start().deprecatedEditingOffset());
}
}
return QVariant();
}
case Qt::ImSurroundingText: {
Frame *frame = d->page->focusController()->focusedFrame();
if (frame) {
Document *document = frame->document();
if (document->focusedNode()) {
return QVariant(document->focusedNode()->nodeValue());
}
}
return QVariant();
}
case Qt::ImCurrentSelection:
return QVariant(selectedText());
default:
return QVariant();
}
}
QWebPage::QWebPage(QObject *parent)
: QObject(parent)
, d(new QWebPagePrivate(this))
{
setView(qobject_cast<QWidget *>(parent));
connect(this, SIGNAL(loadProgress(int)), this, SLOT(_q_onLoadProgressChanged(int)));
#ifndef NDEBUG
connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()), this, SLOT(_q_cleanupLeakMessages()));
#endif
}
QWebPage::~QWebPage()
{
FrameLoader *loader = d->mainFrame->d->frame->loader();
if (loader)
loader->detachFromParent();
delete d;
}
QWebFrame *QWebPage::mainFrame() const
{
d->createMainFrame();
return d->mainFrame;
}
QWebFrame *QWebPage::currentFrame() const
{
return static_cast<WebCore::FrameLoaderClientQt *>(d->page->focusController()->focusedOrMainFrame()->loader()->client())->webFrame();
}
QWebFrame* QWebPage::frameAt(const QPoint& pos) const
{
QWebFrame* webFrame = mainFrame();
if (!webFrame->geometry().contains(pos))
return 0;
QWebHitTestResult hitTestResult = webFrame->hitTestContent(pos);
return hitTestResult.frame();
}
QWebHistory *QWebPage::history() const
{
return &d->history;
}
void QWebPage::setView(QWidget *view)
{
d->view = view;
setViewportSize(view ? view->size() : QSize(0, 0));
}
QWidget *QWebPage::view() const
{
return d->view;
}
void QWebPage::javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID)
{
Q_UNUSED(message)
Q_UNUSED(lineNumber)
Q_UNUSED(sourceID)
}
void QWebPage::javaScriptAlert(QWebFrame *frame, const QString& msg)
{
#ifndef QT_NO_MESSAGEBOX
QMessageBox::information(d->view, tr("JavaScript Alert - %1").arg(mainFrame()->url().host()), msg, QMessageBox::Ok);
#endif
}
bool QWebPage::javaScriptConfirm(QWebFrame *frame, const QString& msg)
{
#ifdef QT_NO_MESSAGEBOX
return true;
#else
return QMessageBox::Yes == QMessageBox::information(d->view, tr("JavaScript Confirm - %1").arg(mainFrame()->url().host()), msg, QMessageBox::Yes, QMessageBox::No);
#endif
}
bool QWebPage::javaScriptPrompt(QWebFrame *frame, const QString& msg, const QString& defaultValue, QString* result)
{
bool ok = false;
#ifndef QT_NO_INPUTDIALOG
QString x = QInputDialog::getText(d->view, tr("JavaScript Prompt - %1").arg(mainFrame()->url().host()), msg, QLineEdit::Normal, defaultValue, &ok);
if (ok && result) {
*result = x;
}
#endif
return ok;
}
QWebPage *QWebPage::createWindow(WebWindowType type)
{
QWebView *webView = qobject_cast<QWebView *>(d->view);
if (webView) {
QWebView *newView = webView->createWindow(type);
if (newView)
return newView->page();
}
return 0;
}
QObject *QWebPage::createPlugin(const QString &classid, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues)
{
Q_UNUSED(classid)
Q_UNUSED(url)
Q_UNUSED(paramNames)
Q_UNUSED(paramValues)
return 0;
}
static WebCore::FrameLoadRequest frameLoadRequest(const QUrl &url, WebCore::Frame *frame)
{
WebCore::ResourceRequest rr(url, frame->loader()->outgoingReferrer());
return WebCore::FrameLoadRequest(rr);
}
static void openNewWindow(const QUrl& url, WebCore::Frame* frame)
{
if (Page* oldPage = frame->page()) {
WindowFeatures features;
if (Page* newPage = oldPage->chrome()->createWindow(frame,
frameLoadRequest(url, frame), features))
newPage->chrome()->show();
}
}
void QWebPage::triggerAction(WebAction action, bool checked)
{
WebCore::Frame *frame = d->page->focusController()->focusedOrMainFrame();
if (!frame)
return;
WebCore::Editor *editor = frame->editor();
const char *command = 0;
switch (action) {
case OpenLink:
if (QWebFrame *targetFrame = d->hitTestResult.linkTargetFrame()) {
WTF::RefPtr<WebCore::Frame> wcFrame = targetFrame->d->frame;
targetFrame->d->frame->loader()->loadFrameRequest(frameLoadRequest(d->hitTestResult.linkUrl(), wcFrame.get()),
false, false, 0,
0);
break;
}
case OpenLinkInNewWindow:
openNewWindow(d->hitTestResult.linkUrl(), frame);
break;
case OpenFrameInNewWindow: {
KURL url = frame->loader()->documentLoader()->unreachableURL();
if (url.isEmpty())
url = frame->loader()->documentLoader()->url();
openNewWindow(url, frame);
break;
}
case CopyLinkToClipboard: {
#if defined(Q_WS_X11)
bool oldSelectionMode = Pasteboard::generalPasteboard()->isSelectionMode();
Pasteboard::generalPasteboard()->setSelectionMode(true);
editor->copyURL(d->hitTestResult.linkUrl(), d->hitTestResult.linkText());
Pasteboard::generalPasteboard()->setSelectionMode(oldSelectionMode);
#endif
editor->copyURL(d->hitTestResult.linkUrl(), d->hitTestResult.linkText());
break;
}
case OpenImageInNewWindow:
openNewWindow(d->hitTestResult.imageUrl(), frame);
break;
case DownloadImageToDisk:
frame->loader()->client()->startDownload(WebCore::ResourceRequest(d->hitTestResult.imageUrl(), frame->loader()->outgoingReferrer()));
break;
case DownloadLinkToDisk:
frame->loader()->client()->startDownload(WebCore::ResourceRequest(d->hitTestResult.linkUrl(), frame->loader()->outgoingReferrer()));
break;
#ifndef QT_NO_CLIPBOARD
case CopyImageToClipboard:
QApplication::clipboard()->setPixmap(d->hitTestResult.pixmap());
break;
#endif
case Back:
d->page->goBack();
break;
case Forward:
d->page->goForward();
break;
case Stop:
mainFrame()->d->frame->loader()->stopForUserCancel();
break;
case Reload:
mainFrame()->d->frame->loader()->reload();
break;
case SetTextDirectionDefault:
editor->setBaseWritingDirection(NaturalWritingDirection);
break;
case SetTextDirectionLeftToRight:
editor->setBaseWritingDirection(LeftToRightWritingDirection);
break;
case SetTextDirectionRightToLeft:
editor->setBaseWritingDirection(RightToLeftWritingDirection);
break;
case InspectElement:
if (!d->hitTestResult.isNull())
d->page->inspectorController()->inspect(d->hitTestResult.d->innerNonSharedNode.get());
else
d->page->inspectorController()->show();
break;
default:
command = QWebPagePrivate::editorCommandForWebActions(action);
break;
}
if (command)
editor->command(command).execute();
}
QSize QWebPage::viewportSize() const
{
if (d->mainFrame && d->mainFrame->d->frame->view())
return d->mainFrame->d->frame->view()->frameRect().size();
return d->viewportSize;
}
void QWebPage::setViewportSize(const QSize &size) const
{
d->viewportSize = size;
QWebFrame *frame = mainFrame();
if (frame->d->frame && frame->d->frame->view()) {
WebCore::FrameView* view = frame->d->frame->view();
view->setFrameRect(QRect(QPoint(0, 0), size));
view->forceLayout();
view->adjustViewSize();
}
}
QSize QWebPage::fixedContentsSize() const
{
QWebFrame* frame = d->mainFrame;
if (frame) {
WebCore::FrameView* view = frame->d->frame->view();
if (view && view->useFixedLayout()) {
return d->mainFrame->d->frame->view()->fixedLayoutSize();
}
}
return d->fixedLayoutSize;
}
void QWebPage::setFixedContentsSize(const QSize &size) const
{
d->fixedLayoutSize = size;
QWebFrame *frame = mainFrame();
if (frame->d->frame && frame->d->frame->view()) {
WebCore::FrameView* view = frame->d->frame->view();
if (size.isValid()) {
view->setUseFixedLayout(true);
view->setFixedLayoutSize(size);
view->forceLayout();
} else if (view->useFixedLayout()) {
view->setUseFixedLayout(false);
view->forceLayout();
}
}
}
#if QT_VERSION >= 0x040400
bool QWebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, QWebPage::NavigationType type)
#else
bool QWebPage::acceptNavigationRequest(QWebFrame *frame, const QWebNetworkRequest &request, QWebPage::NavigationType type)
#endif
{
if (type == NavigationTypeLinkClicked) {
switch (d->linkPolicy) {
case DontDelegateLinks:
return true;
case DelegateExternalLinks:
if (WebCore::SecurityOrigin::shouldTreatURLSchemeAsLocal(request.url().scheme()))
return true;
emit linkClicked(request.url());
return false;
case DelegateAllLinks:
emit linkClicked(request.url());
return false;
}
}
return true;
}
QString QWebPage::selectedText() const
{
return d->page->focusController()->focusedOrMainFrame()->selectedText();
}
QAction *QWebPage::action(WebAction action) const
{
if (action == QWebPage::NoWebAction) return 0;
if (d->actions[action])
return d->actions[action];
QString text;
QIcon icon;
QStyle *style = view() ? view()->style() : qApp->style();
bool checkable = false;
switch (action) {
case OpenLink:
text = contextMenuItemTagOpenLink();
break;
case OpenLinkInNewWindow:
text = contextMenuItemTagOpenLinkInNewWindow();
break;
case OpenFrameInNewWindow:
text = contextMenuItemTagOpenFrameInNewWindow();
break;
case DownloadLinkToDisk:
text = contextMenuItemTagDownloadLinkToDisk();
break;
case CopyLinkToClipboard:
text = contextMenuItemTagCopyLinkToClipboard();
break;
case OpenImageInNewWindow:
text = contextMenuItemTagOpenImageInNewWindow();
break;
case DownloadImageToDisk:
text = contextMenuItemTagDownloadImageToDisk();
break;
case CopyImageToClipboard:
text = contextMenuItemTagCopyImageToClipboard();
break;
case Back:
text = contextMenuItemTagGoBack();
#if QT_VERSION >= 0x040400
icon = style->standardIcon(QStyle::SP_ArrowBack);
#endif
break;
case Forward:
text = contextMenuItemTagGoForward();
#if QT_VERSION >= 0x040400
icon = style->standardIcon(QStyle::SP_ArrowForward);
#endif
break;
case Stop:
text = contextMenuItemTagStop();
#if QT_VERSION >= 0x040400
icon = style->standardIcon(QStyle::SP_BrowserStop);
#endif
break;
case Reload:
text = contextMenuItemTagReload();
#if QT_VERSION >= 0x040400
icon = style->standardIcon(QStyle::SP_BrowserReload);
#endif
break;
case Cut:
text = contextMenuItemTagCut();
break;
case Copy:
text = contextMenuItemTagCopy();
break;
case Paste:
text = contextMenuItemTagPaste();
break;
#ifndef QT_NO_UNDOSTACK
case Undo: {
QAction *a = undoStack()->createUndoAction(d->q);
d->actions[action] = a;
return a;
}
case Redo: {
QAction *a = undoStack()->createRedoAction(d->q);
d->actions[action] = a;
return a;
}
#endif // QT_NO_UNDOSTACK
case MoveToNextChar:
text = tr("Move the cursor to the next character");
break;
case MoveToPreviousChar:
text = tr("Move the cursor to the previous character");
break;
case MoveToNextWord:
text = tr("Move the cursor to the next word");
break;
case MoveToPreviousWord:
text = tr("Move the cursor to the previous word");
break;
case MoveToNextLine:
text = tr("Move the cursor to the next line");
break;
case MoveToPreviousLine:
text = tr("Move the cursor to the previous line");
break;
case MoveToStartOfLine:
text = tr("Move the cursor to the start of the line");
break;
case MoveToEndOfLine:
text = tr("Move the cursor to the end of the line");
break;
case MoveToStartOfBlock:
text = tr("Move the cursor to the start of the block");
break;
case MoveToEndOfBlock:
text = tr("Move the cursor to the end of the block");
break;
case MoveToStartOfDocument:
text = tr("Move the cursor to the start of the document");
break;
case MoveToEndOfDocument:
text = tr("Move the cursor to the end of the document");
break;
case SelectAll:
text = tr("Select all");
break;
case SelectNextChar:
text = tr("Select to the next character");
break;
case SelectPreviousChar:
text = tr("Select to the previous character");
break;
case SelectNextWord:
text = tr("Select to the next word");
break;
case SelectPreviousWord:
text = tr("Select to the previous word");
break;
case SelectNextLine:
text = tr("Select to the next line");
break;
case SelectPreviousLine:
text = tr("Select to the previous line");
break;
case SelectStartOfLine:
text = tr("Select to the start of the line");
break;
case SelectEndOfLine:
text = tr("Select to the end of the line");
break;
case SelectStartOfBlock:
text = tr("Select to the start of the block");
break;
case SelectEndOfBlock:
text = tr("Select to the end of the block");
break;
case SelectStartOfDocument:
text = tr("Select to the start of the document");
break;
case SelectEndOfDocument:
text = tr("Select to the end of the document");
break;
case DeleteStartOfWord:
text = tr("Delete to the start of the word");
break;
case DeleteEndOfWord:
text = tr("Delete to the end of the word");
break;
case SetTextDirectionDefault:
text = contextMenuItemTagDefaultDirection();
break;
case SetTextDirectionLeftToRight:
text = contextMenuItemTagLeftToRight();
checkable = true;
break;
case SetTextDirectionRightToLeft:
text = contextMenuItemTagRightToLeft();
checkable = true;
break;
case ToggleBold:
text = contextMenuItemTagBold();
checkable = true;
break;
case ToggleItalic:
text = contextMenuItemTagItalic();
checkable = true;
break;
case ToggleUnderline:
text = contextMenuItemTagUnderline();
checkable = true;
break;
case InspectElement:
text = contextMenuItemTagInspectElement();
break;
case InsertParagraphSeparator:
text = tr("Insert a new paragraph");
break;
case InsertLineSeparator:
text = tr("Insert a new line");
break;
case PasteAndMatchStyle:
text = tr("Paste and Match Style");
break;
case RemoveFormat:
text = tr("Remove formatting");
break;
case ToggleStrikethrough:
text = tr("Strikethrough");
checkable = true;
break;
case ToggleSubscript:
text = tr("Subscript");
checkable = true;
break;
case ToggleSuperscript:
text = tr("Superscript");
checkable = true;
break;
case InsertUnorderedList:
text = tr("Insert Bulleted List");
checkable = true;
break;
case InsertOrderedList:
text = tr("Insert Numbered List");
checkable = true;
break;
case Indent:
text = tr("Indent");
break;
case Outdent:
text = tr("Outdent");
break;
case AlignCenter:
text = tr("Center");
break;
case AlignJustified:
text = tr("Justify");
break;
case AlignLeft:
text = tr("Align Left");
break;
case AlignRight:
text = tr("Align Right");
break;
case NoWebAction:
return 0;
}
if (text.isEmpty())
return 0;
QAction *a = new QAction(d->q);
a->setText(text);
a->setData(action);
a->setCheckable(checkable);
a->setIcon(icon);
connect(a, SIGNAL(triggered(bool)),
this, SLOT(_q_webActionTriggered(bool)));
d->actions[action] = a;
d->updateAction(action);
return a;
}
bool QWebPage::isModified() const
{
#ifdef QT_NO_UNDOSTACK
return false;
#else
if (!d->undoStack)
return false;
return d->undoStack->canUndo();
#endif // QT_NO_UNDOSTACK
}
#ifndef QT_NO_UNDOSTACK
QUndoStack *QWebPage::undoStack() const
{
if (!d->undoStack)
d->undoStack = new QUndoStack(const_cast<QWebPage *>(this));
return d->undoStack;
}
#endif // QT_NO_UNDOSTACK
bool QWebPage::event(QEvent *ev)
{
switch (ev->type()) {
case QEvent::Timer:
d->timerEvent(static_cast<QTimerEvent*>(ev));
break;
case QEvent::MouseMove:
d->mouseMoveEvent(static_cast<QMouseEvent*>(ev));
break;
case QEvent::MouseButtonPress:
d->mousePressEvent(static_cast<QMouseEvent*>(ev));
break;
case QEvent::MouseButtonDblClick:
d->mouseDoubleClickEvent(static_cast<QMouseEvent*>(ev));
break;
case QEvent::MouseButtonRelease:
d->mouseReleaseEvent(static_cast<QMouseEvent*>(ev));
break;
#ifndef QT_NO_CONTEXTMENU
case QEvent::ContextMenu:
d->contextMenuEvent(static_cast<QContextMenuEvent*>(ev));
break;
#endif
#ifndef QT_NO_WHEELEVENT
case QEvent::Wheel:
d->wheelEvent(static_cast<QWheelEvent*>(ev));
break;
#endif
case QEvent::KeyPress:
d->keyPressEvent(static_cast<QKeyEvent*>(ev));
break;
case QEvent::KeyRelease:
d->keyReleaseEvent(static_cast<QKeyEvent*>(ev));
break;
case QEvent::FocusIn:
d->focusInEvent(static_cast<QFocusEvent*>(ev));
break;
case QEvent::FocusOut:
d->focusOutEvent(static_cast<QFocusEvent*>(ev));
break;
#ifndef QT_NO_DRAGANDDROP
case QEvent::DragEnter:
d->dragEnterEvent(static_cast<QDragEnterEvent*>(ev));
break;
case QEvent::DragLeave:
d->dragLeaveEvent(static_cast<QDragLeaveEvent*>(ev));
break;
case QEvent::DragMove:
d->dragMoveEvent(static_cast<QDragMoveEvent*>(ev));
break;
case QEvent::Drop:
d->dropEvent(static_cast<QDropEvent*>(ev));
break;
#endif
case QEvent::InputMethod:
d->inputMethodEvent(static_cast<QInputMethodEvent*>(ev));
case QEvent::ShortcutOverride:
d->shortcutOverrideEvent(static_cast<QKeyEvent*>(ev));
break;
case QEvent::Leave:
d->leaveEvent(ev);
break;
default:
return QObject::event(ev);
}
return true;
}
bool QWebPage::focusNextPrevChild(bool next)
{
QKeyEvent ev(QEvent::KeyPress, Qt::Key_Tab, Qt::KeyboardModifiers(next ? Qt::NoModifier : Qt::ShiftModifier));
d->keyPressEvent(&ev);
bool hasFocusedNode = false;
Frame *frame = d->page->focusController()->focusedFrame();
if (frame) {
Document *document = frame->document();
hasFocusedNode = document && document->focusedNode();
}
return hasFocusedNode;
}
void QWebPage::setContentEditable(bool editable)
{
if (d->editable != editable) {
d->editable = editable;
d->page->setTabKeyCyclesThroughElements(!editable);
if (d->mainFrame) {
WebCore::Frame* frame = d->mainFrame->d->frame;
if (editable) {
frame->applyEditingStyleToBodyElement();
} else {
frame->removeEditingStyleFromBodyElement();
}
}
d->updateEditorActions();
}
}
bool QWebPage::isContentEditable() const
{
return d->editable;
}
void QWebPage::setForwardUnsupportedContent(bool forward)
{
d->forwardUnsupportedContent = forward;
}
bool QWebPage::forwardUnsupportedContent() const
{
return d->forwardUnsupportedContent;
}
void QWebPage::setLinkDelegationPolicy(LinkDelegationPolicy policy)
{
d->linkPolicy = policy;
}
QWebPage::LinkDelegationPolicy QWebPage::linkDelegationPolicy() const
{
return d->linkPolicy;
}
#ifndef QT_NO_CONTEXTMENU
bool QWebPage::swallowContextMenuEvent(QContextMenuEvent *event)
{
d->page->contextMenuController()->clearContextMenu();
if (QWebFrame* webFrame = frameAt(event->pos())) {
Frame* frame = QWebFramePrivate::core(webFrame);
if (Scrollbar* scrollbar = frame->view()->scrollbarAtPoint(PlatformMouseEvent(event, 1).pos())) {
return scrollbar->contextMenu(PlatformMouseEvent(event, 1));
}
}
WebCore::Frame* focusedFrame = d->page->focusController()->focusedOrMainFrame();
focusedFrame->eventHandler()->sendContextMenuEvent(PlatformMouseEvent(event, 1));
ContextMenu *menu = d->page->contextMenuController()->contextMenu();
return !menu;
}
#endif // QT_NO_CONTEXTMENU
void QWebPage::updatePositionDependentActions(const QPoint &pos)
{
QBitArray originallyEnabledWebActions(QWebPage::WebActionCount);
for (int i = ContextMenuItemTagNoAction; i < ContextMenuItemBaseApplicationTag; ++i) {
QWebPage::WebAction action = webActionForContextMenuAction(WebCore::ContextMenuAction(i));
if (QAction *a = this->action(action)) {
originallyEnabledWebActions.setBit(action, a->isEnabled());
a->setEnabled(false);
}
}
WebCore::Frame* focusedFrame = d->page->focusController()->focusedOrMainFrame();
HitTestResult result = focusedFrame->eventHandler()->hitTestResultAtPoint(focusedFrame->view()->windowToContents(pos), false);
if (result.scrollbar())
d->hitTestResult = QWebHitTestResult();
else
d->hitTestResult = QWebHitTestResult(new QWebHitTestResultPrivate(result));
WebCore::ContextMenu menu(result);
menu.populate();
if (d->page->inspectorController()->enabled())
menu.addInspectElementItem();
QBitArray visitedWebActions(QWebPage::WebActionCount);
#ifndef QT_NO_CONTEXTMENU
delete d->currentContextMenu;
d->currentContextMenu = d->createContextMenu(&menu, menu.platformDescription(), &visitedWebActions);
#endif // QT_NO_CONTEXTMENU
originallyEnabledWebActions &= ~visitedWebActions; for (int i = 0; i < QWebPage::WebActionCount; ++i) {
if (originallyEnabledWebActions.at(i)) {
if (QAction *a = this->action(QWebPage::WebAction(i))) {
a->setEnabled(true);
}
}
}
}
bool QWebPage::extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output)
{
#ifndef QT_NO_FILEDIALOG
if (extension == ChooseMultipleFilesExtension) {
QStringList suggestedFiles = static_cast<const ChooseMultipleFilesExtensionOption*>(option)->suggestedFileNames;
QStringList names = QFileDialog::getOpenFileNames(d->view, QString::null);
static_cast<ChooseMultipleFilesExtensionReturn*>(output)->fileNames = names;
return true;
}
#endif
return false;
}
bool QWebPage::supportsExtension(Extension extension) const
{
#ifndef QT_NO_FILEDIALOG
return extension == ChooseMultipleFilesExtension;
#else
Q_UNUSED(extension);
return false;
#endif
}
bool QWebPage::findText(const QString &subString, FindFlags options)
{
::TextCaseSensitivity caseSensitivity = ::TextCaseInsensitive;
if (options & FindCaseSensitively)
caseSensitivity = ::TextCaseSensitive;
if (options & HighlightAllOccurrences) {
if (subString.isEmpty()) {
d->page->unmarkAllTextMatches();
return true;
} else {
return d->page->markAllMatchesForText(subString, caseSensitivity, true, 0);
}
} else {
::FindDirection direction = ::FindDirectionForward;
if (options & FindBackward)
direction = ::FindDirectionBackward;
const bool shouldWrap = options & FindWrapsAroundDocument;
return d->page->findString(subString, caseSensitivity, direction, shouldWrap);
}
}
QWebSettings *QWebPage::settings() const
{
return d->settings;
}
QString QWebPage::chooseFile(QWebFrame *parentFrame, const QString& suggestedFile)
{
#ifndef QT_NO_FILEDIALOG
return QFileDialog::getOpenFileName(d->view, QString::null, suggestedFile);
#else
return QString::null;
#endif
}
#if QT_VERSION < 0x040400 && !defined qdoc
void QWebPage::setNetworkInterface(QWebNetworkInterface *interface)
{
d->networkInterface = interface;
}
QWebNetworkInterface *QWebPage::networkInterface() const
{
if (d->networkInterface)
return d->networkInterface;
else
return QWebNetworkInterface::defaultInterface();
}
#ifndef QT_NO_NETWORKPROXY
void QWebPage::setNetworkProxy(const QNetworkProxy& proxy)
{
d->networkProxy = proxy;
}
QNetworkProxy QWebPage::networkProxy() const
{
return d->networkProxy;
}
#endif
#else
void QWebPage::setNetworkAccessManager(QNetworkAccessManager *manager)
{
if (manager == d->networkManager)
return;
if (d->networkManager && d->networkManager->parent() == this)
delete d->networkManager;
d->networkManager = manager;
}
QNetworkAccessManager *QWebPage::networkAccessManager() const
{
if (!d->networkManager) {
QWebPage *that = const_cast<QWebPage *>(this);
that->d->networkManager = new QNetworkAccessManager(that);
}
return d->networkManager;
}
#endif
void QWebPage::setPluginFactory(QWebPluginFactory *factory)
{
d->pluginFactory = factory;
}
QWebPluginFactory *QWebPage::pluginFactory() const
{
return d->pluginFactory;
}
QString QWebPage::userAgentForUrl(const QUrl& url) const
{
Q_UNUSED(url)
QString ua = QLatin1String("Mozilla/5.0 ("
#ifdef Q_WS_MAC
"Macintosh"
#elif defined Q_WS_QWS
"QtEmbedded"
#elif defined Q_WS_WIN
"Windows"
#elif defined Q_WS_X11
"X11"
#else
"Unknown"
#endif
"; "
"%1; "
#ifdef Q_OS_AIX
"AIX"
#elif defined Q_OS_WIN32
"%2"
#elif defined Q_OS_DARWIN
#ifdef __i386__ || __x86_64__
"Intel Mac OS X"
#else
"PPC Mac OS X"
#endif
#elif defined Q_OS_BSDI
"BSD"
#elif defined Q_OS_BSD4
"BSD Four"
#elif defined Q_OS_CYGWIN
"Cygwin"
#elif defined Q_OS_DGUX
"DG/UX"
#elif defined Q_OS_DYNIX
"DYNIX/ptx"
#elif defined Q_OS_FREEBSD
"FreeBSD"
#elif defined Q_OS_HPUX
"HP-UX"
#elif defined Q_OS_HURD
"GNU Hurd"
#elif defined Q_OS_IRIX
"SGI Irix"
#elif defined Q_OS_LINUX
"Linux"
#elif defined Q_OS_LYNX
"LynxOS"
#elif defined Q_OS_NETBSD
"NetBSD"
#elif defined Q_OS_OS2
"OS/2"
#elif defined Q_OS_OPENBSD
"OpenBSD"
#elif defined Q_OS_OS2EMX
"OS/2"
#elif defined Q_OS_OSF
"HP Tru64 UNIX"
#elif defined Q_OS_QNX6
"QNX RTP Six"
#elif defined Q_OS_QNX
"QNX"
#elif defined Q_OS_RELIANT
"Reliant UNIX"
#elif defined Q_OS_SCO
"SCO OpenServer"
#elif defined Q_OS_SOLARIS
"Sun Solaris"
#elif defined Q_OS_ULTRIX
"DEC Ultrix"
#elif defined Q_OS_UNIX
"UNIX BSD/SYSV system"
#elif defined Q_OS_UNIXWARE
"UnixWare Seven, Open UNIX Eight"
#else
"Unknown"
#endif
"; ");
QChar securityStrength(QLatin1Char('N'));
#if !defined(QT_NO_OPENSSL)
securityStrength = QLatin1Char('U');
#endif
ua = ua.arg(securityStrength);
#if defined Q_OS_WIN32
QString ver;
switch(QSysInfo::WindowsVersion) {
case QSysInfo::WV_32s:
ver = "Windows 3.1";
break;
case QSysInfo::WV_95:
ver = "Windows 95";
break;
case QSysInfo::WV_98:
ver = "Windows 98";
break;
case QSysInfo::WV_Me:
ver = "Windows 98; Win 9x 4.90";
break;
case QSysInfo::WV_NT:
ver = "WinNT4.0";
break;
case QSysInfo::WV_2000:
ver = "Windows NT 5.0";
break;
case QSysInfo::WV_XP:
ver = "Windows NT 5.1";
break;
case QSysInfo::WV_2003:
ver = "Windows NT 5.2";
break;
case QSysInfo::WV_VISTA:
ver = "Windows NT 6.0";
break;
case QSysInfo::WV_CE:
ver = "Windows CE";
break;
case QSysInfo::WV_CENET:
ver = "Windows CE .NET";
break;
case QSysInfo::WV_CE_5:
ver = "Windows CE 5.x";
break;
case QSysInfo::WV_CE_6:
ver = "Windows CE 6.x";
break;
}
ua = QString(ua).arg(ver);
#endif
QLocale locale;
if (d->view)
locale = d->view->locale();
QString name = locale.name();
name[2] = QLatin1Char('-');
ua.append(name);
ua.append(QLatin1String(") "));
ua.append(QLatin1String("AppleWebKit/" WEBKIT_VERSION " (KHTML, like Gecko, Safari/419.3) "));
QString appName = QCoreApplication::applicationName();
if (!appName.isEmpty()) {
ua.append(QLatin1Char(' ') + appName);
#if QT_VERSION >= 0x040400
QString appVer = QCoreApplication::applicationVersion();
if (!appVer.isEmpty())
ua.append(QLatin1Char('/') + appVer);
#endif
} else {
ua.append(QLatin1String("Qt/"));
ua.append(QLatin1String(qVersion()));
}
return ua;
}
void QWebPagePrivate::_q_onLoadProgressChanged(int) {
m_totalBytes = page->progress()->totalPageAndResourceBytesToLoad();
m_bytesReceived = page->progress()->totalBytesReceived();
}
quint64 QWebPage::totalBytes() const {
return d->m_totalBytes;
}
quint64 QWebPage::bytesReceived() const {
return d->m_bytesReceived;
}
#include "moc_qwebpage.cpp"