Title: [148095] trunk/Source/WebKit/qt
- Revision
- 148095
- Author
- [email protected]
- Date
- 2013-04-10 08:10:08 -0700 (Wed, 10 Apr 2013)
Log 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 <[email protected]> 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):
Modified Paths
Diff
Modified: trunk/Source/WebKit/qt/Api/qwebsettings.cpp (148094 => 148095)
--- trunk/Source/WebKit/qt/Api/qwebsettings.cpp 2013-04-10 14:58:37 UTC (rev 148094)
+++ trunk/Source/WebKit/qt/Api/qwebsettings.cpp 2013-04-10 15:10:08 UTC (rev 148095)
@@ -79,6 +79,7 @@
QString defaultTextEncoding;
QString localStoragePath;
QString offlineWebApplicationCachePath;
+ QString mediaType;
qint64 offlineStorageDefaultQuota;
QWebSettings::ThirdPartyCookiePolicy thirdPartyCookiePolicy;
void apply();
@@ -238,6 +239,9 @@
QString storagePath = !localStoragePath.isEmpty() ? localStoragePath : global->localStoragePath;
settings->setLocalStorageDatabasePath(storagePath);
+ if (mediaType.isEmpty())
+ mediaType = global->mediaType;
+
value = attributes.value(QWebSettings::PrintElementBackgrounds,
global->attributes.value(QWebSettings::PrintElementBackgrounds));
settings->setShouldPrintBackgrounds(value);
@@ -931,6 +935,29 @@
}
/*!
+ Sets the CSS media type to \a type.
+
+ Setting this will override the normal value of the CSS media property.
+
+ \note Setting the value to null QString will restore the default value.
+*/
+void QWebSettings::setCSSMediaType(const QString& type)
+{
+ d->mediaType = type;
+ d->apply();
+}
+
+/*!
+ Returns the current CSS media type.
+
+ \note It will only return the value set through setCSSMediaType and not the one used internally.
+*/
+QString QWebSettings::cssMediaType() const
+{
+ return d->mediaType;
+}
+
+/*!
Sets the actual font family to \a family for the specified generic family,
\a which.
*/
Modified: trunk/Source/WebKit/qt/Api/qwebsettings.h (148094 => 148095)
--- trunk/Source/WebKit/qt/Api/qwebsettings.h 2013-04-10 14:58:37 UTC (rev 148094)
+++ trunk/Source/WebKit/qt/Api/qwebsettings.h 2013-04-10 15:10:08 UTC (rev 148095)
@@ -164,6 +164,9 @@
void setThirdPartyCookiePolicy(ThirdPartyCookiePolicy);
QWebSettings::ThirdPartyCookiePolicy thirdPartyCookiePolicy() const;
+ void setCSSMediaType(const QString&);
+ QString cssMediaType() const;
+
inline QWebSettingsPrivate* handle() const { return d; }
private:
Modified: trunk/Source/WebKit/qt/ChangeLog (148094 => 148095)
--- trunk/Source/WebKit/qt/ChangeLog 2013-04-10 14:58:37 UTC (rev 148094)
+++ trunk/Source/WebKit/qt/ChangeLog 2013-04-10 15:10:08 UTC (rev 148095)
@@ -1,3 +1,23 @@
+2013-04-10 Jose Lejin PJ <[email protected]>
+
+ [Qt] Add API in QWebSettings for setting the CSS media type
+ https://bugs.webkit.org/show_bug.cgi?id=113853
+
+ 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):
+
2013-04-09 Rafael Brandao <[email protected]>
[CoordinatedGraphics] serviceScriptedAnimations expects time in seconds
Modified: trunk/Source/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp (148094 => 148095)
--- trunk/Source/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp 2013-04-10 14:58:37 UTC (rev 148094)
+++ trunk/Source/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp 2013-04-10 15:10:08 UTC (rev 148095)
@@ -78,6 +78,7 @@
#include "qwebhistory_p.h"
#include "qwebhistoryinterface.h"
#include "qwebpluginfactory.h"
+#include "qwebsettings.h"
#include <QCoreApplication>
#include <QDebug>
@@ -1563,6 +1564,9 @@
String FrameLoaderClientQt::overrideMediaType() const
{
+ if (m_webFrame && m_webFrame->pageAdapter && m_webFrame->pageAdapter->settings)
+ return m_webFrame->pageAdapter->settings->cssMediaType();
+
return String();
}
Modified: trunk/Source/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp (148094 => 148095)
--- trunk/Source/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp 2013-04-10 14:58:37 UTC (rev 148094)
+++ trunk/Source/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp 2013-04-10 15:10:08 UTC (rev 148095)
@@ -187,6 +187,8 @@
void loadSignalsOrder_data();
void loadSignalsOrder();
void openWindowDefaultSize();
+ void cssMediaTypeGlobalSetting();
+ void cssMediaTypePageSetting();
#ifdef Q_OS_MAC
void macCopyUnicodeToClipboard();
@@ -3286,5 +3288,59 @@
QVERIFY(requestedGeometry.height() == 100);
}
+void tst_QWebPage::cssMediaTypeGlobalSetting()
+{
+ QString testHtml("<style>@media tv {body{background-color:red;}}@media handheld {body{background-color:green;}}@media screen {body{background-color:blue;}}</style>");
+ QSignalSpy loadSpy(m_view, SIGNAL(loadFinished(bool)));
+
+ QWebSettings::globalSettings()->setCSSMediaType("tv");
+ // Clear page specific setting to read from global setting
+ m_view->page()->settings()->setCSSMediaType(QString());
+ m_view->setHtml(testHtml);
+ QTRY_COMPARE(loadSpy.count(), 1);
+ QVERIFY(m_view->page()->mainFrame()->evaluateJavaScript("window.matchMedia('tv').matches == true").toBool());
+ QVERIFY(QWebSettings::globalSettings()->cssMediaType() == "tv");
+
+ QWebSettings::globalSettings()->setCSSMediaType("handheld");
+ // Clear page specific setting to read from global setting
+ m_view->page()->settings()->setCSSMediaType(QString());
+ m_view->setHtml(testHtml);
+ QTRY_COMPARE(loadSpy.count(), 2);
+ QVERIFY(m_view->page()->mainFrame()->evaluateJavaScript("window.matchMedia('handheld').matches == true").toBool());
+ QVERIFY(QWebSettings::globalSettings()->cssMediaType() == "handheld");
+
+ QWebSettings::globalSettings()->setCSSMediaType("screen");
+ // Clear page specific setting to read from global setting
+ m_view->page()->settings()->setCSSMediaType(QString());
+ m_view->setHtml(testHtml);
+ QTRY_COMPARE(loadSpy.count(), 3);
+ QVERIFY(m_view->page()->mainFrame()->evaluateJavaScript("window.matchMedia('screen').matches == true").toBool());
+ QVERIFY(QWebSettings::globalSettings()->cssMediaType() == "screen");
+}
+
+void tst_QWebPage::cssMediaTypePageSetting()
+{
+ QString testHtml("<style>@media tv {body{background-color:red;}}@media handheld {body{background-color:green;}}@media screen {body{background-color:blue;}}</style>");
+ QSignalSpy loadSpy(m_view, SIGNAL(loadFinished(bool)));
+
+ m_view->page()->settings()->setCSSMediaType("tv");
+ m_view->setHtml(testHtml);
+ QTRY_COMPARE(loadSpy.count(), 1);
+ QVERIFY(m_view->page()->mainFrame()->evaluateJavaScript("window.matchMedia('tv').matches == true").toBool());
+ QVERIFY(m_view->page()->settings()->cssMediaType() == "tv");
+
+ m_view->page()->settings()->setCSSMediaType("handheld");
+ m_view->setHtml(testHtml);
+ QTRY_COMPARE(loadSpy.count(), 2);
+ QVERIFY(m_view->page()->mainFrame()->evaluateJavaScript("window.matchMedia('handheld').matches == true").toBool());
+ QVERIFY(m_view->page()->settings()->cssMediaType() == "handheld");
+
+ m_view->page()->settings()->setCSSMediaType("screen");
+ m_view->setHtml(testHtml);
+ QTRY_COMPARE(loadSpy.count(), 3);
+ QVERIFY(m_view->page()->mainFrame()->evaluateJavaScript("window.matchMedia('screen').matches == true").toBool());
+ QVERIFY(m_view->page()->settings()->cssMediaType() == "screen");
+}
+
QTEST_MAIN(tst_QWebPage)
#include "tst_qwebpage.moc"
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes