1/* This file is part of the KDE project
2 Copyright (C) 1999 David Faure <faure@kde.org>
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
20#ifndef KHTML_SETTINGS_H
21#define KHTML_SETTINGS_H
22
23class KConfig;
24class KConfigGroup;
25
26#include <khtml_export.h>
27#include <kparts/htmlextension.h>
28
29#include <QColor>
30#include <QFont> // ### KDE 5: remove
31#include <QMap> // ### KDE 5: remove
32#include <QStringList>
33#include <QPair>
34
35struct KPerDomainSettings;
36class KHTMLSettingsPrivate;
37
38/**
39 * Settings for the HTML view.
40 */
41class KHTML_EXPORT KHTMLSettings
42{
43public:
44
45 /**
46 * This enum specifies whether Java/JavaScript execution is allowed.
47 */
48 enum KJavaScriptAdvice { // ### KDE 5: Remove. Use KParts::HtmlSettingsInterface::JavaScriptAdvice instead
49 KJavaScriptDunno = 0,
50 KJavaScriptAccept,
51 KJavaScriptReject
52 };
53
54 enum KAnimationAdvice {
55 KAnimationDisabled = 0,
56 KAnimationLoopOnce,
57 KAnimationEnabled
58 };
59
60 enum KSmoothScrollingMode {
61 KSmoothScrollingDisabled = 0,
62 KSmoothScrollingWhenEfficient,
63 KSmoothScrollingEnabled
64 };
65
66 enum KDNSPrefetch {
67 KDNSPrefetchDisabled = 0,
68 KDNSPrefetchOnlyWWWAndSLD,
69 KDNSPrefetchEnabled
70 };
71
72 /**
73 * This enum specifies the policy for window.open
74 */
75 enum KJSWindowOpenPolicy { // ### KDE 5: Remove. Use KParts::HtmlSettingsInterface::JSWindowOpenPolicy instead.
76 KJSWindowOpenAllow = 0,
77 KJSWindowOpenAsk,
78 KJSWindowOpenDeny,
79 KJSWindowOpenSmart
80 };
81
82 /**
83 * This enum specifies the policy for window.status and .defaultStatus
84 */
85 enum KJSWindowStatusPolicy { // ### KDE 5: Remove. Use KParts::HtmlSettingsInterface::JSWindowStatusPolicy instead.
86 KJSWindowStatusAllow = 0,
87 KJSWindowStatusIgnore
88 };
89
90 /**
91 * This enum specifies the policy for window.moveBy and .moveTo
92 */
93 enum KJSWindowMovePolicy { // ### KDE 5: Remove. Use KParts::HtmlSettingsInterface::JSWindowMovePolicy instead.
94 KJSWindowMoveAllow = 0,
95 KJSWindowMoveIgnore
96 };
97
98 /**
99 * This enum specifies the policy for window.resizeBy and .resizeTo
100 */
101 enum KJSWindowResizePolicy { // ### KDE 5: Remove. Use KParts::HtmlSettingsInterface::JSWindowStatusPolicy insead.
102 KJSWindowResizeAllow = 0,
103 KJSWindowResizeIgnore
104 };
105
106 /**
107 * This enum specifies the policy for window.focus
108 */
109 enum KJSWindowFocusPolicy { // ### KDE 5: Remove. Use KParts::HtmlSettingsInterface::JSWindowStatusPolicy instead.
110 KJSWindowFocusAllow = 0,
111 KJSWindowFocusIgnore
112 };
113
114 /**
115 * @internal Constructor
116 */
117 KHTMLSettings();
118 KHTMLSettings(const KHTMLSettings &other);
119
120 /**
121 * Called by constructor and reparseConfiguration
122 */
123 void init();
124
125 /** Read settings from @p config.
126 * @param config is a pointer to KConfig object.
127 * @param reset if true, settings are always set; if false,
128 * settings are only set if the config file has a corresponding key.
129 */
130 void init(KConfig *config, bool reset = true);
131
132 /**
133 * Destructor. Don't delete any instance by yourself.
134 */
135 virtual ~KHTMLSettings();
136
137 // Behavior settings
138 bool changeCursor() const;
139 bool underlineLink() const;
140 bool hoverLink() const;
141 bool allowTabulation() const;
142 bool autoSpellCheck() const;
143 KAnimationAdvice showAnimations() const;
144 KSmoothScrollingMode smoothScrolling() const;
145 KDNSPrefetch dnsPrefetch() const;
146
147 // Font settings
148 QString stdFontName() const;
149 QString fixedFontName() const;
150 QString serifFontName() const;
151 QString sansSerifFontName() const;
152 QString cursiveFontName() const;
153 QString fantasyFontName() const;
154
155 // these two can be set. Mainly for historical reasons (the method in KHTMLPart exists...)
156 void setStdFontName(const QString &n);
157 void setFixedFontName(const QString &n);
158
159 int minFontSize() const;
160 int mediumFontSize() const;
161
162 bool jsErrorsEnabled() const;
163 void setJSErrorsEnabled(bool enabled);
164
165 const QString &encoding() const;
166
167 bool followSystemColors() const;
168
169 // Color settings
170 const QColor &textColor() const;
171 const QColor &baseColor() const;
172 const QColor &linkColor() const;
173 const QColor &vLinkColor() const;
174
175 // Autoload images
176 bool autoLoadImages() const;
177 bool unfinishedImageFrame() const;
178
179 bool isOpenMiddleClickEnabled();
180 /// @deprecated do not use, feature was moved to be only in konqueror
181 bool isBackRightClickEnabled();
182
183 // Java and JavaScript
184 bool isJavaEnabled(const QString &hostname = QString()) const;
185 bool isJavaScriptEnabled(const QString &hostname = QString()) const;
186 bool isJavaScriptDebugEnabled(const QString &hostname = QString()) const;
187 bool isJavaScriptErrorReportingEnabled(const QString &hostname = QString()) const;
188 bool isPluginsEnabled(const QString &hostname = QString()) const;
189
190 // AdBlocK Filtering
191
192 /** tests whether @p url is filtered.
193 * @param url the URL to test.
194 * @return @c true if the URL is blacklisted and is not whitelisted.
195 */
196 bool isAdFiltered(const QString &url) const;
197
198 /** identify the filter which matches @p url.
199 * @param url the URL to test.
200 * @param isWhiteListed if not @c NULL, set to @c true if the URL matched
201 * a whitelist filter; set to @c false if it matched a blacklist filter.
202 * @return the filter string that matched,
203 * or @c QString() if no filter matched.
204 * @since 4.4
205 */
206 QString adFilteredBy(const QString &url, bool *isWhiteListed = nullptr) const;
207
208 bool isAdFilterEnabled() const;
209 bool isHideAdsEnabled() const;
210 void addAdFilter(const QString &url);
211
212 // Access Keys
213 bool accessKeysEnabled() const;
214
215 // ### KDE 5: Replace KJSWindowOpenPolicy with KParts::HtmlSettingsInterface::JSWindowOpenPolicy
216 KJSWindowOpenPolicy windowOpenPolicy(const QString &hostname = QString()) const;
217 KJSWindowMovePolicy windowMovePolicy(const QString &hostname = QString()) const;
218 KJSWindowResizePolicy windowResizePolicy(const QString &hostname = QString()) const;
219 KJSWindowStatusPolicy windowStatusPolicy(const QString &hostname = QString()) const;
220 KJSWindowFocusPolicy windowFocusPolicy(const QString &hostname = QString()) const;
221
222 // helpers for parsing domain-specific configuration, used in KControl module as well
223 // ### KDE 5: Replace KJavaScriptAdvice with KParts::HtmlSettingsInterface::JavaScriptAdvice.
224 // ### KDE 5: Remove ? Equivalent functions now exist in KParts::HtmlSettingsInterface.
225 static KJavaScriptAdvice strToAdvice(const QString &_str);
226 static void splitDomainAdvice(const QString &configStr, QString &domain,
227 KJavaScriptAdvice &javaAdvice,
228 KJavaScriptAdvice &javaScriptAdvice);
229 static const char *adviceToStr(KJavaScriptAdvice _advice);
230
231 /** reads from @p config's current group, forcing initialization
232 * if @p reset is true.
233 * @param config is a pointer to KConfig object.
234 * @param reset true if initialization is to be forced.
235 * @param global true if the global domain is to be read.
236 * @param pd_settings will be initialised with the computed (inherited)
237 * settings.
238 */
239 void readDomainSettings(const KConfigGroup &config, bool reset,
240 bool global, KPerDomainSettings &pd_settings);
241
242 QString settingsToCSS() const;
243 static const QString &availableFamilies();
244
245 QString userStyleSheet() const;
246
247 // Form completion
248 bool isFormCompletionEnabled() const;
249 int maxFormCompletionItems() const;
250
251 // Meta refresh/redirect (http-equiv)
252 bool isAutoDelayedActionsEnabled() const;
253
254 QList< QPair< QString, QChar > > fallbackAccessKeysAssignments() const;
255
256 // Whether to show passive popup when windows are blocked
257 void setJSPopupBlockerPassivePopup(bool enabled);
258 bool jsPopupBlockerPassivePopup() const;
259
260private:
261 friend class KHTMLGlobal;
262 QString lookupFont(int i) const;
263
264 KHTMLSettingsPrivate *const d;
265 static QString *avFamilies;
266};
267
268#endif
269