Home | History | Annotate | Download | only in svg
      1 /*
      2  * Copyright (C) Research In Motion Limited 2010. All rights reserved.
      3  *
      4  * This library is free software; you can redistribute it and/or
      5  * modify it under the terms of the GNU Library General Public
      6  * License as published by the Free Software Foundation; either
      7  * version 2 of the License, or (at your option) any later version.
      8  *
      9  * This library is distributed in the hope that it will be useful,
     10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12  * Library General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU Library General Public License
     15  * along with this library; see the file COPYING.LIB.  If not, write to
     16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     17  * Boston, MA 02110-1301, USA.
     18  */
     19 
     20 #ifndef SVGRect_h
     21 #define SVGRect_h
     22 
     23 #include "core/svg/properties/SVGProperty.h"
     24 #include "platform/geometry/FloatRect.h"
     25 
     26 namespace WebCore {
     27 
     28 class SVGRectTearOff;
     29 
     30 class SVGRect : public SVGPropertyBase {
     31 public:
     32     typedef SVGRectTearOff TearOffType;
     33 
     34     struct InvalidSVGRectTag { };
     35 
     36     static PassRefPtr<SVGRect> create()
     37     {
     38         return adoptRef(new SVGRect());
     39     }
     40 
     41     static PassRefPtr<SVGRect> create(InvalidSVGRectTag)
     42     {
     43         return adoptRef(new SVGRect(InvalidSVGRectTag()));
     44     }
     45 
     46     static PassRefPtr<SVGRect> create(const FloatRect& rect)
     47     {
     48         return adoptRef(new SVGRect(rect));
     49     }
     50 
     51     PassRefPtr<SVGRect> clone() const;
     52     virtual PassRefPtr<SVGPropertyBase> cloneForAnimation(const String&) const OVERRIDE;
     53 
     54     const FloatRect& value() const { return m_value; }
     55     void setValue(const FloatRect& v) { m_value = v; }
     56 
     57     float x() const { return m_value.x(); }
     58     float y() const { return m_value.y(); }
     59     float width() const { return m_value.width(); }
     60     float height() const { return m_value.height(); }
     61     void setX(float f) { m_value.setX(f); }
     62     void setY(float f) { m_value.setY(f); }
     63     void setWidth(float f) { m_value.setWidth(f); }
     64     void setHeight(float f) { m_value.setHeight(f); }
     65 
     66     bool operator==(const SVGRect&) const;
     67     bool operator!=(const SVGRect& other) const { return !operator==(other); }
     68 
     69     virtual String valueAsString() const OVERRIDE;
     70     void setValueAsString(const String&, ExceptionState&);
     71 
     72     virtual void add(PassRefPtrWillBeRawPtr<SVGPropertyBase>, SVGElement*) OVERRIDE;
     73     virtual void calculateAnimatedValue(SVGAnimationElement*, float percentage, unsigned repeatCount, PassRefPtr<SVGPropertyBase> from, PassRefPtr<SVGPropertyBase> to, PassRefPtr<SVGPropertyBase> toAtEndOfDurationValue, SVGElement* contextElement) OVERRIDE;
     74     virtual float calculateDistance(PassRefPtr<SVGPropertyBase> to, SVGElement* contextElement) OVERRIDE;
     75 
     76     bool isValid() const { return m_isValid; }
     77     void setInvalid();
     78 
     79     static AnimatedPropertyType classType() { return AnimatedRect; }
     80 
     81 private:
     82     SVGRect();
     83     SVGRect(InvalidSVGRectTag);
     84     SVGRect(const FloatRect&);
     85 
     86     template<typename CharType>
     87     void parse(const CharType*& ptr, const CharType* end, ExceptionState&);
     88 
     89     bool m_isValid;
     90     FloatRect m_value;
     91 };
     92 
     93 inline PassRefPtr<SVGRect> toSVGRect(PassRefPtr<SVGPropertyBase> passBase)
     94 {
     95     RefPtr<SVGPropertyBase> base = passBase;
     96     ASSERT(base->type() == SVGRect::classType());
     97     return static_pointer_cast<SVGRect>(base.release());
     98 }
     99 
    100 } // namespace WebCore
    101 
    102 #endif // SVGRect_h
    103