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/. */
|
2004-07-01 12:10:34 +04:00
|
|
|
|
2010-12-20 03:45:29 +03:00
|
|
|
#ifndef MOZILLA_SVGANIMATEDPRESERVEASPECTRATIO_H__
|
|
|
|
#define MOZILLA_SVGANIMATEDPRESERVEASPECTRATIO_H__
|
2004-07-01 12:10:34 +04:00
|
|
|
|
2012-01-26 13:57:21 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsISMILAttr.h"
|
2009-01-05 04:19:38 +03:00
|
|
|
#include "nsSVGElement.h"
|
2012-12-23 08:54:20 +04:00
|
|
|
#include "SVGPreserveAspectRatio.h"
|
2012-06-19 06:30:09 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2017-03-30 07:10:07 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2012-01-26 13:57:21 +04:00
|
|
|
|
|
|
|
class nsSMILValue;
|
2004-07-01 12:10:34 +04:00
|
|
|
|
2010-12-20 03:45:29 +03:00
|
|
|
namespace mozilla {
|
2013-01-06 13:32:01 +04:00
|
|
|
namespace dom {
|
|
|
|
class DOMSVGAnimatedPreserveAspectRatio;
|
2013-03-19 07:18:45 +04:00
|
|
|
class SVGAnimationElement;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
2009-01-05 04:19:38 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class SVGAnimatedPreserveAspectRatio final
|
2010-12-20 03:45:29 +03:00
|
|
|
{
|
|
|
|
public:
|
2009-01-05 04:19:38 +03:00
|
|
|
void Init() {
|
2012-12-23 08:54:21 +04:00
|
|
|
mBaseVal.mAlign = SVG_PRESERVEASPECTRATIO_XMIDYMID;
|
|
|
|
mBaseVal.mMeetOrSlice = SVG_MEETORSLICE_MEET;
|
2009-01-05 04:19:38 +03:00
|
|
|
mAnimVal = mBaseVal;
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsAnimated = false;
|
|
|
|
mIsBaseSet = false;
|
2009-01-05 04:19:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult SetBaseValueString(const nsAString& aValue,
|
2012-08-25 21:02:34 +04:00
|
|
|
nsSVGElement *aSVGElement,
|
|
|
|
bool aDoSetAttr);
|
2012-02-16 03:40:46 +04:00
|
|
|
void GetBaseValueString(nsAString& aValue) const;
|
2009-01-05 04:19:38 +03:00
|
|
|
|
2012-05-17 14:02:41 +04:00
|
|
|
void SetBaseValue(const SVGPreserveAspectRatio &aValue,
|
|
|
|
nsSVGElement *aSVGElement);
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult SetBaseAlign(uint16_t aAlign, nsSVGElement *aSVGElement) {
|
2013-01-10 18:37:30 +04:00
|
|
|
if (aAlign < SVG_ALIGN_MIN_VALID || aAlign > SVG_ALIGN_MAX_VALID) {
|
2012-05-17 14:02:41 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
SetBaseValue(SVGPreserveAspectRatio(
|
2016-07-01 03:28:56 +03:00
|
|
|
static_cast<SVGAlign>(aAlign), mBaseVal.GetMeetOrSlice()),
|
2012-05-17 14:02:41 +04:00
|
|
|
aSVGElement);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult SetBaseMeetOrSlice(uint16_t aMeetOrSlice, nsSVGElement *aSVGElement) {
|
2013-01-10 18:37:30 +04:00
|
|
|
if (aMeetOrSlice < SVG_MEETORSLICE_MIN_VALID ||
|
|
|
|
aMeetOrSlice > SVG_MEETORSLICE_MAX_VALID) {
|
2012-05-17 14:02:41 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
SetBaseValue(SVGPreserveAspectRatio(
|
2016-07-01 03:28:56 +03:00
|
|
|
mBaseVal.GetAlign(), static_cast<SVGMeetOrSlice>(aMeetOrSlice)),
|
2012-05-17 14:02:41 +04:00
|
|
|
aSVGElement);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
void SetAnimValue(uint64_t aPackedValue, nsSVGElement *aSVGElement);
|
2010-02-08 05:28:01 +03:00
|
|
|
|
2010-12-20 03:45:29 +03:00
|
|
|
const SVGPreserveAspectRatio &GetBaseValue() const
|
2009-01-05 04:19:38 +03:00
|
|
|
{ return mBaseVal; }
|
2010-12-20 03:45:29 +03:00
|
|
|
const SVGPreserveAspectRatio &GetAnimValue() const
|
2010-02-25 21:20:43 +03:00
|
|
|
{ return mAnimVal; }
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsAnimated() const
|
2010-12-20 03:45:29 +03:00
|
|
|
{ return mIsAnimated; }
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsExplicitlySet() const
|
2011-01-16 10:36:34 +03:00
|
|
|
{ return mIsAnimated || mIsBaseSet; }
|
2009-01-05 04:19:38 +03:00
|
|
|
|
2015-01-27 12:51:34 +03:00
|
|
|
already_AddRefed<mozilla::dom::DOMSVGAnimatedPreserveAspectRatio>
|
|
|
|
ToDOMAnimatedPreserveAspectRatio(nsSVGElement* aSVGElement);
|
2017-03-30 07:10:07 +03:00
|
|
|
UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement* aSVGElement);
|
2009-01-05 04:19:38 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2010-12-20 03:45:29 +03:00
|
|
|
SVGPreserveAspectRatio mAnimVal;
|
|
|
|
SVGPreserveAspectRatio mBaseVal;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsAnimated;
|
|
|
|
bool mIsBaseSet;
|
2009-01-05 04:19:38 +03:00
|
|
|
|
2010-01-12 16:08:43 +03:00
|
|
|
public:
|
2015-03-21 19:28:04 +03:00
|
|
|
struct SMILPreserveAspectRatio final : public nsISMILAttr
|
2010-02-08 05:28:01 +03:00
|
|
|
{
|
|
|
|
public:
|
2010-12-20 03:45:29 +03:00
|
|
|
SMILPreserveAspectRatio(SVGAnimatedPreserveAspectRatio* aVal,
|
|
|
|
nsSVGElement* aSVGElement)
|
2010-02-08 05:28:01 +03:00
|
|
|
: mVal(aVal), mSVGElement(aSVGElement) {}
|
|
|
|
|
|
|
|
// These will stay alive because a nsISMILAttr only lives as long
|
|
|
|
// as the Compositing step, and DOM elements don't get a chance to
|
|
|
|
// die during that.
|
2010-12-20 03:45:29 +03:00
|
|
|
SVGAnimatedPreserveAspectRatio* mVal;
|
2010-02-08 05:28:01 +03:00
|
|
|
nsSVGElement* mSVGElement;
|
|
|
|
|
|
|
|
// nsISMILAttr methods
|
|
|
|
virtual nsresult ValueFromString(const nsAString& aStr,
|
2013-03-19 07:18:45 +04:00
|
|
|
const dom::SVGAnimationElement* aSrcElement,
|
2010-02-21 00:13:11 +03:00
|
|
|
nsSMILValue& aValue,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool& aPreventCachingOfSandwich) const override;
|
|
|
|
virtual nsSMILValue GetBaseValue() const override;
|
|
|
|
virtual void ClearAnimValue() override;
|
|
|
|
virtual nsresult SetAnimValue(const nsSMILValue& aValue) override;
|
2010-02-08 05:28:01 +03:00
|
|
|
};
|
2009-01-05 04:19:38 +03:00
|
|
|
};
|
2004-07-01 12:10:34 +04:00
|
|
|
|
2012-12-23 08:54:20 +04:00
|
|
|
namespace dom {
|
2015-03-21 19:28:04 +03:00
|
|
|
class DOMSVGAnimatedPreserveAspectRatio final : public nsISupports,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsWrapperCache
|
2012-12-23 08:54:20 +04:00
|
|
|
{
|
2014-06-24 20:36:45 +04:00
|
|
|
~DOMSVGAnimatedPreserveAspectRatio();
|
|
|
|
|
2012-12-23 08:54:20 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMSVGAnimatedPreserveAspectRatio)
|
|
|
|
|
|
|
|
DOMSVGAnimatedPreserveAspectRatio(SVGAnimatedPreserveAspectRatio* aVal,
|
|
|
|
nsSVGElement *aSVGElement)
|
|
|
|
: mVal(aVal), mSVGElement(aSVGElement)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// WebIDL
|
|
|
|
nsSVGElement* GetParentObject() const { return mSVGElement; }
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2012-12-23 08:54:20 +04:00
|
|
|
|
|
|
|
// These aren't weak refs because new objects are returned each time
|
|
|
|
already_AddRefed<DOMSVGPreserveAspectRatio> BaseVal();
|
|
|
|
already_AddRefed<DOMSVGPreserveAspectRatio> AnimVal();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// kept alive because it belongs to content:
|
|
|
|
SVGAnimatedPreserveAspectRatio* mVal;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsSVGElement> mSVGElement;
|
2012-12-23 08:54:20 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
2010-12-20 03:45:29 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2010-12-20 03:45:29 +03:00
|
|
|
#endif // MOZILLA_SVGANIMATEDPRESERVEASPECTRATIO_H__
|