📄 qwebpage.cpp
字号:
/* Copyright (C) 2008, 2009 Nokia Corporation and/or its subsidiary(-ies) Copyright (C) 2007 Staikos Computing Services Inc. Copyright (C) 2007 Apple Inc. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*/#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 "ChromeClientQt.h"#include "ContextMenu.h"#include "ContextMenuClientQt.h"#include "DocumentLoader.h"#include "DragClientQt.h"#include "DragController.h"#include "DragData.h"#include "EditorClientQt.h"#include "Settings.h"#include "Page.h"#include "PageGroup.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 "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"#endifusing 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();}// Lookup table mapping QWebPage::WebActions to the associated Editor commandsstatic const char* editorCommandWebActions[] = { 0, // OpenLink, 0, // OpenLinkInNewWindow, 0, // OpenFrameInNewWindow, 0, // DownloadLinkToDisk, 0, // CopyLinkToClipboard, 0, // OpenImageInNewWindow, 0, // DownloadImageToDisk, 0, // CopyImageToClipboard, 0, // Back, 0, // Forward, 0, // Stop, 0, // Reload, "Cut", // Cut, "Copy", // Copy, "Paste", // Paste, "Undo", // Undo, "Redo", // Redo, "MoveForward", // MoveToNextChar, "MoveBackward", // MoveToPreviousChar, "MoveWordForward", // MoveToNextWord, "MoveWordBackward", // MoveToPreviousWord, "MoveDown", // MoveToNextLine, "MoveUp", // MoveToPreviousLine, "MoveToBeginningOfLine", // MoveToStartOfLine, "MoveToEndOfLine", // MoveToEndOfLine, "MoveToBeginningOfParagraph", // MoveToStartOfBlock, "MoveToEndOfParagraph", // MoveToEndOfBlock, "MoveToBeginningOfDocument", // MoveToStartOfDocument, "MoveToEndOfDocument", // MoveToEndOfDocument, "MoveForwardAndModifySelection", // SelectNextChar, "MoveBackwardAndModifySelection", // SelectPreviousChar, "MoveWordForwardAndModifySelection", // SelectNextWord, "MoveWordBackwardAndModifySelection", // SelectPreviousWord, "MoveDownAndModifySelection", // SelectNextLine, "MoveUpAndModifySelection", // SelectPreviousLine, "MoveToBeginningOfLineAndModifySelection", // SelectStartOfLine, "MoveToEndOfLineAndModifySelection", // SelectEndOfLine, "MoveToBeginningOfParagraphAndModifySelection", // SelectStartOfBlock, "MoveToEndOfParagraphAndModifySelection", // SelectEndOfBlock, "MoveToBeginningOfDocumentAndModifySelection", //SelectStartOfDocument, "MoveToEndOfDocumentAndModifySelection", // SelectEndOfDocument, "DeleteWordBackward", // DeleteStartOfWord, "DeleteWordForward", // DeleteEndOfWord, 0, // SetTextDirectionDefault, 0, // SetTextDirectionLeftToRight, 0, // SetTextDirectionRightToLeft, "ToggleBold", // ToggleBold, "ToggleItalic", // ToggleItalic, "ToggleUnderline", // ToggleUnderline, 0, // InspectElement, "InsertNewline", // InsertParagraphSeparator "InsertLineBreak", // InsertLineSeparator "SelectAll", // SelectAll 0 // WebActionCount};// Lookup the appropriate editor command to use for WebAction \a actionconst 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_CURSORSetCursorEvent::SetCursorEvent(const QCursor& cursor) : QEvent(static_cast<QEvent::Type>(EventType)) , m_cursor(cursor){}QCursor SetCursorEvent::cursor() const{ return m_cursor;}#endif// If you change this make sure to also adjust the docs for QWebPage::userAgentForUrl#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(); WebCore::PageGroup::setShouldTrackVisitedLinks(true); 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)); // ### should be configurable 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 < 0x040400bool QWebPagePrivate::acceptNavigationRequest(QWebFrame *frame, const QWebNetworkRequest &request, QWebPage::NavigationType type){ if (insideOpenCall && frame == mainFrame) return true; return q->acceptNavigationRequest(frame, request, type);}#elsebool QWebPagePrivate::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, QWebPage::NavigationType type){ if (insideOpenCall && frame == mainFrame) return true; return q->acceptNavigationRequest(frame, request, type);}#endifvoid 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_CONTEXTMENUQMenu *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: /* fall through */ 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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -