1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is the Mozilla SVG project.
16 : *
17 : * The Initial Developer of the Original Code is the Mozilla Foundation.
18 : * Portions created by the Initial Developer are Copyright (C) 2010
19 : * the Initial Developer. All Rights Reserved.
20 : *
21 : * Contributor(s):
22 : * Daniel Holbert <dholbert@mozilla.com>
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either of the GNU General Public License Version 2 or later (the "GPL"),
26 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : /* Helper class to help with generating anonymous path elements for
39 : <animateMotion> elements to use. */
40 :
41 : #ifndef MOZILLA_SVGMOTIONSMILPATHUTILS_H_
42 : #define MOZILLA_SVGMOTIONSMILPATHUTILS_H_
43 :
44 : #include "gfxContext.h"
45 : #include "gfxPlatform.h"
46 : #include "nsCOMPtr.h"
47 : #include "nsDebug.h"
48 : #include "nsSMILParserUtils.h"
49 : #include "nsTArray.h"
50 :
51 : class gfxFlattenedPath;
52 : class nsAString;
53 : class nsSVGElement;
54 :
55 : namespace mozilla {
56 :
57 : class SVGMotionSMILPathUtils {
58 : public:
59 : // Class to assist in generating a gfxFlattenedPath, based on
60 : // coordinates in the <animateMotion> from/by/to/values attributes.
61 0 : class PathGenerator {
62 : public:
63 0 : PathGenerator(const nsSVGElement* aSVGElement)
64 : : mSVGElement(aSVGElement),
65 : mGfxContext(gfxPlatform::GetPlatform()->ScreenReferenceSurface()),
66 0 : mHaveReceivedCommands(false)
67 0 : {}
68 :
69 : // Methods for adding various path commands to output path.
70 : // Note: aCoordPairStr is expected to be a whitespace and/or
71 : // comma-separated x,y coordinate-pair -- see description of
72 : // "the specified values for from, by, to, and values" at
73 : // http://www.w3.org/TR/SVG11/animate.html#AnimateMotionElement
74 : void MoveToOrigin();
75 : bool MoveToAbsolute(const nsAString& aCoordPairStr);
76 : bool LineToAbsolute(const nsAString& aCoordPairStr,
77 : double& aSegmentDistance);
78 : bool LineToRelative(const nsAString& aCoordPairStr,
79 : double& aSegmentDistance);
80 :
81 : // Accessor to let clients check if we've received any commands yet.
82 0 : inline bool HaveReceivedCommands() { return mHaveReceivedCommands; }
83 : // Accessor to get the finalized path
84 : already_AddRefed<gfxFlattenedPath> GetResultingPath();
85 :
86 : protected:
87 : // Helper methods
88 : bool ParseCoordinatePair(const nsAString& aStr,
89 : float& aXVal, float& aYVal);
90 :
91 : // Member data
92 : const nsSVGElement* mSVGElement; // context for converting to user units
93 : gfxContext mGfxContext;
94 : bool mHaveReceivedCommands;
95 : };
96 :
97 : // Class to assist in passing each subcomponent of a |values| attribute to
98 : // a PathGenerator, for generating a corresponding gfxFlattenedPath.
99 : class MotionValueParser : public nsSMILParserUtils::GenericValueParser
100 : {
101 : public:
102 0 : MotionValueParser(PathGenerator* aPathGenerator,
103 : nsTArray<double>* aPointDistances)
104 : : mPathGenerator(aPathGenerator),
105 : mPointDistances(aPointDistances),
106 0 : mDistanceSoFar(0.0)
107 : {
108 0 : NS_ABORT_IF_FALSE(mPointDistances->IsEmpty(),
109 : "expecting point distances array to start empty");
110 0 : }
111 :
112 : // nsSMILParserUtils::GenericValueParser interface
113 : virtual nsresult Parse(const nsAString& aValueStr);
114 :
115 : protected:
116 : PathGenerator* mPathGenerator;
117 : nsTArray<double>* mPointDistances;
118 : double mDistanceSoFar;
119 : };
120 :
121 : };
122 :
123 : } // namespace mozilla
124 :
125 : #endif // MOZILLA_SVGMOTIONSMILPATHUTILS_H_
|