Home | History | Annotate | Download | only in svg
      1 /*
      2  * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann (at) kde.org>
      3  * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis (at) kde.org>
      4  *
      5  * This library is free software; you can redistribute it and/or
      6  * modify it under the terms of the GNU Library General Public
      7  * License as published by the Free Software Foundation; either
      8  * version 2 of the License, or (at your option) any later version.
      9  *
     10  * This library is distributed in the hope that it will be useful,
     11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13  * Library General Public License for more details.
     14  *
     15  * You should have received a copy of the GNU Library General Public License
     16  * along with this library; see the file COPYING.LIB.  If not, write to
     17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     18  * Boston, MA 02110-1301, USA.
     19  */
     20 
     21 #ifndef SVGZoomAndPan_h
     22 #define SVGZoomAndPan_h
     23 
     24 #include "SVGNames.h"
     25 #include "core/dom/QualifiedName.h"
     26 #include "wtf/HashSet.h"
     27 
     28 namespace WebCore {
     29 
     30 enum SVGZoomAndPanType {
     31     SVGZoomAndPanUnknown = 0,
     32     SVGZoomAndPanDisable,
     33     SVGZoomAndPanMagnify
     34 };
     35 
     36 class SVGZoomAndPan {
     37 public:
     38     // Forward declare enumerations in the W3C naming scheme, for IDL generation.
     39     enum {
     40         SVG_ZOOMANDPAN_UNKNOWN = SVGZoomAndPanUnknown,
     41         SVG_ZOOMANDPAN_DISABLE = SVGZoomAndPanDisable,
     42         SVG_ZOOMANDPAN_MAGNIFY = SVGZoomAndPanMagnify
     43     };
     44 
     45     static bool isKnownAttribute(const QualifiedName&);
     46     static void addSupportedAttributes(HashSet<QualifiedName>&);
     47 
     48     static SVGZoomAndPanType parseFromNumber(unsigned short number)
     49     {
     50         if (!number || number > SVGZoomAndPanMagnify)
     51             return SVGZoomAndPanUnknown;
     52         return static_cast<SVGZoomAndPanType>(number);
     53     }
     54 
     55     static bool parseZoomAndPan(const LChar*& start, const LChar* end, SVGZoomAndPanType&);
     56     static bool parseZoomAndPan(const UChar*& start, const UChar* end, SVGZoomAndPanType&);
     57 
     58     template<class SVGElementTarget>
     59     static bool parseAttribute(SVGElementTarget* target, const QualifiedName& name, const AtomicString& value)
     60     {
     61         ASSERT(target);
     62         ASSERT(target->document());
     63         if (name == SVGNames::zoomAndPanAttr) {
     64             SVGZoomAndPanType zoomAndPan = SVGZoomAndPanUnknown;
     65             if (!value.isEmpty()) {
     66                 if (value.is8Bit()) {
     67                     const LChar* start = value.characters8();
     68                     parseZoomAndPan(start, start + value.length(), zoomAndPan);
     69                 } else {
     70                     const UChar* start = value.characters16();
     71                     parseZoomAndPan(start, start + value.length(), zoomAndPan);
     72                 }
     73             }
     74             target->setZoomAndPan(zoomAndPan);
     75             return true;
     76         }
     77 
     78         return false;
     79     }
     80 
     81     SVGZoomAndPanType zoomAndPan() const { return SVGZoomAndPanUnknown; }
     82 
     83     // These methods only exist to allow us to compile V8/JSSVGZoomAndPan.*.
     84     // These are never called, and thus ASSERT_NOT_REACHED.
     85     void ref();
     86     void deref();
     87     void setZoomAndPan(unsigned short);
     88 };
     89 
     90 } // namespace WebCore
     91 
     92 #endif // SVGZoomAndPan_h
     93