2009-02-03 14:42:24 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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/. */
|
2009-02-03 14:42:24 +00:00
|
|
|
|
|
|
|
#ifndef __NS_SVGVIEWBOX_H__
|
|
|
|
#define __NS_SVGVIEWBOX_H__
|
|
|
|
|
2012-01-26 09:57:21 +00:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsError.h"
|
2013-05-09 17:42:12 +00:00
|
|
|
#include "mozilla/dom/SVGAnimatedRect.h"
|
2013-03-26 15:53:13 +00:00
|
|
|
#include "mozilla/dom/SVGIRect.h"
|
2012-01-26 09:57:21 +00:00
|
|
|
#include "nsISMILAttr.h"
|
2009-02-03 14:42:24 +00:00
|
|
|
#include "nsSVGElement.h"
|
2012-06-19 02:30:09 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-05-09 17:42:12 +00:00
|
|
|
#include "nsSVGAttrTearoffTable.h"
|
2012-01-26 09:57:21 +00:00
|
|
|
|
|
|
|
class nsSMILValue;
|
2009-02-03 14:42:24 +00:00
|
|
|
|
2013-03-19 03:18:45 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class SVGAnimationElement;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-03 14:42:24 +00:00
|
|
|
struct nsSVGViewBoxRect
|
|
|
|
{
|
|
|
|
float x, y;
|
|
|
|
float width, height;
|
2013-02-26 16:58:06 +00:00
|
|
|
bool none;
|
2009-02-03 14:42:24 +00:00
|
|
|
|
2013-02-26 16:58:06 +00:00
|
|
|
nsSVGViewBoxRect() : none(true) {}
|
2009-02-03 14:42:24 +00:00
|
|
|
nsSVGViewBoxRect(float aX, float aY, float aWidth, float aHeight) :
|
2013-02-26 16:58:06 +00:00
|
|
|
x(aX), y(aY), width(aWidth), height(aHeight), none(false) {}
|
2010-02-18 21:51:00 +00:00
|
|
|
nsSVGViewBoxRect(const nsSVGViewBoxRect& rhs) :
|
2013-02-26 16:58:06 +00:00
|
|
|
x(rhs.x), y(rhs.y), width(rhs.width), height(rhs.height), none(rhs.none) {}
|
2011-09-29 06:19:26 +00:00
|
|
|
bool operator==(const nsSVGViewBoxRect& aOther) const;
|
2009-02-03 14:42:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class nsSVGViewBox
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
void Init();
|
|
|
|
|
2012-05-03 16:05:40 +00: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 16:58:06 +00: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 16:05:40 +00:00
|
|
|
bool IsExplicitlySet() const
|
2013-02-26 16:58:06 +00:00
|
|
|
{ return mAnimVal || mHasBaseVal; }
|
2009-02-19 13:53:46 +00:00
|
|
|
|
2009-02-03 14:42:24 +00:00
|
|
|
const nsSVGViewBoxRect& GetBaseValue() const
|
|
|
|
{ return mBaseVal; }
|
2012-05-17 10:02:41 +00:00
|
|
|
void SetBaseValue(const nsSVGViewBoxRect& aRect,
|
2011-10-09 15:25:07 +00:00
|
|
|
nsSVGElement *aSVGElement);
|
2010-02-25 18:20:43 +00:00
|
|
|
const nsSVGViewBoxRect& GetAnimValue() const
|
|
|
|
{ return mAnimVal ? *mAnimVal : mBaseVal; }
|
2013-02-26 16:58:06 +00:00
|
|
|
void SetAnimValue(const nsSVGViewBoxRect& aRect,
|
2010-02-18 21:51:00 +00:00
|
|
|
nsSVGElement *aSVGElement);
|
2009-02-03 14:42:24 +00:00
|
|
|
|
|
|
|
nsresult SetBaseValueString(const nsAString& aValue,
|
2012-08-25 17:02:34 +00:00
|
|
|
nsSVGElement *aSVGElement,
|
|
|
|
bool aDoSetAttr);
|
2009-02-03 14:42:24 +00:00
|
|
|
void GetBaseValueString(nsAString& aValue) const;
|
|
|
|
|
2013-05-20 11:46:12 +00: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 21:51:00 +00:00
|
|
|
// Returns a new nsISMILAttr object that the caller must delete
|
|
|
|
nsISMILAttr* ToSMILAttr(nsSVGElement* aSVGElement);
|
2012-08-25 17:06:10 +00:00
|
|
|
|
2009-02-03 14:42:24 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
nsSVGViewBoxRect mBaseVal;
|
|
|
|
nsAutoPtr<nsSVGViewBoxRect> mAnimVal;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mHasBaseVal;
|
2009-02-03 14:42:24 +00:00
|
|
|
|
2012-12-21 09:18:58 +00:00
|
|
|
public:
|
2013-03-26 15:53:13 +00:00
|
|
|
struct DOMBaseVal MOZ_FINAL : public mozilla::dom::SVGIRect
|
2009-02-03 14:42:24 +00:00
|
|
|
{
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2013-05-16 18:06:21 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMBaseVal)
|
2009-02-03 14:42:24 +00:00
|
|
|
|
|
|
|
DOMBaseVal(nsSVGViewBox *aVal, nsSVGElement *aSVGElement)
|
2013-05-16 18:06:21 +00:00
|
|
|
: mozilla::dom::SVGIRect()
|
2013-05-09 17:42:12 +00:00
|
|
|
, mVal(aVal)
|
|
|
|
, mSVGElement(aSVGElement)
|
|
|
|
{}
|
2009-02-03 14:42:24 +00:00
|
|
|
|
|
|
|
nsSVGViewBox* mVal; // kept alive because it belongs to content
|
|
|
|
nsRefPtr<nsSVGElement> mSVGElement;
|
|
|
|
|
2013-03-26 15:53:13 +00: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 20:43:41 +00: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 18:06:21 +00:00
|
|
|
|
2013-05-29 20:43:41 +00:00
|
|
|
virtual nsIContent* GetParentObject() const MOZ_OVERRIDE
|
2013-05-16 18:06:21 +00:00
|
|
|
{
|
|
|
|
return mSVGElement;
|
|
|
|
}
|
2014-06-24 16:36:45 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~DOMBaseVal();
|
2009-02-03 14:42:24 +00:00
|
|
|
};
|
|
|
|
|
2013-03-26 15:53:13 +00:00
|
|
|
struct DOMAnimVal MOZ_FINAL : public mozilla::dom::SVGIRect
|
2009-02-03 14:42:24 +00:00
|
|
|
{
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2013-05-16 18:06:21 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMAnimVal)
|
2009-02-03 14:42:24 +00:00
|
|
|
|
|
|
|
DOMAnimVal(nsSVGViewBox *aVal, nsSVGElement *aSVGElement)
|
2013-05-16 18:06:21 +00:00
|
|
|
: mozilla::dom::SVGIRect()
|
2013-05-09 17:42:12 +00:00
|
|
|
, mVal(aVal)
|
|
|
|
, mSVGElement(aSVGElement)
|
|
|
|
{}
|
2009-02-03 14:42:24 +00:00
|
|
|
|
|
|
|
nsSVGViewBox* mVal; // kept alive because it belongs to content
|
|
|
|
nsRefPtr<nsSVGElement> mSVGElement;
|
|
|
|
|
2010-02-25 18:20:43 +00:00
|
|
|
// Script may have modified animation parameters or timeline -- DOM getters
|
|
|
|
// need to flush any resample requests to reflect these modifications.
|
2013-03-26 15:53:13 +00:00
|
|
|
float X() const MOZ_OVERRIDE MOZ_FINAL
|
2010-02-25 18:20:43 +00:00
|
|
|
{
|
|
|
|
mSVGElement->FlushAnimations();
|
2013-03-26 15:53:13 +00:00
|
|
|
return mVal->GetAnimValue().x;
|
2010-02-25 18:20:43 +00:00
|
|
|
}
|
2013-03-26 15:53:13 +00:00
|
|
|
|
|
|
|
float Y() const MOZ_OVERRIDE MOZ_FINAL
|
2010-02-25 18:20:43 +00:00
|
|
|
{
|
|
|
|
mSVGElement->FlushAnimations();
|
2013-03-26 15:53:13 +00:00
|
|
|
return mVal->GetAnimValue().y;
|
2010-02-25 18:20:43 +00:00
|
|
|
}
|
2013-03-26 15:53:13 +00:00
|
|
|
|
|
|
|
float Width() const MOZ_OVERRIDE MOZ_FINAL
|
2010-02-25 18:20:43 +00:00
|
|
|
{
|
|
|
|
mSVGElement->FlushAnimations();
|
2013-03-26 15:53:13 +00:00
|
|
|
return mVal->GetAnimValue().width;
|
2010-02-25 18:20:43 +00:00
|
|
|
}
|
2013-03-26 15:53:13 +00:00
|
|
|
|
|
|
|
float Height() const MOZ_OVERRIDE MOZ_FINAL
|
2010-02-25 18:20:43 +00:00
|
|
|
{
|
|
|
|
mSVGElement->FlushAnimations();
|
2013-03-26 15:53:13 +00:00
|
|
|
return mVal->GetAnimValue().height;
|
|
|
|
}
|
|
|
|
|
2013-05-29 20:43:41 +00:00
|
|
|
void SetX(float aX, mozilla::ErrorResult& aRv) MOZ_FINAL MOZ_OVERRIDE
|
2013-03-26 15:53:13 +00:00
|
|
|
{
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
}
|
|
|
|
|
2013-05-29 20:43:41 +00:00
|
|
|
void SetY(float aY, mozilla::ErrorResult& aRv) MOZ_FINAL MOZ_OVERRIDE
|
2013-03-26 15:53:13 +00:00
|
|
|
{
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
2010-02-25 18:20:43 +00:00
|
|
|
}
|
2009-02-03 14:42:24 +00:00
|
|
|
|
2013-05-29 20:43:41 +00:00
|
|
|
void SetWidth(float aWidth, mozilla::ErrorResult& aRv) MOZ_FINAL MOZ_OVERRIDE
|
2013-03-26 15:53:13 +00:00
|
|
|
{
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
}
|
|
|
|
|
2013-05-29 20:43:41 +00:00
|
|
|
void SetHeight(float aHeight, mozilla::ErrorResult& aRv) MOZ_FINAL MOZ_OVERRIDE
|
2013-03-26 15:53:13 +00:00
|
|
|
{
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
}
|
2013-05-16 18:06:21 +00:00
|
|
|
|
2013-05-29 20:43:41 +00:00
|
|
|
virtual nsIContent* GetParentObject() const MOZ_OVERRIDE
|
2013-05-16 18:06:21 +00:00
|
|
|
{
|
|
|
|
return mSVGElement;
|
|
|
|
}
|
2014-06-24 16:36:45 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~DOMAnimVal();
|
|
|
|
|
2009-02-03 14:42:24 +00:00
|
|
|
};
|
|
|
|
|
2010-02-18 21:51:00 +00: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-19 03:18:45 +00:00
|
|
|
const mozilla::dom::SVGAnimationElement* aSrcElement,
|
2010-02-20 21:13:11 +00:00
|
|
|
nsSMILValue& aValue,
|
2013-05-29 20:43:41 +00: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 21:51:00 +00:00
|
|
|
};
|
2013-05-09 17:42:12 +00:00
|
|
|
|
|
|
|
static nsSVGAttrTearoffTable<nsSVGViewBox, mozilla::dom::SVGAnimatedRect>
|
|
|
|
sSVGAnimatedRectTearoffTable;
|
2009-02-03 14:42:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __NS_SVGVIEWBOX_H__
|