Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(396)

Unified Diff: Source/core/svg/SVGLength.h

Issue 112003003: [SVG] SVGLength{,List} migration to new SVG property impl. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebaselined Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/svg/SVGLength.h
diff --git a/Source/core/svg/SVGLength.h b/Source/core/svg/SVGLength.h
index 31310509b1b7d1b78ab262019e68ea658975d677..266facce5bcbc089269e2ad7aa3689147351fc7c 100644
--- a/Source/core/svg/SVGLength.h
+++ b/Source/core/svg/SVGLength.h
@@ -1,34 +1,48 @@
/*
- * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
- * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org>
+ * Copyright (C) 2013 Google Inc. All rights reserved.
pdr. 2014/01/07 06:42:53 Can you check that we're able to change this copyr
kouhei (in TOK) 2014/01/07 09:22:28 I'll revert these copyright changes. These were ac
*
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
*
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
*
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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 THE COPYRIGHT
+ * OWNER 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 SVGLength_h
#define SVGLength_h
-#include "bindings/v8/ExceptionState.h"
+#include "bindings/v8/ExceptionMessages.h"
+#include "bindings/v8/ExceptionStatePlaceholder.h"
+#include "bindings/v8/ScriptWrappable.h"
+#include "core/dom/ExceptionCode.h"
#include "core/svg/SVGLengthContext.h"
#include "core/svg/SVGParsingError.h"
-#include "core/svg/properties/SVGPropertyTraits.h"
-#include "platform/animation/AnimationUtilities.h"
+#include "core/svg/properties/NewSVGProperty.h"
+#include "core/svg/properties/NewSVGPropertyTearOff.h"
namespace WebCore {
+/* use SVGLength.h decls */
class CSSPrimitiveValue;
class ExceptionState;
class QualifiedName;
@@ -38,58 +52,51 @@ enum SVGLengthNegativeValuesMode {
ForbidNegativeLengths
};
-class SVGLength {
- WTF_MAKE_FAST_ALLOCATED;
+class SVGLengthTearOff;
+
+class SVGLength : public NewSVGPropertyBase {
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
- };
+ typedef SVGLengthTearOff TearOffType;
+
+ static PassRefPtr<SVGLength> create(SVGLengthMode mode = LengthModeOther)
+ {
+ return adoptRef(new SVGLength(mode));
+ }
- SVGLength(SVGLengthMode = LengthModeOther, const String& valueAsString = String());
- SVGLength(const SVGLengthContext&, float, SVGLengthMode = LengthModeOther, SVGLengthType = LengthTypeNumber);
- SVGLength(const SVGLength&);
+ PassRefPtr<SVGLength> clone() const;
+ virtual PassRefPtr<NewSVGPropertyBase> cloneForAnimation(const String&) const;
- SVGLengthType unitType() const;
- SVGLengthMode unitMode() const;
+ SVGLengthType unitType() const { return static_cast<SVGLengthType>(m_unitType); }
+ void setUnitType(SVGLengthType);
+ SVGLengthMode unitMode() const { return static_cast<SVGLengthMode>(m_unitMode); }
bool operator==(const SVGLength&) const;
- bool operator!=(const SVGLength&) const;
-
- static SVGLength construct(SVGLengthMode, const String&, SVGParsingError&, SVGLengthNegativeValuesMode = AllowNegativeLengths);
+ bool operator!=(const SVGLength& other) const { return !operator==(other); }
- float value(const SVGLengthContext&) const;
+ float value(const SVGLengthContext& context) const
+ {
+ return value(context, IGNORE_EXCEPTION);
+ }
float value(const SVGLengthContext&, ExceptionState&) const;
void setValue(float, const SVGLengthContext&, ExceptionState&);
- void setValue(const SVGLengthContext&, float, SVGLengthMode, SVGLengthType, ExceptionState&);
float valueInSpecifiedUnits() const { return m_valueInSpecifiedUnits; }
void setValueInSpecifiedUnits(float value) { m_valueInSpecifiedUnits = value; }
float valueAsPercentage() const;
- String valueAsString() const;
+ virtual String valueAsString() const;
pdr. 2014/01/07 06:42:53 Please add OVERRIDE (here, and elsewhere) virtual
kouhei (in TOK) 2014/01/07 09:22:28 Done.
void setValueAsString(const String&, ExceptionState&);
- void setValueAsString(const String&, SVGLengthMode, ExceptionState&);
- void newValueSpecifiedUnits(unsigned short, float valueInSpecifiedUnits, ExceptionState&);
- void convertToSpecifiedUnits(unsigned short, const SVGLengthContext&, ExceptionState&);
+ void newValueSpecifiedUnits(SVGLengthType, float valueInSpecifiedUnits);
+ void convertToSpecifiedUnits(SVGLengthType, const SVGLengthContext&, ExceptionState&);
// Helper functions
inline bool isRelative() const
{
- SVGLengthType type = unitType();
- return type == LengthTypePercentage || type == LengthTypeEMS || type == LengthTypeEXS;
+ return m_unitType == LengthTypePercentage
+ || m_unitType == LengthTypeEMS
+ || m_unitType == LengthTypeEXS;
}
bool isZero() const
@@ -97,77 +104,66 @@ public:
return !m_valueInSpecifiedUnits;
}
- static SVGLength fromCSSPrimitiveValue(CSSPrimitiveValue*);
- static PassRefPtr<CSSPrimitiveValue> toCSSPrimitiveValue(const SVGLength&);
+ static PassRefPtr<SVGLength> fromCSSPrimitiveValue(CSSPrimitiveValue*);
+ static PassRefPtr<CSSPrimitiveValue> toCSSPrimitiveValue(PassRefPtr<SVGLength>);
static SVGLengthMode lengthModeForAnimatedLengthAttribute(const QualifiedName&);
- SVGLength blend(const SVGLength& from, float progress) const
- {
- SVGLengthType toType = unitType();
- SVGLengthType fromType = from.unitType();
- if ((from.isZero() && isZero())
- || fromType == LengthTypeUnknown
- || toType == LengthTypeUnknown
- || (!from.isZero() && fromType != LengthTypePercentage && toType == LengthTypePercentage)
- || (!isZero() && fromType == LengthTypePercentage && toType != LengthTypePercentage)
- || (!from.isZero() && !isZero() && (fromType == LengthTypeEMS || fromType == LengthTypeEXS) && fromType != toType))
- return *this;
-
- SVGLength length;
- TrackExceptionState exceptionState;
-
- if (fromType == LengthTypePercentage || toType == LengthTypePercentage) {
- float fromPercent = from.valueAsPercentage() * 100;
- float toPercent = valueAsPercentage() * 100;
- length.newValueSpecifiedUnits(LengthTypePercentage, WebCore::blend(fromPercent, toPercent, progress), exceptionState);
- if (exceptionState.hadException())
- return SVGLength();
- return length;
- }
-
- if (fromType == toType || from.isZero() || isZero() || fromType == LengthTypeEMS || fromType == LengthTypeEXS) {
- float fromValue = from.valueInSpecifiedUnits();
- float toValue = valueInSpecifiedUnits();
- if (isZero())
- length.newValueSpecifiedUnits(fromType, WebCore::blend(fromValue, toValue, progress), exceptionState);
- else
- length.newValueSpecifiedUnits(toType, WebCore::blend(fromValue, toValue, progress), exceptionState);
- if (exceptionState.hadException())
- return SVGLength();
- return length;
- }
-
- ASSERT(!isRelative());
- ASSERT(!from.isRelative());
-
- SVGLengthContext nonRelativeLengthContext(0);
- float fromValueInUserUnits = nonRelativeLengthContext.convertValueToUserUnits(from.valueInSpecifiedUnits(), from.unitMode(), fromType, exceptionState);
- if (exceptionState.hadException())
- return SVGLength();
-
- float fromValue = nonRelativeLengthContext.convertValueFromUserUnits(fromValueInUserUnits, unitMode(), toType, exceptionState);
- if (exceptionState.hadException())
- return SVGLength();
-
- float toValue = valueInSpecifiedUnits();
- length.newValueSpecifiedUnits(toType, WebCore::blend(fromValue, toValue, progress), exceptionState);
-
- if (exceptionState.hadException())
- return SVGLength();
- return length;
- }
+ PassRefPtr<SVGLength> blend(const SVGLength* from, float progress) const;
+
+ virtual void add(PassRefPtr<NewSVGPropertyBase>, SVGElement*);
+ virtual void calculateAnimatedValue(SVGAnimationElement*, float percentage, unsigned repeatCount, PassRefPtr<NewSVGPropertyBase> from, PassRefPtr<NewSVGPropertyBase> to, PassRefPtr<NewSVGPropertyBase> toAtEndOfDurationValue, SVGElement* contextElement);
+ virtual float calculateDistance(PassRefPtr<NewSVGPropertyBase> to, SVGElement* contextElement);
private:
+ SVGLength(SVGLengthMode);
+
float m_valueInSpecifiedUnits;
- unsigned int m_unit;
+ unsigned m_unitMode : 2;
+ unsigned m_unitType : 4;
};
-template<>
-struct SVGPropertyTraits<SVGLength> {
- static SVGLength initialValue() { return SVGLength(); }
- static String toString(const SVGLength& type) { return type.valueAsString(); }
-};
+inline SVGLength* toSVGLength(NewSVGPropertyBase* base)
+{
+ // FIXME: add type checking
pdr. 2014/01/07 06:42:53 (here, and elsewhere in this patch) Can you implem
kouhei (in TOK) 2014/01/07 09:22:28 Done.
+ return static_cast<SVGLength*>(base);
+}
+
+class SVGLengthTearOff : public NewSVGPropertyTearOff<SVGLength>, public ScriptWrappable {
+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
+ };
+
+ static PassRefPtr<SVGLengthTearOff> create(PassRefPtr<SVGLength> target, SVGElement* contextElement, PropertyIsAnimValType propertyIsAnimVal, const QualifiedName& attributeName = nullQName())
+ {
+ return adoptRef(new SVGLengthTearOff(target, contextElement, propertyIsAnimVal, attributeName));
+ }
+
+ SVGLengthType unitType();
+ SVGLengthMode unitMode();
+ float value(ExceptionState&);
+ void setValue(float value, ExceptionState&);
+ float valueInSpecifiedUnits();
+ void setValueInSpecifiedUnits(float value, ExceptionState&);
+ String valueAsString();
+ void setValueAsString(const String&, ExceptionState&);
+ void newValueSpecifiedUnits(unsigned short unitType, float valueInSpecifiedUnits, ExceptionState&);
+ void convertToSpecifiedUnits(unsigned short unitType, ExceptionState&);
+private:
+ SVGLengthTearOff(PassRefPtr<SVGLength>, SVGElement* contextElement, PropertyIsAnimValType, const QualifiedName& attributeName = nullQName());
pdr. 2014/01/07 06:42:53 Can you check whether this should be anyQName() or
kouhei (in TOK) 2014/01/08 08:12:07 I think nullQName is appropriate here, as we want
+};
} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698