⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qwebsettings.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*    Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)    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 "qwebsettings.h"#include "qwebpage.h"#include "qwebpage_p.h"#include "Cache.h"#include "Page.h"#include "PageCache.h"#include "Settings.h"#include "KURL.h"#include "PlatformString.h"#include "IconDatabase.h"#include "Image.h"#include "IntSize.h"#include "ApplicationCacheStorage.h"#include "DatabaseTracker.h"#include <QHash>#include <QSharedData>#include <QUrl>#include <QFileInfo>class QWebSettingsPrivate{public:    QWebSettingsPrivate(WebCore::Settings *wcSettings = 0)        : settings(wcSettings)    {    }    QHash<int, QString> fontFamilies;    QHash<int, int> fontSizes;    QHash<int, bool> attributes;    QUrl userStyleSheetLocation;    QString localStorageDatabasePath;    QString offlineWebApplicationCachePath;    qint64 offlineStorageDefaultQuota;    void apply();    WebCore::Settings *settings;};typedef QHash<int, QPixmap> WebGraphicHash;Q_GLOBAL_STATIC(WebGraphicHash, _graphics)static WebGraphicHash* graphics(){    WebGraphicHash* hash = _graphics();    if (hash->isEmpty()) {        hash->insert(QWebSettings::MissingImageGraphic, QPixmap(QLatin1String(":webkit/resources/missingImage.png")));        hash->insert(QWebSettings::MissingPluginGraphic, QPixmap(QLatin1String(":webkit/resources/nullPlugin.png")));        hash->insert(QWebSettings::DefaultFrameIconGraphic, QPixmap(QLatin1String(":webkit/resources/urlIcon.png")));        hash->insert(QWebSettings::TextAreaSizeGripCornerGraphic, QPixmap(QLatin1String(":webkit/resources/textAreaResizeCorner.png")));    }    return hash;}Q_GLOBAL_STATIC(QList<QWebSettingsPrivate *>, allSettings);void QWebSettingsPrivate::apply(){    if (settings) {        settings->setTextAreasAreResizable(true);        QWebSettingsPrivate *global = QWebSettings::globalSettings()->d;        QString family = fontFamilies.value(QWebSettings::StandardFont,                                            global->fontFamilies.value(QWebSettings::StandardFont));        settings->setStandardFontFamily(family);        family = fontFamilies.value(QWebSettings::FixedFont,                                    global->fontFamilies.value(QWebSettings::FixedFont));        settings->setFixedFontFamily(family);        family = fontFamilies.value(QWebSettings::SerifFont,                                    global->fontFamilies.value(QWebSettings::SerifFont));        settings->setSerifFontFamily(family);        family = fontFamilies.value(QWebSettings::SansSerifFont,                                    global->fontFamilies.value(QWebSettings::SansSerifFont));        settings->setSansSerifFontFamily(family);        family = fontFamilies.value(QWebSettings::CursiveFont,                                    global->fontFamilies.value(QWebSettings::CursiveFont));        settings->setCursiveFontFamily(family);        family = fontFamilies.value(QWebSettings::FantasyFont,                                    global->fontFamilies.value(QWebSettings::FantasyFont));        settings->setFantasyFontFamily(family);        int size = fontSizes.value(QWebSettings::MinimumFontSize,                                   global->fontSizes.value(QWebSettings::MinimumFontSize));        settings->setMinimumFontSize(size);        size = fontSizes.value(QWebSettings::MinimumLogicalFontSize,                                   global->fontSizes.value(QWebSettings::MinimumLogicalFontSize));        settings->setMinimumLogicalFontSize(size);        size = fontSizes.value(QWebSettings::DefaultFontSize,                                   global->fontSizes.value(QWebSettings::DefaultFontSize));        settings->setDefaultFontSize(size);        size = fontSizes.value(QWebSettings::DefaultFixedFontSize,                                   global->fontSizes.value(QWebSettings::DefaultFixedFontSize));        settings->setDefaultFixedFontSize(size);        bool value = attributes.value(QWebSettings::AutoLoadImages,                                      global->attributes.value(QWebSettings::AutoLoadImages));        settings->setLoadsImagesAutomatically(value);        value = attributes.value(QWebSettings::JavascriptEnabled,                                      global->attributes.value(QWebSettings::JavascriptEnabled));        settings->setJavaScriptEnabled(value);        value = attributes.value(QWebSettings::JavascriptCanOpenWindows,                                      global->attributes.value(QWebSettings::JavascriptCanOpenWindows));        settings->setJavaScriptCanOpenWindowsAutomatically(value);        value = attributes.value(QWebSettings::JavaEnabled,                                      global->attributes.value(QWebSettings::JavaEnabled));        settings->setJavaEnabled(value);        value = attributes.value(QWebSettings::PluginsEnabled,                                      global->attributes.value(QWebSettings::PluginsEnabled));        settings->setPluginsEnabled(value);        value = attributes.value(QWebSettings::PrivateBrowsingEnabled,                                      global->attributes.value(QWebSettings::PrivateBrowsingEnabled));        settings->setPrivateBrowsingEnabled(value);        value = attributes.value(QWebSettings::JavascriptCanAccessClipboard,                                      global->attributes.value(QWebSettings::JavascriptCanAccessClipboard));        settings->setDOMPasteAllowed(value);        value = attributes.value(QWebSettings::DeveloperExtrasEnabled,                                      global->attributes.value(QWebSettings::DeveloperExtrasEnabled));        settings->setDeveloperExtrasEnabled(value);        QUrl location = !userStyleSheetLocation.isEmpty() ? userStyleSheetLocation : global->userStyleSheetLocation;        settings->setUserStyleSheetLocation(WebCore::KURL(location));        QString localStoragePath = !localStorageDatabasePath.isEmpty() ? localStorageDatabasePath : global->localStorageDatabasePath;        settings->setLocalStorageDatabasePath(localStoragePath);        value = attributes.value(QWebSettings::ZoomTextOnly,                                 global->attributes.value(QWebSettings::ZoomTextOnly));        settings->setZoomsTextOnly(value);        value = attributes.value(QWebSettings::PrintElementBackgrounds,                                      global->attributes.value(QWebSettings::PrintElementBackgrounds));        settings->setShouldPrintBackgrounds(value);        value = attributes.value(QWebSettings::OfflineStorageDatabaseEnabled,                                      global->attributes.value(QWebSettings::OfflineStorageDatabaseEnabled));        settings->setDatabasesEnabled(value);        value = attributes.value(QWebSettings::OfflineWebApplicationCacheEnabled,                                      global->attributes.value(QWebSettings::OfflineWebApplicationCacheEnabled));        settings->setOfflineWebApplicationCacheEnabled(value);        value = attributes.value(QWebSettings::LocalStorageDatabaseEnabled,                                      global->attributes.value(QWebSettings::LocalStorageDatabaseEnabled));        settings->setLocalStorageEnabled(value);        value = attributes.value(QWebSettings::AllowUniversalAccessFromFileUrls,                                      global->attributes.value(QWebSettings::AllowUniversalAccessFromFileUrls));        settings->setAllowUniversalAccessFromFileURLs(value);    } else {        QList<QWebSettingsPrivate *> settings = *::allSettings();        for (int i = 0; i < settings.count(); ++i)            settings[i]->apply();    }}/*!    Returns the global settings object.    Any setting changed on the default object is automatically applied to all    QWebPage instances where the particular setting is not overriden already.*/QWebSettings *QWebSettings::globalSettings(){    static QWebSettings *global = 0;    if (!global)        global = new QWebSettings;    return global;}/*!    \class QWebSettings    \since 4.4    \brief The QWebSettings class provides an object to store the settings used    by QWebPage and QWebFrame.    Each QWebPage object has its own QWebSettings object, which configures the    settings for that page. If a setting is not configured, then it is looked    up in the global settings object, which can be accessed using    QWebSettings::globalSettings().    QWebSettings allows configuring font properties such as font size and font    family, the location of a custom stylesheet, and generic attributes like java    script, plugins, etc. The \l{QWebSettings::WebAttribute}{WebAttribute}    enum further describes this.    QWebSettings also configures global properties such as the web page memory    cache and the web page icon database, local database storage and offline    applications storage.    \section1 Web Application Support    WebKit provides support for features specified in \l{HTML 5} that improve the    performance and capabilities of Web applications. These include client-side    (offline) storage and the use of a Web application cache.    Client-side (offline) storage is an improvement over the use of cookies to    store persistent data in Web applications. Applications can configure and    enable the use of an offline storage database by calling the    setOfflineStoragePath() with an appropriate file path, and can limit the quota    for each application by calling setOfflineStorageDefaultQuota().    \sa QWebPage::settings(), QWebView::settings(), {Browser}*//*!    \enum QWebSettings::FontFamily    This enum describes the generic font families defined by CSS 2.    For more information see the    \l{http://www.w3.org/TR/REC-CSS2/fonts.html#generic-font-families}{CSS standard}.    \value StandardFont    \value FixedFont    \value SerifFont    \value SansSerifFont    \value CursiveFont    \value FantasyFont*//*!    \enum QWebSettings::FontSize    This enum describes the font sizes configurable through QWebSettings.    \value MinimumFontSize The hard minimum font size.    \value MinimumLogicalFontSize The minimum logical font size that is applied        after zooming with QWebFrame's textSizeMultiplier().    \value DefaultFontSize The default font size for regular text.    \value DefaultFixedFontSize The default font size for fixed-pitch text.*//*!    \enum QWebSettings::WebGraphic    This enums describes the standard graphical elements used in webpages.    \value MissingImageGraphic The replacement graphic shown when an image could not be loaded.    \value MissingPluginGraphic The replacement graphic shown when a plugin could not be loaded.    \value DefaultFrameIconGraphic The default icon for QWebFrame::icon().    \value TextAreaSizeGripCornerGraphic The graphic shown for the size grip of text areas.*//*!    \enum QWebSettings::WebAttribute    This enum describes various attributes that are configurable through QWebSettings.    \value AutoLoadImages Specifies whether images are automatically loaded in        web pages.    \value JavascriptEnabled Enables or disables the running of JavaScript        programs.    \value JavaEnabled Enables or disables Java applets.        Currently Java applets are not supported.    \value PluginsEnabled Enables or disables plugins in web pages.    \value PrivateBrowsingEnabled Private browsing prevents WebKit from        recording visited pages in the history and storing web page icons.    \value JavascriptCanOpenWindows Specifies whether JavaScript programs        can open new windows.    \value JavascriptCanAccessClipboard Specifies whether JavaScript programs        can read or write to the clipboard.    \value DeveloperExtrasEnabled Enables extra tools for Web developers.        Currently this enables the "Inspect" element in the context menu,    which shows the WebKit WebInspector for web site debugging.    \value LinksIncludedInFocusChain Specifies whether hyperlinks should be        included in the keyboard focus chain.    \value ZoomTextOnly Specifies whether the zoom factor on a frame applies to        only the text or all content.    \value PrintElementBackgrounds Specifies whether the background color and images        are also drawn when the page is printed.    \value OfflineStorageDatabaseEnabled Specifies whether support for the HTML 5        offline storage feature is enabled or not.    \value OfflineWebApplicationCacheEnabled Specifies whether support for the HTML 5        web application cache feature is enabled or not.    \value LocalStorageDatabaseEnabled Specifies whether support for the HTML 5        local storage feature is enabled or not.    \value AllowUniversalAccessFromFileUrls Specifies whether documents from file        Urls should be granted universal access (e.g., to HTTP and HTTPS documents).*//*!    \internal*/QWebSettings::QWebSettings()    : d(new QWebSettingsPrivate){    // Initialize our global defaults    d->fontSizes.insert(QWebSettings::MinimumFontSize, 0);    d->fontSizes.insert(QWebSettings::MinimumLogicalFontSize, 0);    d->fontSizes.insert(QWebSettings::DefaultFontSize, 14);    d->fontSizes.insert(QWebSettings::DefaultFixedFontSize, 14);    d->fontFamilies.insert(QWebSettings::StandardFont, QLatin1String("Arial"));    d->fontFamilies.insert(QWebSettings::FixedFont, QLatin1String("Courier New"));    d->fontFamilies.insert(QWebSettings::SerifFont, QLatin1String("Times New Roman"));    d->fontFamilies.insert(QWebSettings::SansSerifFont, QLatin1String("Arial"));    d->fontFamilies.insert(QWebSettings::CursiveFont, QLatin1String("Arial"));    d->fontFamilies.insert(QWebSettings::FantasyFont, QLatin1String("Arial"));    d->attributes.insert(QWebSettings::AutoLoadImages, true);    d->attributes.insert(QWebSettings::JavascriptEnabled, true);    d->attributes.insert(QWebSettings::LinksIncludedInFocusChain, true);    d->attributes.insert(QWebSettings::ZoomTextOnly, false);    d->attributes.insert(QWebSettings::PrintElementBackgrounds, true);    d->attributes.insert(QWebSettings::OfflineStorageDatabaseEnabled, true);    d->attributes.insert(QWebSettings::OfflineWebApplicationCacheEnabled, true);    d->attributes.insert(QWebSettings::LocalStorageDatabaseEnabled, true);    d->attributes.insert(QWebSettings::AllowUniversalAccessFromFileUrls, true);    d->offlineStorageDefaultQuota = 5 * 1024 * 1024;}/*!    \internal*/QWebSettings::QWebSettings(WebCore::Settings *settings)    : d(new QWebSettingsPrivate(settings)){    d->settings = settings;    d->apply();    allSettings()->append(d);}/*!    \internal*/QWebSettings::~QWebSettings(){    if (d->settings)        allSettings()->removeAll(d);    delete d;}/*!    Sets the font size for \a type to \a size.*/void QWebSettings::setFontSize(FontSize type, int size){    d->fontSizes.insert(type, size);    d->apply();}/*!    Returns the default font size for \a type.*/int QWebSettings::fontSize(FontSize type) const{    int defaultValue = 0;    if (d->settings) {        QWebSettingsPrivate *global = QWebSettings::globalSettings()->d;        defaultValue = global->fontSizes.value(type);    }    return d->fontSizes.value(type, defaultValue);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -