• 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  * Copyright (C) 2014 Samsung Electronics. 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 #ifndef SVGZoomAndPan_h
23 #define SVGZoomAndPan_h
24 
25 #include "core/SVGNames.h"
26 #include "core/dom/QualifiedName.h"
27 #include "wtf/HashSet.h"
28 
29 namespace blink {
30 
31 class ExceptionState;
32 
33 enum SVGZoomAndPanType {
34     SVGZoomAndPanUnknown = 0,
35     SVGZoomAndPanDisable,
36     SVGZoomAndPanMagnify
37 };
38 
39 class SVGZoomAndPan {
40 public:
41     // Forward declare enumerations in the W3C naming scheme, for IDL generation.
42     enum {
43         SVG_ZOOMANDPAN_UNKNOWN = SVGZoomAndPanUnknown,
44         SVG_ZOOMANDPAN_DISABLE = SVGZoomAndPanDisable,
45         SVG_ZOOMANDPAN_MAGNIFY = SVGZoomAndPanMagnify
46     };
47 
~SVGZoomAndPan()48     virtual ~SVGZoomAndPan() { }
49 
50     static bool isKnownAttribute(const QualifiedName&);
51     static void addSupportedAttributes(HashSet<QualifiedName>&);
52 
parseFromNumber(unsigned short number)53     static SVGZoomAndPanType parseFromNumber(unsigned short number)
54     {
55         if (!number || number > SVGZoomAndPanMagnify)
56             return SVGZoomAndPanUnknown;
57         return static_cast<SVGZoomAndPanType>(number);
58     }
59 
60     bool parseZoomAndPan(const LChar*& start, const LChar* end);
61     bool parseZoomAndPan(const UChar*& start, const UChar* end);
62 
parseAttribute(const QualifiedName & name,const AtomicString & value)63     bool parseAttribute(const QualifiedName& name, const AtomicString& value)
64     {
65         if (name == SVGNames::zoomAndPanAttr) {
66             m_zoomAndPan = SVGZoomAndPanUnknown;
67             if (!value.isEmpty()) {
68                 if (value.is8Bit()) {
69                     const LChar* start = value.characters8();
70                     parseZoomAndPan(start, start + value.length());
71                 } else {
72                     const UChar* start = value.characters16();
73                     parseZoomAndPan(start, start + value.length());
74                 }
75             }
76             return true;
77         }
78 
79         return false;
80     }
81 
82     // JS API
zoomAndPan()83     SVGZoomAndPanType zoomAndPan() const { return m_zoomAndPan; }
setZoomAndPan(unsigned short value)84     virtual void setZoomAndPan(unsigned short value) { m_zoomAndPan = parseFromNumber(value); }
setZoomAndPan(unsigned short value,ExceptionState &)85     virtual void setZoomAndPan(unsigned short value, ExceptionState&) { setZoomAndPan(value); }
86 
87 protected:
88     SVGZoomAndPan();
89     void resetZoomAndPan();
90 
91 private:
92     SVGZoomAndPanType m_zoomAndPan;
93 };
94 
95 } // namespace blink
96 
97 #endif // SVGZoomAndPan_h
98