Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> | |
| 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> | |
| 4 * Copyright (C) 2007 Apple Inc. All rights reserved. | |
| 5 * | |
| 6 * This library is free software; you can redistribute it and/or | |
| 7 * modify it under the terms of the GNU Library General Public | |
| 8 * License as published by the Free Software Foundation; either | |
| 9 * version 2 of the License, or (at your option) any later version. | |
| 10 * | |
| 11 * This library is distributed in the hope that it will be useful, | |
| 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 14 * Library General Public License for more details. | |
| 15 * | |
| 16 * You should have received a copy of the GNU Library General Public License | |
| 17 * along with this library; see the file COPYING.LIB. If not, write to | |
| 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
| 19 * Boston, MA 02110-1301, USA. | |
| 20 */ | |
| 21 | |
| 22 #include "config.h" | |
| 23 | |
| 24 #include "core/svg/SVGRect.h" | |
| 25 | |
| 26 #include "bindings/v8/ExceptionState.h" | |
| 27 #include "core/dom/ExceptionCode.h" | |
| 28 #include "core/svg/SVGAnimationElement.h" | |
| 29 #include "core/svg/SVGParserUtilities.h" | |
| 30 #include "wtf/text/WTFString.h" | |
| 31 | |
| 32 namespace WebCore { | |
| 33 | |
| 34 SVGRect::SVGRect() | |
| 35 : NewSVGPropertyBase(classType()) | |
| 36 , m_isValid(true) | |
| 37 { | |
| 38 } | |
| 39 | |
| 40 SVGRect::SVGRect(InvalidSVGRectTag) | |
| 41 : NewSVGPropertyBase(classType()) | |
| 42 { | |
| 43 setInvalid(); | |
| 44 } | |
| 45 | |
| 46 SVGRect::SVGRect(const FloatRect& rect) | |
| 47 : NewSVGPropertyBase(classType()) | |
| 48 , m_isValid(true) | |
| 49 , m_value(rect) | |
| 50 { | |
| 51 } | |
| 52 | |
| 53 PassRefPtr<SVGRect> SVGRect::clone() const | |
| 54 { | |
| 55 return SVGRect::create(m_value); | |
| 56 } | |
| 57 | |
| 58 PassRefPtr<NewSVGPropertyBase> SVGRect::cloneForAnimation(const String& value) c onst | |
| 59 { | |
| 60 RefPtr<SVGRect> rect = SVGRect::create(); | |
| 61 rect->setValueAsString(value, IGNORE_EXCEPTION); | |
| 62 return rect.release(); | |
| 63 } | |
| 64 | |
| 65 template<typename CharType> | |
| 66 void SVGRect::parse(const CharType*& ptr, const CharType* end, ExceptionState& e xceptionState) | |
| 67 { | |
| 68 const CharType* start = ptr; | |
| 69 | |
| 70 skipOptionalSVGSpaces(ptr, end); | |
| 71 | |
| 72 float x = 0.0f; | |
| 73 float y = 0.0f; | |
| 74 float width = 0.0f; | |
| 75 float height = 0.0f; | |
| 76 bool valid = parseNumber(ptr, end, x) && parseNumber(ptr, end, y) && parseNu mber(ptr, end, width) && parseNumber(ptr, end, height, false); | |
| 77 | |
| 78 if (!valid) { | |
| 79 exceptionState.throwDOMException(SyntaxError, "Problem parsing viewBox=\ "" + String(start, end - start) + "\""); | |
| 80 setInvalid(); | |
| 81 return; | |
| 82 } | |
| 83 | |
| 84 skipOptionalSVGSpaces(ptr, end); | |
| 85 if (ptr < end) { // nothing should come after the last, fourth number | |
| 86 exceptionState.throwDOMException(SyntaxError, "Problem parsing viewBox=\ "" + String(start, end - start) + "\""); | |
| 87 setInvalid(); | |
| 88 return; | |
| 89 } | |
| 90 | |
| 91 m_value = FloatRect(x, y, width, height); | |
| 92 m_isValid = true; | |
| 93 } | |
| 94 | |
| 95 void SVGRect::setValueAsString(const String& string, ExceptionState& exceptionSt ate) | |
| 96 { | |
| 97 if (string.isNull()) { | |
| 98 setInvalid(); | |
| 99 return; | |
| 100 } | |
| 101 if (string.isEmpty()) { | |
| 102 m_value = FloatRect(0.0f, 0.0f, 0.0f, 0.0f); | |
| 103 m_isValid = true; | |
| 104 return; | |
| 105 } | |
| 106 | |
| 107 if (string.is8Bit()) { | |
| 108 const LChar* ptr = string.characters8(); | |
| 109 const LChar* end = ptr + string.length(); | |
| 110 parse(ptr, end, exceptionState); | |
| 111 return; | |
| 112 } | |
| 113 | |
| 114 const UChar* ptr = string.characters16(); | |
| 115 const UChar* end = ptr + string.length(); | |
| 116 parse(ptr, end, exceptionState); | |
| 117 } | |
| 118 | |
| 119 String SVGRect::valueAsString() const | |
| 120 { | |
| 121 StringBuilder builder; | |
| 122 builder.append(String::number(x())); | |
| 123 builder.append(' '); | |
| 124 builder.append(String::number(y())); | |
| 125 builder.append(' '); | |
| 126 builder.append(String::number(width())); | |
| 127 builder.append(' '); | |
| 128 builder.append(String::number(height())); | |
| 129 return builder.toString(); | |
| 130 } | |
| 131 | |
| 132 void SVGRect::add(PassRefPtr<NewSVGPropertyBase> other, SVGElement*) | |
| 133 { | |
| 134 m_value += toSVGRect(other)->value(); | |
| 135 } | |
| 136 | |
| 137 void SVGRect::calculateAnimatedValue(SVGAnimationElement* animationElement, floa t percentage, unsigned repeatCount, PassRefPtr<NewSVGPropertyBase> fromValue, Pa ssRefPtr<NewSVGPropertyBase> toValue, PassRefPtr<NewSVGPropertyBase> toAtEndOfDu rationValue, SVGElement*) | |
| 138 { | |
| 139 ASSERT(animationElement); | |
| 140 RefPtr<SVGRect> fromRect = animationElement->animationMode() == ToAnimation ? this : toSVGRect(fromValue); | |
| 141 RefPtr<SVGRect> toRect = toSVGRect(toValue); | |
| 142 RefPtr<SVGRect> toAtEndOfDurationRect = toSVGRect(toAtEndOfDurationValue); | |
| 143 | |
| 144 float animatedX = x(); | |
| 145 float animatedY = y(); | |
| 146 float animatedWidth = width(); | |
| 147 float animatedHeight = height(); | |
| 148 animationElement->animateAdditiveNumber(percentage, repeatCount, fromRect->x (), toRect->x(), toAtEndOfDurationRect->x(), animatedX); | |
| 149 animationElement->animateAdditiveNumber(percentage, repeatCount, fromRect->y (), toRect->y(), toAtEndOfDurationRect->y(), animatedY); | |
| 150 animationElement->animateAdditiveNumber(percentage, repeatCount, fromRect->w idth(), toRect->width(), toAtEndOfDurationRect->width(), animatedWidth); | |
| 151 animationElement->animateAdditiveNumber(percentage, repeatCount, fromRect->h eight(), toRect->height(), toAtEndOfDurationRect->height(), animatedHeight); | |
| 152 | |
| 153 m_value = FloatRect(animatedX, animatedY, animatedWidth, animatedHeight); | |
| 154 } | |
| 155 | |
| 156 float SVGRect::calculateDistance(PassRefPtr<NewSVGPropertyBase> to, SVGElement* contextElement) | |
| 157 { | |
| 158 // FIXME: Distance calculation is not possible for SVGRect right now. We nee d the distance of for every single value. | |
|
pdr.
2014/01/16 03:25:47
// FIXME: Distance calculation is not possible for
kouhei (in TOK)
2014/01/16 03:42:27
Done.
| |
| 159 return -1; | |
| 160 } | |
| 161 | |
| 162 void SVGRect::setInvalid() | |
| 163 { | |
| 164 m_value = FloatRect(0.0f, 0.0f, 0.0f, 0.0f); | |
| 165 m_isValid = false; | |
| 166 } | |
| 167 | |
| 168 } | |
| OLD | NEW |