#include "config.h"
#include "Image.h"
#include "BitmapImage.h"
#include "FloatRect.h"
#include "PlatformString.h"
#include "GraphicsContext.h"
#include "AffineTransform.h"
#include "NotImplemented.h"
#include "qwebsettings.h"
#include <QPixmap>
#include <QPainter>
#include <QImage>
#include <QImageReader>
#if QT_VERSION >= 0x040300
#include <QTransform>
#endif
#include <QDebug>
#include <math.h>
static QPixmap loadResourcePixmap(const char *name)
{
const QString resource = name;
QPixmap pixmap;
if (resource == "missingImage")
pixmap = QWebSettings::webGraphic(QWebSettings::MissingImageGraphic);
else if (resource == "nullPlugin")
pixmap = QWebSettings::webGraphic(QWebSettings::MissingPluginGraphic);
else if (resource == "urlIcon")
pixmap = QWebSettings::webGraphic(QWebSettings::DefaultFaviconGraphic);
else if (resource == "textAreaResizeCorner")
pixmap = QWebSettings::webGraphic(QWebSettings::TextAreaResizeCornerGraphic);
return pixmap;
}
namespace WebCore {
void FrameData::clear()
{
if (m_frame) {
m_frame = 0;
m_duration = 0.0f;
m_hasAlpha = true;
}
}
Image* Image::loadPlatformResource(const char* name)
{
BitmapImage* img = new BitmapImage(loadResourcePixmap(name));
return img;
}
void Image::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const AffineTransform& patternTransform,
const FloatPoint& phase, CompositeOperator op, const FloatRect& destRect)
{
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;
}
void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dst,
const FloatRect& src, CompositeOperator op)
{
QPixmap* image = nativeImageForCurrentFrame();
if (!image)
return;
if (mayFillWithSolidColor()) {
fillWithSolidColor(ctxt, dst, solidColor(), op);
return;
}
IntSize selfSize = size();
ctxt->save();
ctxt->setCompositeOperation(op);
QPainter* painter(ctxt->platformContext());
painter->drawPixmap(dst, *image, src);
ctxt->restore();
startAnimation();
}
void BitmapImage::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const AffineTransform& patternTransform,
const FloatPoint& phase, CompositeOperator op, const FloatRect& destRect)
{
QPixmap* framePixmap = nativeImageForCurrentFrame();
if (!framePixmap) return;
QPixmap pixmap = *framePixmap;
QRect tr = QRectF(tileRect).toRect();
if (tr.x() || tr.y() || tr.width() != pixmap.width() || tr.height() != pixmap.height()) {
pixmap = pixmap.copy(tr);
}
if (patternTransform.isIdentity()) {
ctxt->save();
ctxt->setCompositeOperation(op);
QPainter* p = ctxt->platformContext();
p->setBrushOrigin(phase);
p->drawTiledPixmap(destRect, pixmap);
ctxt->restore();
} else {
QBrush b(pixmap);
b.setMatrix(patternTransform);
ctxt->save();
ctxt->setCompositeOperation(op);
QPainter* p = ctxt->platformContext();
p->setBrushOrigin(phase);
p->fillRect(destRect, b);
ctxt->restore();
}
}
void BitmapImage::checkForSolidColor()
{
m_isSolidColor = false;
}
QPixmap* BitmapImage::getPixmap() const
{
if (!m_pixmap)
return const_cast<BitmapImage*>(this)->frameAtIndex(0);
else
return m_pixmap;
}
}