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