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/. */
|
2004-10-14 23:02:53 +00:00
|
|
|
|
|
|
|
#ifndef __NS_SVGENUM_H__
|
|
|
|
#define __NS_SVGENUM_H__
|
|
|
|
|
2012-01-26 09:57:21 +00:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsError.h"
|
2012-06-19 02:30:09 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2019-01-25 03:24:01 +00:00
|
|
|
#include "mozilla/SMILAttr.h"
|
2019-01-02 18:44:12 +00:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2019-01-02 18:24:11 +00:00
|
|
|
#include "mozilla/dom/SVGAnimatedEnumeration.h"
|
|
|
|
#include "mozilla/dom/SVGElement.h"
|
2012-01-26 09:57:21 +00:00
|
|
|
|
2017-10-02 22:05:19 +00:00
|
|
|
class nsAtom;
|
2007-08-27 23:11:14 +00:00
|
|
|
|
2013-03-19 03:18:45 +00:00
|
|
|
namespace mozilla {
|
2019-01-23 13:48:08 +00:00
|
|
|
|
|
|
|
class SMILValue;
|
|
|
|
|
2013-03-19 03:18:45 +00:00
|
|
|
namespace dom {
|
|
|
|
class SVGAnimationElement;
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace dom
|
2013-03-19 03:18:45 +00:00
|
|
|
|
2019-01-02 18:24:11 +00:00
|
|
|
typedef uint8_t SVGEnumValue;
|
2004-10-14 23:02:53 +00:00
|
|
|
|
2019-01-02 18:24:11 +00:00
|
|
|
struct SVGEnumMapping {
|
2018-03-29 09:45:28 +00:00
|
|
|
nsStaticAtom* const mKey;
|
2019-01-02 18:24:11 +00:00
|
|
|
const SVGEnumValue mVal;
|
2004-10-14 23:02:53 +00:00
|
|
|
};
|
|
|
|
|
2019-01-02 18:24:11 +00:00
|
|
|
class SVGEnum {
|
2007-08-27 23:11:14 +00:00
|
|
|
public:
|
2018-12-21 08:58:14 +00:00
|
|
|
typedef mozilla::dom::SVGElement SVGElement;
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
void Init(uint8_t aAttrEnum, uint16_t aValue) {
|
|
|
|
mAnimVal = mBaseVal = uint8_t(aValue);
|
2007-08-27 23:11:14 +00:00
|
|
|
mAttrEnum = aAttrEnum;
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsAnimated = false;
|
|
|
|
mIsBaseSet = false;
|
2007-08-27 23:11:14 +00:00
|
|
|
}
|
|
|
|
|
2018-12-21 08:58:14 +00:00
|
|
|
nsresult SetBaseValueAtom(const nsAtom* aValue, SVGElement* aSVGElement);
|
|
|
|
nsAtom* GetBaseValueAtom(SVGElement* aSVGElement);
|
|
|
|
nsresult SetBaseValue(uint16_t aValue, SVGElement* aSVGElement);
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t GetBaseValue() const { return mBaseVal; }
|
2010-01-23 18:59:03 +00:00
|
|
|
|
2018-12-21 08:58:14 +00:00
|
|
|
void SetAnimValue(uint16_t aValue, SVGElement* aSVGElement);
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t GetAnimValue() const { return mAnimVal; }
|
2011-01-16 07:36:34 +00:00
|
|
|
bool IsExplicitlySet() const { return mIsAnimated || mIsBaseSet; }
|
2007-08-27 23:11:14 +00:00
|
|
|
|
2013-07-01 07:02:46 +00:00
|
|
|
already_AddRefed<mozilla::dom::SVGAnimatedEnumeration> ToDOMAnimatedEnum(
|
2018-12-21 08:58:14 +00:00
|
|
|
SVGElement* aSVGElement);
|
2013-01-06 14:14:43 +00:00
|
|
|
|
2019-01-25 03:24:01 +00:00
|
|
|
mozilla::UniquePtr<SMILAttr> ToSMILAttr(SVGElement* aSVGElement);
|
2004-10-14 23:02:53 +00:00
|
|
|
|
2007-08-27 23:11:14 +00:00
|
|
|
private:
|
2019-01-02 18:24:11 +00:00
|
|
|
SVGEnumValue mAnimVal;
|
|
|
|
SVGEnumValue mBaseVal;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint8_t mAttrEnum; // element specified tracking for attribute
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mIsAnimated;
|
|
|
|
bool mIsBaseSet;
|
2004-10-14 23:02:53 +00:00
|
|
|
|
2019-01-02 18:24:11 +00:00
|
|
|
const SVGEnumMapping* GetMapping(SVGElement* aSVGElement);
|
2004-10-14 23:02:53 +00:00
|
|
|
|
2010-01-12 13:08:43 +00:00
|
|
|
public:
|
2015-03-21 16:28:04 +00:00
|
|
|
struct DOMAnimatedEnum final : public mozilla::dom::SVGAnimatedEnumeration {
|
2019-01-02 18:24:11 +00:00
|
|
|
DOMAnimatedEnum(SVGEnum* aVal, SVGElement* aSVGElement)
|
2013-07-01 07:02:46 +00:00
|
|
|
: mozilla::dom::SVGAnimatedEnumeration(aSVGElement), mVal(aVal) {}
|
2012-12-21 09:18:58 +00:00
|
|
|
virtual ~DOMAnimatedEnum();
|
2007-08-27 23:11:14 +00:00
|
|
|
|
2019-01-02 18:24:11 +00:00
|
|
|
SVGEnum* mVal; // kept alive because it belongs to content
|
2010-02-25 18:20:43 +00:00
|
|
|
|
2013-07-01 07:02:46 +00:00
|
|
|
using mozilla::dom::SVGAnimatedEnumeration::SetBaseVal;
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual uint16_t BaseVal() override { return mVal->GetBaseValue(); }
|
2013-07-01 07:02:46 +00:00
|
|
|
virtual void SetBaseVal(uint16_t aBaseVal,
|
2015-03-21 16:28:04 +00:00
|
|
|
mozilla::ErrorResult& aRv) override {
|
2013-07-01 07:02:46 +00:00
|
|
|
aRv = mVal->SetBaseValue(aBaseVal, mSVGElement);
|
|
|
|
}
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual uint16_t AnimVal() override {
|
2013-07-01 07:02:46 +00:00
|
|
|
// Script may have modified animation parameters or timeline -- DOM
|
|
|
|
// getters need to flush any resample requests to reflect these
|
|
|
|
// modifications.
|
2010-02-25 18:20:43 +00:00
|
|
|
mSVGElement->FlushAnimations();
|
2013-07-01 07:02:46 +00:00
|
|
|
return mVal->GetAnimValue();
|
2010-02-25 18:20:43 +00:00
|
|
|
}
|
2007-08-27 23:11:14 +00:00
|
|
|
};
|
2010-01-23 18:59:03 +00:00
|
|
|
|
2019-01-25 03:24:01 +00:00
|
|
|
struct SMILEnum : public SMILAttr {
|
2010-01-23 18:59:03 +00:00
|
|
|
public:
|
2019-01-02 18:24:11 +00:00
|
|
|
SMILEnum(SVGEnum* aVal, SVGElement* aSVGElement)
|
2010-01-23 18:59:03 +00:00
|
|
|
: mVal(aVal), mSVGElement(aSVGElement) {}
|
|
|
|
|
2019-01-25 03:24:01 +00:00
|
|
|
// These will stay alive because a SMILAttr only lives as long
|
2010-01-23 18:59:03 +00:00
|
|
|
// as the Compositing step, and DOM elements don't get a chance to
|
|
|
|
// die during that.
|
2019-01-02 18:24:11 +00:00
|
|
|
SVGEnum* mVal;
|
2018-12-21 08:58:14 +00:00
|
|
|
SVGElement* mSVGElement;
|
2010-01-23 18:59:03 +00:00
|
|
|
|
2019-01-25 03:24:01 +00:00
|
|
|
// SMILAttr methods
|
2010-01-23 18:59:03 +00:00
|
|
|
virtual nsresult ValueFromString(
|
|
|
|
const nsAString& aStr,
|
2019-01-23 13:48:08 +00:00
|
|
|
const mozilla::dom::SVGAnimationElement* aSrcElement, SMILValue& aValue,
|
|
|
|
bool& aPreventCachingOfSandwich) const override;
|
|
|
|
virtual SMILValue GetBaseValue() const override;
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void ClearAnimValue() override;
|
2019-01-23 13:48:08 +00:00
|
|
|
virtual nsresult SetAnimValue(const SMILValue& aValue) override;
|
2010-01-23 18:59:03 +00:00
|
|
|
};
|
2007-08-27 23:11:14 +00:00
|
|
|
};
|
2004-10-14 23:02:53 +00:00
|
|
|
|
2019-01-02 18:24:11 +00:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2008-01-09 09:52:14 +00:00
|
|
|
#endif //__NS_SVGENUM_H__
|