blob: b9af57b7b18d9cb4e7e1d492b54286f1a065ed1d [file] [log] [blame]
rwlbuis98021982006-08-23 21:04:08 +00001/*
2 * Copyright (C) 2006 Dirk Mueller <mueller@kde.org>
3 * Copyright (C) 2006 Zack Rusin <zack@kde.org>
4 * Copyright (C) 2006 Simon Hausmann <hausmann@kde.org>
5 *
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#include "config.h"
31#include "Image.h"
32
eseidel61952852006-12-29 01:57:44 +000033#include "BitmapImage.h"
rwlbuis98021982006-08-23 21:04:08 +000034#include "FloatRect.h"
apc5efe7e2006-09-06 17:17:42 +000035#include "PlatformString.h"
rwlbuis98021982006-08-23 21:04:08 +000036#include "GraphicsContext.h"
dino@apple.com0cf2dc92009-01-06 03:00:14 +000037#include "TransformationMatrix.h"
kevino64ee95c2007-05-28 00:39:59 +000038#include "NotImplemented.h"
hausmann@webkit.orgedf35132008-05-08 14:58:01 +000039#include "StillImageQt.h"
hausmann15e7c0e2007-11-07 14:30:50 +000040#include "qwebsettings.h"
rwlbuis98021982006-08-23 21:04:08 +000041
42#include <QPixmap>
43#include <QPainter>
44#include <QImage>
45#include <QImageReader>
staikos309162b2007-01-23 18:18:19 +000046#if QT_VERSION >= 0x040300
larsf6076a42007-01-17 19:04:39 +000047#include <QTransform>
staikos309162b2007-01-23 18:18:19 +000048#endif
rwlbuis98021982006-08-23 21:04:08 +000049
larsf6076a42007-01-17 19:04:39 +000050#include <QDebug>
rwlbuis98021982006-08-23 21:04:08 +000051
52#include <math.h>
53
staikoscdc883d2007-06-22 03:29:41 +000054// This function loads resources into WebKit
hausmann15e7c0e2007-11-07 14:30:50 +000055static QPixmap loadResourcePixmap(const char *name)
56{
hausmann15e7c0e2007-11-07 14:30:50 +000057 QPixmap pixmap;
hausmann@webkit.orge13b7c42008-04-24 10:20:51 +000058 if (qstrcmp(name, "missingImage") == 0)
hausmann2dd43062007-11-07 14:30:57 +000059 pixmap = QWebSettings::webGraphic(QWebSettings::MissingImageGraphic);
hausmann@webkit.orge13b7c42008-04-24 10:20:51 +000060 else if (qstrcmp(name, "nullPlugin") == 0)
hausmann2dd43062007-11-07 14:30:57 +000061 pixmap = QWebSettings::webGraphic(QWebSettings::MissingPluginGraphic);
hausmann@webkit.orge13b7c42008-04-24 10:20:51 +000062 else if (qstrcmp(name, "urlIcon") == 0)
hausmann@webkit.org90a2a202008-04-18 14:53:06 +000063 pixmap = QWebSettings::webGraphic(QWebSettings::DefaultFrameIconGraphic);
hausmann@webkit.orge13b7c42008-04-24 10:20:51 +000064 else if (qstrcmp(name, "textAreaResizeCorner") == 0)
hausmann@webkit.org90a2a202008-04-18 14:53:06 +000065 pixmap = QWebSettings::webGraphic(QWebSettings::TextAreaSizeGripCornerGraphic);
hausmann15e7c0e2007-11-07 14:30:50 +000066
67 return pixmap;
68}
rwlbuis98021982006-08-23 21:04:08 +000069
70namespace WebCore {
71
pkasting@chromium.orga2910e12009-01-09 18:46:51 +000072bool FrameData::clear(bool clearMetadata)
rwlbuis98021982006-08-23 21:04:08 +000073{
pkasting@chromium.orga2910e12009-01-09 18:46:51 +000074 if (clearMetadata)
75 m_haveMetadata = false;
76
rwlbuis98021982006-08-23 21:04:08 +000077 if (m_frame) {
78 m_frame = 0;
pkasting@chromium.orga2910e12009-01-09 18:46:51 +000079 return true;
rwlbuis98021982006-08-23 21:04:08 +000080 }
pkasting@chromium.orga2910e12009-01-09 18:46:51 +000081 return false;
rwlbuis98021982006-08-23 21:04:08 +000082}
83
larsf6076a42007-01-17 19:04:39 +000084
85
rwlbuis98021982006-08-23 21:04:08 +000086// ================================================
87// Image Class
88// ================================================
89
eric@webkit.orgac3f6662008-08-14 01:15:50 +000090PassRefPtr<Image> Image::loadPlatformResource(const char* name)
rwlbuis98021982006-08-23 21:04:08 +000091{
eric@webkit.orgac3f6662008-08-14 01:15:50 +000092 return StillImage::create(loadResourcePixmap(name));
rwlbuis98021982006-08-23 21:04:08 +000093}
94
larsf6076a42007-01-17 19:04:39 +000095
dino@apple.com0cf2dc92009-01-06 03:00:14 +000096void Image::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const TransformationMatrix& patternTransform,
larsf6076a42007-01-17 19:04:39 +000097 const FloatPoint& phase, CompositeOperator op, const FloatRect& destRect)
98{
hausmann@webkit.org42009bb2009-02-07 15:33:19 +000099 QPixmap* framePixmap = nativeImageForCurrentFrame();
100 if (!framePixmap) // If it's too early we won't have an image yet.
101 return;
102
103 QPixmap pixmap = *framePixmap;
104 QRect tr = QRectF(tileRect).toRect();
105 if (tr.x() || tr.y() || tr.width() != pixmap.width() || tr.height() != pixmap.height()) {
106 pixmap = pixmap.copy(tr);
107 }
108
109 QBrush b(pixmap);
110 b.setMatrix(patternTransform);
111 ctxt->save();
112 ctxt->setCompositeOperation(op);
113 QPainter* p = ctxt->platformContext();
114 p->setBrushOrigin(phase);
115 p->fillRect(destRect, b);
116 ctxt->restore();
larsf6076a42007-01-17 19:04:39 +0000117}
118
larsf6076a42007-01-17 19:04:39 +0000119void BitmapImage::initPlatformData()
120{
121}
122
123void BitmapImage::invalidatePlatformData()
124{
125}
126
rwlbuis98021982006-08-23 21:04:08 +0000127// Drawing Routines
eseidel61952852006-12-29 01:57:44 +0000128void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dst,
larsf6076a42007-01-17 19:04:39 +0000129 const FloatRect& src, CompositeOperator op)
rwlbuis98021982006-08-23 21:04:08 +0000130{
pkasting@chromium.orge8a5a6b2008-10-15 20:38:13 +0000131 startAnimation();
132
larsf6076a42007-01-17 19:04:39 +0000133 QPixmap* image = nativeImageForCurrentFrame();
134 if (!image)
rwlbuis98021982006-08-23 21:04:08 +0000135 return;
larsf6076a42007-01-17 19:04:39 +0000136
137 if (mayFillWithSolidColor()) {
138 fillWithSolidColor(ctxt, dst, solidColor(), op);
rwlbuis98021982006-08-23 21:04:08 +0000139 return;
larsf6076a42007-01-17 19:04:39 +0000140 }
rwlbuis98021982006-08-23 21:04:08 +0000141
142 IntSize selfSize = size();
rwlbuis98021982006-08-23 21:04:08 +0000143
144 ctxt->save();
145
146 // Set the compositing operation.
147 ctxt->setCompositeOperation(op);
148
aroben8c8a13e2006-08-24 18:32:46 +0000149 QPainter* painter(ctxt->platformContext());
rwlbuis98021982006-08-23 21:04:08 +0000150
151 // Test using example site at
152 // http://www.meyerweb.com/eric/css/edge/complexspiral/demo.html
zackbfb63512007-01-15 17:19:24 +0000153 painter->drawPixmap(dst, *image, src);
rwlbuis98021982006-08-23 21:04:08 +0000154
155 ctxt->restore();
rwlbuis98021982006-08-23 21:04:08 +0000156}
157
eseidel61952852006-12-29 01:57:44 +0000158void BitmapImage::checkForSolidColor()
rwlbuis98021982006-08-23 21:04:08 +0000159{
160 // FIXME: It's easy to implement this optimization. Just need to check the RGBA32 buffer to see if it is 1x1.
161 m_isSolidColor = false;
162}
163
164}
165
eseidel61952852006-12-29 01:57:44 +0000166
rwlbuis98021982006-08-23 21:04:08 +0000167// vim: ts=4 sw=4 et