2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00: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 23:00:54 +00: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 20:43:41 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2010-08-20 19:29:01 +00:00
|
|
|
#include "gfxPlatform.h"
|
2013-11-18 01:29:05 +00:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2015-10-18 05:24:48 +00:00
|
|
|
#include "mozilla/RefPtr.h"
|
2012-01-26 09:57:21 +00:00
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsSMILParserUtils.h"
|
|
|
|
#include "nsTArray.h"
|
2010-04-28 23:00:54 +00:00
|
|
|
|
|
|
|
class nsAString;
|
2012-01-26 09:57:21 +00:00
|
|
|
class nsSVGElement;
|
2010-04-28 23:00:54 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2013-11-18 01:29:05 +00:00
|
|
|
class SVGMotionSMILPathUtils
|
|
|
|
{
|
|
|
|
typedef mozilla::gfx::DrawTarget DrawTarget;
|
2013-11-18 01:29:06 +00:00
|
|
|
typedef mozilla::gfx::Path Path;
|
2013-11-18 01:29:05 +00:00
|
|
|
typedef mozilla::gfx::PathBuilder PathBuilder;
|
|
|
|
|
2010-04-28 23:00:54 +00:00
|
|
|
public:
|
2013-11-18 01:29:06 +00:00
|
|
|
// Class to assist in generating a Path, based on
|
2010-04-28 23:00:54 +00:00
|
|
|
// coordinates in the <animateMotion> from/by/to/values attributes.
|
|
|
|
class PathGenerator {
|
|
|
|
public:
|
2014-09-01 01:08:04 +00:00
|
|
|
explicit PathGenerator(const nsSVGElement* aSVGElement)
|
2010-04-28 23:00:54 +00:00
|
|
|
: mSVGElement(aSVGElement),
|
2011-10-17 14:59:28 +00:00
|
|
|
mHaveReceivedCommands(false)
|
2013-11-18 01:29:05 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DrawTarget> drawTarget =
|
2013-11-18 01:29:05 +00:00
|
|
|
gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget();
|
|
|
|
NS_ASSERTION(gfxPlatform::GetPlatform()->
|
|
|
|
SupportsAzureContentForDrawTarget(drawTarget),
|
|
|
|
"Should support Moz2D content drawing");
|
|
|
|
|
|
|
|
mPathBuilder = drawTarget->CreatePathBuilder();
|
|
|
|
}
|
2010-04-28 23:00:54 +00: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-29 06:19:26 +00:00
|
|
|
bool MoveToAbsolute(const nsAString& aCoordPairStr);
|
|
|
|
bool LineToAbsolute(const nsAString& aCoordPairStr,
|
2010-04-28 23:00:54 +00:00
|
|
|
double& aSegmentDistance);
|
2011-09-29 06:19:26 +00:00
|
|
|
bool LineToRelative(const nsAString& aCoordPairStr,
|
2010-04-28 23:00:54 +00:00
|
|
|
double& aSegmentDistance);
|
|
|
|
|
|
|
|
// Accessor to let clients check if we've received any commands yet.
|
2011-09-29 06:19:26 +00:00
|
|
|
inline bool HaveReceivedCommands() { return mHaveReceivedCommands; }
|
2010-04-28 23:00:54 +00:00
|
|
|
// Accessor to get the finalized path
|
2015-06-17 14:00:52 +00:00
|
|
|
already_AddRefed<Path> GetResultingPath();
|
2010-04-28 23:00:54 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// Helper methods
|
2011-09-29 06:19:26 +00:00
|
|
|
bool ParseCoordinatePair(const nsAString& aStr,
|
2010-04-28 23:00:54 +00:00
|
|
|
float& aXVal, float& aYVal);
|
|
|
|
|
|
|
|
// Member data
|
2010-12-04 12:26:45 +00:00
|
|
|
const nsSVGElement* mSVGElement; // context for converting to user units
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<PathBuilder> mPathBuilder;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mHaveReceivedCommands;
|
2010-04-28 23:00:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Class to assist in passing each subcomponent of a |values| attribute to
|
2013-11-18 01:29:06 +00:00
|
|
|
// a PathGenerator, for generating a corresponding Path.
|
2013-11-25 19:46:20 +00:00
|
|
|
class MOZ_STACK_CLASS MotionValueParser :
|
|
|
|
public nsSMILParserUtils::GenericValueParser
|
2010-04-28 23:00:54 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
MotionValueParser(PathGenerator* aPathGenerator,
|
2013-11-25 19:46:20 +00:00
|
|
|
FallibleTArray<double>* aPointDistances)
|
2010-04-28 23:00:54 +00:00
|
|
|
: mPathGenerator(aPathGenerator),
|
|
|
|
mPointDistances(aPointDistances),
|
|
|
|
mDistanceSoFar(0.0)
|
|
|
|
{
|
2015-02-09 22:34:50 +00:00
|
|
|
MOZ_ASSERT(mPointDistances->IsEmpty(),
|
|
|
|
"expecting point distances array to start empty");
|
2010-04-28 23:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsSMILParserUtils::GenericValueParser interface
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual bool Parse(const nsAString& aValueStr) override;
|
2010-04-28 23:00:54 +00:00
|
|
|
|
|
|
|
protected:
|
2013-11-25 19:46:20 +00:00
|
|
|
PathGenerator* mPathGenerator;
|
|
|
|
FallibleTArray<double>* mPointDistances;
|
|
|
|
double mDistanceSoFar;
|
2010-04-28 23:00:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // MOZILLA_SVGMOTIONSMILPATHUTILS_H_
|