Reworked the QWebSettings API.
authorhausmann <hausmann@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Nov 2007 14:31:04 +0000 (14:31 +0000)
committerhausmann <hausmann@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Nov 2007 14:31:04 +0000 (14:31 +0000)
QWebPage now returns a pointer to its mutable QWebSettings object and the settings of newly created QWebPageObjects are initialized from QWebSettings::defaultSettings().

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@27551 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit/qt/Api/qwebpage.cpp
WebKit/qt/Api/qwebpage.h
WebKit/qt/Api/qwebpage_p.h
WebKit/qt/Api/qwebsettings.cpp
WebKit/qt/Api/qwebsettings.h
WebKit/qt/ChangeLog
WebKit/qt/QtLauncher/main.cpp
WebKitTools/ChangeLog
WebKitTools/DumpRenderTree/qt/DumpRenderTree.cpp

index 657221da5a57fa15ff692ab07b9daa620298088f..3998458485c2a6c2fc1b444db650a9e26a5f8e6b 100644 (file)
@@ -86,6 +86,12 @@ QWebPagePrivate::QWebPagePrivate(QWebPage *qq)
     page = new Page(chromeClient, contextMenuClient, editorClient,
                     new DragClientQt(q), new InspectorClientQt());
 
+    // ### should be configurable
+    page->settings()->setDefaultTextEncodingName("iso-8859-1");
+    page->settings()->setDOMPasteAllowed(true);
+
+    settings = new QWebSettings(page->settings());
+
     undoStack = 0;
     mainFrame = 0;
     networkInterface = 0;
@@ -98,6 +104,7 @@ QWebPagePrivate::QWebPagePrivate(QWebPage *qq)
 QWebPagePrivate::~QWebPagePrivate()
 {
     delete undoStack;
+    delete settings;
     delete page;
 }
 
@@ -267,7 +274,7 @@ QWebPage::QWebPage(QWidget *parent)
     : QWidget(parent)
     , d(new QWebPagePrivate(this))
 {
-    setSettings(QWebSettings::global());
+
     QPalette pal = palette();
     pal.setBrush(QPalette::Background, Qt::white);
 
@@ -1168,88 +1175,9 @@ QPixmap QWebPage::icon() const
     return *icon;
 }
 
-void QWebPage::setSettings(const QWebSettings &settings)
-{
-    WebCore::Settings *wSettings = d->page->settings();
-
-    wSettings->setStandardFontFamily(
-        settings.fontFamily(QWebSettings::StandardFont));
-    wSettings->setFixedFontFamily(
-        settings.fontFamily(QWebSettings::FixedFont));
-    wSettings->setSerifFontFamily(
-        settings.fontFamily(QWebSettings::SerifFont));
-    wSettings->setSansSerifFontFamily(
-        settings.fontFamily(QWebSettings::SansSerifFont));
-    wSettings->setCursiveFontFamily(
-        settings.fontFamily(QWebSettings::CursiveFont));
-    wSettings->setFantasyFontFamily(
-        settings.fontFamily(QWebSettings::FantasyFont));
-
-    wSettings->setMinimumFontSize(settings.minimumFontSize());
-    wSettings->setMinimumLogicalFontSize(settings.minimumLogicalFontSize());
-    wSettings->setDefaultFontSize(settings.defaultFontSize());
-    wSettings->setDefaultFixedFontSize(settings.defaultFixedFontSize());
-
-    wSettings->setLoadsImagesAutomatically(
-        settings.testAttribute(QWebSettings::AutoLoadImages));
-    wSettings->setJavaScriptEnabled(
-        settings.testAttribute(QWebSettings::JavascriptEnabled));
-    wSettings->setJavaScriptCanOpenWindowsAutomatically(
-        settings.testAttribute(QWebSettings::JavascriptCanOpenWindows));
-    wSettings->setJavaEnabled(
-        settings.testAttribute(QWebSettings::JavaEnabled));
-    wSettings->setPluginsEnabled(
-        settings.testAttribute(QWebSettings::PluginsEnabled));
-    wSettings->setPrivateBrowsingEnabled(
-        settings.testAttribute(QWebSettings::PrivateBrowsingEnabled));
-
-    wSettings->setUserStyleSheetLocation(KURL(settings.userStyleSheetLocation()));
-
-    // ### should be configurable
-    wSettings->setDefaultTextEncodingName("iso-8859-1");
-    wSettings->setDOMPasteAllowed(true);
-}
-
-QWebSettings QWebPage::settings() const
-{
-    QWebSettings settings;
-    WebCore::Settings *wSettings = d->page->settings();
-
-    settings.setFontFamily(QWebSettings::StandardFont,
-                           wSettings->standardFontFamily());
-    settings.setFontFamily(QWebSettings::FixedFont,
-                           wSettings->fixedFontFamily());
-    settings.setFontFamily(QWebSettings::SerifFont,
-                           wSettings->serifFontFamily());
-    settings.setFontFamily(QWebSettings::SansSerifFont,
-                           wSettings->sansSerifFontFamily());
-    settings.setFontFamily(QWebSettings::CursiveFont,
-                           wSettings->cursiveFontFamily());
-    settings.setFontFamily(QWebSettings::FantasyFont,
-                           wSettings->fantasyFontFamily());
-
-    settings.setMinimumFontSize(wSettings->minimumFontSize());
-    settings.setMinimumLogicalFontSize(wSettings->minimumLogicalFontSize());
-    settings.setDefaultFontSize(wSettings->defaultFontSize());
-    settings.setDefaultFixedFontSize(wSettings->defaultFixedFontSize());
-
-    settings.setAttribute(QWebSettings::AutoLoadImages,
-                          wSettings->loadsImagesAutomatically());
-    settings.setAttribute(QWebSettings::JavascriptEnabled,
-                          wSettings->isJavaScriptEnabled());
-    settings.setAttribute(QWebSettings::JavascriptCanOpenWindows,
-                          wSettings->JavaScriptCanOpenWindowsAutomatically());
-    settings.setAttribute(QWebSettings::JavaEnabled,
-                          wSettings->isJavaEnabled());
-    settings.setAttribute(QWebSettings::PluginsEnabled,
-                          wSettings->arePluginsEnabled());
-    settings.setAttribute(QWebSettings::PrivateBrowsingEnabled,
-                          wSettings->privateBrowsingEnabled());
-
-    settings.setUserStyleSheetLocation(
-        wSettings->userStyleSheetLocation().url());
-
-    return settings;
+QWebSettings *QWebPage::settings()
+{
+    return d->settings;
 }
 
 QString QWebPage::chooseFile(QWebFrame *parentFrame, const QString& oldFile)
index 9bd8c4841da7ce01618496a1e636c24e573239bc..5bb094dc3d6055e01689ff83b59d4be2eb5cc64b 100644 (file)
@@ -135,9 +135,7 @@ public:
 
     QWebPageHistory *history() const;
 
-    // ### owned by webpage, returns a pointer, no setter!
-    void setSettings(const QWebSettings &settings);
-    QWebSettings settings() const;
+    QWebSettings *settings();
 
     QSize sizeHint() const;
 
index 210cae13fb6bf72379f486d5ae654a8b3beb7e30..7f56b551b20461845174d3113bf515aa3185b56f 100644 (file)
@@ -120,6 +120,7 @@ public:
 
     QWebPageHistory history;
     QWebPageContext currentContext;
+    QWebSettings *settings;
 
     QAction *actions[QWebPage::NumWebActions];
 };
index d89b163637813985aff6044a32d64000e65f70db..e86e5bd5ac60361c40e05dbb07d9494143a2c24c 100644 (file)
 #include <QHash>
 #include <QSharedData>
 
-class QWebSettingsPrivate : public QSharedData
+class QWebSettingsPrivate
 {
 public:
-    QWebSettingsPrivate()
+    QWebSettingsPrivate(WebCore::Settings *wcSettings = 0)
         : minimumFontSize(5),
           minimumLogicalFontSize(5),
           defaultFontSize(14),
-          defaultFixedFontSize(14)
+          defaultFixedFontSize(14),
+          settings(wcSettings)
     {
-        //Initialize our defaults
+        // Initialize our defaults
         // changing any of those will likely break the LayoutTests
-        fontFamilies[QWebSettings::StandardFont] = QLatin1String("Arial");
-        fontFamilies[QWebSettings::FixedFont] = QLatin1String("Courier");
-        fontFamilies[QWebSettings::SerifFont] = QLatin1String("Times New Roman");
-        fontFamilies[QWebSettings::SansSerifFont] = QLatin1String("Arial");
-
-        attributes[QWebSettings::AutoLoadImages]           = true;
-        attributes[QWebSettings::JavascriptEnabled]        = true;
+        fontFamilies.insert(QWebSettings::StandardFont, QLatin1String("Arial"));
+        fontFamilies.insert(QWebSettings::StandardFont, QLatin1String("Arial"));
+        fontFamilies.insert(QWebSettings::FixedFont, QLatin1String("Courier"));
+        fontFamilies.insert(QWebSettings::SerifFont, QLatin1String("Times New Roman"));
+        fontFamilies.insert(QWebSettings::SansSerifFont, QLatin1String("Arial"));
+
+        attributes.insert(QWebSettings::AutoLoadImages, true);
+        attributes.insert(QWebSettings::JavascriptEnabled, true);
     }
 
     QHash<int, QString> fontFamilies;
@@ -61,18 +63,63 @@ public:
     int defaultFixedFontSize;
     QHash<int, bool> attributes;
     QString userStyleSheetLocation;
+
+    void apply();
+    WebCore::Settings *settings;
 };
 
 typedef QHash<int, QPixmap> WebGraphicHash;
 Q_GLOBAL_STATIC(WebGraphicHash, graphics)
 
-static QWebSettings globalSettings;
+void QWebSettingsPrivate::apply()
+{
+    if (!settings)
+        return;
+
+    settings->setStandardFontFamily(fontFamilies.value(QWebSettings::StandardFont));
+    settings->setFixedFontFamily(fontFamilies.value(QWebSettings::FixedFont));
+    settings->setSerifFontFamily(fontFamilies.value(QWebSettings::SerifFont));
+    settings->setSansSerifFontFamily(fontFamilies.value(QWebSettings::SansSerifFont));
+    settings->setCursiveFontFamily(fontFamilies.value(QWebSettings::CursiveFont));
+    settings->setFantasyFontFamily(fontFamilies.value(QWebSettings::FantasyFont));
+
+    settings->setMinimumFontSize(minimumFontSize);
+    settings->setMinimumLogicalFontSize(minimumLogicalFontSize);
+    settings->setDefaultFontSize(defaultFontSize);
+    settings->setDefaultFixedFontSize(defaultFixedFontSize);
+
+    settings->setLoadsImagesAutomatically(attributes.value(QWebSettings::AutoLoadImages));
+    settings->setJavaScriptEnabled(attributes.value(QWebSettings::JavascriptEnabled));
+    settings->setJavaScriptCanOpenWindowsAutomatically(attributes.value(QWebSettings::JavascriptCanOpenWindows));
+    settings->setJavaEnabled(attributes.value(QWebSettings::JavaEnabled));
+    settings->setPluginsEnabled(attributes.value(QWebSettings::PluginsEnabled));
+    settings->setPrivateBrowsingEnabled(attributes.value(QWebSettings::PrivateBrowsingEnabled));
+
+    settings->setUserStyleSheetLocation(WebCore::KURL(userStyleSheetLocation));
+}
+
+QWebSettings *QWebSettings::defaultSettings()
+{
+    static QWebSettings *global = 0;
+    if (!global)
+        global = new QWebSettings;
+    return global;
+}
 
 QWebSettings::QWebSettings()
     : d(new QWebSettingsPrivate)
 {
 }
 
+QWebSettings::QWebSettings(WebCore::Settings *settings)
+    : d(new QWebSettingsPrivate(settings))
+{
+    // inherit the global default settings
+    *d = *defaultSettings()->d;
+    d->settings = settings;
+    d->apply();
+}
+
 QWebSettings::~QWebSettings()
 {
 }
@@ -80,6 +127,7 @@ QWebSettings::~QWebSettings()
 void QWebSettings::setMinimumFontSize(int size)
 {
     d->minimumFontSize = size;
+    d->apply();
 }
 
 
@@ -92,6 +140,7 @@ int QWebSettings::minimumFontSize() const
 void QWebSettings::setMinimumLogicalFontSize(int size)
 {
     d->minimumLogicalFontSize = size;
+    d->apply();
 }
 
 
@@ -104,6 +153,7 @@ int QWebSettings::minimumLogicalFontSize() const
 void QWebSettings::setDefaultFontSize(int size)
 {
     d->defaultFontSize = size;
+    d->apply();
 }
 
 
@@ -116,6 +166,7 @@ int QWebSettings::defaultFontSize() const
 void QWebSettings::setDefaultFixedFontSize(int size)
 {
     d->defaultFixedFontSize = size;
+    d->apply();
 }
 
 
@@ -127,6 +178,7 @@ int QWebSettings::defaultFixedFontSize() const
 void QWebSettings::setUserStyleSheetLocation(const QString &location)
 {
     d->userStyleSheetLocation = location;
+    d->apply();
 }
 
 QString QWebSettings::userStyleSheetLocation() const
@@ -167,46 +219,25 @@ QPixmap QWebSettings::webGraphic(WebGraphic type)
     return graphics()->value(type);
 }
 
-QWebSettings::QWebSettings(const QWebSettings &other)
-{
-    d = other.d;
-}
-
-QWebSettings &QWebSettings::operator=(const QWebSettings &other)
-{
-    d = other.d;
-    return *this;
-}
-
-void QWebSettings::setGlobal(const QWebSettings &settings)
-{
-    globalSettings = settings;
-}
-
-QWebSettings QWebSettings::global()
-{
-    return globalSettings;
-}
-
 void QWebSettings::setFontFamily(FontType type, const QString &family)
 {
-    d->fontFamilies[type] = family;
+    d->fontFamilies.insert(type, family);
+    d->apply();
 }
 
 QString QWebSettings::fontFamily(FontType type) const
 {
-    return d->fontFamilies[type];
+    return d->fontFamilies.value(type);
 }
 
 void QWebSettings::setAttribute(WebAttribute attr, bool on)
 {
-    d->attributes[attr] = on;
+    d->attributes.insert(attr, on);
+    d->apply();
 }
 
 bool QWebSettings::testAttribute(WebAttribute attr) const
 {
-    if (!d->attributes.contains(attr))
-        return false;
-    return d->attributes[attr];
+    return d->attributes.value(attr);
 }
 
index f0b5132b5228acfd8457b16127d6c3538779ef22..97c487ffa5841f8ef6399aa30dc72b2b0fe3c22e 100644 (file)
 #include <QPixmap>
 #include <QSharedDataPointer>
 
+namespace WebCore
+{
+    class Settings;
+};
+
 class QWebPage;
 class QWebSettingsPrivate;
 
 class QWEBKIT_EXPORT QWebSettings
 {
-public:
-    static void setGlobal(const QWebSettings &settings);
-    static QWebSettings global();
 public:
     enum FontType {
         StandardFont,
@@ -61,11 +63,7 @@ public:
         TextAreaResizeCornerGraphic
     };
 
-    QWebSettings();
-    ~QWebSettings();
-
-    QWebSettings(const QWebSettings &);
-    QWebSettings &operator=(const QWebSettings &);
+    static QWebSettings *defaultSettings();
 
     void setFontFamily(FontType type, const QString &family);
     QString fontFamily(FontType type) const;
@@ -95,7 +93,15 @@ public:
     static QPixmap webGraphic(WebGraphic type);
 
 private:
-    QSharedDataPointer<QWebSettingsPrivate> d;
+    friend class QWebPagePrivate;
+
+    Q_DISABLE_COPY(QWebSettings)
+
+    QWebSettings();
+    QWebSettings(WebCore::Settings *settings);
+    ~QWebSettings();
+
+    QWebSettingsPrivate *d;
 };
 
 #endif
index 7bc95a040689f2959abe74710f3c0b81faf5ead9..d888c48d4b914e821a83ad777d723bf3a7473f95 100644 (file)
@@ -1,3 +1,33 @@
+2007-11-07  Simon Hausmann  <hausmann@kde.org>
+
+        Reviewed by Lars.
+
+        Reworked the QWebSettings API.
+        QWebPage now returns a pointer to its mutable QWebSettings object and the settings of newly created QWebPageObjects are initialized from QWebSettings::defaultSettings().
+
+        * Api/qwebpage.cpp:
+        (QWebPagePrivate::QWebPagePrivate):
+        (QWebPagePrivate::~QWebPagePrivate):
+        (QWebPage::QWebPage):
+        * Api/qwebpage.h:
+        * Api/qwebpage_p.h:
+        * Api/qwebsettings.cpp:
+        (QWebSettingsPrivate::QWebSettingsPrivate):
+        (QWebSettingsPrivate::apply):
+        (QWebSettings::defaultSettings):
+        (QWebSettings::QWebSettings):
+        (QWebSettings::setMinimumFontSize):
+        (QWebSettings::setMinimumLogicalFontSize):
+        (QWebSettings::setDefaultFontSize):
+        (QWebSettings::setDefaultFixedFontSize):
+        (QWebSettings::setUserStyleSheetLocation):
+        (QWebSettings::setFontFamily):
+        (QWebSettings::fontFamily):
+        (QWebSettings::setAttribute):
+        * Api/qwebsettings.h:
+        * QtLauncher/main.cpp:
+        (main):
+
 2007-11-07  Simon Hausmann  <hausmann@kde.org>
 
         Reviewed by Lars.
index b96cf060f81d57871d9b5f748430672def16c4b4..476bac4d61dc431dc63685f49844102b0312d7d5 100644 (file)
@@ -378,9 +378,7 @@ int main(int argc, char **argv)
     QString url = QString("%1/%2").arg(QDir::homePath()).arg(QLatin1String("index.html"));
     QApplication app(argc, argv);
 
-    QWebSettings settings = QWebSettings::global();
-    settings.setAttribute(QWebSettings::PluginsEnabled);
-    QWebSettings::setGlobal(settings);
+    QWebSettings::defaultSettings()->setAttribute(QWebSettings::PluginsEnabled);
 
     const QStringList args = app.arguments();
     if (args.count() > 1)
index 62e907112f27c7cc4782de51b01e1fc42c419646..5c24a0912be96b7305414429d582e7799af3b409 100644 (file)
@@ -1,3 +1,12 @@
+2007-11-07  Simon Hausmann  <hausmann@kde.org>
+
+        Reviewed by Lars.
+
+        Reworked the QWebSettings API.
+        QWebPage now returns a pointer to its mutable QWebSettings object and the settings of newly created QWebPageObjects are initialized from QWebSettings::defaultSettings().
+
+        * DumpRenderTree/qt/DumpRenderTree.cpp:
+
 2007-11-07  Simon Hausmann  <hausmann@kde.org>
 
         Reviewed by Lars.
index 3195c3f77770ccb414a0d549ff3865a6afc87eb7..d6047591808836dee14245dc5299ef9bd852cc8d 100644 (file)
@@ -73,9 +73,7 @@ private:
 WebPage::WebPage(QWidget *parent, DumpRenderTree *drt)
     : QWebPage(parent), m_drt(drt)
 {
-    QWebSettings s = settings();
-    s.setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
-    setSettings(s);
+    settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
 }
 
 QWebPage *WebPage::createWindow()