Changeset 148095 in webkit


Ignore:
Timestamp:
Apr 10, 2013 8:10:08 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

[Qt] Add API in QWebSettings for setting the CSS media type
https://bugs.webkit.org/show_bug.cgi?id=113853

Patch by Jose Lejin PJ <jose.lejin@gmail.com> on 2013-04-10
Reviewed by Jocelyn Turcotte.

  • Api/qwebsettings.cpp:

(QWebSettingsPrivate):
(QWebSettingsPrivate::apply):
(QWebSettings::setCSSMediaType):
(QWebSettings::cssMediaType):

  • Api/qwebsettings.h:
  • WebCoreSupport/FrameLoaderClientQt.cpp:

(WebCore::FrameLoaderClientQt::overrideMediaType):

  • tests/qwebpage/tst_qwebpage.cpp:

(tst_QWebPage):
(tst_QWebPage::cssMediaTypeGlobalSetting):
(tst_QWebPage::cssMediaTypePageSetting):

Location:
trunk/Source/WebKit/qt
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/qt/Api/qwebsettings.cpp

    r147637 r148095  
    8080    QString localStoragePath;
    8181    QString offlineWebApplicationCachePath;
     82    QString mediaType;
    8283    qint64 offlineStorageDefaultQuota;
    8384    QWebSettings::ThirdPartyCookiePolicy thirdPartyCookiePolicy;
     
    238239        QString storagePath = !localStoragePath.isEmpty() ? localStoragePath : global->localStoragePath;
    239240        settings->setLocalStorageDatabasePath(storagePath);
     241
     242        if (mediaType.isEmpty())
     243            mediaType = global->mediaType;
    240244
    241245        value = attributes.value(QWebSettings::PrintElementBackgrounds,
     
    932936
    933937/*!
     938    Sets the CSS media type to \a type.
     939   
     940    Setting this will override the normal value of the CSS media property.
     941   
     942    \note Setting the value to null QString will restore the default value.
     943*/
     944void QWebSettings::setCSSMediaType(const QString& type)
     945{
     946    d->mediaType = type;
     947    d->apply();
     948}
     949
     950/*!
     951    Returns the current CSS media type.
     952   
     953    \note It will only return the value set through setCSSMediaType and not the one used internally.
     954*/
     955QString QWebSettings::cssMediaType() const
     956{
     957    return d->mediaType;
     958}
     959
     960/*!
    934961    Sets the actual font family to \a family for the specified generic family,
    935962    \a which.
  • trunk/Source/WebKit/qt/Api/qwebsettings.h

    r145833 r148095  
    165165    QWebSettings::ThirdPartyCookiePolicy thirdPartyCookiePolicy() const;
    166166
     167    void setCSSMediaType(const QString&);
     168    QString cssMediaType() const;
     169
    167170    inline QWebSettingsPrivate* handle() const { return d; }
    168171
  • trunk/Source/WebKit/qt/ChangeLog

    r148022 r148095  
     12013-04-10  Jose Lejin PJ  <jose.lejin@gmail.com>
     2
     3        [Qt] Add API in QWebSettings for setting the CSS media type
     4        https://bugs.webkit.org/show_bug.cgi?id=113853
     5
     6        Reviewed by Jocelyn Turcotte.
     7
     8        * Api/qwebsettings.cpp:
     9        (QWebSettingsPrivate):
     10        (QWebSettingsPrivate::apply):
     11        (QWebSettings::setCSSMediaType):
     12        (QWebSettings::cssMediaType):
     13        * Api/qwebsettings.h:
     14        * WebCoreSupport/FrameLoaderClientQt.cpp:
     15        (WebCore::FrameLoaderClientQt::overrideMediaType):
     16        * tests/qwebpage/tst_qwebpage.cpp:
     17        (tst_QWebPage):
     18        (tst_QWebPage::cssMediaTypeGlobalSetting):
     19        (tst_QWebPage::cssMediaTypePageSetting):
     20
    1212013-04-09  Rafael Brandao  <rafael.lobo@openbossa.org>
    222
  • trunk/Source/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp

    r145914 r148095  
    7979#include "qwebhistoryinterface.h"
    8080#include "qwebpluginfactory.h"
     81#include "qwebsettings.h"
    8182
    8283#include <QCoreApplication>
     
    15641565String FrameLoaderClientQt::overrideMediaType() const
    15651566{
     1567    if (m_webFrame && m_webFrame->pageAdapter && m_webFrame->pageAdapter->settings)
     1568        return m_webFrame->pageAdapter->settings->cssMediaType();
     1569
    15661570    return String();
    15671571}
  • trunk/Source/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp

    r142755 r148095  
    188188    void loadSignalsOrder();
    189189    void openWindowDefaultSize();
     190    void cssMediaTypeGlobalSetting();
     191    void cssMediaTypePageSetting();
    190192
    191193#ifdef Q_OS_MAC
     
    32873289}
    32883290
     3291void tst_QWebPage::cssMediaTypeGlobalSetting()
     3292{
     3293    QString testHtml("<style>@media tv {body{background-color:red;}}@media handheld {body{background-color:green;}}@media screen {body{background-color:blue;}}</style>");
     3294    QSignalSpy loadSpy(m_view, SIGNAL(loadFinished(bool)));
     3295
     3296    QWebSettings::globalSettings()->setCSSMediaType("tv");
     3297    // Clear page specific setting to read from global setting
     3298    m_view->page()->settings()->setCSSMediaType(QString());
     3299    m_view->setHtml(testHtml);
     3300    QTRY_COMPARE(loadSpy.count(), 1);
     3301    QVERIFY(m_view->page()->mainFrame()->evaluateJavaScript("window.matchMedia('tv').matches == true").toBool());
     3302    QVERIFY(QWebSettings::globalSettings()->cssMediaType() == "tv");
     3303
     3304    QWebSettings::globalSettings()->setCSSMediaType("handheld");
     3305    // Clear page specific setting to read from global setting
     3306    m_view->page()->settings()->setCSSMediaType(QString());
     3307    m_view->setHtml(testHtml);
     3308    QTRY_COMPARE(loadSpy.count(), 2);
     3309    QVERIFY(m_view->page()->mainFrame()->evaluateJavaScript("window.matchMedia('handheld').matches == true").toBool());
     3310    QVERIFY(QWebSettings::globalSettings()->cssMediaType() == "handheld");
     3311
     3312    QWebSettings::globalSettings()->setCSSMediaType("screen");
     3313    // Clear page specific setting to read from global setting
     3314    m_view->page()->settings()->setCSSMediaType(QString());
     3315    m_view->setHtml(testHtml);
     3316    QTRY_COMPARE(loadSpy.count(), 3);
     3317    QVERIFY(m_view->page()->mainFrame()->evaluateJavaScript("window.matchMedia('screen').matches == true").toBool());
     3318    QVERIFY(QWebSettings::globalSettings()->cssMediaType() == "screen");
     3319}
     3320
     3321void tst_QWebPage::cssMediaTypePageSetting()
     3322{
     3323    QString testHtml("<style>@media tv {body{background-color:red;}}@media handheld {body{background-color:green;}}@media screen {body{background-color:blue;}}</style>");
     3324    QSignalSpy loadSpy(m_view, SIGNAL(loadFinished(bool)));
     3325
     3326    m_view->page()->settings()->setCSSMediaType("tv");
     3327    m_view->setHtml(testHtml);
     3328    QTRY_COMPARE(loadSpy.count(), 1);
     3329    QVERIFY(m_view->page()->mainFrame()->evaluateJavaScript("window.matchMedia('tv').matches == true").toBool());
     3330    QVERIFY(m_view->page()->settings()->cssMediaType() == "tv");
     3331
     3332    m_view->page()->settings()->setCSSMediaType("handheld");
     3333    m_view->setHtml(testHtml);
     3334    QTRY_COMPARE(loadSpy.count(), 2);
     3335    QVERIFY(m_view->page()->mainFrame()->evaluateJavaScript("window.matchMedia('handheld').matches == true").toBool());
     3336    QVERIFY(m_view->page()->settings()->cssMediaType() == "handheld");
     3337
     3338    m_view->page()->settings()->setCSSMediaType("screen");
     3339    m_view->setHtml(testHtml);
     3340    QTRY_COMPARE(loadSpy.count(), 3);
     3341    QVERIFY(m_view->page()->mainFrame()->evaluateJavaScript("window.matchMedia('screen').matches == true").toBool());
     3342    QVERIFY(m_view->page()->settings()->cssMediaType() == "screen");
     3343}
     3344
    32893345QTEST_MAIN(tst_QWebPage)
    32903346#include "tst_qwebpage.moc"
Note: See TracChangeset for help on using the changeset viewer.