diff options
author | Steve Block <steveblock@google.com> | 2011-05-06 11:45:16 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2011-05-12 13:44:10 +0100 |
commit | cad810f21b803229eb11403f9209855525a25d57 (patch) | |
tree | 29a6fd0279be608e0fe9ffe9841f722f0f4e4269 /Source/WebCore/svg | |
parent | 121b0cf4517156d0ac5111caf9830c51b69bae8f (diff) | |
download | external_webkit-cad810f21b803229eb11403f9209855525a25d57.zip external_webkit-cad810f21b803229eb11403f9209855525a25d57.tar.gz external_webkit-cad810f21b803229eb11403f9209855525a25d57.tar.bz2 |
Merge WebKit at r75315: Initial merge by git.
Change-Id: I570314b346ce101c935ed22a626b48c2af266b84
Diffstat (limited to 'Source/WebCore/svg')
487 files changed, 44025 insertions, 0 deletions
diff --git a/Source/WebCore/svg/ColorDistance.cpp b/Source/WebCore/svg/ColorDistance.cpp new file mode 100644 index 0000000..bb682b9 --- /dev/null +++ b/Source/WebCore/svg/ColorDistance.cpp @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#if ENABLE(SVG) +#include "ColorDistance.h" + +#include "Color.h" +#include <wtf/MathExtras.h> + +namespace WebCore { + +ColorDistance::ColorDistance() + : m_redDiff(0) + , m_greenDiff(0) + , m_blueDiff(0) +{ +} + +ColorDistance::ColorDistance(const Color& fromColor, const Color& toColor) + : m_redDiff(toColor.red() - fromColor.red()) + , m_greenDiff(toColor.green() - fromColor.green()) + , m_blueDiff(toColor.blue() - fromColor.blue()) +{ +} + +ColorDistance::ColorDistance(int redDiff, int greenDiff, int blueDiff) + : m_redDiff(redDiff) + , m_greenDiff(greenDiff) + , m_blueDiff(blueDiff) +{ +} + +static inline int clampColorValue(int v) +{ + if (v > 255) + v = 255; + else if (v < 0) + v = 0; + return v; +} + +ColorDistance ColorDistance::scaledDistance(float scaleFactor) const +{ + return ColorDistance(static_cast<int>(scaleFactor * m_redDiff), + static_cast<int>(scaleFactor * m_greenDiff), + static_cast<int>(scaleFactor * m_blueDiff)); +} + +Color ColorDistance::addColorsAndClamp(const Color& first, const Color& second) +{ + return Color(clampColorValue(first.red() + second.red()), + clampColorValue(first.green() + second.green()), + clampColorValue(first.blue() + second.blue())); +} + +Color ColorDistance::addToColorAndClamp(const Color& color) const +{ + return Color(clampColorValue(color.red() + m_redDiff), + clampColorValue(color.green() + m_greenDiff), + clampColorValue(color.blue() + m_blueDiff)); +} + +bool ColorDistance::isZero() const +{ + return !m_redDiff && !m_blueDiff && !m_greenDiff; +} + +float ColorDistance::distance() const +{ + // This is just a simple distance calculation, not respecting color spaces + return sqrtf(m_redDiff * m_redDiff + m_blueDiff * m_blueDiff + m_greenDiff * m_greenDiff); +} + +} + +#endif diff --git a/Source/WebCore/svg/ColorDistance.h b/Source/WebCore/svg/ColorDistance.h new file mode 100644 index 0000000..2c142b7 --- /dev/null +++ b/Source/WebCore/svg/ColorDistance.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef ColorDistance_h +#define ColorDistance_h +#if ENABLE(SVG) + +namespace WebCore { + +class Color; + +class ColorDistance { +public: + ColorDistance(); + ColorDistance(const Color& fromColor, const Color& toColor); + ColorDistance(int redDiff, int blueDiff, int greenDiff); + + ColorDistance scaledDistance(float scaleFactor) const; + Color addToColorAndClamp(const Color&) const; + + static Color addColorsAndClamp(const Color&, const Color&); + + bool isZero() const; + + float distance() const; + +private: + short m_redDiff; + short m_greenDiff; + short m_blueDiff; +}; +} + +#endif // ENABLE(SVG) +#endif // ColorDistance_h diff --git a/Source/WebCore/svg/ElementTimeControl.h b/Source/WebCore/svg/ElementTimeControl.h new file mode 100644 index 0000000..101d8d0 --- /dev/null +++ b/Source/WebCore/svg/ElementTimeControl.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2008 Apple Inc. All rights reserved. + * Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au> + * + * 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 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 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 ElementTimeControl_h +#define ElementTimeControl_h + +#if ENABLE(SVG) + +#include "ExceptionCode.h" + +namespace WebCore { + +class ElementTimeControl { +public: + virtual ~ElementTimeControl() {} + virtual void beginElement() = 0; + virtual void beginElementAt(float offset) = 0; + virtual void endElement() = 0; + virtual void endElementAt(float offset) = 0; +}; + +} + +#endif + +#endif diff --git a/Source/WebCore/svg/ElementTimeControl.idl b/Source/WebCore/svg/ElementTimeControl.idl new file mode 100644 index 0000000..3e2cef4 --- /dev/null +++ b/Source/WebCore/svg/ElementTimeControl.idl @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2008 Apple Inc. All rights reserved. + * Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au> + * + * 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 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 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. + */ + +module svg { + + interface [Conditional=SVG, ObjCProtocol, OmitConstructor] ElementTimeControl { + void beginElement(); + void beginElementAt(in float offset); + void endElement(); + void endElementAt(in float offset); + }; + +} diff --git a/Source/WebCore/svg/GradientAttributes.h b/Source/WebCore/svg/GradientAttributes.h new file mode 100644 index 0000000..4b02fae --- /dev/null +++ b/Source/WebCore/svg/GradientAttributes.h @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef GradientAttributes_h +#define GradientAttributes_h + +#if ENABLE(SVG) +#include "Color.h" +#include "Gradient.h" +#include "SVGLength.h" + +namespace WebCore { + +struct GradientAttributes { + GradientAttributes() + : m_spreadMethod(SpreadMethodPad) + , m_boundingBoxMode(true) + , m_spreadMethodSet(false) + , m_boundingBoxModeSet(false) + , m_gradientTransformSet(false) + , m_stopsSet(false) + { + } + + GradientSpreadMethod spreadMethod() const { return m_spreadMethod; } + bool boundingBoxMode() const { return m_boundingBoxMode; } + AffineTransform gradientTransform() const { return m_gradientTransform; } + const Vector<Gradient::ColorStop>& stops() const { return m_stops; } + + void setSpreadMethod(GradientSpreadMethod value) + { + m_spreadMethod = value; + m_spreadMethodSet = true; + } + + void setBoundingBoxMode(bool value) + { + m_boundingBoxMode = value; + m_boundingBoxModeSet = true; + } + + void setGradientTransform(const AffineTransform& value) + { + m_gradientTransform = value; + m_gradientTransformSet = true; + } + + void setStops(const Vector<Gradient::ColorStop>& value) + { + m_stops = value; + m_stopsSet = true; + } + + bool hasSpreadMethod() const { return m_spreadMethodSet; } + bool hasBoundingBoxMode() const { return m_boundingBoxModeSet; } + bool hasGradientTransform() const { return m_gradientTransformSet; } + bool hasStops() const { return m_stopsSet; } + +private: + // Properties + GradientSpreadMethod m_spreadMethod; + bool m_boundingBoxMode; + AffineTransform m_gradientTransform; + Vector<Gradient::ColorStop> m_stops; + + // Property states + bool m_spreadMethodSet : 1; + bool m_boundingBoxModeSet : 1; + bool m_gradientTransformSet : 1; + bool m_stopsSet : 1; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/LinearGradientAttributes.h b/Source/WebCore/svg/LinearGradientAttributes.h new file mode 100644 index 0000000..6ff28f1 --- /dev/null +++ b/Source/WebCore/svg/LinearGradientAttributes.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef LinearGradientAttributes_h +#define LinearGradientAttributes_h + +#if ENABLE(SVG) +#include "GradientAttributes.h" + +namespace WebCore { +struct LinearGradientAttributes : GradientAttributes { + LinearGradientAttributes() + : m_x1() + , m_y1() + , m_x2(LengthModeWidth, "100%") + , m_y2() + , m_x1Set(false) + , m_y1Set(false) + , m_x2Set(false) + , m_y2Set(false) + { + } + + SVGLength x1() const { return m_x1; } + SVGLength y1() const { return m_y1; } + SVGLength x2() const { return m_x2; } + SVGLength y2() const { return m_y2; } + + void setX1(const SVGLength& value) { m_x1 = value; m_x1Set = true; } + void setY1(const SVGLength& value) { m_y1 = value; m_y1Set = true; } + void setX2(const SVGLength& value) { m_x2 = value; m_x2Set = true; } + void setY2(const SVGLength& value) { m_y2 = value; m_y2Set = true; } + + bool hasX1() const { return m_x1Set; } + bool hasY1() const { return m_y1Set; } + bool hasX2() const { return m_x2Set; } + bool hasY2() const { return m_y2Set; } + +private: + // Properties + SVGLength m_x1; + SVGLength m_y1; + SVGLength m_x2; + SVGLength m_y2; + + // Property states + bool m_x1Set : 1; + bool m_y1Set : 1; + bool m_x2Set : 1; + bool m_y2Set : 1; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/PatternAttributes.h b/Source/WebCore/svg/PatternAttributes.h new file mode 100644 index 0000000..613ab94 --- /dev/null +++ b/Source/WebCore/svg/PatternAttributes.h @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef PatternAttributes_h +#define PatternAttributes_h + +#if ENABLE(SVG) +#include "SVGLength.h" + +namespace WebCore { + +class SVGPatternElement; + +struct PatternAttributes { + PatternAttributes() + : m_x() + , m_y() + , m_width() + , m_height() + , m_boundingBoxMode(true) + , m_boundingBoxModeContent(false) + , m_patternContentElement(0) + , m_xSet(false) + , m_ySet(false) + , m_widthSet(false) + , m_heightSet(false) + , m_boundingBoxModeSet(false) + , m_boundingBoxModeContentSet(false) + , m_patternTransformSet(false) + , m_patternContentElementSet(false) + { + } + + SVGLength x() const { return m_x; } + SVGLength y() const { return m_y; } + SVGLength width() const { return m_width; } + SVGLength height() const { return m_height; } + bool boundingBoxMode() const { return m_boundingBoxMode; } + bool boundingBoxModeContent() const { return m_boundingBoxModeContent; } + AffineTransform patternTransform() const { return m_patternTransform; } + const SVGPatternElement* patternContentElement() const { return m_patternContentElement; } + + void setX(const SVGLength& value) + { + m_x = value; + m_xSet = true; + } + + void setY(const SVGLength& value) + { + m_y = value; + m_ySet = true; + } + + void setWidth(const SVGLength& value) + { + m_width = value; + m_widthSet = true; + } + + void setHeight(const SVGLength& value) + { + m_height = value; + m_heightSet = true; + } + + void setBoundingBoxMode(bool value) + { + m_boundingBoxMode = value; + m_boundingBoxModeSet = true; + } + + void setBoundingBoxModeContent(bool value) + { + m_boundingBoxModeContent = value; + m_boundingBoxModeContentSet = true; + } + + void setPatternTransform(const AffineTransform& value) + { + m_patternTransform = value; + m_patternTransformSet = true; + } + + void setPatternContentElement(const SVGPatternElement* value) + { + m_patternContentElement = value; + m_patternContentElementSet = true; + } + + bool hasX() const { return m_xSet; } + bool hasY() const { return m_ySet; } + bool hasWidth() const { return m_widthSet; } + bool hasHeight() const { return m_heightSet; } + bool hasBoundingBoxMode() const { return m_boundingBoxModeSet; } + bool hasBoundingBoxModeContent() const { return m_boundingBoxModeContentSet; } + bool hasPatternTransform() const { return m_patternTransformSet; } + bool hasPatternContentElement() const { return m_patternContentElementSet; } + +private: + // Properties + SVGLength m_x; + SVGLength m_y; + SVGLength m_width; + SVGLength m_height; + bool m_boundingBoxMode; + bool m_boundingBoxModeContent; + AffineTransform m_patternTransform; + const SVGPatternElement* m_patternContentElement; + + // Property states + bool m_xSet : 1; + bool m_ySet : 1; + bool m_widthSet : 1; + bool m_heightSet : 1; + bool m_boundingBoxModeSet : 1; + bool m_boundingBoxModeContentSet : 1; + bool m_patternTransformSet : 1; + bool m_patternContentElementSet : 1; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/RadialGradientAttributes.h b/Source/WebCore/svg/RadialGradientAttributes.h new file mode 100644 index 0000000..5fb06e9 --- /dev/null +++ b/Source/WebCore/svg/RadialGradientAttributes.h @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef RadialGradientAttributes_h +#define RadialGradientAttributes_h + +#if ENABLE(SVG) +#include "GradientAttributes.h" + +namespace WebCore { +struct RadialGradientAttributes : GradientAttributes { + RadialGradientAttributes() + : m_cx(LengthModeWidth, "50%") + , m_cy(LengthModeWidth, "50%") + , m_r(LengthModeWidth, "50%") + , m_fx() + , m_fy() + , m_cxSet(false) + , m_cySet(false) + , m_rSet(false) + , m_fxSet(false) + , m_fySet(false) + { + } + + SVGLength cx() const { return m_cx; } + SVGLength cy() const { return m_cy; } + SVGLength r() const { return m_r; } + SVGLength fx() const { return m_fx; } + SVGLength fy() const { return m_fy; } + + void setCx(const SVGLength& value) { m_cx = value; m_cxSet = true; } + void setCy(const SVGLength& value) { m_cy = value; m_cySet = true; } + void setR(const SVGLength& value) { m_r = value; m_rSet = true; } + void setFx(const SVGLength& value) { m_fx = value; m_fxSet = true; } + void setFy(const SVGLength& value) { m_fy = value; m_fySet = true; } + + bool hasCx() const { return m_cxSet; } + bool hasCy() const { return m_cySet; } + bool hasR() const { return m_rSet; } + bool hasFx() const { return m_fxSet; } + bool hasFy() const { return m_fySet; } + +private: + // Properties + SVGLength m_cx; + SVGLength m_cy; + SVGLength m_r; + SVGLength m_fx; + SVGLength m_fy; + + // Property states + bool m_cxSet : 1; + bool m_cySet : 1; + bool m_rSet : 1; + bool m_fxSet : 1; + bool m_fySet : 1; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGAElement.cpp b/Source/WebCore/svg/SVGAElement.cpp new file mode 100644 index 0000000..8fbfc01 --- /dev/null +++ b/Source/WebCore/svg/SVGAElement.cpp @@ -0,0 +1,226 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2007 Rob Buis <buis@kde.org> + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGAElement.h" + +#include "Attr.h" +#include "Attribute.h" +#include "Document.h" +#include "EventHandler.h" +#include "EventNames.h" +#include "Frame.h" +#include "FrameLoader.h" +#include "FrameLoaderTypes.h" +#include "HTMLAnchorElement.h" +#include "HTMLParserIdioms.h" +#include "KeyboardEvent.h" +#include "MouseEvent.h" +#include "PlatformMouseEvent.h" +#include "RenderSVGInline.h" +#include "RenderSVGTransformableContainer.h" +#include "ResourceRequest.h" +#include "SVGNames.h" +#include "SVGSMILElement.h" +#include "XLinkNames.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_STRING(SVGAElement, SVGNames::targetAttr, SVGTarget, svgTarget) +DEFINE_ANIMATED_STRING(SVGAElement, XLinkNames::hrefAttr, Href, href) +DEFINE_ANIMATED_BOOLEAN(SVGAElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) + +inline SVGAElement::SVGAElement(const QualifiedName& tagName, Document* document) + : SVGStyledTransformableElement(tagName, document) +{ +} + +PassRefPtr<SVGAElement> SVGAElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGAElement(tagName, document)); +} + +String SVGAElement::title() const +{ + // If the xlink:title is set (non-empty string), use it. + const AtomicString& title = getAttribute(XLinkNames::titleAttr); + if (!title.isEmpty()) + return title; + + // Otherwise, use the title of this element. + return SVGStyledElement::title(); +} + +void SVGAElement::parseMappedAttribute(Attribute* attr) +{ + if (attr->name() == SVGNames::targetAttr) + setSVGTargetBaseValue(attr->value()); + else { + if (SVGURIReference::parseMappedAttribute(attr)) + return; + if (SVGTests::parseMappedAttribute(attr)) + return; + if (SVGLangSpace::parseMappedAttribute(attr)) + return; + if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) + return; + SVGStyledTransformableElement::parseMappedAttribute(attr); + } +} + +void SVGAElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGStyledTransformableElement::svgAttributeChanged(attrName); + + // Unlike other SVG*Element classes, SVGAElement only listens to SVGURIReference changes + // as none of the other properties changes the linking behaviour for our <a> element. + if (SVGURIReference::isKnownAttribute(attrName)) { + bool wasLink = isLink(); + setIsLink(!href().isNull()); + + if (wasLink != isLink()) + setNeedsStyleRecalc(); + } +} + +void SVGAElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGStyledTransformableElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeSVGTarget(); + synchronizeHref(); + synchronizeExternalResourcesRequired(); + SVGTests::synchronizeProperties(this, attrName); + return; + } + + if (attrName == SVGNames::targetAttr) + synchronizeSVGTarget(); + else if (SVGURIReference::isKnownAttribute(attrName)) + synchronizeHref(); + else if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) + synchronizeExternalResourcesRequired(); + else if (SVGTests::isKnownAttribute(attrName)) + SVGTests::synchronizeProperties(this, attrName); +} + +RenderObject* SVGAElement::createRenderer(RenderArena* arena, RenderStyle*) +{ + if (static_cast<SVGElement*>(parentNode())->isTextContent()) + return new (arena) RenderSVGInline(this); + + return new (arena) RenderSVGTransformableContainer(this); +} + +void SVGAElement::defaultEventHandler(Event* event) +{ + if (isLink()) { + if (focused() && isEnterKeyKeydownEvent(event)) { + event->setDefaultHandled(); + dispatchSimulatedClick(event); + return; + } + + if (isLinkClick(event)) { + String url = stripLeadingAndTrailingHTMLSpaces(href()); + +#if ENABLE(SVG_ANIMATION) + if (url[0] == '#') { + Element* targetElement = document()->getElementById(url.substring(1)); + if (SVGSMILElement::isSMILElement(targetElement)) { + static_cast<SVGSMILElement*>(targetElement)->beginByLinkActivation(); + event->setDefaultHandled(); + return; + } + } +#endif + + // FIXME: Why does the SVG anchor element have this special logic + // for middle click that the HTML anchor element does not have? + // Making a middle click open a link in a new window or tab is + // properly handled at the client level, not inside WebKit; this + // code should be deleted. + String target = isMiddleMouseButtonEvent(event) ? "_blank" : this->target(); + + // FIXME: It's not clear why setting target to "_self" is ever + // helpful. + if (target.isEmpty()) + target = (getAttribute(XLinkNames::showAttr) == "new") ? "_blank" : "_self"; + + handleLinkClick(event, document(), url, target); + return; + } + } + + SVGStyledTransformableElement::defaultEventHandler(event); +} + +bool SVGAElement::supportsFocus() const +{ + if (isContentEditable()) + return SVGStyledTransformableElement::supportsFocus(); + return true; +} + +bool SVGAElement::isFocusable() const +{ + if (renderer() && renderer()->absoluteClippedOverflowRect().isEmpty()) + return false; + + return SVGElement::isFocusable(); +} + +bool SVGAElement::isMouseFocusable() const +{ + return false; +} + +bool SVGAElement::isKeyboardFocusable(KeyboardEvent* event) const +{ + if (!isFocusable()) + return false; + + if (!document()->frame()) + return false; + + return document()->frame()->eventHandler()->tabsToLinks(event); +} + +bool SVGAElement::childShouldCreateRenderer(Node* child) const +{ + // http://www.w3.org/2003/01/REC-SVG11-20030114-errata#linking-text-environment + // The 'a' element may contain any element that its parent may contain, except itself. + if (child->hasTagName(SVGNames::aTag)) + return false; + if (parentNode() && parentNode()->isSVGElement()) + return parentNode()->childShouldCreateRenderer(child); + + return SVGElement::childShouldCreateRenderer(child); +} + +} // namespace WebCore + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGAElement.h b/Source/WebCore/svg/SVGAElement.h new file mode 100644 index 0000000..20a4e07 --- /dev/null +++ b/Source/WebCore/svg/SVGAElement.h @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGAElement_h +#define SVGAElement_h + +#if ENABLE(SVG) +#include "SVGAnimatedBoolean.h" +#include "SVGExternalResourcesRequired.h" +#include "SVGLangSpace.h" +#include "SVGStyledTransformableElement.h" +#include "SVGTests.h" +#include "SVGURIReference.h" + +namespace WebCore { + +class SVGAElement : public SVGStyledTransformableElement, + public SVGURIReference, + public SVGTests, + public SVGLangSpace, + public SVGExternalResourcesRequired { +public: + static PassRefPtr<SVGAElement> create(const QualifiedName&, Document*); + +private: + SVGAElement(const QualifiedName&, Document*); + + virtual bool isValid() const { return SVGTests::isValid(); } + + virtual String title() const; + virtual String target() const { return svgTarget(); } + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + + virtual void defaultEventHandler(Event*); + + virtual bool supportsFocus() const; + virtual bool isMouseFocusable() const; + virtual bool isKeyboardFocusable(KeyboardEvent*) const; + virtual bool isFocusable() const; + + virtual bool childShouldCreateRenderer(Node*) const; + + // Animated property declarations + + // This declaration used to define a non-virtual "String& target() const" method, that clashes with "virtual String Element::target() const". + // That's why it has been renamed to "svgTarget", the CodeGenerators take care of calling svgTargetAnimated() instead of targetAnimated(), see CodeGenerator.pm. + DECLARE_ANIMATED_STRING(SVGTarget, svgTarget) + + // SVGURIReference + DECLARE_ANIMATED_STRING(Href, href) + + // SVGExternalResourcesRequired + DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGAElement_h diff --git a/Source/WebCore/svg/SVGAElement.idl b/Source/WebCore/svg/SVGAElement.idl new file mode 100644 index 0000000..8f2dc24 --- /dev/null +++ b/Source/WebCore/svg/SVGAElement.idl @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGAElement : SVGElement, + SVGURIReference, + SVGTests, + SVGLangSpace, + SVGExternalResourcesRequired, + SVGStylable, + SVGTransformable { + readonly attribute SVGAnimatedString target; + }; + +} diff --git a/Source/WebCore/svg/SVGAllInOne.cpp b/Source/WebCore/svg/SVGAllInOne.cpp new file mode 100644 index 0000000..ab23cb4 --- /dev/null +++ b/Source/WebCore/svg/SVGAllInOne.cpp @@ -0,0 +1,159 @@ +/* + * Copyright (C) 2009 Apple 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 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 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. + */ + +// This all-in-one cpp file cuts down on template bloat to allow us to build our Windows release build. + +#include "ColorDistance.cpp" +#include "SVGAElement.cpp" +#include "SVGAltGlyphElement.cpp" +#include "SVGAngle.cpp" +#include "SVGAnimateColorElement.cpp" +#include "SVGAnimateElement.cpp" +#include "SVGAnimateMotionElement.cpp" +#include "SVGAnimateTransformElement.cpp" +#include "SVGAnimationElement.cpp" +#include "SVGCircleElement.cpp" +#include "SVGClipPathElement.cpp" +#include "SVGColor.cpp" +#include "SVGComponentTransferFunctionElement.cpp" +#include "SVGCursorElement.cpp" +#include "SVGDefsElement.cpp" +#include "SVGDescElement.cpp" +#include "SVGDocument.cpp" +#include "SVGDocumentExtensions.cpp" +#include "SVGElement.cpp" +#include "SVGElementInstance.cpp" +#include "SVGElementInstanceList.cpp" +#include "SVGEllipseElement.cpp" +#include "SVGExternalResourcesRequired.cpp" +#include "SVGFEBlendElement.cpp" +#include "SVGFEColorMatrixElement.cpp" +#include "SVGFEComponentTransferElement.cpp" +#include "SVGFECompositeElement.cpp" +#include "SVGFEConvolveMatrixElement.cpp" +#include "SVGFEDiffuseLightingElement.cpp" +#include "SVGFEDisplacementMapElement.cpp" +#include "SVGFEDistantLightElement.cpp" +#include "SVGFEFloodElement.cpp" +#include "SVGFEFuncAElement.cpp" +#include "SVGFEFuncBElement.cpp" +#include "SVGFEFuncGElement.cpp" +#include "SVGFEFuncRElement.cpp" +#include "SVGFEGaussianBlurElement.cpp" +#include "SVGFEImageElement.cpp" +#include "SVGFELightElement.cpp" +#include "SVGFEMergeElement.cpp" +#include "SVGFEMergeNodeElement.cpp" +#include "SVGFEMorphologyElement.cpp" +#include "SVGFEOffsetElement.cpp" +#include "SVGFEPointLightElement.cpp" +#include "SVGFESpecularLightingElement.cpp" +#include "SVGFESpotLightElement.cpp" +#include "SVGFETileElement.cpp" +#include "SVGFETurbulenceElement.cpp" +#include "SVGFilterElement.cpp" +#include "SVGFilterPrimitiveStandardAttributes.cpp" +#include "SVGFitToViewBox.cpp" +#include "SVGFont.cpp" +#include "SVGFontData.cpp" +#include "SVGFontElement.cpp" +#include "SVGFontFaceElement.cpp" +#include "SVGFontFaceFormatElement.cpp" +#include "SVGFontFaceNameElement.cpp" +#include "SVGFontFaceSrcElement.cpp" +#include "SVGFontFaceUriElement.cpp" +#include "SVGForeignObjectElement.cpp" +#include "SVGGElement.cpp" +#include "SVGGlyphElement.cpp" +#include "SVGGradientElement.cpp" +#include "SVGHKernElement.cpp" +#include "SVGImageElement.cpp" +#include "SVGImageLoader.cpp" +#include "SVGLangSpace.cpp" +#include "SVGLength.cpp" +#include "SVGLengthList.cpp" +#include "SVGLineElement.cpp" +#include "SVGLinearGradientElement.cpp" +#include "SVGLocatable.cpp" +#include "SVGMPathElement.cpp" +#include "SVGMarkerElement.cpp" +#include "SVGMaskElement.cpp" +#include "SVGMetadataElement.cpp" +#include "SVGMissingGlyphElement.cpp" +#include "SVGNumberList.cpp" +#include "SVGPaint.cpp" +#include "SVGParserUtilities.cpp" +#include "SVGPathBlender.cpp" +#include "SVGPathBuilder.cpp" +#include "SVGPathByteStreamBuilder.cpp" +#include "SVGPathByteStreamSource.cpp" +#include "SVGPathElement.cpp" +#include "SVGPathParser.cpp" +#include "SVGPathParserFactory.cpp" +#include "SVGPathSegList.cpp" +#include "SVGPathSegListBuilder.cpp" +#include "SVGPathSegListSource.cpp" +#include "SVGPathStringBuilder.cpp" +#include "SVGPathStringSource.cpp" +#include "SVGPathTraversalStateBuilder.cpp" +#include "SVGPatternElement.cpp" +#include "SVGPointList.cpp" +#include "SVGPolyElement.cpp" +#include "SVGPolygonElement.cpp" +#include "SVGPolylineElement.cpp" +#include "SVGPreserveAspectRatio.cpp" +#include "SVGRadialGradientElement.cpp" +#include "SVGRectElement.cpp" +#include "SVGSVGElement.cpp" +#include "SVGScriptElement.cpp" +#include "SVGSetElement.cpp" +#include "SVGStopElement.cpp" +#include "SVGStringList.cpp" +#include "SVGStylable.cpp" +#include "SVGStyleElement.cpp" +#include "SVGStyledElement.cpp" +#include "SVGStyledLocatableElement.cpp" +#include "SVGStyledTransformableElement.cpp" +#include "SVGSwitchElement.cpp" +#include "SVGSymbolElement.cpp" +#include "SVGTRefElement.cpp" +#include "SVGTSpanElement.cpp" +#include "SVGTests.cpp" +#include "SVGTextContentElement.cpp" +#include "SVGTextElement.cpp" +#include "SVGTextPathElement.cpp" +#include "SVGTextPositioningElement.cpp" +#include "SVGTitleElement.cpp" +#include "SVGTransform.cpp" +#include "SVGTransformDistance.cpp" +#include "SVGTransformList.cpp" +#include "SVGTransformable.cpp" +#include "SVGURIReference.cpp" +#include "SVGUseElement.cpp" +#include "SVGVKernElement.cpp" +#include "SVGViewElement.cpp" +#include "SVGViewSpec.cpp" +#include "SVGZoomAndPan.cpp" +#include "SVGZoomEvent.cpp" diff --git a/Source/WebCore/svg/SVGAltGlyphElement.cpp b/Source/WebCore/svg/SVGAltGlyphElement.cpp new file mode 100644 index 0000000..ca13740 --- /dev/null +++ b/Source/WebCore/svg/SVGAltGlyphElement.cpp @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG_FONTS) +#include "SVGAltGlyphElement.h" + +#include "ExceptionCode.h" +#include "RenderInline.h" +#include "RenderSVGTSpan.h" +#include "SVGGlyphElement.h" +#include "SVGNames.h" +#include "XLinkNames.h" + +namespace WebCore { + +// Animated property declarations +DEFINE_ANIMATED_STRING(SVGAltGlyphElement, XLinkNames::hrefAttr, Href, href) + +inline SVGAltGlyphElement::SVGAltGlyphElement(const QualifiedName& tagName, Document* document) + : SVGTextPositioningElement(tagName, document) +{ +} + +PassRefPtr<SVGAltGlyphElement> SVGAltGlyphElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGAltGlyphElement(tagName, document)); +} + +void SVGAltGlyphElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGTextPositioningElement::synchronizeProperty(attrName); + + if (attrName == anyQName() || SVGURIReference::isKnownAttribute(attrName)) + synchronizeHref(); +} + +void SVGAltGlyphElement::setGlyphRef(const AtomicString&, ExceptionCode& ec) +{ + ec = NO_MODIFICATION_ALLOWED_ERR; +} + +const AtomicString& SVGAltGlyphElement::glyphRef() const +{ + return getAttribute(SVGNames::glyphRefAttr); +} + +void SVGAltGlyphElement::setFormat(const AtomicString&, ExceptionCode& ec) +{ + ec = NO_MODIFICATION_ALLOWED_ERR; +} + +const AtomicString& SVGAltGlyphElement::format() const +{ + return getAttribute(SVGNames::formatAttr); +} + +bool SVGAltGlyphElement::childShouldCreateRenderer(Node* child) const +{ + if (child->isTextNode()) + return true; + return false; +} + +RenderObject* SVGAltGlyphElement::createRenderer(RenderArena* arena, RenderStyle*) +{ + return new (arena) RenderSVGTSpan(this); +} + +SVGGlyphElement* SVGAltGlyphElement::glyphElement() const +{ + Element* elt = document()->getElementById(getTarget(getAttribute(XLinkNames::hrefAttr))); + if (!elt || !elt->hasTagName(SVGNames::glyphTag)) + return 0; + return static_cast<SVGGlyphElement*>(elt); +} + +} + +#endif // ENABLE(SVG) + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGAltGlyphElement.h b/Source/WebCore/svg/SVGAltGlyphElement.h new file mode 100644 index 0000000..0cbee79 --- /dev/null +++ b/Source/WebCore/svg/SVGAltGlyphElement.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGAltGlyphElement_h +#define SVGAltGlyphElement_h + +#if ENABLE(SVG_FONTS) +#include "SVGTextPositioningElement.h" +#include "SVGURIReference.h" + +namespace WebCore { + +class SVGGlyphElement; + +class SVGAltGlyphElement : public SVGTextPositioningElement, + public SVGURIReference { +public: + static PassRefPtr<SVGAltGlyphElement> create(const QualifiedName&, Document*); + + const AtomicString& glyphRef() const; + void setGlyphRef(const AtomicString&, ExceptionCode&); + const AtomicString& format() const; + void setFormat(const AtomicString&, ExceptionCode&); + + SVGGlyphElement* glyphElement() const; + +private: + SVGAltGlyphElement(const QualifiedName&, Document*); + + virtual void synchronizeProperty(const QualifiedName&); + + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + virtual bool childShouldCreateRenderer(Node*) const; + + // Animated property declarations + + // SVGURIReference + DECLARE_ANIMATED_STRING(Href, href) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGAltGlyphElement.idl b/Source/WebCore/svg/SVGAltGlyphElement.idl new file mode 100644 index 0000000..83ddc0e --- /dev/null +++ b/Source/WebCore/svg/SVGAltGlyphElement.idl @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2008 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG&SVG_FONTS] SVGAltGlyphElement : SVGTextPositioningElement, SVGURIReference { + attribute DOMString glyphRef + setter raises(DOMException); + attribute DOMString format + setter raises(DOMException); + }; + +} diff --git a/Source/WebCore/svg/SVGAngle.cpp b/Source/WebCore/svg/SVGAngle.cpp new file mode 100644 index 0000000..37cb73a --- /dev/null +++ b/Source/WebCore/svg/SVGAngle.cpp @@ -0,0 +1,238 @@ +/* + * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGAngle.h" + +#include "SVGParserUtilities.h" +#include <wtf/MathExtras.h> +#include <wtf/text/StringConcatenate.h> + +namespace WebCore { + +SVGAngle::SVGAngle() + : m_unitType(SVG_ANGLETYPE_UNSPECIFIED) + , m_valueInSpecifiedUnits(0) +{ +} + +float SVGAngle::value() const +{ + switch (m_unitType) { + case SVG_ANGLETYPE_GRAD: + return grad2deg(m_valueInSpecifiedUnits); + case SVG_ANGLETYPE_RAD: + return rad2deg(m_valueInSpecifiedUnits); + case SVG_ANGLETYPE_UNSPECIFIED: + case SVG_ANGLETYPE_UNKNOWN: + case SVG_ANGLETYPE_DEG: + return m_valueInSpecifiedUnits; + } + + ASSERT_NOT_REACHED(); + return 0; +} + +void SVGAngle::setValue(float value) +{ + switch (m_unitType) { + case SVG_ANGLETYPE_GRAD: + m_valueInSpecifiedUnits = deg2grad(value); + break; + case SVG_ANGLETYPE_RAD: + m_valueInSpecifiedUnits = deg2rad(value); + break; + case SVG_ANGLETYPE_UNSPECIFIED: + case SVG_ANGLETYPE_UNKNOWN: + case SVG_ANGLETYPE_DEG: + m_valueInSpecifiedUnits = value; + break; + } +} + +inline SVGAngle::SVGAngleType stringToAngleType(const UChar*& ptr, const UChar* end) +{ + // If there's no unit given, the angle type is unspecified. + if (ptr == end) + return SVGAngle::SVG_ANGLETYPE_UNSPECIFIED; + + const UChar firstChar = *ptr; + + // If the unit contains only one character, the angle type is unknown. + ++ptr; + if (ptr == end) + return SVGAngle::SVG_ANGLETYPE_UNKNOWN; + + const UChar secondChar = *ptr; + + // If the unit contains only two characters, the angle type is unknown. + ++ptr; + if (ptr == end) + return SVGAngle::SVG_ANGLETYPE_UNKNOWN; + + const UChar thirdChar = *ptr; + if (firstChar == 'd' && secondChar == 'e' && thirdChar == 'g') + return SVGAngle::SVG_ANGLETYPE_DEG; + if (firstChar == 'r' && secondChar == 'a' && thirdChar == 'd') + return SVGAngle::SVG_ANGLETYPE_RAD; + + // If the unit contains three characters, but is not deg or rad, then it's unknown. + ++ptr; + if (ptr == end) + return SVGAngle::SVG_ANGLETYPE_UNKNOWN; + + const UChar fourthChar = *ptr; + + if (firstChar == 'g' && secondChar == 'r' && thirdChar == 'a' && fourthChar == 'd') + return SVGAngle::SVG_ANGLETYPE_GRAD; + + return SVGAngle::SVG_ANGLETYPE_UNKNOWN; +} + +String SVGAngle::valueAsString() const +{ + switch (m_unitType) { + case SVG_ANGLETYPE_DEG: + return makeString(String::number(m_valueInSpecifiedUnits), "deg"); + case SVG_ANGLETYPE_RAD: + return makeString(String::number(m_valueInSpecifiedUnits), "rad"); + case SVG_ANGLETYPE_GRAD: + return makeString(String::number(m_valueInSpecifiedUnits), "grad"); + case SVG_ANGLETYPE_UNSPECIFIED: + case SVG_ANGLETYPE_UNKNOWN: + return makeString(String::number(m_valueInSpecifiedUnits)); + } + + ASSERT_NOT_REACHED(); + return String(); +} + +void SVGAngle::setValueAsString(const String& value, ExceptionCode& ec) +{ + if (value.isEmpty()) { + m_unitType = SVG_ANGLETYPE_UNSPECIFIED; + return; + } + + float valueInSpecifiedUnits = 0; + const UChar* ptr = value.characters(); + const UChar* end = ptr + value.length(); + + if (!parseNumber(ptr, end, valueInSpecifiedUnits, false)) { + ec = SYNTAX_ERR; + return; + } + + SVGAngleType unitType = stringToAngleType(ptr, end); + if (unitType == SVG_ANGLETYPE_UNKNOWN) { + ec = SYNTAX_ERR; + return; + } + + m_unitType = unitType; + m_valueInSpecifiedUnits = valueInSpecifiedUnits; +} + +void SVGAngle::newValueSpecifiedUnits(unsigned short unitType, float valueInSpecifiedUnits, ExceptionCode& ec) +{ + if (unitType == SVG_ANGLETYPE_UNKNOWN || unitType > SVG_ANGLETYPE_GRAD) { + ec = NOT_SUPPORTED_ERR; + return; + } + + if (unitType != m_unitType) + m_unitType = static_cast<SVGAngleType>(unitType); + + m_valueInSpecifiedUnits = valueInSpecifiedUnits; +} + +void SVGAngle::convertToSpecifiedUnits(unsigned short unitType, ExceptionCode& ec) +{ + if (unitType == SVG_ANGLETYPE_UNKNOWN || m_unitType == SVG_ANGLETYPE_UNKNOWN || unitType > SVG_ANGLETYPE_GRAD) { + ec = NOT_SUPPORTED_ERR; + return; + } + + if (unitType == m_unitType) + return; + + switch (m_unitType) { + case SVG_ANGLETYPE_RAD: + switch (unitType) { + case SVG_ANGLETYPE_GRAD: + m_valueInSpecifiedUnits = rad2grad(m_valueInSpecifiedUnits); + break; + case SVG_ANGLETYPE_UNSPECIFIED: + case SVG_ANGLETYPE_DEG: + m_valueInSpecifiedUnits = rad2deg(m_valueInSpecifiedUnits); + break; + case SVG_ANGLETYPE_RAD: + case SVG_ANGLETYPE_UNKNOWN: + ASSERT_NOT_REACHED(); + break; + } + break; + case SVG_ANGLETYPE_GRAD: + switch (unitType) { + case SVG_ANGLETYPE_RAD: + m_valueInSpecifiedUnits = grad2rad(m_valueInSpecifiedUnits); + break; + case SVG_ANGLETYPE_UNSPECIFIED: + case SVG_ANGLETYPE_DEG: + m_valueInSpecifiedUnits = grad2deg(m_valueInSpecifiedUnits); + break; + case SVG_ANGLETYPE_GRAD: + case SVG_ANGLETYPE_UNKNOWN: + ASSERT_NOT_REACHED(); + break; + } + break; + case SVG_ANGLETYPE_UNSPECIFIED: + // Spec: For angles, a unitless value is treated the same as if degrees were specified. + case SVG_ANGLETYPE_DEG: + switch (unitType) { + case SVG_ANGLETYPE_RAD: + m_valueInSpecifiedUnits = deg2rad(m_valueInSpecifiedUnits); + break; + case SVG_ANGLETYPE_GRAD: + m_valueInSpecifiedUnits = deg2grad(m_valueInSpecifiedUnits); + break; + case SVG_ANGLETYPE_UNSPECIFIED: + break; + case SVG_ANGLETYPE_DEG: + case SVG_ANGLETYPE_UNKNOWN: + ASSERT_NOT_REACHED(); + break; + } + break; + case SVG_ANGLETYPE_UNKNOWN: + ASSERT_NOT_REACHED(); + break; + } + + m_unitType = static_cast<SVGAngleType>(unitType); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGAngle.h b/Source/WebCore/svg/SVGAngle.h new file mode 100644 index 0000000..6fadabb --- /dev/null +++ b/Source/WebCore/svg/SVGAngle.h @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGAngle_h +#define SVGAngle_h + +#if ENABLE(SVG) +#include "ExceptionCode.h" +#include "SVGPropertyTraits.h" + +namespace WebCore { + +class SVGAngle { +public: + SVGAngle(); + + enum SVGAngleType { + SVG_ANGLETYPE_UNKNOWN = 0, + SVG_ANGLETYPE_UNSPECIFIED = 1, + SVG_ANGLETYPE_DEG = 2, + SVG_ANGLETYPE_RAD = 3, + SVG_ANGLETYPE_GRAD = 4 + }; + + SVGAngleType unitType() const { return m_unitType; } + + void setValue(float); + float value() const; + + void setValueInSpecifiedUnits(float valueInSpecifiedUnits) { m_valueInSpecifiedUnits = valueInSpecifiedUnits; } + float valueInSpecifiedUnits() const { return m_valueInSpecifiedUnits; } + + void setValueAsString(const String&, ExceptionCode&); + String valueAsString() const; + + void newValueSpecifiedUnits(unsigned short unitType, float valueInSpecifiedUnits, ExceptionCode&); + void convertToSpecifiedUnits(unsigned short unitType, ExceptionCode&); + +private: + SVGAngleType m_unitType; + float m_valueInSpecifiedUnits; +}; + +template<> +struct SVGPropertyTraits<SVGAngle> { + static SVGAngle initialValue() { return SVGAngle(); } + static String toString(const SVGAngle& type) { return type.valueAsString(); } +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGAngle_h diff --git a/Source/WebCore/svg/SVGAngle.idl b/Source/WebCore/svg/SVGAngle.idl new file mode 100644 index 0000000..be01ff9 --- /dev/null +++ b/Source/WebCore/svg/SVGAngle.idl @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) 2006 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +module svg { + + interface [Conditional=SVG] SVGAngle { + // Angle Unit Types + const unsigned short SVG_ANGLETYPE_UNKNOWN = 0; + const unsigned short SVG_ANGLETYPE_UNSPECIFIED = 1; + const unsigned short SVG_ANGLETYPE_DEG = 2; + const unsigned short SVG_ANGLETYPE_RAD = 3; + const unsigned short SVG_ANGLETYPE_GRAD = 4; + + readonly attribute unsigned short unitType; + attribute [StrictTypeChecking] float value; + attribute [StrictTypeChecking] float valueInSpecifiedUnits; + + attribute [ConvertNullToNullString] DOMString valueAsString + setter raises(DOMException); + + [StrictTypeChecking, RequiresAllArguments=Raise] void newValueSpecifiedUnits(in unsigned short unitType, in float valueInSpecifiedUnits) + raises(DOMException); + + [StrictTypeChecking, RequiresAllArguments=Raise] void convertToSpecifiedUnits(in unsigned short unitType) + raises(DOMException); + }; + +} diff --git a/Source/WebCore/svg/SVGAnimateColorElement.cpp b/Source/WebCore/svg/SVGAnimateColorElement.cpp new file mode 100644 index 0000000..3960b3e --- /dev/null +++ b/Source/WebCore/svg/SVGAnimateColorElement.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#if ENABLE(SVG_ANIMATION) +#include "SVGAnimateColorElement.h" + +namespace WebCore { + +inline SVGAnimateColorElement::SVGAnimateColorElement(const QualifiedName& tagName, Document* document) + : SVGAnimateElement(tagName, document) +{ +} + +PassRefPtr<SVGAnimateColorElement> SVGAnimateColorElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGAnimateColorElement(tagName, document)); +} + +} + +// vim:ts=4:noet +#endif // ENABLE(SVG) + diff --git a/Source/WebCore/svg/SVGAnimateColorElement.h b/Source/WebCore/svg/SVGAnimateColorElement.h new file mode 100644 index 0000000..140c55f --- /dev/null +++ b/Source/WebCore/svg/SVGAnimateColorElement.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGAnimateColorElement_h +#define SVGAnimateColorElement_h +#if ENABLE(SVG_ANIMATION) + +#include "SVGAnimateElement.h" + +namespace WebCore { + +// SVGAnimateElement implements superset of the functionality. +class SVGAnimateColorElement : public SVGAnimateElement { +public: + static PassRefPtr<SVGAnimateColorElement> create(const QualifiedName&, Document*); + +private: + SVGAnimateColorElement(const QualifiedName&, Document*); +}; + +} // namespace WebCore + +#endif // ENABLE(SVG_ANIMATION) +#endif // KSVG_SVGAnimateColorElementImpl_H + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGAnimateColorElement.idl b/Source/WebCore/svg/SVGAnimateColorElement.idl new file mode 100644 index 0000000..b184332 --- /dev/null +++ b/Source/WebCore/svg/SVGAnimateColorElement.idl @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG_ANIMATION] SVGAnimateColorElement : SVGAnimationElement { + } + +}; diff --git a/Source/WebCore/svg/SVGAnimateElement.cpp b/Source/WebCore/svg/SVGAnimateElement.cpp new file mode 100644 index 0000000..7fe4c87 --- /dev/null +++ b/Source/WebCore/svg/SVGAnimateElement.cpp @@ -0,0 +1,339 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_ANIMATION) +#include "SVGAnimateElement.h" + +#include "ColorDistance.h" +#include "FloatConversion.h" +#include "SVGColor.h" +#include "SVGNames.h" +#include "SVGParserUtilities.h" +#include "SVGPathParserFactory.h" +#include "SVGPathSegList.h" +#include "SVGPointList.h" + +using namespace std; + +namespace WebCore { + +SVGAnimateElement::SVGAnimateElement(const QualifiedName& tagName, Document* document) + : SVGAnimationElement(tagName, document) + , m_propertyType(StringProperty) + , m_fromNumber(0) + , m_toNumber(0) + , m_animatedNumber(numeric_limits<double>::infinity()) + , m_animatedPathPointer(0) +{ +} + +PassRefPtr<SVGAnimateElement> SVGAnimateElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGAnimateElement(tagName, document)); +} + +SVGAnimateElement::~SVGAnimateElement() +{ +} + +static bool parseNumberValueAndUnit(const String& in, double& value, String& unit) +{ + // FIXME: These are from top of my head, figure out all property types that can be animated as numbers. + unsigned unitLength = 0; + String parse = in.stripWhiteSpace(); + if (parse.endsWith("%")) + unitLength = 1; + else if (parse.endsWith("px") || parse.endsWith("pt") || parse.endsWith("em")) + unitLength = 2; + else if (parse.endsWith("deg") || parse.endsWith("rad")) + unitLength = 3; + else if (parse.endsWith("grad")) + unitLength = 4; + String newUnit = parse.right(unitLength); + String number = parse.left(parse.length() - unitLength); + if ((!unit.isEmpty() && newUnit != unit) || number.isEmpty()) + return false; + UChar last = number[number.length() - 1]; + if (last < '0' || last > '9') + return false; + unit = newUnit; + bool ok; + value = number.toDouble(&ok); + return ok; +} + +SVGAnimateElement::PropertyType SVGAnimateElement::determinePropertyType(const String& attribute) const +{ + // FIXME: We need a full property table for figuring this out reliably. + if (hasTagName(SVGNames::animateColorTag)) + return ColorProperty; + if (attribute == "d") + return PathProperty; + if (attribute == "points") + return PointsProperty; + if (attribute == "color" || attribute == "fill" || attribute == "stroke") + return ColorProperty; + return NumberProperty; +} + +void SVGAnimateElement::calculateAnimatedValue(float percentage, unsigned repeat, SVGSMILElement* resultElement) +{ + ASSERT(percentage >= 0.f && percentage <= 1.f); + ASSERT(resultElement); + if (hasTagName(SVGNames::setTag)) + percentage = 1.f; + if (!resultElement->hasTagName(SVGNames::animateTag) && !resultElement->hasTagName(SVGNames::animateColorTag) + && !resultElement->hasTagName(SVGNames::setTag)) + return; + SVGAnimateElement* results = static_cast<SVGAnimateElement*>(resultElement); + // Can't accumulate over a string property. + if (results->m_propertyType == StringProperty && m_propertyType != StringProperty) + return; + if (m_propertyType == NumberProperty) { + // To animation uses contributions from the lower priority animations as the base value. + if (animationMode() == ToAnimation) + m_fromNumber = results->m_animatedNumber; + + double number = (m_toNumber - m_fromNumber) * percentage + m_fromNumber; + + // FIXME: This is not correct for values animation. + if (isAccumulated() && repeat) + number += m_toNumber * repeat; + if (isAdditive() && animationMode() != ToAnimation) + results->m_animatedNumber += number; + else + results->m_animatedNumber = number; + return; + } + if (m_propertyType == ColorProperty) { + if (animationMode() == ToAnimation) + m_fromColor = results->m_animatedColor; + Color color = ColorDistance(m_fromColor, m_toColor).scaledDistance(percentage).addToColorAndClamp(m_fromColor); + // FIXME: Accumulate colors. + if (isAdditive() && animationMode() != ToAnimation) + results->m_animatedColor = ColorDistance::addColorsAndClamp(results->m_animatedColor, color); + else + results->m_animatedColor = color; + return; + } + AnimationMode animationMode = this->animationMode(); + if (m_propertyType == PathProperty) { + if (!percentage) { + ASSERT(m_fromPath); + ASSERT(percentage >= 0); + results->m_animatedPathPointer = m_fromPath.get(); + } else if (percentage == 1.f) { + ASSERT(m_toPath); + results->m_animatedPathPointer = m_toPath.get(); + } else { + if (m_fromPath && m_toPath) { + SVGPathParserFactory* factory = SVGPathParserFactory::self(); + if (!factory->buildAnimatedSVGPathByteStream(m_fromPath.get(), m_toPath.get(), results->m_animatedPath, percentage)) { + results->m_animatedPath.clear(); + results->m_animatedPathPointer = 0; + } else + results->m_animatedPathPointer = results->m_animatedPath.get(); + } else + results->m_animatedPathPointer = 0; + // Fall back to discrete animation if the paths are not compatible + if (!results->m_animatedPathPointer) { + ASSERT(m_fromPath); + ASSERT(m_toPath); + ASSERT(!results->m_animatedPath); + results->m_animatedPathPointer = ((animationMode == FromToAnimation && percentage > 0.5f) || animationMode == ToAnimation || percentage == 1.0f) + ? m_toPath.get() : m_fromPath.get(); + } + } + return; + } + if (m_propertyType == PointsProperty) { + if (!percentage) + results->m_animatedPoints = m_fromPoints; + else if (percentage == 1.f) + results->m_animatedPoints = m_toPoints; + else { + if (!m_fromPoints.isEmpty() && !m_toPoints.isEmpty()) + SVGPointList::createAnimated(m_fromPoints, m_toPoints, results->m_animatedPoints, percentage); + else + results->m_animatedPoints.clear(); + // Fall back to discrete animation if the points are not compatible + if (results->m_animatedPoints.isEmpty()) + results->m_animatedPoints = ((animationMode == FromToAnimation && percentage > 0.5f) || animationMode == ToAnimation || percentage == 1.0f) + ? m_toPoints : m_fromPoints; + } + return; + } + ASSERT(animationMode == FromToAnimation || animationMode == ToAnimation || animationMode == ValuesAnimation); + if ((animationMode == FromToAnimation && percentage > 0.5f) || animationMode == ToAnimation || percentage == 1.0f) + results->m_animatedString = m_toString; + else + results->m_animatedString = m_fromString; + // Higher priority replace animation overrides any additive results so far. + results->m_propertyType = StringProperty; +} + +bool SVGAnimateElement::calculateFromAndToValues(const String& fromString, const String& toString) +{ + // FIXME: Needs more solid way determine target attribute type. + m_propertyType = determinePropertyType(attributeName()); + if (m_propertyType == ColorProperty) { + m_fromColor = SVGColor::colorFromRGBColorString(fromString); + m_toColor = SVGColor::colorFromRGBColorString(toString); + if ((m_fromColor.isValid() && m_toColor.isValid()) || (m_toColor.isValid() && animationMode() == ToAnimation)) + return true; + } else if (m_propertyType == NumberProperty) { + m_numberUnit = String(); + if (parseNumberValueAndUnit(toString, m_toNumber, m_numberUnit)) { + // For to-animations the from number is calculated later + if (animationMode() == ToAnimation || parseNumberValueAndUnit(fromString, m_fromNumber, m_numberUnit)) + return true; + } + } else if (m_propertyType == PathProperty) { + SVGPathParserFactory* factory = SVGPathParserFactory::self(); + if (factory->buildSVGPathByteStreamFromString(fromString, m_fromPath, UnalteredParsing)) { + if (factory->buildSVGPathByteStreamFromString(toString, m_toPath, UnalteredParsing)) + return true; + } + m_fromPath.clear(); + m_toPath.clear(); + } else if (m_propertyType == PointsProperty) { + m_fromPoints.clear(); + if (pointsListFromSVGData(m_fromPoints, fromString)) { + m_toPoints.clear(); + if (pointsListFromSVGData(m_toPoints, toString)) + return true; + } + } + m_fromString = fromString; + m_toString = toString; + m_propertyType = StringProperty; + return true; +} + +bool SVGAnimateElement::calculateFromAndByValues(const String& fromString, const String& byString) +{ + ASSERT(!hasTagName(SVGNames::setTag)); + m_propertyType = determinePropertyType(attributeName()); + if (m_propertyType == ColorProperty) { + m_fromColor = fromString.isEmpty() ? Color() : SVGColor::colorFromRGBColorString(fromString); + m_toColor = ColorDistance::addColorsAndClamp(m_fromColor, SVGColor::colorFromRGBColorString(byString)); + if (!m_fromColor.isValid() || !m_toColor.isValid()) + return false; + } else { + m_numberUnit = String(); + m_fromNumber = 0; + if (!fromString.isEmpty() && !parseNumberValueAndUnit(fromString, m_fromNumber, m_numberUnit)) + return false; + if (!parseNumberValueAndUnit(byString, m_toNumber, m_numberUnit)) + return false; + m_toNumber += m_fromNumber; + } + return true; +} + +void SVGAnimateElement::resetToBaseValue(const String& baseString) +{ + m_animatedString = baseString; + PropertyType lastType = m_propertyType; + m_propertyType = determinePropertyType(attributeName()); + if (m_propertyType == ColorProperty) { + m_animatedColor = baseString.isEmpty() ? Color() : SVGColor::colorFromRGBColorString(baseString); + if (isContributing(elapsed())) { + m_propertyType = lastType; + return; + } + } else if (m_propertyType == NumberProperty) { + if (baseString.isEmpty()) { + m_animatedNumber = 0; + m_numberUnit = String(); + return; + } + if (parseNumberValueAndUnit(baseString, m_animatedNumber, m_numberUnit)) + return; + } else if (m_propertyType == PathProperty) { + m_animatedPath.clear(); + m_animatedPathPointer = 0; + return; + } else if (m_propertyType == PointsProperty) { + m_animatedPoints.clear(); + return; + } + m_propertyType = StringProperty; +} + +void SVGAnimateElement::applyResultsToTarget() +{ + String valueToApply; + if (m_propertyType == ColorProperty) + valueToApply = m_animatedColor.name(); + else if (m_propertyType == NumberProperty) + valueToApply = String::number(m_animatedNumber) + m_numberUnit; + else if (m_propertyType == PathProperty) { + if (!m_animatedPathPointer || m_animatedPathPointer->isEmpty()) + valueToApply = m_animatedString; + else { + // We need to keep going to string and back because we are currently only able to paint + // "processed" paths where complex shapes are replaced with simpler ones. Path + // morphing needs to be done with unprocessed paths. + // FIXME: This could be optimized if paths were not processed at parse time. + SVGPathParserFactory* factory = SVGPathParserFactory::self(); + factory->buildStringFromByteStream(m_animatedPathPointer, valueToApply, UnalteredParsing); + } + } else if (m_propertyType == PointsProperty) + valueToApply = m_animatedPoints.isEmpty() ? m_animatedString : m_animatedPoints.valueAsString(); + else + valueToApply = m_animatedString; + + setTargetAttributeAnimatedValue(valueToApply); +} + +float SVGAnimateElement::calculateDistance(const String& fromString, const String& toString) +{ + m_propertyType = determinePropertyType(attributeName()); + if (m_propertyType == NumberProperty) { + double from; + double to; + String unit; + if (!parseNumberValueAndUnit(fromString, from, unit)) + return -1.f; + if (!parseNumberValueAndUnit(toString, to, unit)) + return -1.f; + return narrowPrecisionToFloat(fabs(to - from)); + } + if (m_propertyType == ColorProperty) { + Color from = SVGColor::colorFromRGBColorString(fromString); + if (!from.isValid()) + return -1.f; + Color to = SVGColor::colorFromRGBColorString(toString); + if (!to.isValid()) + return -1.f; + return ColorDistance(from, to).distance(); + } + return -1.f; +} + +} + +// vim:ts=4:noet +#endif // ENABLE(SVG) + diff --git a/Source/WebCore/svg/SVGAnimateElement.h b/Source/WebCore/svg/SVGAnimateElement.h new file mode 100644 index 0000000..3217c4a --- /dev/null +++ b/Source/WebCore/svg/SVGAnimateElement.h @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGAnimateElement_h +#define SVGAnimateElement_h + +#if ENABLE(SVG) && ENABLE(SVG_ANIMATION) + +#include "Color.h" +#include "SVGAnimationElement.h" +#include "SVGPathByteStream.h" +#include "SVGPointList.h" +#include <wtf/OwnPtr.h> + +namespace WebCore { + +class SVGPathSegList; + +class SVGAnimateElement : public SVGAnimationElement { +public: + static PassRefPtr<SVGAnimateElement> create(const QualifiedName&, Document*); + + virtual ~SVGAnimateElement(); + +protected: + SVGAnimateElement(const QualifiedName&, Document*); + + virtual void resetToBaseValue(const String&); + virtual bool calculateFromAndToValues(const String& fromString, const String& toString); + virtual bool calculateFromAndByValues(const String& fromString, const String& byString); + virtual void calculateAnimatedValue(float percentage, unsigned repeat, SVGSMILElement* resultElement); + virtual void applyResultsToTarget(); + virtual float calculateDistance(const String& fromString, const String& toString); + +private: + enum PropertyType { NumberProperty, ColorProperty, StringProperty, PathProperty, PointsProperty }; + PropertyType determinePropertyType(const String& attribute) const; + PropertyType m_propertyType; + + double m_fromNumber; + double m_toNumber; + double m_animatedNumber; + String m_numberUnit; + Color m_fromColor; + Color m_toColor; + Color m_animatedColor; + String m_fromString; + String m_toString; + String m_animatedString; + OwnPtr<SVGPathByteStream> m_fromPath; + OwnPtr<SVGPathByteStream> m_toPath; + OwnPtr<SVGPathByteStream> m_animatedPath; + SVGPathByteStream* m_animatedPathPointer; + SVGPointList m_fromPoints; + SVGPointList m_toPoints; + SVGPointList m_animatedPoints; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGAnimateElement_h + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGAnimateElement.idl b/Source/WebCore/svg/SVGAnimateElement.idl new file mode 100644 index 0000000..a5e1201 --- /dev/null +++ b/Source/WebCore/svg/SVGAnimateElement.idl @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG&SVG_ANIMATION] SVGAnimateElement : SVGAnimationElement { + } + +}; + diff --git a/Source/WebCore/svg/SVGAnimateMotionElement.cpp b/Source/WebCore/svg/SVGAnimateMotionElement.cpp new file mode 100644 index 0000000..ec51548 --- /dev/null +++ b/Source/WebCore/svg/SVGAnimateMotionElement.cpp @@ -0,0 +1,262 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * Copyright (C) 2007 Rob Buis <buis@kde.org> + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_ANIMATION) +#include "SVGAnimateMotionElement.h" + +#include "Attribute.h" +#include "RenderObject.h" +#include "RenderSVGResource.h" +#include "SVGElementInstance.h" +#include "SVGMPathElement.h" +#include "SVGNames.h" +#include "SVGParserUtilities.h" +#include "SVGPathElement.h" +#include "SVGPathParserFactory.h" +#include "SVGTransformList.h" +#include <wtf/MathExtras.h> +#include <wtf/StdLibExtras.h> + +namespace WebCore { + +using namespace SVGNames; + +inline SVGAnimateMotionElement::SVGAnimateMotionElement(const QualifiedName& tagName, Document* document) + : SVGAnimationElement(tagName, document) + , m_baseIndexInTransformList(0) + , m_angle(0) +{ +} + +PassRefPtr<SVGAnimateMotionElement> SVGAnimateMotionElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGAnimateMotionElement(tagName, document)); +} + +bool SVGAnimateMotionElement::hasValidTarget() const +{ + if (!SVGAnimationElement::hasValidTarget()) + return false; + SVGElement* targetElement = this->targetElement(); + if (!targetElement->isStyledTransformable() && !targetElement->hasTagName(SVGNames::textTag)) + return false; + // Spec: SVG 1.1 section 19.2.15 + if (targetElement->hasTagName(gTag) + || targetElement->hasTagName(defsTag) + || targetElement->hasTagName(useTag) + || targetElement->hasTagName(imageTag) + || targetElement->hasTagName(switchTag) + || targetElement->hasTagName(pathTag) + || targetElement->hasTagName(rectTag) + || targetElement->hasTagName(circleTag) + || targetElement->hasTagName(ellipseTag) + || targetElement->hasTagName(lineTag) + || targetElement->hasTagName(polylineTag) + || targetElement->hasTagName(polygonTag) + || targetElement->hasTagName(textTag) + || targetElement->hasTagName(clipPathTag) + || targetElement->hasTagName(maskTag) + || targetElement->hasTagName(aTag) +#if ENABLE(SVG_FOREIGN_OBJECT) + || targetElement->hasTagName(foreignObjectTag) +#endif + ) + return true; + return false; +} + +void SVGAnimateMotionElement::parseMappedAttribute(Attribute* attr) +{ + if (attr->name() == SVGNames::pathAttr) { + m_path = Path(); + SVGPathParserFactory* factory = SVGPathParserFactory::self(); + factory->buildPathFromString(attr->value(), m_path); + } else + SVGAnimationElement::parseMappedAttribute(attr); +} + +SVGAnimateMotionElement::RotateMode SVGAnimateMotionElement::rotateMode() const +{ + DEFINE_STATIC_LOCAL(const AtomicString, autoVal, ("auto")); + DEFINE_STATIC_LOCAL(const AtomicString, autoReverse, ("auto-reverse")); + String rotate = getAttribute(SVGNames::rotateAttr); + if (rotate == autoVal) + return RotateAuto; + if (rotate == autoReverse) + return RotateAutoReverse; + return RotateAngle; +} + +Path SVGAnimateMotionElement::animationPath() const +{ + for (Node* child = firstChild(); child; child = child->nextSibling()) { + if (child->hasTagName(SVGNames::mpathTag)) { + SVGMPathElement* mPath = static_cast<SVGMPathElement*>(child); + SVGPathElement* pathElement = mPath->pathElement(); + Path path; + if (pathElement) + pathElement->toPathData(path); + return path; + } + } + if (hasAttribute(SVGNames::pathAttr)) + return m_path; + return Path(); +} + +static bool parsePoint(const String& s, FloatPoint& point) +{ + if (s.isEmpty()) + return false; + const UChar* cur = s.characters(); + const UChar* end = cur + s.length(); + + if (!skipOptionalSpaces(cur, end)) + return false; + + float x = 0.0f; + if (!parseNumber(cur, end, x)) + return false; + + float y = 0.0f; + if (!parseNumber(cur, end, y)) + return false; + + point = FloatPoint(x, y); + + // disallow anything except spaces at the end + return !skipOptionalSpaces(cur, end); +} + +void SVGAnimateMotionElement::resetToBaseValue(const String&) +{ + if (!hasValidTarget()) + return; + SVGElement* target = targetElement(); + AffineTransform* transform = target->supplementalTransform(); + if (!transform) + return; + transform->makeIdentity(); +} + +bool SVGAnimateMotionElement::calculateFromAndToValues(const String& fromString, const String& toString) +{ + parsePoint(fromString, m_fromPoint); + parsePoint(toString, m_toPoint); + return true; +} + +bool SVGAnimateMotionElement::calculateFromAndByValues(const String& fromString, const String& byString) +{ + parsePoint(fromString, m_fromPoint); + FloatPoint byPoint; + parsePoint(byString, byPoint); + m_toPoint = FloatPoint(m_fromPoint.x() + byPoint.x(), m_fromPoint.y() + byPoint.y()); + return true; +} + +void SVGAnimateMotionElement::calculateAnimatedValue(float percentage, unsigned, SVGSMILElement*) +{ + SVGElement* target = targetElement(); + if (!target) + return; + AffineTransform* transform = target->supplementalTransform(); + if (!transform) + return; + + if (target->renderer()) + target->renderer()->setNeedsTransformUpdate(); + + if (!isAdditive()) + transform->makeIdentity(); + + // FIXME: Implement accumulate. + + if (animationMode() == PathAnimation) { + ASSERT(!animationPath().isEmpty()); + Path path = animationPath(); + float positionOnPath = path.length() * percentage; + bool ok; + FloatPoint position = path.pointAtLength(positionOnPath, ok); + if (ok) { + transform->translate(position.x(), position.y()); + RotateMode rotateMode = this->rotateMode(); + if (rotateMode == RotateAuto || rotateMode == RotateAutoReverse) { + float angle = path.normalAngleAtLength(positionOnPath, ok); + if (rotateMode == RotateAutoReverse) + angle += 180.f; + transform->rotate(angle); + } + } + return; + } + FloatSize diff = m_toPoint - m_fromPoint; + transform->translate(diff.width() * percentage + m_fromPoint.x(), diff.height() * percentage + m_fromPoint.y()); +} + +void SVGAnimateMotionElement::applyResultsToTarget() +{ + // We accumulate to the target element transform list so there is not much to do here. + SVGElement* targetElement = this->targetElement(); + if (!targetElement) + return; + + if (RenderObject* renderer = targetElement->renderer()) + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); + + AffineTransform* t = targetElement->supplementalTransform(); + if (!t) + return; + + // ...except in case where we have additional instances in <use> trees. + const HashSet<SVGElementInstance*>& instances = targetElement->instancesForElement(); + const HashSet<SVGElementInstance*>::const_iterator end = instances.end(); + for (HashSet<SVGElementInstance*>::const_iterator it = instances.begin(); it != end; ++it) { + SVGElement* shadowTreeElement = (*it)->shadowTreeElement(); + ASSERT(shadowTreeElement); + AffineTransform* transform = shadowTreeElement->supplementalTransform(); + if (!transform) + continue; + transform->setMatrix(t->a(), t->b(), t->c(), t->d(), t->e(), t->f()); + if (RenderObject* renderer = shadowTreeElement->renderer()) { + renderer->setNeedsTransformUpdate(); + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); + } + } +} + +float SVGAnimateMotionElement::calculateDistance(const String& fromString, const String& toString) +{ + FloatPoint from; + FloatPoint to; + if (!parsePoint(fromString, from)) + return -1.f; + if (!parsePoint(toString, to)) + return -1.f; + FloatSize diff = to - from; + return sqrtf(diff.width() * diff.width() + diff.height() * diff.height()); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGAnimateMotionElement.h b/Source/WebCore/svg/SVGAnimateMotionElement.h new file mode 100644 index 0000000..7e168c3 --- /dev/null +++ b/Source/WebCore/svg/SVGAnimateMotionElement.h @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGAnimateMotionElement_h +#define SVGAnimateMotionElement_h +#if ENABLE(SVG_ANIMATION) +#include "AffineTransform.h" +#include "Path.h" +#include "SVGAnimationElement.h" + +namespace WebCore { + +class SVGAnimateMotionElement : public SVGAnimationElement { +public: + static PassRefPtr<SVGAnimateMotionElement> create(const QualifiedName&, Document*); + +private: + SVGAnimateMotionElement(const QualifiedName&, Document*); + + virtual bool hasValidTarget() const; + + virtual void parseMappedAttribute(Attribute*); + + virtual void resetToBaseValue(const String&); + virtual bool calculateFromAndToValues(const String& fromString, const String& toString); + virtual bool calculateFromAndByValues(const String& fromString, const String& byString); + virtual void calculateAnimatedValue(float percentage, unsigned repeat, SVGSMILElement* resultElement); + virtual void applyResultsToTarget(); + virtual float calculateDistance(const String& fromString, const String& toString); + virtual Path animationPath() const; + + enum RotateMode { + RotateAngle, + RotateAuto, + RotateAutoReverse + }; + RotateMode rotateMode() const; + + FloatSize m_animatedTranslation; + float m_animatedAngle; + + // Note: we do not support percentage values for to/from coords as the spec implies we should (opera doesn't either) + FloatPoint m_fromPoint; + float m_fromAngle; + FloatPoint m_toPoint; + float m_toAngle; + + unsigned m_baseIndexInTransformList; + + Path m_path; + Vector<float> m_keyPoints; + float m_angle; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG_ANIMATION) +#endif // SVGAnimateMotionElement_h + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGAnimateTransformElement.cpp b/Source/WebCore/svg/SVGAnimateTransformElement.cpp new file mode 100644 index 0000000..bdcab38 --- /dev/null +++ b/Source/WebCore/svg/SVGAnimateTransformElement.cpp @@ -0,0 +1,234 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_ANIMATION) +#include "SVGAnimateTransformElement.h" + +#include "AffineTransform.h" +#include "Attribute.h" +#include "RenderObject.h" +#include "RenderSVGResource.h" +#include "SVGAngle.h" +#include "SVGElementInstance.h" +#include "SVGGradientElement.h" +#include "SVGNames.h" +#include "SVGParserUtilities.h" +#include "SVGSVGElement.h" +#include "SVGStyledTransformableElement.h" +#include "SVGTextElement.h" +#include "SVGTransform.h" +#include "SVGTransformList.h" +#include "SVGUseElement.h" +#include <math.h> +#include <wtf/MathExtras.h> + +using namespace std; + +namespace WebCore { + +inline SVGAnimateTransformElement::SVGAnimateTransformElement(const QualifiedName& tagName, Document* document) + : SVGAnimationElement(tagName, document) + , m_type(SVGTransform::SVG_TRANSFORM_UNKNOWN) + , m_baseIndexInTransformList(0) +{ +} + +PassRefPtr<SVGAnimateTransformElement> SVGAnimateTransformElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGAnimateTransformElement(tagName, document)); +} + +bool SVGAnimateTransformElement::hasValidTarget() const +{ + SVGElement* targetElement = this->targetElement(); + return SVGAnimationElement::hasValidTarget() + && (targetElement->isStyledTransformable() + || targetElement->hasTagName(SVGNames::textTag) + || targetElement->hasTagName(SVGNames::linearGradientTag) + || targetElement->hasTagName(SVGNames::radialGradientTag)); +} + +void SVGAnimateTransformElement::parseMappedAttribute(Attribute* attr) +{ + if (attr->name() == SVGNames::typeAttr) { + if (attr->value() == "translate") + m_type = SVGTransform::SVG_TRANSFORM_TRANSLATE; + else if (attr->value() == "scale") + m_type = SVGTransform::SVG_TRANSFORM_SCALE; + else if (attr->value() == "rotate") + m_type = SVGTransform::SVG_TRANSFORM_ROTATE; + else if (attr->value() == "skewX") + m_type = SVGTransform::SVG_TRANSFORM_SKEWX; + else if (attr->value() == "skewY") + m_type = SVGTransform::SVG_TRANSFORM_SKEWY; + } else + SVGAnimationElement::parseMappedAttribute(attr); +} + + +static SVGTransformList* transformListFor(SVGElement* element) +{ + ASSERT(element); + if (element->isStyledTransformable()) + return &static_cast<SVGStyledTransformableElement*>(element)->transform(); + if (element->hasTagName(SVGNames::textTag)) + return &static_cast<SVGTextElement*>(element)->transform(); + if (element->hasTagName(SVGNames::linearGradientTag) || element->hasTagName(SVGNames::radialGradientTag)) + return &static_cast<SVGGradientElement*>(element)->gradientTransform(); + // FIXME: Handle patternTransform, which is obviously missing! + return 0; +} + +void SVGAnimateTransformElement::resetToBaseValue(const String& baseValue) +{ + if (!hasValidTarget()) + return; + + if (targetElement()->hasTagName(SVGNames::linearGradientTag) || targetElement()->hasTagName(SVGNames::radialGradientTag)) { + targetElement()->setAttribute(SVGNames::gradientTransformAttr, baseValue.isEmpty() ? "matrix(1 0 0 1 0 0)" : baseValue); + return; + } + + if (baseValue.isEmpty()) { + if (SVGTransformList* list = transformListFor(targetElement())) + list->clear(); + } else + targetElement()->setAttribute(SVGNames::transformAttr, baseValue); +} + +void SVGAnimateTransformElement::calculateAnimatedValue(float percentage, unsigned repeat, SVGSMILElement* resultElement) +{ + if (!hasValidTarget()) + return; + SVGElement* targetElement = resultElement->targetElement(); + SVGTransformList* transformList = transformListFor(targetElement); + ASSERT(transformList); + + if (!isAdditive()) + transformList->clear(); + if (isAccumulated() && repeat) { + SVGTransform accumulatedTransform = SVGTransformDistance(m_fromTransform, m_toTransform).scaledDistance(repeat).addToSVGTransform(SVGTransform()); + transformList->append(accumulatedTransform); + } + SVGTransform transform = SVGTransformDistance(m_fromTransform, m_toTransform).scaledDistance(percentage).addToSVGTransform(m_fromTransform); + transformList->append(transform); +} + +bool SVGAnimateTransformElement::calculateFromAndToValues(const String& fromString, const String& toString) +{ + m_fromTransform = parseTransformValue(fromString); + if (!m_fromTransform.isValid()) + return false; + m_toTransform = parseTransformValue(toString); + return m_toTransform.isValid(); +} + +bool SVGAnimateTransformElement::calculateFromAndByValues(const String& fromString, const String& byString) +{ + + m_fromTransform = parseTransformValue(fromString); + if (!m_fromTransform.isValid()) + return false; + m_toTransform = SVGTransformDistance::addSVGTransforms(m_fromTransform, parseTransformValue(byString)); + return m_toTransform.isValid(); +} + +SVGTransform SVGAnimateTransformElement::parseTransformValue(const String& value) const +{ + if (value.isEmpty()) + return SVGTransform(m_type); + SVGTransform result; + // FIXME: This is pretty dumb but parseTransformValue() wants those parenthesis. + String parseString("(" + value + ")"); + const UChar* ptr = parseString.characters(); + SVGTransformable::parseTransformValue(m_type, ptr, ptr + parseString.length(), result); // ignoring return value + return result; +} + +void SVGAnimateTransformElement::applyResultsToTarget() +{ + if (!hasValidTarget()) + return; + // We accumulate to the target element transform list so there is not much to do here. + SVGElement* targetElement = this->targetElement(); + if (!targetElement) + return; + + if (RenderObject* renderer = targetElement->renderer()) { + renderer->setNeedsTransformUpdate(); + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); + } + + // ...except in case where we have additional instances in <use> trees. + SVGTransformList* transformList = transformListFor(targetElement); + if (!transformList) + return; + + const HashSet<SVGElementInstance*>& instances = targetElement->instancesForElement(); + const HashSet<SVGElementInstance*>::const_iterator end = instances.end(); + for (HashSet<SVGElementInstance*>::const_iterator it = instances.begin(); it != end; ++it) { + SVGElement* shadowTreeElement = (*it)->shadowTreeElement(); + ASSERT(shadowTreeElement); + if (shadowTreeElement->isStyledTransformable()) + static_cast<SVGStyledTransformableElement*>(shadowTreeElement)->setTransformBaseValue(*transformList); + else if (shadowTreeElement->hasTagName(SVGNames::textTag)) + static_cast<SVGTextElement*>(shadowTreeElement)->setTransformBaseValue(*transformList); + else if (shadowTreeElement->hasTagName(SVGNames::linearGradientTag) || shadowTreeElement->hasTagName(SVGNames::radialGradientTag)) + static_cast<SVGGradientElement*>(shadowTreeElement)->setGradientTransformBaseValue(*transformList); + // FIXME: Handle patternTransform, obviously missing! + if (RenderObject* renderer = shadowTreeElement->renderer()) { + renderer->setNeedsTransformUpdate(); + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); + } + } +} + +float SVGAnimateTransformElement::calculateDistance(const String& fromString, const String& toString) +{ + // FIXME: This is not correct in all cases. The spec demands that each component (translate x and y for example) + // is paced separately. To implement this we need to treat each component as individual animation everywhere. + SVGTransform from = parseTransformValue(fromString); + if (!from.isValid()) + return -1.f; + SVGTransform to = parseTransformValue(toString); + if (!to.isValid() || from.type() != to.type()) + return -1.f; + if (to.type() == SVGTransform::SVG_TRANSFORM_TRANSLATE) { + FloatSize diff = to.translate() - from.translate(); + return sqrtf(diff.width() * diff.width() + diff.height() * diff.height()); + } + if (to.type() == SVGTransform::SVG_TRANSFORM_ROTATE) + return fabsf(to.angle() - from.angle()); + if (to.type() == SVGTransform::SVG_TRANSFORM_SCALE) { + FloatSize diff = to.scale() - from.scale(); + return sqrtf(diff.width() * diff.width() + diff.height() * diff.height()); + } + return -1.f; +} + +} + +// vim:ts=4:noet +#endif // ENABLE(SVG) + diff --git a/Source/WebCore/svg/SVGAnimateTransformElement.h b/Source/WebCore/svg/SVGAnimateTransformElement.h new file mode 100644 index 0000000..0f806d7 --- /dev/null +++ b/Source/WebCore/svg/SVGAnimateTransformElement.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGAnimateTransformElement_h +#define SVGAnimateTransformElement_h +#if ENABLE(SVG) && ENABLE(SVG_ANIMATION) + +#include "SVGAnimationElement.h" +#include "SVGTransform.h" +#include "SVGTransformDistance.h" + +namespace WebCore { + +class AffineTransform; + +class SVGAnimateTransformElement : public SVGAnimationElement { +public: + static PassRefPtr<SVGAnimateTransformElement> create(const QualifiedName&, Document*); + +private: + SVGAnimateTransformElement(const QualifiedName&, Document*); + + virtual bool hasValidTarget() const; + + virtual void parseMappedAttribute(Attribute*); + + virtual void resetToBaseValue(const String&); + virtual bool calculateFromAndToValues(const String& fromString, const String& toString); + virtual bool calculateFromAndByValues(const String& fromString, const String& byString); + virtual void calculateAnimatedValue(float percentage, unsigned repeat, SVGSMILElement* resultElement); + virtual void applyResultsToTarget(); + virtual float calculateDistance(const String& fromString, const String& toString); + + SVGTransform parseTransformValue(const String&) const; + + SVGTransform::SVGTransformType m_type; + + unsigned m_baseIndexInTransformList; + + SVGTransform m_toTransform; + SVGTransform m_fromTransform; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGAnimateTransformElement_h + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGAnimateTransformElement.idl b/Source/WebCore/svg/SVGAnimateTransformElement.idl new file mode 100644 index 0000000..d993450 --- /dev/null +++ b/Source/WebCore/svg/SVGAnimateTransformElement.idl @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG&SVG_ANIMATION] SVGAnimateTransformElement : SVGAnimationElement { + } + +}; diff --git a/Source/WebCore/svg/SVGAnimatedAngle.h b/Source/WebCore/svg/SVGAnimatedAngle.h new file mode 100644 index 0000000..a4ded8f --- /dev/null +++ b/Source/WebCore/svg/SVGAnimatedAngle.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGAnimatedAngle_h +#define SVGAnimatedAngle_h + +#if ENABLE(SVG) +#include "SVGAngle.h" +#include "SVGAnimatedPropertyTearOff.h" + +namespace WebCore { + +typedef SVGAnimatedPropertyTearOff<SVGAngle> SVGAnimatedAngle; + +// Helper macros to declare/define a SVGAnimatedAngle object +#define DECLARE_ANIMATED_ANGLE(UpperProperty, LowerProperty) \ +DECLARE_ANIMATED_PROPERTY(SVGAnimatedAngle, SVGAngle, UpperProperty, LowerProperty) + +#define DEFINE_ANIMATED_ANGLE_MULTIPLE_WRAPPERS(OwnerType, DOMAttribute, SVGDOMAttributeIdentifier, UpperProperty, LowerProperty) \ +DEFINE_ANIMATED_PROPERTY(OwnerType, DOMAttribute, SVGDOMAttributeIdentifier, SVGAnimatedAngle, SVGAngle, UpperProperty, LowerProperty) + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGAnimatedAngle.idl b/Source/WebCore/svg/SVGAnimatedAngle.idl new file mode 100644 index 0000000..76d4b71 --- /dev/null +++ b/Source/WebCore/svg/SVGAnimatedAngle.idl @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGAnimatedAngle { + readonly attribute SVGAngle baseVal; + readonly attribute SVGAngle animVal; + }; + +} diff --git a/Source/WebCore/svg/SVGAnimatedBoolean.h b/Source/WebCore/svg/SVGAnimatedBoolean.h new file mode 100644 index 0000000..93ba9cc --- /dev/null +++ b/Source/WebCore/svg/SVGAnimatedBoolean.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGAnimatedBoolean_h +#define SVGAnimatedBoolean_h + +#if ENABLE(SVG) +#include "SVGAnimatedStaticPropertyTearOff.h" + +namespace WebCore { + +typedef SVGAnimatedStaticPropertyTearOff<bool> SVGAnimatedBoolean; + +// Helper macros to declare/define a SVGAnimatedBoolean object +#define DECLARE_ANIMATED_BOOLEAN(UpperProperty, LowerProperty) \ +DECLARE_ANIMATED_PROPERTY(SVGAnimatedBoolean, bool, UpperProperty, LowerProperty) + +#define DEFINE_ANIMATED_BOOLEAN(OwnerType, DOMAttribute, UpperProperty, LowerProperty) \ +DEFINE_ANIMATED_PROPERTY(OwnerType, DOMAttribute, DOMAttribute.localName(), SVGAnimatedBoolean, bool, UpperProperty, LowerProperty) + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGAnimatedBoolean.idl b/Source/WebCore/svg/SVGAnimatedBoolean.idl new file mode 100644 index 0000000..3e41e3c --- /dev/null +++ b/Source/WebCore/svg/SVGAnimatedBoolean.idl @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGAnimatedBoolean { + attribute [StrictTypeChecking] boolean baseVal; + readonly attribute boolean animVal; + }; + +} diff --git a/Source/WebCore/svg/SVGAnimatedEnumeration.h b/Source/WebCore/svg/SVGAnimatedEnumeration.h new file mode 100644 index 0000000..354a935 --- /dev/null +++ b/Source/WebCore/svg/SVGAnimatedEnumeration.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGAnimatedEnumeration_h +#define SVGAnimatedEnumeration_h + +#if ENABLE(SVG) +#include "SVGAnimatedPropertyMacros.h" +#include "SVGAnimatedStaticPropertyTearOff.h" + +namespace WebCore { + +typedef SVGAnimatedStaticPropertyTearOff<int> SVGAnimatedEnumeration; + +// Helper macros to declare/define a SVGAnimatedEnumeration object +#define DECLARE_ANIMATED_ENUMERATION(UpperProperty, LowerProperty) \ +DECLARE_ANIMATED_PROPERTY(SVGAnimatedEnumeration, int, UpperProperty, LowerProperty) + +#define DEFINE_ANIMATED_ENUMERATION(OwnerType, DOMAttribute, UpperProperty, LowerProperty) \ +DEFINE_ANIMATED_PROPERTY(OwnerType, DOMAttribute, DOMAttribute.localName(), SVGAnimatedEnumeration, int, UpperProperty, LowerProperty) + +#define DEFINE_ANIMATED_ENUMERATION_MULTIPLE_WRAPPERS(OwnerType, DOMAttribute, SVGDOMAttributeIdentifier, UpperProperty, LowerProperty) \ +DEFINE_ANIMATED_PROPERTY(OwnerType, DOMAttribute, SVGDOMAttributeIdentifier, SVGAnimatedEnumeration, int, UpperProperty, LowerProperty) + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGAnimatedEnumeration.idl b/Source/WebCore/svg/SVGAnimatedEnumeration.idl new file mode 100644 index 0000000..c0840f2 --- /dev/null +++ b/Source/WebCore/svg/SVGAnimatedEnumeration.idl @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGAnimatedEnumeration { + attribute [StrictTypeChecking] unsigned short baseVal; + readonly attribute unsigned short animVal; + }; + +} diff --git a/Source/WebCore/svg/SVGAnimatedInteger.h b/Source/WebCore/svg/SVGAnimatedInteger.h new file mode 100644 index 0000000..6f83475 --- /dev/null +++ b/Source/WebCore/svg/SVGAnimatedInteger.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGAnimatedInteger_h +#define SVGAnimatedInteger_h + +#if ENABLE(SVG) +#include "SVGAnimatedPropertyMacros.h" +#include "SVGAnimatedStaticPropertyTearOff.h" + +namespace WebCore { + +typedef SVGAnimatedStaticPropertyTearOff<long> SVGAnimatedInteger; + +// Helper macros to declare/define a SVGAnimatedInteger object +#define DECLARE_ANIMATED_INTEGER(UpperProperty, LowerProperty) \ +DECLARE_ANIMATED_PROPERTY(SVGAnimatedInteger, long, UpperProperty, LowerProperty) + +#define DEFINE_ANIMATED_INTEGER(OwnerType, DOMAttribute, UpperProperty, LowerProperty) \ +DEFINE_ANIMATED_PROPERTY(OwnerType, DOMAttribute, DOMAttribute.localName(), SVGAnimatedInteger, long, UpperProperty, LowerProperty) + +#define DEFINE_ANIMATED_INTEGER_MULTIPLE_WRAPPERS(OwnerType, DOMAttribute, SVGDOMAttributeIdentifier, UpperProperty, LowerProperty) \ +DEFINE_ANIMATED_PROPERTY(OwnerType, DOMAttribute, SVGDOMAttributeIdentifier, SVGAnimatedInteger, long, UpperProperty, LowerProperty) + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGAnimatedInteger.idl b/Source/WebCore/svg/SVGAnimatedInteger.idl new file mode 100644 index 0000000..61de26c --- /dev/null +++ b/Source/WebCore/svg/SVGAnimatedInteger.idl @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGAnimatedInteger { + attribute [StrictTypeChecking] long baseVal; + readonly attribute long animVal; + }; + +} diff --git a/Source/WebCore/svg/SVGAnimatedLength.h b/Source/WebCore/svg/SVGAnimatedLength.h new file mode 100644 index 0000000..570b2a0 --- /dev/null +++ b/Source/WebCore/svg/SVGAnimatedLength.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGAnimatedLength_h +#define SVGAnimatedLength_h + +#if ENABLE(SVG) +#include "SVGAnimatedPropertyTearOff.h" +#include "SVGLength.h" + +namespace WebCore { + +typedef SVGAnimatedPropertyTearOff<SVGLength> SVGAnimatedLength; + +// Helper macros to declare/define a SVGAnimatedLength object +#define DECLARE_ANIMATED_LENGTH(UpperProperty, LowerProperty) \ +DECLARE_ANIMATED_PROPERTY(SVGAnimatedLength, SVGLength, UpperProperty, LowerProperty) + +#define DEFINE_ANIMATED_LENGTH(OwnerType, DOMAttribute, UpperProperty, LowerProperty) \ +DEFINE_ANIMATED_PROPERTY(OwnerType, DOMAttribute, DOMAttribute.localName(), SVGAnimatedLength, SVGLength, UpperProperty, LowerProperty) + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGAnimatedLength.idl b/Source/WebCore/svg/SVGAnimatedLength.idl new file mode 100644 index 0000000..7ace261 --- /dev/null +++ b/Source/WebCore/svg/SVGAnimatedLength.idl @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGAnimatedLength { + readonly attribute SVGLength baseVal; + readonly attribute SVGLength animVal; + }; + +} diff --git a/Source/WebCore/svg/SVGAnimatedLengthList.h b/Source/WebCore/svg/SVGAnimatedLengthList.h new file mode 100644 index 0000000..a0217fa --- /dev/null +++ b/Source/WebCore/svg/SVGAnimatedLengthList.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGAnimatedLengthList_h +#define SVGAnimatedLengthList_h + +#if ENABLE(SVG) +#include "SVGAnimatedListPropertyTearOff.h" +#include "SVGLengthList.h" + +namespace WebCore { + +typedef SVGAnimatedListPropertyTearOff<SVGLengthList> SVGAnimatedLengthList; + +// Helper macros to declare/define a SVGAnimatedLengthList object +#define DECLARE_ANIMATED_LENGTH_LIST(UpperProperty, LowerProperty) \ +DECLARE_ANIMATED_LIST_PROPERTY(SVGAnimatedLengthList, SVGLengthList, UpperProperty, LowerProperty) + +#define DEFINE_ANIMATED_LENGTH_LIST(OwnerType, DOMAttribute, UpperProperty, LowerProperty) \ +DEFINE_ANIMATED_LIST_PROPERTY(OwnerType, DOMAttribute, DOMAttribute.localName(), SVGAnimatedLengthList, SVGLengthList, UpperProperty, LowerProperty) + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGAnimatedLengthList.idl b/Source/WebCore/svg/SVGAnimatedLengthList.idl new file mode 100644 index 0000000..a68724a --- /dev/null +++ b/Source/WebCore/svg/SVGAnimatedLengthList.idl @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGAnimatedLengthList { + readonly attribute SVGLengthList baseVal; + readonly attribute SVGLengthList animVal; + }; + +} diff --git a/Source/WebCore/svg/SVGAnimatedNumber.h b/Source/WebCore/svg/SVGAnimatedNumber.h new file mode 100644 index 0000000..b59deac --- /dev/null +++ b/Source/WebCore/svg/SVGAnimatedNumber.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGAnimatedNumber_h +#define SVGAnimatedNumber_h + +#if ENABLE(SVG) +#include "SVGAnimatedPropertyMacros.h" +#include "SVGAnimatedStaticPropertyTearOff.h" + +namespace WebCore { + +typedef SVGAnimatedStaticPropertyTearOff<float> SVGAnimatedNumber; + +// Helper macros to declare/define a SVGAnimatedNumber object +#define DECLARE_ANIMATED_NUMBER(UpperProperty, LowerProperty) \ +DECLARE_ANIMATED_PROPERTY(SVGAnimatedNumber, float, UpperProperty, LowerProperty) + +#define DEFINE_ANIMATED_NUMBER(OwnerType, DOMAttribute, UpperProperty, LowerProperty) \ +DEFINE_ANIMATED_PROPERTY(OwnerType, DOMAttribute, DOMAttribute.localName(), SVGAnimatedNumber, float, UpperProperty, LowerProperty) + +#define DEFINE_ANIMATED_NUMBER_MULTIPLE_WRAPPERS(OwnerType, DOMAttribute, SVGDOMAttributeIdentifier, UpperProperty, LowerProperty) \ +DEFINE_ANIMATED_PROPERTY(OwnerType, DOMAttribute, SVGDOMAttributeIdentifier, SVGAnimatedNumber, float, UpperProperty, LowerProperty) + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGAnimatedNumber.idl b/Source/WebCore/svg/SVGAnimatedNumber.idl new file mode 100644 index 0000000..c3b0419 --- /dev/null +++ b/Source/WebCore/svg/SVGAnimatedNumber.idl @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGAnimatedNumber { + attribute [StrictTypeChecking] float baseVal; + readonly attribute float animVal; + }; + +} diff --git a/Source/WebCore/svg/SVGAnimatedNumberList.h b/Source/WebCore/svg/SVGAnimatedNumberList.h new file mode 100644 index 0000000..8beabaa --- /dev/null +++ b/Source/WebCore/svg/SVGAnimatedNumberList.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGAnimatedNumberList_h +#define SVGAnimatedNumberList_h + +#if ENABLE(SVG) +#include "SVGAnimatedListPropertyTearOff.h" +#include "SVGNumberList.h" + +namespace WebCore { + +typedef SVGAnimatedListPropertyTearOff<SVGNumberList> SVGAnimatedNumberList; + +// Helper macros to declare/define a SVGAnimatedNumberList object +#define DECLARE_ANIMATED_NUMBER_LIST(UpperProperty, LowerProperty) \ +DECLARE_ANIMATED_LIST_PROPERTY(SVGAnimatedNumberList, SVGNumberList, UpperProperty, LowerProperty) + +#define DEFINE_ANIMATED_NUMBER_LIST(OwnerType, DOMAttribute, UpperProperty, LowerProperty) \ +DEFINE_ANIMATED_LIST_PROPERTY(OwnerType, DOMAttribute, DOMAttribute.localName(), SVGAnimatedNumberList, SVGNumberList, UpperProperty, LowerProperty) + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGAnimatedNumberList.idl b/Source/WebCore/svg/SVGAnimatedNumberList.idl new file mode 100644 index 0000000..a207ac1 --- /dev/null +++ b/Source/WebCore/svg/SVGAnimatedNumberList.idl @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGAnimatedNumberList { + readonly attribute SVGNumberList baseVal; + readonly attribute SVGNumberList animVal; + }; + +} diff --git a/Source/WebCore/svg/SVGAnimatedPreserveAspectRatio.h b/Source/WebCore/svg/SVGAnimatedPreserveAspectRatio.h new file mode 100644 index 0000000..01afc95 --- /dev/null +++ b/Source/WebCore/svg/SVGAnimatedPreserveAspectRatio.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGAnimatedPreserveAspectRatio_h +#define SVGAnimatedPreserveAspectRatio_h + +#if ENABLE(SVG) +#include "SVGAnimatedPropertyTearOff.h" +#include "SVGPreserveAspectRatio.h" + +namespace WebCore { + +typedef SVGAnimatedPropertyTearOff<SVGPreserveAspectRatio> SVGAnimatedPreserveAspectRatio; + +// Helper macros to declare/define a SVGAnimatedPreserveAspectRatio object +#define DECLARE_ANIMATED_PRESERVEASPECTRATIO(UpperProperty, LowerProperty) \ +DECLARE_ANIMATED_PROPERTY(SVGAnimatedPreserveAspectRatio, SVGPreserveAspectRatio, UpperProperty, LowerProperty) + +#define DEFINE_ANIMATED_PRESERVEASPECTRATIO(OwnerType, DOMAttribute, UpperProperty, LowerProperty) \ +DEFINE_ANIMATED_PROPERTY(OwnerType, DOMAttribute, DOMAttribute.localName(), SVGAnimatedPreserveAspectRatio, SVGPreserveAspectRatio, UpperProperty, LowerProperty) + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGAnimatedPreserveAspectRatio.idl b/Source/WebCore/svg/SVGAnimatedPreserveAspectRatio.idl new file mode 100644 index 0000000..204c145 --- /dev/null +++ b/Source/WebCore/svg/SVGAnimatedPreserveAspectRatio.idl @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGAnimatedPreserveAspectRatio { + readonly attribute SVGPreserveAspectRatio baseVal; + readonly attribute SVGPreserveAspectRatio animVal; + }; + +} diff --git a/Source/WebCore/svg/SVGAnimatedRect.h b/Source/WebCore/svg/SVGAnimatedRect.h new file mode 100644 index 0000000..af9f94b --- /dev/null +++ b/Source/WebCore/svg/SVGAnimatedRect.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGAnimatedRect_h +#define SVGAnimatedRect_h + +#if ENABLE(SVG) +#include "SVGAnimatedPropertyMacros.h" +#include "SVGAnimatedPropertyTearOff.h" +#include "SVGRect.h" + +namespace WebCore { + +typedef SVGAnimatedPropertyTearOff<FloatRect> SVGAnimatedRect; + +// Helper macros to declare/define a SVGAnimatedRect object +#define DECLARE_ANIMATED_RECT(UpperProperty, LowerProperty) \ +DECLARE_ANIMATED_PROPERTY(SVGAnimatedRect, FloatRect, UpperProperty, LowerProperty) + +#define DEFINE_ANIMATED_RECT(OwnerType, DOMAttribute, UpperProperty, LowerProperty) \ +DEFINE_ANIMATED_PROPERTY(OwnerType, DOMAttribute, DOMAttribute.localName(), SVGAnimatedRect, FloatRect, UpperProperty, LowerProperty) + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGAnimatedRect.idl b/Source/WebCore/svg/SVGAnimatedRect.idl new file mode 100644 index 0000000..a825c40 --- /dev/null +++ b/Source/WebCore/svg/SVGAnimatedRect.idl @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGAnimatedRect { + readonly attribute SVGRect baseVal; + readonly attribute SVGRect animVal; + } + +}; diff --git a/Source/WebCore/svg/SVGAnimatedString.h b/Source/WebCore/svg/SVGAnimatedString.h new file mode 100644 index 0000000..57600fd --- /dev/null +++ b/Source/WebCore/svg/SVGAnimatedString.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGAnimatedString_h +#define SVGAnimatedString_h + +#if ENABLE(SVG) +#include "SVGAnimatedPropertyMacros.h" +#include "SVGAnimatedStaticPropertyTearOff.h" + +namespace WebCore { + +typedef SVGAnimatedStaticPropertyTearOff<String> SVGAnimatedString; + +// Helper macros to declare/define a SVGAnimatedString object +#define DECLARE_ANIMATED_STRING(UpperProperty, LowerProperty) \ +DECLARE_ANIMATED_PROPERTY(SVGAnimatedString, String, UpperProperty, LowerProperty) + +#define DEFINE_ANIMATED_STRING(OwnerType, DOMAttribute, UpperProperty, LowerProperty) \ +DEFINE_ANIMATED_PROPERTY(OwnerType, DOMAttribute, DOMAttribute.localName(), SVGAnimatedString, String, UpperProperty, LowerProperty) + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGAnimatedString.idl b/Source/WebCore/svg/SVGAnimatedString.idl new file mode 100644 index 0000000..3430c2c --- /dev/null +++ b/Source/WebCore/svg/SVGAnimatedString.idl @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGAnimatedString { + attribute DOMString baseVal + /*setter raises(DOMException)*/; + readonly attribute DOMString animVal; + }; + +} diff --git a/Source/WebCore/svg/SVGAnimatedTransformList.h b/Source/WebCore/svg/SVGAnimatedTransformList.h new file mode 100644 index 0000000..8caee3c --- /dev/null +++ b/Source/WebCore/svg/SVGAnimatedTransformList.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGAnimatedTransformList_h +#define SVGAnimatedTransformList_h + +#if ENABLE(SVG) +#include "SVGAnimatedTransformListPropertyTearOff.h" + +namespace WebCore { + +typedef SVGAnimatedTransformListPropertyTearOff SVGAnimatedTransformList; + +// Helper macros to declare/define a SVGAnimatedTransformList object +#define DECLARE_ANIMATED_TRANSFORM_LIST(UpperProperty, LowerProperty) \ +DECLARE_ANIMATED_LIST_PROPERTY(SVGAnimatedTransformList, SVGTransformList, UpperProperty, LowerProperty) + +#define DEFINE_ANIMATED_TRANSFORM_LIST(OwnerType, DOMAttribute, UpperProperty, LowerProperty) \ +DEFINE_ANIMATED_LIST_PROPERTY(OwnerType, DOMAttribute, DOMAttribute.localName(), SVGAnimatedTransformList, SVGTransformList, UpperProperty, LowerProperty) + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGAnimatedTransformList.idl b/Source/WebCore/svg/SVGAnimatedTransformList.idl new file mode 100644 index 0000000..72614a1 --- /dev/null +++ b/Source/WebCore/svg/SVGAnimatedTransformList.idl @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGAnimatedTransformList { + readonly attribute SVGTransformList baseVal; + readonly attribute SVGTransformList animVal; + }; + +} diff --git a/Source/WebCore/svg/SVGAnimationElement.cpp b/Source/WebCore/svg/SVGAnimationElement.cpp new file mode 100644 index 0000000..0fcda6d --- /dev/null +++ b/Source/WebCore/svg/SVGAnimationElement.cpp @@ -0,0 +1,601 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * Copyright (C) 2008 Apple Inc. All rights reserved. + * Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au> + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG_ANIMATION) +#include "SVGAnimationElement.h" + +#include "Attribute.h" +#include "CSSComputedStyleDeclaration.h" +#include "CSSParser.h" +#include "CSSPropertyNames.h" +#include "Color.h" +#include "Document.h" +#include "Event.h" +#include "EventListener.h" +#include "FloatConversion.h" +#include "HTMLNames.h" +#include "PlatformString.h" +#include "RenderObject.h" +#include "SVGElementInstance.h" +#include "SVGNames.h" +#include "SVGParserUtilities.h" +#include "SVGURIReference.h" +#include "SVGUseElement.h" +#include "XLinkNames.h" +#include <wtf/StdLibExtras.h> + +using namespace std; + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_BOOLEAN(SVGAnimationElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) + +SVGAnimationElement::SVGAnimationElement(const QualifiedName& tagName, Document* document) + : SVGSMILElement(tagName, document) + , m_animationValid(false) +{ +} + +static void parseKeyTimes(const String& parse, Vector<float>& result, bool verifyOrder) +{ + result.clear(); + Vector<String> parseList; + parse.split(';', parseList); + for (unsigned n = 0; n < parseList.size(); ++n) { + String timeString = parseList[n]; + bool ok; + float time = timeString.toFloat(&ok); + if (!ok || time < 0 || time > 1.f) + goto fail; + if (verifyOrder) { + if (!n) { + if (time) + goto fail; + } else if (time < result.last()) + goto fail; + } + result.append(time); + } + return; +fail: + result.clear(); +} + +static void parseKeySplines(const String& parse, Vector<UnitBezier>& result) +{ + result.clear(); + if (parse.isEmpty()) + return; + const UChar* cur = parse.characters(); + const UChar* end = cur + parse.length(); + + skipOptionalSpaces(cur, end); + + bool delimParsed = false; + while (cur < end) { + delimParsed = false; + float posA = 0.0f; + if (!parseNumber(cur, end, posA)) { + result.clear(); + return; + } + + float posB = 0.0f; + if (!parseNumber(cur, end, posB)) { + result.clear(); + return; + } + + float posC = 0.0f; + if (!parseNumber(cur, end, posC)) { + result.clear(); + return; + } + + float posD = 0.0f; + if (!parseNumber(cur, end, posD, false)) { + result.clear(); + return; + } + + skipOptionalSpaces(cur, end); + + if (cur < end && *cur == ';') { + delimParsed = true; + cur++; + } + skipOptionalSpaces(cur, end); + + result.append(UnitBezier(posA, posB, posC, posD)); + } + if (!(cur == end && !delimParsed)) + result.clear(); +} + +void SVGAnimationElement::parseMappedAttribute(Attribute* attr) +{ + if (attr->name() == SVGNames::valuesAttr) + attr->value().string().split(';', m_values); + else if (attr->name() == SVGNames::keyTimesAttr) + parseKeyTimes(attr->value(), m_keyTimes, true); + else if (attr->name() == SVGNames::keyPointsAttr && hasTagName(SVGNames::animateMotionTag)) { + // This is specified to be an animateMotion attribute only but it is simpler to put it here + // where the other timing calculatations are. + parseKeyTimes(attr->value(), m_keyPoints, false); + } else if (attr->name() == SVGNames::keySplinesAttr) + parseKeySplines(attr->value(), m_keySplines); + else { + if (SVGTests::parseMappedAttribute(attr)) + return; + if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) + return; + SVGSMILElement::parseMappedAttribute(attr); + } +} + +void SVGAnimationElement::attributeChanged(Attribute* attr, bool preserveDecls) +{ + // Assumptions may not hold after an attribute change. + m_animationValid = false; + SVGSMILElement::attributeChanged(attr, preserveDecls); +} + +void SVGAnimationElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGSMILElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeExternalResourcesRequired(); + SVGTests::synchronizeProperties(this, attrName); + return; + } + + if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) + synchronizeExternalResourcesRequired(); + else if (SVGTests::isKnownAttribute(attrName)) + SVGTests::synchronizeProperties(this, attrName); +} + +float SVGAnimationElement::getStartTime() const +{ + return narrowPrecisionToFloat(intervalBegin().value()); +} + +float SVGAnimationElement::getCurrentTime() const +{ + return narrowPrecisionToFloat(elapsed().value()); +} + +float SVGAnimationElement::getSimpleDuration(ExceptionCode&) const +{ + return narrowPrecisionToFloat(simpleDuration().value()); +} + +void SVGAnimationElement::beginElement() +{ + beginElementAt(0); +} + +void SVGAnimationElement::beginElementAt(float offset) +{ + addBeginTime(elapsed() + offset); +} + +void SVGAnimationElement::endElement() +{ + endElementAt(0); +} + +void SVGAnimationElement::endElementAt(float offset) +{ + addEndTime(elapsed() + offset); +} + +SVGAnimationElement::AnimationMode SVGAnimationElement::animationMode() const +{ + // http://www.w3.org/TR/2001/REC-smil-animation-20010904/#AnimFuncValues + if (hasTagName(SVGNames::setTag)) + return ToAnimation; + if (!animationPath().isEmpty()) + return PathAnimation; + if (hasAttribute(SVGNames::valuesAttr)) + return ValuesAnimation; + if (!toValue().isEmpty()) + return fromValue().isEmpty() ? ToAnimation : FromToAnimation; + if (!byValue().isEmpty()) + return fromValue().isEmpty() ? ByAnimation : FromByAnimation; + return NoAnimation; +} + +SVGAnimationElement::CalcMode SVGAnimationElement::calcMode() const +{ + DEFINE_STATIC_LOCAL(const AtomicString, discrete, ("discrete")); + DEFINE_STATIC_LOCAL(const AtomicString, linear, ("linear")); + DEFINE_STATIC_LOCAL(const AtomicString, paced, ("paced")); + DEFINE_STATIC_LOCAL(const AtomicString, spline, ("spline")); + const AtomicString& value = getAttribute(SVGNames::calcModeAttr); + if (value == discrete) + return CalcModeDiscrete; + if (value == linear) + return CalcModeLinear; + if (value == paced) + return CalcModePaced; + if (value == spline) + return CalcModeSpline; + return hasTagName(SVGNames::animateMotionTag) ? CalcModePaced : CalcModeLinear; +} + +SVGAnimationElement::AttributeType SVGAnimationElement::attributeType() const +{ + DEFINE_STATIC_LOCAL(const AtomicString, css, ("CSS")); + DEFINE_STATIC_LOCAL(const AtomicString, xml, ("XML")); + const AtomicString& value = getAttribute(SVGNames::attributeTypeAttr); + if (value == css) + return AttributeTypeCSS; + if (value == xml) + return AttributeTypeXML; + return AttributeTypeAuto; +} + +String SVGAnimationElement::toValue() const +{ + return getAttribute(SVGNames::toAttr); +} + +String SVGAnimationElement::byValue() const +{ + return getAttribute(SVGNames::byAttr); +} + +String SVGAnimationElement::fromValue() const +{ + return getAttribute(SVGNames::fromAttr); +} + +bool SVGAnimationElement::isAdditive() const +{ + DEFINE_STATIC_LOCAL(const AtomicString, sum, ("sum")); + const AtomicString& value = getAttribute(SVGNames::additiveAttr); + return value == sum || animationMode() == ByAnimation; +} + +bool SVGAnimationElement::isAccumulated() const +{ + DEFINE_STATIC_LOCAL(const AtomicString, sum, ("sum")); + const AtomicString& value = getAttribute(SVGNames::accumulateAttr); + return value == sum && animationMode() != ToAnimation; +} + +bool SVGAnimationElement::hasValidTarget() const +{ + return targetElement(); +} + +bool SVGAnimationElement::attributeIsCSS(const String& attributeName) +{ + // FIXME: We should have a map of all SVG properties and their attribute types so we + // could validate animations better. The spec is very vague about this. + unsigned id = cssPropertyID(attributeName); + // SVG range + if (id >= CSSPropertyClipPath && id <= CSSPropertyWritingMode) + return true; + // Regular CSS properties also in SVG + return id == CSSPropertyColor || id == CSSPropertyDisplay || id == CSSPropertyOpacity + || (id >= CSSPropertyFont && id <= CSSPropertyFontWeight) + || id == CSSPropertyOverflow || id == CSSPropertyVisibility; +} + +bool SVGAnimationElement::targetAttributeIsCSS() const +{ + AttributeType type = attributeType(); + if (type == AttributeTypeCSS) + return true; + if (type == AttributeTypeXML) + return false; + return attributeIsCSS(attributeName()); +} + +void SVGAnimationElement::setTargetAttributeAnimatedValue(const String& value) +{ + if (!hasValidTarget()) + return; + SVGElement* target = targetElement(); + String attributeName = this->attributeName(); + if (!target || attributeName.isEmpty() || value.isNull()) + return; + + // We don't want the instance tree to get rebuild. Instances are updated in the loop below. + if (target->isStyled()) + static_cast<SVGStyledElement*>(target)->setInstanceUpdatesBlocked(true); + + ExceptionCode ec; + bool isCSS = targetAttributeIsCSS(); + if (isCSS) { + // FIXME: This should set the override style, not the inline style. + // Sadly override styles are not yet implemented. + target->style()->setProperty(attributeName, value, "", ec); + } else { + // FIXME: This should set the 'presentation' value, not the actual + // attribute value. Whatever that means in practice. + target->setAttribute(attributeName, value, ec); + } + + if (target->isStyled()) + static_cast<SVGStyledElement*>(target)->setInstanceUpdatesBlocked(false); + + // If the target element is used in an <use> instance tree, update that as well. + const HashSet<SVGElementInstance*>& instances = target->instancesForElement(); + const HashSet<SVGElementInstance*>::const_iterator end = instances.end(); + for (HashSet<SVGElementInstance*>::const_iterator it = instances.begin(); it != end; ++it) { + SVGElement* shadowTreeElement = (*it)->shadowTreeElement(); + if (!shadowTreeElement) + continue; + if (isCSS) + shadowTreeElement->style()->setProperty(attributeName, value, "", ec); + else + shadowTreeElement->setAttribute(attributeName, value, ec); + (*it)->correspondingUseElement()->setNeedsStyleRecalc(); + } +} + +void SVGAnimationElement::calculateKeyTimesForCalcModePaced() +{ + ASSERT(calcMode() == CalcModePaced); + ASSERT(animationMode() == ValuesAnimation); + + unsigned valuesCount = m_values.size(); + ASSERT(valuesCount > 1); + Vector<float> keyTimesForPaced; + float totalDistance = 0; + keyTimesForPaced.append(0); + for (unsigned n = 0; n < valuesCount - 1; ++n) { + // Distance in any units + float distance = calculateDistance(m_values[n], m_values[n + 1]); + if (distance < 0) + return; + totalDistance += distance; + keyTimesForPaced.append(distance); + } + if (!totalDistance) + return; + + // Normalize. + for (unsigned n = 1; n < keyTimesForPaced.size() - 1; ++n) + keyTimesForPaced[n] = keyTimesForPaced[n - 1] + keyTimesForPaced[n] / totalDistance; + keyTimesForPaced[keyTimesForPaced.size() - 1] = 1.f; + + // Use key times calculated based on pacing instead of the user provided ones. + m_keyTimes.swap(keyTimesForPaced); +} + +static inline double solveEpsilon(double duration) { return 1. / (200. * duration); } + +unsigned SVGAnimationElement::calculateKeyTimesIndex(float percent) const +{ + unsigned index; + unsigned keyTimesCount = m_keyTimes.size(); + for (index = 1; index < keyTimesCount; ++index) { + if (m_keyTimes[index] >= percent) + break; + } + return --index; +} + +float SVGAnimationElement::calculatePercentForSpline(float percent, unsigned splineIndex) const +{ + ASSERT(calcMode() == CalcModeSpline); + ASSERT(splineIndex < m_keySplines.size()); + UnitBezier bezier = m_keySplines[splineIndex]; + SMILTime duration = simpleDuration(); + if (!duration.isFinite()) + duration = 100.0; + return narrowPrecisionToFloat(bezier.solve(percent, solveEpsilon(duration.value()))); +} + +float SVGAnimationElement::calculatePercentFromKeyPoints(float percent) const +{ + ASSERT(!m_keyPoints.isEmpty()); + ASSERT(calcMode() != CalcModePaced); + ASSERT(m_keyTimes.size() > 1); + ASSERT(m_keyPoints.size() == m_keyTimes.size()); + + unsigned index = calculateKeyTimesIndex(percent); + float fromPercent = m_keyTimes[index]; + float toPercent = m_keyTimes[index + 1]; + float fromKeyPoint = m_keyPoints[index]; + float toKeyPoint = m_keyPoints[index + 1]; + + if (calcMode() == CalcModeDiscrete) + return percent == 1.0f ? toKeyPoint : fromKeyPoint; + + float keyPointPercent = percent == 1.0f ? 1.0f : (percent - fromPercent) / (toPercent - fromPercent); + + if (calcMode() == CalcModeSpline) { + ASSERT(m_keySplines.size() == m_keyPoints.size() - 1); + keyPointPercent = calculatePercentForSpline(keyPointPercent, index); + } + return (toKeyPoint - fromKeyPoint) * keyPointPercent + fromKeyPoint; +} + +void SVGAnimationElement::currentValuesFromKeyPoints(float percent, float& effectivePercent, String& from, String& to) const +{ + ASSERT(!m_keyPoints.isEmpty()); + ASSERT(m_keyPoints.size() == m_keyTimes.size()); + ASSERT(calcMode() != CalcModePaced); + effectivePercent = calculatePercentFromKeyPoints(percent); + unsigned index = effectivePercent == 1.0f ? m_values.size() - 2 : static_cast<unsigned>(effectivePercent * (m_values.size() - 1)); + from = m_values[index]; + to = m_values[index + 1]; +} + +void SVGAnimationElement::currentValuesForValuesAnimation(float percent, float& effectivePercent, String& from, String& to) const +{ + unsigned valuesCount = m_values.size(); + ASSERT(m_animationValid); + ASSERT(valuesCount > 1); + + CalcMode calcMode = this->calcMode(); + if (!m_keyPoints.isEmpty() && calcMode != CalcModePaced) + return currentValuesFromKeyPoints(percent, effectivePercent, from, to); + + unsigned keyTimesCount = m_keyTimes.size(); + ASSERT(!keyTimesCount || valuesCount == keyTimesCount); + ASSERT(!keyTimesCount || (keyTimesCount > 1 && !m_keyTimes[0])); + + unsigned index = calculateKeyTimesIndex(percent); + if (calcMode == CalcModeDiscrete) { + if (!keyTimesCount) + index = percent == 1.0f ? valuesCount - 1 : static_cast<unsigned>(percent * valuesCount); + from = m_values[index]; + to = m_values[index]; + effectivePercent = 0.0f; + return; + } + + float fromPercent; + float toPercent; + if (keyTimesCount) { + fromPercent = m_keyTimes[index]; + toPercent = m_keyTimes[index + 1]; + } else { + index = static_cast<unsigned>(percent * (valuesCount - 1)); + fromPercent = static_cast<float>(index) / (valuesCount - 1); + toPercent = static_cast<float>(index + 1) / (valuesCount - 1); + } + + if (index == valuesCount - 1) + --index; + from = m_values[index]; + to = m_values[index + 1]; + ASSERT(toPercent > fromPercent); + effectivePercent = percent == 1.0f ? 1.0f : (percent - fromPercent) / (toPercent - fromPercent); + + if (calcMode == CalcModeSpline) { + ASSERT(m_keySplines.size() == m_values.size() - 1); + effectivePercent = calculatePercentForSpline(effectivePercent, index); + } +} +static inline void adjustForCurrentColor(String& value, SVGElement* target) +{ + if (!target || !target->isStyled() || value != "currentColor") + return; + + if (RenderObject* targetRenderer = target->renderer()) + value = targetRenderer->style()->visitedDependentColor(CSSPropertyColor).name(); +} + +void SVGAnimationElement::startedActiveInterval() +{ + m_animationValid = false; + + if (!hasValidTarget()) + return; + + // These validations are appropriate for all animation modes. + if (hasAttribute(SVGNames::keyPointsAttr) && m_keyPoints.size() != m_keyTimes.size()) + return; + + AnimationMode animationMode = this->animationMode(); + CalcMode calcMode = this->calcMode(); + if (calcMode == CalcModeSpline) { + unsigned splinesCount = m_keySplines.size() + 1; + if ((hasAttribute(SVGNames::keyPointsAttr) && m_keyPoints.size() != splinesCount) + || (animationMode == ValuesAnimation && m_values.size() != splinesCount)) + return; + } + + String from = fromValue(); + String to = toValue(); + String by = byValue(); + SVGElement* target = targetElement(); + if (animationMode == NoAnimation) + return; + if (animationMode == FromToAnimation) { + adjustForCurrentColor(from, target); + adjustForCurrentColor(to, target); + m_animationValid = calculateFromAndToValues(from, to); + } else if (animationMode == ToAnimation) { + // For to-animations the from value is the current accumulated value from lower priority animations. + // The value is not static and is determined during the animation. + adjustForCurrentColor(to, target); + m_animationValid = calculateFromAndToValues(String(), to); + } else if (animationMode == FromByAnimation) { + adjustForCurrentColor(from, target); + adjustForCurrentColor(by, target); + m_animationValid = calculateFromAndByValues(from, by); + } else if (animationMode == ByAnimation) { + adjustForCurrentColor(by, target); + m_animationValid = calculateFromAndByValues(String(), by); + } else if (animationMode == ValuesAnimation) { + m_animationValid = m_values.size() > 1 + && (calcMode == CalcModePaced || !hasAttribute(SVGNames::keyTimesAttr) || hasAttribute(SVGNames::keyPointsAttr) || (m_values.size() == m_keyTimes.size())) + && (calcMode == CalcModeDiscrete || !m_keyTimes.size() || m_keyTimes.last() == 1.0) + && (calcMode != CalcModeSpline || ((m_keySplines.size() && (m_keySplines.size() == m_values.size() - 1)) || m_keySplines.size() == m_keyPoints.size() - 1)) + && (!hasAttribute(SVGNames::keyPointsAttr) || (m_keyTimes.size() > 1 && m_keyTimes.size() == m_keyPoints.size())); + if (calcMode == CalcModePaced && m_animationValid) + calculateKeyTimesForCalcModePaced(); + } else if (animationMode == PathAnimation) + m_animationValid = calcMode == CalcModePaced || !hasAttribute(SVGNames::keyPointsAttr) || (m_keyTimes.size() > 1 && m_keyTimes.size() == m_keyPoints.size()); +} + +void SVGAnimationElement::updateAnimation(float percent, unsigned repeat, SVGSMILElement* resultElement) +{ + if (!m_animationValid) + return; + + float effectivePercent; + CalcMode mode = calcMode(); + if (animationMode() == ValuesAnimation) { + String from; + String to; + currentValuesForValuesAnimation(percent, effectivePercent, from, to); + if (from != m_lastValuesAnimationFrom || to != m_lastValuesAnimationTo) { + m_animationValid = calculateFromAndToValues(from, to); + if (!m_animationValid) + return; + m_lastValuesAnimationFrom = from; + m_lastValuesAnimationTo = to; + } + } else if (!m_keyPoints.isEmpty() && mode != CalcModePaced) + effectivePercent = calculatePercentFromKeyPoints(percent); + else if (m_keyPoints.isEmpty() && mode == CalcModeSpline && m_keyTimes.size() > 1) + effectivePercent = calculatePercentForSpline(percent, calculateKeyTimesIndex(percent)); + else + effectivePercent = percent; + + calculateAnimatedValue(effectivePercent, repeat, resultElement); +} + +void SVGAnimationElement::endedActiveInterval() +{ +} + +} + +// vim:ts=4:noet +#endif // ENABLE(SVG_ANIMATION) + diff --git a/Source/WebCore/svg/SVGAnimationElement.h b/Source/WebCore/svg/SVGAnimationElement.h new file mode 100644 index 0000000..59d7f9e --- /dev/null +++ b/Source/WebCore/svg/SVGAnimationElement.h @@ -0,0 +1,128 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * Copyright (C) 2008 Apple Inc. All rights reserved. + * Copyright (C) 2008 Cameron McCormack <cam@mcc.id.au> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGAnimationElement_h +#define SVGAnimationElement_h + +#if ENABLE(SVG_ANIMATION) +#include "ElementTimeControl.h" +#include "Path.h" +#include "SMILTime.h" +#include "SVGAnimatedBoolean.h" +#include "SVGExternalResourcesRequired.h" +#include "SVGSMILElement.h" +#include "SVGStringList.h" +#include "SVGTests.h" +#include "UnitBezier.h" + +namespace WebCore { + +class ConditionEventListener; +class TimeContainer; + +class SVGAnimationElement : public SVGSMILElement, + public SVGTests, + public SVGExternalResourcesRequired, + public ElementTimeControl { +public: + // SVGAnimationElement + float getStartTime() const; + float getCurrentTime() const; + float getSimpleDuration(ExceptionCode&) const; + + // ElementTimeControl + virtual void beginElement(); + virtual void beginElementAt(float offset); + virtual void endElement(); + virtual void endElementAt(float offset); + + static bool attributeIsCSS(const String& attributeName); + +protected: + SVGAnimationElement(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + + enum CalcMode { CalcModeDiscrete, CalcModeLinear, CalcModePaced, CalcModeSpline }; + CalcMode calcMode() const; + + enum AttributeType { AttributeTypeCSS, AttributeTypeXML, AttributeTypeAuto }; + AttributeType attributeType() const; + + String toValue() const; + String byValue() const; + String fromValue() const; + + enum AnimationMode { NoAnimation, ToAnimation, ByAnimation, ValuesAnimation, FromToAnimation, FromByAnimation, PathAnimation }; + AnimationMode animationMode() const; + + virtual bool hasValidTarget() const; + + String targetAttributeBaseValue() const; + void setTargetAttributeAnimatedValue(const String&); + bool targetAttributeIsCSS() const; + + bool isAdditive() const; + bool isAccumulated() const; + + // from SVGSMILElement + virtual void startedActiveInterval(); + virtual void updateAnimation(float percent, unsigned repeat, SVGSMILElement* resultElement); + virtual void endedActiveInterval(); + +private: + virtual void attributeChanged(Attribute*, bool preserveDecls); + virtual void synchronizeProperty(const QualifiedName&); + + virtual bool calculateFromAndToValues(const String& fromString, const String& toString) = 0; + virtual bool calculateFromAndByValues(const String& fromString, const String& byString) = 0; + virtual void calculateAnimatedValue(float percentage, unsigned repeat, SVGSMILElement* resultElement) = 0; + virtual float calculateDistance(const String& /*fromString*/, const String& /*toString*/) { return -1.f; } + virtual Path animationPath() const { return Path(); } + + void currentValuesForValuesAnimation(float percent, float& effectivePercent, String& from, String& to) const; + void calculateKeyTimesForCalcModePaced(); + float calculatePercentFromKeyPoints(float percent) const; + void currentValuesFromKeyPoints(float percent, float& effectivePercent, String& from, String& to) const; + float calculatePercentForSpline(float percent, unsigned splineIndex) const; + unsigned calculateKeyTimesIndex(float percent) const; + + // Animated property declarations + + // SVGExternalResourcesRequired + DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) + + bool m_animationValid; + + Vector<String> m_values; + Vector<float> m_keyTimes; + Vector<float> m_keyPoints; + Vector<UnitBezier> m_keySplines; + String m_lastValuesAnimationFrom; + String m_lastValuesAnimationTo; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGAnimationElement_h diff --git a/Source/WebCore/svg/SVGAnimationElement.idl b/Source/WebCore/svg/SVGAnimationElement.idl new file mode 100644 index 0000000..f39f0b8 --- /dev/null +++ b/Source/WebCore/svg/SVGAnimationElement.idl @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG_ANIMATION, OmitConstructor] SVGAnimationElement : SVGElement, + SVGTests, + SVGExternalResourcesRequired, + ElementTimeControl { + readonly attribute SVGElement targetElement; + + float getStartTime(); + float getCurrentTime(); + float getSimpleDuration() + raises(DOMException); + }; + +} diff --git a/Source/WebCore/svg/SVGCircleElement.cpp b/Source/WebCore/svg/SVGCircleElement.cpp new file mode 100644 index 0000000..0ac4600 --- /dev/null +++ b/Source/WebCore/svg/SVGCircleElement.cpp @@ -0,0 +1,156 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGCircleElement.h" + +#include "Attribute.h" +#include "FloatPoint.h" +#include "RenderSVGPath.h" +#include "RenderSVGResource.h" +#include "SVGLength.h" +#include "SVGNames.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_LENGTH(SVGCircleElement, SVGNames::cxAttr, Cx, cx) +DEFINE_ANIMATED_LENGTH(SVGCircleElement, SVGNames::cyAttr, Cy, cy) +DEFINE_ANIMATED_LENGTH(SVGCircleElement, SVGNames::rAttr, R, r) +DEFINE_ANIMATED_BOOLEAN(SVGCircleElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) + +inline SVGCircleElement::SVGCircleElement(const QualifiedName& tagName, Document* document) + : SVGStyledTransformableElement(tagName, document) + , m_cx(LengthModeWidth) + , m_cy(LengthModeHeight) + , m_r(LengthModeOther) +{ +} + +PassRefPtr<SVGCircleElement> SVGCircleElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGCircleElement(tagName, document)); +} + +void SVGCircleElement::parseMappedAttribute(Attribute* attr) +{ + if (attr->name() == SVGNames::cxAttr) + setCxBaseValue(SVGLength(LengthModeWidth, attr->value())); + else if (attr->name() == SVGNames::cyAttr) + setCyBaseValue(SVGLength(LengthModeHeight, attr->value())); + else if (attr->name() == SVGNames::rAttr) { + setRBaseValue(SVGLength(LengthModeOther, attr->value())); + if (rBaseValue().value(this) < 0.0) + document()->accessSVGExtensions()->reportError("A negative value for circle <r> is not allowed"); + } else { + if (SVGTests::parseMappedAttribute(attr)) + return; + if (SVGLangSpace::parseMappedAttribute(attr)) + return; + if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) + return; + SVGStyledTransformableElement::parseMappedAttribute(attr); + } +} + +void SVGCircleElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGStyledTransformableElement::svgAttributeChanged(attrName); + + bool isLengthAttribute = attrName == SVGNames::cxAttr + || attrName == SVGNames::cyAttr + || attrName == SVGNames::rAttr; + + if (isLengthAttribute) + updateRelativeLengthsInformation(); + + if (SVGTests::handleAttributeChange(this, attrName)) + return; + + RenderSVGPath* renderer = static_cast<RenderSVGPath*>(this->renderer()); + if (!renderer) + return; + + if (SVGStyledTransformableElement::isKnownAttribute(attrName)) { + renderer->setNeedsTransformUpdate(); + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); + return; + } + + if (isLengthAttribute) { + renderer->setNeedsPathUpdate(); + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); + return; + } + + if (SVGLangSpace::isKnownAttribute(attrName) + || SVGExternalResourcesRequired::isKnownAttribute(attrName)) + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); +} + +void SVGCircleElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGStyledTransformableElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeCx(); + synchronizeCy(); + synchronizeR(); + synchronizeExternalResourcesRequired(); + SVGTests::synchronizeProperties(this, attrName); + return; + } + + if (attrName == SVGNames::cxAttr) + synchronizeCx(); + else if (attrName == SVGNames::cyAttr) + synchronizeCy(); + else if (attrName == SVGNames::rAttr) + synchronizeR(); + else if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) + synchronizeExternalResourcesRequired(); + else if (SVGTests::isKnownAttribute(attrName)) + SVGTests::synchronizeProperties(this, attrName); +} + +void SVGCircleElement::toPathData(Path& path) const +{ + ASSERT(path.isEmpty()); + + float radius = r().value(this); + + if (radius <= 0) + return; + + path.addEllipse(FloatRect(cx().value(this) - radius, cy().value(this) - radius, radius * 2, radius * 2)); +} + +bool SVGCircleElement::selfHasRelativeLengths() const +{ + return cx().isRelative() + || cy().isRelative() + || r().isRelative(); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGCircleElement.h b/Source/WebCore/svg/SVGCircleElement.h new file mode 100644 index 0000000..f6946dd --- /dev/null +++ b/Source/WebCore/svg/SVGCircleElement.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGCircleElement_h +#define SVGCircleElement_h + +#if ENABLE(SVG) +#include "SVGAnimatedBoolean.h" +#include "SVGAnimatedLength.h" +#include "SVGExternalResourcesRequired.h" +#include "SVGLangSpace.h" +#include "SVGStyledTransformableElement.h" +#include "SVGTests.h" + +namespace WebCore { + +class SVGCircleElement : public SVGStyledTransformableElement, + public SVGTests, + public SVGLangSpace, + public SVGExternalResourcesRequired { +public: + static PassRefPtr<SVGCircleElement> create(const QualifiedName&, Document*); + +private: + SVGCircleElement(const QualifiedName&, Document*); + + virtual bool isValid() const { return SVGTests::isValid(); } + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + + virtual void toPathData(Path&) const; + + virtual bool selfHasRelativeLengths() const; + + // Animated property declarations + DECLARE_ANIMATED_LENGTH(Cx, cx) + DECLARE_ANIMATED_LENGTH(Cy, cy) + DECLARE_ANIMATED_LENGTH(R, r) + + // SVGExternalResourcesRequired + DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGCircleElement_h diff --git a/Source/WebCore/svg/SVGCircleElement.idl b/Source/WebCore/svg/SVGCircleElement.idl new file mode 100644 index 0000000..8381a61 --- /dev/null +++ b/Source/WebCore/svg/SVGCircleElement.idl @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGCircleElement : SVGElement, + SVGTests, + SVGLangSpace, + SVGExternalResourcesRequired, + SVGStylable, + SVGTransformable { + readonly attribute SVGAnimatedLength cx; + readonly attribute SVGAnimatedLength cy; + readonly attribute SVGAnimatedLength r; + }; + +} diff --git a/Source/WebCore/svg/SVGClipPathElement.cpp b/Source/WebCore/svg/SVGClipPathElement.cpp new file mode 100644 index 0000000..d86370d --- /dev/null +++ b/Source/WebCore/svg/SVGClipPathElement.cpp @@ -0,0 +1,123 @@ +/* + * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007, 2008 Rob Buis <buis@kde.org> + * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGClipPathElement.h" + +#include "Attribute.h" +#include "CSSStyleSelector.h" +#include "Document.h" +#include "RenderSVGResourceClipper.h" +#include "SVGNames.h" +#include "SVGTransformList.h" +#include "SVGUnitTypes.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_ENUMERATION(SVGClipPathElement, SVGNames::clipPathUnitsAttr, ClipPathUnits, clipPathUnits) +DEFINE_ANIMATED_BOOLEAN(SVGClipPathElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) + +inline SVGClipPathElement::SVGClipPathElement(const QualifiedName& tagName, Document* document) + : SVGStyledTransformableElement(tagName, document) + , m_clipPathUnits(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE) +{ +} + +PassRefPtr<SVGClipPathElement> SVGClipPathElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGClipPathElement(tagName, document)); +} + +void SVGClipPathElement::parseMappedAttribute(Attribute* attr) +{ + if (attr->name() == SVGNames::clipPathUnitsAttr) { + if (attr->value() == "userSpaceOnUse") + setClipPathUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE); + else if (attr->value() == "objectBoundingBox") + setClipPathUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX); + } else { + if (SVGTests::parseMappedAttribute(attr)) + return; + if (SVGLangSpace::parseMappedAttribute(attr)) + return; + if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) + return; + SVGStyledTransformableElement::parseMappedAttribute(attr); + } +} + +void SVGClipPathElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGStyledTransformableElement::svgAttributeChanged(attrName); + + RenderObject* object = renderer(); + if (!object) + return; + + if (attrName == SVGNames::clipPathUnitsAttr + || SVGTests::isKnownAttribute(attrName) + || SVGLangSpace::isKnownAttribute(attrName) + || SVGExternalResourcesRequired::isKnownAttribute(attrName) + || SVGStyledTransformableElement::isKnownAttribute(attrName)) + object->setNeedsLayout(true); +} + +void SVGClipPathElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGStyledTransformableElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeClipPathUnits(); + synchronizeExternalResourcesRequired(); + SVGTests::synchronizeProperties(this, attrName); + return; + } + + if (attrName == SVGNames::clipPathUnitsAttr) + synchronizeClipPathUnits(); + else if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) + synchronizeExternalResourcesRequired(); + else if (SVGTests::isKnownAttribute(attrName)) + SVGTests::synchronizeProperties(this, attrName); +} + +void SVGClipPathElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) +{ + SVGStyledTransformableElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); + + if (changedByParser) + return; + + if (RenderObject* object = renderer()) + object->setNeedsLayout(true); +} + +RenderObject* SVGClipPathElement::createRenderer(RenderArena* arena, RenderStyle*) +{ + return new (arena) RenderSVGResourceClipper(this); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGClipPathElement.h b/Source/WebCore/svg/SVGClipPathElement.h new file mode 100644 index 0000000..23242e8 --- /dev/null +++ b/Source/WebCore/svg/SVGClipPathElement.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGClipPathElement_h +#define SVGClipPathElement_h + +#if ENABLE(SVG) +#include "SVGAnimatedBoolean.h" +#include "SVGAnimatedEnumeration.h" +#include "SVGExternalResourcesRequired.h" +#include "SVGLangSpace.h" +#include "SVGStyledTransformableElement.h" +#include "SVGTests.h" + +namespace WebCore { + +class RenderObject; + +class SVGClipPathElement : public SVGStyledTransformableElement, + public SVGTests, + public SVGLangSpace, + public SVGExternalResourcesRequired { +public: + static PassRefPtr<SVGClipPathElement> create(const QualifiedName&, Document*); + +private: + SVGClipPathElement(const QualifiedName&, Document*); + + virtual bool isValid() const { return SVGTests::isValid(); } + virtual bool needsPendingResourceHandling() const { return false; } + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); + + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + + // Animated property declarations + DECLARE_ANIMATED_ENUMERATION(ClipPathUnits, clipPathUnits) + + // SVGExternalResourcesRequired + DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) +}; + +} + +#endif +#endif diff --git a/Source/WebCore/svg/SVGClipPathElement.idl b/Source/WebCore/svg/SVGClipPathElement.idl new file mode 100644 index 0000000..3dbc609 --- /dev/null +++ b/Source/WebCore/svg/SVGClipPathElement.idl @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGClipPathElement : SVGElement, + SVGTests, + SVGLangSpace, + SVGExternalResourcesRequired, + SVGStylable, + SVGTransformable + /* SVGUnitTypes */ { + readonly attribute SVGAnimatedEnumeration clipPathUnits; + }; + +} diff --git a/Source/WebCore/svg/SVGColor.cpp b/Source/WebCore/svg/SVGColor.cpp new file mode 100644 index 0000000..75900ad --- /dev/null +++ b/Source/WebCore/svg/SVGColor.cpp @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#if ENABLE(SVG) +#include "SVGColor.h" + +#include "CSSParser.h" +#include "RGBColor.h" +#include "SVGException.h" + +namespace WebCore { + +SVGColor::SVGColor() + : m_colorType(SVG_COLORTYPE_UNKNOWN) +{ +} + +SVGColor::SVGColor(const String& rgbColor) + : m_colorType(SVG_COLORTYPE_RGBCOLOR) +{ + setRGBColor(rgbColor); +} + +SVGColor::SVGColor(SVGColorType colorType) + : m_colorType(colorType) +{ +} + +SVGColor::SVGColor(const Color& c) + : m_color(c) + , m_colorType(SVG_COLORTYPE_RGBCOLOR) +{ +} + +PassRefPtr<RGBColor> SVGColor::rgbColor() const +{ + return RGBColor::create(m_color.rgb()); +} + +void SVGColor::setRGBColor(const String& rgbColor, ExceptionCode& ec) +{ + Color color = SVGColor::colorFromRGBColorString(rgbColor); + if (color.isValid()) + m_color = color; + else + ec = SVGException::SVG_INVALID_VALUE_ERR; +} + +Color SVGColor::colorFromRGBColorString(const String& colorString) +{ + String s = colorString.stripWhiteSpace(); + // FIXME: rework css parser so it is more svg aware + RGBA32 color; + if (CSSParser::parseColor(color, s)) + return color; + return Color(); +} + +void SVGColor::setRGBColorICCColor(const String& /* rgbColor */, const String& /* iccColor */, ExceptionCode&) +{ + // TODO: implement me! +} + +void SVGColor::setColor(unsigned short colorType, const String& /* rgbColor */ , const String& /* iccColor */, ExceptionCode&) +{ + // TODO: implement me! + m_colorType = colorType; +} + +String SVGColor::cssText() const +{ + if (m_colorType == SVG_COLORTYPE_RGBCOLOR) + return m_color.name(); + + return String(); +} + +} + +// vim:ts=4:noet +#endif // ENABLE(SVG) + diff --git a/Source/WebCore/svg/SVGColor.h b/Source/WebCore/svg/SVGColor.h new file mode 100644 index 0000000..6d8b94e --- /dev/null +++ b/Source/WebCore/svg/SVGColor.h @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGColor_h +#define SVGColor_h +#if ENABLE(SVG) + +#include "CSSValue.h" +#include "Color.h" +#include <wtf/PassRefPtr.h> + +namespace WebCore { + +class RGBColor; + +class SVGColor : public CSSValue { +public: + static PassRefPtr<SVGColor> create(const String& color) + { + return adoptRef(new SVGColor(color)); + } + static PassRefPtr<SVGColor> create(const Color& color) + { + return adoptRef(new SVGColor(color)); + } + static PassRefPtr<SVGColor> createCurrentColor() + { + return adoptRef(new SVGColor(SVG_COLORTYPE_CURRENTCOLOR)); + } + + enum SVGColorType { + SVG_COLORTYPE_UNKNOWN = 0, + SVG_COLORTYPE_RGBCOLOR = 1, + SVG_COLORTYPE_RGBCOLOR_ICCCOLOR = 2, + SVG_COLORTYPE_CURRENTCOLOR = 3 + }; + + // 'SVGColor' functions + unsigned short colorType() const { return m_colorType; } + + PassRefPtr<RGBColor> rgbColor() const; + + static Color colorFromRGBColorString(const String&); + + void setRGBColor(const String& rgbColor) { ExceptionCode ignored = 0; setRGBColor(rgbColor, ignored); } + void setRGBColor(const String& rgbColor, ExceptionCode&); + void setRGBColorICCColor(const String& rgbColor, const String& iccColor, ExceptionCode&); + void setColor(unsigned short colorType, const String& rgbColor, const String& iccColor, ExceptionCode&); + + const Color& color() const { return m_color; } + +protected: + SVGColor(); + SVGColor(const String& color); + SVGColor(const Color&); + + virtual String cssText() const; + +private: + SVGColor(SVGColorType); + + static void create(int); // compile-time guard + + virtual bool isSVGColor() const { return true; } + + Color m_color; + unsigned short m_colorType; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGColor_h + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGColor.idl b/Source/WebCore/svg/SVGColor.idl new file mode 100644 index 0000000..d7af0e9 --- /dev/null +++ b/Source/WebCore/svg/SVGColor.idl @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * Copyright (C) 2006 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +module svg { + + interface [Conditional=SVG] SVGColor : CSSValue { + // Color Types + const unsigned short SVG_COLORTYPE_UNKNOWN = 0; + const unsigned short SVG_COLORTYPE_RGBCOLOR = 1; + const unsigned short SVG_COLORTYPE_RGBCOLOR_ICCCOLOR = 2; + const unsigned short SVG_COLORTYPE_CURRENTCOLOR = 3; + + readonly attribute unsigned short colorType; + readonly attribute RGBColor rgbColor; + /*readonly attribute SVGICCColor iccColor;*/ + + void setRGBColor(in DOMString rgbColor) + raises(SVGException); + void setRGBColorICCColor(in DOMString rgbColor, + in DOMString iccColor) + raises(SVGException); + void setColor(in unsigned short colorType, + in DOMString rgbColor, + in DOMString iccColor) + raises(SVGException); + }; + +} diff --git a/Source/WebCore/svg/SVGComponentTransferFunctionElement.cpp b/Source/WebCore/svg/SVGComponentTransferFunctionElement.cpp new file mode 100644 index 0000000..142d82d --- /dev/null +++ b/Source/WebCore/svg/SVGComponentTransferFunctionElement.cpp @@ -0,0 +1,130 @@ +/* + * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGComponentTransferFunctionElement.h" + +#include "Attribute.h" +#include "SVGFEComponentTransferElement.h" +#include "SVGNames.h" +#include "SVGNumberList.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_ENUMERATION(SVGComponentTransferFunctionElement, SVGNames::typeAttr, Type, type) +DEFINE_ANIMATED_NUMBER_LIST(SVGComponentTransferFunctionElement, SVGNames::tableValuesAttr, TableValues, tableValues) +DEFINE_ANIMATED_NUMBER(SVGComponentTransferFunctionElement, SVGNames::slopeAttr, Slope, slope) +DEFINE_ANIMATED_NUMBER(SVGComponentTransferFunctionElement, SVGNames::interceptAttr, Intercept, intercept) +DEFINE_ANIMATED_NUMBER(SVGComponentTransferFunctionElement, SVGNames::amplitudeAttr, Amplitude, amplitude) +DEFINE_ANIMATED_NUMBER(SVGComponentTransferFunctionElement, SVGNames::exponentAttr, Exponent, exponent) +DEFINE_ANIMATED_NUMBER(SVGComponentTransferFunctionElement, SVGNames::offsetAttr, Offset, offset) + +SVGComponentTransferFunctionElement::SVGComponentTransferFunctionElement(const QualifiedName& tagName, Document* document) + : SVGElement(tagName, document) + , m_type(FECOMPONENTTRANSFER_TYPE_UNKNOWN) + , m_slope(1) + , m_amplitude(1) + , m_exponent(1) +{ +} + +void SVGComponentTransferFunctionElement::parseMappedAttribute(Attribute* attr) +{ + const String& value = attr->value(); + if (attr->name() == SVGNames::typeAttr) { + if (value == "identity") + setTypeBaseValue(FECOMPONENTTRANSFER_TYPE_IDENTITY); + else if (value == "table") + setTypeBaseValue(FECOMPONENTTRANSFER_TYPE_TABLE); + else if (value == "discrete") + setTypeBaseValue(FECOMPONENTTRANSFER_TYPE_DISCRETE); + else if (value == "linear") + setTypeBaseValue(FECOMPONENTTRANSFER_TYPE_LINEAR); + else if (value == "gamma") + setTypeBaseValue(FECOMPONENTTRANSFER_TYPE_GAMMA); + } else if (attr->name() == SVGNames::tableValuesAttr) { + SVGNumberList newList; + newList.parse(value); + detachAnimatedTableValuesListWrappers(newList.size()); + setTableValuesBaseValue(newList); + } else if (attr->name() == SVGNames::slopeAttr) + setSlopeBaseValue(value.toFloat()); + else if (attr->name() == SVGNames::interceptAttr) + setInterceptBaseValue(value.toFloat()); + else if (attr->name() == SVGNames::amplitudeAttr) + setAmplitudeBaseValue(value.toFloat()); + else if (attr->name() == SVGNames::exponentAttr) + setExponentBaseValue(value.toFloat()); + else if (attr->name() == SVGNames::offsetAttr) + setOffsetBaseValue(value.toFloat()); + else + SVGElement::parseMappedAttribute(attr); +} + +void SVGComponentTransferFunctionElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeType(); + synchronizeTableValues(); + synchronizeSlope(); + synchronizeIntercept(); + synchronizeAmplitude(); + synchronizeExponent(); + synchronizeOffset(); + return; + } + + if (attrName == SVGNames::typeAttr) + synchronizeType(); + else if (attrName == SVGNames::tableValuesAttr) + synchronizeTableValues(); + else if (attrName == SVGNames::slopeAttr) + synchronizeSlope(); + else if (attrName == SVGNames::interceptAttr) + synchronizeIntercept(); + else if (attrName == SVGNames::amplitudeAttr) + synchronizeAmplitude(); + else if (attrName == SVGNames::exponentAttr) + synchronizeExponent(); + else if (attrName == SVGNames::offsetAttr) + synchronizeOffset(); +} + +ComponentTransferFunction SVGComponentTransferFunctionElement::transferFunction() const +{ + ComponentTransferFunction func; + func.type = static_cast<ComponentTransferType>(type()); + func.slope = slope(); + func.intercept = intercept(); + func.amplitude = amplitude(); + func.exponent = exponent(); + func.offset = offset(); + func.tableValues = tableValues(); + return func; +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGComponentTransferFunctionElement.h b/Source/WebCore/svg/SVGComponentTransferFunctionElement.h new file mode 100644 index 0000000..5f836f7 --- /dev/null +++ b/Source/WebCore/svg/SVGComponentTransferFunctionElement.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGComponentTransferFunctionElement_h +#define SVGComponentTransferFunctionElement_h + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "FEComponentTransfer.h" +#include "SVGAnimatedEnumeration.h" +#include "SVGAnimatedNumber.h" +#include "SVGAnimatedNumberList.h" + +namespace WebCore { + +class SVGComponentTransferFunctionElement : public SVGElement { +public: + ComponentTransferFunction transferFunction() const; + +protected: + SVGComponentTransferFunctionElement(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + virtual void synchronizeProperty(const QualifiedName&); + +private: + // Animated property declarations + DECLARE_ANIMATED_ENUMERATION(Type, type) + DECLARE_ANIMATED_NUMBER_LIST(TableValues, tableValues) + DECLARE_ANIMATED_NUMBER(Slope, slope) + DECLARE_ANIMATED_NUMBER(Intercept, intercept) + DECLARE_ANIMATED_NUMBER(Amplitude, amplitude) + DECLARE_ANIMATED_NUMBER(Exponent, exponent) + DECLARE_ANIMATED_NUMBER(Offset, offset) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(FILTERS) +#endif diff --git a/Source/WebCore/svg/SVGComponentTransferFunctionElement.idl b/Source/WebCore/svg/SVGComponentTransferFunctionElement.idl new file mode 100644 index 0000000..e4a2596 --- /dev/null +++ b/Source/WebCore/svg/SVGComponentTransferFunctionElement.idl @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [ + Conditional=SVG&FILTERS, + DontCheckEnums + ] SVGComponentTransferFunctionElement : SVGElement { + // Component Transfer Types + const unsigned short SVG_FECOMPONENTTRANSFER_TYPE_UNKNOWN = 0; + const unsigned short SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY = 1; + const unsigned short SVG_FECOMPONENTTRANSFER_TYPE_TABLE = 2; + const unsigned short SVG_FECOMPONENTTRANSFER_TYPE_DISCRETE = 3; + const unsigned short SVG_FECOMPONENTTRANSFER_TYPE_LINEAR = 4; + const unsigned short SVG_FECOMPONENTTRANSFER_TYPE_GAMMA = 5; + + readonly attribute SVGAnimatedEnumeration type; + readonly attribute SVGAnimatedNumberList tableValues; + readonly attribute SVGAnimatedNumber slope; + readonly attribute SVGAnimatedNumber intercept; + readonly attribute SVGAnimatedNumber amplitude; + readonly attribute SVGAnimatedNumber exponent; + readonly attribute SVGAnimatedNumber offset; + }; + +} diff --git a/Source/WebCore/svg/SVGCursorElement.cpp b/Source/WebCore/svg/SVGCursorElement.cpp new file mode 100644 index 0000000..0c6a5d9 --- /dev/null +++ b/Source/WebCore/svg/SVGCursorElement.cpp @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGCursorElement.h" + +#include "Attr.h" +#include "Document.h" +#include "SVGNames.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_LENGTH(SVGCursorElement, SVGNames::xAttr, X, x) +DEFINE_ANIMATED_LENGTH(SVGCursorElement, SVGNames::yAttr, Y, y) +DEFINE_ANIMATED_STRING(SVGCursorElement, XLinkNames::hrefAttr, Href, href) +DEFINE_ANIMATED_BOOLEAN(SVGCursorElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) + +inline SVGCursorElement::SVGCursorElement(const QualifiedName& tagName, Document* document) + : SVGElement(tagName, document) + , m_x(LengthModeWidth) + , m_y(LengthModeHeight) +{ +} + +PassRefPtr<SVGCursorElement> SVGCursorElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGCursorElement(tagName, document)); +} + +SVGCursorElement::~SVGCursorElement() +{ + HashSet<SVGElement*>::iterator end = m_clients.end(); + for (HashSet<SVGElement*>::iterator it = m_clients.begin(); it != end; ++it) + (*it)->cursorElementRemoved(); +} + +void SVGCursorElement::parseMappedAttribute(Attribute* attr) +{ + if (attr->name() == SVGNames::xAttr) + setXBaseValue(SVGLength(LengthModeWidth, attr->value())); + else if (attr->name() == SVGNames::yAttr) + setYBaseValue(SVGLength(LengthModeHeight, attr->value())); + else { + if (SVGTests::parseMappedAttribute(attr)) + return; + if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) + return; + if (SVGURIReference::parseMappedAttribute(attr)) + return; + + SVGElement::parseMappedAttribute(attr); + } +} + +void SVGCursorElement::addClient(SVGElement* element) +{ + m_clients.add(element); + element->setCursorElement(this); +} + +void SVGCursorElement::removeClient(SVGElement* element) +{ + m_clients.remove(element); + element->cursorElementRemoved(); +} + +void SVGCursorElement::removeReferencedElement(SVGElement* element) +{ + m_clients.remove(element); +} + +void SVGCursorElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGElement::svgAttributeChanged(attrName); + + if (attrName == SVGNames::xAttr + || attrName == SVGNames::yAttr + || SVGTests::isKnownAttribute(attrName) + || SVGExternalResourcesRequired::isKnownAttribute(attrName) + || SVGURIReference::isKnownAttribute(attrName)) { + HashSet<SVGElement*>::const_iterator it = m_clients.begin(); + HashSet<SVGElement*>::const_iterator end = m_clients.end(); + + for (; it != end; ++it) + (*it)->setNeedsStyleRecalc(); + } +} + +void SVGCursorElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeX(); + synchronizeY(); + synchronizeExternalResourcesRequired(); + synchronizeHref(); + SVGTests::synchronizeProperties(this, attrName); + return; + } + + if (attrName == SVGNames::xAttr) + synchronizeX(); + else if (attrName == SVGNames::yAttr) + synchronizeY(); + else if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) + synchronizeExternalResourcesRequired(); + else if (SVGURIReference::isKnownAttribute(attrName)) + synchronizeHref(); + else if (SVGTests::isKnownAttribute(attrName)) + SVGTests::synchronizeProperties(this, attrName); +} + +void SVGCursorElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const +{ + SVGElement::addSubresourceAttributeURLs(urls); + + addSubresourceURL(urls, document()->completeURL(href())); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGCursorElement.h b/Source/WebCore/svg/SVGCursorElement.h new file mode 100644 index 0000000..cd4a44e --- /dev/null +++ b/Source/WebCore/svg/SVGCursorElement.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGCursorElement_h +#define SVGCursorElement_h + +#if ENABLE(SVG) +#include "SVGAnimatedBoolean.h" +#include "SVGAnimatedLength.h" +#include "SVGAnimatedString.h" +#include "SVGElement.h" +#include "SVGExternalResourcesRequired.h" +#include "SVGTests.h" +#include "SVGURIReference.h" + +namespace WebCore { + +class SVGCursorElement : public SVGElement, + public SVGTests, + public SVGExternalResourcesRequired, + public SVGURIReference { +public: + static PassRefPtr<SVGCursorElement> create(const QualifiedName&, Document*); + + virtual ~SVGCursorElement(); + + void addClient(SVGElement*); + void removeClient(SVGElement*); + void removeReferencedElement(SVGElement*); + +private: + SVGCursorElement(const QualifiedName&, Document*); + + virtual bool isValid() const { return SVGTests::isValid(); } + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + + virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const; + + // Animated property declarations + DECLARE_ANIMATED_LENGTH(X, x) + DECLARE_ANIMATED_LENGTH(Y, y) + + // SVGURIReference + DECLARE_ANIMATED_STRING(Href, href) + + // SVGExternalResourcesRequired + DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) + + HashSet<SVGElement*> m_clients; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGCursorElement.idl b/Source/WebCore/svg/SVGCursorElement.idl new file mode 100644 index 0000000..3ff701f --- /dev/null +++ b/Source/WebCore/svg/SVGCursorElement.idl @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGCursorElement : SVGElement, + SVGURIReference, + SVGTests, + SVGExternalResourcesRequired { + readonly attribute SVGAnimatedLength x; + readonly attribute SVGAnimatedLength y; + }; + +} diff --git a/Source/WebCore/svg/SVGDefsElement.cpp b/Source/WebCore/svg/SVGDefsElement.cpp new file mode 100644 index 0000000..59c5415 --- /dev/null +++ b/Source/WebCore/svg/SVGDefsElement.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGDefsElement.h" + +#include "RenderSVGHiddenContainer.h" +#include "SVGNames.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_BOOLEAN(SVGDefsElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) + +inline SVGDefsElement::SVGDefsElement(const QualifiedName& tagName, Document* document) + : SVGStyledTransformableElement(tagName, document) +{ +} + +PassRefPtr<SVGDefsElement> SVGDefsElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGDefsElement(tagName, document)); +} + +bool SVGDefsElement::isValid() const +{ + return SVGTests::isValid(); +} + +RenderObject* SVGDefsElement::createRenderer(RenderArena* arena, RenderStyle*) +{ + return new (arena) RenderSVGHiddenContainer(this); +} + +void SVGDefsElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGStyledTransformableElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeExternalResourcesRequired(); + SVGTests::synchronizeProperties(this, attrName); + return; + } + + if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) + synchronizeExternalResourcesRequired(); + else if (SVGTests::isKnownAttribute(attrName)) + SVGTests::synchronizeProperties(this, attrName); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGDefsElement.h b/Source/WebCore/svg/SVGDefsElement.h new file mode 100644 index 0000000..70eca95 --- /dev/null +++ b/Source/WebCore/svg/SVGDefsElement.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGDefsElement_h +#define SVGDefsElement_h + +#if ENABLE(SVG) +#include "SVGAnimatedBoolean.h" +#include "SVGExternalResourcesRequired.h" +#include "SVGLangSpace.h" +#include "SVGStyledTransformableElement.h" +#include "SVGTests.h" + +namespace WebCore { + +class SVGDefsElement : public SVGStyledTransformableElement, + public SVGTests, + public SVGLangSpace, + public SVGExternalResourcesRequired { +public: + static PassRefPtr<SVGDefsElement> create(const QualifiedName&, Document*); + +private: + SVGDefsElement(const QualifiedName&, Document*); + + virtual bool isValid() const; + + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + virtual void synchronizeProperty(const QualifiedName&); + + // Animated property declarations + + // SVGExternalResourcesRequired + DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGDefsElement.idl b/Source/WebCore/svg/SVGDefsElement.idl new file mode 100644 index 0000000..e90b0b6 --- /dev/null +++ b/Source/WebCore/svg/SVGDefsElement.idl @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGDefsElement : SVGElement, + SVGTests, + SVGLangSpace, + SVGExternalResourcesRequired, + SVGStylable, + SVGTransformable { + }; + +} diff --git a/Source/WebCore/svg/SVGDescElement.cpp b/Source/WebCore/svg/SVGDescElement.cpp new file mode 100644 index 0000000..720146c --- /dev/null +++ b/Source/WebCore/svg/SVGDescElement.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#if ENABLE(SVG) +#include "SVGDescElement.h" + +namespace WebCore { + +inline SVGDescElement::SVGDescElement(const QualifiedName& tagName, Document* document) + : SVGStyledElement(tagName, document) +{ +} + +PassRefPtr<SVGDescElement> SVGDescElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGDescElement(tagName, document)); +} + +String SVGDescElement::description() const +{ + return textContent().simplifyWhiteSpace(); +} + +} + +// vim:ts=4:noet +#endif // ENABLE(SVG) + diff --git a/Source/WebCore/svg/SVGDescElement.h b/Source/WebCore/svg/SVGDescElement.h new file mode 100644 index 0000000..32a7ad0 --- /dev/null +++ b/Source/WebCore/svg/SVGDescElement.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGDescElement_h +#define SVGDescElement_h + +#if ENABLE(SVG) +#include "SVGLangSpace.h" +#include "SVGStyledElement.h" + +namespace WebCore { + +class SVGDescElement : public SVGStyledElement, + public SVGLangSpace { +public: + static PassRefPtr<SVGDescElement> create(const QualifiedName&, Document*); + + String description() const; + +private: + SVGDescElement(const QualifiedName&, Document*); + + virtual bool rendererIsNeeded(RenderStyle*) { return false; } +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGDescElement.idl b/Source/WebCore/svg/SVGDescElement.idl new file mode 100644 index 0000000..eceab2d --- /dev/null +++ b/Source/WebCore/svg/SVGDescElement.idl @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGDescElement : SVGElement, + SVGLangSpace, + SVGStylable { + }; + +} diff --git a/Source/WebCore/svg/SVGDocument.cpp b/Source/WebCore/svg/SVGDocument.cpp new file mode 100644 index 0000000..9b200b7 --- /dev/null +++ b/Source/WebCore/svg/SVGDocument.cpp @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#if ENABLE(SVG) +#include "SVGDocument.h" + +#include "EventNames.h" +#include "ExceptionCode.h" +#include "FrameView.h" +#include "RenderView.h" +#include "SVGElement.h" +#include "SVGNames.h" +#include "SVGSVGElement.h" +#include "SVGViewSpec.h" +#include "SVGZoomAndPan.h" +#include "SVGZoomEvent.h" + +namespace WebCore { + +SVGDocument::SVGDocument(Frame* frame, const KURL& url) + : Document(frame, url, false, false) +{ +} + +SVGSVGElement* SVGDocument::rootElement() const +{ + Element* elem = documentElement(); + if (elem && elem->hasTagName(SVGNames::svgTag)) + return static_cast<SVGSVGElement*>(elem); + + return 0; +} + +void SVGDocument::dispatchZoomEvent(float prevScale, float newScale) +{ + ExceptionCode ec = 0; + RefPtr<SVGZoomEvent> event = static_pointer_cast<SVGZoomEvent>(createEvent("SVGZoomEvents", ec)); + event->initEvent(eventNames().zoomEvent, true, false); + event->setPreviousScale(prevScale); + event->setNewScale(newScale); + rootElement()->dispatchEvent(event.release(), ec); +} + +void SVGDocument::dispatchScrollEvent() +{ + ExceptionCode ec = 0; + RefPtr<Event> event = createEvent("SVGEvents", ec); + event->initEvent(eventNames().scrollEvent, true, false); + rootElement()->dispatchEvent(event.release(), ec); +} + +bool SVGDocument::zoomAndPanEnabled() const +{ + if (rootElement()) { + if (rootElement()->useCurrentView()) { + if (rootElement()->currentView()) + return rootElement()->currentView()->zoomAndPan() == SVGZoomAndPan::SVG_ZOOMANDPAN_MAGNIFY; + } else + return rootElement()->zoomAndPan() == SVGZoomAndPan::SVG_ZOOMANDPAN_MAGNIFY; + } + + return false; +} + +void SVGDocument::startPan(const FloatPoint& start) +{ + if (rootElement()) + m_translate = FloatPoint(start.x() - rootElement()->currentTranslate().x(), rootElement()->currentTranslate().y() + start.y()); +} + +void SVGDocument::updatePan(const FloatPoint& pos) const +{ + if (rootElement()) { + rootElement()->setCurrentTranslate(FloatPoint(pos.x() - m_translate.x(), m_translate.y() - pos.y())); + if (renderer()) + renderer()->repaint(); + } +} + +bool SVGDocument::childShouldCreateRenderer(Node* node) const +{ + if (node->hasTagName(SVGNames::svgTag)) + return static_cast<SVGSVGElement*>(node)->isValid(); + return true; +} + +} + +// vim:ts=4:noet +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGDocument.h b/Source/WebCore/svg/SVGDocument.h new file mode 100644 index 0000000..b934145 --- /dev/null +++ b/Source/WebCore/svg/SVGDocument.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGDocument_h +#define SVGDocument_h +#if ENABLE(SVG) + +#include "Document.h" +#include "FloatPoint.h" + +namespace WebCore { + +class DOMImplementation; +class SVGElement; +class SVGSVGElement; + +class SVGDocument : public Document { +public: + static PassRefPtr<SVGDocument> create(Frame* frame, const KURL& url) + { + return adoptRef(new SVGDocument(frame, url)); + } + + SVGSVGElement* rootElement() const; + + void dispatchZoomEvent(float prevScale, float newScale); + void dispatchScrollEvent(); + + bool zoomAndPanEnabled() const; + + void startPan(const FloatPoint& start); + void updatePan(const FloatPoint& pos) const; + +private: + SVGDocument(Frame*, const KURL&); + + virtual bool isSVGDocument() const { return true; } + + virtual bool childShouldCreateRenderer(Node*) const; + + FloatPoint m_translate; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGDocument_h + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGDocument.idl b/Source/WebCore/svg/SVGDocument.idl new file mode 100644 index 0000000..fbf02ea --- /dev/null +++ b/Source/WebCore/svg/SVGDocument.idl @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * Copyright (C) 2006 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +module svg { + + interface [Conditional=SVG] SVGDocument : Document { + readonly attribute SVGSVGElement rootElement; + + // Overwrite the one in events::DocumentEvent + Event createEvent(in DOMString eventType) + raises(DOMException); + }; + +} diff --git a/Source/WebCore/svg/SVGDocumentExtensions.cpp b/Source/WebCore/svg/SVGDocumentExtensions.cpp new file mode 100644 index 0000000..3fd9761 --- /dev/null +++ b/Source/WebCore/svg/SVGDocumentExtensions.cpp @@ -0,0 +1,195 @@ +/* + * Copyright (C) 2006 Apple Inc. All rights reserved. + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGDocumentExtensions.h" + +#include "Console.h" +#include "DOMWindow.h" +#include "Document.h" +#include "EventListener.h" +#include "Frame.h" +#include "FrameLoader.h" +#include "Page.h" +#include "SMILTimeContainer.h" +#include "SVGSMILElement.h" +#include "SVGSVGElement.h" +#include "ScriptController.h" +#include "ScriptableDocumentParser.h" +#include <wtf/text/AtomicString.h> + +namespace WebCore { + +SVGDocumentExtensions::SVGDocumentExtensions(Document* document) + : m_document(document) + , m_resourcesCache(adoptPtr(new SVGResourcesCache)) +{ +} + +SVGDocumentExtensions::~SVGDocumentExtensions() +{ + deleteAllValues(m_pendingResources); +} + +void SVGDocumentExtensions::addTimeContainer(SVGSVGElement* element) +{ + m_timeContainers.add(element); +} + +void SVGDocumentExtensions::removeTimeContainer(SVGSVGElement* element) +{ + m_timeContainers.remove(element); +} + +void SVGDocumentExtensions::addResource(const AtomicString& id, RenderSVGResourceContainer* resource) +{ + ASSERT(resource); + + if (id.isEmpty()) + return; + + // Replaces resource if already present, to handle potential id changes + m_resources.set(id, resource); +} + +void SVGDocumentExtensions::removeResource(const AtomicString& id) +{ + if (id.isEmpty() || !m_resources.contains(id)) + return; + + m_resources.remove(id); +} + +RenderSVGResourceContainer* SVGDocumentExtensions::resourceById(const AtomicString& id) const +{ + if (id.isEmpty()) + return 0; + + return m_resources.get(id); +} + +void SVGDocumentExtensions::startAnimations() +{ + // FIXME: Eventually every "Time Container" will need a way to latch on to some global timer + // starting animations for a document will do this "latching" +#if ENABLE(SVG_ANIMATION) + HashSet<SVGSVGElement*>::iterator end = m_timeContainers.end(); + for (HashSet<SVGSVGElement*>::iterator itr = m_timeContainers.begin(); itr != end; ++itr) + (*itr)->timeContainer()->begin(); +#endif +} + +void SVGDocumentExtensions::pauseAnimations() +{ + HashSet<SVGSVGElement*>::iterator end = m_timeContainers.end(); + for (HashSet<SVGSVGElement*>::iterator itr = m_timeContainers.begin(); itr != end; ++itr) + (*itr)->pauseAnimations(); +} + +void SVGDocumentExtensions::unpauseAnimations() +{ + HashSet<SVGSVGElement*>::iterator end = m_timeContainers.end(); + for (HashSet<SVGSVGElement*>::iterator itr = m_timeContainers.begin(); itr != end; ++itr) + (*itr)->unpauseAnimations(); +} + +bool SVGDocumentExtensions::sampleAnimationAtTime(const String& elementId, SVGSMILElement* element, double time) +{ +#if !ENABLE(SVG_ANIMATION) + UNUSED_PARAM(elementId); + UNUSED_PARAM(element); + UNUSED_PARAM(time); + return false; +#else + ASSERT(element); + SMILTimeContainer* container = element->timeContainer(); + if (!container || container->isPaused()) + return false; + + container->sampleAnimationAtTime(elementId, time); + return true; +#endif +} + +// FIXME: Callers should probably use ScriptController::eventHandlerLineNumber() +static int parserLineNumber(Document* document) +{ + ScriptableDocumentParser* parser = document->scriptableDocumentParser(); + if (!parser) + return 1; + return parser->lineNumber(); +} + +static void reportMessage(Document* document, MessageLevel level, const String& message) +{ + if (Frame* frame = document->frame()) + frame->domWindow()->console()->addMessage(JSMessageSource, LogMessageType, level, message, parserLineNumber(document), String()); +} + +void SVGDocumentExtensions::reportWarning(const String& message) +{ + reportMessage(m_document, WarningMessageLevel, "Warning: " + message); +} + +void SVGDocumentExtensions::reportError(const String& message) +{ + reportMessage(m_document, ErrorMessageLevel, "Error: " + message); +} + +void SVGDocumentExtensions::addPendingResource(const AtomicString& id, PassRefPtr<SVGStyledElement> obj) +{ + ASSERT(obj); + + if (id.isEmpty()) + return; + + if (m_pendingResources.contains(id)) + m_pendingResources.get(id)->add(obj); + else { + SVGPendingElements* set = new SVGPendingElements; + set->add(obj); + + m_pendingResources.add(id, set); + } +} + +bool SVGDocumentExtensions::isPendingResource(const AtomicString& id) const +{ + if (id.isEmpty()) + return false; + + return m_pendingResources.contains(id); +} + +PassOwnPtr<HashSet<RefPtr<SVGStyledElement> > > SVGDocumentExtensions::removePendingResource(const AtomicString& id) +{ + ASSERT(m_pendingResources.contains(id)); + + OwnPtr<SVGPendingElements> set(m_pendingResources.get(id)); + m_pendingResources.remove(id); + return set.release(); +} + +} + +#endif diff --git a/Source/WebCore/svg/SVGDocumentExtensions.h b/Source/WebCore/svg/SVGDocumentExtensions.h new file mode 100644 index 0000000..a0cf2bb --- /dev/null +++ b/Source/WebCore/svg/SVGDocumentExtensions.h @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2006 Apple Inc. All rights reserved. + * Copyright (C) 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGDocumentExtensions_h +#define SVGDocumentExtensions_h + +#if ENABLE(SVG) +#include "SVGResourcesCache.h" +#include <wtf/Forward.h> +#include <wtf/HashMap.h> +#include <wtf/HashSet.h> +#include <wtf/PassOwnPtr.h> +#include <wtf/text/AtomicStringHash.h> +#include <wtf/text/StringImpl.h> + +namespace WebCore { + +class Document; +class RenderSVGResourceContainer; +class SVGStyledElement; +class SVGSMILElement; +class SVGSVGElement; + +class SVGDocumentExtensions : public Noncopyable { +public: + typedef HashSet<RefPtr<SVGStyledElement> > SVGPendingElements; + SVGDocumentExtensions(Document*); + ~SVGDocumentExtensions(); + + void addTimeContainer(SVGSVGElement*); + void removeTimeContainer(SVGSVGElement*); + + void addResource(const AtomicString& id, RenderSVGResourceContainer*); + void removeResource(const AtomicString& id); + RenderSVGResourceContainer* resourceById(const AtomicString& id) const; + + void startAnimations(); + void pauseAnimations(); + void unpauseAnimations(); + bool sampleAnimationAtTime(const String& elementId, SVGSMILElement*, double time); + + void reportWarning(const String&); + void reportError(const String&); + + SVGResourcesCache* resourcesCache() const { return m_resourcesCache.get(); } + +private: + Document* m_document; // weak reference + HashSet<SVGSVGElement*> m_timeContainers; // For SVG 1.2 support this will need to be made more general. + HashMap<AtomicString, RenderSVGResourceContainer*> m_resources; + HashMap<AtomicString, SVGPendingElements*> m_pendingResources; + OwnPtr<SVGResourcesCache> m_resourcesCache; + + SVGDocumentExtensions(const SVGDocumentExtensions&); + SVGDocumentExtensions& operator=(const SVGDocumentExtensions&); + +public: + // This HashMap contains a list of pending resources. Pending resources, are such + // which are referenced by any object in the SVG document, but do NOT exist yet. + // For instance, dynamically build gradients / patterns / clippers... + void addPendingResource(const AtomicString& id, PassRefPtr<SVGStyledElement>); + bool isPendingResource(const AtomicString& id) const; + PassOwnPtr<SVGPendingElements> removePendingResource(const AtomicString& id); +}; + +} + +#endif +#endif diff --git a/Source/WebCore/svg/SVGElement.cpp b/Source/WebCore/svg/SVGElement.cpp new file mode 100644 index 0000000..1f5b0fa --- /dev/null +++ b/Source/WebCore/svg/SVGElement.cpp @@ -0,0 +1,376 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2008 Rob Buis <buis@kde.org> + * Copyright (C) 2008 Apple Inc. All rights reserved. + * Copyright (C) 2008 Alp Toker <alp@atoker.com> + * Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGElement.h" + +#include "Attribute.h" +#include "CSSCursorImageValue.h" +#include "DOMImplementation.h" +#include "Document.h" +#include "Event.h" +#include "EventListener.h" +#include "EventNames.h" +#include "FrameView.h" +#include "HTMLNames.h" +#include "RegisteredEventListener.h" +#include "RenderObject.h" +#include "SVGCursorElement.h" +#include "SVGElementInstance.h" +#include "SVGElementRareData.h" +#include "SVGNames.h" +#include "SVGSVGElement.h" +#include "SVGStyledLocatableElement.h" +#include "SVGTextElement.h" +#include "SVGURIReference.h" +#include "SVGUseElement.h" +#include "ScriptEventListener.h" +#include "XMLNames.h" + +namespace WebCore { + +using namespace HTMLNames; + +SVGElement::SVGElement(const QualifiedName& tagName, Document* document) + : StyledElement(tagName, document, CreateSVGElement) +{ +} + +PassRefPtr<SVGElement> SVGElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGElement(tagName, document)); +} + +SVGElement::~SVGElement() +{ + if (!hasRareSVGData()) + ASSERT(!SVGElementRareData::rareDataMap().contains(this)); + else { + SVGElementRareData::SVGElementRareDataMap& rareDataMap = SVGElementRareData::rareDataMap(); + SVGElementRareData::SVGElementRareDataMap::iterator it = rareDataMap.find(this); + ASSERT(it != rareDataMap.end()); + + SVGElementRareData* rareData = it->second; + if (SVGCursorElement* cursorElement = rareData->cursorElement()) + cursorElement->removeClient(this); + if (CSSCursorImageValue* cursorImageValue = rareData->cursorImageValue()) + cursorImageValue->removeReferencedElement(this); + + delete rareData; + rareDataMap.remove(it); + } +} + +SVGElementRareData* SVGElement::rareSVGData() const +{ + ASSERT(hasRareSVGData()); + return SVGElementRareData::rareDataFromMap(this); +} + +SVGElementRareData* SVGElement::ensureRareSVGData() +{ + if (hasRareSVGData()) + return rareSVGData(); + + ASSERT(!SVGElementRareData::rareDataMap().contains(this)); + SVGElementRareData* data = new SVGElementRareData; + SVGElementRareData::rareDataMap().set(this, data); + setHasRareSVGData(); + return data; +} + +bool SVGElement::isSupported(StringImpl* feature, StringImpl* version) const +{ + return DOMImplementation::hasFeature(feature, version); +} + +String SVGElement::xmlbase() const +{ + return getAttribute(XMLNames::baseAttr); +} + +void SVGElement::setXmlbase(const String& value, ExceptionCode&) +{ + setAttribute(XMLNames::baseAttr, value); +} + +SVGSVGElement* SVGElement::ownerSVGElement() const +{ + ContainerNode* n = parentOrHostNode(); + while (n) { + if (n->hasTagName(SVGNames::svgTag)) + return static_cast<SVGSVGElement*>(n); + + n = n->parentOrHostNode(); + } + + return 0; +} + +SVGElement* SVGElement::viewportElement() const +{ + // This function needs shadow tree support - as RenderSVGContainer uses this function + // to determine the "overflow" property. <use> on <symbol> wouldn't work otherwhise. + ContainerNode* n = parentOrHostNode(); + while (n) { + if (n->hasTagName(SVGNames::svgTag) || n->hasTagName(SVGNames::imageTag) || n->hasTagName(SVGNames::symbolTag)) + return static_cast<SVGElement*>(n); + + n = n->parentOrHostNode(); + } + + return 0; +} + +SVGDocumentExtensions* SVGElement::accessDocumentSVGExtensions() const +{ + // This function is provided for use by SVGAnimatedProperty to avoid + // global inclusion of Document.h in SVG code. + return document() ? document()->accessSVGExtensions() : 0; +} + +void SVGElement::mapInstanceToElement(SVGElementInstance* instance) +{ + ASSERT(instance); + + HashSet<SVGElementInstance*>& instances = ensureRareSVGData()->elementInstances(); + ASSERT(!instances.contains(instance)); + + instances.add(instance); +} + +void SVGElement::removeInstanceMapping(SVGElementInstance* instance) +{ + ASSERT(instance); + ASSERT(hasRareSVGData()); + + HashSet<SVGElementInstance*>& instances = rareSVGData()->elementInstances(); + ASSERT(instances.contains(instance)); + + instances.remove(instance); +} + +const HashSet<SVGElementInstance*>& SVGElement::instancesForElement() const +{ + if (!hasRareSVGData()) { + DEFINE_STATIC_LOCAL(HashSet<SVGElementInstance*>, emptyInstances, ()); + return emptyInstances; + } + return rareSVGData()->elementInstances(); +} + +bool SVGElement::boundingBox(FloatRect& rect, SVGLocatable::StyleUpdateStrategy styleUpdateStrategy) const +{ + if (isStyledLocatable()) { + rect = static_cast<const SVGStyledLocatableElement*>(this)->getBBox(styleUpdateStrategy); + return true; + } + if (hasTagName(SVGNames::textTag)) { + rect = static_cast<const SVGTextElement*>(this)->getBBox(styleUpdateStrategy); + return true; + } + return false; +} + +void SVGElement::setCursorElement(SVGCursorElement* cursorElement) +{ + SVGElementRareData* rareData = ensureRareSVGData(); + if (SVGCursorElement* oldCursorElement = rareData->cursorElement()) { + if (cursorElement == oldCursorElement) + return; + oldCursorElement->removeReferencedElement(this); + } + rareData->setCursorElement(cursorElement); +} + +void SVGElement::cursorElementRemoved() +{ + ASSERT(hasRareSVGData()); + rareSVGData()->setCursorElement(0); +} + +void SVGElement::setCursorImageValue(CSSCursorImageValue* cursorImageValue) +{ + SVGElementRareData* rareData = ensureRareSVGData(); + if (CSSCursorImageValue* oldCursorImageValue = rareData->cursorImageValue()) { + if (cursorImageValue == oldCursorImageValue) + return; + oldCursorImageValue->removeReferencedElement(this); + } + rareData->setCursorImageValue(cursorImageValue); +} + +void SVGElement::cursorImageValueRemoved() +{ + ASSERT(hasRareSVGData()); + rareSVGData()->setCursorImageValue(0); +} + +void SVGElement::parseMappedAttribute(Attribute* attr) +{ + // standard events + if (attr->name() == onloadAttr) + setAttributeEventListener(eventNames().loadEvent, createAttributeEventListener(this, attr)); + else if (attr->name() == onclickAttr) + setAttributeEventListener(eventNames().clickEvent, createAttributeEventListener(this, attr)); + else if (attr->name() == onmousedownAttr) + setAttributeEventListener(eventNames().mousedownEvent, createAttributeEventListener(this, attr)); + else if (attr->name() == onmousemoveAttr) + setAttributeEventListener(eventNames().mousemoveEvent, createAttributeEventListener(this, attr)); + else if (attr->name() == onmouseoutAttr) + setAttributeEventListener(eventNames().mouseoutEvent, createAttributeEventListener(this, attr)); + else if (attr->name() == onmouseoverAttr) + setAttributeEventListener(eventNames().mouseoverEvent, createAttributeEventListener(this, attr)); + else if (attr->name() == onmouseupAttr) + setAttributeEventListener(eventNames().mouseupEvent, createAttributeEventListener(this, attr)); + else if (attr->name() == SVGNames::onfocusinAttr) + setAttributeEventListener(eventNames().focusinEvent, createAttributeEventListener(this, attr)); + else if (attr->name() == SVGNames::onfocusoutAttr) + setAttributeEventListener(eventNames().focusoutEvent, createAttributeEventListener(this, attr)); + else if (attr->name() == SVGNames::onactivateAttr) + setAttributeEventListener(eventNames().DOMActivateEvent, createAttributeEventListener(this, attr)); + else + StyledElement::parseMappedAttribute(attr); +} + +bool SVGElement::haveLoadedRequiredResources() +{ + Node* child = firstChild(); + while (child) { + if (child->isSVGElement() && !static_cast<SVGElement*>(child)->haveLoadedRequiredResources()) + return false; + child = child->nextSibling(); + } + return true; +} + +static bool hasLoadListener(Node* node) +{ + if (node->hasEventListeners(eventNames().loadEvent)) + return true; + + for (node = node->parentNode(); node && node->isElementNode(); node = node->parentNode()) { + const EventListenerVector& entry = node->getEventListeners(eventNames().loadEvent); + for (size_t i = 0; i < entry.size(); ++i) { + if (entry[i].useCapture) + return true; + } + } + + return false; +} + +void SVGElement::sendSVGLoadEventIfPossible(bool sendParentLoadEvents) +{ + RefPtr<SVGElement> currentTarget = this; + while (currentTarget && currentTarget->haveLoadedRequiredResources()) { + RefPtr<Node> parent; + if (sendParentLoadEvents) + parent = currentTarget->parentNode(); // save the next parent to dispatch too incase dispatching the event changes the tree + if (hasLoadListener(currentTarget.get())) { + RefPtr<Event> event = Event::create(eventNames().loadEvent, false, false); + event->setTarget(currentTarget); + currentTarget->dispatchGenericEvent(event.release()); + } + currentTarget = (parent && parent->isSVGElement()) ? static_pointer_cast<SVGElement>(parent) : 0; + } +} + +void SVGElement::finishParsingChildren() +{ + StyledElement::finishParsingChildren(); + + // finishParsingChildren() is called when the close tag is reached for an element (e.g. </svg>) + // we send SVGLoad events here if we can, otherwise they'll be sent when any required loads finish + sendSVGLoadEventIfPossible(); +} + +bool SVGElement::childShouldCreateRenderer(Node* child) const +{ + if (child->isSVGElement()) + return static_cast<SVGElement*>(child)->isValid(); + return false; +} + +void SVGElement::insertedIntoDocument() +{ + StyledElement::insertedIntoDocument(); + + if (!needsPendingResourceHandling()) + return; + + SVGDocumentExtensions* extensions = document()->accessSVGExtensions(); + String resourceId = getIdAttribute(); + if (!extensions->isPendingResource(resourceId)) + return; + + OwnPtr<SVGDocumentExtensions::SVGPendingElements> clients(extensions->removePendingResource(resourceId)); + if (clients->isEmpty()) + return; + + const SVGDocumentExtensions::SVGPendingElements::const_iterator end = clients->end(); + for (SVGDocumentExtensions::SVGPendingElements::const_iterator it = clients->begin(); it != end; ++it) + (*it)->buildPendingResource(); +} + +void SVGElement::attributeChanged(Attribute* attr, bool preserveDecls) +{ + ASSERT(attr); + if (!attr) + return; + + StyledElement::attributeChanged(attr, preserveDecls); + + // When an animated SVG property changes through SVG DOM, svgAttributeChanged() is called, not attributeChanged(). + // Next time someone tries to access the XML attributes, the synchronization code starts. During that synchronization + // SVGAnimatedPropertySynchronizer may call NamedNodeMap::removeAttribute(), which in turn calls attributeChanged(). + // At this point we're not allowed to call svgAttributeChanged() again - it may lead to extra work being done, or crashes + // see bug https://bugs.webkit.org/show_bug.cgi?id=40994. + if (isSynchronizingSVGAttributes()) + return; + + // Changes to the style attribute are processed lazily (see Element::getAttribute() and related methods), + // so we don't want changes to the style attribute to result in extra work here. + if (attr->name() != HTMLNames::styleAttr) + svgAttributeChanged(attr->name()); +} + +void SVGElement::updateAnimatedSVGAttribute(const QualifiedName& name) const +{ + if (isSynchronizingSVGAttributes() || areSVGAttributesValid()) + return; + + setIsSynchronizingSVGAttributes(); + + const_cast<SVGElement*>(this)->synchronizeProperty(name); + if (name == anyQName()) + setAreSVGAttributesValid(); + + clearIsSynchronizingSVGAttributes(); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGElement.h b/Source/WebCore/svg/SVGElement.h new file mode 100644 index 0000000..d961c73 --- /dev/null +++ b/Source/WebCore/svg/SVGElement.h @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGElement_h +#define SVGElement_h + +#if ENABLE(SVG) +#include "SVGDocumentExtensions.h" +#include "SVGLocatable.h" +#include "StyledElement.h" + +namespace WebCore { + +class CSSCursorImageValue; +class Document; +class SVGCursorElement; +class SVGElementInstance; +class SVGElementRareData; +class SVGSVGElement; +class AffineTransform; + +class SVGElement : public StyledElement { +public: + static PassRefPtr<SVGElement> create(const QualifiedName&, Document*); + virtual ~SVGElement(); + + String xmlbase() const; + void setXmlbase(const String&, ExceptionCode&); + + SVGSVGElement* ownerSVGElement() const; + SVGElement* viewportElement() const; + + SVGDocumentExtensions* accessDocumentSVGExtensions() const; + + virtual bool isStyled() const { return false; } + virtual bool isStyledTransformable() const { return false; } + virtual bool isStyledLocatable() const { return false; } + virtual bool isSVG() const { return false; } + virtual bool isFilterEffect() const { return false; } + virtual bool isGradientStop() const { return false; } + virtual bool isTextContent() const { return false; } + + // For SVGTests + virtual bool isValid() const { return true; } + + virtual void svgAttributeChanged(const QualifiedName&) { } + virtual void synchronizeProperty(const QualifiedName&) { } + + void sendSVGLoadEventIfPossible(bool sendParentLoadEvents = false); + + virtual AffineTransform* supplementalTransform() { return 0; } + + void invalidateSVGAttributes() { clearAreSVGAttributesValid(); } + + const HashSet<SVGElementInstance*>& instancesForElement() const; + + bool boundingBox(FloatRect&, SVGLocatable::StyleUpdateStrategy = SVGLocatable::AllowStyleUpdate) const; + + void setCursorElement(SVGCursorElement*); + void cursorElementRemoved(); + void setCursorImageValue(CSSCursorImageValue*); + void cursorImageValueRemoved(); + + virtual void updateAnimatedSVGAttribute(const QualifiedName&) const; + +protected: + SVGElement(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + + virtual void finishParsingChildren(); + virtual void insertedIntoDocument(); + virtual void attributeChanged(Attribute*, bool preserveDecls = false); + virtual bool childShouldCreateRenderer(Node*) const; + + SVGElementRareData* rareSVGData() const; + SVGElementRareData* ensureRareSVGData(); + +private: + friend class SVGElementInstance; + + virtual bool rendererIsNeeded(RenderStyle*) { return false; } + + virtual bool isSupported(StringImpl* feature, StringImpl* version) const; + + virtual bool needsPendingResourceHandling() const { return true; } + virtual void buildPendingResource() { } + + void mapInstanceToElement(SVGElementInstance*); + void removeInstanceMapping(SVGElementInstance*); + + virtual bool haveLoadedRequiredResources(); +}; + +} + +#endif +#endif diff --git a/Source/WebCore/svg/SVGElement.idl b/Source/WebCore/svg/SVGElement.idl new file mode 100644 index 0000000..956fa32 --- /dev/null +++ b/Source/WebCore/svg/SVGElement.idl @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) 2006 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +module svg { + + interface [GenerateNativeConverter, Conditional=SVG] SVGElement : Element { + attribute [Reflect] DOMString id setter raises(DOMException); + attribute [ConvertNullToNullString] DOMString xmlbase setter raises(DOMException); + readonly attribute SVGSVGElement ownerSVGElement; + readonly attribute SVGElement viewportElement; + }; + +} diff --git a/Source/WebCore/svg/SVGElementInstance.cpp b/Source/WebCore/svg/SVGElementInstance.cpp new file mode 100644 index 0000000..a873f0b --- /dev/null +++ b/Source/WebCore/svg/SVGElementInstance.cpp @@ -0,0 +1,167 @@ +/* + * Copyright (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGElementInstance.h" + +#include "ContainerNodeAlgorithms.h" +#include "Event.h" +#include "EventException.h" +#include "EventListener.h" +#include "EventNames.h" +#include "FrameView.h" +#include "SVGElementInstanceList.h" +#include "SVGUseElement.h" + +#include <wtf/RefCountedLeakCounter.h> + +namespace WebCore { + +#ifndef NDEBUG +static WTF::RefCountedLeakCounter instanceCounter("WebCoreSVGElementInstance"); +#endif + +SVGElementInstance::SVGElementInstance(SVGUseElement* useElement, PassRefPtr<SVGElement> originalElement) + : m_useElement(useElement) + , m_element(originalElement) + , m_previousSibling(0) + , m_nextSibling(0) + , m_firstChild(0) + , m_lastChild(0) +{ + ASSERT(m_useElement); + ASSERT(m_element); + + // Register as instance for passed element. + m_element->mapInstanceToElement(this); + +#ifndef NDEBUG + instanceCounter.increment(); +#endif +} + +SVGElementInstance::~SVGElementInstance() +{ +#ifndef NDEBUG + instanceCounter.decrement(); +#endif + + // Deregister as instance for passed element. + m_element->removeInstanceMapping(this); + + removeAllChildrenInContainer<SVGElementInstance, SVGElementInstance>(this); +} + +PassRefPtr<SVGElementInstanceList> SVGElementInstance::childNodes() +{ + return SVGElementInstanceList::create(this); +} + +void SVGElementInstance::setShadowTreeElement(SVGElement* element) +{ + ASSERT(element); + m_shadowTreeElement = element; +} + +void SVGElementInstance::appendChild(PassRefPtr<SVGElementInstance> child) +{ + appendChildToContainer<SVGElementInstance, SVGElementInstance>(child.get(), this); +} + +void SVGElementInstance::invalidateAllInstancesOfElement(SVGElement* element) +{ + if (!element || !element->inDocument()) + return; + + if (element->isStyled() && static_cast<SVGStyledElement*>(element)->instanceUpdatesBlocked()) + return; + + const HashSet<SVGElementInstance*>& set = element->instancesForElement(); + if (set.isEmpty()) + return; + + // Mark all use elements referencing 'element' for rebuilding + const HashSet<SVGElementInstance*>::const_iterator end = set.end(); + for (HashSet<SVGElementInstance*>::const_iterator it = set.begin(); it != end; ++it) { + ASSERT((*it)->correspondingElement() == element); + if (SVGUseElement* element = (*it)->correspondingUseElement()) + element->invalidateShadowTree(); + } + + // Be sure to rebuild use trees, if needed + element->document()->updateLayoutIgnorePendingStylesheets(); +} + +ScriptExecutionContext* SVGElementInstance::scriptExecutionContext() const +{ + return m_element->document(); +} + +bool SVGElementInstance::addEventListener(const AtomicString& eventType, PassRefPtr<EventListener> listener, bool useCapture) +{ + return m_element->addEventListener(eventType, listener, useCapture); +} + +bool SVGElementInstance::removeEventListener(const AtomicString& eventType, EventListener* listener, bool useCapture) +{ + return m_element->removeEventListener(eventType, listener, useCapture); +} + +void SVGElementInstance::removeAllEventListeners() +{ + m_element->removeAllEventListeners(); +} + +bool SVGElementInstance::dispatchEvent(PassRefPtr<Event> prpEvent) +{ + RefPtr<EventTarget> protect = this; + RefPtr<Event> event = prpEvent; + + event->setTarget(this); + + SVGElement* element = shadowTreeElement(); + if (!element) + return false; + + RefPtr<FrameView> view = element->document()->view(); + return element->dispatchGenericEvent(event.release()); +} + +EventTargetData* SVGElementInstance::eventTargetData() +{ + // EventTarget would use these methods if we were actually using its add/removeEventListener logic. + // As we're forwarding those calls to the correspondingElement(), no one should ever call this function. + ASSERT_NOT_REACHED(); + return 0; +} + +EventTargetData* SVGElementInstance::ensureEventTargetData() +{ + // EventTarget would use these methods if we were actually using its add/removeEventListener logic. + // As we're forwarding those calls to the correspondingElement(), no one should ever call this function. + ASSERT_NOT_REACHED(); + return 0; +} + +} + +#endif diff --git a/Source/WebCore/svg/SVGElementInstance.h b/Source/WebCore/svg/SVGElementInstance.h new file mode 100644 index 0000000..6dbcff4 --- /dev/null +++ b/Source/WebCore/svg/SVGElementInstance.h @@ -0,0 +1,167 @@ +/* + * Copyright (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGElementInstance_h +#define SVGElementInstance_h + +#if ENABLE(SVG) +#include "EventTarget.h" +#include "SVGElement.h" +#include "TreeShared.h" + +namespace WebCore { + +namespace Private { +template<class GenericNode, class GenericNodeContainer> +void addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, GenericNodeContainer* container); +}; + +class SVGUseElement; +class SVGElementInstanceList; + +// SVGElementInstance mimics Node, but without providing all its functionality +class SVGElementInstance : public TreeShared<SVGElementInstance>, + public EventTarget { +public: + static PassRefPtr<SVGElementInstance> create(SVGUseElement* useElement, PassRefPtr<SVGElement> originalElement) + { + return adoptRef(new SVGElementInstance(useElement, originalElement)); + } + + virtual ~SVGElementInstance(); + + virtual ScriptExecutionContext* scriptExecutionContext() const; + + virtual bool addEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture); + virtual bool removeEventListener(const AtomicString& eventType, EventListener*, bool useCapture); + virtual void removeAllEventListeners(); + using EventTarget::dispatchEvent; + virtual bool dispatchEvent(PassRefPtr<Event>); + + SVGElement* correspondingElement() const { return m_element.get(); } + SVGUseElement* correspondingUseElement() const { return m_useElement; } + SVGElement* shadowTreeElement() const { return m_shadowTreeElement.get(); } + void clearUseElement() { m_useElement = 0; } + + SVGElementInstance* parentNode() const { return parent(); } + PassRefPtr<SVGElementInstanceList> childNodes(); + + SVGElementInstance* previousSibling() const { return m_previousSibling; } + SVGElementInstance* nextSibling() const { return m_nextSibling; } + + SVGElementInstance* firstChild() const { return m_firstChild; } + SVGElementInstance* lastChild() const { return m_lastChild; } + + Document* ownerDocument() const { return m_element ? m_element->ownerDocument() : 0; } + + static void invalidateAllInstancesOfElement(SVGElement*); + + using TreeShared<SVGElementInstance>::ref; + using TreeShared<SVGElementInstance>::deref; + + // EventTarget API + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), abort); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), blur); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), change); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), click); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), contextmenu); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), dblclick); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), error); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), focus); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), input); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), keydown); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), keypress); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), keyup); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), load); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), mousedown); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), mousemove); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), mouseout); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), mouseover); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), mouseup); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), mousewheel); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), beforecut); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), cut); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), beforecopy); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), copy); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), beforepaste); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), paste); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), dragenter); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), dragover); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), dragleave); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), drop); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), dragstart); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), drag); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), dragend); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), reset); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), resize); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), scroll); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), search); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), select); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), selectstart); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), submit); + DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), unload); + +private: + friend class SVGUseElement; + + SVGElementInstance(SVGUseElement*, PassRefPtr<SVGElement> originalElement); + + virtual Node* toNode() { return shadowTreeElement(); } + virtual SVGElementInstance* toSVGElementInstance() { return this; } + + void appendChild(PassRefPtr<SVGElementInstance> child); + void setShadowTreeElement(SVGElement*); + + template<class GenericNode, class GenericNodeContainer> + friend void appendChildToContainer(GenericNode* child, GenericNodeContainer* container); + + template<class GenericNode, class GenericNodeContainer> + friend void removeAllChildrenInContainer(GenericNodeContainer* container); + + template<class GenericNode, class GenericNodeContainer> + friend void Private::addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, GenericNodeContainer* container); + + bool hasChildNodes() const { return m_firstChild; } + + void setFirstChild(SVGElementInstance* child) { m_firstChild = child; } + void setLastChild(SVGElementInstance* child) { m_lastChild = child; } + + void setNextSibling(SVGElementInstance* sibling) { m_nextSibling = sibling; } + void setPreviousSibling(SVGElementInstance* sibling) { m_previousSibling = sibling; } + + virtual void refEventTarget() { ref(); } + virtual void derefEventTarget() { deref(); } + virtual EventTargetData* eventTargetData(); + virtual EventTargetData* ensureEventTargetData(); + + SVGUseElement* m_useElement; + RefPtr<SVGElement> m_element; + RefPtr<SVGElement> m_shadowTreeElement; + + SVGElementInstance* m_previousSibling; + SVGElementInstance* m_nextSibling; + + SVGElementInstance* m_firstChild; + SVGElementInstance* m_lastChild; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGElementInstance.idl b/Source/WebCore/svg/SVGElementInstance.idl new file mode 100644 index 0000000..f5c2cb8 --- /dev/null +++ b/Source/WebCore/svg/SVGElementInstance.idl @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2008 Apple 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 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 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. + */ + +module svg { + + interface [ + Conditional=SVG, + CustomMarkFunction, + GenerateNativeConverter + ] SVGElementInstance +#if defined(LANGUAGE_OBJECTIVE_C) && LANGUAGE_OBJECTIVE_C + : Object, EventTarget +#endif /* defined(LANGUAGE_OBJECTIVE_C) */ + { + readonly attribute SVGElement correspondingElement; + readonly attribute SVGUseElement correspondingUseElement; + readonly attribute SVGElementInstance parentNode; + readonly attribute SVGElementInstanceList childNodes; + readonly attribute SVGElementInstance firstChild; + readonly attribute SVGElementInstance lastChild; + readonly attribute SVGElementInstance previousSibling; + readonly attribute SVGElementInstance nextSibling; + + // EventTarget +#if !defined(LANGUAGE_OBJECTIVE_C) || !LANGUAGE_OBJECTIVE_C + attribute [DontEnum] EventListener onabort; + attribute [DontEnum] EventListener onblur; + attribute [DontEnum] EventListener onchange; + attribute [DontEnum] EventListener onclick; + attribute [DontEnum] EventListener oncontextmenu; + attribute [DontEnum] EventListener ondblclick; + attribute [DontEnum] EventListener onerror; + attribute [DontEnum] EventListener onfocus; + attribute [DontEnum] EventListener oninput; + attribute [DontEnum] EventListener onkeydown; + attribute [DontEnum] EventListener onkeypress; + attribute [DontEnum] EventListener onkeyup; + attribute [DontEnum] EventListener onload; + attribute [DontEnum] EventListener onmousedown; + attribute [DontEnum] EventListener onmousemove; + attribute [DontEnum] EventListener onmouseout; + attribute [DontEnum] EventListener onmouseover; + attribute [DontEnum] EventListener onmouseup; + attribute [DontEnum] EventListener onmousewheel; + attribute [DontEnum] EventListener onbeforecut; + attribute [DontEnum] EventListener oncut; + attribute [DontEnum] EventListener onbeforecopy; + attribute [DontEnum] EventListener oncopy; + attribute [DontEnum] EventListener onbeforepaste; + attribute [DontEnum] EventListener onpaste; + attribute [DontEnum] EventListener ondragenter; + attribute [DontEnum] EventListener ondragover; + attribute [DontEnum] EventListener ondragleave; + attribute [DontEnum] EventListener ondrop; + attribute [DontEnum] EventListener ondragstart; + attribute [DontEnum] EventListener ondrag; + attribute [DontEnum] EventListener ondragend; + attribute [DontEnum] EventListener onreset; + attribute [DontEnum] EventListener onresize; + attribute [DontEnum] EventListener onscroll; + attribute [DontEnum] EventListener onsearch; + attribute [DontEnum] EventListener onselect; + attribute [DontEnum] EventListener onselectstart; + attribute [DontEnum] EventListener onsubmit; + attribute [DontEnum] EventListener onunload; + + void addEventListener(in DOMString type, + in EventListener listener, + in boolean useCapture); + void removeEventListener(in DOMString type, + in EventListener listener, + in boolean useCapture); + boolean dispatchEvent(in Event event) + raises(EventException); +#endif /* defined(LANGUAGE_OBJECTIVE_C) */ + }; +} diff --git a/Source/WebCore/svg/SVGElementInstanceList.cpp b/Source/WebCore/svg/SVGElementInstanceList.cpp new file mode 100644 index 0000000..0c04e10 --- /dev/null +++ b/Source/WebCore/svg/SVGElementInstanceList.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGElementInstanceList.h" + +namespace WebCore { + +SVGElementInstanceList::SVGElementInstanceList(PassRefPtr<SVGElementInstance> rootInstance) + : m_rootInstance(rootInstance) +{ +} + +SVGElementInstanceList::~SVGElementInstanceList() +{ +} + +unsigned SVGElementInstanceList::length() const +{ + // NOTE: We could use the same caching facilities, like the ones "ChildNodeList" uses. + unsigned length = 0; + for (SVGElementInstance* instance = m_rootInstance->firstChild(); instance; instance = instance->nextSibling()) + length++; + return length; +} + +SVGElementInstance* SVGElementInstanceList::item(unsigned index) +{ + unsigned pos = 0; + SVGElementInstance* instance = m_rootInstance->firstChild(); + while (instance && pos < index) { + instance = instance->nextSibling(); + pos++; + } + return instance; +} + +} + +#endif // ENABLE(SVG) + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGElementInstanceList.h b/Source/WebCore/svg/SVGElementInstanceList.h new file mode 100644 index 0000000..643876a --- /dev/null +++ b/Source/WebCore/svg/SVGElementInstanceList.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGElementInstanceList_h +#define SVGElementInstanceList_h + +#if ENABLE(SVG) + +#include "SVGElementInstance.h" +#include <wtf/RefCounted.h> + +namespace WebCore { + +class SVGElementInstanceList : public RefCounted<SVGElementInstanceList> { +public: + static PassRefPtr<SVGElementInstanceList> create(PassRefPtr<SVGElementInstance> root) { return adoptRef(new SVGElementInstanceList(root)); } + virtual ~SVGElementInstanceList(); + + unsigned length() const; + SVGElementInstance* item(unsigned index); + +private: + SVGElementInstanceList(PassRefPtr<SVGElementInstance>); + + RefPtr<SVGElementInstance> m_rootInstance; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGElementInstanceList.idl b/Source/WebCore/svg/SVGElementInstanceList.idl new file mode 100644 index 0000000..ea26fc2 --- /dev/null +++ b/Source/WebCore/svg/SVGElementInstanceList.idl @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> + * + * 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 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 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. + */ + +module svg { + interface [Conditional=SVG] SVGElementInstanceList { + readonly attribute unsigned long length; + + SVGElementInstance item(in unsigned long index); + }; +} diff --git a/Source/WebCore/svg/SVGElementRareData.h b/Source/WebCore/svg/SVGElementRareData.h new file mode 100644 index 0000000..4276c4a --- /dev/null +++ b/Source/WebCore/svg/SVGElementRareData.h @@ -0,0 +1,77 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGElementRareData_h +#define SVGElementRareData_h + +#include <wtf/HashSet.h> +#include <wtf/Noncopyable.h> +#include <wtf/StdLibExtras.h> + +namespace WebCore { + +class CSSCursorImageValue; +class SVGCursorElement; +class SVGElement; +class SVGElementInstance; + +class SVGElementRareData : public Noncopyable { +public: + SVGElementRareData() + : m_cursorElement(0) + , m_cursorImageValue(0) + , m_instancesUpdatesBlocked(false) + { + } + + typedef HashMap<const SVGElement*, SVGElementRareData*> SVGElementRareDataMap; + + static SVGElementRareDataMap& rareDataMap() + { + DEFINE_STATIC_LOCAL(SVGElementRareDataMap, rareDataMap, ()); + return rareDataMap; + } + + static SVGElementRareData* rareDataFromMap(const SVGElement* element) + { + return rareDataMap().get(element); + } + + HashSet<SVGElementInstance*>& elementInstances() { return m_elementInstances; } + const HashSet<SVGElementInstance*>& elementInstances() const { return m_elementInstances; } + + bool instanceUpdatesBlocked() const { return m_instancesUpdatesBlocked; } + void setInstanceUpdatesBlocked(bool value) { m_instancesUpdatesBlocked = value; } + + SVGCursorElement* cursorElement() const { return m_cursorElement; } + void setCursorElement(SVGCursorElement* cursorElement) { m_cursorElement = cursorElement; } + + CSSCursorImageValue* cursorImageValue() const { return m_cursorImageValue; } + void setCursorImageValue(CSSCursorImageValue* cursorImageValue) { m_cursorImageValue = cursorImageValue; } + +private: + HashSet<SVGElementInstance*> m_elementInstances; + SVGCursorElement* m_cursorElement; + CSSCursorImageValue* m_cursorImageValue; + bool m_instancesUpdatesBlocked : 1; +}; + +} + +#endif diff --git a/Source/WebCore/svg/SVGEllipseElement.cpp b/Source/WebCore/svg/SVGEllipseElement.cpp new file mode 100644 index 0000000..4a12aa7 --- /dev/null +++ b/Source/WebCore/svg/SVGEllipseElement.cpp @@ -0,0 +1,170 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGEllipseElement.h" + +#include "Attribute.h" +#include "FloatPoint.h" +#include "RenderSVGPath.h" +#include "RenderSVGResource.h" +#include "SVGLength.h" +#include "SVGNames.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_LENGTH(SVGEllipseElement, SVGNames::cxAttr, Cx, cx) +DEFINE_ANIMATED_LENGTH(SVGEllipseElement, SVGNames::cyAttr, Cy, cy) +DEFINE_ANIMATED_LENGTH(SVGEllipseElement, SVGNames::rxAttr, Rx, rx) +DEFINE_ANIMATED_LENGTH(SVGEllipseElement, SVGNames::ryAttr, Ry, ry) +DEFINE_ANIMATED_BOOLEAN(SVGEllipseElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) + +inline SVGEllipseElement::SVGEllipseElement(const QualifiedName& tagName, Document* document) + : SVGStyledTransformableElement(tagName, document) + , m_cx(LengthModeWidth) + , m_cy(LengthModeHeight) + , m_rx(LengthModeWidth) + , m_ry(LengthModeHeight) +{ +} + +PassRefPtr<SVGEllipseElement> SVGEllipseElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGEllipseElement(tagName, document)); +} + +void SVGEllipseElement::parseMappedAttribute(Attribute* attr) +{ + if (attr->name() == SVGNames::cxAttr) + setCxBaseValue(SVGLength(LengthModeWidth, attr->value())); + else if (attr->name() == SVGNames::cyAttr) + setCyBaseValue(SVGLength(LengthModeHeight, attr->value())); + else if (attr->name() == SVGNames::rxAttr) { + setRxBaseValue(SVGLength(LengthModeWidth, attr->value())); + if (rxBaseValue().value(this) < 0.0) + document()->accessSVGExtensions()->reportError("A negative value for ellipse <rx> is not allowed"); + } else if (attr->name() == SVGNames::ryAttr) { + setRyBaseValue(SVGLength(LengthModeHeight, attr->value())); + if (ryBaseValue().value(this) < 0.0) + document()->accessSVGExtensions()->reportError("A negative value for ellipse <ry> is not allowed"); + } else { + if (SVGTests::parseMappedAttribute(attr)) + return; + if (SVGLangSpace::parseMappedAttribute(attr)) + return; + if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) + return; + SVGStyledTransformableElement::parseMappedAttribute(attr); + } +} + +void SVGEllipseElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGStyledTransformableElement::svgAttributeChanged(attrName); + + bool isLengthAttribute = attrName == SVGNames::cxAttr + || attrName == SVGNames::cyAttr + || attrName == SVGNames::rxAttr + || attrName == SVGNames::ryAttr; + + if (isLengthAttribute) + updateRelativeLengthsInformation(); + + if (SVGTests::handleAttributeChange(this, attrName)) + return; + + RenderSVGPath* renderer = static_cast<RenderSVGPath*>(this->renderer()); + if (!renderer) + return; + + if (SVGStyledTransformableElement::isKnownAttribute(attrName)) { + renderer->setNeedsTransformUpdate(); + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); + return; + } + + if (isLengthAttribute) { + renderer->setNeedsPathUpdate(); + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); + return; + } + + if (SVGLangSpace::isKnownAttribute(attrName) + || SVGExternalResourcesRequired::isKnownAttribute(attrName)) + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); +} + +void SVGEllipseElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGStyledTransformableElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeCx(); + synchronizeCy(); + synchronizeRx(); + synchronizeRy(); + synchronizeExternalResourcesRequired(); + SVGTests::synchronizeProperties(this, attrName); + return; + } + + if (attrName == SVGNames::cxAttr) + synchronizeCx(); + else if (attrName == SVGNames::cyAttr) + synchronizeCy(); + else if (attrName == SVGNames::rxAttr) + synchronizeRx(); + else if (attrName == SVGNames::ryAttr) + synchronizeRy(); + else if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) + synchronizeExternalResourcesRequired(); + else if (SVGTests::isKnownAttribute(attrName)) + SVGTests::synchronizeProperties(this, attrName); +} + +void SVGEllipseElement::toPathData(Path& path) const +{ + ASSERT(path.isEmpty()); + + float radiusX = rx().value(this); + if (radiusX <= 0) + return; + + float radiusY = ry().value(this); + if (radiusY <= 0) + return; + + path.addEllipse(FloatRect(cx().value(this) - radiusX, cy().value(this) - radiusY, radiusX * 2, radiusY * 2)); +} + +bool SVGEllipseElement::selfHasRelativeLengths() const +{ + return cx().isRelative() + || cy().isRelative() + || rx().isRelative() + || ry().isRelative(); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGEllipseElement.h b/Source/WebCore/svg/SVGEllipseElement.h new file mode 100644 index 0000000..7ba2085 --- /dev/null +++ b/Source/WebCore/svg/SVGEllipseElement.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGEllipseElement_h +#define SVGEllipseElement_h + +#if ENABLE(SVG) +#include "SVGAnimatedBoolean.h" +#include "SVGAnimatedLength.h" +#include "SVGExternalResourcesRequired.h" +#include "SVGLangSpace.h" +#include "SVGStyledTransformableElement.h" +#include "SVGTests.h" + +namespace WebCore { + +class SVGEllipseElement : public SVGStyledTransformableElement, + public SVGTests, + public SVGLangSpace, + public SVGExternalResourcesRequired { +public: + static PassRefPtr<SVGEllipseElement> create(const QualifiedName&, Document*); + +private: + SVGEllipseElement(const QualifiedName&, Document*); + + virtual bool isValid() const { return SVGTests::isValid(); } + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + + virtual void toPathData(Path&) const; + + virtual bool selfHasRelativeLengths() const; + + // Animated property declarations + DECLARE_ANIMATED_LENGTH(Cx, cx) + DECLARE_ANIMATED_LENGTH(Cy, cy) + DECLARE_ANIMATED_LENGTH(Rx, rx) + DECLARE_ANIMATED_LENGTH(Ry, ry) + + // SVGExternalResourcesRequired + DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGEllipseElement.idl b/Source/WebCore/svg/SVGEllipseElement.idl new file mode 100644 index 0000000..bb9f95c --- /dev/null +++ b/Source/WebCore/svg/SVGEllipseElement.idl @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGEllipseElement : SVGElement, + SVGTests, + SVGLangSpace, + SVGExternalResourcesRequired, + SVGStylable, + SVGTransformable { + readonly attribute SVGAnimatedLength cx; + readonly attribute SVGAnimatedLength cy; + readonly attribute SVGAnimatedLength rx; + readonly attribute SVGAnimatedLength ry; + }; + +} diff --git a/Source/WebCore/svg/SVGException.h b/Source/WebCore/svg/SVGException.h new file mode 100644 index 0000000..0193bac --- /dev/null +++ b/Source/WebCore/svg/SVGException.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGException_h +#define SVGException_h + +#include "ExceptionBase.h" + +#if ENABLE(SVG) + +namespace WebCore { + +class SVGException : public ExceptionBase { +public: + static PassRefPtr<SVGException> create(const ExceptionCodeDescription& description) + { + return adoptRef(new SVGException(description)); + } + + static const int SVGExceptionOffset = 300; + static const int SVGExceptionMax = 399; + + enum SVGExceptionCode { + SVG_WRONG_TYPE_ERR = SVGExceptionOffset, + SVG_INVALID_VALUE_ERR = SVGExceptionOffset + 1, + SVG_MATRIX_NOT_INVERTABLE = SVGExceptionOffset + 2 + }; + +private: + SVGException(const ExceptionCodeDescription& description) + : ExceptionBase(description) + { + } +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) + +#endif // SVGException_h diff --git a/Source/WebCore/svg/SVGException.idl b/Source/WebCore/svg/SVGException.idl new file mode 100644 index 0000000..3f1f8ec --- /dev/null +++ b/Source/WebCore/svg/SVGException.idl @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2007 Rob Buis <buis@kde.org> + * Copyright (C) 2007 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +module svg { + + interface [ + Conditional=SVG, + DontCheckEnums + ] SVGException { + + readonly attribute unsigned short code; + readonly attribute DOMString name; + readonly attribute DOMString message; + +#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT + // Override in a Mozilla compatible format + [DontEnum] DOMString toString(); +#endif + + // SVGExceptionCode + const unsigned short SVG_WRONG_TYPE_ERR = 0; + const unsigned short SVG_INVALID_VALUE_ERR = 1; + const unsigned short SVG_MATRIX_NOT_INVERTABLE = 2; + }; +} diff --git a/Source/WebCore/svg/SVGExternalResourcesRequired.cpp b/Source/WebCore/svg/SVGExternalResourcesRequired.cpp new file mode 100644 index 0000000..beae203 --- /dev/null +++ b/Source/WebCore/svg/SVGExternalResourcesRequired.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGExternalResourcesRequired.h" + +#include "Attr.h" +#include "SVGNames.h" + +namespace WebCore { + +bool SVGExternalResourcesRequired::parseMappedAttribute(Attribute* attr) +{ + if (attr->name() == SVGNames::externalResourcesRequiredAttr) { + setExternalResourcesRequiredBaseValue(attr->value() == "true"); + return true; + } + + return false; +} + +bool SVGExternalResourcesRequired::isKnownAttribute(const QualifiedName& attrName) +{ + return attrName == SVGNames::externalResourcesRequiredAttr; +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGExternalResourcesRequired.h b/Source/WebCore/svg/SVGExternalResourcesRequired.h new file mode 100644 index 0000000..7a37267 --- /dev/null +++ b/Source/WebCore/svg/SVGExternalResourcesRequired.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGExternalResourcesRequired_h +#define SVGExternalResourcesRequired_h + +#if ENABLE(SVG) +namespace WebCore { + +class Attribute; +class QualifiedName; + +// Notes on a SVG 1.1 spec discrepancy: +// The SVG DOM defines the attribute externalResourcesRequired as being of type SVGAnimatedBoolean, whereas the +// SVG language definition says that externalResourcesRequired is not animated. Because the SVG language definition +// states that externalResourcesRequired cannot be animated, the animVal will always be the same as the baseVal. +// FIXME: When implementing animVal support, make sure that animVal==baseVal for externalResourcesRequired +class SVGExternalResourcesRequired { +public: + virtual ~SVGExternalResourcesRequired() { } + + bool parseMappedAttribute(Attribute*); + bool isKnownAttribute(const QualifiedName&); + +protected: + virtual void setExternalResourcesRequiredBaseValue(const bool&) = 0; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGExternalResourcesRequired.idl b/Source/WebCore/svg/SVGExternalResourcesRequired.idl new file mode 100644 index 0000000..62e2c5d --- /dev/null +++ b/Source/WebCore/svg/SVGExternalResourcesRequired.idl @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG, ObjCProtocol, OmitConstructor] SVGExternalResourcesRequired { + readonly attribute SVGAnimatedBoolean externalResourcesRequired; + }; + +} diff --git a/Source/WebCore/svg/SVGFEBlendElement.cpp b/Source/WebCore/svg/SVGFEBlendElement.cpp new file mode 100644 index 0000000..86299fe --- /dev/null +++ b/Source/WebCore/svg/SVGFEBlendElement.cpp @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFEBlendElement.h" + +#include "Attribute.h" +#include "SVGNames.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_STRING(SVGFEBlendElement, SVGNames::inAttr, In1, in1) +DEFINE_ANIMATED_STRING(SVGFEBlendElement, SVGNames::in2Attr, In2, in2) +DEFINE_ANIMATED_ENUMERATION(SVGFEBlendElement, SVGNames::modeAttr, Mode, mode) + +inline SVGFEBlendElement::SVGFEBlendElement(const QualifiedName& tagName, Document* document) + : SVGFilterPrimitiveStandardAttributes(tagName, document) + , m_mode(FEBLEND_MODE_NORMAL) +{ +} + +PassRefPtr<SVGFEBlendElement> SVGFEBlendElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGFEBlendElement(tagName, document)); +} + +void SVGFEBlendElement::parseMappedAttribute(Attribute* attr) +{ + const String& value = attr->value(); + if (attr->name() == SVGNames::modeAttr) { + if (value == "normal") + setModeBaseValue(FEBLEND_MODE_NORMAL); + else if (value == "multiply") + setModeBaseValue(FEBLEND_MODE_MULTIPLY); + else if (value == "screen") + setModeBaseValue(FEBLEND_MODE_SCREEN); + else if (value == "darken") + setModeBaseValue(FEBLEND_MODE_DARKEN); + else if (value == "lighten") + setModeBaseValue(FEBLEND_MODE_LIGHTEN); + } else if (attr->name() == SVGNames::inAttr) + setIn1BaseValue(value); + else if (attr->name() == SVGNames::in2Attr) + setIn2BaseValue(value); + else + SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr); +} + +void SVGFEBlendElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName); + + if (attrName == SVGNames::modeAttr + || attrName == SVGNames::inAttr + || attrName == SVGNames::in2Attr) + invalidate(); +} + +void SVGFEBlendElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGFilterPrimitiveStandardAttributes::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeMode(); + synchronizeIn1(); + synchronizeIn2(); + return; + } + + if (attrName == SVGNames::modeAttr) + synchronizeMode(); + else if (attrName == SVGNames::inAttr) + synchronizeIn1(); + else if (attrName == SVGNames::in2Attr) + synchronizeIn2(); +} + +PassRefPtr<FilterEffect> SVGFEBlendElement::build(SVGFilterBuilder* filterBuilder, Filter* filter) +{ + FilterEffect* input1 = filterBuilder->getEffectById(in1()); + FilterEffect* input2 = filterBuilder->getEffectById(in2()); + + if (!input1 || !input2) + return 0; + + RefPtr<FilterEffect> effect = FEBlend::create(filter, static_cast<BlendModeType>(mode())); + FilterEffectVector& inputEffects = effect->inputEffects(); + inputEffects.reserveCapacity(2); + inputEffects.append(input1); + inputEffects.append(input2); + return effect.release(); +} + +} + +#endif // ENABLE(SVG) + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGFEBlendElement.h b/Source/WebCore/svg/SVGFEBlendElement.h new file mode 100644 index 0000000..292f385 --- /dev/null +++ b/Source/WebCore/svg/SVGFEBlendElement.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFEBlendElement_h +#define SVGFEBlendElement_h + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "FEBlend.h" +#include "SVGAnimatedEnumeration.h" +#include "SVGFilterPrimitiveStandardAttributes.h" + +namespace WebCore { + +class SVGFEBlendElement : public SVGFilterPrimitiveStandardAttributes { +public: + static PassRefPtr<SVGFEBlendElement> create(const QualifiedName&, Document*); + +private: + SVGFEBlendElement(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + virtual PassRefPtr<FilterEffect> build(SVGFilterBuilder*, Filter*); + + // Animated property declarations + DECLARE_ANIMATED_STRING(In1, in1) + DECLARE_ANIMATED_STRING(In2, in2) + DECLARE_ANIMATED_ENUMERATION(Mode, mode) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGFEBlendElement.idl b/Source/WebCore/svg/SVGFEBlendElement.idl new file mode 100644 index 0000000..03a5543 --- /dev/null +++ b/Source/WebCore/svg/SVGFEBlendElement.idl @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [ + Conditional=SVG&FILTERS, + DontCheckEnums + ] SVGFEBlendElement : SVGElement, + SVGFilterPrimitiveStandardAttributes { + // Blend Mode Types + const unsigned short SVG_FEBLEND_MODE_UNKNOWN = 0; + const unsigned short SVG_FEBLEND_MODE_NORMAL = 1; + const unsigned short SVG_FEBLEND_MODE_MULTIPLY = 2; + const unsigned short SVG_FEBLEND_MODE_SCREEN = 3; + const unsigned short SVG_FEBLEND_MODE_DARKEN = 4; + const unsigned short SVG_FEBLEND_MODE_LIGHTEN = 5; + + readonly attribute SVGAnimatedString in1; + readonly attribute SVGAnimatedString in2; + readonly attribute SVGAnimatedEnumeration mode; + }; + +} diff --git a/Source/WebCore/svg/SVGFEColorMatrixElement.cpp b/Source/WebCore/svg/SVGFEColorMatrixElement.cpp new file mode 100644 index 0000000..79716fb --- /dev/null +++ b/Source/WebCore/svg/SVGFEColorMatrixElement.cpp @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFEColorMatrixElement.h" + +#include "Attribute.h" +#include "SVGNames.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_STRING(SVGFEColorMatrixElement, SVGNames::inAttr, In1, in1) +DEFINE_ANIMATED_ENUMERATION(SVGFEColorMatrixElement, SVGNames::typeAttr, Type, type) +DEFINE_ANIMATED_NUMBER_LIST(SVGFEColorMatrixElement, SVGNames::valuesAttr, Values, values) + +inline SVGFEColorMatrixElement::SVGFEColorMatrixElement(const QualifiedName& tagName, Document* document) + : SVGFilterPrimitiveStandardAttributes(tagName, document) + , m_type(FECOLORMATRIX_TYPE_UNKNOWN) +{ +} + +PassRefPtr<SVGFEColorMatrixElement> SVGFEColorMatrixElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGFEColorMatrixElement(tagName, document)); +} + +void SVGFEColorMatrixElement::parseMappedAttribute(Attribute* attr) +{ + const String& value = attr->value(); + if (attr->name() == SVGNames::typeAttr) { + if (value == "matrix") + setTypeBaseValue(FECOLORMATRIX_TYPE_MATRIX); + else if (value == "saturate") + setTypeBaseValue(FECOLORMATRIX_TYPE_SATURATE); + else if (value == "hueRotate") + setTypeBaseValue(FECOLORMATRIX_TYPE_HUEROTATE); + else if (value == "luminanceToAlpha") + setTypeBaseValue(FECOLORMATRIX_TYPE_LUMINANCETOALPHA); + } else if (attr->name() == SVGNames::inAttr) + setIn1BaseValue(value); + else if (attr->name() == SVGNames::valuesAttr) { + SVGNumberList newList; + newList.parse(value); + detachAnimatedValuesListWrappers(newList.size()); + setValuesBaseValue(newList); + } else + SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr); +} + +void SVGFEColorMatrixElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName); + + if (attrName == SVGNames::typeAttr + || attrName == SVGNames::inAttr + || attrName == SVGNames::valuesAttr) + invalidate(); +} + +void SVGFEColorMatrixElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGFilterPrimitiveStandardAttributes::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeType(); + synchronizeIn1(); + synchronizeValues(); + return; + } + + if (attrName == SVGNames::typeAttr) + synchronizeType(); + else if (attrName == SVGNames::inAttr) + synchronizeIn1(); + else if (attrName == SVGNames::valuesAttr) + synchronizeValues(); +} + +PassRefPtr<FilterEffect> SVGFEColorMatrixElement::build(SVGFilterBuilder* filterBuilder, Filter* filter) +{ + FilterEffect* input1 = filterBuilder->getEffectById(in1()); + + if (!input1) + return 0; + + Vector<float> filterValues; + const ColorMatrixType filterType(static_cast<ColorMatrixType>(type())); + + // Use defaults if values is empty (SVG 1.1 15.10). + if (!hasAttribute(SVGNames::valuesAttr)) { + switch (filterType) { + case FECOLORMATRIX_TYPE_MATRIX: + for (size_t i = 0; i < 20; i++) + filterValues.append((i % 6) ? 0.0f : 1.0f); + break; + case FECOLORMATRIX_TYPE_HUEROTATE: + filterValues.append(0.0f); + break; + case FECOLORMATRIX_TYPE_SATURATE: + filterValues.append(1.0f); + break; + default: + break; + } + } else { + filterValues = values(); + unsigned size = filterValues.size(); + + if ((filterType == FECOLORMATRIX_TYPE_MATRIX && size != 20) + || (filterType == FECOLORMATRIX_TYPE_HUEROTATE && size != 1) + || (filterType == FECOLORMATRIX_TYPE_SATURATE && (size != 1 + || filterValues[0] < 0.0f || filterValues[0] > 1.0f))) + return 0; + } + + RefPtr<FilterEffect> effect = FEColorMatrix::create(filter, filterType, filterValues); + effect->inputEffects().append(input1); + return effect.release(); +} + +} // namespace WebCore + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGFEColorMatrixElement.h b/Source/WebCore/svg/SVGFEColorMatrixElement.h new file mode 100644 index 0000000..04a8966 --- /dev/null +++ b/Source/WebCore/svg/SVGFEColorMatrixElement.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFEColorMatrixElement_h +#define SVGFEColorMatrixElement_h + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "FEColorMatrix.h" +#include "SVGAnimatedEnumeration.h" +#include "SVGAnimatedNumberList.h" +#include "SVGFilterPrimitiveStandardAttributes.h" + +namespace WebCore { + +class SVGFEColorMatrixElement : public SVGFilterPrimitiveStandardAttributes { +public: + static PassRefPtr<SVGFEColorMatrixElement> create(const QualifiedName&, Document*); + +private: + SVGFEColorMatrixElement(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + virtual PassRefPtr<FilterEffect> build(SVGFilterBuilder*, Filter*); + + // Animated property declarations + DECLARE_ANIMATED_STRING(In1, in1) + DECLARE_ANIMATED_ENUMERATION(Type, type) + DECLARE_ANIMATED_NUMBER_LIST(Values, values) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGFEColorMatrixElement.idl b/Source/WebCore/svg/SVGFEColorMatrixElement.idl new file mode 100644 index 0000000..01f57fd --- /dev/null +++ b/Source/WebCore/svg/SVGFEColorMatrixElement.idl @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [ + Conditional=SVG&FILTERS, + DontCheckEnums + ] SVGFEColorMatrixElement : SVGElement, + SVGFilterPrimitiveStandardAttributes { + // Color Matrix Types + const unsigned short SVG_FECOLORMATRIX_TYPE_UNKNOWN = 0; + const unsigned short SVG_FECOLORMATRIX_TYPE_MATRIX = 1; + const unsigned short SVG_FECOLORMATRIX_TYPE_SATURATE = 2; + const unsigned short SVG_FECOLORMATRIX_TYPE_HUEROTATE = 3; + const unsigned short SVG_FECOLORMATRIX_TYPE_LUMINANCETOALPHA = 4; + + readonly attribute SVGAnimatedString in1; + readonly attribute SVGAnimatedEnumeration type; + readonly attribute SVGAnimatedNumberList values; + }; + +} diff --git a/Source/WebCore/svg/SVGFEComponentTransferElement.cpp b/Source/WebCore/svg/SVGFEComponentTransferElement.cpp new file mode 100644 index 0000000..0fa98a4 --- /dev/null +++ b/Source/WebCore/svg/SVGFEComponentTransferElement.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFEComponentTransferElement.h" + +#include "Attr.h" +#include "SVGFEFuncAElement.h" +#include "SVGFEFuncBElement.h" +#include "SVGFEFuncGElement.h" +#include "SVGFEFuncRElement.h" +#include "SVGNames.h" + +namespace WebCore { + +// Animated property declarations +DEFINE_ANIMATED_STRING(SVGFEComponentTransferElement, SVGNames::inAttr, In1, in1) + +inline SVGFEComponentTransferElement::SVGFEComponentTransferElement(const QualifiedName& tagName, Document* document) + : SVGFilterPrimitiveStandardAttributes(tagName, document) +{ +} + +PassRefPtr<SVGFEComponentTransferElement> SVGFEComponentTransferElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGFEComponentTransferElement(tagName, document)); +} + +void SVGFEComponentTransferElement::parseMappedAttribute(Attribute* attr) +{ + const String& value = attr->value(); + if (attr->name() == SVGNames::inAttr) + setIn1BaseValue(value); + else + SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr); +} + +void SVGFEComponentTransferElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGFilterPrimitiveStandardAttributes::synchronizeProperty(attrName); + + if (attrName == anyQName() || attrName == SVGNames::inAttr) + synchronizeIn1(); +} + +PassRefPtr<FilterEffect> SVGFEComponentTransferElement::build(SVGFilterBuilder* filterBuilder, Filter* filter) +{ + FilterEffect* input1 = filterBuilder->getEffectById(in1()); + + if (!input1) + return 0; + + ComponentTransferFunction red; + ComponentTransferFunction green; + ComponentTransferFunction blue; + ComponentTransferFunction alpha; + + for (Node* node = firstChild(); node; node = node->nextSibling()) { + if (node->hasTagName(SVGNames::feFuncRTag)) + red = static_cast<SVGFEFuncRElement*>(node)->transferFunction(); + else if (node->hasTagName(SVGNames::feFuncGTag)) + green = static_cast<SVGFEFuncGElement*>(node)->transferFunction(); + else if (node->hasTagName(SVGNames::feFuncBTag)) + blue = static_cast<SVGFEFuncBElement*>(node)->transferFunction(); + else if (node->hasTagName(SVGNames::feFuncATag)) + alpha = static_cast<SVGFEFuncAElement*>(node)->transferFunction(); + } + + RefPtr<FilterEffect> effect = FEComponentTransfer::create(filter, red, green, blue, alpha); + effect->inputEffects().append(input1); + return effect.release(); +} + +} + +#endif diff --git a/Source/WebCore/svg/SVGFEComponentTransferElement.h b/Source/WebCore/svg/SVGFEComponentTransferElement.h new file mode 100644 index 0000000..ea7f84d --- /dev/null +++ b/Source/WebCore/svg/SVGFEComponentTransferElement.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFEComponentTransferElement_h +#define SVGFEComponentTransferElement_h + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "FEComponentTransfer.h" +#include "SVGFilterPrimitiveStandardAttributes.h" + +namespace WebCore { + +class SVGFEComponentTransferElement : public SVGFilterPrimitiveStandardAttributes { +public: + static PassRefPtr<SVGFEComponentTransferElement> create(const QualifiedName&, Document*); + +private: + SVGFEComponentTransferElement(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + virtual void synchronizeProperty(const QualifiedName&); + virtual PassRefPtr<FilterEffect> build(SVGFilterBuilder*, Filter*); + + // Animated property declarations + DECLARE_ANIMATED_STRING(In1, in1) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGFEComponentTransferElement.idl b/Source/WebCore/svg/SVGFEComponentTransferElement.idl new file mode 100644 index 0000000..af340c9 --- /dev/null +++ b/Source/WebCore/svg/SVGFEComponentTransferElement.idl @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG&FILTERS] SVGFEComponentTransferElement : SVGElement, + SVGFilterPrimitiveStandardAttributes { + readonly attribute SVGAnimatedString in1; + }; + +} diff --git a/Source/WebCore/svg/SVGFECompositeElement.cpp b/Source/WebCore/svg/SVGFECompositeElement.cpp new file mode 100644 index 0000000..1433a78 --- /dev/null +++ b/Source/WebCore/svg/SVGFECompositeElement.cpp @@ -0,0 +1,147 @@ +/* + * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFECompositeElement.h" + +#include "Attribute.h" +#include "SVGNames.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_STRING(SVGFECompositeElement, SVGNames::inAttr, In1, in1) +DEFINE_ANIMATED_STRING(SVGFECompositeElement, SVGNames::in2Attr, In2, in2) +DEFINE_ANIMATED_ENUMERATION(SVGFECompositeElement, SVGNames::operatorAttr, _operator, _operator) +DEFINE_ANIMATED_NUMBER(SVGFECompositeElement, SVGNames::k1Attr, K1, k1) +DEFINE_ANIMATED_NUMBER(SVGFECompositeElement, SVGNames::k2Attr, K2, k2) +DEFINE_ANIMATED_NUMBER(SVGFECompositeElement, SVGNames::k3Attr, K3, k3) +DEFINE_ANIMATED_NUMBER(SVGFECompositeElement, SVGNames::k4Attr, K4, k4) + +inline SVGFECompositeElement::SVGFECompositeElement(const QualifiedName& tagName, Document* document) + : SVGFilterPrimitiveStandardAttributes(tagName, document) + , m__operator(FECOMPOSITE_OPERATOR_OVER) +{ +} + +PassRefPtr<SVGFECompositeElement> SVGFECompositeElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGFECompositeElement(tagName, document)); +} + +void SVGFECompositeElement::parseMappedAttribute(Attribute* attr) +{ + const String& value = attr->value(); + if (attr->name() == SVGNames::operatorAttr) { + if (value == "over") + set_operatorBaseValue(FECOMPOSITE_OPERATOR_OVER); + else if (value == "in") + set_operatorBaseValue(FECOMPOSITE_OPERATOR_IN); + else if (value == "out") + set_operatorBaseValue(FECOMPOSITE_OPERATOR_OUT); + else if (value == "atop") + set_operatorBaseValue(FECOMPOSITE_OPERATOR_ATOP); + else if (value == "xor") + set_operatorBaseValue(FECOMPOSITE_OPERATOR_XOR); + else if (value == "arithmetic") + set_operatorBaseValue(FECOMPOSITE_OPERATOR_ARITHMETIC); + } else if (attr->name() == SVGNames::inAttr) + setIn1BaseValue(value); + else if (attr->name() == SVGNames::in2Attr) + setIn2BaseValue(value); + else if (attr->name() == SVGNames::k1Attr) + setK1BaseValue(value.toFloat()); + else if (attr->name() == SVGNames::k2Attr) + setK2BaseValue(value.toFloat()); + else if (attr->name() == SVGNames::k3Attr) + setK3BaseValue(value.toFloat()); + else if (attr->name() == SVGNames::k4Attr) + setK4BaseValue(value.toFloat()); + else + SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr); +} + +void SVGFECompositeElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName); + + if (attrName == SVGNames::inAttr + || attrName == SVGNames::in2Attr + || attrName == SVGNames::operatorAttr + || attrName == SVGNames::k1Attr + || attrName == SVGNames::k2Attr + || attrName == SVGNames::k3Attr + || attrName == SVGNames::k4Attr) + invalidate(); +} + +void SVGFECompositeElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGFilterPrimitiveStandardAttributes::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronize_operator(); + synchronizeIn1(); + synchronizeIn2(); + synchronizeK1(); + synchronizeK2(); + synchronizeK3(); + synchronizeK4(); + return; + } + + if (attrName == SVGNames::operatorAttr) + synchronize_operator(); + else if (attrName == SVGNames::inAttr) + synchronizeIn1(); + else if (attrName == SVGNames::in2Attr) + synchronizeIn2(); + else if (attrName == SVGNames::k1Attr) + synchronizeK1(); + else if (attrName == SVGNames::k2Attr) + synchronizeK2(); + else if (attrName == SVGNames::k3Attr) + synchronizeK3(); + else if (attrName == SVGNames::k4Attr) + synchronizeK4(); +} + +PassRefPtr<FilterEffect> SVGFECompositeElement::build(SVGFilterBuilder* filterBuilder, Filter* filter) +{ + FilterEffect* input1 = filterBuilder->getEffectById(in1()); + FilterEffect* input2 = filterBuilder->getEffectById(in2()); + + if (!input1 || !input2) + return 0; + + RefPtr<FilterEffect> effect = FEComposite::create(filter, static_cast<CompositeOperationType>(_operator()), + k1(), k2(), k3(), k4()); + FilterEffectVector& inputEffects = effect->inputEffects(); + inputEffects.reserveCapacity(2); + inputEffects.append(input1); + inputEffects.append(input2); + return effect.release(); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGFECompositeElement.h b/Source/WebCore/svg/SVGFECompositeElement.h new file mode 100644 index 0000000..6892220 --- /dev/null +++ b/Source/WebCore/svg/SVGFECompositeElement.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFECompositeElement_h +#define SVGFECompositeElement_h + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "FEComposite.h" +#include "SVGAnimatedEnumeration.h" +#include "SVGAnimatedNumber.h" +#include "SVGFilterPrimitiveStandardAttributes.h" + +namespace WebCore { + +class SVGFECompositeElement : public SVGFilterPrimitiveStandardAttributes { +public: + static PassRefPtr<SVGFECompositeElement> create(const QualifiedName&, Document*); + +private: + SVGFECompositeElement(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + virtual PassRefPtr<FilterEffect> build(SVGFilterBuilder*, Filter*); + + // Animated property declarations + DECLARE_ANIMATED_STRING(In1, in1) + DECLARE_ANIMATED_STRING(In2, in2) + DECLARE_ANIMATED_ENUMERATION(_operator, _operator) + DECLARE_ANIMATED_NUMBER(K1, k1) + DECLARE_ANIMATED_NUMBER(K2, k2) + DECLARE_ANIMATED_NUMBER(K3, k3) + DECLARE_ANIMATED_NUMBER(K4, k4) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGFECompositeElement.idl b/Source/WebCore/svg/SVGFECompositeElement.idl new file mode 100644 index 0000000..dc7fd8d --- /dev/null +++ b/Source/WebCore/svg/SVGFECompositeElement.idl @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [ + Conditional=SVG&FILTERS, + DontCheckEnums + ] SVGFECompositeElement : SVGElement, + SVGFilterPrimitiveStandardAttributes { + // Composite Operators + const unsigned short SVG_FECOMPOSITE_OPERATOR_UNKNOWN = 0; + const unsigned short SVG_FECOMPOSITE_OPERATOR_OVER = 1; + const unsigned short SVG_FECOMPOSITE_OPERATOR_IN = 2; + const unsigned short SVG_FECOMPOSITE_OPERATOR_OUT = 3; + const unsigned short SVG_FECOMPOSITE_OPERATOR_ATOP = 4; + const unsigned short SVG_FECOMPOSITE_OPERATOR_XOR = 5; + const unsigned short SVG_FECOMPOSITE_OPERATOR_ARITHMETIC = 6; + + readonly attribute SVGAnimatedString in1; + readonly attribute SVGAnimatedString in2; + readonly attribute SVGAnimatedEnumeration operator; + readonly attribute SVGAnimatedNumber k1; + readonly attribute SVGAnimatedNumber k2; + readonly attribute SVGAnimatedNumber k3; + readonly attribute SVGAnimatedNumber k4; + }; + +} diff --git a/Source/WebCore/svg/SVGFEConvolveMatrixElement.cpp b/Source/WebCore/svg/SVGFEConvolveMatrixElement.cpp new file mode 100644 index 0000000..373d508 --- /dev/null +++ b/Source/WebCore/svg/SVGFEConvolveMatrixElement.cpp @@ -0,0 +1,212 @@ +/* + * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFEConvolveMatrixElement.h" + +#include "Attr.h" +#include "FloatPoint.h" +#include "IntPoint.h" +#include "IntSize.h" +#include "SVGNames.h" +#include "SVGParserUtilities.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_STRING(SVGFEConvolveMatrixElement, SVGNames::inAttr, In1, in1) +DEFINE_ANIMATED_INTEGER_MULTIPLE_WRAPPERS(SVGFEConvolveMatrixElement, SVGNames::orderAttr, orderXIdentifier(), OrderX, orderX) +DEFINE_ANIMATED_INTEGER_MULTIPLE_WRAPPERS(SVGFEConvolveMatrixElement, SVGNames::orderAttr, orderYIdentifier(), OrderY, orderY) +DEFINE_ANIMATED_NUMBER_LIST(SVGFEConvolveMatrixElement, SVGNames::kernelMatrixAttr, KernelMatrix, kernelMatrix) +DEFINE_ANIMATED_NUMBER(SVGFEConvolveMatrixElement, SVGNames::divisorAttr, Divisor, divisor) +DEFINE_ANIMATED_NUMBER(SVGFEConvolveMatrixElement, SVGNames::biasAttr, Bias, bias) +DEFINE_ANIMATED_INTEGER(SVGFEConvolveMatrixElement, SVGNames::targetXAttr, TargetX, targetX) +DEFINE_ANIMATED_INTEGER(SVGFEConvolveMatrixElement, SVGNames::targetYAttr, TargetY, targetY) +DEFINE_ANIMATED_ENUMERATION(SVGFEConvolveMatrixElement, SVGNames::operatorAttr, EdgeMode, edgeMode) +DEFINE_ANIMATED_NUMBER_MULTIPLE_WRAPPERS(SVGFEConvolveMatrixElement, SVGNames::kernelUnitLengthAttr, kernelUnitLengthXIdentifier(), KernelUnitLengthX, kernelUnitLengthX) +DEFINE_ANIMATED_NUMBER_MULTIPLE_WRAPPERS(SVGFEConvolveMatrixElement, SVGNames::kernelUnitLengthAttr, kernelUnitLengthYIdentifier(), KernelUnitLengthY, kernelUnitLengthY) +DEFINE_ANIMATED_BOOLEAN(SVGFEConvolveMatrixElement, SVGNames::preserveAlphaAttr, PreserveAlpha, preserveAlpha) + +inline SVGFEConvolveMatrixElement::SVGFEConvolveMatrixElement(const QualifiedName& tagName, Document* document) + : SVGFilterPrimitiveStandardAttributes(tagName, document) + , m_edgeMode(EDGEMODE_DUPLICATE) +{ +} + +PassRefPtr<SVGFEConvolveMatrixElement> SVGFEConvolveMatrixElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGFEConvolveMatrixElement(tagName, document)); +} + +const AtomicString& SVGFEConvolveMatrixElement::kernelUnitLengthXIdentifier() +{ + DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGKernelUnitLengthX")); + return s_identifier; +} + +const AtomicString& SVGFEConvolveMatrixElement::kernelUnitLengthYIdentifier() +{ + DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGKernelUnitLengthY")); + return s_identifier; +} + +const AtomicString& SVGFEConvolveMatrixElement::orderXIdentifier() +{ + DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGOrderX")); + return s_identifier; +} + +const AtomicString& SVGFEConvolveMatrixElement::orderYIdentifier() +{ + DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGOrderY")); + return s_identifier; +} + +void SVGFEConvolveMatrixElement::parseMappedAttribute(Attribute* attr) +{ + const String& value = attr->value(); + if (attr->name() == SVGNames::inAttr) + setIn1BaseValue(value); + else if (attr->name() == SVGNames::orderAttr) { + float x, y; + if (parseNumberOptionalNumber(value, x, y)) { + setOrderXBaseValue(x); + setOrderYBaseValue(y); + } + } else if (attr->name() == SVGNames::edgeModeAttr) { + if (value == "duplicate") + setEdgeModeBaseValue(EDGEMODE_DUPLICATE); + else if (value == "wrap") + setEdgeModeBaseValue(EDGEMODE_WRAP); + else if (value == "none") + setEdgeModeBaseValue(EDGEMODE_NONE); + } else if (attr->name() == SVGNames::kernelMatrixAttr) { + SVGNumberList newList; + newList.parse(value); + detachAnimatedKernelMatrixListWrappers(newList.size()); + setKernelMatrixBaseValue(newList); + } else if (attr->name() == SVGNames::divisorAttr) + setDivisorBaseValue(value.toFloat()); + else if (attr->name() == SVGNames::biasAttr) + setBiasBaseValue(value.toFloat()); + else if (attr->name() == SVGNames::targetXAttr) + setTargetXBaseValue(value.toUIntStrict()); + else if (attr->name() == SVGNames::targetYAttr) + setTargetYBaseValue(value.toUIntStrict()); + else if (attr->name() == SVGNames::kernelUnitLengthAttr) { + float x, y; + if (parseNumberOptionalNumber(value, x, y)) { + setKernelUnitLengthXBaseValue(x); + setKernelUnitLengthYBaseValue(y); + } + } else if (attr->name() == SVGNames::preserveAlphaAttr) { + if (value == "true") + setPreserveAlphaBaseValue(true); + else if (value == "false") + setPreserveAlphaBaseValue(false); + } else + SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr); +} + +void SVGFEConvolveMatrixElement::setOrder(float x, float y) +{ + setOrderXBaseValue(x); + setOrderYBaseValue(y); + invalidate(); +} + +void SVGFEConvolveMatrixElement::setKernelUnitLength(float x, float y) +{ + setKernelUnitLengthXBaseValue(x); + setKernelUnitLengthYBaseValue(y); + invalidate(); +} + +void SVGFEConvolveMatrixElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName); + + if (attrName == SVGNames::inAttr + || attrName == SVGNames::orderAttr + || attrName == SVGNames::edgeModeAttr + || attrName == SVGNames::kernelMatrixAttr + || attrName == SVGNames::divisorAttr + || attrName == SVGNames::biasAttr + || attrName == SVGNames::targetXAttr + || attrName == SVGNames::targetYAttr + || attrName == SVGNames::kernelUnitLengthAttr + || attrName == SVGNames::preserveAlphaAttr) + invalidate(); +} + +PassRefPtr<FilterEffect> SVGFEConvolveMatrixElement::build(SVGFilterBuilder* filterBuilder, Filter* filter) +{ + FilterEffect* input1 = filterBuilder->getEffectById(in1()); + + if (!input1) + return 0; + + int orderXValue = orderX(); + int orderYValue = orderY(); + if (!hasAttribute(SVGNames::orderAttr)) { + orderXValue = 3; + orderYValue = 3; + } + SVGNumberList& kernelMatrix = this->kernelMatrix(); + int kernelMatrixSize = kernelMatrix.size(); + // The spec says this is a requirement, and should bail out if fails + if (orderXValue * orderYValue != kernelMatrixSize) + return 0; + + int targetXValue = targetX(); + int targetYValue = targetY(); + if (hasAttribute(SVGNames::targetXAttr) && (targetXValue < 0 || targetXValue >= orderXValue)) + return 0; + // The spec says the default value is: targetX = floor ( orderX / 2 )) + if (!hasAttribute(SVGNames::targetXAttr)) + targetXValue = static_cast<int>(floorf(orderXValue / 2)); + if (hasAttribute(SVGNames::targetYAttr) && (targetYValue < 0 || targetYValue >= orderYValue)) + return 0; + // The spec says the default value is: targetY = floor ( orderY / 2 )) + if (!hasAttribute(SVGNames::targetYAttr)) + targetYValue = static_cast<int>(floorf(orderYValue / 2)); + + float divisorValue = divisor(); + if (hasAttribute(SVGNames::divisorAttr) && !divisorValue) + return 0; + if (!hasAttribute(SVGNames::divisorAttr)) { + for (int i = 0; i < kernelMatrixSize; ++i) + divisorValue += kernelMatrix.at(i); + if (!divisorValue) + divisorValue = 1; + } + + RefPtr<FilterEffect> effect = FEConvolveMatrix::create(filter, + IntSize(orderXValue, orderYValue), divisorValue, + bias(), IntPoint(targetXValue, targetYValue), static_cast<EdgeModeType>(edgeMode()), + FloatPoint(kernelUnitLengthX(), kernelUnitLengthX()), preserveAlpha(), kernelMatrix); + effect->inputEffects().append(input1); + return effect.release(); +} + +} // namespace WebCore + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGFEConvolveMatrixElement.h b/Source/WebCore/svg/SVGFEConvolveMatrixElement.h new file mode 100644 index 0000000..21826ec --- /dev/null +++ b/Source/WebCore/svg/SVGFEConvolveMatrixElement.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFEConvolveMatrixElement_h +#define SVGFEConvolveMatrixElement_h + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "FEConvolveMatrix.h" +#include "SVGAnimatedEnumeration.h" +#include "SVGAnimatedNumber.h" +#include "SVGAnimatedNumberList.h" +#include "SVGFilterPrimitiveStandardAttributes.h" + +namespace WebCore { + +class SVGFEConvolveMatrixElement : public SVGFilterPrimitiveStandardAttributes { +public: + static PassRefPtr<SVGFEConvolveMatrixElement> create(const QualifiedName&, Document*); + + void setOrder(float orderX, float orderY); + void setKernelUnitLength(float kernelUnitLengthX, float kernelUnitLengthY); + +private: + SVGFEConvolveMatrixElement(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual PassRefPtr<FilterEffect> build(SVGFilterBuilder*, Filter*); + + static const AtomicString& orderXIdentifier(); + static const AtomicString& orderYIdentifier(); + static const AtomicString& kernelUnitLengthXIdentifier(); + static const AtomicString& kernelUnitLengthYIdentifier(); + + // Animated property declarations + DECLARE_ANIMATED_STRING(In1, in1) + DECLARE_ANIMATED_INTEGER(OrderX, orderX) + DECLARE_ANIMATED_INTEGER(OrderY, orderY) + DECLARE_ANIMATED_NUMBER_LIST(KernelMatrix, kernelMatrix) + DECLARE_ANIMATED_NUMBER(Divisor, divisor) + DECLARE_ANIMATED_NUMBER(Bias, bias) + DECLARE_ANIMATED_INTEGER(TargetX, targetX) + DECLARE_ANIMATED_INTEGER(TargetY, targetY) + DECLARE_ANIMATED_ENUMERATION(EdgeMode, edgeMode) + DECLARE_ANIMATED_NUMBER(KernelUnitLengthX, kernelUnitLengthX) + DECLARE_ANIMATED_NUMBER(KernelUnitLengthY, kernelUnitLengthY) + DECLARE_ANIMATED_BOOLEAN(PreserveAlpha, preserveAlpha) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGFEConvolveMatrixElement.idl b/Source/WebCore/svg/SVGFEConvolveMatrixElement.idl new file mode 100644 index 0000000..5fdc55c --- /dev/null +++ b/Source/WebCore/svg/SVGFEConvolveMatrixElement.idl @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> + * + * 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 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 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. + */ + +module svg { + + interface [ + Conditional=SVG&FILTERS, + GenerateConstructor, + DontCheckEnums + ] SVGFEConvolveMatrixElement : SVGElement, + SVGFilterPrimitiveStandardAttributes { + // Edge Mode Values + const unsigned short SVG_EDGEMODE_UNKNOWN = 0; + const unsigned short SVG_EDGEMODE_DUPLICATE = 1; + const unsigned short SVG_EDGEMODE_WRAP = 2; + const unsigned short SVG_EDGEMODE_NONE = 3; + + readonly attribute SVGAnimatedString in1; + readonly attribute SVGAnimatedInteger orderX; + readonly attribute SVGAnimatedInteger orderY; + readonly attribute SVGAnimatedNumberList kernelMatrix; + readonly attribute SVGAnimatedNumber divisor; + readonly attribute SVGAnimatedNumber bias; + readonly attribute SVGAnimatedInteger targetX; + readonly attribute SVGAnimatedInteger targetY; + readonly attribute SVGAnimatedEnumeration edgeMode; + readonly attribute SVGAnimatedNumber kernelUnitLengthX; + readonly attribute SVGAnimatedNumber kernelUnitLengthY; + readonly attribute SVGAnimatedBoolean preserveAlpha; + }; + +} diff --git a/Source/WebCore/svg/SVGFEDiffuseLightingElement.cpp b/Source/WebCore/svg/SVGFEDiffuseLightingElement.cpp new file mode 100644 index 0000000..873b831 --- /dev/null +++ b/Source/WebCore/svg/SVGFEDiffuseLightingElement.cpp @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2005 Oliver Hunt <ojh16@student.canterbury.ac.nz> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFEDiffuseLightingElement.h" + +#include "Attr.h" +#include "FEDiffuseLighting.h" +#include "RenderStyle.h" +#include "SVGColor.h" +#include "SVGFELightElement.h" +#include "SVGNames.h" +#include "SVGParserUtilities.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_STRING(SVGFEDiffuseLightingElement, SVGNames::inAttr, In1, in1) +DEFINE_ANIMATED_NUMBER(SVGFEDiffuseLightingElement, SVGNames::diffuseConstantAttr, DiffuseConstant, diffuseConstant) +DEFINE_ANIMATED_NUMBER(SVGFEDiffuseLightingElement, SVGNames::surfaceScaleAttr, SurfaceScale, surfaceScale) +DEFINE_ANIMATED_NUMBER_MULTIPLE_WRAPPERS(SVGFEDiffuseLightingElement, SVGNames::kernelUnitLengthAttr, kernelUnitLengthXIdentifier(), KernelUnitLengthX, kernelUnitLengthX) +DEFINE_ANIMATED_NUMBER_MULTIPLE_WRAPPERS(SVGFEDiffuseLightingElement, SVGNames::kernelUnitLengthAttr, kernelUnitLengthYIdentifier(), KernelUnitLengthY, kernelUnitLengthY) + +inline SVGFEDiffuseLightingElement::SVGFEDiffuseLightingElement(const QualifiedName& tagName, Document* document) + : SVGFilterPrimitiveStandardAttributes(tagName, document) + , m_diffuseConstant(1) + , m_surfaceScale(1) +{ +} + +PassRefPtr<SVGFEDiffuseLightingElement> SVGFEDiffuseLightingElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGFEDiffuseLightingElement(tagName, document)); +} + +const AtomicString& SVGFEDiffuseLightingElement::kernelUnitLengthXIdentifier() +{ + DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGKernelUnitLengthX")); + return s_identifier; +} + +const AtomicString& SVGFEDiffuseLightingElement::kernelUnitLengthYIdentifier() +{ + DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGKernelUnitLengthY")); + return s_identifier; +} + +void SVGFEDiffuseLightingElement::parseMappedAttribute(Attribute* attr) +{ + const String& value = attr->value(); + if (attr->name() == SVGNames::inAttr) + setIn1BaseValue(value); + else if (attr->name() == SVGNames::surfaceScaleAttr) + setSurfaceScaleBaseValue(value.toFloat()); + else if (attr->name() == SVGNames::diffuseConstantAttr) + setDiffuseConstantBaseValue(value.toFloat()); + else if (attr->name() == SVGNames::kernelUnitLengthAttr) { + float x, y; + if (parseNumberOptionalNumber(value, x, y)) { + setKernelUnitLengthXBaseValue(x); + setKernelUnitLengthYBaseValue(y); + } + } else + SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr); +} + +void SVGFEDiffuseLightingElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName); + + if (attrName == SVGNames::inAttr + || attrName == SVGNames::surfaceScaleAttr + || attrName == SVGNames::diffuseConstantAttr + || attrName == SVGNames::kernelUnitLengthAttr + || attrName == SVGNames::lighting_colorAttr) + invalidate(); +} + +void SVGFEDiffuseLightingElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGFilterPrimitiveStandardAttributes::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeIn1(); + synchronizeSurfaceScale(); + synchronizeDiffuseConstant(); + synchronizeKernelUnitLengthX(); + synchronizeKernelUnitLengthY(); + return; + } + + if (attrName == SVGNames::inAttr) + synchronizeIn1(); + else if (attrName == SVGNames::surfaceScaleAttr) + synchronizeSurfaceScale(); + else if (attrName == SVGNames::diffuseConstantAttr) + synchronizeDiffuseConstant(); + else if (attrName == SVGNames::kernelUnitLengthAttr) { + synchronizeKernelUnitLengthX(); + synchronizeKernelUnitLengthY(); + } +} + +PassRefPtr<FilterEffect> SVGFEDiffuseLightingElement::build(SVGFilterBuilder* filterBuilder, Filter* filter) +{ + FilterEffect* input1 = filterBuilder->getEffectById(in1()); + + if (!input1) + return 0; + + RefPtr<RenderStyle> filterStyle = styleForRenderer(); + Color color = filterStyle->svgStyle()->lightingColor(); + + RefPtr<FilterEffect> effect = FEDiffuseLighting::create(filter, color, surfaceScale(), diffuseConstant(), + kernelUnitLengthX(), kernelUnitLengthY(), findLights()); + effect->inputEffects().append(input1); + return effect.release(); +} + +PassRefPtr<LightSource> SVGFEDiffuseLightingElement::findLights() const +{ + for (Node* node = firstChild(); node; node = node->nextSibling()) { + if (node->hasTagName(SVGNames::feDistantLightTag) + || node->hasTagName(SVGNames::fePointLightTag) + || node->hasTagName(SVGNames::feSpotLightTag)) { + SVGFELightElement* lightNode = static_cast<SVGFELightElement*>(node); + return lightNode->lightSource(); + } + } + + return 0; +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGFEDiffuseLightingElement.h b/Source/WebCore/svg/SVGFEDiffuseLightingElement.h new file mode 100644 index 0000000..d56ced9 --- /dev/null +++ b/Source/WebCore/svg/SVGFEDiffuseLightingElement.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * Copyright (C) 2005 Oliver Hunt <oliver@nerget.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFEDiffuseLightingElement_h +#define SVGFEDiffuseLightingElement_h + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFELightElement.h" +#include "SVGFilterPrimitiveStandardAttributes.h" + +namespace WebCore { + +class FEDiffuseLighting; +class SVGColor; + +class SVGFEDiffuseLightingElement : public SVGFilterPrimitiveStandardAttributes { +public: + static PassRefPtr<SVGFEDiffuseLightingElement> create(const QualifiedName&, Document*); + +private: + SVGFEDiffuseLightingElement(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + virtual PassRefPtr<FilterEffect> build(SVGFilterBuilder*, Filter*); + + static const AtomicString& kernelUnitLengthXIdentifier(); + static const AtomicString& kernelUnitLengthYIdentifier(); + + // Animated property declarations + DECLARE_ANIMATED_STRING(In1, in1) + DECLARE_ANIMATED_NUMBER(DiffuseConstant, diffuseConstant) + DECLARE_ANIMATED_NUMBER(SurfaceScale, surfaceScale) + DECLARE_ANIMATED_NUMBER(KernelUnitLengthX, kernelUnitLengthX) + DECLARE_ANIMATED_NUMBER(KernelUnitLengthY, kernelUnitLengthY) + + PassRefPtr<LightSource> findLights() const; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGFEDiffuseLightingElement.idl b/Source/WebCore/svg/SVGFEDiffuseLightingElement.idl new file mode 100644 index 0000000..bbab929 --- /dev/null +++ b/Source/WebCore/svg/SVGFEDiffuseLightingElement.idl @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG&FILTERS] SVGFEDiffuseLightingElement : SVGElement, + SVGFilterPrimitiveStandardAttributes { + readonly attribute SVGAnimatedString in1; + readonly attribute SVGAnimatedNumber surfaceScale; + readonly attribute SVGAnimatedNumber diffuseConstant; + readonly attribute SVGAnimatedNumber kernelUnitLengthX; + readonly attribute SVGAnimatedNumber kernelUnitLengthY; + }; + +} diff --git a/Source/WebCore/svg/SVGFEDisplacementMapElement.cpp b/Source/WebCore/svg/SVGFEDisplacementMapElement.cpp new file mode 100644 index 0000000..a363b3a --- /dev/null +++ b/Source/WebCore/svg/SVGFEDisplacementMapElement.cpp @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2006 Oliver Hunt <oliver@nerget.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFEDisplacementMapElement.h" + +#include "Attribute.h" +#include "SVGNames.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_STRING(SVGFEDisplacementMapElement, SVGNames::inAttr, In1, in1) +DEFINE_ANIMATED_STRING(SVGFEDisplacementMapElement, SVGNames::in2Attr, In2, in2) +DEFINE_ANIMATED_ENUMERATION(SVGFEDisplacementMapElement, SVGNames::xChannelSelectorAttr, XChannelSelector, xChannelSelector) +DEFINE_ANIMATED_ENUMERATION(SVGFEDisplacementMapElement, SVGNames::yChannelSelectorAttr, YChannelSelector, yChannelSelector) +DEFINE_ANIMATED_NUMBER(SVGFEDisplacementMapElement, SVGNames::scaleAttr, Scale, scale) + +inline SVGFEDisplacementMapElement::SVGFEDisplacementMapElement(const QualifiedName& tagName, Document* document) + : SVGFilterPrimitiveStandardAttributes(tagName, document) + , m_xChannelSelector(CHANNEL_A) + , m_yChannelSelector(CHANNEL_A) +{ +} + +PassRefPtr<SVGFEDisplacementMapElement> SVGFEDisplacementMapElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGFEDisplacementMapElement(tagName, document)); +} + +ChannelSelectorType SVGFEDisplacementMapElement::stringToChannel(const String& key) +{ + if (key == "R") + return CHANNEL_R; + if (key == "G") + return CHANNEL_G; + if (key == "B") + return CHANNEL_B; + if (key == "A") + return CHANNEL_A; + + return CHANNEL_UNKNOWN; +} + +void SVGFEDisplacementMapElement::parseMappedAttribute(Attribute* attr) +{ + const String& value = attr->value(); + if (attr->name() == SVGNames::xChannelSelectorAttr) + setXChannelSelectorBaseValue(stringToChannel(value)); + else if (attr->name() == SVGNames::yChannelSelectorAttr) + setYChannelSelectorBaseValue(stringToChannel(value)); + else if (attr->name() == SVGNames::inAttr) + setIn1BaseValue(value); + else if (attr->name() == SVGNames::in2Attr) + setIn2BaseValue(value); + else if (attr->name() == SVGNames::scaleAttr) + setScaleBaseValue(value.toFloat()); + else + SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr); +} + +void SVGFEDisplacementMapElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName); + + if (attrName == SVGNames::xChannelSelectorAttr + || attrName == SVGNames::yChannelSelectorAttr + || attrName == SVGNames::inAttr + || attrName == SVGNames::in2Attr + || attrName == SVGNames::scaleAttr) + invalidate(); +} + +void SVGFEDisplacementMapElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGFilterPrimitiveStandardAttributes::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeXChannelSelector(); + synchronizeYChannelSelector(); + synchronizeIn1(); + synchronizeIn2(); + synchronizeScale(); + return; + } + + if (attrName == SVGNames::xChannelSelectorAttr) + synchronizeXChannelSelector(); + else if (attrName == SVGNames::yChannelSelectorAttr) + synchronizeYChannelSelector(); + else if (attrName == SVGNames::inAttr) + synchronizeIn1(); + else if (attrName == SVGNames::in2Attr) + synchronizeIn2(); + else if (attrName == SVGNames::scaleAttr) + synchronizeScale(); +} + +PassRefPtr<FilterEffect> SVGFEDisplacementMapElement::build(SVGFilterBuilder* filterBuilder, Filter* filter) +{ + FilterEffect* input1 = filterBuilder->getEffectById(in1()); + FilterEffect* input2 = filterBuilder->getEffectById(in2()); + + if (!input1 || !input2) + return 0; + + RefPtr<FilterEffect> effect = FEDisplacementMap::create(filter, static_cast<ChannelSelectorType>(xChannelSelector()), + static_cast<ChannelSelectorType>(yChannelSelector()), scale()); + FilterEffectVector& inputEffects = effect->inputEffects(); + inputEffects.reserveCapacity(2); + inputEffects.append(input1); + inputEffects.append(input2); + return effect.release(); +} + +} + +#endif // ENABLE(SVG) + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGFEDisplacementMapElement.h b/Source/WebCore/svg/SVGFEDisplacementMapElement.h new file mode 100644 index 0000000..3af378c --- /dev/null +++ b/Source/WebCore/svg/SVGFEDisplacementMapElement.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2006 Oliver Hunt <oliver@nerget.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFEDisplacementMapElement_h +#define SVGFEDisplacementMapElement_h + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "FEDisplacementMap.h" +#include "SVGAnimatedEnumeration.h" +#include "SVGAnimatedNumber.h" +#include "SVGFilterPrimitiveStandardAttributes.h" + +namespace WebCore { + +class SVGFEDisplacementMapElement : public SVGFilterPrimitiveStandardAttributes { +public: + static PassRefPtr<SVGFEDisplacementMapElement> create(const QualifiedName&, Document*); + + static ChannelSelectorType stringToChannel(const String&); + +private: + SVGFEDisplacementMapElement(const QualifiedName& tagName, Document*); + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + virtual PassRefPtr<FilterEffect> build(SVGFilterBuilder*, Filter*); + + // Animated property declarations + DECLARE_ANIMATED_STRING(In1, in1) + DECLARE_ANIMATED_STRING(In2, in2) + DECLARE_ANIMATED_ENUMERATION(XChannelSelector, xChannelSelector) + DECLARE_ANIMATED_ENUMERATION(YChannelSelector, yChannelSelector) + DECLARE_ANIMATED_NUMBER(Scale, scale) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGFEDisplacementMapElement_h diff --git a/Source/WebCore/svg/SVGFEDisplacementMapElement.idl b/Source/WebCore/svg/SVGFEDisplacementMapElement.idl new file mode 100644 index 0000000..0fb4e63 --- /dev/null +++ b/Source/WebCore/svg/SVGFEDisplacementMapElement.idl @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [ + Conditional=SVG&FILTERS, + DontCheckEnums + ] SVGFEDisplacementMapElement : SVGElement, + SVGFilterPrimitiveStandardAttributes { + // Channel Selectors + const unsigned short SVG_CHANNEL_UNKNOWN = 0; + const unsigned short SVG_CHANNEL_R = 1; + const unsigned short SVG_CHANNEL_G = 2; + const unsigned short SVG_CHANNEL_B = 3; + const unsigned short SVG_CHANNEL_A = 4; + + readonly attribute SVGAnimatedString in1; + readonly attribute SVGAnimatedString in2; + readonly attribute SVGAnimatedNumber scale; + readonly attribute SVGAnimatedEnumeration xChannelSelector; + readonly attribute SVGAnimatedEnumeration yChannelSelector; + }; + +} diff --git a/Source/WebCore/svg/SVGFEDistantLightElement.cpp b/Source/WebCore/svg/SVGFEDistantLightElement.cpp new file mode 100644 index 0000000..43a2868 --- /dev/null +++ b/Source/WebCore/svg/SVGFEDistantLightElement.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2005 Oliver Hunt <ojh16@student.canterbury.ac.nz> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFEDistantLightElement.h" + +#include "DistantLightSource.h" + +namespace WebCore { + +inline SVGFEDistantLightElement::SVGFEDistantLightElement(const QualifiedName& tagName, Document* document) + : SVGFELightElement(tagName, document) +{ +} + +PassRefPtr<SVGFEDistantLightElement> SVGFEDistantLightElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGFEDistantLightElement(tagName, document)); +} + +PassRefPtr<LightSource> SVGFEDistantLightElement::lightSource() const +{ + return DistantLightSource::create(azimuth(), elevation()); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGFEDistantLightElement.h b/Source/WebCore/svg/SVGFEDistantLightElement.h new file mode 100644 index 0000000..04964ac --- /dev/null +++ b/Source/WebCore/svg/SVGFEDistantLightElement.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2005 Oliver Hunt <ojh16@student.canterbury.ac.nz> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFEDistantLightElement_h +#define SVGFEDistantLightElement_h + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFELightElement.h" + +namespace WebCore { + +class SVGFEDistantLightElement : public SVGFELightElement { +public: + static PassRefPtr<SVGFEDistantLightElement> create(const QualifiedName&, Document*); + +private: + SVGFEDistantLightElement(const QualifiedName&, Document*); + + virtual PassRefPtr<LightSource> lightSource() const; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGFEDistantLightElement.idl b/Source/WebCore/svg/SVGFEDistantLightElement.idl new file mode 100644 index 0000000..d9d1be9 --- /dev/null +++ b/Source/WebCore/svg/SVGFEDistantLightElement.idl @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG&FILTERS] SVGFEDistantLightElement : SVGElement { + readonly attribute SVGAnimatedNumber azimuth; + readonly attribute SVGAnimatedNumber elevation; + }; + +} diff --git a/Source/WebCore/svg/SVGFEFloodElement.cpp b/Source/WebCore/svg/SVGFEFloodElement.cpp new file mode 100644 index 0000000..53ad910 --- /dev/null +++ b/Source/WebCore/svg/SVGFEFloodElement.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2007, 2008 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFEFloodElement.h" + +#include "Attribute.h" +#include "RenderStyle.h" +#include "SVGRenderStyle.h" + +namespace WebCore { + +inline SVGFEFloodElement::SVGFEFloodElement(const QualifiedName& tagName, Document* document) + : SVGFilterPrimitiveStandardAttributes(tagName, document) +{ +} + +PassRefPtr<SVGFEFloodElement> SVGFEFloodElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGFEFloodElement(tagName, document)); +} + +PassRefPtr<FilterEffect> SVGFEFloodElement::build(SVGFilterBuilder*, Filter* filter) +{ + RefPtr<RenderStyle> filterStyle = styleForRenderer(); + + Color color = filterStyle->svgStyle()->floodColor(); + float opacity = filterStyle->svgStyle()->floodOpacity(); + + return FEFlood::create(filter, color, opacity); +} + +} + +#endif // ENABLE(SVG) && ENABLE(FILTERS) + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGFEFloodElement.h b/Source/WebCore/svg/SVGFEFloodElement.h new file mode 100644 index 0000000..1485ddd --- /dev/null +++ b/Source/WebCore/svg/SVGFEFloodElement.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2008 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFEFloodElement_h +#define SVGFEFloodElement_h + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "FEFlood.h" +#include "SVGFilterPrimitiveStandardAttributes.h" + +namespace WebCore { + +class SVGFEFloodElement : public SVGFilterPrimitiveStandardAttributes { +public: + static PassRefPtr<SVGFEFloodElement> create(const QualifiedName&, Document*); + +private: + SVGFEFloodElement(const QualifiedName&, Document*); + + virtual PassRefPtr<FilterEffect> build(SVGFilterBuilder*, Filter*); +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(FILTERS) +#endif diff --git a/Source/WebCore/svg/SVGFEFloodElement.idl b/Source/WebCore/svg/SVGFEFloodElement.idl new file mode 100644 index 0000000..6adbefb --- /dev/null +++ b/Source/WebCore/svg/SVGFEFloodElement.idl @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG&FILTERS] SVGFEFloodElement : SVGElement, + SVGFilterPrimitiveStandardAttributes { + }; +} diff --git a/Source/WebCore/svg/SVGFEFuncAElement.cpp b/Source/WebCore/svg/SVGFEFuncAElement.cpp new file mode 100644 index 0000000..8967efe --- /dev/null +++ b/Source/WebCore/svg/SVGFEFuncAElement.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFEFuncAElement.h" + +namespace WebCore { + +inline SVGFEFuncAElement::SVGFEFuncAElement(const QualifiedName& tagName, Document* document) + : SVGComponentTransferFunctionElement(tagName, document) +{ +} + +PassRefPtr<SVGFEFuncAElement> SVGFEFuncAElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGFEFuncAElement(tagName, document)); +} + +} + +#endif // ENABLE(SVG) + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGFEFuncAElement.h b/Source/WebCore/svg/SVGFEFuncAElement.h new file mode 100644 index 0000000..26fcc23 --- /dev/null +++ b/Source/WebCore/svg/SVGFEFuncAElement.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFEFuncAElement_h +#define SVGFEFuncAElement_h + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGComponentTransferFunctionElement.h" + +namespace WebCore { + +class SVGFEFuncAElement : public SVGComponentTransferFunctionElement { +public: + static PassRefPtr<SVGFEFuncAElement> create(const QualifiedName&, Document*); + +private: + SVGFEFuncAElement(const QualifiedName&, Document*); +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGFEFuncAElement.idl b/Source/WebCore/svg/SVGFEFuncAElement.idl new file mode 100644 index 0000000..8bde3a7 --- /dev/null +++ b/Source/WebCore/svg/SVGFEFuncAElement.idl @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG&FILTERS] SVGFEFuncAElement : SVGComponentTransferFunctionElement { + }; + +} diff --git a/Source/WebCore/svg/SVGFEFuncBElement.cpp b/Source/WebCore/svg/SVGFEFuncBElement.cpp new file mode 100644 index 0000000..2b4287a --- /dev/null +++ b/Source/WebCore/svg/SVGFEFuncBElement.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFEFuncBElement.h" + +namespace WebCore { + +inline SVGFEFuncBElement::SVGFEFuncBElement(const QualifiedName& tagName, Document* document) + : SVGComponentTransferFunctionElement(tagName, document) +{ +} + +PassRefPtr<SVGFEFuncBElement> SVGFEFuncBElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGFEFuncBElement(tagName, document)); +} + +} + +#endif // ENABLE(SVG) + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGFEFuncBElement.h b/Source/WebCore/svg/SVGFEFuncBElement.h new file mode 100644 index 0000000..83143db --- /dev/null +++ b/Source/WebCore/svg/SVGFEFuncBElement.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFEFuncBElement_h +#define SVGFEFuncBElement_h + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGComponentTransferFunctionElement.h" + +namespace WebCore { + +class SVGFEFuncBElement : public SVGComponentTransferFunctionElement { +public: + static PassRefPtr<SVGFEFuncBElement> create(const QualifiedName&, Document*); + +private: + SVGFEFuncBElement(const QualifiedName&, Document*); +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGFEFuncBElement.idl b/Source/WebCore/svg/SVGFEFuncBElement.idl new file mode 100644 index 0000000..2575ab5 --- /dev/null +++ b/Source/WebCore/svg/SVGFEFuncBElement.idl @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG&FILTERS] SVGFEFuncBElement : SVGComponentTransferFunctionElement { + }; + +} diff --git a/Source/WebCore/svg/SVGFEFuncGElement.cpp b/Source/WebCore/svg/SVGFEFuncGElement.cpp new file mode 100644 index 0000000..32cbdf3 --- /dev/null +++ b/Source/WebCore/svg/SVGFEFuncGElement.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFEFuncGElement.h" + +namespace WebCore { + +inline SVGFEFuncGElement::SVGFEFuncGElement(const QualifiedName& tagName, Document* document) + : SVGComponentTransferFunctionElement(tagName, document) +{ +} + +PassRefPtr<SVGFEFuncGElement> SVGFEFuncGElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGFEFuncGElement(tagName, document)); +} + +} + +#endif // ENABLE(SVG) + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGFEFuncGElement.h b/Source/WebCore/svg/SVGFEFuncGElement.h new file mode 100644 index 0000000..1c679b6 --- /dev/null +++ b/Source/WebCore/svg/SVGFEFuncGElement.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFEFuncGElement_h +#define SVGFEFuncGElement_h + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGComponentTransferFunctionElement.h" + +namespace WebCore { + +class SVGFEFuncGElement : public SVGComponentTransferFunctionElement { +public: + static PassRefPtr<SVGFEFuncGElement> create(const QualifiedName&, Document*); + +private: + SVGFEFuncGElement(const QualifiedName&, Document*); +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGFEFuncGElement.idl b/Source/WebCore/svg/SVGFEFuncGElement.idl new file mode 100644 index 0000000..16f7811 --- /dev/null +++ b/Source/WebCore/svg/SVGFEFuncGElement.idl @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG&FILTERS] SVGFEFuncGElement : SVGComponentTransferFunctionElement { + }; + +} diff --git a/Source/WebCore/svg/SVGFEFuncRElement.cpp b/Source/WebCore/svg/SVGFEFuncRElement.cpp new file mode 100644 index 0000000..9c17909 --- /dev/null +++ b/Source/WebCore/svg/SVGFEFuncRElement.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFEFuncRElement.h" + +namespace WebCore { + +inline SVGFEFuncRElement::SVGFEFuncRElement(const QualifiedName& tagName, Document* document) + : SVGComponentTransferFunctionElement(tagName, document) +{ +} + +PassRefPtr<SVGFEFuncRElement> SVGFEFuncRElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGFEFuncRElement(tagName, document)); +} + +} + +#endif // ENABLE(SVG) + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGFEFuncRElement.h b/Source/WebCore/svg/SVGFEFuncRElement.h new file mode 100644 index 0000000..b3e651c --- /dev/null +++ b/Source/WebCore/svg/SVGFEFuncRElement.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFEFuncRElement_h +#define SVGFEFuncRElement_h + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGComponentTransferFunctionElement.h" + +namespace WebCore { + +class SVGFEFuncRElement : public SVGComponentTransferFunctionElement { +public: + static PassRefPtr<SVGFEFuncRElement> create(const QualifiedName&, Document*); + +private: + SVGFEFuncRElement(const QualifiedName&, Document*); +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGFEFuncRElement.idl b/Source/WebCore/svg/SVGFEFuncRElement.idl new file mode 100644 index 0000000..c3c742a --- /dev/null +++ b/Source/WebCore/svg/SVGFEFuncRElement.idl @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG&FILTERS] SVGFEFuncRElement : SVGComponentTransferFunctionElement { + }; + +} diff --git a/Source/WebCore/svg/SVGFEGaussianBlurElement.cpp b/Source/WebCore/svg/SVGFEGaussianBlurElement.cpp new file mode 100644 index 0000000..43b6fd6 --- /dev/null +++ b/Source/WebCore/svg/SVGFEGaussianBlurElement.cpp @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFEGaussianBlurElement.h" + +#include "Attribute.h" +#include "SVGNames.h" +#include "SVGParserUtilities.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_STRING(SVGFEGaussianBlurElement, SVGNames::inAttr, In1, in1) +DEFINE_ANIMATED_NUMBER_MULTIPLE_WRAPPERS(SVGFEGaussianBlurElement, SVGNames::stdDeviationAttr, stdDeviationXIdentifier(), StdDeviationX, stdDeviationX) +DEFINE_ANIMATED_NUMBER_MULTIPLE_WRAPPERS(SVGFEGaussianBlurElement, SVGNames::stdDeviationAttr, stdDeviationYIdentifier(), StdDeviationY, stdDeviationY) + +inline SVGFEGaussianBlurElement::SVGFEGaussianBlurElement(const QualifiedName& tagName, Document* document) + : SVGFilterPrimitiveStandardAttributes(tagName, document) +{ +} + +PassRefPtr<SVGFEGaussianBlurElement> SVGFEGaussianBlurElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGFEGaussianBlurElement(tagName, document)); +} + +const AtomicString& SVGFEGaussianBlurElement::stdDeviationXIdentifier() +{ + DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGStdDeviationX")); + return s_identifier; +} + +const AtomicString& SVGFEGaussianBlurElement::stdDeviationYIdentifier() +{ + DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGStdDeviationY")); + return s_identifier; +} + +void SVGFEGaussianBlurElement::setStdDeviation(float x, float y) +{ + setStdDeviationXBaseValue(x); + setStdDeviationYBaseValue(y); + invalidate(); +} + +void SVGFEGaussianBlurElement::parseMappedAttribute(Attribute* attr) +{ + const String& value = attr->value(); + if (attr->name() == SVGNames::stdDeviationAttr) { + float x, y; + if (parseNumberOptionalNumber(value, x, y)) { + setStdDeviationXBaseValue(x); + setStdDeviationYBaseValue(y); + } + } else if (attr->name() == SVGNames::inAttr) + setIn1BaseValue(value); + else + SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr); +} + +void SVGFEGaussianBlurElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName); + + if (attrName == SVGNames::inAttr + || attrName == SVGNames::stdDeviationAttr) + invalidate(); +} + +void SVGFEGaussianBlurElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGFilterPrimitiveStandardAttributes::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeStdDeviationX(); + synchronizeStdDeviationY(); + synchronizeIn1(); + return; + } + + if (attrName == SVGNames::stdDeviationAttr) { + synchronizeStdDeviationX(); + synchronizeStdDeviationY(); + } else if (attrName == SVGNames::inAttr) + synchronizeIn1(); +} + +PassRefPtr<FilterEffect> SVGFEGaussianBlurElement::build(SVGFilterBuilder* filterBuilder, Filter* filter) +{ + FilterEffect* input1 = filterBuilder->getEffectById(in1()); + + if (!input1) + return 0; + + RefPtr<FilterEffect> effect = FEGaussianBlur::create(filter, stdDeviationX(), stdDeviationY()); + effect->inputEffects().append(input1); + return effect.release(); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGFEGaussianBlurElement.h b/Source/WebCore/svg/SVGFEGaussianBlurElement.h new file mode 100644 index 0000000..1b04658 --- /dev/null +++ b/Source/WebCore/svg/SVGFEGaussianBlurElement.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFEGaussianBlurElement_h +#define SVGFEGaussianBlurElement_h + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "FEGaussianBlur.h" +#include "SVGAnimatedNumber.h" +#include "SVGFilterPrimitiveStandardAttributes.h" + +namespace WebCore { + +class SVGFEGaussianBlurElement : public SVGFilterPrimitiveStandardAttributes { +public: + static PassRefPtr<SVGFEGaussianBlurElement> create(const QualifiedName&, Document*); + + void setStdDeviation(float stdDeviationX, float stdDeviationY); + +private: + SVGFEGaussianBlurElement(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + virtual PassRefPtr<FilterEffect> build(SVGFilterBuilder*, Filter*); + + static const AtomicString& stdDeviationXIdentifier(); + static const AtomicString& stdDeviationYIdentifier(); + + // Animated property declarations + DECLARE_ANIMATED_STRING(In1, in1) + DECLARE_ANIMATED_NUMBER(StdDeviationX, stdDeviationX) + DECLARE_ANIMATED_NUMBER(StdDeviationY, stdDeviationY) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGFEGaussianBlurElement.idl b/Source/WebCore/svg/SVGFEGaussianBlurElement.idl new file mode 100644 index 0000000..52478d8 --- /dev/null +++ b/Source/WebCore/svg/SVGFEGaussianBlurElement.idl @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG&FILTERS] SVGFEGaussianBlurElement : SVGElement, + SVGFilterPrimitiveStandardAttributes { + readonly attribute SVGAnimatedString in1; + readonly attribute SVGAnimatedNumber stdDeviationX; + readonly attribute SVGAnimatedNumber stdDeviationY; + + void setStdDeviation(in float stdDeviationX, in float stdDeviationY); + }; + +} diff --git a/Source/WebCore/svg/SVGFEImageElement.cpp b/Source/WebCore/svg/SVGFEImageElement.cpp new file mode 100644 index 0000000..04ea14c --- /dev/null +++ b/Source/WebCore/svg/SVGFEImageElement.cpp @@ -0,0 +1,168 @@ +/* + * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * Copyright (C) 2010 Dirk Schulze <krit@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFEImageElement.h" + +#include "Attr.h" +#include "CachedImage.h" +#include "CachedResourceLoader.h" +#include "ColorSpace.h" +#include "Document.h" +#include "RenderObject.h" +#include "RenderSVGResource.h" +#include "SVGImageBufferTools.h" +#include "SVGNames.h" +#include "SVGPreserveAspectRatio.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_PRESERVEASPECTRATIO(SVGFEImageElement, SVGNames::preserveAspectRatioAttr, PreserveAspectRatio, preserveAspectRatio) +DEFINE_ANIMATED_STRING(SVGFEImageElement, XLinkNames::hrefAttr, Href, href) +DEFINE_ANIMATED_BOOLEAN(SVGFEImageElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) + +inline SVGFEImageElement::SVGFEImageElement(const QualifiedName& tagName, Document* document) + : SVGFilterPrimitiveStandardAttributes(tagName, document) +{ +} + +PassRefPtr<SVGFEImageElement> SVGFEImageElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGFEImageElement(tagName, document)); +} + +SVGFEImageElement::~SVGFEImageElement() +{ + if (m_cachedImage) + m_cachedImage->removeClient(this); +} + +void SVGFEImageElement::requestImageResource() +{ + if (m_cachedImage) { + m_cachedImage->removeClient(this); + m_cachedImage = 0; + } + + Element* hrefElement = document()->getElementById(SVGURIReference::getTarget(href())); + if (hrefElement && hrefElement->isSVGElement() && hrefElement->renderer()) + return; + + m_cachedImage = ownerDocument()->cachedResourceLoader()->requestImage(href()); + + if (m_cachedImage) + m_cachedImage->addClient(this); +} + +void SVGFEImageElement::parseMappedAttribute(Attribute* attr) +{ + const String& value = attr->value(); + if (attr->name() == SVGNames::preserveAspectRatioAttr) + SVGPreserveAspectRatio::parsePreserveAspectRatio(this, value); + else { + if (SVGURIReference::parseMappedAttribute(attr)) { + requestImageResource(); + return; + } + if (SVGLangSpace::parseMappedAttribute(attr)) + return; + if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) + return; + + SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr); + } +} + +void SVGFEImageElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName); + + if (attrName == SVGNames::preserveAspectRatioAttr) + invalidate(); +} + +void SVGFEImageElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGFilterPrimitiveStandardAttributes::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizePreserveAspectRatio(); + synchronizeHref(); + synchronizeExternalResourcesRequired(); + return; + } + + if (attrName == SVGNames::preserveAspectRatioAttr) + synchronizePreserveAspectRatio(); + else if (SVGURIReference::isKnownAttribute(attrName)) + synchronizeHref(); + else if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) + synchronizeExternalResourcesRequired(); +} + +void SVGFEImageElement::notifyFinished(CachedResource*) +{ + if (!inDocument()) + return; + + Element* parent = parentElement(); + ASSERT(parent); + + if (!parent->hasTagName(SVGNames::filterTag) || !parent->renderer()) + return; + + RenderSVGResource::markForLayoutAndParentResourceInvalidation(parent->renderer()); +} + +PassRefPtr<FilterEffect> SVGFEImageElement::build(SVGFilterBuilder*, Filter* filter) +{ + if (!m_cachedImage && !m_targetImage) { + Element* hrefElement = document()->getElementById(SVGURIReference::getTarget(href())); + if (!hrefElement || !hrefElement->isSVGElement()) + return 0; + + RenderObject* renderer = hrefElement->renderer(); + if (!renderer) + return 0; + + IntRect targetRect = enclosingIntRect(renderer->objectBoundingBox()); + m_targetImage = ImageBuffer::create(targetRect.size(), ColorSpaceLinearRGB); + + AffineTransform contentTransformation; + SVGImageBufferTools::renderSubtreeToImageBuffer(m_targetImage.get(), renderer, contentTransformation); + } + + return FEImage::create(filter, m_targetImage ? m_targetImage->copyImage() : m_cachedImage->image(), preserveAspectRatio()); +} + +void SVGFEImageElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const +{ + SVGFilterPrimitiveStandardAttributes::addSubresourceAttributeURLs(urls); + + addSubresourceURL(urls, document()->completeURL(href())); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGFEImageElement.h b/Source/WebCore/svg/SVGFEImageElement.h new file mode 100644 index 0000000..64d95dc --- /dev/null +++ b/Source/WebCore/svg/SVGFEImageElement.h @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFEImageElement_h +#define SVGFEImageElement_h + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "CachedResourceClient.h" +#include "CachedResourceHandle.h" +#include "ImageBuffer.h" +#include "SVGAnimatedPreserveAspectRatio.h" +#include "SVGExternalResourcesRequired.h" +#include "SVGFEImage.h" +#include "SVGFilterPrimitiveStandardAttributes.h" +#include "SVGLangSpace.h" +#include "SVGURIReference.h" + +namespace WebCore { + +class SVGFEImageElement : public SVGFilterPrimitiveStandardAttributes, + public SVGURIReference, + public SVGLangSpace, + public SVGExternalResourcesRequired, + public CachedResourceClient { +public: + static PassRefPtr<SVGFEImageElement> create(const QualifiedName&, Document*); + + virtual ~SVGFEImageElement(); + +private: + SVGFEImageElement(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + virtual void notifyFinished(CachedResource*); + + virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const; + virtual PassRefPtr<FilterEffect> build(SVGFilterBuilder*, Filter*); + + void requestImageResource(); + + // Animated property declarations + DECLARE_ANIMATED_PRESERVEASPECTRATIO(PreserveAspectRatio, preserveAspectRatio) + + // SVGURIReference + DECLARE_ANIMATED_STRING(Href, href) + + // SVGExternalResourcesRequired + DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) + + CachedResourceHandle<CachedImage> m_cachedImage; + OwnPtr<ImageBuffer> m_targetImage; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGFEImageElement.idl b/Source/WebCore/svg/SVGFEImageElement.idl new file mode 100644 index 0000000..6c7363c --- /dev/null +++ b/Source/WebCore/svg/SVGFEImageElement.idl @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG&FILTERS] SVGFEImageElement : SVGElement, + SVGURIReference, + SVGLangSpace, + SVGExternalResourcesRequired, + SVGFilterPrimitiveStandardAttributes { + readonly attribute SVGAnimatedPreserveAspectRatio preserveAspectRatio; + }; + +} diff --git a/Source/WebCore/svg/SVGFELightElement.cpp b/Source/WebCore/svg/SVGFELightElement.cpp new file mode 100644 index 0000000..8ff8eb1 --- /dev/null +++ b/Source/WebCore/svg/SVGFELightElement.cpp @@ -0,0 +1,157 @@ +/* + * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * Copyright (C) 2005 Oliver Hunt <oliver@nerget.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFELightElement.h" + +#include "Attribute.h" +#include "RenderObject.h" +#include "RenderSVGResource.h" +#include "SVGFilterElement.h" +#include "SVGNames.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_NUMBER(SVGFELightElement, SVGNames::azimuthAttr, Azimuth, azimuth) +DEFINE_ANIMATED_NUMBER(SVGFELightElement, SVGNames::elevationAttr, Elevation, elevation) +DEFINE_ANIMATED_NUMBER(SVGFELightElement, SVGNames::xAttr, X, x) +DEFINE_ANIMATED_NUMBER(SVGFELightElement, SVGNames::yAttr, Y, y) +DEFINE_ANIMATED_NUMBER(SVGFELightElement, SVGNames::zAttr, Z, z) +DEFINE_ANIMATED_NUMBER(SVGFELightElement, SVGNames::pointsAtXAttr, PointsAtX, pointsAtX) +DEFINE_ANIMATED_NUMBER(SVGFELightElement, SVGNames::pointsAtYAttr, PointsAtY, pointsAtY) +DEFINE_ANIMATED_NUMBER(SVGFELightElement, SVGNames::pointsAtZAttr, PointsAtZ, pointsAtZ) +DEFINE_ANIMATED_NUMBER(SVGFELightElement, SVGNames::specularExponentAttr, SpecularExponent, specularExponent) +DEFINE_ANIMATED_NUMBER(SVGFELightElement, SVGNames::limitingConeAngleAttr, LimitingConeAngle, limitingConeAngle) + +SVGFELightElement::SVGFELightElement(const QualifiedName& tagName, Document* document) + : SVGElement(tagName, document) + , m_specularExponent(1) +{ +} + +void SVGFELightElement::parseMappedAttribute(Attribute* attr) +{ + const String& value = attr->value(); + if (attr->name() == SVGNames::azimuthAttr) + setAzimuthBaseValue(value.toFloat()); + else if (attr->name() == SVGNames::elevationAttr) + setElevationBaseValue(value.toFloat()); + else if (attr->name() == SVGNames::xAttr) + setXBaseValue(value.toFloat()); + else if (attr->name() == SVGNames::yAttr) + setYBaseValue(value.toFloat()); + else if (attr->name() == SVGNames::zAttr) + setZBaseValue(value.toFloat()); + else if (attr->name() == SVGNames::pointsAtXAttr) + setPointsAtXBaseValue(value.toFloat()); + else if (attr->name() == SVGNames::pointsAtYAttr) + setPointsAtYBaseValue(value.toFloat()); + else if (attr->name() == SVGNames::pointsAtZAttr) + setPointsAtZBaseValue(value.toFloat()); + else if (attr->name() == SVGNames::specularExponentAttr) + setSpecularExponentBaseValue(value.toFloat()); + else if (attr->name() == SVGNames::limitingConeAngleAttr) + setLimitingConeAngleBaseValue(value.toFloat()); + else + SVGElement::parseMappedAttribute(attr); +} + +void SVGFELightElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGElement::svgAttributeChanged(attrName); + + if (attrName == SVGNames::azimuthAttr + || attrName == SVGNames::elevationAttr + || attrName == SVGNames::xAttr + || attrName == SVGNames::yAttr + || attrName == SVGNames::zAttr + || attrName == SVGNames::pointsAtXAttr + || attrName == SVGNames::pointsAtYAttr + || attrName == SVGNames::pointsAtZAttr + || attrName == SVGNames::specularExponentAttr + || attrName == SVGNames::limitingConeAngleAttr) { + if (ContainerNode* parent = parentNode()) { + RenderObject* renderer = parent->renderer(); + if (renderer && renderer->isSVGResourceFilterPrimitive()) + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); + } + } +} + +void SVGFELightElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeAzimuth(); + synchronizeElevation(); + synchronizeX(); + synchronizeY(); + synchronizeZ(); + synchronizePointsAtX(); + synchronizePointsAtY(); + synchronizePointsAtZ(); + synchronizeSpecularExponent(); + synchronizeLimitingConeAngle(); + return; + } + + if (attrName == SVGNames::azimuthAttr) + synchronizeAzimuth(); + else if (attrName == SVGNames::elevationAttr) + synchronizeElevation(); + else if (attrName == SVGNames::xAttr) + synchronizeX(); + else if (attrName == SVGNames::yAttr) + synchronizeY(); + else if (attrName == SVGNames::zAttr) + synchronizeZ(); + else if (attrName == SVGNames::pointsAtXAttr) + synchronizePointsAtX(); + else if (attrName == SVGNames::pointsAtYAttr) + synchronizePointsAtY(); + else if (attrName == SVGNames::pointsAtZAttr) + synchronizePointsAtZ(); + else if (attrName == SVGNames::specularExponentAttr) + synchronizeSpecularExponent(); + else if (attrName == SVGNames::limitingConeAngleAttr) + synchronizeLimitingConeAngle(); +} + +void SVGFELightElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) +{ + SVGElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); + + if (!changedByParser) { + if (ContainerNode* parent = parentNode()) { + RenderObject* renderer = parent->renderer(); + if (renderer && renderer->isSVGResourceFilterPrimitive()) + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); + } + } +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGFELightElement.h b/Source/WebCore/svg/SVGFELightElement.h new file mode 100644 index 0000000..2f6e687 --- /dev/null +++ b/Source/WebCore/svg/SVGFELightElement.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * Copyright (C) 2005 Oliver Hunt <oliver@nerget.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFELightElement_h +#define SVGFELightElement_h + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "LightSource.h" +#include "SVGAnimatedNumber.h" +#include "SVGElement.h" + +namespace WebCore { + +class SVGFELightElement : public SVGElement { +public: + virtual PassRefPtr<LightSource> lightSource() const = 0; + +protected: + SVGFELightElement(const QualifiedName&, Document*); + +private: + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); + + // Animated property declarations + DECLARE_ANIMATED_NUMBER(Azimuth, azimuth) + DECLARE_ANIMATED_NUMBER(Elevation, elevation) + DECLARE_ANIMATED_NUMBER(X, x) + DECLARE_ANIMATED_NUMBER(Y, y) + DECLARE_ANIMATED_NUMBER(Z, z) + DECLARE_ANIMATED_NUMBER(PointsAtX, pointsAtX) + DECLARE_ANIMATED_NUMBER(PointsAtY, pointsAtY) + DECLARE_ANIMATED_NUMBER(PointsAtZ, pointsAtZ) + DECLARE_ANIMATED_NUMBER(SpecularExponent, specularExponent) + DECLARE_ANIMATED_NUMBER(LimitingConeAngle, limitingConeAngle) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(FILTERS) +#endif diff --git a/Source/WebCore/svg/SVGFEMergeElement.cpp b/Source/WebCore/svg/SVGFEMergeElement.cpp new file mode 100644 index 0000000..92f2346 --- /dev/null +++ b/Source/WebCore/svg/SVGFEMergeElement.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFEMergeElement.h" + +#include "SVGFEMergeNodeElement.h" +#include "SVGNames.h" + +namespace WebCore { + +inline SVGFEMergeElement::SVGFEMergeElement(const QualifiedName& tagName, Document* document) + : SVGFilterPrimitiveStandardAttributes(tagName, document) +{ +} + +PassRefPtr<SVGFEMergeElement> SVGFEMergeElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGFEMergeElement(tagName, document)); +} + +PassRefPtr<FilterEffect> SVGFEMergeElement::build(SVGFilterBuilder* filterBuilder, Filter* filter) +{ + RefPtr<FilterEffect> effect = FEMerge::create(filter); + FilterEffectVector& mergeInputs = effect->inputEffects(); + for (Node* node = firstChild(); node; node = node->nextSibling()) { + if (node->hasTagName(SVGNames::feMergeNodeTag)) { + FilterEffect* mergeEffect = filterBuilder->getEffectById(static_cast<SVGFEMergeNodeElement*>(node)->in1()); + if (!mergeEffect) + return 0; + mergeInputs.append(mergeEffect); + } + } + + if (mergeInputs.isEmpty()) + return 0; + + return effect.release(); +} + +} + +#endif // ENABLE(SVG) + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGFEMergeElement.h b/Source/WebCore/svg/SVGFEMergeElement.h new file mode 100644 index 0000000..2495a56 --- /dev/null +++ b/Source/WebCore/svg/SVGFEMergeElement.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFEMergeElement_h +#define SVGFEMergeElement_h + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "FEMerge.h" +#include "SVGFilterPrimitiveStandardAttributes.h" + +namespace WebCore { + +class SVGFEMergeElement : public SVGFilterPrimitiveStandardAttributes { +public: + static PassRefPtr<SVGFEMergeElement> create(const QualifiedName&, Document*); + +private: + SVGFEMergeElement(const QualifiedName&, Document*); + + virtual PassRefPtr<FilterEffect> build(SVGFilterBuilder*, Filter*); +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGFEMergeElement.idl b/Source/WebCore/svg/SVGFEMergeElement.idl new file mode 100644 index 0000000..a648598 --- /dev/null +++ b/Source/WebCore/svg/SVGFEMergeElement.idl @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG&FILTERS] SVGFEMergeElement : SVGElement, + SVGFilterPrimitiveStandardAttributes { + }; + +} diff --git a/Source/WebCore/svg/SVGFEMergeNodeElement.cpp b/Source/WebCore/svg/SVGFEMergeNodeElement.cpp new file mode 100644 index 0000000..83739de --- /dev/null +++ b/Source/WebCore/svg/SVGFEMergeNodeElement.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFEMergeNodeElement.h" + +#include "Attribute.h" +#include "RenderObject.h" +#include "RenderSVGResource.h" +#include "SVGFilterElement.h" +#include "SVGNames.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_STRING(SVGFEMergeNodeElement, SVGNames::inAttr, In1, in1) + +inline SVGFEMergeNodeElement::SVGFEMergeNodeElement(const QualifiedName& tagName, Document* document) + : SVGElement(tagName, document) +{ +} + +PassRefPtr<SVGFEMergeNodeElement> SVGFEMergeNodeElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGFEMergeNodeElement(tagName, document)); +} + +void SVGFEMergeNodeElement::parseMappedAttribute(Attribute* attr) +{ + const String& value = attr->value(); + if (attr->name() == SVGNames::inAttr) + setIn1BaseValue(value); + else + SVGElement::parseMappedAttribute(attr); +} + +void SVGFEMergeNodeElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGElement::svgAttributeChanged(attrName); + + if (attrName != SVGNames::inAttr) + return; + + ContainerNode* parent = parentNode(); + if (!parent) + return; + + RenderObject* renderer = parent->renderer(); + if (!renderer || !renderer->isSVGResourceFilterPrimitive()) + return; + + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); +} + +void SVGFEMergeNodeElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGElement::synchronizeProperty(attrName); + + if (attrName == anyQName() || attrName == SVGNames::inAttr) + synchronizeIn1(); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGFEMergeNodeElement.h b/Source/WebCore/svg/SVGFEMergeNodeElement.h new file mode 100644 index 0000000..14f0e8e --- /dev/null +++ b/Source/WebCore/svg/SVGFEMergeNodeElement.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFEMergeNodeElement_h +#define SVGFEMergeNodeElement_h + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGAnimatedString.h" +#include "SVGElement.h" + +namespace WebCore { + +class SVGFEMergeNodeElement : public SVGElement { +public: + static PassRefPtr<SVGFEMergeNodeElement> create(const QualifiedName&, Document*); + +private: + SVGFEMergeNodeElement(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + + // Animated property declarations + DECLARE_ANIMATED_STRING(In1, in1) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGFEMergeNodeElement.idl b/Source/WebCore/svg/SVGFEMergeNodeElement.idl new file mode 100644 index 0000000..7463461 --- /dev/null +++ b/Source/WebCore/svg/SVGFEMergeNodeElement.idl @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG&FILTERS] SVGFEMergeNodeElement : SVGElement { + readonly attribute SVGAnimatedString in1; + }; + +} diff --git a/Source/WebCore/svg/SVGFEMorphologyElement.cpp b/Source/WebCore/svg/SVGFEMorphologyElement.cpp new file mode 100644 index 0000000..282c495 --- /dev/null +++ b/Source/WebCore/svg/SVGFEMorphologyElement.cpp @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFEMorphologyElement.h" + +#include "Attribute.h" +#include "SVGNames.h" +#include "SVGParserUtilities.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_STRING(SVGFEMorphologyElement, SVGNames::inAttr, In1, in1) +DEFINE_ANIMATED_ENUMERATION(SVGFEMorphologyElement, SVGNames::operatorAttr, _operator, _operator) +DEFINE_ANIMATED_NUMBER_MULTIPLE_WRAPPERS(SVGFEMorphologyElement, SVGNames::radiusAttr, radiusXIdentifier(), RadiusX, radiusX) +DEFINE_ANIMATED_NUMBER_MULTIPLE_WRAPPERS(SVGFEMorphologyElement, SVGNames::radiusAttr, radiusYIdentifier(), RadiusY, radiusY) + +inline SVGFEMorphologyElement::SVGFEMorphologyElement(const QualifiedName& tagName, Document* document) + : SVGFilterPrimitiveStandardAttributes(tagName, document) + , m__operator(FEMORPHOLOGY_OPERATOR_ERODE) +{ +} + +PassRefPtr<SVGFEMorphologyElement> SVGFEMorphologyElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGFEMorphologyElement(tagName, document)); +} + +const AtomicString& SVGFEMorphologyElement::radiusXIdentifier() +{ + DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGRadiusX")); + return s_identifier; +} + +const AtomicString& SVGFEMorphologyElement::radiusYIdentifier() +{ + DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGRadiusY")); + return s_identifier; +} + +void SVGFEMorphologyElement::setRadius(float x, float y) +{ + setRadiusXBaseValue(x); + setRadiusYBaseValue(y); + invalidate(); +} + +void SVGFEMorphologyElement::parseMappedAttribute(Attribute* attr) +{ + const String& value = attr->value(); + if (attr->name() == SVGNames::operatorAttr) { + if (value == "erode") + set_operatorBaseValue(FEMORPHOLOGY_OPERATOR_ERODE); + else if (value == "dilate") + set_operatorBaseValue(FEMORPHOLOGY_OPERATOR_DILATE); + } else if (attr->name() == SVGNames::inAttr) + setIn1BaseValue(value); + else if (attr->name() == SVGNames::radiusAttr) { + float x, y; + if (parseNumberOptionalNumber(value, x, y)) { + setRadiusXBaseValue(x); + setRadiusYBaseValue(y); + } + } else + SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr); +} + +void SVGFEMorphologyElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName); + + if (attrName == SVGNames::inAttr + || attrName == SVGNames::operatorAttr + || attrName == SVGNames::radiusAttr) + invalidate(); +} + +void SVGFEMorphologyElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGFilterPrimitiveStandardAttributes::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronize_operator(); + synchronizeIn1(); + synchronizeRadiusX(); + synchronizeRadiusY(); + return; + } + + if (attrName == SVGNames::operatorAttr) + synchronize_operator(); + else if (attrName == SVGNames::inAttr) + synchronizeIn1(); + else if (attrName == SVGNames::radiusAttr) { + synchronizeRadiusX(); + synchronizeRadiusY(); + } +} + +PassRefPtr<FilterEffect> SVGFEMorphologyElement::build(SVGFilterBuilder* filterBuilder, Filter* filter) +{ + FilterEffect* input1 = filterBuilder->getEffectById(in1()); + float xRadius = radiusX(); + float yRadius = radiusY(); + + if (!input1) + return 0; + + if (xRadius < 0 || yRadius < 0) + return 0; + + RefPtr<FilterEffect> effect = FEMorphology::create(filter, static_cast<MorphologyOperatorType>(_operator()), xRadius, yRadius); + effect->inputEffects().append(input1); + return effect.release(); +} + +} // namespace WebCore + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGFEMorphologyElement.h b/Source/WebCore/svg/SVGFEMorphologyElement.h new file mode 100644 index 0000000..77190e6 --- /dev/null +++ b/Source/WebCore/svg/SVGFEMorphologyElement.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFEMorphologyElement_h +#define SVGFEMorphologyElement_h + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "FEMorphology.h" +#include "SVGAnimatedEnumeration.h" +#include "SVGAnimatedNumber.h" +#include "SVGFilterPrimitiveStandardAttributes.h" + +namespace WebCore { + +class SVGFEMorphologyElement : public SVGFilterPrimitiveStandardAttributes { +public: + static PassRefPtr<SVGFEMorphologyElement> create(const QualifiedName&, Document*); + + void setRadius(float radiusX, float radiusY); + +private: + SVGFEMorphologyElement(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + virtual PassRefPtr<FilterEffect> build(SVGFilterBuilder*, Filter*); + + static const AtomicString& radiusXIdentifier(); + static const AtomicString& radiusYIdentifier(); + + // Animated property declarations + DECLARE_ANIMATED_STRING(In1, in1) + DECLARE_ANIMATED_ENUMERATION(_operator, _operator) + DECLARE_ANIMATED_NUMBER(RadiusX, radiusX) + DECLARE_ANIMATED_NUMBER(RadiusY, radiusY) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGFEMorphologyElement.idl b/Source/WebCore/svg/SVGFEMorphologyElement.idl new file mode 100644 index 0000000..36746c1 --- /dev/null +++ b/Source/WebCore/svg/SVGFEMorphologyElement.idl @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> + * + * 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 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 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. + */ + +module svg { + + interface [ + Conditional=SVG&FILTERS, + DontCheckEnums + ] SVGFEMorphologyElement : SVGElement, + SVGFilterPrimitiveStandardAttributes { + // Morphology Operators + const unsigned short SVG_MORPHOLOGY_OPERATOR_UNKNOWN = 0; + const unsigned short SVG_MORPHOLOGY_OPERATOR_ERODE = 1; + const unsigned short SVG_MORPHOLOGY_OPERATOR_DILATE = 2; + + readonly attribute SVGAnimatedString in1; + readonly attribute SVGAnimatedEnumeration operator; + readonly attribute SVGAnimatedNumber radiusX; + readonly attribute SVGAnimatedNumber radiusY; + + void setRadius(in float radiusX, in float radiusY); + }; + +} diff --git a/Source/WebCore/svg/SVGFEOffsetElement.cpp b/Source/WebCore/svg/SVGFEOffsetElement.cpp new file mode 100644 index 0000000..d41e6db --- /dev/null +++ b/Source/WebCore/svg/SVGFEOffsetElement.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFEOffsetElement.h" + +#include "Attribute.h" +#include "SVGNames.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_STRING(SVGFEOffsetElement, SVGNames::inAttr, In1, in1) +DEFINE_ANIMATED_NUMBER(SVGFEOffsetElement, SVGNames::dxAttr, Dx, dx) +DEFINE_ANIMATED_NUMBER(SVGFEOffsetElement, SVGNames::dyAttr, Dy, dy) + +inline SVGFEOffsetElement::SVGFEOffsetElement(const QualifiedName& tagName, Document* document) + : SVGFilterPrimitiveStandardAttributes(tagName, document) +{ +} + +PassRefPtr<SVGFEOffsetElement> SVGFEOffsetElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGFEOffsetElement(tagName, document)); +} + +void SVGFEOffsetElement::parseMappedAttribute(Attribute* attr) +{ + const String& value = attr->value(); + if (attr->name() == SVGNames::dxAttr) + setDxBaseValue(value.toFloat()); + else if (attr->name() == SVGNames::dyAttr) + setDyBaseValue(value.toFloat()); + else if (attr->name() == SVGNames::inAttr) + setIn1BaseValue(value); + else + SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr); +} + +void SVGFEOffsetElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName); + + if (attrName == SVGNames::inAttr + || attrName == SVGNames::dxAttr + || attrName == SVGNames::dyAttr) + invalidate(); +} + +void SVGFEOffsetElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGFilterPrimitiveStandardAttributes::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeDx(); + synchronizeDy(); + synchronizeIn1(); + return; + } + + if (attrName == SVGNames::dxAttr) + synchronizeDx(); + else if (attrName == SVGNames::dyAttr) + synchronizeDy(); + else if (attrName == SVGNames::inAttr) + synchronizeIn1(); +} + +PassRefPtr<FilterEffect> SVGFEOffsetElement::build(SVGFilterBuilder* filterBuilder, Filter* filter) +{ + FilterEffect* input1 = filterBuilder->getEffectById(in1()); + + if (!input1) + return 0; + + RefPtr<FilterEffect> effect = FEOffset::create(filter, dx(), dy()); + effect->inputEffects().append(input1); + return effect.release(); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGFEOffsetElement.h b/Source/WebCore/svg/SVGFEOffsetElement.h new file mode 100644 index 0000000..2092df2 --- /dev/null +++ b/Source/WebCore/svg/SVGFEOffsetElement.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFEOffsetElement_h +#define SVGFEOffsetElement_h + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "FEOffset.h" +#include "SVGAnimatedNumber.h" +#include "SVGFilterPrimitiveStandardAttributes.h" + +namespace WebCore { + +class SVGFEOffsetElement : public SVGFilterPrimitiveStandardAttributes { +public: + static PassRefPtr<SVGFEOffsetElement> create(const QualifiedName&, Document*); + +private: + SVGFEOffsetElement(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + virtual PassRefPtr<FilterEffect> build(SVGFilterBuilder*, Filter*); + + // Animated property declarations + DECLARE_ANIMATED_STRING(In1, in1) + DECLARE_ANIMATED_NUMBER(Dx, dx) + DECLARE_ANIMATED_NUMBER(Dy, dy) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGFEOffsetElement.idl b/Source/WebCore/svg/SVGFEOffsetElement.idl new file mode 100644 index 0000000..9308573 --- /dev/null +++ b/Source/WebCore/svg/SVGFEOffsetElement.idl @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG&FILTERS] SVGFEOffsetElement : SVGElement, + SVGFilterPrimitiveStandardAttributes { + readonly attribute SVGAnimatedString in1; + readonly attribute SVGAnimatedNumber dx; + readonly attribute SVGAnimatedNumber dy; + }; + +} diff --git a/Source/WebCore/svg/SVGFEPointLightElement.cpp b/Source/WebCore/svg/SVGFEPointLightElement.cpp new file mode 100644 index 0000000..666b744 --- /dev/null +++ b/Source/WebCore/svg/SVGFEPointLightElement.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2005 Oliver Hunt <ojh16@student.canterbury.ac.nz> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFEPointLightElement.h" + +#include "PointLightSource.h" + +namespace WebCore { + +inline SVGFEPointLightElement::SVGFEPointLightElement(const QualifiedName& tagName, Document* document) + : SVGFELightElement(tagName, document) +{ +} + +PassRefPtr<SVGFEPointLightElement> SVGFEPointLightElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGFEPointLightElement(tagName, document)); +} + +PassRefPtr<LightSource> SVGFEPointLightElement::lightSource() const +{ + return PointLightSource::create(FloatPoint3D(x(), y(), z())); +} + +} + +#endif // ENABLE(SVG) + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGFEPointLightElement.h b/Source/WebCore/svg/SVGFEPointLightElement.h new file mode 100644 index 0000000..a3f47e8 --- /dev/null +++ b/Source/WebCore/svg/SVGFEPointLightElement.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2005 Oliver Hunt <ojh16@student.canterbury.ac.nz> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFEPointLightElement_h +#define SVGFEPointLightElement_h + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFELightElement.h" + +namespace WebCore { + +class SVGFEPointLightElement : public SVGFELightElement { +public: + static PassRefPtr<SVGFEPointLightElement> create(const QualifiedName&, Document*); + +private: + SVGFEPointLightElement(const QualifiedName&, Document*); + + virtual PassRefPtr<LightSource> lightSource() const; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGFEPointLightElement.idl b/Source/WebCore/svg/SVGFEPointLightElement.idl new file mode 100644 index 0000000..09e0b56 --- /dev/null +++ b/Source/WebCore/svg/SVGFEPointLightElement.idl @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG&FILTERS] SVGFEPointLightElement : SVGElement { + readonly attribute SVGAnimatedNumber x; + readonly attribute SVGAnimatedNumber y; + readonly attribute SVGAnimatedNumber z; + }; + +} diff --git a/Source/WebCore/svg/SVGFESpecularLightingElement.cpp b/Source/WebCore/svg/SVGFESpecularLightingElement.cpp new file mode 100644 index 0000000..806d0cd --- /dev/null +++ b/Source/WebCore/svg/SVGFESpecularLightingElement.cpp @@ -0,0 +1,151 @@ +/* + * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * Copyright (C) 2005 Oliver Hunt <oliver@nerget.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFESpecularLightingElement.h" + +#include "Attribute.h" +#include "RenderStyle.h" +#include "SVGColor.h" +#include "SVGFELightElement.h" +#include "SVGNames.h" +#include "SVGParserUtilities.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_STRING(SVGFESpecularLightingElement, SVGNames::inAttr, In1, in1) +DEFINE_ANIMATED_NUMBER(SVGFESpecularLightingElement, SVGNames::specularConstantAttr, SpecularConstant, specularConstant) +DEFINE_ANIMATED_NUMBER(SVGFESpecularLightingElement, SVGNames::specularExponentAttr, SpecularExponent, specularExponent) +DEFINE_ANIMATED_NUMBER(SVGFESpecularLightingElement, SVGNames::surfaceScaleAttr, SurfaceScale, surfaceScale) +DEFINE_ANIMATED_NUMBER_MULTIPLE_WRAPPERS(SVGFESpecularLightingElement, SVGNames::kernelUnitLengthAttr, kernelUnitLengthXIdentifier(), KernelUnitLengthX, kernelUnitLengthX) +DEFINE_ANIMATED_NUMBER_MULTIPLE_WRAPPERS(SVGFESpecularLightingElement, SVGNames::kernelUnitLengthAttr, kernelUnitLengthYIdentifier(), KernelUnitLengthY, kernelUnitLengthY) + +inline SVGFESpecularLightingElement::SVGFESpecularLightingElement(const QualifiedName& tagName, Document* document) + : SVGFilterPrimitiveStandardAttributes(tagName, document) + , m_specularConstant(1) + , m_specularExponent(1) + , m_surfaceScale(1) +{ +} + +PassRefPtr<SVGFESpecularLightingElement> SVGFESpecularLightingElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGFESpecularLightingElement(tagName, document)); +} + +const AtomicString& SVGFESpecularLightingElement::kernelUnitLengthXIdentifier() +{ + DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGKernelUnitLengthX")); + return s_identifier; +} + +const AtomicString& SVGFESpecularLightingElement::kernelUnitLengthYIdentifier() +{ + DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGKernelUnitLengthY")); + return s_identifier; +} + +void SVGFESpecularLightingElement::parseMappedAttribute(Attribute* attr) +{ + const String& value = attr->value(); + if (attr->name() == SVGNames::inAttr) + setIn1BaseValue(value); + else if (attr->name() == SVGNames::surfaceScaleAttr) + setSurfaceScaleBaseValue(value.toFloat()); + else if (attr->name() == SVGNames::specularConstantAttr) + setSpecularConstantBaseValue(value.toFloat()); + else if (attr->name() == SVGNames::specularExponentAttr) + setSpecularExponentBaseValue(value.toFloat()); + else if (attr->name() == SVGNames::kernelUnitLengthAttr) { + float x, y; + if (parseNumberOptionalNumber(value, x, y)) { + setKernelUnitLengthXBaseValue(x); + setKernelUnitLengthYBaseValue(y); + } + } else + SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr); +} + +void SVGFESpecularLightingElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGFilterPrimitiveStandardAttributes::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeIn1(); + synchronizeSurfaceScale(); + synchronizeSpecularConstant(); + synchronizeSpecularExponent(); + synchronizeKernelUnitLengthX(); + synchronizeKernelUnitLengthY(); + return; + } + + if (attrName == SVGNames::inAttr) + synchronizeIn1(); + else if (attrName == SVGNames::surfaceScaleAttr) + synchronizeSurfaceScale(); + else if (attrName == SVGNames::specularConstantAttr) + synchronizeSpecularConstant(); + else if (attrName == SVGNames::specularExponentAttr) + synchronizeSpecularExponent(); + else if (attrName == SVGNames::kernelUnitLengthAttr) { + synchronizeKernelUnitLengthX(); + synchronizeKernelUnitLengthY(); + } +} + +PassRefPtr<LightSource> SVGFESpecularLightingElement::findLights() const +{ + for (Node* node = firstChild(); node; node = node->nextSibling()) { + if (node->hasTagName(SVGNames::feDistantLightTag) + || node->hasTagName(SVGNames::fePointLightTag) + || node->hasTagName(SVGNames::feSpotLightTag)) { + SVGFELightElement* lightNode = static_cast<SVGFELightElement*>(node); + return lightNode->lightSource(); + } + } + + return 0; +} + +PassRefPtr<FilterEffect> SVGFESpecularLightingElement::build(SVGFilterBuilder* filterBuilder, Filter* filter) +{ + FilterEffect* input1 = filterBuilder->getEffectById(in1()); + + if (!input1) + return 0; + + RefPtr<RenderStyle> filterStyle = styleForRenderer(); + + Color color = filterStyle->svgStyle()->lightingColor(); + + RefPtr<FilterEffect> effect = FESpecularLighting::create(filter, color, surfaceScale(), specularConstant(), + specularExponent(), kernelUnitLengthX(), kernelUnitLengthY(), findLights()); + effect->inputEffects().append(input1); + return effect.release(); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGFESpecularLightingElement.h b/Source/WebCore/svg/SVGFESpecularLightingElement.h new file mode 100644 index 0000000..ace3a3e --- /dev/null +++ b/Source/WebCore/svg/SVGFESpecularLightingElement.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * Copyright (C) 2005 Oliver Hunt <oliver@nerget.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFESpecularLightingElement_h +#define SVGFESpecularLightingElement_h + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "FESpecularLighting.h" +#include "SVGAnimatedNumber.h" +#include "SVGFilterPrimitiveStandardAttributes.h" + +namespace WebCore { + +class SVGFESpecularLightingElement : public SVGFilterPrimitiveStandardAttributes { +public: + static PassRefPtr<SVGFESpecularLightingElement> create(const QualifiedName&, Document*); + +private: + SVGFESpecularLightingElement(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + virtual void synchronizeProperty(const QualifiedName&); + virtual PassRefPtr<FilterEffect> build(SVGFilterBuilder*, Filter*); + + static const AtomicString& kernelUnitLengthXIdentifier(); + static const AtomicString& kernelUnitLengthYIdentifier(); + + // Animated property declarations + DECLARE_ANIMATED_STRING(In1, in1) + DECLARE_ANIMATED_NUMBER(SpecularConstant, specularConstant) + DECLARE_ANIMATED_NUMBER(SpecularExponent, specularExponent) + DECLARE_ANIMATED_NUMBER(SurfaceScale, surfaceScale) + DECLARE_ANIMATED_NUMBER(KernelUnitLengthX, kernelUnitLengthX) + DECLARE_ANIMATED_NUMBER(KernelUnitLengthY, kernelUnitLengthY) + + PassRefPtr<LightSource> findLights() const; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGFESpecularLightingElement.idl b/Source/WebCore/svg/SVGFESpecularLightingElement.idl new file mode 100644 index 0000000..fa7da96 --- /dev/null +++ b/Source/WebCore/svg/SVGFESpecularLightingElement.idl @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG&FILTERS] SVGFESpecularLightingElement : SVGElement, + SVGFilterPrimitiveStandardAttributes { + readonly attribute SVGAnimatedString in1; + readonly attribute SVGAnimatedNumber surfaceScale; + readonly attribute SVGAnimatedNumber specularConstant; + readonly attribute SVGAnimatedNumber specularExponent; + }; + +} diff --git a/Source/WebCore/svg/SVGFESpotLightElement.cpp b/Source/WebCore/svg/SVGFESpotLightElement.cpp new file mode 100644 index 0000000..528cb5c --- /dev/null +++ b/Source/WebCore/svg/SVGFESpotLightElement.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2005 Oliver Hunt <ojh16@student.canterbury.ac.nz> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFESpotLightElement.h" + +#include "SpotLightSource.h" + +namespace WebCore { + +inline SVGFESpotLightElement::SVGFESpotLightElement(const QualifiedName& tagName, Document* document) + : SVGFELightElement(tagName, document) +{ +} + +PassRefPtr<SVGFESpotLightElement> SVGFESpotLightElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGFESpotLightElement(tagName, document)); +} + +PassRefPtr<LightSource> SVGFESpotLightElement::lightSource() const +{ + FloatPoint3D pos(x(), y(), z()); + FloatPoint3D direction(pointsAtX(), pointsAtY(), pointsAtZ()); + + return SpotLightSource::create(pos, direction, specularExponent(), limitingConeAngle()); +} + +} + +#endif // ENABLE(SVG) + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGFESpotLightElement.h b/Source/WebCore/svg/SVGFESpotLightElement.h new file mode 100644 index 0000000..fe1e73e --- /dev/null +++ b/Source/WebCore/svg/SVGFESpotLightElement.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2005 Oliver Hunt <ojh16@student.canterbury.ac.nz> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFESpotLightElement_h +#define SVGFESpotLightElement_h + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFELightElement.h" + +namespace WebCore { + +class SVGFESpotLightElement : public SVGFELightElement { +public: + static PassRefPtr<SVGFESpotLightElement> create(const QualifiedName&, Document*); + +private: + SVGFESpotLightElement(const QualifiedName&, Document*); + + virtual PassRefPtr<LightSource> lightSource() const; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGFESpotLightElement.idl b/Source/WebCore/svg/SVGFESpotLightElement.idl new file mode 100644 index 0000000..1c553a7 --- /dev/null +++ b/Source/WebCore/svg/SVGFESpotLightElement.idl @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG&FILTERS] SVGFESpotLightElement : SVGElement { + readonly attribute SVGAnimatedNumber x; + readonly attribute SVGAnimatedNumber y; + readonly attribute SVGAnimatedNumber z; + readonly attribute SVGAnimatedNumber pointsAtX; + readonly attribute SVGAnimatedNumber pointsAtY; + readonly attribute SVGAnimatedNumber pointsAtZ; + readonly attribute SVGAnimatedNumber specularExponent; + readonly attribute SVGAnimatedNumber limitingConeAngle; + }; + +} diff --git a/Source/WebCore/svg/SVGFETileElement.cpp b/Source/WebCore/svg/SVGFETileElement.cpp new file mode 100644 index 0000000..e981482 --- /dev/null +++ b/Source/WebCore/svg/SVGFETileElement.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFETileElement.h" + +#include "Attribute.h" +#include "SVGNames.h" +#include "SVGRenderStyle.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_STRING(SVGFETileElement, SVGNames::inAttr, In1, in1) + +inline SVGFETileElement::SVGFETileElement(const QualifiedName& tagName, Document* document) + : SVGFilterPrimitiveStandardAttributes(tagName, document) +{ +} + +PassRefPtr<SVGFETileElement> SVGFETileElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGFETileElement(tagName, document)); +} + +void SVGFETileElement::parseMappedAttribute(Attribute* attr) +{ + const String& value = attr->value(); + if (attr->name() == SVGNames::inAttr) + setIn1BaseValue(value); + else + SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr); +} + +void SVGFETileElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName); + + if (attrName == SVGNames::inAttr) + invalidate(); +} + +void SVGFETileElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGFilterPrimitiveStandardAttributes::synchronizeProperty(attrName); + + if (attrName == anyQName() || attrName == SVGNames::inAttr) + synchronizeIn1(); +} + +PassRefPtr<FilterEffect> SVGFETileElement::build(SVGFilterBuilder* filterBuilder, Filter* filter) +{ + FilterEffect* input1 = filterBuilder->getEffectById(in1()); + + if (!input1) + return 0; + + RefPtr<FilterEffect> effect = FETile::create(filter); + effect->inputEffects().append(input1); + return effect.release(); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGFETileElement.h b/Source/WebCore/svg/SVGFETileElement.h new file mode 100644 index 0000000..f47d355 --- /dev/null +++ b/Source/WebCore/svg/SVGFETileElement.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFETileElement_h +#define SVGFETileElement_h + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "FETile.h" +#include "SVGFilterPrimitiveStandardAttributes.h" + +namespace WebCore { + +class SVGFETileElement : public SVGFilterPrimitiveStandardAttributes { +public: + static PassRefPtr<SVGFETileElement> create(const QualifiedName&, Document*); + +private: + SVGFETileElement(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + virtual PassRefPtr<FilterEffect> build(SVGFilterBuilder*, Filter*); + + // Animated property declarations + DECLARE_ANIMATED_STRING(In1, in1) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGFETileElement.idl b/Source/WebCore/svg/SVGFETileElement.idl new file mode 100644 index 0000000..8d54991 --- /dev/null +++ b/Source/WebCore/svg/SVGFETileElement.idl @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG&FILTERS] SVGFETileElement : SVGElement, + SVGFilterPrimitiveStandardAttributes { + readonly attribute SVGAnimatedString in1; + }; + +} diff --git a/Source/WebCore/svg/SVGFETurbulenceElement.cpp b/Source/WebCore/svg/SVGFETurbulenceElement.cpp new file mode 100644 index 0000000..0f59bf7 --- /dev/null +++ b/Source/WebCore/svg/SVGFETurbulenceElement.cpp @@ -0,0 +1,142 @@ +/* + * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFETurbulenceElement.h" + +#include "Attribute.h" +#include "SVGNames.h" +#include "SVGParserUtilities.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_NUMBER_MULTIPLE_WRAPPERS(SVGFETurbulenceElement, SVGNames::baseFrequencyAttr, baseFrequencyXIdentifier(), BaseFrequencyX, baseFrequencyX) +DEFINE_ANIMATED_NUMBER_MULTIPLE_WRAPPERS(SVGFETurbulenceElement, SVGNames::baseFrequencyAttr, baseFrequencyYIdentifier(), BaseFrequencyY, baseFrequencyY) +DEFINE_ANIMATED_INTEGER(SVGFETurbulenceElement, SVGNames::numOctavesAttr, NumOctaves, numOctaves) +DEFINE_ANIMATED_NUMBER(SVGFETurbulenceElement, SVGNames::seedAttr, Seed, seed) +DEFINE_ANIMATED_ENUMERATION(SVGFETurbulenceElement, SVGNames::stitchTilesAttr, StitchTiles, stitchTiles) +DEFINE_ANIMATED_ENUMERATION(SVGFETurbulenceElement, SVGNames::typeAttr, Type, type) + +inline SVGFETurbulenceElement::SVGFETurbulenceElement(const QualifiedName& tagName, Document* document) + : SVGFilterPrimitiveStandardAttributes(tagName, document) + , m_numOctaves(1) + , m_stitchTiles(SVG_STITCHTYPE_NOSTITCH) + , m_type(FETURBULENCE_TYPE_TURBULENCE) +{ +} + +PassRefPtr<SVGFETurbulenceElement> SVGFETurbulenceElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGFETurbulenceElement(tagName, document)); +} + +const AtomicString& SVGFETurbulenceElement::baseFrequencyXIdentifier() +{ + DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGBaseFrequencyX")); + return s_identifier; +} + +const AtomicString& SVGFETurbulenceElement::baseFrequencyYIdentifier() +{ + DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGBaseFrequencyY")); + return s_identifier; +} + +void SVGFETurbulenceElement::parseMappedAttribute(Attribute* attr) +{ + const String& value = attr->value(); + if (attr->name() == SVGNames::typeAttr) { + if (value == "fractalNoise") + setTypeBaseValue(FETURBULENCE_TYPE_FRACTALNOISE); + else if (value == "turbulence") + setTypeBaseValue(FETURBULENCE_TYPE_TURBULENCE); + } else if (attr->name() == SVGNames::stitchTilesAttr) { + if (value == "stitch") + setStitchTilesBaseValue(SVG_STITCHTYPE_STITCH); + else if (value == "noStitch") + setStitchTilesBaseValue(SVG_STITCHTYPE_NOSTITCH); + } else if (attr->name() == SVGNames::baseFrequencyAttr) { + float x, y; + if (parseNumberOptionalNumber(value, x, y)) { + setBaseFrequencyXBaseValue(x); + setBaseFrequencyYBaseValue(y); + } + } else if (attr->name() == SVGNames::seedAttr) + setSeedBaseValue(value.toFloat()); + else if (attr->name() == SVGNames::numOctavesAttr) + setNumOctavesBaseValue(value.toUIntStrict()); + else + SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr); +} + +void SVGFETurbulenceElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName); + + if (attrName == SVGNames::baseFrequencyAttr + || attrName == SVGNames::numOctavesAttr + || attrName == SVGNames::seedAttr + || attrName == SVGNames::stitchTilesAttr + || attrName == SVGNames::typeAttr) + invalidate(); +} + +void SVGFETurbulenceElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGFilterPrimitiveStandardAttributes::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeType(); + synchronizeStitchTiles(); + synchronizeBaseFrequencyX(); + synchronizeBaseFrequencyY(); + synchronizeSeed(); + synchronizeNumOctaves(); + return; + } + + if (attrName == SVGNames::typeAttr) + synchronizeType(); + else if (attrName == SVGNames::stitchTilesAttr) + synchronizeStitchTiles(); + else if (attrName == SVGNames::baseFrequencyAttr) { + synchronizeBaseFrequencyX(); + synchronizeBaseFrequencyY(); + } else if (attrName == SVGNames::seedAttr) + synchronizeSeed(); + else if (attrName == SVGNames::numOctavesAttr) + synchronizeNumOctaves(); +} + +PassRefPtr<FilterEffect> SVGFETurbulenceElement::build(SVGFilterBuilder*, Filter* filter) +{ + if (baseFrequencyX() < 0 || baseFrequencyY() < 0) + return 0; + + return FETurbulence::create(filter, static_cast<TurbulanceType>(type()), baseFrequencyX(), + baseFrequencyY(), numOctaves(), seed(), stitchTiles() == SVG_STITCHTYPE_STITCH); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGFETurbulenceElement.h b/Source/WebCore/svg/SVGFETurbulenceElement.h new file mode 100644 index 0000000..5e436f4 --- /dev/null +++ b/Source/WebCore/svg/SVGFETurbulenceElement.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFETurbulenceElement_h +#define SVGFETurbulenceElement_h + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "FETurbulence.h" +#include "SVGAnimatedEnumeration.h" +#include "SVGAnimatedNumber.h" +#include "SVGFilterPrimitiveStandardAttributes.h" + +namespace WebCore { + +enum SVGStitchOptions { + SVG_STITCHTYPE_UNKNOWN = 0, + SVG_STITCHTYPE_STITCH = 1, + SVG_STITCHTYPE_NOSTITCH = 2 +}; + +class SVGFETurbulenceElement : public SVGFilterPrimitiveStandardAttributes { +public: + static PassRefPtr<SVGFETurbulenceElement> create(const QualifiedName&, Document*); + +private: + SVGFETurbulenceElement(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + virtual PassRefPtr<FilterEffect> build(SVGFilterBuilder*, Filter*); + + static const AtomicString& baseFrequencyXIdentifier(); + static const AtomicString& baseFrequencyYIdentifier(); + + // Animated property declarations + DECLARE_ANIMATED_NUMBER(BaseFrequencyX, baseFrequencyX) + DECLARE_ANIMATED_NUMBER(BaseFrequencyY, baseFrequencyY) + DECLARE_ANIMATED_INTEGER(NumOctaves, numOctaves) + DECLARE_ANIMATED_NUMBER(Seed, seed) + DECLARE_ANIMATED_ENUMERATION(StitchTiles, stitchTiles) + DECLARE_ANIMATED_ENUMERATION(Type, type) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGFETurbulenceElement.idl b/Source/WebCore/svg/SVGFETurbulenceElement.idl new file mode 100644 index 0000000..bd538bd --- /dev/null +++ b/Source/WebCore/svg/SVGFETurbulenceElement.idl @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [ + Conditional=SVG&FILTERS, + DontCheckEnums + ] SVGFETurbulenceElement : SVGElement, + SVGFilterPrimitiveStandardAttributes { + // Turbulence Types + const unsigned short SVG_TURBULENCE_TYPE_UNKNOWN = 0; + const unsigned short SVG_TURBULENCE_TYPE_FRACTALNOISE = 1; + const unsigned short SVG_TURBULENCE_TYPE_TURBULENCE = 2; + + // Stitch Options + const unsigned short SVG_STITCHTYPE_UNKNOWN = 0; + const unsigned short SVG_STITCHTYPE_STITCH = 1; + const unsigned short SVG_STITCHTYPE_NOSTITCH = 2; + + readonly attribute SVGAnimatedNumber baseFrequencyX; + readonly attribute SVGAnimatedNumber baseFrequencyY; + readonly attribute SVGAnimatedInteger numOctaves; + readonly attribute SVGAnimatedNumber seed; + readonly attribute SVGAnimatedEnumeration stitchTiles; + readonly attribute SVGAnimatedEnumeration type; + }; + +} diff --git a/Source/WebCore/svg/SVGFilterElement.cpp b/Source/WebCore/svg/SVGFilterElement.cpp new file mode 100644 index 0000000..03ff7fa --- /dev/null +++ b/Source/WebCore/svg/SVGFilterElement.cpp @@ -0,0 +1,242 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFilterElement.h" + +#include "Attr.h" +#include "RenderSVGResourceFilter.h" +#include "SVGFilterBuilder.h" +#include "SVGFilterPrimitiveStandardAttributes.h" +#include "SVGNames.h" +#include "SVGParserUtilities.h" +#include "SVGUnitTypes.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_ENUMERATION(SVGFilterElement, SVGNames::filterUnitsAttr, FilterUnits, filterUnits) +DEFINE_ANIMATED_ENUMERATION(SVGFilterElement, SVGNames::primitiveUnitsAttr, PrimitiveUnits, primitiveUnits) +DEFINE_ANIMATED_LENGTH(SVGFilterElement, SVGNames::xAttr, X, x) +DEFINE_ANIMATED_LENGTH(SVGFilterElement, SVGNames::yAttr, Y, y) +DEFINE_ANIMATED_LENGTH(SVGFilterElement, SVGNames::widthAttr, Width, width) +DEFINE_ANIMATED_LENGTH(SVGFilterElement, SVGNames::heightAttr, Height, height) +DEFINE_ANIMATED_INTEGER_MULTIPLE_WRAPPERS(SVGFilterElement, SVGNames::filterResAttr, filterResXIdentifier(), FilterResX, filterResX) +DEFINE_ANIMATED_INTEGER_MULTIPLE_WRAPPERS(SVGFilterElement, SVGNames::filterResAttr, filterResYIdentifier(), FilterResY, filterResY) +DEFINE_ANIMATED_STRING(SVGFilterElement, XLinkNames::hrefAttr, Href, href) +DEFINE_ANIMATED_BOOLEAN(SVGFilterElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) + +inline SVGFilterElement::SVGFilterElement(const QualifiedName& tagName, Document* document) + : SVGStyledElement(tagName, document) + , SVGURIReference() + , SVGLangSpace() + , SVGExternalResourcesRequired() + , m_filterUnits(SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) + , m_primitiveUnits(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE) + , m_x(LengthModeWidth, "-10%") + , m_y(LengthModeHeight, "-10%") + , m_width(LengthModeWidth, "120%") + , m_height(LengthModeHeight, "120%") +{ + // Spec: If the x/y attribute is not specified, the effect is as if a value of "-10%" were specified. + // Spec: If the width/height attribute is not specified, the effect is as if a value of "120%" were specified. +} + +PassRefPtr<SVGFilterElement> SVGFilterElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGFilterElement(tagName, document)); +} + +const AtomicString& SVGFilterElement::filterResXIdentifier() +{ + DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGFilterResX")); + return s_identifier; +} + +const AtomicString& SVGFilterElement::filterResYIdentifier() +{ + DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGFilterResY")); + return s_identifier; +} + +void SVGFilterElement::setFilterRes(unsigned long filterResX, unsigned long filterResY) +{ + setFilterResXBaseValue(filterResX); + setFilterResYBaseValue(filterResY); + + if (RenderObject* object = renderer()) + object->setNeedsLayout(true); +} + +void SVGFilterElement::parseMappedAttribute(Attribute* attr) +{ + const String& value = attr->value(); + if (attr->name() == SVGNames::filterUnitsAttr) { + if (value == "userSpaceOnUse") + setFilterUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE); + else if (value == "objectBoundingBox") + setFilterUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX); + } else if (attr->name() == SVGNames::primitiveUnitsAttr) { + if (value == "userSpaceOnUse") + setPrimitiveUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE); + else if (value == "objectBoundingBox") + setPrimitiveUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX); + } else if (attr->name() == SVGNames::xAttr) + setXBaseValue(SVGLength(LengthModeWidth, value)); + else if (attr->name() == SVGNames::yAttr) + setYBaseValue(SVGLength(LengthModeHeight, value)); + else if (attr->name() == SVGNames::widthAttr) + setWidthBaseValue(SVGLength(LengthModeWidth, value)); + else if (attr->name() == SVGNames::heightAttr) + setHeightBaseValue(SVGLength(LengthModeHeight, value)); + else if (attr->name() == SVGNames::filterResAttr) { + float x, y; + if (parseNumberOptionalNumber(value, x, y)) { + setFilterResXBaseValue(x); + setFilterResYBaseValue(y); + } + } else { + if (SVGURIReference::parseMappedAttribute(attr)) + return; + if (SVGLangSpace::parseMappedAttribute(attr)) + return; + if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) + return; + + SVGStyledElement::parseMappedAttribute(attr); + } +} + +void SVGFilterElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGStyledElement::svgAttributeChanged(attrName); + + bool invalidateClients = false; + if (attrName == SVGNames::xAttr + || attrName == SVGNames::yAttr + || attrName == SVGNames::widthAttr + || attrName == SVGNames::heightAttr) { + invalidateClients = true; + updateRelativeLengthsInformation(); + } + + RenderObject* object = renderer(); + if (!object) + return; + + if (invalidateClients + || attrName == SVGNames::filterUnitsAttr + || attrName == SVGNames::primitiveUnitsAttr + || attrName == SVGNames::filterResAttr + || SVGStyledElement::isKnownAttribute(attrName) + || SVGURIReference::isKnownAttribute(attrName) + || SVGLangSpace::isKnownAttribute(attrName) + || SVGExternalResourcesRequired::isKnownAttribute(attrName)) + object->setNeedsLayout(true); +} + +void SVGFilterElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGStyledElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeX(); + synchronizeY(); + synchronizeWidth(); + synchronizeHeight(); + synchronizeFilterUnits(); + synchronizePrimitiveUnits(); + synchronizeFilterResX(); + synchronizeFilterResY(); + synchronizeExternalResourcesRequired(); + synchronizeHref(); + return; + } + + if (attrName == SVGNames::xAttr) + synchronizeX(); + else if (attrName == SVGNames::yAttr) + synchronizeY(); + else if (attrName == SVGNames::widthAttr) + synchronizeWidth(); + else if (attrName == SVGNames::heightAttr) + synchronizeHeight(); + else if (attrName == SVGNames::filterUnitsAttr) + synchronizeFilterUnits(); + else if (attrName == SVGNames::primitiveUnitsAttr) + synchronizePrimitiveUnits(); + else if (attrName == SVGNames::filterResAttr) { + synchronizeFilterResX(); + synchronizeFilterResY(); + } else if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) + synchronizeExternalResourcesRequired(); + else if (SVGURIReference::isKnownAttribute(attrName)) + synchronizeHref(); +} + +void SVGFilterElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) +{ + SVGStyledElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); + + if (changedByParser) + return; + + if (RenderObject* object = renderer()) + object->setNeedsLayout(true); +} + +FloatRect SVGFilterElement::filterBoundingBox(const FloatRect& objectBoundingBox) const +{ + FloatRect filterBBox; + if (filterUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) + filterBBox = FloatRect(x().valueAsPercentage() * objectBoundingBox.width() + objectBoundingBox.x(), + y().valueAsPercentage() * objectBoundingBox.height() + objectBoundingBox.y(), + width().valueAsPercentage() * objectBoundingBox.width(), + height().valueAsPercentage() * objectBoundingBox.height()); + else + filterBBox = FloatRect(x().value(this), + y().value(this), + width().value(this), + height().value(this)); + + return filterBBox; +} + +RenderObject* SVGFilterElement::createRenderer(RenderArena* arena, RenderStyle*) +{ + return new (arena) RenderSVGResourceFilter(this); +} + +bool SVGFilterElement::selfHasRelativeLengths() const +{ + return x().isRelative() + || y().isRelative() + || width().isRelative() + || height().isRelative(); +} + +} + +#endif diff --git a/Source/WebCore/svg/SVGFilterElement.h b/Source/WebCore/svg/SVGFilterElement.h new file mode 100644 index 0000000..a438625 --- /dev/null +++ b/Source/WebCore/svg/SVGFilterElement.h @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFilterElement_h +#define SVGFilterElement_h + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGAnimatedBoolean.h" +#include "SVGAnimatedEnumeration.h" +#include "SVGAnimatedInteger.h" +#include "SVGAnimatedLength.h" +#include "SVGExternalResourcesRequired.h" +#include "SVGLangSpace.h" +#include "SVGStyledElement.h" +#include "SVGURIReference.h" + +namespace WebCore { + +class SVGFilterElement : public SVGStyledElement, + public SVGURIReference, + public SVGLangSpace, + public SVGExternalResourcesRequired { +public: + static PassRefPtr<SVGFilterElement> create(const QualifiedName&, Document*); + + void setFilterRes(unsigned long filterResX, unsigned long filterResY); + FloatRect filterBoundingBox(const FloatRect&) const; + +private: + SVGFilterElement(const QualifiedName&, Document*); + + virtual bool needsPendingResourceHandling() const { return false; } + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); + + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + + virtual bool selfHasRelativeLengths() const; + + static const AtomicString& filterResXIdentifier(); + static const AtomicString& filterResYIdentifier(); + + // Animated property declarations + DECLARE_ANIMATED_ENUMERATION(FilterUnits, filterUnits) + DECLARE_ANIMATED_ENUMERATION(PrimitiveUnits, primitiveUnits) + DECLARE_ANIMATED_LENGTH(X, x) + DECLARE_ANIMATED_LENGTH(Y, y) + DECLARE_ANIMATED_LENGTH(Width, width) + DECLARE_ANIMATED_LENGTH(Height, height) + DECLARE_ANIMATED_INTEGER(FilterResX, filterResX) + DECLARE_ANIMATED_INTEGER(FilterResY, filterResY) + + // SVGURIReference + DECLARE_ANIMATED_STRING(Href, href) + + // SVGExternalResourcesRequired + DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) +}; + +} + +#endif +#endif diff --git a/Source/WebCore/svg/SVGFilterElement.idl b/Source/WebCore/svg/SVGFilterElement.idl new file mode 100644 index 0000000..1a74b7e --- /dev/null +++ b/Source/WebCore/svg/SVGFilterElement.idl @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2006 Apple Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * + * 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 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 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. + */ + +module svg { + + interface [Conditional=SVG&FILTERS] SVGFilterElement : SVGElement, + SVGURIReference, + SVGLangSpace, + SVGExternalResourcesRequired, + SVGStylable + /* SVGUnitTypes */ { + readonly attribute SVGAnimatedEnumeration filterUnits; + readonly attribute SVGAnimatedEnumeration primitiveUnits; + readonly attribute SVGAnimatedLength x; + readonly attribute SVGAnimatedLength y; + readonly attribute SVGAnimatedLength width; + readonly attribute SVGAnimatedLength height; + readonly attribute SVGAnimatedInteger filterResX; + readonly attribute SVGAnimatedInteger filterResY; + + void setFilterRes(in unsigned long filterResX, in unsigned long filterResY); + }; + +} diff --git a/Source/WebCore/svg/SVGFilterPrimitiveStandardAttributes.cpp b/Source/WebCore/svg/SVGFilterPrimitiveStandardAttributes.cpp new file mode 100644 index 0000000..bd717ea --- /dev/null +++ b/Source/WebCore/svg/SVGFilterPrimitiveStandardAttributes.cpp @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFilterPrimitiveStandardAttributes.h" + +#include "Attribute.h" +#include "FilterEffect.h" +#include "RenderSVGResourceFilterPrimitive.h" +#include "SVGLength.h" +#include "SVGNames.h" +#include "SVGStyledElement.h" +#include "SVGUnitTypes.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_LENGTH(SVGFilterPrimitiveStandardAttributes, SVGNames::xAttr, X, x) +DEFINE_ANIMATED_LENGTH(SVGFilterPrimitiveStandardAttributes, SVGNames::yAttr, Y, y) +DEFINE_ANIMATED_LENGTH(SVGFilterPrimitiveStandardAttributes, SVGNames::widthAttr, Width, width) +DEFINE_ANIMATED_LENGTH(SVGFilterPrimitiveStandardAttributes, SVGNames::heightAttr, Height, height) +DEFINE_ANIMATED_STRING(SVGFilterPrimitiveStandardAttributes, SVGNames::resultAttr, Result, result) + +SVGFilterPrimitiveStandardAttributes::SVGFilterPrimitiveStandardAttributes(const QualifiedName& tagName, Document* document) + : SVGStyledElement(tagName, document) + , m_x(LengthModeWidth, "0%") + , m_y(LengthModeHeight, "0%") + , m_width(LengthModeWidth, "100%") + , m_height(LengthModeHeight, "100%") +{ + // Spec: If the x/y attribute is not specified, the effect is as if a value of "0%" were specified. + // Spec: If the width/height attribute is not specified, the effect is as if a value of "100%" were specified. +} + +void SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(Attribute* attr) +{ + const AtomicString& value = attr->value(); + if (attr->name() == SVGNames::xAttr) + setXBaseValue(SVGLength(LengthModeWidth, value)); + else if (attr->name() == SVGNames::yAttr) + setYBaseValue(SVGLength(LengthModeHeight, value)); + else if (attr->name() == SVGNames::widthAttr) + setWidthBaseValue(SVGLength(LengthModeWidth, value)); + else if (attr->name() == SVGNames::heightAttr) + setHeightBaseValue(SVGLength(LengthModeHeight, value)); + else if (attr->name() == SVGNames::resultAttr) + setResultBaseValue(value); + else + return SVGStyledElement::parseMappedAttribute(attr); +} + +void SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGStyledElement::svgAttributeChanged(attrName); + + if (attrName == SVGNames::xAttr + || attrName == SVGNames::yAttr + || attrName == SVGNames::widthAttr + || attrName == SVGNames::heightAttr + || attrName == SVGNames::resultAttr) + invalidate(); +} + +void SVGFilterPrimitiveStandardAttributes::synchronizeProperty(const QualifiedName& attrName) +{ + SVGStyledElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeX(); + synchronizeY(); + synchronizeWidth(); + synchronizeHeight(); + synchronizeResult(); + return; + } + + if (attrName == SVGNames::xAttr) + synchronizeX(); + else if (attrName == SVGNames::yAttr) + synchronizeY(); + else if (attrName == SVGNames::widthAttr) + synchronizeWidth(); + else if (attrName == SVGNames::heightAttr) + synchronizeHeight(); + else if (attrName == SVGNames::resultAttr) + synchronizeResult(); +} + +void SVGFilterPrimitiveStandardAttributes::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) +{ + SVGStyledElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); + + if (!changedByParser) + invalidate(); +} + +void SVGFilterPrimitiveStandardAttributes::setStandardAttributes(bool primitiveBoundingBoxMode, FilterEffect* filterEffect) const +{ + ASSERT(filterEffect); + if (!filterEffect) + return; + + if (this->hasAttribute(SVGNames::xAttr)) + filterEffect->setHasX(true); + if (this->hasAttribute(SVGNames::yAttr)) + filterEffect->setHasY(true); + if (this->hasAttribute(SVGNames::widthAttr)) + filterEffect->setHasWidth(true); + if (this->hasAttribute(SVGNames::heightAttr)) + filterEffect->setHasHeight(true); + + FloatRect effectBBox; + if (primitiveBoundingBoxMode) + effectBBox = FloatRect(x().valueAsPercentage(), + y().valueAsPercentage(), + width().valueAsPercentage(), + height().valueAsPercentage()); + else + effectBBox = FloatRect(x().value(this), + y().value(this), + width().value(this), + height().value(this)); + + filterEffect->setEffectBoundaries(effectBBox); +} + +RenderObject* SVGFilterPrimitiveStandardAttributes::createRenderer(RenderArena* arena, RenderStyle*) +{ + return new (arena) RenderSVGResourceFilterPrimitive(this); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGFilterPrimitiveStandardAttributes.h b/Source/WebCore/svg/SVGFilterPrimitiveStandardAttributes.h new file mode 100644 index 0000000..b13084b --- /dev/null +++ b/Source/WebCore/svg/SVGFilterPrimitiveStandardAttributes.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFilterPrimitiveStandardAttributes_h +#define SVGFilterPrimitiveStandardAttributes_h + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "FilterEffect.h" +#include "RenderSVGResource.h" +#include "SVGAnimatedLength.h" +#include "SVGFilterBuilder.h" +#include "SVGFilterElement.h" +#include "SVGStyledElement.h" + +#include <wtf/PassRefPtr.h> +#include <wtf/RefPtr.h> + +namespace WebCore { + +class SVGFilterPrimitiveStandardAttributes : public SVGStyledElement { +public: + void setStandardAttributes(bool, FilterEffect*) const; + + virtual PassRefPtr<FilterEffect> build(SVGFilterBuilder*, Filter* filter) = 0; + +protected: + SVGFilterPrimitiveStandardAttributes(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); + +protected: + inline void invalidate() + { + if (RenderObject* primitiveRenderer = renderer()) + RenderSVGResource::markForLayoutAndParentResourceInvalidation(primitiveRenderer); + } + +private: + virtual bool isFilterEffect() const { return true; } + + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + + // Animated property declarations + DECLARE_ANIMATED_LENGTH(X, x) + DECLARE_ANIMATED_LENGTH(Y, y) + DECLARE_ANIMATED_LENGTH(Width, width) + DECLARE_ANIMATED_LENGTH(Height, height) + DECLARE_ANIMATED_STRING(Result, result) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGFilterPrimitiveStandardAttributes.idl b/Source/WebCore/svg/SVGFilterPrimitiveStandardAttributes.idl new file mode 100644 index 0000000..8e43f90 --- /dev/null +++ b/Source/WebCore/svg/SVGFilterPrimitiveStandardAttributes.idl @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG, ObjCProtocol] SVGFilterPrimitiveStandardAttributes : SVGStylable { + readonly attribute SVGAnimatedLength x; + readonly attribute SVGAnimatedLength y; + readonly attribute SVGAnimatedLength width; + readonly attribute SVGAnimatedLength height; + readonly attribute SVGAnimatedString result; + }; + +} diff --git a/Source/WebCore/svg/SVGFitToViewBox.cpp b/Source/WebCore/svg/SVGFitToViewBox.cpp new file mode 100644 index 0000000..fadb982 --- /dev/null +++ b/Source/WebCore/svg/SVGFitToViewBox.cpp @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007, 2010 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGFitToViewBox.h" + +#include "AffineTransform.h" +#include "Attr.h" +#include "Document.h" +#include "FloatRect.h" +#include "SVGDocumentExtensions.h" +#include "SVGNames.h" +#include "SVGParserUtilities.h" +#include "SVGPreserveAspectRatio.h" +#include <wtf/text/StringImpl.h> + +namespace WebCore { + +bool SVGFitToViewBox::parseViewBox(Document* doc, const String& s, FloatRect& viewBox) +{ + const UChar* c = s.characters(); + const UChar* end = c + s.length(); + return parseViewBox(doc, c, end, viewBox, true); +} + +bool SVGFitToViewBox::parseViewBox(Document* doc, const UChar*& c, const UChar* end, FloatRect& viewBox, bool validate) +{ + String str(c, end - c); + + skipOptionalSpaces(c, end); + + float x = 0.0f; + float y = 0.0f; + float width = 0.0f; + float height = 0.0f; + bool valid = parseNumber(c, end, x) && parseNumber(c, end, y) && parseNumber(c, end, width) && parseNumber(c, end, height, false); + if (!validate) { + viewBox = FloatRect(x, y, width, height); + return true; + } + if (!valid) { + doc->accessSVGExtensions()->reportWarning("Problem parsing viewBox=\"" + str + "\""); + return false; + } + + if (width < 0.0) { // check that width is positive + doc->accessSVGExtensions()->reportError("A negative value for ViewBox width is not allowed"); + return false; + } + if (height < 0.0) { // check that height is positive + doc->accessSVGExtensions()->reportError("A negative value for ViewBox height is not allowed"); + return false; + } + skipOptionalSpaces(c, end); + if (c < end) { // nothing should come after the last, fourth number + doc->accessSVGExtensions()->reportWarning("Problem parsing viewBox=\"" + str + "\""); + return false; + } + + viewBox = FloatRect(x, y, width, height); + return true; +} + +AffineTransform SVGFitToViewBox::viewBoxToViewTransform(const FloatRect& viewBoxRect, const SVGPreserveAspectRatio& preserveAspectRatio, float viewWidth, float viewHeight) +{ + if (!viewBoxRect.width() || !viewBoxRect.height()) + return AffineTransform(); + + return preserveAspectRatio.getCTM(viewBoxRect.x(), viewBoxRect.y(), viewBoxRect.width(), viewBoxRect.height(), viewWidth, viewHeight); +} + +bool SVGFitToViewBox::parseMappedAttribute(Document* document, Attribute* attr) +{ + if (attr->name() == SVGNames::viewBoxAttr) { + FloatRect viewBox; + if (!attr->value().isNull()) { + if (!parseViewBox(document, attr->value(), viewBox)) + return true; + } + setViewBoxBaseValue(viewBox); + } else if (attr->name() == SVGNames::preserveAspectRatioAttr) { + SVGPreserveAspectRatio::parsePreserveAspectRatio(this, attr->value()); + return true; + } + + return false; +} + +bool SVGFitToViewBox::isKnownAttribute(const QualifiedName& attrName) +{ + return attrName == SVGNames::viewBoxAttr || attrName == SVGNames::preserveAspectRatioAttr; +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGFitToViewBox.h b/Source/WebCore/svg/SVGFitToViewBox.h new file mode 100644 index 0000000..3d62271 --- /dev/null +++ b/Source/WebCore/svg/SVGFitToViewBox.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007, 2010 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFitToViewBox_h +#define SVGFitToViewBox_h + +#if ENABLE(SVG) +#include <wtf/text/WTFString.h> + +namespace WebCore { + +class AffineTransform; +class Attribute; +class Document; +class FloatRect; +class QualifiedName; +class SVGPreserveAspectRatio; + +class SVGFitToViewBox { +public: + virtual ~SVGFitToViewBox() { } + + bool parseViewBox(Document*, const UChar*& start, const UChar* end, FloatRect& viewBox, bool validate = true); + static AffineTransform viewBoxToViewTransform(const FloatRect& viewBoxRect, const SVGPreserveAspectRatio&, float viewWidth, float viewHeight); + + bool parseMappedAttribute(Document*, Attribute*); + bool isKnownAttribute(const QualifiedName&); + + virtual void setViewBoxBaseValue(const FloatRect&) = 0; + virtual void setPreserveAspectRatioBaseValue(const SVGPreserveAspectRatio&) = 0; + +private: + bool parseViewBox(Document*, const String&, FloatRect&); +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGFitToViewBox_h diff --git a/Source/WebCore/svg/SVGFitToViewBox.idl b/Source/WebCore/svg/SVGFitToViewBox.idl new file mode 100644 index 0000000..af6efda --- /dev/null +++ b/Source/WebCore/svg/SVGFitToViewBox.idl @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG, ObjCProtocol, OmitConstructor] SVGFitToViewBox { + readonly attribute SVGAnimatedRect viewBox; + readonly attribute SVGAnimatedPreserveAspectRatio preserveAspectRatio; + }; + +} diff --git a/Source/WebCore/svg/SVGFont.cpp b/Source/WebCore/svg/SVGFont.cpp new file mode 100644 index 0000000..dd99ac5 --- /dev/null +++ b/Source/WebCore/svg/SVGFont.cpp @@ -0,0 +1,590 @@ +/* + * Copyright (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG_FONTS) +#include "Font.h" + +#include "CSSFontSelector.h" +#include "GraphicsContext.h" +#include "RenderObject.h" +#include "RenderSVGResourceSolidColor.h" +#include "SVGAltGlyphElement.h" +#include "SVGFontData.h" +#include "SVGFontElement.h" +#include "SVGFontFaceElement.h" +#include "SVGGlyphElement.h" +#include "SVGGlyphMap.h" +#include "SVGMissingGlyphElement.h" +#include "SVGNames.h" +#include "SimpleFontData.h" +#include "XMLNames.h" + +using namespace WTF::Unicode; + +namespace WebCore { + +static inline float convertEmUnitToPixel(float fontSize, float unitsPerEm, float value) +{ + if (!unitsPerEm) + return 0.0f; + + return value * fontSize / unitsPerEm; +} + +static inline bool isVerticalWritingMode(const SVGRenderStyle* style) +{ + return style->writingMode() == WM_TBRL || style->writingMode() == WM_TB; +} + +// Helper functions to determine the arabic character forms (initial, medial, terminal, isolated) +enum ArabicCharShapingMode { + SNone = 0, + SRight = 1, + SDual = 2 +}; + +static const ArabicCharShapingMode s_arabicCharShapingMode[222] = { + SRight, SRight, SRight, SRight, SDual , SRight, SDual , SRight, SDual , SDual , SDual , SDual , SDual , SRight, /* 0x0622 - 0x062F */ + SRight, SRight, SRight, SDual , SDual , SDual , SDual , SDual , SDual , SDual , SDual , SNone , SNone , SNone , SNone , SNone , /* 0x0630 - 0x063F */ + SNone , SDual , SDual , SDual , SDual , SDual , SDual , SRight, SDual , SDual , SNone , SNone , SNone , SNone , SNone , SNone , /* 0x0640 - 0x064F */ + SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , /* 0x0650 - 0x065F */ + SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , /* 0x0660 - 0x066F */ + SNone , SRight, SRight, SRight, SNone , SRight, SRight, SRight, SDual , SDual , SDual , SDual , SDual , SDual , SDual , SDual , /* 0x0670 - 0x067F */ + SDual , SDual , SDual , SDual , SDual , SDual , SDual , SDual , SRight, SRight, SRight, SRight, SRight, SRight, SRight, SRight, /* 0x0680 - 0x068F */ + SRight, SRight, SRight, SRight, SRight, SRight, SRight, SRight, SRight, SRight, SDual , SDual , SDual , SDual , SDual , SDual , /* 0x0690 - 0x069F */ + SDual , SDual , SDual , SDual , SDual , SDual , SDual , SDual , SDual , SDual , SDual , SDual , SDual , SDual , SDual , SDual , /* 0x06A0 - 0x06AF */ + SDual , SDual , SDual , SDual , SDual , SDual , SDual , SDual , SDual , SDual , SDual , SDual , SDual , SDual , SDual , SDual , /* 0x06B0 - 0x06BF */ + SRight, SDual , SRight, SRight, SRight, SRight, SRight, SRight, SRight, SRight, SRight, SRight, SDual , SRight, SDual , SRight, /* 0x06C0 - 0x06CF */ + SDual , SDual , SRight, SRight, SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , /* 0x06D0 - 0x06DF */ + SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , /* 0x06E0 - 0x06EF */ + SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , SNone , SDual , SDual , SDual , SNone , SNone , SNone /* 0x06F0 - 0x06FF */ +}; + +static inline SVGGlyphIdentifier::ArabicForm processArabicFormDetection(const UChar& curChar, bool& lastCharShapesRight, SVGGlyphIdentifier::ArabicForm* prevForm) +{ + SVGGlyphIdentifier::ArabicForm curForm; + + ArabicCharShapingMode shapingMode = SNone; + if (curChar >= 0x0622 && curChar <= 0x06FF) + shapingMode = s_arabicCharShapingMode[curChar - 0x0622]; + + // Use a simple state machine to identify the actual arabic form + // It depends on the order of the arabic form enum: + // enum ArabicForm { None = 0, Isolated, Terminal, Initial, Medial }; + + if (lastCharShapesRight && shapingMode == SDual) { + if (prevForm) { + int correctedForm = (int) *prevForm + 1; + ASSERT(correctedForm >= SVGGlyphIdentifier::None && correctedForm <= SVGGlyphIdentifier::Medial); + *prevForm = static_cast<SVGGlyphIdentifier::ArabicForm>(correctedForm); + } + + curForm = SVGGlyphIdentifier::Initial; + } else + curForm = shapingMode == SNone ? SVGGlyphIdentifier::None : SVGGlyphIdentifier::Isolated; + + lastCharShapesRight = shapingMode != SNone; + return curForm; +} + +static Vector<SVGGlyphIdentifier::ArabicForm> charactersWithArabicForm(const String& input, bool rtl) +{ + Vector<SVGGlyphIdentifier::ArabicForm> forms; + unsigned length = input.length(); + + bool containsArabic = false; + for (unsigned i = 0; i < length; ++i) { + if (isArabicChar(input[i])) { + containsArabic = true; + break; + } + } + + if (!containsArabic) + return forms; + + bool lastCharShapesRight = false; + + // Start identifying arabic forms + if (rtl) { + for (int i = length - 1; i >= 0; --i) + forms.prepend(processArabicFormDetection(input[i], lastCharShapesRight, forms.isEmpty() ? 0 : &forms.first())); + } else { + for (unsigned i = 0; i < length; ++i) + forms.append(processArabicFormDetection(input[i], lastCharShapesRight, forms.isEmpty() ? 0 : &forms.last())); + } + + return forms; +} + +static inline bool isCompatibleArabicForm(const SVGGlyphIdentifier& identifier, const Vector<SVGGlyphIdentifier::ArabicForm>& chars, unsigned startPosition, unsigned endPosition) +{ + if (chars.isEmpty()) + return true; + + Vector<SVGGlyphIdentifier::ArabicForm>::const_iterator it = chars.begin() + startPosition; + Vector<SVGGlyphIdentifier::ArabicForm>::const_iterator end = chars.begin() + endPosition; + + ASSERT(end <= chars.end()); + for (; it != end; ++it) { + if (*it != static_cast<SVGGlyphIdentifier::ArabicForm>(identifier.arabicForm) && *it != SVGGlyphIdentifier::None) + return false; + } + + return true; +} + +static inline bool isCompatibleGlyph(const SVGGlyphIdentifier& identifier, bool isVerticalText, const String& language, + const Vector<SVGGlyphIdentifier::ArabicForm>& chars, unsigned startPosition, unsigned endPosition) +{ + bool valid = true; + + // Check wheter orientation if glyph fits within the request + switch (identifier.orientation) { + case SVGGlyphIdentifier::Vertical: + valid = isVerticalText; + break; + case SVGGlyphIdentifier::Horizontal: + valid = !isVerticalText; + break; + case SVGGlyphIdentifier::Both: + break; + } + + if (!valid) + return false; + + // Check wheter languages are compatible + if (!identifier.languages.isEmpty()) { + // This glyph exists only in certain languages, if we're not specifying a + // language on the referencing element we're unable to use this glyph. + if (language.isEmpty()) + return false; + + // Split subcode from language, if existant. + String languagePrefix; + + size_t subCodeSeparator = language.find('-'); + if (subCodeSeparator != notFound) + languagePrefix = language.left(subCodeSeparator); + + Vector<String>::const_iterator it = identifier.languages.begin(); + Vector<String>::const_iterator end = identifier.languages.end(); + + bool found = false; + for (; it != end; ++it) { + const String& cur = *it; + if (cur == language || cur == languagePrefix) { + found = true; + break; + } + } + + if (!found) + return false; + } + + // Check wheter arabic form is compatible + return isCompatibleArabicForm(identifier, chars, startPosition, endPosition); +} + +static inline const SVGFontData* svgFontAndFontFaceElementForFontData(const SimpleFontData* fontData, SVGFontFaceElement*& fontFace, SVGFontElement*& font) +{ + ASSERT(fontData->isCustomFont()); + ASSERT(fontData->isSVGFont()); + + const SVGFontData* svgFontData = static_cast<const SVGFontData*>(fontData->svgFontData()); + + fontFace = svgFontData->svgFontFaceElement(); + ASSERT(fontFace); + + font = fontFace->associatedFontElement(); + return svgFontData; +} + +// Helper class to walk a text run. Lookup a SVGGlyphIdentifier for each character +// - also respecting possibly defined ligatures - and invoke a callback for each found glyph. +template<typename SVGTextRunData> +struct SVGTextRunWalker { + typedef bool (*SVGTextRunWalkerCallback)(const SVGGlyphIdentifier&, SVGTextRunData&); + typedef void (*SVGTextRunWalkerMissingGlyphCallback)(const TextRun&, SVGTextRunData&); + + SVGTextRunWalker(const SVGFontData* fontData, SVGFontElement* fontElement, SVGTextRunData& data, + SVGTextRunWalkerCallback callback, SVGTextRunWalkerMissingGlyphCallback missingGlyphCallback) + : m_fontData(fontData) + , m_fontElement(fontElement) + , m_walkerData(data) + , m_walkerCallback(callback) + , m_walkerMissingGlyphCallback(missingGlyphCallback) + { + } + + void walk(const TextRun& run, bool isVerticalText, const String& language, int from, int to) + { + ASSERT(0 <= from && from <= to && to - from <= run.length()); + + const String text = Font::normalizeSpaces(String(run.data(from), run.length())); + Vector<SVGGlyphIdentifier::ArabicForm> chars(charactersWithArabicForm(text, run.rtl())); + + SVGGlyphIdentifier identifier; + bool foundGlyph = false; + int characterLookupRange; + int endOfScanRange = to + m_walkerData.extraCharsAvailable; + + bool haveAltGlyph = false; + SVGGlyphIdentifier altGlyphIdentifier; + if (RenderObject* renderObject = run.referencingRenderObject()) { + if (renderObject->node() && renderObject->node()->hasTagName(SVGNames::altGlyphTag)) { + SVGGlyphElement* glyphElement = static_cast<SVGAltGlyphElement*>(renderObject->node())->glyphElement(); + if (glyphElement) { + haveAltGlyph = true; + altGlyphIdentifier = glyphElement->buildGlyphIdentifier(); + altGlyphIdentifier.isValid = true; + altGlyphIdentifier.nameLength = to - from; + } + } + } + + for (int i = from; i < to; ++i) { + // If characterLookupRange is > 0, then the font defined ligatures (length of unicode property value > 1). + // We have to check wheter the current character & the next character define a ligature. This needs to be + // extended to the n-th next character (where n is 'characterLookupRange'), to check for any possible ligature. + characterLookupRange = endOfScanRange - i; + + String lookupString = Font::normalizeSpaces(String(run.data(i), characterLookupRange)); + + Vector<SVGGlyphIdentifier> glyphs; + if (haveAltGlyph) + glyphs.append(altGlyphIdentifier); + else + m_fontElement->getGlyphIdentifiersForString(lookupString, glyphs); + + Vector<SVGGlyphIdentifier>::iterator it = glyphs.begin(); + Vector<SVGGlyphIdentifier>::iterator end = glyphs.end(); + + for (; it != end; ++it) { + identifier = *it; + if (identifier.isValid && isCompatibleGlyph(identifier, isVerticalText, language, chars, i, i + identifier.nameLength)) { + ASSERT(characterLookupRange > 0); + i += identifier.nameLength - 1; + m_walkerData.charsConsumed += identifier.nameLength; + m_walkerData.glyphName = identifier.glyphName; + + foundGlyph = true; + SVGGlyphElement::inheritUnspecifiedAttributes(identifier, m_fontData); + break; + } + } + + if (!foundGlyph) { + ++m_walkerData.charsConsumed; + if (SVGMissingGlyphElement* element = m_fontElement->firstMissingGlyphElement()) { + // <missing-glyph> element support + identifier = SVGGlyphElement::buildGenericGlyphIdentifier(element); + SVGGlyphElement::inheritUnspecifiedAttributes(identifier, m_fontData); + identifier.isValid = true; + } else { + // Fallback to system font fallback + TextRun subRun(run); + subRun.setText(subRun.data(i), 1); + + (*m_walkerMissingGlyphCallback)(subRun, m_walkerData); + continue; + } + } + + if (!(*m_walkerCallback)(identifier, m_walkerData)) + break; + + foundGlyph = false; + } + } + +private: + const SVGFontData* m_fontData; + SVGFontElement* m_fontElement; + SVGTextRunData& m_walkerData; + SVGTextRunWalkerCallback m_walkerCallback; + SVGTextRunWalkerMissingGlyphCallback m_walkerMissingGlyphCallback; +}; + +// Callback & data structures to compute the width of text using SVG Fonts +struct SVGTextRunWalkerMeasuredLengthData { + int at; + int from; + int to; + int extraCharsAvailable; + int charsConsumed; + String glyphName; + + float scale; + float length; + const Font* font; +}; + +static bool floatWidthUsingSVGFontCallback(const SVGGlyphIdentifier& identifier, SVGTextRunWalkerMeasuredLengthData& data) +{ + if (data.at >= data.from && data.at < data.to) + data.length += identifier.horizontalAdvanceX * data.scale; + + data.at++; + return data.at < data.to; +} + +static void floatWidthMissingGlyphCallback(const TextRun& run, SVGTextRunWalkerMeasuredLengthData& data) +{ + // Handle system font fallback + FontDescription fontDescription(data.font->fontDescription()); + fontDescription.setFamily(FontFamily()); + Font font(fontDescription, 0, 0); // spacing handled by SVG text code. + font.update(data.font->fontSelector()); + + data.length += font.floatWidth(run); +} + + +SVGFontElement* Font::svgFont() const +{ + if (!isSVGFont()) + return 0; + + SVGFontElement* fontElement = 0; + SVGFontFaceElement* fontFaceElement = 0; + if (svgFontAndFontFaceElementForFontData(primaryFont(), fontFaceElement, fontElement)) + return fontElement; + + return 0; +} + +static float floatWidthOfSubStringUsingSVGFont(const Font* font, const TextRun& run, int extraCharsAvailable, int from, int to, int& charsConsumed, String& glyphName) +{ + int newFrom = to > from ? from : to; + int newTo = to > from ? to : from; + + from = newFrom; + to = newTo; + + SVGFontElement* fontElement = 0; + SVGFontFaceElement* fontFaceElement = 0; + + if (const SVGFontData* fontData = svgFontAndFontFaceElementForFontData(font->primaryFont(), fontFaceElement, fontElement)) { + if (!fontElement) + return 0.0f; + + SVGTextRunWalkerMeasuredLengthData data; + + data.font = font; + data.at = from; + data.from = from; + data.to = to; + data.extraCharsAvailable = extraCharsAvailable; + data.charsConsumed = 0; + data.scale = convertEmUnitToPixel(font->size(), fontFaceElement->unitsPerEm(), 1.0f); + data.length = 0.0f; + + String language; + bool isVerticalText = false; // Holds true for HTML text + + // TODO: language matching & svg glyphs should be possible for HTML text, too. + if (RenderObject* renderObject = run.referencingRenderObject()) { + isVerticalText = isVerticalWritingMode(renderObject->style()->svgStyle()); + + if (SVGElement* element = static_cast<SVGElement*>(renderObject->node())) + language = element->getAttribute(XMLNames::langAttr); + } + + SVGTextRunWalker<SVGTextRunWalkerMeasuredLengthData> runWalker(fontData, fontElement, data, floatWidthUsingSVGFontCallback, floatWidthMissingGlyphCallback); + runWalker.walk(run, isVerticalText, language, from, to); + charsConsumed = data.charsConsumed; + glyphName = data.glyphName; + return data.length; + } + + return 0.0f; +} + +float Font::floatWidthUsingSVGFont(const TextRun& run) const +{ + int charsConsumed; + String glyphName; + return floatWidthOfSubStringUsingSVGFont(this, run, 0, 0, run.length(), charsConsumed, glyphName); +} + +float Font::floatWidthUsingSVGFont(const TextRun& run, int extraCharsAvailable, int& charsConsumed, String& glyphName) const +{ + return floatWidthOfSubStringUsingSVGFont(this, run, extraCharsAvailable, 0, run.length(), charsConsumed, glyphName); +} + +// Callback & data structures to draw text using SVG Fonts +struct SVGTextRunWalkerDrawTextData { + int extraCharsAvailable; + int charsConsumed; + String glyphName; + Vector<SVGGlyphIdentifier> glyphIdentifiers; + Vector<UChar> fallbackCharacters; +}; + +static bool drawTextUsingSVGFontCallback(const SVGGlyphIdentifier& identifier, SVGTextRunWalkerDrawTextData& data) +{ + data.glyphIdentifiers.append(identifier); + return true; +} + +static void drawTextMissingGlyphCallback(const TextRun& run, SVGTextRunWalkerDrawTextData& data) +{ + ASSERT(run.length() == 1); + data.glyphIdentifiers.append(SVGGlyphIdentifier()); + data.fallbackCharacters.append(run[0]); +} + +void Font::drawTextUsingSVGFont(GraphicsContext* context, const TextRun& run, + const FloatPoint& point, int from, int to) const +{ + SVGFontElement* fontElement = 0; + SVGFontFaceElement* fontFaceElement = 0; + + if (const SVGFontData* fontData = svgFontAndFontFaceElementForFontData(primaryFont(), fontFaceElement, fontElement)) { + if (!fontElement) + return; + + SVGTextRunWalkerDrawTextData data; + FloatPoint currentPoint = point; + float scale = convertEmUnitToPixel(size(), fontFaceElement->unitsPerEm(), 1.0f); + + RenderSVGResource* activePaintingResource = run.activePaintingResource(); + + // If renderObject is not set, we're dealing for HTML text rendered using SVG Fonts. + if (!run.referencingRenderObject()) { + ASSERT(!activePaintingResource); + + // TODO: We're only supporting simple filled HTML text so far. + RenderSVGResourceSolidColor* solidPaintingResource = RenderSVGResource::sharedSolidPaintingResource(); + solidPaintingResource->setColor(context->fillColor()); + + activePaintingResource = solidPaintingResource; + } + + ASSERT(activePaintingResource); + + int charsConsumed; + String glyphName; + bool isVerticalText = false; + float xStartOffset = floatWidthOfSubStringUsingSVGFont(this, run, 0, run.rtl() ? to : 0, run.rtl() ? run.length() : from, charsConsumed, glyphName); + FloatPoint glyphOrigin; + + String language; + + // TODO: language matching & svg glyphs should be possible for HTML text, too. + if (run.referencingRenderObject()) { + isVerticalText = isVerticalWritingMode(run.referencingRenderObject()->style()->svgStyle()); + + if (SVGElement* element = static_cast<SVGElement*>(run.referencingRenderObject()->node())) + language = element->getAttribute(XMLNames::langAttr); + } + + if (!isVerticalText) { + glyphOrigin.setX(fontData->horizontalOriginX() * scale); + glyphOrigin.setY(fontData->horizontalOriginY() * scale); + } + + data.extraCharsAvailable = 0; + data.charsConsumed = 0; + + SVGTextRunWalker<SVGTextRunWalkerDrawTextData> runWalker(fontData, fontElement, data, drawTextUsingSVGFontCallback, drawTextMissingGlyphCallback); + runWalker.walk(run, isVerticalText, language, from, to); + + RenderSVGResourceMode resourceMode = context->textDrawingMode() == TextModeStroke ? ApplyToStrokeMode : ApplyToFillMode; + + unsigned numGlyphs = data.glyphIdentifiers.size(); + unsigned fallbackCharacterIndex = 0; + for (unsigned i = 0; i < numGlyphs; ++i) { + const SVGGlyphIdentifier& identifier = data.glyphIdentifiers[run.rtl() ? numGlyphs - i - 1 : i]; + if (identifier.isValid) { + // FIXME: Support arbitary SVG content as glyph (currently limited to <glyph d="..."> situations). + if (!identifier.pathData.isEmpty()) { + context->save(); + + if (isVerticalText) { + glyphOrigin.setX(identifier.verticalOriginX * scale); + glyphOrigin.setY(identifier.verticalOriginY * scale); + } + + AffineTransform glyphPathTransform; + glyphPathTransform.translate(xStartOffset + currentPoint.x() + glyphOrigin.x(), currentPoint.y() + glyphOrigin.y()); + glyphPathTransform.scale(scale, -scale); + + Path glyphPath = identifier.pathData; + glyphPath.transform(glyphPathTransform); + + RenderStyle* style = run.referencingRenderObject() ? run.referencingRenderObject()->style() : 0; + if (activePaintingResource->applyResource(run.referencingRenderObject(), style, context, resourceMode)) + activePaintingResource->postApplyResource(run.referencingRenderObject(), context, resourceMode, &glyphPath); + + context->restore(); + } + + if (isVerticalText) + currentPoint.move(0.0f, identifier.verticalAdvanceY * scale); + else + currentPoint.move(identifier.horizontalAdvanceX * scale, 0.0f); + } else { + // Handle system font fallback + FontDescription fontDescription(m_fontDescription); + fontDescription.setFamily(FontFamily()); + Font font(fontDescription, 0, 0); // spacing handled by SVG text code. + font.update(fontSelector()); + + TextRun fallbackCharacterRun(run); + fallbackCharacterRun.setText(&data.fallbackCharacters[run.rtl() ? data.fallbackCharacters.size() - fallbackCharacterIndex - 1 : fallbackCharacterIndex], 1); + font.drawText(context, fallbackCharacterRun, currentPoint); + + if (isVerticalText) + currentPoint.move(0.0f, font.floatWidth(fallbackCharacterRun)); + else + currentPoint.move(font.floatWidth(fallbackCharacterRun), 0.0f); + + fallbackCharacterIndex++; + } + } + } +} + +FloatRect Font::selectionRectForTextUsingSVGFont(const TextRun& run, const FloatPoint& point, int height, int from, int to) const +{ + int charsConsumed; + String glyphName; + + return FloatRect(point.x() + floatWidthOfSubStringUsingSVGFont(this, run, 0, run.rtl() ? to : 0, run.rtl() ? run.length() : from, charsConsumed, glyphName), + point.y(), floatWidthOfSubStringUsingSVGFont(this, run, 0, from, to, charsConsumed, glyphName), height); +} + +int Font::offsetForPositionForTextUsingSVGFont(const TextRun&, float, bool) const +{ + // TODO: Fix text selection when HTML text is drawn using a SVG Font + // We need to integrate the SVG text selection code in the offsetForPosition() framework. + // This will also fix a major issue, that SVG Text code can't select arabic strings properly. + return 0; +} + +} + +#endif diff --git a/Source/WebCore/svg/SVGFontData.cpp b/Source/WebCore/svg/SVGFontData.cpp new file mode 100644 index 0000000..63433ee --- /dev/null +++ b/Source/WebCore/svg/SVGFontData.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG_FONTS) +#include "SVGFontData.h" + +namespace WebCore { + +SVGFontData::SVGFontData(SVGFontFaceElement* fontFaceElement) + : m_svgFontFaceElement(fontFaceElement) + , m_horizontalOriginX(fontFaceElement->horizontalOriginX()) + , m_horizontalOriginY(fontFaceElement->horizontalOriginY()) + , m_horizontalAdvanceX(fontFaceElement->horizontalAdvanceX()) + , m_verticalOriginX(fontFaceElement->verticalOriginX()) + , m_verticalOriginY(fontFaceElement->verticalOriginY()) + , m_verticalAdvanceY(fontFaceElement->verticalAdvanceY()) +{ + ASSERT_ARG(fontFaceElement, fontFaceElement); +} + +} // namespace WebCore + +#endif diff --git a/Source/WebCore/svg/SVGFontData.h b/Source/WebCore/svg/SVGFontData.h new file mode 100644 index 0000000..e897a59 --- /dev/null +++ b/Source/WebCore/svg/SVGFontData.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFontData_h +#define SVGFontData_h + +#if ENABLE(SVG_FONTS) +#include "SVGFontFaceElement.h" + +namespace WebCore { + +class SVGFontData : public Noncopyable { +public: + SVGFontData(SVGFontFaceElement*); + virtual ~SVGFontData() { } + + SVGFontFaceElement* svgFontFaceElement() const { return m_svgFontFaceElement; } + + float horizontalOriginX() const { return m_horizontalOriginX; } + float horizontalOriginY() const { return m_horizontalOriginY; } + float horizontalAdvanceX() const { return m_horizontalAdvanceX; } + + float verticalOriginX() const { return m_verticalOriginX; } + float verticalOriginY() const { return m_verticalOriginY; } + float verticalAdvanceY() const { return m_verticalAdvanceY; } + +private: + // Ths SVGFontFaceElement is kept alive -- + // 1) in the external font case: by the CSSFontFaceSource, which holds a reference to the external SVG document + // containing the element; + // 2) in the in-document font case: by virtue of being in the document tree and making sure that when it is removed + // from the document, it removes the @font-face rule it owns from the document's mapped element sheet and forces + // a style update. + SVGFontFaceElement* m_svgFontFaceElement; + + float m_horizontalOriginX; + float m_horizontalOriginY; + float m_horizontalAdvanceX; + + float m_verticalOriginX; + float m_verticalOriginY; + float m_verticalAdvanceY; +}; + +} // namespace WebCore + +#endif +#endif // SVGFontData_h diff --git a/Source/WebCore/svg/SVGFontElement.cpp b/Source/WebCore/svg/SVGFontElement.cpp new file mode 100644 index 0000000..d70d46a --- /dev/null +++ b/Source/WebCore/svg/SVGFontElement.cpp @@ -0,0 +1,184 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG_FONTS) +#include "SVGFontElement.h" + +#include "Document.h" +#include "Font.h" +#include "GlyphPageTreeNode.h" +#include "SVGGlyphElement.h" +#include "SVGHKernElement.h" +#include "SVGMissingGlyphElement.h" +#include "SVGNames.h" +#include "SVGVKernElement.h" +#include <wtf/ASCIICType.h> + +namespace WebCore { + +// Animated property declarations +DEFINE_ANIMATED_BOOLEAN(SVGFontElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) + +inline SVGFontElement::SVGFontElement(const QualifiedName& tagName, Document* document) + : SVGStyledElement(tagName, document) + , m_isGlyphCacheValid(false) +{ +} + +PassRefPtr<SVGFontElement> SVGFontElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGFontElement(tagName, document)); +} + +void SVGFontElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGStyledElement::synchronizeProperty(attrName); + + if (attrName == anyQName() || SVGExternalResourcesRequired::isKnownAttribute(attrName)) + synchronizeExternalResourcesRequired(); +} + +void SVGFontElement::invalidateGlyphCache() +{ + if (m_isGlyphCacheValid) { + m_glyphMap.clear(); + m_horizontalKerningPairs.clear(); + m_verticalKerningPairs.clear(); + } + m_isGlyphCacheValid = false; +} + +SVGMissingGlyphElement* SVGFontElement::firstMissingGlyphElement() const +{ + for (Node* child = firstChild(); child; child = child->nextSibling()) { + if (child->hasTagName(SVGNames::missing_glyphTag)) + return static_cast<SVGMissingGlyphElement*>(child); + } + + return 0; +} + +void SVGFontElement::ensureGlyphCache() const +{ + if (m_isGlyphCacheValid) + return; + + for (Node* child = firstChild(); child; child = child->nextSibling()) { + if (child->hasTagName(SVGNames::glyphTag)) { + SVGGlyphElement* glyph = static_cast<SVGGlyphElement*>(child); + String unicode = glyph->getAttribute(SVGNames::unicodeAttr); + if (unicode.length()) + m_glyphMap.add(unicode, glyph->buildGlyphIdentifier()); + } else if (child->hasTagName(SVGNames::hkernTag)) { + SVGHKernElement* hkern = static_cast<SVGHKernElement*>(child); + hkern->buildHorizontalKerningPair(m_horizontalKerningPairs); + } else if (child->hasTagName(SVGNames::vkernTag)) { + SVGVKernElement* vkern = static_cast<SVGVKernElement*>(child); + vkern->buildVerticalKerningPair(m_verticalKerningPairs); + } + } + + m_isGlyphCacheValid = true; +} + +static bool stringMatchesUnicodeRange(const String& unicodeString, const UnicodeRanges& ranges, const HashSet<String>& unicodeValues) +{ + if (unicodeString.isEmpty()) + return false; + + if (!ranges.isEmpty()) { + UChar firstChar = unicodeString[0]; + const UnicodeRanges::const_iterator end = ranges.end(); + for (UnicodeRanges::const_iterator it = ranges.begin(); it != end; ++it) { + if (firstChar >= it->first && firstChar <= it->second) + return true; + } + } + + if (!unicodeValues.isEmpty()) + return unicodeValues.contains(unicodeString); + + return false; +} + +static bool stringMatchesGlyphName(const String& glyphName, const HashSet<String>& glyphValues) +{ + if (glyphName.isEmpty()) + return false; + + if (!glyphValues.isEmpty()) + return glyphValues.contains(glyphName); + + return false; +} + +static bool matches(const String& u1, const String& g1, const String& u2, const String& g2, const SVGKerningPair& kerningPair) +{ + if (!stringMatchesUnicodeRange(u1, kerningPair.unicodeRange1, kerningPair.unicodeName1) + && !stringMatchesGlyphName(g1, kerningPair.glyphName1)) + return false; + + if (!stringMatchesUnicodeRange(u2, kerningPair.unicodeRange2, kerningPair.unicodeName2) + && !stringMatchesGlyphName(g2, kerningPair.glyphName2)) + return false; + + return true; +} + +static float kerningForPairOfStringsAndGlyphs(KerningPairVector& kerningPairs, const String& u1, const String& g1, const String& u2, const String& g2) +{ + KerningPairVector::const_iterator it = kerningPairs.end() - 1; + const KerningPairVector::const_iterator begin = kerningPairs.begin() - 1; + for (; it != begin; --it) { + if (matches(u1, g1, u2, g2, *it)) + return it->kerning; + } + + return 0.0f; +} + +float SVGFontElement::horizontalKerningForPairOfStringsAndGlyphs(const String& u1, const String& g1, const String& u2, const String& g2) const +{ + if (m_horizontalKerningPairs.isEmpty()) + return 0.0f; + + return kerningForPairOfStringsAndGlyphs(m_horizontalKerningPairs, u1, g1, u2, g2); +} + +float SVGFontElement::verticalKerningForPairOfStringsAndGlyphs(const String& u1, const String& g1, const String& u2, const String& g2) const +{ + if (m_verticalKerningPairs.isEmpty()) + return 0.0f; + + return kerningForPairOfStringsAndGlyphs(m_verticalKerningPairs, u1, g1, u2, g2); +} + +void SVGFontElement::getGlyphIdentifiersForString(const String& string, Vector<SVGGlyphIdentifier>& glyphs) const +{ + ensureGlyphCache(); + m_glyphMap.get(string, glyphs); +} + +} + +#endif // ENABLE(SVG_FONTS) diff --git a/Source/WebCore/svg/SVGFontElement.h b/Source/WebCore/svg/SVGFontElement.h new file mode 100644 index 0000000..b2de38c --- /dev/null +++ b/Source/WebCore/svg/SVGFontElement.h @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFontElement_h +#define SVGFontElement_h + +#if ENABLE(SVG_FONTS) +#include "SVGAnimatedBoolean.h" +#include "SVGExternalResourcesRequired.h" +#include "SVGGlyphElement.h" +#include "SVGGlyphMap.h" +#include "SVGParserUtilities.h" +#include "SVGStyledElement.h" + +namespace WebCore { + +// Describe an SVG <hkern>/<vkern> element +struct SVGKerningPair { + float kerning; + UnicodeRanges unicodeRange1; + UnicodeRanges unicodeRange2; + HashSet<String> unicodeName1; + HashSet<String> unicodeName2; + HashSet<String> glyphName1; + HashSet<String> glyphName2; + + SVGKerningPair() + : kerning(0.0f) + { + } +}; + +typedef Vector<SVGKerningPair> KerningPairVector; + +class SVGMissingGlyphElement; + +class SVGFontElement : public SVGStyledElement + , public SVGExternalResourcesRequired { +public: + static PassRefPtr<SVGFontElement> create(const QualifiedName&, Document*); + + void invalidateGlyphCache(); + + void getGlyphIdentifiersForString(const String&, Vector<SVGGlyphIdentifier>&) const; + + float horizontalKerningForPairOfStringsAndGlyphs(const String& u1, const String& g1, const String& u2, const String& g2) const; + float verticalKerningForPairOfStringsAndGlyphs(const String& u1, const String& g1, const String& u2, const String& g2) const; + + SVGMissingGlyphElement* firstMissingGlyphElement() const; + +private: + SVGFontElement(const QualifiedName&, Document*); + + virtual void synchronizeProperty(const QualifiedName&); + virtual bool rendererIsNeeded(RenderStyle*) { return false; } + + void ensureGlyphCache() const; + + // Animated property declarations + + // SVGExternalResourcesRequired + DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) + + mutable KerningPairVector m_horizontalKerningPairs; + mutable KerningPairVector m_verticalKerningPairs; + mutable SVGGlyphMap m_glyphMap; + mutable bool m_isGlyphCacheValid; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG_FONTS) +#endif diff --git a/Source/WebCore/svg/SVGFontElement.idl b/Source/WebCore/svg/SVGFontElement.idl new file mode 100644 index 0000000..71967bf --- /dev/null +++ b/Source/WebCore/svg/SVGFontElement.idl @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * + * 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 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 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. + */ + +module svg { + + interface [Conditional=SVG&SVG_FONTS] SVGFontElement : SVGElement { + }; + +} diff --git a/Source/WebCore/svg/SVGFontFaceElement.cpp b/Source/WebCore/svg/SVGFontFaceElement.cpp new file mode 100644 index 0000000..ef7f5bd --- /dev/null +++ b/Source/WebCore/svg/SVGFontFaceElement.cpp @@ -0,0 +1,351 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * Copyright (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG_FONTS) +#include "SVGFontFaceElement.h" + +#include "Attribute.h" +#include "CSSFontFaceRule.h" +#include "CSSFontFaceSrcValue.h" +#include "CSSParser.h" +#include "CSSProperty.h" +#include "CSSPropertyNames.h" +#include "CSSStyleSelector.h" +#include "CSSStyleSheet.h" +#include "CSSValueKeywords.h" +#include "CSSValueList.h" +#include "Document.h" +#include "Font.h" +#include "SVGFontElement.h" +#include "SVGFontFaceSrcElement.h" +#include "SVGGlyphElement.h" +#include "SVGNames.h" +#include <math.h> + +namespace WebCore { + +using namespace SVGNames; + +inline SVGFontFaceElement::SVGFontFaceElement(const QualifiedName& tagName, Document* document) + : SVGElement(tagName, document) + , m_fontFaceRule(CSSFontFaceRule::create()) + , m_styleDeclaration(CSSMutableStyleDeclaration::create()) +{ + m_styleDeclaration->setParent(document->mappedElementSheet()); + m_styleDeclaration->setStrictParsing(true); + m_fontFaceRule->setDeclaration(m_styleDeclaration.get()); +} + +PassRefPtr<SVGFontFaceElement> SVGFontFaceElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGFontFaceElement(tagName, document)); +} + +static int cssPropertyIdForSVGAttributeName(const QualifiedName& attrName) +{ + if (!attrName.namespaceURI().isNull()) + return 0; + + static HashMap<AtomicStringImpl*, int>* propertyNameToIdMap = 0; + if (!propertyNameToIdMap) { + propertyNameToIdMap = new HashMap<AtomicStringImpl*, int>; + // This is a list of all @font-face CSS properties which are exposed as SVG XML attributes + // Those commented out are not yet supported by WebCore's style system + // mapAttributeToCSSProperty(propertyNameToIdMap, accent_heightAttr); + // mapAttributeToCSSProperty(propertyNameToIdMap, alphabeticAttr); + // mapAttributeToCSSProperty(propertyNameToIdMap, ascentAttr); + // mapAttributeToCSSProperty(propertyNameToIdMap, bboxAttr); + // mapAttributeToCSSProperty(propertyNameToIdMap, cap_heightAttr); + // mapAttributeToCSSProperty(propertyNameToIdMap, descentAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, font_familyAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, font_sizeAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, font_stretchAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, font_styleAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, font_variantAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, font_weightAttr); + // mapAttributeToCSSProperty(propertyNameToIdMap, hangingAttr); + // mapAttributeToCSSProperty(propertyNameToIdMap, ideographicAttr); + // mapAttributeToCSSProperty(propertyNameToIdMap, mathematicalAttr); + // mapAttributeToCSSProperty(propertyNameToIdMap, overline_positionAttr); + // mapAttributeToCSSProperty(propertyNameToIdMap, overline_thicknessAttr); + // mapAttributeToCSSProperty(propertyNameToIdMap, panose_1Attr); + // mapAttributeToCSSProperty(propertyNameToIdMap, slopeAttr); + // mapAttributeToCSSProperty(propertyNameToIdMap, stemhAttr); + // mapAttributeToCSSProperty(propertyNameToIdMap, stemvAttr); + // mapAttributeToCSSProperty(propertyNameToIdMap, strikethrough_positionAttr); + // mapAttributeToCSSProperty(propertyNameToIdMap, strikethrough_thicknessAttr); + // mapAttributeToCSSProperty(propertyNameToIdMap, underline_positionAttr); + // mapAttributeToCSSProperty(propertyNameToIdMap, underline_thicknessAttr); + // mapAttributeToCSSProperty(propertyNameToIdMap, unicode_rangeAttr); + // mapAttributeToCSSProperty(propertyNameToIdMap, units_per_emAttr); + // mapAttributeToCSSProperty(propertyNameToIdMap, v_alphabeticAttr); + // mapAttributeToCSSProperty(propertyNameToIdMap, v_hangingAttr); + // mapAttributeToCSSProperty(propertyNameToIdMap, v_ideographicAttr); + // mapAttributeToCSSProperty(propertyNameToIdMap, v_mathematicalAttr); + // mapAttributeToCSSProperty(propertyNameToIdMap, widthsAttr); + // mapAttributeToCSSProperty(propertyNameToIdMap, x_heightAttr); + } + + return propertyNameToIdMap->get(attrName.localName().impl()); +} + +void SVGFontFaceElement::parseMappedAttribute(Attribute* attr) +{ + int propId = cssPropertyIdForSVGAttributeName(attr->name()); + if (propId > 0) { + m_styleDeclaration->setProperty(propId, attr->value(), false); + rebuildFontFace(); + return; + } + + SVGElement::parseMappedAttribute(attr); +} + +unsigned SVGFontFaceElement::unitsPerEm() const +{ + const AtomicString& value = getAttribute(units_per_emAttr); + if (value.isEmpty()) + return defaultUnitsPerEm; + + return static_cast<unsigned>(ceilf(value.toFloat())); +} + +int SVGFontFaceElement::xHeight() const +{ + return static_cast<int>(ceilf(getAttribute(x_heightAttr).toFloat())); +} + +float SVGFontFaceElement::horizontalOriginX() const +{ + if (!m_fontElement) + return 0.0f; + + // Spec: The X-coordinate in the font coordinate system of the origin of a glyph to be used when + // drawing horizontally oriented text. (Note that the origin applies to all glyphs in the font.) + // If the attribute is not specified, the effect is as if a value of "0" were specified. + return m_fontElement->getAttribute(horiz_origin_xAttr).toFloat(); +} + +float SVGFontFaceElement::horizontalOriginY() const +{ + if (!m_fontElement) + return 0.0f; + + // Spec: The Y-coordinate in the font coordinate system of the origin of a glyph to be used when + // drawing horizontally oriented text. (Note that the origin applies to all glyphs in the font.) + // If the attribute is not specified, the effect is as if a value of "0" were specified. + return m_fontElement->getAttribute(horiz_origin_yAttr).toFloat(); +} + +float SVGFontFaceElement::horizontalAdvanceX() const +{ + if (!m_fontElement) + return 0.0f; + + // Spec: The default horizontal advance after rendering a glyph in horizontal orientation. Glyph + // widths are required to be non-negative, even if the glyph is typically rendered right-to-left, + // as in Hebrew and Arabic scripts. + return m_fontElement->getAttribute(horiz_adv_xAttr).toFloat(); +} + +float SVGFontFaceElement::verticalOriginX() const +{ + if (!m_fontElement) + return 0.0f; + + // Spec: The default X-coordinate in the font coordinate system of the origin of a glyph to be used when + // drawing vertically oriented text. If the attribute is not specified, the effect is as if the attribute + // were set to half of the effective value of attribute horiz-adv-x. + const AtomicString& value = m_fontElement->getAttribute(vert_origin_xAttr); + if (value.isEmpty()) + return horizontalAdvanceX() / 2.0f; + + return value.toFloat(); +} + +float SVGFontFaceElement::verticalOriginY() const +{ + if (!m_fontElement) + return 0.0f; + + // Spec: The default Y-coordinate in the font coordinate system of the origin of a glyph to be used when + // drawing vertically oriented text. If the attribute is not specified, the effect is as if the attribute + // were set to the position specified by the font's ascent attribute. + const AtomicString& value = m_fontElement->getAttribute(vert_origin_yAttr); + if (value.isEmpty()) + return ascent(); + + return value.toFloat(); +} + +float SVGFontFaceElement::verticalAdvanceY() const +{ + if (!m_fontElement) + return 0.0f; + + // Spec: The default vertical advance after rendering a glyph in vertical orientation. If the attribute is + // not specified, the effect is as if a value equivalent of one em were specified (see units-per-em). + const AtomicString& value = m_fontElement->getAttribute(vert_adv_yAttr); + if (value.isEmpty()) + return 1.0f; + + return value.toFloat(); +} + +int SVGFontFaceElement::ascent() const +{ + // Spec: Same syntax and semantics as the 'ascent' descriptor within an @font-face rule. The maximum + // unaccented height of the font within the font coordinate system. If the attribute is not specified, + // the effect is as if the attribute were set to the difference between the units-per-em value and the + // vert-origin-y value for the corresponding font. + const AtomicString& ascentValue = getAttribute(ascentAttr); + if (!ascentValue.isEmpty()) + return static_cast<int>(ceilf(ascentValue.toFloat())); + + if (m_fontElement) { + const AtomicString& vertOriginY = m_fontElement->getAttribute(vert_origin_yAttr); + if (!vertOriginY.isEmpty()) + return static_cast<int>(unitsPerEm()) - static_cast<int>(ceilf(vertOriginY.toFloat())); + } + + // Match Batiks default value + return static_cast<int>(ceilf(unitsPerEm() * 0.8f)); +} + +int SVGFontFaceElement::descent() const +{ + // Spec: Same syntax and semantics as the 'descent' descriptor within an @font-face rule. The maximum + // unaccented depth of the font within the font coordinate system. If the attribute is not specified, + // the effect is as if the attribute were set to the vert-origin-y value for the corresponding font. + const AtomicString& descentValue = getAttribute(descentAttr); + if (!descentValue.isEmpty()) { + // 14 different W3C SVG 1.1 testcases use a negative descent value, + // where a positive was meant to be used Including: + // animate-elem-24-t.svg, fonts-elem-01-t.svg, fonts-elem-02-t.svg (and 11 others) + int descent = static_cast<int>(ceilf(descentValue.toFloat())); + return descent < 0 ? -descent : descent; + } + + if (m_fontElement) { + const AtomicString& vertOriginY = m_fontElement->getAttribute(vert_origin_yAttr); + if (!vertOriginY.isEmpty()) + return static_cast<int>(ceilf(vertOriginY.toFloat())); + } + + // Match Batiks default value + return static_cast<int>(ceilf(unitsPerEm() * 0.2f)); +} + +String SVGFontFaceElement::fontFamily() const +{ + return m_styleDeclaration->getPropertyValue(CSSPropertyFontFamily); +} + +void SVGFontFaceElement::rebuildFontFace() +{ + if (!inDocument()) + return; + + // we currently ignore all but the first src element, alternatively we could concat them + SVGFontFaceSrcElement* srcElement = 0; + + for (Node* child = firstChild(); child && !srcElement; child = child->nextSibling()) { + if (child->hasTagName(font_face_srcTag)) + srcElement = static_cast<SVGFontFaceSrcElement*>(child); + } + + bool describesParentFont = parentNode()->hasTagName(SVGNames::fontTag); + RefPtr<CSSValueList> list; + + if (describesParentFont) { + m_fontElement = static_cast<SVGFontElement*>(parentNode()); + + list = CSSValueList::createCommaSeparated(); + list->append(CSSFontFaceSrcValue::createLocal(fontFamily())); + } else { + m_fontElement = 0; + if (srcElement) + list = srcElement->srcValue(); + } + + if (!list || !list->length()) + return; + + // Parse in-memory CSS rules + CSSProperty srcProperty(CSSPropertySrc, list); + const CSSProperty* srcPropertyRef = &srcProperty; + m_styleDeclaration->addParsedProperties(&srcPropertyRef, 1); + + if (describesParentFont) { + // Traverse parsed CSS values and associate CSSFontFaceSrcValue elements with ourselves. + RefPtr<CSSValue> src = m_styleDeclaration->getPropertyCSSValue(CSSPropertySrc); + CSSValueList* srcList = static_cast<CSSValueList*>(src.get()); + + unsigned srcLength = srcList ? srcList->length() : 0; + for (unsigned i = 0; i < srcLength; i++) { + if (CSSFontFaceSrcValue* item = static_cast<CSSFontFaceSrcValue*>(srcList->itemWithoutBoundsCheck(i))) + item->setSVGFontFaceElement(this); + } + } + + document()->styleSelectorChanged(DeferRecalcStyle); +} + +void SVGFontFaceElement::insertedIntoDocument() +{ + SVGElement::insertedIntoDocument(); + document()->mappedElementSheet()->append(m_fontFaceRule); + m_fontFaceRule->setParent(document()->mappedElementSheet()); + rebuildFontFace(); +} + +void SVGFontFaceElement::removedFromDocument() +{ + removeFromMappedElementSheet(); + SVGElement::removedFromDocument(); +} + +void SVGFontFaceElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) +{ + SVGElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); + rebuildFontFace(); +} + +void SVGFontFaceElement::removeFromMappedElementSheet() +{ + CSSStyleSheet* mappedElementSheet = document()->mappedElementSheet(); + if (!mappedElementSheet) + return; + + for (unsigned i = 0; i < mappedElementSheet->length(); ++i) { + if (mappedElementSheet->item(i) == m_fontFaceRule) { + mappedElementSheet->remove(i); + break; + } + } + document()->styleSelectorChanged(DeferRecalcStyle); +} + +} // namespace WebCore + +#endif // ENABLE(SVG_FONTS) diff --git a/Source/WebCore/svg/SVGFontFaceElement.h b/Source/WebCore/svg/SVGFontFaceElement.h new file mode 100644 index 0000000..5e974a7 --- /dev/null +++ b/Source/WebCore/svg/SVGFontFaceElement.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFontFaceElement_h +#define SVGFontFaceElement_h + +#if ENABLE(SVG_FONTS) +#include "SVGElement.h" + +namespace WebCore { + +class CSSFontFaceRule; +class CSSMutableStyleDeclaration; +class SVGFontElement; + +class SVGFontFaceElement : public SVGElement { +public: + static PassRefPtr<SVGFontFaceElement> create(const QualifiedName&, Document*); + + unsigned unitsPerEm() const; + int xHeight() const; + float horizontalOriginX() const; + float horizontalOriginY() const; + float horizontalAdvanceX() const; + float verticalOriginX() const; + float verticalOriginY() const; + float verticalAdvanceY() const; + int ascent() const; + int descent() const; + String fontFamily() const; + + SVGFontElement* associatedFontElement() const { return m_fontElement; } + void rebuildFontFace(); + void removeFromMappedElementSheet(); + +private: + SVGFontFaceElement(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + + virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); + virtual void insertedIntoDocument(); + virtual void removedFromDocument(); + + RefPtr<CSSFontFaceRule> m_fontFaceRule; + RefPtr<CSSMutableStyleDeclaration> m_styleDeclaration; + + SVGFontElement* m_fontElement; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG_FONTS) +#endif + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGFontFaceElement.idl b/Source/WebCore/svg/SVGFontFaceElement.idl new file mode 100644 index 0000000..e7e6980 --- /dev/null +++ b/Source/WebCore/svg/SVGFontFaceElement.idl @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * + * 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 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 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. + */ + +module svg { + + interface [Conditional=SVG&SVG_FONTS] SVGFontFaceElement : SVGElement { + }; + +} diff --git a/Source/WebCore/svg/SVGFontFaceFormatElement.cpp b/Source/WebCore/svg/SVGFontFaceFormatElement.cpp new file mode 100644 index 0000000..939b062 --- /dev/null +++ b/Source/WebCore/svg/SVGFontFaceFormatElement.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG_FONTS) +#include "SVGFontFaceFormatElement.h" + +#include "SVGFontFaceElement.h" +#include "SVGNames.h" + +namespace WebCore { + +using namespace SVGNames; + +inline SVGFontFaceFormatElement::SVGFontFaceFormatElement(const QualifiedName& tagName, Document* document) + : SVGElement(tagName, document) +{ +} + +PassRefPtr<SVGFontFaceFormatElement> SVGFontFaceFormatElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGFontFaceFormatElement(tagName, document)); +} + +void SVGFontFaceFormatElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) +{ + SVGElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); + + if (!parentNode() || !parentNode()->hasTagName(font_face_uriTag)) + return; + + ContainerNode* ancestor = parentNode()->parentNode(); + if (!ancestor || !ancestor->hasTagName(font_face_srcTag)) + return; + + ancestor = ancestor->parentNode(); + if (ancestor && ancestor->hasTagName(font_faceTag)) + static_cast<SVGFontFaceElement*>(ancestor)->rebuildFontFace(); +} + +} + +#endif // ENABLE(SVG_FONTS) diff --git a/Source/WebCore/svg/SVGFontFaceFormatElement.h b/Source/WebCore/svg/SVGFontFaceFormatElement.h new file mode 100644 index 0000000..6ca6c1f --- /dev/null +++ b/Source/WebCore/svg/SVGFontFaceFormatElement.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFontFaceFormatElement_h +#define SVGFontFaceFormatElement_h + +#if ENABLE(SVG_FONTS) +#include "SVGElement.h" + +namespace WebCore { + +class SVGFontFaceFormatElement : public SVGElement { +public: + static PassRefPtr<SVGFontFaceFormatElement> create(const QualifiedName&, Document*); + +private: + SVGFontFaceFormatElement(const QualifiedName&, Document*); + + virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); +}; + +} // namespace WebCore + +#endif // ENABLE(SVG_FONTS) +#endif + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGFontFaceFormatElement.idl b/Source/WebCore/svg/SVGFontFaceFormatElement.idl new file mode 100644 index 0000000..6053c98 --- /dev/null +++ b/Source/WebCore/svg/SVGFontFaceFormatElement.idl @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * + * 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 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 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. + */ + +module svg { + + interface [Conditional=SVG&SVG_FONTS] SVGFontFaceFormatElement : SVGElement { + }; + +} diff --git a/Source/WebCore/svg/SVGFontFaceNameElement.cpp b/Source/WebCore/svg/SVGFontFaceNameElement.cpp new file mode 100644 index 0000000..39ac2b3 --- /dev/null +++ b/Source/WebCore/svg/SVGFontFaceNameElement.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG_FONTS) +#include "SVGFontFaceNameElement.h" + +#include "CSSFontFaceSrcValue.h" +#include "SVGNames.h" + +namespace WebCore { + +inline SVGFontFaceNameElement::SVGFontFaceNameElement(const QualifiedName& tagName, Document* document) + : SVGElement(tagName, document) +{ +} + +PassRefPtr<SVGFontFaceNameElement> SVGFontFaceNameElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGFontFaceNameElement(tagName, document)); +} + +PassRefPtr<CSSFontFaceSrcValue> SVGFontFaceNameElement::srcValue() const +{ + return CSSFontFaceSrcValue::createLocal(getAttribute(SVGNames::nameAttr)); +} + +} + +#endif // ENABLE(SVG) + diff --git a/Source/WebCore/svg/SVGFontFaceNameElement.h b/Source/WebCore/svg/SVGFontFaceNameElement.h new file mode 100644 index 0000000..e99d2d5 --- /dev/null +++ b/Source/WebCore/svg/SVGFontFaceNameElement.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFontFaceNameElement_h +#define SVGFontFaceNameElement_h + +#if ENABLE(SVG_FONTS) +#include "SVGElement.h" + +namespace WebCore { + +class CSSFontFaceSrcValue; + +class SVGFontFaceNameElement : public SVGElement { +public: + static PassRefPtr<SVGFontFaceNameElement> create(const QualifiedName&, Document*); + + PassRefPtr<CSSFontFaceSrcValue> srcValue() const; + +private: + SVGFontFaceNameElement(const QualifiedName&, Document*); +}; + +} // namespace WebCore + +#endif // ENABLE(SVG_FONTS) +#endif + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGFontFaceNameElement.idl b/Source/WebCore/svg/SVGFontFaceNameElement.idl new file mode 100644 index 0000000..4292a28 --- /dev/null +++ b/Source/WebCore/svg/SVGFontFaceNameElement.idl @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * + * 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 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 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. + */ + +module svg { + + interface [Conditional=SVG&SVG_FONTS] SVGFontFaceNameElement : SVGElement { + }; + +} diff --git a/Source/WebCore/svg/SVGFontFaceSrcElement.cpp b/Source/WebCore/svg/SVGFontFaceSrcElement.cpp new file mode 100644 index 0000000..ce75872 --- /dev/null +++ b/Source/WebCore/svg/SVGFontFaceSrcElement.cpp @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG_FONTS) +#include "SVGFontFaceSrcElement.h" + +#include "CSSFontFaceSrcValue.h" +#include "CSSValueList.h" +#include "SVGFontFaceElement.h" +#include "SVGFontFaceNameElement.h" +#include "SVGFontFaceUriElement.h" +#include "SVGNames.h" + +namespace WebCore { + +using namespace SVGNames; + +inline SVGFontFaceSrcElement::SVGFontFaceSrcElement(const QualifiedName& tagName, Document* document) + : SVGElement(tagName, document) +{ +} + +PassRefPtr<SVGFontFaceSrcElement> SVGFontFaceSrcElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGFontFaceSrcElement(tagName, document)); +} + +PassRefPtr<CSSValueList> SVGFontFaceSrcElement::srcValue() const +{ + RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); + for (Node* child = firstChild(); child; child = child->nextSibling()) { + RefPtr<CSSFontFaceSrcValue> srcValue; + if (child->hasTagName(font_face_uriTag)) + srcValue = static_cast<SVGFontFaceUriElement*>(child)->srcValue(); + else if (child->hasTagName(font_face_nameTag)) + srcValue = static_cast<SVGFontFaceNameElement*>(child)->srcValue(); + if (srcValue && srcValue->resource().length()) + list->append(srcValue); + } + return list; +} + +void SVGFontFaceSrcElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) +{ + SVGElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); + if (parentNode() && parentNode()->hasTagName(font_faceTag)) + static_cast<SVGFontFaceElement*>(parentNode())->rebuildFontFace(); +} + +} + +#endif // ENABLE(SVG_FONTS) diff --git a/Source/WebCore/svg/SVGFontFaceSrcElement.h b/Source/WebCore/svg/SVGFontFaceSrcElement.h new file mode 100644 index 0000000..5e27625 --- /dev/null +++ b/Source/WebCore/svg/SVGFontFaceSrcElement.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFontFaceSrcElement_h +#define SVGFontFaceSrcElement_h + +#if ENABLE(SVG_FONTS) +#include "SVGElement.h" + +namespace WebCore { + +class CSSValueList; + +class SVGFontFaceSrcElement : public SVGElement { +public: + static PassRefPtr<SVGFontFaceSrcElement> create(const QualifiedName&, Document*); + + PassRefPtr<CSSValueList> srcValue() const; + +private: + SVGFontFaceSrcElement(const QualifiedName&, Document*); + + virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); +}; + +} // namespace WebCore + +#endif // ENABLE(SVG_FONTS) +#endif + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGFontFaceSrcElement.idl b/Source/WebCore/svg/SVGFontFaceSrcElement.idl new file mode 100644 index 0000000..addfc0e --- /dev/null +++ b/Source/WebCore/svg/SVGFontFaceSrcElement.idl @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * + * 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 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 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. + */ + +module svg { + + interface [Conditional=SVG&SVG_FONTS] SVGFontFaceSrcElement : SVGElement { + }; + +} diff --git a/Source/WebCore/svg/SVGFontFaceUriElement.cpp b/Source/WebCore/svg/SVGFontFaceUriElement.cpp new file mode 100644 index 0000000..58a22c7 --- /dev/null +++ b/Source/WebCore/svg/SVGFontFaceUriElement.cpp @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG_FONTS) +#include "SVGFontFaceUriElement.h" + +#include "Attribute.h" +#include "CSSFontFaceSrcValue.h" +#include "CachedFont.h" +#include "CachedResourceLoader.h" +#include "Document.h" +#include "SVGFontFaceElement.h" +#include "SVGNames.h" +#include "XLinkNames.h" + +namespace WebCore { + +using namespace SVGNames; + +inline SVGFontFaceUriElement::SVGFontFaceUriElement(const QualifiedName& tagName, Document* document) + : SVGElement(tagName, document) +{ +} + +PassRefPtr<SVGFontFaceUriElement> SVGFontFaceUriElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGFontFaceUriElement(tagName, document)); +} + +SVGFontFaceUriElement::~SVGFontFaceUriElement() +{ + if (m_cachedFont) + m_cachedFont->removeClient(this); +} + +PassRefPtr<CSSFontFaceSrcValue> SVGFontFaceUriElement::srcValue() const +{ + RefPtr<CSSFontFaceSrcValue> src = CSSFontFaceSrcValue::create(getAttribute(XLinkNames::hrefAttr)); + AtomicString value(getAttribute(formatAttr)); + src->setFormat(value.isEmpty() ? "svg" : value); // Default format + return src.release(); +} + +void SVGFontFaceUriElement::parseMappedAttribute(Attribute* attr) +{ + const QualifiedName& attrName = attr->name(); + if (attrName == XLinkNames::hrefAttr) + loadFont(); + else + SVGElement::parseMappedAttribute(attr); +} + +void SVGFontFaceUriElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) +{ + SVGElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); + + if (!parentNode() || !parentNode()->hasTagName(font_face_srcTag)) + return; + + ContainerNode* grandparent = parentNode()->parentNode(); + if (grandparent && grandparent->hasTagName(font_faceTag)) + static_cast<SVGFontFaceElement*>(grandparent)->rebuildFontFace(); +} + +void SVGFontFaceUriElement::insertedIntoDocument() +{ + loadFont(); + SVGElement::insertedIntoDocument(); +} + +void SVGFontFaceUriElement::loadFont() +{ + if (m_cachedFont) + m_cachedFont->removeClient(this); + + String href = getAttribute(XLinkNames::hrefAttr); + if (!href.isNull()) { + CachedResourceLoader* cachedResourceLoader = document()->cachedResourceLoader(); + m_cachedFont = cachedResourceLoader->requestFont(href); + if (m_cachedFont) { + m_cachedFont->setSVGFont(true); + m_cachedFont->addClient(this); + m_cachedFont->beginLoadIfNeeded(cachedResourceLoader); + } + } else + m_cachedFont = 0; +} + +} + +#endif // ENABLE(SVG_FONTS) diff --git a/Source/WebCore/svg/SVGFontFaceUriElement.h b/Source/WebCore/svg/SVGFontFaceUriElement.h new file mode 100644 index 0000000..ad9ba97 --- /dev/null +++ b/Source/WebCore/svg/SVGFontFaceUriElement.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFontFaceUriElement_h +#define SVGFontFaceUriElement_h + +#if ENABLE(SVG_FONTS) +#include "CachedResourceClient.h" +#include "CachedResourceHandle.h" +#include "SVGElement.h" + +namespace WebCore { + +class CSSFontFaceSrcValue; +class CachedFont; + +class SVGFontFaceUriElement : public SVGElement, public CachedResourceClient { +public: + static PassRefPtr<SVGFontFaceUriElement> create(const QualifiedName&, Document*); + + virtual ~SVGFontFaceUriElement(); + + PassRefPtr<CSSFontFaceSrcValue> srcValue() const; + +private: + SVGFontFaceUriElement(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); + virtual void insertedIntoDocument(); + +#ifdef ANDROID_INSTRUMENT + void* operator new(size_t size) { + return SVGElement::operator new(size); + } + void* operator new[](size_t size) { + return SVGElement::operator new[](size); + } + + void operator delete(void* p, size_t size) { + SVGElement::operator delete(p, size); + } + void operator delete[](void* p, size_t size) { + SVGElement::operator delete[](p, size); + } +#endif + + void loadFont(); + + CachedResourceHandle<CachedFont> m_cachedFont; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG_FONTS) +#endif + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGFontFaceUriElement.idl b/Source/WebCore/svg/SVGFontFaceUriElement.idl new file mode 100644 index 0000000..ae34a91 --- /dev/null +++ b/Source/WebCore/svg/SVGFontFaceUriElement.idl @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * + * 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 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 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. + */ + +module svg { + + interface [Conditional=SVG&SVG_FONTS] SVGFontFaceUriElement : SVGElement { + }; + +} diff --git a/Source/WebCore/svg/SVGForeignObjectElement.cpp b/Source/WebCore/svg/SVGForeignObjectElement.cpp new file mode 100644 index 0000000..c2fcecb --- /dev/null +++ b/Source/WebCore/svg/SVGForeignObjectElement.cpp @@ -0,0 +1,165 @@ +/* + * Copyright (C) 2006 Apple Inc. All rights reserved. + * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FOREIGN_OBJECT) +#include "SVGForeignObjectElement.h" + +#include "Attribute.h" +#include "CSSPropertyNames.h" +#include "RenderForeignObject.h" +#include "RenderSVGResource.h" +#include "SVGLength.h" +#include "SVGNames.h" +#include <wtf/Assertions.h> + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_LENGTH(SVGForeignObjectElement, SVGNames::xAttr, X, x) +DEFINE_ANIMATED_LENGTH(SVGForeignObjectElement, SVGNames::yAttr, Y, y) +DEFINE_ANIMATED_LENGTH(SVGForeignObjectElement, SVGNames::widthAttr, Width, width) +DEFINE_ANIMATED_LENGTH(SVGForeignObjectElement, SVGNames::heightAttr, Height, height) +DEFINE_ANIMATED_STRING(SVGForeignObjectElement, XLinkNames::hrefAttr, Href, href) +DEFINE_ANIMATED_BOOLEAN(SVGForeignObjectElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) + +inline SVGForeignObjectElement::SVGForeignObjectElement(const QualifiedName& tagName, Document* document) + : SVGStyledTransformableElement(tagName, document) + , m_x(LengthModeWidth) + , m_y(LengthModeHeight) + , m_width(LengthModeWidth) + , m_height(LengthModeHeight) +{ +} + +PassRefPtr<SVGForeignObjectElement> SVGForeignObjectElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGForeignObjectElement(tagName, document)); +} + +void SVGForeignObjectElement::parseMappedAttribute(Attribute* attr) +{ + const AtomicString& value = attr->value(); + if (attr->name() == SVGNames::xAttr) + setXBaseValue(SVGLength(LengthModeWidth, value)); + else if (attr->name() == SVGNames::yAttr) + setYBaseValue(SVGLength(LengthModeHeight, value)); + else if (attr->name() == SVGNames::widthAttr) + setWidthBaseValue(SVGLength(LengthModeWidth, value)); + else if (attr->name() == SVGNames::heightAttr) + setHeightBaseValue(SVGLength(LengthModeHeight, value)); + else { + if (SVGTests::parseMappedAttribute(attr)) + return; + if (SVGLangSpace::parseMappedAttribute(attr)) + return; + if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) + return; + SVGStyledTransformableElement::parseMappedAttribute(attr); + } +} + +void SVGForeignObjectElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGStyledTransformableElement::svgAttributeChanged(attrName); + + bool isLengthAttribute = attrName == SVGNames::xAttr + || attrName == SVGNames::yAttr + || attrName == SVGNames::widthAttr + || attrName == SVGNames::heightAttr; + + if (isLengthAttribute) + updateRelativeLengthsInformation(); + + if (SVGTests::handleAttributeChange(this, attrName)) + return; + + RenderObject* renderer = this->renderer(); + if (!renderer) + return; + + if (SVGStyledTransformableElement::isKnownAttribute(attrName)) { + renderer->setNeedsTransformUpdate(); + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); + return; + } + + if (isLengthAttribute + || SVGLangSpace::isKnownAttribute(attrName) + || SVGExternalResourcesRequired::isKnownAttribute(attrName)) + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); +} + +void SVGForeignObjectElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGStyledTransformableElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeX(); + synchronizeY(); + synchronizeWidth(); + synchronizeHeight(); + synchronizeExternalResourcesRequired(); + synchronizeHref(); + SVGTests::synchronizeProperties(this, attrName); + return; + } + + if (attrName == SVGNames::xAttr) + synchronizeX(); + else if (attrName == SVGNames::yAttr) + synchronizeY(); + else if (attrName == SVGNames::widthAttr) + synchronizeWidth(); + else if (attrName == SVGNames::heightAttr) + synchronizeHeight(); + else if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) + synchronizeExternalResourcesRequired(); + else if (SVGTests::isKnownAttribute(attrName)) + SVGTests::synchronizeProperties(this, attrName); +} + +RenderObject* SVGForeignObjectElement::createRenderer(RenderArena* arena, RenderStyle*) +{ + return new (arena) RenderForeignObject(this); +} + +bool SVGForeignObjectElement::childShouldCreateRenderer(Node* child) const +{ + // Disallow arbitary SVG content. Only allow proper <svg xmlns="svgNS"> subdocuments. + if (child->isSVGElement()) + return child->hasTagName(SVGNames::svgTag); + + // Skip over SVG rules which disallow non-SVG kids + return StyledElement::childShouldCreateRenderer(child); +} + +bool SVGForeignObjectElement::selfHasRelativeLengths() const +{ + return x().isRelative() + || y().isRelative() + || width().isRelative() + || height().isRelative(); +} + +} + +#endif diff --git a/Source/WebCore/svg/SVGForeignObjectElement.h b/Source/WebCore/svg/SVGForeignObjectElement.h new file mode 100644 index 0000000..687d089 --- /dev/null +++ b/Source/WebCore/svg/SVGForeignObjectElement.h @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2006 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGForeignObjectElement_h +#define SVGForeignObjectElement_h + +#if ENABLE(SVG) && ENABLE(SVG_FOREIGN_OBJECT) +#include "SVGAnimatedBoolean.h" +#include "SVGAnimatedLength.h" +#include "SVGExternalResourcesRequired.h" +#include "SVGLangSpace.h" +#include "SVGStyledTransformableElement.h" +#include "SVGTests.h" +#include "SVGURIReference.h" + +namespace WebCore { + +class SVGForeignObjectElement : public SVGStyledTransformableElement, + public SVGTests, + public SVGLangSpace, + public SVGExternalResourcesRequired { +public: + static PassRefPtr<SVGForeignObjectElement> create(const QualifiedName&, Document*); + +private: + SVGForeignObjectElement(const QualifiedName&, Document*); + + virtual bool isValid() const { return SVGTests::isValid(); } + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + + virtual bool childShouldCreateRenderer(Node*) const; + virtual RenderObject* createRenderer(RenderArena* arena, RenderStyle* style); + + virtual bool selfHasRelativeLengths() const; + + // Animated property declarations + DECLARE_ANIMATED_LENGTH(X, x) + DECLARE_ANIMATED_LENGTH(Y, y) + DECLARE_ANIMATED_LENGTH(Width, width) + DECLARE_ANIMATED_LENGTH(Height, height) + + // SVGURIReference + DECLARE_ANIMATED_STRING(Href, href) + + // SVGExternalResourcesRequired + DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FOREIGN_OBJECT) +#endif diff --git a/Source/WebCore/svg/SVGForeignObjectElement.idl b/Source/WebCore/svg/SVGForeignObjectElement.idl new file mode 100644 index 0000000..0d3fc25 --- /dev/null +++ b/Source/WebCore/svg/SVGForeignObjectElement.idl @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG&SVG_FOREIGN_OBJECT] SVGForeignObjectElement : SVGElement, + SVGTests, + SVGLangSpace, + SVGExternalResourcesRequired, + SVGStylable, + SVGTransformable { + readonly attribute SVGAnimatedLength x; + readonly attribute SVGAnimatedLength y; + readonly attribute SVGAnimatedLength width; + readonly attribute SVGAnimatedLength height; + }; + +} diff --git a/Source/WebCore/svg/SVGGElement.cpp b/Source/WebCore/svg/SVGGElement.cpp new file mode 100644 index 0000000..233aa74 --- /dev/null +++ b/Source/WebCore/svg/SVGGElement.cpp @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGGElement.h" + +#include "RenderSVGHiddenContainer.h" +#include "RenderSVGResource.h" +#include "RenderSVGTransformableContainer.h" +#include "SVGNames.h" + +namespace WebCore { + +// Animated property declarations +DEFINE_ANIMATED_BOOLEAN(SVGGElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) + +SVGGElement::SVGGElement(const QualifiedName& tagName, Document* document) + : SVGStyledTransformableElement(tagName, document) +{ +} + +PassRefPtr<SVGGElement> SVGGElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGGElement(tagName, document)); +} + +void SVGGElement::parseMappedAttribute(Attribute* attr) +{ + if (SVGTests::parseMappedAttribute(attr)) + return; + if (SVGLangSpace::parseMappedAttribute(attr)) + return; + if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) + return; + + SVGStyledTransformableElement::parseMappedAttribute(attr); +} + +void SVGGElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGStyledTransformableElement::svgAttributeChanged(attrName); + + if (SVGTests::handleAttributeChange(this, attrName)) + return; + + RenderObject* renderer = this->renderer(); + if (!renderer) + return; + + if (SVGStyledTransformableElement::isKnownAttribute(attrName)) { + renderer->setNeedsTransformUpdate(); + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); + return; + } + + if (SVGLangSpace::isKnownAttribute(attrName) + || SVGExternalResourcesRequired::isKnownAttribute(attrName)) + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); +} + +void SVGGElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGStyledTransformableElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeExternalResourcesRequired(); + SVGTests::synchronizeProperties(this, attrName); + return; + } + + if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) + synchronizeExternalResourcesRequired(); + else if (SVGTests::isKnownAttribute(attrName)) + SVGTests::synchronizeProperties(this, attrName); +} + +RenderObject* SVGGElement::createRenderer(RenderArena* arena, RenderStyle* style) +{ + // SVG 1.1 testsuite explicitely uses constructs like <g display="none"><linearGradient> + // We still have to create renderers for the <g> & <linearGradient> element, though the + // subtree may be hidden - we only want the resource renderers to exist so they can be + // referenced from somewhere else. + if (style->display() == NONE) + return new (arena) RenderSVGHiddenContainer(this); + + return new (arena) RenderSVGTransformableContainer(this); +} + +bool SVGGElement::rendererIsNeeded(RenderStyle*) +{ + return parentNode() && parentNode()->isSVGElement(); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGGElement.h b/Source/WebCore/svg/SVGGElement.h new file mode 100644 index 0000000..3c00b34 --- /dev/null +++ b/Source/WebCore/svg/SVGGElement.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGGElement_h +#define SVGGElement_h + +#if ENABLE(SVG) +#include "SVGAnimatedBoolean.h" +#include "SVGExternalResourcesRequired.h" +#include "SVGLangSpace.h" +#include "SVGStyledTransformableElement.h" +#include "SVGTests.h" + +namespace WebCore { + +class SVGGElement : public SVGStyledTransformableElement, + public SVGTests, + public SVGLangSpace, + public SVGExternalResourcesRequired { +public: + static PassRefPtr<SVGGElement> create(const QualifiedName&, Document*); + + virtual bool isShadowTreeContainerElement() const { return false; } + +protected: + SVGGElement(const QualifiedName&, Document*); + + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + +private: + virtual bool isValid() const { return SVGTests::isValid(); } + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + + virtual bool rendererIsNeeded(RenderStyle*); + + // Animated property declarations + + // SVGExternalResourcesRequired + DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGGElement.idl b/Source/WebCore/svg/SVGGElement.idl new file mode 100644 index 0000000..5c539f7 --- /dev/null +++ b/Source/WebCore/svg/SVGGElement.idl @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGGElement : SVGElement, + SVGTests, + SVGLangSpace, + SVGExternalResourcesRequired, + SVGStylable, + SVGTransformable { + }; + +} diff --git a/Source/WebCore/svg/SVGGlyphElement.cpp b/Source/WebCore/svg/SVGGlyphElement.cpp new file mode 100644 index 0000000..a64d833 --- /dev/null +++ b/Source/WebCore/svg/SVGGlyphElement.cpp @@ -0,0 +1,180 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * Copyright (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2008 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG_FONTS) +#include "SVGGlyphElement.h" + +#include "Attribute.h" +#include "SVGFontData.h" +#include "SVGFontElement.h" +#include "SVGFontFaceElement.h" +#include "SVGNames.h" +#include "SVGPathParserFactory.h" +#include "SimpleFontData.h" +#include "XMLNames.h" + +namespace WebCore { + +using namespace SVGNames; + +inline SVGGlyphElement::SVGGlyphElement(const QualifiedName& tagName, Document* document) + : SVGStyledElement(tagName, document) +{ +} + +PassRefPtr<SVGGlyphElement> SVGGlyphElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGGlyphElement(tagName, document)); +} + +void SVGGlyphElement::invalidateGlyphCache() +{ + ContainerNode* fontNode = parentNode(); + if (fontNode && fontNode->hasTagName(SVGNames::fontTag)) { + if (SVGFontElement* element = static_cast<SVGFontElement*>(fontNode)) + element->invalidateGlyphCache(); + } +} + +void SVGGlyphElement::parseMappedAttribute(Attribute* attr) +{ + if (attr->name() == SVGNames::dAttr) + invalidateGlyphCache(); + else + SVGStyledElement::parseMappedAttribute(attr); +} + +void SVGGlyphElement::insertedIntoDocument() +{ + invalidateGlyphCache(); + SVGStyledElement::insertedIntoDocument(); +} + +void SVGGlyphElement::removedFromDocument() +{ + invalidateGlyphCache(); + SVGStyledElement::removedFromDocument(); +} + +static inline SVGGlyphIdentifier::ArabicForm parseArabicForm(const AtomicString& value) +{ + if (value == "medial") + return SVGGlyphIdentifier::Medial; + if (value == "terminal") + return SVGGlyphIdentifier::Terminal; + if (value == "isolated") + return SVGGlyphIdentifier::Isolated; + if (value == "initial") + return SVGGlyphIdentifier::Initial; + + return SVGGlyphIdentifier::None; +} + +static inline SVGGlyphIdentifier::Orientation parseOrientation(const AtomicString& value) +{ + if (value == "h") + return SVGGlyphIdentifier::Horizontal; + if (value == "v") + return SVGGlyphIdentifier::Vertical; + + return SVGGlyphIdentifier::Both; +} + +static inline Path parsePathData(const AtomicString& value) +{ + Path result; + SVGPathParserFactory* factory = SVGPathParserFactory::self(); + factory->buildPathFromString(value, result); + return result; +} + +void SVGGlyphElement::inheritUnspecifiedAttributes(SVGGlyphIdentifier& identifier, const SVGFontData* svgFontData) +{ + if (identifier.horizontalAdvanceX == SVGGlyphIdentifier::inheritedValue()) + identifier.horizontalAdvanceX = svgFontData->horizontalAdvanceX(); + + if (identifier.verticalOriginX == SVGGlyphIdentifier::inheritedValue()) + identifier.verticalOriginX = svgFontData->verticalOriginX(); + + if (identifier.verticalOriginY == SVGGlyphIdentifier::inheritedValue()) + identifier.verticalOriginY = svgFontData->verticalOriginY(); + + if (identifier.verticalAdvanceY == SVGGlyphIdentifier::inheritedValue()) + identifier.verticalAdvanceY = svgFontData->verticalAdvanceY(); +} + +static inline float parseSVGGlyphAttribute(const SVGElement* element, const WebCore::QualifiedName& name) +{ + AtomicString value(element->getAttribute(name)); + if (value.isEmpty()) + return SVGGlyphIdentifier::inheritedValue(); + + return value.toFloat(); +} + +SVGGlyphIdentifier SVGGlyphElement::buildGenericGlyphIdentifier(const SVGElement* element) +{ + SVGGlyphIdentifier identifier; + identifier.pathData = parsePathData(element->getAttribute(dAttr)); + + // Spec: The horizontal advance after rendering the glyph in horizontal orientation. + // If the attribute is not specified, the effect is as if the attribute were set to the + // value of the font's horiz-adv-x attribute. Glyph widths are required to be non-negative, + // even if the glyph is typically rendered right-to-left, as in Hebrew and Arabic scripts. + identifier.horizontalAdvanceX = parseSVGGlyphAttribute(element, horiz_adv_xAttr); + + // Spec: The X-coordinate in the font coordinate system of the origin of the glyph to be + // used when drawing vertically oriented text. If the attribute is not specified, the effect + // is as if the attribute were set to the value of the font's vert-origin-x attribute. + identifier.verticalOriginX = parseSVGGlyphAttribute(element, vert_origin_xAttr); + + // Spec: The Y-coordinate in the font coordinate system of the origin of a glyph to be + // used when drawing vertically oriented text. If the attribute is not specified, the effect + // is as if the attribute were set to the value of the font's vert-origin-y attribute. + identifier.verticalOriginY = parseSVGGlyphAttribute(element, vert_origin_yAttr); + + // Spec: The vertical advance after rendering a glyph in vertical orientation. + // If the attribute is not specified, the effect is as if the attribute were set to the + // value of the font's vert-adv-y attribute. + identifier.verticalAdvanceY = parseSVGGlyphAttribute(element, vert_adv_yAttr); + + return identifier; +} + +SVGGlyphIdentifier SVGGlyphElement::buildGlyphIdentifier() const +{ + SVGGlyphIdentifier identifier(buildGenericGlyphIdentifier(this)); + identifier.glyphName = getAttribute(glyph_nameAttr); + identifier.orientation = parseOrientation(getAttribute(orientationAttr)); + identifier.arabicForm = parseArabicForm(getAttribute(arabic_formAttr)); + + String language = getAttribute(SVGNames::langAttr); + if (!language.isEmpty()) + identifier.languages = parseDelimitedString(language, ','); + + return identifier; +} + +} + +#endif // ENABLE(SVG_FONTS) diff --git a/Source/WebCore/svg/SVGGlyphElement.h b/Source/WebCore/svg/SVGGlyphElement.h new file mode 100644 index 0000000..4ac5d9b --- /dev/null +++ b/Source/WebCore/svg/SVGGlyphElement.h @@ -0,0 +1,132 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2008 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGGlyphElement_h +#define SVGGlyphElement_h + +#if ENABLE(SVG_FONTS) +#include "Path.h" +#include "SVGStyledElement.h" + +#include <limits> +#include <wtf/Forward.h> + +namespace WebCore { + +class SVGFontData; + +// Describe a SVG <glyph> element +struct SVGGlyphIdentifier { + enum Orientation { + Vertical, + Horizontal, + Both + }; + + // SVG Font depends on exactly this order. + enum ArabicForm { + None = 0, + Isolated, + Terminal, + Initial, + Medial + }; + + SVGGlyphIdentifier() + : isValid(false) + , orientation(Both) + , arabicForm(None) + , priority(0) + , nameLength(0) + , horizontalAdvanceX(0.0f) + , verticalOriginX(0.0f) + , verticalOriginY(0.0f) + , verticalAdvanceY(0.0f) + { + } + + // Used to mark our float properties as "to be inherited from SVGFontData" + static float inheritedValue() + { + static float s_inheritedValue = std::numeric_limits<float>::infinity(); + return s_inheritedValue; + } + + bool operator==(const SVGGlyphIdentifier& other) const + { + return isValid == other.isValid + && orientation == other.orientation + && arabicForm == other.arabicForm + && glyphName == other.glyphName + && horizontalAdvanceX == other.horizontalAdvanceX + && verticalOriginX == other.verticalOriginX + && verticalOriginY == other.verticalOriginY + && verticalAdvanceY == other.verticalAdvanceY + && languages == other.languages; + } + + bool isValid : 1; + + unsigned orientation : 2; // Orientation + unsigned arabicForm : 3; // ArabicForm + int priority; + size_t nameLength; + String glyphName; + + float horizontalAdvanceX; + float verticalOriginX; + float verticalOriginY; + float verticalAdvanceY; + + Path pathData; + Vector<String> languages; +}; + +class SVGGlyphElement : public SVGStyledElement { +public: + static PassRefPtr<SVGGlyphElement> create(const QualifiedName&, Document*); + + SVGGlyphIdentifier buildGlyphIdentifier() const; + + // Helper function used by SVGFont + static void inheritUnspecifiedAttributes(SVGGlyphIdentifier&, const SVGFontData*); + static String querySVGFontLanguage(const SVGElement*); + + // Helper function shared between SVGGlyphElement & SVGMissingGlyphElement + static SVGGlyphIdentifier buildGenericGlyphIdentifier(const SVGElement*); + +private: + SVGGlyphElement(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + + virtual void insertedIntoDocument(); + virtual void removedFromDocument(); + + virtual bool rendererIsNeeded(RenderStyle*) { return false; } + + void invalidateGlyphCache(); +}; + +} // namespace WebCore + +#endif // ENABLE(SVG_FONTS) +#endif diff --git a/Source/WebCore/svg/SVGGlyphElement.idl b/Source/WebCore/svg/SVGGlyphElement.idl new file mode 100644 index 0000000..2d68698 --- /dev/null +++ b/Source/WebCore/svg/SVGGlyphElement.idl @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * + * 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 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 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. + */ + +module svg { + + interface [Conditional=SVG&SVG_FONTS] SVGGlyphElement : SVGElement { + }; + +} diff --git a/Source/WebCore/svg/SVGGlyphMap.h b/Source/WebCore/svg/SVGGlyphMap.h new file mode 100644 index 0000000..5241b2e --- /dev/null +++ b/Source/WebCore/svg/SVGGlyphMap.h @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGGlyphMap_h +#define SVGGlyphMap_h + +#if ENABLE(SVG_FONTS) +#include "SVGGlyphElement.h" + +namespace WebCore { + +struct GlyphMapNode; + +typedef HashMap<UChar, RefPtr<GlyphMapNode> > GlyphMapLayer; + +struct GlyphMapNode : public RefCounted<GlyphMapNode> { +private: + GlyphMapNode() { } +public: + static PassRefPtr<GlyphMapNode> create() { return adoptRef(new GlyphMapNode); } + + Vector<SVGGlyphIdentifier> glyphs; + + GlyphMapLayer children; +}; + +class SVGGlyphMap { + +public: + SVGGlyphMap() : m_currentPriority(0) { } + + void add(const String& string, const SVGGlyphIdentifier& glyph) + { + size_t len = string.length(); + GlyphMapLayer* currentLayer = &m_rootLayer; + + RefPtr<GlyphMapNode> node; + for (size_t i = 0; i < len; ++i) { + UChar curChar = string[i]; + node = currentLayer->get(curChar); + if (!node) { + node = GlyphMapNode::create(); + currentLayer->set(curChar, node); + } + currentLayer = &node->children; + } + + if (node) { + node->glyphs.append(glyph); + node->glyphs.last().priority = m_currentPriority++; + node->glyphs.last().nameLength = len; + node->glyphs.last().isValid = true; + } + } + + static inline bool compareGlyphPriority(const SVGGlyphIdentifier& first, const SVGGlyphIdentifier& second) + { + return first.priority < second.priority; + } + + void get(const String& string, Vector<SVGGlyphIdentifier>& glyphs) + { + GlyphMapLayer* currentLayer = &m_rootLayer; + + for (size_t i = 0; i < string.length(); ++i) { + UChar curChar = string[i]; + RefPtr<GlyphMapNode> node = currentLayer->get(curChar); + if (!node) + break; + glyphs.append(node->glyphs); + currentLayer = &node->children; + } + std::sort(glyphs.begin(), glyphs.end(), compareGlyphPriority); + } + + void clear() + { + m_rootLayer.clear(); + m_currentPriority = 0; + } + +private: + GlyphMapLayer m_rootLayer; + int m_currentPriority; +}; + +} + +#endif // ENABLE(SVG_FONTS) + + +#endif // SVGGlyphMap_h diff --git a/Source/WebCore/svg/SVGGradientElement.cpp b/Source/WebCore/svg/SVGGradientElement.cpp new file mode 100644 index 0000000..f36fea5 --- /dev/null +++ b/Source/WebCore/svg/SVGGradientElement.cpp @@ -0,0 +1,169 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGGradientElement.h" + +#include "Attribute.h" +#include "CSSStyleSelector.h" +#include "RenderSVGHiddenContainer.h" +#include "RenderSVGPath.h" +#include "RenderSVGResourceLinearGradient.h" +#include "RenderSVGResourceRadialGradient.h" +#include "SVGNames.h" +#include "SVGStopElement.h" +#include "SVGTransformList.h" +#include "SVGTransformable.h" +#include "SVGUnitTypes.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_ENUMERATION(SVGGradientElement, SVGNames::spreadMethodAttr, SpreadMethod, spreadMethod) +DEFINE_ANIMATED_ENUMERATION(SVGGradientElement, SVGNames::gradientUnitsAttr, GradientUnits, gradientUnits) +DEFINE_ANIMATED_TRANSFORM_LIST(SVGGradientElement, SVGNames::gradientTransformAttr, GradientTransform, gradientTransform) +DEFINE_ANIMATED_STRING(SVGGradientElement, XLinkNames::hrefAttr, Href, href) +DEFINE_ANIMATED_BOOLEAN(SVGGradientElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) + +SVGGradientElement::SVGGradientElement(const QualifiedName& tagName, Document* document) + : SVGStyledElement(tagName, document) + , m_gradientUnits(SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) +{ +} + +void SVGGradientElement::parseMappedAttribute(Attribute* attr) +{ + if (attr->name() == SVGNames::gradientUnitsAttr) { + if (attr->value() == "userSpaceOnUse") + setGradientUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE); + else if (attr->value() == "objectBoundingBox") + setGradientUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX); + } else if (attr->name() == SVGNames::gradientTransformAttr) { + SVGTransformList newList; + if (!SVGTransformable::parseTransformAttribute(newList, attr->value())) + newList.clear(); + + detachAnimatedGradientTransformListWrappers(newList.size()); + setGradientTransformBaseValue(newList); + } else if (attr->name() == SVGNames::spreadMethodAttr) { + if (attr->value() == "reflect") + setSpreadMethodBaseValue(SpreadMethodReflect); + else if (attr->value() == "repeat") + setSpreadMethodBaseValue(SpreadMethodRepeat); + else if (attr->value() == "pad") + setSpreadMethodBaseValue(SpreadMethodPad); + } else { + if (SVGURIReference::parseMappedAttribute(attr)) + return; + if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) + return; + + SVGStyledElement::parseMappedAttribute(attr); + } +} + +void SVGGradientElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGStyledElement::svgAttributeChanged(attrName); + + RenderObject* object = renderer(); + if (!object) + return; + + if (attrName == SVGNames::gradientUnitsAttr + || attrName == SVGNames::gradientTransformAttr + || attrName == SVGNames::spreadMethodAttr + || SVGURIReference::isKnownAttribute(attrName) + || SVGExternalResourcesRequired::isKnownAttribute(attrName) + || SVGStyledElement::isKnownAttribute(attrName)) + object->setNeedsLayout(true); +} + +void SVGGradientElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGStyledElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeGradientUnits(); + synchronizeGradientTransform(); + synchronizeSpreadMethod(); + synchronizeExternalResourcesRequired(); + synchronizeHref(); + return; + } + + if (attrName == SVGNames::gradientUnitsAttr) + synchronizeGradientUnits(); + else if (attrName == SVGNames::gradientTransformAttr) + synchronizeGradientTransform(); + else if (attrName == SVGNames::spreadMethodAttr) + synchronizeSpreadMethod(); + else if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) + synchronizeExternalResourcesRequired(); + else if (SVGURIReference::isKnownAttribute(attrName)) + synchronizeHref(); +} + +void SVGGradientElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) +{ + SVGStyledElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); + + if (changedByParser) + return; + + if (RenderObject* object = renderer()) + object->setNeedsLayout(true); +} + +Vector<Gradient::ColorStop> SVGGradientElement::buildStops() +{ + Vector<Gradient::ColorStop> stops; + + float previousOffset = 0.0f; + for (Node* n = firstChild(); n; n = n->nextSibling()) { + SVGElement* element = n->isSVGElement() ? static_cast<SVGElement*>(n) : 0; + if (!element || !element->isGradientStop()) + continue; + + SVGStopElement* stop = static_cast<SVGStopElement*>(element); + Color color = stop->stopColorIncludingOpacity(); + + // Figure out right monotonic offset + float offset = stop->offset(); + offset = std::min(std::max(previousOffset, offset), 1.0f); + previousOffset = offset; + + // Extract individual channel values + // FIXME: Why doesn't ColorStop take a Color and an offset?? + float r, g, b, a; + color.getRGBA(r, g, b, a); + + stops.append(Gradient::ColorStop(offset, r, g, b, a)); + } + + return stops; +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGGradientElement.h b/Source/WebCore/svg/SVGGradientElement.h new file mode 100644 index 0000000..1fd1f0b --- /dev/null +++ b/Source/WebCore/svg/SVGGradientElement.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGGradientElement_h +#define SVGGradientElement_h + +#if ENABLE(SVG) +#include "Gradient.h" +#include "SVGAnimatedBoolean.h" +#include "SVGAnimatedEnumeration.h" +#include "SVGAnimatedTransformList.h" +#include "SVGExternalResourcesRequired.h" +#include "SVGStyledElement.h" +#include "SVGURIReference.h" + +namespace WebCore { + +class SVGGradientElement : public SVGStyledElement, + public SVGURIReference, + public SVGExternalResourcesRequired { +public: + Vector<Gradient::ColorStop> buildStops(); + +protected: + SVGGradientElement(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + +private: + virtual bool needsPendingResourceHandling() const { return false; } + + virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); + + // Animated property declarations + DECLARE_ANIMATED_ENUMERATION(SpreadMethod, spreadMethod) + DECLARE_ANIMATED_ENUMERATION(GradientUnits, gradientUnits) + DECLARE_ANIMATED_TRANSFORM_LIST(GradientTransform, gradientTransform) + + // SVGURIReference + DECLARE_ANIMATED_STRING(Href, href) + + // SVGExternalResourcesRequired + DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGGradientElement.idl b/Source/WebCore/svg/SVGGradientElement.idl new file mode 100644 index 0000000..853081f --- /dev/null +++ b/Source/WebCore/svg/SVGGradientElement.idl @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [ + Conditional=SVG, + DontCheckEnums + ] SVGGradientElement : SVGElement, + SVGURIReference, + SVGExternalResourcesRequired, + SVGStylable + /* SVGUnitTypes */ { + // Spread Method Types + const unsigned short SVG_SPREADMETHOD_UNKNOWN = 0; + const unsigned short SVG_SPREADMETHOD_PAD = 1; + const unsigned short SVG_SPREADMETHOD_REFLECT = 2; + const unsigned short SVG_SPREADMETHOD_REPEAT = 3; + + readonly attribute SVGAnimatedEnumeration gradientUnits; + readonly attribute SVGAnimatedTransformList gradientTransform; + readonly attribute SVGAnimatedEnumeration spreadMethod; + }; + +} diff --git a/Source/WebCore/svg/SVGHKernElement.cpp b/Source/WebCore/svg/SVGHKernElement.cpp new file mode 100644 index 0000000..4632378 --- /dev/null +++ b/Source/WebCore/svg/SVGHKernElement.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * Copyright (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2008 Eric Seidel <eric@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG_FONTS) +#include "SVGHKernElement.h" + +#include "SVGFontData.h" +#include "SVGFontElement.h" +#include "SVGFontFaceElement.h" +#include "SVGNames.h" +#include "SimpleFontData.h" +#include "XMLNames.h" + +namespace WebCore { + +using namespace SVGNames; + +inline SVGHKernElement::SVGHKernElement(const QualifiedName& tagName, Document* document) + : SVGElement(tagName, document) +{ +} + +PassRefPtr<SVGHKernElement> SVGHKernElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGHKernElement(tagName, document)); +} + +void SVGHKernElement::insertedIntoDocument() +{ + ContainerNode* fontNode = parentNode(); + if (fontNode && fontNode->hasTagName(SVGNames::fontTag)) { + if (SVGFontElement* element = static_cast<SVGFontElement*>(fontNode)) + element->invalidateGlyphCache(); + } +} + +void SVGHKernElement::removedFromDocument() +{ + ContainerNode* fontNode = parentNode(); + if (fontNode && fontNode->hasTagName(SVGNames::fontTag)) { + if (SVGFontElement* element = static_cast<SVGFontElement*>(fontNode)) + element->invalidateGlyphCache(); + } +} + +void SVGHKernElement::buildHorizontalKerningPair(KerningPairVector& kerningPairs) +{ + String u1 = getAttribute(u1Attr); + String g1 = getAttribute(g1Attr); + String u2 = getAttribute(u2Attr); + String g2 = getAttribute(g2Attr); + if ((u1.isEmpty() && g1.isEmpty()) || (u2.isEmpty() && g2.isEmpty())) + return; + + SVGKerningPair kerningPair; + if (parseGlyphName(g1, kerningPair.glyphName1) + && parseGlyphName(g2, kerningPair.glyphName2) + && parseKerningUnicodeString(u1, kerningPair.unicodeRange1, kerningPair.unicodeName1) + && parseKerningUnicodeString(u2, kerningPair.unicodeRange2, kerningPair.unicodeName2)) { + kerningPair.kerning = getAttribute(kAttr).string().toFloat(); + kerningPairs.append(kerningPair); + } +} + +} + +#endif // ENABLE(SVG_FONTS) diff --git a/Source/WebCore/svg/SVGHKernElement.h b/Source/WebCore/svg/SVGHKernElement.h new file mode 100644 index 0000000..0defcbb --- /dev/null +++ b/Source/WebCore/svg/SVGHKernElement.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGHKernElement_h +#define SVGHKernElement_h + +#if ENABLE(SVG_FONTS) +#include "SVGFontElement.h" + +namespace WebCore { + +class SVGHKernElement : public SVGElement { +public: + static PassRefPtr<SVGHKernElement> create(const QualifiedName&, Document*); + + void buildHorizontalKerningPair(KerningPairVector&); + +private: + SVGHKernElement(const QualifiedName&, Document*); + + virtual void insertedIntoDocument(); + virtual void removedFromDocument(); + + virtual bool rendererIsNeeded(RenderStyle*) { return false; } +}; + +} // namespace WebCore + +#endif // ENABLE(SVG_FONTS) +#endif diff --git a/Source/WebCore/svg/SVGHKernElement.idl b/Source/WebCore/svg/SVGHKernElement.idl new file mode 100644 index 0000000..7e042ff --- /dev/null +++ b/Source/WebCore/svg/SVGHKernElement.idl @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +module svg { + + interface [Conditional=SVG&SVG_FONTS] SVGHKernElement : SVGElement { + }; + +} diff --git a/Source/WebCore/svg/SVGImageElement.cpp b/Source/WebCore/svg/SVGImageElement.cpp new file mode 100644 index 0000000..80bf34b --- /dev/null +++ b/Source/WebCore/svg/SVGImageElement.cpp @@ -0,0 +1,226 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Rob Buis <buis@kde.org> + * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGImageElement.h" + +#include "Attribute.h" +#include "CSSPropertyNames.h" +#include "RenderImageResource.h" +#include "RenderSVGImage.h" +#include "RenderSVGResource.h" +#include "SVGNames.h" +#include "SVGSVGElement.h" +#include "XLinkNames.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_LENGTH(SVGImageElement, SVGNames::xAttr, X, x) +DEFINE_ANIMATED_LENGTH(SVGImageElement, SVGNames::yAttr, Y, y) +DEFINE_ANIMATED_LENGTH(SVGImageElement, SVGNames::widthAttr, Width, width) +DEFINE_ANIMATED_LENGTH(SVGImageElement, SVGNames::heightAttr, Height, height) +DEFINE_ANIMATED_PRESERVEASPECTRATIO(SVGImageElement, SVGNames::preserveAspectRatioAttr, PreserveAspectRatio, preserveAspectRatio) +DEFINE_ANIMATED_STRING(SVGImageElement, XLinkNames::hrefAttr, Href, href) +DEFINE_ANIMATED_BOOLEAN(SVGImageElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) + +inline SVGImageElement::SVGImageElement(const QualifiedName& tagName, Document* document) + : SVGStyledTransformableElement(tagName, document) + , m_x(LengthModeWidth) + , m_y(LengthModeHeight) + , m_width(LengthModeWidth) + , m_height(LengthModeHeight) + , m_imageLoader(this) +{ +} + +PassRefPtr<SVGImageElement> SVGImageElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGImageElement(tagName, document)); +} + +void SVGImageElement::parseMappedAttribute(Attribute* attr) +{ + if (attr->name() == SVGNames::xAttr) + setXBaseValue(SVGLength(LengthModeWidth, attr->value())); + else if (attr->name() == SVGNames::yAttr) + setYBaseValue(SVGLength(LengthModeHeight, attr->value())); + else if (attr->name() == SVGNames::preserveAspectRatioAttr) + SVGPreserveAspectRatio::parsePreserveAspectRatio(this, attr->value()); + else if (attr->name() == SVGNames::widthAttr) { + setWidthBaseValue(SVGLength(LengthModeWidth, attr->value())); + addCSSProperty(attr, CSSPropertyWidth, attr->value()); + if (widthBaseValue().value(this) < 0.0) + document()->accessSVGExtensions()->reportError("A negative value for image attribute <width> is not allowed"); + } else if (attr->name() == SVGNames::heightAttr) { + setHeightBaseValue(SVGLength(LengthModeHeight, attr->value())); + addCSSProperty(attr, CSSPropertyHeight, attr->value()); + if (heightBaseValue().value(this) < 0.0) + document()->accessSVGExtensions()->reportError("A negative value for image attribute <height> is not allowed"); + } else { + if (SVGTests::parseMappedAttribute(attr)) + return; + if (SVGLangSpace::parseMappedAttribute(attr)) + return; + if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) + return; + if (SVGURIReference::parseMappedAttribute(attr)) + return; + SVGStyledTransformableElement::parseMappedAttribute(attr); + } +} + +void SVGImageElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGStyledTransformableElement::svgAttributeChanged(attrName); + + if (SVGURIReference::isKnownAttribute(attrName)) + m_imageLoader.updateFromElementIgnoringPreviousError(); + + bool isLengthAttribute = attrName == SVGNames::xAttr + || attrName == SVGNames::yAttr + || attrName == SVGNames::widthAttr + || attrName == SVGNames::heightAttr; + + if (isLengthAttribute) + updateRelativeLengthsInformation(); + + if (SVGTests::handleAttributeChange(this, attrName)) + return; + + RenderObject* renderer = this->renderer(); + if (!renderer) + return; + + if (SVGStyledTransformableElement::isKnownAttribute(attrName)) { + renderer->setNeedsTransformUpdate(); + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); + return; + } + + if (isLengthAttribute) { + renderer->updateFromElement(); + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer, false); + return; + } + + if (attrName == SVGNames::preserveAspectRatioAttr + || SVGLangSpace::isKnownAttribute(attrName) + || SVGExternalResourcesRequired::isKnownAttribute(attrName)) + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); +} + +void SVGImageElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGStyledTransformableElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeX(); + synchronizeY(); + synchronizeWidth(); + synchronizeHeight(); + synchronizePreserveAspectRatio(); + synchronizeExternalResourcesRequired(); + synchronizeHref(); + SVGTests::synchronizeProperties(this, attrName); + return; + } + + if (attrName == SVGNames::xAttr) + synchronizeX(); + else if (attrName == SVGNames::yAttr) + synchronizeY(); + else if (attrName == SVGNames::widthAttr) + synchronizeWidth(); + else if (attrName == SVGNames::heightAttr) + synchronizeHeight(); + else if (attrName == SVGNames::preserveAspectRatioAttr) + synchronizePreserveAspectRatio(); + else if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) + synchronizeExternalResourcesRequired(); + else if (SVGURIReference::isKnownAttribute(attrName)) + synchronizeHref(); + else if (SVGTests::isKnownAttribute(attrName)) + SVGTests::synchronizeProperties(this, attrName); +} + +bool SVGImageElement::selfHasRelativeLengths() const +{ + return x().isRelative() + || y().isRelative() + || width().isRelative() + || height().isRelative(); +} + +RenderObject* SVGImageElement::createRenderer(RenderArena* arena, RenderStyle*) +{ + return new (arena) RenderSVGImage(this); +} + +bool SVGImageElement::haveLoadedRequiredResources() +{ + return !externalResourcesRequiredBaseValue() || m_imageLoader.haveFiredLoadEvent(); +} + +void SVGImageElement::attach() +{ + SVGStyledTransformableElement::attach(); + + if (RenderSVGImage* imageObj = toRenderSVGImage(renderer())) { + if (imageObj->imageResource()->hasImage()) + return; + + imageObj->imageResource()->setCachedImage(m_imageLoader.image()); + } +} + +void SVGImageElement::insertedIntoDocument() +{ + SVGStyledTransformableElement::insertedIntoDocument(); + + // Update image loader, as soon as we're living in the tree. + // We can only resolve base URIs properly, after that! + m_imageLoader.updateFromElement(); +} + +const QualifiedName& SVGImageElement::imageSourceAttributeName() const +{ + return XLinkNames::hrefAttr; +} + +void SVGImageElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const +{ + SVGStyledTransformableElement::addSubresourceAttributeURLs(urls); + + addSubresourceURL(urls, document()->completeURL(href())); +} + +void SVGImageElement::willMoveToNewOwnerDocument() +{ + m_imageLoader.elementWillMoveToNewOwnerDocument(); + SVGStyledTransformableElement::willMoveToNewOwnerDocument(); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGImageElement.h b/Source/WebCore/svg/SVGImageElement.h new file mode 100644 index 0000000..06e6490 --- /dev/null +++ b/Source/WebCore/svg/SVGImageElement.h @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGImageElement_h +#define SVGImageElement_h + +#if ENABLE(SVG) +#include "SVGAnimatedBoolean.h" +#include "SVGAnimatedLength.h" +#include "SVGAnimatedPreserveAspectRatio.h" +#include "SVGExternalResourcesRequired.h" +#include "SVGImageLoader.h" +#include "SVGLangSpace.h" +#include "SVGStyledTransformableElement.h" +#include "SVGTests.h" +#include "SVGURIReference.h" + +namespace WebCore { + +class SVGImageElement : public SVGStyledTransformableElement, + public SVGTests, + public SVGLangSpace, + public SVGExternalResourcesRequired, + public SVGURIReference { +public: + static PassRefPtr<SVGImageElement> create(const QualifiedName&, Document*); + +private: + SVGImageElement(const QualifiedName&, Document*); + + virtual bool isValid() const { return SVGTests::isValid(); } + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + + virtual void attach(); + virtual void insertedIntoDocument(); + + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + + virtual const QualifiedName& imageSourceAttributeName() const; + virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const; + + virtual bool haveLoadedRequiredResources(); + + virtual bool selfHasRelativeLengths() const; + virtual void willMoveToNewOwnerDocument(); + + // Animated property declarations + DECLARE_ANIMATED_LENGTH(X, x) + DECLARE_ANIMATED_LENGTH(Y, y) + DECLARE_ANIMATED_LENGTH(Width, width) + DECLARE_ANIMATED_LENGTH(Height, height) + DECLARE_ANIMATED_PRESERVEASPECTRATIO(PreserveAspectRatio, preserveAspectRatio) + + // SVGURIReference + DECLARE_ANIMATED_STRING(Href, href) + + // SVGExternalResourcesRequired + DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) + + SVGImageLoader m_imageLoader; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGImageElement.idl b/Source/WebCore/svg/SVGImageElement.idl new file mode 100644 index 0000000..5ea8671 --- /dev/null +++ b/Source/WebCore/svg/SVGImageElement.idl @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGImageElement : SVGElement, + SVGURIReference, + SVGTests, + SVGLangSpace, + SVGExternalResourcesRequired, + SVGStylable, + SVGTransformable { + readonly attribute SVGAnimatedLength x; + readonly attribute SVGAnimatedLength y; + readonly attribute SVGAnimatedLength width; + readonly attribute SVGAnimatedLength height; + readonly attribute SVGAnimatedPreserveAspectRatio preserveAspectRatio; + }; + +} diff --git a/Source/WebCore/svg/SVGImageLoader.cpp b/Source/WebCore/svg/SVGImageLoader.cpp new file mode 100644 index 0000000..17e9004 --- /dev/null +++ b/Source/WebCore/svg/SVGImageLoader.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2005, 2005 Alexander Kellett <lypanov@kde.org> + * Copyright (C) 2008 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGImageLoader.h" + +#include "Event.h" +#include "EventNames.h" +#include "HTMLParserIdioms.h" +#include "RenderImage.h" +#include "SVGImageElement.h" + +namespace WebCore { + +SVGImageLoader::SVGImageLoader(SVGImageElement* node) + : ImageLoader(node) +{ +} + +void SVGImageLoader::dispatchLoadEvent() +{ + if (image()->errorOccurred()) + element()->dispatchEvent(Event::create(eventNames().errorEvent, false, false)); + else { + SVGImageElement* imageElement = static_cast<SVGImageElement*>(element()); + if (imageElement->externalResourcesRequiredBaseValue()) + imageElement->sendSVGLoadEventIfPossible(true); + } +} + +String SVGImageLoader::sourceURI(const AtomicString& attr) const +{ + return KURL(element()->baseURI(), stripLeadingAndTrailingHTMLSpaces(attr)).string(); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGImageLoader.h b/Source/WebCore/svg/SVGImageLoader.h new file mode 100644 index 0000000..b7a1617 --- /dev/null +++ b/Source/WebCore/svg/SVGImageLoader.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGImageLoader_h +#define SVGImageLoader_h + +#if ENABLE(SVG) +#include "ImageLoader.h" + +namespace WebCore { + +class SVGImageElement; + +class SVGImageLoader : public ImageLoader { +public: + SVGImageLoader(SVGImageElement*); + +private: + virtual void dispatchLoadEvent(); + virtual String sourceURI(const AtomicString&) const; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGImageLoader_h diff --git a/Source/WebCore/svg/SVGLangSpace.cpp b/Source/WebCore/svg/SVGLangSpace.cpp new file mode 100644 index 0000000..73a52e9 --- /dev/null +++ b/Source/WebCore/svg/SVGLangSpace.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGLangSpace.h" + +#include "Attribute.h" +#include "SVGElement.h" +#include "XMLNames.h" +#include <wtf/StdLibExtras.h> + +namespace WebCore { + +void SVGLangSpace::setXmllang(const AtomicString& xmlLang) +{ + m_lang = xmlLang; +} + +const AtomicString& SVGLangSpace::xmlspace() const +{ + if (!m_space) { + DEFINE_STATIC_LOCAL(const AtomicString, defaultString, ("default")); + return defaultString; + } + + return m_space; +} + +void SVGLangSpace::setXmlspace(const AtomicString& xmlSpace) +{ + m_space = xmlSpace; +} + +bool SVGLangSpace::parseMappedAttribute(Attribute* attr) +{ + if (attr->name().matches(XMLNames::langAttr)) { + setXmllang(attr->value()); + return true; + } + if (attr->name().matches(XMLNames::spaceAttr)) { + setXmlspace(attr->value()); + return true; + } + + return false; +} + +bool SVGLangSpace::isKnownAttribute(const QualifiedName& attrName) +{ + return attrName.matches(XMLNames::langAttr) || attrName.matches(XMLNames::spaceAttr); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGLangSpace.h b/Source/WebCore/svg/SVGLangSpace.h new file mode 100644 index 0000000..61c6edf --- /dev/null +++ b/Source/WebCore/svg/SVGLangSpace.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGLangSpace_h +#define SVGLangSpace_h + +#if ENABLE(SVG) +#include <wtf/text/AtomicString.h> + +namespace WebCore { + +class Attribute; +class QualifiedName; + +class SVGLangSpace { +public: + const AtomicString& xmllang() const { return m_lang; } + void setXmllang(const AtomicString& xmlLang); + + const AtomicString& xmlspace() const; + void setXmlspace(const AtomicString& xmlSpace); + + bool parseMappedAttribute(Attribute*); + bool isKnownAttribute(const QualifiedName&); + +private: + AtomicString m_lang; + AtomicString m_space; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGLangSpace_h diff --git a/Source/WebCore/svg/SVGLangSpace.idl b/Source/WebCore/svg/SVGLangSpace.idl new file mode 100644 index 0000000..a62b49b --- /dev/null +++ b/Source/WebCore/svg/SVGLangSpace.idl @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG, ObjCProtocol, OmitConstructor] SVGLangSpace { + attribute DOMString xmllang + /*setter raises(DOMException)*/; + attribute DOMString xmlspace + /*setter raises(DOMException)*/; + }; + +} diff --git a/Source/WebCore/svg/SVGLength.cpp b/Source/WebCore/svg/SVGLength.cpp new file mode 100644 index 0000000..6d75f8b --- /dev/null +++ b/Source/WebCore/svg/SVGLength.cpp @@ -0,0 +1,560 @@ +/* + * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * Copyright (C) 2007 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGLength.h" + +#include "CSSHelper.h" +#include "FloatConversion.h" +#include "FrameView.h" +#include "RenderObject.h" +#include "RenderView.h" +#include "SVGNames.h" +#include "SVGParserUtilities.h" +#include "SVGSVGElement.h" + +#include <wtf/MathExtras.h> +#include <wtf/text/StringConcatenate.h> + +namespace WebCore { + +// Helper functions +static inline unsigned int storeUnit(SVGLengthMode mode, SVGLengthType type) +{ + return (mode << 4) | type; +} + +static inline SVGLengthMode extractMode(unsigned int unit) +{ + unsigned int mode = unit >> 4; + return static_cast<SVGLengthMode>(mode); +} + +static inline SVGLengthType extractType(unsigned int unit) +{ + unsigned int mode = unit >> 4; + unsigned int type = unit ^ (mode << 4); + return static_cast<SVGLengthType>(type); +} + +static inline String lengthTypeToString(SVGLengthType type) +{ + switch (type) { + case LengthTypeUnknown: + case LengthTypeNumber: + return ""; + case LengthTypePercentage: + return "%"; + case LengthTypeEMS: + return "em"; + case LengthTypeEXS: + return "ex"; + case LengthTypePX: + return "px"; + case LengthTypeCM: + return "cm"; + case LengthTypeMM: + return "mm"; + case LengthTypeIN: + return "in"; + case LengthTypePT: + return "pt"; + case LengthTypePC: + return "pc"; + } + + ASSERT_NOT_REACHED(); + return String(); +} + +inline SVGLengthType stringToLengthType(const UChar*& ptr, const UChar* end) +{ + if (ptr == end) + return LengthTypeNumber; + + const UChar firstChar = *ptr; + + if (++ptr == end) + return firstChar == '%' ? LengthTypePercentage : LengthTypeUnknown; + + const UChar secondChar = *ptr; + + if (++ptr != end) + return LengthTypeUnknown; + + if (firstChar == 'e' && secondChar == 'm') + return LengthTypeEMS; + if (firstChar == 'e' && secondChar == 'x') + return LengthTypeEXS; + if (firstChar == 'p' && secondChar == 'x') + return LengthTypePX; + if (firstChar == 'c' && secondChar == 'm') + return LengthTypeCM; + if (firstChar == 'm' && secondChar == 'm') + return LengthTypeMM; + if (firstChar == 'i' && secondChar == 'n') + return LengthTypeIN; + if (firstChar == 'p' && secondChar == 't') + return LengthTypePT; + if (firstChar == 'p' && secondChar == 'c') + return LengthTypePC; + + return LengthTypeUnknown; +} + +SVGLength::SVGLength(SVGLengthMode mode, const String& valueAsString) + : m_valueInSpecifiedUnits(0) + , m_unit(storeUnit(mode, LengthTypeNumber)) +{ + ExceptionCode ec = 0; + setValueAsString(valueAsString, ec); +} + +SVGLength::SVGLength(const SVGLength& other) + : m_valueInSpecifiedUnits(other.m_valueInSpecifiedUnits) + , m_unit(other.m_unit) +{ +} + +bool SVGLength::operator==(const SVGLength& other) const +{ + return m_unit == other.m_unit + && m_valueInSpecifiedUnits == other.m_valueInSpecifiedUnits; +} + +bool SVGLength::operator!=(const SVGLength& other) const +{ + return !operator==(other); +} + +SVGLengthType SVGLength::unitType() const +{ + return extractType(m_unit); +} + +float SVGLength::value(const SVGElement* context) const +{ + ExceptionCode ec = 0; + return value(context, ec); +} + +float SVGLength::value(const SVGElement* context, ExceptionCode& ec) const +{ + switch (extractType(m_unit)) { + case LengthTypeUnknown: + ec = NOT_SUPPORTED_ERR; + return 0; + case LengthTypeNumber: + return m_valueInSpecifiedUnits; + case LengthTypePercentage: + return convertValueFromPercentageToUserUnits(m_valueInSpecifiedUnits / 100, context, ec); + case LengthTypeEMS: + return convertValueFromEMSToUserUnits(m_valueInSpecifiedUnits, context, ec); + case LengthTypeEXS: + return convertValueFromEXSToUserUnits(m_valueInSpecifiedUnits, context, ec); + case LengthTypePX: + return m_valueInSpecifiedUnits; + case LengthTypeCM: + return m_valueInSpecifiedUnits / 2.54f * cssPixelsPerInch; + case LengthTypeMM: + return m_valueInSpecifiedUnits / 25.4f * cssPixelsPerInch; + case LengthTypeIN: + return m_valueInSpecifiedUnits * cssPixelsPerInch; + case LengthTypePT: + return m_valueInSpecifiedUnits / 72 * cssPixelsPerInch; + case LengthTypePC: + return m_valueInSpecifiedUnits / 6 * cssPixelsPerInch; + } + + ASSERT_NOT_REACHED(); + return 0; +} + +void SVGLength::setValue(float value, const SVGElement* context, ExceptionCode& ec) +{ + switch (extractType(m_unit)) { + case LengthTypeUnknown: + ec = NOT_SUPPORTED_ERR; + break; + case LengthTypeNumber: + m_valueInSpecifiedUnits = value; + break; + case LengthTypePercentage: { + float result = convertValueFromUserUnitsToPercentage(value, context, ec); + if (!ec) + m_valueInSpecifiedUnits = result; + break; + } + case LengthTypeEMS: { + float result = convertValueFromUserUnitsToEMS(value, context, ec); + if (!ec) + m_valueInSpecifiedUnits = result; + break; + } + case LengthTypeEXS: { + float result = convertValueFromUserUnitsToEXS(value, context, ec); + if (!ec) + m_valueInSpecifiedUnits = result; + break; + } + case LengthTypePX: + m_valueInSpecifiedUnits = value; + break; + case LengthTypeCM: + m_valueInSpecifiedUnits = value * 2.54f / cssPixelsPerInch; + break; + case LengthTypeMM: + m_valueInSpecifiedUnits = value * 25.4f / cssPixelsPerInch; + break; + case LengthTypeIN: + m_valueInSpecifiedUnits = value / cssPixelsPerInch; + break; + case LengthTypePT: + m_valueInSpecifiedUnits = value * 72 / cssPixelsPerInch; + break; + case LengthTypePC: + m_valueInSpecifiedUnits = value * 6 / cssPixelsPerInch; + break; + } +} + +float SVGLength::valueAsPercentage() const +{ + // 100% = 100.0 instead of 1.0 for historical reasons, this could eventually be changed + if (extractType(m_unit) == LengthTypePercentage) + return m_valueInSpecifiedUnits / 100; + + return m_valueInSpecifiedUnits; +} + +void SVGLength::setValueAsString(const String& string, ExceptionCode& ec) +{ + if (string.isEmpty()) + return; + + float convertedNumber = 0; + const UChar* ptr = string.characters(); + const UChar* end = ptr + string.length(); + + if (!parseNumber(ptr, end, convertedNumber, false)) { + ec = SYNTAX_ERR; + return; + } + + SVGLengthType type = stringToLengthType(ptr, end); + ASSERT(ptr <= end); + if (type == LengthTypeUnknown) { + ec = SYNTAX_ERR; + return; + } + + m_unit = storeUnit(extractMode(m_unit), type); + m_valueInSpecifiedUnits = convertedNumber; +} + +String SVGLength::valueAsString() const +{ + return makeString(String::number(m_valueInSpecifiedUnits), lengthTypeToString(extractType(m_unit))); +} + +void SVGLength::newValueSpecifiedUnits(unsigned short type, float value, ExceptionCode& ec) +{ + if (type == LengthTypeUnknown || type > LengthTypePC) { + ec = NOT_SUPPORTED_ERR; + return; + } + + m_unit = storeUnit(extractMode(m_unit), static_cast<SVGLengthType>(type)); + m_valueInSpecifiedUnits = value; +} + +void SVGLength::convertToSpecifiedUnits(unsigned short type, const SVGElement* context, ExceptionCode& ec) +{ + if (type == LengthTypeUnknown || type > LengthTypePC) { + ec = NOT_SUPPORTED_ERR; + return; + } + + float valueInUserUnits = value(context, ec); + if (ec) + return; + + unsigned int originalUnitAndType = m_unit; + m_unit = storeUnit(extractMode(m_unit), static_cast<SVGLengthType>(type)); + setValue(valueInUserUnits, context, ec); + if (!ec) + return; + + // Eventually restore old unit and type + m_unit = originalUnitAndType; +} + +bool SVGLength::determineViewport(const SVGElement* context, float& width, float& height) const +{ + if (!context) + return false; + + // Take size from outermost <svg> element. + Document* document = context->document(); + if (document->documentElement() == context) { + if (RenderView* view = toRenderView(document->renderer())) { + width = view->viewWidth(); + height = view->viewHeight(); + return true; + } + + return false; + } + + // Resolve value against nearest viewport element (common case: inner <svg> elements) + SVGElement* viewportElement = context->viewportElement(); + if (viewportElement && viewportElement->isSVG()) { + const SVGSVGElement* svg = static_cast<const SVGSVGElement*>(viewportElement); + if (svg->hasAttribute(SVGNames::viewBoxAttr)) { + width = svg->viewBox().width(); + height = svg->viewBox().height(); + } else { + width = svg->width().value(svg); + height = svg->height().value(svg); + } + + return true; + } + + // Resolve value against enclosing non-SVG RenderBox + if (!context->parentNode() || context->parentNode()->isSVGElement()) + return false; + + RenderObject* renderer = context->renderer(); + if (!renderer || !renderer->isBox()) + return false; + + RenderBox* box = toRenderBox(renderer); + width = box->width(); + height = box->height(); + return true; +} + +float SVGLength::convertValueFromUserUnitsToPercentage(float value, const SVGElement* context, ExceptionCode& ec) const +{ + float width = 0; + float height = 0; + if (!determineViewport(context, width, height)) { + ec = NOT_SUPPORTED_ERR; + return 0; + } + + switch (extractMode(m_unit)) { + case LengthModeWidth: + return value / width * 100; + case LengthModeHeight: + return value / height * 100; + case LengthModeOther: + return value / (sqrtf((width * width + height * height) / 2)) * 100; + }; + + ASSERT_NOT_REACHED(); + return 0; +} + +float SVGLength::convertValueFromPercentageToUserUnits(float value, const SVGElement* context, ExceptionCode& ec) const +{ + float width = 0; + float height = 0; + if (!determineViewport(context, width, height)) { + ec = NOT_SUPPORTED_ERR; + return 0; + } + + switch (extractMode(m_unit)) { + case LengthModeWidth: + return value * width; + case LengthModeHeight: + return value * height; + case LengthModeOther: + return value * sqrtf((width * width + height * height) / 2); + }; + + ASSERT_NOT_REACHED(); + return 0; +} + +float SVGLength::convertValueFromUserUnitsToEMS(float value, const SVGElement* context, ExceptionCode& ec) const +{ + if (!context || !context->renderer() || !context->renderer()->style()) { + ec = NOT_SUPPORTED_ERR; + return 0; + } + + RenderStyle* style = context->renderer()->style(); + float fontSize = style->fontSize(); + if (!fontSize) { + ec = NOT_SUPPORTED_ERR; + return 0; + } + + return value / fontSize; +} + +float SVGLength::convertValueFromEMSToUserUnits(float value, const SVGElement* context, ExceptionCode& ec) const +{ + if (!context || !context->renderer() || !context->renderer()->style()) { + ec = NOT_SUPPORTED_ERR; + return 0; + } + + RenderStyle* style = context->renderer()->style(); + return value * style->fontSize(); +} + +float SVGLength::convertValueFromUserUnitsToEXS(float value, const SVGElement* context, ExceptionCode& ec) const +{ + if (!context || !context->renderer() || !context->renderer()->style()) { + ec = NOT_SUPPORTED_ERR; + return 0; + } + + RenderStyle* style = context->renderer()->style(); + + // Use of ceil allows a pixel match to the W3Cs expected output of coords-units-03-b.svg + // if this causes problems in real world cases maybe it would be best to remove this + float xHeight = ceilf(style->font().xHeight()); + if (!xHeight) { + ec = NOT_SUPPORTED_ERR; + return 0; + } + + return value / xHeight; +} + +float SVGLength::convertValueFromEXSToUserUnits(float value, const SVGElement* context, ExceptionCode& ec) const +{ + if (!context || !context->renderer() || !context->renderer()->style()) { + ec = NOT_SUPPORTED_ERR; + return 0; + } + + RenderStyle* style = context->renderer()->style(); + // Use of ceil allows a pixel match to the W3Cs expected output of coords-units-03-b.svg + // if this causes problems in real world cases maybe it would be best to remove this + return value * ceilf(style->font().xHeight()); +} + +SVGLength SVGLength::fromCSSPrimitiveValue(CSSPrimitiveValue* value) +{ + ASSERT(value); + + SVGLengthType svgType; + switch (value->primitiveType()) { + case CSSPrimitiveValue::CSS_NUMBER: + svgType = LengthTypeNumber; + break; + case CSSPrimitiveValue::CSS_PERCENTAGE: + svgType = LengthTypePercentage; + break; + case CSSPrimitiveValue::CSS_EMS: + svgType = LengthTypeEMS; + break; + case CSSPrimitiveValue::CSS_EXS: + svgType = LengthTypeEXS; + break; + case CSSPrimitiveValue::CSS_PX: + svgType = LengthTypePX; + break; + case CSSPrimitiveValue::CSS_CM: + svgType = LengthTypeCM; + break; + case CSSPrimitiveValue::CSS_MM: + svgType = LengthTypeMM; + break; + case CSSPrimitiveValue::CSS_IN: + svgType = LengthTypeIN; + break; + case CSSPrimitiveValue::CSS_PT: + svgType = LengthTypePT; + break; + case CSSPrimitiveValue::CSS_PC: + svgType = LengthTypePC; + break; + case CSSPrimitiveValue::CSS_UNKNOWN: + default: + svgType = LengthTypeUnknown; + break; + }; + + if (svgType == LengthTypeUnknown) + return SVGLength(); + + ExceptionCode ec = 0; + SVGLength length; + length.newValueSpecifiedUnits(svgType, value->getFloatValue(), ec); + if (ec) + return SVGLength(); + + return length; +} + +PassRefPtr<CSSPrimitiveValue> SVGLength::toCSSPrimitiveValue(const SVGLength& length) +{ + CSSPrimitiveValue::UnitTypes cssType = CSSPrimitiveValue::CSS_UNKNOWN; + switch (length.unitType()) { + case LengthTypeUnknown: + break; + case LengthTypeNumber: + cssType = CSSPrimitiveValue::CSS_NUMBER; + break; + case LengthTypePercentage: + cssType = CSSPrimitiveValue::CSS_PERCENTAGE; + break; + case LengthTypeEMS: + cssType = CSSPrimitiveValue::CSS_EMS; + break; + case LengthTypeEXS: + cssType = CSSPrimitiveValue::CSS_EXS; + break; + case LengthTypePX: + cssType = CSSPrimitiveValue::CSS_PX; + break; + case LengthTypeCM: + cssType = CSSPrimitiveValue::CSS_CM; + break; + case LengthTypeMM: + cssType = CSSPrimitiveValue::CSS_MM; + break; + case LengthTypeIN: + cssType = CSSPrimitiveValue::CSS_IN; + break; + case LengthTypePT: + cssType = CSSPrimitiveValue::CSS_PT; + break; + case LengthTypePC: + cssType = CSSPrimitiveValue::CSS_PC; + break; + }; + + return CSSPrimitiveValue::create(length.valueInSpecifiedUnits(), cssType); +} + +} + +#endif diff --git a/Source/WebCore/svg/SVGLength.h b/Source/WebCore/svg/SVGLength.h new file mode 100644 index 0000000..a256ed3 --- /dev/null +++ b/Source/WebCore/svg/SVGLength.h @@ -0,0 +1,131 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGLength_h +#define SVGLength_h + +#if ENABLE(SVG) +#include "ExceptionCode.h" +#include "SVGPropertyTraits.h" + +namespace WebCore { + +class CSSPrimitiveValue; + +enum SVGLengthType { + LengthTypeUnknown = 0, + LengthTypeNumber = 1, + LengthTypePercentage = 2, + LengthTypeEMS = 3, + LengthTypeEXS = 4, + LengthTypePX = 5, + LengthTypeCM = 6, + LengthTypeMM = 7, + LengthTypeIN = 8, + LengthTypePT = 9, + LengthTypePC = 10 +}; + +enum SVGLengthMode { + LengthModeWidth = 0, + LengthModeHeight, + LengthModeOther +}; + +class SVGElement; + +class SVGLength { +public: + // Forward declare these enums in the w3c naming scheme, for IDL generation + enum { + SVG_LENGTHTYPE_UNKNOWN = LengthTypeUnknown, + SVG_LENGTHTYPE_NUMBER = LengthTypeNumber, + SVG_LENGTHTYPE_PERCENTAGE = LengthTypePercentage, + SVG_LENGTHTYPE_EMS = LengthTypeEMS, + SVG_LENGTHTYPE_EXS = LengthTypeEXS, + SVG_LENGTHTYPE_PX = LengthTypePX, + SVG_LENGTHTYPE_CM = LengthTypeCM, + SVG_LENGTHTYPE_MM = LengthTypeMM, + SVG_LENGTHTYPE_IN = LengthTypeIN, + SVG_LENGTHTYPE_PT = LengthTypePT, + SVG_LENGTHTYPE_PC = LengthTypePC + }; + + SVGLength(SVGLengthMode mode = LengthModeOther, const String& valueAsString = String()); + SVGLength(const SVGLength&); + + SVGLengthType unitType() const; + + bool operator==(const SVGLength&) const; + bool operator!=(const SVGLength&) const; + + float value(const SVGElement* context) const; + float value(const SVGElement* context, ExceptionCode&) const; + void setValue(float, const SVGElement* context, ExceptionCode&); + + float valueInSpecifiedUnits() const { return m_valueInSpecifiedUnits; } + void setValueInSpecifiedUnits(float value) { m_valueInSpecifiedUnits = value; } + + float valueAsPercentage() const; + + String valueAsString() const; + void setValueAsString(const String&, ExceptionCode&); + + void newValueSpecifiedUnits(unsigned short, float valueInSpecifiedUnits, ExceptionCode&); + void convertToSpecifiedUnits(unsigned short, const SVGElement* context, ExceptionCode&); + + // Helper functions + inline bool isRelative() const + { + SVGLengthType type = unitType(); + return type == LengthTypePercentage || type == LengthTypeEMS || type == LengthTypeEXS; + } + + static SVGLength fromCSSPrimitiveValue(CSSPrimitiveValue*); + static PassRefPtr<CSSPrimitiveValue> toCSSPrimitiveValue(const SVGLength&); + +private: + bool determineViewport(const SVGElement* context, float& width, float& height) const; + + float convertValueFromPercentageToUserUnits(float value, const SVGElement* context, ExceptionCode&) const; + float convertValueFromUserUnitsToPercentage(float value, const SVGElement* context, ExceptionCode&) const; + + float convertValueFromUserUnitsToEMS(float value, const SVGElement* context, ExceptionCode&) const; + float convertValueFromEMSToUserUnits(float value, const SVGElement* context, ExceptionCode&) const; + + float convertValueFromUserUnitsToEXS(float value, const SVGElement* context, ExceptionCode&) const; + float convertValueFromEXSToUserUnits(float value, const SVGElement* context, ExceptionCode&) const; + +private: + float m_valueInSpecifiedUnits; + unsigned int m_unit; +}; + +template<> +struct SVGPropertyTraits<SVGLength> { + static SVGLength initialValue() { return SVGLength(); } + static String toString(const SVGLength& type) { return type.valueAsString(); } +}; + + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGLength_h diff --git a/Source/WebCore/svg/SVGLength.idl b/Source/WebCore/svg/SVGLength.idl new file mode 100644 index 0000000..0e6807f --- /dev/null +++ b/Source/WebCore/svg/SVGLength.idl @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) 2006 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +module svg { + + interface [Conditional=SVG] SVGLength { + // Length Unit Types + const unsigned short SVG_LENGTHTYPE_UNKNOWN = 0; + const unsigned short SVG_LENGTHTYPE_NUMBER = 1; + const unsigned short SVG_LENGTHTYPE_PERCENTAGE = 2; + const unsigned short SVG_LENGTHTYPE_EMS = 3; + const unsigned short SVG_LENGTHTYPE_EXS = 4; + const unsigned short SVG_LENGTHTYPE_PX = 5; + const unsigned short SVG_LENGTHTYPE_CM = 6; + const unsigned short SVG_LENGTHTYPE_MM = 7; + const unsigned short SVG_LENGTHTYPE_IN = 8; + const unsigned short SVG_LENGTHTYPE_PT = 9; + const unsigned short SVG_LENGTHTYPE_PC = 10; + + readonly attribute unsigned short unitType; + attribute [Custom, StrictTypeChecking] float value + setter raises(DOMException), + getter raises(DOMException); + + attribute [StrictTypeChecking] float valueInSpecifiedUnits; + attribute [ConvertNullToNullString, StrictTypeChecking] DOMString valueAsString + setter raises(DOMException); + + [StrictTypeChecking, RequiresAllArguments=Raise] void newValueSpecifiedUnits(in unsigned short unitType, + in float valueInSpecifiedUnits) + raises(DOMException); + + [Custom, StrictTypeChecking, RequiresAllArguments=Raise] void convertToSpecifiedUnits(in unsigned short unitType) + raises(DOMException); + }; + +} diff --git a/Source/WebCore/svg/SVGLengthList.cpp b/Source/WebCore/svg/SVGLengthList.cpp new file mode 100644 index 0000000..d2e8fbb --- /dev/null +++ b/Source/WebCore/svg/SVGLengthList.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGLengthList.h" + +#include "SVGParserUtilities.h" +#include <wtf/text/StringBuilder.h> + +namespace WebCore { + +void SVGLengthList::parse(const String& value, SVGLengthMode mode) +{ + clear(); + ExceptionCode ec = 0; + + const UChar* ptr = value.characters(); + const UChar* end = ptr + value.length(); + while (ptr < end) { + const UChar* start = ptr; + while (ptr < end && *ptr != ',' && !isWhitespace(*ptr)) + ptr++; + if (ptr == start) + break; + + SVGLength length(mode); + String valueString(start, ptr - start); + if (valueString.isEmpty()) + return; + length.setValueAsString(valueString, ec); + if (ec) + return; + append(length); + skipOptionalSpacesOrDelimiter(ptr, end); + } +} + +String SVGLengthList::valueAsString() const +{ + StringBuilder builder; + + unsigned size = this->size(); + for (unsigned i = 0; i < size; ++i) { + if (i > 0) + builder.append(' '); + + builder.append(at(i).valueAsString()); + } + + return builder.toString(); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGLengthList.h b/Source/WebCore/svg/SVGLengthList.h new file mode 100644 index 0000000..865f7bc --- /dev/null +++ b/Source/WebCore/svg/SVGLengthList.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGLengthList_h +#define SVGLengthList_h + +#if ENABLE(SVG) +#include "SVGLength.h" +#include <wtf/Vector.h> + +namespace WebCore { + +class SVGLengthList : public Vector<SVGLength> { +public: + SVGLengthList() { } + + void parse(const String& value, SVGLengthMode); + String valueAsString() const; +}; + +template<> +struct SVGPropertyTraits<SVGLengthList> { + typedef SVGLength ListItemType; + + static SVGLengthList initialValue() { return SVGLengthList(); } + static String toString(const SVGLengthList& type) { return type.valueAsString(); } +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGLengthList.idl b/Source/WebCore/svg/SVGLengthList.idl new file mode 100644 index 0000000..e23f8af --- /dev/null +++ b/Source/WebCore/svg/SVGLengthList.idl @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGLengthList { + readonly attribute unsigned long numberOfItems; + + void clear() + raises(DOMException); + [StrictTypeChecking, RequiresAllArguments=Raise] SVGLength initialize(in SVGLength item) + raises(DOMException, SVGException); + [StrictTypeChecking, RequiresAllArguments=Raise] SVGLength getItem(in unsigned long index) + raises(DOMException); + [StrictTypeChecking, RequiresAllArguments=Raise] SVGLength insertItemBefore(in SVGLength item, in unsigned long index) + raises(DOMException, SVGException); + [StrictTypeChecking, RequiresAllArguments=Raise] SVGLength replaceItem(in SVGLength item, in unsigned long index) + raises(DOMException, SVGException); + [StrictTypeChecking, RequiresAllArguments=Raise] SVGLength removeItem(in unsigned long index) + raises(DOMException); + [StrictTypeChecking, RequiresAllArguments=Raise] SVGLength appendItem(in SVGLength item) + raises(DOMException, SVGException); + }; + +} diff --git a/Source/WebCore/svg/SVGLineElement.cpp b/Source/WebCore/svg/SVGLineElement.cpp new file mode 100644 index 0000000..cfe43da --- /dev/null +++ b/Source/WebCore/svg/SVGLineElement.cpp @@ -0,0 +1,159 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGLineElement.h" + +#include "Attribute.h" +#include "FloatPoint.h" +#include "RenderSVGPath.h" +#include "RenderSVGResource.h" +#include "SVGLength.h" +#include "SVGNames.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_LENGTH(SVGLineElement, SVGNames::x1Attr, X1, x1) +DEFINE_ANIMATED_LENGTH(SVGLineElement, SVGNames::y1Attr, Y1, y1) +DEFINE_ANIMATED_LENGTH(SVGLineElement, SVGNames::x2Attr, X2, x2) +DEFINE_ANIMATED_LENGTH(SVGLineElement, SVGNames::y2Attr, Y2, y2) +DEFINE_ANIMATED_BOOLEAN(SVGLineElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) + +inline SVGLineElement::SVGLineElement(const QualifiedName& tagName, Document* document) + : SVGStyledTransformableElement(tagName, document) + , m_x1(LengthModeWidth) + , m_y1(LengthModeHeight) + , m_x2(LengthModeWidth) + , m_y2(LengthModeHeight) +{ +} + +PassRefPtr<SVGLineElement> SVGLineElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGLineElement(tagName, document)); +} + +void SVGLineElement::parseMappedAttribute(Attribute* attr) +{ + if (attr->name() == SVGNames::x1Attr) + setX1BaseValue(SVGLength(LengthModeWidth, attr->value())); + else if (attr->name() == SVGNames::y1Attr) + setY1BaseValue(SVGLength(LengthModeHeight, attr->value())); + else if (attr->name() == SVGNames::x2Attr) + setX2BaseValue(SVGLength(LengthModeWidth, attr->value())); + else if (attr->name() == SVGNames::y2Attr) + setY2BaseValue(SVGLength(LengthModeHeight, attr->value())); + else { + if (SVGTests::parseMappedAttribute(attr)) + return; + if (SVGLangSpace::parseMappedAttribute(attr)) + return; + if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) + return; + SVGStyledTransformableElement::parseMappedAttribute(attr); + } +} + +void SVGLineElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGStyledTransformableElement::svgAttributeChanged(attrName); + + bool isLengthAttribute = attrName == SVGNames::x1Attr + || attrName == SVGNames::y1Attr + || attrName == SVGNames::x2Attr + || attrName == SVGNames::y2Attr; + + if (isLengthAttribute) + updateRelativeLengthsInformation(); + + if (SVGTests::handleAttributeChange(this, attrName)) + return; + + RenderSVGPath* renderer = static_cast<RenderSVGPath*>(this->renderer()); + if (!renderer) + return; + + if (SVGStyledTransformableElement::isKnownAttribute(attrName)) { + renderer->setNeedsTransformUpdate(); + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); + return; + } + + if (isLengthAttribute) { + renderer->setNeedsPathUpdate(); + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); + return; + } + + if (SVGLangSpace::isKnownAttribute(attrName) + || SVGExternalResourcesRequired::isKnownAttribute(attrName)) + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); +} + +void SVGLineElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGStyledTransformableElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeX1(); + synchronizeY1(); + synchronizeX2(); + synchronizeY2(); + synchronizeExternalResourcesRequired(); + SVGTests::synchronizeProperties(this, attrName); + return; + } + + if (attrName == SVGNames::x1Attr) + synchronizeX1(); + else if (attrName == SVGNames::y1Attr) + synchronizeY1(); + else if (attrName == SVGNames::x2Attr) + synchronizeX2(); + else if (attrName == SVGNames::y2Attr) + synchronizeY2(); + else if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) + synchronizeExternalResourcesRequired(); + else if (SVGTests::isKnownAttribute(attrName)) + SVGTests::synchronizeProperties(this, attrName); +} + +void SVGLineElement::toPathData(Path& path) const +{ + ASSERT(path.isEmpty()); + + path.moveTo(FloatPoint(x1().value(this), y1().value(this))); + path.addLineTo(FloatPoint(x2().value(this), y2().value(this))); +} + +bool SVGLineElement::selfHasRelativeLengths() const +{ + return x1().isRelative() + || y1().isRelative() + || x2().isRelative() + || y2().isRelative(); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGLineElement.h b/Source/WebCore/svg/SVGLineElement.h new file mode 100644 index 0000000..ad60a95 --- /dev/null +++ b/Source/WebCore/svg/SVGLineElement.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGLineElement_h +#define SVGLineElement_h + +#if ENABLE(SVG) +#include "SVGAnimatedBoolean.h" +#include "SVGAnimatedLength.h" +#include "SVGExternalResourcesRequired.h" +#include "SVGLangSpace.h" +#include "SVGStyledTransformableElement.h" +#include "SVGTests.h" + +namespace WebCore { + +class SVGLineElement : public SVGStyledTransformableElement, + public SVGTests, + public SVGLangSpace, + public SVGExternalResourcesRequired { +public: + static PassRefPtr<SVGLineElement> create(const QualifiedName&, Document*); + +private: + SVGLineElement(const QualifiedName&, Document*); + + virtual bool isValid() const { return SVGTests::isValid(); } + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + + virtual void toPathData(Path&) const; + + virtual bool supportsMarkers() const { return true; } + + virtual bool selfHasRelativeLengths() const; + + // Animated property declarations + DECLARE_ANIMATED_LENGTH(X1, x1) + DECLARE_ANIMATED_LENGTH(Y1, y1) + DECLARE_ANIMATED_LENGTH(X2, x2) + DECLARE_ANIMATED_LENGTH(Y2, y2) + + // SVGExternalResourcesRequired + DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGLineElement.idl b/Source/WebCore/svg/SVGLineElement.idl new file mode 100644 index 0000000..56270a1 --- /dev/null +++ b/Source/WebCore/svg/SVGLineElement.idl @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGLineElement : SVGElement, + SVGTests, + SVGLangSpace, + SVGExternalResourcesRequired, + SVGStylable, + SVGTransformable { + readonly attribute SVGAnimatedLength x1; + readonly attribute SVGAnimatedLength y1; + readonly attribute SVGAnimatedLength x2; + readonly attribute SVGAnimatedLength y2; + }; + +} diff --git a/Source/WebCore/svg/SVGLinearGradientElement.cpp b/Source/WebCore/svg/SVGLinearGradientElement.cpp new file mode 100644 index 0000000..5bece06 --- /dev/null +++ b/Source/WebCore/svg/SVGLinearGradientElement.cpp @@ -0,0 +1,205 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * Copyright (C) 2008 Eric Seidel <eric@webkit.org> + * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGLinearGradientElement.h" + +#include "Attribute.h" +#include "Document.h" +#include "FloatPoint.h" +#include "LinearGradientAttributes.h" +#include "RenderSVGResourceLinearGradient.h" +#include "SVGLength.h" +#include "SVGNames.h" +#include "SVGTransform.h" +#include "SVGTransformList.h" +#include "SVGUnitTypes.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_LENGTH(SVGLinearGradientElement, SVGNames::x1Attr, X1, x1) +DEFINE_ANIMATED_LENGTH(SVGLinearGradientElement, SVGNames::y1Attr, Y1, y1) +DEFINE_ANIMATED_LENGTH(SVGLinearGradientElement, SVGNames::x2Attr, X2, x2) +DEFINE_ANIMATED_LENGTH(SVGLinearGradientElement, SVGNames::y2Attr, Y2, y2) + +inline SVGLinearGradientElement::SVGLinearGradientElement(const QualifiedName& tagName, Document* document) + : SVGGradientElement(tagName, document) + , m_x1(LengthModeWidth) + , m_y1(LengthModeHeight) + , m_x2(LengthModeWidth, "100%") + , m_y2(LengthModeHeight) +{ + // Spec: If the x2 attribute is not specified, the effect is as if a value of "100%" were specified. +} + +PassRefPtr<SVGLinearGradientElement> SVGLinearGradientElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGLinearGradientElement(tagName, document)); +} + +void SVGLinearGradientElement::parseMappedAttribute(Attribute* attr) +{ + if (attr->name() == SVGNames::x1Attr) + setX1BaseValue(SVGLength(LengthModeWidth, attr->value())); + else if (attr->name() == SVGNames::y1Attr) + setY1BaseValue(SVGLength(LengthModeHeight, attr->value())); + else if (attr->name() == SVGNames::x2Attr) + setX2BaseValue(SVGLength(LengthModeWidth, attr->value())); + else if (attr->name() == SVGNames::y2Attr) + setY2BaseValue(SVGLength(LengthModeHeight, attr->value())); + else + SVGGradientElement::parseMappedAttribute(attr); +} + +void SVGLinearGradientElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGGradientElement::svgAttributeChanged(attrName); + + if (attrName == SVGNames::x1Attr + || attrName == SVGNames::y1Attr + || attrName == SVGNames::x2Attr + || attrName == SVGNames::y2Attr) { + updateRelativeLengthsInformation(); + + RenderObject* object = renderer(); + if (!object) + return; + + object->setNeedsLayout(true); + } +} + +void SVGLinearGradientElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGGradientElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeX1(); + synchronizeY1(); + synchronizeX2(); + synchronizeY2(); + return; + } + + if (attrName == SVGNames::x1Attr) + synchronizeX1(); + else if (attrName == SVGNames::y1Attr) + synchronizeY1(); + else if (attrName == SVGNames::x2Attr) + synchronizeX2(); + else if (attrName == SVGNames::y2Attr) + synchronizeY2(); +} + +RenderObject* SVGLinearGradientElement::createRenderer(RenderArena* arena, RenderStyle*) +{ + return new (arena) RenderSVGResourceLinearGradient(this); +} + +void SVGLinearGradientElement::collectGradientAttributes(LinearGradientAttributes& attributes) +{ + HashSet<SVGGradientElement*> processedGradients; + + bool isLinear = true; + SVGGradientElement* current = this; + + while (current) { + if (!attributes.hasSpreadMethod() && current->hasAttribute(SVGNames::spreadMethodAttr)) + attributes.setSpreadMethod((GradientSpreadMethod) current->spreadMethod()); + + if (!attributes.hasBoundingBoxMode() && current->hasAttribute(SVGNames::gradientUnitsAttr)) + attributes.setBoundingBoxMode(current->gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX); + + if (!attributes.hasGradientTransform() && current->hasAttribute(SVGNames::gradientTransformAttr)) { + AffineTransform transform; + current->gradientTransform().concatenate(transform); + attributes.setGradientTransform(transform); + } + + if (!attributes.hasStops()) { + const Vector<Gradient::ColorStop>& stops(current->buildStops()); + if (!stops.isEmpty()) + attributes.setStops(stops); + } + + if (isLinear) { + SVGLinearGradientElement* linear = static_cast<SVGLinearGradientElement*>(current); + + if (!attributes.hasX1() && current->hasAttribute(SVGNames::x1Attr)) + attributes.setX1(linear->x1()); + + if (!attributes.hasY1() && current->hasAttribute(SVGNames::y1Attr)) + attributes.setY1(linear->y1()); + + if (!attributes.hasX2() && current->hasAttribute(SVGNames::x2Attr)) + attributes.setX2(linear->x2()); + + if (!attributes.hasY2() && current->hasAttribute(SVGNames::y2Attr)) + attributes.setY2(linear->y2()); + } + + processedGradients.add(current); + + // Respect xlink:href, take attributes from referenced element + Node* refNode = ownerDocument()->getElementById(SVGURIReference::getTarget(current->href())); + if (refNode && (refNode->hasTagName(SVGNames::linearGradientTag) || refNode->hasTagName(SVGNames::radialGradientTag))) { + current = static_cast<SVGGradientElement*>(refNode); + + // Cycle detection + if (processedGradients.contains(current)) { + current = 0; + break; + } + + isLinear = current->hasTagName(SVGNames::linearGradientTag); + } else + current = 0; + } +} + +void SVGLinearGradientElement::calculateStartEndPoints(const LinearGradientAttributes& attributes, FloatPoint& startPoint, FloatPoint& endPoint) +{ + // Determine gradient start/end points + if (attributes.boundingBoxMode()) { + startPoint = FloatPoint(attributes.x1().valueAsPercentage(), attributes.y1().valueAsPercentage()); + endPoint = FloatPoint(attributes.x2().valueAsPercentage(), attributes.y2().valueAsPercentage()); + } else { + startPoint = FloatPoint(attributes.x1().value(this), attributes.y1().value(this)); + endPoint = FloatPoint(attributes.x2().value(this), attributes.y2().value(this)); + } +} + +bool SVGLinearGradientElement::selfHasRelativeLengths() const +{ + return x1().isRelative() + || y1().isRelative() + || x2().isRelative() + || y2().isRelative(); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGLinearGradientElement.h b/Source/WebCore/svg/SVGLinearGradientElement.h new file mode 100644 index 0000000..198f0ee --- /dev/null +++ b/Source/WebCore/svg/SVGLinearGradientElement.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGLinearGradientElement_h +#define SVGLinearGradientElement_h + +#if ENABLE(SVG) +#include "SVGAnimatedLength.h" +#include "SVGGradientElement.h" + +namespace WebCore { + +struct LinearGradientAttributes; + +class SVGLinearGradientElement : public SVGGradientElement { +public: + static PassRefPtr<SVGLinearGradientElement> create(const QualifiedName&, Document*); + + void collectGradientAttributes(LinearGradientAttributes&); + void calculateStartEndPoints(const LinearGradientAttributes&, FloatPoint& startPoint, FloatPoint& endPoint); + +private: + SVGLinearGradientElement(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + + virtual bool selfHasRelativeLengths() const; + + // Animated property declarations + DECLARE_ANIMATED_LENGTH(X1, x1) + DECLARE_ANIMATED_LENGTH(Y1, y1) + DECLARE_ANIMATED_LENGTH(X2, x2) + DECLARE_ANIMATED_LENGTH(Y2, y2) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGLinearGradientElement.idl b/Source/WebCore/svg/SVGLinearGradientElement.idl new file mode 100644 index 0000000..0ef8197 --- /dev/null +++ b/Source/WebCore/svg/SVGLinearGradientElement.idl @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGLinearGradientElement : SVGGradientElement { + readonly attribute SVGAnimatedLength x1; + readonly attribute SVGAnimatedLength y1; + readonly attribute SVGAnimatedLength x2; + readonly attribute SVGAnimatedLength y2; + }; + +} diff --git a/Source/WebCore/svg/SVGLocatable.cpp b/Source/WebCore/svg/SVGLocatable.cpp new file mode 100644 index 0000000..43961d9 --- /dev/null +++ b/Source/WebCore/svg/SVGLocatable.cpp @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * Copyright (C) 2009 Google, Inc. All rights reserved. + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGLocatable.h" + +#include "RenderObject.h" +#include "SVGException.h" +#include "SVGNames.h" +#include "SVGStyledLocatableElement.h" + +namespace WebCore { + +static bool isViewportElement(Node* node) +{ + return (node->hasTagName(SVGNames::svgTag) + || node->hasTagName(SVGNames::symbolTag) +#if ENABLE(SVG_FOREIGN_OBJECT) + || node->hasTagName(SVGNames::foreignObjectTag) +#endif + || node->hasTagName(SVGNames::imageTag)); +} + +SVGElement* SVGLocatable::nearestViewportElement(const SVGElement* element) +{ + ASSERT(element); + for (ContainerNode* n = element->parentNode(); n; n = n->parentNode()) { + if (isViewportElement(n)) + return static_cast<SVGElement*>(n); + } + + return 0; +} + +SVGElement* SVGLocatable::farthestViewportElement(const SVGElement* element) +{ + ASSERT(element); + SVGElement* farthest = 0; + for (ContainerNode* n = element->parentNode(); n; n = n->parentNode()) { + if (isViewportElement(n)) + farthest = static_cast<SVGElement*>(n); + } + return farthest; +} + +FloatRect SVGLocatable::getBBox(const SVGElement* element, StyleUpdateStrategy styleUpdateStrategy) +{ + ASSERT(element); + if (styleUpdateStrategy == AllowStyleUpdate) + element->document()->updateLayoutIgnorePendingStylesheets(); + + // FIXME: Eventually we should support getBBox for detached elements. + if (!element->renderer()) + return FloatRect(); + + return element->renderer()->objectBoundingBox(); +} + +AffineTransform SVGLocatable::computeCTM(const SVGElement* element, CTMScope mode, StyleUpdateStrategy styleUpdateStrategy) +{ + ASSERT(element); + if (styleUpdateStrategy == AllowStyleUpdate) + element->document()->updateLayoutIgnorePendingStylesheets(); + + AffineTransform ctm; + + SVGElement* stopAtElement = mode == NearestViewportScope ? nearestViewportElement(element) : 0; + + Node* current = const_cast<SVGElement*>(element); + while (current && current->isSVGElement()) { + SVGElement* currentElement = static_cast<SVGElement*>(current); + if (currentElement->isStyled()) + ctm = static_cast<SVGStyledElement*>(currentElement)->localCoordinateSpaceTransform(mode).multLeft(ctm); + + // For getCTM() computation, stop at the nearest viewport element + if (currentElement == stopAtElement) + break; + + current = current->parentOrHostNode(); + } + + return ctm; +} + +AffineTransform SVGLocatable::getTransformToElement(SVGElement* target, ExceptionCode& ec, StyleUpdateStrategy styleUpdateStrategy) const +{ + AffineTransform ctm = getCTM(styleUpdateStrategy); + + if (target && target->isStyledLocatable()) { + AffineTransform targetCTM = static_cast<SVGStyledLocatableElement*>(target)->getCTM(styleUpdateStrategy); + if (!targetCTM.isInvertible()) { + ec = SVGException::SVG_MATRIX_NOT_INVERTABLE; + return ctm; + } + ctm *= targetCTM.inverse(); + } + + return ctm; +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGLocatable.h b/Source/WebCore/svg/SVGLocatable.h new file mode 100644 index 0000000..b19f5cd --- /dev/null +++ b/Source/WebCore/svg/SVGLocatable.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2007 Rob Buis <buis@kde.org> + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGLocatable_h +#define SVGLocatable_h + +#if ENABLE(SVG) +#include "AffineTransform.h" +#include "ExceptionCode.h" + +namespace WebCore { + +class FloatRect; +class SVGElement; + +class SVGLocatable { +public: + virtual ~SVGLocatable() { } + + // 'SVGLocatable' functions + virtual SVGElement* nearestViewportElement() const = 0; + virtual SVGElement* farthestViewportElement() const = 0; + + enum StyleUpdateStrategy { AllowStyleUpdate, DisallowStyleUpdate }; + + virtual FloatRect getBBox(StyleUpdateStrategy) const = 0; + virtual AffineTransform getCTM(StyleUpdateStrategy) const = 0; + virtual AffineTransform getScreenCTM(StyleUpdateStrategy) const = 0; + AffineTransform getTransformToElement(SVGElement*, ExceptionCode&, StyleUpdateStrategy = AllowStyleUpdate) const; + + static SVGElement* nearestViewportElement(const SVGElement*); + static SVGElement* farthestViewportElement(const SVGElement*); + + enum CTMScope { + NearestViewportScope, // Used for getCTM() + ScreenScope // Used for getScreenCTM() + }; + +protected: + virtual AffineTransform localCoordinateSpaceTransform(SVGLocatable::CTMScope) const { return AffineTransform(); } + + static FloatRect getBBox(const SVGElement*, StyleUpdateStrategy); + static AffineTransform computeCTM(const SVGElement*, CTMScope, StyleUpdateStrategy); +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGLocatable_h diff --git a/Source/WebCore/svg/SVGLocatable.idl b/Source/WebCore/svg/SVGLocatable.idl new file mode 100644 index 0000000..247f390 --- /dev/null +++ b/Source/WebCore/svg/SVGLocatable.idl @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG, ObjCProtocol, OmitConstructor] SVGLocatable { + readonly attribute SVGElement nearestViewportElement; + readonly attribute SVGElement farthestViewportElement; + + SVGRect getBBox(); + SVGMatrix getCTM(); + SVGMatrix getScreenCTM(); + SVGMatrix getTransformToElement(in SVGElement element) + raises(SVGException); + }; + +} diff --git a/Source/WebCore/svg/SVGMPathElement.cpp b/Source/WebCore/svg/SVGMPathElement.cpp new file mode 100644 index 0000000..0df262e --- /dev/null +++ b/Source/WebCore/svg/SVGMPathElement.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGMPathElement.h" + +#include "Document.h" +#include "SVGNames.h" +#include "SVGPathElement.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_STRING(SVGMPathElement, XLinkNames::hrefAttr, Href, href) +DEFINE_ANIMATED_BOOLEAN(SVGMPathElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) + +inline SVGMPathElement::SVGMPathElement(const QualifiedName& tagName, Document* document) + : SVGElement(tagName, document) +{ +} + +PassRefPtr<SVGMPathElement> SVGMPathElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGMPathElement(tagName, document)); +} + +void SVGMPathElement::parseMappedAttribute(Attribute* attr) +{ + if (SVGURIReference::parseMappedAttribute(attr)) + return; + SVGElement::parseMappedAttribute(attr); +} + +void SVGMPathElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeExternalResourcesRequired(); + synchronizeHref(); + return; + } + + if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) + synchronizeExternalResourcesRequired(); + else if (SVGURIReference::isKnownAttribute(attrName)) + synchronizeHref(); +} + +SVGPathElement* SVGMPathElement::pathElement() +{ + Element* target = document()->getElementById(getTarget(href())); + if (target && target->hasTagName(SVGNames::pathTag)) + return static_cast<SVGPathElement*>(target); + return 0; +} + +} // namespace WebCore + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGMPathElement.h b/Source/WebCore/svg/SVGMPathElement.h new file mode 100644 index 0000000..2fa7c28 --- /dev/null +++ b/Source/WebCore/svg/SVGMPathElement.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGMPathElement_h +#define SVGMPathElement_h + +#if ENABLE(SVG) +#include "SVGAnimatedBoolean.h" +#include "SVGAnimatedString.h" +#include "SVGExternalResourcesRequired.h" +#include "SVGURIReference.h" + +namespace WebCore { + +class SVGPathElement; + +class SVGMPathElement : public SVGElement, + public SVGURIReference, + public SVGExternalResourcesRequired { +public: + static PassRefPtr<SVGMPathElement> create(const QualifiedName&, Document*); + + SVGPathElement* pathElement(); + +private: + SVGMPathElement(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + virtual void synchronizeProperty(const QualifiedName&); + + // Animated property declarations + + // SVGURIReference + DECLARE_ANIMATED_STRING(Href, href) + + // SVGExternalResourcesRequired + DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGMPathElement_h diff --git a/Source/WebCore/svg/SVGMarkerElement.cpp b/Source/WebCore/svg/SVGMarkerElement.cpp new file mode 100644 index 0000000..3174711 --- /dev/null +++ b/Source/WebCore/svg/SVGMarkerElement.cpp @@ -0,0 +1,230 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGMarkerElement.h" + +#include "Attribute.h" +#include "RenderSVGResourceMarker.h" +#include "SVGFitToViewBox.h" +#include "SVGNames.h" +#include "SVGSVGElement.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_LENGTH(SVGMarkerElement, SVGNames::refXAttr, RefX, refX) +DEFINE_ANIMATED_LENGTH(SVGMarkerElement, SVGNames::refYAttr, RefY, refY) +DEFINE_ANIMATED_LENGTH(SVGMarkerElement, SVGNames::markerWidthAttr, MarkerWidth, markerWidth) +DEFINE_ANIMATED_LENGTH(SVGMarkerElement, SVGNames::markerHeightAttr, MarkerHeight, markerHeight) +DEFINE_ANIMATED_ENUMERATION(SVGMarkerElement, SVGNames::markerUnitsAttr, MarkerUnits, markerUnits) +DEFINE_ANIMATED_ENUMERATION_MULTIPLE_WRAPPERS(SVGMarkerElement, SVGNames::orientAttr, orientTypeIdentifier(), OrientType, orientType) +DEFINE_ANIMATED_ANGLE_MULTIPLE_WRAPPERS(SVGMarkerElement, SVGNames::orientAttr, orientAngleIdentifier(), OrientAngle, orientAngle) +DEFINE_ANIMATED_BOOLEAN(SVGMarkerElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) +DEFINE_ANIMATED_RECT(SVGMarkerElement, SVGNames::viewBoxAttr, ViewBox, viewBox) +DEFINE_ANIMATED_PRESERVEASPECTRATIO(SVGMarkerElement, SVGNames::preserveAspectRatioAttr, PreserveAspectRatio, preserveAspectRatio) + +inline SVGMarkerElement::SVGMarkerElement(const QualifiedName& tagName, Document* document) + : SVGStyledElement(tagName, document) + , m_refX(LengthModeWidth) + , m_refY(LengthModeHeight) + , m_markerWidth(LengthModeWidth, "3") + , m_markerHeight(LengthModeHeight, "3") + , m_markerUnits(SVG_MARKERUNITS_STROKEWIDTH) + , m_orientType(SVG_MARKER_ORIENT_ANGLE) +{ + // Spec: If the markerWidth/markerHeight attribute is not specified, the effect is as if a value of "3" were specified. +} + +PassRefPtr<SVGMarkerElement> SVGMarkerElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGMarkerElement(tagName, document)); +} + +const AtomicString& SVGMarkerElement::orientTypeIdentifier() +{ + DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGOrientType")); + return s_identifier; +} + +const AtomicString& SVGMarkerElement::orientAngleIdentifier() +{ + DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGOrientAngle")); + return s_identifier; +} + +AffineTransform SVGMarkerElement::viewBoxToViewTransform(float viewWidth, float viewHeight) const +{ + return SVGFitToViewBox::viewBoxToViewTransform(viewBox(), preserveAspectRatio(), viewWidth, viewHeight); +} + +void SVGMarkerElement::parseMappedAttribute(Attribute* attr) +{ + if (attr->name() == SVGNames::markerUnitsAttr) { + if (attr->value() == "userSpaceOnUse") + setMarkerUnitsBaseValue(SVG_MARKERUNITS_USERSPACEONUSE); + else if (attr->value() == "strokeWidth") + setMarkerUnitsBaseValue(SVG_MARKERUNITS_STROKEWIDTH); + } else if (attr->name() == SVGNames::refXAttr) + setRefXBaseValue(SVGLength(LengthModeWidth, attr->value())); + else if (attr->name() == SVGNames::refYAttr) + setRefYBaseValue(SVGLength(LengthModeHeight, attr->value())); + else if (attr->name() == SVGNames::markerWidthAttr) + setMarkerWidthBaseValue(SVGLength(LengthModeWidth, attr->value())); + else if (attr->name() == SVGNames::markerHeightAttr) + setMarkerHeightBaseValue(SVGLength(LengthModeHeight, attr->value())); + else if (attr->name() == SVGNames::orientAttr) { + SVGAngle angle; + + if (attr->value() == "auto") + setOrientTypeBaseValue(SVG_MARKER_ORIENT_AUTO); + else { + ExceptionCode ec = 0; + angle.setValueAsString(attr->value(), ec); + setOrientTypeBaseValue(SVG_MARKER_ORIENT_ANGLE); + } + + setOrientAngleBaseValue(angle); + } else { + if (SVGLangSpace::parseMappedAttribute(attr)) + return; + if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) + return; + if (SVGFitToViewBox::parseMappedAttribute(document(), attr)) + return; + + SVGStyledElement::parseMappedAttribute(attr); + } +} + +void SVGMarkerElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGStyledElement::svgAttributeChanged(attrName); + + bool invalidateClients = false; + if (attrName == SVGNames::refXAttr + || attrName == SVGNames::refYAttr + || attrName == SVGNames::markerWidthAttr + || attrName == SVGNames::markerHeightAttr) { + invalidateClients = true; + updateRelativeLengthsInformation(); + } + + RenderObject* object = renderer(); + if (!object) + return; + + if (invalidateClients + || attrName == SVGNames::markerUnitsAttr + || attrName == SVGNames::orientAttr + || SVGLangSpace::isKnownAttribute(attrName) + || SVGExternalResourcesRequired::isKnownAttribute(attrName) + || SVGFitToViewBox::isKnownAttribute(attrName) + || SVGStyledElement::isKnownAttribute(attrName)) + object->setNeedsLayout(true); +} + +void SVGMarkerElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGStyledElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeMarkerUnits(); + synchronizeRefX(); + synchronizeRefY(); + synchronizeMarkerWidth(); + synchronizeMarkerHeight(); + synchronizeOrientAngle(); + synchronizeOrientType(); + synchronizeExternalResourcesRequired(); + synchronizeViewBox(); + synchronizePreserveAspectRatio(); + return; + } + + if (attrName == SVGNames::markerUnitsAttr) + synchronizeMarkerUnits(); + else if (attrName == SVGNames::refXAttr) + synchronizeRefX(); + else if (attrName == SVGNames::refYAttr) + synchronizeRefY(); + else if (attrName == SVGNames::markerWidthAttr) + synchronizeMarkerWidth(); + else if (attrName == SVGNames::markerHeightAttr) + synchronizeMarkerHeight(); + else if (attrName == SVGNames::orientAttr) { + synchronizeOrientAngle(); + synchronizeOrientType(); + } else if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) + synchronizeExternalResourcesRequired(); + else if (SVGFitToViewBox::isKnownAttribute(attrName)) { + synchronizeViewBox(); + synchronizePreserveAspectRatio(); + } +} + +void SVGMarkerElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) +{ + SVGStyledElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); + + if (changedByParser) + return; + + if (RenderObject* object = renderer()) + object->setNeedsLayout(true); +} + +void SVGMarkerElement::setOrientToAuto() +{ + setOrientTypeBaseValue(SVG_MARKER_ORIENT_AUTO); + setOrientAngleBaseValue(SVGAngle()); + + if (RenderObject* object = renderer()) + object->setNeedsLayout(true); +} + +void SVGMarkerElement::setOrientToAngle(const SVGAngle& angle) +{ + setOrientTypeBaseValue(SVG_MARKER_ORIENT_ANGLE); + setOrientAngleBaseValue(angle); + + if (RenderObject* object = renderer()) + object->setNeedsLayout(true); +} + +RenderObject* SVGMarkerElement::createRenderer(RenderArena* arena, RenderStyle*) +{ + return new (arena) RenderSVGResourceMarker(this); +} + +bool SVGMarkerElement::selfHasRelativeLengths() const +{ + return refX().isRelative() + || refY().isRelative() + || markerWidth().isRelative() + || markerHeight().isRelative(); +} + +} + +#endif diff --git a/Source/WebCore/svg/SVGMarkerElement.h b/Source/WebCore/svg/SVGMarkerElement.h new file mode 100644 index 0000000..472baa6 --- /dev/null +++ b/Source/WebCore/svg/SVGMarkerElement.h @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGMarkerElement_h +#define SVGMarkerElement_h + +#if ENABLE(SVG) +#include "SVGAnimatedAngle.h" +#include "SVGAnimatedBoolean.h" +#include "SVGAnimatedEnumeration.h" +#include "SVGAnimatedLength.h" +#include "SVGAnimatedPreserveAspectRatio.h" +#include "SVGAnimatedRect.h" +#include "SVGExternalResourcesRequired.h" +#include "SVGFitToViewBox.h" +#include "SVGLangSpace.h" +#include "SVGStyledElement.h" + +namespace WebCore { + +class SVGMarkerElement : public SVGStyledElement, + public SVGLangSpace, + public SVGExternalResourcesRequired, + public SVGFitToViewBox { +public: + enum SVGMarkerUnitsType { + SVG_MARKERUNITS_UNKNOWN = 0, + SVG_MARKERUNITS_USERSPACEONUSE = 1, + SVG_MARKERUNITS_STROKEWIDTH = 2 + }; + + enum SVGMarkerOrientType { + SVG_MARKER_ORIENT_UNKNOWN = 0, + SVG_MARKER_ORIENT_AUTO = 1, + SVG_MARKER_ORIENT_ANGLE = 2 + }; + + static PassRefPtr<SVGMarkerElement> create(const QualifiedName&, Document*); + + AffineTransform viewBoxToViewTransform(float viewWidth, float viewHeight) const; + + void setOrientToAuto(); + void setOrientToAngle(const SVGAngle&); + +private: + SVGMarkerElement(const QualifiedName&, Document*); + + virtual bool needsPendingResourceHandling() const { return false; } + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); + + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + + virtual bool selfHasRelativeLengths() const; + + static const AtomicString& orientTypeIdentifier(); + static const AtomicString& orientAngleIdentifier(); + + // Animated property declarations + DECLARE_ANIMATED_LENGTH(RefX, refX) + DECLARE_ANIMATED_LENGTH(RefY, refY) + DECLARE_ANIMATED_LENGTH(MarkerWidth, markerWidth) + DECLARE_ANIMATED_LENGTH(MarkerHeight, markerHeight) + DECLARE_ANIMATED_ENUMERATION(MarkerUnits, markerUnits) + DECLARE_ANIMATED_ENUMERATION(OrientType, orientType) + DECLARE_ANIMATED_ANGLE(OrientAngle, orientAngle) + + // SVGExternalResourcesRequired + DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) + + // SVGFitToViewBox + DECLARE_ANIMATED_RECT(ViewBox, viewBox) + DECLARE_ANIMATED_PRESERVEASPECTRATIO(PreserveAspectRatio, preserveAspectRatio) +}; + +} + +#endif +#endif diff --git a/Source/WebCore/svg/SVGMarkerElement.idl b/Source/WebCore/svg/SVGMarkerElement.idl new file mode 100644 index 0000000..3870941 --- /dev/null +++ b/Source/WebCore/svg/SVGMarkerElement.idl @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGMarkerElement : SVGElement, + SVGLangSpace, + SVGExternalResourcesRequired, + SVGStylable, + SVGFitToViewBox { + // Marker Unit Types + const unsigned short SVG_MARKERUNITS_UNKNOWN = 0; + const unsigned short SVG_MARKERUNITS_USERSPACEONUSE = 1; + const unsigned short SVG_MARKERUNITS_STROKEWIDTH = 2; + + // Marker Orientation Types + const unsigned short SVG_MARKER_ORIENT_UNKNOWN = 0; + const unsigned short SVG_MARKER_ORIENT_AUTO = 1; + const unsigned short SVG_MARKER_ORIENT_ANGLE = 2; + + readonly attribute SVGAnimatedLength refX; + readonly attribute SVGAnimatedLength refY; + readonly attribute SVGAnimatedEnumeration markerUnits; + readonly attribute SVGAnimatedLength markerWidth; + readonly attribute SVGAnimatedLength markerHeight; + readonly attribute SVGAnimatedEnumeration orientType; + readonly attribute SVGAnimatedAngle orientAngle; + + void setOrientToAuto(); + void setOrientToAngle(in SVGAngle angle); + }; + +} diff --git a/Source/WebCore/svg/SVGMaskElement.cpp b/Source/WebCore/svg/SVGMaskElement.cpp new file mode 100644 index 0000000..ec23e29 --- /dev/null +++ b/Source/WebCore/svg/SVGMaskElement.cpp @@ -0,0 +1,194 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * Copyright (C) 2005 Alexander Kellett <lypanov@kde.org> + * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> + * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGMaskElement.h" + +#include "Attribute.h" +#include "CSSStyleSelector.h" +#include "RenderSVGResourceMasker.h" +#include "SVGNames.h" +#include "SVGRenderSupport.h" +#include "SVGUnitTypes.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_ENUMERATION(SVGMaskElement, SVGNames::maskUnitsAttr, MaskUnits, maskUnits) +DEFINE_ANIMATED_ENUMERATION(SVGMaskElement, SVGNames::maskContentUnitsAttr, MaskContentUnits, maskContentUnits) +DEFINE_ANIMATED_LENGTH(SVGMaskElement, SVGNames::xAttr, X, x) +DEFINE_ANIMATED_LENGTH(SVGMaskElement, SVGNames::yAttr, Y, y) +DEFINE_ANIMATED_LENGTH(SVGMaskElement, SVGNames::widthAttr, Width, width) +DEFINE_ANIMATED_LENGTH(SVGMaskElement, SVGNames::heightAttr, Height, height) +DEFINE_ANIMATED_BOOLEAN(SVGMaskElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) + +inline SVGMaskElement::SVGMaskElement(const QualifiedName& tagName, Document* document) + : SVGStyledLocatableElement(tagName, document) + , m_maskUnits(SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) + , m_maskContentUnits(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE) + , m_x(LengthModeWidth, "-10%") + , m_y(LengthModeHeight, "-10%") + , m_width(LengthModeWidth, "120%") + , m_height(LengthModeHeight, "120%") +{ + // Spec: If the x/y attribute is not specified, the effect is as if a value of "-10%" were specified. + // Spec: If the width/height attribute is not specified, the effect is as if a value of "120%" were specified. +} + +PassRefPtr<SVGMaskElement> SVGMaskElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGMaskElement(tagName, document)); +} + +void SVGMaskElement::parseMappedAttribute(Attribute* attr) +{ + if (attr->name() == SVGNames::maskUnitsAttr) { + if (attr->value() == "userSpaceOnUse") + setMaskUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE); + else if (attr->value() == "objectBoundingBox") + setMaskUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX); + } else if (attr->name() == SVGNames::maskContentUnitsAttr) { + if (attr->value() == "userSpaceOnUse") + setMaskContentUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE); + else if (attr->value() == "objectBoundingBox") + setMaskContentUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX); + } else if (attr->name() == SVGNames::xAttr) + setXBaseValue(SVGLength(LengthModeWidth, attr->value())); + else if (attr->name() == SVGNames::yAttr) + setYBaseValue(SVGLength(LengthModeHeight, attr->value())); + else if (attr->name() == SVGNames::widthAttr) + setWidthBaseValue(SVGLength(LengthModeWidth, attr->value())); + else if (attr->name() == SVGNames::heightAttr) + setHeightBaseValue(SVGLength(LengthModeHeight, attr->value())); + else { + if (SVGTests::parseMappedAttribute(attr)) + return; + if (SVGLangSpace::parseMappedAttribute(attr)) + return; + if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) + return; + SVGStyledElement::parseMappedAttribute(attr); + } +} + +void SVGMaskElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGStyledElement::svgAttributeChanged(attrName); + + bool invalidateClients = false; + if (attrName == SVGNames::xAttr + || attrName == SVGNames::yAttr + || attrName == SVGNames::widthAttr + || attrName == SVGNames::heightAttr) { + invalidateClients = true; + updateRelativeLengthsInformation(); + } + + RenderObject* object = renderer(); + if (!object) + return; + + if (invalidateClients + || attrName == SVGNames::maskUnitsAttr + || attrName == SVGNames::maskContentUnitsAttr + || SVGTests::isKnownAttribute(attrName) + || SVGLangSpace::isKnownAttribute(attrName) + || SVGExternalResourcesRequired::isKnownAttribute(attrName) + || SVGStyledElement::isKnownAttribute(attrName)) + object->setNeedsLayout(true); +} + +void SVGMaskElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGStyledElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeMaskUnits(); + synchronizeMaskContentUnits(); + synchronizeX(); + synchronizeY(); + synchronizeExternalResourcesRequired(); + SVGTests::synchronizeProperties(this, attrName); + return; + } + + if (attrName == SVGNames::maskUnitsAttr) + synchronizeMaskUnits(); + else if (attrName == SVGNames::maskContentUnitsAttr) + synchronizeMaskContentUnits(); + else if (attrName == SVGNames::xAttr) + synchronizeX(); + else if (attrName == SVGNames::yAttr) + synchronizeY(); + else if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) + synchronizeExternalResourcesRequired(); + else if (SVGTests::isKnownAttribute(attrName)) + SVGTests::synchronizeProperties(this, attrName); +} + +void SVGMaskElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) +{ + SVGStyledElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); + + if (changedByParser) + return; + + if (RenderObject* object = renderer()) + object->setNeedsLayout(true); +} + +FloatRect SVGMaskElement::maskBoundingBox(const FloatRect& objectBoundingBox) const +{ + FloatRect maskBBox; + if (maskUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) + maskBBox = FloatRect(x().valueAsPercentage() * objectBoundingBox.width() + objectBoundingBox.x(), + y().valueAsPercentage() * objectBoundingBox.height() + objectBoundingBox.y(), + width().valueAsPercentage() * objectBoundingBox.width(), + height().valueAsPercentage() * objectBoundingBox.height()); + else + maskBBox = FloatRect(x().value(this), + y().value(this), + width().value(this), + height().value(this)); + + return maskBBox; +} + +RenderObject* SVGMaskElement::createRenderer(RenderArena* arena, RenderStyle*) +{ + return new (arena) RenderSVGResourceMasker(this); +} + +bool SVGMaskElement::selfHasRelativeLengths() const +{ + return x().isRelative() + || y().isRelative() + || width().isRelative() + || height().isRelative(); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGMaskElement.h b/Source/WebCore/svg/SVGMaskElement.h new file mode 100644 index 0000000..87e91ff --- /dev/null +++ b/Source/WebCore/svg/SVGMaskElement.h @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2005 Alexander Kellett <lypanov@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGMaskElement_h +#define SVGMaskElement_h + +#if ENABLE(SVG) +#include "SVGAnimatedBoolean.h" +#include "SVGAnimatedEnumeration.h" +#include "SVGAnimatedLength.h" +#include "SVGExternalResourcesRequired.h" +#include "SVGLangSpace.h" +#include "SVGStyledLocatableElement.h" +#include "SVGTests.h" + +namespace WebCore { + +class SVGMaskElement : public SVGStyledLocatableElement, + public SVGTests, + public SVGLangSpace, + public SVGExternalResourcesRequired { +public: + static PassRefPtr<SVGMaskElement> create(const QualifiedName&, Document*); + + FloatRect maskBoundingBox(const FloatRect&) const; + +private: + SVGMaskElement(const QualifiedName&, Document*); + + virtual bool isValid() const { return SVGTests::isValid(); } + virtual bool needsPendingResourceHandling() const { return false; } + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); + + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + + virtual bool selfHasRelativeLengths() const; + + // Animated property declarations + DECLARE_ANIMATED_ENUMERATION(MaskUnits, maskUnits) + DECLARE_ANIMATED_ENUMERATION(MaskContentUnits, maskContentUnits) + DECLARE_ANIMATED_LENGTH(X, x) + DECLARE_ANIMATED_LENGTH(Y, y) + DECLARE_ANIMATED_LENGTH(Width, width) + DECLARE_ANIMATED_LENGTH(Height, height) + + // SVGExternalResourcesRequired + DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) +}; + +} + +#endif +#endif diff --git a/Source/WebCore/svg/SVGMaskElement.idl b/Source/WebCore/svg/SVGMaskElement.idl new file mode 100644 index 0000000..1bb9752 --- /dev/null +++ b/Source/WebCore/svg/SVGMaskElement.idl @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGMaskElement : SVGElement, + SVGTests, + SVGLangSpace, + SVGExternalResourcesRequired, + SVGStylable { + readonly attribute SVGAnimatedEnumeration maskUnits; + readonly attribute SVGAnimatedEnumeration maskContentUnits; + + readonly attribute SVGAnimatedLength x; + readonly attribute SVGAnimatedLength y; + readonly attribute SVGAnimatedLength width; + readonly attribute SVGAnimatedLength height; + }; + +} diff --git a/Source/WebCore/svg/SVGMatrix.h b/Source/WebCore/svg/SVGMatrix.h new file mode 100644 index 0000000..807b703 --- /dev/null +++ b/Source/WebCore/svg/SVGMatrix.h @@ -0,0 +1,131 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGMatrix_h +#define SVGMatrix_h + +#if ENABLE(SVG) +#include "AffineTransform.h" +#include "SVGException.h" + +namespace WebCore { + +// Only used in the bindings. +class SVGMatrix : public AffineTransform { +public: + SVGMatrix() { } + SVGMatrix(const AffineTransform& other) + : AffineTransform(other) + { + } + + SVGMatrix(double a, double b, double c, double d, double e, double f) + : AffineTransform(a, b, c, d, e, f) + { + } + + SVGMatrix translate(double tx, double ty) + { + AffineTransform copy = *this; + copy.translate(tx, ty); + return static_cast<SVGMatrix>(copy); + } + + SVGMatrix scale(double s) + { + AffineTransform copy = *this; + copy.scale(s, s); + return static_cast<SVGMatrix>(copy); + } + + SVGMatrix scaleNonUniform(double sx, double sy) + { + AffineTransform copy = *this; + copy.scale(sx, sy); + return static_cast<SVGMatrix>(copy); + } + + SVGMatrix rotate(double d) + { + AffineTransform copy = *this; + copy.rotate(d); + return static_cast<SVGMatrix>(copy); + } + + SVGMatrix flipX() + { + AffineTransform copy = *this; + copy.flipX(); + return static_cast<SVGMatrix>(copy); + } + + SVGMatrix flipY() + { + AffineTransform copy = *this; + copy.flipY(); + return static_cast<SVGMatrix>(copy); + } + + SVGMatrix skewX(double angle) + { + AffineTransform copy = *this; + copy.skewX(angle); + return static_cast<SVGMatrix>(copy); + } + + SVGMatrix skewY(double angle) + { + AffineTransform copy = *this; + copy.skewY(angle); + return static_cast<SVGMatrix>(copy); + } + + // SVGMatrix::multiply needs to call SVGMatrix::multLeft. + SVGMatrix multiply(const SVGMatrix& other) + { + AffineTransform copy = *this; + copy.multLeft(static_cast<const AffineTransform&>(other)); + return static_cast<SVGMatrix>(copy); + } + + SVGMatrix inverse(ExceptionCode& ec) const + { + AffineTransform transform = AffineTransform::inverse(); + if (!isInvertible()) + ec = SVGException::SVG_MATRIX_NOT_INVERTABLE; + + return transform; + } + + SVGMatrix rotateFromVector(double x, double y, ExceptionCode& ec) + { + if (!x || !y) + ec = SVGException::SVG_INVALID_VALUE_ERR; + + AffineTransform copy = *this; + copy.rotateFromVector(x, y); + return static_cast<SVGMatrix>(copy); + } + +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGMatrix.idl b/Source/WebCore/svg/SVGMatrix.idl new file mode 100644 index 0000000..270a62c --- /dev/null +++ b/Source/WebCore/svg/SVGMatrix.idl @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) 2006 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +module svg { + + interface [Conditional=SVG] SVGMatrix { + // FIXME: these attributes should all be floats but since we implement + // AffineTransform with doubles setting these as doubles makes more sense. + attribute [StrictTypeChecking] double a; + attribute [StrictTypeChecking] double b; + attribute [StrictTypeChecking] double c; + attribute [StrictTypeChecking] double d; + attribute [StrictTypeChecking] double e; + attribute [StrictTypeChecking] double f; + + [StrictTypeChecking, RequiresAllArguments=Raise] SVGMatrix multiply(in SVGMatrix secondMatrix); + SVGMatrix inverse() + raises(SVGException); + [Immutable, StrictTypeChecking, RequiresAllArguments=Raise] SVGMatrix translate(in float x, in float y); + [Immutable, StrictTypeChecking, RequiresAllArguments=Raise] SVGMatrix scale(in float scaleFactor); + [Immutable, StrictTypeChecking, RequiresAllArguments=Raise] SVGMatrix scaleNonUniform(in float scaleFactorX, in float scaleFactorY); + [Immutable, StrictTypeChecking, RequiresAllArguments=Raise] SVGMatrix rotate(in float angle); + [StrictTypeChecking, RequiresAllArguments=Raise] SVGMatrix rotateFromVector(in float x, in float y) + raises(SVGException); + [Immutable] SVGMatrix flipX(); + [Immutable] SVGMatrix flipY(); + [Immutable, StrictTypeChecking, RequiresAllArguments=Raise] SVGMatrix skewX(in float angle); + [Immutable, StrictTypeChecking, RequiresAllArguments=Raise] SVGMatrix skewY(in float angle); + }; + +} diff --git a/Source/WebCore/svg/SVGMetadataElement.cpp b/Source/WebCore/svg/SVGMetadataElement.cpp new file mode 100644 index 0000000..6db3806 --- /dev/null +++ b/Source/WebCore/svg/SVGMetadataElement.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#if ENABLE(SVG) +#include "SVGMetadataElement.h" + +namespace WebCore { + +inline SVGMetadataElement::SVGMetadataElement(const QualifiedName& tagName, Document* document) + : SVGElement(tagName, document) +{ +} + +PassRefPtr<SVGMetadataElement> SVGMetadataElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGMetadataElement(tagName, document)); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGMetadataElement.h b/Source/WebCore/svg/SVGMetadataElement.h new file mode 100644 index 0000000..8fdbfb4 --- /dev/null +++ b/Source/WebCore/svg/SVGMetadataElement.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGMetadataElement_h +#define SVGMetadataElement_h +#if ENABLE(SVG) + +#include "SVGElement.h" + +namespace WebCore { + +class SVGMetadataElement : public SVGElement { +public: + static PassRefPtr<SVGMetadataElement> create(const QualifiedName&, Document*); + +private: + SVGMetadataElement(const QualifiedName&, Document*); +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGMetadataElement.idl b/Source/WebCore/svg/SVGMetadataElement.idl new file mode 100644 index 0000000..8714a15 --- /dev/null +++ b/Source/WebCore/svg/SVGMetadataElement.idl @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * Copyright (C) 2006 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +module svg { + + interface [Conditional=SVG] SVGMetadataElement : SVGElement { + }; + +} diff --git a/Source/WebCore/svg/SVGMissingGlyphElement.cpp b/Source/WebCore/svg/SVGMissingGlyphElement.cpp new file mode 100644 index 0000000..4c80494 --- /dev/null +++ b/Source/WebCore/svg/SVGMissingGlyphElement.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG_FONTS) +#include "SVGMissingGlyphElement.h" + +namespace WebCore { + +inline SVGMissingGlyphElement::SVGMissingGlyphElement(const QualifiedName& tagName, Document* document) + : SVGStyledElement(tagName, document) +{ +} + +PassRefPtr<SVGMissingGlyphElement> SVGMissingGlyphElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGMissingGlyphElement(tagName, document)); +} + +} + +#endif // ENABLE(SVG_FONTS) diff --git a/Source/WebCore/svg/SVGMissingGlyphElement.h b/Source/WebCore/svg/SVGMissingGlyphElement.h new file mode 100644 index 0000000..a133d6d --- /dev/null +++ b/Source/WebCore/svg/SVGMissingGlyphElement.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGMissingGlyphElement_h +#define SVGMissingGlyphElement_h + +#if ENABLE(SVG_FONTS) +#include "SVGStyledElement.h" + +namespace WebCore { + +class SVGMissingGlyphElement : public SVGStyledElement { +public: + static PassRefPtr<SVGMissingGlyphElement> create(const QualifiedName&, Document*); + +private: + SVGMissingGlyphElement(const QualifiedName&, Document*); + + virtual bool rendererIsNeeded(RenderStyle*) { return false; } +}; + +} // namespace WebCore + +#endif // ENABLE(SVG_FONTS) +#endif + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGMissingGlyphElement.idl b/Source/WebCore/svg/SVGMissingGlyphElement.idl new file mode 100644 index 0000000..23d7628 --- /dev/null +++ b/Source/WebCore/svg/SVGMissingGlyphElement.idl @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * + * 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 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 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. + */ + +module svg { + + interface [Conditional=SVG&SVG_FONTS] SVGMissingGlyphElement : SVGElement { + }; + +} diff --git a/Source/WebCore/svg/SVGNumber.idl b/Source/WebCore/svg/SVGNumber.idl new file mode 100644 index 0000000..83e3b6b --- /dev/null +++ b/Source/WebCore/svg/SVGNumber.idl @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) 2006 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +module svg { + + interface [Conditional=SVG] SVGNumber { + attribute [StrictTypeChecking] float value; + }; + +} diff --git a/Source/WebCore/svg/SVGNumberList.cpp b/Source/WebCore/svg/SVGNumberList.cpp new file mode 100644 index 0000000..7c0149c --- /dev/null +++ b/Source/WebCore/svg/SVGNumberList.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGNumberList.h" + +#include "SVGParserUtilities.h" +#include <wtf/text/StringBuilder.h> + +namespace WebCore { + +void SVGNumberList::parse(const String& value) +{ + clear(); + + float number = 0; + const UChar* ptr = value.characters(); + const UChar* end = ptr + value.length(); + + // The spec strangely doesn't allow leading whitespace. We might choose to violate that intentionally. (section 4.1) + while (ptr < end) { + if (!parseNumber(ptr, end, number)) + return; + append(number); + } +} + +String SVGNumberList::valueAsString() const +{ + StringBuilder builder; + + unsigned size = this->size(); + for (unsigned i = 0; i < size; ++i) { + if (i > 0) + builder.append(' '); + + builder.append(String::number(at(i))); + } + + return builder.toString(); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGNumberList.h b/Source/WebCore/svg/SVGNumberList.h new file mode 100644 index 0000000..f42d937 --- /dev/null +++ b/Source/WebCore/svg/SVGNumberList.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGNumberList_h +#define SVGNumberList_h + +#if ENABLE(SVG) +#include "SVGPropertyTraits.h" +#include <wtf/Vector.h> + +namespace WebCore { + +class SVGNumberList : public Vector<float> { +public: + SVGNumberList() { } + + void parse(const String&); + String valueAsString() const; +}; + +template<> +struct SVGPropertyTraits<SVGNumberList> { + typedef float ListItemType; + + static SVGNumberList initialValue() { return SVGNumberList(); } + static String toString(const SVGNumberList& type) { return type.valueAsString(); } +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGNumberList.idl b/Source/WebCore/svg/SVGNumberList.idl new file mode 100644 index 0000000..01ecf31 --- /dev/null +++ b/Source/WebCore/svg/SVGNumberList.idl @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGNumberList { + readonly attribute unsigned long numberOfItems; + + void clear() + raises(DOMException); + [StrictTypeChecking, RequiresAllArguments=Raise] SVGNumber initialize(in SVGNumber item) + raises(DOMException, SVGException); + [StrictTypeChecking, RequiresAllArguments=Raise] SVGNumber getItem(in unsigned long index) + raises(DOMException); + [StrictTypeChecking, RequiresAllArguments=Raise] SVGNumber insertItemBefore(in SVGNumber item, in unsigned long index) + raises(DOMException, SVGException); + [StrictTypeChecking, RequiresAllArguments=Raise] SVGNumber replaceItem(in SVGNumber item, in unsigned long index) + raises(DOMException, SVGException); + [StrictTypeChecking, RequiresAllArguments=Raise] SVGNumber removeItem(in unsigned long index) + raises(DOMException); + [StrictTypeChecking, RequiresAllArguments=Raise] SVGNumber appendItem(in SVGNumber item) + raises(DOMException, SVGException); + }; + +} diff --git a/Source/WebCore/svg/SVGPaint.cpp b/Source/WebCore/svg/SVGPaint.cpp new file mode 100644 index 0000000..76c13d5 --- /dev/null +++ b/Source/WebCore/svg/SVGPaint.cpp @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPaint.h" + +#include "SVGURIReference.h" + +namespace WebCore { + +SVGPaint::SVGPaint() + : m_paintType(SVG_PAINTTYPE_UNKNOWN) +{ +} + +SVGPaint::SVGPaint(const String& uri) + : m_paintType(SVG_PAINTTYPE_URI_RGBCOLOR) +{ + setUri(uri); +} + +SVGPaint::SVGPaint(SVGPaintType paintType) + : m_paintType(paintType) +{ +} + +SVGPaint::SVGPaint(SVGPaintType paintType, const String& uri, const String& rgbPaint, const String&) + : SVGColor(rgbPaint) + , m_paintType(paintType) +{ + setUri(uri); +} + +SVGPaint::SVGPaint(const Color& c) + : SVGColor(c) + , m_paintType(SVG_PAINTTYPE_RGBCOLOR) +{ +} + +SVGPaint::SVGPaint(const String& uri, const Color& c) + : SVGColor(c) + , m_paintType(SVG_PAINTTYPE_URI_RGBCOLOR) +{ + setUri(uri); +} + +SVGPaint* SVGPaint::defaultFill() +{ + static SVGPaint* staticDefaultFill = create(Color::black).releaseRef(); + return staticDefaultFill; +} + +SVGPaint* SVGPaint::defaultStroke() +{ + static SVGPaint* staticDefaultStroke = create(SVG_PAINTTYPE_NONE).releaseRef(); + return staticDefaultStroke; +} + +String SVGPaint::uri() const +{ + return m_uri; +} + +void SVGPaint::setUri(const String& uri) +{ + m_uri = uri; +} + +void SVGPaint::setPaint(SVGPaintType paintType, const String& uri, const String& rgbPaint, const String&, ExceptionCode&) +{ + m_paintType = paintType; + + if (m_paintType == SVG_PAINTTYPE_URI) + setUri(uri); + else if (m_paintType == SVG_PAINTTYPE_RGBCOLOR) + setRGBColor(rgbPaint); +} + +String SVGPaint::cssText() const +{ + if (m_paintType == SVG_PAINTTYPE_NONE) + return "none"; + if (m_paintType == SVG_PAINTTYPE_CURRENTCOLOR) + return "currentColor"; + if (m_paintType == SVG_PAINTTYPE_URI) + return "url(" + m_uri + ")"; + + return SVGColor::cssText(); +} + +bool SVGPaint::matchesTargetURI(const String& referenceId) +{ + if (m_paintType != SVG_PAINTTYPE_URI && m_paintType != SVG_PAINTTYPE_URI_RGBCOLOR) + return false; + + return referenceId == SVGURIReference::getTarget(m_uri); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGPaint.h b/Source/WebCore/svg/SVGPaint.h new file mode 100644 index 0000000..9b66295 --- /dev/null +++ b/Source/WebCore/svg/SVGPaint.h @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmial.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPaint_h +#define SVGPaint_h +#if ENABLE(SVG) +#include "PlatformString.h" +#include "SVGColor.h" + +namespace WebCore { + +class SVGPaint : public SVGColor { +public: + enum SVGPaintType { + SVG_PAINTTYPE_UNKNOWN = 0, + SVG_PAINTTYPE_RGBCOLOR = 1, + SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR = 2, + SVG_PAINTTYPE_NONE = 101, + SVG_PAINTTYPE_CURRENTCOLOR = 102, + SVG_PAINTTYPE_URI_NONE = 103, + SVG_PAINTTYPE_URI_CURRENTCOLOR = 104, + SVG_PAINTTYPE_URI_RGBCOLOR = 105, + SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR = 106, + SVG_PAINTTYPE_URI = 107 + }; + + static PassRefPtr<SVGPaint> create() + { + return adoptRef(new SVGPaint); + } + static PassRefPtr<SVGPaint> create(SVGPaintType type) + { + return adoptRef(new SVGPaint(type)); + } + static PassRefPtr<SVGPaint> create(const Color& color) + { + return adoptRef(new SVGPaint(color)); + } + static PassRefPtr<SVGPaint> create(SVGPaintType type, const String& uri) + { + return adoptRef(new SVGPaint(type, uri, String(), String())); + } + static PassRefPtr<SVGPaint> create(const String& uri, const Color& color) + { + return adoptRef(new SVGPaint(uri, color)); + } + + // 'SVGPaint' functions + SVGPaintType paintType() const { return m_paintType; } + String uri() const; + + void setUri(const String&); + void setPaint(SVGPaintType, const String& uri, const String& rgbPaint, const String& iccPaint, ExceptionCode&); + + static SVGPaint* defaultFill(); + static SVGPaint* defaultStroke(); + + bool matchesTargetURI(const String& referenceId); + +private: + SVGPaint(); + SVGPaint(const String& uri); + SVGPaint(SVGPaintType); + SVGPaint(SVGPaintType, const String& uri, const String& rgbPaint, const String& iccPaint); + SVGPaint(const Color& c); + SVGPaint(const String& uri, const Color& c); + + virtual bool isSVGPaint() const { return true; } + + virtual String cssText() const; + + SVGPaintType m_paintType; + String m_uri; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGPaint_h diff --git a/Source/WebCore/svg/SVGPaint.idl b/Source/WebCore/svg/SVGPaint.idl new file mode 100644 index 0000000..426b762 --- /dev/null +++ b/Source/WebCore/svg/SVGPaint.idl @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGPaint : SVGColor { + // SVGPaintType + const unsigned short SVG_PAINTTYPE_UNKNOWN = 0; + const unsigned short SVG_PAINTTYPE_RGBCOLOR = 1; + const unsigned short SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR = 2; + const unsigned short SVG_PAINTTYPE_NONE = 101; + const unsigned short SVG_PAINTTYPE_CURRENTCOLOR = 102; + const unsigned short SVG_PAINTTYPE_URI_NONE = 103; + const unsigned short SVG_PAINTTYPE_URI_CURRENTCOLOR = 104; + const unsigned short SVG_PAINTTYPE_URI_RGBCOLOR = 105; + const unsigned short SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR = 106; + const unsigned short SVG_PAINTTYPE_URI = 107; + + readonly attribute SVGPaintType paintType; + readonly attribute DOMString uri; + + void setUri(in DOMString uri); + void setPaint(in SVGPaintType paintType, + in DOMString uri, + in DOMString rgbColor, + in DOMString iccColor) + raises(SVGException); + }; + +} diff --git a/Source/WebCore/svg/SVGParserUtilities.cpp b/Source/WebCore/svg/SVGParserUtilities.cpp new file mode 100644 index 0000000..0405230 --- /dev/null +++ b/Source/WebCore/svg/SVGParserUtilities.cpp @@ -0,0 +1,374 @@ +/* + * Copyright (C) 2002, 2003 The Karbon Developers + * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org> + * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org> + * Copyright (C) 2007, 2009 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGParserUtilities.h" + +#include "Document.h" +#include "FloatPoint.h" +#include "SVGPointList.h" + +#include <limits> +#include <wtf/ASCIICType.h> + +namespace WebCore { + +template <typename FloatType> static inline bool isValidRange(const FloatType& x) +{ + static const FloatType max = std::numeric_limits<FloatType>::max(); + return x >= -max && x <= max; +} + +// We use this generic parseNumber function to allow the Path parsing code to work +// at a higher precision internally, without any unnecessary runtime cost or code +// complexity. +template <typename FloatType> static bool genericParseNumber(const UChar*& ptr, const UChar* end, FloatType& number, bool skip) +{ + FloatType integer, decimal, frac, exponent; + int sign, expsign; + const UChar* start = ptr; + + exponent = 0; + integer = 0; + frac = 1; + decimal = 0; + sign = 1; + expsign = 1; + + // read the sign + if (ptr < end && *ptr == '+') + ptr++; + else if (ptr < end && *ptr == '-') { + ptr++; + sign = -1; + } + + if (ptr == end || ((*ptr < '0' || *ptr > '9') && *ptr != '.')) + // The first character of a number must be one of [0-9+-.] + return false; + + // read the integer part, build right-to-left + const UChar* ptrStartIntPart = ptr; + while (ptr < end && *ptr >= '0' && *ptr <= '9') + ++ptr; // Advance to first non-digit. + + if (ptr != ptrStartIntPart) { + const UChar* ptrScanIntPart = ptr - 1; + FloatType multiplier = 1; + while (ptrScanIntPart >= ptrStartIntPart) { + integer += multiplier * static_cast<FloatType>(*(ptrScanIntPart--) - '0'); + multiplier *= 10; + } + // Bail out early if this overflows. + if (!isValidRange(integer)) + return false; + } + + if (ptr < end && *ptr == '.') { // read the decimals + ptr++; + + // There must be a least one digit following the . + if (ptr >= end || *ptr < '0' || *ptr > '9') + return false; + + while (ptr < end && *ptr >= '0' && *ptr <= '9') + decimal += (*(ptr++) - '0') * (frac *= static_cast<FloatType>(0.1)); + } + + // read the exponent part + if (ptr != start && ptr + 1 < end && (*ptr == 'e' || *ptr == 'E') + && (ptr[1] != 'x' && ptr[1] != 'm')) { + ptr++; + + // read the sign of the exponent + if (*ptr == '+') + ptr++; + else if (*ptr == '-') { + ptr++; + expsign = -1; + } + + // There must be an exponent + if (ptr >= end || *ptr < '0' || *ptr > '9') + return false; + + while (ptr < end && *ptr >= '0' && *ptr <= '9') { + exponent *= static_cast<FloatType>(10); + exponent += *ptr - '0'; + ptr++; + } + // Make sure exponent is valid. + if (!isValidRange(exponent) || exponent > std::numeric_limits<FloatType>::max_exponent) + return false; + } + + number = integer + decimal; + number *= sign; + + if (exponent) + number *= static_cast<FloatType>(pow(10.0, expsign * static_cast<int>(exponent))); + + // Don't return Infinity() or NaN(). + if (!isValidRange(number)) + return false; + + if (start == ptr) + return false; + + if (skip) + skipOptionalSpacesOrDelimiter(ptr, end); + + return true; +} + +bool parseNumber(const UChar*& ptr, const UChar* end, float& number, bool skip) +{ + return genericParseNumber(ptr, end, number, skip); +} + +// only used to parse largeArcFlag and sweepFlag which must be a "0" or "1" +// and might not have any whitespace/comma after it +bool parseArcFlag(const UChar*& ptr, const UChar* end, bool& flag) +{ + const UChar flagChar = *ptr++; + if (flagChar == '0') + flag = false; + else if (flagChar == '1') + flag = true; + else + return false; + + skipOptionalSpacesOrDelimiter(ptr, end); + + return true; +} + +bool parseNumberOptionalNumber(const String& s, float& x, float& y) +{ + if (s.isEmpty()) + return false; + const UChar* cur = s.characters(); + const UChar* end = cur + s.length(); + + if (!parseNumber(cur, end, x)) + return false; + + if (cur == end) + y = x; + else if (!parseNumber(cur, end, y, false)) + return false; + + return cur == end; +} + +bool pointsListFromSVGData(SVGPointList& pointsList, const String& points) +{ + if (points.isEmpty()) + return true; + const UChar* cur = points.characters(); + const UChar* end = cur + points.length(); + + skipOptionalSpaces(cur, end); + + bool delimParsed = false; + while (cur < end) { + delimParsed = false; + float xPos = 0.0f; + if (!parseNumber(cur, end, xPos)) + return false; + + float yPos = 0.0f; + if (!parseNumber(cur, end, yPos, false)) + return false; + + skipOptionalSpaces(cur, end); + + if (cur < end && *cur == ',') { + delimParsed = true; + cur++; + } + skipOptionalSpaces(cur, end); + + pointsList.append(FloatPoint(xPos, yPos)); + } + return cur == end && !delimParsed; +} + +bool parseGlyphName(const String& input, HashSet<String>& values) +{ + // FIXME: Parsing error detection is missing. + values.clear(); + + const UChar* ptr = input.characters(); + const UChar* end = ptr + input.length(); + skipOptionalSpaces(ptr, end); + + while (ptr < end) { + // Leading and trailing white space, and white space before and after separators, will be ignored. + const UChar* inputStart = ptr; + while (ptr < end && *ptr != ',') + ++ptr; + + if (ptr == inputStart) + break; + + // walk backwards from the ; to ignore any whitespace + const UChar* inputEnd = ptr - 1; + while (inputStart < inputEnd && isWhitespace(*inputEnd)) + --inputEnd; + + values.add(String(inputStart, inputEnd - inputStart + 1)); + skipOptionalSpacesOrDelimiter(ptr, end, ','); + } + + return true; +} + +static bool parseUnicodeRange(const UChar* characters, unsigned length, UnicodeRange& range) +{ + if (length < 2 || characters[0] != 'U' || characters[1] != '+') + return false; + + // Parse the starting hex number (or its prefix). + unsigned startRange = 0; + unsigned startLength = 0; + + const UChar* ptr = characters + 2; + const UChar* end = characters + length; + while (ptr < end) { + if (!isASCIIHexDigit(*ptr)) + break; + ++startLength; + if (startLength > 6) + return false; + startRange = (startRange << 4) | toASCIIHexValue(*ptr); + ++ptr; + } + + // Handle the case of ranges separated by "-" sign. + if (2 + startLength < length && *ptr == '-') { + if (!startLength) + return false; + + // Parse the ending hex number (or its prefix). + unsigned endRange = 0; + unsigned endLength = 0; + ++ptr; + while (ptr < end) { + if (!isASCIIHexDigit(*ptr)) + break; + ++endLength; + if (endLength > 6) + return false; + endRange = (endRange << 4) | toASCIIHexValue(*ptr); + ++ptr; + } + + if (!endLength) + return false; + + range.first = startRange; + range.second = endRange; + return true; + } + + // Handle the case of a number with some optional trailing question marks. + unsigned endRange = startRange; + while (ptr < end) { + if (*ptr != '?') + break; + ++startLength; + if (startLength > 6) + return false; + startRange <<= 4; + endRange = (endRange << 4) | 0xF; + ++ptr; + } + + if (!startLength) + return false; + + range.first = startRange; + range.second = endRange; + return true; +} + +bool parseKerningUnicodeString(const String& input, UnicodeRanges& rangeList, HashSet<String>& stringList) +{ + // FIXME: Parsing error detection is missing. + const UChar* ptr = input.characters(); + const UChar* end = ptr + input.length(); + + while (ptr < end) { + const UChar* inputStart = ptr; + while (ptr < end && *ptr != ',') + ++ptr; + + if (ptr == inputStart) + break; + + // Try to parse unicode range first + UnicodeRange range; + if (parseUnicodeRange(inputStart, ptr - inputStart, range)) + rangeList.append(range); + else + stringList.add(String(inputStart, ptr - inputStart)); + ++ptr; + } + + return true; +} + +Vector<String> parseDelimitedString(const String& input, const char seperator) +{ + Vector<String> values; + + const UChar* ptr = input.characters(); + const UChar* end = ptr + input.length(); + skipOptionalSpaces(ptr, end); + + while (ptr < end) { + // Leading and trailing white space, and white space before and after semicolon separators, will be ignored. + const UChar* inputStart = ptr; + while (ptr < end && *ptr != seperator) // careful not to ignore whitespace inside inputs + ptr++; + + if (ptr == inputStart) + break; + + // walk backwards from the ; to ignore any whitespace + const UChar* inputEnd = ptr - 1; + while (inputStart < inputEnd && isWhitespace(*inputEnd)) + inputEnd--; + + values.append(String(inputStart, inputEnd - inputStart + 1)); + skipOptionalSpacesOrDelimiter(ptr, end, seperator); + } + + return values; +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGParserUtilities.h b/Source/WebCore/svg/SVGParserUtilities.h new file mode 100644 index 0000000..da8ac1f --- /dev/null +++ b/Source/WebCore/svg/SVGParserUtilities.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2002, 2003 The Karbon Developers + * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGParserUtilities_h +#define SVGParserUtilities_h +#if ENABLE(SVG) + +#include "ParserUtilities.h" +#include <wtf/HashSet.h> + +typedef pair<unsigned, unsigned> UnicodeRange; +typedef Vector<UnicodeRange> UnicodeRanges; + +namespace WebCore { + +class SVGPointList; + +bool parseNumber(const UChar*& ptr, const UChar* end, float& number, bool skip = true); +bool parseNumberOptionalNumber(const String& s, float& h, float& v); +bool parseArcFlag(const UChar*& ptr, const UChar* end, bool& flag); + +// SVG allows several different whitespace characters: +// http://www.w3.org/TR/SVG/paths.html#PathDataBNF +inline bool isWhitespace(const UChar& c) +{ + return c == ' ' || c == '\t' || c == '\n' || c == '\r'; +} + +inline bool skipOptionalSpaces(const UChar*& ptr, const UChar* end) +{ + while (ptr < end && isWhitespace(*ptr)) + ptr++; + return ptr < end; +} + +inline bool skipOptionalSpacesOrDelimiter(const UChar*& ptr, const UChar* end, UChar delimiter = ',') +{ + if (ptr < end && !isWhitespace(*ptr) && *ptr != delimiter) + return false; + if (skipOptionalSpaces(ptr, end)) { + if (ptr < end && *ptr == delimiter) { + ptr++; + skipOptionalSpaces(ptr, end); + } + } + return ptr < end; +} + +bool pointsListFromSVGData(SVGPointList& pointsList, const String& points); +Vector<String> parseDelimitedString(const String& input, const char seperator); +bool parseKerningUnicodeString(const String& input, UnicodeRanges&, HashSet<String>& stringList); +bool parseGlyphName(const String& input, HashSet<String>& values); + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGParserUtilities_h diff --git a/Source/WebCore/svg/SVGPathBlender.cpp b/Source/WebCore/svg/SVGPathBlender.cpp new file mode 100644 index 0000000..d46e24a --- /dev/null +++ b/Source/WebCore/svg/SVGPathBlender.cpp @@ -0,0 +1,288 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPathBlender.h" + +#include "SVGPathSeg.h" + +namespace WebCore { + +SVGPathBlender::SVGPathBlender() + : m_fromSource(0) + , m_toSource(0) + , m_consumer(0) + , m_progress(0) +{ +} + +float SVGPathBlender::blendAnimatedFloat(float from, float to) +{ + return (to - from) * m_progress + from; +} + +FloatPoint SVGPathBlender::blendAnimatedFloatPoint(FloatPoint& from, FloatPoint& to) +{ + return FloatPoint((to.x() - from.x()) * m_progress + from.x(), (to.y() - from.y()) * m_progress + from.y()); +} + +bool SVGPathBlender::blendMoveToSegment() +{ + FloatPoint fromTargetPoint; + FloatPoint toTargetPoint; + if (!m_fromSource->parseMoveToSegment(fromTargetPoint) + || !m_toSource->parseMoveToSegment(toTargetPoint)) + return false; + + m_consumer->moveTo(blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint), false, m_mode); + return true; +} + +bool SVGPathBlender::blendLineToSegment() +{ + FloatPoint fromTargetPoint; + FloatPoint toTargetPoint; + if (!m_fromSource->parseLineToSegment(fromTargetPoint) + || !m_toSource->parseLineToSegment(toTargetPoint)) + return false; + + m_consumer->lineTo(blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint), m_mode); + return true; +} + +bool SVGPathBlender::blendLineToHorizontalSegment() +{ + float fromX; + float toX; + if (!m_fromSource->parseLineToHorizontalSegment(fromX) + || !m_toSource->parseLineToHorizontalSegment(toX)) + return false; + + m_consumer->lineToHorizontal(blendAnimatedFloat(fromX, toX), m_mode); + return true; +} + +bool SVGPathBlender::blendLineToVerticalSegment() +{ + float fromY; + float toY; + if (!m_fromSource->parseLineToVerticalSegment(fromY) + || !m_toSource->parseLineToVerticalSegment(toY)) + return false; + + m_consumer->lineToVertical(blendAnimatedFloat(fromY, toY), m_mode); + return true; +} + +bool SVGPathBlender::blendCurveToCubicSegment() +{ + FloatPoint fromTargetPoint; + FloatPoint fromPoint1; + FloatPoint fromPoint2; + FloatPoint toTargetPoint; + FloatPoint toPoint1; + FloatPoint toPoint2; + if (!m_fromSource->parseCurveToCubicSegment(fromPoint1, fromPoint2, fromTargetPoint) + || !m_toSource->parseCurveToCubicSegment(toPoint1, toPoint2, toTargetPoint)) + return false; + + m_consumer->curveToCubic(blendAnimatedFloatPoint(fromPoint1, toPoint1), + blendAnimatedFloatPoint(fromPoint2, toPoint2), + blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint), + m_mode); + return true; +} + +bool SVGPathBlender::blendCurveToCubicSmoothSegment() +{ + FloatPoint fromTargetPoint; + FloatPoint fromPoint2; + FloatPoint toTargetPoint; + FloatPoint toPoint2; + if (!m_fromSource->parseCurveToCubicSmoothSegment(fromPoint2, fromTargetPoint) + || !m_toSource->parseCurveToCubicSmoothSegment(toPoint2, toTargetPoint)) + return false; + + m_consumer->curveToCubicSmooth(blendAnimatedFloatPoint(fromPoint2, toPoint2), + blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint), + m_mode); + return true; +} + +bool SVGPathBlender::blendCurveToQuadraticSegment() +{ + FloatPoint fromTargetPoint; + FloatPoint fromPoint1; + FloatPoint toTargetPoint; + FloatPoint toPoint1; + if (!m_fromSource->parseCurveToQuadraticSegment(fromPoint1, fromTargetPoint) + || !m_toSource->parseCurveToQuadraticSegment(toPoint1, toTargetPoint)) + return false; + + m_consumer->curveToQuadratic(blendAnimatedFloatPoint(fromPoint1, toPoint1), + blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint), + m_mode); + return true; +} + +bool SVGPathBlender::blendCurveToQuadraticSmoothSegment() +{ + FloatPoint fromTargetPoint; + FloatPoint toTargetPoint; + if (!m_fromSource->parseCurveToQuadraticSmoothSegment(fromTargetPoint) + || !m_toSource->parseCurveToQuadraticSmoothSegment(toTargetPoint)) + return false; + + m_consumer->curveToQuadraticSmooth(blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint), m_mode); + return true; +} + +bool SVGPathBlender::blendArcToSegment() +{ + float fromRx; + float fromRy; + float fromAngle; + bool fromLargeArc; + bool fromSweep; + FloatPoint fromTargetPoint; + float toRx; + float toRy; + float toAngle; + bool toLargeArc; + bool toSweep; + FloatPoint toTargetPoint; + if (!m_fromSource->parseArcToSegment(fromRx, fromRy, fromAngle, fromLargeArc, fromSweep, fromTargetPoint) + || !m_toSource->parseArcToSegment(toRx, toRy, toAngle, toLargeArc, toSweep, toTargetPoint)) + return false; + + m_consumer->arcTo(blendAnimatedFloat(fromRx, toRx), + blendAnimatedFloat(fromRy, toRy), + blendAnimatedFloat(fromAngle, toAngle), + m_progress < 0.5 ? fromLargeArc : toLargeArc, + m_progress < 0.5 ? fromSweep : toSweep, + blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint), + m_mode); + return true; +} + +bool SVGPathBlender::blendAnimatedPath(float progress, SVGPathSource* fromSource, SVGPathSource* toSource, SVGPathConsumer* consumer) +{ + ASSERT(fromSource); + ASSERT(toSource); + ASSERT(consumer); + m_fromSource = fromSource; + m_toSource = toSource; + m_consumer = consumer; + + m_progress = progress; + while (true) { + SVGPathSegType fromCommand; + SVGPathSegType toCommand; + if (!m_fromSource->parseSVGSegmentType(fromCommand) || !m_toSource->parseSVGSegmentType(toCommand)) + return false; + if (fromCommand != toCommand) + return false; + + m_mode = AbsoluteCoordinates; + switch (fromCommand) { + case PathSegMoveToRel: + m_mode = RelativeCoordinates; + case PathSegMoveToAbs: + if (!blendMoveToSegment()) + return false; + break; + case PathSegLineToRel: + m_mode = RelativeCoordinates; + case PathSegLineToAbs: + if (!blendLineToSegment()) + return false; + break; + case PathSegLineToHorizontalRel: + m_mode = RelativeCoordinates; + case PathSegLineToHorizontalAbs: + if (!blendLineToHorizontalSegment()) + return false; + break; + case PathSegLineToVerticalRel: + m_mode = RelativeCoordinates; + case PathSegLineToVerticalAbs: + if (!blendLineToVerticalSegment()) + return false; + break; + case PathSegClosePath: + m_consumer->closePath(); + break; + case PathSegCurveToCubicRel: + m_mode = RelativeCoordinates; + case PathSegCurveToCubicAbs: + if (!blendCurveToCubicSegment()) + return false; + break; + case PathSegCurveToCubicSmoothRel: + m_mode = RelativeCoordinates; + case PathSegCurveToCubicSmoothAbs: + if (!blendCurveToCubicSmoothSegment()) + return false; + break; + case PathSegCurveToQuadraticRel: + m_mode = RelativeCoordinates; + case PathSegCurveToQuadraticAbs: + if (!blendCurveToQuadraticSegment()) + return false; + break; + case PathSegCurveToQuadraticSmoothRel: + m_mode = RelativeCoordinates; + case PathSegCurveToQuadraticSmoothAbs: + if (!blendCurveToQuadraticSmoothSegment()) + return false; + break; + case PathSegArcRel: + m_mode = RelativeCoordinates; + case PathSegArcAbs: + if (!blendArcToSegment()) + return false; + break; + default: + return false; + } + if (m_fromSource->hasMoreData() != m_toSource->hasMoreData()) + return false; + if (!m_fromSource->hasMoreData() || !m_toSource->hasMoreData()) + break; + } + return true; +} + +void SVGPathBlender::cleanup() +{ + ASSERT(m_toSource); + ASSERT(m_fromSource); + ASSERT(m_consumer); + + m_consumer->cleanup(); + m_toSource = 0; + m_fromSource = 0; + m_consumer = 0; +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGPathBlender.h b/Source/WebCore/svg/SVGPathBlender.h new file mode 100644 index 0000000..c0ae7f3 --- /dev/null +++ b/Source/WebCore/svg/SVGPathBlender.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPathBlender_h +#define SVGPathBlender_h + +#if ENABLE(SVG) +#include "SVGPathConsumer.h" +#include "SVGPathSource.h" +#include <wtf/Noncopyable.h> + +namespace WebCore { + +class SVGPathBlender : public Noncopyable { +public: + SVGPathBlender(); + + bool blendAnimatedPath(float, SVGPathSource*, SVGPathSource*, SVGPathConsumer*); + void cleanup(); + +private: + bool blendMoveToSegment(); + bool blendLineToSegment(); + bool blendLineToHorizontalSegment(); + bool blendLineToVerticalSegment(); + bool blendCurveToCubicSegment(); + bool blendCurveToCubicSmoothSegment(); + bool blendCurveToQuadraticSegment(); + bool blendCurveToQuadraticSmoothSegment(); + bool blendArcToSegment(); + + float blendAnimatedFloat(float, float); + FloatPoint blendAnimatedFloatPoint(FloatPoint&, FloatPoint&); + + SVGPathSource* m_fromSource; + SVGPathSource* m_toSource; + SVGPathConsumer* m_consumer; + PathCoordinateMode m_mode; + float m_progress; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGPathBlender_h diff --git a/Source/WebCore/svg/SVGPathBuilder.cpp b/Source/WebCore/svg/SVGPathBuilder.cpp new file mode 100644 index 0000000..6687edf --- /dev/null +++ b/Source/WebCore/svg/SVGPathBuilder.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2002, 2003 The Karbon Developers + * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org> + * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org> + * Copyright (C) 2007, 2009 Apple Inc. All rights reserved. + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPathBuilder.h" + +namespace WebCore { + +SVGPathBuilder::SVGPathBuilder() + : m_path(0) +{ +} + +void SVGPathBuilder::moveTo(const FloatPoint& targetPoint, bool closed, PathCoordinateMode mode) +{ + ASSERT(m_path); + m_current = mode == AbsoluteCoordinates ? targetPoint : m_current + targetPoint; + if (closed && !m_path->isEmpty()) + m_path->closeSubpath(); + m_path->moveTo(m_current); +} + +void SVGPathBuilder::lineTo(const FloatPoint& targetPoint, PathCoordinateMode mode) +{ + ASSERT(m_path); + m_current = mode == AbsoluteCoordinates ? targetPoint : m_current + targetPoint; + m_path->addLineTo(m_current); +} + +void SVGPathBuilder::curveToCubic(const FloatPoint& point1, const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode) +{ + ASSERT(m_path); + if (mode == RelativeCoordinates) { + m_path->addBezierCurveTo(m_current + point1, m_current + point2, m_current + targetPoint); + m_current += targetPoint; + } else { + m_current = targetPoint; + m_path->addBezierCurveTo(point1, point2, m_current); + } +} + +void SVGPathBuilder::closePath() +{ + ASSERT(m_path); + m_path->closeSubpath(); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGPathBuilder.h b/Source/WebCore/svg/SVGPathBuilder.h new file mode 100644 index 0000000..f3c2632 --- /dev/null +++ b/Source/WebCore/svg/SVGPathBuilder.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2002, 2003 The Karbon Developers + * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org> + * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org> + * Copyright (C) 2007, 2009 Apple Inc. All rights reserved. + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPathBuilder_h +#define SVGPathBuilder_h + +#if ENABLE(SVG) +#include "FloatPoint.h" +#include "Path.h" +#include "SVGPathConsumer.h" + +namespace WebCore { + +class SVGPathBuilder : public SVGPathConsumer { +public: + SVGPathBuilder(); + + void setCurrentPath(Path* path) { m_path = path; } + +private: + virtual void incrementPathSegmentCount() { } + virtual bool continueConsuming() { return true; } + virtual void cleanup() { m_path = 0; } + + // Used in UnalteredParisng/NormalizedParsing modes. + virtual void moveTo(const FloatPoint&, bool closed, PathCoordinateMode); + virtual void lineTo(const FloatPoint&, PathCoordinateMode); + virtual void curveToCubic(const FloatPoint&, const FloatPoint&, const FloatPoint&, PathCoordinateMode); + virtual void closePath(); + + // Only used in UnalteredParsing mode. + virtual void lineToHorizontal(float, PathCoordinateMode) { ASSERT_NOT_REACHED(); } + virtual void lineToVertical(float, PathCoordinateMode) { ASSERT_NOT_REACHED(); } + virtual void curveToCubicSmooth(const FloatPoint&, const FloatPoint&, PathCoordinateMode) { ASSERT_NOT_REACHED(); } + virtual void curveToQuadratic(const FloatPoint&, const FloatPoint&, PathCoordinateMode) { ASSERT_NOT_REACHED(); } + virtual void curveToQuadraticSmooth(const FloatPoint&, PathCoordinateMode) { ASSERT_NOT_REACHED(); } + virtual void arcTo(float, float, float, bool, bool, const FloatPoint&, PathCoordinateMode) { ASSERT_NOT_REACHED(); } + + Path* m_path; + FloatPoint m_current; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGPathBuilder_h diff --git a/Source/WebCore/svg/SVGPathByteStream.h b/Source/WebCore/svg/SVGPathByteStream.h new file mode 100644 index 0000000..b8882b6 --- /dev/null +++ b/Source/WebCore/svg/SVGPathByteStream.h @@ -0,0 +1,70 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPathByteStream_h +#define SVGPathByteStream_h + +#if ENABLE(SVG) +#include <wtf/Noncopyable.h> +#include <wtf/PassOwnPtr.h> +#include <wtf/Vector.h> + +namespace WebCore { + +// Type definitions for the byte stream data +typedef union { + bool value; + unsigned char bytes[sizeof(bool)]; +} BoolByte; + +typedef union { + float value; + unsigned char bytes[sizeof(float)]; +} FloatByte; + +typedef union { + unsigned short value; + unsigned char bytes[sizeof(unsigned short)]; +} UnsignedShortByte; + +class SVGPathByteStream : public Noncopyable { +public: + static PassOwnPtr<SVGPathByteStream> create() + { + return adoptPtr(new SVGPathByteStream); + } + + typedef Vector<unsigned char> Data; + typedef Data::const_iterator DataIterator; + + DataIterator begin() { return m_data.begin(); } + DataIterator end() { return m_data.end(); } + void append(unsigned char byte) { m_data.append(byte); } + void clear() { m_data.clear(); } + bool isEmpty() const { return !m_data.size(); } + +private: + SVGPathByteStream() { } + Data m_data; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGPathByteStream_h diff --git a/Source/WebCore/svg/SVGPathByteStreamBuilder.cpp b/Source/WebCore/svg/SVGPathByteStreamBuilder.cpp new file mode 100644 index 0000000..cf939f0 --- /dev/null +++ b/Source/WebCore/svg/SVGPathByteStreamBuilder.cpp @@ -0,0 +1,117 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPathByteStreamBuilder.h" + +#include "SVGPathParser.h" +#include "SVGPathSeg.h" +#include "SVGPathStringSource.h" +#include <wtf/OwnPtr.h> + +namespace WebCore { + +SVGPathByteStreamBuilder::SVGPathByteStreamBuilder() + : m_byteStream(0) +{ +} + +void SVGPathByteStreamBuilder::moveTo(const FloatPoint& targetPoint, bool, PathCoordinateMode mode) +{ + ASSERT(m_byteStream); + writeSegmentType(mode == RelativeCoordinates ? PathSegMoveToRel : PathSegMoveToAbs); + writeFloatPoint(targetPoint); +} + +void SVGPathByteStreamBuilder::lineTo(const FloatPoint& targetPoint, PathCoordinateMode mode) +{ + ASSERT(m_byteStream); + writeSegmentType(mode == RelativeCoordinates ? PathSegLineToRel : PathSegLineToAbs); + writeFloatPoint(targetPoint); +} + +void SVGPathByteStreamBuilder::lineToHorizontal(float x, PathCoordinateMode mode) +{ + ASSERT(m_byteStream); + writeSegmentType(mode == RelativeCoordinates ? PathSegLineToHorizontalRel : PathSegLineToHorizontalAbs); + writeFloat(x); +} + +void SVGPathByteStreamBuilder::lineToVertical(float y, PathCoordinateMode mode) +{ + ASSERT(m_byteStream); + writeSegmentType(mode == RelativeCoordinates ? PathSegLineToVerticalRel : PathSegLineToVerticalAbs); + writeFloat(y); +} + +void SVGPathByteStreamBuilder::curveToCubic(const FloatPoint& point1, const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode) +{ + ASSERT(m_byteStream); + writeSegmentType(mode == RelativeCoordinates ? PathSegCurveToCubicRel : PathSegCurveToCubicAbs); + writeFloatPoint(point1); + writeFloatPoint(point2); + writeFloatPoint(targetPoint); +} + +void SVGPathByteStreamBuilder::curveToCubicSmooth(const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode) +{ + ASSERT(m_byteStream); + writeSegmentType(mode == RelativeCoordinates ? PathSegCurveToCubicSmoothRel : PathSegCurveToCubicSmoothAbs); + writeFloatPoint(point2); + writeFloatPoint(targetPoint); +} + +void SVGPathByteStreamBuilder::curveToQuadratic(const FloatPoint& point1, const FloatPoint& targetPoint, PathCoordinateMode mode) +{ + ASSERT(m_byteStream); + writeSegmentType(mode == RelativeCoordinates ? PathSegCurveToQuadraticRel : PathSegCurveToQuadraticAbs); + writeFloatPoint(point1); + writeFloatPoint(targetPoint); +} + +void SVGPathByteStreamBuilder::curveToQuadraticSmooth(const FloatPoint& targetPoint, PathCoordinateMode mode) +{ + ASSERT(m_byteStream); + writeSegmentType(mode == RelativeCoordinates ? PathSegCurveToQuadraticSmoothRel : PathSegCurveToQuadraticSmoothAbs); + writeFloatPoint(targetPoint); +} + +void SVGPathByteStreamBuilder::arcTo(float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag, const FloatPoint& targetPoint, PathCoordinateMode mode) +{ + ASSERT(m_byteStream); + writeSegmentType(mode == RelativeCoordinates ? PathSegArcRel : PathSegArcAbs); + writeFloat(r1); + writeFloat(r2); + writeFloat(angle); + writeFlag(largeArcFlag); + writeFlag(sweepFlag); + writeFloatPoint(targetPoint); +} + +void SVGPathByteStreamBuilder::closePath() +{ + ASSERT(m_byteStream); + writeSegmentType(PathSegClosePath); +} + +} // namespace WebCore + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGPathByteStreamBuilder.h b/Source/WebCore/svg/SVGPathByteStreamBuilder.h new file mode 100644 index 0000000..55803aa --- /dev/null +++ b/Source/WebCore/svg/SVGPathByteStreamBuilder.h @@ -0,0 +1,98 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPathByteStreamBuilder_h +#define SVGPathByteStreamBuilder_h + +#if ENABLE(SVG) +#include "FloatPoint.h" +#include "PlatformString.h" +#include "SVGPathByteStream.h" +#include "SVGPathConsumer.h" +#include <wtf/PassOwnPtr.h> + +namespace WebCore { + +class SVGPathByteStreamBuilder : public SVGPathConsumer { +public: + SVGPathByteStreamBuilder(); + + void setCurrentByteStream(SVGPathByteStream* byteStream) { m_byteStream = byteStream; } + +private: + virtual void incrementPathSegmentCount() { } + virtual bool continueConsuming() { return true; } + virtual void cleanup() { m_byteStream = 0; } + + // Used in UnalteredParsing/NormalizedParsing modes. + virtual void moveTo(const FloatPoint&, bool closed, PathCoordinateMode); + virtual void lineTo(const FloatPoint&, PathCoordinateMode); + virtual void curveToCubic(const FloatPoint&, const FloatPoint&, const FloatPoint&, PathCoordinateMode); + virtual void closePath(); + + // Only used in UnalteredParsing mode. + virtual void lineToHorizontal(float, PathCoordinateMode); + virtual void lineToVertical(float, PathCoordinateMode); + virtual void curveToCubicSmooth(const FloatPoint&, const FloatPoint&, PathCoordinateMode); + virtual void curveToQuadratic(const FloatPoint&, const FloatPoint&, PathCoordinateMode); + virtual void curveToQuadraticSmooth(const FloatPoint&, PathCoordinateMode); + virtual void arcTo(float, float, float, bool largeArcFlag, bool sweepFlag, const FloatPoint&, PathCoordinateMode); + + template<typename ByteType> + void writeType(const ByteType& type) + { + size_t typeSize = sizeof(ByteType); + for (size_t i = 0; i < typeSize; ++i) + m_byteStream->append(type.bytes[i]); + } + + void writeFlag(bool value) + { + BoolByte data; + data.value = value; + writeType(data); + } + + void writeFloat(float value) + { + FloatByte data; + data.value = value; + writeType(data); + } + + void writeFloatPoint(const FloatPoint& point) + { + writeFloat(point.x()); + writeFloat(point.y()); + } + + void writeSegmentType(unsigned short value) + { + UnsignedShortByte data; + data.value = value; + writeType(data); + } + + SVGPathByteStream* m_byteStream; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGPathByteStreamBuilder_h diff --git a/Source/WebCore/svg/SVGPathByteStreamSource.cpp b/Source/WebCore/svg/SVGPathByteStreamSource.cpp new file mode 100644 index 0000000..d0475f3 --- /dev/null +++ b/Source/WebCore/svg/SVGPathByteStreamSource.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPathByteStreamSource.h" + +namespace WebCore { + +SVGPathByteStreamSource::SVGPathByteStreamSource(SVGPathByteStream* stream) + : m_stream(stream) +{ + ASSERT(stream); + m_streamCurrent = stream->begin(); + m_streamEnd = stream->end(); +} + +bool SVGPathByteStreamSource::hasMoreData() const +{ + return m_streamCurrent < m_streamEnd; +} + +bool SVGPathByteStreamSource::parseSVGSegmentType(SVGPathSegType& pathSegType) +{ + pathSegType = static_cast<SVGPathSegType>(readSVGSegmentType()); + return true; +} + +SVGPathSegType SVGPathByteStreamSource::nextCommand(SVGPathSegType) +{ + return static_cast<SVGPathSegType>(readSVGSegmentType()); +} + +bool SVGPathByteStreamSource::parseMoveToSegment(FloatPoint& targetPoint) +{ + targetPoint = readFloatPoint(); + return true; +} + +bool SVGPathByteStreamSource::parseLineToSegment(FloatPoint& targetPoint) +{ + targetPoint = readFloatPoint(); + return true; +} + +bool SVGPathByteStreamSource::parseLineToHorizontalSegment(float& x) +{ + x = readFloat(); + return true; +} + +bool SVGPathByteStreamSource::parseLineToVerticalSegment(float& y) +{ + y = readFloat(); + return true; +} + +bool SVGPathByteStreamSource::parseCurveToCubicSegment(FloatPoint& point1, FloatPoint& point2, FloatPoint& targetPoint) +{ + point1 = readFloatPoint(); + point2 = readFloatPoint(); + targetPoint = readFloatPoint(); + return true; +} + +bool SVGPathByteStreamSource::parseCurveToCubicSmoothSegment(FloatPoint& point2, FloatPoint& targetPoint) +{ + point2 = readFloatPoint(); + targetPoint = readFloatPoint(); + return true; +} + +bool SVGPathByteStreamSource::parseCurveToQuadraticSegment(FloatPoint& point1, FloatPoint& targetPoint) +{ + point1 = readFloatPoint(); + targetPoint = readFloatPoint(); + return true; +} + +bool SVGPathByteStreamSource::parseCurveToQuadraticSmoothSegment(FloatPoint& targetPoint) +{ + targetPoint = readFloatPoint(); + return true; +} + +bool SVGPathByteStreamSource::parseArcToSegment(float& rx, float& ry, float& angle, bool& largeArc, bool& sweep, FloatPoint& targetPoint) +{ + rx = readFloat(); + ry = readFloat(); + angle = readFloat(); + largeArc = readFlag(); + sweep = readFlag(); + targetPoint = readFloatPoint(); + return true; +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGPathByteStreamSource.h b/Source/WebCore/svg/SVGPathByteStreamSource.h new file mode 100644 index 0000000..6895c73 --- /dev/null +++ b/Source/WebCore/svg/SVGPathByteStreamSource.h @@ -0,0 +1,104 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPathByteStreamSource_h +#define SVGPathByteStreamSource_h + +#if ENABLE(SVG) +#include "FloatPoint.h" +#include "SVGPathByteStream.h" +#include "SVGPathSource.h" +#include <wtf/PassOwnPtr.h> + +namespace WebCore { + +class SVGPathByteStreamSource : public SVGPathSource { +public: + static PassOwnPtr<SVGPathByteStreamSource> create(SVGPathByteStream* stream) + { + return adoptPtr(new SVGPathByteStreamSource(stream)); + } + +private: + SVGPathByteStreamSource(SVGPathByteStream*); + + virtual bool hasMoreData() const; + virtual bool moveToNextToken() { return true; } + virtual bool parseSVGSegmentType(SVGPathSegType&); + virtual SVGPathSegType nextCommand(SVGPathSegType); + + virtual bool parseMoveToSegment(FloatPoint&); + virtual bool parseLineToSegment(FloatPoint&); + virtual bool parseLineToHorizontalSegment(float&); + virtual bool parseLineToVerticalSegment(float&); + virtual bool parseCurveToCubicSegment(FloatPoint&, FloatPoint&, FloatPoint&); + virtual bool parseCurveToCubicSmoothSegment(FloatPoint&, FloatPoint&); + virtual bool parseCurveToQuadraticSegment(FloatPoint&, FloatPoint&); + virtual bool parseCurveToQuadraticSmoothSegment(FloatPoint&); + virtual bool parseArcToSegment(float&, float&, float&, bool&, bool&, FloatPoint&); + +#if COMPILER(MSVC) +#pragma warning(disable: 4701) +#endif + template<typename DataType, typename ByteType> + DataType readType() + { + ByteType data; + size_t typeSize = sizeof(ByteType); + + for (size_t i = 0; i < typeSize; ++i) { + ASSERT(m_streamCurrent < m_streamEnd); + data.bytes[i] = *m_streamCurrent; + ++m_streamCurrent; + } + + return data.value; + } + + bool readFlag() + { + return readType<bool, BoolByte>(); + } + + float readFloat() + { + return readType<float, FloatByte>(); + } + + unsigned short readSVGSegmentType() + { + return readType<unsigned short, UnsignedShortByte>(); + } + + FloatPoint readFloatPoint() + { + float x = readType<float, FloatByte>(); + float y = readType<float, FloatByte>(); + return FloatPoint(x, y); + } + + SVGPathByteStream* m_stream; + SVGPathByteStream::DataIterator m_streamCurrent; + SVGPathByteStream::DataIterator m_streamEnd; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGPathByteStreamSource_h diff --git a/Source/WebCore/svg/SVGPathConsumer.h b/Source/WebCore/svg/SVGPathConsumer.h new file mode 100644 index 0000000..b7c5e73 --- /dev/null +++ b/Source/WebCore/svg/SVGPathConsumer.h @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2002, 2003 The Karbon Developers + * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org> + * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org> + * Copyright (C) 2007, 2009 Apple Inc. All rights reserved. + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPathConsumer_h +#define SVGPathConsumer_h + +#if ENABLE(SVG) +#include "FloatPoint.h" +#include <wtf/Noncopyable.h> + +namespace WebCore { + +enum PathCoordinateMode { + AbsoluteCoordinates, + RelativeCoordinates +}; + +enum PathParsingMode { + NormalizedParsing, + UnalteredParsing +}; + +class SVGPathConsumer : public Noncopyable { +public: + virtual void incrementPathSegmentCount() = 0; + virtual bool continueConsuming() = 0; + virtual void cleanup() = 0; + + // Used in UnalteredParisng/NormalizedParsing modes. + virtual void moveTo(const FloatPoint&, bool closed, PathCoordinateMode) = 0; + virtual void lineTo(const FloatPoint&, PathCoordinateMode) = 0; + virtual void curveToCubic(const FloatPoint&, const FloatPoint&, const FloatPoint&, PathCoordinateMode) = 0; + virtual void closePath() = 0; + + // Only used in UnalteredParsing mode. + virtual void lineToHorizontal(float, PathCoordinateMode) = 0; + virtual void lineToVertical(float, PathCoordinateMode) = 0; + virtual void curveToCubicSmooth(const FloatPoint&, const FloatPoint&, PathCoordinateMode) = 0; + virtual void curveToQuadratic(const FloatPoint&, const FloatPoint&, PathCoordinateMode) = 0; + virtual void curveToQuadraticSmooth(const FloatPoint&, PathCoordinateMode) = 0; + virtual void arcTo(float, float, float, bool largeArcFlag, bool sweepFlag, const FloatPoint&, PathCoordinateMode) = 0; + +protected: + virtual ~SVGPathConsumer() { } +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGPathConsumer_h diff --git a/Source/WebCore/svg/SVGPathElement.cpp b/Source/WebCore/svg/SVGPathElement.cpp new file mode 100644 index 0000000..77b543f --- /dev/null +++ b/Source/WebCore/svg/SVGPathElement.cpp @@ -0,0 +1,353 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPathElement.h" + +#include "Attribute.h" +#include "RenderSVGPath.h" +#include "RenderSVGResource.h" +#include "SVGNames.h" +#include "SVGPathParserFactory.h" +#include "SVGPathSegArc.h" +#include "SVGPathSegClosePath.h" +#include "SVGPathSegCurvetoCubic.h" +#include "SVGPathSegCurvetoCubicSmooth.h" +#include "SVGPathSegCurvetoQuadratic.h" +#include "SVGPathSegCurvetoQuadraticSmooth.h" +#include "SVGPathSegLineto.h" +#include "SVGPathSegLinetoHorizontal.h" +#include "SVGPathSegLinetoVertical.h" +#include "SVGPathSegList.h" +#include "SVGPathSegListBuilder.h" +#include "SVGPathSegListPropertyTearOff.h" +#include "SVGPathSegMoveto.h" +#include "SVGSVGElement.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_NUMBER(SVGPathElement, SVGNames::pathLengthAttr, PathLength, pathLength) +DEFINE_ANIMATED_BOOLEAN(SVGPathElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) + +inline SVGPathElement::SVGPathElement(const QualifiedName& tagName, Document* document) + : SVGStyledTransformableElement(tagName, document) + , m_pathByteStream(SVGPathByteStream::create()) + , m_pathSegList(PathSegUnalteredRole) +{ +} + +PassRefPtr<SVGPathElement> SVGPathElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGPathElement(tagName, document)); +} + +float SVGPathElement::getTotalLength() +{ + // FIXME: this may wish to use the pathSegList instead of the pathdata if that's cheaper to build (or cached) + Path path; + toPathData(path); + return path.length(); +} + +FloatPoint SVGPathElement::getPointAtLength(float length) +{ + // FIXME: this may wish to use the pathSegList instead of the pathdata if that's cheaper to build (or cached) + bool ok = false; + Path path; + toPathData(path); + return path.pointAtLength(length, ok); +} + +unsigned long SVGPathElement::getPathSegAtLength(float length) +{ + SVGPathParserFactory* factory = SVGPathParserFactory::self(); + unsigned long pathSeg = 0; + factory->getSVGPathSegAtLengthFromSVGPathByteStream(m_pathByteStream.get(), length, pathSeg); + return pathSeg; +} + +PassRefPtr<SVGPathSegClosePath> SVGPathElement::createSVGPathSegClosePath(SVGPathSegRole role) +{ + return SVGPathSegClosePath::create(this, role); +} + +PassRefPtr<SVGPathSegMovetoAbs> SVGPathElement::createSVGPathSegMovetoAbs(float x, float y, SVGPathSegRole role) +{ + return SVGPathSegMovetoAbs::create(this, role, x, y); +} + +PassRefPtr<SVGPathSegMovetoRel> SVGPathElement::createSVGPathSegMovetoRel(float x, float y, SVGPathSegRole role) +{ + return SVGPathSegMovetoRel::create(this, role, x, y); +} + +PassRefPtr<SVGPathSegLinetoAbs> SVGPathElement::createSVGPathSegLinetoAbs(float x, float y, SVGPathSegRole role) +{ + return SVGPathSegLinetoAbs::create(this, role, x, y); +} + +PassRefPtr<SVGPathSegLinetoRel> SVGPathElement::createSVGPathSegLinetoRel(float x, float y, SVGPathSegRole role) +{ + return SVGPathSegLinetoRel::create(this, role, x, y); +} + +PassRefPtr<SVGPathSegCurvetoCubicAbs> SVGPathElement::createSVGPathSegCurvetoCubicAbs(float x, float y, float x1, float y1, float x2, float y2, SVGPathSegRole role) +{ + return SVGPathSegCurvetoCubicAbs::create(this, role, x, y, x1, y1, x2, y2); +} + +PassRefPtr<SVGPathSegCurvetoCubicRel> SVGPathElement::createSVGPathSegCurvetoCubicRel(float x, float y, float x1, float y1, float x2, float y2, SVGPathSegRole role) +{ + return SVGPathSegCurvetoCubicRel::create(this, role, x, y, x1, y1, x2, y2); +} + +PassRefPtr<SVGPathSegCurvetoQuadraticAbs> SVGPathElement::createSVGPathSegCurvetoQuadraticAbs(float x, float y, float x1, float y1, SVGPathSegRole role) +{ + return SVGPathSegCurvetoQuadraticAbs::create(this, role, x, y, x1, y1); +} + +PassRefPtr<SVGPathSegCurvetoQuadraticRel> SVGPathElement::createSVGPathSegCurvetoQuadraticRel(float x, float y, float x1, float y1, SVGPathSegRole role) +{ + return SVGPathSegCurvetoQuadraticRel::create(this, role, x, y, x1, y1); +} + +PassRefPtr<SVGPathSegArcAbs> SVGPathElement::createSVGPathSegArcAbs(float x, float y, float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag, SVGPathSegRole role) +{ + return SVGPathSegArcAbs::create(this, role, x, y, r1, r2, angle, largeArcFlag, sweepFlag); +} + +PassRefPtr<SVGPathSegArcRel> SVGPathElement::createSVGPathSegArcRel(float x, float y, float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag, SVGPathSegRole role) +{ + return SVGPathSegArcRel::create(this, role, x, y, r1, r2, angle, largeArcFlag, sweepFlag); +} + +PassRefPtr<SVGPathSegLinetoHorizontalAbs> SVGPathElement::createSVGPathSegLinetoHorizontalAbs(float x, SVGPathSegRole role) +{ + return SVGPathSegLinetoHorizontalAbs::create(this, role, x); +} + +PassRefPtr<SVGPathSegLinetoHorizontalRel> SVGPathElement::createSVGPathSegLinetoHorizontalRel(float x, SVGPathSegRole role) +{ + return SVGPathSegLinetoHorizontalRel::create(this, role, x); +} + +PassRefPtr<SVGPathSegLinetoVerticalAbs> SVGPathElement::createSVGPathSegLinetoVerticalAbs(float y, SVGPathSegRole role) +{ + return SVGPathSegLinetoVerticalAbs::create(this, role, y); +} + +PassRefPtr<SVGPathSegLinetoVerticalRel> SVGPathElement::createSVGPathSegLinetoVerticalRel(float y, SVGPathSegRole role) +{ + return SVGPathSegLinetoVerticalRel::create(this, role, y); +} + +PassRefPtr<SVGPathSegCurvetoCubicSmoothAbs> SVGPathElement::createSVGPathSegCurvetoCubicSmoothAbs(float x, float y, float x2, float y2, SVGPathSegRole role) +{ + return SVGPathSegCurvetoCubicSmoothAbs::create(this, role, x, y, x2, y2); +} + +PassRefPtr<SVGPathSegCurvetoCubicSmoothRel> SVGPathElement::createSVGPathSegCurvetoCubicSmoothRel(float x, float y, float x2, float y2, SVGPathSegRole role) +{ + return SVGPathSegCurvetoCubicSmoothRel::create(this, role, x, y, x2, y2); +} + +PassRefPtr<SVGPathSegCurvetoQuadraticSmoothAbs> SVGPathElement::createSVGPathSegCurvetoQuadraticSmoothAbs(float x, float y, SVGPathSegRole role) +{ + return SVGPathSegCurvetoQuadraticSmoothAbs::create(this, role, x, y); +} + +PassRefPtr<SVGPathSegCurvetoQuadraticSmoothRel> SVGPathElement::createSVGPathSegCurvetoQuadraticSmoothRel(float x, float y, SVGPathSegRole role) +{ + return SVGPathSegCurvetoQuadraticSmoothRel::create(this, role, x, y); +} + +void SVGPathElement::parseMappedAttribute(Attribute* attr) +{ + if (attr->name() == SVGNames::dAttr) { + SVGPathParserFactory* factory = SVGPathParserFactory::self(); + if (!factory->buildSVGPathByteStreamFromString(attr->value(), m_pathByteStream, UnalteredParsing)) + document()->accessSVGExtensions()->reportError("Problem parsing d=\"" + attr->value() + "\""); + } else if (attr->name() == SVGNames::pathLengthAttr) { + setPathLengthBaseValue(attr->value().toFloat()); + if (pathLengthBaseValue() < 0.0f) + document()->accessSVGExtensions()->reportError("A negative value for path attribute <pathLength> is not allowed"); + } else { + if (SVGTests::parseMappedAttribute(attr)) + return; + if (SVGLangSpace::parseMappedAttribute(attr)) + return; + if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) + return; + SVGStyledTransformableElement::parseMappedAttribute(attr); + } +} + +void SVGPathElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGStyledTransformableElement::svgAttributeChanged(attrName); + + if (SVGTests::handleAttributeChange(this, attrName)) + return; + + RenderSVGPath* renderer = static_cast<RenderSVGPath*>(this->renderer()); + + if (attrName == SVGNames::dAttr) { + if (m_animatablePathSegList) { + SVGPathSegList newList(PathSegUnalteredRole); + SVGPathParserFactory* factory = SVGPathParserFactory::self(); + factory->buildSVGPathSegListFromByteStream(m_pathByteStream.get(), this, newList, UnalteredParsing); + m_pathSegList.value = newList; + } + + if (!renderer) + return; + + renderer->setNeedsPathUpdate(); + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); + return; + } + + if (!renderer) + return; + + if (SVGStyledTransformableElement::isKnownAttribute(attrName)) { + renderer->setNeedsTransformUpdate(); + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); + return; + } + + if (attrName == SVGNames::pathLengthAttr + || SVGLangSpace::isKnownAttribute(attrName) + || SVGExternalResourcesRequired::isKnownAttribute(attrName)) + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); +} + +void SVGPathElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGStyledTransformableElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeD(); + synchronizePathLength(); + synchronizeExternalResourcesRequired(); + SVGTests::synchronizeProperties(this, attrName); + return; + } + + if (attrName == SVGNames::dAttr) + synchronizeD(); + else if (attrName == SVGNames::pathLengthAttr) + synchronizePathLength(); + else if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) + synchronizeExternalResourcesRequired(); + else if (SVGTests::isKnownAttribute(attrName)) + SVGTests::synchronizeProperties(this, attrName); +} + +void SVGPathElement::synchronizeD() +{ + if (!m_pathSegList.shouldSynchronize) + return; + + SVGAnimatedPropertySynchronizer<true>::synchronize(this, SVGNames::dAttr, m_pathSegList.value.valueAsString()); +} + +SVGPathSegListPropertyTearOff* SVGPathElement::pathSegList() +{ + if (!m_animatablePathSegList) { + m_pathSegList.shouldSynchronize = true; + + SVGPathParserFactory* factory = SVGPathParserFactory::self(); + factory->buildSVGPathSegListFromByteStream(m_pathByteStream.get(), this, m_pathSegList.value, UnalteredParsing); + + m_animatablePathSegList = SVGAnimatedProperty::lookupOrCreateWrapper<SVGAnimatedPathSegListPropertyTearOff, SVGPathSegList> + (this, SVGNames::dAttr, SVGNames::dAttr.localName(), m_pathSegList.value); + } + + return static_cast<SVGPathSegListPropertyTearOff*>(m_animatablePathSegList->baseVal(PathSegUnalteredRole)); +} + +SVGPathSegListPropertyTearOff* SVGPathElement::normalizedPathSegList() +{ + // FIXME: https://bugs.webkit.org/show_bug.cgi?id=15412 - Implement normalized path segment lists! + return 0; +} + +SVGPathSegListPropertyTearOff* SVGPathElement::animatedPathSegList() +{ + if (!m_animatablePathSegList) { + m_pathSegList.shouldSynchronize = true; + + SVGPathParserFactory* factory = SVGPathParserFactory::self(); + factory->buildSVGPathSegListFromByteStream(m_pathByteStream.get(), this, m_pathSegList.value, UnalteredParsing); + + m_animatablePathSegList = SVGAnimatedProperty::lookupOrCreateWrapper<SVGAnimatedPathSegListPropertyTearOff, SVGPathSegList> + (this, SVGNames::dAttr, SVGNames::dAttr.localName(), m_pathSegList.value); + } + + return static_cast<SVGPathSegListPropertyTearOff*>(m_animatablePathSegList->animVal(PathSegUnalteredRole)); +} + +SVGPathSegListPropertyTearOff* SVGPathElement::animatedNormalizedPathSegList() +{ + // FIXME: https://bugs.webkit.org/show_bug.cgi?id=15412 - Implement normalized path segment lists! + return 0; +} + +void SVGPathElement::toPathData(Path& path) const +{ + ASSERT(path.isEmpty()); + + SVGPathParserFactory* factory = SVGPathParserFactory::self(); + factory->buildPathFromByteStream(m_pathByteStream.get(), path); +} + +void SVGPathElement::pathSegListChanged(SVGPathSegRole role) +{ + SVGPathParserFactory* factory = SVGPathParserFactory::self(); + + switch (role) { + case PathSegNormalizedRole: + // FIXME: https://bugs.webkit.org/show_bug.cgi?id=15412 - Implement normalized path segment lists! + break; + case PathSegUnalteredRole: + m_pathByteStream->clear(); + factory->buildSVGPathByteStreamFromSVGPathSegList(m_pathSegList.value, m_pathByteStream, UnalteredParsing); + break; + case PathSegUndefinedRole: + return; + } + + invalidateSVGAttributes(); + + RenderSVGPath* renderer = static_cast<RenderSVGPath*>(this->renderer()); + if (!renderer) + return; + + renderer->setNeedsPathUpdate(); + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGPathElement.h b/Source/WebCore/svg/SVGPathElement.h new file mode 100644 index 0000000..6ea7d55 --- /dev/null +++ b/Source/WebCore/svg/SVGPathElement.h @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPathElement_h +#define SVGPathElement_h + +#if ENABLE(SVG) +#include "SVGAnimatedBoolean.h" +#include "SVGAnimatedNumber.h" +#include "SVGAnimatedPathSegListPropertyTearOff.h" +#include "SVGExternalResourcesRequired.h" +#include "SVGLangSpace.h" +#include "SVGPathByteStream.h" +#include "SVGStyledTransformableElement.h" +#include "SVGTests.h" + +namespace WebCore { + +class SVGPathSegArcAbs; +class SVGPathSegArcRel; +class SVGPathSegClosePath; +class SVGPathSegLinetoAbs; +class SVGPathSegLinetoRel; +class SVGPathSegMovetoAbs; +class SVGPathSegMovetoRel; +class SVGPathSegCurvetoCubicAbs; +class SVGPathSegCurvetoCubicRel; +class SVGPathSegLinetoVerticalAbs; +class SVGPathSegLinetoVerticalRel; +class SVGPathSegLinetoHorizontalAbs; +class SVGPathSegLinetoHorizontalRel; +class SVGPathSegCurvetoQuadraticAbs; +class SVGPathSegCurvetoQuadraticRel; +class SVGPathSegCurvetoCubicSmoothAbs; +class SVGPathSegCurvetoCubicSmoothRel; +class SVGPathSegCurvetoQuadraticSmoothAbs; +class SVGPathSegCurvetoQuadraticSmoothRel; + +class SVGPathElement : public SVGStyledTransformableElement, + public SVGTests, + public SVGLangSpace, + public SVGExternalResourcesRequired { +public: + static PassRefPtr<SVGPathElement> create(const QualifiedName&, Document*); + + float getTotalLength(); + FloatPoint getPointAtLength(float distance); + unsigned long getPathSegAtLength(float distance); + + PassRefPtr<SVGPathSegClosePath> createSVGPathSegClosePath(SVGPathSegRole role = PathSegUndefinedRole); + PassRefPtr<SVGPathSegMovetoAbs> createSVGPathSegMovetoAbs(float x, float y, SVGPathSegRole role = PathSegUndefinedRole); + PassRefPtr<SVGPathSegMovetoRel> createSVGPathSegMovetoRel(float x, float y, SVGPathSegRole role = PathSegUndefinedRole); + PassRefPtr<SVGPathSegLinetoAbs> createSVGPathSegLinetoAbs(float x, float y, SVGPathSegRole role = PathSegUndefinedRole); + PassRefPtr<SVGPathSegLinetoRel> createSVGPathSegLinetoRel(float x, float y, SVGPathSegRole role = PathSegUndefinedRole); + PassRefPtr<SVGPathSegCurvetoCubicAbs> createSVGPathSegCurvetoCubicAbs(float x, float y, float x1, float y1, float x2, float y2, SVGPathSegRole role = PathSegUndefinedRole); + PassRefPtr<SVGPathSegCurvetoCubicRel> createSVGPathSegCurvetoCubicRel(float x, float y, float x1, float y1, float x2, float y2, SVGPathSegRole role = PathSegUndefinedRole); + PassRefPtr<SVGPathSegCurvetoQuadraticAbs> createSVGPathSegCurvetoQuadraticAbs(float x, float y, float x1, float y1, SVGPathSegRole role = PathSegUndefinedRole); + PassRefPtr<SVGPathSegCurvetoQuadraticRel> createSVGPathSegCurvetoQuadraticRel(float x, float y, float x1, float y1, SVGPathSegRole role = PathSegUndefinedRole); + PassRefPtr<SVGPathSegArcAbs> createSVGPathSegArcAbs(float x, float y, float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag, SVGPathSegRole role = PathSegUndefinedRole); + PassRefPtr<SVGPathSegArcRel> createSVGPathSegArcRel(float x, float y, float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag, SVGPathSegRole role = PathSegUndefinedRole); + PassRefPtr<SVGPathSegLinetoHorizontalAbs> createSVGPathSegLinetoHorizontalAbs(float x, SVGPathSegRole role = PathSegUndefinedRole); + PassRefPtr<SVGPathSegLinetoHorizontalRel> createSVGPathSegLinetoHorizontalRel(float x, SVGPathSegRole role = PathSegUndefinedRole); + PassRefPtr<SVGPathSegLinetoVerticalAbs> createSVGPathSegLinetoVerticalAbs(float y, SVGPathSegRole role = PathSegUndefinedRole); + PassRefPtr<SVGPathSegLinetoVerticalRel> createSVGPathSegLinetoVerticalRel(float y, SVGPathSegRole role = PathSegUndefinedRole); + PassRefPtr<SVGPathSegCurvetoCubicSmoothAbs> createSVGPathSegCurvetoCubicSmoothAbs(float x, float y, float x2, float y2, SVGPathSegRole role = PathSegUndefinedRole); + PassRefPtr<SVGPathSegCurvetoCubicSmoothRel> createSVGPathSegCurvetoCubicSmoothRel(float x, float y, float x2, float y2, SVGPathSegRole role = PathSegUndefinedRole); + PassRefPtr<SVGPathSegCurvetoQuadraticSmoothAbs> createSVGPathSegCurvetoQuadraticSmoothAbs(float x, float y, SVGPathSegRole role = PathSegUndefinedRole); + PassRefPtr<SVGPathSegCurvetoQuadraticSmoothRel> createSVGPathSegCurvetoQuadraticSmoothRel(float x, float y, SVGPathSegRole role = PathSegUndefinedRole); + + // Used in the bindings only. + SVGPathSegListPropertyTearOff* pathSegList(); + SVGPathSegListPropertyTearOff* animatedPathSegList(); + SVGPathSegListPropertyTearOff* normalizedPathSegList(); + SVGPathSegListPropertyTearOff* animatedNormalizedPathSegList(); + + SVGPathByteStream* pathByteStream() const { return m_pathByteStream.get(); } + SVGAnimatedProperty* animatablePathSegList() const { return m_animatablePathSegList.get(); } + + virtual void toPathData(Path&) const; + void pathSegListChanged(SVGPathSegRole); + +private: + SVGPathElement(const QualifiedName&, Document*); + + virtual bool isValid() const { return SVGTests::isValid(); } + + virtual void parseMappedAttribute(Attribute*); + virtual void synchronizeProperty(const QualifiedName&); + virtual void svgAttributeChanged(const QualifiedName&); + virtual bool supportsMarkers() const { return true; } + + // Animated property declarations + DECLARE_ANIMATED_NUMBER(PathLength, pathLength) + + // SVGExternalResourcesRequired + DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) + + void synchronizeD(); + +protected: + OwnPtr<SVGPathByteStream> m_pathByteStream; + mutable SVGSynchronizableAnimatedProperty<SVGPathSegList> m_pathSegList; + RefPtr<SVGAnimatedPathSegListPropertyTearOff> m_animatablePathSegList; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGPathElement.idl b/Source/WebCore/svg/SVGPathElement.idl new file mode 100644 index 0000000..00a9d85 --- /dev/null +++ b/Source/WebCore/svg/SVGPathElement.idl @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGPathElement : SVGElement, + SVGTests, + SVGLangSpace, + SVGExternalResourcesRequired, + SVGStylable, + SVGTransformable { + readonly attribute SVGAnimatedNumber pathLength; + + float getTotalLength(); + SVGPoint getPointAtLength(in float distance); + unsigned long getPathSegAtLength(in float distance); + + SVGPathSegClosePath createSVGPathSegClosePath(); + + SVGPathSegMovetoAbs createSVGPathSegMovetoAbs(in float x, + in float y); + SVGPathSegMovetoRel createSVGPathSegMovetoRel(in float x, + in float y); + + SVGPathSegLinetoAbs createSVGPathSegLinetoAbs(in float x, + in float y); + SVGPathSegLinetoRel createSVGPathSegLinetoRel(in float x, + in float y); + + SVGPathSegCurvetoCubicAbs createSVGPathSegCurvetoCubicAbs(in float x, + in float y, + in float x1, + in float y1, + in float x2, + in float y2); + SVGPathSegCurvetoCubicRel createSVGPathSegCurvetoCubicRel(in float x, + in float y, + in float x1, + in float y1, + in float x2, + in float y2); + + SVGPathSegCurvetoQuadraticAbs createSVGPathSegCurvetoQuadraticAbs(in float x, + in float y, + in float x1, + in float y1); + SVGPathSegCurvetoQuadraticRel createSVGPathSegCurvetoQuadraticRel(in float x, + in float y, + in float x1, + in float y1); + + SVGPathSegArcAbs createSVGPathSegArcAbs(in float x, + in float y, + in float r1, + in float r2, + in float angle, + in boolean largeArcFlag, + in boolean sweepFlag); + SVGPathSegArcRel createSVGPathSegArcRel(in float x, + in float y, + in float r1, + in float r2, + in float angle, + in boolean largeArcFlag, + in boolean sweepFlag); + + SVGPathSegLinetoHorizontalAbs createSVGPathSegLinetoHorizontalAbs(in float x); + SVGPathSegLinetoHorizontalRel createSVGPathSegLinetoHorizontalRel(in float x); + + SVGPathSegLinetoVerticalAbs createSVGPathSegLinetoVerticalAbs(in float y); + SVGPathSegLinetoVerticalRel createSVGPathSegLinetoVerticalRel(in float y); + + SVGPathSegCurvetoCubicSmoothAbs createSVGPathSegCurvetoCubicSmoothAbs(in float x, + in float y, + in float x2, + in float y2); + SVGPathSegCurvetoCubicSmoothRel createSVGPathSegCurvetoCubicSmoothRel(in float x, + in float y, + in float x2, + in float y2); + + SVGPathSegCurvetoQuadraticSmoothAbs createSVGPathSegCurvetoQuadraticSmoothAbs(in float x, + in float y); + SVGPathSegCurvetoQuadraticSmoothRel createSVGPathSegCurvetoQuadraticSmoothRel(in float x, + in float y); + + readonly attribute SVGPathSegList pathSegList; + readonly attribute SVGPathSegList normalizedPathSegList; + readonly attribute SVGPathSegList animatedPathSegList; + readonly attribute SVGPathSegList animatedNormalizedPathSegList; + }; + +} diff --git a/Source/WebCore/svg/SVGPathParser.cpp b/Source/WebCore/svg/SVGPathParser.cpp new file mode 100644 index 0000000..a0d6847 --- /dev/null +++ b/Source/WebCore/svg/SVGPathParser.cpp @@ -0,0 +1,488 @@ +/* + * Copyright (C) 2002, 2003 The Karbon Developers + * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org> + * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org> + * Copyright (C) 2007, 2009 Apple Inc. All rights reserved. + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPathParser.h" + +#include "AffineTransform.h" +#include <wtf/MathExtras.h> + +static const float gOneOverThree = 1 / 3.f; + +namespace WebCore { + +SVGPathParser::SVGPathParser() + : m_consumer(0) +{ +} + +void SVGPathParser::parseClosePathSegment() +{ + // Reset m_currentPoint for the next path. + if (m_pathParsingMode == NormalizedParsing) + m_currentPoint = m_subPathPoint; + m_closePath = true; + m_consumer->closePath(); +} + +bool SVGPathParser::parseMoveToSegment() +{ + FloatPoint targetPoint; + if (!m_source->parseMoveToSegment(targetPoint)) + return false; + + if (m_pathParsingMode == NormalizedParsing) { + if (m_mode == RelativeCoordinates) + m_currentPoint += targetPoint; + else + m_currentPoint = targetPoint; + m_subPathPoint = m_currentPoint; + m_consumer->moveTo(m_currentPoint, m_closePath, AbsoluteCoordinates); + } else + m_consumer->moveTo(targetPoint, m_closePath, m_mode); + m_closePath = false; + return true; +} + +bool SVGPathParser::parseLineToSegment() +{ + FloatPoint targetPoint; + if (!m_source->parseLineToSegment(targetPoint)) + return false; + + if (m_pathParsingMode == NormalizedParsing) { + if (m_mode == RelativeCoordinates) + m_currentPoint += targetPoint; + else + m_currentPoint = targetPoint; + m_consumer->lineTo(m_currentPoint, AbsoluteCoordinates); + } else + m_consumer->lineTo(targetPoint, m_mode); + return true; +} + +bool SVGPathParser::parseLineToHorizontalSegment() +{ + float toX; + if (!m_source->parseLineToHorizontalSegment(toX)) + return false; + + if (m_pathParsingMode == NormalizedParsing) { + if (m_mode == RelativeCoordinates) + m_currentPoint.move(toX, 0); + else + m_currentPoint.setX(toX); + m_consumer->lineTo(m_currentPoint, AbsoluteCoordinates); + } else + m_consumer->lineToHorizontal(toX, m_mode); + return true; +} + +bool SVGPathParser::parseLineToVerticalSegment() +{ + float toY; + if (!m_source->parseLineToVerticalSegment(toY)) + return false; + + if (m_pathParsingMode == NormalizedParsing) { + if (m_mode == RelativeCoordinates) + m_currentPoint.move(0, toY); + else + m_currentPoint.setY(toY); + m_consumer->lineTo(m_currentPoint, AbsoluteCoordinates); + } else + m_consumer->lineToVertical(toY, m_mode); + return true; +} + +bool SVGPathParser::parseCurveToCubicSegment() +{ + FloatPoint point1; + FloatPoint point2; + FloatPoint targetPoint; + if (!m_source->parseCurveToCubicSegment(point1, point2, targetPoint)) + return false; + + if (m_pathParsingMode == NormalizedParsing) { + if (m_mode == RelativeCoordinates) { + point1 += m_currentPoint; + point2 += m_currentPoint; + targetPoint += m_currentPoint; + } + m_consumer->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates); + + m_controlPoint = point2; + m_currentPoint = targetPoint; + } else + m_consumer->curveToCubic(point1, point2, targetPoint, m_mode); + return true; +} + +bool SVGPathParser::parseCurveToCubicSmoothSegment() +{ + FloatPoint point2; + FloatPoint targetPoint; + if (!m_source->parseCurveToCubicSmoothSegment(point2, targetPoint)) + return false; + + if (m_lastCommand != PathSegCurveToCubicAbs + && m_lastCommand != PathSegCurveToCubicRel + && m_lastCommand != PathSegCurveToCubicSmoothAbs + && m_lastCommand != PathSegCurveToCubicSmoothRel) + m_controlPoint = m_currentPoint; + + if (m_pathParsingMode == NormalizedParsing) { + FloatPoint point1 = m_currentPoint; + point1.scale(2, 2); + point1.move(-m_controlPoint.x(), -m_controlPoint.y()); + if (m_mode == RelativeCoordinates) { + point2 += m_currentPoint; + targetPoint += m_currentPoint; + } + + m_consumer->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates); + + m_controlPoint = point2; + m_currentPoint = targetPoint; + } else + m_consumer->curveToCubicSmooth(point2, targetPoint, m_mode); + return true; +} + +bool SVGPathParser::parseCurveToQuadraticSegment() +{ + FloatPoint point1; + FloatPoint targetPoint; + if (!m_source->parseCurveToQuadraticSegment(point1, targetPoint)) + return false; + + if (m_pathParsingMode == NormalizedParsing) { + m_controlPoint = point1; + FloatPoint point1 = m_currentPoint; + point1.move(2 * m_controlPoint.x(), 2 * m_controlPoint.y()); + FloatPoint point2(targetPoint.x() + 2 * m_controlPoint.x(), targetPoint.y() + 2 * m_controlPoint.y()); + if (m_mode == RelativeCoordinates) { + point1.move(2 * m_currentPoint.x(), 2 * m_currentPoint.y()); + point2.move(3 * m_currentPoint.x(), 3 * m_currentPoint.y()); + targetPoint += m_currentPoint; + } + point1.scale(gOneOverThree, gOneOverThree); + point2.scale(gOneOverThree, gOneOverThree); + + m_consumer->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates); + + if (m_mode == RelativeCoordinates) + m_controlPoint += m_currentPoint; + m_currentPoint = targetPoint; + } else + m_consumer->curveToQuadratic(point1, targetPoint, m_mode); + return true; +} + +bool SVGPathParser::parseCurveToQuadraticSmoothSegment() +{ + FloatPoint targetPoint; + if (!m_source->parseCurveToQuadraticSmoothSegment(targetPoint)) + return false; + + if (m_lastCommand != PathSegCurveToQuadraticAbs + && m_lastCommand != PathSegCurveToQuadraticRel + && m_lastCommand != PathSegCurveToQuadraticSmoothAbs + && m_lastCommand != PathSegCurveToQuadraticSmoothRel) + m_controlPoint = m_currentPoint; + + if (m_pathParsingMode == NormalizedParsing) { + FloatPoint cubicPoint = m_currentPoint; + cubicPoint.scale(2, 2); + cubicPoint.move(-m_controlPoint.x(), -m_controlPoint.y()); + FloatPoint point1(m_currentPoint.x() + 2 * cubicPoint.x(), m_currentPoint.y() + 2 * cubicPoint.y()); + FloatPoint point2(targetPoint.x() + 2 * cubicPoint.x(), targetPoint.y() + 2 * cubicPoint.y()); + if (m_mode == RelativeCoordinates) { + point2 += m_currentPoint; + targetPoint += m_currentPoint; + } + point1.scale(gOneOverThree, gOneOverThree); + point2.scale(gOneOverThree, gOneOverThree); + + m_consumer->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates); + + m_controlPoint = cubicPoint; + m_currentPoint = targetPoint; + } else + m_consumer->curveToQuadraticSmooth(targetPoint, m_mode); + return true; +} + +bool SVGPathParser::parseArcToSegment() +{ + float rx; + float ry; + float angle; + bool largeArc; + bool sweep; + FloatPoint targetPoint; + if (!m_source->parseArcToSegment(rx, ry, angle, largeArc, sweep, targetPoint)) + return false; + + // If rx = 0 or ry = 0 then this arc is treated as a straight line segment (a "lineto") joining the endpoints. + // http://www.w3.org/TR/SVG/implnote.html#ArcOutOfRangeParameters + rx = fabsf(rx); + ry = fabsf(ry); + if (!rx || !ry) { + if (m_pathParsingMode == NormalizedParsing) { + if (m_mode == RelativeCoordinates) + m_currentPoint += targetPoint; + else + m_currentPoint = targetPoint; + m_consumer->lineTo(m_currentPoint, AbsoluteCoordinates); + } else + m_consumer->lineTo(targetPoint, m_mode); + return true; + } + + if (m_pathParsingMode == NormalizedParsing) { + FloatPoint point1 = m_currentPoint; + if (m_mode == RelativeCoordinates) + targetPoint += m_currentPoint; + m_currentPoint = targetPoint; + return decomposeArcToCubic(angle, rx, ry, point1, targetPoint, largeArc, sweep); + } + m_consumer->arcTo(rx, ry, angle, largeArc, sweep, targetPoint, m_mode); + return true; +} + +bool SVGPathParser::parsePathDataFromSource(PathParsingMode pathParsingMode) +{ + ASSERT(m_source); + ASSERT(m_consumer); + + m_pathParsingMode = pathParsingMode; + + m_controlPoint = FloatPoint(); + m_currentPoint = FloatPoint(); + m_subPathPoint = FloatPoint(); + m_closePath = true; + + // Skip any leading spaces. + if (!m_source->moveToNextToken()) + return false; + + SVGPathSegType command; + m_source->parseSVGSegmentType(command); + m_lastCommand = PathSegUnknown; + + // Path must start with moveto. + if (command != PathSegMoveToAbs && command != PathSegMoveToRel) + return false; + + while (true) { + // Skip spaces between command and first coordinate. + m_source->moveToNextToken(); + m_mode = AbsoluteCoordinates; + switch (command) { + case PathSegMoveToRel: + m_mode = RelativeCoordinates; + case PathSegMoveToAbs: + if (!parseMoveToSegment()) + return false; + break; + case PathSegLineToRel: + m_mode = RelativeCoordinates; + case PathSegLineToAbs: + if (!parseLineToSegment()) + return false; + break; + case PathSegLineToHorizontalRel: + m_mode = RelativeCoordinates; + case PathSegLineToHorizontalAbs: + if (!parseLineToHorizontalSegment()) + return false; + break; + case PathSegLineToVerticalRel: + m_mode = RelativeCoordinates; + case PathSegLineToVerticalAbs: + if (!parseLineToVerticalSegment()) + return false; + break; + case PathSegClosePath: + parseClosePathSegment(); + break; + case PathSegCurveToCubicRel: + m_mode = RelativeCoordinates; + case PathSegCurveToCubicAbs: + if (!parseCurveToCubicSegment()) + return false; + break; + case PathSegCurveToCubicSmoothRel: + m_mode = RelativeCoordinates; + case PathSegCurveToCubicSmoothAbs: + if (!parseCurveToCubicSmoothSegment()) + return false; + break; + case PathSegCurveToQuadraticRel: + m_mode = RelativeCoordinates; + case PathSegCurveToQuadraticAbs: + if (!parseCurveToQuadraticSegment()) + return false; + break; + case PathSegCurveToQuadraticSmoothRel: + m_mode = RelativeCoordinates; + case PathSegCurveToQuadraticSmoothAbs: + if (!parseCurveToQuadraticSmoothSegment()) + return false; + break; + case PathSegArcRel: + m_mode = RelativeCoordinates; + case PathSegArcAbs: + if (!parseArcToSegment()) + return false; + break; + default: + return false; + } + if (!m_consumer->continueConsuming()) + return true; + + m_lastCommand = command; + + if (!m_source->hasMoreData()) + return true; + + command = m_source->nextCommand(command); + + if (m_lastCommand != PathSegCurveToCubicAbs + && m_lastCommand != PathSegCurveToCubicRel + && m_lastCommand != PathSegCurveToCubicSmoothAbs + && m_lastCommand != PathSegCurveToCubicSmoothRel + && m_lastCommand != PathSegCurveToQuadraticAbs + && m_lastCommand != PathSegCurveToQuadraticRel + && m_lastCommand != PathSegCurveToQuadraticSmoothAbs + && m_lastCommand != PathSegCurveToQuadraticSmoothRel) + m_controlPoint = m_currentPoint; + + m_consumer->incrementPathSegmentCount(); + } + + return false; +} + +void SVGPathParser::cleanup() +{ + ASSERT(m_source); + ASSERT(m_consumer); + + m_consumer->cleanup(); + m_source = 0; + m_consumer = 0; +} + +// This works by converting the SVG arc to "simple" beziers. +// Partly adapted from Niko's code in kdelibs/kdecore/svgicons. +// See also SVG implementation notes: http://www.w3.org/TR/SVG/implnote.html#ArcConversionEndpointToCenter +bool SVGPathParser::decomposeArcToCubic(float angle, float rx, float ry, FloatPoint& point1, FloatPoint& point2, bool largeArcFlag, bool sweepFlag) +{ + FloatSize midPointDistance = point1 - point2; + midPointDistance.scale(0.5f); + + AffineTransform pointTransform; + pointTransform.rotate(-angle); + + FloatPoint transformedMidPoint = pointTransform.mapPoint(FloatPoint(midPointDistance.width(), midPointDistance.height())); + float squareRx = rx * rx; + float squareRy = ry * ry; + float squareX = transformedMidPoint.x() * transformedMidPoint.x(); + float squareY = transformedMidPoint.y() * transformedMidPoint.y(); + + // Check if the radii are big enough to draw the arc, scale radii if not. + // http://www.w3.org/TR/SVG/implnote.html#ArcCorrectionOutOfRangeRadii + float radiiScale = squareX / squareRx + squareY / squareRy; + if (radiiScale > 1) { + rx *= sqrtf(radiiScale); + ry *= sqrtf(radiiScale); + } + + pointTransform.makeIdentity(); + pointTransform.scale(1 / rx, 1 / ry); + pointTransform.rotate(-angle); + + point1 = pointTransform.mapPoint(point1); + point2 = pointTransform.mapPoint(point2); + FloatSize delta = point2 - point1; + + float d = delta.width() * delta.width() + delta.height() * delta.height(); + float scaleFactorSquared = std::max(1 / d - 0.25f, 0.f); + + float scaleFactor = sqrtf(scaleFactorSquared); + if (sweepFlag == largeArcFlag) + scaleFactor = -scaleFactor; + + delta.scale(scaleFactor); + FloatPoint centerPoint = FloatPoint(0.5f * (point1.x() + point2.x()) - delta.height(), + 0.5f * (point1.y() + point2.y()) + delta.width()); + + float theta1 = atan2f(point1.y() - centerPoint.y(), point1.x() - centerPoint.x()); + float theta2 = atan2f(point2.y() - centerPoint.y(), point2.x() - centerPoint.x()); + + float thetaArc = theta2 - theta1; + if (thetaArc < 0 && sweepFlag) + thetaArc += 2 * piFloat; + else if (thetaArc > 0 && !sweepFlag) + thetaArc -= 2 * piFloat; + + pointTransform.makeIdentity(); + pointTransform.rotate(angle); + pointTransform.scale(rx, ry); + + // Some results of atan2 on some platform implementations are not exact enough. So that we get more + // cubic curves than expected here. Adding 0.001f reduces the count of sgements to the correct count. + int segments = ceilf(fabsf(thetaArc / (piOverTwoFloat + 0.001f))); + for (int i = 0; i < segments; ++i) { + float startTheta = theta1 + i * thetaArc / segments; + float endTheta = theta1 + (i + 1) * thetaArc / segments; + + float t = (8 / 6.f) * tanf(0.25f * (endTheta - startTheta)); + if (!isfinite(t)) + return false; + float sinStartTheta = sinf(startTheta); + float cosStartTheta = cosf(startTheta); + float sinEndTheta = sinf(endTheta); + float cosEndTheta = cosf(endTheta); + + point1 = FloatPoint(cosStartTheta - t * sinStartTheta, sinStartTheta + t * cosStartTheta); + point1.move(centerPoint.x(), centerPoint.y()); + FloatPoint targetPoint = FloatPoint(cosEndTheta, sinEndTheta); + targetPoint.move(centerPoint.x(), centerPoint.y()); + point2 = targetPoint; + point2.move(t * sinEndTheta, -t * cosEndTheta); + + m_consumer->curveToCubic(pointTransform.mapPoint(point1), pointTransform.mapPoint(point2), + pointTransform.mapPoint(targetPoint), AbsoluteCoordinates); + } + return true; +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGPathParser.h b/Source/WebCore/svg/SVGPathParser.h new file mode 100644 index 0000000..7679a95 --- /dev/null +++ b/Source/WebCore/svg/SVGPathParser.h @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2002, 2003 The Karbon Developers + * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org> + * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org> + * Copyright (C) 2007, 2009 Apple Inc. All rights reserved. + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPathParser_h +#define SVGPathParser_h + +#if ENABLE(SVG) +#include "PlatformString.h" +#include "SVGPathConsumer.h" +#include "SVGPathSeg.h" +#include "SVGPathSource.h" +#include <wtf/Noncopyable.h> +#include <wtf/PassOwnPtr.h> + +namespace WebCore { + +class SVGPathParser : public Noncopyable { +public: + SVGPathParser(); + + bool parsePathDataFromSource(PathParsingMode pathParsingMode); + void setCurrentConsumer(SVGPathConsumer* consumer) { m_consumer = consumer; } + void setCurrentSource(SVGPathSource* source) { m_source = source; } + void cleanup(); + +private: + bool decomposeArcToCubic(float, float, float, FloatPoint&, FloatPoint&, bool largeArcFlag, bool sweepFlag); + void parseClosePathSegment(); + bool parseMoveToSegment(); + bool parseLineToSegment(); + bool parseLineToHorizontalSegment(); + bool parseLineToVerticalSegment(); + bool parseCurveToCubicSegment(); + bool parseCurveToCubicSmoothSegment(); + bool parseCurveToQuadraticSegment(); + bool parseCurveToQuadraticSmoothSegment(); + bool parseArcToSegment(); + + SVGPathSource* m_source; + SVGPathConsumer* m_consumer; + PathCoordinateMode m_mode; + PathParsingMode m_pathParsingMode; + SVGPathSegType m_lastCommand; + bool m_closePath; + FloatPoint m_controlPoint; + FloatPoint m_currentPoint; + FloatPoint m_subPathPoint; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGPathParser_h diff --git a/Source/WebCore/svg/SVGPathParserFactory.cpp b/Source/WebCore/svg/SVGPathParserFactory.cpp new file mode 100644 index 0000000..deb0307 --- /dev/null +++ b/Source/WebCore/svg/SVGPathParserFactory.cpp @@ -0,0 +1,272 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPathParserFactory.h" + +#include "PathTraversalState.h" +#include "SVGPathBlender.h" +#include "SVGPathBuilder.h" +#include "SVGPathByteStreamBuilder.h" +#include "SVGPathByteStreamSource.h" +#include "SVGPathElement.h" +#include "SVGPathParser.h" +#include "SVGPathSegListBuilder.h" +#include "SVGPathSegListSource.h" +#include "SVGPathStringBuilder.h" +#include "SVGPathStringSource.h" +#include "SVGPathTraversalStateBuilder.h" + +namespace WebCore { + +static SVGPathBuilder* globalSVGPathBuilder(Path& result) +{ + static SVGPathBuilder* s_builder = 0; + if (!s_builder) + s_builder = new SVGPathBuilder; + + s_builder->setCurrentPath(&result); + return s_builder; +} + +static SVGPathSegListBuilder* globalSVGPathSegListBuilder(SVGPathElement* element, SVGPathSegRole role, SVGPathSegList& result) +{ + static SVGPathSegListBuilder* s_builder = 0; + if (!s_builder) + s_builder = new SVGPathSegListBuilder; + + s_builder->setCurrentSVGPathElement(element); + s_builder->setCurrentSVGPathSegList(result); + s_builder->setCurrentSVGPathSegRole(role); + return s_builder; +} + +static SVGPathByteStreamBuilder* globalSVGPathByteStreamBuilder(SVGPathByteStream* result) +{ + static SVGPathByteStreamBuilder* s_builder = 0; + if (!s_builder) + s_builder = new SVGPathByteStreamBuilder; + + s_builder->setCurrentByteStream(result); + return s_builder; +} + +static SVGPathStringBuilder* globalSVGPathStringBuilder() +{ + static SVGPathStringBuilder* s_builder = 0; + if (!s_builder) + s_builder = new SVGPathStringBuilder; + + return s_builder; +} + +static SVGPathTraversalStateBuilder* globalSVGPathTraversalStateBuilder(PathTraversalState& traversalState, float length) +{ + static SVGPathTraversalStateBuilder* s_builder = 0; + if (!s_builder) + s_builder = new SVGPathTraversalStateBuilder; + + s_builder->setCurrentTraversalState(&traversalState); + s_builder->setDesiredLength(length); + return s_builder; +} + +static SVGPathParser* globalSVGPathParser(SVGPathSource* source, SVGPathConsumer* consumer) +{ + static SVGPathParser* s_parser = 0; + if (!s_parser) + s_parser = new SVGPathParser; + + s_parser->setCurrentSource(source); + s_parser->setCurrentConsumer(consumer); + return s_parser; +} + +static SVGPathBlender* globalSVGPathBlender() +{ + static SVGPathBlender* s_blender = 0; + if (!s_blender) + s_blender = new SVGPathBlender; + + return s_blender; +} + +SVGPathParserFactory* SVGPathParserFactory::self() +{ + static SVGPathParserFactory* s_instance = 0; + if (!s_instance) + s_instance = new SVGPathParserFactory; + + return s_instance; +} + +SVGPathParserFactory::SVGPathParserFactory() +{ +} + +SVGPathParserFactory::~SVGPathParserFactory() +{ +} + +bool SVGPathParserFactory::buildPathFromString(const String& d, Path& result) +{ + if (d.isEmpty()) + return false; + + SVGPathBuilder* builder = globalSVGPathBuilder(result); + + OwnPtr<SVGPathStringSource> source = SVGPathStringSource::create(d); + SVGPathParser* parser = globalSVGPathParser(source.get(), builder); + bool ok = parser->parsePathDataFromSource(NormalizedParsing); + parser->cleanup(); + return ok; +} + +bool SVGPathParserFactory::buildSVGPathByteStreamFromSVGPathSegList(const SVGPathSegList& list, OwnPtr<SVGPathByteStream>& result, PathParsingMode parsingMode) +{ + result = SVGPathByteStream::create(); + if (list.isEmpty()) + return false; + + SVGPathByteStreamBuilder* builder = globalSVGPathByteStreamBuilder(result.get()); + + OwnPtr<SVGPathSegListSource> source = SVGPathSegListSource::create(list); + SVGPathParser* parser = globalSVGPathParser(source.get(), builder); + bool ok = parser->parsePathDataFromSource(parsingMode); + parser->cleanup(); + return ok; +} + +bool SVGPathParserFactory::buildPathFromByteStream(SVGPathByteStream* stream, Path& result) +{ + ASSERT(stream); + if (stream->isEmpty()) + return false; + + SVGPathBuilder* builder = globalSVGPathBuilder(result); + + OwnPtr<SVGPathByteStreamSource> source = SVGPathByteStreamSource::create(stream); + SVGPathParser* parser = globalSVGPathParser(source.get(), builder); + bool ok = parser->parsePathDataFromSource(NormalizedParsing); + parser->cleanup(); + return ok; +} + +bool SVGPathParserFactory::buildSVGPathSegListFromByteStream(SVGPathByteStream* stream, SVGPathElement* element, SVGPathSegList& result, PathParsingMode parsingMode) +{ + ASSERT(stream); + if (stream->isEmpty()) + return false; + + SVGPathSegListBuilder* builder = globalSVGPathSegListBuilder(element, parsingMode == NormalizedParsing ? PathSegNormalizedRole : PathSegUnalteredRole, result); + + OwnPtr<SVGPathByteStreamSource> source = SVGPathByteStreamSource::create(stream); + SVGPathParser* parser = globalSVGPathParser(source.get(), builder); + bool ok = parser->parsePathDataFromSource(parsingMode); + parser->cleanup(); + return ok; +} + +bool SVGPathParserFactory::buildStringFromByteStream(SVGPathByteStream* stream, String& result, PathParsingMode parsingMode) +{ + ASSERT(stream); + if (stream->isEmpty()) + return false; + + SVGPathStringBuilder* builder = globalSVGPathStringBuilder(); + + OwnPtr<SVGPathByteStreamSource> source = SVGPathByteStreamSource::create(stream); + SVGPathParser* parser = globalSVGPathParser(source.get(), builder); + bool ok = parser->parsePathDataFromSource(parsingMode); + result = builder->result(); + parser->cleanup(); + return ok; +} + +bool SVGPathParserFactory::buildStringFromSVGPathSegList(const SVGPathSegList& list, String& result, PathParsingMode parsingMode) +{ + result = String(); + if (list.isEmpty()) + return false; + + SVGPathStringBuilder* builder = globalSVGPathStringBuilder(); + + OwnPtr<SVGPathSegListSource> source = SVGPathSegListSource::create(list); + SVGPathParser* parser = globalSVGPathParser(source.get(), builder); + bool ok = parser->parsePathDataFromSource(parsingMode); + result = builder->result(); + parser->cleanup(); + return ok; +} + +bool SVGPathParserFactory::buildSVGPathByteStreamFromString(const String& d, OwnPtr<SVGPathByteStream>& result, PathParsingMode parsingMode) +{ + result = SVGPathByteStream::create(); + if (d.isEmpty()) + return false; + + SVGPathByteStreamBuilder* builder = globalSVGPathByteStreamBuilder(result.get()); + + OwnPtr<SVGPathStringSource> source = SVGPathStringSource::create(d); + SVGPathParser* parser = globalSVGPathParser(source.get(), builder); + bool ok = parser->parsePathDataFromSource(parsingMode); + parser->cleanup(); + return ok; +} + +bool SVGPathParserFactory::buildAnimatedSVGPathByteStream(SVGPathByteStream* fromStream, SVGPathByteStream* toStream, OwnPtr<SVGPathByteStream>& result, float progress) +{ + ASSERT(fromStream); + ASSERT(toStream); + result = SVGPathByteStream::create(); + if (fromStream->isEmpty() || toStream->isEmpty()) + return false; + + SVGPathByteStreamBuilder* builder = globalSVGPathByteStreamBuilder(result.get()); + + OwnPtr<SVGPathByteStreamSource> fromSource = SVGPathByteStreamSource::create(fromStream); + OwnPtr<SVGPathByteStreamSource> toSource = SVGPathByteStreamSource::create(toStream); + SVGPathBlender* blender = globalSVGPathBlender(); + bool ok = blender->blendAnimatedPath(progress, fromSource.get(), toSource.get(), builder); + blender->cleanup(); + return ok; +} + +bool SVGPathParserFactory::getSVGPathSegAtLengthFromSVGPathByteStream(SVGPathByteStream* stream, float length, unsigned long& pathSeg) +{ + ASSERT(stream); + if (stream->isEmpty()) + return false; + + PathTraversalState traversalState(PathTraversalState::TraversalSegmentAtLength); + SVGPathTraversalStateBuilder* builder = globalSVGPathTraversalStateBuilder(traversalState, length); + + OwnPtr<SVGPathByteStreamSource> source = SVGPathByteStreamSource::create(stream); + SVGPathParser* parser = globalSVGPathParser(source.get(), builder); + bool ok = parser->parsePathDataFromSource(NormalizedParsing); + pathSeg = builder->pathSegmentIndex(); + parser->cleanup(); + return ok; +} + +} + +#endif diff --git a/Source/WebCore/svg/SVGPathParserFactory.h b/Source/WebCore/svg/SVGPathParserFactory.h new file mode 100644 index 0000000..895e65a --- /dev/null +++ b/Source/WebCore/svg/SVGPathParserFactory.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPathParserFactory_h +#define SVGPathParserFactory_h + +#if ENABLE(SVG) +#include "Path.h" +#include "PlatformString.h" +#include "SVGPathByteStream.h" +#include "SVGPathConsumer.h" +#include "SVGPathSegList.h" + +#include <wtf/OwnPtr.h> + +namespace WebCore { + +class SVGPathElement; + +class SVGPathParserFactory { +public: + static SVGPathParserFactory* self(); + + // String/SVGPathByteStream -> Path + bool buildPathFromString(const String&, Path&); + bool buildPathFromByteStream(SVGPathByteStream*, Path&); + + // SVGPathSegList/String -> SVGPathByteStream + bool buildSVGPathByteStreamFromSVGPathSegList(const SVGPathSegList&, OwnPtr<SVGPathByteStream>&, PathParsingMode); + bool buildSVGPathByteStreamFromString(const String&, OwnPtr<SVGPathByteStream>&, PathParsingMode); + + // SVGPathByteStream/SVGPathSegList -> String + bool buildStringFromByteStream(SVGPathByteStream*, String&, PathParsingMode); + bool buildStringFromSVGPathSegList(const SVGPathSegList&, String&, PathParsingMode); + + // SVGPathByteStream -> SVGPathSegList + bool buildSVGPathSegListFromByteStream(SVGPathByteStream*, SVGPathElement*, SVGPathSegList&, PathParsingMode); + + bool buildAnimatedSVGPathByteStream(SVGPathByteStream*, SVGPathByteStream*, OwnPtr<SVGPathByteStream>&, float); + bool getSVGPathSegAtLengthFromSVGPathByteStream(SVGPathByteStream*, float length, unsigned long& pathSeg); + +private: + SVGPathParserFactory(); + ~SVGPathParserFactory(); +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGPathParserFactory_h diff --git a/Source/WebCore/svg/SVGPathSeg.h b/Source/WebCore/svg/SVGPathSeg.h new file mode 100644 index 0000000..4fce0c3 --- /dev/null +++ b/Source/WebCore/svg/SVGPathSeg.h @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2008 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPathSeg_h +#define SVGPathSeg_h + +#if ENABLE(SVG) +#include <wtf/text/WTFString.h> + +namespace WebCore { + +enum SVGPathSegType { + PathSegUnknown = 0, + PathSegClosePath = 1, + PathSegMoveToAbs = 2, + PathSegMoveToRel = 3, + PathSegLineToAbs = 4, + PathSegLineToRel = 5, + PathSegCurveToCubicAbs = 6, + PathSegCurveToCubicRel = 7, + PathSegCurveToQuadraticAbs = 8, + PathSegCurveToQuadraticRel = 9, + PathSegArcAbs = 10, + PathSegArcRel = 11, + PathSegLineToHorizontalAbs = 12, + PathSegLineToHorizontalRel = 13, + PathSegLineToVerticalAbs = 14, + PathSegLineToVerticalRel = 15, + PathSegCurveToCubicSmoothAbs = 16, + PathSegCurveToCubicSmoothRel = 17, + PathSegCurveToQuadraticSmoothAbs = 18, + PathSegCurveToQuadraticSmoothRel = 19 +}; + +enum SVGPathSegRole { + PathSegUnalteredRole = 0, + PathSegNormalizedRole = 1, + PathSegUndefinedRole = 2 +}; + +class SVGPathSeg : public RefCounted<SVGPathSeg> { +public: + SVGPathSeg() { } + virtual ~SVGPathSeg() { } + + // Forward declare these enums in the w3c naming scheme, for IDL generation + enum { + PATHSEG_UNKNOWN = PathSegUnknown, + PATHSEG_CLOSEPATH = PathSegClosePath, + PATHSEG_MOVETO_ABS = PathSegMoveToAbs, + PATHSEG_MOVETO_REL = PathSegMoveToRel, + PATHSEG_LINETO_ABS = PathSegLineToAbs, + PATHSEG_LINETO_REL = PathSegLineToRel, + PATHSEG_CURVETO_CUBIC_ABS = PathSegCurveToCubicAbs, + PATHSEG_CURVETO_CUBIC_REL = PathSegCurveToCubicRel, + PATHSEG_CURVETO_QUADRATIC_ABS = PathSegCurveToQuadraticAbs, + PATHSEG_CURVETO_QUADRATIC_REL = PathSegCurveToQuadraticRel, + PATHSEG_ARC_ABS = PathSegArcAbs, + PATHSEG_ARC_REL = PathSegArcRel, + PATHSEG_LINETO_HORIZONTAL_ABS = PathSegLineToHorizontalAbs, + PATHSEG_LINETO_HORIZONTAL_REL = PathSegLineToHorizontalRel, + PATHSEG_LINETO_VERTICAL_ABS = PathSegLineToVerticalAbs, + PATHSEG_LINETO_VERTICAL_REL = PathSegLineToVerticalRel, + PATHSEG_CURVETO_CUBIC_SMOOTH_ABS = PathSegCurveToCubicSmoothAbs, + PATHSEG_CURVETO_CUBIC_SMOOTH_REL = PathSegCurveToCubicSmoothRel, + PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS = PathSegCurveToQuadraticSmoothAbs, + PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL = PathSegCurveToQuadraticSmoothRel + }; + + virtual unsigned short pathSegType() const = 0; + virtual String pathSegTypeAsLetter() const = 0; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGPathSeg.idl b/Source/WebCore/svg/SVGPathSeg.idl new file mode 100644 index 0000000..f46518c --- /dev/null +++ b/Source/WebCore/svg/SVGPathSeg.idl @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) 2006, 2009 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG, CustomToJS, Polymorphic] SVGPathSeg { + // Path Segment Types + const unsigned short PATHSEG_UNKNOWN = 0; + const unsigned short PATHSEG_CLOSEPATH = 1; + const unsigned short PATHSEG_MOVETO_ABS = 2; + const unsigned short PATHSEG_MOVETO_REL = 3; + const unsigned short PATHSEG_LINETO_ABS = 4; + const unsigned short PATHSEG_LINETO_REL = 5; + const unsigned short PATHSEG_CURVETO_CUBIC_ABS = 6; + const unsigned short PATHSEG_CURVETO_CUBIC_REL = 7; + const unsigned short PATHSEG_CURVETO_QUADRATIC_ABS = 8; + const unsigned short PATHSEG_CURVETO_QUADRATIC_REL = 9; + const unsigned short PATHSEG_ARC_ABS = 10; + const unsigned short PATHSEG_ARC_REL = 11; + const unsigned short PATHSEG_LINETO_HORIZONTAL_ABS = 12; + const unsigned short PATHSEG_LINETO_HORIZONTAL_REL = 13; + const unsigned short PATHSEG_LINETO_VERTICAL_ABS = 14; + const unsigned short PATHSEG_LINETO_VERTICAL_REL = 15; + const unsigned short PATHSEG_CURVETO_CUBIC_SMOOTH_ABS = 16; + const unsigned short PATHSEG_CURVETO_CUBIC_SMOOTH_REL = 17; + const unsigned short PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS = 18; + const unsigned short PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL = 19; + + readonly attribute unsigned short pathSegType; + readonly attribute DOMString pathSegTypeAsLetter; + }; + +} diff --git a/Source/WebCore/svg/SVGPathSegArc.h b/Source/WebCore/svg/SVGPathSegArc.h new file mode 100644 index 0000000..e835bc3 --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegArc.h @@ -0,0 +1,140 @@ +/* + * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2008 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPathSegArc_h +#define SVGPathSegArc_h + +#if ENABLE(SVG) +#include "SVGPathSegWithContext.h" + +namespace WebCore { + +class SVGPathSegArc : public SVGPathSegWithContext { +public: + SVGPathSegArc(SVGPathElement* element, SVGPathSegRole role, float x, float y, float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag) + : SVGPathSegWithContext(element, role) + , m_x(x) + , m_y(y) + , m_r1(r1) + , m_r2(r2) + , m_angle(angle) + , m_largeArcFlag(largeArcFlag) + , m_sweepFlag(sweepFlag) + { + } + + float x() const { return m_x; } + void setX(float x) + { + m_x = x; + commitChange(); + } + + float y() const { return m_y; } + void setY(float y) + { + m_y = y; + commitChange(); + } + + float r1() const { return m_r1; } + void setR1(float r1) + { + m_r1 = r1; + commitChange(); + } + + float r2() const { return m_r2; } + void setR2(float r2) + { + m_r2 = r2; + commitChange(); + } + + float angle() const { return m_angle; } + void setAngle(float angle) + { + m_angle = angle; + commitChange(); + } + + bool largeArcFlag() const { return m_largeArcFlag; } + void setLargeArcFlag(bool largeArcFlag) + { + m_largeArcFlag = largeArcFlag; + commitChange(); + } + + bool sweepFlag() const { return m_sweepFlag; } + void setSweepFlag(bool sweepFlag) + { + m_sweepFlag = sweepFlag; + commitChange(); + } + +private: + float m_x; + float m_y; + float m_r1; + float m_r2; + float m_angle; + + bool m_largeArcFlag : 1; + bool m_sweepFlag : 1; +}; + +class SVGPathSegArcAbs : public SVGPathSegArc { +public: + static PassRefPtr<SVGPathSegArcAbs> create(SVGPathElement* element, SVGPathSegRole role, float x, float y, float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag) + { + return adoptRef(new SVGPathSegArcAbs(element, role, x, y, r1, r2, angle, largeArcFlag, sweepFlag)); + } + +private: + SVGPathSegArcAbs(SVGPathElement* element, SVGPathSegRole role, float x, float y, float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag) + : SVGPathSegArc(element, role, x, y, r1, r2, angle, largeArcFlag, sweepFlag) + { + } + + virtual unsigned short pathSegType() const { return PATHSEG_ARC_ABS; } + virtual String pathSegTypeAsLetter() const { return "A"; } +}; + +class SVGPathSegArcRel : public SVGPathSegArc { +public: + static PassRefPtr<SVGPathSegArcRel> create(SVGPathElement* element, SVGPathSegRole role, float x, float y, float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag) + { + return adoptRef(new SVGPathSegArcRel(element, role, x, y, r1, r2, angle, largeArcFlag, sweepFlag)); + } + +private: + SVGPathSegArcRel(SVGPathElement* element, SVGPathSegRole role, float x, float y, float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag) + : SVGPathSegArc(element, role, x, y, r1, r2, angle, largeArcFlag, sweepFlag) + { + } + + virtual unsigned short pathSegType() const { return PATHSEG_ARC_REL; } + virtual String pathSegTypeAsLetter() const { return "a"; } +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGPathSegArcAbs.idl b/Source/WebCore/svg/SVGPathSegArcAbs.idl new file mode 100644 index 0000000..7568155 --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegArcAbs.idl @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2006 Apple Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * + * 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGPathSegArcAbs : SVGPathSeg { + attribute [StrictTypeChecking] float x; + attribute [StrictTypeChecking] float y; + attribute [StrictTypeChecking] float r1; + attribute [StrictTypeChecking] float r2; + attribute [StrictTypeChecking] float angle; + attribute [StrictTypeChecking] boolean largeArcFlag; + attribute [StrictTypeChecking] boolean sweepFlag; + }; + +} diff --git a/Source/WebCore/svg/SVGPathSegArcRel.idl b/Source/WebCore/svg/SVGPathSegArcRel.idl new file mode 100644 index 0000000..78852d8 --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegArcRel.idl @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2006 Apple Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * + * 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGPathSegArcRel : SVGPathSeg { + attribute [StrictTypeChecking] float x; + attribute [StrictTypeChecking] float y; + attribute [StrictTypeChecking] float r1; + attribute [StrictTypeChecking] float r2; + attribute [StrictTypeChecking] float angle; + attribute [StrictTypeChecking] boolean largeArcFlag; + attribute [StrictTypeChecking] boolean sweepFlag; + }; + +} diff --git a/Source/WebCore/svg/SVGPathSegClosePath.h b/Source/WebCore/svg/SVGPathSegClosePath.h new file mode 100644 index 0000000..c3b2c14 --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegClosePath.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPathSegClosePath_h +#define SVGPathSegClosePath_h + +#if ENABLE(SVG) +#include "SVGPathSegWithContext.h" + +namespace WebCore { + +class SVGPathSegClosePath : public SVGPathSegWithContext { +public: + static PassRefPtr<SVGPathSegClosePath> create(SVGPathElement* element, SVGPathSegRole role) + { + return adoptRef(new SVGPathSegClosePath(element, role)); + } + +private: + SVGPathSegClosePath(SVGPathElement* element, SVGPathSegRole role) + : SVGPathSegWithContext(element, role) + { + } + + virtual unsigned short pathSegType() const { return PATHSEG_CLOSEPATH; } + virtual String pathSegTypeAsLetter() const { return "Z"; } +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGPathSegClosePath.idl b/Source/WebCore/svg/SVGPathSegClosePath.idl new file mode 100644 index 0000000..2bd6c61 --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegClosePath.idl @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2006 Apple Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * + * 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGPathSegClosePath : SVGPathSeg { + }; + +} diff --git a/Source/WebCore/svg/SVGPathSegCurvetoCubic.h b/Source/WebCore/svg/SVGPathSegCurvetoCubic.h new file mode 100644 index 0000000..169d8f8 --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegCurvetoCubic.h @@ -0,0 +1,130 @@ +/* + * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2008 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPathSegCurvetoCubic_h +#define SVGPathSegCurvetoCubic_h + +#if ENABLE(SVG) +#include "SVGPathSegWithContext.h" + +namespace WebCore { + +class SVGPathSegCurvetoCubic : public SVGPathSegWithContext { +public: + SVGPathSegCurvetoCubic(SVGPathElement* element, SVGPathSegRole role, float x, float y, float x1, float y1, float x2, float y2) + : SVGPathSegWithContext(element, role) + , m_x(x) + , m_y(y) + , m_x1(x1) + , m_y1(y1) + , m_x2(x2) + , m_y2(y2) + { + } + + float x() const { return m_x; } + void setX(float x) + { + m_x = x; + commitChange(); + } + + float y() const { return m_y; } + void setY(float y) + { + m_y = y; + commitChange(); + } + + float x1() const { return m_x1; } + void setX1(float x1) + { + m_x1 = x1; + commitChange(); + } + + float y1() const { return m_y1; } + void setY1(float y1) + { + m_y1 = y1; + commitChange(); + } + + float x2() const { return m_x2; } + void setX2(float x2) + { + m_x2 = x2; + commitChange(); + } + + float y2() const { return m_y2; } + void setY2(float y2) + { + m_y2 = y2; + commitChange(); + } + +private: + float m_x; + float m_y; + float m_x1; + float m_y1; + float m_x2; + float m_y2; +}; + +class SVGPathSegCurvetoCubicAbs : public SVGPathSegCurvetoCubic { +public: + static PassRefPtr<SVGPathSegCurvetoCubicAbs> create(SVGPathElement* element, SVGPathSegRole role, float x, float y, float x1, float y1, float x2, float y2) + { + return adoptRef(new SVGPathSegCurvetoCubicAbs(element, role, x, y, x1, y1, x2, y2)); + } + +private: + SVGPathSegCurvetoCubicAbs(SVGPathElement* element, SVGPathSegRole role, float x, float y, float x1, float y1, float x2, float y2) + : SVGPathSegCurvetoCubic(element, role, x, y, x1, y1, x2, y2) + { + } + + virtual unsigned short pathSegType() const { return PATHSEG_CURVETO_CUBIC_ABS; } + virtual String pathSegTypeAsLetter() const { return "C"; } +}; + +class SVGPathSegCurvetoCubicRel : public SVGPathSegCurvetoCubic { +public: + static PassRefPtr<SVGPathSegCurvetoCubicRel> create(SVGPathElement* element, SVGPathSegRole role, float x, float y, float x1, float y1, float x2, float y2) + { + return adoptRef(new SVGPathSegCurvetoCubicRel(element, role, x, y, x1, y1, x2, y2)); + } + +private: + SVGPathSegCurvetoCubicRel(SVGPathElement* element, SVGPathSegRole role, float x, float y, float x1, float y1, float x2, float y2) + : SVGPathSegCurvetoCubic(element, role, x, y, x1, y1, x2, y2) + { + } + + virtual unsigned short pathSegType() const { return PATHSEG_CURVETO_CUBIC_REL; } + virtual String pathSegTypeAsLetter() const { return "c"; } +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGPathSegCurvetoCubicAbs.idl b/Source/WebCore/svg/SVGPathSegCurvetoCubicAbs.idl new file mode 100644 index 0000000..4baf113 --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegCurvetoCubicAbs.idl @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2006 Apple Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * + * 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGPathSegCurvetoCubicAbs : SVGPathSeg { + attribute [StrictTypeChecking] float x; + attribute [StrictTypeChecking] float y; + attribute [StrictTypeChecking] float x1; + attribute [StrictTypeChecking] float y1; + attribute [StrictTypeChecking] float x2; + attribute [StrictTypeChecking] float y2; + }; + +} diff --git a/Source/WebCore/svg/SVGPathSegCurvetoCubicRel.idl b/Source/WebCore/svg/SVGPathSegCurvetoCubicRel.idl new file mode 100644 index 0000000..7e9fb7f --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegCurvetoCubicRel.idl @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2006 Apple Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * + * 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGPathSegCurvetoCubicRel : SVGPathSeg { + attribute [StrictTypeChecking] float x; + attribute [StrictTypeChecking] float y; + attribute [StrictTypeChecking] float x1; + attribute [StrictTypeChecking] float y1; + attribute [StrictTypeChecking] float x2; + attribute [StrictTypeChecking] float y2; + }; + +} diff --git a/Source/WebCore/svg/SVGPathSegCurvetoCubicSmooth.h b/Source/WebCore/svg/SVGPathSegCurvetoCubicSmooth.h new file mode 100644 index 0000000..a654297 --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegCurvetoCubicSmooth.h @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2008 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPathSegCurvetoCubicSmooth_h +#define SVGPathSegCurvetoCubicSmooth_h + +#if ENABLE(SVG) +#include "SVGPathSegWithContext.h" + +namespace WebCore { + +class SVGPathSegCurvetoCubicSmooth : public SVGPathSegWithContext { +public: + SVGPathSegCurvetoCubicSmooth(SVGPathElement* element, SVGPathSegRole role, float x, float y, float x2, float y2) + : SVGPathSegWithContext(element, role) + , m_x(x) + , m_y(y) + , m_x2(x2) + , m_y2(y2) + { + } + + float x() const { return m_x; } + void setX(float x) + { + m_x = x; + commitChange(); + } + + float y() const { return m_y; } + void setY(float y) + { + m_y = y; + commitChange(); + } + + float x2() const { return m_x2; } + void setX2(float x2) + { + m_x2 = x2; + commitChange(); + } + + float y2() const { return m_y2; } + void setY2(float y2) + { + m_y2 = y2; + commitChange(); + } + +private: + float m_x; + float m_y; + float m_x2; + float m_y2; +}; + +class SVGPathSegCurvetoCubicSmoothAbs : public SVGPathSegCurvetoCubicSmooth { +public: + static PassRefPtr<SVGPathSegCurvetoCubicSmoothAbs> create(SVGPathElement* element, SVGPathSegRole role, float x, float y, float x2, float y2) + { + return adoptRef(new SVGPathSegCurvetoCubicSmoothAbs(element, role, x, y, x2, y2)); + } + +private: + SVGPathSegCurvetoCubicSmoothAbs(SVGPathElement* element, SVGPathSegRole role, float x, float y, float x2, float y2) + : SVGPathSegCurvetoCubicSmooth(element, role, x, y, x2, y2) + { + } + + virtual unsigned short pathSegType() const { return PATHSEG_CURVETO_CUBIC_SMOOTH_ABS; } + virtual String pathSegTypeAsLetter() const { return "S"; } +}; + +class SVGPathSegCurvetoCubicSmoothRel : public SVGPathSegCurvetoCubicSmooth { +public: + static PassRefPtr<SVGPathSegCurvetoCubicSmoothRel> create(SVGPathElement* element, SVGPathSegRole role, float x, float y, float x2, float y2) + { + return adoptRef(new SVGPathSegCurvetoCubicSmoothRel(element, role, x, y, x2, y2)); + } + +private: + SVGPathSegCurvetoCubicSmoothRel(SVGPathElement* element, SVGPathSegRole role, float x, float y, float x2, float y2) + : SVGPathSegCurvetoCubicSmooth(element, role, x, y, x2, y2) + { + } + + virtual unsigned short pathSegType() const { return PATHSEG_CURVETO_CUBIC_SMOOTH_REL; } + virtual String pathSegTypeAsLetter() const { return "s"; } +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGPathSegCurvetoCubicSmoothAbs.idl b/Source/WebCore/svg/SVGPathSegCurvetoCubicSmoothAbs.idl new file mode 100644 index 0000000..0779c9f --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegCurvetoCubicSmoothAbs.idl @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2006 Apple Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * + * 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGPathSegCurvetoCubicSmoothAbs : SVGPathSeg { + attribute [StrictTypeChecking] float x; + attribute [StrictTypeChecking] float y; + attribute [StrictTypeChecking] float x2; + attribute [StrictTypeChecking] float y2; + }; + +} diff --git a/Source/WebCore/svg/SVGPathSegCurvetoCubicSmoothRel.idl b/Source/WebCore/svg/SVGPathSegCurvetoCubicSmoothRel.idl new file mode 100644 index 0000000..d4f71e4 --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegCurvetoCubicSmoothRel.idl @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2006 Apple Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * + * 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGPathSegCurvetoCubicSmoothRel : SVGPathSeg { + attribute [StrictTypeChecking] float x; + attribute [StrictTypeChecking] float y; + attribute [StrictTypeChecking] float x2; + attribute [StrictTypeChecking] float y2; + }; + +} diff --git a/Source/WebCore/svg/SVGPathSegCurvetoQuadratic.h b/Source/WebCore/svg/SVGPathSegCurvetoQuadratic.h new file mode 100644 index 0000000..894f787 --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegCurvetoQuadratic.h @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2008 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPathSegCurvetoQuadratic_h +#define SVGPathSegCurvetoQuadratic_h + +#if ENABLE(SVG) +#include "SVGPathSegWithContext.h" + +namespace WebCore { + +class SVGPathSegCurvetoQuadratic : public SVGPathSegWithContext { +public: + SVGPathSegCurvetoQuadratic(SVGPathElement* element, SVGPathSegRole role, float x, float y, float x1, float y1) + : SVGPathSegWithContext(element, role) + , m_x(x) + , m_y(y) + , m_x1(x1) + , m_y1(y1) + { + } + + float x() const { return m_x; } + void setX(float x) + { + m_x = x; + commitChange(); + } + + float y() const { return m_y; } + void setY(float y) + { + m_y = y; + commitChange(); + } + + float x1() const { return m_x1; } + void setX1(float x1) + { + m_x1 = x1; + commitChange(); + } + + float y1() const { return m_y1; } + void setY1(float y1) + { + m_y1 = y1; + commitChange(); + } + +private: + float m_x; + float m_y; + float m_x1; + float m_y1; +}; + +class SVGPathSegCurvetoQuadraticAbs : public SVGPathSegCurvetoQuadratic { +public: + static PassRefPtr<SVGPathSegCurvetoQuadraticAbs> create(SVGPathElement* element, SVGPathSegRole role, float x, float y, float x1, float y1) + { + return adoptRef(new SVGPathSegCurvetoQuadraticAbs(element, role, x, y, x1, y1)); + } + +private: + SVGPathSegCurvetoQuadraticAbs(SVGPathElement* element, SVGPathSegRole role, float x, float y, float x1, float y1) + : SVGPathSegCurvetoQuadratic(element, role, x, y, x1, y1) + { + } + + virtual unsigned short pathSegType() const { return PATHSEG_CURVETO_QUADRATIC_ABS; } + virtual String pathSegTypeAsLetter() const { return "Q"; } +}; + +class SVGPathSegCurvetoQuadraticRel : public SVGPathSegCurvetoQuadratic { +public: + static PassRefPtr<SVGPathSegCurvetoQuadraticRel> create(SVGPathElement* element, SVGPathSegRole role, float x, float y, float x1, float y1) + { + return adoptRef(new SVGPathSegCurvetoQuadraticRel(element, role, x, y, x1, y1)); + } + +private: + SVGPathSegCurvetoQuadraticRel(SVGPathElement* element, SVGPathSegRole role, float x, float y, float x1, float y1) + : SVGPathSegCurvetoQuadratic(element, role, x, y, x1, y1) + { + } + + virtual unsigned short pathSegType() const { return PATHSEG_CURVETO_QUADRATIC_REL; } + virtual String pathSegTypeAsLetter() const { return "q"; } +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGPathSegCurvetoQuadraticAbs.idl b/Source/WebCore/svg/SVGPathSegCurvetoQuadraticAbs.idl new file mode 100644 index 0000000..1fbb461 --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegCurvetoQuadraticAbs.idl @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2006 Apple Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * + * 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGPathSegCurvetoQuadraticAbs : SVGPathSeg { + attribute [StrictTypeChecking] float x; + attribute [StrictTypeChecking] float y; + attribute [StrictTypeChecking] float x1; + attribute [StrictTypeChecking] float y1; + }; + +} diff --git a/Source/WebCore/svg/SVGPathSegCurvetoQuadraticRel.idl b/Source/WebCore/svg/SVGPathSegCurvetoQuadraticRel.idl new file mode 100644 index 0000000..48a39fb --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegCurvetoQuadraticRel.idl @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2006 Apple Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * + * 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGPathSegCurvetoQuadraticRel : SVGPathSeg { + attribute [StrictTypeChecking] float x; + attribute [StrictTypeChecking] float y; + attribute [StrictTypeChecking] float x1; + attribute [StrictTypeChecking] float y1; + }; + +} diff --git a/Source/WebCore/svg/SVGPathSegCurvetoQuadraticSmooth.h b/Source/WebCore/svg/SVGPathSegCurvetoQuadraticSmooth.h new file mode 100644 index 0000000..b66062a --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegCurvetoQuadraticSmooth.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2008 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPathSegCurvetoQuadraticSmooth_h +#define SVGPathSegCurvetoQuadraticSmooth_h + +#if ENABLE(SVG) +#include "SVGPathSegWithContext.h" + +namespace WebCore { + +class SVGPathSegCurvetoQuadraticSmoothAbs : public SVGPathSegSingleCoordinate { +public: + static PassRefPtr<SVGPathSegCurvetoQuadraticSmoothAbs> create(SVGPathElement* element, SVGPathSegRole role, float x, float y) + { + return adoptRef(new SVGPathSegCurvetoQuadraticSmoothAbs(element, role, x, y)); + } + +private: + SVGPathSegCurvetoQuadraticSmoothAbs(SVGPathElement* element, SVGPathSegRole role, float x, float y) + : SVGPathSegSingleCoordinate(element, role, x, y) + { + } + + virtual unsigned short pathSegType() const { return PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS; } + virtual String pathSegTypeAsLetter() const { return "T"; } +}; + +class SVGPathSegCurvetoQuadraticSmoothRel : public SVGPathSegSingleCoordinate { +public: + static PassRefPtr<SVGPathSegCurvetoQuadraticSmoothRel> create(SVGPathElement* element, SVGPathSegRole role, float x, float y) + { + return adoptRef(new SVGPathSegCurvetoQuadraticSmoothRel(element, role, x, y)); + } + +private: + SVGPathSegCurvetoQuadraticSmoothRel(SVGPathElement* element, SVGPathSegRole role, float x, float y) + : SVGPathSegSingleCoordinate(element, role, x, y) + { + } + + virtual unsigned short pathSegType() const { return PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL; } + virtual String pathSegTypeAsLetter() const { return "t"; } +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGPathSegCurvetoQuadraticSmoothAbs.idl b/Source/WebCore/svg/SVGPathSegCurvetoQuadraticSmoothAbs.idl new file mode 100644 index 0000000..ad02534 --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegCurvetoQuadraticSmoothAbs.idl @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2006 Apple Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * + * 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGPathSegCurvetoQuadraticSmoothAbs : SVGPathSeg { + attribute [StrictTypeChecking] float x; + attribute [StrictTypeChecking] float y; + }; + +} diff --git a/Source/WebCore/svg/SVGPathSegCurvetoQuadraticSmoothRel.idl b/Source/WebCore/svg/SVGPathSegCurvetoQuadraticSmoothRel.idl new file mode 100644 index 0000000..6d58b8f --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegCurvetoQuadraticSmoothRel.idl @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2006 Apple Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * + * 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGPathSegCurvetoQuadraticSmoothRel : SVGPathSeg { + attribute [StrictTypeChecking] float x; + attribute [StrictTypeChecking] float y; + }; + +} diff --git a/Source/WebCore/svg/SVGPathSegLineto.h b/Source/WebCore/svg/SVGPathSegLineto.h new file mode 100644 index 0000000..c995c98 --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegLineto.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2008 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPathSegLineto_h +#define SVGPathSegLineto_h + +#if ENABLE(SVG) +#include "SVGPathSegWithContext.h" + +namespace WebCore { + +class SVGPathSegLinetoAbs : public SVGPathSegSingleCoordinate { +public: + static PassRefPtr<SVGPathSegLinetoAbs> create(SVGPathElement* element, SVGPathSegRole role, float x, float y) + { + return adoptRef(new SVGPathSegLinetoAbs(element, role, x, y)); + } + +private: + SVGPathSegLinetoAbs(SVGPathElement* element, SVGPathSegRole role, float x, float y) + : SVGPathSegSingleCoordinate(element, role, x, y) + { + } + + virtual unsigned short pathSegType() const { return PATHSEG_LINETO_ABS; } + virtual String pathSegTypeAsLetter() const { return "L"; } +}; + +class SVGPathSegLinetoRel : public SVGPathSegSingleCoordinate { +public: + static PassRefPtr<SVGPathSegLinetoRel> create(SVGPathElement* element, SVGPathSegRole role, float x, float y) + { + return adoptRef(new SVGPathSegLinetoRel(element, role, x, y)); + } + +private: + SVGPathSegLinetoRel(SVGPathElement* element, SVGPathSegRole role, float x, float y) + : SVGPathSegSingleCoordinate(element, role, x, y) + { + } + + virtual unsigned short pathSegType() const { return PATHSEG_LINETO_REL; } + virtual String pathSegTypeAsLetter() const { return "l"; } +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGPathSegLinetoAbs.idl b/Source/WebCore/svg/SVGPathSegLinetoAbs.idl new file mode 100644 index 0000000..c428a2b --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegLinetoAbs.idl @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2006 Apple Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * + * 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGPathSegLinetoAbs : SVGPathSeg { + attribute [StrictTypeChecking] float x; + attribute [StrictTypeChecking] float y; + }; + +} diff --git a/Source/WebCore/svg/SVGPathSegLinetoHorizontal.h b/Source/WebCore/svg/SVGPathSegLinetoHorizontal.h new file mode 100644 index 0000000..d175cdd --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegLinetoHorizontal.h @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2008 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPathSegLinetoHorizontal_h +#define SVGPathSegLinetoHorizontal_h + +#if ENABLE(SVG) +#include "SVGPathSegWithContext.h" + +namespace WebCore { + +class SVGPathSegLinetoHorizontal : public SVGPathSegWithContext { +public: + SVGPathSegLinetoHorizontal(SVGPathElement* element, SVGPathSegRole role, float x) + : SVGPathSegWithContext(element, role) + , m_x(x) + { + } + + float x() const { return m_x; } + void setX(float x) + { + m_x = x; + commitChange(); + } + +private: + float m_x; +}; + +class SVGPathSegLinetoHorizontalAbs : public SVGPathSegLinetoHorizontal { +public: + static PassRefPtr<SVGPathSegLinetoHorizontalAbs> create(SVGPathElement* element, SVGPathSegRole role, float x) + { + return adoptRef(new SVGPathSegLinetoHorizontalAbs(element, role, x)); + } + +private: + SVGPathSegLinetoHorizontalAbs(SVGPathElement* element, SVGPathSegRole role, float x) + : SVGPathSegLinetoHorizontal(element, role, x) + { + } + + virtual unsigned short pathSegType() const { return PATHSEG_LINETO_HORIZONTAL_ABS; } + virtual String pathSegTypeAsLetter() const { return "H"; } +}; + +class SVGPathSegLinetoHorizontalRel : public SVGPathSegLinetoHorizontal { +public: + static PassRefPtr<SVGPathSegLinetoHorizontalRel> create(SVGPathElement* element, SVGPathSegRole role, float x) + { + return adoptRef(new SVGPathSegLinetoHorizontalRel(element, role, x)); + } + +private: + SVGPathSegLinetoHorizontalRel(SVGPathElement* element, SVGPathSegRole role, float x) + : SVGPathSegLinetoHorizontal(element, role, x) + { + } + + virtual unsigned short pathSegType() const { return PATHSEG_LINETO_HORIZONTAL_REL; } + virtual String pathSegTypeAsLetter() const { return "h"; } +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGPathSegLinetoHorizontalAbs.idl b/Source/WebCore/svg/SVGPathSegLinetoHorizontalAbs.idl new file mode 100644 index 0000000..522f997 --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegLinetoHorizontalAbs.idl @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2006 Apple Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * + * 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGPathSegLinetoHorizontalAbs : SVGPathSeg { + attribute [StrictTypeChecking] float x; + }; + +} diff --git a/Source/WebCore/svg/SVGPathSegLinetoHorizontalRel.idl b/Source/WebCore/svg/SVGPathSegLinetoHorizontalRel.idl new file mode 100644 index 0000000..3f9a22a --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegLinetoHorizontalRel.idl @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2006 Apple Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * + * 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGPathSegLinetoHorizontalRel : SVGPathSeg { + attribute [StrictTypeChecking] float x; + }; + +} diff --git a/Source/WebCore/svg/SVGPathSegLinetoRel.idl b/Source/WebCore/svg/SVGPathSegLinetoRel.idl new file mode 100644 index 0000000..d92cdc4 --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegLinetoRel.idl @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2006 Apple Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * + * 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGPathSegLinetoRel : SVGPathSeg { + attribute [StrictTypeChecking] float x; + attribute [StrictTypeChecking] float y; + }; + +} diff --git a/Source/WebCore/svg/SVGPathSegLinetoVertical.h b/Source/WebCore/svg/SVGPathSegLinetoVertical.h new file mode 100644 index 0000000..fec7fb6 --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegLinetoVertical.h @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2008 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPathSegLinetoVertical_h +#define SVGPathSegLinetoVertical_h + +#if ENABLE(SVG) +#include "SVGPathSegWithContext.h" + +namespace WebCore { + +class SVGPathSegLinetoVertical : public SVGPathSegWithContext { +public: + SVGPathSegLinetoVertical(SVGPathElement* element, SVGPathSegRole role, float y) + : SVGPathSegWithContext(element, role) + , m_y(y) + { + } + + float y() const { return m_y; } + void setY(float y) + { + m_y = y; + commitChange(); + } + +private: + float m_y; +}; + +class SVGPathSegLinetoVerticalAbs : public SVGPathSegLinetoVertical { +public: + static PassRefPtr<SVGPathSegLinetoVerticalAbs> create(SVGPathElement* element, SVGPathSegRole role, float y) + { + return adoptRef(new SVGPathSegLinetoVerticalAbs(element, role, y)); + } + +private: + SVGPathSegLinetoVerticalAbs(SVGPathElement* element, SVGPathSegRole role, float y) + : SVGPathSegLinetoVertical(element, role, y) + { + } + + virtual unsigned short pathSegType() const { return PATHSEG_LINETO_VERTICAL_ABS; } + virtual String pathSegTypeAsLetter() const { return "V"; } +}; + +class SVGPathSegLinetoVerticalRel : public SVGPathSegLinetoVertical { +public: + static PassRefPtr<SVGPathSegLinetoVerticalRel> create(SVGPathElement* element, SVGPathSegRole role, float y) + { + return adoptRef(new SVGPathSegLinetoVerticalRel(element, role, y)); + } + +private: + SVGPathSegLinetoVerticalRel(SVGPathElement* element, SVGPathSegRole role, float y) + : SVGPathSegLinetoVertical(element, role, y) + { + } + + virtual unsigned short pathSegType() const { return PATHSEG_LINETO_VERTICAL_REL; } + virtual String pathSegTypeAsLetter() const { return "v"; } +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGPathSegLinetoVerticalAbs.idl b/Source/WebCore/svg/SVGPathSegLinetoVerticalAbs.idl new file mode 100644 index 0000000..a9af261 --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegLinetoVerticalAbs.idl @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2006 Apple Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * + * 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGPathSegLinetoVerticalAbs : SVGPathSeg { + attribute [StrictTypeChecking] float y; + }; + +} diff --git a/Source/WebCore/svg/SVGPathSegLinetoVerticalRel.idl b/Source/WebCore/svg/SVGPathSegLinetoVerticalRel.idl new file mode 100644 index 0000000..a9b9b36 --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegLinetoVerticalRel.idl @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2006 Apple Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * + * 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGPathSegLinetoVerticalRel : SVGPathSeg { + attribute [StrictTypeChecking] float y; + }; + +} diff --git a/Source/WebCore/svg/SVGPathSegList.cpp b/Source/WebCore/svg/SVGPathSegList.cpp new file mode 100644 index 0000000..3782e19 --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegList.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPathSegList.h" + +#include "SVGNames.h" +#include "SVGPathElement.h" +#include "SVGPathParserFactory.h" + +namespace WebCore { + +String SVGPathSegList::valueAsString() const +{ + String pathString; + SVGPathParserFactory::self()->buildStringFromSVGPathSegList(*this, pathString, UnalteredParsing); + return pathString; +} + +void SVGPathSegList::commitChange(SVGElement* contextElement) +{ + ASSERT(contextElement); + ASSERT(contextElement->hasTagName(SVGNames::pathTag)); + static_cast<SVGPathElement*>(contextElement)->pathSegListChanged(m_role); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGPathSegList.h b/Source/WebCore/svg/SVGPathSegList.h new file mode 100644 index 0000000..5013b9f --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegList.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPathSegList_h +#define SVGPathSegList_h + +#if ENABLE(SVG) +#include "SVGPathSeg.h" +#include "SVGPropertyTraits.h" + +#include <wtf/Vector.h> +#include <wtf/text/WTFString.h> + +namespace WebCore { + +class SVGElement; + +class SVGPathSegList : public Vector<RefPtr<SVGPathSeg> > { +public: + SVGPathSegList(SVGPathSegRole role) + : m_role(role) + { + } + + String valueAsString() const; + + // Only used by SVGPathSegListPropertyTearOff. + void commitChange(SVGElement* contextElement); + +private: + SVGPathSegRole m_role; +}; + +template<> +struct SVGPropertyTraits<SVGPathSegList> { + static SVGPathSegList initialValue() { return SVGPathSegList(PathSegUndefinedRole); } + typedef RefPtr<SVGPathSeg> ListItemType; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGPathSegList.idl b/Source/WebCore/svg/SVGPathSegList.idl new file mode 100644 index 0000000..e77a997 --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegList.idl @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGPathSegList { + readonly attribute unsigned long numberOfItems; + + void clear() + raises(DOMException); + [StrictTypeChecking, RequiresAllArguments=Raise] SVGPathSeg initialize(in SVGPathSeg newItem) + raises(DOMException, SVGException); + [StrictTypeChecking, RequiresAllArguments=Raise] SVGPathSeg getItem(in unsigned long index) + raises(DOMException); + [StrictTypeChecking, RequiresAllArguments=Raise] SVGPathSeg insertItemBefore(in SVGPathSeg newItem, in unsigned long index) + raises(DOMException, SVGException); + [StrictTypeChecking, RequiresAllArguments=Raise] SVGPathSeg replaceItem(in SVGPathSeg newItem, in unsigned long index) + raises(DOMException, SVGException); + [StrictTypeChecking, RequiresAllArguments=Raise] SVGPathSeg removeItem(in unsigned long index) + raises(DOMException); + [StrictTypeChecking, RequiresAllArguments=Raise] SVGPathSeg appendItem(in SVGPathSeg newItem) + raises(DOMException, SVGException); + }; + +} diff --git a/Source/WebCore/svg/SVGPathSegListBuilder.cpp b/Source/WebCore/svg/SVGPathSegListBuilder.cpp new file mode 100644 index 0000000..bd657c3 --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegListBuilder.cpp @@ -0,0 +1,151 @@ +/* + * Copyright (C) 2002, 2003 The Karbon Developers + * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org> + * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org> + * Copyright (C) 2007, 2009 Apple Inc. All rights reserved. + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPathSegListBuilder.h" + +#include "ExceptionCode.h" +#include "SVGPathElement.h" +#include "SVGPathSegArc.h" +#include "SVGPathSegClosePath.h" +#include "SVGPathSegCurvetoCubic.h" +#include "SVGPathSegCurvetoCubicSmooth.h" +#include "SVGPathSegCurvetoQuadratic.h" +#include "SVGPathSegCurvetoQuadraticSmooth.h" +#include "SVGPathSegLineto.h" +#include "SVGPathSegLinetoHorizontal.h" +#include "SVGPathSegLinetoVertical.h" +#include "SVGPathSegList.h" +#include "SVGPathSegMoveto.h" + +namespace WebCore { + +SVGPathSegListBuilder::SVGPathSegListBuilder() + : m_pathElement(0) + , m_pathSegList(0) + , m_pathSegRole(PathSegUndefinedRole) +{ +} + +void SVGPathSegListBuilder::moveTo(const FloatPoint& targetPoint, bool, PathCoordinateMode mode) +{ + ASSERT(m_pathElement); + ASSERT(m_pathSegList); + if (mode == AbsoluteCoordinates) + m_pathSegList->append(m_pathElement->createSVGPathSegMovetoAbs(targetPoint.x(), targetPoint.y(), m_pathSegRole)); + else + m_pathSegList->append(m_pathElement->createSVGPathSegMovetoRel(targetPoint.x(), targetPoint.y(), m_pathSegRole)); +} + +void SVGPathSegListBuilder::lineTo(const FloatPoint& targetPoint, PathCoordinateMode mode) +{ + ASSERT(m_pathElement); + ASSERT(m_pathSegList); + if (mode == AbsoluteCoordinates) + m_pathSegList->append(m_pathElement->createSVGPathSegLinetoAbs(targetPoint.x(), targetPoint.y(), m_pathSegRole)); + else + m_pathSegList->append(m_pathElement->createSVGPathSegLinetoRel(targetPoint.x(), targetPoint.y(), m_pathSegRole)); +} + +void SVGPathSegListBuilder::lineToHorizontal(float x, PathCoordinateMode mode) +{ + ASSERT(m_pathElement); + ASSERT(m_pathSegList); + if (mode == AbsoluteCoordinates) + m_pathSegList->append(m_pathElement->createSVGPathSegLinetoHorizontalAbs(x, m_pathSegRole)); + else + m_pathSegList->append(m_pathElement->createSVGPathSegLinetoHorizontalRel(x, m_pathSegRole)); +} + +void SVGPathSegListBuilder::lineToVertical(float y, PathCoordinateMode mode) +{ + ASSERT(m_pathElement); + ASSERT(m_pathSegList); + if (mode == AbsoluteCoordinates) + m_pathSegList->append(m_pathElement->createSVGPathSegLinetoVerticalAbs(y, m_pathSegRole)); + else + m_pathSegList->append(m_pathElement->createSVGPathSegLinetoVerticalRel(y, m_pathSegRole)); +} + +void SVGPathSegListBuilder::curveToCubic(const FloatPoint& point1, const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode) +{ + ASSERT(m_pathElement); + ASSERT(m_pathSegList); + if (mode == AbsoluteCoordinates) + m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoCubicAbs(targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), point2.x(), point2.y(), m_pathSegRole)); + else + m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoCubicRel(targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), point2.x(), point2.y(), m_pathSegRole)); +} + +void SVGPathSegListBuilder::curveToCubicSmooth(const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode) +{ + ASSERT(m_pathElement); + ASSERT(m_pathSegList); + if (mode == AbsoluteCoordinates) + m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoCubicSmoothAbs(targetPoint.x(), targetPoint.y(), point2.x(), point2.y(), m_pathSegRole)); + else + m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoCubicSmoothRel(targetPoint.x(), targetPoint.y(), point2.x(), point2.y(), m_pathSegRole)); +} + +void SVGPathSegListBuilder::curveToQuadratic(const FloatPoint& point1, const FloatPoint& targetPoint, PathCoordinateMode mode) +{ + ASSERT(m_pathElement); + ASSERT(m_pathSegList); + if (mode == AbsoluteCoordinates) + m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoQuadraticAbs(targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), m_pathSegRole)); + else + m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoQuadraticRel(targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), m_pathSegRole)); +} + +void SVGPathSegListBuilder::curveToQuadraticSmooth(const FloatPoint& targetPoint, PathCoordinateMode mode) +{ + ASSERT(m_pathElement); + ASSERT(m_pathSegList); + if (mode == AbsoluteCoordinates) + m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoQuadraticSmoothAbs(targetPoint.x(), targetPoint.y(), m_pathSegRole)); + else + m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoQuadraticSmoothRel(targetPoint.x(), targetPoint.y(), m_pathSegRole)); +} + +void SVGPathSegListBuilder::arcTo(float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag, const FloatPoint& targetPoint, PathCoordinateMode mode) +{ + ASSERT(m_pathElement); + ASSERT(m_pathSegList); + if (mode == AbsoluteCoordinates) + m_pathSegList->append(m_pathElement->createSVGPathSegArcAbs(targetPoint.x(), targetPoint.y(), r1, r2, angle, largeArcFlag, sweepFlag, m_pathSegRole)); + else + m_pathSegList->append(m_pathElement->createSVGPathSegArcRel(targetPoint.x(), targetPoint.y(), r1, r2, angle, largeArcFlag, sweepFlag, m_pathSegRole)); +} + +void SVGPathSegListBuilder::closePath() +{ + ASSERT(m_pathElement); + ASSERT(m_pathSegList); + m_pathSegList->append(m_pathElement->createSVGPathSegClosePath(m_pathSegRole)); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGPathSegListBuilder.h b/Source/WebCore/svg/SVGPathSegListBuilder.h new file mode 100644 index 0000000..8f75b26 --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegListBuilder.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2002, 2003 The Karbon Developers + * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org> + * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org> + * Copyright (C) 2007, 2009 Apple Inc. All rights reserved. + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPathSegListBuilder_h +#define SVGPathSegListBuilder_h + +#if ENABLE(SVG) +#include "FloatPoint.h" +#include "SVGPathConsumer.h" +#include "SVGPathElement.h" +#include "SVGPathSegList.h" + +namespace WebCore { + +class SVGPathSegListBuilder : public SVGPathConsumer { +public: + SVGPathSegListBuilder(); + + void setCurrentSVGPathElement(SVGPathElement* pathElement) { m_pathElement = pathElement; } + void setCurrentSVGPathSegList(SVGPathSegList& pathSegList) { m_pathSegList = &pathSegList; } + void setCurrentSVGPathSegRole(SVGPathSegRole pathSegRole) { m_pathSegRole = pathSegRole; } + +private: + virtual void incrementPathSegmentCount() { } + virtual bool continueConsuming() { return true; } + virtual void cleanup() + { + m_pathElement = 0; + m_pathSegList = 0; + m_pathSegRole = PathSegUndefinedRole; + } + + // Used in UnalteredParisng/NormalizedParsing modes. + virtual void moveTo(const FloatPoint&, bool closed, PathCoordinateMode); + virtual void lineTo(const FloatPoint&, PathCoordinateMode); + virtual void curveToCubic(const FloatPoint&, const FloatPoint&, const FloatPoint&, PathCoordinateMode); + virtual void closePath(); + + // Only used in UnalteredParsing mode. + virtual void lineToHorizontal(float, PathCoordinateMode); + virtual void lineToVertical(float, PathCoordinateMode); + virtual void curveToCubicSmooth(const FloatPoint&, const FloatPoint&, PathCoordinateMode); + virtual void curveToQuadratic(const FloatPoint&, const FloatPoint&, PathCoordinateMode); + virtual void curveToQuadraticSmooth(const FloatPoint&, PathCoordinateMode); + virtual void arcTo(float, float, float, bool largeArcFlag, bool sweepFlag, const FloatPoint&, PathCoordinateMode); + + SVGPathElement* m_pathElement; + SVGPathSegList* m_pathSegList; + SVGPathSegRole m_pathSegRole; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGPathSegListBuilder_h diff --git a/Source/WebCore/svg/SVGPathSegListSource.cpp b/Source/WebCore/svg/SVGPathSegListSource.cpp new file mode 100644 index 0000000..5526cd6 --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegListSource.cpp @@ -0,0 +1,154 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPathSegListSource.h" + +#include "SVGPathSegArc.h" +#include "SVGPathSegCurvetoCubic.h" +#include "SVGPathSegCurvetoCubicSmooth.h" +#include "SVGPathSegCurvetoQuadratic.h" +#include "SVGPathSegLinetoHorizontal.h" +#include "SVGPathSegLinetoVertical.h" + +namespace WebCore { + +SVGPathSegListSource::SVGPathSegListSource(const SVGPathSegList& pathSegList) + : m_pathSegList(pathSegList) +{ + m_itemCurrent = 0; + m_itemEnd = m_pathSegList.size(); +} + +bool SVGPathSegListSource::hasMoreData() const +{ + return m_itemCurrent < m_itemEnd; +} + +bool SVGPathSegListSource::parseSVGSegmentType(SVGPathSegType& pathSegType) +{ + m_segment = m_pathSegList.at(m_itemCurrent); + pathSegType = static_cast<SVGPathSegType>(m_segment->pathSegType()); + ++m_itemCurrent; + return true; +} + +SVGPathSegType SVGPathSegListSource::nextCommand(SVGPathSegType) +{ + m_segment = m_pathSegList.at(m_itemCurrent); + SVGPathSegType pathSegType = static_cast<SVGPathSegType>(m_segment->pathSegType()); + ++m_itemCurrent; + return pathSegType; +} + +bool SVGPathSegListSource::parseMoveToSegment(FloatPoint& targetPoint) +{ + ASSERT(m_segment); + ASSERT(m_segment->pathSegType() == PathSegMoveToAbs || m_segment->pathSegType() == PathSegMoveToRel); + SVGPathSegSingleCoordinate* moveTo = static_cast<SVGPathSegSingleCoordinate*>(m_segment.get()); + targetPoint = FloatPoint(moveTo->x(), moveTo->y()); + return true; +} + +bool SVGPathSegListSource::parseLineToSegment(FloatPoint& targetPoint) +{ + ASSERT(m_segment); + ASSERT(m_segment->pathSegType() == PathSegLineToAbs || m_segment->pathSegType() == PathSegLineToRel); + SVGPathSegSingleCoordinate* lineTo = static_cast<SVGPathSegSingleCoordinate*>(m_segment.get()); + targetPoint = FloatPoint(lineTo->x(), lineTo->y()); + return true; +} + +bool SVGPathSegListSource::parseLineToHorizontalSegment(float& x) +{ + ASSERT(m_segment); + ASSERT(m_segment->pathSegType() == PathSegLineToHorizontalAbs || m_segment->pathSegType() == PathSegLineToHorizontalRel); + SVGPathSegLinetoHorizontal* horizontal = static_cast<SVGPathSegLinetoHorizontal*>(m_segment.get()); + x = horizontal->x(); + return true; +} + +bool SVGPathSegListSource::parseLineToVerticalSegment(float& y) +{ + ASSERT(m_segment); + ASSERT(m_segment->pathSegType() == PathSegLineToVerticalAbs || m_segment->pathSegType() == PathSegLineToVerticalRel); + SVGPathSegLinetoVertical* vertical = static_cast<SVGPathSegLinetoVertical*>(m_segment.get()); + y = vertical->y(); + return true; +} + +bool SVGPathSegListSource::parseCurveToCubicSegment(FloatPoint& point1, FloatPoint& point2, FloatPoint& targetPoint) +{ + ASSERT(m_segment); + ASSERT(m_segment->pathSegType() == PathSegCurveToCubicAbs || m_segment->pathSegType() == PathSegCurveToCubicRel); + SVGPathSegCurvetoCubic* cubic = static_cast<SVGPathSegCurvetoCubic*>(m_segment.get()); + point1 = FloatPoint(cubic->x1(), cubic->y1()); + point2 = FloatPoint(cubic->x2(), cubic->y2()); + targetPoint = FloatPoint(cubic->x(), cubic->y()); + return true; +} + +bool SVGPathSegListSource::parseCurveToCubicSmoothSegment(FloatPoint& point2, FloatPoint& targetPoint) +{ + ASSERT(m_segment); + ASSERT(m_segment->pathSegType() == PathSegCurveToCubicSmoothAbs || m_segment->pathSegType() == PathSegCurveToCubicSmoothRel); + SVGPathSegCurvetoCubicSmooth* cubicSmooth = static_cast<SVGPathSegCurvetoCubicSmooth*>(m_segment.get()); + point2 = FloatPoint(cubicSmooth->x2(), cubicSmooth->y2()); + targetPoint = FloatPoint(cubicSmooth->x(), cubicSmooth->y()); + return true; +} + +bool SVGPathSegListSource::parseCurveToQuadraticSegment(FloatPoint& point1, FloatPoint& targetPoint) +{ + ASSERT(m_segment); + ASSERT(m_segment->pathSegType() == PathSegCurveToQuadraticAbs || m_segment->pathSegType() == PathSegCurveToQuadraticRel); + SVGPathSegCurvetoQuadratic* quadratic = static_cast<SVGPathSegCurvetoQuadratic*>(m_segment.get()); + point1 = FloatPoint(quadratic->x1(), quadratic->y1()); + targetPoint = FloatPoint(quadratic->x(), quadratic->y()); + return true; +} + +bool SVGPathSegListSource::parseCurveToQuadraticSmoothSegment(FloatPoint& targetPoint) +{ + ASSERT(m_segment); + ASSERT(m_segment->pathSegType() == PathSegCurveToQuadraticSmoothAbs || m_segment->pathSegType() == PathSegCurveToQuadraticSmoothRel); + SVGPathSegSingleCoordinate* quadraticSmooth = static_cast<SVGPathSegSingleCoordinate*>(m_segment.get()); + targetPoint = FloatPoint(quadraticSmooth->x(), quadraticSmooth->y()); + return true; +} + +bool SVGPathSegListSource::parseArcToSegment(float& rx, float& ry, float& angle, bool& largeArc, bool& sweep, FloatPoint& targetPoint) +{ + ASSERT(m_segment); + ASSERT(m_segment->pathSegType() == PathSegArcAbs || m_segment->pathSegType() == PathSegArcRel); + SVGPathSegArc* arcTo = static_cast<SVGPathSegArc*>(m_segment.get()); + rx = arcTo->r1(); + ry = arcTo->r2(); + angle = arcTo->angle(); + largeArc = arcTo->largeArcFlag(); + sweep = arcTo->sweepFlag(); + targetPoint = FloatPoint(arcTo->x(), arcTo->y()); + return true; +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGPathSegListSource.h b/Source/WebCore/svg/SVGPathSegListSource.h new file mode 100644 index 0000000..357248f --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegListSource.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPathSegListSource_h +#define SVGPathSegListSource_h + +#if ENABLE(SVG) +#include "FloatPoint.h" +#include "SVGPathSeg.h" +#include "SVGPathSegList.h" +#include "SVGPathSource.h" +#include <wtf/PassOwnPtr.h> +#include <wtf/RefPtr.h> + +namespace WebCore { + +class SVGPathSegListSource : public SVGPathSource { +public: + static PassOwnPtr<SVGPathSegListSource> create(const SVGPathSegList& pathSegList) + { + return adoptPtr(new SVGPathSegListSource(pathSegList)); + } + +private: + SVGPathSegListSource(const SVGPathSegList&); + + virtual bool hasMoreData() const; + virtual bool moveToNextToken() { return true; } + virtual bool parseSVGSegmentType(SVGPathSegType&); + virtual SVGPathSegType nextCommand(SVGPathSegType); + + virtual bool parseMoveToSegment(FloatPoint&); + virtual bool parseLineToSegment(FloatPoint&); + virtual bool parseLineToHorizontalSegment(float&); + virtual bool parseLineToVerticalSegment(float&); + virtual bool parseCurveToCubicSegment(FloatPoint&, FloatPoint&, FloatPoint&); + virtual bool parseCurveToCubicSmoothSegment(FloatPoint&, FloatPoint&); + virtual bool parseCurveToQuadraticSegment(FloatPoint&, FloatPoint&); + virtual bool parseCurveToQuadraticSmoothSegment(FloatPoint&); + virtual bool parseArcToSegment(float&, float&, float&, bool&, bool&, FloatPoint&); + + const SVGPathSegList& m_pathSegList; + RefPtr<SVGPathSeg> m_segment; + int m_itemCurrent; + int m_itemEnd; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGPathSegListSource_h diff --git a/Source/WebCore/svg/SVGPathSegMoveto.h b/Source/WebCore/svg/SVGPathSegMoveto.h new file mode 100644 index 0000000..87fcd7d --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegMoveto.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2008 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPathSegMoveto_h +#define SVGPathSegMoveto_h + +#if ENABLE(SVG) +#include "SVGPathSegWithContext.h" + +namespace WebCore { + +class SVGPathSegMovetoAbs : public SVGPathSegSingleCoordinate { +public: + static PassRefPtr<SVGPathSegMovetoAbs> create(SVGPathElement* element, SVGPathSegRole role, float x, float y) + { + return adoptRef(new SVGPathSegMovetoAbs(element, role, x, y)); + } + +private: + SVGPathSegMovetoAbs(SVGPathElement* element, SVGPathSegRole role, float x, float y) + : SVGPathSegSingleCoordinate(element, role, x, y) + { + } + + virtual unsigned short pathSegType() const { return PATHSEG_MOVETO_ABS; } + virtual String pathSegTypeAsLetter() const { return "M"; } +}; + +class SVGPathSegMovetoRel : public SVGPathSegSingleCoordinate { +public: + static PassRefPtr<SVGPathSegMovetoRel> create(SVGPathElement* element, SVGPathSegRole role, float x, float y) + { + return adoptRef(new SVGPathSegMovetoRel(element, role, x, y)); + } + +private: + SVGPathSegMovetoRel(SVGPathElement* element, SVGPathSegRole role, float x, float y) + : SVGPathSegSingleCoordinate(element, role, x, y) + { + } + + virtual unsigned short pathSegType() const { return PATHSEG_MOVETO_REL; } + virtual String pathSegTypeAsLetter() const { return "m"; } +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGPathSegMovetoAbs.idl b/Source/WebCore/svg/SVGPathSegMovetoAbs.idl new file mode 100644 index 0000000..bf371a2 --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegMovetoAbs.idl @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2006 Apple Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * + * 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGPathSegMovetoAbs : SVGPathSeg { + attribute [StrictTypeChecking] float x; + attribute [StrictTypeChecking] float y; + }; + +} diff --git a/Source/WebCore/svg/SVGPathSegMovetoRel.idl b/Source/WebCore/svg/SVGPathSegMovetoRel.idl new file mode 100644 index 0000000..a8763a1 --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegMovetoRel.idl @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2006 Apple Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * + * 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGPathSegMovetoRel : SVGPathSeg { + attribute [StrictTypeChecking] float x; + attribute [StrictTypeChecking] float y; + }; + +} diff --git a/Source/WebCore/svg/SVGPathSegWithContext.h b/Source/WebCore/svg/SVGPathSegWithContext.h new file mode 100644 index 0000000..97d8df1 --- /dev/null +++ b/Source/WebCore/svg/SVGPathSegWithContext.h @@ -0,0 +1,109 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPathSegWithContext_h +#define SVGPathSegWithContext_h + +#if ENABLE(SVG) +#include "SVGPathElement.h" + +namespace WebCore { + +class SVGPathSegWithContext : public SVGPathSeg { +public: + SVGPathSegWithContext(SVGPathElement* element, SVGPathSegRole role) + : m_role(role) + , m_element(element) + { + } + + SVGAnimatedProperty* animatedProperty() const + { + switch (m_role) { + case PathSegUndefinedRole: + return 0; + case PathSegUnalteredRole: + return m_element->animatablePathSegList(); + case PathSegNormalizedRole: + // FIXME: https://bugs.webkit.org/show_bug.cgi?id=15412 - Implement normalized path segment lists! + return 0; + }; + + return 0; + } + + SVGPathElement* contextElement() const { return m_element.get(); } + SVGPathSegRole role() const { return m_role; } + + void setContextAndRole(SVGPathElement* element, SVGPathSegRole role) + { + m_role = role; + m_element = element; + } + +protected: + void commitChange() + { + if (!m_element) { + ASSERT(m_role == PathSegUndefinedRole); + return; + } + + ASSERT(m_role != PathSegUndefinedRole); + m_element->pathSegListChanged(m_role); + } + +private: + SVGPathSegRole m_role; + RefPtr<SVGPathElement> m_element; +}; + +class SVGPathSegSingleCoordinate : public SVGPathSegWithContext { +public: + float x() const { return m_x; } + void setX(float x) + { + m_x = x; + commitChange(); + } + + float y() const { return m_y; } + void setY(float y) + { + m_y = y; + commitChange(); + } + +protected: + SVGPathSegSingleCoordinate(SVGPathElement* element, SVGPathSegRole role, float x, float y) + : SVGPathSegWithContext(element, role) + , m_x(x) + , m_y(y) + { + } + +private: + float m_x; + float m_y; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGPathSource.h b/Source/WebCore/svg/SVGPathSource.h new file mode 100644 index 0000000..d1a6149 --- /dev/null +++ b/Source/WebCore/svg/SVGPathSource.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPathSource_h +#define SVGPathSource_h + +#if ENABLE(SVG) +#include "SVGPathSeg.h" + +namespace WebCore { + +class SVGPathSource : public Noncopyable { +public: + virtual ~SVGPathSource() { } + + virtual bool hasMoreData() const = 0; + virtual bool moveToNextToken() = 0; + virtual bool parseSVGSegmentType(SVGPathSegType&) = 0; + virtual SVGPathSegType nextCommand(SVGPathSegType previousCommand) = 0; + + virtual bool parseMoveToSegment(FloatPoint&) = 0; + virtual bool parseLineToSegment(FloatPoint&) = 0; + virtual bool parseLineToHorizontalSegment(float&) = 0; + virtual bool parseLineToVerticalSegment(float&) = 0; + virtual bool parseCurveToCubicSegment(FloatPoint&, FloatPoint&, FloatPoint&) = 0; + virtual bool parseCurveToCubicSmoothSegment(FloatPoint&, FloatPoint&) = 0; + virtual bool parseCurveToQuadraticSegment(FloatPoint&, FloatPoint&) = 0; + virtual bool parseCurveToQuadraticSmoothSegment(FloatPoint&) = 0; + virtual bool parseArcToSegment(float&, float&, float&, bool&, bool&, FloatPoint&) = 0; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGPathSource_h diff --git a/Source/WebCore/svg/SVGPathStringBuilder.cpp b/Source/WebCore/svg/SVGPathStringBuilder.cpp new file mode 100644 index 0000000..e5f4419 --- /dev/null +++ b/Source/WebCore/svg/SVGPathStringBuilder.cpp @@ -0,0 +1,117 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPathStringBuilder.h" + +namespace WebCore { + +String SVGPathStringBuilder::result() +{ + unsigned size = m_stringBuilder.length(); + if (!size) + return String(); + + // Remove trailing space. + m_stringBuilder.resize(size - 1); + return m_stringBuilder.toString(); +} + +void SVGPathStringBuilder::moveTo(const FloatPoint& targetPoint, bool, PathCoordinateMode mode) +{ + if (mode == AbsoluteCoordinates) + m_stringBuilder.append(String::format("M %.6lg %.6lg ", targetPoint.x(), targetPoint.y())); + else + m_stringBuilder.append(String::format("m %.6lg %.6lg ", targetPoint.x(), targetPoint.y())); +} + +void SVGPathStringBuilder::lineTo(const FloatPoint& targetPoint, PathCoordinateMode mode) +{ + if (mode == AbsoluteCoordinates) + m_stringBuilder.append(String::format("L %.6lg %.6lg ", targetPoint.x(), targetPoint.y())); + else + m_stringBuilder.append(String::format("l %.6lg %.6lg ", targetPoint.x(), targetPoint.y())); +} + +void SVGPathStringBuilder::lineToHorizontal(float x, PathCoordinateMode mode) +{ + if (mode == AbsoluteCoordinates) + m_stringBuilder.append(String::format("H %.6lg ", x)); + else + m_stringBuilder.append(String::format("h %.6lg ", x)); +} + +void SVGPathStringBuilder::lineToVertical(float y, PathCoordinateMode mode) +{ + if (mode == AbsoluteCoordinates) + m_stringBuilder.append(String::format("V %.6lg ", y)); + else + m_stringBuilder.append(String::format("v %.6lg ", y)); +} + +void SVGPathStringBuilder::curveToCubic(const FloatPoint& point1, const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode) +{ + if (mode == AbsoluteCoordinates) + m_stringBuilder.append(String::format("C %.6lg %.6lg %.6lg %.6lg %.6lg %.6lg ", point1.x(), point1.y(), point2.x(), point2.y(), targetPoint.x(), targetPoint.y())); + else + m_stringBuilder.append(String::format("c %.6lg %.6lg %.6lg %.6lg %.6lg %.6lg ", point1.x(), point1.y(), point2.x(), point2.y(), targetPoint.x(), targetPoint.y())); +} + +void SVGPathStringBuilder::curveToCubicSmooth(const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode) +{ + if (mode == AbsoluteCoordinates) + m_stringBuilder.append(String::format("S %.6lg %.6lg %.6lg %.6lg ", point2.x(), point2.y(), targetPoint.x(), targetPoint.y())); + else + m_stringBuilder.append(String::format("s %.6lg %.6lg %.6lg %.6lg ", point2.x(), point2.y(), targetPoint.x(), targetPoint.y())); +} + +void SVGPathStringBuilder::curveToQuadratic(const FloatPoint& point1, const FloatPoint& targetPoint, PathCoordinateMode mode) +{ + if (mode == AbsoluteCoordinates) + m_stringBuilder.append(String::format("Q %.6lg %.6lg %.6lg %.6lg ", point1.x(), point1.y(), targetPoint.x(), targetPoint.y())); + else + m_stringBuilder.append(String::format("q %.6lg %.6lg %.6lg %.6lg ", point1.x(), point1.y(), targetPoint.x(), targetPoint.y())); +} + +void SVGPathStringBuilder::curveToQuadraticSmooth(const FloatPoint& targetPoint, PathCoordinateMode mode) +{ + if (mode == AbsoluteCoordinates) + m_stringBuilder.append(String::format("T %.6lg %.6lg ", targetPoint.x(), targetPoint.y())); + else + m_stringBuilder.append(String::format("t %.6lg %.6lg ", targetPoint.x(), targetPoint.y())); +} + +void SVGPathStringBuilder::arcTo(float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag, const FloatPoint& targetPoint, PathCoordinateMode mode) +{ + if (mode == AbsoluteCoordinates) + m_stringBuilder.append(String::format("A %.6lg %.6lg %.6lg %d %d %.6lg %.6lg ", r1, r2, angle, largeArcFlag, sweepFlag, targetPoint.x(), targetPoint.y())); + else + m_stringBuilder.append(String::format("a %.6lg %.6lg %.6lg %d %d %.6lg %.6lg ", r1, r2, angle, largeArcFlag, sweepFlag, targetPoint.x(), targetPoint.y())); +} + +void SVGPathStringBuilder::closePath() +{ + m_stringBuilder.append("Z "); +} + +} // namespace WebCore + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGPathStringBuilder.h b/Source/WebCore/svg/SVGPathStringBuilder.h new file mode 100644 index 0000000..6a7e980 --- /dev/null +++ b/Source/WebCore/svg/SVGPathStringBuilder.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPathStringBuilder_h +#define SVGPathStringBuilder_h + +#if ENABLE(SVG) +#include "FloatPoint.h" +#include "SVGPathConsumer.h" +#include <wtf/text/StringBuilder.h> + +namespace WebCore { + +class SVGPathStringBuilder : public SVGPathConsumer { +public: + String result(); + +private: + virtual void cleanup() { m_stringBuilder = StringBuilder(); } + virtual void incrementPathSegmentCount() { } + virtual bool continueConsuming() { return true; } + + // Used in UnalteredParsing/NormalizedParsing modes. + virtual void moveTo(const FloatPoint&, bool closed, PathCoordinateMode); + virtual void lineTo(const FloatPoint&, PathCoordinateMode); + virtual void curveToCubic(const FloatPoint&, const FloatPoint&, const FloatPoint&, PathCoordinateMode); + virtual void closePath(); + + // Only used in UnalteredParsing mode. + virtual void lineToHorizontal(float, PathCoordinateMode); + virtual void lineToVertical(float, PathCoordinateMode); + virtual void curveToCubicSmooth(const FloatPoint&, const FloatPoint&, PathCoordinateMode); + virtual void curveToQuadratic(const FloatPoint&, const FloatPoint&, PathCoordinateMode); + virtual void curveToQuadraticSmooth(const FloatPoint&, PathCoordinateMode); + virtual void arcTo(float, float, float, bool largeArcFlag, bool sweepFlag, const FloatPoint&, PathCoordinateMode); + + StringBuilder m_stringBuilder; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGPathStringBuilder_h diff --git a/Source/WebCore/svg/SVGPathStringSource.cpp b/Source/WebCore/svg/SVGPathStringSource.cpp new file mode 100644 index 0000000..5154ee6 --- /dev/null +++ b/Source/WebCore/svg/SVGPathStringSource.cpp @@ -0,0 +1,243 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPathStringSource.h" + +#include "SVGParserUtilities.h" + +namespace WebCore { + +SVGPathStringSource::SVGPathStringSource(const String& string) + : m_string(string) + , m_current(string.characters()) + , m_end(m_current + string.length()) +{ + ASSERT(!string.isEmpty()); +} + +bool SVGPathStringSource::hasMoreData() const +{ + return m_current < m_end; +} + +bool SVGPathStringSource::moveToNextToken() +{ + return skipOptionalSpaces(m_current, m_end); +} + +bool SVGPathStringSource::parseSVGSegmentType(SVGPathSegType& pathSegType) +{ + switch (*(m_current++)) { + case 'Z': + case 'z': + pathSegType = PathSegClosePath; + break; + case 'M': + pathSegType = PathSegMoveToAbs; + break; + case 'm': + pathSegType = PathSegMoveToRel; + break; + case 'L': + pathSegType = PathSegLineToAbs; + break; + case 'l': + pathSegType = PathSegLineToRel; + break; + case 'C': + pathSegType = PathSegCurveToCubicAbs; + break; + case 'c': + pathSegType = PathSegCurveToCubicRel; + break; + case 'Q': + pathSegType = PathSegCurveToQuadraticAbs; + break; + case 'q': + pathSegType = PathSegCurveToQuadraticRel; + break; + case 'A': + pathSegType = PathSegArcAbs; + break; + case 'a': + pathSegType = PathSegArcRel; + break; + case 'H': + pathSegType = PathSegLineToHorizontalAbs; + break; + case 'h': + pathSegType = PathSegLineToHorizontalRel; + break; + case 'V': + pathSegType = PathSegLineToVerticalAbs; + break; + case 'v': + pathSegType = PathSegLineToVerticalRel; + break; + case 'S': + pathSegType = PathSegCurveToCubicSmoothAbs; + break; + case 's': + pathSegType = PathSegCurveToCubicSmoothRel; + break; + case 'T': + pathSegType = PathSegCurveToQuadraticSmoothAbs; + break; + case 't': + pathSegType = PathSegCurveToQuadraticSmoothRel; + break; + default: + pathSegType = PathSegUnknown; + } + return true; +} + +SVGPathSegType SVGPathStringSource::nextCommand(SVGPathSegType previousCommand) +{ + // Check for remaining coordinates in the current command. + if ((*m_current == '+' || *m_current == '-' || *m_current == '.' || (*m_current >= '0' && *m_current <= '9')) + && previousCommand != PathSegClosePath) { + if (previousCommand == PathSegMoveToAbs) + return PathSegLineToAbs; + if (previousCommand == PathSegMoveToRel) + return PathSegLineToRel; + return previousCommand; + } + SVGPathSegType nextCommand; + parseSVGSegmentType(nextCommand); + return nextCommand; +} + +bool SVGPathStringSource::parseMoveToSegment(FloatPoint& targetPoint) +{ + float toX; + float toY; + if (!parseNumber(m_current, m_end, toX) || !parseNumber(m_current, m_end, toY)) + return false; + targetPoint = FloatPoint(toX, toY); + return true; +} + +bool SVGPathStringSource::parseLineToSegment(FloatPoint& targetPoint) +{ + float toX; + float toY; + if (!parseNumber(m_current, m_end, toX) || !parseNumber(m_current, m_end, toY)) + return false; + targetPoint = FloatPoint(toX, toY); + return true; +} + +bool SVGPathStringSource::parseLineToHorizontalSegment(float& x) +{ + return parseNumber(m_current, m_end, x); +} + +bool SVGPathStringSource::parseLineToVerticalSegment(float& y) +{ + return parseNumber(m_current, m_end, y); +} + +bool SVGPathStringSource::parseCurveToCubicSegment(FloatPoint& point1, FloatPoint& point2, FloatPoint& targetPoint) +{ + float x1; + float y1; + float x2; + float y2; + float toX; + float toY; + if (!parseNumber(m_current, m_end, x1) + || !parseNumber(m_current, m_end, y1) + || !parseNumber(m_current, m_end, x2) + || !parseNumber(m_current, m_end, y2) + || !parseNumber(m_current, m_end, toX) + || !parseNumber(m_current, m_end, toY)) + return false; + point1 = FloatPoint(x1, y1); + point2 = FloatPoint(x2, y2); + targetPoint = FloatPoint(toX, toY); + return true; +} + +bool SVGPathStringSource::parseCurveToCubicSmoothSegment(FloatPoint& point1, FloatPoint& targetPoint) +{ + float x1; + float y1; + float toX; + float toY; + if (!parseNumber(m_current, m_end, x1) + || !parseNumber(m_current, m_end, y1) + || !parseNumber(m_current, m_end, toX) + || !parseNumber(m_current, m_end, toY)) + return false; + point1 = FloatPoint(x1, y1); + targetPoint = FloatPoint(toX, toY); + return true; +} + +bool SVGPathStringSource::parseCurveToQuadraticSegment(FloatPoint& point2, FloatPoint& targetPoint) +{ + float x2; + float y2; + float toX; + float toY; + if (!parseNumber(m_current, m_end, x2) + || !parseNumber(m_current, m_end, y2) + || !parseNumber(m_current, m_end, toX) + || !parseNumber(m_current, m_end, toY)) + return false; + point2 = FloatPoint(x2, y2); + targetPoint = FloatPoint(toX, toY); + return true; +} + +bool SVGPathStringSource::parseCurveToQuadraticSmoothSegment(FloatPoint& targetPoint) +{ + float toX; + float toY; + if (!parseNumber(m_current, m_end, toX) + || !parseNumber(m_current, m_end, toY)) + return false; + targetPoint = FloatPoint(toX, toY); + return true; +} + +bool SVGPathStringSource::parseArcToSegment(float& rx, float& ry, float& angle, bool& largeArc, bool& sweep, FloatPoint& targetPoint) +{ + float toX; + float toY; + if (!parseNumber(m_current, m_end, rx) + || !parseNumber(m_current, m_end, ry) + || !parseNumber(m_current, m_end, angle) + || !parseArcFlag(m_current, m_end, largeArc) + || !parseArcFlag(m_current, m_end, sweep) + || !parseNumber(m_current, m_end, toX) + || !parseNumber(m_current, m_end, toY)) + return false; + targetPoint = FloatPoint(toX, toY); + return true; +} + + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGPathStringSource.h b/Source/WebCore/svg/SVGPathStringSource.h new file mode 100644 index 0000000..a3c8a95 --- /dev/null +++ b/Source/WebCore/svg/SVGPathStringSource.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPathStringSource_h +#define SVGPathStringSource_h + +#if ENABLE(SVG) +#include "FloatPoint.h" +#include "PlatformString.h" +#include "SVGPathSource.h" +#include <wtf/PassOwnPtr.h> + +namespace WebCore { + +class SVGPathStringSource : public SVGPathSource { +public: + static PassOwnPtr<SVGPathStringSource> create(const String& string) + { + return adoptPtr(new SVGPathStringSource(string)); + } + +private: + SVGPathStringSource(const String&); + + virtual bool hasMoreData() const; + virtual bool moveToNextToken(); + virtual bool parseSVGSegmentType(SVGPathSegType&); + virtual SVGPathSegType nextCommand(SVGPathSegType previousCommand); + + virtual bool parseMoveToSegment(FloatPoint&); + virtual bool parseLineToSegment(FloatPoint&); + virtual bool parseLineToHorizontalSegment(float&); + virtual bool parseLineToVerticalSegment(float&); + virtual bool parseCurveToCubicSegment(FloatPoint&, FloatPoint&, FloatPoint&); + virtual bool parseCurveToCubicSmoothSegment(FloatPoint&, FloatPoint&); + virtual bool parseCurveToQuadraticSegment(FloatPoint&, FloatPoint&); + virtual bool parseCurveToQuadraticSmoothSegment(FloatPoint&); + virtual bool parseArcToSegment(float&, float&, float&, bool&, bool&, FloatPoint&); + + String m_string; + + const UChar* m_current; + const UChar* m_end; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGPathStringSource_h diff --git a/Source/WebCore/svg/SVGPathTraversalStateBuilder.cpp b/Source/WebCore/svg/SVGPathTraversalStateBuilder.cpp new file mode 100644 index 0000000..a4ef2fb --- /dev/null +++ b/Source/WebCore/svg/SVGPathTraversalStateBuilder.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPathTraversalStateBuilder.h" + +namespace WebCore { + +SVGPathTraversalStateBuilder::SVGPathTraversalStateBuilder() + : m_traversalState(0) + , m_desiredLength(0) +{ +} + +void SVGPathTraversalStateBuilder::moveTo(const FloatPoint& targetPoint, bool, PathCoordinateMode) +{ + ASSERT(m_traversalState); + m_traversalState->m_totalLength += m_traversalState->moveTo(targetPoint); +} + +void SVGPathTraversalStateBuilder::lineTo(const FloatPoint& targetPoint, PathCoordinateMode) +{ + ASSERT(m_traversalState); + m_traversalState->m_totalLength += m_traversalState->lineTo(targetPoint); +} + +void SVGPathTraversalStateBuilder::curveToCubic(const FloatPoint& point1, const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode) +{ + ASSERT(m_traversalState); + m_traversalState->m_totalLength += m_traversalState->cubicBezierTo(point1, point2, targetPoint); +} + +void SVGPathTraversalStateBuilder::closePath() +{ + ASSERT(m_traversalState); + m_traversalState->m_totalLength += m_traversalState->closeSubpath(); +} + +void SVGPathTraversalStateBuilder::setDesiredLength(float desiredLength) +{ + ASSERT(m_traversalState); + m_traversalState->m_desiredLength = desiredLength; +} + +bool SVGPathTraversalStateBuilder::continueConsuming() +{ + ASSERT(m_traversalState); + ASSERT(m_traversalState->m_action == PathTraversalState::TraversalSegmentAtLength); + return m_traversalState->m_totalLength < m_traversalState->m_desiredLength; +} + +void SVGPathTraversalStateBuilder::incrementPathSegmentCount() +{ + ASSERT(m_traversalState); + ++m_traversalState->m_segmentIndex; +} + +unsigned long SVGPathTraversalStateBuilder::pathSegmentIndex() +{ + ASSERT(m_traversalState); + return m_traversalState->m_segmentIndex; +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGPathTraversalStateBuilder.h b/Source/WebCore/svg/SVGPathTraversalStateBuilder.h new file mode 100644 index 0000000..a5f3f79 --- /dev/null +++ b/Source/WebCore/svg/SVGPathTraversalStateBuilder.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPathTraversalStateBuilder_h +#define SVGPathTraversalStateBuilder_h + +#if ENABLE(SVG) +#include "FloatPoint.h" +#include "PathTraversalState.h" +#include "SVGPathConsumer.h" + +namespace WebCore { + +class SVGPathTraversalStateBuilder : public SVGPathConsumer { +public: + SVGPathTraversalStateBuilder(); + + unsigned long pathSegmentIndex(); + void setCurrentTraversalState(PathTraversalState* traversalState) { m_traversalState = traversalState; } + void setDesiredLength(float); + virtual void incrementPathSegmentCount(); + virtual bool continueConsuming(); + virtual void cleanup() { m_traversalState = 0; } + +private: + // Used in UnalteredParisng/NormalizedParsing modes. + virtual void moveTo(const FloatPoint&, bool closed, PathCoordinateMode); + virtual void lineTo(const FloatPoint&, PathCoordinateMode); + virtual void curveToCubic(const FloatPoint&, const FloatPoint&, const FloatPoint&, PathCoordinateMode); + virtual void closePath(); + +private: + // Not used for PathTraversalState. + virtual void lineToHorizontal(float, PathCoordinateMode) { ASSERT_NOT_REACHED(); } + virtual void lineToVertical(float, PathCoordinateMode) { ASSERT_NOT_REACHED(); } + virtual void curveToCubicSmooth(const FloatPoint&, const FloatPoint&, PathCoordinateMode) { ASSERT_NOT_REACHED(); } + virtual void curveToQuadratic(const FloatPoint&, const FloatPoint&, PathCoordinateMode) { ASSERT_NOT_REACHED(); } + virtual void curveToQuadraticSmooth(const FloatPoint&, PathCoordinateMode) { ASSERT_NOT_REACHED(); } + virtual void arcTo(float, float, float, bool, bool, const FloatPoint&, PathCoordinateMode) { ASSERT_NOT_REACHED(); } + + PathTraversalState* m_traversalState; + float m_desiredLength; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGPathTraversalStateBuilder_h diff --git a/Source/WebCore/svg/SVGPatternElement.cpp b/Source/WebCore/svg/SVGPatternElement.cpp new file mode 100644 index 0000000..29723e7 --- /dev/null +++ b/Source/WebCore/svg/SVGPatternElement.cpp @@ -0,0 +1,273 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPatternElement.h" + +#include "AffineTransform.h" +#include "Attribute.h" +#include "Document.h" +#include "FloatConversion.h" +#include "GraphicsContext.h" +#include "ImageBuffer.h" +#include "PatternAttributes.h" +#include "RenderSVGContainer.h" +#include "RenderSVGResourcePattern.h" +#include "SVGNames.h" +#include "SVGRenderSupport.h" +#include "SVGSVGElement.h" +#include "SVGStyledTransformableElement.h" +#include "SVGTransformable.h" +#include "SVGUnitTypes.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_LENGTH(SVGPatternElement, SVGNames::xAttr, X, x) +DEFINE_ANIMATED_LENGTH(SVGPatternElement, SVGNames::yAttr, Y, y) +DEFINE_ANIMATED_LENGTH(SVGPatternElement, SVGNames::widthAttr, Width, width) +DEFINE_ANIMATED_LENGTH(SVGPatternElement, SVGNames::heightAttr, Height, height) +DEFINE_ANIMATED_ENUMERATION(SVGPatternElement, SVGNames::patternUnitsAttr, PatternUnits, patternUnits) +DEFINE_ANIMATED_ENUMERATION(SVGPatternElement, SVGNames::patternContentUnitsAttr, PatternContentUnits, patternContentUnits) +DEFINE_ANIMATED_TRANSFORM_LIST(SVGPatternElement, SVGNames::patternTransformAttr, PatternTransform, patternTransform) +DEFINE_ANIMATED_STRING(SVGPatternElement, XLinkNames::hrefAttr, Href, href) +DEFINE_ANIMATED_BOOLEAN(SVGPatternElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) +DEFINE_ANIMATED_RECT(SVGPatternElement, SVGNames::viewBoxAttr, ViewBox, viewBox) +DEFINE_ANIMATED_PRESERVEASPECTRATIO(SVGPatternElement, SVGNames::preserveAspectRatioAttr, PreserveAspectRatio, preserveAspectRatio) + +inline SVGPatternElement::SVGPatternElement(const QualifiedName& tagName, Document* document) + : SVGStyledElement(tagName, document) + , m_x(LengthModeWidth) + , m_y(LengthModeHeight) + , m_width(LengthModeWidth) + , m_height(LengthModeHeight) + , m_patternUnits(SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) + , m_patternContentUnits(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE) +{ +} + +PassRefPtr<SVGPatternElement> SVGPatternElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGPatternElement(tagName, document)); +} + +void SVGPatternElement::parseMappedAttribute(Attribute* attr) +{ + if (attr->name() == SVGNames::patternUnitsAttr) { + if (attr->value() == "userSpaceOnUse") + setPatternUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE); + else if (attr->value() == "objectBoundingBox") + setPatternUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX); + } else if (attr->name() == SVGNames::patternContentUnitsAttr) { + if (attr->value() == "userSpaceOnUse") + setPatternContentUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE); + else if (attr->value() == "objectBoundingBox") + setPatternContentUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX); + } else if (attr->name() == SVGNames::patternTransformAttr) { + SVGTransformList newList; + if (!SVGTransformable::parseTransformAttribute(newList, attr->value())) + newList.clear(); + + detachAnimatedPatternTransformListWrappers(newList.size()); + setPatternTransformBaseValue(newList); + } else if (attr->name() == SVGNames::xAttr) + setXBaseValue(SVGLength(LengthModeWidth, attr->value())); + else if (attr->name() == SVGNames::yAttr) + setYBaseValue(SVGLength(LengthModeHeight, attr->value())); + else if (attr->name() == SVGNames::widthAttr) { + setWidthBaseValue(SVGLength(LengthModeWidth, attr->value())); + if (widthBaseValue().value(this) < 0.0) + document()->accessSVGExtensions()->reportError("A negative value for pattern attribute <width> is not allowed"); + } else if (attr->name() == SVGNames::heightAttr) { + setHeightBaseValue(SVGLength(LengthModeHeight, attr->value())); + if (heightBaseValue().value(this) < 0.0) + document()->accessSVGExtensions()->reportError("A negative value for pattern attribute <height> is not allowed"); + } else { + if (SVGURIReference::parseMappedAttribute(attr)) + return; + if (SVGTests::parseMappedAttribute(attr)) + return; + if (SVGLangSpace::parseMappedAttribute(attr)) + return; + if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) + return; + if (SVGFitToViewBox::parseMappedAttribute(document(), attr)) + return; + + SVGStyledElement::parseMappedAttribute(attr); + } +} + +void SVGPatternElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGStyledElement::svgAttributeChanged(attrName); + + bool invalidateClients = false; + if (attrName == SVGNames::xAttr + || attrName == SVGNames::yAttr + || attrName == SVGNames::widthAttr + || attrName == SVGNames::heightAttr) { + invalidateClients = true; + updateRelativeLengthsInformation(); + } + + RenderObject* object = renderer(); + if (!object) + return; + + if (invalidateClients + || attrName == SVGNames::patternUnitsAttr + || attrName == SVGNames::patternContentUnitsAttr + || attrName == SVGNames::patternTransformAttr + || SVGURIReference::isKnownAttribute(attrName) + || SVGTests::isKnownAttribute(attrName) + || SVGLangSpace::isKnownAttribute(attrName) + || SVGExternalResourcesRequired::isKnownAttribute(attrName) + || SVGFitToViewBox::isKnownAttribute(attrName) + || SVGStyledElement::isKnownAttribute(attrName)) + object->setNeedsLayout(true); +} + +void SVGPatternElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGStyledElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizePatternUnits(); + synchronizePatternContentUnits(); + synchronizePatternTransform(); + synchronizeX(); + synchronizeY(); + synchronizeWidth(); + synchronizeHeight(); + synchronizeExternalResourcesRequired(); + synchronizeViewBox(); + synchronizePreserveAspectRatio(); + synchronizeHref(); + SVGTests::synchronizeProperties(this, attrName); + return; + } + + if (attrName == SVGNames::patternUnitsAttr) + synchronizePatternUnits(); + else if (attrName == SVGNames::patternContentUnitsAttr) + synchronizePatternContentUnits(); + else if (attrName == SVGNames::patternTransformAttr) + synchronizePatternTransform(); + else if (attrName == SVGNames::xAttr) + synchronizeX(); + else if (attrName == SVGNames::yAttr) + synchronizeY(); + else if (attrName == SVGNames::widthAttr) + synchronizeWidth(); + else if (attrName == SVGNames::heightAttr) + synchronizeHeight(); + else if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) + synchronizeExternalResourcesRequired(); + else if (attrName == SVGNames::viewBoxAttr) + synchronizeViewBox(); + else if (attrName == SVGNames::preserveAspectRatioAttr) + synchronizePreserveAspectRatio(); + else if (SVGURIReference::isKnownAttribute(attrName)) + synchronizeHref(); + else if (SVGTests::isKnownAttribute(attrName)) + SVGTests::synchronizeProperties(this, attrName); +} + +void SVGPatternElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) +{ + SVGStyledElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); + + if (changedByParser) + return; + + if (RenderObject* object = renderer()) + object->setNeedsLayout(true); +} + +RenderObject* SVGPatternElement::createRenderer(RenderArena* arena, RenderStyle*) +{ + return new (arena) RenderSVGResourcePattern(this); +} + +void SVGPatternElement::collectPatternAttributes(PatternAttributes& attributes) const +{ + HashSet<const SVGPatternElement*> processedPatterns; + + const SVGPatternElement* current = this; + while (current) { + if (!attributes.hasX() && current->hasAttribute(SVGNames::xAttr)) + attributes.setX(current->x()); + + if (!attributes.hasY() && current->hasAttribute(SVGNames::yAttr)) + attributes.setY(current->y()); + + if (!attributes.hasWidth() && current->hasAttribute(SVGNames::widthAttr)) + attributes.setWidth(current->width()); + + if (!attributes.hasHeight() && current->hasAttribute(SVGNames::heightAttr)) + attributes.setHeight(current->height()); + + if (!attributes.hasBoundingBoxMode() && current->hasAttribute(SVGNames::patternUnitsAttr)) + attributes.setBoundingBoxMode(current->patternUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX); + + if (!attributes.hasBoundingBoxModeContent() && current->hasAttribute(SVGNames::patternContentUnitsAttr)) + attributes.setBoundingBoxModeContent(current->patternContentUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX); + + if (!attributes.hasPatternTransform() && current->hasAttribute(SVGNames::patternTransformAttr)) { + AffineTransform transform; + current->patternTransform().concatenate(transform); + attributes.setPatternTransform(transform); + } + + if (!attributes.hasPatternContentElement() && current->hasChildNodes()) + attributes.setPatternContentElement(current); + + processedPatterns.add(current); + + // Respect xlink:href, take attributes from referenced element + Node* refNode = ownerDocument()->getElementById(SVGURIReference::getTarget(current->href())); + if (refNode && refNode->hasTagName(SVGNames::patternTag)) { + current = static_cast<const SVGPatternElement*>(const_cast<const Node*>(refNode)); + + // Cycle detection + if (processedPatterns.contains(current)) { + current = 0; + break; + } + } else + current = 0; + } +} + +bool SVGPatternElement::selfHasRelativeLengths() const +{ + return x().isRelative() + || y().isRelative() + || width().isRelative() + || height().isRelative(); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGPatternElement.h b/Source/WebCore/svg/SVGPatternElement.h new file mode 100644 index 0000000..e581308 --- /dev/null +++ b/Source/WebCore/svg/SVGPatternElement.h @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPatternElement_h +#define SVGPatternElement_h + +#if ENABLE(SVG) +#include "SVGAnimatedBoolean.h" +#include "SVGAnimatedEnumeration.h" +#include "SVGAnimatedLength.h" +#include "SVGAnimatedPreserveAspectRatio.h" +#include "SVGAnimatedRect.h" +#include "SVGAnimatedTransformList.h" +#include "SVGExternalResourcesRequired.h" +#include "SVGFitToViewBox.h" +#include "SVGLangSpace.h" +#include "SVGStyledElement.h" +#include "SVGTests.h" +#include "SVGURIReference.h" + +namespace WebCore { + +struct PatternAttributes; + +class SVGPatternElement : public SVGStyledElement, + public SVGURIReference, + public SVGTests, + public SVGLangSpace, + public SVGExternalResourcesRequired, + public SVGFitToViewBox { +public: + static PassRefPtr<SVGPatternElement> create(const QualifiedName&, Document*); + + void collectPatternAttributes(PatternAttributes&) const; + +private: + SVGPatternElement(const QualifiedName&, Document*); + + virtual bool isValid() const { return SVGTests::isValid(); } + virtual bool needsPendingResourceHandling() const { return false; } + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); + + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + + virtual bool selfHasRelativeLengths() const; + + // Animated property declarations + DECLARE_ANIMATED_LENGTH(X, x) + DECLARE_ANIMATED_LENGTH(Y, y) + DECLARE_ANIMATED_LENGTH(Width, width) + DECLARE_ANIMATED_LENGTH(Height, height) + DECLARE_ANIMATED_ENUMERATION(PatternUnits, patternUnits) + DECLARE_ANIMATED_ENUMERATION(PatternContentUnits, patternContentUnits) + DECLARE_ANIMATED_TRANSFORM_LIST(PatternTransform, patternTransform) + + // SVGURIReference + DECLARE_ANIMATED_STRING(Href, href) + + // SVGExternalResourcesRequired + DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) + + // SVGPatternElement + DECLARE_ANIMATED_RECT(ViewBox, viewBox) + DECLARE_ANIMATED_PRESERVEASPECTRATIO(PreserveAspectRatio, preserveAspectRatio) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGPatternElement.idl b/Source/WebCore/svg/SVGPatternElement.idl new file mode 100644 index 0000000..59d6f8c --- /dev/null +++ b/Source/WebCore/svg/SVGPatternElement.idl @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGPatternElement : SVGElement, + SVGURIReference, + SVGTests, + SVGLangSpace, + SVGExternalResourcesRequired, + SVGStylable, + SVGFitToViewBox + /* SVGUnitTypes */ { + readonly attribute SVGAnimatedEnumeration patternUnits; + readonly attribute SVGAnimatedEnumeration patternContentUnits; + readonly attribute SVGAnimatedTransformList patternTransform; + readonly attribute SVGAnimatedLength x; + readonly attribute SVGAnimatedLength y; + readonly attribute SVGAnimatedLength width; + readonly attribute SVGAnimatedLength height; + }; + +} diff --git a/Source/WebCore/svg/SVGPoint.idl b/Source/WebCore/svg/SVGPoint.idl new file mode 100644 index 0000000..f6d2514 --- /dev/null +++ b/Source/WebCore/svg/SVGPoint.idl @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) 2006 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +module svg { + + interface [Conditional=SVG] SVGPoint { + attribute [StrictTypeChecking] float x; + attribute [StrictTypeChecking] float y; + + [StrictTypeChecking, RequiresAllArguments=Raise] SVGPoint matrixTransform(in SVGMatrix matrix); + }; + +} diff --git a/Source/WebCore/svg/SVGPointList.cpp b/Source/WebCore/svg/SVGPointList.cpp new file mode 100644 index 0000000..ae460a1 --- /dev/null +++ b/Source/WebCore/svg/SVGPointList.cpp @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPointList.h" + +#include "FloatPoint.h" +#include <wtf/text/StringBuilder.h> +#include <wtf/text/StringConcatenate.h> + +namespace WebCore { + +String SVGPointList::valueAsString() const +{ + StringBuilder builder; + + unsigned size = this->size(); + for (unsigned i = 0; i < size; ++i) { + if (i > 0) + builder.append(" "); // FIXME: Shouldn't we use commas to seperate? + + const FloatPoint& point = at(i); + builder.append(makeString(String::number(point.x()), ' ', String::number(point.y()))); + } + + return builder.toString(); +} + +float inline adjustAnimatedValue(float from, float to, float progress) +{ + return (to - from) * progress + from; +} + +bool SVGPointList::createAnimated(const SVGPointList& fromList, const SVGPointList& toList, SVGPointList& resultList, float progress) +{ + unsigned itemCount = fromList.size(); + if (!itemCount || itemCount != toList.size()) + return false; + for (unsigned n = 0; n < itemCount; ++n) { + const FloatPoint& from = fromList.at(n); + const FloatPoint& to = toList.at(n); + FloatPoint segment = FloatPoint(adjustAnimatedValue(from.x(), to.x(), progress), + adjustAnimatedValue(from.y(), to.y(), progress)); + resultList.append(segment); + } + return true; +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGPointList.h b/Source/WebCore/svg/SVGPointList.h new file mode 100644 index 0000000..4918936 --- /dev/null +++ b/Source/WebCore/svg/SVGPointList.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPointList_h +#define SVGPointList_h + +#if ENABLE(SVG) +#include "QualifiedName.h" +#include "SVGPropertyTraits.h" +#include <wtf/Vector.h> + +namespace WebCore { + +class FloatPoint; + +class SVGPointList : public Vector<FloatPoint> { +public: + SVGPointList() { } + + String valueAsString() const; + + static bool createAnimated(const SVGPointList& fromList, const SVGPointList& toList, SVGPointList& resultList, float progress); +}; + +template<> +struct SVGPropertyTraits<SVGPointList> { + static SVGPointList initialValue() { return SVGPointList(); } + typedef FloatPoint ListItemType; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGPointList.idl b/Source/WebCore/svg/SVGPointList.idl new file mode 100644 index 0000000..080d114 --- /dev/null +++ b/Source/WebCore/svg/SVGPointList.idl @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGPointList { + readonly attribute unsigned long numberOfItems; + + void clear() + raises(DOMException); + [StrictTypeChecking, RequiresAllArguments=Raise] SVGPoint initialize(in SVGPoint item) + raises(DOMException, SVGException); + [StrictTypeChecking, RequiresAllArguments=Raise] SVGPoint getItem(in unsigned long index) + raises(DOMException); + [StrictTypeChecking, RequiresAllArguments=Raise] SVGPoint insertItemBefore(in SVGPoint item, in unsigned long index) + raises(DOMException, SVGException); + [StrictTypeChecking, RequiresAllArguments=Raise] SVGPoint replaceItem(in SVGPoint item, in unsigned long index) + raises(DOMException, SVGException); + [StrictTypeChecking, RequiresAllArguments=Raise] SVGPoint removeItem(in unsigned long index) + raises(DOMException); + [StrictTypeChecking, RequiresAllArguments=Raise] SVGPoint appendItem(in SVGPoint item) + raises(DOMException, SVGException); + }; + +} diff --git a/Source/WebCore/svg/SVGPolyElement.cpp b/Source/WebCore/svg/SVGPolyElement.cpp new file mode 100644 index 0000000..0fb48d7 --- /dev/null +++ b/Source/WebCore/svg/SVGPolyElement.cpp @@ -0,0 +1,147 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPolyElement.h" + +#include "Attribute.h" +#include "Document.h" +#include "FloatPoint.h" +#include "RenderSVGPath.h" +#include "RenderSVGResource.h" +#include "SVGNames.h" +#include "SVGParserUtilities.h" +#include "SVGPointList.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_BOOLEAN(SVGPolyElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) + +SVGPolyElement::SVGPolyElement(const QualifiedName& tagName, Document* document) + : SVGStyledTransformableElement(tagName, document) +{ +} + +void SVGPolyElement::parseMappedAttribute(Attribute* attr) +{ + const AtomicString& value = attr->value(); + if (attr->name() == SVGNames::pointsAttr) { + SVGPointList newList; + if (!pointsListFromSVGData(newList, value)) + document()->accessSVGExtensions()->reportError("Problem parsing points=\"" + value + "\""); + + if (SVGAnimatedListPropertyTearOff<SVGPointList>* list = m_animatablePointsList.get()) + list->detachListWrappers(newList.size()); + + m_points.value = newList; + } else { + if (SVGTests::parseMappedAttribute(attr)) + return; + if (SVGLangSpace::parseMappedAttribute(attr)) + return; + if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) + return; + SVGStyledTransformableElement::parseMappedAttribute(attr); + } +} + +void SVGPolyElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGStyledTransformableElement::svgAttributeChanged(attrName); + + if (SVGTests::handleAttributeChange(this, attrName)) + return; + + RenderSVGPath* renderer = static_cast<RenderSVGPath*>(this->renderer()); + if (!renderer) + return; + + if (SVGStyledTransformableElement::isKnownAttribute(attrName)) { + renderer->setNeedsTransformUpdate(); + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); + return; + } + + if (attrName == SVGNames::pointsAttr) { + renderer->setNeedsPathUpdate(); + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); + return; + } + + if (SVGLangSpace::isKnownAttribute(attrName) + || SVGExternalResourcesRequired::isKnownAttribute(attrName)) + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); +} + +void SVGPolyElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGStyledTransformableElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeExternalResourcesRequired(); + synchronizePoints(); + SVGTests::synchronizeProperties(this, attrName); + return; + } + + if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) + synchronizeExternalResourcesRequired(); + else if (attrName == SVGNames::pointsAttr) + synchronizePoints(); + else if (SVGTests::isKnownAttribute(attrName)) + SVGTests::synchronizeProperties(this, attrName); +} + +void SVGPolyElement::synchronizePoints() +{ + if (!m_points.shouldSynchronize) + return; + + SVGAnimatedPropertySynchronizer<true>::synchronize(this, SVGNames::pointsAttr, m_points.value.valueAsString()); +} + +SVGListPropertyTearOff<SVGPointList>* SVGPolyElement::points() +{ + if (!m_animatablePointsList) { + m_points.shouldSynchronize = true; + m_animatablePointsList = SVGAnimatedProperty::lookupOrCreateWrapper<SVGAnimatedListPropertyTearOff<SVGPointList> , SVGPointList> + (this, SVGNames::pointsAttr, SVGNames::pointsAttr.localName(), m_points.value); + } + + return static_cast<SVGListPropertyTearOff<SVGPointList>*>(m_animatablePointsList->baseVal()); +} + +SVGListPropertyTearOff<SVGPointList>* SVGPolyElement::animatedPoints() +{ + if (!m_animatablePointsList) { + m_points.shouldSynchronize = true; + m_animatablePointsList = SVGAnimatedProperty::lookupOrCreateWrapper<SVGAnimatedListPropertyTearOff<SVGPointList> , SVGPointList> + (this, SVGNames::pointsAttr, SVGNames::pointsAttr.localName(), m_points.value); + } + + return static_cast<SVGListPropertyTearOff<SVGPointList>*>(m_animatablePointsList->animVal()); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGPolyElement.h b/Source/WebCore/svg/SVGPolyElement.h new file mode 100644 index 0000000..3af8a79 --- /dev/null +++ b/Source/WebCore/svg/SVGPolyElement.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPolyElement_h +#define SVGPolyElement_h + +#if ENABLE(SVG) +#include "SVGAnimatedBoolean.h" +#include "SVGExternalResourcesRequired.h" +#include "SVGLangSpace.h" +#include "SVGPointList.h" +#include "SVGStyledTransformableElement.h" +#include "SVGTests.h" + +namespace WebCore { + +class SVGPolyElement : public SVGStyledTransformableElement + , public SVGTests + , public SVGLangSpace + , public SVGExternalResourcesRequired { +public: + SVGListPropertyTearOff<SVGPointList>* points(); + SVGListPropertyTearOff<SVGPointList>* animatedPoints(); + + SVGPointList& pointList() const { return m_points.value; } + +protected: + SVGPolyElement(const QualifiedName&, Document*); + +private: + virtual bool isValid() const { return SVGTests::isValid(); } + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + + virtual bool supportsMarkers() const { return true; } + + // SVGExternalResourcesRequired + DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) + + void synchronizePoints(); + +protected: + mutable SVGSynchronizableAnimatedProperty<SVGPointList> m_points; + RefPtr<SVGAnimatedListPropertyTearOff<SVGPointList> > m_animatablePointsList; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGPolygonElement.cpp b/Source/WebCore/svg/SVGPolygonElement.cpp new file mode 100644 index 0000000..f0bca35 --- /dev/null +++ b/Source/WebCore/svg/SVGPolygonElement.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPolygonElement.h" + +#include "Path.h" + +namespace WebCore { + +inline SVGPolygonElement::SVGPolygonElement(const QualifiedName& tagName, Document* document) + : SVGPolyElement(tagName, document) +{ +} + +PassRefPtr<SVGPolygonElement> SVGPolygonElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGPolygonElement(tagName, document)); +} + +void SVGPolygonElement::toPathData(Path& path) const +{ + ASSERT(path.isEmpty()); + + SVGPointList& points = pointList(); + if (points.isEmpty()) + return; + + path.moveTo(points.first()); + + unsigned size = points.size(); + for (unsigned i = 1; i < size; ++i) + path.addLineTo(points.at(i)); + + path.closeSubpath(); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGPolygonElement.h b/Source/WebCore/svg/SVGPolygonElement.h new file mode 100644 index 0000000..5d1bf52 --- /dev/null +++ b/Source/WebCore/svg/SVGPolygonElement.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPolygonElement_h +#define SVGPolygonElement_h + +#if ENABLE(SVG) +#include "SVGPolyElement.h" + +namespace WebCore { + +class SVGPolygonElement : public SVGPolyElement { +public: + static PassRefPtr<SVGPolygonElement> create(const QualifiedName&, Document*); + +private: + SVGPolygonElement(const QualifiedName&, Document*); + + virtual void toPathData(Path&) const; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGPolygonElement.idl b/Source/WebCore/svg/SVGPolygonElement.idl new file mode 100644 index 0000000..b767aaa --- /dev/null +++ b/Source/WebCore/svg/SVGPolygonElement.idl @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGPolygonElement : SVGElement, + SVGTests, + SVGLangSpace, + SVGExternalResourcesRequired, + SVGStylable, + SVGTransformable { + readonly attribute SVGPointList points; + readonly attribute SVGPointList animatedPoints; + }; + +} diff --git a/Source/WebCore/svg/SVGPolylineElement.cpp b/Source/WebCore/svg/SVGPolylineElement.cpp new file mode 100644 index 0000000..e72173b --- /dev/null +++ b/Source/WebCore/svg/SVGPolylineElement.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPolylineElement.h" + +#include "Path.h" + +namespace WebCore { + +inline SVGPolylineElement::SVGPolylineElement(const QualifiedName& tagName, Document* document) + : SVGPolyElement(tagName, document) +{ +} + +PassRefPtr<SVGPolylineElement> SVGPolylineElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGPolylineElement(tagName, document)); +} + +void SVGPolylineElement::toPathData(Path& path) const +{ + ASSERT(path.isEmpty()); + + SVGPointList& points = pointList(); + if (points.isEmpty()) + return; + + path.moveTo(points.first()); + + unsigned size = points.size(); + for (unsigned i = 1; i < size; ++i) + path.addLineTo(points.at(i)); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGPolylineElement.h b/Source/WebCore/svg/SVGPolylineElement.h new file mode 100644 index 0000000..c7cce53 --- /dev/null +++ b/Source/WebCore/svg/SVGPolylineElement.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPolylineElement_h +#define SVGPolylineElement_h + +#if ENABLE(SVG) +#include "SVGPolyElement.h" + +namespace WebCore { + +class SVGPolylineElement : public SVGPolyElement { +public: + static PassRefPtr<SVGPolylineElement> create(const QualifiedName&, Document*); + +private: + SVGPolylineElement(const QualifiedName&, Document*); + + virtual void toPathData(Path&) const; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGPolylineElement.idl b/Source/WebCore/svg/SVGPolylineElement.idl new file mode 100644 index 0000000..b7af89f --- /dev/null +++ b/Source/WebCore/svg/SVGPolylineElement.idl @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGPolylineElement : SVGElement, + SVGTests, + SVGLangSpace, + SVGExternalResourcesRequired, + SVGStylable, + SVGTransformable { + readonly attribute SVGPointList points; + readonly attribute SVGPointList animatedPoints; + }; + +} diff --git a/Source/WebCore/svg/SVGPreserveAspectRatio.cpp b/Source/WebCore/svg/SVGPreserveAspectRatio.cpp new file mode 100644 index 0000000..3f1172d --- /dev/null +++ b/Source/WebCore/svg/SVGPreserveAspectRatio.cpp @@ -0,0 +1,344 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * Copyright (C) 2010 Dirk Schulze <krit@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPreserveAspectRatio.h" + +#include "AffineTransform.h" +#include "FloatRect.h" +#include "SVGParserUtilities.h" +#include <wtf/text/StringConcatenate.h> + +namespace WebCore { + +SVGPreserveAspectRatio::SVGPreserveAspectRatio() + : m_align(SVG_PRESERVEASPECTRATIO_XMIDYMID) + , m_meetOrSlice(SVG_MEETORSLICE_MEET) +{ +} + +void SVGPreserveAspectRatio::setAlign(unsigned short align, ExceptionCode& ec) +{ + if (align == SVG_PRESERVEASPECTRATIO_UNKNOWN || align > SVG_PRESERVEASPECTRATIO_XMAXYMAX) { + ec = NOT_SUPPORTED_ERR; + return; + } + + m_align = static_cast<SVGPreserveAspectRatioType>(align); +} + +void SVGPreserveAspectRatio::setMeetOrSlice(unsigned short meetOrSlice, ExceptionCode& ec) +{ + if (meetOrSlice == SVG_MEETORSLICE_UNKNOWN || meetOrSlice > SVG_MEETORSLICE_SLICE) { + ec = NOT_SUPPORTED_ERR; + return; + } + + m_meetOrSlice = static_cast<SVGMeetOrSliceType>(meetOrSlice); +} + +SVGPreserveAspectRatio SVGPreserveAspectRatio::parsePreserveAspectRatio(const UChar*& currParam, const UChar* end, bool validate, bool& result) +{ + SVGPreserveAspectRatio aspectRatio; + aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_NONE; + aspectRatio.m_meetOrSlice = SVG_MEETORSLICE_MEET; + result = false; + + // FIXME: Rewrite this parser, without gotos! + if (!skipOptionalSpaces(currParam, end)) + goto bailOut; + + if (*currParam == 'd') { + if (!skipString(currParam, end, "defer")) + goto bailOut; + // FIXME: We just ignore the "defer" here. + if (!skipOptionalSpaces(currParam, end)) + goto bailOut; + } + + if (*currParam == 'n') { + if (!skipString(currParam, end, "none")) + goto bailOut; + skipOptionalSpaces(currParam, end); + } else if (*currParam == 'x') { + if ((end - currParam) < 8) + goto bailOut; + if (currParam[1] != 'M' || currParam[4] != 'Y' || currParam[5] != 'M') + goto bailOut; + if (currParam[2] == 'i') { + if (currParam[3] == 'n') { + if (currParam[6] == 'i') { + if (currParam[7] == 'n') + aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_XMINYMIN; + else if (currParam[7] == 'd') + aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_XMINYMID; + else + goto bailOut; + } else if (currParam[6] == 'a' && currParam[7] == 'x') + aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_XMINYMAX; + else + goto bailOut; + } else if (currParam[3] == 'd') { + if (currParam[6] == 'i') { + if (currParam[7] == 'n') + aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_XMIDYMIN; + else if (currParam[7] == 'd') + aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_XMIDYMID; + else + goto bailOut; + } else if (currParam[6] == 'a' && currParam[7] == 'x') + aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_XMIDYMAX; + else + goto bailOut; + } else + goto bailOut; + } else if (currParam[2] == 'a' && currParam[3] == 'x') { + if (currParam[6] == 'i') { + if (currParam[7] == 'n') + aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_XMAXYMIN; + else if (currParam[7] == 'd') + aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_XMAXYMID; + else + goto bailOut; + } else if (currParam[6] == 'a' && currParam[7] == 'x') + aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_XMAXYMAX; + else + goto bailOut; + } else + goto bailOut; + currParam += 8; + skipOptionalSpaces(currParam, end); + } else + goto bailOut; + + if (currParam < end) { + if (*currParam == 'm') { + if (!skipString(currParam, end, "meet")) + goto bailOut; + skipOptionalSpaces(currParam, end); + } else if (*currParam == 's') { + if (!skipString(currParam, end, "slice")) + goto bailOut; + skipOptionalSpaces(currParam, end); + if (aspectRatio.m_align != SVG_PRESERVEASPECTRATIO_NONE) + aspectRatio.m_meetOrSlice = SVG_MEETORSLICE_SLICE; + } + } + + if (end != currParam && validate) { +bailOut: + // FIXME: Should the two values be set to UNKNOWN instead? + aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_NONE; + aspectRatio.m_meetOrSlice = SVG_MEETORSLICE_MEET; + } else + result = true; + + return aspectRatio; +} + +void SVGPreserveAspectRatio::transformRect(FloatRect& destRect, FloatRect& srcRect) +{ + FloatSize imageSize = srcRect.size(); + float origDestWidth = destRect.width(); + float origDestHeight = destRect.height(); + switch (m_meetOrSlice) { + case SVGPreserveAspectRatio::SVG_MEETORSLICE_UNKNOWN: + break; + case SVGPreserveAspectRatio::SVG_MEETORSLICE_MEET: { + float widthToHeightMultiplier = srcRect.height() / srcRect.width(); + if (origDestHeight > origDestWidth * widthToHeightMultiplier) { + destRect.setHeight(origDestWidth * widthToHeightMultiplier); + switch (m_align) { + case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMID: + case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID: + case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID: + destRect.setY(destRect.y() + origDestHeight / 2 - destRect.height() / 2); + break; + case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMAX: + case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX: + case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX: + destRect.setY(destRect.y() + origDestHeight - destRect.height()); + break; + default: + break; + } + } + if (origDestWidth > origDestHeight / widthToHeightMultiplier) { + destRect.setWidth(origDestHeight / widthToHeightMultiplier); + switch (m_align) { + case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMIN: + case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID: + case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX: + destRect.setX(destRect.x() + origDestWidth / 2 - destRect.width() / 2); + break; + case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMIN: + case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID: + case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX: + destRect.setX(destRect.x() + origDestWidth - destRect.width()); + break; + default: + break; + } + } + break; + } + case SVGPreserveAspectRatio::SVG_MEETORSLICE_SLICE: { + float widthToHeightMultiplier = srcRect.height() / srcRect.width(); + // if the destination height is less than the height of the image we'll be drawing + if (origDestHeight < origDestWidth * widthToHeightMultiplier) { + float destToSrcMultiplier = srcRect.width() / destRect.width(); + srcRect.setHeight(destRect.height() * destToSrcMultiplier); + switch (m_align) { + case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMID: + case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID: + case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID: + srcRect.setY(destRect.y() + imageSize.height() / 2 - srcRect.height() / 2); + break; + case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMAX: + case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX: + case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX: + srcRect.setY(destRect.y() + imageSize.height() - srcRect.height()); + break; + default: + break; + } + } + // if the destination width is less than the width of the image we'll be drawing + if (origDestWidth < origDestHeight / widthToHeightMultiplier) { + float destToSrcMultiplier = srcRect.height() / destRect.height(); + srcRect.setWidth(destRect.width() * destToSrcMultiplier); + switch (m_align) { + case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMIN: + case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID: + case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX: + srcRect.setX(destRect.x() + imageSize.width() / 2 - srcRect.width() / 2); + break; + case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMIN: + case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID: + case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX: + srcRect.setX(destRect.x() + imageSize.width() - srcRect.width()); + break; + default: + break; + } + } + break; + } + } +} + +// FIXME: We should use floats here, like everywhere else! +AffineTransform SVGPreserveAspectRatio::getCTM(double logicX, double logicY, double logicWidth, double logicHeight, double physWidth, double physHeight) const +{ + AffineTransform transform; + if (m_align == SVG_PRESERVEASPECTRATIO_UNKNOWN) + return transform; + + double logicalRatio = logicWidth / logicHeight; + double physRatio = physWidth / physHeight; + + if (m_align == SVG_PRESERVEASPECTRATIO_NONE) { + transform.scaleNonUniform(physWidth / logicWidth, physHeight / logicHeight); + transform.translate(-logicX, -logicY); + return transform; + } + + if ((logicalRatio < physRatio && (m_meetOrSlice == SVG_MEETORSLICE_MEET)) || (logicalRatio >= physRatio && (m_meetOrSlice == SVG_MEETORSLICE_SLICE))) { + transform.scaleNonUniform(physHeight / logicHeight, physHeight / logicHeight); + + if (m_align == SVG_PRESERVEASPECTRATIO_XMINYMIN || m_align == SVG_PRESERVEASPECTRATIO_XMINYMID || m_align == SVG_PRESERVEASPECTRATIO_XMINYMAX) + transform.translate(-logicX, -logicY); + else if (m_align == SVG_PRESERVEASPECTRATIO_XMIDYMIN || m_align == SVG_PRESERVEASPECTRATIO_XMIDYMID || m_align == SVG_PRESERVEASPECTRATIO_XMIDYMAX) + transform.translate(-logicX - (logicWidth - physWidth * logicHeight / physHeight) / 2, -logicY); + else + transform.translate(-logicX - (logicWidth - physWidth * logicHeight / physHeight), -logicY); + + return transform; + } + + transform.scaleNonUniform(physWidth / logicWidth, physWidth / logicWidth); + + if (m_align == SVG_PRESERVEASPECTRATIO_XMINYMIN || m_align == SVG_PRESERVEASPECTRATIO_XMIDYMIN || m_align == SVG_PRESERVEASPECTRATIO_XMAXYMIN) + transform.translate(-logicX, -logicY); + else if (m_align == SVG_PRESERVEASPECTRATIO_XMINYMID || m_align == SVG_PRESERVEASPECTRATIO_XMIDYMID || m_align == SVG_PRESERVEASPECTRATIO_XMAXYMID) + transform.translate(-logicX, -logicY - (logicHeight - physHeight * logicWidth / physWidth) / 2); + else + transform.translate(-logicX, -logicY - (logicHeight - physHeight * logicWidth / physWidth)); + + return transform; +} + +String SVGPreserveAspectRatio::valueAsString() const +{ + String alignType; + + switch (m_align) { + case SVG_PRESERVEASPECTRATIO_NONE: + alignType = "none"; + break; + case SVG_PRESERVEASPECTRATIO_XMINYMIN: + alignType = "xMinYMin"; + break; + case SVG_PRESERVEASPECTRATIO_XMIDYMIN: + alignType = "xMidYMin"; + break; + case SVG_PRESERVEASPECTRATIO_XMAXYMIN: + alignType = "xMaxYMin"; + break; + case SVG_PRESERVEASPECTRATIO_XMINYMID: + alignType = "xMinYMid"; + break; + case SVG_PRESERVEASPECTRATIO_XMIDYMID: + alignType = "xMidYMid"; + break; + case SVG_PRESERVEASPECTRATIO_XMAXYMID: + alignType = "xMaxYMid"; + break; + case SVG_PRESERVEASPECTRATIO_XMINYMAX: + alignType = "xMinYMax"; + break; + case SVG_PRESERVEASPECTRATIO_XMIDYMAX: + alignType = "xMidYMax"; + break; + case SVG_PRESERVEASPECTRATIO_XMAXYMAX: + alignType = "xMaxYMax"; + break; + case SVG_PRESERVEASPECTRATIO_UNKNOWN: + alignType = "unknown"; + break; + }; + + switch (m_meetOrSlice) { + default: + case SVG_MEETORSLICE_UNKNOWN: + return alignType; + case SVG_MEETORSLICE_MEET: + return makeString(alignType, " meet"); + case SVG_MEETORSLICE_SLICE: + return makeString(alignType, " slice"); + }; +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGPreserveAspectRatio.h b/Source/WebCore/svg/SVGPreserveAspectRatio.h new file mode 100644 index 0000000..bf00ee4 --- /dev/null +++ b/Source/WebCore/svg/SVGPreserveAspectRatio.h @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPreserveAspectRatio_h +#define SVGPreserveAspectRatio_h + +#if ENABLE(SVG) +#include "ExceptionCode.h" +#include "SVGPropertyTraits.h" + +namespace WebCore { + +class AffineTransform; +class FloatRect; + +class SVGPreserveAspectRatio { +public: + enum SVGPreserveAspectRatioType { + SVG_PRESERVEASPECTRATIO_UNKNOWN = 0, + SVG_PRESERVEASPECTRATIO_NONE = 1, + SVG_PRESERVEASPECTRATIO_XMINYMIN = 2, + SVG_PRESERVEASPECTRATIO_XMIDYMIN = 3, + SVG_PRESERVEASPECTRATIO_XMAXYMIN = 4, + SVG_PRESERVEASPECTRATIO_XMINYMID = 5, + SVG_PRESERVEASPECTRATIO_XMIDYMID = 6, + SVG_PRESERVEASPECTRATIO_XMAXYMID = 7, + SVG_PRESERVEASPECTRATIO_XMINYMAX = 8, + SVG_PRESERVEASPECTRATIO_XMIDYMAX = 9, + SVG_PRESERVEASPECTRATIO_XMAXYMAX = 10 + }; + + enum SVGMeetOrSliceType { + SVG_MEETORSLICE_UNKNOWN = 0, + SVG_MEETORSLICE_MEET = 1, + SVG_MEETORSLICE_SLICE = 2 + }; + + SVGPreserveAspectRatio(); + + void setAlign(unsigned short align, ExceptionCode&); + unsigned short align() const { return m_align; } + + void setMeetOrSlice(unsigned short, ExceptionCode&); + unsigned short meetOrSlice() const { return m_meetOrSlice; } + + void transformRect(FloatRect& destRect, FloatRect& srcRect); + + AffineTransform getCTM(double logicX, double logicY, + double logicWidth, double logicHeight, + double physWidth, double physHeight) const; + + template<class Consumer> + static bool parsePreserveAspectRatio(Consumer* consumer, const String& value, bool validate = true) + { + bool result = false; + const UChar* begin = value.characters(); + const UChar* end = begin + value.length(); + consumer->setPreserveAspectRatioBaseValue(parsePreserveAspectRatio(begin, end, validate, result)); + return result; + } + + // It's recommended to use the method above, only SVGViewSpec needs this parsing method + static SVGPreserveAspectRatio parsePreserveAspectRatio(const UChar*& currParam, const UChar* end, bool validate, bool& result); + + String valueAsString() const; + +private: + SVGPreserveAspectRatioType m_align; + SVGMeetOrSliceType m_meetOrSlice; +}; + +template<> +struct SVGPropertyTraits<SVGPreserveAspectRatio> { + static SVGPreserveAspectRatio initialValue() { return SVGPreserveAspectRatio(); } + static String toString(const SVGPreserveAspectRatio& type) { return type.valueAsString(); } +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGPreserveAspectRatio_h diff --git a/Source/WebCore/svg/SVGPreserveAspectRatio.idl b/Source/WebCore/svg/SVGPreserveAspectRatio.idl new file mode 100644 index 0000000..80696e7 --- /dev/null +++ b/Source/WebCore/svg/SVGPreserveAspectRatio.idl @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGPreserveAspectRatio { + // Alignment Types + const unsigned short SVG_PRESERVEASPECTRATIO_UNKNOWN = 0; + const unsigned short SVG_PRESERVEASPECTRATIO_NONE = 1; + const unsigned short SVG_PRESERVEASPECTRATIO_XMINYMIN = 2; + const unsigned short SVG_PRESERVEASPECTRATIO_XMIDYMIN = 3; + const unsigned short SVG_PRESERVEASPECTRATIO_XMAXYMIN = 4; + const unsigned short SVG_PRESERVEASPECTRATIO_XMINYMID = 5; + const unsigned short SVG_PRESERVEASPECTRATIO_XMIDYMID = 6; + const unsigned short SVG_PRESERVEASPECTRATIO_XMAXYMID = 7; + const unsigned short SVG_PRESERVEASPECTRATIO_XMINYMAX = 8; + const unsigned short SVG_PRESERVEASPECTRATIO_XMIDYMAX = 9; + const unsigned short SVG_PRESERVEASPECTRATIO_XMAXYMAX = 10; + + // Meet-or-slice Types + const unsigned short SVG_MEETORSLICE_UNKNOWN = 0; + const unsigned short SVG_MEETORSLICE_MEET = 1; + const unsigned short SVG_MEETORSLICE_SLICE = 2; + + attribute [StrictTypeChecking] unsigned short align + setter raises(DOMException); + + attribute [StrictTypeChecking] unsigned short meetOrSlice + setter raises(DOMException); + }; + +} diff --git a/Source/WebCore/svg/SVGRadialGradientElement.cpp b/Source/WebCore/svg/SVGRadialGradientElement.cpp new file mode 100644 index 0000000..d525531 --- /dev/null +++ b/Source/WebCore/svg/SVGRadialGradientElement.cpp @@ -0,0 +1,244 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * Copyright (C) 2008 Eric Seidel <eric@webkit.org> + * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGRadialGradientElement.h" + +#include "Attribute.h" +#include "FloatConversion.h" +#include "FloatPoint.h" +#include "RadialGradientAttributes.h" +#include "RenderSVGResourceRadialGradient.h" +#include "SVGNames.h" +#include "SVGStopElement.h" +#include "SVGTransform.h" +#include "SVGTransformList.h" +#include "SVGUnitTypes.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_LENGTH(SVGRadialGradientElement, SVGNames::cxAttr, Cx, cx) +DEFINE_ANIMATED_LENGTH(SVGRadialGradientElement, SVGNames::cyAttr, Cy, cy) +DEFINE_ANIMATED_LENGTH(SVGRadialGradientElement, SVGNames::rAttr, R, r) +DEFINE_ANIMATED_LENGTH(SVGRadialGradientElement, SVGNames::fxAttr, Fx, fx) +DEFINE_ANIMATED_LENGTH(SVGRadialGradientElement, SVGNames::fyAttr, Fy, fy) + +inline SVGRadialGradientElement::SVGRadialGradientElement(const QualifiedName& tagName, Document* document) + : SVGGradientElement(tagName, document) + , m_cx(LengthModeWidth, "50%") + , m_cy(LengthModeHeight, "50%") + , m_r(LengthModeOther, "50%") + , m_fx(LengthModeWidth) + , m_fy(LengthModeHeight) +{ + // Spec: If the cx/cy/r attribute is not specified, the effect is as if a value of "50%" were specified. +} + +PassRefPtr<SVGRadialGradientElement> SVGRadialGradientElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGRadialGradientElement(tagName, document)); +} + +void SVGRadialGradientElement::parseMappedAttribute(Attribute* attr) +{ + if (attr->name() == SVGNames::cxAttr) + setCxBaseValue(SVGLength(LengthModeWidth, attr->value())); + else if (attr->name() == SVGNames::cyAttr) + setCyBaseValue(SVGLength(LengthModeHeight, attr->value())); + else if (attr->name() == SVGNames::rAttr) { + setRBaseValue(SVGLength(LengthModeOther, attr->value())); + if (rBaseValue().value(this) < 0.0) + document()->accessSVGExtensions()->reportError("A negative value for radial gradient radius <r> is not allowed"); + } else if (attr->name() == SVGNames::fxAttr) + setFxBaseValue(SVGLength(LengthModeWidth, attr->value())); + else if (attr->name() == SVGNames::fyAttr) + setFyBaseValue(SVGLength(LengthModeHeight, attr->value())); + else + SVGGradientElement::parseMappedAttribute(attr); +} + +void SVGRadialGradientElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGGradientElement::svgAttributeChanged(attrName); + + if (attrName == SVGNames::cxAttr + || attrName == SVGNames::cyAttr + || attrName == SVGNames::fxAttr + || attrName == SVGNames::fyAttr + || attrName == SVGNames::rAttr) { + updateRelativeLengthsInformation(); + + RenderObject* object = renderer(); + if (!object) + return; + + object->setNeedsLayout(true); + } +} + +void SVGRadialGradientElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGGradientElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeCx(); + synchronizeCy(); + synchronizeFx(); + synchronizeFy(); + synchronizeR(); + return; + } + + if (attrName == SVGNames::cxAttr) + synchronizeCx(); + else if (attrName == SVGNames::cyAttr) + synchronizeCy(); + else if (attrName == SVGNames::fxAttr) + synchronizeFx(); + else if (attrName == SVGNames::fyAttr) + synchronizeFy(); + else if (attrName == SVGNames::rAttr) + synchronizeR(); +} + +RenderObject* SVGRadialGradientElement::createRenderer(RenderArena* arena, RenderStyle*) +{ + return new (arena) RenderSVGResourceRadialGradient(this); +} + +void SVGRadialGradientElement::collectGradientAttributes(RadialGradientAttributes& attributes) +{ + HashSet<SVGGradientElement*> processedGradients; + + bool isRadial = true; + SVGGradientElement* current = this; + + while (current) { + if (!attributes.hasSpreadMethod() && current->hasAttribute(SVGNames::spreadMethodAttr)) + attributes.setSpreadMethod((GradientSpreadMethod) current->spreadMethod()); + + if (!attributes.hasBoundingBoxMode() && current->hasAttribute(SVGNames::gradientUnitsAttr)) + attributes.setBoundingBoxMode(current->gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX); + + if (!attributes.hasGradientTransform() && current->hasAttribute(SVGNames::gradientTransformAttr)) { + AffineTransform transform; + current->gradientTransform().concatenate(transform); + attributes.setGradientTransform(transform); + } + + if (!attributes.hasStops()) { + const Vector<Gradient::ColorStop>& stops(current->buildStops()); + if (!stops.isEmpty()) + attributes.setStops(stops); + } + + if (isRadial) { + SVGRadialGradientElement* radial = static_cast<SVGRadialGradientElement*>(current); + + if (!attributes.hasCx() && current->hasAttribute(SVGNames::cxAttr)) + attributes.setCx(radial->cx()); + + if (!attributes.hasCy() && current->hasAttribute(SVGNames::cyAttr)) + attributes.setCy(radial->cy()); + + if (!attributes.hasR() && current->hasAttribute(SVGNames::rAttr)) + attributes.setR(radial->r()); + + if (!attributes.hasFx() && current->hasAttribute(SVGNames::fxAttr)) + attributes.setFx(radial->fx()); + + if (!attributes.hasFy() && current->hasAttribute(SVGNames::fyAttr)) + attributes.setFy(radial->fy()); + } + + processedGradients.add(current); + + // Respect xlink:href, take attributes from referenced element + Node* refNode = ownerDocument()->getElementById(SVGURIReference::getTarget(current->href())); + if (refNode && (refNode->hasTagName(SVGNames::radialGradientTag) || refNode->hasTagName(SVGNames::linearGradientTag))) { + current = static_cast<SVGGradientElement*>(refNode); + + // Cycle detection + if (processedGradients.contains(current)) { + current = 0; + break; + } + + isRadial = current->hasTagName(SVGNames::radialGradientTag); + } else + current = 0; + } + + // Handle default values for fx/fy + if (!attributes.hasFx()) + attributes.setFx(attributes.cx()); + + if (!attributes.hasFy()) + attributes.setFy(attributes.cy()); +} + +void SVGRadialGradientElement::calculateFocalCenterPointsAndRadius(const RadialGradientAttributes& attributes, FloatPoint& focalPoint, FloatPoint& centerPoint, float& radius) +{ + // Determine gradient focal/center points and radius + if (attributes.boundingBoxMode()) { + focalPoint = FloatPoint(attributes.fx().valueAsPercentage(), attributes.fy().valueAsPercentage()); + centerPoint = FloatPoint(attributes.cx().valueAsPercentage(), attributes.cy().valueAsPercentage()); + radius = attributes.r().valueAsPercentage(); + } else { + focalPoint = FloatPoint(attributes.fx().value(this), attributes.fy().value(this)); + centerPoint = FloatPoint(attributes.cx().value(this), attributes.cy().value(this)); + radius = attributes.r().value(this); + } + + // Eventually adjust focal points, as described below + float deltaX = focalPoint.x() - centerPoint.x(); + float deltaY = focalPoint.y() - centerPoint.y(); + float radiusMax = 0.99f * radius; + + // Spec: If (fx, fy) lies outside the circle defined by (cx, cy) and r, set + // (fx, fy) to the point of intersection of the line through (fx, fy) and the circle. + // We scale the radius by 0.99 to match the behavior of FireFox. + if (sqrt(deltaX * deltaX + deltaY * deltaY) > radiusMax) { + float angle = atan2f(deltaY, deltaX); + + deltaX = cosf(angle) * radiusMax; + deltaY = sinf(angle) * radiusMax; + focalPoint = FloatPoint(deltaX + centerPoint.x(), deltaY + centerPoint.y()); + } +} + +bool SVGRadialGradientElement::selfHasRelativeLengths() const +{ + return cy().isRelative() + || cy().isRelative() + || r().isRelative() + || fx().isRelative() + || fy().isRelative(); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGRadialGradientElement.h b/Source/WebCore/svg/SVGRadialGradientElement.h new file mode 100644 index 0000000..199eaba --- /dev/null +++ b/Source/WebCore/svg/SVGRadialGradientElement.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGRadialGradientElement_h +#define SVGRadialGradientElement_h + +#if ENABLE(SVG) +#include "SVGAnimatedLength.h" +#include "SVGGradientElement.h" + +namespace WebCore { + +struct RadialGradientAttributes; + +class SVGRadialGradientElement : public SVGGradientElement { +public: + static PassRefPtr<SVGRadialGradientElement> create(const QualifiedName&, Document*); + + void collectGradientAttributes(RadialGradientAttributes&); + void calculateFocalCenterPointsAndRadius(const RadialGradientAttributes&, FloatPoint& focalPoint, FloatPoint& centerPoint, float& radius); + +private: + SVGRadialGradientElement(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + + virtual bool selfHasRelativeLengths() const; + + // Animated property declarations + DECLARE_ANIMATED_LENGTH(Cx, cx) + DECLARE_ANIMATED_LENGTH(Cy, cy) + DECLARE_ANIMATED_LENGTH(R, r) + DECLARE_ANIMATED_LENGTH(Fx, fx) + DECLARE_ANIMATED_LENGTH(Fy, fy) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGRadialGradientElement.idl b/Source/WebCore/svg/SVGRadialGradientElement.idl new file mode 100644 index 0000000..a10aa57 --- /dev/null +++ b/Source/WebCore/svg/SVGRadialGradientElement.idl @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGRadialGradientElement : SVGGradientElement { + readonly attribute SVGAnimatedLength cx; + readonly attribute SVGAnimatedLength cy; + readonly attribute SVGAnimatedLength r; + readonly attribute SVGAnimatedLength fx; + readonly attribute SVGAnimatedLength fy; + }; + +} diff --git a/Source/WebCore/svg/SVGRect.h b/Source/WebCore/svg/SVGRect.h new file mode 100644 index 0000000..379a5bf --- /dev/null +++ b/Source/WebCore/svg/SVGRect.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGRect_h +#define SVGRect_h + +#if ENABLE(SVG) +#include "FloatRect.h" +#include "SVGPropertyTraits.h" +#include <wtf/text/StringBuilder.h> + +namespace WebCore { + +template<> +struct SVGPropertyTraits<FloatRect> { + static FloatRect initialValue() { return FloatRect(); } + static String toString(const FloatRect& type) + { + StringBuilder builder; + builder.append(String::number(type.x())); + builder.append(' '); + builder.append(String::number(type.y())); + builder.append(' '); + builder.append(String::number(type.width())); + builder.append(' '); + builder.append(String::number(type.height())); + builder.append(' '); + return builder.toString(); + } +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGRect_h diff --git a/Source/WebCore/svg/SVGRect.idl b/Source/WebCore/svg/SVGRect.idl new file mode 100644 index 0000000..4231ac0 --- /dev/null +++ b/Source/WebCore/svg/SVGRect.idl @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) 2006 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +module svg { + + interface [Conditional=SVG] SVGRect { + attribute [StrictTypeChecking] float x; + attribute [StrictTypeChecking] float y; + attribute [StrictTypeChecking] float width; + attribute [StrictTypeChecking] float height; + }; + +} diff --git a/Source/WebCore/svg/SVGRectElement.cpp b/Source/WebCore/svg/SVGRectElement.cpp new file mode 100644 index 0000000..d5db5b9 --- /dev/null +++ b/Source/WebCore/svg/SVGRectElement.cpp @@ -0,0 +1,209 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGRectElement.h" + +#include "Attribute.h" +#include "RenderSVGPath.h" +#include "RenderSVGResource.h" +#include "SVGLength.h" +#include "SVGNames.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_LENGTH(SVGRectElement, SVGNames::xAttr, X, x) +DEFINE_ANIMATED_LENGTH(SVGRectElement, SVGNames::yAttr, Y, y) +DEFINE_ANIMATED_LENGTH(SVGRectElement, SVGNames::widthAttr, Width, width) +DEFINE_ANIMATED_LENGTH(SVGRectElement, SVGNames::heightAttr, Height, height) +DEFINE_ANIMATED_LENGTH(SVGRectElement, SVGNames::rxAttr, Rx, rx) +DEFINE_ANIMATED_LENGTH(SVGRectElement, SVGNames::ryAttr, Ry, ry) +DEFINE_ANIMATED_BOOLEAN(SVGRectElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) + +inline SVGRectElement::SVGRectElement(const QualifiedName& tagName, Document* document) + : SVGStyledTransformableElement(tagName, document) + , m_x(LengthModeWidth) + , m_y(LengthModeHeight) + , m_width(LengthModeWidth) + , m_height(LengthModeHeight) + , m_rx(LengthModeWidth) + , m_ry(LengthModeHeight) +{ +} + +PassRefPtr<SVGRectElement> SVGRectElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGRectElement(tagName, document)); +} + +void SVGRectElement::parseMappedAttribute(Attribute* attr) +{ + if (attr->name() == SVGNames::xAttr) + setXBaseValue(SVGLength(LengthModeWidth, attr->value())); + else if (attr->name() == SVGNames::yAttr) + setYBaseValue(SVGLength(LengthModeHeight, attr->value())); + else if (attr->name() == SVGNames::rxAttr) { + setRxBaseValue(SVGLength(LengthModeWidth, attr->value())); + if (rxBaseValue().value(this) < 0.0) + document()->accessSVGExtensions()->reportError("A negative value for rect <rx> is not allowed"); + } else if (attr->name() == SVGNames::ryAttr) { + setRyBaseValue(SVGLength(LengthModeHeight, attr->value())); + if (ryBaseValue().value(this) < 0.0) + document()->accessSVGExtensions()->reportError("A negative value for rect <ry> is not allowed"); + } else if (attr->name() == SVGNames::widthAttr) { + setWidthBaseValue(SVGLength(LengthModeWidth, attr->value())); + if (widthBaseValue().value(this) < 0.0) + document()->accessSVGExtensions()->reportError("A negative value for rect <width> is not allowed"); + } else if (attr->name() == SVGNames::heightAttr) { + setHeightBaseValue(SVGLength(LengthModeHeight, attr->value())); + if (heightBaseValue().value(this) < 0.0) + document()->accessSVGExtensions()->reportError("A negative value for rect <height> is not allowed"); + } else { + if (SVGTests::parseMappedAttribute(attr)) + return; + if (SVGLangSpace::parseMappedAttribute(attr)) + return; + if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) + return; + SVGStyledTransformableElement::parseMappedAttribute(attr); + } +} + +void SVGRectElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGStyledTransformableElement::svgAttributeChanged(attrName); + + bool isLengthAttribute = attrName == SVGNames::xAttr + || attrName == SVGNames::yAttr + || attrName == SVGNames::widthAttr + || attrName == SVGNames::heightAttr + || attrName == SVGNames::rxAttr + || attrName == SVGNames::ryAttr; + + if (isLengthAttribute) + updateRelativeLengthsInformation(); + + if (SVGTests::handleAttributeChange(this, attrName)) + return; + + RenderSVGPath* renderer = static_cast<RenderSVGPath*>(this->renderer()); + if (!renderer) + return; + + if (SVGStyledTransformableElement::isKnownAttribute(attrName)) { + renderer->setNeedsTransformUpdate(); + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); + return; + } + + if (isLengthAttribute) { + renderer->setNeedsPathUpdate(); + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); + return; + } + + if (SVGLangSpace::isKnownAttribute(attrName) + || SVGExternalResourcesRequired::isKnownAttribute(attrName)) + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); +} + +void SVGRectElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGStyledTransformableElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeX(); + synchronizeY(); + synchronizeWidth(); + synchronizeHeight(); + synchronizeRx(); + synchronizeRy(); + synchronizeExternalResourcesRequired(); + SVGTests::synchronizeProperties(this, attrName); + return; + } + + if (attrName == SVGNames::xAttr) + synchronizeX(); + else if (attrName == SVGNames::yAttr) + synchronizeY(); + else if (attrName == SVGNames::widthAttr) + synchronizeWidth(); + else if (attrName == SVGNames::heightAttr) + synchronizeHeight(); + else if (attrName == SVGNames::rxAttr) + synchronizeRx(); + else if (attrName == SVGNames::ryAttr) + synchronizeRy(); + else if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) + synchronizeExternalResourcesRequired(); + else if (SVGTests::isKnownAttribute(attrName)) + SVGTests::synchronizeProperties(this, attrName); +} + +void SVGRectElement::toPathData(Path& path) const +{ + ASSERT(path.isEmpty()); + + float widthValue = width().value(this); + if (widthValue <= 0) + return; + + float heightValue = height().value(this); + if (heightValue <= 0) + return; + + float xValue = x().value(this); + float yValue = y().value(this); + + FloatRect rect(xValue, yValue, widthValue, heightValue); + + bool hasRx = hasAttribute(SVGNames::rxAttr); + bool hasRy = hasAttribute(SVGNames::ryAttr); + if (hasRx || hasRy) { + float rxValue = rx().value(this); + float ryValue = ry().value(this); + if (!hasRx) + rxValue = ryValue; + else if (!hasRy) + ryValue = rxValue; + path.addRoundedRect(rect, FloatSize(rxValue, ryValue)); + return; + } + + path.addRect(rect); +} + +bool SVGRectElement::selfHasRelativeLengths() const +{ + return x().isRelative() + || y().isRelative() + || width().isRelative() + || height().isRelative() + || rx().isRelative() + || ry().isRelative(); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGRectElement.h b/Source/WebCore/svg/SVGRectElement.h new file mode 100644 index 0000000..0c30378 --- /dev/null +++ b/Source/WebCore/svg/SVGRectElement.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGRectElement_h +#define SVGRectElement_h + +#if ENABLE(SVG) +#include "SVGAnimatedBoolean.h" +#include "SVGAnimatedLength.h" +#include "SVGExternalResourcesRequired.h" +#include "SVGLangSpace.h" +#include "SVGStyledTransformableElement.h" +#include "SVGTests.h" + +namespace WebCore { + +class SVGRectElement : public SVGStyledTransformableElement, + public SVGTests, + public SVGLangSpace, + public SVGExternalResourcesRequired { +public: + static PassRefPtr<SVGRectElement> create(const QualifiedName&, Document*); + +private: + SVGRectElement(const QualifiedName&, Document*); + + virtual bool isValid() const { return SVGTests::isValid(); } + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + + virtual void toPathData(Path&) const; + + virtual bool selfHasRelativeLengths() const; + + // Animated property declarations + DECLARE_ANIMATED_LENGTH(X, x) + DECLARE_ANIMATED_LENGTH(Y, y) + DECLARE_ANIMATED_LENGTH(Width, width) + DECLARE_ANIMATED_LENGTH(Height, height) + DECLARE_ANIMATED_LENGTH(Rx, rx) + DECLARE_ANIMATED_LENGTH(Ry, ry) + + // SVGExternalResourcesRequired + DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGRectElement.idl b/Source/WebCore/svg/SVGRectElement.idl new file mode 100644 index 0000000..c7f8c7c --- /dev/null +++ b/Source/WebCore/svg/SVGRectElement.idl @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGRectElement : SVGElement, + SVGTests, + SVGLangSpace, + SVGExternalResourcesRequired, + SVGStylable, + SVGTransformable { + readonly attribute SVGAnimatedLength x; + readonly attribute SVGAnimatedLength y; + readonly attribute SVGAnimatedLength width; + readonly attribute SVGAnimatedLength height; + readonly attribute SVGAnimatedLength rx; + readonly attribute SVGAnimatedLength ry; + }; + +} diff --git a/Source/WebCore/svg/SVGRenderingIntent.h b/Source/WebCore/svg/SVGRenderingIntent.h new file mode 100644 index 0000000..230258a --- /dev/null +++ b/Source/WebCore/svg/SVGRenderingIntent.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGRenderingIntent_h +#define SVGRenderingIntent_h + +#if ENABLE(SVG) + +#include <wtf/RefCounted.h> + +namespace WebCore { + +class SVGRenderingIntent : public RefCounted<SVGRenderingIntent> { +public: + enum SVGRenderingIntentType { + RENDERING_INTENT_UNKNOWN = 0, + RENDERING_INTENT_AUTO = 1, + RENDERING_INTENT_PERCEPTUAL = 2, + RENDERING_INTENT_RELATIVE_COLORIMETRIC = 3, + RENDERING_INTENT_SATURATION = 4, + RENDERING_INTENT_ABSOLUTE_COLORIMETRIC = 5 + }; + +private: + SVGRenderingIntent() { } +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGRenderingIntent_h + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGRenderingIntent.idl b/Source/WebCore/svg/SVGRenderingIntent.idl new file mode 100644 index 0000000..47eaccc --- /dev/null +++ b/Source/WebCore/svg/SVGRenderingIntent.idl @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGRenderingIntent { + // Rendering Intent Types + const unsigned short RENDERING_INTENT_UNKNOWN = 0; + const unsigned short RENDERING_INTENT_AUTO = 1; + const unsigned short RENDERING_INTENT_PERCEPTUAL = 2; + const unsigned short RENDERING_INTENT_RELATIVE_COLORIMETRIC = 3; + const unsigned short RENDERING_INTENT_SATURATION = 4; + const unsigned short RENDERING_INTENT_ABSOLUTE_COLORIMETRIC = 5; + }; + +} diff --git a/Source/WebCore/svg/SVGSVGElement.cpp b/Source/WebCore/svg/SVGSVGElement.cpp new file mode 100644 index 0000000..7e04f5d --- /dev/null +++ b/Source/WebCore/svg/SVGSVGElement.cpp @@ -0,0 +1,656 @@ +/* + * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Rob Buis <buis@kde.org> + * Copyright (C) 2007 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGSVGElement.h" + +#include "AffineTransform.h" +#include "Attribute.h" +#include "CSSHelper.h" +#include "CSSPropertyNames.h" +#include "Document.h" +#include "EventListener.h" +#include "EventNames.h" +#include "FloatConversion.h" +#include "FloatRect.h" +#include "FrameView.h" +#include "HTMLNames.h" +#include "RenderSVGResource.h" +#include "RenderSVGRoot.h" +#include "RenderSVGViewportContainer.h" +#include "SMILTimeContainer.h" +#include "SVGAngle.h" +#include "SVGNames.h" +#include "SVGPreserveAspectRatio.h" +#include "SVGTransform.h" +#include "SVGTransformList.h" +#include "SVGViewElement.h" +#include "SVGViewSpec.h" +#include "SVGZoomEvent.h" +#include "ScriptEventListener.h" +#include "SelectionController.h" +#include <wtf/StdLibExtras.h> + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_LENGTH(SVGSVGElement, SVGNames::xAttr, X, x) +DEFINE_ANIMATED_LENGTH(SVGSVGElement, SVGNames::yAttr, Y, y) +DEFINE_ANIMATED_LENGTH(SVGSVGElement, SVGNames::widthAttr, Width, width) +DEFINE_ANIMATED_LENGTH(SVGSVGElement, SVGNames::heightAttr, Height, height) +DEFINE_ANIMATED_BOOLEAN(SVGSVGElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) +DEFINE_ANIMATED_PRESERVEASPECTRATIO(SVGSVGElement, SVGNames::preserveAspectRatioAttr, PreserveAspectRatio, preserveAspectRatio) +DEFINE_ANIMATED_RECT(SVGSVGElement, SVGNames::viewBoxAttr, ViewBox, viewBox) + +inline SVGSVGElement::SVGSVGElement(const QualifiedName& tagName, Document* doc) + : SVGStyledLocatableElement(tagName, doc) + , m_x(LengthModeWidth) + , m_y(LengthModeHeight) + , m_width(LengthModeWidth, "100%") + , m_height(LengthModeHeight, "100%") + , m_useCurrentView(false) + , m_timeContainer(SMILTimeContainer::create(this)) + , m_scale(1) + , m_viewSpec(0) + , m_containerSize(300, 150) + , m_hasSetContainerSize(false) +{ + doc->registerForDocumentActivationCallbacks(this); +} + +PassRefPtr<SVGSVGElement> SVGSVGElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGSVGElement(tagName, document)); +} + +SVGSVGElement::~SVGSVGElement() +{ + document()->unregisterForDocumentActivationCallbacks(this); + // There are cases where removedFromDocument() is not called. + // see ContainerNode::removeAllChildren, called by its destructor. + document()->accessSVGExtensions()->removeTimeContainer(this); +} + +void SVGSVGElement::willMoveToNewOwnerDocument() +{ + document()->unregisterForDocumentActivationCallbacks(this); + SVGStyledLocatableElement::willMoveToNewOwnerDocument(); +} + +void SVGSVGElement::didMoveToNewOwnerDocument() +{ + document()->registerForDocumentActivationCallbacks(this); + SVGStyledLocatableElement::didMoveToNewOwnerDocument(); +} + +const AtomicString& SVGSVGElement::contentScriptType() const +{ + DEFINE_STATIC_LOCAL(const AtomicString, defaultValue, ("text/ecmascript")); + const AtomicString& n = getAttribute(SVGNames::contentScriptTypeAttr); + return n.isNull() ? defaultValue : n; +} + +void SVGSVGElement::setContentScriptType(const AtomicString& type) +{ + setAttribute(SVGNames::contentScriptTypeAttr, type); +} + +const AtomicString& SVGSVGElement::contentStyleType() const +{ + DEFINE_STATIC_LOCAL(const AtomicString, defaultValue, ("text/css")); + const AtomicString& n = getAttribute(SVGNames::contentStyleTypeAttr); + return n.isNull() ? defaultValue : n; +} + +void SVGSVGElement::setContentStyleType(const AtomicString& type) +{ + setAttribute(SVGNames::contentStyleTypeAttr, type); +} + +FloatRect SVGSVGElement::viewport() const +{ + double x = 0; + double y = 0; + if (!isOutermostSVG()) { + x = this->x().value(this); + y = this->y().value(this); + } + float w = width().value(this); + float h = height().value(this); + AffineTransform viewBox = viewBoxToViewTransform(w, h); + double wDouble = w; + double hDouble = h; + viewBox.map(x, y, x, y); + viewBox.map(w, h, wDouble, hDouble); + return FloatRect::narrowPrecision(x, y, wDouble, hDouble); +} + +int SVGSVGElement::relativeWidthValue() const +{ + SVGLength w = width(); + if (w.unitType() != LengthTypePercentage) + return 0; + + return static_cast<int>(w.valueAsPercentage() * m_containerSize.width()); +} + +int SVGSVGElement::relativeHeightValue() const +{ + SVGLength h = height(); + if (h.unitType() != LengthTypePercentage) + return 0; + + return static_cast<int>(h.valueAsPercentage() * m_containerSize.height()); +} + +float SVGSVGElement::pixelUnitToMillimeterX() const +{ + // 2.54 / cssPixelsPerInch gives CM. + return (2.54f / cssPixelsPerInch) * 10.0f; +} + +float SVGSVGElement::pixelUnitToMillimeterY() const +{ + // 2.54 / cssPixelsPerInch gives CM. + return (2.54f / cssPixelsPerInch) * 10.0f; +} + +float SVGSVGElement::screenPixelToMillimeterX() const +{ + return pixelUnitToMillimeterX(); +} + +float SVGSVGElement::screenPixelToMillimeterY() const +{ + return pixelUnitToMillimeterY(); +} + +bool SVGSVGElement::useCurrentView() const +{ + return m_useCurrentView; +} + +void SVGSVGElement::setUseCurrentView(bool currentView) +{ + m_useCurrentView = currentView; +} + +SVGViewSpec* SVGSVGElement::currentView() const +{ + if (!m_viewSpec) + m_viewSpec = adoptPtr(new SVGViewSpec(const_cast<SVGSVGElement*>(this))); + return m_viewSpec.get(); +} + +float SVGSVGElement::currentScale() const +{ + // Only the page zoom factor is relevant for SVG + if (Frame* frame = document()->frame()) + return frame->pageZoomFactor(); + return m_scale; +} + +void SVGSVGElement::setCurrentScale(float scale) +{ + if (Frame* frame = document()->frame()) { + // Calling setCurrentScale() on the outermost <svg> element in a standalone SVG document + // is allowed to change the page zoom factor, influencing the document size, scrollbars etc. + if (parentNode() == document()) + frame->setPageZoomFactor(scale); + return; + } + + m_scale = scale; + if (RenderObject* object = renderer()) + RenderSVGResource::markForLayoutAndParentResourceInvalidation(object); +} + +void SVGSVGElement::setCurrentTranslate(const FloatPoint& translation) +{ + m_translation = translation; + updateCurrentTranslate(); +} + +void SVGSVGElement::updateCurrentTranslate() +{ + if (RenderObject* object = renderer()) + object->setNeedsLayout(true); + + if (parentNode() == document() && document()->renderer()) + document()->renderer()->repaint(); +} + +void SVGSVGElement::parseMappedAttribute(Attribute* attr) +{ + if (!nearestViewportElement()) { + bool setListener = true; + + // Only handle events if we're the outermost <svg> element + if (attr->name() == HTMLNames::onunloadAttr) + document()->setWindowAttributeEventListener(eventNames().unloadEvent, createAttributeEventListener(document()->frame(), attr)); + else if (attr->name() == HTMLNames::onresizeAttr) + document()->setWindowAttributeEventListener(eventNames().resizeEvent, createAttributeEventListener(document()->frame(), attr)); + else if (attr->name() == HTMLNames::onscrollAttr) + document()->setWindowAttributeEventListener(eventNames().scrollEvent, createAttributeEventListener(document()->frame(), attr)); + else if (attr->name() == SVGNames::onzoomAttr) + document()->setWindowAttributeEventListener(eventNames().zoomEvent, createAttributeEventListener(document()->frame(), attr)); + else + setListener = false; + + if (setListener) + return; + } + + if (attr->name() == HTMLNames::onabortAttr) + document()->setWindowAttributeEventListener(eventNames().abortEvent, createAttributeEventListener(document()->frame(), attr)); + else if (attr->name() == HTMLNames::onerrorAttr) + document()->setWindowAttributeEventListener(eventNames().errorEvent, createAttributeEventListener(document()->frame(), attr)); + else if (attr->name() == SVGNames::xAttr) + setXBaseValue(SVGLength(LengthModeWidth, attr->value())); + else if (attr->name() == SVGNames::yAttr) + setYBaseValue(SVGLength(LengthModeHeight, attr->value())); + else if (attr->name() == SVGNames::widthAttr) { + setWidthBaseValue(SVGLength(LengthModeWidth, attr->value())); + addCSSProperty(attr, CSSPropertyWidth, attr->value()); + if (widthBaseValue().value(this) < 0.0) + document()->accessSVGExtensions()->reportError("A negative value for svg attribute <width> is not allowed"); + } else if (attr->name() == SVGNames::heightAttr) { + setHeightBaseValue(SVGLength(LengthModeHeight, attr->value())); + addCSSProperty(attr, CSSPropertyHeight, attr->value()); + if (heightBaseValue().value(this) < 0.0) + document()->accessSVGExtensions()->reportError("A negative value for svg attribute <height> is not allowed"); + } else { + if (SVGTests::parseMappedAttribute(attr)) + return; + if (SVGLangSpace::parseMappedAttribute(attr)) + return; + if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) + return; + if (SVGFitToViewBox::parseMappedAttribute(document(), attr)) + return; + if (SVGZoomAndPan::parseMappedAttribute(attr)) + return; + + SVGStyledLocatableElement::parseMappedAttribute(attr); + } +} + +// This hack will not handle the case where we're setting a width/height +// on a root <svg> via svg.width.baseValue = when it has none. +static void updateCSSForAttribute(SVGSVGElement* element, const QualifiedName& attrName, CSSPropertyID property, const SVGLength& value) +{ + Attribute* attribute = element->attributes(false)->getAttributeItem(attrName); + if (!attribute || !attribute->isMappedAttribute()) + return; + element->addCSSProperty(attribute, property, value.valueAsString()); +} + +void SVGSVGElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGStyledElement::svgAttributeChanged(attrName); + + // FIXME: Ugly, ugly hack to around that parseMappedAttribute is not called + // when svg.width.baseValue = 100 is evaluated. + // Thus the CSS length value for width is not updated, and width() computeLogicalWidth() + // calculations on RenderSVGRoot will be wrong. + // https://bugs.webkit.org/show_bug.cgi?id=25387 + bool updateRelativeLengths = false; + if (attrName == SVGNames::widthAttr) { + updateCSSForAttribute(this, attrName, CSSPropertyWidth, widthBaseValue()); + updateRelativeLengths = true; + } else if (attrName == SVGNames::heightAttr) { + updateCSSForAttribute(this, attrName, CSSPropertyHeight, heightBaseValue()); + updateRelativeLengths = true; + } + + if (updateRelativeLengths + || attrName == SVGNames::xAttr + || attrName == SVGNames::yAttr + || SVGFitToViewBox::isKnownAttribute(attrName)) { + updateRelativeLengths = true; + updateRelativeLengthsInformation(); + } + + if (SVGTests::handleAttributeChange(this, attrName)) + return; + + if (!renderer()) + return; + + if (updateRelativeLengths + || SVGLangSpace::isKnownAttribute(attrName) + || SVGExternalResourcesRequired::isKnownAttribute(attrName) + || SVGZoomAndPan::isKnownAttribute(attrName) + || SVGStyledLocatableElement::isKnownAttribute(attrName)) + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer()); +} + +void SVGSVGElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGStyledElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeX(); + synchronizeY(); + synchronizeWidth(); + synchronizeHeight(); + synchronizeExternalResourcesRequired(); + synchronizeViewBox(); + synchronizePreserveAspectRatio(); + SVGTests::synchronizeProperties(this, attrName); + return; + } + + if (attrName == SVGNames::xAttr) + synchronizeX(); + else if (attrName == SVGNames::yAttr) + synchronizeY(); + else if (attrName == SVGNames::widthAttr) + synchronizeWidth(); + else if (attrName == SVGNames::heightAttr) + synchronizeHeight(); + else if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) + synchronizeExternalResourcesRequired(); + else if (attrName == SVGNames::viewBoxAttr) + synchronizeViewBox(); + else if (attrName == SVGNames::preserveAspectRatioAttr) + synchronizePreserveAspectRatio(); + else if (SVGTests::isKnownAttribute(attrName)) + SVGTests::synchronizeProperties(this, attrName); +} + +unsigned SVGSVGElement::suspendRedraw(unsigned /* maxWaitMilliseconds */) +{ + // FIXME: Implement me (see bug 11275) + return 0; +} + +void SVGSVGElement::unsuspendRedraw(unsigned /* suspendHandleId */) +{ + // FIXME: Implement me (see bug 11275) +} + +void SVGSVGElement::unsuspendRedrawAll() +{ + // FIXME: Implement me (see bug 11275) +} + +void SVGSVGElement::forceRedraw() +{ + // FIXME: Implement me (see bug 11275) +} + +NodeList* SVGSVGElement::getIntersectionList(const FloatRect&, SVGElement*) +{ + // FIXME: Implement me (see bug 11274) + return 0; +} + +NodeList* SVGSVGElement::getEnclosureList(const FloatRect&, SVGElement*) +{ + // FIXME: Implement me (see bug 11274) + return 0; +} + +bool SVGSVGElement::checkIntersection(SVGElement*, const FloatRect& rect) +{ + // TODO : take into account pointer-events? + // FIXME: Why is element ignored?? + // FIXME: Implement me (see bug 11274) + return rect.intersects(getBBox()); +} + +bool SVGSVGElement::checkEnclosure(SVGElement*, const FloatRect& rect) +{ + // TODO : take into account pointer-events? + // FIXME: Why is element ignored?? + // FIXME: Implement me (see bug 11274) + return rect.contains(getBBox()); +} + +void SVGSVGElement::deselectAll() +{ + if (Frame* frame = document()->frame()) + frame->selection()->clear(); +} + +float SVGSVGElement::createSVGNumber() +{ + return 0.0f; +} + +SVGLength SVGSVGElement::createSVGLength() +{ + return SVGLength(); +} + +SVGAngle SVGSVGElement::createSVGAngle() +{ + return SVGAngle(); +} + +FloatPoint SVGSVGElement::createSVGPoint() +{ + return FloatPoint(); +} + +SVGMatrix SVGSVGElement::createSVGMatrix() +{ + return SVGMatrix(); +} + +FloatRect SVGSVGElement::createSVGRect() +{ + return FloatRect(); +} + +SVGTransform SVGSVGElement::createSVGTransform() +{ + return SVGTransform(SVGTransform::SVG_TRANSFORM_MATRIX); +} + +SVGTransform SVGSVGElement::createSVGTransformFromMatrix(const SVGMatrix& matrix) +{ + return SVGTransform(static_cast<const AffineTransform&>(matrix)); +} + +AffineTransform SVGSVGElement::localCoordinateSpaceTransform(SVGLocatable::CTMScope mode) const +{ + AffineTransform viewBoxTransform; + if (attributes()->getAttributeItem(SVGNames::viewBoxAttr)) + viewBoxTransform = viewBoxToViewTransform(width().value(this), height().value(this)); + + AffineTransform transform; + if (!isOutermostSVG()) + transform.translate(x().value(this), y().value(this)); + else if (mode == SVGLocatable::ScreenScope) { + if (RenderObject* renderer = this->renderer()) { + // Translate in our CSS parent coordinate space + // FIXME: This doesn't work correctly with CSS transforms. + FloatPoint location = renderer->localToAbsolute(FloatPoint(), false, true); + + // Be careful here! localToAbsolute() includes the x/y offset coming from the viewBoxToViewTransform(), because + // RenderSVGRoot::localToBorderBoxTransform() (called through mapLocalToContainer(), called from localToAbsolute()) + // also takes the viewBoxToViewTransform() into account, so we have to subtract it here (original cause of bug #27183) + transform.translate(location.x() - viewBoxTransform.e(), location.y() - viewBoxTransform.f()); + + // Respect scroll offset. + if (FrameView* view = document()->view()) { + IntSize scrollOffset = view->scrollOffset(); + transform.translate(-scrollOffset.width(), -scrollOffset.height()); + } + } + } + + return transform.multLeft(viewBoxTransform); +} + +RenderObject* SVGSVGElement::createRenderer(RenderArena* arena, RenderStyle*) +{ + if (isOutermostSVG()) + return new (arena) RenderSVGRoot(this); + + return new (arena) RenderSVGViewportContainer(this); +} + +void SVGSVGElement::insertedIntoDocument() +{ + document()->accessSVGExtensions()->addTimeContainer(this); + SVGStyledLocatableElement::insertedIntoDocument(); +} + +void SVGSVGElement::removedFromDocument() +{ + document()->accessSVGExtensions()->removeTimeContainer(this); + SVGStyledLocatableElement::removedFromDocument(); +} + +void SVGSVGElement::pauseAnimations() +{ + if (!m_timeContainer->isPaused()) + m_timeContainer->pause(); +} + +void SVGSVGElement::unpauseAnimations() +{ + if (m_timeContainer->isPaused()) + m_timeContainer->resume(); +} + +bool SVGSVGElement::animationsPaused() const +{ + return m_timeContainer->isPaused(); +} + +float SVGSVGElement::getCurrentTime() const +{ + return narrowPrecisionToFloat(m_timeContainer->elapsed().value()); +} + +void SVGSVGElement::setCurrentTime(float /* seconds */) +{ + // FIXME: Implement me, bug 12073 +} + +bool SVGSVGElement::selfHasRelativeLengths() const +{ + return x().isRelative() + || y().isRelative() + || width().isRelative() + || height().isRelative() + || hasAttribute(SVGNames::viewBoxAttr); +} + +bool SVGSVGElement::isOutermostSVG() const +{ + // Element may not be in the document, pretend we're outermost for viewport(), getCTM(), etc. + if (!parentNode()) + return true; + +#if ENABLE(SVG_FOREIGN_OBJECT) + // We act like an outermost SVG element, if we're a direct child of a <foreignObject> element. + if (parentNode()->hasTagName(SVGNames::foreignObjectTag)) + return true; +#endif + + // This is true whenever this is the outermost SVG, even if there are HTML elements outside it + return !parentNode()->isSVGElement(); +} + +AffineTransform SVGSVGElement::viewBoxToViewTransform(float viewWidth, float viewHeight) const +{ + FloatRect viewBoxRect; + if (useCurrentView()) { + if (currentView()) // what if we should use it but it is not set? + viewBoxRect = currentView()->viewBox(); + } else + viewBoxRect = viewBox(); + + AffineTransform ctm = SVGFitToViewBox::viewBoxToViewTransform(viewBoxRect, preserveAspectRatio(), viewWidth, viewHeight); + if (useCurrentView() && currentView()) { + AffineTransform transform; + if (!currentView()->transform().concatenate(transform)) + return ctm; + + return transform * ctm; + } + + return ctm; +} + +void SVGSVGElement::inheritViewAttributes(SVGViewElement* viewElement) +{ + setUseCurrentView(true); + if (viewElement->hasAttribute(SVGNames::viewBoxAttr)) + currentView()->setViewBoxBaseValue(viewElement->viewBox()); + else + currentView()->setViewBoxBaseValue(viewBox()); + + SVGPreserveAspectRatio aspectRatio; + if (viewElement->hasAttribute(SVGNames::preserveAspectRatioAttr)) + aspectRatio = viewElement->preserveAspectRatioBaseValue(); + else + aspectRatio = preserveAspectRatioBaseValue(); + currentView()->setPreserveAspectRatioBaseValue(aspectRatio); + + if (viewElement->hasAttribute(SVGNames::zoomAndPanAttr)) + currentView()->setZoomAndPan(viewElement->zoomAndPan()); + + if (RenderObject* object = renderer()) + RenderSVGResource::markForLayoutAndParentResourceInvalidation(object); +} + +void SVGSVGElement::documentWillBecomeInactive() +{ + pauseAnimations(); +} + +void SVGSVGElement::documentDidBecomeActive() +{ + unpauseAnimations(); +} + +// getElementById on SVGSVGElement is restricted to only the child subtree defined by the <svg> element. +// See http://www.w3.org/TR/SVG11/struct.html#InterfaceSVGSVGElement +Element* SVGSVGElement::getElementById(const AtomicString& id) const +{ + Element* element = document()->getElementById(id); + if (element && element->isDescendantOf(this)) + return element; + + // Fall back to traversing our subtree. Duplicate ids are allowed, the first found will + // be returned. + for (Node* node = traverseNextNode(this); node; node = node->traverseNextNode(this)) { + if (!node->isElementNode()) + continue; + + Element* element = static_cast<Element*>(node); + if (element->hasID() && element->getIdAttribute() == id) + return element; + } + return 0; +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGSVGElement.h b/Source/WebCore/svg/SVGSVGElement.h new file mode 100644 index 0000000..0995c67 --- /dev/null +++ b/Source/WebCore/svg/SVGSVGElement.h @@ -0,0 +1,180 @@ +/* + * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007, 2010 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGSVGElement_h +#define SVGSVGElement_h + +#if ENABLE(SVG) +#include "SVGAnimatedBoolean.h" +#include "SVGAnimatedLength.h" +#include "SVGAnimatedPreserveAspectRatio.h" +#include "SVGAnimatedRect.h" +#include "SVGExternalResourcesRequired.h" +#include "SVGFitToViewBox.h" +#include "SVGLangSpace.h" +#include "SVGStyledLocatableElement.h" +#include "SVGTests.h" +#include "SVGZoomAndPan.h" + +namespace WebCore { + +class SVGAngle; +class SVGMatrix; +class SVGTransform; +class SVGViewSpec; +class SVGViewElement; +class SMILTimeContainer; + +class SVGSVGElement : public SVGStyledLocatableElement, + public SVGTests, + public SVGLangSpace, + public SVGExternalResourcesRequired, + public SVGFitToViewBox, + public SVGZoomAndPan { +public: + static PassRefPtr<SVGSVGElement> create(const QualifiedName&, Document*); + + virtual bool isValid() const { return SVGTests::isValid(); } + + // 'SVGSVGElement' functions + const AtomicString& contentScriptType() const; + void setContentScriptType(const AtomicString& type); + + const AtomicString& contentStyleType() const; + void setContentStyleType(const AtomicString& type); + + FloatRect viewport() const; + + void setContainerSize(const IntSize& containerSize) { m_containerSize = containerSize; m_hasSetContainerSize = true; } + IntSize containerSize() const { return m_containerSize; } + bool hasSetContainerSize() const { return m_hasSetContainerSize; } + int relativeWidthValue() const; + int relativeHeightValue() const; + + float pixelUnitToMillimeterX() const; + float pixelUnitToMillimeterY() const; + float screenPixelToMillimeterX() const; + float screenPixelToMillimeterY() const; + + bool useCurrentView() const; + void setUseCurrentView(bool currentView); + + SVGViewSpec* currentView() const; + + float currentScale() const; + void setCurrentScale(float scale); + + FloatPoint& currentTranslate() { return m_translation; } + void setCurrentTranslate(const FloatPoint&); + + // Only used from the bindings. + void updateCurrentTranslate(); + + SMILTimeContainer* timeContainer() const { return m_timeContainer.get(); } + + void pauseAnimations(); + void unpauseAnimations(); + bool animationsPaused() const; + + float getCurrentTime() const; + void setCurrentTime(float seconds); + + unsigned suspendRedraw(unsigned maxWaitMilliseconds); + void unsuspendRedraw(unsigned suspendHandleId); + void unsuspendRedrawAll(); + void forceRedraw(); + + NodeList* getIntersectionList(const FloatRect&, SVGElement* referenceElement); + NodeList* getEnclosureList(const FloatRect&, SVGElement* referenceElement); + bool checkIntersection(SVGElement*, const FloatRect&); + bool checkEnclosure(SVGElement*, const FloatRect&); + void deselectAll(); + + static float createSVGNumber(); + static SVGLength createSVGLength(); + static SVGAngle createSVGAngle(); + static FloatPoint createSVGPoint(); + static SVGMatrix createSVGMatrix(); + static FloatRect createSVGRect(); + static SVGTransform createSVGTransform(); + static SVGTransform createSVGTransformFromMatrix(const SVGMatrix&); + + AffineTransform viewBoxToViewTransform(float viewWidth, float viewHeight) const; + + void inheritViewAttributes(SVGViewElement*); + + bool isOutermostSVG() const; + + Element* getElementById(const AtomicString&) const; + +protected: + virtual void willMoveToNewOwnerDocument(); + virtual void didMoveToNewOwnerDocument(); + +private: + SVGSVGElement(const QualifiedName&, Document*); + virtual ~SVGSVGElement(); + + virtual bool isSVG() const { return true; } + + virtual void parseMappedAttribute(Attribute*); + + virtual bool rendererIsNeeded(RenderStyle* style) { return StyledElement::rendererIsNeeded(style); } + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + + virtual void insertedIntoDocument(); + virtual void removedFromDocument(); + + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + + virtual bool selfHasRelativeLengths() const; + + // Animated property declarations + DECLARE_ANIMATED_LENGTH(X, x) + DECLARE_ANIMATED_LENGTH(Y, y) + DECLARE_ANIMATED_LENGTH(Width, width) + DECLARE_ANIMATED_LENGTH(Height, height) + + // SVGExternalResourcesRequired + DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) + + // SVGFitToViewBox + DECLARE_ANIMATED_RECT(ViewBox, viewBox) + DECLARE_ANIMATED_PRESERVEASPECTRATIO(PreserveAspectRatio, preserveAspectRatio) + + virtual void documentWillBecomeInactive(); + virtual void documentDidBecomeActive(); + + virtual AffineTransform localCoordinateSpaceTransform(SVGLocatable::CTMScope) const; + + bool m_useCurrentView; + RefPtr<SMILTimeContainer> m_timeContainer; + FloatPoint m_translation; + float m_scale; + mutable OwnPtr<SVGViewSpec> m_viewSpec; + IntSize m_containerSize; + bool m_hasSetContainerSize; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGSVGElement.idl b/Source/WebCore/svg/SVGSVGElement.idl new file mode 100644 index 0000000..39912ec --- /dev/null +++ b/Source/WebCore/svg/SVGSVGElement.idl @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2010 Rob Buis <buis@kde.org> + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) 2006 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +module svg { + + // TODO: no css::ViewCSS available! + // TODO: Fix SVGSVGElement inheritance (css::DocumentCSS)! + // TODO: no events::DocumentEvent available! + interface [Conditional=SVG] SVGSVGElement : SVGElement, + SVGTests, + SVGLangSpace, + SVGExternalResourcesRequired, + SVGStylable, + SVGLocatable, + SVGFitToViewBox, + SVGZoomAndPan { + readonly attribute SVGAnimatedLength x; + readonly attribute SVGAnimatedLength y; + readonly attribute SVGAnimatedLength width; + readonly attribute SVGAnimatedLength height; + attribute DOMString contentScriptType + /*setter raises(DOMException)*/; + attribute DOMString contentStyleType + /*setter raises(DOMException)*/; + readonly attribute SVGRect viewport; + readonly attribute float pixelUnitToMillimeterX; + readonly attribute float pixelUnitToMillimeterY; + readonly attribute float screenPixelToMillimeterX; + readonly attribute float screenPixelToMillimeterY; + attribute boolean useCurrentView + /*setter raises(DOMException)*/; + // TODO readonly attribute SVGViewSpec currentView; + attribute float currentScale + /*setter raises(DOMException)*/; + readonly attribute SVGPoint currentTranslate; + + unsigned long suspendRedraw(in unsigned long maxWaitMilliseconds); + void unsuspendRedraw(in unsigned long suspendHandleId); + void unsuspendRedrawAll(); + void forceRedraw(); + void pauseAnimations(); + void unpauseAnimations(); + boolean animationsPaused(); + float getCurrentTime(); + void setCurrentTime(in float seconds); + NodeList getIntersectionList(in SVGRect rect, + in SVGElement referenceElement); + NodeList getEnclosureList(in SVGRect rect, + in SVGElement referenceElement); + boolean checkIntersection(in SVGElement element, + in SVGRect rect); + boolean checkEnclosure(in SVGElement element, + in SVGRect rect); + void deselectAll(); + + SVGNumber createSVGNumber(); + SVGLength createSVGLength(); + SVGAngle createSVGAngle(); + SVGPoint createSVGPoint(); + SVGMatrix createSVGMatrix(); + SVGRect createSVGRect(); + SVGTransform createSVGTransform(); + SVGTransform createSVGTransformFromMatrix(in SVGMatrix matrix); + Element getElementById(in DOMString elementId); + }; + +} diff --git a/Source/WebCore/svg/SVGScriptElement.cpp b/Source/WebCore/svg/SVGScriptElement.cpp new file mode 100644 index 0000000..6452700 --- /dev/null +++ b/Source/WebCore/svg/SVGScriptElement.cpp @@ -0,0 +1,244 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGScriptElement.h" + +#include "Attribute.h" +#include "Document.h" +#include "Event.h" +#include "EventNames.h" +#include "SVGNames.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_STRING(SVGScriptElement, XLinkNames::hrefAttr, Href, href) +DEFINE_ANIMATED_BOOLEAN(SVGScriptElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) + +inline SVGScriptElement::SVGScriptElement(const QualifiedName& tagName, Document* document, bool wasInsertedByParser, bool wasAlreadyStarted) + : SVGElement(tagName, document) + , ScriptElement(this, wasInsertedByParser, wasAlreadyStarted) +{ +} + +PassRefPtr<SVGScriptElement> SVGScriptElement::create(const QualifiedName& tagName, Document* document, bool insertedByParser) +{ + return adoptRef(new SVGScriptElement(tagName, document, insertedByParser, false)); +} + +void SVGScriptElement::parseMappedAttribute(Attribute* attr) +{ + const QualifiedName& attrName = attr->name(); + + if (attrName == SVGNames::typeAttr) + setType(attr->value()); + else { + if (SVGURIReference::parseMappedAttribute(attr)) + return; + if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) + return; + + SVGElement::parseMappedAttribute(attr); + } +} + +void SVGScriptElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGElement::svgAttributeChanged(attrName); + + if (SVGURIReference::isKnownAttribute(attrName)) + handleSourceAttribute(href()); + else if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) { + // Handle dynamic updates of the 'externalResourcesRequired' attribute. Only possible case: changing from 'true' to 'false' + // causes an immediate dispatch of the SVGLoad event. If the attribute value was 'false' before inserting the script element + // in the document, the SVGLoad event has already been dispatched. + if (!externalResourcesRequiredBaseValue() && !haveFiredLoadEvent() && !wasInsertedByParser()) { + setHaveFiredLoadEvent(true); + ASSERT(haveLoadedRequiredResources()); + + sendSVGLoadEventIfPossible(); + } + } +} + +void SVGScriptElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeExternalResourcesRequired(); + synchronizeHref(); + return; + } + + if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) + synchronizeExternalResourcesRequired(); + else if (SVGURIReference::isKnownAttribute(attrName)) + synchronizeHref(); +} + +void SVGScriptElement::insertedIntoDocument() +{ + SVGElement::insertedIntoDocument(); + ScriptElement::insertedIntoDocument(sourceAttributeValue()); + + if (wasInsertedByParser()) + return; + + // Eventually send SVGLoad event now for the dynamically inserted script element + if (!externalResourcesRequiredBaseValue()) { + setHaveFiredLoadEvent(true); + sendSVGLoadEventIfPossible(); + } +} + +void SVGScriptElement::removedFromDocument() +{ + SVGElement::removedFromDocument(); + ScriptElement::removedFromDocument(); +} + +void SVGScriptElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) +{ + ScriptElement::childrenChanged(); + SVGElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); +} + +bool SVGScriptElement::isURLAttribute(Attribute* attr) const +{ + return attr->name() == sourceAttributeValue(); +} + +void SVGScriptElement::finishParsingChildren() +{ + ScriptElement::finishParsingChildren(sourceAttributeValue()); + SVGElement::finishParsingChildren(); + + // A SVGLoad event has been fired by SVGElement::finishParsingChildren. + if (!externalResourcesRequiredBaseValue()) + setHaveFiredLoadEvent(true); +} + +String SVGScriptElement::type() const +{ + return m_type; +} + +void SVGScriptElement::setType(const String& type) +{ + m_type = type; +} + +void SVGScriptElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const +{ + SVGElement::addSubresourceAttributeURLs(urls); + + addSubresourceURL(urls, document()->completeURL(href())); +} + +bool SVGScriptElement::haveLoadedRequiredResources() +{ + return !externalResourcesRequiredBaseValue() || haveFiredLoadEvent(); +} + +String SVGScriptElement::sourceAttributeValue() const +{ + return href(); +} + +String SVGScriptElement::charsetAttributeValue() const +{ + return String(); +} + +String SVGScriptElement::typeAttributeValue() const +{ + return type(); +} + +String SVGScriptElement::languageAttributeValue() const +{ + return String(); +} + +String SVGScriptElement::forAttributeValue() const +{ + return String(); +} + +String SVGScriptElement::eventAttributeValue() const +{ + return String(); +} + +bool SVGScriptElement::asyncAttributeValue() const +{ + return false; +} + +bool SVGScriptElement::deferAttributeValue() const +{ + return false; +} + +void SVGScriptElement::dispatchLoadEvent() +{ + bool externalResourcesRequired = externalResourcesRequiredBaseValue(); + + if (wasInsertedByParser()) + ASSERT(externalResourcesRequired != haveFiredLoadEvent()); + else if (haveFiredLoadEvent()) { + // If we've already fired an load event and externalResourcesRequired is set to 'true' + // externalResourcesRequired has been modified while loading the <script>. Don't dispatch twice. + if (externalResourcesRequired) + return; + } + + // HTML and SVG differ completly in the 'onload' event handling of <script> elements. + // HTML fires the 'load' event after it sucessfully loaded a remote resource, otherwhise an error event. + // SVG fires the SVGLoad event immediately after parsing the <script> element, if externalResourcesRequired + // is set to 'false', otherwhise it dispatches the 'SVGLoad' event just after loading the remote resource. + if (externalResourcesRequired) { + ASSERT(!haveFiredLoadEvent()); + + // Dispatch SVGLoad event + setHaveFiredLoadEvent(true); + ASSERT(haveLoadedRequiredResources()); + + sendSVGLoadEventIfPossible(); + } +} + +void SVGScriptElement::dispatchErrorEvent() +{ + dispatchEvent(Event::create(eventNames().errorEvent, true, false)); +} + +PassRefPtr<Element> SVGScriptElement::cloneElementWithoutAttributesAndChildren() const +{ + return adoptRef(new SVGScriptElement(tagQName(), document(), false, wasAlreadyStarted())); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGScriptElement.h b/Source/WebCore/svg/SVGScriptElement.h new file mode 100644 index 0000000..df502e0 --- /dev/null +++ b/Source/WebCore/svg/SVGScriptElement.h @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGScriptElement_h +#define SVGScriptElement_h + +#if ENABLE(SVG) +#include "SVGAnimatedBoolean.h" +#include "SVGAnimatedString.h" +#include "SVGElement.h" +#include "SVGExternalResourcesRequired.h" +#include "SVGURIReference.h" +#include "ScriptElement.h" + +namespace WebCore { + +class SVGScriptElement : public SVGElement + , public SVGURIReference + , public SVGExternalResourcesRequired + , public ScriptElement { +public: + static PassRefPtr<SVGScriptElement> create(const QualifiedName&, Document*, bool wasInsertedByParser); + + String type() const; + void setType(const String&); + +private: + SVGScriptElement(const QualifiedName&, Document*, bool wasInsertedByParser, bool wasAlreadyStarted); + + virtual void parseMappedAttribute(Attribute*); + virtual void insertedIntoDocument(); + virtual void removedFromDocument(); + virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); + + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + virtual bool isURLAttribute(Attribute*) const; + virtual void finishParsingChildren(); + + virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const; + + virtual bool haveLoadedRequiredResources(); + + virtual String sourceAttributeValue() const; + virtual String charsetAttributeValue() const; + virtual String typeAttributeValue() const; + virtual String languageAttributeValue() const; + virtual String forAttributeValue() const; + virtual String eventAttributeValue() const; + virtual bool asyncAttributeValue() const; + virtual bool deferAttributeValue() const; + + virtual void dispatchLoadEvent(); + virtual void dispatchErrorEvent(); + + PassRefPtr<Element> cloneElementWithoutAttributesAndChildren() const; + + // Animated property declarations + + // SVGURIReference + DECLARE_ANIMATED_STRING(Href, href) + + // SVGExternalResourcesRequired + DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) + + String m_type; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGScriptElement.idl b/Source/WebCore/svg/SVGScriptElement.idl new file mode 100644 index 0000000..2513238 --- /dev/null +++ b/Source/WebCore/svg/SVGScriptElement.idl @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGScriptElement : SVGElement, + SVGURIReference, + SVGExternalResourcesRequired { + attribute [ConvertNullToNullString] DOMString type + /*setter raises(DOMException)*/; + }; + +} diff --git a/Source/WebCore/svg/SVGSetElement.cpp b/Source/WebCore/svg/SVGSetElement.cpp new file mode 100644 index 0000000..d455c9b --- /dev/null +++ b/Source/WebCore/svg/SVGSetElement.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#if ENABLE(SVG_ANIMATION) +#include "SVGSetElement.h" + +namespace WebCore { + +inline SVGSetElement::SVGSetElement(const QualifiedName& tagName, Document* document) + : SVGAnimateElement(tagName, document) +{ +} + +PassRefPtr<SVGSetElement> SVGSetElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGSetElement(tagName, document)); +} + +} + +// vim:ts=4:noet +#endif // ENABLE(SVG_ANIMATION) + diff --git a/Source/WebCore/svg/SVGSetElement.h b/Source/WebCore/svg/SVGSetElement.h new file mode 100644 index 0000000..30218bf --- /dev/null +++ b/Source/WebCore/svg/SVGSetElement.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGSetElement_h +#define SVGSetElement_h +#if ENABLE(SVG_ANIMATION) + +#include "SVGAnimateElement.h" + +namespace WebCore { + +// SVGAnimateElement implements superset of the functionality. +class SVGSetElement : public SVGAnimateElement { +public: + static PassRefPtr<SVGSetElement> create(const QualifiedName&, Document*); + +private: + SVGSetElement(const QualifiedName&, Document*); +}; + +} // namespace WebCore + +#endif // ENABLE(SVG_ANIMATION) +#endif + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGSetElement.idl b/Source/WebCore/svg/SVGSetElement.idl new file mode 100644 index 0000000..6e806e7 --- /dev/null +++ b/Source/WebCore/svg/SVGSetElement.idl @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG_ANIMATION] SVGSetElement : SVGAnimationElement { + }; + +} diff --git a/Source/WebCore/svg/SVGStopElement.cpp b/Source/WebCore/svg/SVGStopElement.cpp new file mode 100644 index 0000000..10bd9ae --- /dev/null +++ b/Source/WebCore/svg/SVGStopElement.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGStopElement.h" + +#include "Attribute.h" +#include "Document.h" +#include "RenderSVGGradientStop.h" +#include "RenderSVGResource.h" +#include "SVGGradientElement.h" +#include "SVGNames.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_NUMBER(SVGStopElement, SVGNames::offsetAttr, Offset, offset) + +inline SVGStopElement::SVGStopElement(const QualifiedName& tagName, Document* document) + : SVGStyledElement(tagName, document) + , m_offset(0) +{ +} + +PassRefPtr<SVGStopElement> SVGStopElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGStopElement(tagName, document)); +} + +void SVGStopElement::parseMappedAttribute(Attribute* attr) +{ + if (attr->name() == SVGNames::offsetAttr) { + const String& value = attr->value(); + if (value.endsWith("%")) + setOffsetBaseValue(value.left(value.length() - 1).toFloat() / 100.0f); + else + setOffsetBaseValue(value.toFloat()); + } else + SVGStyledElement::parseMappedAttribute(attr); +} + +void SVGStopElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGStyledElement::svgAttributeChanged(attrName); + + if (!renderer()) + return; + + if (attrName == SVGNames::offsetAttr) + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer()); +} + +void SVGStopElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGStyledElement::synchronizeProperty(attrName); + + if (attrName == anyQName() || attrName == SVGNames::offsetAttr) + synchronizeOffset(); +} + +RenderObject* SVGStopElement::createRenderer(RenderArena* arena, RenderStyle*) +{ + return new (arena) RenderSVGGradientStop(this); +} + +Color SVGStopElement::stopColorIncludingOpacity() const +{ + ASSERT(renderer()); + ASSERT(renderer()->style()); + + const SVGRenderStyle* svgStyle = renderer()->style()->svgStyle(); + return colorWithOverrideAlpha(svgStyle->stopColor().rgb(), svgStyle->stopOpacity()); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGStopElement.h b/Source/WebCore/svg/SVGStopElement.h new file mode 100644 index 0000000..907afae --- /dev/null +++ b/Source/WebCore/svg/SVGStopElement.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGStopElement_h +#define SVGStopElement_h + +#if ENABLE(SVG) +#include "SVGAnimatedNumber.h" +#include "SVGStyledElement.h" + +namespace WebCore { + +class SVGStopElement : public SVGStyledElement { +public: + static PassRefPtr<SVGStopElement> create(const QualifiedName&, Document*); + + Color stopColorIncludingOpacity() const; + +private: + SVGStopElement(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + + virtual bool isGradientStop() const { return true; } + + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + + // Animated property declarations + DECLARE_ANIMATED_NUMBER(Offset, offset) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGStopElement.idl b/Source/WebCore/svg/SVGStopElement.idl new file mode 100644 index 0000000..248f519 --- /dev/null +++ b/Source/WebCore/svg/SVGStopElement.idl @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGStopElement : SVGElement, + SVGStylable { + readonly attribute SVGAnimatedNumber offset; + }; + +} diff --git a/Source/WebCore/svg/SVGStringList.cpp b/Source/WebCore/svg/SVGStringList.cpp new file mode 100644 index 0000000..2a1238b --- /dev/null +++ b/Source/WebCore/svg/SVGStringList.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGStringList.h" + +#include "SVGElement.h" +#include "SVGParserUtilities.h" +#include <wtf/text/StringBuilder.h> + +namespace WebCore { + +void SVGStringList::commitChange(SVGElement* contextElement) +{ + ASSERT(contextElement); + contextElement->invalidateSVGAttributes(); + contextElement->svgAttributeChanged(m_attributeName); +} + +void SVGStringList::reset(const String& string) +{ + parse(string, ' '); + + // Add empty string, if list is empty. + if (isEmpty()) + append(String("")); +} + +void SVGStringList::parse(const String& data, UChar delimiter) +{ + // TODO : more error checking/reporting + clear(); + + const UChar* ptr = data.characters(); + const UChar* end = ptr + data.length(); + while (ptr < end) { + const UChar* start = ptr; + while (ptr < end && *ptr != delimiter && !isWhitespace(*ptr)) + ptr++; + if (ptr == start) + break; + append(String(start, ptr - start)); + skipOptionalSpacesOrDelimiter(ptr, end, delimiter); + } +} + +String SVGStringList::valueAsString() const +{ + StringBuilder builder; + + unsigned size = this->size(); + for (unsigned i = 0; i < size; ++i) { + if (i > 0) + builder.append(' '); + + builder.append(at(i)); + } + + return builder.toString(); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGStringList.h b/Source/WebCore/svg/SVGStringList.h new file mode 100644 index 0000000..5463cc2 --- /dev/null +++ b/Source/WebCore/svg/SVGStringList.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGStringList_h +#define SVGStringList_h + +#if ENABLE(SVG) +#include "QualifiedName.h" +#include "SVGPropertyTraits.h" +#include <wtf/Vector.h> + +namespace WebCore { + +class SVGElement; + +class SVGStringList : public Vector<String> { +public: + SVGStringList(const QualifiedName& attributeName) + : m_attributeName(attributeName) + { + } + + void reset(const String&); + void parse(const String&, UChar delimiter = ','); + + // Only used by SVGStringListPropertyTearOff. + void commitChange(SVGElement* contextElement); + + String valueAsString() const; + +private: + const QualifiedName& m_attributeName; +}; + +template<> +struct SVGPropertyTraits<SVGStringList> { + typedef String ListItemType; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGStringList.idl b/Source/WebCore/svg/SVGStringList.idl new file mode 100644 index 0000000..82af72d --- /dev/null +++ b/Source/WebCore/svg/SVGStringList.idl @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGStringList { + readonly attribute unsigned long numberOfItems; + + void clear() + raises(DOMException); + [StrictTypeChecking, RequiresAllArguments=Raise] DOMString initialize(in DOMString item) + raises(DOMException, SVGException); + [StrictTypeChecking, RequiresAllArguments=Raise] DOMString getItem(in unsigned long index) + raises(DOMException); + [StrictTypeChecking, RequiresAllArguments=Raise] DOMString insertItemBefore(in DOMString item, in unsigned long index) + raises(DOMException, SVGException); + [StrictTypeChecking, RequiresAllArguments=Raise] DOMString replaceItem(in DOMString item, in unsigned long index) + raises(DOMException, SVGException); + [StrictTypeChecking, RequiresAllArguments=Raise] DOMString removeItem(in unsigned long index) + raises(DOMException); + [StrictTypeChecking, RequiresAllArguments=Raise] DOMString appendItem(in DOMString item) + raises(DOMException, SVGException); + }; + +} diff --git a/Source/WebCore/svg/SVGStylable.cpp b/Source/WebCore/svg/SVGStylable.cpp new file mode 100644 index 0000000..6f54888 --- /dev/null +++ b/Source/WebCore/svg/SVGStylable.cpp @@ -0,0 +1 @@ +// This file is now intentionally empty. Delete it after removing it from all the build systems and project files. diff --git a/Source/WebCore/svg/SVGStylable.h b/Source/WebCore/svg/SVGStylable.h new file mode 100644 index 0000000..4f57336 --- /dev/null +++ b/Source/WebCore/svg/SVGStylable.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGStylable_h +#define SVGStylable_h + +#if ENABLE(SVG) +#include <wtf/Forward.h> +#include <wtf/PassRefPtr.h> + +namespace WebCore { + +class CSSValue; +class CSSStyleDeclaration; + +class SVGStylable { +public: + virtual ~SVGStylable() { } + + virtual CSSStyleDeclaration* style() = 0; + virtual PassRefPtr<CSSValue> getPresentationAttribute(const String&) = 0; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGStylable_h diff --git a/Source/WebCore/svg/SVGStylable.idl b/Source/WebCore/svg/SVGStylable.idl new file mode 100644 index 0000000..0df1424 --- /dev/null +++ b/Source/WebCore/svg/SVGStylable.idl @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) 2007 Rob Buis <rwlbuis@gmail.com> + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG, ObjCProtocol, OmitConstructor] SVGStylable { + readonly attribute SVGAnimatedString className; + readonly attribute CSSStyleDeclaration style; + + CSSValue getPresentationAttribute(in DOMString name); + }; + +} diff --git a/Source/WebCore/svg/SVGStyleElement.cpp b/Source/WebCore/svg/SVGStyleElement.cpp new file mode 100644 index 0000000..042af1c --- /dev/null +++ b/Source/WebCore/svg/SVGStyleElement.cpp @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * Copyright (C) 2006 Apple Inc. All rights reserved. + * Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGStyleElement.h" + +#include "Attribute.h" +#include "CSSStyleSheet.h" +#include "Document.h" +#include "ExceptionCode.h" +#include "SVGNames.h" +#include <wtf/StdLibExtras.h> + +namespace WebCore { + +inline SVGStyleElement::SVGStyleElement(const QualifiedName& tagName, Document* document, bool createdByParser) + : SVGElement(tagName, document) + , StyleElement(document, createdByParser) +{ +} + +SVGStyleElement::~SVGStyleElement() +{ + if (m_sheet) + m_sheet->clearOwnerNode(); +} + +PassRefPtr<SVGStyleElement> SVGStyleElement::create(const QualifiedName& tagName, Document* document, bool createdByParser) +{ + return adoptRef(new SVGStyleElement(tagName, document, createdByParser)); +} + +const AtomicString& SVGStyleElement::type() const +{ + DEFINE_STATIC_LOCAL(const AtomicString, defaultValue, ("text/css")); + const AtomicString& n = getAttribute(SVGNames::typeAttr); + return n.isNull() ? defaultValue : n; +} + +void SVGStyleElement::setType(const AtomicString& type, ExceptionCode& ec) +{ + setAttribute(SVGNames::typeAttr, type, ec); +} + +const AtomicString& SVGStyleElement::media() const +{ + DEFINE_STATIC_LOCAL(const AtomicString, defaultValue, ("all")); + const AtomicString& n = getAttribute(SVGNames::mediaAttr); + return n.isNull() ? defaultValue : n; +} + +void SVGStyleElement::setMedia(const AtomicString& media, ExceptionCode& ec) +{ + setAttribute(SVGNames::mediaAttr, media, ec); +} + +String SVGStyleElement::title() const +{ + return getAttribute(SVGNames::titleAttr); +} + +void SVGStyleElement::setTitle(const AtomicString& title, ExceptionCode& ec) +{ + setAttribute(SVGNames::titleAttr, title, ec); +} + +void SVGStyleElement::parseMappedAttribute(Attribute* attr) +{ + if (attr->name() == SVGNames::titleAttr && m_sheet) + m_sheet->setTitle(attr->value()); + else { + if (SVGLangSpace::parseMappedAttribute(attr)) + return; + SVGElement::parseMappedAttribute(attr); + } +} + +void SVGStyleElement::finishParsingChildren() +{ + StyleElement::finishParsingChildren(this); + SVGElement::finishParsingChildren(); +} + +void SVGStyleElement::insertedIntoDocument() +{ + SVGElement::insertedIntoDocument(); + StyleElement::insertedIntoDocument(document(), this); +} + +void SVGStyleElement::removedFromDocument() +{ + SVGElement::removedFromDocument(); + StyleElement::removedFromDocument(document(), this); +} + +void SVGStyleElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) +{ + StyleElement::childrenChanged(this); + SVGElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGStyleElement.h b/Source/WebCore/svg/SVGStyleElement.h new file mode 100644 index 0000000..acf358e --- /dev/null +++ b/Source/WebCore/svg/SVGStyleElement.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGStyleElement_h +#define SVGStyleElement_h + +#if ENABLE(SVG) +#include "SVGElement.h" +#include "SVGLangSpace.h" +#include "StyleElement.h" + +namespace WebCore { + +class SVGStyleElement : public SVGElement + , public SVGLangSpace + , public StyleElement { +public: + static PassRefPtr<SVGStyleElement> create(const QualifiedName&, Document*, bool createdByParser); + virtual ~SVGStyleElement(); + + using StyleElement::sheet; + + virtual const AtomicString& type() const; + void setType(const AtomicString&, ExceptionCode&); + + virtual const AtomicString& media() const; + void setMedia(const AtomicString&, ExceptionCode&); + + virtual String title() const; + void setTitle(const AtomicString&, ExceptionCode&); + +private: + SVGStyleElement(const QualifiedName&, Document*, bool createdByParser); + + virtual void parseMappedAttribute(Attribute*); + virtual void insertedIntoDocument(); + virtual void removedFromDocument(); + virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); + + virtual void finishParsingChildren(); + + virtual bool isLoading() const { return StyleElement::isLoading(); } + virtual bool sheetLoaded() { return StyleElement::sheetLoaded(document()); } +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGStyleElement_h diff --git a/Source/WebCore/svg/SVGStyleElement.idl b/Source/WebCore/svg/SVGStyleElement.idl new file mode 100644 index 0000000..515e042 --- /dev/null +++ b/Source/WebCore/svg/SVGStyleElement.idl @@ -0,0 +1,39 @@ +/* + * Copyright (C) Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGStyleElement : SVGElement, + SVGLangSpace { + attribute DOMString type + setter raises(DOMException); + attribute DOMString media + setter raises(DOMException); + attribute DOMString title + setter raises(DOMException); + }; + +} diff --git a/Source/WebCore/svg/SVGStyledElement.cpp b/Source/WebCore/svg/SVGStyledElement.cpp new file mode 100644 index 0000000..58248d8 --- /dev/null +++ b/Source/WebCore/svg/SVGStyledElement.cpp @@ -0,0 +1,387 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2007, 2008 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGStyledElement.h" + +#include "Attr.h" +#include "CSSParser.h" +#include "CSSStyleSelector.h" +#include "Document.h" +#include "HTMLNames.h" +#include "PlatformString.h" +#include "RenderObject.h" +#include "RenderSVGResource.h" +#include "RenderSVGResourceClipper.h" +#include "RenderSVGResourceFilter.h" +#include "RenderSVGResourceMasker.h" +#include "SVGElement.h" +#include "SVGElementInstance.h" +#include "SVGElementRareData.h" +#include "SVGNames.h" +#include "SVGRenderStyle.h" +#include "SVGRenderSupport.h" +#include "SVGSVGElement.h" +#include "SVGUseElement.h" +#include <wtf/Assertions.h> + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_STRING(SVGStyledElement, HTMLNames::classAttr, ClassName, className) + +using namespace SVGNames; + +void mapAttributeToCSSProperty(HashMap<AtomicStringImpl*, int>* propertyNameToIdMap, const QualifiedName& attrName) +{ + int propertyId = cssPropertyID(attrName.localName()); + ASSERT(propertyId > 0); + propertyNameToIdMap->set(attrName.localName().impl(), propertyId); +} + +SVGStyledElement::SVGStyledElement(const QualifiedName& tagName, Document* document) + : SVGElement(tagName, document) +{ +} + +SVGStyledElement::~SVGStyledElement() +{ +} + +String SVGStyledElement::title() const +{ + // According to spec, we should not return titles when hovering over root <svg> elements (those + // <title> elements are the title of the document, not a tooltip) so we instantly return. + if (hasTagName(SVGNames::svgTag)) { + const SVGSVGElement* svg = static_cast<const SVGSVGElement*>(this); + if (svg->isOutermostSVG()) + return String(); + } + + // Walk up the tree, to find out whether we're inside a <use> shadow tree, to find the right title. + Node* parent = const_cast<SVGStyledElement*>(this); + while (parent) { + if (!parent->isShadowRoot()) { + parent = parent->parentNodeGuaranteedHostFree(); + continue; + } + + // Get the <use> element. + Element* shadowParent = parent->shadowHost(); + if (shadowParent && shadowParent->isSVGElement() && shadowParent->hasTagName(SVGNames::useTag)) { + SVGUseElement* useElement = static_cast<SVGUseElement*>(shadowParent); + // If the <use> title is not empty we found the title to use. + String useTitle(useElement->title()); + if (useTitle.isEmpty()) + break; + return useTitle; + } + parent = parent->parentNode(); + } + + // If we aren't an instance in a <use> or the <use> title was not found, then find the first + // <title> child of this element. + Element* titleElement = firstElementChild(); + for (; titleElement; titleElement = titleElement->nextElementSibling()) { + if (titleElement->hasTagName(SVGNames::titleTag) && titleElement->isSVGElement()) + break; + } + + // If a title child was found, return the text contents. + if (titleElement) + return titleElement->innerText(); + + // Otherwise return a null/empty string. + return String(); +} + +bool SVGStyledElement::rendererIsNeeded(RenderStyle* style) +{ + // http://www.w3.org/TR/SVG/extend.html#PrivateData + // Prevent anything other than SVG renderers from appearing in our render tree + // Spec: SVG allows inclusion of elements from foreign namespaces anywhere + // with the SVG content. In general, the SVG user agent will include the unknown + // elements in the DOM but will otherwise ignore unknown elements. + if (!parentNode() || parentNode()->isSVGElement()) + return StyledElement::rendererIsNeeded(style); + + return false; +} + +int SVGStyledElement::cssPropertyIdForSVGAttributeName(const QualifiedName& attrName) +{ + if (!attrName.namespaceURI().isNull()) + return 0; + + static HashMap<AtomicStringImpl*, int>* propertyNameToIdMap = 0; + if (!propertyNameToIdMap) { + propertyNameToIdMap = new HashMap<AtomicStringImpl*, int>; + // This is a list of all base CSS and SVG CSS properties which are exposed as SVG XML attributes + mapAttributeToCSSProperty(propertyNameToIdMap, alignment_baselineAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, baseline_shiftAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, clipAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, clip_pathAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, clip_ruleAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, SVGNames::colorAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, color_interpolationAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, color_interpolation_filtersAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, color_profileAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, color_renderingAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, cursorAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, SVGNames::directionAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, displayAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, dominant_baselineAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, enable_backgroundAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, fillAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, fill_opacityAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, fill_ruleAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, filterAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, flood_colorAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, flood_opacityAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, font_familyAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, font_sizeAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, font_stretchAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, font_styleAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, font_variantAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, font_weightAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, glyph_orientation_horizontalAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, glyph_orientation_verticalAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, image_renderingAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, kerningAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, letter_spacingAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, lighting_colorAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, marker_endAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, marker_midAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, marker_startAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, maskAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, opacityAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, overflowAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, pointer_eventsAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, shape_renderingAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, stop_colorAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, stop_opacityAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, strokeAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, stroke_dasharrayAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, stroke_dashoffsetAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, stroke_linecapAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, stroke_linejoinAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, stroke_miterlimitAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, stroke_opacityAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, stroke_widthAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, text_anchorAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, text_decorationAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, text_renderingAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, unicode_bidiAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, vector_effectAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, visibilityAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, word_spacingAttr); + mapAttributeToCSSProperty(propertyNameToIdMap, writing_modeAttr); + } + + return propertyNameToIdMap->get(attrName.localName().impl()); +} + +bool SVGStyledElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const +{ + if (SVGStyledElement::cssPropertyIdForSVGAttributeName(attrName) > 0) { + result = eSVG; + return false; + } + return SVGElement::mapToEntry(attrName, result); +} + +void SVGStyledElement::parseMappedAttribute(Attribute* attr) +{ + const QualifiedName& attrName = attr->name(); + // NOTE: Any subclass which overrides parseMappedAttribute for a property handled by + // cssPropertyIdForSVGAttributeName will also have to override mapToEntry to disable the default eSVG mapping + int propId = SVGStyledElement::cssPropertyIdForSVGAttributeName(attrName); + if (propId > 0) { + addCSSProperty(attr, propId, attr->value()); + setNeedsStyleRecalc(); + return; + } + + // SVG animation has currently requires special storage of values so we set + // the className here. svgAttributeChanged actually causes the resulting + // style updates (instead of StyledElement::parseMappedAttribute). We don't + // tell StyledElement about the change to avoid parsing the class list twice + if (attrName.matches(HTMLNames::classAttr)) + setClassNameBaseValue(attr->value()); + else + // id is handled by StyledElement which SVGElement inherits from + SVGElement::parseMappedAttribute(attr); +} + +bool SVGStyledElement::isKnownAttribute(const QualifiedName& attrName) +{ + return isIdAttributeName(attrName); +} + +void SVGStyledElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGElement::svgAttributeChanged(attrName); + + if (attrName.matches(HTMLNames::classAttr)) + classAttributeChanged(className()); + + RenderObject* object = renderer(); + + if (isIdAttributeName(attrName)) { + // Notify resources about id changes, this is important as we cache resources by id in SVGDocumentExtensions + if (object && object->isSVGResourceContainer()) + object->toRenderSVGResourceContainer()->idChanged(); + } + + // Invalidate all SVGElementInstances associated with us + SVGElementInstance::invalidateAllInstancesOfElement(this); +} + +void SVGStyledElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGElement::synchronizeProperty(attrName); + + if (attrName == anyQName() || attrName.matches(HTMLNames::classAttr)) + synchronizeClassName(); +} + +void SVGStyledElement::attach() +{ + SVGElement::attach(); + + if (RenderObject* object = renderer()) + object->updateFromElement(); +} + +void SVGStyledElement::insertedIntoDocument() +{ + SVGElement::insertedIntoDocument(); + updateRelativeLengthsInformation(); +} + +void SVGStyledElement::removedFromDocument() +{ + updateRelativeLengthsInformation(false, this); + SVGElement::removedFromDocument(); +} + +void SVGStyledElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) +{ + SVGElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); + + // Invalidate all SVGElementInstances associated with us + if (!changedByParser) + SVGElementInstance::invalidateAllInstancesOfElement(this); +} + +PassRefPtr<RenderStyle> SVGStyledElement::resolveStyle(RenderStyle* parentStyle) +{ + if (renderer()) + return renderer()->style(); + return document()->styleSelector()->styleForElement(this, parentStyle); +} + +PassRefPtr<CSSValue> SVGStyledElement::getPresentationAttribute(const String& name) +{ + if (!attributeMap()) + return 0; + + QualifiedName attributeName(nullAtom, name, nullAtom); + Attribute* attr = attributeMap()->getAttributeItem(attributeName); + if (!attr || !attr->isMappedAttribute() || !attr->style()) + return 0; + + Attribute* cssSVGAttr = attr; + // This function returns a pointer to a CSSValue which can be mutated from JavaScript. + // If the associated MappedAttribute uses the same CSSMappedAttributeDeclaration + // as StyledElement's mappedAttributeDecls cache, create a new CSSMappedAttributeDeclaration + // before returning so that any modifications to the CSSValue will not affect other attributes. + MappedAttributeEntry entry; + mapToEntry(attributeName, entry); + if (getMappedAttributeDecl(entry, cssSVGAttr) == cssSVGAttr->decl()) { + cssSVGAttr->setDecl(0); + int propId = SVGStyledElement::cssPropertyIdForSVGAttributeName(cssSVGAttr->name()); + addCSSProperty(cssSVGAttr, propId, cssSVGAttr->value()); + } + return cssSVGAttr->style()->getPropertyCSSValue(name); +} + +bool SVGStyledElement::instanceUpdatesBlocked() const +{ + return hasRareSVGData() && rareSVGData()->instanceUpdatesBlocked(); +} + +void SVGStyledElement::setInstanceUpdatesBlocked(bool value) +{ + if (hasRareSVGData()) + rareSVGData()->setInstanceUpdatesBlocked(value); +} + +AffineTransform SVGStyledElement::localCoordinateSpaceTransform(SVGLocatable::CTMScope) const +{ + // To be overriden by SVGStyledLocatableElement/SVGStyledTransformableElement (or as special case SVGTextElement) + ASSERT_NOT_REACHED(); + return AffineTransform(); +} + +void SVGStyledElement::updateRelativeLengthsInformation(bool hasRelativeLengths, SVGStyledElement* element) +{ + // If we're not yet in a document, this function will be called again from insertedIntoDocument(). Do nothing now. + if (!inDocument()) + return; + + // An element wants to notify us that its own relative lengths state changed. + // Register it in the relative length map, and register us in the parent relative length map. + // Register the parent in the grandparents map, etc. Repeat procedure until the root of the SVG tree. + + if (hasRelativeLengths) + m_elementsWithRelativeLengths.add(element); + else { + if (!m_elementsWithRelativeLengths.contains(element)) { + // We were never registered. Do nothing. + return; + } + + m_elementsWithRelativeLengths.remove(element); + } + + // Find first styled parent node, and notify it that we've changed our relative length state. + ContainerNode* node = parentNode(); + while (node) { + if (!node->isSVGElement()) + break; + + SVGElement* element = static_cast<SVGElement*>(node); + if (!element->isStyled()) { + node = node->parentNode(); + continue; + } + + // Register us in the parent element map. + static_cast<SVGStyledElement*>(element)->updateRelativeLengthsInformation(hasRelativeLengths, this); + break; + } +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGStyledElement.h b/Source/WebCore/svg/SVGStyledElement.h new file mode 100644 index 0000000..0714d43 --- /dev/null +++ b/Source/WebCore/svg/SVGStyledElement.h @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGStyledElement_h +#define SVGStyledElement_h + +#if ENABLE(SVG) +#include "SVGAnimatedString.h" +#include "SVGLocatable.h" +#include "SVGStylable.h" +#include <wtf/HashSet.h> + +namespace WebCore { + +void mapAttributeToCSSProperty(HashMap<AtomicStringImpl*, int>* propertyNameToIdMap, const QualifiedName& attrName); + +class SVGStyledElement : public SVGElement, + public SVGStylable { +public: + virtual ~SVGStyledElement(); + + virtual String title() const; + + bool hasRelativeLengths() const { return !m_elementsWithRelativeLengths.isEmpty(); } + + virtual bool supportsMarkers() const { return false; } + + virtual PassRefPtr<CSSValue> getPresentationAttribute(const String& name); + + bool isKnownAttribute(const QualifiedName&); + + // Centralized place to force a manual style resolution. Hacky but needed for now. + PassRefPtr<RenderStyle> resolveStyle(RenderStyle* parentStyle); + + bool instanceUpdatesBlocked() const; + void setInstanceUpdatesBlocked(bool); + + virtual AffineTransform localCoordinateSpaceTransform(SVGLocatable::CTMScope) const; + + virtual CSSStyleDeclaration* style() { return StyledElement::style(); } + +protected: + SVGStyledElement(const QualifiedName&, Document*); + + virtual bool rendererIsNeeded(RenderStyle*); + + virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + + virtual void attach(); + virtual void insertedIntoDocument(); + virtual void removedFromDocument(); + virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); + + static int cssPropertyIdForSVGAttributeName(const QualifiedName&); + void updateRelativeLengthsInformation() { updateRelativeLengthsInformation(selfHasRelativeLengths(), this); } + void updateRelativeLengthsInformation(bool hasRelativeLengths, SVGStyledElement*); + + virtual bool selfHasRelativeLengths() const { return false; } + +private: + virtual bool isStyled() const { return true; } + + HashSet<SVGStyledElement*> m_elementsWithRelativeLengths; + + // Animated property declarations + DECLARE_ANIMATED_STRING(ClassName, className) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGStyledElement diff --git a/Source/WebCore/svg/SVGStyledLocatableElement.cpp b/Source/WebCore/svg/SVGStyledLocatableElement.cpp new file mode 100644 index 0000000..f29121b --- /dev/null +++ b/Source/WebCore/svg/SVGStyledLocatableElement.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGStyledLocatableElement.h" + +#include "AffineTransform.h" +#include "SVGElement.h" +#include "SVGSVGElement.h" + +namespace WebCore { + +SVGStyledLocatableElement::SVGStyledLocatableElement(const QualifiedName& tagName, Document* document) + : SVGStyledElement(tagName, document) +{ +} + +SVGElement* SVGStyledLocatableElement::nearestViewportElement() const +{ + return SVGLocatable::nearestViewportElement(this); +} + +SVGElement* SVGStyledLocatableElement::farthestViewportElement() const +{ + return SVGLocatable::farthestViewportElement(this); +} + +FloatRect SVGStyledLocatableElement::getBBox(StyleUpdateStrategy styleUpdateStrategy) const +{ + return SVGLocatable::getBBox(this, styleUpdateStrategy); +} + +AffineTransform SVGStyledLocatableElement::getCTM(StyleUpdateStrategy styleUpdateStrategy) const +{ + return SVGLocatable::computeCTM(this, SVGLocatable::NearestViewportScope, styleUpdateStrategy); +} + +AffineTransform SVGStyledLocatableElement::getScreenCTM(StyleUpdateStrategy styleUpdateStrategy) const +{ + return SVGLocatable::computeCTM(this, SVGLocatable::ScreenScope, styleUpdateStrategy); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGStyledLocatableElement.h b/Source/WebCore/svg/SVGStyledLocatableElement.h new file mode 100644 index 0000000..114ae83 --- /dev/null +++ b/Source/WebCore/svg/SVGStyledLocatableElement.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGStyledLocatableElement_h +#define SVGStyledLocatableElement_h + +#if ENABLE(SVG) +#include "SVGLocatable.h" +#include "SVGStyledElement.h" + +namespace WebCore { + +class SVGElement; + +class SVGStyledLocatableElement : public SVGStyledElement, + virtual public SVGLocatable { +public: + virtual SVGElement* nearestViewportElement() const; + virtual SVGElement* farthestViewportElement() const; + + virtual FloatRect getBBox(StyleUpdateStrategy = AllowStyleUpdate) const; + virtual AffineTransform getCTM(StyleUpdateStrategy = AllowStyleUpdate) const; + virtual AffineTransform getScreenCTM(StyleUpdateStrategy = AllowStyleUpdate) const; + + virtual AffineTransform localCoordinateSpaceTransform(SVGLocatable::CTMScope mode) const { return SVGLocatable::localCoordinateSpaceTransform(mode); } + +protected: + SVGStyledLocatableElement(const QualifiedName&, Document*); + +private: + virtual bool isStyledLocatable() const { return true; } +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGStyledLocatableElement_h diff --git a/Source/WebCore/svg/SVGStyledTransformableElement.cpp b/Source/WebCore/svg/SVGStyledTransformableElement.cpp new file mode 100644 index 0000000..2334943 --- /dev/null +++ b/Source/WebCore/svg/SVGStyledTransformableElement.cpp @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGStyledTransformableElement.h" + +#include "AffineTransform.h" +#include "Attribute.h" +#include "RenderSVGPath.h" +#include "SVGNames.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_TRANSFORM_LIST(SVGStyledTransformableElement, SVGNames::transformAttr, Transform, transform) + +SVGStyledTransformableElement::SVGStyledTransformableElement(const QualifiedName& tagName, Document* document) + : SVGStyledLocatableElement(tagName, document) +{ +} + +SVGStyledTransformableElement::~SVGStyledTransformableElement() +{ +} + +AffineTransform SVGStyledTransformableElement::getCTM(StyleUpdateStrategy styleUpdateStrategy) const +{ + return SVGLocatable::computeCTM(this, SVGLocatable::NearestViewportScope, styleUpdateStrategy); +} + +AffineTransform SVGStyledTransformableElement::getScreenCTM(StyleUpdateStrategy styleUpdateStrategy) const +{ + return SVGLocatable::computeCTM(this, SVGLocatable::ScreenScope, styleUpdateStrategy); +} + +AffineTransform SVGStyledTransformableElement::animatedLocalTransform() const +{ + AffineTransform matrix; + transform().concatenate(matrix); + return m_supplementalTransform ? *m_supplementalTransform * matrix : matrix; +} + +AffineTransform* SVGStyledTransformableElement::supplementalTransform() +{ + if (!m_supplementalTransform) + m_supplementalTransform.set(new AffineTransform()); + return m_supplementalTransform.get(); +} + +void SVGStyledTransformableElement::parseMappedAttribute(Attribute* attr) +{ + if (SVGTransformable::isKnownAttribute(attr->name())) { + SVGTransformList newList; + if (!SVGTransformable::parseTransformAttribute(newList, attr->value())) + newList.clear(); + detachAnimatedTransformListWrappers(newList.size()); + setTransformBaseValue(newList); + } else + SVGStyledLocatableElement::parseMappedAttribute(attr); +} + +void SVGStyledTransformableElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGStyledLocatableElement::synchronizeProperty(attrName); + + if (attrName == anyQName() || SVGTransformable::isKnownAttribute(attrName)) + synchronizeTransform(); +} + +bool SVGStyledTransformableElement::isKnownAttribute(const QualifiedName& attrName) +{ + return SVGTransformable::isKnownAttribute(attrName) || SVGStyledLocatableElement::isKnownAttribute(attrName); +} + +SVGElement* SVGStyledTransformableElement::nearestViewportElement() const +{ + return SVGTransformable::nearestViewportElement(this); +} + +SVGElement* SVGStyledTransformableElement::farthestViewportElement() const +{ + return SVGTransformable::farthestViewportElement(this); +} + +FloatRect SVGStyledTransformableElement::getBBox(StyleUpdateStrategy styleUpdateStrategy) const +{ + return SVGTransformable::getBBox(this, styleUpdateStrategy); +} + +RenderObject* SVGStyledTransformableElement::createRenderer(RenderArena* arena, RenderStyle*) +{ + // By default, any subclass is expected to do path-based drawing + return new (arena) RenderSVGPath(this); +} + +void SVGStyledTransformableElement::toClipPath(Path& path) const +{ + toPathData(path); + // FIXME: How do we know the element has done a layout? + path.transform(animatedLocalTransform()); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGStyledTransformableElement.h b/Source/WebCore/svg/SVGStyledTransformableElement.h new file mode 100644 index 0000000..1d882e5 --- /dev/null +++ b/Source/WebCore/svg/SVGStyledTransformableElement.h @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGStyledTransformableElement_h +#define SVGStyledTransformableElement_h + +#if ENABLE(SVG) +#include "SVGAnimatedTransformList.h" +#include "SVGStyledLocatableElement.h" +#include "SVGTransformable.h" + +namespace WebCore { + +class AffineTransform; +class Path; + +class SVGStyledTransformableElement : public SVGStyledLocatableElement, + public SVGTransformable { +public: + virtual ~SVGStyledTransformableElement(); + + virtual AffineTransform getCTM(StyleUpdateStrategy = AllowStyleUpdate) const; + virtual AffineTransform getScreenCTM(StyleUpdateStrategy = AllowStyleUpdate) const; + virtual SVGElement* nearestViewportElement() const; + virtual SVGElement* farthestViewportElement() const; + + virtual AffineTransform localCoordinateSpaceTransform(SVGLocatable::CTMScope mode) const { return SVGTransformable::localCoordinateSpaceTransform(mode); } + virtual AffineTransform animatedLocalTransform() const; + virtual AffineTransform* supplementalTransform(); + + virtual FloatRect getBBox(StyleUpdateStrategy = AllowStyleUpdate) const; + + bool isKnownAttribute(const QualifiedName&); + + // "base class" methods for all the elements which render as paths + virtual void toPathData(Path&) const { } + virtual void toClipPath(Path&) const; + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + +protected: + SVGStyledTransformableElement(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + virtual void synchronizeProperty(const QualifiedName&); + + // Animated property declarations + DECLARE_ANIMATED_TRANSFORM_LIST(Transform, transform) + +private: + virtual bool isStyledTransformable() const { return true; } + + // Used by <animateMotion> + OwnPtr<AffineTransform> m_supplementalTransform; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGStyledTransformableElement_h diff --git a/Source/WebCore/svg/SVGSwitchElement.cpp b/Source/WebCore/svg/SVGSwitchElement.cpp new file mode 100644 index 0000000..c225053 --- /dev/null +++ b/Source/WebCore/svg/SVGSwitchElement.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGSwitchElement.h" + +#include "RenderSVGTransformableContainer.h" +#include "SVGNames.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_BOOLEAN(SVGSwitchElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) + +inline SVGSwitchElement::SVGSwitchElement(const QualifiedName& tagName, Document* document) + : SVGStyledTransformableElement(tagName, document) +{ +} + +PassRefPtr<SVGSwitchElement> SVGSwitchElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGSwitchElement(tagName, document)); +} + +bool SVGSwitchElement::childShouldCreateRenderer(Node* child) const +{ + // FIXME: This function does not do what the comment below implies it does. + // It will create a renderer for any valid SVG element children, not just the first one. + for (Node* node = firstChild(); node; node = node->nextSibling()) { + if (!node->isSVGElement()) + continue; + + SVGElement* element = static_cast<SVGElement*>(node); + if (!element || !element->isValid()) + continue; + + return node == child; // Only allow this child if it's the first valid child + } + + return false; +} + +RenderObject* SVGSwitchElement::createRenderer(RenderArena* arena, RenderStyle*) +{ + return new (arena) RenderSVGTransformableContainer(this); +} + +void SVGSwitchElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGStyledTransformableElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeExternalResourcesRequired(); + SVGTests::synchronizeProperties(this, attrName); + return; + } + + if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) + synchronizeExternalResourcesRequired(); + else if (SVGTests::isKnownAttribute(attrName)) + SVGTests::synchronizeProperties(this, attrName); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGSwitchElement.h b/Source/WebCore/svg/SVGSwitchElement.h new file mode 100644 index 0000000..937a1e4 --- /dev/null +++ b/Source/WebCore/svg/SVGSwitchElement.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGSwitchElement_h +#define SVGSwitchElement_h + +#if ENABLE(SVG) +#include "SVGAnimatedBoolean.h" +#include "SVGExternalResourcesRequired.h" +#include "SVGLangSpace.h" +#include "SVGStyledTransformableElement.h" +#include "SVGTests.h" + +namespace WebCore { + +class SVGSwitchElement : public SVGStyledTransformableElement, + public SVGTests, + public SVGLangSpace, + public SVGExternalResourcesRequired { +public: + static PassRefPtr<SVGSwitchElement> create(const QualifiedName&, Document*); + +private: + SVGSwitchElement(const QualifiedName&, Document*); + + virtual bool isValid() const { return SVGTests::isValid(); } + + virtual bool childShouldCreateRenderer(Node*) const; + + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + virtual void synchronizeProperty(const QualifiedName&); + + // Animated property declarations + + // SVGExternalResourcesRequired + DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGSwitchElement.idl b/Source/WebCore/svg/SVGSwitchElement.idl new file mode 100644 index 0000000..e4749b7 --- /dev/null +++ b/Source/WebCore/svg/SVGSwitchElement.idl @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGSwitchElement : SVGElement, + SVGTests, + SVGLangSpace, + SVGExternalResourcesRequired, + SVGStylable, + SVGTransformable { + }; + +} diff --git a/Source/WebCore/svg/SVGSymbolElement.cpp b/Source/WebCore/svg/SVGSymbolElement.cpp new file mode 100644 index 0000000..ee4278d --- /dev/null +++ b/Source/WebCore/svg/SVGSymbolElement.cpp @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGSymbolElement.h" + +#include "SVGFitToViewBox.h" +#include "SVGNames.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_BOOLEAN(SVGSymbolElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) +DEFINE_ANIMATED_PRESERVEASPECTRATIO(SVGSymbolElement, SVGNames::preserveAspectRatioAttr, PreserveAspectRatio, preserveAspectRatio) +DEFINE_ANIMATED_RECT(SVGSymbolElement, SVGNames::viewBoxAttr, ViewBox, viewBox) + +inline SVGSymbolElement::SVGSymbolElement(const QualifiedName& tagName, Document* document) + : SVGStyledElement(tagName, document) +{ +} + +PassRefPtr<SVGSymbolElement> SVGSymbolElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGSymbolElement(tagName, document)); +} + +void SVGSymbolElement::parseMappedAttribute(Attribute* attr) +{ + if (SVGLangSpace::parseMappedAttribute(attr)) + return; + if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) + return; + if (SVGFitToViewBox::parseMappedAttribute(document(), attr)) + return; + + SVGStyledElement::parseMappedAttribute(attr); +} + +void SVGSymbolElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGStyledElement::svgAttributeChanged(attrName); + + if (attrName == SVGNames::viewBoxAttr) + updateRelativeLengthsInformation(); +} + +void SVGSymbolElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGStyledElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizePreserveAspectRatio(); + synchronizeViewBox(); + synchronizeExternalResourcesRequired(); + synchronizeViewBox(); + synchronizePreserveAspectRatio(); + return; + } + + if (attrName == SVGNames::preserveAspectRatioAttr) + synchronizePreserveAspectRatio(); + else if (attrName == SVGNames::viewBoxAttr) + synchronizeViewBox(); + else if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) + synchronizeExternalResourcesRequired(); + else if (SVGFitToViewBox::isKnownAttribute(attrName)) { + synchronizeViewBox(); + synchronizePreserveAspectRatio(); + } +} + +bool SVGSymbolElement::selfHasRelativeLengths() const +{ + return hasAttribute(SVGNames::viewBoxAttr); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGSymbolElement.h b/Source/WebCore/svg/SVGSymbolElement.h new file mode 100644 index 0000000..e049f0d --- /dev/null +++ b/Source/WebCore/svg/SVGSymbolElement.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGSymbolElement_h +#define SVGSymbolElement_h + +#if ENABLE(SVG) +#include "SVGAnimatedBoolean.h" +#include "SVGAnimatedPreserveAspectRatio.h" +#include "SVGAnimatedRect.h" +#include "SVGExternalResourcesRequired.h" +#include "SVGFitToViewBox.h" +#include "SVGLangSpace.h" +#include "SVGStyledElement.h" + +namespace WebCore { + +class SVGSymbolElement : public SVGStyledElement, + public SVGLangSpace, + public SVGExternalResourcesRequired, + public SVGFitToViewBox { +public: + static PassRefPtr<SVGSymbolElement> create(const QualifiedName&, Document*); + +private: + SVGSymbolElement(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + virtual bool rendererIsNeeded(RenderStyle*) { return false; } + + virtual bool selfHasRelativeLengths() const; + + // Animated property declarations + + // SVGExternalResourcesRequired + DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) + + // SVGFitToViewBox + DECLARE_ANIMATED_RECT(ViewBox, viewBox) + DECLARE_ANIMATED_PRESERVEASPECTRATIO(PreserveAspectRatio, preserveAspectRatio) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGSymbolElement.idl b/Source/WebCore/svg/SVGSymbolElement.idl new file mode 100644 index 0000000..5d93de1 --- /dev/null +++ b/Source/WebCore/svg/SVGSymbolElement.idl @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGSymbolElement : SVGElement, + SVGLangSpace, + SVGExternalResourcesRequired, + SVGStylable, + SVGFitToViewBox { + }; + +} diff --git a/Source/WebCore/svg/SVGTRefElement.cpp b/Source/WebCore/svg/SVGTRefElement.cpp new file mode 100644 index 0000000..14c4700 --- /dev/null +++ b/Source/WebCore/svg/SVGTRefElement.cpp @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGTRefElement.h" + +#include "RenderSVGInline.h" +#include "RenderSVGResource.h" +#include "SVGDocument.h" +#include "SVGNames.h" +#include "Text.h" +#include "XLinkNames.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_STRING(SVGTRefElement, XLinkNames::hrefAttr, Href, href) + +inline SVGTRefElement::SVGTRefElement(const QualifiedName& tagName, Document* document) + : SVGTextPositioningElement(tagName, document) +{ +} + +PassRefPtr<SVGTRefElement> SVGTRefElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGTRefElement(tagName, document)); +} + +void SVGTRefElement::updateReferencedText() +{ + Element* target = document()->getElementById(SVGURIReference::getTarget(href())); + String textContent; + if (target && target->isSVGElement()) + textContent = static_cast<SVGElement*>(target)->textContent(); + ExceptionCode ignore = 0; + setTextContent(textContent, ignore); +} + +void SVGTRefElement::parseMappedAttribute(Attribute* attr) +{ + if (SVGURIReference::parseMappedAttribute(attr)) { + updateReferencedText(); + return; + } + + SVGTextPositioningElement::parseMappedAttribute(attr); +} + +void SVGTRefElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGTextPositioningElement::svgAttributeChanged(attrName); + + if (!renderer()) + return; + + if (SVGURIReference::isKnownAttribute(attrName)) + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer()); +} + +void SVGTRefElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGTextPositioningElement::synchronizeProperty(attrName); + + if (attrName == anyQName() || SVGURIReference::isKnownAttribute(attrName)) + synchronizeHref(); +} + +RenderObject* SVGTRefElement::createRenderer(RenderArena* arena, RenderStyle*) +{ + return new (arena) RenderSVGInline(this); +} + +bool SVGTRefElement::childShouldCreateRenderer(Node* child) const +{ + if (child->isTextNode()) + return true; + + return false; +} + +bool SVGTRefElement::rendererIsNeeded(RenderStyle* style) +{ + if (parentNode() + && (parentNode()->hasTagName(SVGNames::aTag) +#if ENABLE(SVG_FONTS) + || parentNode()->hasTagName(SVGNames::altGlyphTag) +#endif + || parentNode()->hasTagName(SVGNames::textTag) + || parentNode()->hasTagName(SVGNames::textPathTag) + || parentNode()->hasTagName(SVGNames::tspanTag))) + return StyledElement::rendererIsNeeded(style); + + return false; +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGTRefElement.h b/Source/WebCore/svg/SVGTRefElement.h new file mode 100644 index 0000000..8b98383 --- /dev/null +++ b/Source/WebCore/svg/SVGTRefElement.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGTRefElement_h +#define SVGTRefElement_h + +#if ENABLE(SVG) +#include "SVGTextPositioningElement.h" +#include "SVGURIReference.h" + +namespace WebCore { + +class SVGTRefElement : public SVGTextPositioningElement, + public SVGURIReference { +public: + static PassRefPtr<SVGTRefElement> create(const QualifiedName&, Document*); + +private: + SVGTRefElement(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + virtual bool childShouldCreateRenderer(Node*) const; + virtual bool rendererIsNeeded(RenderStyle*); + + void updateReferencedText(); + + // Animated property declarations + + // SVGURIReference + DECLARE_ANIMATED_STRING(Href, href) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGTRefElement.idl b/Source/WebCore/svg/SVGTRefElement.idl new file mode 100644 index 0000000..68ec9be --- /dev/null +++ b/Source/WebCore/svg/SVGTRefElement.idl @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGTRefElement : SVGTextPositioningElement, + SVGURIReference { + }; + +} diff --git a/Source/WebCore/svg/SVGTSpanElement.cpp b/Source/WebCore/svg/SVGTSpanElement.cpp new file mode 100644 index 0000000..8fe30e2 --- /dev/null +++ b/Source/WebCore/svg/SVGTSpanElement.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2010 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGTSpanElement.h" + +#include "RenderInline.h" +#include "RenderSVGTSpan.h" +#include "SVGNames.h" + +namespace WebCore { + +inline SVGTSpanElement::SVGTSpanElement(const QualifiedName& tagName, Document* document) + : SVGTextPositioningElement(tagName, document) +{ +} + +PassRefPtr<SVGTSpanElement> SVGTSpanElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGTSpanElement(tagName, document)); +} + +RenderObject* SVGTSpanElement::createRenderer(RenderArena* arena, RenderStyle*) +{ + return new (arena) RenderSVGTSpan(this); +} + +bool SVGTSpanElement::childShouldCreateRenderer(Node* child) const +{ + if (child->isTextNode() + || child->hasTagName(SVGNames::aTag) +#if ENABLE(SVG_FONTS) + || child->hasTagName(SVGNames::altGlyphTag) +#endif + || child->hasTagName(SVGNames::trefTag) + || child->hasTagName(SVGNames::tspanTag)) + return true; + + return false; +} + +bool SVGTSpanElement::rendererIsNeeded(RenderStyle* style) +{ + if (parentNode() + && (parentNode()->hasTagName(SVGNames::aTag) +#if ENABLE(SVG_FONTS) + || parentNode()->hasTagName(SVGNames::altGlyphTag) +#endif + || parentNode()->hasTagName(SVGNames::textTag) + || parentNode()->hasTagName(SVGNames::textPathTag) + || parentNode()->hasTagName(SVGNames::tspanTag))) + return StyledElement::rendererIsNeeded(style); + + return false; +} + +} + +#endif // ENABLE(SVG) + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGTSpanElement.h b/Source/WebCore/svg/SVGTSpanElement.h new file mode 100644 index 0000000..58a7990 --- /dev/null +++ b/Source/WebCore/svg/SVGTSpanElement.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGTSpanElement_h +#define SVGTSpanElement_h + +#if ENABLE(SVG) +#include "SVGTextPositioningElement.h" + +namespace WebCore { + +class SVGTSpanElement : public SVGTextPositioningElement { +public: + static PassRefPtr<SVGTSpanElement> create(const QualifiedName&, Document*); + +private: + SVGTSpanElement(const QualifiedName&, Document*); + + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + virtual bool childShouldCreateRenderer(Node*) const; + virtual bool rendererIsNeeded(RenderStyle*); +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGTSpanElement.idl b/Source/WebCore/svg/SVGTSpanElement.idl new file mode 100644 index 0000000..14cdcae --- /dev/null +++ b/Source/WebCore/svg/SVGTSpanElement.idl @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGTSpanElement : SVGTextPositioningElement { + }; + +} diff --git a/Source/WebCore/svg/SVGTests.cpp b/Source/WebCore/svg/SVGTests.cpp new file mode 100644 index 0000000..eb92981 --- /dev/null +++ b/Source/WebCore/svg/SVGTests.cpp @@ -0,0 +1,172 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGTests.h" + +#include "Attribute.h" +#include "DOMImplementation.h" +#include "Language.h" +#include "SVGElement.h" +#include "SVGNames.h" +#include "SVGStringList.h" + +namespace WebCore { + +SVGTests::SVGTests() + : m_requiredFeatures(SVGNames::requiredFeaturesAttr) + , m_requiredExtensions(SVGNames::requiredExtensionsAttr) + , m_systemLanguage(SVGNames::systemLanguageAttr) +{ +} + +bool SVGTests::hasExtension(const String&) const +{ + // FIXME: Implement me! + return false; +} + +bool SVGTests::isValid() const +{ + unsigned featuresSize = m_requiredFeatures.value.size(); + for (unsigned i = 0; i < featuresSize; ++i) { + String value = m_requiredFeatures.value.at(i); + if (value.isEmpty() || !DOMImplementation::hasFeature(value, String())) + return false; + } + + unsigned systemLanguageSize = m_systemLanguage.value.size(); + for (unsigned i = 0; i < systemLanguageSize; ++i) { + String value = m_systemLanguage.value.at(i); + if (value != defaultLanguage().substring(0, 2)) + return false; + } + + if (!m_requiredExtensions.value.isEmpty()) + return false; + + return true; +} + +bool SVGTests::parseMappedAttribute(Attribute* attr) +{ + if (attr->name() == SVGNames::requiredFeaturesAttr) { + m_requiredFeatures.value.reset(attr->value()); + return true; + } + if (attr->name() == SVGNames::requiredExtensionsAttr) { + m_requiredExtensions.value.reset(attr->value()); + return true; + } + if (attr->name() == SVGNames::systemLanguageAttr) { + m_systemLanguage.value.reset(attr->value()); + return true; + } + + return false; +} + +bool SVGTests::isKnownAttribute(const QualifiedName& attrName) +{ + return attrName == SVGNames::requiredFeaturesAttr + || attrName == SVGNames::requiredExtensionsAttr + || attrName == SVGNames::systemLanguageAttr; +} + +bool SVGTests::handleAttributeChange(const SVGElement* targetElement, const QualifiedName& attrName) +{ + if (!isKnownAttribute(attrName)) + return false; + if (!targetElement->inDocument()) + return false; + SVGElement* svgElement = const_cast<SVGElement*>(targetElement); + ASSERT(svgElement); + bool valid = svgElement->isValid(); + if (valid && !svgElement->attached()) + svgElement->attach(); + if (!valid && svgElement->attached()) + svgElement->detach(); + return true; +} + +void SVGTests::synchronizeProperties(SVGElement* contextElement, const QualifiedName& attrName) +{ + if (attrName == anyQName()) { + synchronizeRequiredFeatures(contextElement); + synchronizeRequiredExtensions(contextElement); + synchronizeSystemLanguage(contextElement); + return; + } + + if (attrName == SVGNames::requiredFeaturesAttr) + synchronizeRequiredFeatures(contextElement); + else if (attrName == SVGNames::requiredExtensionsAttr) + synchronizeRequiredExtensions(contextElement); + else if (attrName == SVGNames::systemLanguageAttr) + synchronizeSystemLanguage(contextElement); +} + +void SVGTests::synchronizeRequiredFeatures(SVGElement* contextElement) +{ + if (!m_requiredFeatures.shouldSynchronize) + return; + AtomicString value(m_requiredFeatures.value.valueAsString()); + SVGAnimatedPropertySynchronizer<true>::synchronize(contextElement, SVGNames::requiredFeaturesAttr, value); +} + +void SVGTests::synchronizeRequiredExtensions(SVGElement* contextElement) +{ + if (!m_requiredExtensions.shouldSynchronize) + return; + AtomicString value(m_requiredExtensions.value.valueAsString()); + SVGAnimatedPropertySynchronizer<true>::synchronize(contextElement, SVGNames::requiredExtensionsAttr, value); +} + +void SVGTests::synchronizeSystemLanguage(SVGElement* contextElement) +{ + if (!m_systemLanguage.shouldSynchronize) + return; + AtomicString value(m_systemLanguage.value.valueAsString()); + SVGAnimatedPropertySynchronizer<true>::synchronize(contextElement, SVGNames::systemLanguageAttr, value); +} + +SVGStringList& SVGTests::requiredFeatures() +{ + m_requiredFeatures.shouldSynchronize = true; + return m_requiredFeatures.value; +} + +SVGStringList& SVGTests::requiredExtensions() +{ + m_requiredExtensions.shouldSynchronize = true; + return m_requiredExtensions.value; +} + +SVGStringList& SVGTests::systemLanguage() +{ + m_systemLanguage.shouldSynchronize = true; + return m_systemLanguage.value; +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGTests.h b/Source/WebCore/svg/SVGTests.h new file mode 100644 index 0000000..8160955 --- /dev/null +++ b/Source/WebCore/svg/SVGTests.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2010 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGTests_h +#define SVGTests_h + +#if ENABLE(SVG) +#include "SVGAnimatedPropertyMacros.h" +#include "SVGStringList.h" + +namespace WebCore { + +class Attribute; +class QualifiedName; +class SVGElement; + +class SVGTests { +public: + SVGStringList& requiredFeatures(); + SVGStringList& requiredExtensions(); + SVGStringList& systemLanguage(); + + bool hasExtension(const String&) const; + bool isValid() const; + + bool parseMappedAttribute(Attribute*); + bool isKnownAttribute(const QualifiedName&); + + bool handleAttributeChange(const SVGElement*, const QualifiedName&); + void synchronizeProperties(SVGElement*, const QualifiedName&); + +protected: + SVGTests(); + +private: + void synchronizeRequiredFeatures(SVGElement*); + void synchronizeRequiredExtensions(SVGElement*); + void synchronizeSystemLanguage(SVGElement*); + + SVGSynchronizableAnimatedProperty<SVGStringList> m_requiredFeatures; + SVGSynchronizableAnimatedProperty<SVGStringList> m_requiredExtensions; + SVGSynchronizableAnimatedProperty<SVGStringList> m_systemLanguage; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGTests_h diff --git a/Source/WebCore/svg/SVGTests.idl b/Source/WebCore/svg/SVGTests.idl new file mode 100644 index 0000000..3508a98 --- /dev/null +++ b/Source/WebCore/svg/SVGTests.idl @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG, ObjCProtocol, OmitConstructor] SVGTests { + readonly attribute SVGStringList requiredFeatures; + readonly attribute SVGStringList requiredExtensions; + readonly attribute SVGStringList systemLanguage; + + boolean hasExtension(in DOMString extension); + }; + +} diff --git a/Source/WebCore/svg/SVGTextContentElement.cpp b/Source/WebCore/svg/SVGTextContentElement.cpp new file mode 100644 index 0000000..de75f5b --- /dev/null +++ b/Source/WebCore/svg/SVGTextContentElement.cpp @@ -0,0 +1,263 @@ +/* + * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007, 2008 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGTextContentElement.h" + +#include "CSSPropertyNames.h" +#include "CSSValueKeywords.h" +#include "Frame.h" +#include "RenderObject.h" +#include "SVGNames.h" +#include "SVGTextQuery.h" +#include "SelectionController.h" +#include "XMLNames.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_LENGTH(SVGTextContentElement, SVGNames::textLengthAttr, TextLength, textLength) +DEFINE_ANIMATED_ENUMERATION(SVGTextContentElement, SVGNames::lengthAdjustAttr, LengthAdjust, lengthAdjust) +DEFINE_ANIMATED_BOOLEAN(SVGTextContentElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) + +SVGTextContentElement::SVGTextContentElement(const QualifiedName& tagName, Document* document) + : SVGStyledElement(tagName, document) + , m_textLength(LengthModeOther) + , m_lengthAdjust(LENGTHADJUST_SPACING) +{ +} + +unsigned SVGTextContentElement::getNumberOfChars() const +{ + document()->updateLayoutIgnorePendingStylesheets(); + return SVGTextQuery(renderer()).numberOfCharacters(); +} + +float SVGTextContentElement::getComputedTextLength() const +{ + document()->updateLayoutIgnorePendingStylesheets(); + return SVGTextQuery(renderer()).textLength(); +} + +float SVGTextContentElement::getSubStringLength(unsigned charnum, unsigned nchars, ExceptionCode& ec) const +{ + document()->updateLayoutIgnorePendingStylesheets(); + + unsigned numberOfChars = getNumberOfChars(); + if (charnum >= numberOfChars) { + ec = INDEX_SIZE_ERR; + return 0.0f; + } + + return SVGTextQuery(renderer()).subStringLength(charnum, nchars); +} + +FloatPoint SVGTextContentElement::getStartPositionOfChar(unsigned charnum, ExceptionCode& ec) const +{ + document()->updateLayoutIgnorePendingStylesheets(); + + if (charnum > getNumberOfChars()) { + ec = INDEX_SIZE_ERR; + return FloatPoint(); + } + + return SVGTextQuery(renderer()).startPositionOfCharacter(charnum); +} + +FloatPoint SVGTextContentElement::getEndPositionOfChar(unsigned charnum, ExceptionCode& ec) const +{ + document()->updateLayoutIgnorePendingStylesheets(); + + if (charnum > getNumberOfChars()) { + ec = INDEX_SIZE_ERR; + return FloatPoint(); + } + + return SVGTextQuery(renderer()).endPositionOfCharacter(charnum); +} + +FloatRect SVGTextContentElement::getExtentOfChar(unsigned charnum, ExceptionCode& ec) const +{ + document()->updateLayoutIgnorePendingStylesheets(); + + if (charnum > getNumberOfChars()) { + ec = INDEX_SIZE_ERR; + return FloatRect(); + } + + return SVGTextQuery(renderer()).extentOfCharacter(charnum); +} + +float SVGTextContentElement::getRotationOfChar(unsigned charnum, ExceptionCode& ec) const +{ + document()->updateLayoutIgnorePendingStylesheets(); + + if (charnum > getNumberOfChars()) { + ec = INDEX_SIZE_ERR; + return 0.0f; + } + + return SVGTextQuery(renderer()).rotationOfCharacter(charnum); +} + +int SVGTextContentElement::getCharNumAtPosition(const FloatPoint& point) const +{ + document()->updateLayoutIgnorePendingStylesheets(); + return SVGTextQuery(renderer()).characterNumberAtPosition(point); +} + +void SVGTextContentElement::selectSubString(unsigned charnum, unsigned nchars, ExceptionCode& ec) const +{ + unsigned numberOfChars = getNumberOfChars(); + if (charnum >= numberOfChars) { + ec = INDEX_SIZE_ERR; + return; + } + + if (nchars > numberOfChars - charnum) + nchars = numberOfChars - charnum; + + ASSERT(document()); + ASSERT(document()->frame()); + + SelectionController* controller = document()->frame()->selection(); + if (!controller) + return; + + // Find selection start + VisiblePosition start(const_cast<SVGTextContentElement*>(this), 0, SEL_DEFAULT_AFFINITY); + for (unsigned i = 0; i < charnum; ++i) + start = start.next(); + + // Find selection end + VisiblePosition end(start); + for (unsigned i = 0; i < nchars; ++i) + end = end.next(); + + controller->setSelection(VisibleSelection(start, end)); +} + +void SVGTextContentElement::parseMappedAttribute(Attribute* attr) +{ + if (attr->name() == SVGNames::lengthAdjustAttr) { + if (attr->value() == "spacing") + setLengthAdjustBaseValue(LENGTHADJUST_SPACING); + else if (attr->value() == "spacingAndGlyphs") + setLengthAdjustBaseValue(LENGTHADJUST_SPACINGANDGLYPHS); + } else if (attr->name() == SVGNames::textLengthAttr) { + setTextLengthBaseValue(SVGLength(LengthModeOther, attr->value())); + if (textLengthBaseValue().value(this) < 0.0) + document()->accessSVGExtensions()->reportError("A negative value for text attribute <textLength> is not allowed"); + } else { + if (SVGTests::parseMappedAttribute(attr)) + return; + if (SVGLangSpace::parseMappedAttribute(attr)) { + if (attr->name().matches(XMLNames::spaceAttr)) { + DEFINE_STATIC_LOCAL(const AtomicString, preserveString, ("preserve")); + + if (attr->value() == preserveString) + addCSSProperty(attr, CSSPropertyWhiteSpace, CSSValuePre); + else + addCSSProperty(attr, CSSPropertyWhiteSpace, CSSValueNowrap); + } + return; + } + if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) + return; + + SVGStyledElement::parseMappedAttribute(attr); + } +} + +void SVGTextContentElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGStyledElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeLengthAdjust(); + synchronizeTextLength(); + synchronizeExternalResourcesRequired(); + SVGTests::synchronizeProperties(this, attrName); + return; + } + + if (attrName == SVGNames::lengthAdjustAttr) + synchronizeLengthAdjust(); + else if (attrName == SVGNames::textLengthAttr) + synchronizeTextLength(); + else if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) + synchronizeExternalResourcesRequired(); + else if (SVGTests::isKnownAttribute(attrName)) + SVGTests::synchronizeProperties(this, attrName); +} + +void SVGTextContentElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGStyledElement::svgAttributeChanged(attrName); + + if (SVGTests::handleAttributeChange(this, attrName)) + return; + + // FIXME: also handle attribute changes for lengthAdjust and textLength +} + +bool SVGTextContentElement::isKnownAttribute(const QualifiedName& attrName) +{ + return attrName.matches(SVGNames::lengthAdjustAttr) + || attrName.matches(SVGNames::textLengthAttr) + || SVGLangSpace::isKnownAttribute(attrName) + || SVGExternalResourcesRequired::isKnownAttribute(attrName) + || SVGStyledElement::isKnownAttribute(attrName); +} + +bool SVGTextContentElement::selfHasRelativeLengths() const +{ + return textLength().isRelative(); +} + +SVGTextContentElement* SVGTextContentElement::elementFromRenderer(RenderObject* renderer) +{ + if (!renderer) + return 0; + + if (!renderer->isSVGText() && !renderer->isSVGInline()) + return 0; + + Node* node = renderer->node(); + ASSERT(node); + ASSERT(node->isSVGElement()); + + if (!node->hasTagName(SVGNames::textTag) + && !node->hasTagName(SVGNames::tspanTag) +#if ENABLE(SVG_FONTS) + && !node->hasTagName(SVGNames::altGlyphTag) +#endif + && !node->hasTagName(SVGNames::trefTag) + && !node->hasTagName(SVGNames::textPathTag)) + return 0; + + return static_cast<SVGTextContentElement*>(node); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGTextContentElement.h b/Source/WebCore/svg/SVGTextContentElement.h new file mode 100644 index 0000000..60b023b --- /dev/null +++ b/Source/WebCore/svg/SVGTextContentElement.h @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2008 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGTextContentElement_h +#define SVGTextContentElement_h + +#if ENABLE(SVG) +#include "SVGAnimatedBoolean.h" +#include "SVGAnimatedEnumeration.h" +#include "SVGAnimatedLength.h" +#include "SVGExternalResourcesRequired.h" +#include "SVGLangSpace.h" +#include "SVGStyledElement.h" +#include "SVGTests.h" + +namespace WebCore { + +class SVGTextContentElement : public SVGStyledElement, + public SVGTests, + public SVGLangSpace, + public SVGExternalResourcesRequired { +public: + enum SVGLengthAdjustType { + LENGTHADJUST_UNKNOWN = 0, + LENGTHADJUST_SPACING = 1, + LENGTHADJUST_SPACINGANDGLYPHS = 2 + }; + + unsigned getNumberOfChars() const; + float getComputedTextLength() const; + float getSubStringLength(unsigned charnum, unsigned nchars, ExceptionCode&) const; + FloatPoint getStartPositionOfChar(unsigned charnum, ExceptionCode&) const; + FloatPoint getEndPositionOfChar(unsigned charnum, ExceptionCode&) const; + FloatRect getExtentOfChar(unsigned charnum, ExceptionCode&) const; + float getRotationOfChar(unsigned charnum, ExceptionCode&) const; + int getCharNumAtPosition(const FloatPoint&) const; + void selectSubString(unsigned charnum, unsigned nchars, ExceptionCode&) const; + + bool isKnownAttribute(const QualifiedName&); + + static SVGTextContentElement* elementFromRenderer(RenderObject*); + +protected: + SVGTextContentElement(const QualifiedName&, Document*); + + virtual bool isValid() const { return SVGTests::isValid(); } + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + + virtual bool selfHasRelativeLengths() const; + +private: + virtual bool isTextContent() const { return true; } + + // Animated property declarations + DECLARE_ANIMATED_LENGTH(TextLength, textLength) + DECLARE_ANIMATED_ENUMERATION(LengthAdjust, lengthAdjust) + + // SVGExternalResourcesRequired + DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGTextContentElement.idl b/Source/WebCore/svg/SVGTextContentElement.idl new file mode 100644 index 0000000..400b184 --- /dev/null +++ b/Source/WebCore/svg/SVGTextContentElement.idl @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGTextContentElement : SVGElement, + SVGTests, + SVGLangSpace, + SVGExternalResourcesRequired, + SVGStylable { + // lengthAdjust Types + const unsigned short LENGTHADJUST_UNKNOWN = 0; + const unsigned short LENGTHADJUST_SPACING = 1; + const unsigned short LENGTHADJUST_SPACINGANDGLYPHS = 2; + + readonly attribute SVGAnimatedLength textLength; + readonly attribute SVGAnimatedEnumeration lengthAdjust; + + long getNumberOfChars(); + float getComputedTextLength(); + float getSubStringLength(in [IsIndex] unsigned long offset, + in [IsIndex] unsigned long length) + raises(DOMException); + SVGPoint getStartPositionOfChar(in [IsIndex] unsigned long offset) + raises(DOMException); + SVGPoint getEndPositionOfChar(in [IsIndex] unsigned long offset) + raises(DOMException); + SVGRect getExtentOfChar(in [IsIndex] unsigned long offset) + raises(DOMException); + float getRotationOfChar(in [IsIndex] unsigned long offset) + raises(DOMException); + long getCharNumAtPosition(in SVGPoint point); + void selectSubString(in [IsIndex] unsigned long offset, + in [IsIndex] unsigned long length) + raises(DOMException); + }; + +} diff --git a/Source/WebCore/svg/SVGTextElement.cpp b/Source/WebCore/svg/SVGTextElement.cpp new file mode 100644 index 0000000..7229824 --- /dev/null +++ b/Source/WebCore/svg/SVGTextElement.cpp @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2008 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGTextElement.h" + +#include "AffineTransform.h" +#include "Attribute.h" +#include "FloatRect.h" +#include "RenderSVGResource.h" +#include "RenderSVGText.h" +#include "SVGNames.h" +#include "SVGRenderStyle.h" +#include "SVGTSpanElement.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_TRANSFORM_LIST(SVGTextElement, SVGNames::transformAttr, Transform, transform) + +inline SVGTextElement::SVGTextElement(const QualifiedName& tagName, Document* doc) + : SVGTextPositioningElement(tagName, doc) +{ +} + +PassRefPtr<SVGTextElement> SVGTextElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGTextElement(tagName, document)); +} + +void SVGTextElement::parseMappedAttribute(Attribute* attr) +{ + if (SVGTransformable::isKnownAttribute(attr->name())) { + SVGTransformList newList; + if (!SVGTransformable::parseTransformAttribute(newList, attr->value())) + newList.clear(); + + detachAnimatedTransformListWrappers(newList.size()); + setTransformBaseValue(newList); + } else + SVGTextPositioningElement::parseMappedAttribute(attr); +} + +SVGElement* SVGTextElement::nearestViewportElement() const +{ + return SVGTransformable::nearestViewportElement(this); +} + +SVGElement* SVGTextElement::farthestViewportElement() const +{ + return SVGTransformable::farthestViewportElement(this); +} + +FloatRect SVGTextElement::getBBox(StyleUpdateStrategy styleUpdateStrategy) const +{ + return SVGTransformable::getBBox(this, styleUpdateStrategy); +} + +AffineTransform SVGTextElement::getCTM(StyleUpdateStrategy styleUpdateStrategy) const +{ + return SVGLocatable::computeCTM(this, SVGLocatable::NearestViewportScope, styleUpdateStrategy); +} + +AffineTransform SVGTextElement::getScreenCTM(StyleUpdateStrategy styleUpdateStrategy) const +{ + return SVGLocatable::computeCTM(this, SVGLocatable::ScreenScope, styleUpdateStrategy); +} + +AffineTransform SVGTextElement::animatedLocalTransform() const +{ + AffineTransform matrix; + transform().concatenate(matrix); + return m_supplementalTransform ? *m_supplementalTransform * matrix : matrix; +} + +AffineTransform* SVGTextElement::supplementalTransform() +{ + if (!m_supplementalTransform) + m_supplementalTransform.set(new AffineTransform()); + return m_supplementalTransform.get(); +} + +RenderObject* SVGTextElement::createRenderer(RenderArena* arena, RenderStyle*) +{ + return new (arena) RenderSVGText(this); +} + +bool SVGTextElement::childShouldCreateRenderer(Node* child) const +{ + if (child->isTextNode() + || child->hasTagName(SVGNames::aTag) +#if ENABLE(SVG_FONTS) + || child->hasTagName(SVGNames::altGlyphTag) +#endif + || child->hasTagName(SVGNames::textPathTag) + || child->hasTagName(SVGNames::trefTag) + || child->hasTagName(SVGNames::tspanTag)) + return true; + + return false; +} + +void SVGTextElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGTextPositioningElement::svgAttributeChanged(attrName); + + RenderObject* renderer = this->renderer(); + if (!renderer) + return; + + if (SVGTransformable::isKnownAttribute(attrName)) { + renderer->setNeedsTransformUpdate(); + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); + } +} + +void SVGTextElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGTextPositioningElement::synchronizeProperty(attrName); + + if (attrName == anyQName() || SVGTransformable::isKnownAttribute(attrName)) + synchronizeTransform(); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGTextElement.h b/Source/WebCore/svg/SVGTextElement.h new file mode 100644 index 0000000..8dda8c6 --- /dev/null +++ b/Source/WebCore/svg/SVGTextElement.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2008 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGTextElement_h +#define SVGTextElement_h + +#if ENABLE(SVG) +#include "SVGAnimatedTransformList.h" +#include "SVGTextPositioningElement.h" +#include "SVGTransformable.h" + +namespace WebCore { + +class SVGTextElement : public SVGTextPositioningElement, + public SVGTransformable { +public: + static PassRefPtr<SVGTextElement> create(const QualifiedName&, Document*); + + virtual SVGElement* nearestViewportElement() const; + virtual SVGElement* farthestViewportElement() const; + + virtual FloatRect getBBox(StyleUpdateStrategy = AllowStyleUpdate) const; + virtual AffineTransform getCTM(StyleUpdateStrategy = AllowStyleUpdate) const; + virtual AffineTransform getScreenCTM(StyleUpdateStrategy = AllowStyleUpdate) const; + virtual AffineTransform animatedLocalTransform() const; + +private: + SVGTextElement(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + + virtual AffineTransform* supplementalTransform(); + virtual AffineTransform localCoordinateSpaceTransform(SVGLocatable::CTMScope mode) const { return SVGTransformable::localCoordinateSpaceTransform(mode); } + + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + virtual bool childShouldCreateRenderer(Node*) const; + + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + + // Animated property declarations + DECLARE_ANIMATED_TRANSFORM_LIST(Transform, transform) + + // Used by <animateMotion> + OwnPtr<AffineTransform> m_supplementalTransform; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGTextElement.idl b/Source/WebCore/svg/SVGTextElement.idl new file mode 100644 index 0000000..0867d81 --- /dev/null +++ b/Source/WebCore/svg/SVGTextElement.idl @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGTextElement : SVGTextPositioningElement, + SVGTransformable { + }; + +} diff --git a/Source/WebCore/svg/SVGTextPathElement.cpp b/Source/WebCore/svg/SVGTextPathElement.cpp new file mode 100644 index 0000000..9935b43 --- /dev/null +++ b/Source/WebCore/svg/SVGTextPathElement.cpp @@ -0,0 +1,159 @@ +/* + * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2010 Rob Buis <rwlbuis@gmail.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGTextPathElement.h" + +#include "Attribute.h" +#include "RenderSVGResource.h" +#include "RenderSVGTextPath.h" +#include "SVGNames.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_LENGTH(SVGTextPathElement, SVGNames::startOffsetAttr, StartOffset, startOffset) +DEFINE_ANIMATED_ENUMERATION(SVGTextPathElement, SVGNames::methodAttr, Method, method) +DEFINE_ANIMATED_ENUMERATION(SVGTextPathElement, SVGNames::spacingAttr, Spacing, spacing) +DEFINE_ANIMATED_STRING(SVGTextPathElement, XLinkNames::hrefAttr, Href, href) + +inline SVGTextPathElement::SVGTextPathElement(const QualifiedName& tagName, Document* document) + : SVGTextContentElement(tagName, document) + , m_startOffset(LengthModeOther) + , m_method(SVG_TEXTPATH_METHODTYPE_ALIGN) + , m_spacing(SVG_TEXTPATH_SPACINGTYPE_EXACT) +{ +} + +PassRefPtr<SVGTextPathElement> SVGTextPathElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGTextPathElement(tagName, document)); +} + +void SVGTextPathElement::parseMappedAttribute(Attribute* attr) +{ + const String& value = attr->value(); + + if (attr->name() == SVGNames::startOffsetAttr) + setStartOffsetBaseValue(SVGLength(LengthModeOther, value)); + else if (attr->name() == SVGNames::methodAttr) { + if (value == "align") + setSpacingBaseValue(SVG_TEXTPATH_METHODTYPE_ALIGN); + else if (value == "stretch") + setSpacingBaseValue(SVG_TEXTPATH_METHODTYPE_STRETCH); + } else if (attr->name() == SVGNames::spacingAttr) { + if (value == "auto") + setMethodBaseValue(SVG_TEXTPATH_SPACINGTYPE_AUTO); + else if (value == "exact") + setMethodBaseValue(SVG_TEXTPATH_SPACINGTYPE_EXACT); + } else { + if (SVGURIReference::parseMappedAttribute(attr)) + return; + SVGTextContentElement::parseMappedAttribute(attr); + } +} + +void SVGTextPathElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGTextContentElement::svgAttributeChanged(attrName); + + if (attrName == SVGNames::startOffsetAttr) + updateRelativeLengthsInformation(); + + if (!renderer()) + return; + + if (attrName == SVGNames::startOffsetAttr + || SVGTextContentElement::isKnownAttribute(attrName) + || SVGURIReference::isKnownAttribute(attrName)) + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer()); +} + +void SVGTextPathElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGTextContentElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeStartOffset(); + synchronizeMethod(); + synchronizeSpacing(); + synchronizeHref(); + return; + } + + if (attrName == SVGNames::startOffsetAttr) + synchronizeStartOffset(); + else if (attrName == SVGNames::methodAttr) + synchronizeMethod(); + else if (attrName == SVGNames::spacingAttr) + synchronizeSpacing(); + else if (SVGURIReference::isKnownAttribute(attrName)) + synchronizeHref(); +} + +RenderObject* SVGTextPathElement::createRenderer(RenderArena* arena, RenderStyle*) +{ + return new (arena) RenderSVGTextPath(this); +} + +bool SVGTextPathElement::childShouldCreateRenderer(Node* child) const +{ + if (child->isTextNode() + || child->hasTagName(SVGNames::aTag) + || child->hasTagName(SVGNames::trefTag) + || child->hasTagName(SVGNames::tspanTag)) + return true; + + return false; +} + +bool SVGTextPathElement::rendererIsNeeded(RenderStyle* style) +{ + if (parentNode() + && (parentNode()->hasTagName(SVGNames::aTag) + || parentNode()->hasTagName(SVGNames::textTag))) + return StyledElement::rendererIsNeeded(style); + + return false; +} + +void SVGTextPathElement::insertedIntoDocument() +{ + SVGTextContentElement::insertedIntoDocument(); + + String id = SVGURIReference::getTarget(href()); + Element* targetElement = ownerDocument()->getElementById(id); + if (!targetElement) { + document()->accessSVGExtensions()->addPendingResource(id, this); + return; + } +} + +bool SVGTextPathElement::selfHasRelativeLengths() const +{ + return startOffset().isRelative() + || SVGTextContentElement::selfHasRelativeLengths(); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGTextPathElement.h b/Source/WebCore/svg/SVGTextPathElement.h new file mode 100644 index 0000000..6c372f9 --- /dev/null +++ b/Source/WebCore/svg/SVGTextPathElement.h @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGTextPathElement_h +#define SVGTextPathElement_h + +#if ENABLE(SVG) +#include "SVGTextContentElement.h" + +#include "SVGURIReference.h" + +namespace WebCore { + +enum SVGTextPathMethodType { + SVG_TEXTPATH_METHODTYPE_UNKNOWN = 0, + SVG_TEXTPATH_METHODTYPE_ALIGN = 1, + SVG_TEXTPATH_METHODTYPE_STRETCH = 2 +}; + +enum SVGTextPathSpacingType { + SVG_TEXTPATH_SPACINGTYPE_UNKNOWN = 0, + SVG_TEXTPATH_SPACINGTYPE_AUTO = 1, + SVG_TEXTPATH_SPACINGTYPE_EXACT = 2 +}; + +class SVGTextPathElement : public SVGTextContentElement, + public SVGURIReference { +public: + // Forward declare these enums in the w3c naming scheme, for IDL generation + enum { + TEXTPATH_METHODTYPE_UNKNOWN = SVG_TEXTPATH_METHODTYPE_UNKNOWN, + TEXTPATH_METHODTYPE_ALIGN = SVG_TEXTPATH_METHODTYPE_ALIGN, + TEXTPATH_METHODTYPE_STRETCH = SVG_TEXTPATH_METHODTYPE_STRETCH, + TEXTPATH_SPACINGTYPE_UNKNOWN = SVG_TEXTPATH_SPACINGTYPE_UNKNOWN, + TEXTPATH_SPACINGTYPE_AUTO = SVG_TEXTPATH_SPACINGTYPE_AUTO, + TEXTPATH_SPACINGTYPE_EXACT = SVG_TEXTPATH_SPACINGTYPE_EXACT + }; + + static PassRefPtr<SVGTextPathElement> create(const QualifiedName&, Document*); + +private: + SVGTextPathElement(const QualifiedName&, Document*); + + virtual void insertedIntoDocument(); + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + virtual bool childShouldCreateRenderer(Node*) const; + virtual bool rendererIsNeeded(RenderStyle*); + + virtual bool selfHasRelativeLengths() const; + + // Animated property declarations + DECLARE_ANIMATED_LENGTH(StartOffset, startOffset) + DECLARE_ANIMATED_ENUMERATION(Method, method) + DECLARE_ANIMATED_ENUMERATION(Spacing, spacing) + + // SVGURIReference + DECLARE_ANIMATED_STRING(Href, href) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGTextPathElement.idl b/Source/WebCore/svg/SVGTextPathElement.idl new file mode 100644 index 0000000..b8c6e7d --- /dev/null +++ b/Source/WebCore/svg/SVGTextPathElement.idl @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> + * + * 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGTextPathElement : SVGTextContentElement, + SVGURIReference { + // textPath Method Types + const unsigned short TEXTPATH_METHODTYPE_UNKNOWN = 0; + const unsigned short TEXTPATH_METHODTYPE_ALIGN = 1; + const unsigned short TEXTPATH_METHODTYPE_STRETCH = 2; + + // textPath Spacing Types + const unsigned short TEXTPATH_SPACINGTYPE_UNKNOWN = 0; + const unsigned short TEXTPATH_SPACINGTYPE_AUTO = 1; + const unsigned short TEXTPATH_SPACINGTYPE_EXACT = 2; + + readonly attribute SVGAnimatedLength startOffset; + readonly attribute SVGAnimatedEnumeration method; + readonly attribute SVGAnimatedEnumeration spacing; + }; + +} diff --git a/Source/WebCore/svg/SVGTextPositioningElement.cpp b/Source/WebCore/svg/SVGTextPositioningElement.cpp new file mode 100644 index 0000000..544d192 --- /dev/null +++ b/Source/WebCore/svg/SVGTextPositioningElement.cpp @@ -0,0 +1,216 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007, 2008 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGTextPositioningElement.h" + +#include "Attribute.h" +#include "RenderSVGResource.h" +#include "RenderSVGText.h" +#include "SVGLengthList.h" +#include "SVGNames.h" +#include "SVGNumberList.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_LENGTH_LIST(SVGTextPositioningElement, SVGNames::xAttr, X, x) +DEFINE_ANIMATED_LENGTH_LIST(SVGTextPositioningElement, SVGNames::yAttr, Y, y) +DEFINE_ANIMATED_LENGTH_LIST(SVGTextPositioningElement, SVGNames::dxAttr, Dx, dx) +DEFINE_ANIMATED_LENGTH_LIST(SVGTextPositioningElement, SVGNames::dyAttr, Dy, dy) +DEFINE_ANIMATED_NUMBER_LIST(SVGTextPositioningElement, SVGNames::rotateAttr, Rotate, rotate) + +SVGTextPositioningElement::SVGTextPositioningElement(const QualifiedName& tagName, Document* document) + : SVGTextContentElement(tagName, document) +{ +} + +void SVGTextPositioningElement::parseMappedAttribute(Attribute* attr) +{ + if (attr->name() == SVGNames::xAttr) { + SVGLengthList newList; + newList.parse(attr->value(), LengthModeWidth); + detachAnimatedXListWrappers(newList.size()); + setXBaseValue(newList); + } else if (attr->name() == SVGNames::yAttr) { + SVGLengthList newList; + newList.parse(attr->value(), LengthModeHeight); + detachAnimatedYListWrappers(newList.size()); + setYBaseValue(newList); + } else if (attr->name() == SVGNames::dxAttr) { + SVGLengthList newList; + newList.parse(attr->value(), LengthModeWidth); + detachAnimatedDxListWrappers(newList.size()); + setDxBaseValue(newList); + } else if (attr->name() == SVGNames::dyAttr) { + SVGLengthList newList; + newList.parse(attr->value(), LengthModeHeight); + detachAnimatedDyListWrappers(newList.size()); + setDyBaseValue(newList); + } else if (attr->name() == SVGNames::rotateAttr) { + SVGNumberList newList; + newList.parse(attr->value()); + detachAnimatedRotateListWrappers(newList.size()); + setRotateBaseValue(newList); + } else + SVGTextContentElement::parseMappedAttribute(attr); +} + +static inline void updatePositioningValuesInRenderer(RenderObject* renderer) +{ + RenderSVGText* textRenderer = 0; + + if (renderer->isSVGText()) + textRenderer = toRenderSVGText(renderer); + else { + // Locate RenderSVGText parent renderer. + RenderObject* parent = renderer->parent(); + while (parent && !parent->isSVGText()) + parent = parent->parent(); + + if (parent) { + ASSERT(parent->isSVGText()); + textRenderer = toRenderSVGText(parent); + } + } + + if (!textRenderer) + return; + + textRenderer->setNeedsPositioningValuesUpdate(); +} + +void SVGTextPositioningElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGTextContentElement::svgAttributeChanged(attrName); + + bool updateRelativeLengths = attrName == SVGNames::xAttr + || attrName == SVGNames::yAttr + || attrName == SVGNames::dxAttr + || attrName == SVGNames::dyAttr; + + if (updateRelativeLengths) + updateRelativeLengthsInformation(); + + RenderObject* renderer = this->renderer(); + if (!renderer) + return; + + if (updateRelativeLengths || attrName == SVGNames::rotateAttr) { + updatePositioningValuesInRenderer(renderer); + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); + return; + } + + if (SVGTextContentElement::isKnownAttribute(attrName)) + RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); +} + +void SVGTextPositioningElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) +{ + SVGTextContentElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); + + if (changedByParser) + return; + + if (RenderObject* object = renderer()) + updatePositioningValuesInRenderer(object); +} + +void SVGTextPositioningElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGTextContentElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeX(); + synchronizeY(); + synchronizeDx(); + synchronizeDy(); + synchronizeRotate(); + return; + } + + if (attrName == SVGNames::xAttr) + synchronizeX(); + else if (attrName == SVGNames::yAttr) + synchronizeY(); + else if (attrName == SVGNames::dxAttr) + synchronizeDx(); + else if (attrName == SVGNames::dyAttr) + synchronizeDy(); + else if (attrName == SVGNames::rotateAttr) + synchronizeRotate(); +} + +static inline bool listContainsRelativeValue(const SVGLengthList& list) +{ + unsigned size = list.size(); + for (unsigned i = 0; i < size; ++i) { + const SVGLength& length = list.at(i); + if (length.isRelative()) + return true; + } + + return false; +} + +bool SVGTextPositioningElement::selfHasRelativeLengths() const +{ + if (SVGTextContentElement::selfHasRelativeLengths()) + return true; + if (listContainsRelativeValue(x())) + return true; + if (listContainsRelativeValue(y())) + return true; + if (listContainsRelativeValue(dx())) + return true; + if (listContainsRelativeValue(dy())) + return true; + return false; +} + +SVGTextPositioningElement* SVGTextPositioningElement::elementFromRenderer(RenderObject* renderer) +{ + if (!renderer) + return 0; + + if (!renderer->isSVGText() && !renderer->isSVGInline()) + return 0; + + Node* node = renderer->node(); + ASSERT(node); + ASSERT(node->isSVGElement()); + + if (!node->hasTagName(SVGNames::textTag) + && !node->hasTagName(SVGNames::tspanTag) +#if ENABLE(SVG_FONTS) + && !node->hasTagName(SVGNames::altGlyphTag) +#endif + && !node->hasTagName(SVGNames::trefTag)) + return 0; + + return static_cast<SVGTextPositioningElement*>(node); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGTextPositioningElement.h b/Source/WebCore/svg/SVGTextPositioningElement.h new file mode 100644 index 0000000..e4bc4ea --- /dev/null +++ b/Source/WebCore/svg/SVGTextPositioningElement.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2008 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGTextPositioningElement_h +#define SVGTextPositioningElement_h + +#if ENABLE(SVG) +#include "SVGAnimatedLengthList.h" +#include "SVGAnimatedNumberList.h" +#include "SVGTextContentElement.h" + +namespace WebCore { + +class SVGTextPositioningElement : public SVGTextContentElement { +public: + static SVGTextPositioningElement* elementFromRenderer(RenderObject*); + +protected: + SVGTextPositioningElement(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + + virtual bool selfHasRelativeLengths() const; + + // Animated property declarations + DECLARE_ANIMATED_LENGTH_LIST(X, x) + DECLARE_ANIMATED_LENGTH_LIST(Y, y) + DECLARE_ANIMATED_LENGTH_LIST(Dx, dx) + DECLARE_ANIMATED_LENGTH_LIST(Dy, dy) + DECLARE_ANIMATED_NUMBER_LIST(Rotate, rotate) +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGTextPositioningElement.idl b/Source/WebCore/svg/SVGTextPositioningElement.idl new file mode 100644 index 0000000..6f5d1fa --- /dev/null +++ b/Source/WebCore/svg/SVGTextPositioningElement.idl @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGTextPositioningElement : SVGTextContentElement { + readonly attribute SVGAnimatedLengthList x; + readonly attribute SVGAnimatedLengthList y; + readonly attribute SVGAnimatedLengthList dx; + readonly attribute SVGAnimatedLengthList dy; + readonly attribute SVGAnimatedNumberList rotate; + }; + +} diff --git a/Source/WebCore/svg/SVGTitleElement.cpp b/Source/WebCore/svg/SVGTitleElement.cpp new file mode 100644 index 0000000..5eb2204 --- /dev/null +++ b/Source/WebCore/svg/SVGTitleElement.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#if ENABLE(SVG) +#include "SVGTitleElement.h" + +#include "Document.h" + +namespace WebCore { + +inline SVGTitleElement::SVGTitleElement(const QualifiedName& tagName, Document* document) + : SVGStyledElement(tagName, document) +{ +} + +PassRefPtr<SVGTitleElement> SVGTitleElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGTitleElement(tagName, document)); +} + +void SVGTitleElement::insertedIntoDocument() +{ + SVGStyledElement::insertedIntoDocument(); + if (firstChild()) + document()->setTitle(textContent(), this); +} + +void SVGTitleElement::removedFromDocument() +{ + SVGElement::removedFromDocument(); + document()->removeTitle(this); +} + +void SVGTitleElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) +{ + SVGElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); + if (inDocument()) + document()->setTitle(textContent(), this); +} + +} + +// vim:ts=4:noet +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGTitleElement.h b/Source/WebCore/svg/SVGTitleElement.h new file mode 100644 index 0000000..5d0762f --- /dev/null +++ b/Source/WebCore/svg/SVGTitleElement.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGTitleElement_h +#define SVGTitleElement_h +#if ENABLE(SVG) + +#include "SVGLangSpace.h" +#include "SVGStyledElement.h" + +namespace WebCore { + +class SVGTitleElement : public SVGStyledElement, + public SVGLangSpace { +public: + static PassRefPtr<SVGTitleElement> create(const QualifiedName&, Document*); + +private: + SVGTitleElement(const QualifiedName&, Document*); + + virtual void insertedIntoDocument(); + virtual void removedFromDocument(); + virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); + + virtual bool rendererIsNeeded(RenderStyle*) { return false; } +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGTitleElement.idl b/Source/WebCore/svg/SVGTitleElement.idl new file mode 100644 index 0000000..dde5ba2 --- /dev/null +++ b/Source/WebCore/svg/SVGTitleElement.idl @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGTitleElement : SVGElement, + SVGLangSpace, + SVGStylable { + }; + +} diff --git a/Source/WebCore/svg/SVGTransform.cpp b/Source/WebCore/svg/SVGTransform.cpp new file mode 100644 index 0000000..4878b57 --- /dev/null +++ b/Source/WebCore/svg/SVGTransform.cpp @@ -0,0 +1,169 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGTransform.h" + +#include "FloatConversion.h" +#include "FloatPoint.h" +#include "FloatSize.h" +#include "SVGAngle.h" +#include "SVGSVGElement.h" +#include <wtf/MathExtras.h> +#include <wtf/text/StringBuilder.h> +#include <wtf/text/StringConcatenate.h> + +namespace WebCore { + +SVGTransform::SVGTransform() + : m_type(SVG_TRANSFORM_UNKNOWN) + , m_angle(0) +{ +} + +SVGTransform::SVGTransform(SVGTransformType type) + : m_type(type) + , m_angle(0) +{ +} + +SVGTransform::SVGTransform(const AffineTransform& matrix) + : m_type(SVG_TRANSFORM_MATRIX) + , m_angle(0) + , m_matrix(matrix) +{ +} + +void SVGTransform::setMatrix(const AffineTransform& matrix) +{ + m_type = SVG_TRANSFORM_MATRIX; + m_angle = 0; + m_matrix = matrix; +} + +void SVGTransform::updateMatrix() +{ + // The underlying matrix has been changed, alter the transformation type. + // Spec: In case the matrix object is changed directly (i.e., without using the methods on the SVGTransform interface itself) + // then the type of the SVGTransform changes to SVG_TRANSFORM_MATRIX. + m_type = SVG_TRANSFORM_MATRIX; + m_angle = 0; +} + +void SVGTransform::setTranslate(float tx, float ty) +{ + m_type = SVG_TRANSFORM_TRANSLATE; + m_angle = 0; + + m_matrix.makeIdentity(); + m_matrix.translate(tx, ty); +} + +FloatPoint SVGTransform::translate() const +{ + return FloatPoint::narrowPrecision(m_matrix.e(), m_matrix.f()); +} + +void SVGTransform::setScale(float sx, float sy) +{ + m_type = SVG_TRANSFORM_SCALE; + m_angle = 0; + m_center = FloatPoint(); + + m_matrix.makeIdentity(); + m_matrix.scaleNonUniform(sx, sy); +} + +FloatSize SVGTransform::scale() const +{ + return FloatSize::narrowPrecision(m_matrix.a(), m_matrix.d()); +} + +void SVGTransform::setRotate(float angle, float cx, float cy) +{ + m_type = SVG_TRANSFORM_ROTATE; + m_angle = angle; + m_center = FloatPoint(cx, cy); + + // TODO: toString() implementation, which can show cx, cy (need to be stored?) + m_matrix.makeIdentity(); + m_matrix.translate(cx, cy); + m_matrix.rotate(angle); + m_matrix.translate(-cx, -cy); +} + +void SVGTransform::setSkewX(float angle) +{ + m_type = SVG_TRANSFORM_SKEWX; + m_angle = angle; + + m_matrix.makeIdentity(); + m_matrix.skewX(angle); +} + +void SVGTransform::setSkewY(float angle) +{ + m_type = SVG_TRANSFORM_SKEWY; + m_angle = angle; + + m_matrix.makeIdentity(); + m_matrix.skewY(angle); +} + +String SVGTransform::valueAsString() const +{ + switch (m_type) { + case SVG_TRANSFORM_UNKNOWN: + return String(); + case SVG_TRANSFORM_MATRIX: { + StringBuilder builder; + builder.append(makeString("matrix(", String::number(m_matrix.a()), ' ', String::number(m_matrix.b()), ' ', String::number(m_matrix.c()), ' ')); + builder.append(makeString(String::number(m_matrix.d()), ' ', String::number(m_matrix.e()), ' ', String::number(m_matrix.f()), ')')); + return builder.toString(); + } + case SVG_TRANSFORM_TRANSLATE: + return makeString("translate(", String::number(m_matrix.e()), ' ', String::number(m_matrix.f()), ')'); + case SVG_TRANSFORM_SCALE: + return makeString("scale(", String::number(m_matrix.xScale()), ' ', String::number(m_matrix.yScale()), ')'); + case SVG_TRANSFORM_ROTATE: { + double angleInRad = deg2rad(m_angle); + double cosAngle = cos(angleInRad); + double sinAngle = sin(angleInRad); + float cx = narrowPrecisionToFloat(cosAngle != 1 ? (m_matrix.e() * (1 - cosAngle) - m_matrix.f() * sinAngle) / (1 - cosAngle) / 2 : 0); + float cy = narrowPrecisionToFloat(cosAngle != 1 ? (m_matrix.e() * sinAngle / (1 - cosAngle) + m_matrix.f()) / 2 : 0); + if (cx || cy) + return makeString("rotate(", String::number(m_angle), ' ', String::number(cx), ' ', String::number(cy), ')'); + return makeString("rotate(", String::number(m_angle), ')'); + } + case SVG_TRANSFORM_SKEWX: + return makeString("skewX(", String::number(m_angle), ')'); + case SVG_TRANSFORM_SKEWY: + return makeString("skewY(", String::number(m_angle), ')'); + } + + ASSERT_NOT_REACHED(); + return String(); +} + +} // namespace WebCore + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGTransform.h b/Source/WebCore/svg/SVGTransform.h new file mode 100644 index 0000000..14718ae --- /dev/null +++ b/Source/WebCore/svg/SVGTransform.h @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGTransform_h +#define SVGTransform_h + +#if ENABLE(SVG) +#include "FloatPoint.h" +#include "SVGMatrix.h" + +namespace WebCore { + +class FloatSize; + +class SVGTransform { +public: + enum SVGTransformType { + SVG_TRANSFORM_UNKNOWN = 0, + SVG_TRANSFORM_MATRIX = 1, + SVG_TRANSFORM_TRANSLATE = 2, + SVG_TRANSFORM_SCALE = 3, + SVG_TRANSFORM_ROTATE = 4, + SVG_TRANSFORM_SKEWX = 5, + SVG_TRANSFORM_SKEWY = 6 + }; + + SVGTransform(); + SVGTransform(SVGTransformType); + explicit SVGTransform(const AffineTransform&); + + SVGTransformType type() const { return m_type; } + + SVGMatrix& svgMatrix() { return static_cast<SVGMatrix&>(m_matrix); } + AffineTransform matrix() const { return m_matrix; } + void updateMatrix(); + + float angle() const { return m_angle; } + FloatPoint rotationCenter() const { return m_center; } + + void setMatrix(const AffineTransform&); + void setTranslate(float tx, float ty); + void setScale(float sx, float sy); + void setRotate(float angle, float cx, float cy); + void setSkewX(float angle); + void setSkewY(float angle); + + // Internal use only (animation system) + FloatPoint translate() const; + FloatSize scale() const; + + bool isValid() const { return m_type != SVG_TRANSFORM_UNKNOWN; } + String valueAsString() const; + +private: + friend bool operator==(const SVGTransform& a, const SVGTransform& b); + + SVGTransformType m_type; + float m_angle; + FloatPoint m_center; + AffineTransform m_matrix; +}; + +inline bool operator==(const SVGTransform& a, const SVGTransform& b) +{ + return a.m_type == b.m_type && a.m_angle == b.m_angle && a.m_matrix == b.m_matrix; +} + +inline bool operator!=(const SVGTransform& a, const SVGTransform& b) +{ + return !(a == b); +} + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGTransform.idl b/Source/WebCore/svg/SVGTransform.idl new file mode 100644 index 0000000..773ad6c --- /dev/null +++ b/Source/WebCore/svg/SVGTransform.idl @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * Copyright (C) 2006 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +module svg { + + interface [Conditional=SVG] SVGTransform { + // Transform Types + const unsigned short SVG_TRANSFORM_UNKNOWN = 0; + const unsigned short SVG_TRANSFORM_MATRIX = 1; + const unsigned short SVG_TRANSFORM_TRANSLATE = 2; + const unsigned short SVG_TRANSFORM_SCALE = 3; + const unsigned short SVG_TRANSFORM_ROTATE = 4; + const unsigned short SVG_TRANSFORM_SKEWX = 5; + const unsigned short SVG_TRANSFORM_SKEWY = 6; + + readonly attribute unsigned short type; + readonly attribute SVGMatrix matrix; + readonly attribute float angle; + + [StrictTypeChecking, RequiresAllArguments=Raise] void setMatrix(in SVGMatrix matrix); + [StrictTypeChecking, RequiresAllArguments=Raise] void setTranslate(in float tx, in float ty); + [StrictTypeChecking, RequiresAllArguments=Raise] void setScale(in float sx, in float sy); + [StrictTypeChecking, RequiresAllArguments=Raise] void setRotate(in float angle, in float cx, in float cy); + [StrictTypeChecking, RequiresAllArguments=Raise] void setSkewX(in float angle); + [StrictTypeChecking, RequiresAllArguments=Raise] void setSkewY(in float angle); + }; + +} diff --git a/Source/WebCore/svg/SVGTransformDistance.cpp b/Source/WebCore/svg/SVGTransformDistance.cpp new file mode 100644 index 0000000..736e6bf --- /dev/null +++ b/Source/WebCore/svg/SVGTransformDistance.cpp @@ -0,0 +1,266 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#if ENABLE(SVG) +#include "SVGTransformDistance.h" + +#include "FloatConversion.h" +#include "FloatPoint.h" +#include "FloatSize.h" +#include "SVGTransform.h" + +#include <math.h> + +namespace WebCore { + +SVGTransformDistance::SVGTransformDistance() + : m_type(SVGTransform::SVG_TRANSFORM_UNKNOWN) + , m_angle(0) + , m_cx(0) + , m_cy(0) +{ +} + +SVGTransformDistance::SVGTransformDistance(SVGTransform::SVGTransformType type, float angle, float cx, float cy, const AffineTransform& transform) + : m_type(type) + , m_angle(angle) + , m_cx(cx) + , m_cy(cy) + , m_transform(transform) +{ +} + +SVGTransformDistance::SVGTransformDistance(const SVGTransform& fromSVGTransform, const SVGTransform& toSVGTransform) + : m_type(fromSVGTransform.type()) + , m_angle(0) + , m_cx(0) + , m_cy(0) +{ + ASSERT(m_type == toSVGTransform.type()); + + switch (m_type) { + case SVGTransform::SVG_TRANSFORM_UNKNOWN: + return; + case SVGTransform::SVG_TRANSFORM_MATRIX: + // FIXME: need to be able to subtract to matrices + return; + case SVGTransform::SVG_TRANSFORM_ROTATE: { + FloatSize centerDistance = toSVGTransform.rotationCenter() - fromSVGTransform.rotationCenter(); + m_angle = toSVGTransform.angle() - fromSVGTransform.angle(); + m_cx = centerDistance.width(); + m_cy = centerDistance.height(); + return; + } + case SVGTransform::SVG_TRANSFORM_TRANSLATE: { + FloatSize translationDistance = toSVGTransform.translate() - fromSVGTransform.translate(); + m_transform.translate(translationDistance.width(), translationDistance.height()); + return; + } + case SVGTransform::SVG_TRANSFORM_SCALE: { + float scaleX = toSVGTransform.scale().width() - fromSVGTransform.scale().width(); + float scaleY = toSVGTransform.scale().height() - fromSVGTransform.scale().height(); + m_transform.scaleNonUniform(scaleX, scaleY); + return; + } + case SVGTransform::SVG_TRANSFORM_SKEWX: + case SVGTransform::SVG_TRANSFORM_SKEWY: + m_angle = toSVGTransform.angle() - fromSVGTransform.angle(); + return; + } +} + +SVGTransformDistance SVGTransformDistance::scaledDistance(float scaleFactor) const +{ + switch (m_type) { + case SVGTransform::SVG_TRANSFORM_UNKNOWN: + return SVGTransformDistance(); + case SVGTransform::SVG_TRANSFORM_ROTATE: + return SVGTransformDistance(m_type, m_angle * scaleFactor, m_cx * scaleFactor, m_cy * scaleFactor, AffineTransform()); + case SVGTransform::SVG_TRANSFORM_SCALE: + case SVGTransform::SVG_TRANSFORM_MATRIX: + return SVGTransformDistance(m_type, m_angle * scaleFactor, m_cx * scaleFactor, m_cy * scaleFactor, AffineTransform(m_transform).scale(scaleFactor)); + case SVGTransform::SVG_TRANSFORM_TRANSLATE: { + AffineTransform newTransform(m_transform); + newTransform.setE(m_transform.e() * scaleFactor); + newTransform.setF(m_transform.f() * scaleFactor); + return SVGTransformDistance(m_type, 0, 0, 0, newTransform); + } + case SVGTransform::SVG_TRANSFORM_SKEWX: + case SVGTransform::SVG_TRANSFORM_SKEWY: + return SVGTransformDistance(m_type, m_angle * scaleFactor, m_cx * scaleFactor, m_cy * scaleFactor, AffineTransform()); + } + + ASSERT_NOT_REACHED(); + return SVGTransformDistance(); +} + +SVGTransform SVGTransformDistance::addSVGTransforms(const SVGTransform& first, const SVGTransform& second) +{ + ASSERT(first.type() == second.type()); + + SVGTransform transform; + + switch (first.type()) { + case SVGTransform::SVG_TRANSFORM_UNKNOWN: + return SVGTransform(); + case SVGTransform::SVG_TRANSFORM_ROTATE: { + transform.setRotate(first.angle() + second.angle(), first.rotationCenter().x() + second.rotationCenter().x(), + first.rotationCenter().y() + second.rotationCenter().y()); + return transform; + } + case SVGTransform::SVG_TRANSFORM_MATRIX: + transform.setMatrix(first.matrix() * second.matrix()); + return transform; + case SVGTransform::SVG_TRANSFORM_TRANSLATE: { + float dx = first.translate().x() + second.translate().x(); + float dy = first.translate().y() + second.translate().y(); + transform.setTranslate(dx, dy); + return transform; + } + case SVGTransform::SVG_TRANSFORM_SCALE: { + FloatSize scale = first.scale() + second.scale(); + transform.setScale(scale.width(), scale.height()); + return transform; + } + case SVGTransform::SVG_TRANSFORM_SKEWX: + transform.setSkewX(first.angle() + second.angle()); + return transform; + case SVGTransform::SVG_TRANSFORM_SKEWY: + transform.setSkewY(first.angle() + second.angle()); + return transform; + } + + ASSERT_NOT_REACHED(); + return SVGTransform(); +} + +void SVGTransformDistance::addSVGTransform(const SVGTransform& transform, bool absoluteValue) +{ + // If this is the first add, set the type for this SVGTransformDistance + if (m_type == SVGTransform::SVG_TRANSFORM_UNKNOWN) + m_type = transform.type(); + + ASSERT(m_type == transform.type()); + + switch (m_type) { + case SVGTransform::SVG_TRANSFORM_UNKNOWN: + return; + case SVGTransform::SVG_TRANSFORM_MATRIX: + m_transform *= transform.matrix(); // FIXME: what does 'distance' between two transforms mean? how should we respect 'absoluteValue' here? + return; + case SVGTransform::SVG_TRANSFORM_ROTATE: + m_angle += absoluteValue ? fabsf(transform.angle()) : transform.angle(); + m_cx += absoluteValue ? fabsf(transform.rotationCenter().x()) : transform.rotationCenter().x(); + m_cy += absoluteValue ? fabsf(transform.rotationCenter().y()) : transform.rotationCenter().y(); + // fall through + case SVGTransform::SVG_TRANSFORM_TRANSLATE: { + float dx = absoluteValue ? fabsf(transform.translate().x()) : transform.translate().x(); + float dy = absoluteValue ? fabsf(transform.translate().y()) : transform.translate().y(); + m_transform.translate(dx, dy); + return; + } + case SVGTransform::SVG_TRANSFORM_SCALE: { + float scaleX = absoluteValue ? fabsf(transform.scale().width()) : transform.scale().width(); + float scaleY = absoluteValue ? fabsf(transform.scale().height()) : transform.scale().height(); + m_transform.scaleNonUniform(scaleX, scaleY); + return; + } + case SVGTransform::SVG_TRANSFORM_SKEWX: + case SVGTransform::SVG_TRANSFORM_SKEWY: + m_angle += absoluteValue ? fabsf(transform.angle()) : transform.angle(); + return; + } + + ASSERT_NOT_REACHED(); + return; +} + +SVGTransform SVGTransformDistance::addToSVGTransform(const SVGTransform& transform) const +{ + ASSERT(m_type == transform.type() || transform == SVGTransform()); + + SVGTransform newTransform(transform); + + switch (m_type) { + case SVGTransform::SVG_TRANSFORM_UNKNOWN: + return SVGTransform(); + case SVGTransform::SVG_TRANSFORM_MATRIX: + return SVGTransform(transform.matrix() * m_transform); + case SVGTransform::SVG_TRANSFORM_TRANSLATE: { + FloatPoint translation = transform.translate(); + translation += FloatSize::narrowPrecision(m_transform.e(), m_transform.f()); + newTransform.setTranslate(translation.x(), translation.y()); + return newTransform; + } + case SVGTransform::SVG_TRANSFORM_SCALE: { + FloatSize scale = transform.scale(); + scale += FloatSize::narrowPrecision(m_transform.a(), m_transform.d()); + newTransform.setScale(scale.width(), scale.height()); + return newTransform; + } + case SVGTransform::SVG_TRANSFORM_ROTATE: { + // FIXME: I'm not certain the translation is calculated correctly here + FloatPoint center = transform.rotationCenter(); + newTransform.setRotate(transform.angle() + m_angle, + center.x() + m_cx, + center.y() + m_cy); + return newTransform; + } + case SVGTransform::SVG_TRANSFORM_SKEWX: + newTransform.setSkewX(transform.angle() + m_angle); + return newTransform; + case SVGTransform::SVG_TRANSFORM_SKEWY: + newTransform.setSkewY(transform.angle() + m_angle); + return newTransform; + } + + ASSERT_NOT_REACHED(); + return SVGTransform(); +} + +bool SVGTransformDistance::isZero() const +{ + return m_transform.isIdentity() && !m_angle; +} + +float SVGTransformDistance::distance() const +{ + switch (m_type) { + case SVGTransform::SVG_TRANSFORM_UNKNOWN: + return 0; + case SVGTransform::SVG_TRANSFORM_ROTATE: + return sqrtf(m_angle * m_angle + m_cx * m_cx + m_cy * m_cy); + case SVGTransform::SVG_TRANSFORM_MATRIX: + return 0; // I'm not quite sure yet what distance between two matrices means. + case SVGTransform::SVG_TRANSFORM_SCALE: + return static_cast<float>(sqrt(m_transform.a() * m_transform.a() + m_transform.d() * m_transform.d())); + case SVGTransform::SVG_TRANSFORM_TRANSLATE: + return static_cast<float>(sqrt(m_transform.e() * m_transform.e() + m_transform.f() * m_transform.f())); + case SVGTransform::SVG_TRANSFORM_SKEWX: + case SVGTransform::SVG_TRANSFORM_SKEWY: + return m_angle; + } + ASSERT_NOT_REACHED(); + return 0; +} + +} + +#endif diff --git a/Source/WebCore/svg/SVGTransformDistance.h b/Source/WebCore/svg/SVGTransformDistance.h new file mode 100644 index 0000000..ad46974 --- /dev/null +++ b/Source/WebCore/svg/SVGTransformDistance.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGTransformDistance_h +#define SVGTransformDistance_h +#if ENABLE(SVG) + +#include "SVGTransform.h" + +namespace WebCore { + +class AffineTransform; + +class SVGTransformDistance { +public: + SVGTransformDistance(); + SVGTransformDistance(const SVGTransform& fromTransform, const SVGTransform& toTransform); + + SVGTransformDistance scaledDistance(float scaleFactor) const; + SVGTransform addToSVGTransform(const SVGTransform&) const; + void addSVGTransform(const SVGTransform&, bool absoluteValue = false); + + static SVGTransform addSVGTransforms(const SVGTransform&, const SVGTransform&); + + bool isZero() const; + + float distance() const; +private: + SVGTransformDistance(SVGTransform::SVGTransformType, float angle, float cx, float cy, const AffineTransform&); + + SVGTransform::SVGTransformType m_type; + float m_angle; + float m_cx; + float m_cy; + AffineTransform m_transform; // for storing scale, translation or matrix transforms +}; +} + +#endif // ENABLE(SVG) +#endif // SVGTransformDistance_h diff --git a/Source/WebCore/svg/SVGTransformList.cpp b/Source/WebCore/svg/SVGTransformList.cpp new file mode 100644 index 0000000..52bfc85 --- /dev/null +++ b/Source/WebCore/svg/SVGTransformList.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGTransformList.h" + +#include "AffineTransform.h" +#include "SVGSVGElement.h" +#include "SVGTransform.h" + +#include <wtf/text/StringBuilder.h> +#include <wtf/text/StringConcatenate.h> + +namespace WebCore { + +SVGTransform SVGTransformList::createSVGTransformFromMatrix(const SVGMatrix& matrix) const +{ + return SVGSVGElement::createSVGTransformFromMatrix(matrix); +} + +SVGTransform SVGTransformList::consolidate() +{ + AffineTransform matrix; + if (!concatenate(matrix)) + return SVGTransform(); + + SVGTransform transform(matrix); + clear(); + append(transform); + return transform; +} + +bool SVGTransformList::concatenate(AffineTransform& result) const +{ + unsigned size = this->size(); + if (!size) + return false; + + for (unsigned i = 0; i < size; ++i) + result = at(i).matrix() * result; + + return true; +} + +String SVGTransformList::valueAsString() const +{ + StringBuilder builder; + unsigned size = this->size(); + for (unsigned i = 0; i < size; ++i) { + if (i > 0) + builder.append(' '); + + builder.append(at(i).valueAsString()); + } + + return builder.toString(); +} + +} // namespace WebCore + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGTransformList.h b/Source/WebCore/svg/SVGTransformList.h new file mode 100644 index 0000000..0afc832 --- /dev/null +++ b/Source/WebCore/svg/SVGTransformList.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGTransformList_h +#define SVGTransformList_h + +#if ENABLE(SVG) +#include "SVGPropertyTraits.h" +#include "SVGTransform.h" +#include <wtf/Vector.h> + +namespace WebCore { + +class SVGTransformList : public Vector<SVGTransform> { +public: + SVGTransformList() { } + + SVGTransform createSVGTransformFromMatrix(const SVGMatrix&) const; + SVGTransform consolidate(); + + // Internal use only + bool concatenate(AffineTransform& result) const; + + String valueAsString() const; +}; + +template<> +struct SVGPropertyTraits<SVGTransformList> { + static SVGTransformList initialValue() { return SVGTransformList(); } + static String toString(const SVGTransformList& type) { return type.valueAsString(); } + typedef SVGTransform ListItemType; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGTransformList_h diff --git a/Source/WebCore/svg/SVGTransformList.idl b/Source/WebCore/svg/SVGTransformList.idl new file mode 100644 index 0000000..8bbb091 --- /dev/null +++ b/Source/WebCore/svg/SVGTransformList.idl @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGTransformList { + readonly attribute unsigned long numberOfItems; + + void clear() + raises(DOMException); + [StrictTypeChecking, RequiresAllArguments=Raise] SVGTransform initialize(in SVGTransform item) + raises(DOMException, SVGException); + [StrictTypeChecking, RequiresAllArguments=Raise] SVGTransform getItem(in unsigned long index) + raises(DOMException); + [StrictTypeChecking, RequiresAllArguments=Raise] SVGTransform insertItemBefore(in SVGTransform item, in unsigned long index) + raises(DOMException, SVGException); + [StrictTypeChecking, RequiresAllArguments=Raise] SVGTransform replaceItem(in SVGTransform item, in unsigned long index) + raises(DOMException, SVGException); + [StrictTypeChecking, RequiresAllArguments=Raise] SVGTransform removeItem(in unsigned long index) + raises(DOMException); + [StrictTypeChecking, RequiresAllArguments=Raise] SVGTransform appendItem(in SVGTransform item) + raises(DOMException, SVGException); + + [StrictTypeChecking, RequiresAllArguments=Raise] SVGTransform createSVGTransformFromMatrix(in SVGMatrix matrix) + raises(DOMException); + + SVGTransform consolidate() + raises(DOMException); + }; + +} diff --git a/Source/WebCore/svg/SVGTransformable.cpp b/Source/WebCore/svg/SVGTransformable.cpp new file mode 100644 index 0000000..e637e7c --- /dev/null +++ b/Source/WebCore/svg/SVGTransformable.cpp @@ -0,0 +1,211 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGTransformable.h" + +#include "AffineTransform.h" +#include "FloatConversion.h" +#include "SVGNames.h" +#include "SVGParserUtilities.h" +#include "SVGStyledElement.h" +#include "SVGTransformList.h" + +namespace WebCore { + +static int parseTransformParamList(const UChar*& ptr, const UChar* end, float* values, int required, int optional) +{ + int optionalParams = 0, requiredParams = 0; + + if (!skipOptionalSpaces(ptr, end) || *ptr != '(') + return -1; + + ptr++; + + skipOptionalSpaces(ptr, end); + + while (requiredParams < required) { + if (ptr >= end || !parseNumber(ptr, end, values[requiredParams], false)) + return -1; + requiredParams++; + if (requiredParams < required) + skipOptionalSpacesOrDelimiter(ptr, end); + } + if (!skipOptionalSpaces(ptr, end)) + return -1; + + bool delimParsed = skipOptionalSpacesOrDelimiter(ptr, end); + + if (ptr >= end) + return -1; + + if (*ptr == ')') { // skip optionals + ptr++; + if (delimParsed) + return -1; + } else { + while (optionalParams < optional) { + if (ptr >= end || !parseNumber(ptr, end, values[requiredParams + optionalParams], false)) + return -1; + optionalParams++; + if (optionalParams < optional) + skipOptionalSpacesOrDelimiter(ptr, end); + } + + if (!skipOptionalSpaces(ptr, end)) + return -1; + + delimParsed = skipOptionalSpacesOrDelimiter(ptr, end); + + if (ptr >= end || *ptr != ')' || delimParsed) + return -1; + ptr++; + } + + return requiredParams + optionalParams; +} + +// These should be kept in sync with enum SVGTransformType +static const int requiredValuesForType[] = {0, 6, 1, 1, 1, 1, 1}; +static const int optionalValuesForType[] = {0, 0, 1, 1, 2, 0, 0}; + +bool SVGTransformable::parseTransformValue(unsigned type, const UChar*& ptr, const UChar* end, SVGTransform& transform) +{ + if (type == SVGTransform::SVG_TRANSFORM_UNKNOWN) + return false; + + int valueCount = 0; + float values[] = {0, 0, 0, 0, 0, 0}; + if ((valueCount = parseTransformParamList(ptr, end, values, requiredValuesForType[type], optionalValuesForType[type])) < 0) + return false; + + switch (type) { + case SVGTransform::SVG_TRANSFORM_SKEWX: + transform.setSkewX(values[0]); + break; + case SVGTransform::SVG_TRANSFORM_SKEWY: + transform.setSkewY(values[0]); + break; + case SVGTransform::SVG_TRANSFORM_SCALE: + if (valueCount == 1) // Spec: if only one param given, assume uniform scaling + transform.setScale(values[0], values[0]); + else + transform.setScale(values[0], values[1]); + break; + case SVGTransform::SVG_TRANSFORM_TRANSLATE: + if (valueCount == 1) // Spec: if only one param given, assume 2nd param to be 0 + transform.setTranslate(values[0], 0); + else + transform.setTranslate(values[0], values[1]); + break; + case SVGTransform::SVG_TRANSFORM_ROTATE: + if (valueCount == 1) + transform.setRotate(values[0], 0, 0); + else + transform.setRotate(values[0], values[1], values[2]); + break; + case SVGTransform::SVG_TRANSFORM_MATRIX: + transform.setMatrix(AffineTransform(values[0], values[1], values[2], values[3], values[4], values[5])); + break; + } + + return true; +} + +static const UChar skewXDesc[] = {'s', 'k', 'e', 'w', 'X'}; +static const UChar skewYDesc[] = {'s', 'k', 'e', 'w', 'Y'}; +static const UChar scaleDesc[] = {'s', 'c', 'a', 'l', 'e'}; +static const UChar translateDesc[] = {'t', 'r', 'a', 'n', 's', 'l', 'a', 't', 'e'}; +static const UChar rotateDesc[] = {'r', 'o', 't', 'a', 't', 'e'}; +static const UChar matrixDesc[] = {'m', 'a', 't', 'r', 'i', 'x'}; + +static inline bool parseAndSkipType(const UChar*& currTransform, const UChar* end, unsigned short& type) +{ + if (currTransform >= end) + return false; + + if (*currTransform == 's') { + if (skipString(currTransform, end, skewXDesc, WTF_ARRAY_LENGTH(skewXDesc))) + type = SVGTransform::SVG_TRANSFORM_SKEWX; + else if (skipString(currTransform, end, skewYDesc, WTF_ARRAY_LENGTH(skewYDesc))) + type = SVGTransform::SVG_TRANSFORM_SKEWY; + else if (skipString(currTransform, end, scaleDesc, WTF_ARRAY_LENGTH(scaleDesc))) + type = SVGTransform::SVG_TRANSFORM_SCALE; + else + return false; + } else if (skipString(currTransform, end, translateDesc, WTF_ARRAY_LENGTH(translateDesc))) + type = SVGTransform::SVG_TRANSFORM_TRANSLATE; + else if (skipString(currTransform, end, rotateDesc, WTF_ARRAY_LENGTH(rotateDesc))) + type = SVGTransform::SVG_TRANSFORM_ROTATE; + else if (skipString(currTransform, end, matrixDesc, WTF_ARRAY_LENGTH(matrixDesc))) + type = SVGTransform::SVG_TRANSFORM_MATRIX; + else + return false; + + return true; +} + +bool SVGTransformable::parseTransformAttribute(SVGTransformList& list, const AtomicString& transform) +{ + const UChar* start = transform.characters(); + return parseTransformAttribute(list, start, start + transform.length()); +} + +bool SVGTransformable::parseTransformAttribute(SVGTransformList& list, const UChar*& currTransform, const UChar* end, TransformParsingMode mode) +{ + if (mode == ClearList) + list.clear(); + + bool delimParsed = false; + while (currTransform < end) { + delimParsed = false; + unsigned short type = SVGTransform::SVG_TRANSFORM_UNKNOWN; + skipOptionalSpaces(currTransform, end); + + if (!parseAndSkipType(currTransform, end, type)) + return false; + + SVGTransform transform; + if (!parseTransformValue(type, currTransform, end, transform)) + return false; + + list.append(transform); + skipOptionalSpaces(currTransform, end); + if (currTransform < end && *currTransform == ',') { + delimParsed = true; + ++currTransform; + } + skipOptionalSpaces(currTransform, end); + } + + return !delimParsed; +} + +bool SVGTransformable::isKnownAttribute(const QualifiedName& attrName) +{ + return attrName == SVGNames::transformAttr; +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGTransformable.h b/Source/WebCore/svg/SVGTransformable.h new file mode 100644 index 0000000..1cd2881 --- /dev/null +++ b/Source/WebCore/svg/SVGTransformable.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGTransformable_h +#define SVGTransformable_h + +#if ENABLE(SVG) +#include "PlatformString.h" +#include "SVGLocatable.h" +#include "SVGTransformList.h" +#include <wtf/Forward.h> + +namespace WebCore { + +class AffineTransform; +class SVGTransform; +class QualifiedName; + +class SVGTransformable : virtual public SVGLocatable { +public: + enum TransformParsingMode { + ClearList, + DoNotClearList + }; + + static bool parseTransformAttribute(SVGTransformList&, const AtomicString& transform); + static bool parseTransformAttribute(SVGTransformList&, const UChar*& ptr, const UChar* end, TransformParsingMode mode = ClearList); + static bool parseTransformValue(unsigned type, const UChar*& ptr, const UChar* end, SVGTransform&); + + virtual AffineTransform localCoordinateSpaceTransform(SVGLocatable::CTMScope) const { return animatedLocalTransform(); } + virtual AffineTransform animatedLocalTransform() const = 0; + + bool isKnownAttribute(const QualifiedName&); +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGTransformable_h diff --git a/Source/WebCore/svg/SVGTransformable.idl b/Source/WebCore/svg/SVGTransformable.idl new file mode 100644 index 0000000..86822b7 --- /dev/null +++ b/Source/WebCore/svg/SVGTransformable.idl @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG, ObjCProtocol, OmitConstructor] SVGTransformable : SVGLocatable { + readonly attribute SVGAnimatedTransformList transform; + }; + +} diff --git a/Source/WebCore/svg/SVGURIReference.cpp b/Source/WebCore/svg/SVGURIReference.cpp new file mode 100644 index 0000000..95aa0dc --- /dev/null +++ b/Source/WebCore/svg/SVGURIReference.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGURIReference.h" + +#include "Attribute.h" + +namespace WebCore { + +bool SVGURIReference::parseMappedAttribute(Attribute* attr) +{ + if (attr->name().matches(XLinkNames::hrefAttr)) { + setHrefBaseValue(attr->value()); + return true; + } + + return false; +} + +bool SVGURIReference::isKnownAttribute(const QualifiedName& attrName) +{ + return attrName.matches(XLinkNames::hrefAttr); +} + +String SVGURIReference::getTarget(const String& url) +{ + if (url.startsWith("url(")) { // URI References, ie. fill:url(#target) + size_t start = url.find('#') + 1; + size_t end = url.reverseFind(')'); + return url.substring(start, end - start); + } + if (url.find('#') != notFound) { // format is #target + size_t start = url.find('#') + 1; + return url.substring(start, url.length() - start); + } + + // The url doesn't have any target. + return String(); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGURIReference.h b/Source/WebCore/svg/SVGURIReference.h new file mode 100644 index 0000000..3804791 --- /dev/null +++ b/Source/WebCore/svg/SVGURIReference.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2004, 2005, 2008, 2009 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGURIReference_h +#define SVGURIReference_h + +#if ENABLE(SVG) +#include "SVGElement.h" +#include "XLinkNames.h" + +namespace WebCore { + +class Attribute; + +class SVGURIReference { +public: + virtual ~SVGURIReference() { } + + bool parseMappedAttribute(Attribute*); + bool isKnownAttribute(const QualifiedName&); + + static String getTarget(const String& url); + +protected: + virtual void setHrefBaseValue(const String&) = 0; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGURIReference_h diff --git a/Source/WebCore/svg/SVGURIReference.idl b/Source/WebCore/svg/SVGURIReference.idl new file mode 100644 index 0000000..cc9498a --- /dev/null +++ b/Source/WebCore/svg/SVGURIReference.idl @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG, ObjCProtocol, OmitConstructor] SVGURIReference { + readonly attribute SVGAnimatedString href; + }; + +} diff --git a/Source/WebCore/svg/SVGUnitTypes.h b/Source/WebCore/svg/SVGUnitTypes.h new file mode 100644 index 0000000..d30132c --- /dev/null +++ b/Source/WebCore/svg/SVGUnitTypes.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGUnitTypes_h +#define SVGUnitTypes_h + +#if ENABLE(SVG) + +#include <wtf/RefCounted.h> + +namespace WebCore { + +class SVGUnitTypes : public RefCounted<SVGUnitTypes> { +public: + enum SVGUnitType { + SVG_UNIT_TYPE_UNKNOWN = 0, + SVG_UNIT_TYPE_USERSPACEONUSE = 1, + SVG_UNIT_TYPE_OBJECTBOUNDINGBOX = 2 + }; + +private: + SVGUnitTypes() { } +}; + +static inline SVGUnitTypes::SVGUnitType toUnitType(int type) { return static_cast<SVGUnitTypes::SVGUnitType>(type); } + +} + +#endif +#endif diff --git a/Source/WebCore/svg/SVGUnitTypes.idl b/Source/WebCore/svg/SVGUnitTypes.idl new file mode 100644 index 0000000..6eb3919 --- /dev/null +++ b/Source/WebCore/svg/SVGUnitTypes.idl @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGUnitTypes { + // Unit Types + const unsigned short SVG_UNIT_TYPE_UNKNOWN = 0; + const unsigned short SVG_UNIT_TYPE_USERSPACEONUSE = 1; + const unsigned short SVG_UNIT_TYPE_OBJECTBOUNDINGBOX = 2; + }; + +} diff --git a/Source/WebCore/svg/SVGUseElement.cpp b/Source/WebCore/svg/SVGUseElement.cpp new file mode 100644 index 0000000..589a560 --- /dev/null +++ b/Source/WebCore/svg/SVGUseElement.cpp @@ -0,0 +1,1066 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. + * Copyright (C) 2011 Torch Mobile (Beijing) Co. Ltd. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGUseElement.h" + +#include "Attribute.h" +#include "CSSStyleSelector.h" +#include "Document.h" +#include "Event.h" +#include "EventListener.h" +#include "HTMLNames.h" +#include "NodeRenderStyle.h" +#include "RegisteredEventListener.h" +#include "RenderSVGResource.h" +#include "RenderSVGShadowTreeRootContainer.h" +#include "SVGElementInstance.h" +#include "SVGElementInstanceList.h" +#include "SVGGElement.h" +#include "SVGNames.h" +#include "SVGSMILElement.h" +#include "SVGSVGElement.h" +#include "SVGShadowTreeElements.h" +#include "SVGSymbolElement.h" +#include "XLinkNames.h" +#include "XMLDocumentParser.h" +#include "XMLSerializer.h" + +#include <wtf/text/StringConcatenate.h> + +// Dump SVGElementInstance object tree - useful to debug instanceRoot problems +// #define DUMP_INSTANCE_TREE + +// Dump the deep-expanded shadow tree (where the renderers are built from) +// #define DUMP_SHADOW_TREE + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_LENGTH(SVGUseElement, SVGNames::xAttr, X, x) +DEFINE_ANIMATED_LENGTH(SVGUseElement, SVGNames::yAttr, Y, y) +DEFINE_ANIMATED_LENGTH(SVGUseElement, SVGNames::widthAttr, Width, width) +DEFINE_ANIMATED_LENGTH(SVGUseElement, SVGNames::heightAttr, Height, height) +DEFINE_ANIMATED_STRING(SVGUseElement, XLinkNames::hrefAttr, Href, href) +DEFINE_ANIMATED_BOOLEAN(SVGUseElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) + +inline SVGUseElement::SVGUseElement(const QualifiedName& tagName, Document* document) + : SVGStyledTransformableElement(tagName, document) + , m_x(LengthModeWidth) + , m_y(LengthModeHeight) + , m_width(LengthModeWidth) + , m_height(LengthModeHeight) + , m_updatesBlocked(false) + , m_isPendingResource(false) + , m_needsShadowTreeRecreation(false) +{ +} + +PassRefPtr<SVGUseElement> SVGUseElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGUseElement(tagName, document)); +} + +SVGElementInstance* SVGUseElement::instanceRoot() const +{ + // If there is no element instance tree, force immediate SVGElementInstance tree + // creation by asking the document to invoke our recalcStyle function - as we can't + // wait for the lazy creation to happen if e.g. JS wants to access the instanceRoot + // object right after creating the element on-the-fly + if (!m_targetElementInstance) + document()->updateLayoutIgnorePendingStylesheets(); + + return m_targetElementInstance.get(); +} + +SVGElementInstance* SVGUseElement::animatedInstanceRoot() const +{ + // FIXME: Implement me. + return 0; +} + +void SVGUseElement::parseMappedAttribute(Attribute* attr) +{ + if (attr->name() == SVGNames::xAttr) + setXBaseValue(SVGLength(LengthModeWidth, attr->value())); + else if (attr->name() == SVGNames::yAttr) + setYBaseValue(SVGLength(LengthModeHeight, attr->value())); + else if (attr->name() == SVGNames::widthAttr) { + setWidthBaseValue(SVGLength(LengthModeWidth, attr->value())); + if (widthBaseValue().value(this) < 0.0) + document()->accessSVGExtensions()->reportError("A negative value for use attribute <width> is not allowed"); + } else if (attr->name() == SVGNames::heightAttr) { + setHeightBaseValue(SVGLength(LengthModeHeight, attr->value())); + if (heightBaseValue().value(this) < 0.0) + document()->accessSVGExtensions()->reportError("A negative value for use attribute <height> is not allowed"); + } else { + if (SVGTests::parseMappedAttribute(attr)) + return; + if (SVGLangSpace::parseMappedAttribute(attr)) + return; + if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) + return; + if (SVGURIReference::parseMappedAttribute(attr)) + return; + SVGStyledTransformableElement::parseMappedAttribute(attr); + } +} + +void SVGUseElement::insertedIntoDocument() +{ + // This functions exists to assure assumptions made in the code regarding SVGElementInstance creation/destruction are satisfied. + SVGStyledTransformableElement::insertedIntoDocument(); + ASSERT(!m_targetElementInstance || ((document()->isSVGDocument() || document()->isXHTMLDocument()) && !static_cast<XMLDocumentParser*>(document()->parser())->wellFormed())); + ASSERT(!m_isPendingResource); +} + +void SVGUseElement::removedFromDocument() +{ + SVGStyledTransformableElement::removedFromDocument(); + detachInstance(); +} + +void SVGUseElement::svgAttributeChanged(const QualifiedName& attrName) +{ + SVGStyledTransformableElement::svgAttributeChanged(attrName); + + bool isXYAttribute = attrName == SVGNames::xAttr || attrName == SVGNames::yAttr; + bool isWidthHeightAttribute = attrName == SVGNames::widthAttr || attrName == SVGNames::heightAttr; + + if (isXYAttribute || isWidthHeightAttribute) + updateRelativeLengthsInformation(); + + if (SVGTests::handleAttributeChange(this, attrName)) + return; + + RenderObject* object = renderer(); + if (!object) + return; + + if (SVGURIReference::isKnownAttribute(attrName)) { + if (m_isPendingResource) { + document()->accessSVGExtensions()->removePendingResource(m_resourceId); + m_resourceId = String(); + m_isPendingResource = false; + } + + invalidateShadowTree(); + return; + } + + if (isXYAttribute) { + updateContainerOffsets(); + return; + } + + if (isWidthHeightAttribute) { + updateContainerSizes(); + return; + } + + // Be very careful here, if svgAttributeChanged() has been called because a SVG CSS property changed, we do NOT want to reclone the tree! + if (SVGStyledElement::isKnownAttribute(attrName)) { + setNeedsStyleRecalc(); + return; + } + + if (SVGStyledTransformableElement::isKnownAttribute(attrName)) { + object->setNeedsTransformUpdate(); + RenderSVGResource::markForLayoutAndParentResourceInvalidation(object); + return; + } + + if (SVGLangSpace::isKnownAttribute(attrName) + || SVGExternalResourcesRequired::isKnownAttribute(attrName)) + invalidateShadowTree(); +} + +void SVGUseElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGStyledTransformableElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeX(); + synchronizeY(); + synchronizeWidth(); + synchronizeHeight(); + synchronizeExternalResourcesRequired(); + synchronizeHref(); + SVGTests::synchronizeProperties(this, attrName); + return; + } + + if (attrName == SVGNames::xAttr) + synchronizeX(); + else if (attrName == SVGNames::yAttr) + synchronizeY(); + else if (attrName == SVGNames::widthAttr) + synchronizeWidth(); + else if (attrName == SVGNames::heightAttr) + synchronizeHeight(); + else if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) + synchronizeExternalResourcesRequired(); + else if (SVGURIReference::isKnownAttribute(attrName)) + synchronizeHref(); + else if (SVGTests::isKnownAttribute(attrName)) + SVGTests::synchronizeProperties(this, attrName); +} + +static void updateContainerSize(SVGUseElement* useElement, SVGElementInstance* targetInstance) +{ + // Depth-first used to write the method in early exit style, no particular other reason. + for (SVGElementInstance* instance = targetInstance->firstChild(); instance; instance = instance->nextSibling()) + updateContainerSize(useElement, instance); + + SVGElement* correspondingElement = targetInstance->correspondingElement(); + ASSERT(correspondingElement); + + bool isSymbolTag = correspondingElement->hasTagName(SVGNames::symbolTag); + if (!correspondingElement->hasTagName(SVGNames::svgTag) && !isSymbolTag) + return; + + SVGElement* shadowTreeElement = targetInstance->shadowTreeElement(); + ASSERT(shadowTreeElement); + ASSERT(shadowTreeElement->hasTagName(SVGNames::svgTag)); + + // Spec (<use> on <symbol>): This generated 'svg' will always have explicit values for attributes width and height. + // If attributes width and/or height are provided on the 'use' element, then these attributes + // will be transferred to the generated 'svg'. If attributes width and/or height are not specified, + // the generated 'svg' element will use values of 100% for these attributes. + + // Spec (<use> on <svg>): If attributes width and/or height are provided on the 'use' element, then these + // values will override the corresponding attributes on the 'svg' in the generated tree. + + if (useElement->hasAttribute(SVGNames::widthAttr)) + shadowTreeElement->setAttribute(SVGNames::widthAttr, useElement->getAttribute(SVGNames::widthAttr)); + else if (isSymbolTag && shadowTreeElement->hasAttribute(SVGNames::widthAttr)) + shadowTreeElement->setAttribute(SVGNames::widthAttr, "100%"); + + if (useElement->hasAttribute(SVGNames::heightAttr)) + shadowTreeElement->setAttribute(SVGNames::heightAttr, useElement->getAttribute(SVGNames::heightAttr)); + else if (isSymbolTag && shadowTreeElement->hasAttribute(SVGNames::heightAttr)) + shadowTreeElement->setAttribute(SVGNames::heightAttr, "100%"); +} + +void SVGUseElement::updateContainerSizes() +{ + if (!m_targetElementInstance) + return; + + // Update whole subtree, scanning for shadow container elements, that correspond to <svg>/<symbol> tags + updateContainerSize(this, m_targetElementInstance.get()); + + if (RenderObject* object = renderer()) + RenderSVGResource::markForLayoutAndParentResourceInvalidation(object); +} + +static void updateContainerOffset(SVGElementInstance* targetInstance) +{ + // Depth-first used to write the method in early exit style, no particular other reason. + for (SVGElementInstance* instance = targetInstance->firstChild(); instance; instance = instance->nextSibling()) + updateContainerOffset(instance); + + SVGElement* correspondingElement = targetInstance->correspondingElement(); + ASSERT(correspondingElement); + + if (!correspondingElement->hasTagName(SVGNames::useTag)) + return; + + SVGElement* shadowTreeElement = targetInstance->shadowTreeElement(); + ASSERT(shadowTreeElement); + ASSERT(shadowTreeElement->hasTagName(SVGNames::gTag)); + + if (!static_cast<SVGGElement*>(shadowTreeElement)->isShadowTreeContainerElement()) + return; + + // Spec: An additional transformation translate(x,y) is appended to the end + // (i.e., right-side) of the transform attribute on the generated 'g', where x + // and y represent the values of the x and y attributes on the 'use' element. + SVGUseElement* useElement = static_cast<SVGUseElement*>(correspondingElement); + SVGShadowTreeContainerElement* containerElement = static_cast<SVGShadowTreeContainerElement*>(shadowTreeElement); + containerElement->setContainerOffset(useElement->x(), useElement->y()); +} + +void SVGUseElement::updateContainerOffsets() +{ + if (!m_targetElementInstance) + return; + + // Update root container offset (not reachable through instance tree) + SVGElement* shadowRoot = m_targetElementInstance->shadowTreeElement(); + ASSERT(shadowRoot); + + ContainerNode* parentNode = shadowRoot->parentNode(); + ASSERT(parentNode); + ASSERT(parentNode->isSVGElement()); + ASSERT(parentNode->hasTagName(SVGNames::gTag)); + ASSERT(static_cast<SVGGElement*>(parentNode)->isShadowTreeContainerElement()); + + SVGShadowTreeContainerElement* containerElement = static_cast<SVGShadowTreeContainerElement*>(parentNode); + containerElement->setContainerOffset(x(), y()); + + // Update whole subtree, scanning for shadow container elements, marking a cloned use subtree + updateContainerOffset(m_targetElementInstance.get()); + + if (RenderObject* object = renderer()) + RenderSVGResource::markForLayoutAndParentResourceInvalidation(object); +} + +void SVGUseElement::recalcStyle(StyleChange change) +{ + // Eventually mark shadow root element needing style recalc + if (needsStyleRecalc() && m_targetElementInstance && !m_updatesBlocked) { + if (SVGElement* shadowRoot = m_targetElementInstance->shadowTreeElement()) + shadowRoot->setNeedsStyleRecalc(); + } + + SVGStyledTransformableElement::recalcStyle(change); + + // Assure that the shadow tree has not been marked for recreation, while we're building it. + if (m_updatesBlocked) + ASSERT(!m_needsShadowTreeRecreation); + + RenderSVGShadowTreeRootContainer* shadowRoot = static_cast<RenderSVGShadowTreeRootContainer*>(renderer()); + if (!shadowRoot) + return; + + bool needsStyleUpdate = !m_needsShadowTreeRecreation; + if (m_needsShadowTreeRecreation) { + shadowRoot->markShadowTreeForRecreation(); + m_needsShadowTreeRecreation = false; + } + + shadowRoot->updateFromElement(); + + if (!needsStyleUpdate) + return; + + shadowRoot->updateStyle(change); +} + +#ifdef DUMP_INSTANCE_TREE +void dumpInstanceTree(unsigned int& depth, String& text, SVGElementInstance* targetInstance) +{ + SVGElement* element = targetInstance->correspondingElement(); + ASSERT(element); + + SVGElement* shadowTreeElement = targetInstance->shadowTreeElement(); + ASSERT(shadowTreeElement); + + String elementId = element->getIdAttribute(); + String elementNodeName = element->nodeName(); + String shadowTreeElementNodeName = shadowTreeElement->nodeName(); + String parentNodeName = element->parentNode() ? element->parentNode()->nodeName() : "null"; + String firstChildNodeName = element->firstChild() ? element->firstChild()->nodeName() : "null"; + + for (unsigned int i = 0; i < depth; ++i) + text += " "; + + text += String::format("SVGElementInstance this=%p, (parentNode=%s (%p), firstChild=%s (%p), correspondingElement=%s (%p), shadowTreeElement=%s (%p), id=%s)\n", + targetInstance, parentNodeName.latin1().data(), element->parentNode(), firstChildNodeName.latin1().data(), element->firstChild(), + elementNodeName.latin1().data(), element, shadowTreeElementNodeName.latin1().data(), shadowTreeElement, elementId.latin1().data()); + + for (unsigned int i = 0; i < depth; ++i) + text += " "; + + const HashSet<SVGElementInstance*>& elementInstances = element->instancesForElement(); + text += makeString("Corresponding element is associated with ", String::number(elementInstances.size()), " instance(s):\n"); + + const HashSet<SVGElementInstance*>::const_iterator end = elementInstances.end(); + for (HashSet<SVGElementInstance*>::const_iterator it = elementInstances.begin(); it != end; ++it) { + for (unsigned int i = 0; i < depth; ++i) + text += " "; + + text += String::format(" -> SVGElementInstance this=%p, (refCount: %i, shadowTreeElement in document? %i)\n", + *it, (*it)->refCount(), (*it)->shadowTreeElement()->inDocument()); + } + + ++depth; + + for (SVGElementInstance* instance = targetInstance->firstChild(); instance; instance = instance->nextSibling()) + dumpInstanceTree(depth, text, instance); + + --depth; +} +#endif + +static bool isDisallowedElement(Node* element) +{ +#if ENABLE(SVG_FOREIGN_OBJECT) + // <foreignObject> should never be contained in a <use> tree. Too dangerous side effects possible. + if (element->hasTagName(SVGNames::foreignObjectTag)) + return true; +#endif +#if ENABLE(SVG_ANIMATION) + if (SVGSMILElement::isSMILElement(element)) + return true; +#endif + + return false; +} + +static bool subtreeContainsDisallowedElement(Node* start) +{ + if (isDisallowedElement(start)) + return true; + + for (Node* cur = start->firstChild(); cur; cur = cur->nextSibling()) { + if (subtreeContainsDisallowedElement(cur)) + return true; + } + + return false; +} + +void SVGUseElement::buildPendingResource() +{ + // If we're called the first time (during shadow tree root creation from RenderSVGShadowTreeRootContainer) + // we either determine that our target is available or not - then we add ourselves to the pending resource list + // Once the pending resource appears, it will call buildPendingResource(), so we're called a second time. + String id = SVGURIReference::getTarget(href()); + Element* targetElement = document()->getElementById(id); + ASSERT(!m_targetElementInstance); + + if (!targetElement) { + if (m_isPendingResource || id.isEmpty()) + return; + + m_isPendingResource = true; + m_resourceId = id; + document()->accessSVGExtensions()->addPendingResource(id, this); + return; + } + + if (m_isPendingResource) { + ASSERT(!m_targetElementInstance); + m_isPendingResource = false; + invalidateShadowTree(); + } +} + +void SVGUseElement::buildShadowAndInstanceTree(SVGShadowTreeRootElement* shadowRoot) +{ + struct ShadowTreeUpdateBlocker { + ShadowTreeUpdateBlocker(SVGUseElement* currentUseElement) + : useElement(currentUseElement) + { + useElement->setUpdatesBlocked(true); + } + + ~ShadowTreeUpdateBlocker() + { + useElement->setUpdatesBlocked(false); + } + + SVGUseElement* useElement; + }; + + // When cloning the target nodes, they may decide to synchronize style and/or animated SVG attributes. + // That causes calls to SVGElementInstance::updateAllInstancesOfElement(), which mark the shadow tree for recreation. + // Solution: block any updates to the shadow tree while we're building it. + ShadowTreeUpdateBlocker blocker(this); + + String id = SVGURIReference::getTarget(href()); + Element* targetElement = document()->getElementById(id); + if (!targetElement) { + // The only time we should get here is when the use element has not been + // given a resource to target. + ASSERT(m_resourceId.isEmpty()); + return; + } + + // Do not build the shadow/instance tree for <use> elements living in a shadow tree. + // The will be expanded soon anyway - see expandUseElementsInShadowTree(). + ContainerNode* parent = parentNode(); + while (parent) { + if (parent->isShadowRoot()) + return; + + parent = parent->parentNodeGuaranteedHostFree(); + } + + SVGElement* target = 0; + if (targetElement && targetElement->isSVGElement()) + target = static_cast<SVGElement*>(targetElement); + + detachInstance(); + + // Do not allow self-referencing. + // 'target' may be null, if it's a non SVG namespaced element. + if (!target || target == this) + return; + + // Why a seperated instance/shadow tree? SVG demands it: + // The instance tree is accesable from JavaScript, and has to + // expose a 1:1 copy of the referenced tree, whereas internally we need + // to alter the tree for correct "use-on-symbol", "use-on-svg" support. + + // Build instance tree. Create root SVGElementInstance object for the first sub-tree node. + // + // Spec: If the 'use' element references a simple graphics element such as a 'rect', then there is only a + // single SVGElementInstance object, and the correspondingElement attribute on this SVGElementInstance object + // is the SVGRectElement that corresponds to the referenced 'rect' element. + m_targetElementInstance = SVGElementInstance::create(this, target); + + // Eventually enter recursion to build SVGElementInstance objects for the sub-tree children + bool foundProblem = false; + buildInstanceTree(target, m_targetElementInstance.get(), foundProblem); + + // SVG specification does not say a word about <use> & cycles. My view on this is: just ignore it! + // Non-appearing <use> content is easier to debug, then half-appearing content. + if (foundProblem) { + detachInstance(); + return; + } + + // Assure instance tree building was successfull + ASSERT(m_targetElementInstance); + ASSERT(!m_targetElementInstance->shadowTreeElement()); + ASSERT(m_targetElementInstance->correspondingUseElement() == this); + ASSERT(m_targetElementInstance->correspondingElement() == target); + + // Build shadow tree from instance tree + // This also handles the special cases: <use> on <symbol>, <use> on <svg>. + buildShadowTree(shadowRoot, target, m_targetElementInstance.get()); + +#if ENABLE(SVG) && ENABLE(SVG_USE) + // Expand all <use> elements in the shadow tree. + // Expand means: replace the actual <use> element by what it references. + expandUseElementsInShadowTree(shadowRoot, shadowRoot); + + // Expand all <symbol> elements in the shadow tree. + // Expand means: replace the actual <symbol> element by the <svg> element. + expandSymbolElementsInShadowTree(shadowRoot, shadowRoot); +#endif + + // Now that the shadow tree is completly expanded, we can associate + // shadow tree elements <-> instances in the instance tree. + associateInstancesWithShadowTreeElements(shadowRoot->firstChild(), m_targetElementInstance.get()); + + // If no shadow tree element is present, this means that the reference root + // element was removed, as it is disallowed (ie. <use> on <foreignObject>) + // Do NOT leave an inconsistent instance tree around, instead destruct it. + if (!m_targetElementInstance->shadowTreeElement()) { + shadowRoot->removeAllChildren(); + detachInstance(); + return; + } + + // Consistency checks - this is assumed in updateContainerOffset(). + ASSERT(m_targetElementInstance->shadowTreeElement()->parentNode() == shadowRoot); + + // Eventually dump instance tree +#ifdef DUMP_INSTANCE_TREE + String text; + unsigned int depth = 0; + + dumpInstanceTree(depth, text, m_targetElementInstance.get()); + fprintf(stderr, "\nDumping <use> instance tree:\n%s\n", text.latin1().data()); +#endif + + // Eventually dump shadow tree +#ifdef DUMP_SHADOW_TREE + ExceptionCode ec = 0; + + RefPtr<XMLSerializer> serializer = XMLSerializer::create(); + + String markup = serializer->serializeToString(shadowRoot, ec); + ASSERT(!ec); + + fprintf(stderr, "Dumping <use> shadow tree markup:\n%s\n", markup.latin1().data()); +#endif + + // Transfer event listeners assigned to the referenced element to our shadow tree elements. + transferEventListenersToShadowTree(m_targetElementInstance.get()); + + // Update container offset/size + updateContainerOffsets(); + updateContainerSizes(); + + // Update relative length information + updateRelativeLengthsInformation(); +} + +void SVGUseElement::detachInstance() +{ + if (!m_targetElementInstance) + return; + m_targetElementInstance->clearUseElement(); + m_targetElementInstance = 0; +} + +RenderObject* SVGUseElement::createRenderer(RenderArena* arena, RenderStyle*) +{ + return new (arena) RenderSVGShadowTreeRootContainer(this); +} + +static void updateFromElementCallback(Node* node) +{ + if (RenderObject* renderer = node->renderer()) + renderer->updateFromElement(); +} + +void SVGUseElement::attach() +{ + SVGStyledTransformableElement::attach(); + + if (renderer()) + queuePostAttachCallback(updateFromElementCallback, this); +} + +void SVGUseElement::detach() +{ + SVGStyledTransformableElement::detach(); + detachInstance(); +} + +static bool isDirectReference(Node* node) +{ + return node->hasTagName(SVGNames::pathTag) + || node->hasTagName(SVGNames::rectTag) + || node->hasTagName(SVGNames::circleTag) + || node->hasTagName(SVGNames::ellipseTag) + || node->hasTagName(SVGNames::polygonTag) + || node->hasTagName(SVGNames::polylineTag) + || node->hasTagName(SVGNames::textTag); +} + +void SVGUseElement::toClipPath(Path& path) const +{ + ASSERT(path.isEmpty()); + + Node* n = m_targetElementInstance ? m_targetElementInstance->shadowTreeElement() : 0; + if (!n) + return; + + if (n->isSVGElement() && static_cast<SVGElement*>(n)->isStyledTransformable()) { + if (!isDirectReference(n)) + // Spec: Indirect references are an error (14.3.5) + document()->accessSVGExtensions()->reportError("Not allowed to use indirect reference in <clip-path>"); + else { + static_cast<SVGStyledTransformableElement*>(n)->toClipPath(path); + path.translate(FloatSize(x().value(this), y().value(this))); + path.transform(animatedLocalTransform()); + } + } +} + +RenderObject* SVGUseElement::rendererClipChild() const +{ + Node* n = m_targetElementInstance ? m_targetElementInstance->shadowTreeElement() : 0; + if (!n) + return 0; + + if (n->isSVGElement() && isDirectReference(n)) + return static_cast<SVGElement*>(n)->renderer(); + + return 0; +} + +void SVGUseElement::buildInstanceTree(SVGElement* target, SVGElementInstance* targetInstance, bool& foundProblem) +{ + ASSERT(target); + ASSERT(targetInstance); + + // Spec: If the referenced object is itself a 'use', or if there are 'use' subelements within the referenced + // object, the instance tree will contain recursive expansion of the indirect references to form a complete tree. + bool targetHasUseTag = target->hasTagName(SVGNames::useTag); + SVGElement* newTarget = 0; + if (targetHasUseTag) { + foundProblem = hasCycleUseReferencing(static_cast<SVGUseElement*>(target), targetInstance, newTarget); + if (foundProblem) + return; + } + + // A general description from the SVG spec, describing what buildInstanceTree() actually does. + // + // Spec: If the 'use' element references a 'g' which contains two 'rect' elements, then the instance tree + // contains three SVGElementInstance objects, a root SVGElementInstance object whose correspondingElement + // is the SVGGElement object for the 'g', and then two child SVGElementInstance objects, each of which has + // its correspondingElement that is an SVGRectElement object. + + for (Node* node = target->firstChild(); node; node = node->nextSibling()) { + SVGElement* element = 0; + if (node->isSVGElement()) + element = static_cast<SVGElement*>(node); + + // Skip any non-svg nodes or any disallowed element. + if (!element || isDisallowedElement(element)) + continue; + + // Create SVGElementInstance object, for both container/non-container nodes. + RefPtr<SVGElementInstance> instance = SVGElementInstance::create(this, element); + SVGElementInstance* instancePtr = instance.get(); + targetInstance->appendChild(instance.release()); + + // Enter recursion, appending new instance tree nodes to the "instance" object. + buildInstanceTree(element, instancePtr, foundProblem); + } + + if (!targetHasUseTag || !newTarget) + return; + + RefPtr<SVGElementInstance> newInstance = SVGElementInstance::create(this, newTarget); + SVGElementInstance* newInstancePtr = newInstance.get(); + targetInstance->appendChild(newInstance.release()); + buildInstanceTree(newTarget, newInstancePtr, foundProblem); +} + +bool SVGUseElement::hasCycleUseReferencing(SVGUseElement* use, SVGElementInstance* targetInstance, SVGElement*& newTarget) +{ + String id = SVGURIReference::getTarget(use->href()); + Element* targetElement = document()->getElementById(id); + newTarget = 0; + if (targetElement && targetElement->isSVGElement()) + newTarget = static_cast<SVGElement*>(targetElement); + + if (!newTarget) + return false; + + // Shortcut for self-references + if (newTarget == this) + return true; + + SVGElementInstance* instance = targetInstance->parentNode(); + while (instance) { + SVGElement* element = instance->correspondingElement(); + + // FIXME: This should probably be using getIdAttribute instead of idForStyleResolution. + if (element->hasID() && element->idForStyleResolution() == id) + return true; + + instance = instance->parentNode(); + } + return false; +} + +void SVGUseElement::removeDisallowedElementsFromSubtree(Node* subtree) +{ + ASSERT(!subtree->inDocument()); + ExceptionCode ec; + Node* node = subtree->firstChild(); + while (node) { + if (isDisallowedElement(node)) { + Node* next = node->traverseNextSibling(subtree); + // The subtree is not in document so this won't generate events that could mutate the tree. + node->parentNode()->removeChild(node, ec); + node = next; + } else + node = node->traverseNextNode(subtree); + } +} + +void SVGUseElement::buildShadowTree(SVGShadowTreeRootElement* shadowRoot, SVGElement* target, SVGElementInstance* targetInstance) +{ + // For instance <use> on <foreignObject> (direct case). + if (isDisallowedElement(target)) + return; + + RefPtr<Element> newChild = targetInstance->correspondingElement()->cloneElementWithChildren(); + + // We don't walk the target tree element-by-element, and clone each element, + // but instead use cloneElementWithChildren(). This is an optimization for the common + // case where <use> doesn't contain disallowed elements (ie. <foreignObject>). + // Though if there are disallowed elements in the subtree, we have to remove them. + // For instance: <use> on <g> containing <foreignObject> (indirect case). + if (subtreeContainsDisallowedElement(newChild.get())) + removeDisallowedElementsFromSubtree(newChild.get()); + + SVGElement* newChildPtr = 0; + if (newChild->isSVGElement()) + newChildPtr = static_cast<SVGElement*>(newChild.get()); + ASSERT(newChildPtr); + + ExceptionCode ec = 0; + shadowRoot->appendChild(newChild.release(), ec); + ASSERT(!ec); +} + +#if ENABLE(SVG) && ENABLE(SVG_USE) +void SVGUseElement::expandUseElementsInShadowTree(SVGShadowTreeRootElement* shadowRoot, Node* element) +{ + // Why expand the <use> elements in the shadow tree here, and not just + // do this directly in buildShadowTree, if we encounter a <use> element? + // + // Short answer: Because we may miss to expand some elements. Ie. if a <symbol> + // contains <use> tags, we'd miss them. So once we're done with settin' up the + // actual shadow tree (after the special case modification for svg/symbol) we have + // to walk it completely and expand all <use> elements. + if (element->hasTagName(SVGNames::useTag)) { + SVGUseElement* use = static_cast<SVGUseElement*>(element); + + String id = SVGURIReference::getTarget(use->href()); + Element* targetElement = document()->getElementById(id); + SVGElement* target = 0; + if (targetElement && targetElement->isSVGElement()) + target = static_cast<SVGElement*>(targetElement); + + // Don't ASSERT(target) here, it may be "pending", too. + // Setup sub-shadow tree root node + RefPtr<SVGShadowTreeContainerElement> cloneParent = SVGShadowTreeContainerElement::create(document()); + use->cloneChildNodes(cloneParent.get()); + + // Spec: In the generated content, the 'use' will be replaced by 'g', where all attributes from the + // 'use' element except for x, y, width, height and xlink:href are transferred to the generated 'g' element. + transferUseAttributesToReplacedElement(use, cloneParent.get()); + + ExceptionCode ec = 0; + if (target && !isDisallowedElement(target)) { + RefPtr<Element> newChild = target->cloneElementWithChildren(); + + SVGElement* newChildPtr = 0; + if (newChild->isSVGElement()) + newChildPtr = static_cast<SVGElement*>(newChild.get()); + ASSERT(newChildPtr); + + cloneParent->appendChild(newChild.release(), ec); + ASSERT(!ec); + } + + // We don't walk the target tree element-by-element, and clone each element, + // but instead use cloneElementWithChildren(). This is an optimization for the common + // case where <use> doesn't contain disallowed elements (ie. <foreignObject>). + // Though if there are disallowed elements in the subtree, we have to remove them. + // For instance: <use> on <g> containing <foreignObject> (indirect case). + if (subtreeContainsDisallowedElement(cloneParent.get())) + removeDisallowedElementsFromSubtree(cloneParent.get()); + + // Replace <use> with referenced content. + ASSERT(use->parentNode()); + use->parentNode()->replaceChild(cloneParent.release(), use, ec); + ASSERT(!ec); + + // Immediately stop here, and restart expanding. + expandUseElementsInShadowTree(shadowRoot, shadowRoot); + return; + } + + for (RefPtr<Node> child = element->firstChild(); child; child = child->nextSibling()) + expandUseElementsInShadowTree(shadowRoot, child.get()); +} + +void SVGUseElement::expandSymbolElementsInShadowTree(SVGShadowTreeRootElement* shadowRoot, Node* element) +{ + if (element->hasTagName(SVGNames::symbolTag)) { + // Spec: The referenced 'symbol' and its contents are deep-cloned into the generated tree, + // with the exception that the 'symbol' is replaced by an 'svg'. This generated 'svg' will + // always have explicit values for attributes width and height. If attributes width and/or + // height are provided on the 'use' element, then these attributes will be transferred to + // the generated 'svg'. If attributes width and/or height are not specified, the generated + // 'svg' element will use values of 100% for these attributes. + RefPtr<SVGSVGElement> svgElement = SVGSVGElement::create(SVGNames::svgTag, document()); + + // Transfer all attributes from <symbol> to the new <svg> element + svgElement->attributes()->setAttributes(*element->attributes()); + + // Only clone symbol children, and add them to the new <svg> element + ExceptionCode ec = 0; + for (Node* child = element->firstChild(); child; child = child->nextSibling()) { + RefPtr<Node> newChild = child->cloneNode(true); + svgElement->appendChild(newChild.release(), ec); + ASSERT(!ec); + } + + // We don't walk the target tree element-by-element, and clone each element, + // but instead use cloneNode(deep=true). This is an optimization for the common + // case where <use> doesn't contain disallowed elements (ie. <foreignObject>). + // Though if there are disallowed elements in the subtree, we have to remove them. + // For instance: <use> on <g> containing <foreignObject> (indirect case). + if (subtreeContainsDisallowedElement(svgElement.get())) + removeDisallowedElementsFromSubtree(svgElement.get()); + + // Replace <symbol> with <svg>. + ASSERT(element->parentNode()); + element->parentNode()->replaceChild(svgElement.release(), element, ec); + ASSERT(!ec); + + // Immediately stop here, and restart expanding. + expandSymbolElementsInShadowTree(shadowRoot, shadowRoot); + return; + } + + for (RefPtr<Node> child = element->firstChild(); child; child = child->nextSibling()) + expandSymbolElementsInShadowTree(shadowRoot, child.get()); +} + +#endif + +void SVGUseElement::transferEventListenersToShadowTree(SVGElementInstance* target) +{ + if (!target) + return; + + SVGElement* originalElement = target->correspondingElement(); + ASSERT(originalElement); + + if (SVGElement* shadowTreeElement = target->shadowTreeElement()) { + if (EventTargetData* d = originalElement->eventTargetData()) { + EventListenerMap& map = d->eventListenerMap; + EventListenerMap::iterator end = map.end(); + for (EventListenerMap::iterator it = map.begin(); it != end; ++it) { + EventListenerVector& entry = *it->second; + for (size_t i = 0; i < entry.size(); ++i) { + // Event listeners created from markup have already been transfered to the shadow tree during cloning. + if (entry[i].listener->wasCreatedFromMarkup()) + continue; + shadowTreeElement->addEventListener(it->first, entry[i].listener, entry[i].useCapture); + } + } + } + } + + for (SVGElementInstance* instance = target->firstChild(); instance; instance = instance->nextSibling()) + transferEventListenersToShadowTree(instance); +} + +void SVGUseElement::associateInstancesWithShadowTreeElements(Node* target, SVGElementInstance* targetInstance) +{ + if (!target || !targetInstance) + return; + + SVGElement* originalElement = targetInstance->correspondingElement(); + + if (originalElement->hasTagName(SVGNames::useTag)) { +#if ENABLE(SVG) && ENABLE(SVG_USE) + // <use> gets replaced by <g> + ASSERT(target->nodeName() == SVGNames::gTag); +#else + ASSERT(target->nodeName() == SVGNames::gTag || target->nodeName() == SVGNames::useTag); +#endif + } else if (originalElement->hasTagName(SVGNames::symbolTag)) { + // <symbol> gets replaced by <svg> +#if ENABLE(SVG) && ENABLE(SVG_USE) && ENABLE(SVG_FOREIGN_OBJECT) + ASSERT(target->nodeName() == SVGNames::svgTag); +#endif + } else + ASSERT(target->nodeName() == originalElement->nodeName()); + + SVGElement* element = 0; + if (target->isSVGElement()) + element = static_cast<SVGElement*>(target); + + ASSERT(!targetInstance->shadowTreeElement()); + targetInstance->setShadowTreeElement(element); + + Node* node = target->firstChild(); + for (SVGElementInstance* instance = targetInstance->firstChild(); node && instance; instance = instance->nextSibling()) { + // Skip any non-svg elements in shadow tree + while (node && !node->isSVGElement()) + node = node->nextSibling(); + + if (!node) + break; + + associateInstancesWithShadowTreeElements(node, instance); + node = node->nextSibling(); + } +} + +SVGElementInstance* SVGUseElement::instanceForShadowTreeElement(Node* element) const +{ + if (!m_targetElementInstance) { + ASSERT(!inDocument()); + return 0; + } + + return instanceForShadowTreeElement(element, m_targetElementInstance.get()); +} + +SVGElementInstance* SVGUseElement::instanceForShadowTreeElement(Node* element, SVGElementInstance* instance) const +{ + ASSERT(element); + ASSERT(instance); + + // We're dispatching a mutation event during shadow tree construction + // this instance hasn't yet been associated to a shadowTree element. + if (!instance->shadowTreeElement()) + return 0; + + if (element == instance->shadowTreeElement()) + return instance; + + for (SVGElementInstance* current = instance->firstChild(); current; current = current->nextSibling()) { + if (SVGElementInstance* search = instanceForShadowTreeElement(element, current)) + return search; + } + + return 0; +} + +void SVGUseElement::invalidateShadowTree() +{ + // Don't mutate the shadow tree while we're building it. + if (m_updatesBlocked) + return; + + m_needsShadowTreeRecreation = true; + setNeedsStyleRecalc(); +} + +void SVGUseElement::transferUseAttributesToReplacedElement(SVGElement* from, SVGElement* to) const +{ + ASSERT(from); + ASSERT(to); + + to->attributes()->setAttributes(*from->attributes()); + + ExceptionCode ec = 0; + + to->removeAttribute(SVGNames::xAttr, ec); + ASSERT(!ec); + + to->removeAttribute(SVGNames::yAttr, ec); + ASSERT(!ec); + + to->removeAttribute(SVGNames::widthAttr, ec); + ASSERT(!ec); + + to->removeAttribute(SVGNames::heightAttr, ec); + ASSERT(!ec); + + to->removeAttribute(XLinkNames::hrefAttr, ec); + ASSERT(!ec); +} + +bool SVGUseElement::selfHasRelativeLengths() const +{ + if (x().isRelative() + || y().isRelative() + || width().isRelative() + || height().isRelative()) + return true; + + if (!m_targetElementInstance) + return false; + + SVGElement* element = m_targetElementInstance->correspondingElement(); + if (!element || !element->isStyled()) + return false; + + return static_cast<SVGStyledElement*>(element)->hasRelativeLengths(); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGUseElement.h b/Source/WebCore/svg/SVGUseElement.h new file mode 100644 index 0000000..c1095ed --- /dev/null +++ b/Source/WebCore/svg/SVGUseElement.h @@ -0,0 +1,128 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGUseElement_h +#define SVGUseElement_h + +#if ENABLE(SVG) +#include "SVGAnimatedBoolean.h" +#include "SVGAnimatedLength.h" +#include "SVGExternalResourcesRequired.h" +#include "SVGLangSpace.h" +#include "SVGStyledTransformableElement.h" +#include "SVGTests.h" +#include "SVGURIReference.h" + +namespace WebCore { + +class SVGElementInstance; +class SVGShadowTreeRootElement; + +class SVGUseElement : public SVGStyledTransformableElement, + public SVGTests, + public SVGLangSpace, + public SVGExternalResourcesRequired, + public SVGURIReference { +public: + static PassRefPtr<SVGUseElement> create(const QualifiedName&, Document*); + + SVGElementInstance* instanceRoot() const; + SVGElementInstance* animatedInstanceRoot() const; + SVGElementInstance* instanceForShadowTreeElement(Node*) const; + void invalidateShadowTree(); + + RenderObject* rendererClipChild() const; + +private: + SVGUseElement(const QualifiedName&, Document*); + + virtual bool isValid() const { return SVGTests::isValid(); } + + virtual void insertedIntoDocument(); + virtual void removedFromDocument(); + virtual void buildPendingResource(); + + virtual void parseMappedAttribute(Attribute*); + virtual void svgAttributeChanged(const QualifiedName&); + virtual void synchronizeProperty(const QualifiedName&); + + virtual void recalcStyle(StyleChange = NoChange); + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + virtual void attach(); + virtual void detach(); + + virtual void toClipPath(Path&) const; + + static void removeDisallowedElementsFromSubtree(Node* element); + + void setUpdatesBlocked(bool blocked) { m_updatesBlocked = blocked; } + + friend class RenderSVGShadowTreeRootContainer; + bool isPendingResource() const { return m_isPendingResource; } + void buildShadowAndInstanceTree(SVGShadowTreeRootElement*); + void detachInstance(); + + virtual bool selfHasRelativeLengths() const; + + // Instance tree handling + void buildInstanceTree(SVGElement* target, SVGElementInstance* targetInstance, bool& foundCycle); + bool hasCycleUseReferencing(SVGUseElement*, SVGElementInstance* targetInstance, SVGElement*& newTarget); + + // Shadow tree handling + void buildShadowTree(SVGShadowTreeRootElement*, SVGElement* target, SVGElementInstance* targetInstance); + +#if ENABLE(SVG) && ENABLE(SVG_USE) + void expandUseElementsInShadowTree(SVGShadowTreeRootElement*, Node* element); + void expandSymbolElementsInShadowTree(SVGShadowTreeRootElement*, Node* element); +#endif + + // "Tree connector" + void associateInstancesWithShadowTreeElements(Node* target, SVGElementInstance* targetInstance); + SVGElementInstance* instanceForShadowTreeElement(Node* element, SVGElementInstance* instance) const; + + void transferUseAttributesToReplacedElement(SVGElement* from, SVGElement* to) const; + void transferEventListenersToShadowTree(SVGElementInstance* target); + + void updateContainerOffsets(); + void updateContainerSizes(); + + // Animated property declarations + DECLARE_ANIMATED_LENGTH(X, x) + DECLARE_ANIMATED_LENGTH(Y, y) + DECLARE_ANIMATED_LENGTH(Width, width) + DECLARE_ANIMATED_LENGTH(Height, height) + + // SVGURIReference + DECLARE_ANIMATED_STRING(Href, href) + + // SVGExternalResourcesRequired + DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) + + bool m_updatesBlocked; + bool m_isPendingResource; + bool m_needsShadowTreeRecreation; + String m_resourceId; + RefPtr<SVGElementInstance> m_targetElementInstance; +}; + +} + +#endif +#endif diff --git a/Source/WebCore/svg/SVGUseElement.idl b/Source/WebCore/svg/SVGUseElement.idl new file mode 100644 index 0000000..6c1cf12 --- /dev/null +++ b/Source/WebCore/svg/SVGUseElement.idl @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGUseElement : SVGElement, + SVGURIReference, + SVGTests, + SVGLangSpace, + SVGExternalResourcesRequired, + SVGStylable, + SVGTransformable { + readonly attribute SVGAnimatedLength x; + readonly attribute SVGAnimatedLength y; + readonly attribute SVGAnimatedLength width; + readonly attribute SVGAnimatedLength height; + + readonly attribute SVGElementInstance instanceRoot; + readonly attribute SVGElementInstance animatedInstanceRoot; + }; + +} diff --git a/Source/WebCore/svg/SVGVKernElement.cpp b/Source/WebCore/svg/SVGVKernElement.cpp new file mode 100644 index 0000000..eed13d2 --- /dev/null +++ b/Source/WebCore/svg/SVGVKernElement.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG_FONTS) +#include "SVGVKernElement.h" + +#include "SVGFontData.h" +#include "SVGFontElement.h" +#include "SVGFontFaceElement.h" +#include "SVGNames.h" +#include "SimpleFontData.h" +#include "XMLNames.h" + +namespace WebCore { + +using namespace SVGNames; + +inline SVGVKernElement::SVGVKernElement(const QualifiedName& tagName, Document* document) + : SVGElement(tagName, document) +{ +} + +PassRefPtr<SVGVKernElement> SVGVKernElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGVKernElement(tagName, document)); +} + +void SVGVKernElement::insertedIntoDocument() +{ + ContainerNode* fontNode = parentNode(); + if (fontNode && fontNode->hasTagName(SVGNames::fontTag)) { + if (SVGFontElement* element = static_cast<SVGFontElement*>(fontNode)) + element->invalidateGlyphCache(); + } +} + +void SVGVKernElement::removedFromDocument() +{ + ContainerNode* fontNode = parentNode(); + if (fontNode && fontNode->hasTagName(SVGNames::fontTag)) { + if (SVGFontElement* element = static_cast<SVGFontElement*>(fontNode)) + element->invalidateGlyphCache(); + } +} + +void SVGVKernElement::buildVerticalKerningPair(KerningPairVector& kerningPairs) +{ + String u1 = getAttribute(u1Attr); + String g1 = getAttribute(g1Attr); + String u2 = getAttribute(u2Attr); + String g2 = getAttribute(g2Attr); + if ((u1.isEmpty() && g1.isEmpty()) || (u2.isEmpty() && g2.isEmpty())) + return; + + SVGKerningPair kerningPair; + if (parseGlyphName(g1, kerningPair.glyphName1) + && parseGlyphName(g2, kerningPair.glyphName2) + && parseKerningUnicodeString(u1, kerningPair.unicodeRange1, kerningPair.unicodeName1) + && parseKerningUnicodeString(u2, kerningPair.unicodeRange2, kerningPair.unicodeName2)) { + kerningPair.kerning = getAttribute(kAttr).string().toFloat(); + kerningPairs.append(kerningPair); + } +} + +} + +#endif // ENABLE(SVG_FONTS) diff --git a/Source/WebCore/svg/SVGVKernElement.h b/Source/WebCore/svg/SVGVKernElement.h new file mode 100644 index 0000000..d8a9d1b --- /dev/null +++ b/Source/WebCore/svg/SVGVKernElement.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGVKernElement_h +#define SVGVKernElement_h + +#if ENABLE(SVG_FONTS) +#include "SVGFontElement.h" +#include "SVGParserUtilities.h" +#include "SVGStyledElement.h" + +#include <limits> +#include <wtf/Forward.h> + +namespace WebCore { + +class SVGFontData; + +class SVGVKernElement : public SVGElement { +public: + static PassRefPtr<SVGVKernElement> create(const QualifiedName&, Document*); + + void buildVerticalKerningPair(KerningPairVector&); + +private: + SVGVKernElement(const QualifiedName&, Document*); + + virtual void insertedIntoDocument(); + virtual void removedFromDocument(); + + virtual bool rendererIsNeeded(RenderStyle*) { return false; } +}; + +} // namespace WebCore + +#endif // ENABLE(SVG_FONTS) +#endif diff --git a/Source/WebCore/svg/SVGVKernElement.idl b/Source/WebCore/svg/SVGVKernElement.idl new file mode 100644 index 0000000..8280da1 --- /dev/null +++ b/Source/WebCore/svg/SVGVKernElement.idl @@ -0,0 +1,25 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +module svg { + + interface [Conditional=SVG&SVG_FONTS] SVGVKernElement : SVGElement { + }; + +} diff --git a/Source/WebCore/svg/SVGViewElement.cpp b/Source/WebCore/svg/SVGViewElement.cpp new file mode 100644 index 0000000..ee3c8d1 --- /dev/null +++ b/Source/WebCore/svg/SVGViewElement.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGViewElement.h" + +#include "Attribute.h" +#include "SVGFitToViewBox.h" +#include "SVGNames.h" +#include "SVGStringList.h" +#include "SVGZoomAndPan.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_BOOLEAN(SVGViewElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) +DEFINE_ANIMATED_RECT(SVGViewElement, SVGNames::viewBoxAttr, ViewBox, viewBox) +DEFINE_ANIMATED_PRESERVEASPECTRATIO(SVGViewElement, SVGNames::preserveAspectRatioAttr, PreserveAspectRatio, preserveAspectRatio) + +inline SVGViewElement::SVGViewElement(const QualifiedName& tagName, Document* document) + : SVGStyledElement(tagName, document) + , m_viewTarget(SVGNames::viewTargetAttr) +{ +} + +PassRefPtr<SVGViewElement> SVGViewElement::create(const QualifiedName& tagName, Document* document) +{ + return adoptRef(new SVGViewElement(tagName, document)); +} + +void SVGViewElement::parseMappedAttribute(Attribute* attr) +{ + if (attr->name() == SVGNames::viewTargetAttr) + viewTarget().reset(attr->value()); + else { + if (SVGExternalResourcesRequired::parseMappedAttribute(attr) + || SVGFitToViewBox::parseMappedAttribute(document(), attr) + || SVGZoomAndPan::parseMappedAttribute(attr)) + return; + + SVGStyledElement::parseMappedAttribute(attr); + } +} + +void SVGViewElement::synchronizeProperty(const QualifiedName& attrName) +{ + SVGStyledElement::synchronizeProperty(attrName); + + if (attrName == anyQName()) { + synchronizeExternalResourcesRequired(); + synchronizeViewBox(); + synchronizePreserveAspectRatio(); + return; + } + + if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) + synchronizeExternalResourcesRequired(); + else if (SVGFitToViewBox::isKnownAttribute(attrName)) { + synchronizeViewBox(); + synchronizePreserveAspectRatio(); + } +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGViewElement.h b/Source/WebCore/svg/SVGViewElement.h new file mode 100644 index 0000000..0e2e4fd --- /dev/null +++ b/Source/WebCore/svg/SVGViewElement.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGViewElement_h +#define SVGViewElement_h + +#if ENABLE(SVG) +#include "SVGAnimatedBoolean.h" +#include "SVGAnimatedPreserveAspectRatio.h" +#include "SVGAnimatedRect.h" +#include "SVGExternalResourcesRequired.h" +#include "SVGFitToViewBox.h" +#include "SVGStringList.h" +#include "SVGStyledElement.h" +#include "SVGZoomAndPan.h" + +namespace WebCore { + +class SVGViewElement : public SVGStyledElement, + public SVGExternalResourcesRequired, + public SVGFitToViewBox, + public SVGZoomAndPan { +public: + static PassRefPtr<SVGViewElement> create(const QualifiedName&, Document*); + + SVGStringList& viewTarget() { return m_viewTarget; } + +private: + SVGViewElement(const QualifiedName&, Document*); + + virtual void parseMappedAttribute(Attribute*); + virtual void synchronizeProperty(const QualifiedName&); + + virtual bool rendererIsNeeded(RenderStyle*) { return false; } + + // Animated property declarations + + // SVGExternalResourcesRequired + DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) + + // SVGFitToViewBox + DECLARE_ANIMATED_RECT(ViewBox, viewBox) + DECLARE_ANIMATED_PRESERVEASPECTRATIO(PreserveAspectRatio, preserveAspectRatio) + + SVGStringList m_viewTarget; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGViewElement.idl b/Source/WebCore/svg/SVGViewElement.idl new file mode 100644 index 0000000..2365438 --- /dev/null +++ b/Source/WebCore/svg/SVGViewElement.idl @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGViewElement : SVGElement, + SVGExternalResourcesRequired, + SVGFitToViewBox, + SVGZoomAndPan { + readonly attribute SVGStringList viewTarget; + }; + +} diff --git a/Source/WebCore/svg/SVGViewSpec.cpp b/Source/WebCore/svg/SVGViewSpec.cpp new file mode 100644 index 0000000..7a0c2a9 --- /dev/null +++ b/Source/WebCore/svg/SVGViewSpec.cpp @@ -0,0 +1,168 @@ +/* + * Copyright (C) 2007, 2010 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGViewSpec.h" + +#include "Document.h" +#include "SVGNames.h" +#include "SVGParserUtilities.h" +#include "SVGSVGElement.h" +#include "SVGTransformable.h" + +namespace WebCore { + +// Animated property definitions +DEFINE_ANIMATED_RECT(SVGViewSpec, SVGNames::viewBoxAttr, ViewBox, viewBox) +DEFINE_ANIMATED_PRESERVEASPECTRATIO(SVGViewSpec, SVGNames::preserveAspectRatioAttr, PreserveAspectRatio, preserveAspectRatio) + +SVGViewSpec::SVGViewSpec(SVGElement* contextElement) + : m_contextElement(contextElement) +{ +} + +void SVGViewSpec::setTransform(const String& transform) +{ + SVGTransformable::parseTransformAttribute(m_transform, transform); +} + +void SVGViewSpec::setViewBoxString(const String& viewBoxStr) +{ + FloatRect viewBox; + const UChar* c = viewBoxStr.characters(); + const UChar* end = c + viewBoxStr.length(); + if (!parseViewBox(m_contextElement->document(), c, end, viewBox, false)) + return; + setViewBoxBaseValue(viewBox); +} + +void SVGViewSpec::setPreserveAspectRatioString(const String& preserve) +{ + SVGPreserveAspectRatio::parsePreserveAspectRatio(this, preserve); +} + +void SVGViewSpec::setViewTargetString(const String& viewTargetString) +{ + m_viewTargetString = viewTargetString; +} + +SVGElement* SVGViewSpec::viewTarget() const +{ + return static_cast<SVGElement*>(m_contextElement->document()->getElementById(m_viewTargetString)); +} + +static const UChar svgViewSpec[] = {'s', 'v', 'g', 'V', 'i', 'e', 'w'}; +static const UChar viewBoxSpec[] = {'v', 'i', 'e', 'w', 'B', 'o', 'x'}; +static const UChar preserveAspectRatioSpec[] = {'p', 'r', 'e', 's', 'e', 'r', 'v', 'e', 'A', 's', 'p', 'e', 'c', 't', 'R', 'a', 't', 'i', 'o'}; +static const UChar transformSpec[] = {'t', 'r', 'a', 'n', 's', 'f', 'o', 'r', 'm'}; +static const UChar zoomAndPanSpec[] = {'z', 'o', 'o', 'm', 'A', 'n', 'd', 'P', 'a', 'n'}; +static const UChar viewTargetSpec[] = {'v', 'i', 'e', 'w', 'T', 'a', 'r', 'g', 'e', 't'}; + +bool SVGViewSpec::parseViewSpec(const String& viewSpec) +{ + const UChar* currViewSpec = viewSpec.characters(); + const UChar* end = currViewSpec + viewSpec.length(); + + if (currViewSpec >= end) + return false; + + if (!skipString(currViewSpec, end, svgViewSpec, WTF_ARRAY_LENGTH(svgViewSpec))) + return false; + + if (currViewSpec >= end || *currViewSpec != '(') + return false; + currViewSpec++; + + while (currViewSpec < end && *currViewSpec != ')') { + if (*currViewSpec == 'v') { + if (skipString(currViewSpec, end, viewBoxSpec, WTF_ARRAY_LENGTH(viewBoxSpec))) { + if (currViewSpec >= end || *currViewSpec != '(') + return false; + currViewSpec++; + FloatRect viewBox; + if (!parseViewBox(m_contextElement->document(), currViewSpec, end, viewBox, false)) + return false; + setViewBoxBaseValue(viewBox); + if (currViewSpec >= end || *currViewSpec != ')') + return false; + currViewSpec++; + } else if (skipString(currViewSpec, end, viewTargetSpec, WTF_ARRAY_LENGTH(viewTargetSpec))) { + if (currViewSpec >= end || *currViewSpec != '(') + return false; + const UChar* viewTargetStart = ++currViewSpec; + while (currViewSpec < end && *currViewSpec != ')') + currViewSpec++; + if (currViewSpec >= end) + return false; + setViewTargetString(String(viewTargetStart, currViewSpec - viewTargetStart)); + currViewSpec++; + } else + return false; + } else if (*currViewSpec == 'z') { + if (!skipString(currViewSpec, end, zoomAndPanSpec, WTF_ARRAY_LENGTH(zoomAndPanSpec))) + return false; + if (currViewSpec >= end || *currViewSpec != '(') + return false; + currViewSpec++; + if (!parseZoomAndPan(currViewSpec, end)) + return false; + if (currViewSpec >= end || *currViewSpec != ')') + return false; + currViewSpec++; + } else if (*currViewSpec == 'p') { + if (!skipString(currViewSpec, end, preserveAspectRatioSpec, WTF_ARRAY_LENGTH(preserveAspectRatioSpec))) + return false; + if (currViewSpec >= end || *currViewSpec != '(') + return false; + currViewSpec++; + bool result = false; + setPreserveAspectRatioBaseValue(SVGPreserveAspectRatio::parsePreserveAspectRatio(currViewSpec, end, false, result)); + if (!result) + return false; + if (currViewSpec >= end || *currViewSpec != ')') + return false; + currViewSpec++; + } else if (*currViewSpec == 't') { + if (!skipString(currViewSpec, end, transformSpec, WTF_ARRAY_LENGTH(transformSpec))) + return false; + if (currViewSpec >= end || *currViewSpec != '(') + return false; + currViewSpec++; + SVGTransformable::parseTransformAttribute(m_transform, currViewSpec, end, SVGTransformable::DoNotClearList); + if (currViewSpec >= end || *currViewSpec != ')') + return false; + currViewSpec++; + } else + return false; + + if (currViewSpec < end && *currViewSpec == ';') + currViewSpec++; + } + + if (currViewSpec >= end || *currViewSpec != ')') + return false; + + return true; +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGViewSpec.h b/Source/WebCore/svg/SVGViewSpec.h new file mode 100644 index 0000000..686cec3 --- /dev/null +++ b/Source/WebCore/svg/SVGViewSpec.h @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGViewSpec_h +#define SVGViewSpec_h + +#if ENABLE(SVG) +#include "SVGAnimatedPreserveAspectRatio.h" +#include "SVGAnimatedRect.h" +#include "SVGFitToViewBox.h" +#include "SVGTransformList.h" +#include "SVGZoomAndPan.h" + +namespace WebCore { + +class SVGElement; + +class SVGViewSpec : public SVGFitToViewBox, + public SVGZoomAndPan, + public Noncopyable { +public: + SVGViewSpec(SVGElement*); + + bool parseViewSpec(const String&); + + void setTransform(const String&); + SVGTransformList transform() const { return m_transform; } + + void setViewBoxString(const String&); + + void setPreserveAspectRatioString(const String&); + + void setViewTargetString(const String&); + String viewTargetString() const { return m_viewTargetString; } + SVGElement* viewTarget() const; + + SVGElement* contextElement() const { return const_cast<SVGElement*>(m_contextElement); } + +private: + SVGElement* m_contextElement; + + // Animated property declarations + + // SVGFitToViewBox + DECLARE_ANIMATED_RECT(ViewBox, viewBox) + DECLARE_ANIMATED_PRESERVEASPECTRATIO(PreserveAspectRatio, preserveAspectRatio) + + SVGTransformList m_transform; + String m_viewTargetString; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif diff --git a/Source/WebCore/svg/SVGViewSpec.idl b/Source/WebCore/svg/SVGViewSpec.idl new file mode 100644 index 0000000..e58ca37 --- /dev/null +++ b/Source/WebCore/svg/SVGViewSpec.idl @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * + * 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGViewSpec : SVGZoomAndPan, SVGFitToViewBox + { + readonly attribute SVGTransformList transform; + readonly attribute SVGElement viewTarget; + readonly attribute DOMString viewBoxString; + readonly attribute DOMString preserveAspectRatioString; + readonly attribute DOMString transformString; + readonly attribute DOMString viewTargetString; + }; + +} diff --git a/Source/WebCore/svg/SVGZoomAndPan.cpp b/Source/WebCore/svg/SVGZoomAndPan.cpp new file mode 100644 index 0000000..36d4a60 --- /dev/null +++ b/Source/WebCore/svg/SVGZoomAndPan.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGZoomAndPan.h" + +#include "Attribute.h" +#include "SVGNames.h" +#include "SVGParserUtilities.h" + +namespace WebCore { + +void SVGZoomAndPan::setZoomAndPan(unsigned short zoomAndPan) +{ + m_zoomAndPan = zoomAndPan; +} + +bool SVGZoomAndPan::parseMappedAttribute(Attribute* attr) +{ + if (attr->name() == SVGNames::zoomAndPanAttr) { + const UChar* start = attr->value().characters(); + const UChar* end = start + attr->value().length(); + parseZoomAndPan(start, end); + return true; + } + + return false; +} + +bool SVGZoomAndPan::isKnownAttribute(const QualifiedName& attrName) +{ + return attrName == SVGNames::zoomAndPanAttr; +} + +static const UChar disable[] = {'d', 'i', 's', 'a', 'b', 'l', 'e'}; +static const UChar magnify[] = {'m', 'a', 'g', 'n', 'i', 'f', 'y'}; + +bool SVGZoomAndPan::parseZoomAndPan(const UChar*& start, const UChar* end) +{ + if (skipString(start, end, disable, WTF_ARRAY_LENGTH(disable))) + setZoomAndPan(SVG_ZOOMANDPAN_DISABLE); + else if (skipString(start, end, magnify, WTF_ARRAY_LENGTH(magnify))) + setZoomAndPan(SVG_ZOOMANDPAN_MAGNIFY); + else + return false; + + return true; +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/SVGZoomAndPan.h b/Source/WebCore/svg/SVGZoomAndPan.h new file mode 100644 index 0000000..973e97b --- /dev/null +++ b/Source/WebCore/svg/SVGZoomAndPan.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGZoomAndPan_h +#define SVGZoomAndPan_h + +#if ENABLE(SVG) + +#include <wtf/unicode/Unicode.h> + +namespace WebCore { + +class Attribute; +class QualifiedName; + +class SVGZoomAndPan { +public: + enum SVGZoomAndPanType { + SVG_ZOOMANDPAN_UNKNOWN = 0, + SVG_ZOOMANDPAN_DISABLE = 1, + SVG_ZOOMANDPAN_MAGNIFY = 2 + }; + + SVGZoomAndPan() : m_zoomAndPan(SVG_ZOOMANDPAN_MAGNIFY) { } + virtual ~SVGZoomAndPan() { } + + unsigned short zoomAndPan() const { return m_zoomAndPan; } + virtual void setZoomAndPan(unsigned short zoomAndPan); + + bool parseMappedAttribute(Attribute*); + bool isKnownAttribute(const QualifiedName&); + + bool parseZoomAndPan(const UChar*& start, const UChar* end); + +private: + unsigned short m_zoomAndPan; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) + +#endif // SVGZoomAndPan_h diff --git a/Source/WebCore/svg/SVGZoomAndPan.idl b/Source/WebCore/svg/SVGZoomAndPan.idl new file mode 100644 index 0000000..8135852 --- /dev/null +++ b/Source/WebCore/svg/SVGZoomAndPan.idl @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG, ObjCProtocol] SVGZoomAndPan { + // Zoom and Pan Types + const unsigned short SVG_ZOOMANDPAN_UNKNOWN = 0; + const unsigned short SVG_ZOOMANDPAN_DISABLE = 1; + const unsigned short SVG_ZOOMANDPAN_MAGNIFY = 2; + + attribute unsigned short zoomAndPan + /*setter raises(DOMException)*/; + }; + +} diff --git a/Source/WebCore/svg/SVGZoomEvent.cpp b/Source/WebCore/svg/SVGZoomEvent.cpp new file mode 100644 index 0000000..784c32b --- /dev/null +++ b/Source/WebCore/svg/SVGZoomEvent.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#if ENABLE(SVG) +#include "SVGZoomEvent.h" + +namespace WebCore { + +SVGZoomEvent::SVGZoomEvent() + : m_newScale(0.0f) + , m_previousScale(0.0f) +{ +} + +FloatRect SVGZoomEvent::zoomRectScreen() const +{ + return m_zoomRectScreen; +} + +float SVGZoomEvent::previousScale() const +{ + return m_previousScale; +} + +void SVGZoomEvent::setPreviousScale(float scale) +{ + m_previousScale = scale; +} + +FloatPoint SVGZoomEvent::previousTranslate() const +{ + return m_previousTranslate; +} + +float SVGZoomEvent::newScale() const +{ + return m_newScale; +} + +void SVGZoomEvent::setNewScale(float scale) +{ + m_newScale = scale; +} + +FloatPoint SVGZoomEvent::newTranslate() const +{ + return m_newTranslate; +} + +bool SVGZoomEvent::isSVGZoomEvent() const +{ + return true; +} + +} // namespace WebCore + +#endif // ENABLE(SVG) + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGZoomEvent.h b/Source/WebCore/svg/SVGZoomEvent.h new file mode 100644 index 0000000..d8d77ad --- /dev/null +++ b/Source/WebCore/svg/SVGZoomEvent.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGZoomEvent_h +#define SVGZoomEvent_h +#if ENABLE(SVG) + +#include "FloatRect.h" +#include "UIEvent.h" + +namespace WebCore { + +class SVGZoomEvent : public UIEvent { +public: + static PassRefPtr<SVGZoomEvent> create() { return adoptRef(new SVGZoomEvent); } + + // 'SVGZoomEvent' functions + FloatRect zoomRectScreen() const; + + float previousScale() const; + void setPreviousScale(float); + + FloatPoint previousTranslate() const; + + float newScale() const; + void setNewScale(float); + + FloatPoint newTranslate() const; + +private: + SVGZoomEvent(); + + virtual bool isSVGZoomEvent() const; + + float m_newScale; + float m_previousScale; + + FloatRect m_zoomRectScreen; + + FloatPoint m_newTranslate; + FloatPoint m_previousTranslate; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) +#endif // SVGZoomEvent_h + +// vim:ts=4:noet diff --git a/Source/WebCore/svg/SVGZoomEvent.idl b/Source/WebCore/svg/SVGZoomEvent.idl new file mode 100644 index 0000000..7ddd08f --- /dev/null +++ b/Source/WebCore/svg/SVGZoomEvent.idl @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2006 Apple 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 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 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. + */ + +module svg { + + interface [Conditional=SVG] SVGZoomEvent : UIEvent { + readonly attribute SVGRect zoomRectScreen; + readonly attribute float previousScale; + readonly attribute [Immutable] SVGPoint previousTranslate; + readonly attribute float newScale; + readonly attribute [Immutable] SVGPoint newTranslate; + }; + +} diff --git a/Source/WebCore/svg/animation/SMILTime.cpp b/Source/WebCore/svg/animation/SMILTime.cpp new file mode 100644 index 0000000..2b1f19e --- /dev/null +++ b/Source/WebCore/svg/animation/SMILTime.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2008 Apple 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 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 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" +#if ENABLE(SVG) +#include "SMILTime.h" + +#include <float.h> + +using namespace WebCore; + +const double SMILTime::unresolvedValue = DBL_MAX; +// Just a big value smaller than DBL_MAX. Our times are relative to 0, we don't really need the full range. +const double SMILTime::indefiniteValue = FLT_MAX; + +SMILTime WebCore::operator+(const SMILTime& a, const SMILTime& b) +{ + if (a.isUnresolved() || b.isUnresolved()) + return SMILTime::unresolved(); + if (a.isIndefinite() || b.isIndefinite()) + return SMILTime::indefinite(); + return a.value() + b.value(); +} + +SMILTime WebCore::operator-(const SMILTime& a, const SMILTime& b) +{ + if (a.isUnresolved() || b.isUnresolved()) + return SMILTime::unresolved(); + if (a.isIndefinite() || b.isIndefinite()) + return SMILTime::indefinite(); + return a.value() - b.value(); +} + +SMILTime WebCore::operator*(const SMILTime& a, const SMILTime& b) +{ + if (a.isUnresolved() || b.isUnresolved()) + return SMILTime::unresolved(); + if (!a.value() || !b.value()) + return SMILTime(0); + if (a.isIndefinite() || b.isIndefinite()) + return SMILTime::indefinite(); + return a.value() * b.value(); +} +#endif + diff --git a/Source/WebCore/svg/animation/SMILTime.h b/Source/WebCore/svg/animation/SMILTime.h new file mode 100644 index 0000000..f7276c3 --- /dev/null +++ b/Source/WebCore/svg/animation/SMILTime.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2008 Apple 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 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 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 SMILTime_h +#define SMILTime_h + +#if ENABLE(SVG) + +#include <algorithm> + +namespace WebCore { + +class SMILTime { +public: + SMILTime() : m_time(0) { } + SMILTime(double time) : m_time(time) { } + SMILTime(const SMILTime& o) : m_time(o.m_time) { } + + static SMILTime unresolved() { return unresolvedValue; } + static SMILTime indefinite() { return indefiniteValue; } + + SMILTime& operator=(const SMILTime& o) { m_time = o.m_time; return *this; } + double value() const { return m_time; } + + bool isFinite() const { return m_time < indefiniteValue; } + bool isIndefinite() const { return m_time == indefiniteValue; } + bool isUnresolved() const { return m_time == unresolvedValue; } + +private: + static const double unresolvedValue; + static const double indefiniteValue; + + double m_time; +}; + +inline bool operator==(const SMILTime& a, const SMILTime& b) { return a.isFinite() && a.value() == b.value(); } +inline bool operator!(const SMILTime& a) { return !a.isFinite() || !a.value(); } +inline bool operator!=(const SMILTime& a, const SMILTime& b) { return !operator==(a, b); } +inline bool operator>(const SMILTime& a, const SMILTime& b) { return a.value() > b.value(); } +inline bool operator<(const SMILTime& a, const SMILTime& b) { return a.value() < b.value(); } +inline bool operator>=(const SMILTime& a, const SMILTime& b) { return a.value() > b.value() || operator==(a, b); } +inline bool operator<=(const SMILTime& a, const SMILTime& b) { return a.value() < b.value() || operator==(a, b); } + +SMILTime operator+(const SMILTime&, const SMILTime&); +SMILTime operator-(const SMILTime&, const SMILTime&); +// So multiplying times does not make too much sense but SMIL defines it for duration * repeatCount +SMILTime operator*(const SMILTime&, const SMILTime&); + +} + +#endif // ENABLE(SVG) +#endif // SMILTime_h diff --git a/Source/WebCore/svg/animation/SMILTimeContainer.cpp b/Source/WebCore/svg/animation/SMILTimeContainer.cpp new file mode 100644 index 0000000..3251d5b --- /dev/null +++ b/Source/WebCore/svg/animation/SMILTimeContainer.cpp @@ -0,0 +1,319 @@ +/* + * Copyright (C) 2008 Apple 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 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 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 "SMILTimeContainer.h" + +#if ENABLE(SVG) +#include "CSSComputedStyleDeclaration.h" +#include "CSSParser.h" +#include "Document.h" +#include "SVGAnimationElement.h" +#include "SVGNames.h" +#include "SVGSMILElement.h" +#include "SVGSVGElement.h" +#include <wtf/CurrentTime.h> + +using namespace std; + +namespace WebCore { + +static const double animationFrameDelay = 0.025; + +SMILTimeContainer::SMILTimeContainer(SVGSVGElement* owner) + : m_beginTime(0) + , m_pauseTime(0) + , m_accumulatedPauseTime(0) + , m_nextManualSampleTime(0) + , m_documentOrderIndexesDirty(false) + , m_timer(this, &SMILTimeContainer::timerFired) + , m_ownerSVGElement(owner) +{ +} + +#if !ENABLE(SVG_ANIMATION) +void SMILTimeContainer::begin() {} +void SMILTimeContainer::pause() {} +void SMILTimeContainer::resume() {} +SMILTime SMILTimeContainer::elapsed() const { return 0; } +bool SMILTimeContainer::isPaused() const { return false; } +void SMILTimeContainer::timerFired(Timer<SMILTimeContainer>*) {} +#else + +void SMILTimeContainer::schedule(SVGSMILElement* animation) +{ + ASSERT(animation->timeContainer() == this); + SMILTime nextFireTime = animation->nextProgressTime(); + if (!nextFireTime.isFinite()) + return; + m_scheduledAnimations.add(animation); + startTimer(0); +} + +void SMILTimeContainer::unschedule(SVGSMILElement* animation) +{ + ASSERT(animation->timeContainer() == this); + + m_scheduledAnimations.remove(animation); +} + +SMILTime SMILTimeContainer::elapsed() const +{ + if (!m_beginTime) + return 0; + return currentTime() - m_beginTime - m_accumulatedPauseTime; +} + +bool SMILTimeContainer::isActive() const +{ + return m_beginTime && !isPaused(); +} + +bool SMILTimeContainer::isPaused() const +{ + return m_pauseTime; +} + +void SMILTimeContainer::begin() +{ + ASSERT(!m_beginTime); + m_beginTime = currentTime(); + updateAnimations(0); +} + +void SMILTimeContainer::pause() +{ + if (!m_beginTime) + return; + ASSERT(!isPaused()); + m_pauseTime = currentTime(); + m_timer.stop(); +} + +void SMILTimeContainer::resume() +{ + if (!m_beginTime) + return; + ASSERT(isPaused()); + m_accumulatedPauseTime += currentTime() - m_pauseTime; + m_pauseTime = 0; + startTimer(0); +} + +void SMILTimeContainer::startTimer(SMILTime fireTime, SMILTime minimumDelay) +{ + if (!m_beginTime || isPaused()) + return; + + if (!fireTime.isFinite()) + return; + + SMILTime delay = max(fireTime - elapsed(), minimumDelay); + m_timer.startOneShot(delay.value()); +} + +void SMILTimeContainer::timerFired(Timer<SMILTimeContainer>*) +{ + ASSERT(m_beginTime); + ASSERT(!m_pauseTime); + SMILTime elapsed = this->elapsed(); + updateAnimations(elapsed); +} + +void SMILTimeContainer::updateDocumentOrderIndexes() +{ + unsigned timingElementCount = 0; + for (Node* node = m_ownerSVGElement; node; node = node->traverseNextNode(m_ownerSVGElement)) { + if (SVGSMILElement::isSMILElement(node)) + static_cast<SVGSMILElement*>(node)->setDocumentOrderIndex(timingElementCount++); + } + m_documentOrderIndexesDirty = false; +} + +struct PriorityCompare { + PriorityCompare(SMILTime elapsed) : m_elapsed(elapsed) {} + bool operator()(SVGSMILElement* a, SVGSMILElement* b) + { + // FIXME: This should also consider possible timing relations between the elements. + SMILTime aBegin = a->intervalBegin(); + SMILTime bBegin = b->intervalBegin(); + // Frozen elements need to be prioritized based on their previous interval. + aBegin = a->isFrozen() && m_elapsed < aBegin ? a->previousIntervalBegin() : aBegin; + bBegin = b->isFrozen() && m_elapsed < bBegin ? b->previousIntervalBegin() : bBegin; + if (aBegin == bBegin) + return a->documentOrderIndex() < b->documentOrderIndex(); + return aBegin < bBegin; + } + SMILTime m_elapsed; +}; + +void SMILTimeContainer::sortByPriority(Vector<SVGSMILElement*>& smilElements, SMILTime elapsed) +{ + if (m_documentOrderIndexesDirty) + updateDocumentOrderIndexes(); + std::sort(smilElements.begin(), smilElements.end(), PriorityCompare(elapsed)); +} + +static bool applyOrderSortFunction(SVGSMILElement* a, SVGSMILElement* b) +{ + if (!a->hasTagName(SVGNames::animateTransformTag) && b->hasTagName(SVGNames::animateTransformTag)) + return true; + return false; +} + +static void sortByApplyOrder(Vector<SVGSMILElement*>& smilElements) +{ + std::sort(smilElements.begin(), smilElements.end(), applyOrderSortFunction); +} + +String SMILTimeContainer::baseValueFor(ElementAttributePair key) +{ + // FIXME: We wouldn't need to do this if we were keeping base values around properly in DOM. + // Currently animation overwrites them so we need to save them somewhere. + BaseValueMap::iterator it = m_savedBaseValues.find(key); + if (it != m_savedBaseValues.end()) + return it->second; + + SVGElement* target = key.first; + String attributeName = key.second; + ASSERT(target); + ASSERT(!attributeName.isEmpty()); + String baseValue; + if (SVGAnimationElement::attributeIsCSS(attributeName)) + baseValue = computedStyle(target)->getPropertyValue(cssPropertyID(attributeName)); + else + baseValue = target->getAttribute(attributeName); + m_savedBaseValues.add(key, baseValue); + return baseValue; +} + +void SMILTimeContainer::sampleAnimationAtTime(const String& elementId, double newTime) +{ + ASSERT(m_beginTime); + ASSERT(!isPaused()); + + // Fast-forward to the time DRT wants to sample + m_timer.stop(); + m_nextSamplingTarget = elementId; + m_nextManualSampleTime = newTime; + + updateAnimations(elapsed()); +} + +void SMILTimeContainer::updateAnimations(SMILTime elapsed) +{ + SMILTime earliersFireTime = SMILTime::unresolved(); + + Vector<SVGSMILElement*> toAnimate; + copyToVector(m_scheduledAnimations, toAnimate); + + if (m_nextManualSampleTime) { + SMILTime samplingDiff; + for (unsigned n = 0; n < toAnimate.size(); ++n) { + SVGSMILElement* animation = toAnimate[n]; + ASSERT(animation->timeContainer() == this); + + SVGElement* targetElement = animation->targetElement(); + // FIXME: This should probably be using getIdAttribute instead of idForStyleResolution. + if (!targetElement || !targetElement->hasID() || targetElement->idForStyleResolution() != m_nextSamplingTarget) + continue; + + samplingDiff = animation->intervalBegin(); + break; + } + + elapsed = SMILTime(m_nextManualSampleTime) + samplingDiff; + m_nextManualSampleTime = 0; + } + + // Sort according to priority. Elements with later begin time have higher priority. + // In case of a tie, document order decides. + // FIXME: This should also consider timing relationships between the elements. Dependents + // have higher priority. + sortByPriority(toAnimate, elapsed); + + // Calculate animation contributions. + typedef HashMap<ElementAttributePair, RefPtr<SVGSMILElement> > ResultElementMap; + ResultElementMap resultsElements; + for (unsigned n = 0; n < toAnimate.size(); ++n) { + SVGSMILElement* animation = toAnimate[n]; + ASSERT(animation->timeContainer() == this); + + SVGElement* targetElement = animation->targetElement(); + if (!targetElement) + continue; + String attributeName = animation->attributeName(); + if (attributeName.isEmpty()) { + if (animation->hasTagName(SVGNames::animateMotionTag)) + attributeName = SVGNames::animateMotionTag.localName(); + else + continue; + } + + // Results are accumulated to the first animation that animates a particular element/attribute pair. + ElementAttributePair key(targetElement, attributeName); + SVGSMILElement* resultElement = resultsElements.get(key).get(); + if (!resultElement) { + resultElement = animation; + resultElement->resetToBaseValue(baseValueFor(key)); + resultsElements.add(key, resultElement); + } + + // This will calculate the contribution from the animation and add it to the resultsElement. + animation->progress(elapsed, resultElement); + + SMILTime nextFireTime = animation->nextProgressTime(); + if (nextFireTime.isFinite()) + earliersFireTime = min(nextFireTime, earliersFireTime); + else if (!animation->isContributing(elapsed)) { + m_scheduledAnimations.remove(animation); + if (m_scheduledAnimations.isEmpty()) + m_savedBaseValues.clear(); + } + } + + Vector<SVGSMILElement*> animationsToApply; + ResultElementMap::iterator end = resultsElements.end(); + for (ResultElementMap::iterator it = resultsElements.begin(); it != end; ++it) + animationsToApply.append(it->second.get()); + + // Sort <animateTranform> to be the last one to be applied. <animate> may change transform attribute as + // well (directly or indirectly by modifying <use> x/y) and this way transforms combine properly. + sortByApplyOrder(animationsToApply); + + // Apply results to target elements. + for (unsigned n = 0; n < animationsToApply.size(); ++n) + animationsToApply[n]->applyResultsToTarget(); + + startTimer(earliersFireTime, animationFrameDelay); + + Document::updateStyleForAllDocuments(); +} + +#endif + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/animation/SMILTimeContainer.h b/Source/WebCore/svg/animation/SMILTimeContainer.h new file mode 100644 index 0000000..bf734d3 --- /dev/null +++ b/Source/WebCore/svg/animation/SMILTimeContainer.h @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2008 Apple 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 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 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 SMILTimeContainer_h +#define SMILTimeContainer_h + +#if ENABLE(SVG) + +#include "PlatformString.h" +#include "SMILTime.h" +#include "Timer.h" +#include <wtf/HashMap.h> +#include <wtf/HashSet.h> +#include <wtf/PassRefPtr.h> +#include <wtf/RefCounted.h> +#include <wtf/text/StringHash.h> + +namespace WebCore { + +class SVGElement; +class SVGSMILElement; +class SVGSVGElement; + +class SMILTimeContainer : public RefCounted<SMILTimeContainer> { +public: + static PassRefPtr<SMILTimeContainer> create(SVGSVGElement* owner) { return adoptRef(new SMILTimeContainer(owner)); } + + void schedule(SVGSMILElement*); + void unschedule(SVGSMILElement*); + + SMILTime elapsed() const; + + bool isActive() const; + bool isPaused() const; + + void begin(); + void pause(); + void resume(); + + void setDocumentOrderIndexesDirty() { m_documentOrderIndexesDirty = true; } + + // Move to a specific time. Only used for DRT testing purposes. + void sampleAnimationAtTime(const String& elementId, double seconds); + +private: + SMILTimeContainer(SVGSVGElement* owner); + + void timerFired(Timer<SMILTimeContainer>*); + void startTimer(SMILTime fireTime, SMILTime minimumDelay = 0); + void updateAnimations(SMILTime elapsed); + + void updateDocumentOrderIndexes(); + void sortByPriority(Vector<SVGSMILElement*>& smilElements, SMILTime elapsed); + + typedef pair<SVGElement*, String> ElementAttributePair; + String baseValueFor(ElementAttributePair); + + double m_beginTime; + double m_pauseTime; + double m_accumulatedPauseTime; + double m_nextManualSampleTime; + String m_nextSamplingTarget; + + bool m_documentOrderIndexesDirty; + + Timer<SMILTimeContainer> m_timer; + + typedef HashSet<SVGSMILElement*> TimingElementSet; + TimingElementSet m_scheduledAnimations; + + typedef HashMap<ElementAttributePair, String> BaseValueMap; + BaseValueMap m_savedBaseValues; + + SVGSVGElement* m_ownerSVGElement; +}; +} + +#endif // ENABLE(SVG) +#endif // SMILTimeContainer_h diff --git a/Source/WebCore/svg/animation/SVGSMILElement.cpp b/Source/WebCore/svg/animation/SVGSMILElement.cpp new file mode 100644 index 0000000..2364c6a --- /dev/null +++ b/Source/WebCore/svg/animation/SVGSMILElement.cpp @@ -0,0 +1,963 @@ +/* + * Copyright (C) 2008 Apple 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 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 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" + +#if ENABLE(SVG_ANIMATION) +#include "SVGSMILElement.h" + +#include "Attribute.h" +#include "CSSPropertyNames.h" +#include "Document.h" +#include "Event.h" +#include "EventListener.h" +#include "FloatConversion.h" +#include "FrameView.h" +#include "HTMLNames.h" +#include "SMILTimeContainer.h" +#include "SVGNames.h" +#include "SVGParserUtilities.h" +#include "SVGSVGElement.h" +#include "SVGURIReference.h" +#include "XLinkNames.h" +#include <math.h> +#include <wtf/MathExtras.h> +#include <wtf/StdLibExtras.h> +#include <wtf/Vector.h> + +using namespace std; + +namespace WebCore { + +// This is used for duration type time values that can't be negative. +static const double invalidCachedTime = -1.; + +class ConditionEventListener : public EventListener { +public: + static PassRefPtr<ConditionEventListener> create(SVGSMILElement* animation, SVGSMILElement::Condition* condition) + { + return adoptRef(new ConditionEventListener(animation, condition)); + } + + static const ConditionEventListener* cast(const EventListener* listener) + { + return listener->type() == ConditionEventListenerType + ? static_cast<const ConditionEventListener*>(listener) + : 0; + } + + virtual bool operator==(const EventListener& other); + + void disconnectAnimation() + { + m_animation = 0; + } + +private: + ConditionEventListener(SVGSMILElement* animation, SVGSMILElement::Condition* condition) + : EventListener(ConditionEventListenerType) + , m_animation(animation) + , m_condition(condition) + { + } + + virtual void handleEvent(ScriptExecutionContext*, Event*); + + SVGSMILElement* m_animation; + SVGSMILElement::Condition* m_condition; +}; + +bool ConditionEventListener::operator==(const EventListener& listener) +{ + if (const ConditionEventListener* conditionEventListener = ConditionEventListener::cast(&listener)) + return m_animation == conditionEventListener->m_animation && m_condition == conditionEventListener->m_condition; + return false; +} + +void ConditionEventListener::handleEvent(ScriptExecutionContext*, Event* event) +{ + if (!m_animation) + return; + m_animation->handleConditionEvent(event, m_condition); +} + +SVGSMILElement::Condition::Condition(Type type, BeginOrEnd beginOrEnd, const String& baseID, const String& name, SMILTime offset, int repeats) + : m_type(type) + , m_beginOrEnd(beginOrEnd) + , m_baseID(baseID) + , m_name(name) + , m_offset(offset) + , m_repeats(repeats) +{ +} + +SVGSMILElement::SVGSMILElement(const QualifiedName& tagName, Document* doc) + : SVGElement(tagName, doc) + , m_conditionsConnected(false) + , m_hasEndEventConditions(false) + , m_intervalBegin(SMILTime::unresolved()) + , m_intervalEnd(SMILTime::unresolved()) + , m_previousIntervalBegin(SMILTime::unresolved()) + , m_isWaitingForFirstInterval(true) + , m_activeState(Inactive) + , m_lastPercent(0) + , m_lastRepeat(0) + , m_nextProgressTime(0) + , m_documentOrderIndex(0) + , m_cachedDur(invalidCachedTime) + , m_cachedRepeatDur(invalidCachedTime) + , m_cachedRepeatCount(invalidCachedTime) + , m_cachedMin(invalidCachedTime) + , m_cachedMax(invalidCachedTime) +{ +} + +SVGSMILElement::~SVGSMILElement() +{ + disconnectConditions(); + if (m_timeContainer) + m_timeContainer->unschedule(this); +} + +void SVGSMILElement::insertedIntoDocument() +{ + SVGElement::insertedIntoDocument(); +#ifndef NDEBUG + // Verify we are not in <use> instance tree. + for (ContainerNode* n = this; n; n = n->parentNode()) + ASSERT(!n->isShadowRoot()); +#endif + SVGSVGElement* owner = ownerSVGElement(); + if (!owner) + return; + m_timeContainer = owner->timeContainer(); + ASSERT(m_timeContainer); + m_timeContainer->setDocumentOrderIndexesDirty(); + reschedule(); +} + +void SVGSMILElement::removedFromDocument() +{ + if (m_timeContainer) { + m_timeContainer->unschedule(this); + m_timeContainer = 0; + } + // Calling disconnectConditions() may kill us if there are syncbase conditions. + // OK, but we don't want to die inside the call. + RefPtr<SVGSMILElement> keepAlive(this); + disconnectConditions(); + SVGElement::removedFromDocument(); +} + +void SVGSMILElement::finishParsingChildren() +{ + SVGElement::finishParsingChildren(); + + // "If no attribute is present, the default begin value (an offset-value of 0) must be evaluated." + if (!hasAttribute(SVGNames::beginAttr)) + m_beginTimes.append(0); + + if (m_isWaitingForFirstInterval) { + resolveFirstInterval(); + reschedule(); + } +} + +SMILTime SVGSMILElement::parseOffsetValue(const String& data) +{ + bool ok; + double result = 0; + String parse = data.stripWhiteSpace(); + if (parse.endsWith("h")) + result = parse.left(parse.length() - 1).toDouble(&ok) * 60 * 60; + else if (parse.endsWith("min")) + result = parse.left(parse.length() - 3).toDouble(&ok) * 60; + else if (parse.endsWith("ms")) + result = parse.left(parse.length() - 2).toDouble(&ok) / 1000; + else if (parse.endsWith("s")) + result = parse.left(parse.length() - 1).toDouble(&ok); + else + result = parse.toDouble(&ok); + if (!ok) + return SMILTime::unresolved(); + return result; +} + +SMILTime SVGSMILElement::parseClockValue(const String& data) +{ + if (data.isNull()) + return SMILTime::unresolved(); + + String parse = data.stripWhiteSpace(); + + DEFINE_STATIC_LOCAL(const AtomicString, indefiniteValue, ("indefinite")); + if (parse == indefiniteValue) + return SMILTime::indefinite(); + + double result = 0; + bool ok; + size_t doublePointOne = parse.find(':'); + size_t doublePointTwo = parse.find(':', doublePointOne + 1); + if (doublePointOne == 2 && doublePointTwo == 5 && parse.length() >= 8) { + result += parse.substring(0, 2).toUIntStrict(&ok) * 60 * 60; + if (!ok) + return SMILTime::unresolved(); + result += parse.substring(3, 2).toUIntStrict(&ok) * 60; + if (!ok) + return SMILTime::unresolved(); + result += parse.substring(6).toDouble(&ok); + } else if (doublePointOne == 2 && doublePointTwo == notFound && parse.length() >= 5) { + result += parse.substring(0, 2).toUIntStrict(&ok) * 60; + if (!ok) + return SMILTime::unresolved(); + result += parse.substring(3).toDouble(&ok); + } else + return parseOffsetValue(parse); + + if (!ok) + return SMILTime::unresolved(); + return result; +} + +static void sortTimeList(Vector<SMILTime>& timeList) +{ + std::sort(timeList.begin(), timeList.end()); +} + +bool SVGSMILElement::parseCondition(const String& value, BeginOrEnd beginOrEnd) +{ + String parseString = value.stripWhiteSpace(); + + double sign = 1.; + bool ok; + size_t pos = parseString.find('+'); + if (pos == notFound) { + pos = parseString.find('-'); + if (pos != notFound) + sign = -1.; + } + String conditionString; + SMILTime offset = 0; + if (pos == notFound) + conditionString = parseString; + else { + conditionString = parseString.left(pos).stripWhiteSpace(); + String offsetString = parseString.substring(pos + 1).stripWhiteSpace(); + offset = parseOffsetValue(offsetString); + if (offset.isUnresolved()) + return false; + offset = offset * sign; + } + if (conditionString.isEmpty()) + return false; + pos = conditionString.find('.'); + + String baseID; + String nameString; + if (pos == notFound) + nameString = conditionString; + else { + baseID = conditionString.left(pos); + nameString = conditionString.substring(pos + 1); + } + if (nameString.isEmpty()) + return false; + + Condition::Type type; + int repeats = -1; + if (nameString.startsWith("repeat(") && nameString.endsWith(")")) { + // FIXME: For repeat events we just need to add the data carrying TimeEvent class and + // fire the events at appropiate times. + repeats = nameString.substring(7, nameString.length() - 8).toUIntStrict(&ok); + if (!ok) + return false; + nameString = "repeat"; + type = Condition::EventBase; + } else if (nameString == "begin" || nameString == "end") { + if (baseID.isEmpty()) + return false; + type = Condition::Syncbase; + } else if (nameString.startsWith("accesskey(")) { + // FIXME: accesskey() support. + type = Condition::AccessKey; + } else + type = Condition::EventBase; + + m_conditions.append(Condition(type, beginOrEnd, baseID, nameString, offset, repeats)); + + if (type == Condition::EventBase && beginOrEnd == End) + m_hasEndEventConditions = true; + + return true; +} + +bool SVGSMILElement::isSMILElement(Node* node) +{ + if (!node) + return false; + return node->hasTagName(SVGNames::setTag) || node->hasTagName(SVGNames::animateTag) || node->hasTagName(SVGNames::animateMotionTag) + || node->hasTagName(SVGNames::animateTransformTag) || node->hasTagName(SVGNames::animateColorTag); +} + +void SVGSMILElement::parseBeginOrEnd(const String& parseString, BeginOrEnd beginOrEnd) +{ + Vector<SMILTime>& timeList = beginOrEnd == Begin ? m_beginTimes : m_endTimes; + if (beginOrEnd == End) + m_hasEndEventConditions = false; + HashSet<double> existing; + for (unsigned n = 0; n < timeList.size(); ++n) + existing.add(timeList[n].value()); + Vector<String> splitString; + parseString.split(';', splitString); + for (unsigned n = 0; n < splitString.size(); ++n) { + SMILTime value = parseClockValue(splitString[n]); + if (value.isUnresolved()) + parseCondition(splitString[n], beginOrEnd); + else if (!existing.contains(value.value())) + timeList.append(value); + } + sortTimeList(timeList); +} + +void SVGSMILElement::parseMappedAttribute(Attribute* attr) +{ + if (attr->name() == SVGNames::beginAttr) { + if (!m_conditions.isEmpty()) { + disconnectConditions(); + m_conditions.clear(); + parseBeginOrEnd(getAttribute(SVGNames::endAttr), End); + } + parseBeginOrEnd(attr->value().string(), Begin); + if (inDocument()) + connectConditions(); + } else if (attr->name() == SVGNames::endAttr) { + if (!m_conditions.isEmpty()) { + disconnectConditions(); + m_conditions.clear(); + parseBeginOrEnd(getAttribute(SVGNames::beginAttr), Begin); + } + parseBeginOrEnd(attr->value().string(), End); + if (inDocument()) + connectConditions(); + } else + SVGElement::parseMappedAttribute(attr); +} + +void SVGSMILElement::attributeChanged(Attribute* attr, bool preserveDecls) +{ + SVGElement::attributeChanged(attr, preserveDecls); + + const QualifiedName& attrName = attr->name(); + if (attrName == SVGNames::durAttr) + m_cachedDur = invalidCachedTime; + else if (attrName == SVGNames::repeatDurAttr) + m_cachedRepeatDur = invalidCachedTime; + else if (attrName == SVGNames::repeatCountAttr) + m_cachedRepeatCount = invalidCachedTime; + else if (attrName == SVGNames::minAttr) + m_cachedMin = invalidCachedTime; + else if (attrName == SVGNames::maxAttr) + m_cachedMax = invalidCachedTime; + + if (inDocument()) { + if (attrName == SVGNames::beginAttr) + beginListChanged(); + else if (attrName == SVGNames::endAttr) + endListChanged(); + } +} + +inline Element* SVGSMILElement::eventBaseFor(const Condition& condition) const +{ + return condition.m_baseID.isEmpty() ? targetElement() : document()->getElementById(condition.m_baseID); +} + +void SVGSMILElement::connectConditions() +{ + if (m_conditionsConnected) + disconnectConditions(); + m_conditionsConnected = true; + for (unsigned n = 0; n < m_conditions.size(); ++n) { + Condition& condition = m_conditions[n]; + if (condition.m_type == Condition::EventBase) { + ASSERT(!condition.m_syncbase); + Element* eventBase = eventBaseFor(condition); + if (!eventBase) + continue; + ASSERT(!condition.m_eventListener); + condition.m_eventListener = ConditionEventListener::create(this, &condition); + eventBase->addEventListener(condition.m_name, condition.m_eventListener, false); + } else if (condition.m_type == Condition::Syncbase) { + ASSERT(!condition.m_baseID.isEmpty()); + condition.m_syncbase = document()->getElementById(condition.m_baseID); + if (!isSMILElement(condition.m_syncbase.get())) { + condition.m_syncbase = 0; + continue; + } + SVGSMILElement* syncbase = static_cast<SVGSMILElement*>(condition.m_syncbase.get()); + syncbase->addTimeDependent(this); + } + } +} + +void SVGSMILElement::disconnectConditions() +{ + if (!m_conditionsConnected) + return; + m_conditionsConnected = false; + for (unsigned n = 0; n < m_conditions.size(); ++n) { + Condition& condition = m_conditions[n]; + if (condition.m_type == Condition::EventBase) { + ASSERT(!condition.m_syncbase); + if (!condition.m_eventListener) + continue; + // Note: It's a memory optimization to try to remove our condition + // event listener, but it's not guaranteed to work, since we have + // no guarantee that eventBaseFor() will be able to find our condition's + // original eventBase. So, we also have to disconnect ourselves from + // our condition event listener, in case it later fires. + Element* eventBase = eventBaseFor(condition); + if (eventBase) + eventBase->removeEventListener(condition.m_name, condition.m_eventListener.get(), false); + condition.m_eventListener->disconnectAnimation(); + condition.m_eventListener = 0; + } else if (condition.m_type == Condition::Syncbase) { + if (condition.m_syncbase) { + ASSERT(isSMILElement(condition.m_syncbase.get())); + static_cast<SVGSMILElement*>(condition.m_syncbase.get())->removeTimeDependent(this); + } + } + condition.m_syncbase = 0; + } +} + +void SVGSMILElement::reschedule() +{ + if (m_timeContainer) + m_timeContainer->schedule(this); +} + +SVGElement* SVGSMILElement::targetElement() const +{ + String href = xlinkHref(); + ContainerNode* target = href.isEmpty() ? parentNode() : document()->getElementById(SVGURIReference::getTarget(href)); + if (target && target->isSVGElement()) + return static_cast<SVGElement*>(target); + return 0; +} + +String SVGSMILElement::attributeName() const +{ + return getAttribute(SVGNames::attributeNameAttr).string().stripWhiteSpace(); +} + +SMILTime SVGSMILElement::elapsed() const +{ + return m_timeContainer ? m_timeContainer->elapsed() : 0; +} + +bool SVGSMILElement::isInactive() const +{ + return m_activeState == Inactive; +} + +bool SVGSMILElement::isFrozen() const +{ + return m_activeState == Frozen; +} + +SVGSMILElement::Restart SVGSMILElement::restart() const +{ + DEFINE_STATIC_LOCAL(const AtomicString, never, ("never")); + DEFINE_STATIC_LOCAL(const AtomicString, whenNotActive, ("whenNotActive")); + const AtomicString& value = getAttribute(SVGNames::restartAttr); + if (value == never) + return RestartNever; + if (value == whenNotActive) + return RestartWhenNotActive; + return RestartAlways; +} + +SVGSMILElement::FillMode SVGSMILElement::fill() const +{ + DEFINE_STATIC_LOCAL(const AtomicString, freeze, ("freeze")); + const AtomicString& value = getAttribute(SVGNames::fillAttr); + return value == freeze ? FillFreeze : FillRemove; +} + +String SVGSMILElement::xlinkHref() const +{ + return getAttribute(XLinkNames::hrefAttr); +} + +SMILTime SVGSMILElement::dur() const +{ + if (m_cachedDur != invalidCachedTime) + return m_cachedDur; + const AtomicString& value = getAttribute(SVGNames::durAttr); + SMILTime clockValue = parseClockValue(value); + return m_cachedDur = clockValue <= 0 ? SMILTime::unresolved() : clockValue; +} + +SMILTime SVGSMILElement::repeatDur() const +{ + if (m_cachedRepeatDur != invalidCachedTime) + return m_cachedRepeatDur; + const AtomicString& value = getAttribute(SVGNames::repeatDurAttr); + SMILTime clockValue = parseClockValue(value); + m_cachedRepeatDur = clockValue <= 0 ? SMILTime::unresolved() : clockValue; + return m_cachedRepeatDur; +} + +// So a count is not really a time but let just all pretend we did not notice. +SMILTime SVGSMILElement::repeatCount() const +{ + if (m_cachedRepeatCount != invalidCachedTime) + return m_cachedRepeatCount; + const AtomicString& value = getAttribute(SVGNames::repeatCountAttr); + if (value.isNull()) + return SMILTime::unresolved(); + + DEFINE_STATIC_LOCAL(const AtomicString, indefiniteValue, ("indefinite")); + if (value == indefiniteValue) + return SMILTime::indefinite(); + bool ok; + double result = value.string().toDouble(&ok); + return m_cachedRepeatCount = ok && result > 0 ? result : SMILTime::unresolved(); +} + +SMILTime SVGSMILElement::maxValue() const +{ + if (m_cachedMax != invalidCachedTime) + return m_cachedMax; + const AtomicString& value = getAttribute(SVGNames::maxAttr); + SMILTime result = parseClockValue(value); + return m_cachedMax = (result.isUnresolved() || result < 0) ? SMILTime::indefinite() : result; +} + +SMILTime SVGSMILElement::minValue() const +{ + if (m_cachedMin != invalidCachedTime) + return m_cachedMin; + const AtomicString& value = getAttribute(SVGNames::minAttr); + SMILTime result = parseClockValue(value); + return m_cachedMin = (result.isUnresolved() || result < 0) ? 0 : result; +} + +SMILTime SVGSMILElement::simpleDuration() const +{ + return min(dur(), SMILTime::indefinite()); +} + +void SVGSMILElement::addBeginTime(SMILTime time) +{ + m_beginTimes.append(time); + sortTimeList(m_beginTimes); + beginListChanged(); +} + +void SVGSMILElement::addEndTime(SMILTime time) +{ + m_endTimes.append(time); + sortTimeList(m_endTimes); + endListChanged(); +} + +SMILTime SVGSMILElement::findInstanceTime(BeginOrEnd beginOrEnd, SMILTime minimumTime, bool equalsMinimumOK) const +{ + // FIXME: This searches from the beginning which is inefficient. The list is usually not long + // (one entry in common cases) but you can construct a case where it does grow. + const Vector<SMILTime>& list = beginOrEnd == Begin ? m_beginTimes : m_endTimes; + for (unsigned n = 0; n < list.size(); ++n) { + SMILTime time = list[n]; + ASSERT(!time.isUnresolved()); + if (time.isIndefinite() && beginOrEnd == Begin) { + // "The special value "indefinite" does not yield an instance time in the begin list." + continue; + } + if (equalsMinimumOK) { + if (time >= minimumTime) + return time; + } else if (time > minimumTime) + return time; + } + return SMILTime::unresolved(); +} + +SMILTime SVGSMILElement::repeatingDuration() const +{ + // Computing the active duration + // http://www.w3.org/TR/SMIL2/smil-timing.html#Timing-ComputingActiveDur + SMILTime repeatCount = this->repeatCount(); + SMILTime repeatDur = this->repeatDur(); + SMILTime simpleDuration = this->simpleDuration(); + if (!simpleDuration || (repeatDur.isUnresolved() && repeatCount.isUnresolved())) + return simpleDuration; + SMILTime repeatCountDuration = simpleDuration * repeatCount; + return min(repeatCountDuration, min(repeatDur, SMILTime::indefinite())); +} + +SMILTime SVGSMILElement::resolveActiveEnd(SMILTime resolvedBegin, SMILTime resolvedEnd) const +{ + // Computing the active duration + // http://www.w3.org/TR/SMIL2/smil-timing.html#Timing-ComputingActiveDur + SMILTime preliminaryActiveDuration; + if (!resolvedEnd.isUnresolved() && dur().isUnresolved() && repeatDur().isUnresolved() && repeatCount().isUnresolved()) + preliminaryActiveDuration = resolvedEnd - resolvedBegin; + else if (!resolvedEnd.isFinite()) + preliminaryActiveDuration = repeatingDuration(); + else + preliminaryActiveDuration = min(repeatingDuration(), resolvedEnd - resolvedBegin); + + SMILTime minValue = this->minValue(); + SMILTime maxValue = this->maxValue(); + if (minValue > maxValue) { + // Ignore both. + // http://www.w3.org/TR/2001/REC-smil-animation-20010904/#MinMax + minValue = 0; + maxValue = SMILTime::indefinite(); + } + return resolvedBegin + min(maxValue, max(minValue, preliminaryActiveDuration)); +} + +void SVGSMILElement::resolveInterval(bool first, SMILTime& beginResult, SMILTime& endResult) const +{ + // See the pseudocode in + // http://www.w3.org/TR/2001/REC-smil-animation-20010904/#Timing-BeginEnd-LifeCycle + SMILTime beginAfter = first ? -numeric_limits<double>::infinity() : m_intervalEnd; + SMILTime lastIntervalTempEnd = numeric_limits<double>::infinity(); + while (true) { + SMILTime tempBegin = findInstanceTime(Begin, beginAfter, true); + if (tempBegin.isUnresolved()) + break; + SMILTime tempEnd; + if (m_endTimes.isEmpty()) + tempEnd = resolveActiveEnd(tempBegin, SMILTime::indefinite()); + else { + tempEnd = findInstanceTime(End, tempBegin, true); + if ((first && tempBegin == tempEnd && tempEnd == lastIntervalTempEnd) || (!first && tempEnd == m_intervalEnd)) + tempEnd = findInstanceTime(End, tempBegin, false); + if (tempEnd.isUnresolved()) { + if (!m_endTimes.isEmpty() && !m_hasEndEventConditions) + break; + } + tempEnd = resolveActiveEnd(tempBegin, tempEnd); + } + if (tempEnd > 0 || !first) { + beginResult = tempBegin; + endResult = tempEnd; + return; + } + if (restart() == RestartNever) + break; + + beginAfter = tempEnd; + lastIntervalTempEnd = tempEnd; + } + beginResult = SMILTime::unresolved(); + endResult = SMILTime::unresolved(); +} + +void SVGSMILElement::resolveFirstInterval() +{ + SMILTime begin; + SMILTime end; + resolveInterval(true, begin, end); + ASSERT(!begin.isIndefinite()); + + if (!begin.isUnresolved() && (begin != m_intervalBegin || end != m_intervalEnd)) { + bool wasUnresolved = m_intervalBegin.isUnresolved(); + m_intervalBegin = begin; + m_intervalEnd = end; + notifyDependentsIntervalChanged(wasUnresolved ? NewInterval : ExistingInterval); + m_nextProgressTime = min(m_nextProgressTime, m_intervalBegin); + reschedule(); + } +} + +void SVGSMILElement::resolveNextInterval() +{ + SMILTime begin; + SMILTime end; + resolveInterval(false, begin, end); + ASSERT(!begin.isIndefinite()); + + if (!begin.isUnresolved() && begin != m_intervalBegin) { + m_intervalBegin = begin; + m_intervalEnd = end; + notifyDependentsIntervalChanged(NewInterval); + m_nextProgressTime = min(m_nextProgressTime, m_intervalBegin); + } +} + +SMILTime SVGSMILElement::nextProgressTime() const +{ + return m_nextProgressTime; +} + +void SVGSMILElement::beginListChanged() +{ + SMILTime elapsed = this->elapsed(); + if (m_isWaitingForFirstInterval) + resolveFirstInterval(); + else if (elapsed < m_intervalBegin) { + SMILTime newBegin = findInstanceTime(Begin, elapsed, false); + if (newBegin < m_intervalBegin) { + // Begin time changed, re-resolve the interval. + SMILTime oldBegin = m_intervalBegin; + m_intervalBegin = elapsed; + resolveInterval(false, m_intervalBegin, m_intervalEnd); + ASSERT(!m_intervalBegin.isUnresolved()); + if (m_intervalBegin != oldBegin) + notifyDependentsIntervalChanged(ExistingInterval); + } + } + m_nextProgressTime = elapsed; + reschedule(); +} + +void SVGSMILElement::endListChanged() +{ + SMILTime elapsed = this->elapsed(); + if (m_isWaitingForFirstInterval) + resolveFirstInterval(); + else if (elapsed < m_intervalEnd && m_intervalBegin.isFinite()) { + SMILTime newEnd = findInstanceTime(End, m_intervalBegin, false); + if (newEnd < m_intervalEnd) { + newEnd = resolveActiveEnd(m_intervalBegin, newEnd); + if (newEnd != m_intervalEnd) { + m_intervalEnd = newEnd; + notifyDependentsIntervalChanged(ExistingInterval); + } + } + } + m_nextProgressTime = elapsed; + reschedule(); +} + +void SVGSMILElement::checkRestart(SMILTime elapsed) +{ + ASSERT(!m_isWaitingForFirstInterval); + ASSERT(elapsed >= m_intervalBegin); + + Restart restart = this->restart(); + if (restart == RestartNever) + return; + + if (elapsed < m_intervalEnd) { + if (restart != RestartAlways) + return; + SMILTime nextBegin = findInstanceTime(Begin, m_intervalBegin, false); + if (nextBegin < m_intervalEnd) { + m_intervalEnd = nextBegin; + notifyDependentsIntervalChanged(ExistingInterval); + } + } + if (elapsed >= m_intervalEnd) + resolveNextInterval(); +} + +float SVGSMILElement::calculateAnimationPercentAndRepeat(SMILTime elapsed, unsigned& repeat) const +{ + SMILTime simpleDuration = this->simpleDuration(); + repeat = 0; + if (simpleDuration.isIndefinite()) { + repeat = 0; + return 0.f; + } + if (!simpleDuration) { + repeat = 0; + return 1.f; + } + ASSERT(m_intervalBegin.isFinite()); + ASSERT(simpleDuration.isFinite()); + SMILTime activeTime = elapsed - m_intervalBegin; + SMILTime repeatingDuration = this->repeatingDuration(); + if (elapsed >= m_intervalEnd || activeTime > repeatingDuration) { + repeat = static_cast<unsigned>(repeatingDuration.value() / simpleDuration.value()); + if (fmod(repeatingDuration.value(), !simpleDuration.value())) + repeat--; + return 1.f; + } + repeat = static_cast<unsigned>(activeTime.value() / simpleDuration.value()); + SMILTime simpleTime = fmod(activeTime.value(), simpleDuration.value()); + return narrowPrecisionToFloat(simpleTime.value() / simpleDuration.value()); +} + +SMILTime SVGSMILElement::calculateNextProgressTime(SMILTime elapsed) const +{ + if (m_activeState == Active) { + // If duration is indefinite the value does not actually change over time. Same is true for <set>. + SMILTime simpleDuration = this->simpleDuration(); + if (simpleDuration.isIndefinite() || hasTagName(SVGNames::setTag)) { + SMILTime repeatCount = this->repeatCount(); + SMILTime repeatingDurationEnd = m_intervalBegin + repeatingDuration(); + // We are supposed to do freeze semantics when repeating ends, even if the element is still active. + // Take care that we get a timer callback at that point. + if (elapsed < repeatingDurationEnd && repeatingDurationEnd < m_intervalEnd && repeatingDurationEnd.isFinite()) + return repeatingDurationEnd; + return m_intervalEnd; + } + return elapsed + 0.025; + } + return m_intervalBegin >= elapsed ? m_intervalBegin : SMILTime::unresolved(); +} + +SVGSMILElement::ActiveState SVGSMILElement::determineActiveState(SMILTime elapsed) const +{ + if (elapsed >= m_intervalBegin && elapsed < m_intervalEnd) + return Active; + + if (m_activeState == Active) + return fill() == FillFreeze ? Frozen : Inactive; + + return m_activeState; +} + +bool SVGSMILElement::isContributing(SMILTime elapsed) const +{ + // Animation does not contribute during the active time if it is past its repeating duration and has fill=remove. + return (m_activeState == Active && (fill() == FillFreeze || elapsed <= m_intervalBegin + repeatingDuration())) || m_activeState == Frozen; +} + +void SVGSMILElement::progress(SMILTime elapsed, SVGSMILElement* resultElement) +{ + ASSERT(m_timeContainer); + ASSERT(m_isWaitingForFirstInterval || m_intervalBegin.isFinite()); + + if (!m_conditionsConnected) + connectConditions(); + + if (!m_intervalBegin.isFinite()) { + ASSERT(m_activeState == Inactive); + m_nextProgressTime = SMILTime::unresolved(); + return; + } + + if (elapsed < m_intervalBegin) { + ASSERT(m_activeState != Active); + if (m_activeState == Frozen && resultElement) + updateAnimation(m_lastPercent, m_lastRepeat, resultElement); + m_nextProgressTime = m_intervalBegin; + return; + } + + m_previousIntervalBegin = m_intervalBegin; + + if (m_activeState == Inactive) { + m_isWaitingForFirstInterval = false; + m_activeState = Active; + startedActiveInterval(); + } + + unsigned repeat; + float percent = calculateAnimationPercentAndRepeat(elapsed, repeat); + + checkRestart(elapsed); + + ActiveState oldActiveState = m_activeState; + m_activeState = determineActiveState(elapsed); + + if (isContributing(elapsed)) { + if (resultElement) + updateAnimation(percent, repeat, resultElement); + m_lastPercent = percent; + m_lastRepeat = repeat; + } + + if (oldActiveState == Active && m_activeState != Active) + endedActiveInterval(); + + m_nextProgressTime = calculateNextProgressTime(elapsed); +} + +void SVGSMILElement::notifyDependentsIntervalChanged(NewOrExistingInterval newOrExisting) +{ + ASSERT(m_intervalBegin.isFinite()); + DEFINE_STATIC_LOCAL(HashSet<SVGSMILElement*>, loopBreaker, ()); + if (loopBreaker.contains(this)) + return; + loopBreaker.add(this); + + TimeDependentSet::iterator end = m_timeDependents.end(); + for (TimeDependentSet::iterator it = m_timeDependents.begin(); it != end; ++it) { + SVGSMILElement* dependent = *it; + dependent->createInstanceTimesFromSyncbase(this, newOrExisting); + } + + loopBreaker.remove(this); +} + +void SVGSMILElement::createInstanceTimesFromSyncbase(SVGSMILElement* syncbase, NewOrExistingInterval) +{ + // FIXME: To be really correct, this should handle updating exising interval by changing + // the associated times instead of creating new ones. + for (unsigned n = 0; n < m_conditions.size(); ++n) { + Condition& condition = m_conditions[n]; + if (condition.m_type == Condition::Syncbase && condition.m_syncbase == syncbase) { + ASSERT(condition.m_name == "begin" || condition.m_name == "end"); + // No nested time containers in SVG, no need for crazy time space conversions. Phew! + SMILTime time = 0; + if (condition.m_name == "begin") + time = syncbase->m_intervalBegin + condition.m_offset; + else + time = syncbase->m_intervalEnd + condition.m_offset; + ASSERT(time.isFinite()); + if (condition.m_beginOrEnd == Begin) + addBeginTime(time); + else + addEndTime(time); + } + } +} + +void SVGSMILElement::addTimeDependent(SVGSMILElement* animation) +{ + m_timeDependents.add(animation); + if (m_intervalBegin.isFinite()) + animation->createInstanceTimesFromSyncbase(this, NewInterval); +} + +void SVGSMILElement::removeTimeDependent(SVGSMILElement* animation) +{ + m_timeDependents.remove(animation); +} + +void SVGSMILElement::handleConditionEvent(Event*, Condition* condition) +{ + if (condition->m_beginOrEnd == Begin) + addBeginTime(elapsed() + condition->m_offset); + else + addEndTime(elapsed() + condition->m_offset); +} + +void SVGSMILElement::beginByLinkActivation() +{ + addBeginTime(elapsed()); +} + +} + +#endif diff --git a/Source/WebCore/svg/animation/SVGSMILElement.h b/Source/WebCore/svg/animation/SVGSMILElement.h new file mode 100644 index 0000000..2135642 --- /dev/null +++ b/Source/WebCore/svg/animation/SVGSMILElement.h @@ -0,0 +1,223 @@ +/* + * Copyright (C) 2008 Apple 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 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 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 SVGSMILElement_h +#define SVGSMILElement_h +#if ENABLE(SVG_ANIMATION) +#include "SMILTime.h" +#include "SVGElement.h" + +#include <wtf/HashMap.h> + +namespace WebCore { + +class ConditionEventListener; +class SMILTimeContainer; + +// This class implements SMIL interval timing model as needed for SVG animation. +class SVGSMILElement : public SVGElement { +public: + SVGSMILElement(const QualifiedName&, Document*); + virtual ~SVGSMILElement(); + + static bool isSMILElement(Node*); + + virtual void parseMappedAttribute(Attribute*); + virtual void attributeChanged(Attribute*, bool preserveDecls); + virtual void insertedIntoDocument(); + virtual void removedFromDocument(); + virtual void finishParsingChildren(); + + SMILTimeContainer* timeContainer() const { return m_timeContainer.get(); } + + SVGElement* targetElement() const; + String attributeName() const; + + void beginByLinkActivation(); + + enum Restart { + RestartAlways, + RestartWhenNotActive, + RestartNever + }; + + Restart restart() const; + + enum FillMode { + FillRemove, + FillFreeze + }; + + FillMode fill() const; + + String xlinkHref() const; + + SMILTime dur() const; + SMILTime repeatDur() const; + SMILTime repeatCount() const; + SMILTime maxValue() const; + SMILTime minValue() const; + + SMILTime elapsed() const; + + SMILTime intervalBegin() const { return m_intervalBegin; } + SMILTime intervalEnd() const { return m_intervalEnd; } + SMILTime previousIntervalBegin() const { return m_previousIntervalBegin; } + SMILTime simpleDuration() const; + + void progress(SMILTime elapsed, SVGSMILElement* resultsElement); + SMILTime nextProgressTime() const; + + static SMILTime parseClockValue(const String&); + static SMILTime parseOffsetValue(const String&); + + bool isContributing(SMILTime elapsed) const; + bool isInactive() const; + bool isFrozen() const; + + unsigned documentOrderIndex() const { return m_documentOrderIndex; } + void setDocumentOrderIndex(unsigned index) { m_documentOrderIndex = index; } + + virtual bool isAdditive() const = 0; + virtual void resetToBaseValue(const String&) = 0; + virtual void applyResultsToTarget() = 0; + +protected: + void addBeginTime(SMILTime); + void addEndTime(SMILTime); + +private: + virtual void startedActiveInterval() = 0; + virtual void updateAnimation(float percent, unsigned repeat, SVGSMILElement* resultElement) = 0; + virtual void endedActiveInterval() = 0; + + enum BeginOrEnd { + Begin, + End + }; + + SMILTime findInstanceTime(BeginOrEnd, SMILTime minimumTime, bool equalsMinimumOK) const; + void resolveFirstInterval(); + void resolveNextInterval(); + void resolveInterval(bool first, SMILTime& beginResult, SMILTime& endResult) const; + SMILTime resolveActiveEnd(SMILTime resolvedBegin, SMILTime resolvedEnd) const; + SMILTime repeatingDuration() const; + void checkRestart(SMILTime elapsed); + void beginListChanged(); + void endListChanged(); + void reschedule(); + + // This represents conditions on elements begin or end list that need to be resolved on runtime + // for example <animate begin="otherElement.begin + 8s; button.click" ... /> + struct Condition { + enum Type { + EventBase, + Syncbase, + AccessKey + }; + + Condition(Type, BeginOrEnd, const String& baseID, const String& name, SMILTime offset, int repeats = -1); + Type m_type; + BeginOrEnd m_beginOrEnd; + String m_baseID; + String m_name; + SMILTime m_offset; + int m_repeats; + RefPtr<Element> m_syncbase; + RefPtr<ConditionEventListener> m_eventListener; + }; + bool parseCondition(const String&, BeginOrEnd beginOrEnd); + void parseBeginOrEnd(const String&, BeginOrEnd beginOrEnd); + Element* eventBaseFor(const Condition&) const; + + void connectConditions(); + void disconnectConditions(); + + // Event base timing + void handleConditionEvent(Event*, Condition*); + + // Syncbase timing + enum NewOrExistingInterval { + NewInterval, + ExistingInterval + }; + + void notifyDependentsIntervalChanged(NewOrExistingInterval); + void createInstanceTimesFromSyncbase(SVGSMILElement* syncbase, NewOrExistingInterval); + void addTimeDependent(SVGSMILElement*); + void removeTimeDependent(SVGSMILElement*); + + enum ActiveState { + Inactive, + Active, + Frozen + }; + + ActiveState determineActiveState(SMILTime elapsed) const; + float calculateAnimationPercentAndRepeat(SMILTime elapsed, unsigned& repeat) const; + SMILTime calculateNextProgressTime(SMILTime elapsed) const; + + Vector<Condition> m_conditions; + bool m_conditionsConnected; + bool m_hasEndEventConditions; + + typedef HashSet<SVGSMILElement*> TimeDependentSet; + TimeDependentSet m_timeDependents; + + // Instance time lists + Vector<SMILTime> m_beginTimes; + Vector<SMILTime> m_endTimes; + + // This is the upcoming or current interval + SMILTime m_intervalBegin; + SMILTime m_intervalEnd; + + SMILTime m_previousIntervalBegin; + + bool m_isWaitingForFirstInterval; + + ActiveState m_activeState; + float m_lastPercent; + unsigned m_lastRepeat; + + SMILTime m_nextProgressTime; + + RefPtr<SMILTimeContainer> m_timeContainer; + unsigned m_documentOrderIndex; + + mutable SMILTime m_cachedDur; + mutable SMILTime m_cachedRepeatDur; + mutable SMILTime m_cachedRepeatCount; + mutable SMILTime m_cachedMin; + mutable SMILTime m_cachedMax; + + friend class ConditionEventListener; +}; + +} + +#endif // ENABLE(SVG) +#endif // SVGSMILElement_h + diff --git a/Source/WebCore/svg/graphics/SVGImage.cpp b/Source/WebCore/svg/graphics/SVGImage.cpp new file mode 100644 index 0000000..97f86be --- /dev/null +++ b/Source/WebCore/svg/graphics/SVGImage.cpp @@ -0,0 +1,298 @@ +/* + * Copyright (C) 2006 Eric Seidel <eric@webkit.org> + * Copyright (C) 2008, 2009 Apple 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 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 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" +#if ENABLE(SVG) +#include "SVGImage.h" + +#include "CachedPage.h" +#include "DocumentLoader.h" +#include "FileChooser.h" +#include "FloatRect.h" +#include "Frame.h" +#include "FrameLoader.h" +#include "FrameView.h" +#include "GraphicsContext.h" +#include "HTMLFormElement.h" +#include "ImageBuffer.h" +#include "ImageObserver.h" +#include "Page.h" +#include "RenderView.h" +#include "ResourceError.h" +#include "SVGDocument.h" +#include "SVGLength.h" +#include "SVGRenderSupport.h" +#include "SVGSVGElement.h" +#include "Settings.h" + +// Moving this #include above FrameLoader.h causes the Windows build to fail due to warnings about +// alignment in Timer<FrameLoader>. It seems that the definition of EmptyFrameLoaderClient is what +// causes this (removing that definition fixes the warnings), but it isn't clear why. +#include "EmptyClients.h" // NOLINT + +namespace WebCore { + +class SVGImageChromeClient : public EmptyChromeClient, public Noncopyable { +public: + SVGImageChromeClient(SVGImage* image) + : m_image(image) + { + } + + SVGImage* image() const { return m_image; } + +private: + virtual void chromeDestroyed() + { + m_image = 0; + } + + virtual void invalidateContentsAndWindow(const IntRect& r, bool) + { + if (m_image && m_image->imageObserver()) + m_image->imageObserver()->changedInRect(m_image, r); + } + + SVGImage* m_image; +}; + +SVGImage::SVGImage(ImageObserver* observer) + : Image(observer) +{ +} + +SVGImage::~SVGImage() +{ + if (m_page) { + m_page->mainFrame()->loader()->frameDetached(); // Break both the loader and view references to the frame + + // Clear explicitly because we want to delete the page before the ChromeClient. + // FIXME: I believe that's already guaranteed by C++ object destruction rules, + // so this may matter only for the assertion below. + m_page.clear(); + } + + // Verify that page teardown destroyed the Chrome + ASSERT(!m_chromeClient || !m_chromeClient->image()); +} + +void SVGImage::setContainerSize(const IntSize& containerSize) +{ + if (containerSize.isEmpty()) + return; + + if (!m_page) + return; + Frame* frame = m_page->mainFrame(); + SVGSVGElement* rootElement = static_cast<SVGDocument*>(frame->document())->rootElement(); + if (!rootElement) + return; + + rootElement->setContainerSize(containerSize); +} + +bool SVGImage::usesContainerSize() const +{ + if (!m_page) + return false; + Frame* frame = m_page->mainFrame(); + SVGSVGElement* rootElement = static_cast<SVGDocument*>(frame->document())->rootElement(); + if (!rootElement) + return false; + + return rootElement->hasSetContainerSize(); +} + +IntSize SVGImage::size() const +{ + if (!m_page) + return IntSize(); + Frame* frame = m_page->mainFrame(); + SVGSVGElement* rootElement = static_cast<SVGDocument*>(frame->document())->rootElement(); + if (!rootElement) + return IntSize(); + + SVGLength width = rootElement->width(); + SVGLength height = rootElement->height(); + + IntSize svgSize; + if (width.unitType() == LengthTypePercentage) + svgSize.setWidth(rootElement->relativeWidthValue()); + else + svgSize.setWidth(static_cast<int>(width.value(rootElement))); + + if (height.unitType() == LengthTypePercentage) + svgSize.setHeight(rootElement->relativeHeightValue()); + else + svgSize.setHeight(static_cast<int>(height.value(rootElement))); + + return svgSize; +} + +bool SVGImage::hasRelativeWidth() const +{ + if (!m_page) + return false; + SVGSVGElement* rootElement = static_cast<SVGDocument*>(m_page->mainFrame()->document())->rootElement(); + if (!rootElement) + return false; + + return rootElement->width().unitType() == LengthTypePercentage; +} + +bool SVGImage::hasRelativeHeight() const +{ + if (!m_page) + return false; + SVGSVGElement* rootElement = static_cast<SVGDocument*>(m_page->mainFrame()->document())->rootElement(); + if (!rootElement) + return false; + + return rootElement->height().unitType() == LengthTypePercentage; +} + +void SVGImage::draw(GraphicsContext* context, const FloatRect& dstRect, const FloatRect& srcRect, ColorSpace, CompositeOperator compositeOp) +{ + if (!m_page) + return; + + FrameView* view = m_page->mainFrame()->view(); + + context->save(); + context->setCompositeOperation(compositeOp); + context->clip(enclosingIntRect(dstRect)); + if (compositeOp != CompositeSourceOver) + context->beginTransparencyLayer(1); + + FloatSize scale(dstRect.width() / srcRect.width(), dstRect.height() / srcRect.height()); + + // We can only draw the entire frame, clipped to the rect we want. So compute where the top left + // of the image would be if we were drawing without clipping, and translate accordingly. + FloatSize topLeftOffset(srcRect.location().x() * scale.width(), srcRect.location().y() * scale.height()); + FloatPoint destOffset = dstRect.location() - topLeftOffset; + + context->translate(destOffset.x(), destOffset.y()); + context->scale(scale); + + view->resize(size()); + + if (view->needsLayout()) + view->layout(); + + view->paint(context, IntRect(0, 0, view->width(), view->height())); + + if (compositeOp != CompositeSourceOver) + context->endTransparencyLayer(); + + context->restore(); + + if (imageObserver()) + imageObserver()->didDraw(this); +} + +NativeImagePtr SVGImage::nativeImageForCurrentFrame() +{ + // FIXME: In order to support dynamic SVGs we need to have a way to invalidate this + // frame cache, or better yet, not use a cache for tiled drawing at all, instead + // having a tiled drawing callback (hopefully non-virtual). + if (!m_frameCache) { + if (!m_page) + return 0; + OwnPtr<ImageBuffer> buffer = ImageBuffer::create(size()); + if (!buffer) // failed to allocate image + return 0; + draw(buffer->context(), rect(), rect(), ColorSpaceDeviceRGB, CompositeSourceOver); + m_frameCache = buffer->copyImage(); + } + return m_frameCache->nativeImageForCurrentFrame(); +} + +bool SVGImage::dataChanged(bool allDataReceived) +{ + // Don't do anything if is an empty image. + if (!data()->size()) + return true; + + if (allDataReceived) { + static FrameLoaderClient* dummyFrameLoaderClient = new EmptyFrameLoaderClient; + + Page::PageClients pageClients; + m_chromeClient = adoptPtr(new SVGImageChromeClient(this)); + pageClients.chromeClient = m_chromeClient.get(); +#if ENABLE(CONTEXT_MENUS) + static ContextMenuClient* dummyContextMenuClient = new EmptyContextMenuClient; + pageClients.contextMenuClient = dummyContextMenuClient; +#endif + static EditorClient* dummyEditorClient = new EmptyEditorClient; + pageClients.editorClient = dummyEditorClient; +#if ENABLE(DRAG_SUPPORT) + static DragClient* dummyDragClient = new EmptyDragClient; + pageClients.dragClient = dummyDragClient; +#endif + static InspectorClient* dummyInspectorClient = new EmptyInspectorClient; + pageClients.inspectorClient = dummyInspectorClient; +#if ENABLE(DEVICE_ORIENTATION) + static DeviceMotionClient* dummyDeviceMotionClient = new EmptyDeviceMotionClient; + pageClients.deviceMotionClient = dummyDeviceMotionClient; + static DeviceOrientationClient* dummyDeviceOrientationClient = new EmptyDeviceOrientationClient; + pageClients.deviceOrientationClient = dummyDeviceOrientationClient; +#endif + + // FIXME: If this SVG ends up loading itself, we might leak the world. + // The comment said that the Cache code does not know about CachedImages + // holding Frames and won't know to break the cycle. But + m_page.set(new Page(pageClients)); + m_page->settings()->setMediaEnabled(false); + m_page->settings()->setJavaScriptEnabled(false); + m_page->settings()->setPluginsEnabled(false); + + RefPtr<Frame> frame = Frame::create(m_page.get(), 0, dummyFrameLoaderClient); + frame->setView(FrameView::create(frame.get())); + frame->init(); + ResourceRequest fakeRequest(KURL(ParsedURLString, "")); + FrameLoader* loader = frame->loader(); + loader->setForcedSandboxFlags(SandboxAll); + loader->load(fakeRequest, false); // Make sure the DocumentLoader is created + loader->policyChecker()->cancelCheck(); // cancel any policy checks + loader->commitProvisionalLoad(); + loader->writer()->setMIMEType("image/svg+xml"); + loader->writer()->begin(KURL()); // create the empty document + loader->writer()->addData(data()->data(), data()->size()); + loader->writer()->end(); + frame->view()->setTransparent(true); // SVG Images are transparent. + } + + return m_page; +} + +String SVGImage::filenameExtension() const +{ + return "svg"; +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/graphics/SVGImage.h b/Source/WebCore/svg/graphics/SVGImage.h new file mode 100644 index 0000000..a14332e --- /dev/null +++ b/Source/WebCore/svg/graphics/SVGImage.h @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2006 Eric Seidel <eric@webkit.org> + * Copyright (C) 2009 Apple 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 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 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 SVGImage_h +#define SVGImage_h + +#if ENABLE(SVG) + +#include "Image.h" + +namespace WebCore { + +class Page; +class SVGImageChromeClient; + +class SVGImage : public Image { +public: + static PassRefPtr<SVGImage> create(ImageObserver* observer) + { + return adoptRef(new SVGImage(observer)); + } + +private: + virtual ~SVGImage(); + + virtual String filenameExtension() const; + + virtual void setContainerSize(const IntSize&); + virtual bool usesContainerSize() const; + virtual bool hasRelativeWidth() const; + virtual bool hasRelativeHeight() const; + + virtual IntSize size() const; + + virtual bool dataChanged(bool allDataReceived); + + // FIXME: SVGImages are underreporting decoded sizes and will be unable + // to prune because these functions are not implemented yet. + virtual void destroyDecodedData(bool) { } + virtual unsigned decodedSize() const { return 0; } + + virtual NativeImagePtr frameAtIndex(size_t) { return 0; } + + SVGImage(ImageObserver*); + virtual void draw(GraphicsContext*, const FloatRect& fromRect, const FloatRect& toRect, ColorSpace styleColorSpace, CompositeOperator); + + virtual NativeImagePtr nativeImageForCurrentFrame(); + + OwnPtr<SVGImageChromeClient> m_chromeClient; + OwnPtr<Page> m_page; + RefPtr<Image> m_frameCache; +}; +} + +#endif // ENABLE(SVG) +#endif // SVGImage_h diff --git a/Source/WebCore/svg/graphics/filters/SVGFEImage.cpp b/Source/WebCore/svg/graphics/filters/SVGFEImage.cpp new file mode 100644 index 0000000..6ed305e --- /dev/null +++ b/Source/WebCore/svg/graphics/filters/SVGFEImage.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * Copyright (C) 2005 Eric Seidel <eric@webkit.org> + * Copyright (C) 2010 Dirk Schulze <krit@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFEImage.h" + +#include "AffineTransform.h" +#include "Filter.h" +#include "GraphicsContext.h" +#include "SVGPreserveAspectRatio.h" + +namespace WebCore { + +FEImage::FEImage(Filter* filter, RefPtr<Image> image, const SVGPreserveAspectRatio& preserveAspectRatio) + : FilterEffect(filter) + , m_image(image) + , m_preserveAspectRatio(preserveAspectRatio) +{ +} + +PassRefPtr<FEImage> FEImage::create(Filter* filter, RefPtr<Image> image, const SVGPreserveAspectRatio& preserveAspectRatio) +{ + return adoptRef(new FEImage(filter, image, preserveAspectRatio)); +} + +void FEImage::determineAbsolutePaintRect() +{ + ASSERT(m_image); + FloatRect srcRect(FloatPoint(), m_image->size()); + FloatRect paintRect(m_absoluteSubregion); + m_preserveAspectRatio.transformRect(paintRect, srcRect); + paintRect.intersect(maxEffectRect()); + setAbsolutePaintRect(enclosingIntRect(paintRect)); +} + +void FEImage::apply() +{ + if (!m_image.get() || hasResult()) + return; + + ImageBuffer* resultImage = createImageBufferResult(); + if (!resultImage) + return; + + FloatRect srcRect(FloatPoint(), m_image->size()); + FloatRect destRect(m_absoluteSubregion); + m_preserveAspectRatio.transformRect(destRect, srcRect); + + IntPoint paintLocation = absolutePaintRect().location(); + destRect.move(-paintLocation.x(), -paintLocation.y()); + + resultImage->context()->drawImage(m_image.get(), ColorSpaceDeviceRGB, destRect, srcRect); +} + +void FEImage::dump() +{ +} + +TextStream& FEImage::externalRepresentation(TextStream& ts, int indent) const +{ + ASSERT(m_image); + IntSize imageSize = m_image->size(); + writeIndent(ts, indent); + ts << "[feImage"; + FilterEffect::externalRepresentation(ts); + ts << " image-size=\"" << imageSize.width() << "x" << imageSize.height() << "\"]\n"; + // FIXME: should this dump also object returned by SVGFEImage::image() ? + return ts; +} + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(FILTERS) diff --git a/Source/WebCore/svg/graphics/filters/SVGFEImage.h b/Source/WebCore/svg/graphics/filters/SVGFEImage.h new file mode 100644 index 0000000..9ac5527 --- /dev/null +++ b/Source/WebCore/svg/graphics/filters/SVGFEImage.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * Copyright (C) 2005 Eric Seidel <eric@webkit.org> + * Copyright (C) 2010 Dirk Schulze <krit@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFEImage_h +#define SVGFEImage_h + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "FilterEffect.h" +#include "SVGPreserveAspectRatio.h" + +namespace WebCore { + +class FEImage : public FilterEffect { +public: + static PassRefPtr<FEImage> create(Filter*, RefPtr<Image>, const SVGPreserveAspectRatio&); + + void setAbsoluteSubregion(const FloatRect& absoluteSubregion) { m_absoluteSubregion = absoluteSubregion; } + + virtual void apply(); + virtual void dump(); + + virtual void determineAbsolutePaintRect(); + + virtual FilterEffectType filterEffectType() const { return FilterEffectTypeImage; } + + virtual TextStream& externalRepresentation(TextStream&, int indention) const; + +private: + FEImage(Filter*, RefPtr<Image>, const SVGPreserveAspectRatio&); + + RefPtr<Image> m_image; + SVGPreserveAspectRatio m_preserveAspectRatio; + FloatRect m_absoluteSubregion; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(FILTERS) + +#endif // SVGFEImage_h diff --git a/Source/WebCore/svg/graphics/filters/SVGFilter.cpp b/Source/WebCore/svg/graphics/filters/SVGFilter.cpp new file mode 100644 index 0000000..e7b61db --- /dev/null +++ b/Source/WebCore/svg/graphics/filters/SVGFilter.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFilter.h" + +namespace WebCore { + +SVGFilter::SVGFilter(const AffineTransform& absoluteTransform, const FloatRect& absoluteSourceDrawingRegion, const FloatRect& targetBoundingBox, const FloatRect& filterRegion, bool effectBBoxMode) + : Filter() + , m_absoluteTransform(absoluteTransform) + , m_absoluteSourceDrawingRegion(absoluteSourceDrawingRegion) + , m_targetBoundingBox(targetBoundingBox) + , m_filterRegion(filterRegion) + , m_effectBBoxMode(effectBBoxMode) +{ + m_absoluteFilterRegion = absoluteTransform.mapRect(filterRegion); +} + +float SVGFilter::applyHorizontalScale(float value) const +{ + if (m_effectBBoxMode) + value *= m_targetBoundingBox.width(); + return Filter::applyHorizontalScale(value) * m_absoluteFilterRegion.width() / m_filterRegion.width(); +} + +float SVGFilter::applyVerticalScale(float value) const +{ + if (m_effectBBoxMode) + value *= m_targetBoundingBox.height(); + return Filter::applyVerticalScale(value) * m_absoluteFilterRegion.height() / m_filterRegion.height(); +} + +PassRefPtr<SVGFilter> SVGFilter::create(const AffineTransform& absoluteTransform, const FloatRect& absoluteSourceDrawingRegion, const FloatRect& targetBoundingBox, const FloatRect& filterRegion, bool effectBBoxMode) +{ + return adoptRef(new SVGFilter(absoluteTransform, absoluteSourceDrawingRegion, targetBoundingBox, filterRegion, effectBBoxMode)); +} + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(FILTERS) diff --git a/Source/WebCore/svg/graphics/filters/SVGFilter.h b/Source/WebCore/svg/graphics/filters/SVGFilter.h new file mode 100644 index 0000000..6465f9f --- /dev/null +++ b/Source/WebCore/svg/graphics/filters/SVGFilter.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFilter_h +#define SVGFilter_h + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "AffineTransform.h" +#include "Filter.h" +#include "FilterEffect.h" +#include "FloatRect.h" +#include "FloatSize.h" + +#include <wtf/PassRefPtr.h> +#include <wtf/RefCounted.h> +#include <wtf/RefPtr.h> + +namespace WebCore { + +class SVGFilter : public Filter { +public: + static PassRefPtr<SVGFilter> create(const AffineTransform&, const FloatRect&, const FloatRect&, const FloatRect&, bool); + + virtual bool effectBoundingBoxMode() const { return m_effectBBoxMode; } + + virtual FloatRect filterRegionInUserSpace() const { return m_filterRegion; } + virtual FloatRect filterRegion() const { return m_absoluteFilterRegion; } + + virtual FloatPoint mapAbsolutePointToLocalPoint(const FloatPoint& point) const { return m_absoluteTransform.inverse().mapPoint(point); } + FloatRect mapLocalRectToAbsoluteRect(const FloatRect& rect) const { return m_absoluteTransform.mapRect(rect); } + + virtual float applyHorizontalScale(float value) const; + virtual float applyVerticalScale(float value) const; + + virtual FloatRect sourceImageRect() const { return m_absoluteSourceDrawingRegion; } + FloatRect targetBoundingBox() const { return m_targetBoundingBox; } + +private: + SVGFilter(const AffineTransform& absoluteTransform, const FloatRect& absoluteSourceDrawingRegion, const FloatRect& targetBoundingBox, const FloatRect& filterRegion, bool effectBBoxMode); + + AffineTransform m_absoluteTransform; + FloatRect m_absoluteSourceDrawingRegion; + FloatRect m_targetBoundingBox; + FloatRect m_absoluteFilterRegion; + FloatRect m_filterRegion; + bool m_effectBBoxMode; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(FILTERS) + +#endif // SVGFilter_h diff --git a/Source/WebCore/svg/graphics/filters/SVGFilterBuilder.cpp b/Source/WebCore/svg/graphics/filters/SVGFilterBuilder.cpp new file mode 100644 index 0000000..b31b994 --- /dev/null +++ b/Source/WebCore/svg/graphics/filters/SVGFilterBuilder.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "SVGFilterBuilder.h" + +#include "FilterEffect.h" +#include "PlatformString.h" +#include "SourceAlpha.h" +#include "SourceGraphic.h" + +#include <wtf/PassRefPtr.h> + +namespace WebCore { + +SVGFilterBuilder::SVGFilterBuilder(Filter* filter) + : m_lastEffect(0) +{ + m_builtinEffects.add(SourceGraphic::effectName(), SourceGraphic::create(filter)); + m_builtinEffects.add(SourceAlpha::effectName(), SourceAlpha::create(filter)); + addBuiltinEffects(); +} + +void SVGFilterBuilder::add(const AtomicString& id, RefPtr<FilterEffect> effect) +{ + if (id.isEmpty()) { + m_lastEffect = effect; + return; + } + + if (m_builtinEffects.contains(id)) + return; + + m_lastEffect = effect; + m_namedEffects.set(id, m_lastEffect); +} + +FilterEffect* SVGFilterBuilder::getEffectById(const AtomicString& id) const +{ + if (id.isEmpty()) { + if (m_lastEffect) + return m_lastEffect.get(); + + return m_builtinEffects.get(SourceGraphic::effectName()).get(); + } + + if (m_builtinEffects.contains(id)) + return m_builtinEffects.get(id).get(); + + return m_namedEffects.get(id).get(); +} + +void SVGFilterBuilder::appendEffectToEffectReferences(RefPtr<FilterEffect> effectReference) +{ + // The effect must be a newly created filter effect. + ASSERT(!m_effectReferences.contains(effectReference)); + m_effectReferences.add(effectReference, FilterEffectSet()); + + FilterEffect* effect = effectReference.get(); + unsigned numberOfInputEffects = effect->inputEffects().size(); + + // It is not possible to add the same value to a set twice. + for (unsigned i = 0; i < numberOfInputEffects; ++i) + getEffectReferences(effect->inputEffect(i)).add(effect); +} + +void SVGFilterBuilder::clearEffects() +{ + m_lastEffect = 0; + m_namedEffects.clear(); + m_effectReferences.clear(); + addBuiltinEffects(); +} + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(FILTERS) diff --git a/Source/WebCore/svg/graphics/filters/SVGFilterBuilder.h b/Source/WebCore/svg/graphics/filters/SVGFilterBuilder.h new file mode 100644 index 0000000..a3c1244 --- /dev/null +++ b/Source/WebCore/svg/graphics/filters/SVGFilterBuilder.h @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2008 Alex Mathews <possessedpenguinbob@gmail.com> + * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGFilterBuilder_h +#define SVGFilterBuilder_h + +#if ENABLE(SVG) && ENABLE(FILTERS) +#include "FilterEffect.h" +#include "PlatformString.h" + +#include <wtf/HashMap.h> +#include <wtf/HashSet.h> +#include <wtf/PassRefPtr.h> +#include <wtf/text/AtomicStringHash.h> + +namespace WebCore { + +class SVGFilterBuilder : public RefCounted<SVGFilterBuilder> { +public: + typedef HashSet<FilterEffect*> FilterEffectSet; + + static PassRefPtr<SVGFilterBuilder> create(Filter* filter) { return adoptRef(new SVGFilterBuilder(filter)); } + + void add(const AtomicString& id, RefPtr<FilterEffect> effect); + + FilterEffect* getEffectById(const AtomicString& id) const; + FilterEffect* lastEffect() const { return m_lastEffect.get(); } + + void appendEffectToEffectReferences(RefPtr<FilterEffect>); + + inline FilterEffectSet& getEffectReferences(FilterEffect* effect) + { + // Only allowed for effects belongs to this builder. + ASSERT(m_effectReferences.contains(effect)); + return m_effectReferences.find(effect)->second; + } + + void clearEffects(); + +private: + SVGFilterBuilder(Filter*); + + inline void addBuiltinEffects() + { + HashMap<AtomicString, RefPtr<FilterEffect> >::iterator end = m_builtinEffects.end(); + for (HashMap<AtomicString, RefPtr<FilterEffect> >::iterator iterator = m_builtinEffects.begin(); iterator != end; ++iterator) + m_effectReferences.add(iterator->second, FilterEffectSet()); + } + + HashMap<AtomicString, RefPtr<FilterEffect> > m_builtinEffects; + HashMap<AtomicString, RefPtr<FilterEffect> > m_namedEffects; + // The value is a list, which contains those filter effects, + // which depends on the key filter effect. + HashMap<RefPtr<FilterEffect>, FilterEffectSet> m_effectReferences; + + RefPtr<FilterEffect> m_lastEffect; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(FILTERS) +#endif // SVGFilterBuilder_h diff --git a/Source/WebCore/svg/properties/SVGAnimatedListPropertyTearOff.h b/Source/WebCore/svg/properties/SVGAnimatedListPropertyTearOff.h new file mode 100644 index 0000000..40d3888 --- /dev/null +++ b/Source/WebCore/svg/properties/SVGAnimatedListPropertyTearOff.h @@ -0,0 +1,116 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGAnimatedListPropertyTearOff_h +#define SVGAnimatedListPropertyTearOff_h + +#if ENABLE(SVG) +#include "SVGAnimatedProperty.h" +#include "SVGListPropertyTearOff.h" +#include "SVGStaticListPropertyTearOff.h" + +namespace WebCore { + +template<typename PropertyType> +class SVGPropertyTearOff; + +template<typename PropertyType> +class SVGAnimatedListPropertyTearOff : public SVGAnimatedProperty { +public: + typedef typename SVGPropertyTraits<PropertyType>::ListItemType ListItemType; + typedef SVGPropertyTearOff<ListItemType> ListItemTearOff; + typedef Vector<RefPtr<ListItemTearOff> > ListWrapperCache; + + SVGProperty* baseVal() + { + if (!m_baseVal) + m_baseVal = SVGListPropertyTearOff<PropertyType>::create(this, BaseValRole); + return m_baseVal.get(); + } + + SVGProperty* animVal() + { + if (!m_animVal) + m_animVal = SVGListPropertyTearOff<PropertyType>::create(this, AnimValRole); + return m_animVal.get(); + } + + virtual bool isAnimatedListTearOff() const { return true; } + + int removeItemFromList(SVGProperty* property, bool shouldSynchronizeWrappers) + { + // This should ever be called for our baseVal, as animVal can't modify the list. + typedef SVGPropertyTearOff<typename SVGPropertyTraits<PropertyType>::ListItemType> ListItemTearOff; + return static_pointer_cast<SVGListPropertyTearOff<PropertyType> >(m_baseVal)->removeItemFromList(static_cast<ListItemTearOff*>(property), shouldSynchronizeWrappers); + } + + void detachListWrappers(unsigned newListSize) + { + // See SVGPropertyTearOff::detachWrapper() for an explaination what's happening here. + unsigned size = m_wrappers.size(); + ASSERT(size == m_values.size()); + for (unsigned i = 0; i < size; ++i) { + RefPtr<ListItemTearOff>& item = m_wrappers.at(i); + if (!item) + continue; + item->detachWrapper(); + } + + // Reinitialize the wrapper cache to be equal to the new values size, after the XML DOM changed the list. + if (newListSize) + m_wrappers.fill(0, newListSize); + else + m_wrappers.clear(); + } + + PropertyType& values() { return m_values; } + ListWrapperCache& wrappers() { return m_wrappers; } + +private: + friend class SVGAnimatedProperty; + + static PassRefPtr<SVGAnimatedListPropertyTearOff<PropertyType> > create(SVGElement* contextElement, const QualifiedName& attributeName, PropertyType& values) + { + ASSERT(contextElement); + return adoptRef(new SVGAnimatedListPropertyTearOff<PropertyType>(contextElement, attributeName, values)); + } + +protected: + SVGAnimatedListPropertyTearOff(SVGElement* contextElement, const QualifiedName& attributeName, PropertyType& values) + : SVGAnimatedProperty(contextElement, attributeName) + , m_values(values) + { + if (!values.isEmpty()) + m_wrappers.fill(0, values.size()); + } + + PropertyType& m_values; + + // FIXME: The list wrapper cache is shared between baseVal/animVal. If we implement animVal, + // we need two seperated wrapper caches if the attribute gets animated. + ListWrapperCache m_wrappers; + + RefPtr<SVGProperty> m_baseVal; + RefPtr<SVGProperty> m_animVal; +}; + +} + +#endif // ENABLE(SVG) +#endif // SVGAnimatedListPropertyTearOff_h diff --git a/Source/WebCore/svg/properties/SVGAnimatedPathSegListPropertyTearOff.h b/Source/WebCore/svg/properties/SVGAnimatedPathSegListPropertyTearOff.h new file mode 100644 index 0000000..f515ab4 --- /dev/null +++ b/Source/WebCore/svg/properties/SVGAnimatedPathSegListPropertyTearOff.h @@ -0,0 +1,72 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGAnimatedPathSegListPropertyTearOff_h +#define SVGAnimatedPathSegListPropertyTearOff_h + +#if ENABLE(SVG) +#include "SVGAnimatedListPropertyTearOff.h" +#include "SVGPathSegList.h" +#include "SVGPathSegListPropertyTearOff.h" + +namespace WebCore { + +class SVGPathSegListPropertyTearOff; + +class SVGAnimatedPathSegListPropertyTearOff : public SVGAnimatedListPropertyTearOff<SVGPathSegList> { +public: + SVGProperty* baseVal(SVGPathSegRole role) + { + if (!m_baseVal) + m_baseVal = SVGPathSegListPropertyTearOff::create(this, BaseValRole, role); + return m_baseVal.get(); + } + + SVGProperty* animVal(SVGPathSegRole role) + { + if (!m_animVal) + m_animVal = SVGPathSegListPropertyTearOff::create(this, AnimValRole, role); + return m_animVal.get(); + } + + int removeItemFromList(const RefPtr<SVGPathSeg>& segment, bool shouldSynchronizeWrappers) + { + // This should ever be called for our baseVal, as animVal can't modify the list. + return static_pointer_cast<SVGPathSegListPropertyTearOff>(m_baseVal)->removeItemFromList(segment, shouldSynchronizeWrappers); + } + +private: + friend class SVGAnimatedProperty; + + static PassRefPtr<SVGAnimatedPathSegListPropertyTearOff> create(SVGElement* contextElement, const QualifiedName& attributeName, SVGPathSegList& values) + { + ASSERT(contextElement); + return adoptRef(new SVGAnimatedPathSegListPropertyTearOff(contextElement, attributeName, values)); + } + + SVGAnimatedPathSegListPropertyTearOff(SVGElement* contextElement, const QualifiedName& attributeName, SVGPathSegList& values) + : SVGAnimatedListPropertyTearOff<SVGPathSegList>(contextElement, attributeName, values) + { + } +}; + +} + +#endif // ENABLE(SVG) +#endif // SVGAnimatedPathSegListPropertyTearOff_h diff --git a/Source/WebCore/svg/properties/SVGAnimatedProperty.h b/Source/WebCore/svg/properties/SVGAnimatedProperty.h new file mode 100644 index 0000000..1c25935 --- /dev/null +++ b/Source/WebCore/svg/properties/SVGAnimatedProperty.h @@ -0,0 +1,105 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGAnimatedProperty_h +#define SVGAnimatedProperty_h + +#if ENABLE(SVG) +#include "QualifiedName.h" +#include "SVGAnimatedPropertyDescription.h" +#include "SVGElement.h" +#include <wtf/RefCounted.h> + +namespace WebCore { + +class SVGElement; +class SVGProperty; + +class SVGAnimatedProperty : public RefCounted<SVGAnimatedProperty> { +public: + SVGElement* contextElement() const { return m_contextElement.get(); } + const QualifiedName& attributeName() const { return m_attributeName; } + + void commitChange() + { + ASSERT(m_contextElement); + m_contextElement->invalidateSVGAttributes(); + m_contextElement->svgAttributeChanged(m_attributeName); + } + + virtual bool isAnimatedListTearOff() const { return false; } + + // Caching facilities. + typedef HashMap<SVGAnimatedPropertyDescription, RefPtr<SVGAnimatedProperty>, SVGAnimatedPropertyDescriptionHash, SVGAnimatedPropertyDescriptionHashTraits> Cache; + + virtual ~SVGAnimatedProperty() + { + // Remove wrapper from cache. + Cache* cache = animatedPropertyCache(); + const Cache::const_iterator end = cache->end(); + for (Cache::const_iterator it = cache->begin(); it != end; ++it) { + if (it->second == this) { + cache->remove(it->first); + break; + } + } + } + + template<typename TearOffType, typename PropertyType> + static PassRefPtr<TearOffType> lookupOrCreateWrapper(SVGElement* element, const QualifiedName& attributeName, const AtomicString& attributeIdentifier, PropertyType& property) + { + SVGAnimatedPropertyDescription key(element, attributeIdentifier); + RefPtr<SVGAnimatedProperty> wrapper = animatedPropertyCache()->get(key); + if (!wrapper) { + wrapper = TearOffType::create(element, attributeName, property); + animatedPropertyCache()->set(key, wrapper); + } + + return static_pointer_cast<TearOffType>(wrapper).release(); + } + + template<typename TearOffType> + static TearOffType* lookupWrapper(SVGElement* element, const AtomicString& attributeIdentifier) + { + SVGAnimatedPropertyDescription key(element, attributeIdentifier); + return static_pointer_cast<TearOffType>(animatedPropertyCache()->get(key)).get(); + } + +protected: + SVGAnimatedProperty(SVGElement* contextElement, const QualifiedName& attributeName) + : m_contextElement(contextElement) + , m_attributeName(attributeName) + { + } + +private: + static Cache* animatedPropertyCache() + { + static Cache* s_cache = new Cache; + return s_cache; + } + + RefPtr<SVGElement> m_contextElement; + const QualifiedName& m_attributeName; +}; + +} + +#endif // ENABLE(SVG) +#endif // SVGAnimatedProperty_h diff --git a/Source/WebCore/svg/properties/SVGAnimatedPropertyDescription.h b/Source/WebCore/svg/properties/SVGAnimatedPropertyDescription.h new file mode 100644 index 0000000..6fb5e66 --- /dev/null +++ b/Source/WebCore/svg/properties/SVGAnimatedPropertyDescription.h @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGAnimatedPropertyDescription_h +#define SVGAnimatedPropertyDescription_h + +#if ENABLE(SVG) +#include <wtf/HashMap.h> +#include <wtf/text/AtomicString.h> + +namespace WebCore { + +class SVGElement; + +struct SVGAnimatedPropertyDescription { + // Empty value + SVGAnimatedPropertyDescription() + : m_element(0) + , m_attributeName(0) + { + } + + // Deleted value + SVGAnimatedPropertyDescription(WTF::HashTableDeletedValueType) + : m_element(reinterpret_cast<SVGElement*>(-1)) + { + } + + bool isHashTableDeletedValue() const + { + return m_element == reinterpret_cast<SVGElement*>(-1); + } + + SVGAnimatedPropertyDescription(SVGElement* element, const AtomicString& attributeName) + : m_element(element) + , m_attributeName(attributeName.impl()) + { + ASSERT(m_element); + ASSERT(m_attributeName); + } + + bool operator==(const SVGAnimatedPropertyDescription& other) const + { + return m_element == other.m_element && m_attributeName == other.m_attributeName; + } + + SVGElement* m_element; + AtomicStringImpl* m_attributeName; +}; + +struct SVGAnimatedPropertyDescriptionHash { + static unsigned hash(const SVGAnimatedPropertyDescription& key) + { + return WTF::StringHasher::createBlobHash<sizeof(SVGAnimatedPropertyDescription)>(&key); + } + + static bool equal(const SVGAnimatedPropertyDescription& a, const SVGAnimatedPropertyDescription& b) + { + return a == b; + } + + static const bool safeToCompareToEmptyOrDeleted = true; +}; + +struct SVGAnimatedPropertyDescriptionHashTraits : WTF::GenericHashTraits<SVGAnimatedPropertyDescription> { + static const bool emptyValueIsZero = true; + + static void constructDeletedValue(SVGAnimatedPropertyDescription& slot) + { + new (&slot) SVGAnimatedPropertyDescription(WTF::HashTableDeletedValue); + } + + static bool isDeletedValue(const SVGAnimatedPropertyDescription& value) + { + return value.isHashTableDeletedValue(); + } +}; + +} + +#endif // ENABLE(SVG) +#endif // SVGAnimatedPropertyDescription_h diff --git a/Source/WebCore/svg/properties/SVGAnimatedPropertyMacros.h b/Source/WebCore/svg/properties/SVGAnimatedPropertyMacros.h new file mode 100644 index 0000000..d5ba21a --- /dev/null +++ b/Source/WebCore/svg/properties/SVGAnimatedPropertyMacros.h @@ -0,0 +1,151 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGAnimatedPropertyMacros_h +#define SVGAnimatedPropertyMacros_h + +#if ENABLE(SVG) +#include "SVGAnimatedPropertySynchronizer.h" +#include "SVGPropertyTraits.h" + +namespace WebCore { + +// GetOwnerElementForType implementation +template<typename OwnerType, bool isDerivedFromSVGElement> +struct GetOwnerElementForType; + +template<typename OwnerType> +struct GetOwnerElementForType<OwnerType, true> { + static SVGElement* ownerElement(OwnerType* type) + { + return type; + } +}; + +template<typename OwnerType> +struct GetOwnerElementForType<OwnerType, false> { + static SVGElement* ownerElement(OwnerType* type) + { + SVGElement* context = type->contextElement(); + ASSERT(context); + return context; + } +}; + +// IsDerivedFromSVGElement implementation +template<typename OwnerType> +struct IsDerivedFromSVGElement { + static const bool value = true; +}; + +class SVGViewSpec; +template<> +struct IsDerivedFromSVGElement<SVGViewSpec> { + static const bool value = false; +}; + +// SVGSynchronizableAnimatedProperty implementation +template<typename PropertyType> +struct SVGSynchronizableAnimatedProperty { + SVGSynchronizableAnimatedProperty() + : value(SVGPropertyTraits<PropertyType>::initialValue()) + , shouldSynchronize(false) + { + } + + template<typename ConstructorParameter1> + SVGSynchronizableAnimatedProperty(const ConstructorParameter1& value1) + : value(value1) + , shouldSynchronize(false) + { + } + + template<typename ConstructorParameter1, typename ConstructorParameter2> + SVGSynchronizableAnimatedProperty(const ConstructorParameter1& value1, const ConstructorParameter2& value2) + : value(value1, value2) + , shouldSynchronize(false) + { + } + + PropertyType value; + bool shouldSynchronize : 1; +}; + +#define DEFINE_ANIMATED_PROPERTY(OwnerType, DOMAttribute, SVGDOMAttributeIdentifier, TearOffType, PropertyType, UpperProperty, LowerProperty) \ +void OwnerType::synchronize##UpperProperty() \ +{ \ + if (!m_##LowerProperty.shouldSynchronize) \ + return; \ + AtomicString value(SVGPropertyTraits<PropertyType>::toString(LowerProperty##BaseValue())); \ + SVGElement* contextElement = GetOwnerElementForType<OwnerType, IsDerivedFromSVGElement<OwnerType>::value>::ownerElement(this); \ + SVGAnimatedPropertySynchronizer<IsDerivedFromSVGElement<OwnerType>::value>::synchronize(contextElement, DOMAttribute, value); \ +} \ +\ +PassRefPtr<TearOffType> OwnerType::LowerProperty##Animated() \ +{ \ + m_##LowerProperty.shouldSynchronize = true; \ + SVGElement* contextElement = GetOwnerElementForType<OwnerType, IsDerivedFromSVGElement<OwnerType>::value>::ownerElement(this); \ + return SVGAnimatedProperty::lookupOrCreateWrapper<TearOffType, PropertyType>(contextElement, DOMAttribute, SVGDOMAttributeIdentifier, m_##LowerProperty.value); \ +} + +#define DECLARE_ANIMATED_PROPERTY(TearOffType, PropertyType, UpperProperty, LowerProperty) \ +public: \ +PropertyType& LowerProperty() const \ +{ \ + return m_##LowerProperty.value; \ +} \ +\ +PropertyType& LowerProperty##BaseValue() const \ +{ \ + return m_##LowerProperty.value; \ +} \ +\ +void set##UpperProperty##BaseValue(const PropertyType& type) \ +{ \ + m_##LowerProperty.value = type; \ +} \ +\ +PassRefPtr<TearOffType> LowerProperty##Animated(); \ +\ +private: \ + void synchronize##UpperProperty(); \ +\ + mutable SVGSynchronizableAnimatedProperty<PropertyType> m_##LowerProperty; + +#define DECLARE_ANIMATED_LIST_PROPERTY(TearOffType, PropertyType, UpperProperty, LowerProperty) \ +DECLARE_ANIMATED_PROPERTY(TearOffType, PropertyType, UpperProperty, LowerProperty) \ +void detachAnimated##UpperProperty##ListWrappers(unsigned newListSize); + +#define DEFINE_ANIMATED_LIST_PROPERTY(OwnerType, DOMAttribute, SVGDOMAttributeIdentifier, TearOffType, PropertyType, UpperProperty, LowerProperty) \ +DEFINE_ANIMATED_PROPERTY(OwnerType, DOMAttribute, SVGDOMAttributeIdentifier, TearOffType, PropertyType, UpperProperty, LowerProperty) \ +void OwnerType::detachAnimated##UpperProperty##ListWrappers(unsigned newListSize) \ +{ \ + SVGElement* contextElement = GetOwnerElementForType<OwnerType, IsDerivedFromSVGElement<OwnerType>::value>::ownerElement(this); \ + SVGAnimatedProperty* wrapper = SVGAnimatedProperty::lookupWrapper<TearOffType>(contextElement, DOMAttribute.localName()); \ + if (!wrapper) \ + return; \ + static_cast<TearOffType*>(wrapper)->detachListWrappers(newListSize); \ +} + +} + +#endif // ENABLE(SVG) +#endif // SVGAnimatedPropertyMacros_h diff --git a/Source/WebCore/svg/properties/SVGAnimatedPropertySynchronizer.h b/Source/WebCore/svg/properties/SVGAnimatedPropertySynchronizer.h new file mode 100644 index 0000000..bb52442 --- /dev/null +++ b/Source/WebCore/svg/properties/SVGAnimatedPropertySynchronizer.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGAnimatedPropertySynchronizer_h +#define SVGAnimatedPropertySynchronizer_h + +#if ENABLE(SVG) +#include "SVGElement.h" + +namespace WebCore { + +// Helper template used for synchronizing SVG <-> XML properties +template<bool isDerivedFromSVGElement> +struct SVGAnimatedPropertySynchronizer { + static void synchronize(SVGElement*, const QualifiedName&, const AtomicString&); +}; + +template<> +struct SVGAnimatedPropertySynchronizer<true> { + static void synchronize(SVGElement* ownerElement, const QualifiedName& attrName, const AtomicString& value) + { + NamedNodeMap* namedAttrMap = ownerElement->attributes(false); + Attribute* old = namedAttrMap->getAttributeItem(attrName); + if (old && value.isNull()) + namedAttrMap->removeAttribute(old->name()); + else if (!old && !value.isNull()) + namedAttrMap->addAttribute(ownerElement->createAttribute(attrName, value)); + else if (old && !value.isNull()) + old->setValue(value); + } +}; + +template<> +struct SVGAnimatedPropertySynchronizer<false> { + static void synchronize(SVGElement*, const QualifiedName&, const AtomicString&) + { + // no-op, for types not inheriting from Element, thus nothing to synchronize + } +}; + +}; + +#endif +#endif diff --git a/Source/WebCore/svg/properties/SVGAnimatedPropertyTearOff.h b/Source/WebCore/svg/properties/SVGAnimatedPropertyTearOff.h new file mode 100644 index 0000000..252a4b4 --- /dev/null +++ b/Source/WebCore/svg/properties/SVGAnimatedPropertyTearOff.h @@ -0,0 +1,71 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGAnimatedPropertyTearOff_h +#define SVGAnimatedPropertyTearOff_h + +#if ENABLE(SVG) +#include "SVGAnimatedProperty.h" +#include "SVGPropertyTearOff.h" + +namespace WebCore { + +template<typename PropertyType> +class SVGAnimatedPropertyTearOff : public SVGAnimatedProperty { +public: + SVGProperty* baseVal() + { + if (!m_baseVal) + m_baseVal = SVGPropertyTearOff<PropertyType>::create(this, BaseValRole, m_property); + return m_baseVal.get(); + } + + SVGProperty* animVal() + { + if (!m_animVal) + m_animVal = SVGPropertyTearOff<PropertyType>::create(this, AnimValRole, m_property); + return m_animVal.get(); + } + +private: + friend class SVGAnimatedProperty; + + static PassRefPtr<SVGAnimatedPropertyTearOff<PropertyType> > create(SVGElement* contextElement, const QualifiedName& attributeName, PropertyType& property) + { + ASSERT(contextElement); + return adoptRef(new SVGAnimatedPropertyTearOff<PropertyType>(contextElement, attributeName, property)); + } + + SVGAnimatedPropertyTearOff(SVGElement* contextElement, const QualifiedName& attributeName, PropertyType& property) + : SVGAnimatedProperty(contextElement, attributeName) + , m_property(property) + { + } + +private: + PropertyType& m_property; + + RefPtr<SVGProperty> m_baseVal; + RefPtr<SVGProperty> m_animVal; +}; + +} + +#endif // ENABLE(SVG) +#endif // SVGAnimatedPropertyTearOff_h diff --git a/Source/WebCore/svg/properties/SVGAnimatedStaticPropertyTearOff.h b/Source/WebCore/svg/properties/SVGAnimatedStaticPropertyTearOff.h new file mode 100644 index 0000000..930569e --- /dev/null +++ b/Source/WebCore/svg/properties/SVGAnimatedStaticPropertyTearOff.h @@ -0,0 +1,73 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGAnimatedStaticPropertyTearOff_h +#define SVGAnimatedStaticPropertyTearOff_h + +#if ENABLE(SVG) +#include "SVGAnimatedProperty.h" + +namespace WebCore { + +template<typename PropertyType> +class SVGAnimatedStaticPropertyTearOff : public SVGAnimatedProperty { +public: + PropertyType& baseVal() + { + return m_property; + } + + PropertyType& animVal() + { + // FIXME: No animVal support. + return m_property; + } + + void setBaseVal(const PropertyType& property) + { + m_property = property; + commitChange(); + } + + // FIXME: No animVal support. + void setAnimVal(const PropertyType&) { } + +private: + friend class SVGAnimatedProperty; + + static PassRefPtr<SVGAnimatedStaticPropertyTearOff<PropertyType> > create(SVGElement* contextElement, const QualifiedName& attributeName, PropertyType& property) + { + ASSERT(contextElement); + return adoptRef(new SVGAnimatedStaticPropertyTearOff<PropertyType>(contextElement, attributeName, property)); + } + + SVGAnimatedStaticPropertyTearOff(SVGElement* contextElement, const QualifiedName& attributeName, PropertyType& property) + : SVGAnimatedProperty(contextElement, attributeName) + , m_property(property) + { + } + +private: + PropertyType& m_property; +}; + +} + +#endif // ENABLE(SVG) +#endif // SVGAnimatedStaticPropertyTearOff_h diff --git a/Source/WebCore/svg/properties/SVGAnimatedTransformListPropertyTearOff.h b/Source/WebCore/svg/properties/SVGAnimatedTransformListPropertyTearOff.h new file mode 100644 index 0000000..2aa94c3 --- /dev/null +++ b/Source/WebCore/svg/properties/SVGAnimatedTransformListPropertyTearOff.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGAnimatedTransformListPropertyTearOff_h +#define SVGAnimatedTransformListPropertyTearOff_h + +#if ENABLE(SVG) +#include "SVGAnimatedListPropertyTearOff.h" +#include "SVGTransformList.h" +#include "SVGTransformListPropertyTearOff.h" + +namespace WebCore { + +class SVGAnimatedTransformListPropertyTearOff : public SVGAnimatedListPropertyTearOff<SVGTransformList> { +public: + SVGProperty* baseVal() + { + if (!m_baseVal) + m_baseVal = SVGTransformListPropertyTearOff::create(this, BaseValRole); + return m_baseVal.get(); + } + + SVGProperty* animVal() + { + if (!m_animVal) + m_animVal = SVGTransformListPropertyTearOff::create(this, AnimValRole); + return m_animVal.get(); + } + +private: + friend class SVGAnimatedProperty; + + static PassRefPtr<SVGAnimatedTransformListPropertyTearOff> create(SVGElement* contextElement, const QualifiedName& attributeName, SVGTransformList& values) + { + ASSERT(contextElement); + return adoptRef(new SVGAnimatedTransformListPropertyTearOff(contextElement, attributeName, values)); + } + + SVGAnimatedTransformListPropertyTearOff(SVGElement* contextElement, const QualifiedName& attributeName, SVGTransformList& values) + : SVGAnimatedListPropertyTearOff<SVGTransformList>(contextElement, attributeName, values) + { + } +}; + +} + +#endif // ENABLE(SVG) +#endif // SVGAnimatedTransformListPropertyTearOff_h diff --git a/Source/WebCore/svg/properties/SVGListProperty.h b/Source/WebCore/svg/properties/SVGListProperty.h new file mode 100644 index 0000000..0985ddb --- /dev/null +++ b/Source/WebCore/svg/properties/SVGListProperty.h @@ -0,0 +1,428 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGListProperty_h +#define SVGListProperty_h + +#if ENABLE(SVG) +#include "SVGAnimatedProperty.h" +#include "SVGException.h" +#include "SVGPropertyTearOff.h" +#include "SVGPropertyTraits.h" + +namespace WebCore { + +template<typename PropertyType> +class SVGAnimatedListPropertyTearOff; + +template<typename PropertyType> +class SVGListProperty : public SVGProperty { +public: + typedef SVGListProperty<PropertyType> Self; + + typedef typename SVGPropertyTraits<PropertyType>::ListItemType ListItemType; + typedef SVGPropertyTearOff<ListItemType> ListItemTearOff; + typedef PassRefPtr<ListItemTearOff> PassListItemTearOff; + typedef SVGAnimatedListPropertyTearOff<PropertyType> AnimatedListPropertyTearOff; + typedef typename SVGAnimatedListPropertyTearOff<PropertyType>::ListWrapperCache ListWrapperCache; + + bool canAlterList(ExceptionCode& ec) const + { + if (m_role == AnimValRole) { + ec = NO_MODIFICATION_ALLOWED_ERR; + return false; + } + + return true; + } + + // SVGList::clear() + void clearValues(PropertyType& values, ExceptionCode& ec) + { + if (!canAlterList(ec)) + return; + + values.clear(); + commitChange(); + } + + void clearValuesAndWrappers(AnimatedListPropertyTearOff* animatedList, ExceptionCode& ec) + { + ASSERT(animatedList); + if (!canAlterList(ec)) + return; + + animatedList->detachListWrappers(0); + animatedList->values().clear(); + commitChange(); + } + + // SVGList::numberOfItems() + unsigned numberOfItemsValues(PropertyType& values) const + { + return values.size(); + } + + unsigned numberOfItemsValuesAndWrappers(AnimatedListPropertyTearOff* animatedList) const + { + ASSERT(animatedList); + return animatedList->values().size(); + } + + // SVGList::initialize() + ListItemType initializeValues(PropertyType& values, const ListItemType& newItem, ExceptionCode& ec) + { + if (!canAlterList(ec)) + return ListItemType(); + + // Spec: If the inserted item is already in a list, it is removed from its previous list before it is inserted into this list. + processIncomingListItemValue(newItem, 0); + + // Spec: Clears all existing current items from the list and re-initializes the list to hold the single item specified by the parameter. + values.clear(); + values.append(newItem); + + commitChange(); + return newItem; + } + + PassListItemTearOff initializeValuesAndWrappers(AnimatedListPropertyTearOff* animatedList, PassListItemTearOff passNewItem, ExceptionCode& ec) + { + ASSERT(animatedList); + if (!canAlterList(ec)) + return 0; + + // Not specified, but FF/Opera do it this way, and it's just sane. + if (!passNewItem) { + ec = SVGException::SVG_WRONG_TYPE_ERR; + return 0; + } + + PropertyType& values = animatedList->values(); + ListWrapperCache& wrappers = animatedList->wrappers(); + + RefPtr<ListItemTearOff> newItem = passNewItem; + ASSERT(values.size() == wrappers.size()); + + // Spec: If the inserted item is already in a list, it is removed from its previous list before it is inserted into this list. + processIncomingListItemWrapper(newItem, 0); + + // Spec: Clears all existing current items from the list and re-initializes the list to hold the single item specified by the parameter. + animatedList->detachListWrappers(0); + values.clear(); + + values.append(newItem->propertyReference()); + wrappers.append(newItem); + + commitChange(); + return newItem.release(); + } + + // SVGList::getItem() + bool canGetItem(PropertyType& values, unsigned index, ExceptionCode& ec) + { + if (index >= values.size()) { + ec = INDEX_SIZE_ERR; + return false; + } + + return true; + } + + ListItemType getItemValues(PropertyType& values, unsigned index, ExceptionCode& ec) + { + if (!canGetItem(values, index, ec)) + return ListItemType(); + + // Spec: Returns the specified item from the list. The returned item is the item itself and not a copy. + return values.at(index); + } + + PassListItemTearOff getItemValuesAndWrappers(AnimatedListPropertyTearOff* animatedList, unsigned index, ExceptionCode& ec) + { + ASSERT(animatedList); + PropertyType& values = animatedList->values(); + if (!canGetItem(values, index, ec)) + return 0; + + ListWrapperCache& wrappers = animatedList->wrappers(); + + // Spec: Returns the specified item from the list. The returned item is the item itself and not a copy. + // Any changes made to the item are immediately reflected in the list. + ASSERT(values.size() == wrappers.size()); + RefPtr<ListItemTearOff> wrapper = wrappers.at(index); + if (!wrapper) { + // Create new wrapper, which is allowed to directly modify the item in the list, w/o copying and cache the wrapper in our map. + // It is also associated with our animated property, so it can notify the SVG Element which holds the SVGAnimated*List + // that it has been modified (and thus can call svgAttributeChanged(associatedAttributeName)). + wrapper = ListItemTearOff::create(animatedList, UndefinedRole, values.at(index)); + wrappers.at(index) = wrapper; + } + + return wrapper.release(); + } + + // SVGList::insertItemBefore() + ListItemType insertItemBeforeValues(PropertyType& values, const ListItemType& newItem, unsigned index, ExceptionCode& ec) + { + if (!canAlterList(ec)) + return ListItemType(); + + // Spec: If the index is greater than or equal to numberOfItems, then the new item is appended to the end of the list. + if (index > values.size()) + index = values.size(); + + // Spec: If newItem is already in a list, it is removed from its previous list before it is inserted into this list. + processIncomingListItemValue(newItem, &index); + + // Spec: Inserts a new item into the list at the specified position. The index of the item before which the new item is to be + // inserted. The first item is number 0. If the index is equal to 0, then the new item is inserted at the front of the list. + values.insert(index, newItem); + + commitChange(); + return newItem; + } + + PassListItemTearOff insertItemBeforeValuesAndWrappers(AnimatedListPropertyTearOff* animatedList, PassListItemTearOff passNewItem, unsigned index, ExceptionCode& ec) + { + ASSERT(animatedList); + if (!canAlterList(ec)) + return 0; + + // Not specified, but FF/Opera do it this way, and it's just sane. + if (!passNewItem) { + ec = SVGException::SVG_WRONG_TYPE_ERR; + return 0; + } + + PropertyType& values = animatedList->values(); + ListWrapperCache& wrappers = animatedList->wrappers(); + + // Spec: If the index is greater than or equal to numberOfItems, then the new item is appended to the end of the list. + if (index > values.size()) + index = values.size(); + + RefPtr<ListItemTearOff> newItem = passNewItem; + ASSERT(values.size() == wrappers.size()); + + // Spec: If newItem is already in a list, it is removed from its previous list before it is inserted into this list. + processIncomingListItemWrapper(newItem, &index); + + // Spec: Inserts a new item into the list at the specified position. The index of the item before which the new item is to be + // inserted. The first item is number 0. If the index is equal to 0, then the new item is inserted at the front of the list. + values.insert(index, newItem->propertyReference()); + + // Store new wrapper at position 'index', change its underlying value, so mutations of newItem, directly affect the item in the list. + wrappers.insert(index, newItem); + + commitChange(); + return newItem.release(); + } + + // SVGList::replaceItem() + bool canReplaceItem(PropertyType& values, unsigned index, ExceptionCode& ec) + { + if (!canAlterList(ec)) + return false; + + if (index >= values.size()) { + ec = INDEX_SIZE_ERR; + return false; + } + + return true; + } + + ListItemType replaceItemValues(PropertyType& values, const ListItemType& newItem, unsigned index, ExceptionCode& ec) + { + if (!canReplaceItem(values, index, ec)) + return ListItemType(); + + // Spec: If newItem is already in a list, it is removed from its previous list before it is inserted into this list. + // Spec: If the item is already in this list, note that the index of the item to replace is before the removal of the item. + processIncomingListItemValue(newItem, &index); + + if (values.isEmpty()) { + // 'newItem' already lived in our list, we removed it, and now we're empty, which means there's nothing to replace. + ec = INDEX_SIZE_ERR; + return ListItemType(); + } + + // Update the value at the desired position 'index'. + values.at(index) = newItem; + + commitChange(); + return newItem; + } + + PassListItemTearOff replaceItemValuesAndWrappers(AnimatedListPropertyTearOff* animatedList, PassListItemTearOff passNewItem, unsigned index, ExceptionCode& ec) + { + ASSERT(animatedList); + PropertyType& values = animatedList->values(); + if (!canReplaceItem(values, index, ec)) + return 0; + + // Not specified, but FF/Opera do it this way, and it's just sane. + if (!passNewItem) { + ec = SVGException::SVG_WRONG_TYPE_ERR; + return 0; + } + + ListWrapperCache& wrappers = animatedList->wrappers(); + ASSERT(values.size() == wrappers.size()); + RefPtr<ListItemTearOff> newItem = passNewItem; + + // Spec: If newItem is already in a list, it is removed from its previous list before it is inserted into this list. + // Spec: If the item is already in this list, note that the index of the item to replace is before the removal of the item. + processIncomingListItemWrapper(newItem, &index); + + if (values.isEmpty()) { + ASSERT(wrappers.isEmpty()); + // 'passNewItem' already lived in our list, we removed it, and now we're empty, which means there's nothing to replace. + ec = INDEX_SIZE_ERR; + return 0; + } + + // Detach the existing wrapper. + RefPtr<ListItemTearOff> oldItem = wrappers.at(index); + if (oldItem) + oldItem->detachWrapper(); + + // Update the value and the wrapper at the desired position 'index'. + values.at(index) = newItem->propertyReference(); + wrappers.at(index) = newItem; + + commitChange(); + return newItem.release(); + } + + // SVGList::removeItem() + bool canRemoveItem(PropertyType& values, unsigned index, ExceptionCode& ec) + { + if (!canAlterList(ec)) + return false; + + if (index >= values.size()) { + ec = INDEX_SIZE_ERR; + return false; + } + + return true; + } + + ListItemType removeItemValues(PropertyType& values, unsigned index, ExceptionCode& ec) + { + if (!canRemoveItem(values, index, ec)) + return ListItemType(); + + ListItemType oldItem = values.at(index); + values.remove(index); + + commitChange(); + return oldItem; + } + + PassListItemTearOff removeItemValuesAndWrappers(AnimatedListPropertyTearOff* animatedList, unsigned index, ExceptionCode& ec) + { + ASSERT(animatedList); + PropertyType& values = animatedList->values(); + if (!canRemoveItem(values, index, ec)) + return 0; + + ListWrapperCache& wrappers = animatedList->wrappers(); + ASSERT(values.size() == wrappers.size()); + + // Detach the existing wrapper. + RefPtr<ListItemTearOff> oldItem = wrappers.at(index); + if (!oldItem) + oldItem = ListItemTearOff::create(animatedList, UndefinedRole, values.at(index)); + + oldItem->detachWrapper(); + wrappers.remove(index); + values.remove(index); + + commitChange(); + return oldItem.release(); + } + + // SVGList::appendItem() + ListItemType appendItemValues(PropertyType& values, const ListItemType& newItem, ExceptionCode& ec) + { + if (!canAlterList(ec)) + return ListItemType(); + + // Spec: If newItem is already in a list, it is removed from its previous list before it is inserted into this list. + processIncomingListItemValue(newItem, 0); + + // Append the value at the end of the list. + values.append(newItem); + + commitChange(); + return newItem; + } + + PassListItemTearOff appendItemValuesAndWrappers(AnimatedListPropertyTearOff* animatedList, PassListItemTearOff passNewItem, ExceptionCode& ec) + { + ASSERT(animatedList); + if (!canAlterList(ec)) + return 0; + + // Not specified, but FF/Opera do it this way, and it's just sane. + if (!passNewItem) { + ec = SVGException::SVG_WRONG_TYPE_ERR; + return 0; + } + + PropertyType& values = animatedList->values(); + ListWrapperCache& wrappers = animatedList->wrappers(); + + RefPtr<ListItemTearOff> newItem = passNewItem; + ASSERT(values.size() == wrappers.size()); + + // Spec: If newItem is already in a list, it is removed from its previous list before it is inserted into this list. + processIncomingListItemWrapper(newItem, 0); + + // Append the value and wrapper at the end of the list. + values.append(newItem->propertyReference()); + wrappers.append(newItem); + + commitChange(); + return newItem.release(); + } + + virtual SVGPropertyRole role() const { return m_role; } + +protected: + SVGListProperty(SVGPropertyRole role) + : m_role(role) + { + } + + virtual void commitChange() = 0; + virtual void processIncomingListItemValue(const ListItemType& newItem, unsigned* indexToModify) = 0; + virtual void processIncomingListItemWrapper(RefPtr<ListItemTearOff>& newItem, unsigned* indexToModify) = 0; + +private: + SVGPropertyRole m_role; +}; + +} + +#endif // ENABLE(SVG) +#endif // SVGListProperty_h diff --git a/Source/WebCore/svg/properties/SVGListPropertyTearOff.h b/Source/WebCore/svg/properties/SVGListPropertyTearOff.h new file mode 100644 index 0000000..5a71735 --- /dev/null +++ b/Source/WebCore/svg/properties/SVGListPropertyTearOff.h @@ -0,0 +1,190 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGListPropertyTearOff_h +#define SVGListPropertyTearOff_h + +#if ENABLE(SVG) +#include "SVGListProperty.h" + +namespace WebCore { + +template<typename PropertyType> +class SVGListPropertyTearOff : public SVGListProperty<PropertyType> { +public: + typedef SVGListProperty<PropertyType> Base; + + typedef typename SVGPropertyTraits<PropertyType>::ListItemType ListItemType; + typedef SVGPropertyTearOff<ListItemType> ListItemTearOff; + typedef PassRefPtr<ListItemTearOff> PassListItemTearOff; + typedef SVGAnimatedListPropertyTearOff<PropertyType> AnimatedListPropertyTearOff; + typedef typename SVGAnimatedListPropertyTearOff<PropertyType>::ListWrapperCache ListWrapperCache; + + static PassRefPtr<SVGListPropertyTearOff<PropertyType> > create(AnimatedListPropertyTearOff* animatedProperty, SVGPropertyRole role) + { + ASSERT(animatedProperty); + return adoptRef(new SVGListPropertyTearOff<PropertyType>(animatedProperty, role)); + } + + int removeItemFromList(ListItemTearOff* removeItem, bool shouldSynchronizeWrappers) + { + PropertyType& values = m_animatedProperty->values(); + ListWrapperCache& wrappers = m_animatedProperty->wrappers(); + + // Lookup item in cache and remove its corresponding wrapper. + unsigned size = wrappers.size(); + ASSERT(size == values.size()); + for (unsigned i = 0; i < size; ++i) { + RefPtr<ListItemTearOff>& item = wrappers.at(i); + if (item != removeItem) + continue; + + item->detachWrapper(); + wrappers.remove(i); + values.remove(i); + + if (shouldSynchronizeWrappers) + commitChange(); + + return i; + } + + return -1; + } + + // SVGList API + void clear(ExceptionCode& ec) + { + Base::clearValuesAndWrappers(m_animatedProperty.get(), ec); + } + + unsigned numberOfItems() const + { + return Base::numberOfItemsValuesAndWrappers(m_animatedProperty.get()); + } + + PassListItemTearOff initialize(PassListItemTearOff passNewItem, ExceptionCode& ec) + { + return Base::initializeValuesAndWrappers(m_animatedProperty.get(), passNewItem, ec); + } + + PassListItemTearOff getItem(unsigned index, ExceptionCode& ec) + { + return Base::getItemValuesAndWrappers(m_animatedProperty.get(), index, ec); + } + + PassListItemTearOff insertItemBefore(PassListItemTearOff passNewItem, unsigned index, ExceptionCode& ec) + { + return Base::insertItemBeforeValuesAndWrappers(m_animatedProperty.get(), passNewItem, index, ec); + } + + PassListItemTearOff replaceItem(PassListItemTearOff passNewItem, unsigned index, ExceptionCode& ec) + { + return Base::replaceItemValuesAndWrappers(m_animatedProperty.get(), passNewItem, index, ec); + } + + PassListItemTearOff removeItem(unsigned index, ExceptionCode& ec) + { + return Base::removeItemValuesAndWrappers(m_animatedProperty.get(), index, ec); + } + + PassListItemTearOff appendItem(PassListItemTearOff passNewItem, ExceptionCode& ec) + { + return Base::appendItemValuesAndWrappers(m_animatedProperty.get(), passNewItem, ec); + } + +protected: + SVGListPropertyTearOff(AnimatedListPropertyTearOff* animatedProperty, SVGPropertyRole role) + : SVGListProperty<PropertyType>(role) + , m_animatedProperty(animatedProperty) + { + } + + virtual void commitChange() + { + PropertyType& values = m_animatedProperty->values(); + ListWrapperCache& wrappers = m_animatedProperty->wrappers(); + + // Update existing wrappers, as the index in the values list has changed. + unsigned size = wrappers.size(); + ASSERT(size == values.size()); + for (unsigned i = 0; i < size; ++i) { + RefPtr<ListItemTearOff>& item = wrappers.at(i); + if (!item) + continue; + item->setAnimatedProperty(m_animatedProperty.get()); + item->setValue(values.at(i)); + } + + m_animatedProperty->commitChange(); + } + + virtual void processIncomingListItemValue(const ListItemType&, unsigned*) + { + ASSERT_NOT_REACHED(); + } + + virtual void processIncomingListItemWrapper(RefPtr<ListItemTearOff>& newItem, unsigned* indexToModify) + { + SVGAnimatedProperty* animatedPropertyOfItem = newItem->animatedProperty(); + + // newItem has been created manually, it doesn't belong to any SVGElement. + // (for example: "textElement.x.baseVal.appendItem(svgsvgElement.createSVGLength())") + if (!animatedPropertyOfItem) + return; + + // newItem belongs to a SVGElement, but its associated SVGAnimatedProperty is not an animated list tear off. + // (for example: "textElement.x.baseVal.appendItem(rectElement.width.baseVal)") + if (!animatedPropertyOfItem->isAnimatedListTearOff()) { + // We have to copy the incoming newItem, as we're not allowed to insert this tear off as is into our wrapper cache. + // Otherwhise we'll end up having two SVGAnimatedPropertys that operate on the same SVGPropertyTearOff. Consider the example above: + // SVGRectElements SVGAnimatedLength 'width' property baseVal points to the same tear off object + // that's inserted into SVGTextElements SVGAnimatedLengthList 'x'. textElement.x.baseVal.getItem(0).value += 150 would + // mutate the rectElement width _and_ the textElement x list. That's obviously wrong, take care of that. + newItem = ListItemTearOff::create(newItem->propertyReference()); + return; + } + + // Spec: If newItem is already in a list, it is removed from its previous list before it is inserted into this list. + // 'newItem' is already living in another list. If it's not our list, synchronize the other lists wrappers after the removal. + bool livesInOtherList = animatedPropertyOfItem != m_animatedProperty; + int removedIndex = static_cast<AnimatedListPropertyTearOff*>(animatedPropertyOfItem)->removeItemFromList(newItem.get(), livesInOtherList); + ASSERT(removedIndex != -1); + + if (!indexToModify) + return; + + // If the item lived in our list, adjust the insertion index. + if (!livesInOtherList) { + unsigned& index = *indexToModify; + // Spec: If the item is already in this list, note that the index of the item to (replace|insert before) is before the removal of the item. + if (static_cast<unsigned>(removedIndex) < index) + --index; + } + } + + // Back pointer to the animated property that created us + // For example (text.x.baseVal): m_animatedProperty points to the 'x' SVGAnimatedLengthList object + RefPtr<AnimatedListPropertyTearOff> m_animatedProperty; +}; + +} + +#endif // ENABLE(SVG) +#endif // SVGListPropertyTearOff_h diff --git a/Source/WebCore/svg/properties/SVGPathSegListPropertyTearOff.cpp b/Source/WebCore/svg/properties/SVGPathSegListPropertyTearOff.cpp new file mode 100644 index 0000000..a4eaf73 --- /dev/null +++ b/Source/WebCore/svg/properties/SVGPathSegListPropertyTearOff.cpp @@ -0,0 +1,111 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPathSegListPropertyTearOff.h" + +#include "SVGAnimatedPathSegListPropertyTearOff.h" +#include "SVGNames.h" +#include "SVGPathElement.h" +#include "SVGPathSegWithContext.h" + +namespace WebCore { + +void SVGPathSegListPropertyTearOff::clear(ExceptionCode& ec) +{ + SVGPathSegList& values = m_animatedProperty->values(); + if (values.isEmpty()) + return; + + unsigned size = values.size(); + for (unsigned i = 0; i < size; ++i) { + ListItemType item = values.at(i); + static_cast<SVGPathSegWithContext*>(item.get())->setContextAndRole(0, PathSegUndefinedRole); + } + + SVGPathSegListPropertyTearOff::Base::clearValues(values, ec); +} + +SVGPathSegListPropertyTearOff::PassListItemType SVGPathSegListPropertyTearOff::getItem(unsigned index, ExceptionCode& ec) +{ + SVGPathSegList& values = m_animatedProperty->values(); + ListItemType returnedItem = Base::getItemValues(values, index, ec); + if (returnedItem) { + ASSERT(static_cast<SVGPathSegWithContext*>(returnedItem.get())->contextElement() == contextElement()); + ASSERT(static_cast<SVGPathSegWithContext*>(returnedItem.get())->role() == m_pathSegRole); + } + return returnedItem.release(); +} + +SVGPathSegListPropertyTearOff::PassListItemType SVGPathSegListPropertyTearOff::removeItem(unsigned index, ExceptionCode& ec) +{ + SVGPathSegList& values = m_animatedProperty->values(); + SVGPathSegListPropertyTearOff::ListItemType removedItem = SVGPathSegListPropertyTearOff::Base::removeItemValues(values, index, ec); + if (removedItem) + static_cast<SVGPathSegWithContext*>(removedItem.get())->setContextAndRole(0, PathSegUndefinedRole); + return removedItem.release(); +} + +SVGPathElement* SVGPathSegListPropertyTearOff::contextElement() const +{ + SVGElement* contextElement = m_animatedProperty->contextElement(); + ASSERT(contextElement); + ASSERT(contextElement->hasTagName(SVGNames::pathTag)); + return static_cast<SVGPathElement*>(contextElement); +} + +void SVGPathSegListPropertyTearOff::processIncomingListItemValue(const ListItemType& newItem, unsigned* indexToModify) +{ + SVGPathSegWithContext* newItemWithContext = static_cast<SVGPathSegWithContext*>(newItem.get()); + SVGAnimatedProperty* animatedPropertyOfItem = newItemWithContext->animatedProperty(); + + // Alter the role, after calling animatedProperty(), as that may influence the returned animated property. + newItemWithContext->setContextAndRole(contextElement(), m_pathSegRole); + + if (!animatedPropertyOfItem) + return; + + // newItem belongs to a SVGPathElement, but its associated SVGAnimatedProperty is not an animated list tear off. + // (for example: "pathElement.pathSegList.appendItem(pathElement.createSVGPathSegClosepath())") + if (!animatedPropertyOfItem->isAnimatedListTearOff()) + return; + + // Spec: If newItem is already in a list, it is removed from its previous list before it is inserted into this list. + // 'newItem' is already living in another list. If it's not our list, synchronize the other lists wrappers after the removal. + bool livesInOtherList = animatedPropertyOfItem != m_animatedProperty; + int removedIndex = static_cast<SVGAnimatedPathSegListPropertyTearOff*>(animatedPropertyOfItem)->removeItemFromList(newItem.get(), livesInOtherList); + ASSERT(removedIndex != -1); + + if (!indexToModify) + return; + + // If the item lived in our list, adjust the insertion index. + if (!livesInOtherList) { + unsigned& index = *indexToModify; + // Spec: If the item is already in this list, note that the index of the item to (replace|insert before) is before the removal of the item. + if (static_cast<unsigned>(removedIndex) < index) + --index; + } +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/svg/properties/SVGPathSegListPropertyTearOff.h b/Source/WebCore/svg/properties/SVGPathSegListPropertyTearOff.h new file mode 100644 index 0000000..94acda1 --- /dev/null +++ b/Source/WebCore/svg/properties/SVGPathSegListPropertyTearOff.h @@ -0,0 +1,160 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPathSegListPropertyTearOff_h +#define SVGPathSegListPropertyTearOff_h + +#if ENABLE(SVG) +#include "SVGAnimatedListPropertyTearOff.h" +#include "SVGPathSegList.h" + +namespace WebCore { + +class SVGPathElement; + +class SVGPathSegListPropertyTearOff : public SVGListProperty<SVGPathSegList> { +public: + typedef SVGListProperty<SVGPathSegList> Base; + typedef SVGAnimatedListPropertyTearOff<SVGPathSegList> AnimatedListPropertyTearOff; + typedef SVGPropertyTraits<SVGPathSegList>::ListItemType ListItemType; + typedef PassRefPtr<SVGPathSeg> PassListItemType; + + static PassRefPtr<SVGPathSegListPropertyTearOff> create(AnimatedListPropertyTearOff* animatedProperty, SVGPropertyRole role, SVGPathSegRole pathSegRole) + { + ASSERT(animatedProperty); + return adoptRef(new SVGPathSegListPropertyTearOff(animatedProperty, role, pathSegRole)); + } + + int removeItemFromList(const ListItemType& removeItem, bool shouldSynchronizeWrappers) + { + SVGPathSegList& values = m_animatedProperty->values(); + + unsigned size = values.size(); + for (unsigned i = 0; i < size; ++i) { + ListItemType& item = values.at(i); + if (item != removeItem) + continue; + + values.remove(i); + + if (shouldSynchronizeWrappers) + commitChange(); + + return i; + } + + return -1; + } + + // SVGList API + void clear(ExceptionCode&); + + unsigned numberOfItems() const + { + SVGPathSegList& values = m_animatedProperty->values(); + return Base::numberOfItemsValues(values); + } + + PassListItemType initialize(PassListItemType passNewItem, ExceptionCode& ec) + { + // Not specified, but FF/Opera do it this way, and it's just sane. + if (!passNewItem) { + ec = SVGException::SVG_WRONG_TYPE_ERR; + return 0; + } + + ListItemType newItem = passNewItem; + SVGPathSegList& values = m_animatedProperty->values(); + return Base::initializeValues(values, newItem, ec); + } + + PassListItemType getItem(unsigned index, ExceptionCode&); + + PassListItemType insertItemBefore(PassListItemType passNewItem, unsigned index, ExceptionCode& ec) + { + // Not specified, but FF/Opera do it this way, and it's just sane. + if (!passNewItem) { + ec = SVGException::SVG_WRONG_TYPE_ERR; + return 0; + } + + ListItemType newItem = passNewItem; + SVGPathSegList& values = m_animatedProperty->values(); + return Base::insertItemBeforeValues(values, newItem, index, ec); + } + + PassListItemType replaceItem(PassListItemType passNewItem, unsigned index, ExceptionCode& ec) + { + // Not specified, but FF/Opera do it this way, and it's just sane. + if (!passNewItem) { + ec = SVGException::SVG_WRONG_TYPE_ERR; + return 0; + } + + ListItemType newItem = passNewItem; + SVGPathSegList& values = m_animatedProperty->values(); + return Base::replaceItemValues(values, newItem, index, ec); + } + + PassListItemType removeItem(unsigned index, ExceptionCode&); + + PassListItemType appendItem(PassListItemType passNewItem, ExceptionCode& ec) + { + // Not specified, but FF/Opera do it this way, and it's just sane. + if (!passNewItem) { + ec = SVGException::SVG_WRONG_TYPE_ERR; + return 0; + } + + ListItemType newItem = passNewItem; + SVGPathSegList& values = m_animatedProperty->values(); + return Base::appendItemValues(values, newItem, ec); + } + +private: + SVGPathSegListPropertyTearOff(AnimatedListPropertyTearOff* animatedProperty, SVGPropertyRole role, SVGPathSegRole pathSegRole) + : SVGListProperty<SVGPathSegList>(role) + , m_animatedProperty(animatedProperty) + , m_pathSegRole(pathSegRole) + { + } + + SVGPathElement* contextElement() const; + + virtual void commitChange() + { + SVGPathSegList& values = m_animatedProperty->values(); + values.commitChange(m_animatedProperty->contextElement()); + } + + virtual void processIncomingListItemValue(const ListItemType& newItem, unsigned* indexToModify); + virtual void processIncomingListItemWrapper(RefPtr<ListItemTearOff>&, unsigned*) + { + ASSERT_NOT_REACHED(); + } + +private: + RefPtr<AnimatedListPropertyTearOff> m_animatedProperty; + SVGPathSegRole m_pathSegRole; +}; + +} + +#endif // ENABLE(SVG) +#endif // SVGListPropertyTearOff_h diff --git a/Source/WebCore/svg/properties/SVGProperty.h b/Source/WebCore/svg/properties/SVGProperty.h new file mode 100644 index 0000000..609e264 --- /dev/null +++ b/Source/WebCore/svg/properties/SVGProperty.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGProperty_h +#define SVGProperty_h + +#if ENABLE(SVG) +#include <wtf/RefCounted.h> + +namespace WebCore { + +enum SVGPropertyRole { + UndefinedRole, + BaseValRole, + AnimValRole +}; + +class SVGProperty : public RefCounted<SVGProperty> { +public: + virtual ~SVGProperty() { } + + virtual SVGPropertyRole role() const = 0; + virtual void commitChange() = 0; +}; + +} + +#endif // ENABLE(SVG) +#endif // SVGProperty_h diff --git a/Source/WebCore/svg/properties/SVGPropertyTearOff.h b/Source/WebCore/svg/properties/SVGPropertyTearOff.h new file mode 100644 index 0000000..d0eac3b --- /dev/null +++ b/Source/WebCore/svg/properties/SVGPropertyTearOff.h @@ -0,0 +1,130 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPropertyTearOff_h +#define SVGPropertyTearOff_h + +#if ENABLE(SVG) +#include "SVGAnimatedProperty.h" +#include "SVGElement.h" +#include "SVGProperty.h" + +namespace WebCore { + +template<typename PropertyType> +class SVGPropertyTearOff : public SVGProperty { +public: + typedef SVGPropertyTearOff<PropertyType> Self; + + // Used for child types (baseVal/animVal) of a SVGAnimated* property (for example: SVGAnimatedLength::baseVal()). + // Also used for list tear offs (for example: text.x.baseVal.getItem(0)). + static PassRefPtr<Self> create(SVGAnimatedProperty* animatedProperty, SVGPropertyRole role, PropertyType& value) + { + ASSERT(animatedProperty); + return adoptRef(new Self(animatedProperty, role, value)); + } + + // Used for non-animated POD types (for example: SVGSVGElement::createSVGLength()). + static PassRefPtr<Self> create(const PropertyType& initialValue) + { + return adoptRef(new Self(initialValue)); + } + + PropertyType& propertyReference() { return *m_value; } + SVGAnimatedProperty* animatedProperty() const { return m_animatedProperty.get(); } + + // Used only by the list tear offs! + void setValue(PropertyType& value) + { + if (m_valueIsCopy) + delete m_value; + m_valueIsCopy = false; + m_value = &value; + } + + void setAnimatedProperty(SVGAnimatedProperty* animatedProperty) { m_animatedProperty = animatedProperty; } + + SVGElement* contextElement() const + { + if (!m_animatedProperty || m_valueIsCopy) + return 0; + return m_animatedProperty->contextElement(); + } + + void detachWrapper() + { + if (m_valueIsCopy) + return; + + // Switch from a live value, to a non-live value. + // For example: <text x="50"/> + // var item = text.x.baseVal.getItem(0); + // text.setAttribute("x", "100"); + // item.value still has to report '50' and it has to be possible to modify 'item' + // w/o changing the "new item" (with x=100) in the text element. + // Whenever the XML DOM modifies the "x" attribute, all existing wrappers are detached, using this function. + m_value = new PropertyType(*m_value); + m_valueIsCopy = true; + m_animatedProperty = 0; + } + + virtual void commitChange() + { + if (!m_animatedProperty || m_valueIsCopy) + return; + m_animatedProperty->commitChange(); + } + + virtual SVGPropertyRole role() const { return m_role; } + +protected: + SVGPropertyTearOff(SVGAnimatedProperty* animatedProperty, SVGPropertyRole role, PropertyType& value) + : m_animatedProperty(animatedProperty) + , m_role(role) + , m_value(&value) + , m_valueIsCopy(false) + { + // Using operator & is completly fine, as SVGAnimatedProperty owns this reference, + // and we're guaranteed to live as long as SVGAnimatedProperty does. + } + + SVGPropertyTearOff(const PropertyType& initialValue) + : m_animatedProperty(0) + , m_role(UndefinedRole) + , m_value(new PropertyType(initialValue)) + , m_valueIsCopy(true) + { + } + + virtual ~SVGPropertyTearOff() + { + if (m_valueIsCopy) + delete m_value; + } + + RefPtr<SVGAnimatedProperty> m_animatedProperty; + SVGPropertyRole m_role; + PropertyType* m_value; + bool m_valueIsCopy : 1; +}; + +} + +#endif // ENABLE(SVG) +#endif // SVGPropertyTearOff_h diff --git a/Source/WebCore/svg/properties/SVGPropertyTraits.h b/Source/WebCore/svg/properties/SVGPropertyTraits.h new file mode 100644 index 0000000..0ed9339 --- /dev/null +++ b/Source/WebCore/svg/properties/SVGPropertyTraits.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGPropertyTraits_h +#define SVGPropertyTraits_h + +#if ENABLE(SVG) +#include <wtf/text/WTFString.h> + +namespace WebCore { + +template<typename PropertyType> +struct SVGPropertyTraits { }; + +template<> +struct SVGPropertyTraits<bool> { + static bool initialValue() { return false; } + static String toString(bool type) { return type ? "true" : "false"; } +}; + +template<> +struct SVGPropertyTraits<int> { + static int initialValue() { return 0; } + static String toString(int type) { return String::number(type); } +}; + +template<> +struct SVGPropertyTraits<long> { + static long initialValue() { return 0; } + static String toString(long type) { return String::number(type); } +}; + +template<> +struct SVGPropertyTraits<float> { + static float initialValue() { return 0; } + static String toString(float type) { return String::number(type); } +}; + +template<> +struct SVGPropertyTraits<String> { + static String initialValue() { return String(); } + static String toString(const String& type) { return type; } +}; + +} + +#endif +#endif diff --git a/Source/WebCore/svg/properties/SVGStaticListPropertyTearOff.h b/Source/WebCore/svg/properties/SVGStaticListPropertyTearOff.h new file mode 100644 index 0000000..a6f0f28 --- /dev/null +++ b/Source/WebCore/svg/properties/SVGStaticListPropertyTearOff.h @@ -0,0 +1,114 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGStaticListPropertyTearOff_h +#define SVGStaticListPropertyTearOff_h + +#if ENABLE(SVG) +#include "SVGListProperty.h" + +namespace WebCore { + +template<typename PropertyType> +class SVGStaticListPropertyTearOff : public SVGListProperty<PropertyType> { +public: + typedef SVGListProperty<PropertyType> Base; + + typedef typename SVGPropertyTraits<PropertyType>::ListItemType ListItemType; + typedef SVGPropertyTearOff<ListItemType> ListItemTearOff; + + static PassRefPtr<SVGStaticListPropertyTearOff<PropertyType> > create(SVGElement* contextElement, PropertyType& values) + { + ASSERT(contextElement); + return adoptRef(new SVGStaticListPropertyTearOff<PropertyType>(contextElement, values)); + } + + // SVGList API + void clear(ExceptionCode& ec) + { + Base::clearValues(m_values, ec); + } + + unsigned numberOfItems() const + { + return Base::numberOfItemsValues(m_values); + } + + ListItemType initialize(const ListItemType& newItem, ExceptionCode& ec) + { + return Base::initializeValues(m_values, newItem, ec); + } + + ListItemType getItem(unsigned index, ExceptionCode& ec) + { + return Base::getItemValues(m_values, index, ec); + } + + ListItemType insertItemBefore(const ListItemType& newItem, unsigned index, ExceptionCode& ec) + { + return Base::insertItemBeforeValues(m_values, newItem, index, ec); + } + + ListItemType replaceItem(const ListItemType& newItem, unsigned index, ExceptionCode& ec) + { + return Base::replaceItemValues(m_values, newItem, index, ec); + } + + ListItemType removeItem(unsigned index, ExceptionCode& ec) + { + return Base::removeItemValues(m_values, index, ec); + } + + ListItemType appendItem(const ListItemType& newItem, ExceptionCode& ec) + { + return Base::appendItemValues(m_values, newItem, ec); + } + +private: + SVGStaticListPropertyTearOff(SVGElement* contextElement, PropertyType& values) + : SVGListProperty<PropertyType>(UndefinedRole) + , m_contextElement(contextElement) + , m_values(values) + { + } + + virtual void commitChange() + { + m_values.commitChange(m_contextElement.get()); + } + + virtual void processIncomingListItemValue(const ListItemType&, unsigned*) + { + // no-op for static lists + } + + virtual void processIncomingListItemWrapper(RefPtr<ListItemTearOff>&, unsigned*) + { + ASSERT_NOT_REACHED(); + } + +private: + RefPtr<SVGElement> m_contextElement; + PropertyType& m_values; +}; + +} + +#endif // ENABLE(SVG) +#endif // SVGStaticListPropertyTearOff_h diff --git a/Source/WebCore/svg/properties/SVGStaticPropertyTearOff.h b/Source/WebCore/svg/properties/SVGStaticPropertyTearOff.h new file mode 100644 index 0000000..233880f --- /dev/null +++ b/Source/WebCore/svg/properties/SVGStaticPropertyTearOff.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGStaticPropertyTearOff_h +#define SVGStaticPropertyTearOff_h + +#if ENABLE(SVG) +#include "SVGPropertyTearOff.h" + +namespace WebCore { + +#if COMPILER(MSVC) +// UpdateMethod is 12 bytes. We have to pack to a size greater than or equal to that to avoid an +// alignment warning (C4121). 16 is the next-largest size allowed for packing, so we use that. +#pragma pack(push, 16) +#endif +template<typename ContextElement, typename PropertyType> +class SVGStaticPropertyTearOff : public SVGPropertyTearOff<PropertyType> { +public: + typedef SVGStaticPropertyTearOff<ContextElement, PropertyType> Self; + typedef void (ContextElement::*UpdateMethod)(); + + // Used for non-animated POD types that are not associated with a SVGAnimatedProperty object, nor with a XML DOM attribute + // (for example: SVGSVGElement::currentTranslate). + static PassRefPtr<Self> create(ContextElement* contextElement, PropertyType& value, UpdateMethod update) + { + ASSERT(contextElement); + return adoptRef(new Self(contextElement, value, update)); + } + + virtual void commitChange() { (m_contextElement.get()->*m_update)(); } + +private: + SVGStaticPropertyTearOff(ContextElement* contextElement, PropertyType& value, UpdateMethod update) + : SVGPropertyTearOff<PropertyType>(0, UndefinedRole, value) + , m_update(update) + , m_contextElement(contextElement) + { + } + + UpdateMethod m_update; + RefPtr<ContextElement> m_contextElement; +}; +#if COMPILER(MSVC) +#pragma pack(pop) +#endif + +} + +#endif // ENABLE(SVG) +#endif // SVGStaticPropertyTearOff_h diff --git a/Source/WebCore/svg/properties/SVGStaticPropertyWithParentTearOff.h b/Source/WebCore/svg/properties/SVGStaticPropertyWithParentTearOff.h new file mode 100644 index 0000000..cf47960 --- /dev/null +++ b/Source/WebCore/svg/properties/SVGStaticPropertyWithParentTearOff.h @@ -0,0 +1,72 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGStaticPropertyWithParentTearOff_h +#define SVGStaticPropertyWithParentTearOff_h + +#if ENABLE(SVG) +#include "SVGPropertyTearOff.h" + +namespace WebCore { + +#if COMPILER(MSVC) +// UpdateMethod is 12 bytes. We have to pack to a size greater than or equal to that to avoid an +// alignment warning (C4121). 16 is the next-largest size allowed for packing, so we use that. +#pragma pack(push, 16) +#endif +template<typename ParentType, typename PropertyType> +class SVGStaticPropertyWithParentTearOff : public SVGPropertyTearOff<PropertyType> { +public: + typedef SVGStaticPropertyWithParentTearOff<ParentType, PropertyType> Self; + typedef void (ParentType::*UpdateMethod)(); + + // Used for non-animated POD types that are not associated with a SVGAnimatedProperty object, nor with a XML DOM attribute + // and that contain a parent type that's exposed to the bindings via a SVGStaticPropertyTearOff object + // (for example: SVGTransform::matrix). + static PassRefPtr<Self> create(SVGProperty* parent, PropertyType& value, UpdateMethod update) + { + ASSERT(parent); + return adoptRef(new Self(parent, value, update)); + } + + virtual void commitChange() + { + (static_cast<SVGPropertyTearOff<ParentType>*>(m_parent.get())->propertyReference().*m_update)(); + m_parent->commitChange(); + } + +private: + SVGStaticPropertyWithParentTearOff(SVGProperty* parent, PropertyType& value, UpdateMethod update) + : SVGPropertyTearOff<PropertyType>(0, UndefinedRole, value) + , m_update(update) + , m_parent(parent) + { + } + + UpdateMethod m_update; + RefPtr<SVGProperty> m_parent; +}; +#if COMPILER(MSVC) +#pragma pack(pop) +#endif + +} + +#endif // ENABLE(SVG) +#endif // SVGStaticPropertyWithParentTearOff_h diff --git a/Source/WebCore/svg/properties/SVGTransformListPropertyTearOff.h b/Source/WebCore/svg/properties/SVGTransformListPropertyTearOff.h new file mode 100644 index 0000000..e496c81 --- /dev/null +++ b/Source/WebCore/svg/properties/SVGTransformListPropertyTearOff.h @@ -0,0 +1,83 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SVGTransformListPropertyTearOff_h +#define SVGTransformListPropertyTearOff_h + +#if ENABLE(SVG) +#include "SVGListPropertyTearOff.h" +#include "SVGTransformList.h" + +namespace WebCore { + +// SVGTransformList contains two additional methods, that can be exposed to the bindings. +class SVGTransformListPropertyTearOff : public SVGListPropertyTearOff<SVGTransformList> { +public: + typedef SVGAnimatedListPropertyTearOff<SVGTransformList> AnimatedListPropertyTearOff; + typedef SVGAnimatedListPropertyTearOff<SVGTransformList>::ListWrapperCache ListWrapperCache; + + static PassRefPtr<SVGListPropertyTearOff<SVGTransformList> > create(AnimatedListPropertyTearOff* animatedProperty, SVGPropertyRole role) + { + ASSERT(animatedProperty); + return adoptRef(new SVGTransformListPropertyTearOff(animatedProperty, role)); + } + + PassRefPtr<SVGPropertyTearOff<SVGTransform> > createSVGTransformFromMatrix(SVGPropertyTearOff<SVGMatrix>* matrix, ExceptionCode& ec) + { + if (!matrix) { + ec = TYPE_MISMATCH_ERR; + return 0; + } + SVGTransformList& values = m_animatedProperty->values(); + return SVGPropertyTearOff<SVGTransform>::create(values.createSVGTransformFromMatrix(matrix->propertyReference())); + } + + PassRefPtr<SVGPropertyTearOff<SVGTransform> > consolidate(ExceptionCode& ec) + { + if (!canAlterList(ec)) + return 0; + + SVGTransformList& values = m_animatedProperty->values(); + ListWrapperCache& wrappers = m_animatedProperty->wrappers(); + ASSERT(values.size() == wrappers.size()); + + // Spec: If the list was empty, then a value of null is returned. + if (values.isEmpty()) + return 0; + + m_animatedProperty->detachListWrappers(0); + RefPtr<SVGPropertyTearOff<SVGTransform> > wrapper = SVGPropertyTearOff<SVGTransform>::create(values.consolidate()); + wrappers.append(wrapper); + + ASSERT(values.size() == wrappers.size()); + return wrapper.release(); + } + +private: + SVGTransformListPropertyTearOff(AnimatedListPropertyTearOff* animatedProperty, SVGPropertyRole role) + : SVGListPropertyTearOff<SVGTransformList>(animatedProperty, role) + { + } + +}; + +} + +#endif // ENABLE(SVG) +#endif // SVGListPropertyTearOff_h diff --git a/Source/WebCore/svg/svgattrs.in b/Source/WebCore/svg/svgattrs.in new file mode 100644 index 0000000..dbe7663 --- /dev/null +++ b/Source/WebCore/svg/svgattrs.in @@ -0,0 +1,253 @@ +namespace="SVG" +namespaceURI="http://www.w3.org/2000/svg" +guardFactoryWith="ENABLE(SVG)" +attrsNullNamespace + +accent-height +accumulate +additive +alignment-baseline +alphabetic +amplitude +animate +arabic-form +ascent +attributeName +attributeType +azimuth +baseFrequency +baseline-shift +baseProfile +bbox +begin +bias +by +calcMode +cap-height +clip +clip-path +clip-rule +clipPathUnits +color +color-interpolation +color-interpolation-filters +color-profile +color-rendering +contentScriptType +contentStyleType +cursor +cx +cy +d +descent +diffuseConstant +direction +display +divisor +dominant-baseline +dur +dx +dy +edgeMode +elevation +enable-background +end +exponent +externalResourcesRequired +feColorMatrix +feComposite +feGaussianBlur +feMorphology +feTile +fill +fill-opacity +fill-rule +filter +filterRes +filterUnits +flood-color +flood-opacity +font-family +font-size +font-size-adjust +font-stretch +font-style +font-variant +font-weight +format +from +fx +fy +g1 +g2 +glyph-name +glyph-orientation-horizontal +glyph-orientation-vertical +glyphRef +gradientTransform +gradientUnits +hanging +height +horiz-adv-x +horiz-origin-x +horiz-origin-y +ideographic +image-rendering +in +in2 +intercept +k +k1 +k2 +k3 +k4 +kernelMatrix +kernelUnitLength +kerning +keyPoints +keySplines +keyTimes +lang +lengthAdjust +letter-spacing +lighting-color +limitingConeAngle +local +marker-end +marker-mid +marker-start +markerHeight +markerUnits +markerWidth +mask +maskContentUnits +maskUnits +mathematical +max +media +method +min +mode +name +numOctaves +offset +onactivate +onbegin +onend +onfocusin +onfocusout +onrepeat +onzoom +opacity +operator +order +orient +orientation +origin +overflow +overline-position +overline-thickness +panose-1 +path +pathLength +patternContentUnits +patternTransform +patternUnits +pointer-events +points +pointsAtX +pointsAtY +pointsAtZ +preserveAlpha +preserveAspectRatio +primitiveUnits +r +radius +refX +refY +rendering-intent +repeatCount +repeatDur +requiredExtensions +requiredFeatures +restart +result +rotate +rx +ry +scale +seed +shape-rendering +slope +spacing +specularConstant +specularExponent +spreadMethod +startOffset +stdDeviation +stemh +stemv +stitchTiles +stop-color +stop-opacity +strikethrough-position +strikethrough-thickness +stroke +stroke-dasharray +stroke-dashoffset +stroke-linecap +stroke-linejoin +stroke-miterlimit +stroke-opacity +stroke-width +style +surfaceScale +systemLanguage +tableValues +target +targetX +targetY +text-anchor +text-decoration +text-rendering +textLength +title +to +transform +type +u1 +u2 +underline-position +underline-thickness +unicode +unicode-bidi +unicode-range +units-per-em +v-alphabetic +v-hanging +v-ideographic +v-mathematical +values +vector-effect +version +vert-adv-y +vert-origin-x +vert-origin-y +viewBox +viewTarget +visibility +width +widths +word-spacing +writing-mode +x +x-height +x1 +x2 +xChannelSelector +y +y1 +y2 +yChannelSelector +z +zoomAndPan diff --git a/Source/WebCore/svg/svgtags.in b/Source/WebCore/svg/svgtags.in new file mode 100644 index 0000000..ee6765c --- /dev/null +++ b/Source/WebCore/svg/svgtags.in @@ -0,0 +1,106 @@ +namespace="SVG" +namespaceURI="http://www.w3.org/2000/svg" +guardFactoryWith="ENABLE(SVG)" + +a +#if ENABLE_SVG_FONTS +altGlyph +#endif +#if 0 +altGlyphDef +altGlyphItem +#endif +#if ENABLE_SVG_ANIMATION +animate +animateColor +animateMotion JSInterfaceName=SVGElement +animateTransform +set +#endif +circle +clipPath +#if 0 +color_profile +#endif +cursor +defs +desc +ellipse +#if ENABLE_FILTERS +feBlend +feColorMatrix +feComponentTransfer +feComposite +feConvolveMatrix +feDiffuseLighting +feDisplacementMap +feDistantLight +feFlood +feFuncA +feFuncB +feFuncG +feFuncR +feGaussianBlur +feImage +feMerge +feMergeNode +feMorphology +feOffset +fePointLight +feSpecularLighting +feSpotLight +feTile +feTurbulence +filter +#endif +#if ENABLE_SVG_FONTS +font +font_face +font_face_format +font_face_name +font_face_src +font_face_uri +#endif +#if ENABLE_SVG_FOREIGN_OBJECT +foreignObject +#endif +g +#if ENABLE_SVG_FONTS +glyph +#endif +#if 0 +glyphRef +#endif +#if ENABLE_SVG_FONTS +hkern interfaceName=SVGHKernElement, JSInterfaceName=SVGElement +#endif +image +line +linearGradient +marker +mask +metadata +#if ENABLE_SVG_FONTS +missing_glyph +#endif +mpath interfaceName=SVGMPathElement, JSInterfaceName=SVGElement +path +pattern +polygon +polyline +radialGradient +rect +script constructorNeedsCreatedByParser +stop +style constructorNeedsCreatedByParser +svg interfaceName=SVGSVGElement +switch +symbol +text +textPath +title +tref interfaceName=SVGTRefElement +tspan interfaceName=SVGTSpanElement +use +view +vkern interfaceName=SVGVKernElement diff --git a/Source/WebCore/svg/xlinkattrs.in b/Source/WebCore/svg/xlinkattrs.in new file mode 100644 index 0000000..6e7fef1 --- /dev/null +++ b/Source/WebCore/svg/xlinkattrs.in @@ -0,0 +1,10 @@ +namespace="XLink" +namespaceURI="http://www.w3.org/1999/xlink" + +actuate +arcrole +href +role +show +title +type |