Commit 9ac6744a authored by eseidel's avatar eseidel

2006-08-27 Eric Seidel <eric@eseidel.com>

        Reviewed by andersca.

        No logic changes.  Just cleanup.

        * ksvg2/svg/SVGAngle.cpp:
        (SVGAngle::SVGAngle):
        (SVGAngle::unitType):
        (SVGAngle::valueAsString):
        (SVGAngle::newValueSpecifiedUnits):
        (SVGAngle::convertToSpecifiedUnits):
        * ksvg2/svg/SVGAngle.h:
        * ksvg2/svg/SVGLength.cpp:
        (WebCore::SVGLength::unitType):
        (WebCore::SVGLength::newValueSpecifiedUnits):
        (WebCore::SVGLength::convertToSpecifiedUnits):
        (WebCore::SVGLength::updateValue):
        (WebCore::SVGLength::updateValueInSpecifiedUnits):
        * ksvg2/svg/SVGLength.h:
        * platform/BitmapImage.cpp: Removed.
        * platform/BitmapImage.h: Removed.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@16058 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f3bdfcc3
2006-08-27 Eric Seidel <eric@eseidel.com>
Reviewed by andersca.
No logic changes. Just cleanup.
* ksvg2/svg/SVGAngle.cpp:
(SVGAngle::SVGAngle):
(SVGAngle::unitType):
(SVGAngle::valueAsString):
(SVGAngle::newValueSpecifiedUnits):
(SVGAngle::convertToSpecifiedUnits):
* ksvg2/svg/SVGAngle.h:
* ksvg2/svg/SVGLength.cpp:
(WebCore::SVGLength::unitType):
(WebCore::SVGLength::newValueSpecifiedUnits):
(WebCore::SVGLength::convertToSpecifiedUnits):
(WebCore::SVGLength::updateValue):
(WebCore::SVGLength::updateValueInSpecifiedUnits):
* ksvg2/svg/SVGLength.h:
* platform/BitmapImage.cpp: Removed.
* platform/BitmapImage.h: Removed.
2006-08-27 Brady Eidson <beidson@apple.com>
Reviewed by Anders
......
......@@ -20,13 +20,11 @@
Boston, MA 02111-1307, USA.
*/
//#include "SVGAngle.h"
#include "config.h"
#ifdef SVG_SUPPORT
#include <math.h>
#include <ksvg2/ksvg.h>
//#include <kdom/ecma/Ecma.h>
#include "SVGAngle.h"
#include "SVGHelper.h"
......@@ -38,19 +36,20 @@ const double deg2grad = 400.0 / 360.0;
#define rad2grad deg2grad / deg2rad
SVGAngle::SVGAngle(const SVGStyledElement *context) : Shared<SVGAngle>()
SVGAngle::SVGAngle(const SVGStyledElement* context)
: Shared<SVGAngle>()
, m_unitType(SVG_ANGLETYPE_UNKNOWN)
, m_value(0)
, m_valueInSpecifiedUnits(0)
, m_context(context)
{
m_unitType = SVG_ANGLETYPE_UNKNOWN;
m_valueInSpecifiedUnits = 0;
m_value = 0;
m_context = context;
}
SVGAngle::~SVGAngle()
{
}
unsigned short SVGAngle::unitType() const
SVGAngle::SVGAngleType SVGAngle::unitType() const
{
return m_unitType;
}
......@@ -122,6 +121,8 @@ String SVGAngle::valueAsString() const
case SVG_ANGLETYPE_GRAD:
m_valueAsString += "grad";
break;
case SVG_ANGLETYPE_UNKNOWN:
break;
}
return m_valueAsString;
......@@ -129,7 +130,7 @@ String SVGAngle::valueAsString() const
void SVGAngle::newValueSpecifiedUnits(unsigned short unitType, float valueInSpecifiedUnits)
{
m_unitType = unitType;
m_unitType = (SVGAngleType)unitType;
m_valueInSpecifiedUnits = valueInSpecifiedUnits;
calculate();
}
......@@ -152,7 +153,7 @@ void SVGAngle::convertToSpecifiedUnits(unsigned short unitType)
else if (m_unitType == SVG_ANGLETYPE_GRAD && unitType == SVG_ANGLETYPE_DEG)
m_valueInSpecifiedUnits /= deg2grad;
m_unitType = unitType;
m_unitType = (SVGAngleType)unitType;
}
// Helpers
......
......@@ -32,7 +32,7 @@ namespace WebCore {
class SVGAngle : public Shared<SVGAngle> {
public:
SVGAngle(const SVGStyledElement *context);
SVGAngle(const SVGStyledElement* context);
virtual ~SVGAngle();
enum SVGAngleType {
......@@ -43,7 +43,7 @@ namespace WebCore {
SVG_ANGLETYPE_GRAD = 4
};
unsigned short unitType() const;
SVGAngleType unitType() const;
void setValue(float);
float value() const;
......@@ -68,7 +68,7 @@ namespace WebCore {
void setContext(const SVGStyledElement*);
private:
unsigned short m_unitType;
SVGAngleType m_unitType;
float m_value;
float m_valueInSpecifiedUnits;
mutable String m_valueAsString;
......
......@@ -37,7 +37,6 @@
#include <math.h>
using namespace WebCore;
using namespace std;
// keep track of textual description of the unit type
......@@ -51,6 +50,8 @@ static const char* UnitText[] =
"pc"
};
namespace WebCore {
SVGLength::SVGLength(const SVGStyledElement *context, LengthMode mode, const SVGElement *viewport)
: Shared<SVGLength>()
, m_value(0)
......@@ -68,7 +69,7 @@ SVGLength::~SVGLength()
{
}
unsigned short SVGLength::unitType() const
SVGLength::SVGLengthType SVGLength::unitType() const
{
return m_unitType;
}
......@@ -157,13 +158,13 @@ String SVGLength::valueAsString() const
void SVGLength::newValueSpecifiedUnits(unsigned short unitType, float valueInSpecifiedUnits)
{
m_valueInSpecifiedUnits = valueInSpecifiedUnits;
m_unitType = unitType;
m_unitType = (SVGLengthType)unitType;
updateValue();
}
void SVGLength::convertToSpecifiedUnits(unsigned short unitType)
{
m_unitType = unitType;
m_unitType = (SVGLengthType)unitType;
updateValueInSpecifiedUnits();
}
......@@ -225,6 +226,10 @@ void SVGLength::updateValue(bool notify)
m_requiresLayout = true;
}
break;
case SVG_LENGTHTYPE_UNKNOWN:
case SVG_LENGTHTYPE_NUMBER:
case SVG_LENGTHTYPE_PERCENTAGE:
break;
}
if (notify && m_context)
m_context->notifyAttributeChange();
......@@ -264,6 +269,9 @@ bool SVGLength::updateValueInSpecifiedUnits(bool notify)
case SVG_LENGTHTYPE_PC:
m_valueInSpecifiedUnits = m_value / dpi() * 6.0;
break;
case SVG_LENGTHTYPE_UNKNOWN:
case SVG_LENGTHTYPE_NUMBER:
break;
};
if (notify && m_context)
......@@ -292,6 +300,8 @@ void SVGLength::setContext(const SVGStyledElement *context)
m_context = context;
}
}
// vim:ts=4:noet
#endif // SVG_SUPPORT
......@@ -53,7 +53,7 @@ namespace WebCore {
};
// 'SVGLength' functions
unsigned short unitType() const;
SVGLengthType unitType() const;
float value() const;
void setValue(float value);
......@@ -83,9 +83,9 @@ namespace WebCore {
float m_value;
float m_valueInSpecifiedUnits;
unsigned m_mode : 2; // LengthMode
LengthMode m_mode : 2;
bool m_bboxRelative : 1;
unsigned m_unitType : 4;
SVGLengthType m_unitType : 4;
bool m_requiresLayout : 1;
const SVGStyledElement *m_context;
......
/*
* Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
* Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "Image.h"
#include "FloatRect.h"
#include "Image.h"
#include "ImageAnimationObserver.h"
#include "IntRect.h"
#include "PlatformString.h"
#include "Timer.h"
#include <wtf/Vector.h>
#if __APPLE__
// FIXME: Will go away when we make PDF a subclass.
#include "PDFDocumentImage.h"
#endif
namespace WebCore {
// ================================================
// Image Class
// ================================================
Image::Image()
: m_currentFrame(0), m_frames(0), m_animationObserver(0),
m_frameTimer(0), m_repetitionCount(0), m_repetitionsComplete(0),
m_isSolidColor(false), m_animatingImageType(true), m_animationFinished(false),
m_haveSize(false), m_sizeAvailable(false)
{
initNativeData();
}
Image::Image(ImageAnimationObserver* observer, bool isPDF)
: m_currentFrame(0), m_frames(0), m_animationObserver(0),
m_frameTimer(0), m_repetitionCount(0), m_repetitionsComplete(0),
m_isSolidColor(false), m_animatingImageType(true), m_animationFinished(false),
m_haveSize(false), m_sizeAvailable(false)
{
initNativeData();
#if __APPLE__
if (isPDF)
setIsPDF(); // FIXME: Will go away when we make PDF a subclass.
#endif
m_animationObserver = observer;
}
Image::~Image()
{
invalidateData();
stopAnimation();
destroyNativeData();
}
void Image::invalidateData()
{
// Destroy the cached images and release them.
if (m_frames.size()) {
m_frames.last().clear();
m_isSolidColor = false;
invalidateNativeData();
}
}
void Image::cacheFrame(size_t index)
{
size_t numFrames = frameCount();
if (!m_frames.size() && shouldAnimate()) {
// Snag the repetition count.
m_repetitionCount = m_source.repetitionCount();
if (m_repetitionCount == cAnimationNone)
m_animatingImageType = false;
}
if (m_frames.size() < numFrames)
m_frames.resize(numFrames);
m_frames[index].m_frame = m_source.createFrameAtIndex(index);
if (m_frames[index].m_frame)
checkForSolidColor();
if (shouldAnimate())
m_frames[index].m_duration = m_source.frameDurationAtIndex(index);
m_frames[index].m_hasAlpha = m_source.frameHasAlphaAtIndex(index);
}
bool Image::isNull() const
{
return size().isEmpty();
}
IntSize Image::size() const
{
#if __APPLE__
// FIXME: Will go away when we make PDF a subclass.
if (m_isPDF) {
if (m_PDFDoc) {
FloatSize size = m_PDFDoc->size();
return IntSize((int)size.width(), (int)size.height());
}
} else
#endif
if (m_sizeAvailable && !m_haveSize) {
m_size = m_source.size();
m_haveSize = true;
}
return m_size;
}
bool Image::setData(bool allDataReceived)
{
int length = m_data.size();
if (!length)
return true;
#ifdef kImageBytesCutoff
// This is a hack to help with testing display of partially-loaded images.
// To enable it, define kImageBytesCutoff to be a size smaller than that of the image files
// being loaded. They'll never finish loading.
if (length > kImageBytesCutoff) {
length = kImageBytesCutoff;
allDataReceived = false;
}
#endif
#if __APPLE__
// Avoid the extra copy of bytes by just handing the byte array directly to a CFDataRef.
CFDataRef data = CFDataCreateWithBytesNoCopy(0, reinterpret_cast<const UInt8*>(m_data.data()), length, kCFAllocatorNull);
bool result = setNativeData(data, allDataReceived);
CFRelease(data);
#else
bool result = setNativeData(&m_data, allDataReceived);
#endif
return result;
}
bool Image::setNativeData(NativeBytePtr data, bool allDataReceived)
{
#if __APPLE__
// FIXME: Will go away when we make PDF a subclass.
if (m_isPDF) {
if (allDataReceived && !m_PDFDoc)
m_PDFDoc = new PDFDocumentImage(data);
return m_PDFDoc;
}
#endif
invalidateData();
// Feed all the data we've seen so far to the image decoder.
m_source.setData(data, allDataReceived);
// Image properties will not be available until the first frame of the file
// reaches kCGImageStatusIncomplete.
return isSizeAvailable();
}
size_t Image::frameCount()
{
return m_source.frameCount();
}
bool Image::isSizeAvailable()
{
if (m_sizeAvailable)
return true;
m_sizeAvailable = m_source.isSizeAvailable();
return m_sizeAvailable;
}
NativeImagePtr Image::frameAtIndex(size_t index)
{
if (index >= frameCount())
return 0;
if (index >= m_frames.size() || !m_frames[index].m_frame)
cacheFrame(index);
return m_frames[index].m_frame;
}
float Image::frameDurationAtIndex(size_t index)
{
if (index >= frameCount())
return 0;
if (index >= m_frames.size() || !m_frames[index].m_frame)
cacheFrame(index);
return m_frames[index].m_duration;
}
bool Image::frameHasAlphaAtIndex(size_t index)
{
if (index >= frameCount())
return 0;
if (index >= m_frames.size() || !m_frames[index].m_frame)
cacheFrame(index);
return m_frames[index].m_hasAlpha;
}
bool Image::shouldAnimate()
{
return (m_animatingImageType && frameCount() > 1 && !m_animationFinished && m_animationObserver);
}
void Image::startAnimation()
{
if (m_frameTimer || !shouldAnimate())
return;
m_frameTimer = new Timer<Image>(this, &Image::advanceAnimation);
m_frameTimer->startOneShot(frameDurationAtIndex(m_currentFrame));
}
void Image::stopAnimation()
{
// This timer is used to animate all occurrences of this image. Don't invalidate
// the timer unless all renderers have stopped drawing.
delete m_frameTimer;
m_frameTimer = 0;
}
void Image::resetAnimation()
{
stopAnimation();
m_currentFrame = 0;
m_repetitionsComplete = 0;
m_animationFinished = false;
}
void Image::advanceAnimation(Timer<Image>* timer)
{
// Stop the animation.
stopAnimation();
// See if anyone is still paying attention to this animation. If not, we don't
// advance and will simply pause the animation.
if (animationObserver()->shouldStopAnimation(this))
return;
m_currentFrame++;
if (m_currentFrame >= frameCount()) {
m_repetitionsComplete += 1;
if (m_repetitionCount && m_repetitionsComplete >= m_repetitionCount) {
m_animationFinished = false;
m_currentFrame--;
return;
}
m_currentFrame = 0;
}
// Notify our observer that the animation has advanced.
animationObserver()->animationAdvanced(this);
// Kick off a timer to move to the next frame.
m_frameTimer = new Timer<Image>(this, &Image::advanceAnimation);
m_frameTimer->startOneShot(frameDurationAtIndex(m_currentFrame));
}
IntRect Image::rect() const
{
return IntRect(IntPoint(), size());
}
int Image::width() const
{
return size().width();
}
int Image::height() const
{
return size().height();
}
}
/*
* Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
* Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef IMAGE_H_
#define IMAGE_H_
#include "Color.h"
#include "GraphicsTypes.h"
#include "ImageSource.h"
#include "IntSize.h"
#include "FloatSize.h"
#if __APPLE__
#ifdef __OBJC__
@class NSImage;
#else
class NSImage;
#endif
#endif
namespace WebCore {
struct FrameData;
}
// This complicated-looking declaration tells the framedata Vector that it can copy without
// having to invoke our copy constructor. This allows us to not have to worry about ref counting
// the native frames.
namespace WTF {
template<> class VectorTraits<WebCore::FrameData> : public SimpleClassVectorTraits {};
}
namespace WebCore {
class FloatPoint;
class FloatRect;
class GraphicsContext;
class IntRect;
class IntSize;
class PDFDocumentImage;
class String;
template <typename T> class Timer;
// This class gets notified when an image advances animation frames.
class ImageAnimationObserver;
// ================================================
// FrameData Class
// ================================================
struct FrameData {
FrameData()
:m_frame(0), m_duration(0), m_hasAlpha(true)
{}
~FrameData()
{
clear();
}
void clear();
NativeImagePtr m_frame;
float m_duration;
bool m_hasAlpha;
};
// =================================================
// Image Class
// =================================================
class Image : Noncopyable {
friend class GraphicsContext;
public:
Image();
Image(ImageAnimationObserver* observer, bool isPDF = false);
~Image();
static Image* loadResource(const char *name);
static bool supportsType(const String& type);
bool isNull() const;
IntSize size() const;
IntRect rect() const;
int width() const;
int height() const;
bool setData(bool allDataReceived);
bool setNativeData(NativeBytePtr, bool allDataReceived);
Vector<char>& dataBuffer() { return m_data; }
// It may look unusual that there is no start animation call as public API. This is because
// we start and stop animating lazily. Animation begins whenever someone draws the image. It will
// automatically pause once all observers no longer want to render the image anywhere.
void stopAnimation();
void resetAnimation();
// Frame accessors.
size_t currentFrame() const { return m_currentFrame; }
size_t frameCount();
NativeImagePtr frameAtIndex(size_t index);
float frameDurationAtIndex(size_t index);
bool frameHasAlphaAtIndex(size_t index);
// Typically the CachedImage that owns us.
ImageAnimationObserver* animationObserver() const { return m_animationObserver; }
enum TileRule { StretchTile, RoundTile, RepeatTile };