rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
eseidel | 6195285 | 2006-12-29 01:57:44 +0000 | [diff] [blame] | 33 | #include "BitmapImage.h" |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 34 | #include "FloatRect.h" |
ap | c5efe7e | 2006-09-06 17:17:42 +0000 | [diff] [blame] | 35 | #include "PlatformString.h" |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 36 | #include "GraphicsContext.h" |
dino@apple.com | 0cf2dc9 | 2009-01-06 03:00:14 +0000 | [diff] [blame] | 37 | #include "TransformationMatrix.h" |
kevino | 64ee95c | 2007-05-28 00:39:59 +0000 | [diff] [blame] | 38 | #include "NotImplemented.h" |
hausmann@webkit.org | edf3513 | 2008-05-08 14:58:01 +0000 | [diff] [blame] | 39 | #include "StillImageQt.h" |
hausmann | 15e7c0e | 2007-11-07 14:30:50 +0000 | [diff] [blame] | 40 | #include "qwebsettings.h" |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 41 | |
| 42 | #include <QPixmap> |
| 43 | #include <QPainter> |
| 44 | #include <QImage> |
| 45 | #include <QImageReader> |
staikos | 309162b | 2007-01-23 18:18:19 +0000 | [diff] [blame] | 46 | #if QT_VERSION >= 0x040300 |
lars | f6076a4 | 2007-01-17 19:04:39 +0000 | [diff] [blame] | 47 | #include <QTransform> |
staikos | 309162b | 2007-01-23 18:18:19 +0000 | [diff] [blame] | 48 | #endif |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 49 | |
lars | f6076a4 | 2007-01-17 19:04:39 +0000 | [diff] [blame] | 50 | #include <QDebug> |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 51 | |
| 52 | #include <math.h> |
| 53 | |
staikos | cdc883d | 2007-06-22 03:29:41 +0000 | [diff] [blame] | 54 | // This function loads resources into WebKit |
hausmann | 15e7c0e | 2007-11-07 14:30:50 +0000 | [diff] [blame] | 55 | static QPixmap loadResourcePixmap(const char *name) |
| 56 | { |
hausmann | 15e7c0e | 2007-11-07 14:30:50 +0000 | [diff] [blame] | 57 | QPixmap pixmap; |
hausmann@webkit.org | e13b7c4 | 2008-04-24 10:20:51 +0000 | [diff] [blame] | 58 | if (qstrcmp(name, "missingImage") == 0) |
hausmann | 2dd4306 | 2007-11-07 14:30:57 +0000 | [diff] [blame] | 59 | pixmap = QWebSettings::webGraphic(QWebSettings::MissingImageGraphic); |
hausmann@webkit.org | e13b7c4 | 2008-04-24 10:20:51 +0000 | [diff] [blame] | 60 | else if (qstrcmp(name, "nullPlugin") == 0) |
hausmann | 2dd4306 | 2007-11-07 14:30:57 +0000 | [diff] [blame] | 61 | pixmap = QWebSettings::webGraphic(QWebSettings::MissingPluginGraphic); |
hausmann@webkit.org | e13b7c4 | 2008-04-24 10:20:51 +0000 | [diff] [blame] | 62 | else if (qstrcmp(name, "urlIcon") == 0) |
hausmann@webkit.org | 90a2a20 | 2008-04-18 14:53:06 +0000 | [diff] [blame] | 63 | pixmap = QWebSettings::webGraphic(QWebSettings::DefaultFrameIconGraphic); |
hausmann@webkit.org | e13b7c4 | 2008-04-24 10:20:51 +0000 | [diff] [blame] | 64 | else if (qstrcmp(name, "textAreaResizeCorner") == 0) |
hausmann@webkit.org | 90a2a20 | 2008-04-18 14:53:06 +0000 | [diff] [blame] | 65 | pixmap = QWebSettings::webGraphic(QWebSettings::TextAreaSizeGripCornerGraphic); |
hausmann | 15e7c0e | 2007-11-07 14:30:50 +0000 | [diff] [blame] | 66 | |
| 67 | return pixmap; |
| 68 | } |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 69 | |
| 70 | namespace WebCore { |
| 71 | |
pkasting@chromium.org | a2910e1 | 2009-01-09 18:46:51 +0000 | [diff] [blame] | 72 | bool FrameData::clear(bool clearMetadata) |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 73 | { |
pkasting@chromium.org | a2910e1 | 2009-01-09 18:46:51 +0000 | [diff] [blame] | 74 | if (clearMetadata) |
| 75 | m_haveMetadata = false; |
| 76 | |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 77 | if (m_frame) { |
| 78 | m_frame = 0; |
pkasting@chromium.org | a2910e1 | 2009-01-09 18:46:51 +0000 | [diff] [blame] | 79 | return true; |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 80 | } |
pkasting@chromium.org | a2910e1 | 2009-01-09 18:46:51 +0000 | [diff] [blame] | 81 | return false; |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 82 | } |
| 83 | |
lars | f6076a4 | 2007-01-17 19:04:39 +0000 | [diff] [blame] | 84 | |
| 85 | |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 86 | // ================================================ |
| 87 | // Image Class |
| 88 | // ================================================ |
| 89 | |
eric@webkit.org | ac3f666 | 2008-08-14 01:15:50 +0000 | [diff] [blame] | 90 | PassRefPtr<Image> Image::loadPlatformResource(const char* name) |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 91 | { |
eric@webkit.org | ac3f666 | 2008-08-14 01:15:50 +0000 | [diff] [blame] | 92 | return StillImage::create(loadResourcePixmap(name)); |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 93 | } |
| 94 | |
lars | f6076a4 | 2007-01-17 19:04:39 +0000 | [diff] [blame] | 95 | |
dino@apple.com | 0cf2dc9 | 2009-01-06 03:00:14 +0000 | [diff] [blame] | 96 | void Image::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const TransformationMatrix& patternTransform, |
lars | f6076a4 | 2007-01-17 19:04:39 +0000 | [diff] [blame] | 97 | const FloatPoint& phase, CompositeOperator op, const FloatRect& destRect) |
| 98 | { |
hausmann@webkit.org | 42009bb | 2009-02-07 15:33:19 +0000 | [diff] [blame^] | 99 | 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(); |
lars | f6076a4 | 2007-01-17 19:04:39 +0000 | [diff] [blame] | 117 | } |
| 118 | |
lars | f6076a4 | 2007-01-17 19:04:39 +0000 | [diff] [blame] | 119 | void BitmapImage::initPlatformData() |
| 120 | { |
| 121 | } |
| 122 | |
| 123 | void BitmapImage::invalidatePlatformData() |
| 124 | { |
| 125 | } |
| 126 | |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 127 | // Drawing Routines |
eseidel | 6195285 | 2006-12-29 01:57:44 +0000 | [diff] [blame] | 128 | void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dst, |
lars | f6076a4 | 2007-01-17 19:04:39 +0000 | [diff] [blame] | 129 | const FloatRect& src, CompositeOperator op) |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 130 | { |
pkasting@chromium.org | e8a5a6b | 2008-10-15 20:38:13 +0000 | [diff] [blame] | 131 | startAnimation(); |
| 132 | |
lars | f6076a4 | 2007-01-17 19:04:39 +0000 | [diff] [blame] | 133 | QPixmap* image = nativeImageForCurrentFrame(); |
| 134 | if (!image) |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 135 | return; |
lars | f6076a4 | 2007-01-17 19:04:39 +0000 | [diff] [blame] | 136 | |
| 137 | if (mayFillWithSolidColor()) { |
| 138 | fillWithSolidColor(ctxt, dst, solidColor(), op); |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 139 | return; |
lars | f6076a4 | 2007-01-17 19:04:39 +0000 | [diff] [blame] | 140 | } |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 141 | |
| 142 | IntSize selfSize = size(); |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 143 | |
| 144 | ctxt->save(); |
| 145 | |
| 146 | // Set the compositing operation. |
| 147 | ctxt->setCompositeOperation(op); |
| 148 | |
aroben | 8c8a13e | 2006-08-24 18:32:46 +0000 | [diff] [blame] | 149 | QPainter* painter(ctxt->platformContext()); |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 150 | |
| 151 | // Test using example site at |
| 152 | // http://www.meyerweb.com/eric/css/edge/complexspiral/demo.html |
zack | bfb6351 | 2007-01-15 17:19:24 +0000 | [diff] [blame] | 153 | painter->drawPixmap(dst, *image, src); |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 154 | |
| 155 | ctxt->restore(); |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 156 | } |
| 157 | |
eseidel | 6195285 | 2006-12-29 01:57:44 +0000 | [diff] [blame] | 158 | void BitmapImage::checkForSolidColor() |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 159 | { |
| 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 | |
eseidel | 6195285 | 2006-12-29 01:57:44 +0000 | [diff] [blame] | 166 | |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 167 | // vim: ts=4 sw=4 et |