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/. */
|
2009-10-03 01:37:25 +04:00
|
|
|
|
|
|
|
/* representation of a value for a SMIL-animated CSS property */
|
|
|
|
|
2019-01-25 11:16:09 +03:00
|
|
|
#ifndef mozilla_SMILCSSValueType_h
|
|
|
|
#define mozilla_SMILCSSValueType_h
|
2009-10-03 01:37:25 +04:00
|
|
|
|
2019-01-09 03:34:14 +03:00
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/SMILType.h"
|
2016-08-17 04:37:48 +03:00
|
|
|
#include "nsCSSPropertyID.h"
|
2017-08-17 02:48:52 +03:00
|
|
|
#include "nsStringFwd.h"
|
2009-10-03 01:37:25 +04:00
|
|
|
|
2011-03-28 20:49:11 +04:00
|
|
|
namespace mozilla {
|
2017-04-26 07:00:12 +03:00
|
|
|
struct AnimationValue;
|
2018-05-03 19:27:44 +03:00
|
|
|
class DeclarationBlock;
|
2011-03-28 20:49:11 +04:00
|
|
|
namespace dom {
|
|
|
|
class Element;
|
|
|
|
} // namespace dom
|
|
|
|
|
2009-10-03 01:37:25 +04:00
|
|
|
/*
|
2018-12-27 20:02:38 +03:00
|
|
|
* SMILCSSValueType: Represents a SMIL-animated CSS value.
|
2009-10-03 01:37:25 +04:00
|
|
|
*/
|
2018-12-28 13:34:35 +03:00
|
|
|
class SMILCSSValueType : public SMILType {
|
2009-10-03 01:37:25 +04:00
|
|
|
public:
|
2019-01-23 16:48:08 +03:00
|
|
|
// Singleton for SMILValue objects to hold onto.
|
2018-12-27 20:02:38 +03:00
|
|
|
static SMILCSSValueType sSingleton;
|
2010-02-02 05:46:13 +03:00
|
|
|
|
|
|
|
protected:
|
2018-12-28 13:34:35 +03:00
|
|
|
// SMILType Methods
|
2010-02-02 05:46:13 +03:00
|
|
|
// -------------------
|
2019-01-23 16:48:08 +03:00
|
|
|
void Init(SMILValue& aValue) const override;
|
|
|
|
void Destroy(SMILValue&) const override;
|
|
|
|
nsresult Assign(SMILValue& aDest, const SMILValue& aSrc) const override;
|
|
|
|
bool IsEqual(const SMILValue& aLeft, const SMILValue& aRight) const override;
|
|
|
|
nsresult Add(SMILValue& aDest, const SMILValue& aValueToAdd,
|
2017-06-02 09:14:52 +03:00
|
|
|
uint32_t aCount) const override;
|
2019-01-23 16:48:08 +03:00
|
|
|
nsresult SandwichAdd(SMILValue& aDest,
|
|
|
|
const SMILValue& aValueToAdd) const override;
|
|
|
|
nsresult ComputeDistance(const SMILValue& aFrom, const SMILValue& aTo,
|
2017-06-02 09:14:52 +03:00
|
|
|
double& aDistance) const override;
|
2019-01-23 16:48:08 +03:00
|
|
|
nsresult Interpolate(const SMILValue& aStartVal, const SMILValue& aEndVal,
|
|
|
|
double aUnitDistance, SMILValue& aResult) const override;
|
2009-10-03 01:37:25 +04:00
|
|
|
|
2010-02-02 05:46:13 +03:00
|
|
|
public:
|
|
|
|
// Helper Methods
|
|
|
|
// --------------
|
2009-12-10 20:26:28 +03:00
|
|
|
/**
|
2019-01-23 16:48:08 +03:00
|
|
|
* Sets up the given SMILValue to represent the given string value. The
|
2009-12-10 20:26:28 +03:00
|
|
|
* string is interpreted as a value for the given property on the given
|
|
|
|
* element.
|
|
|
|
*
|
2018-12-27 13:21:40 +03:00
|
|
|
* On failure, this method leaves aValue.mType == SMILNullType::sSingleton.
|
2010-02-02 05:46:13 +03:00
|
|
|
* Otherwise, this method leaves aValue.mType == this class's singleton.
|
2009-12-10 20:26:28 +03:00
|
|
|
*
|
|
|
|
* @param aPropID The property for which we're parsing a value.
|
|
|
|
* @param aTargetElement The target element to whom the property/value
|
|
|
|
* setting applies.
|
|
|
|
* @param aString The string to be parsed as a CSS value.
|
2019-01-23 16:48:08 +03:00
|
|
|
* @param [out] aValue The SMILValue to be populated. Should
|
2010-02-02 05:46:13 +03:00
|
|
|
* initially be null-typed.
|
2011-10-17 18:59:28 +04:00
|
|
|
* @param [out] aIsContextSensitive Set to true if |aString| may produce
|
2011-08-23 03:34:03 +04:00
|
|
|
* a different |aValue| depending on other
|
|
|
|
* CSS properties on |aTargetElement|
|
|
|
|
* or its ancestors (e.g. 'inherit).
|
2012-07-30 18:20:58 +04:00
|
|
|
* false otherwise. May be nullptr.
|
2011-08-23 03:34:03 +04:00
|
|
|
* Not set if the method fails.
|
2010-02-02 05:46:13 +03:00
|
|
|
* @pre aValue.IsNull()
|
2018-12-27 20:02:38 +03:00
|
|
|
* @post aValue.IsNull() || aValue.mType == SMILCSSValueType::sSingleton
|
2009-12-10 20:26:28 +03:00
|
|
|
*/
|
2019-01-25 06:24:01 +03:00
|
|
|
static void ValueFromString(nsCSSPropertyID aPropID,
|
|
|
|
dom::Element* aTargetElement,
|
2019-01-23 16:48:08 +03:00
|
|
|
const nsAString& aString, SMILValue& aValue,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool* aIsContextSensitive);
|
2009-10-03 01:37:25 +04:00
|
|
|
|
2017-03-30 10:53:15 +03:00
|
|
|
/**
|
2019-01-23 16:48:08 +03:00
|
|
|
* Creates a SMILValue to wrap the given animation value.
|
2017-03-30 10:53:15 +03:00
|
|
|
*
|
|
|
|
* @param aPropID The property that |aValue| corresponds to.
|
|
|
|
* @param aTargetElement The target element to which the animation value
|
|
|
|
* applies.
|
|
|
|
* @param aValue The animation value to use.
|
2019-01-23 16:48:08 +03:00
|
|
|
* @return A new SMILValue. On failure, returns a
|
|
|
|
* SMILValue with the null type (i.e. rv.IsNull()
|
2017-03-30 10:53:15 +03:00
|
|
|
* returns true).
|
|
|
|
*/
|
2019-01-23 16:48:08 +03:00
|
|
|
static SMILValue ValueFromAnimationValue(nsCSSPropertyID aPropID,
|
2019-01-25 06:24:01 +03:00
|
|
|
dom::Element* aTargetElement,
|
2019-01-23 16:48:08 +03:00
|
|
|
const AnimationValue& aValue);
|
2017-03-30 10:53:15 +03:00
|
|
|
|
2018-05-03 19:27:44 +03:00
|
|
|
/**
|
|
|
|
* Sets the relevant property values in the declaration block.
|
|
|
|
*
|
|
|
|
* Returns whether the declaration changed.
|
|
|
|
*/
|
2019-01-23 16:48:08 +03:00
|
|
|
static bool SetPropertyValues(const SMILValue&, mozilla::DeclarationBlock&);
|
2018-05-03 19:27:44 +03:00
|
|
|
|
2016-04-20 03:05:29 +03:00
|
|
|
/**
|
|
|
|
* Return the CSS property animated by the specified value.
|
|
|
|
*
|
2019-01-23 16:48:08 +03:00
|
|
|
* @param aValue The SMILValue to examine.
|
2016-08-17 04:37:48 +03:00
|
|
|
* @return The nsCSSPropertyID enum value of the property animated
|
2016-04-20 03:05:29 +03:00
|
|
|
* by |aValue|, or eCSSProperty_UNKNOWN if the type of
|
2018-12-27 20:02:38 +03:00
|
|
|
* |aValue| is not SMILCSSValueType.
|
2016-04-20 03:05:29 +03:00
|
|
|
*/
|
2019-01-23 16:48:08 +03:00
|
|
|
static nsCSSPropertyID PropertyFromValue(const SMILValue& aValue);
|
2016-04-20 03:05:29 +03:00
|
|
|
|
2017-10-04 09:04:23 +03:00
|
|
|
/**
|
|
|
|
* If |aValue| is an empty value, converts it to a suitable zero value by
|
|
|
|
* matching the type of value stored in |aValueToMatch|.
|
|
|
|
*
|
|
|
|
* There is no indication if this method fails. If a suitable zero value could
|
|
|
|
* not be created, |aValue| is simply unmodified.
|
|
|
|
*
|
2019-01-23 16:48:08 +03:00
|
|
|
* @param aValue The SMILValue (of type SMILCSSValueType) to
|
2017-10-04 09:04:23 +03:00
|
|
|
* possibly update.
|
2019-01-23 16:48:08 +03:00
|
|
|
* @param aValueToMatch A SMILValue (of type SMILCSSValueType) for which
|
2017-10-04 09:04:23 +03:00
|
|
|
* a corresponding zero value will be created if |aValue|
|
|
|
|
* is empty.
|
|
|
|
*/
|
2019-01-23 16:48:08 +03:00
|
|
|
static void FinalizeValue(SMILValue& aValue, const SMILValue& aValueToMatch);
|
2017-10-04 09:04:23 +03:00
|
|
|
|
2009-10-03 01:37:25 +04:00
|
|
|
private:
|
2013-08-12 18:13:34 +04:00
|
|
|
// Private constructor: prevent instances beyond my singleton.
|
2018-12-27 20:02:38 +03:00
|
|
|
constexpr SMILCSSValueType() {}
|
2009-10-03 01:37:25 +04:00
|
|
|
};
|
|
|
|
|
2018-12-27 20:02:38 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2019-01-25 11:16:09 +03:00
|
|
|
#endif // mozilla_SMILCSSValueType_h
|