• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3  * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@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 
parseFromNumber(unsigned short number)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>
parseAttribute(SVGElementTarget * target,const QualifiedName & name,const AtomicString & value)59     static bool parseAttribute(SVGElementTarget* target, const QualifiedName& name, const AtomicString& value)
60     {
61         ASSERT(target);
62         if (name == SVGNames::zoomAndPanAttr) {
63             SVGZoomAndPanType zoomAndPan = SVGZoomAndPanUnknown;
64             if (!value.isEmpty()) {
65                 if (value.is8Bit()) {
66                     const LChar* start = value.characters8();
67                     parseZoomAndPan(start, start + value.length(), zoomAndPan);
68                 } else {
69                     const UChar* start = value.characters16();
70                     parseZoomAndPan(start, start + value.length(), zoomAndPan);
71                 }
72             }
73             target->setZoomAndPan(zoomAndPan);
74             return true;
75         }
76 
77         return false;
78     }
79 
zoomAndPan()80     SVGZoomAndPanType zoomAndPan() const { return SVGZoomAndPanUnknown; }
81 
82     // These methods only exist to allow us to compile V8/JSSVGZoomAndPan.*.
83     // These are never called, and thus ASSERT_NOT_REACHED.
84     void ref();
85     void deref();
86     void setZoomAndPan(unsigned short);
87 };
88 
89 } // namespace WebCore
90 
91 #endif // SVGZoomAndPan_h
92