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"
|
2012-12-23 08:54:20 +04:00
|
|
|
#include "SVGPreserveAspectRatio.h"
|
2012-06-19 06:30:09 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2019-01-25 06:24:01 +03:00
|
|
|
#include "mozilla/SMILAttr.h"
|
2017-03-30 07:10:07 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2019-01-25 06:24:01 +03:00
|
|
|
#include "mozilla/dom/SVGElement.h"
|
2012-01-26 13:57:21 +04:00
|
|
|
|
2010-12-20 03:45:29 +03:00
|
|
|
namespace mozilla {
|
2019-01-23 16:48:08 +03:00
|
|
|
|
|
|
|
class SMILValue;
|
|
|
|
|
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() {
|
2018-02-18 18:53:13 +03:00
|
|
|
mBaseVal.mAlign =
|
2018-06-26 00:20:54 +03:00
|
|
|
dom::SVGPreserveAspectRatio_Binding::SVG_PRESERVEASPECTRATIO_XMIDYMID;
|
2018-02-18 18:53:13 +03:00
|
|
|
mBaseVal.mMeetOrSlice =
|
2018-06-26 00:20:54 +03:00
|
|
|
dom::SVGPreserveAspectRatio_Binding::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,
|
2018-12-21 11:58:14 +03:00
|
|
|
dom::SVGElement* 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,
|
2018-12-21 11:58:14 +03:00
|
|
|
dom::SVGElement* aSVGElement);
|
|
|
|
nsresult SetBaseAlign(uint16_t aAlign, dom::SVGElement* 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;
|
|
|
|
}
|
2019-04-02 20:00:45 +03:00
|
|
|
SetBaseValue(SVGPreserveAspectRatio(static_cast<uint8_t>(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,
|
2018-12-21 11:58:14 +03:00
|
|
|
dom::SVGElement* 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;
|
|
|
|
}
|
2019-04-02 20:00:45 +03:00
|
|
|
SetBaseValue(SVGPreserveAspectRatio(mBaseVal.GetAlign(),
|
|
|
|
static_cast<uint8_t>(aMeetOrSlice)),
|
2012-05-17 14:02:41 +04:00
|
|
|
aSVGElement);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2018-12-21 11:58:14 +03:00
|
|
|
void SetAnimValue(uint64_t aPackedValue, dom::SVGElement* aSVGElement);
|
2010-02-08 05:28:01 +03:00
|
|
|
|
2010-12-20 03:45:29 +03:00
|
|
|
const SVGPreserveAspectRatio& GetBaseValue() const { return mBaseVal; }
|
|
|
|
const SVGPreserveAspectRatio& GetAnimValue() const { return mAnimVal; }
|
2010-12-20 03:45:29 +03:00
|
|
|
bool IsAnimated() const { return mIsAnimated; }
|
2011-01-16 10:36:34 +03:00
|
|
|
bool IsExplicitlySet() const { return mIsAnimated || mIsBaseSet; }
|
2009-01-05 04:19:38 +03:00
|
|
|
|
2015-01-27 12:51:34 +03:00
|
|
|
already_AddRefed<mozilla::dom::DOMSVGAnimatedPreserveAspectRatio>
|
2018-12-21 11:58:14 +03:00
|
|
|
ToDOMAnimatedPreserveAspectRatio(dom::SVGElement* aSVGElement);
|
2019-01-25 06:24:01 +03:00
|
|
|
UniquePtr<SMILAttr> ToSMILAttr(dom::SVGElement* 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:
|
2019-01-25 06:24:01 +03:00
|
|
|
struct SMILPreserveAspectRatio final : public SMILAttr {
|
2010-02-08 05:28:01 +03:00
|
|
|
public:
|
2010-12-20 03:45:29 +03:00
|
|
|
SMILPreserveAspectRatio(SVGAnimatedPreserveAspectRatio* aVal,
|
2018-12-21 11:58:14 +03:00
|
|
|
dom::SVGElement* aSVGElement)
|
2010-02-08 05:28:01 +03:00
|
|
|
: mVal(aVal), mSVGElement(aSVGElement) {}
|
|
|
|
|
2019-01-25 06:24:01 +03:00
|
|
|
// These will stay alive because a SMILAttr only lives as long
|
2010-02-08 05:28:01 +03:00
|
|
|
// 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;
|
2018-12-21 11:58:14 +03:00
|
|
|
dom::SVGElement* mSVGElement;
|
2010-02-08 05:28:01 +03:00
|
|
|
|
2019-01-25 06:24:01 +03:00
|
|
|
// SMILAttr methods
|
2010-02-08 05:28:01 +03:00
|
|
|
virtual nsresult ValueFromString(
|
2013-03-19 07:18:45 +04:00
|
|
|
const nsAString& aStr, const dom::SVGAnimationElement* aSrcElement,
|
2019-01-23 16:48:08 +03:00
|
|
|
SMILValue& aValue, bool& aPreventCachingOfSandwich) const override;
|
|
|
|
virtual SMILValue GetBaseValue() const override;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void ClearAnimValue() override;
|
2019-01-23 16:48:08 +03:00
|
|
|
virtual nsresult SetAnimValue(const SMILValue& 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 {
|
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,
|
2018-12-21 11:58:14 +03:00
|
|
|
dom::SVGElement* aSVGElement)
|
2012-12-23 08:54:20 +04:00
|
|
|
: mVal(aVal), mSVGElement(aSVGElement) {}
|
|
|
|
|
|
|
|
// WebIDL
|
2018-12-21 11:58:14 +03:00
|
|
|
dom::SVGElement* 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;
|
2018-12-21 11:58:14 +03:00
|
|
|
RefPtr<dom::SVGElement> 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__
|