File indexing completed on 2024-03-24 15:32:32

0001 /* This file is part of the KDE project
0002    Copyright (C) 1999 David Faure <faure@kde.org>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017    Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #ifndef KHTML_SETTINGS_H
0021 #define KHTML_SETTINGS_H
0022 
0023 class KConfig;
0024 class KConfigGroup;
0025 
0026 #include <khtml_export.h>
0027 #include <kparts/htmlextension.h>
0028 
0029 #include <QColor>
0030 #include <QFont> // ### KDE 5: remove
0031 #include <QMap> // ### KDE 5: remove
0032 #include <QStringList>
0033 #include <QPair>
0034 
0035 struct KPerDomainSettings;
0036 class KHTMLSettingsPrivate;
0037 
0038 /**
0039  * Settings for the HTML view.
0040  */
0041 class KHTML_EXPORT KHTMLSettings
0042 {
0043 public:
0044 
0045     /**
0046      * This enum specifies whether Java/JavaScript execution is allowed.
0047      */
0048     enum KJavaScriptAdvice {  // ### KDE 5: Remove. Use KParts::HtmlSettingsInterface::JavaScriptAdvice instead
0049         KJavaScriptDunno = 0,
0050         KJavaScriptAccept,
0051         KJavaScriptReject
0052     };
0053 
0054     enum KAnimationAdvice {
0055         KAnimationDisabled = 0,
0056         KAnimationLoopOnce,
0057         KAnimationEnabled
0058     };
0059 
0060     enum KSmoothScrollingMode {
0061         KSmoothScrollingDisabled = 0,
0062         KSmoothScrollingWhenEfficient,
0063         KSmoothScrollingEnabled
0064     };
0065 
0066     enum KDNSPrefetch {
0067         KDNSPrefetchDisabled = 0,
0068         KDNSPrefetchOnlyWWWAndSLD,
0069         KDNSPrefetchEnabled
0070     };
0071 
0072     /**
0073      * This enum specifies the policy for window.open
0074      */
0075     enum KJSWindowOpenPolicy { // ### KDE 5: Remove. Use KParts::HtmlSettingsInterface::JSWindowOpenPolicy instead.
0076         KJSWindowOpenAllow = 0,
0077         KJSWindowOpenAsk,
0078         KJSWindowOpenDeny,
0079         KJSWindowOpenSmart
0080     };
0081 
0082     /**
0083      * This enum specifies the policy for window.status and .defaultStatus
0084      */
0085     enum KJSWindowStatusPolicy { // ### KDE 5: Remove. Use KParts::HtmlSettingsInterface::JSWindowStatusPolicy instead.
0086         KJSWindowStatusAllow = 0,
0087         KJSWindowStatusIgnore
0088     };
0089 
0090     /**
0091      * This enum specifies the policy for window.moveBy and .moveTo
0092      */
0093     enum KJSWindowMovePolicy { // ### KDE 5: Remove. Use KParts::HtmlSettingsInterface::JSWindowMovePolicy instead.
0094         KJSWindowMoveAllow = 0,
0095         KJSWindowMoveIgnore
0096     };
0097 
0098     /**
0099      * This enum specifies the policy for window.resizeBy and .resizeTo
0100      */
0101     enum KJSWindowResizePolicy { // ### KDE 5: Remove. Use KParts::HtmlSettingsInterface::JSWindowStatusPolicy insead.
0102         KJSWindowResizeAllow = 0,
0103         KJSWindowResizeIgnore
0104     };
0105 
0106     /**
0107      * This enum specifies the policy for window.focus
0108      */
0109     enum KJSWindowFocusPolicy { // ### KDE 5: Remove. Use KParts::HtmlSettingsInterface::JSWindowStatusPolicy instead.
0110         KJSWindowFocusAllow = 0,
0111         KJSWindowFocusIgnore
0112     };
0113 
0114     /**
0115      * @internal Constructor
0116      */
0117     KHTMLSettings();
0118     KHTMLSettings(const KHTMLSettings &other);
0119 
0120     /**
0121      * Called by constructor and reparseConfiguration
0122      */
0123     void init();
0124 
0125     /** Read settings from @p config.
0126      * @param config is a pointer to KConfig object.
0127      * @param reset if true, settings are always set; if false,
0128      *  settings are only set if the config file has a corresponding key.
0129      */
0130     void init(KConfig *config, bool reset = true);
0131 
0132     /**
0133      * Destructor. Don't delete any instance by yourself.
0134      */
0135     virtual ~KHTMLSettings();
0136 
0137     // Behavior settings
0138     bool changeCursor() const;
0139     bool underlineLink() const;
0140     bool hoverLink() const;
0141     bool allowTabulation() const;
0142     bool autoSpellCheck() const;
0143     KAnimationAdvice showAnimations() const;
0144     KSmoothScrollingMode smoothScrolling() const;
0145     KDNSPrefetch dnsPrefetch() const;
0146 
0147     // Font settings
0148     QString stdFontName() const;
0149     QString fixedFontName() const;
0150     QString serifFontName() const;
0151     QString sansSerifFontName() const;
0152     QString cursiveFontName() const;
0153     QString fantasyFontName() const;
0154 
0155     // these two can be set. Mainly for historical reasons (the method in KHTMLPart exists...)
0156     void setStdFontName(const QString &n);
0157     void setFixedFontName(const QString &n);
0158 
0159     int minFontSize() const;
0160     int mediumFontSize() const;
0161 
0162     bool jsErrorsEnabled() const;
0163     void setJSErrorsEnabled(bool enabled);
0164 
0165     const QString &encoding() const;
0166 
0167     bool followSystemColors() const;
0168 
0169     // Color settings
0170     const QColor &textColor() const;
0171     const QColor &baseColor() const;
0172     const QColor &linkColor() const;
0173     const QColor &vLinkColor() const;
0174 
0175     // Autoload images
0176     bool autoLoadImages() const;
0177     bool unfinishedImageFrame() const;
0178 
0179     bool isOpenMiddleClickEnabled();
0180     /// @deprecated do not use, feature was moved to be only in konqueror
0181     bool isBackRightClickEnabled();
0182 
0183     // Java and JavaScript
0184     bool isJavaEnabled(const QString &hostname = QString()) const;
0185     bool isJavaScriptEnabled(const QString &hostname = QString()) const;
0186     bool isJavaScriptDebugEnabled(const QString &hostname = QString()) const;
0187     bool isJavaScriptErrorReportingEnabled(const QString &hostname = QString()) const;
0188     bool isPluginsEnabled(const QString &hostname = QString()) const;
0189 
0190     // AdBlocK Filtering
0191 
0192     /** tests whether @p url is filtered.
0193      * @param url the URL to test.
0194      * @return @c true if the URL is blacklisted and is not whitelisted.
0195      */
0196     bool isAdFiltered(const QString &url) const;
0197 
0198     /** identify the filter which matches @p url.
0199      * @param url the URL to test.
0200      * @param isWhiteListed if not @c NULL, set to @c true if the URL matched
0201      * a whitelist filter; set to @c false if it matched a blacklist filter.
0202      * @return the filter string that matched,
0203      * or @c QString() if no filter matched.
0204      * @since 4.4
0205     */
0206     QString adFilteredBy(const QString &url, bool *isWhiteListed = nullptr) const;
0207 
0208     bool isAdFilterEnabled() const;
0209     bool isHideAdsEnabled() const;
0210     void addAdFilter(const QString &url);
0211 
0212     // Access Keys
0213     bool accessKeysEnabled() const;
0214 
0215     // ### KDE 5: Replace KJSWindowOpenPolicy with KParts::HtmlSettingsInterface::JSWindowOpenPolicy
0216     KJSWindowOpenPolicy windowOpenPolicy(const QString &hostname = QString()) const;
0217     KJSWindowMovePolicy windowMovePolicy(const QString &hostname = QString()) const;
0218     KJSWindowResizePolicy windowResizePolicy(const QString &hostname = QString()) const;
0219     KJSWindowStatusPolicy windowStatusPolicy(const QString &hostname = QString()) const;
0220     KJSWindowFocusPolicy windowFocusPolicy(const QString &hostname = QString()) const;
0221 
0222     // helpers for parsing domain-specific configuration, used in KControl module as well
0223     // ### KDE 5: Replace KJavaScriptAdvice with KParts::HtmlSettingsInterface::JavaScriptAdvice.
0224     // ### KDE 5: Remove ? Equivalent functions now exist in KParts::HtmlSettingsInterface.
0225     static KJavaScriptAdvice strToAdvice(const QString &_str);
0226     static void splitDomainAdvice(const QString &configStr, QString &domain,
0227                                   KJavaScriptAdvice &javaAdvice,
0228                                   KJavaScriptAdvice &javaScriptAdvice);
0229     static const char *adviceToStr(KJavaScriptAdvice _advice);
0230 
0231     /** reads from @p config's current group, forcing initialization
0232       * if @p reset is true.
0233       * @param config is a pointer to KConfig object.
0234       * @param reset true if initialization is to be forced.
0235       * @param global true if the global domain is to be read.
0236       * @param pd_settings will be initialised with the computed (inherited)
0237       *     settings.
0238       */
0239     void readDomainSettings(const KConfigGroup &config, bool reset,
0240                             bool global, KPerDomainSettings &pd_settings);
0241 
0242     QString settingsToCSS() const;
0243     static const QString &availableFamilies();
0244 
0245     QString userStyleSheet() const;
0246 
0247     // Form completion
0248     bool isFormCompletionEnabled() const;
0249     int maxFormCompletionItems() const;
0250 
0251     // Meta refresh/redirect (http-equiv)
0252     bool isAutoDelayedActionsEnabled() const;
0253 
0254     QList< QPair< QString, QChar > > fallbackAccessKeysAssignments() const;
0255 
0256     // Whether to show passive popup when windows are blocked
0257     void setJSPopupBlockerPassivePopup(bool enabled);
0258     bool jsPopupBlockerPassivePopup() const;
0259 
0260 private:
0261     friend class KHTMLGlobal;
0262     QString lookupFont(int i) const;
0263 
0264     KHTMLSettingsPrivate *const d;
0265     static QString *avFamilies;
0266 };
0267 
0268 #endif