2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is the Mozilla SVG project.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Crocodile Clips Ltd..
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2001
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Alex Fritze <alex.fritze@crocodile-clips.com> (original author)
|
|
|
|
* Jonathan Watt <jonathan.watt@strath.ac.uk>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#ifndef __NS_SVGSVGELEMENT_H__
|
|
|
|
#define __NS_SVGSVGELEMENT_H__
|
|
|
|
|
|
|
|
#include "nsSVGStylableElement.h"
|
2007-06-20 14:56:03 -07:00
|
|
|
#include "nsIDOMSVGSVGElement.h"
|
2011-12-31 01:44:03 -08:00
|
|
|
#include "DOMSVGTests.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMSVGFitToViewBox.h"
|
|
|
|
#include "nsIDOMSVGLocatable.h"
|
|
|
|
#include "nsIDOMSVGZoomAndPan.h"
|
|
|
|
#include "nsIDOMSVGMatrix.h"
|
2009-04-28 06:25:03 -07:00
|
|
|
#include "nsIDOMSVGPoint.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsSVGLength2.h"
|
2007-08-27 16:11:14 -07:00
|
|
|
#include "nsSVGEnum.h"
|
2009-02-03 06:42:24 -08:00
|
|
|
#include "nsSVGViewBox.h"
|
2010-12-19 16:45:29 -08:00
|
|
|
#include "SVGAnimatedPreserveAspectRatio.h"
|
2010-10-25 05:17:38 -07:00
|
|
|
#include "mozilla/dom/FromParser.h"
|
2007-06-20 14:56:03 -07:00
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
class nsSMILTimeContainer;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
typedef nsSVGStylableElement nsSVGSVGElementBase;
|
|
|
|
|
2009-04-28 06:25:03 -07:00
|
|
|
class nsSVGSVGElement;
|
|
|
|
|
|
|
|
class nsSVGTranslatePoint {
|
|
|
|
public:
|
|
|
|
nsSVGTranslatePoint(float aX, float aY) :
|
|
|
|
mX(aX), mY(aY) {}
|
|
|
|
|
|
|
|
void SetX(float aX)
|
|
|
|
{ mX = aX; }
|
|
|
|
void SetY(float aY)
|
|
|
|
{ mY = aY; }
|
|
|
|
float GetX() const
|
|
|
|
{ return mX; }
|
|
|
|
float GetY() const
|
|
|
|
{ return mY; }
|
|
|
|
|
|
|
|
nsresult ToDOMVal(nsSVGSVGElement *aElement, nsIDOMSVGPoint **aResult);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
struct DOMVal : public nsIDOMSVGPoint {
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS(DOMVal)
|
|
|
|
|
|
|
|
DOMVal(nsSVGTranslatePoint* aVal, nsSVGSVGElement *aElement)
|
|
|
|
: mVal(aVal), mElement(aElement) {}
|
|
|
|
|
|
|
|
NS_IMETHOD GetX(float *aValue)
|
|
|
|
{ *aValue = mVal->GetX(); return NS_OK; }
|
|
|
|
NS_IMETHOD GetY(float *aValue)
|
|
|
|
{ *aValue = mVal->GetY(); return NS_OK; }
|
|
|
|
|
|
|
|
NS_IMETHOD SetX(float aValue);
|
|
|
|
NS_IMETHOD SetY(float aValue);
|
|
|
|
|
|
|
|
NS_IMETHOD MatrixTransform(nsIDOMSVGMatrix *matrix,
|
|
|
|
nsIDOMSVGPoint **_retval);
|
|
|
|
|
|
|
|
nsSVGTranslatePoint *mVal; // kept alive because it belongs to mElement
|
|
|
|
nsRefPtr<nsSVGSVGElement> mElement;
|
|
|
|
};
|
|
|
|
|
|
|
|
float mX;
|
|
|
|
float mY;
|
|
|
|
};
|
|
|
|
|
2007-11-18 04:09:03 -08:00
|
|
|
class svgFloatSize {
|
|
|
|
public:
|
|
|
|
svgFloatSize(float aWidth, float aHeight)
|
|
|
|
: width(aWidth)
|
|
|
|
, height(aHeight)
|
|
|
|
{}
|
2011-09-28 23:19:26 -07:00
|
|
|
bool operator!=(const svgFloatSize& rhs) {
|
2007-11-18 04:09:03 -08:00
|
|
|
return width != rhs.width || height != rhs.height;
|
|
|
|
}
|
|
|
|
float width;
|
|
|
|
float height;
|
|
|
|
};
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsSVGSVGElement : public nsSVGSVGElementBase,
|
2007-06-20 14:56:03 -07:00
|
|
|
public nsIDOMSVGSVGElement,
|
2011-12-31 01:44:03 -08:00
|
|
|
public DOMSVGTests,
|
2007-03-22 10:30:00 -07:00
|
|
|
public nsIDOMSVGFitToViewBox,
|
|
|
|
public nsIDOMSVGLocatable,
|
|
|
|
public nsIDOMSVGZoomAndPan
|
|
|
|
{
|
|
|
|
friend class nsSVGOuterSVGFrame;
|
|
|
|
friend class nsSVGInnerSVGFrame;
|
2010-12-19 16:45:29 -08:00
|
|
|
friend class nsSVGImageFrame;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
friend nsresult NS_NewSVGSVGElement(nsIContent **aResult,
|
2010-07-23 02:49:57 -07:00
|
|
|
already_AddRefed<nsINodeInfo> aNodeInfo,
|
2010-10-25 05:17:38 -07:00
|
|
|
mozilla::dom::FromParser aFromParser);
|
|
|
|
nsSVGSVGElement(already_AddRefed<nsINodeInfo> aNodeInfo,
|
|
|
|
mozilla::dom::FromParser aFromParser);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
public:
|
2010-12-19 16:45:29 -08:00
|
|
|
typedef mozilla::SVGAnimatedPreserveAspectRatio SVGAnimatedPreserveAspectRatio;
|
2010-12-19 16:45:29 -08:00
|
|
|
typedef mozilla::SVGPreserveAspectRatio SVGPreserveAspectRatio;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// interfaces:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2010-01-12 12:00:49 -08:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsSVGSVGElement, nsSVGSVGElementBase)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_DECL_NSIDOMSVGSVGELEMENT
|
|
|
|
NS_DECL_NSIDOMSVGFITTOVIEWBOX
|
|
|
|
NS_DECL_NSIDOMSVGLOCATABLE
|
|
|
|
NS_DECL_NSIDOMSVGZOOMANDPAN
|
|
|
|
|
|
|
|
// xxx I wish we could use virtual inheritance
|
|
|
|
NS_FORWARD_NSIDOMNODE(nsSVGSVGElementBase::)
|
|
|
|
NS_FORWARD_NSIDOMELEMENT(nsSVGSVGElementBase::)
|
|
|
|
NS_FORWARD_NSIDOMSVGELEMENT(nsSVGSVGElementBase::)
|
|
|
|
|
2007-06-20 14:56:03 -07:00
|
|
|
/**
|
|
|
|
* For use by zoom controls to allow currentScale, currentTranslate.x and
|
|
|
|
* currentTranslate.y to be set by a single operation that dispatches a
|
|
|
|
* single SVGZoom event (instead of one SVGZoom and two SVGScroll events).
|
|
|
|
*/
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHOD SetCurrentScaleTranslate(float s, float x, float y);
|
2007-06-20 14:56:03 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* For use by pan controls to allow currentTranslate.x and currentTranslate.y
|
|
|
|
* to be set by a single operation that dispatches a single SVGScroll event
|
|
|
|
* (instead of two).
|
|
|
|
*/
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHOD SetCurrentTranslate(float x, float y);
|
2007-06-20 14:56:03 -07:00
|
|
|
|
|
|
|
/**
|
2009-04-28 06:25:03 -07:00
|
|
|
* Retrieve the value of currentScale and currentTranslate.
|
2007-06-20 14:56:03 -07:00
|
|
|
*/
|
2009-04-28 06:25:03 -07:00
|
|
|
const nsSVGTranslatePoint& GetCurrentTranslate() { return mCurrentTranslate; }
|
|
|
|
float GetCurrentScale() { return mCurrentScale; }
|
2007-06-20 14:56:03 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the value of currentScale, currentTranslate.x or
|
|
|
|
* currentTranslate.y prior to the last change made to any one of them.
|
|
|
|
*/
|
2009-04-28 06:25:03 -07:00
|
|
|
const nsSVGTranslatePoint& GetPreviousTranslate() { return mPreviousTranslate; }
|
2009-01-16 00:16:46 -08:00
|
|
|
float GetPreviousScale() { return mPreviousScale; }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
nsSMILTimeContainer* GetTimedDocumentRoot();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsIContent interface
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
|
2009-01-14 20:38:07 -08:00
|
|
|
virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsSVGElement specializations:
|
2011-06-16 03:53:13 -07:00
|
|
|
virtual gfxMatrix PrependLocalTransformTo(const gfxMatrix &aMatrix) const;
|
2010-02-07 18:28:01 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsSVGSVGElement methods:
|
|
|
|
float GetLength(PRUint8 mCtxType);
|
|
|
|
|
|
|
|
// public helpers:
|
2011-06-16 03:53:13 -07:00
|
|
|
gfxMatrix GetViewBoxTransform() const;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HasValidViewbox() const { return mViewBox.IsValid(); }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-02-09 12:13:18 -08:00
|
|
|
// This services any pending notifications for the transform on on this root
|
|
|
|
// <svg> node needing to be recalculated. (Only applicable in
|
|
|
|
// SVG-as-an-image documents.)
|
|
|
|
virtual void FlushImageTransformInvalidation();
|
2010-12-19 16:45:29 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
|
|
|
|
|
2009-02-03 06:42:24 -08:00
|
|
|
svgFloatSize GetViewportSize() const {
|
2007-11-18 04:09:03 -08:00
|
|
|
return svgFloatSize(mViewportWidth, mViewportHeight);
|
|
|
|
}
|
|
|
|
|
2009-02-03 06:42:24 -08:00
|
|
|
void SetViewportSize(const svgFloatSize& aSize) {
|
2007-11-18 04:09:03 -08:00
|
|
|
mViewportWidth = aSize.width;
|
|
|
|
mViewportHeight = aSize.height;
|
|
|
|
}
|
|
|
|
|
2010-07-23 02:49:57 -07:00
|
|
|
virtual nsXPCClassInfo* GetClassInfo();
|
2010-11-16 15:19:21 -08:00
|
|
|
|
2010-12-19 16:45:29 -08:00
|
|
|
private:
|
|
|
|
// Methods for <image> elements to override my "PreserveAspectRatio" value.
|
|
|
|
// These are private so that only our friends (nsSVGImageFrame in
|
|
|
|
// particular) have access.
|
|
|
|
void SetImageOverridePreserveAspectRatio(const SVGPreserveAspectRatio& aPAR);
|
|
|
|
void ClearImageOverridePreserveAspectRatio();
|
2011-06-16 03:53:13 -07:00
|
|
|
const SVGPreserveAspectRatio* GetImageOverridePreserveAspectRatio() const;
|
2010-12-19 16:45:29 -08:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
// Returns true if we should synthesize a viewBox for ourselves (that is,
|
2011-02-09 12:13:18 -08:00
|
|
|
// if we're the outermost <svg> in an image document, and we're not currently
|
|
|
|
// being painted by an <svg:image> element). This method also assumes that we
|
|
|
|
// lack a valid viewBox attribute.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool ShouldSynthesizeViewBox() const;
|
2011-02-09 12:13:18 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
|
|
|
// nsSVGElement overrides
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsEventName(nsIAtom* aName);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aCompileEventHandlers);
|
|
|
|
virtual void UnbindFromTree(bool aDeep, bool aNullParent);
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// implementation helpers:
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsRoot() const {
|
2007-12-11 18:26:09 -08:00
|
|
|
NS_ASSERTION((IsInDoc() && !GetParent()) ==
|
2011-10-18 03:53:36 -07:00
|
|
|
(OwnerDoc() && (OwnerDoc()->GetRootElement() == this)),
|
2007-12-11 18:26:09 -08:00
|
|
|
"Can't determine if we're root");
|
|
|
|
return IsInDoc() && !GetParent();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-02-26 02:21:11 -08:00
|
|
|
/**
|
|
|
|
* Returns true if this is an SVG <svg> element that is the child of
|
|
|
|
* another non-foreignObject SVG element.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsInner() const {
|
2011-04-07 22:27:57 -07:00
|
|
|
const nsIContent *parent = GetFlattenedTreeParent();
|
2011-12-15 06:47:03 -08:00
|
|
|
return parent && parent->IsSVG() &&
|
2011-02-26 02:21:11 -08:00
|
|
|
parent->Tag() != nsGkAtoms::foreignObject;
|
|
|
|
}
|
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
/*
|
|
|
|
* While binding to the tree we need to determine if we will be the outermost
|
|
|
|
* <svg> element _before_ the children are bound (as they want to know what
|
|
|
|
* timed document root to register with) and therefore _before_ our parent is
|
|
|
|
* set (both actions are performed by nsGenericElement::BindToTree) so we
|
|
|
|
* can't use GetOwnerSVGElement() as it relies on GetParent(). This code is
|
|
|
|
* basically a simplified version of GetOwnerSVGElement that uses the parent
|
|
|
|
* parameters passed in instead.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool WillBeOutermostSVG(nsIContent* aParent,
|
2009-01-14 20:38:07 -08:00
|
|
|
nsIContent* aBindingParent) const;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// invalidate viewbox -> viewport xform & inform frames
|
|
|
|
void InvalidateTransformNotifyFrame();
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
// Returns true if we have at least one of the following:
|
2010-12-19 16:45:29 -08:00
|
|
|
// - a (valid or invalid) value for the preserveAspectRatio attribute
|
|
|
|
// - a SMIL-animated value for the preserveAspectRatio attribute
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HasPreserveAspectRatio();
|
2010-12-19 16:45:29 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
virtual LengthAttributesInfo GetLengthInfo();
|
|
|
|
|
|
|
|
enum { X, Y, WIDTH, HEIGHT };
|
|
|
|
nsSVGLength2 mLengthAttributes[4];
|
|
|
|
static LengthInfo sLengthInfo[4];
|
|
|
|
|
2007-08-27 16:11:14 -07:00
|
|
|
virtual EnumAttributesInfo GetEnumInfo();
|
|
|
|
|
|
|
|
enum { ZOOMANDPAN };
|
|
|
|
nsSVGEnum mEnumAttributes[1];
|
|
|
|
static nsSVGEnumMapping sZoomAndPanMap[];
|
|
|
|
static EnumInfo sEnumInfo[1];
|
|
|
|
|
2009-02-03 06:42:24 -08:00
|
|
|
virtual nsSVGViewBox *GetViewBox();
|
2010-12-19 16:45:29 -08:00
|
|
|
virtual SVGAnimatedPreserveAspectRatio *GetPreserveAspectRatio();
|
2009-01-04 17:19:38 -08:00
|
|
|
|
2010-12-19 16:45:29 -08:00
|
|
|
nsSVGViewBox mViewBox;
|
|
|
|
SVGAnimatedPreserveAspectRatio mPreserveAspectRatio;
|
2009-01-04 17:19:38 -08:00
|
|
|
|
2010-12-19 16:45:29 -08:00
|
|
|
nsSVGSVGElement *mCoordCtx;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-11-18 04:09:03 -08:00
|
|
|
// The size of the rectangular SVG viewport into which we render. This is
|
|
|
|
// not (necessarily) the same as the content area. See:
|
|
|
|
//
|
|
|
|
// http://www.w3.org/TR/SVG11/coords.html#ViewportSpace
|
|
|
|
//
|
|
|
|
// XXXjwatt Currently only used for outer <svg>, but maybe we could use -1 to
|
|
|
|
// flag this as an inner <svg> to save the overhead of GetCtx calls?
|
|
|
|
// XXXjwatt our frame should probably reset these when it's destroyed.
|
|
|
|
float mViewportWidth, mViewportHeight;
|
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
// The time container for animations within this SVG document fragment. Set
|
|
|
|
// for all outermost <svg> elements (not nested <svg> elements).
|
|
|
|
nsAutoPtr<nsSMILTimeContainer> mTimedDocumentRoot;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// zoom and pan
|
2009-04-28 06:25:03 -07:00
|
|
|
// IMPORTANT: see the comment in RecordCurrentScaleTranslate before writing
|
|
|
|
// code to change any of these!
|
|
|
|
nsSVGTranslatePoint mCurrentTranslate;
|
|
|
|
float mCurrentScale;
|
|
|
|
nsSVGTranslatePoint mPreviousTranslate;
|
2007-03-22 10:30:00 -07:00
|
|
|
float mPreviousScale;
|
|
|
|
PRInt32 mRedrawSuspendCount;
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
// For outermost <svg> elements created from parsing, animation is started by
|
|
|
|
// the onload event in accordance with the SVG spec, but for <svg> elements
|
|
|
|
// created by script or promoted from inner <svg> to outermost <svg> we need
|
|
|
|
// to manually kick off animation when they are bound to the tree.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mStartAnimationOnBindToTree;
|
|
|
|
bool mImageNeedsTransformInvalidation;
|
|
|
|
bool mIsPaintingSVGImageElement;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|