|
1 /* |
|
2 Copyright (C) 2007 Trolltech ASA |
|
3 |
|
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. |
|
8 |
|
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. |
|
13 |
|
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. |
|
18 |
|
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. |
|
21 */ |
|
22 |
|
23 #include "qwebsettings.h" |
|
24 |
|
25 #include "qwebpage.h" |
|
26 #include "qwebpage_p.h" |
|
27 |
|
28 #include "Page.h" |
|
29 #include "Settings.h" |
|
30 #include "KURL.h" |
|
31 #include "PlatformString.h" |
|
32 #include "IconDatabase.h" |
|
33 |
|
34 #include <QHash> |
|
35 #include <QSharedData> |
|
36 |
|
37 class QWebSettingsPrivate : public QSharedData |
|
38 { |
|
39 public: |
|
40 QWebSettingsPrivate() |
|
41 : minimumFontSize(5), |
|
42 minimumLogicalFontSize(5), |
|
43 defaultFontSize(14), |
|
44 defaultFixedFontSize(14) |
|
45 { |
|
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"); |
|
52 |
|
53 attributes[QWebSettings::AutoLoadImages] = true; |
|
54 attributes[QWebSettings::JavascriptEnabled] = true; |
|
55 } |
|
56 |
|
57 QHash<int, QString> fontFamilies; |
|
58 int minimumFontSize; |
|
59 int minimumLogicalFontSize; |
|
60 int defaultFontSize; |
|
61 int defaultFixedFontSize; |
|
62 QHash<int, bool> attributes; |
|
63 QHash<int, QPixmap> graphics; |
|
64 QString userStyleSheetLocation; |
|
65 }; |
|
66 |
|
67 static QWebSettings globalSettings; |
|
68 |
|
69 QWebSettings::QWebSettings() |
|
70 : d(new QWebSettingsPrivate) |
|
71 { |
|
72 } |
|
73 |
|
74 QWebSettings::~QWebSettings() |
|
75 { |
|
76 } |
|
77 |
|
78 void QWebSettings::setMinimumFontSize(int size) |
|
79 { |
|
80 d->minimumFontSize = size; |
|
81 } |
|
82 |
|
83 |
|
84 int QWebSettings::minimumFontSize() const |
|
85 { |
|
86 return d->minimumFontSize; |
|
87 } |
|
88 |
|
89 |
|
90 void QWebSettings::setMinimumLogicalFontSize(int size) |
|
91 { |
|
92 d->minimumLogicalFontSize = size; |
|
93 } |
|
94 |
|
95 |
|
96 int QWebSettings::minimumLogicalFontSize() const |
|
97 { |
|
98 return d->minimumLogicalFontSize; |
|
99 } |
|
100 |
|
101 |
|
102 void QWebSettings::setDefaultFontSize(int size) |
|
103 { |
|
104 d->defaultFontSize = size; |
|
105 } |
|
106 |
|
107 |
|
108 int QWebSettings::defaultFontSize() const |
|
109 { |
|
110 return d->defaultFontSize; |
|
111 } |
|
112 |
|
113 |
|
114 void QWebSettings::setDefaultFixedFontSize(int size) |
|
115 { |
|
116 d->defaultFixedFontSize = size; |
|
117 } |
|
118 |
|
119 |
|
120 int QWebSettings::defaultFixedFontSize() const |
|
121 { |
|
122 return d->defaultFixedFontSize; |
|
123 } |
|
124 |
|
125 void QWebSettings::setUserStyleSheetLocation(const QString &location) |
|
126 { |
|
127 d->userStyleSheetLocation = location; |
|
128 } |
|
129 |
|
130 QString QWebSettings::userStyleSheetLocation() const |
|
131 { |
|
132 return d->userStyleSheetLocation; |
|
133 } |
|
134 |
|
135 void QWebSettings::setIconDatabaseEnabled(bool enabled, const QString &location) |
|
136 { |
|
137 WebCore::iconDatabase()->setEnabled(enabled); |
|
138 if (enabled) { |
|
139 if (!location.isEmpty()) { |
|
140 WebCore::iconDatabase()->open(location); |
|
141 } else { |
|
142 WebCore::iconDatabase()->open(WebCore::iconDatabase()->defaultDatabaseFilename()); |
|
143 } |
|
144 } else { |
|
145 WebCore::iconDatabase()->close(); |
|
146 } |
|
147 } |
|
148 |
|
149 bool QWebSettings::iconDatabaseEnabled() const |
|
150 { |
|
151 return WebCore::iconDatabase()->isEnabled() && WebCore::iconDatabase()->isOpen(); |
|
152 } |
|
153 |
|
154 void QWebSettings::setWebGraphic(WebGraphic type, const QPixmap &graphic) |
|
155 { |
|
156 d->graphics[type] = graphic; |
|
157 } |
|
158 |
|
159 QPixmap QWebSettings::webGraphic(WebGraphic type) const |
|
160 { |
|
161 if (d->graphics.contains(type)) |
|
162 return d->graphics[type]; |
|
163 else |
|
164 return QPixmap(); |
|
165 } |
|
166 |
|
167 QWebSettings::QWebSettings(const QWebSettings &other) |
|
168 { |
|
169 d = other.d; |
|
170 } |
|
171 |
|
172 QWebSettings &QWebSettings::operator=(const QWebSettings &other) |
|
173 { |
|
174 d = other.d; |
|
175 return *this; |
|
176 } |
|
177 |
|
178 void QWebSettings::setGlobal(const QWebSettings &settings) |
|
179 { |
|
180 globalSettings = settings; |
|
181 } |
|
182 |
|
183 QWebSettings QWebSettings::global() |
|
184 { |
|
185 return globalSettings; |
|
186 } |
|
187 |
|
188 void QWebSettings::setFontFamily(FontType type, const QString &family) |
|
189 { |
|
190 d->fontFamilies[type] = family; |
|
191 } |
|
192 |
|
193 QString QWebSettings::fontFamily(FontType type) const |
|
194 { |
|
195 return d->fontFamilies[type]; |
|
196 } |
|
197 |
|
198 void QWebSettings::setAttribute(WebAttribute attr, bool on) |
|
199 { |
|
200 d->attributes[attr] = on; |
|
201 } |
|
202 |
|
203 bool QWebSettings::testAttribute(WebAttribute attr) const |
|
204 { |
|
205 if (!d->attributes.contains(attr)) |
|
206 return false; |
|
207 return d->attributes[attr]; |
|
208 } |
|
209 |
|
210 QPixmap loadResourcePixmap(const char *name) |
|
211 { |
|
212 const QWebSettings settings = QWebSettings::global(); |
|
213 const QString resource = name; |
|
214 |
|
215 QPixmap pixmap; |
|
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); |
|
224 |
|
225 return pixmap; |
|
226 } |