2010-04-28 16:00:54 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-04-28 16:00:54 -07:00
|
|
|
|
|
|
|
/* Helper class to help with generating anonymous path elements for
|
|
|
|
<animateMotion> elements to use. */
|
|
|
|
|
|
|
|
#ifndef MOZILLA_SVGMOTIONSMILPATHUTILS_H_
|
|
|
|
#define MOZILLA_SVGMOTIONSMILPATHUTILS_H_
|
|
|
|
|
2013-05-29 13:43:41 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2010-08-20 12:29:01 -07:00
|
|
|
#include "gfxPlatform.h"
|
2013-11-17 17:29:05 -08:00
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
#include "mozilla/RefPtr.h"
|
2012-01-26 01:57:21 -08:00
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsSMILParserUtils.h"
|
|
|
|
#include "nsTArray.h"
|
2010-04-28 16:00:54 -07:00
|
|
|
|
|
|
|
class nsAString;
|
2012-01-26 01:57:21 -08:00
|
|
|
class nsSVGElement;
|
2010-04-28 16:00:54 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2013-11-17 17:29:05 -08:00
|
|
|
class SVGMotionSMILPathUtils
|
|
|
|
{
|
|
|
|
typedef mozilla::gfx::DrawTarget DrawTarget;
|
2013-11-17 17:29:06 -08:00
|
|
|
typedef mozilla::gfx::Path Path;
|
2013-11-17 17:29:05 -08:00
|
|
|
typedef mozilla::gfx::PathBuilder PathBuilder;
|
|
|
|
|
2010-04-28 16:00:54 -07:00
|
|
|
public:
|
2013-11-17 17:29:06 -08:00
|
|
|
// Class to assist in generating a Path, based on
|
2010-04-28 16:00:54 -07:00
|
|
|
// coordinates in the <animateMotion> from/by/to/values attributes.
|
|
|
|
class PathGenerator {
|
|
|
|
public:
|
2014-08-31 18:08:04 -07:00
|
|
|
explicit PathGenerator(const nsSVGElement* aSVGElement)
|
2010-04-28 16:00:54 -07:00
|
|
|
: mSVGElement(aSVGElement),
|
2011-10-17 07:59:28 -07:00
|
|
|
mHaveReceivedCommands(false)
|
2013-11-17 17:29:05 -08:00
|
|
|
{
|
|
|
|
RefPtr<DrawTarget> drawTarget =
|
|
|
|
gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget();
|
|
|
|
NS_ASSERTION(gfxPlatform::GetPlatform()->
|
|
|
|
SupportsAzureContentForDrawTarget(drawTarget),
|
|
|
|
"Should support Moz2D content drawing");
|
|
|
|
|
|
|
|
mPathBuilder = drawTarget->CreatePathBuilder();
|
|
|
|
}
|
2010-04-28 16:00:54 -07:00
|
|
|
|
|
|
|
// Methods for adding various path commands to output path.
|
|
|
|
// Note: aCoordPairStr is expected to be a whitespace and/or
|
|
|
|
// comma-separated x,y coordinate-pair -- see description of
|
|
|
|
// "the specified values for from, by, to, and values" at
|
|
|
|
// http://www.w3.org/TR/SVG11/animate.html#AnimateMotionElement
|
|
|
|
void MoveToOrigin();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool MoveToAbsolute(const nsAString& aCoordPairStr);
|
|
|
|
bool LineToAbsolute(const nsAString& aCoordPairStr,
|
2010-04-28 16:00:54 -07:00
|
|
|
double& aSegmentDistance);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool LineToRelative(const nsAString& aCoordPairStr,
|
2010-04-28 16:00:54 -07:00
|
|
|
double& aSegmentDistance);
|
|
|
|
|
|
|
|
// Accessor to let clients check if we've received any commands yet.
|
2011-09-28 23:19:26 -07:00
|
|
|
inline bool HaveReceivedCommands() { return mHaveReceivedCommands; }
|
2010-04-28 16:00:54 -07:00
|
|
|
// Accessor to get the finalized path
|
2013-11-17 17:29:06 -08:00
|
|
|
mozilla::TemporaryRef<Path> GetResultingPath();
|
2010-04-28 16:00:54 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// Helper methods
|
2011-09-28 23:19:26 -07:00
|
|
|
bool ParseCoordinatePair(const nsAString& aStr,
|
2010-04-28 16:00:54 -07:00
|
|
|
float& aXVal, float& aYVal);
|
|
|
|
|
|
|
|
// Member data
|
2010-12-04 04:26:45 -08:00
|
|
|
const nsSVGElement* mSVGElement; // context for converting to user units
|
2013-11-17 17:29:05 -08:00
|
|
|
RefPtr<PathBuilder> mPathBuilder;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mHaveReceivedCommands;
|
2010-04-28 16:00:54 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// Class to assist in passing each subcomponent of a |values| attribute to
|
2013-11-17 17:29:06 -08:00
|
|
|
// a PathGenerator, for generating a corresponding Path.
|
2013-11-25 11:46:20 -08:00
|
|
|
class MOZ_STACK_CLASS MotionValueParser :
|
|
|
|
public nsSMILParserUtils::GenericValueParser
|
2010-04-28 16:00:54 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
MotionValueParser(PathGenerator* aPathGenerator,
|
2013-11-25 11:46:20 -08:00
|
|
|
FallibleTArray<double>* aPointDistances)
|
2010-04-28 16:00:54 -07:00
|
|
|
: mPathGenerator(aPathGenerator),
|
|
|
|
mPointDistances(aPointDistances),
|
|
|
|
mDistanceSoFar(0.0)
|
|
|
|
{
|
2015-02-09 14:34:50 -08:00
|
|
|
MOZ_ASSERT(mPointDistances->IsEmpty(),
|
|
|
|
"expecting point distances array to start empty");
|
2010-04-28 16:00:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsSMILParserUtils::GenericValueParser interface
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual bool Parse(const nsAString& aValueStr) override;
|
2010-04-28 16:00:54 -07:00
|
|
|
|
|
|
|
protected:
|
2013-11-25 11:46:20 -08:00
|
|
|
PathGenerator* mPathGenerator;
|
|
|
|
FallibleTArray<double>* mPointDistances;
|
|
|
|
double mDistanceSoFar;
|
2010-04-28 16:00:54 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // MOZILLA_SVGMOTIONSMILPATHUTILS_H_
|