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-02-03 17:42:24 +03:00
|
|
|
|
2020-07-15 02:40:05 +03:00
|
|
|
#ifndef DOM_SVG_SVGANIMATEDVIEWBOX_H_
|
|
|
|
#define DOM_SVG_SVGANIMATEDVIEWBOX_H_
|
2009-02-03 17:42:24 +03:00
|
|
|
|
2012-01-26 13:57:21 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsError.h"
|
2019-01-24 00:48:00 +03:00
|
|
|
#include "SVGAttrTearoffTable.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"
|
2019-01-06 20:52:55 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
|
|
|
#include "mozilla/dom/SVGAnimatedRect.h"
|
2012-01-26 13:57:21 +04:00
|
|
|
|
2013-03-19 07:18:45 +04:00
|
|
|
namespace mozilla {
|
2019-01-23 16:48:08 +03:00
|
|
|
|
|
|
|
class SMILValue;
|
|
|
|
|
2013-03-19 07:18:45 +04:00
|
|
|
namespace dom {
|
2019-06-20 17:03:54 +03:00
|
|
|
class SVGRect;
|
2013-03-19 07:18:45 +04:00
|
|
|
class SVGAnimationElement;
|
2019-01-06 20:52:55 +03:00
|
|
|
class SVGElement;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
2013-03-19 07:18:45 +04:00
|
|
|
|
2019-04-10 07:08:14 +03:00
|
|
|
struct SVGViewBox {
|
2009-02-03 17:42:24 +03:00
|
|
|
float x, y;
|
|
|
|
float width, height;
|
2013-02-26 20:58:06 +04:00
|
|
|
bool none;
|
2009-02-03 17:42:24 +03:00
|
|
|
|
2019-04-10 07:08:14 +03:00
|
|
|
SVGViewBox() : x(0.0), y(0.0), width(0.0), height(0.0), none(true) {}
|
|
|
|
SVGViewBox(float aX, float aY, float aWidth, float aHeight)
|
2013-02-26 20:58:06 +04:00
|
|
|
: x(aX), y(aY), width(aWidth), height(aHeight), none(false) {}
|
2019-04-10 07:08:14 +03:00
|
|
|
bool operator==(const SVGViewBox& aOther) const;
|
2017-04-10 19:02:34 +03:00
|
|
|
|
2019-04-10 07:08:14 +03:00
|
|
|
static nsresult FromString(const nsAString& aStr, SVGViewBox* aViewBox);
|
2009-02-03 17:42:24 +03:00
|
|
|
};
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
class SVGAnimatedViewBox {
|
2009-02-03 17:42:24 +03:00
|
|
|
public:
|
2018-12-21 11:58:14 +03:00
|
|
|
typedef mozilla::dom::SVGElement SVGElement;
|
|
|
|
|
2009-02-03 17:42:24 +03:00
|
|
|
void Init();
|
|
|
|
|
2012-05-03 20:05:40 +04:00
|
|
|
/**
|
|
|
|
* Returns true if the corresponding "viewBox" attribute defined a rectangle
|
2016-02-24 07:29:14 +03:00
|
|
|
* with finite values and nonnegative width/height.
|
|
|
|
* Returns false if the viewBox was set to an invalid
|
2012-05-03 20:05:40 +04:00
|
|
|
* string, or if any of the four rect values were too big to store in a
|
2016-02-24 07:29:14 +03:00
|
|
|
* float, or the width/height are negative.
|
2012-05-03 20:05:40 +04:00
|
|
|
*/
|
2016-05-03 17:40:26 +03:00
|
|
|
bool HasRect() const;
|
2013-02-26 20:58:06 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the corresponding "viewBox" attribute either defined a
|
|
|
|
* rectangle with finite values or the special "none" value.
|
|
|
|
*/
|
2012-05-03 20:05:40 +04:00
|
|
|
bool IsExplicitlySet() const {
|
2016-02-24 07:29:14 +03:00
|
|
|
if (mAnimVal || mHasBaseVal) {
|
2019-04-10 07:08:14 +03:00
|
|
|
const SVGViewBox& rect = GetAnimValue();
|
2016-02-24 07:29:14 +03:00
|
|
|
return rect.none || (rect.width >= 0 && rect.height >= 0);
|
|
|
|
}
|
|
|
|
return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2009-02-19 16:53:46 +03:00
|
|
|
|
2019-04-10 07:08:14 +03:00
|
|
|
const SVGViewBox& GetBaseValue() const { return mBaseVal; }
|
|
|
|
void SetBaseValue(const SVGViewBox& aRect, SVGElement* aSVGElement);
|
|
|
|
const SVGViewBox& GetAnimValue() const {
|
2010-02-25 21:20:43 +03:00
|
|
|
return mAnimVal ? *mAnimVal : mBaseVal;
|
|
|
|
}
|
2019-04-10 07:08:14 +03:00
|
|
|
void SetAnimValue(const SVGViewBox& aRect, SVGElement* aSVGElement);
|
2009-02-03 17:42:24 +03:00
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
nsresult SetBaseValueString(const nsAString& aValue, SVGElement* aSVGElement,
|
|
|
|
bool aDoSetAttr);
|
2009-02-03 17:42:24 +03:00
|
|
|
void GetBaseValueString(nsAString& aValue) const;
|
|
|
|
|
2013-05-20 15:46:12 +04:00
|
|
|
already_AddRefed<mozilla::dom::SVGAnimatedRect> ToSVGAnimatedRect(
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement* aSVGElement);
|
2013-05-20 15:46:12 +04:00
|
|
|
|
2019-06-20 17:03:54 +03:00
|
|
|
already_AddRefed<dom::SVGRect> ToDOMBaseVal(SVGElement* aSVGElement);
|
2013-05-20 15:46:12 +04:00
|
|
|
|
2019-06-20 17:03:54 +03:00
|
|
|
already_AddRefed<dom::SVGRect> ToDOMAnimVal(SVGElement* aSVGElement);
|
2013-05-20 15:46:12 +04:00
|
|
|
|
2019-01-25 06:24:01 +03:00
|
|
|
mozilla::UniquePtr<SMILAttr> ToSMILAttr(SVGElement* aSVGElement);
|
2012-08-25 21:06:10 +04:00
|
|
|
|
2009-02-03 17:42:24 +03:00
|
|
|
private:
|
2019-04-10 07:08:14 +03:00
|
|
|
SVGViewBox mBaseVal;
|
2020-02-25 23:03:26 +03:00
|
|
|
UniquePtr<SVGViewBox> mAnimVal;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mHasBaseVal;
|
2009-02-03 17:42:24 +03:00
|
|
|
|
2012-12-21 13:18:58 +04:00
|
|
|
public:
|
2019-01-25 06:24:01 +03:00
|
|
|
struct SMILViewBox : public SMILAttr {
|
2010-02-19 00:51:00 +03:00
|
|
|
public:
|
2019-04-04 20:40:56 +03:00
|
|
|
SMILViewBox(SVGAnimatedViewBox* aVal, SVGElement* aSVGElement)
|
2010-02-19 00:51:00 +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-19 00:51:00 +03:00
|
|
|
// as the Compositing step, and DOM elements don't get a chance to
|
|
|
|
// die during that.
|
2019-04-04 20:40:56 +03:00
|
|
|
SVGAnimatedViewBox* mVal;
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement* mSVGElement;
|
2010-02-19 00:51:00 +03:00
|
|
|
|
2019-01-25 06:24:01 +03:00
|
|
|
// SMILAttr methods
|
2010-02-19 00:51:00 +03:00
|
|
|
virtual nsresult ValueFromString(
|
|
|
|
const nsAString& aStr,
|
2019-01-23 16:48:08 +03:00
|
|
|
const mozilla::dom::SVGAnimationElement* aSrcElement, 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-19 00:51:00 +03:00
|
|
|
};
|
2013-05-09 21:42:12 +04:00
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
static SVGAttrTearoffTable<SVGAnimatedViewBox, mozilla::dom::SVGAnimatedRect>
|
2013-05-09 21:42:12 +04:00
|
|
|
sSVGAnimatedRectTearoffTable;
|
2009-02-03 17:42:24 +03:00
|
|
|
};
|
|
|
|
|
2019-01-06 20:52:55 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2020-07-15 02:40:05 +03:00
|
|
|
#endif // DOM_SVG_SVGANIMATEDVIEWBOX_H_
|