Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(843)

Side by Side Diff: Source/core/svg/SVGFitToViewBox.h

Issue 132233010: [SVG] SVGAnimatedRect migration to new SVG property impl. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007, 2010 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007, 2010 Rob Buis <buis@kde.org>
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details. 13 * Library General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU Library General Public License 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 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, 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA. 18 * Boston, MA 02110-1301, USA.
19 */ 19 */
20 20
21 #ifndef SVGFitToViewBox_h 21 #ifndef SVGFitToViewBox_h
22 #define SVGFitToViewBox_h 22 #define SVGFitToViewBox_h
23 23
24 #include "SVGNames.h" 24 #include "SVGNames.h"
25 #include "core/dom/QualifiedName.h" 25 #include "core/dom/QualifiedName.h"
26 #include "core/svg/SVGDocumentExtensions.h"
27 #include "core/svg/SVGParsingError.h"
26 #include "core/svg/SVGPreserveAspectRatio.h" 28 #include "core/svg/SVGPreserveAspectRatio.h"
27 #include "core/svg/SVGRect.h" 29 #include "core/svg/SVGRect.h"
28 #include "wtf/HashSet.h" 30 #include "wtf/HashSet.h"
29 31
30 namespace WebCore { 32 namespace WebCore {
31 33
32 class AffineTransform; 34 class AffineTransform;
33 class Document; 35 class Document;
34 36
35 class SVGFitToViewBox { 37 class SVGFitToViewBox {
36 public: 38 public:
37 static AffineTransform viewBoxToViewTransform(const FloatRect& viewBoxRect, const SVGPreserveAspectRatio&, float viewWidth, float viewHeight); 39 static AffineTransform viewBoxToViewTransform(const FloatRect& viewBoxRect, const SVGPreserveAspectRatio&, float viewWidth, float viewHeight);
38 40
39 static bool isKnownAttribute(const QualifiedName&); 41 static bool isKnownAttribute(const QualifiedName&);
40 static void addSupportedAttributes(HashSet<QualifiedName>&); 42 static void addSupportedAttributes(HashSet<QualifiedName>&);
41 43
42 template<class SVGElementTarget> 44 template<class SVGElementTarget>
43 static bool parseAttribute(SVGElementTarget* target, const QualifiedName& na me, const AtomicString& value) 45 static bool parseAttribute(SVGElementTarget* target, const QualifiedName& na me, const AtomicString& value)
44 { 46 {
45 ASSERT(target); 47 ASSERT(target);
46 if (name == SVGNames::viewBoxAttr) { 48 if (name == SVGNames::viewBoxAttr) {
47 FloatRect viewBox; 49 SVGParsingError parseError = NoError;
48 bool valueIsValid = !value.isNull() && parseViewBox(&target->documen t(), value, viewBox); 50 target->viewBox()->setBaseValueAsString(value, parseError);
49 if (valueIsValid) 51 target->reportAttributeParsingError(parseError, name, value);
50 target->setViewBoxBaseValue(viewBox); 52 if (target->viewBox()->baseValue()->width() < 0.0f) { // check that width is positive
51 else 53 target->document().accessSVGExtensions()->reportError("A negativ e value for ViewBox width is not allowed");
52 target->setViewBoxBaseValue(SVGRect(SVGRect::InvalidSVGRectTag() )); 54 target->viewBox()->baseValue()->setInvalid();
55 return true;
pdr. 2014/01/16 03:25:47 Should these return false instead of true?
kouhei (in TOK) 2014/01/16 03:42:27 This is tricky, but these must return true. This f
56 }
57 if (target->viewBox()->baseValue()->height() < 0.0f) { // check that height is positive
58 target->document().accessSVGExtensions()->reportError("A negativ e value for ViewBox height is not allowed");
59 target->viewBox()->baseValue()->setInvalid();
60 return true;
61 }
53 return true; 62 return true;
54 } 63 }
55 64
56 if (name == SVGNames::preserveAspectRatioAttr) { 65 if (name == SVGNames::preserveAspectRatioAttr) {
57 SVGPreserveAspectRatio preserveAspectRatio; 66 SVGPreserveAspectRatio preserveAspectRatio;
58 preserveAspectRatio.parse(value); 67 preserveAspectRatio.parse(value);
59 target->setPreserveAspectRatioBaseValue(preserveAspectRatio); 68 target->setPreserveAspectRatioBaseValue(preserveAspectRatio);
60 return true; 69 return true;
61 } 70 }
62 71
63 return false; 72 return false;
64 } 73 }
65
66 static bool parseViewBox(Document*, const LChar*& start, const LChar* end, F loatRect& viewBox, bool validate = true);
67 static bool parseViewBox(Document*, const UChar*& start, const UChar* end, F loatRect& viewBox, bool validate = true);
68
69 private:
70 static bool parseViewBox(Document*, const String&, FloatRect&);
71 }; 74 };
72 75
73 } // namespace WebCore 76 } // namespace WebCore
74 77
75 #endif // SVGFitToViewBox_h 78 #endif // SVGFitToViewBox_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698