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. */
|
|
|
|
|
2020-07-15 02:40:05 +03:00
|
|
|
#ifndef DOM_SVG_SVGMOTIONSMILPATHUTILS_H_
|
|
|
|
#define DOM_SVG_SVGMOTIONSMILPATHUTILS_H_
|
2010-04-29 03:00:54 +04:00
|
|
|
|
2013-05-30 00:43:41 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2015-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2019-01-08 10:55:14 +03:00
|
|
|
#include "mozilla/SMILParserUtils.h"
|
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
#include "gfxPlatform.h"
|
2012-01-26 13:57:21 +04:00
|
|
|
#include "nsDebug.h"
|
2017-08-17 02:48:52 +03:00
|
|
|
#include "nsStringFwd.h"
|
2012-01-26 13:57:21 +04:00
|
|
|
#include "nsTArray.h"
|
2010-04-29 03:00:54 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
namespace dom {
|
|
|
|
class SVGElement;
|
|
|
|
}
|
|
|
|
|
2013-11-18 05:29:05 +04:00
|
|
|
class SVGMotionSMILPathUtils {
|
2020-07-15 13:37:55 +03:00
|
|
|
using DrawTarget = mozilla::gfx::DrawTarget;
|
|
|
|
using Path = mozilla::gfx::Path;
|
|
|
|
using PathBuilder = mozilla::gfx::PathBuilder;
|
2013-11-18 05:29:05 +04:00
|
|
|
|
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:
|
2018-12-21 11:58:14 +03:00
|
|
|
explicit PathGenerator(const dom::SVGElement* aSVGElement)
|
2011-10-17 18:59:28 +04:00
|
|
|
: mSVGElement(aSVGElement), mHaveReceivedCommands(false) {
|
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");
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2013-11-18 05:29:05 +04:00
|
|
|
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
|
2019-04-27 10:57:50 +03:00
|
|
|
bool ParseCoordinatePair(const nsAString& aCoordPairStr, float& aXVal,
|
|
|
|
float& aYVal);
|
2010-04-29 03:00:54 +04:00
|
|
|
|
|
|
|
// Member data
|
2018-12-21 11:58:14 +03:00
|
|
|
const dom::SVGElement* 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
|
2019-01-08 10:55:14 +03:00
|
|
|
: public SMILParserUtils::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
|
|
|
}
|
|
|
|
|
2019-01-08 10:55:14 +03:00
|
|
|
// SMILParserUtils::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
|
|
|
|
|
2020-07-15 02:40:05 +03:00
|
|
|
#endif // DOM_SVG_SVGMOTIONSMILPATHUTILS_H_
|