Patch from Adam Treat to implement default icons / resources for Qt. Also does
a small cleanup to QWebPage::icon. This is a great example of how QWebSettings
is not ideal.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@23733 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 5644c6b..f5a0e2e 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,19 @@
+2007-06-21 Adam Treat <adam@staikos.net>
+
+ Reviewed by George Staikos.
+
+ Implement the default resources on Qt.
+
+ * platform/graphics/BitmapImage.h:
+ * platform/graphics/Image.h:
+ * platform/graphics/qt/ImageQt.cpp:
+ (WebCore::Image::loadPlatformResource):
+ (WebCore::BitmapImage::BitmapImage):
+ (WebCore::BitmapImage::initPlatformData):
+ (WebCore::BitmapImage::invalidatePlatformData):
+ (WebCore::BitmapImage::getPixmap):
+ * platform/qt/TemporaryLinkStubs.cpp:
+
2007-06-21 Oliver Hunt <oliver@apple.com>
Reviewed by Darin.
diff --git a/WebCore/platform/graphics/BitmapImage.h b/WebCore/platform/graphics/BitmapImage.h
index d76172e..5a70808 100644
--- a/WebCore/platform/graphics/BitmapImage.h
+++ b/WebCore/platform/graphics/BitmapImage.h
@@ -89,6 +89,9 @@
class BitmapImage : public Image {
friend class GraphicsContext;
public:
+#if PLATFORM(QT)
+ BitmapImage(const QPixmap &pixmap, ImageObserver* = 0);
+#endif
BitmapImage(ImageObserver* = 0);
~BitmapImage();
@@ -187,6 +190,11 @@
mutable bool m_haveSize; // Whether or not our |m_size| member variable has the final overall image size yet.
bool m_sizeAvailable; // Whether or not we can obtain the size of the first image frame yet from ImageIO.
unsigned m_decodedSize; // The current size of all decoded frames.
+
+#if PLATFORM(QT)
+ QPixmap *m_pixmap;
+#endif
+
};
}
diff --git a/WebCore/platform/graphics/Image.h b/WebCore/platform/graphics/Image.h
index 7784f9a..d4f92c8 100644
--- a/WebCore/platform/graphics/Image.h
+++ b/WebCore/platform/graphics/Image.h
@@ -51,7 +51,7 @@
#endif
#if PLATFORM(QT)
-class QPixmap;
+#include <QPixmap>
#endif
namespace WebCore {
diff --git a/WebCore/platform/graphics/qt/ImageQt.cpp b/WebCore/platform/graphics/qt/ImageQt.cpp
index aba4a87..f3cec6c 100644
--- a/WebCore/platform/graphics/qt/ImageQt.cpp
+++ b/WebCore/platform/graphics/qt/ImageQt.cpp
@@ -49,8 +49,8 @@
#include <math.h>
-// This function loads resources from WebKit
-Vector<char> loadResourceIntoArray(const char*);
+// This function loads resources into WebKit
+QPixmap loadResourcePixmap(const char*);
namespace WebCore {
@@ -71,10 +71,7 @@
Image* Image::loadPlatformResource(const char* name)
{
- Vector<char> arr = loadResourceIntoArray(name);
- Image* img = new BitmapImage();
- RefPtr<SharedBuffer> buffer = new SharedBuffer(arr.data(), arr.size());
- img->setData(buffer, true);
+ BitmapImage* img = new BitmapImage(loadResourcePixmap(name));
return img;
}
@@ -85,13 +82,33 @@
notImplemented();
}
+BitmapImage::BitmapImage(const QPixmap &pixmap, ImageObserver *observer)
+ : Image(observer)
+ , m_currentFrame(0)
+ , m_frames(0)
+ , m_frameTimer(0)
+ , m_repetitionCount(0)
+ , m_repetitionsComplete(0)
+ , m_isSolidColor(false)
+ , m_animatingImageType(true)
+ , m_animationFinished(false)
+ , m_allDataReceived(false)
+ , m_haveSize(false)
+ , m_sizeAvailable(false)
+ , m_decodedSize(0)
+{
+ m_pixmap = new QPixmap(pixmap);
+}
void BitmapImage::initPlatformData()
{
+ m_pixmap = 0;
}
void BitmapImage::invalidatePlatformData()
{
+ delete m_pixmap;
+ m_pixmap = 0;
}
// Drawing Routines
@@ -167,7 +184,10 @@
QPixmap* BitmapImage::getPixmap() const
{
- return const_cast<BitmapImage*>(this)->frameAtIndex(0);
+ if (!m_pixmap)
+ return const_cast<BitmapImage*>(this)->frameAtIndex(0);
+ else
+ return m_pixmap;
}
}
diff --git a/WebCore/platform/qt/TemporaryLinkStubs.cpp b/WebCore/platform/qt/TemporaryLinkStubs.cpp
index c6a9b5b..eb46ae5 100644
--- a/WebCore/platform/qt/TemporaryLinkStubs.cpp
+++ b/WebCore/platform/qt/TemporaryLinkStubs.cpp
@@ -128,8 +128,6 @@
bool AXObjectCache::gAccessibilityEnabled = false;
-Vector<char> loadResourceIntoArray(const char*) { return Vector<char>(); }
-
namespace WebCore {
Vector<String> supportedKeySizes() { notImplemented(); return Vector<String>(); }
diff --git a/WebKitQt/Api/qwebpage.cpp b/WebKitQt/Api/qwebpage.cpp
index 67025d5..c851dec 100644
--- a/WebKitQt/Api/qwebpage.cpp
+++ b/WebKitQt/Api/qwebpage.cpp
@@ -348,13 +348,18 @@
QPixmap QWebPage::icon() const
{
Image* image = iconDatabase()->iconForPageURL(url().toString(), IntSize(16, 16));
+ if (!image || image->isNull()) {
+ image = iconDatabase()->defaultIcon(IntSize(16, 16));
+ }
+
if (!image) {
- return QPixmap();
+ return QPixmap();
}
QPixmap *icon = image->getPixmap();
- Q_ASSERT(icon);
- Q_ASSERT(!icon->isNull());
+ if (!icon) {
+ return QPixmap();
+ }
return *icon;
}
diff --git a/WebKitQt/Api/qwebsettings.cpp b/WebKitQt/Api/qwebsettings.cpp
index fea9e45..53d883f 100644
--- a/WebKitQt/Api/qwebsettings.cpp
+++ b/WebKitQt/Api/qwebsettings.cpp
@@ -60,6 +60,7 @@
int defaultFontSize;
int defaultFixedFontSize;
QHash<int, bool> attributes;
+ QHash<int, QPixmap> graphics;
QString userStyleSheetLocation;
};
@@ -150,6 +151,19 @@
return WebCore::iconDatabase()->enabled() && WebCore::iconDatabase()->isOpen();
}
+void QWebSettings::setWebGraphic(WebGraphic type, const QPixmap &graphic)
+{
+ d->graphics[type] = graphic;
+}
+
+QPixmap QWebSettings::webGraphic(WebGraphic type) const
+{
+ if (d->graphics.contains(type))
+ return d->graphics[type];
+ else
+ return QPixmap();
+}
+
QWebSettings::QWebSettings(const QWebSettings &other)
{
d = other.d;
@@ -187,3 +201,20 @@
return d->attributes[attr];
}
+QPixmap loadResourcePixmap(const char *name)
+{
+ const QWebSettings settings = QWebSettings::global();
+ const QString resource = name;
+
+ QPixmap pixmap;
+ if (resource == "missingImage")
+ pixmap = settings.webGraphic(QWebSettings::MissingImageGraphic);
+ else if (resource == "nullPlugin")
+ pixmap = settings.webGraphic(QWebSettings::MissingPluginGraphic);
+ else if (resource == "urlIcon")
+ pixmap = settings.webGraphic(QWebSettings::DefaultFaviconGraphic);
+ else if (resource == "textAreaResizeCorner")
+ pixmap = settings.webGraphic(QWebSettings::TextAreaResizeCornerGraphic);
+
+ return pixmap;
+}
diff --git a/WebKitQt/Api/qwebsettings.h b/WebKitQt/Api/qwebsettings.h
index fe410e8..2ea2202 100644
--- a/WebKitQt/Api/qwebsettings.h
+++ b/WebKitQt/Api/qwebsettings.h
@@ -26,6 +26,7 @@
#include <qwebkitglobal.h>
#include <QString>
+#include <QPixmap>
#include <QSharedDataPointer>
class QWebPage;
@@ -53,6 +54,12 @@
PrivateBrowsingEnabled,
JavascriptCanOpenWindows
};
+ enum WebGraphic {
+ MissingImageGraphic,
+ MissingPluginGraphic,
+ DefaultFaviconGraphic,
+ TextAreaResizeCornerGraphic
+ };
QWebSettings();
~QWebSettings();
@@ -83,6 +90,9 @@
void setIconDatabaseEnabled(bool enabled, const QString &location = QString());
bool iconDatabaseEnabled() const;
+ void setWebGraphic(WebGraphic type, const QPixmap &graphic);
+ QPixmap webGraphic(WebGraphic type) const;
+
private:
QSharedDataPointer<QWebSettingsPrivate> d;
};
diff --git a/WebKitQt/ChangeLog b/WebKitQt/ChangeLog
index dfdd1a8..9af5de5 100644
--- a/WebKitQt/ChangeLog
+++ b/WebKitQt/ChangeLog
@@ -1,3 +1,17 @@
+2007-06-21 Adam Treat <adam@staikos.net>
+
+ Reviewed by George Staikos.
+
+ Implement the default resources on Qt.
+
+ * Api/qwebpage.cpp:
+ (QWebPage::icon):
+ * Api/qwebsettings.cpp:
+ (QWebSettings::setWebGraphic):
+ (QWebSettings::webGraphic):
+ (loadResourcePixmap):
+ * Api/qwebsettings.h:
+
2007-06-15 Adam Treat <adam@staikos.net>
Reviewed by George Staikos.