2 Copyright (C) 2007 Trolltech ASA
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
19 This class provides all functionality needed for loading images, style sheets and html
20 pages from the web. It has a memory cache for these objects.
23 #include "qwebsettings.h"
26 #include "qwebpage_p.h"
31 #include "PlatformString.h"
32 #include "IconDatabase.h"
35 #include <QSharedData>
37 class QWebSettingsPrivate : public QSharedData
42 minimumLogicalFontSize(5),
44 defaultFixedFontSize(14)
46 //Initialize our defaults
47 // changing any of those will likely break the LayoutTests
48 fontFamilies[QWebSettings::StandardFont] = QLatin1String("Arial");
49 fontFamilies[QWebSettings::FixedFont] = QLatin1String("Courier");
50 fontFamilies[QWebSettings::SerifFont] = QLatin1String("Times New Roman");
51 fontFamilies[QWebSettings::SansSerifFont] = QLatin1String("Arial");
53 attributes[QWebSettings::AutoLoadImages] = true;
54 attributes[QWebSettings::JavascriptEnabled] = true;
57 QHash<int, QString> fontFamilies;
59 int minimumLogicalFontSize;
61 int defaultFixedFontSize;
62 QHash<int, bool> attributes;
63 QHash<int, QPixmap> graphics;
64 QString userStyleSheetLocation;
67 static QWebSettings globalSettings;
69 QWebSettings::QWebSettings()
70 : d(new QWebSettingsPrivate)
74 QWebSettings::~QWebSettings()
78 void QWebSettings::setMinimumFontSize(int size)
80 d->minimumFontSize = size;
84 int QWebSettings::minimumFontSize() const
86 return d->minimumFontSize;
90 void QWebSettings::setMinimumLogicalFontSize(int size)
92 d->minimumLogicalFontSize = size;
96 int QWebSettings::minimumLogicalFontSize() const
98 return d->minimumLogicalFontSize;
102 void QWebSettings::setDefaultFontSize(int size)
104 d->defaultFontSize = size;
108 int QWebSettings::defaultFontSize() const
110 return d->defaultFontSize;
114 void QWebSettings::setDefaultFixedFontSize(int size)
116 d->defaultFixedFontSize = size;
120 int QWebSettings::defaultFixedFontSize() const
122 return d->defaultFixedFontSize;
125 void QWebSettings::setUserStyleSheetLocation(const QString &location)
127 d->userStyleSheetLocation = location;
130 QString QWebSettings::userStyleSheetLocation() const
132 return d->userStyleSheetLocation;
135 void QWebSettings::setIconDatabaseEnabled(bool enabled, const QString &location)
137 WebCore::iconDatabase()->setEnabled(enabled);
139 if (!location.isEmpty()) {
140 WebCore::iconDatabase()->open(location);
142 WebCore::iconDatabase()->open(WebCore::iconDatabase()->defaultDatabaseFilename());
145 WebCore::iconDatabase()->close();
149 bool QWebSettings::iconDatabaseEnabled() const
151 return WebCore::iconDatabase()->isEnabled() && WebCore::iconDatabase()->isOpen();
154 void QWebSettings::setWebGraphic(WebGraphic type, const QPixmap &graphic)
156 d->graphics[type] = graphic;
159 QPixmap QWebSettings::webGraphic(WebGraphic type) const
161 if (d->graphics.contains(type))
162 return d->graphics[type];
167 QWebSettings::QWebSettings(const QWebSettings &other)
172 QWebSettings &QWebSettings::operator=(const QWebSettings &other)
178 void QWebSettings::setGlobal(const QWebSettings &settings)
180 globalSettings = settings;
183 QWebSettings QWebSettings::global()
185 return globalSettings;
188 void QWebSettings::setFontFamily(FontType type, const QString &family)
190 d->fontFamilies[type] = family;
193 QString QWebSettings::fontFamily(FontType type) const
195 return d->fontFamilies[type];
198 void QWebSettings::setAttribute(WebAttribute attr, bool on)
200 d->attributes[attr] = on;
203 bool QWebSettings::testAttribute(WebAttribute attr) const
205 if (!d->attributes.contains(attr))
207 return d->attributes[attr];
210 QPixmap loadResourcePixmap(const char *name)
212 const QWebSettings settings = QWebSettings::global();
213 const QString resource = name;
216 if (resource == "missingImage")
217 pixmap = settings.webGraphic(QWebSettings::MissingImageGraphic);
218 else if (resource == "nullPlugin")
219 pixmap = settings.webGraphic(QWebSettings::MissingPluginGraphic);
220 else if (resource == "urlIcon")
221 pixmap = settings.webGraphic(QWebSettings::DefaultFaviconGraphic);
222 else if (resource == "textAreaResizeCorner")
223 pixmap = settings.webGraphic(QWebSettings::TextAreaResizeCornerGraphic);