2009-02-03 06:42:24 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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 06:42:24 -08:00
|
|
|
|
|
|
|
#ifndef __NS_SVGVIEWBOX_H__
|
|
|
|
#define __NS_SVGVIEWBOX_H__
|
|
|
|
|
2012-01-26 01:57:21 -08:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsError.h"
|
2013-05-09 10:42:12 -07:00
|
|
|
#include "mozilla/dom/SVGAnimatedRect.h"
|
2013-03-26 08:53:13 -07:00
|
|
|
#include "mozilla/dom/SVGIRect.h"
|
2012-01-26 01:57:21 -08:00
|
|
|
#include "nsISMILAttr.h"
|
2009-02-03 06:42:24 -08:00
|
|
|
#include "nsSVGElement.h"
|
2012-06-18 19:30:09 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-05-09 10:42:12 -07:00
|
|
|
#include "nsSVGAttrTearoffTable.h"
|
2012-01-26 01:57:21 -08:00
|
|
|
|
|
|
|
class nsSMILValue;
|
2009-02-03 06:42:24 -08:00
|
|
|
|
2013-03-18 20:18:45 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class SVGAnimationElement;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-03 06:42:24 -08:00
|
|
|
struct nsSVGViewBoxRect
|
|
|
|
{
|
|
|
|
float x, y;
|
|
|
|
float width, height;
|
2013-02-26 08:58:06 -08:00
|
|
|
bool none;
|
2009-02-03 06:42:24 -08:00
|
|
|
|
2013-02-26 08:58:06 -08:00
|
|
|
nsSVGViewBoxRect() : none(true) {}
|
2009-02-03 06:42:24 -08:00
|
|
|
nsSVGViewBoxRect(float aX, float aY, float aWidth, float aHeight) :
|
2013-02-26 08:58:06 -08:00
|
|
|
x(aX), y(aY), width(aWidth), height(aHeight), none(false) {}
|
2010-02-18 13:51:00 -08:00
|
|
|
nsSVGViewBoxRect(const nsSVGViewBoxRect& rhs) :
|
2013-02-26 08:58:06 -08:00
|
|
|
x(rhs.x), y(rhs.y), width(rhs.width), height(rhs.height), none(rhs.none) {}
|
2011-09-28 23:19:26 -07:00
|
|
|
bool operator==(const nsSVGViewBoxRect& aOther) const;
|
2009-02-03 06:42:24 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
class nsSVGViewBox
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
void Init();
|
|
|
|
|
2012-05-03 09:05:40 -07:00
|
|
|
/**
|
|
|
|
* Returns true if the corresponding "viewBox" attribute defined a rectangle
|
|
|
|
* with finite values. Returns false if the viewBox was set to an invalid
|
|
|
|
* string, or if any of the four rect values were too big to store in a
|
|
|
|
* float.
|
|
|
|
*
|
|
|
|
* This method does not check whether the width or height values are
|
|
|
|
* positive, so callers must check whether the viewBox rect is valid where
|
|
|
|
* necessary!
|
|
|
|
*/
|
2013-02-26 08:58:06 -08:00
|
|
|
bool HasRect() const
|
|
|
|
{ return (mAnimVal && !mAnimVal->none) ||
|
|
|
|
(!mAnimVal && mHasBaseVal && !mBaseVal.none); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the corresponding "viewBox" attribute either defined a
|
|
|
|
* rectangle with finite values or the special "none" value.
|
|
|
|
*/
|
2012-05-03 09:05:40 -07:00
|
|
|
bool IsExplicitlySet() const
|
2013-02-26 08:58:06 -08:00
|
|
|
{ return mAnimVal || mHasBaseVal; }
|
2009-02-19 05:53:46 -08:00
|
|
|
|
2009-02-03 06:42:24 -08:00
|
|
|
const nsSVGViewBoxRect& GetBaseValue() const
|
|
|
|
{ return mBaseVal; }
|
2012-05-17 03:02:41 -07:00
|
|
|
void SetBaseValue(const nsSVGViewBoxRect& aRect,
|
2011-10-09 08:25:07 -07:00
|
|
|
nsSVGElement *aSVGElement);
|
2010-02-25 10:20:43 -08:00
|
|
|
const nsSVGViewBoxRect& GetAnimValue() const
|
|
|
|
{ return mAnimVal ? *mAnimVal : mBaseVal; }
|
2013-02-26 08:58:06 -08:00
|
|
|
void SetAnimValue(const nsSVGViewBoxRect& aRect,
|
2010-02-18 13:51:00 -08:00
|
|
|
nsSVGElement *aSVGElement);
|
2009-02-03 06:42:24 -08:00
|
|
|
|
|
|
|
nsresult SetBaseValueString(const nsAString& aValue,
|
2012-08-25 10:02:34 -07:00
|
|
|
nsSVGElement *aSVGElement,
|
|
|
|
bool aDoSetAttr);
|
2009-02-03 06:42:24 -08:00
|
|
|
void GetBaseValueString(nsAString& aValue) const;
|
|
|
|
|
2013-05-20 04:46:12 -07:00
|
|
|
already_AddRefed<mozilla::dom::SVGAnimatedRect>
|
|
|
|
ToSVGAnimatedRect(nsSVGElement *aSVGElement);
|
|
|
|
|
|
|
|
already_AddRefed<mozilla::dom::SVGIRect>
|
|
|
|
ToDOMBaseVal(nsSVGElement* aSVGElement);
|
|
|
|
|
|
|
|
already_AddRefed<mozilla::dom::SVGIRect>
|
|
|
|
ToDOMAnimVal(nsSVGElement* aSVGElement);
|
|
|
|
|
2010-02-18 13:51:00 -08:00
|
|
|
// Returns a new nsISMILAttr object that the caller must delete
|
|
|
|
nsISMILAttr* ToSMILAttr(nsSVGElement* aSVGElement);
|
2012-08-25 10:06:10 -07:00
|
|
|
|
2009-02-03 06:42:24 -08:00
|
|
|
private:
|
|
|
|
|
|
|
|
nsSVGViewBoxRect mBaseVal;
|
|
|
|
nsAutoPtr<nsSVGViewBoxRect> mAnimVal;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mHasBaseVal;
|
2009-02-03 06:42:24 -08:00
|
|
|
|
2012-12-21 01:18:58 -08:00
|
|
|
public:
|
2013-03-26 08:53:13 -07:00
|
|
|
struct DOMBaseVal MOZ_FINAL : public mozilla::dom::SVGIRect
|
2009-02-03 06:42:24 -08:00
|
|
|
{
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2013-05-16 11:06:21 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMBaseVal)
|
2009-02-03 06:42:24 -08:00
|
|
|
|
|
|
|
DOMBaseVal(nsSVGViewBox *aVal, nsSVGElement *aSVGElement)
|
2013-05-16 11:06:21 -07:00
|
|
|
: mozilla::dom::SVGIRect()
|
2013-05-09 10:42:12 -07:00
|
|
|
, mVal(aVal)
|
|
|
|
, mSVGElement(aSVGElement)
|
|
|
|
{}
|
2009-02-03 06:42:24 -08:00
|
|
|
|
|
|
|
nsSVGViewBox* mVal; // kept alive because it belongs to content
|
|
|
|
nsRefPtr<nsSVGElement> mSVGElement;
|
|
|
|
|
2013-03-26 08:53:13 -07:00
|
|
|
float X() const MOZ_OVERRIDE MOZ_FINAL
|
|
|
|
{
|
|
|
|
return mVal->GetBaseValue().x;
|
|
|
|
}
|
|
|
|
|
|
|
|
float Y() const MOZ_OVERRIDE MOZ_FINAL
|
|
|
|
{
|
|
|
|
return mVal->GetBaseValue().y;
|
|
|
|
}
|
|
|
|
|
|
|
|
float Width() const MOZ_OVERRIDE MOZ_FINAL
|
|
|
|
{
|
|
|
|
return mVal->GetBaseValue().width;
|
|
|
|
}
|
|
|
|
|
|
|
|
float Height() const MOZ_OVERRIDE MOZ_FINAL
|
|
|
|
{
|
|
|
|
return mVal->GetBaseValue().height;
|
|
|
|
}
|
|
|
|
|
2013-05-29 13:43:41 -07:00
|
|
|
void SetX(float aX, mozilla::ErrorResult& aRv) MOZ_FINAL MOZ_OVERRIDE;
|
|
|
|
void SetY(float aY, mozilla::ErrorResult& aRv) MOZ_FINAL MOZ_OVERRIDE;
|
|
|
|
void SetWidth(float aWidth, mozilla::ErrorResult& aRv) MOZ_FINAL MOZ_OVERRIDE;
|
|
|
|
void SetHeight(float aHeight, mozilla::ErrorResult& aRv) MOZ_FINAL MOZ_OVERRIDE;
|
2013-05-16 11:06:21 -07:00
|
|
|
|
2013-05-29 13:43:41 -07:00
|
|
|
virtual nsIContent* GetParentObject() const MOZ_OVERRIDE
|
2013-05-16 11:06:21 -07:00
|
|
|
{
|
|
|
|
return mSVGElement;
|
|
|
|
}
|
2014-06-24 09:36:45 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~DOMBaseVal();
|
2009-02-03 06:42:24 -08:00
|
|
|
};
|
|
|
|
|
2013-03-26 08:53:13 -07:00
|
|
|
struct DOMAnimVal MOZ_FINAL : public mozilla::dom::SVGIRect
|
2009-02-03 06:42:24 -08:00
|
|
|
{
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2013-05-16 11:06:21 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMAnimVal)
|
2009-02-03 06:42:24 -08:00
|
|
|
|
|
|
|
DOMAnimVal(nsSVGViewBox *aVal, nsSVGElement *aSVGElement)
|
2013-05-16 11:06:21 -07:00
|
|
|
: mozilla::dom::SVGIRect()
|
2013-05-09 10:42:12 -07:00
|
|
|
, mVal(aVal)
|
|
|
|
, mSVGElement(aSVGElement)
|
|
|
|
{}
|
2009-02-03 06:42:24 -08:00
|
|
|
|
|
|
|
nsSVGViewBox* mVal; // kept alive because it belongs to content
|
|
|
|
nsRefPtr<nsSVGElement> mSVGElement;
|
|
|
|
|
2010-02-25 10:20:43 -08:00
|
|
|
// Script may have modified animation parameters or timeline -- DOM getters
|
|
|
|
// need to flush any resample requests to reflect these modifications.
|
2013-03-26 08:53:13 -07:00
|
|
|
float X() const MOZ_OVERRIDE MOZ_FINAL
|
2010-02-25 10:20:43 -08:00
|
|
|
{
|
|
|
|
mSVGElement->FlushAnimations();
|
2013-03-26 08:53:13 -07:00
|
|
|
return mVal->GetAnimValue().x;
|
2010-02-25 10:20:43 -08:00
|
|
|
}
|
2013-03-26 08:53:13 -07:00
|
|
|
|
|
|
|
float Y() const MOZ_OVERRIDE MOZ_FINAL
|
2010-02-25 10:20:43 -08:00
|
|
|
{
|
|
|
|
mSVGElement->FlushAnimations();
|
2013-03-26 08:53:13 -07:00
|
|
|
return mVal->GetAnimValue().y;
|
2010-02-25 10:20:43 -08:00
|
|
|
}
|
2013-03-26 08:53:13 -07:00
|
|
|
|
|
|
|
float Width() const MOZ_OVERRIDE MOZ_FINAL
|
2010-02-25 10:20:43 -08:00
|
|
|
{
|
|
|
|
mSVGElement->FlushAnimations();
|
2013-03-26 08:53:13 -07:00
|
|
|
return mVal->GetAnimValue().width;
|
2010-02-25 10:20:43 -08:00
|
|
|
}
|
2013-03-26 08:53:13 -07:00
|
|
|
|
|
|
|
float Height() const MOZ_OVERRIDE MOZ_FINAL
|
2010-02-25 10:20:43 -08:00
|
|
|
{
|
|
|
|
mSVGElement->FlushAnimations();
|
2013-03-26 08:53:13 -07:00
|
|
|
return mVal->GetAnimValue().height;
|
|
|
|
}
|
|
|
|
|
2013-05-29 13:43:41 -07:00
|
|
|
void SetX(float aX, mozilla::ErrorResult& aRv) MOZ_FINAL MOZ_OVERRIDE
|
2013-03-26 08:53:13 -07:00
|
|
|
{
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
}
|
|
|
|
|
2013-05-29 13:43:41 -07:00
|
|
|
void SetY(float aY, mozilla::ErrorResult& aRv) MOZ_FINAL MOZ_OVERRIDE
|
2013-03-26 08:53:13 -07:00
|
|
|
{
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
2010-02-25 10:20:43 -08:00
|
|
|
}
|
2009-02-03 06:42:24 -08:00
|
|
|
|
2013-05-29 13:43:41 -07:00
|
|
|
void SetWidth(float aWidth, mozilla::ErrorResult& aRv) MOZ_FINAL MOZ_OVERRIDE
|
2013-03-26 08:53:13 -07:00
|
|
|
{
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
}
|
|
|
|
|
2013-05-29 13:43:41 -07:00
|
|
|
void SetHeight(float aHeight, mozilla::ErrorResult& aRv) MOZ_FINAL MOZ_OVERRIDE
|
2013-03-26 08:53:13 -07:00
|
|
|
{
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
}
|
2013-05-16 11:06:21 -07:00
|
|
|
|
2013-05-29 13:43:41 -07:00
|
|
|
virtual nsIContent* GetParentObject() const MOZ_OVERRIDE
|
2013-05-16 11:06:21 -07:00
|
|
|
{
|
|
|
|
return mSVGElement;
|
|
|
|
}
|
2014-06-24 09:36:45 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~DOMAnimVal();
|
|
|
|
|
2009-02-03 06:42:24 -08:00
|
|
|
};
|
|
|
|
|
2010-02-18 13:51:00 -08:00
|
|
|
struct SMILViewBox : public nsISMILAttr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SMILViewBox(nsSVGViewBox* aVal, nsSVGElement* aSVGElement)
|
|
|
|
: 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.
|
|
|
|
nsSVGViewBox* mVal;
|
|
|
|
nsSVGElement* mSVGElement;
|
|
|
|
|
|
|
|
// nsISMILAttr methods
|
|
|
|
virtual nsresult ValueFromString(const nsAString& aStr,
|
2013-03-18 20:18:45 -07:00
|
|
|
const mozilla::dom::SVGAnimationElement* aSrcElement,
|
2010-02-20 13:13:11 -08:00
|
|
|
nsSMILValue& aValue,
|
2013-05-29 13:43:41 -07:00
|
|
|
bool& aPreventCachingOfSandwich) const MOZ_OVERRIDE;
|
|
|
|
virtual nsSMILValue GetBaseValue() const MOZ_OVERRIDE;
|
|
|
|
virtual void ClearAnimValue() MOZ_OVERRIDE;
|
|
|
|
virtual nsresult SetAnimValue(const nsSMILValue& aValue) MOZ_OVERRIDE;
|
2010-02-18 13:51:00 -08:00
|
|
|
};
|
2013-05-09 10:42:12 -07:00
|
|
|
|
|
|
|
static nsSVGAttrTearoffTable<nsSVGViewBox, mozilla::dom::SVGAnimatedRect>
|
|
|
|
sSVGAnimatedRectTearoffTable;
|
2009-02-03 06:42:24 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __NS_SVGVIEWBOX_H__
|