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/SVGPropertyHelper.h"
     24 #include "platform/geometry/FloatRect.h"
     25 
     26 namespace blink {
     27 
     28 class SVGRectTearOff;
     29 
     30 class SVGRect : public SVGPropertyHelper<SVGRect> {
     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 
     53     const FloatRect& value() const { return m_value; }
     54     void setValue(const FloatRect& v) { m_value = v; }
     55 
     56     float x() const { return m_value.x(); }
     57     float y() const { return m_value.y(); }
     58     float width() const { return m_value.width(); }
     59     float height() const { return m_value.height(); }
     60     void setX(float f) { m_value.setX(f); }
     61     void setY(float f) { m_value.setY(f); }
     62     void setWidth(float f) { m_value.setWidth(f); }
     63     void setHeight(float f) { m_value.setHeight(f); }
     64 
     65     virtual String valueAsString() const OVERRIDE;
     66     void setValueAsString(const String&, ExceptionState&);
     67 
     68     virtual void add(PassRefPtrWillBeRawPtr<SVGPropertyBase>, SVGElement*) OVERRIDE;
     69     virtual void calculateAnimatedValue(SVGAnimationElement*, float percentage, unsigned repeatCount, PassRefPtr<SVGPropertyBase> from, PassRefPtr<SVGPropertyBase> to, PassRefPtr<SVGPropertyBase> toAtEndOfDurationValue, SVGElement* contextElement) OVERRIDE;
     70     virtual float calculateDistance(PassRefPtr<SVGPropertyBase> to, SVGElement* contextElement) OVERRIDE;
     71 
     72     bool isValid() const { return m_isValid; }
     73     void setInvalid();
     74 
     75     static AnimatedPropertyType classType() { return AnimatedRect; }
     76 
     77 private:
     78     SVGRect();
     79     SVGRect(InvalidSVGRectTag);
     80     SVGRect(const FloatRect&);
     81 
     82     template<typename CharType>
     83     void parse(const CharType*& ptr, const CharType* end, ExceptionState&);
     84 
     85     bool m_isValid;
     86     FloatRect m_value;
     87 };
     88 
     89 inline PassRefPtr<SVGRect> toSVGRect(PassRefPtr<SVGPropertyBase> passBase)
     90 {
     91     RefPtr<SVGPropertyBase> base = passBase;
     92     ASSERT(base->type() == SVGRect::classType());
     93     return static_pointer_cast<SVGRect>(base.release());
     94 }
     95 
     96 } // namespace blink
     97 
     98 #endif // SVGRect_h
     99