Bug 163068 - backend support for zoom and pan. r=jwatt

This commit is contained in:
tor%cs.brown.edu 2004-12-02 23:13:13 +00:00
parent fc7746a6a5
commit 26931c5a71
8 changed files with 189 additions and 10 deletions

View File

@ -171,6 +171,7 @@ SVG_ATOM(x2, "x2")
SVG_ATOM(y, "y")
SVG_ATOM(y1, "y1")
SVG_ATOM(y2, "y2")
SVG_ATOM(zoomAndPan, "zoomAndPan")
// transformation keywords
SVG_ATOM(matrix, "matrix")
@ -199,3 +200,7 @@ SVG_ATOM(repeat, "repeat")
// Gradient Units
SVG_ATOM(userSpaceOnUse, "userSpaceOnUse")
SVG_ATOM(objectBoundingBox, "objectBoundingBox")
// Zoom and Pan options
SVG_ATOM(disable, "disable")
SVG_ATOM(magnify, "magnify")

View File

@ -43,13 +43,14 @@
#include "nsIDOMSVGSVGElement.h"
class nsSVGCoordCtxProvider;
class nsIDOMSVGNumber;
class nsISVGEnum;
////////////////////////////////////////////////////////////////////////
// nsISVGSVGElement: private interface implemented by <svg>-elements
// {EB4533A1-10F3-4366-88CE-77682D140759}
#define NS_ISVGSVGELEMENT_IID \
{ 0xeb4533a1, 0x10f3, 0x4366, { 0x88, 0xce, 0x77, 0x68, 0x2d, 0x14, 0x07, 0x59 } }
{ 0x8ae345f3, 0x5232, 0x426b, { 0xba, 0x23, 0x47, 0x1e, 0x45, 0x64, 0x50, 0xf9 } }
class nsISVGSVGElement : public nsIDOMSVGSVGElement
{
@ -57,6 +58,8 @@ public:
static const nsIID& GetIID() { static nsIID iid = NS_ISVGSVGELEMENT_IID; return iid; }
NS_IMETHOD SetParentCoordCtxProvider(nsSVGCoordCtxProvider *parentCtx)=0;
NS_IMETHOD GetCurrentScaleNumber(nsIDOMSVGNumber **aResult)=0;
NS_IMETHOD GetZoomAndPanEnum(nsISVGEnum **aResult)=0;
};
#endif // __NS_ISVGSVGELEMENT__

View File

@ -171,6 +171,7 @@ SVG_ATOM(x2, "x2")
SVG_ATOM(y, "y")
SVG_ATOM(y1, "y1")
SVG_ATOM(y2, "y2")
SVG_ATOM(zoomAndPan, "zoomAndPan")
// transformation keywords
SVG_ATOM(matrix, "matrix")
@ -199,3 +200,7 @@ SVG_ATOM(repeat, "repeat")
// Gradient Units
SVG_ATOM(userSpaceOnUse, "userSpaceOnUse")
SVG_ATOM(objectBoundingBox, "objectBoundingBox")
// Zoom and Pan options
SVG_ATOM(disable, "disable")
SVG_ATOM(magnify, "magnify")

View File

@ -65,6 +65,8 @@
#include "nsSVGPreserveAspectRatio.h"
#include "nsISVGValueUtils.h"
#include "nsDOMError.h"
#include "nsIDOMSVGZoomAndPan.h"
#include "nsSVGEnum.h"
typedef nsSVGStylableElement nsSVGSVGElementBase;
@ -72,6 +74,7 @@ class nsSVGSVGElement : public nsSVGSVGElementBase,
public nsISVGSVGElement, // : nsIDOMSVGSVGElement
public nsIDOMSVGFitToViewBox,
public nsIDOMSVGLocatable,
public nsIDOMSVGZoomAndPan,
public nsSVGCoordCtxProvider
{
protected:
@ -88,6 +91,7 @@ public:
NS_DECL_NSIDOMSVGSVGELEMENT
NS_DECL_NSIDOMSVGFITTOVIEWBOX
NS_DECL_NSIDOMSVGLOCATABLE
NS_DECL_NSIDOMSVGZOOMANDPAN
// xxx I wish we could use virtual inheritance
NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsSVGSVGElementBase::)
@ -96,6 +100,8 @@ public:
// nsISVGSVGElement interface:
NS_IMETHOD SetParentCoordCtxProvider(nsSVGCoordCtxProvider *parentCtx);
NS_IMETHOD GetCurrentScaleNumber(nsIDOMSVGNumber **aResult);
NS_IMETHOD GetZoomAndPanEnum(nsISVGEnum **aResult);
// nsIStyledContent interface
NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
@ -103,7 +109,7 @@ public:
// nsISVGValueObserver
NS_IMETHOD WillModifySVGObservable(nsISVGValue* observable);
NS_IMETHOD DidModifySVGObservable (nsISVGValue* observable);
protected:
// nsSVGElement overrides
PRBool IsEventName(nsIAtom* aName);
@ -118,6 +124,11 @@ protected:
nsCOMPtr<nsIDOMSVGAnimatedPreserveAspectRatio> mPreserveAspectRatio;
nsCOMPtr<nsIDOMSVGAnimatedLength> mX;
nsCOMPtr<nsIDOMSVGAnimatedLength> mY;
// zoom and pan
nsCOMPtr<nsISVGEnum> mZoomAndPan;
nsCOMPtr<nsIDOMSVGPoint> mCurrentTranslate;
nsCOMPtr<nsIDOMSVGNumber> mCurrentScale;
PRInt32 mRedrawSuspendCount;
};
@ -139,6 +150,7 @@ NS_INTERFACE_MAP_BEGIN(nsSVGSVGElement)
NS_INTERFACE_MAP_ENTRY(nsIDOMSVGSVGElement)
NS_INTERFACE_MAP_ENTRY(nsIDOMSVGFitToViewBox)
NS_INTERFACE_MAP_ENTRY(nsIDOMSVGLocatable)
NS_INTERFACE_MAP_ENTRY(nsIDOMSVGZoomAndPan)
NS_INTERFACE_MAP_ENTRY(nsISVGSVGElement)
NS_INTERFACE_MAP_ENTRY(nsSVGCoordCtxProvider)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(SVGSVGElement)
@ -255,9 +267,37 @@ nsSVGSVGElement::Init()
NS_ENSURE_SUCCESS(rv,rv);
}
// add observers -------------------------- :
NS_ADD_SVGVALUE_OBSERVER(mViewBox);
NS_ADD_SVGVALUE_OBSERVER(mPreserveAspectRatio);
// nsIDOMSVGZoomAndPan attribute ------:
// Define enumeration mappings
static struct nsSVGEnumMapping zoomMap[] = {
{&nsSVGAtoms::disable, nsIDOMSVGZoomAndPan::SVG_ZOOMANDPAN_DISABLE},
{&nsSVGAtoms::magnify, nsIDOMSVGZoomAndPan::SVG_ZOOMANDPAN_MAGNIFY},
{nsnull, 0}
};
// DOM property: zoomAndPan , #IMPLIED attrib: zoomAndPan
{
rv = NS_NewSVGEnum(getter_AddRefs(mZoomAndPan),
nsIDOMSVGZoomAndPan::SVG_ZOOMANDPAN_MAGNIFY, zoomMap);
NS_ENSURE_SUCCESS(rv,rv);
rv = AddMappedSVGValue(nsSVGAtoms::zoomAndPan, mZoomAndPan);
NS_ENSURE_SUCCESS(rv,rv);
}
// DOM property: currentScale
{
rv = NS_NewSVGNumber(getter_AddRefs(mCurrentScale), 1.0f);
NS_ENSURE_SUCCESS(rv,rv);
NS_ADD_SVGVALUE_OBSERVER(mCurrentScale);
}
// DOM property: currentTranslate
{
rv = nsSVGPoint::Create(0.0f, 0.0f, getter_AddRefs(mCurrentTranslate));
NS_ENSURE_SUCCESS(rv,rv);
NS_ADD_SVGVALUE_OBSERVER(mCurrentTranslate);
}
return rv;
}
@ -432,21 +472,22 @@ nsSVGSVGElement::GetCurrentView(nsIDOMSVGViewSpec * *aCurrentView)
NS_IMETHODIMP
nsSVGSVGElement::GetCurrentScale(float *aCurrentScale)
{
*aCurrentScale = 1.0;
return NS_OK;
return mCurrentScale->GetValue(aCurrentScale);
}
NS_IMETHODIMP
nsSVGSVGElement::SetCurrentScale(float aCurrentScale)
{
return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
return mCurrentScale->SetValue(aCurrentScale);
}
/* readonly attribute nsIDOMSVGPoint currentTranslate; */
NS_IMETHODIMP
nsSVGSVGElement::GetCurrentTranslate(nsIDOMSVGPoint * *aCurrentTranslate)
{
return nsSVGPoint::Create(0.0f, 0.0f, aCurrentTranslate);
*aCurrentTranslate = mCurrentTranslate;
NS_ADDREF(*aCurrentTranslate);
return NS_OK;
}
/* unsigned long suspendRedraw (in unsigned long max_wait_milliseconds); */
@ -1061,6 +1102,25 @@ nsSVGSVGElement::GetTransformToElement(nsIDOMSVGElement *element, nsIDOMSVGMatri
return NS_ERROR_NOT_IMPLEMENTED;
}
//----------------------------------------------------------------------
// nsIDOMSVGZoomAndPan methods
/* attribute unsigned short zoomAndPan; */
NS_IMETHODIMP
nsSVGSVGElement::GetZoomAndPan(PRUint16 *aZoomAndPan)
{
return mZoomAndPan->GetIntegerValue(*aZoomAndPan);
}
NS_IMETHODIMP
nsSVGSVGElement::SetZoomAndPan(PRUint16 aZoomAndPan)
{
if (aZoomAndPan == nsIDOMSVGZoomAndPan::SVG_ZOOMANDPAN_DISABLE ||
aZoomAndPan == nsIDOMSVGZoomAndPan::SVG_ZOOMANDPAN_MAGNIFY)
return mZoomAndPan->SetIntegerValue(aZoomAndPan);
return NS_ERROR_DOM_SVG_INVALID_VALUE_ERR;
}
//----------------------------------------------------------------------
// nsISVGSVGElement methods:
@ -1110,6 +1170,22 @@ nsSVGSVGElement::SetParentCoordCtxProvider(nsSVGCoordCtxProvider *parentCtx)
return NS_OK;
}
NS_IMETHODIMP
nsSVGSVGElement::GetCurrentScaleNumber(nsIDOMSVGNumber **aResult)
{
*aResult = mCurrentScale;
NS_ADDREF(*aResult);
return NS_OK;
}
NS_IMETHODIMP
nsSVGSVGElement::GetZoomAndPanEnum(nsISVGEnum **aResult)
{
*aResult = mZoomAndPan;
NS_ADDREF(*aResult);
return NS_OK;
}
//----------------------------------------------------------------------
// nsIStyledContent methods

View File

@ -103,6 +103,7 @@ XPIDLSRCS = \
nsIDOMSVGTSpanElement.idl \
nsIDOMSVGURIReference.idl \
nsIDOMSVGUseElement.idl \
nsIDOMSVGZoomAndPan.idl \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1,49 @@
/* -*- Mode: IDL; 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 IBM Corporation.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* 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 ***** */
#include "domstubs.idl"
[scriptable, uuid(18967370-921a-4245-8158-a279b190abca)]
interface nsIDOMSVGZoomAndPan : nsISupports
{
// Zoom and Pan Types
const unsigned short SVG_ZOOMANDPAN_UNKNOWN = 0;
const unsigned short SVG_ZOOMANDPAN_DISABLE = 1;
const unsigned short SVG_ZOOMANDPAN_MAGNIFY = 2;
attribute unsigned short zoomAndPan;
// raises DOMException on setting
};

View File

@ -358,6 +358,7 @@
#include "nsIDOMSVGTSpanElement.h"
#include "nsIDOMSVGURIReference.h"
#include "nsIDOMSVGUseElement.h"
#include "nsIDOMSVGZoomAndPan.h"
#endif // MOZ_SVG
#include "nsIImageDocument.h"
@ -2415,6 +2416,7 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGFitToViewBox)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGLocatable)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGStylable)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGZoomAndPan)
DOM_CLASSINFO_SVG_ELEMENT_MAP_ENTRIES
DOM_CLASSINFO_MAP_END

View File

@ -66,6 +66,12 @@
#include "nsIDeviceContext.h"
#include "nsTransform2D.h"
#endif
#include "nsISVGEnum.h"
#include "nsIDOMSVGPoint.h"
#include "nsIDOMSVGZoomAndPan.h"
#include "nsIDOMSVGAnimatedRect.h"
#include "nsIDOMSVGFitToViewBox.h"
////////////////////////////////////////////////////////////////////////
// VMRectInvalidator: helper class for invalidating rects on the viewmanager.
// used in nsSVGOuterSVGFrame::InvalidateRegion
@ -260,6 +266,11 @@ protected:
PRBool mViewportInitialized;
nsCOMPtr<nsISVGRenderer> mRenderer;
nsCOMPtr<nsIDOMSVGMatrix> mCanvasTM;
// zoom and pan
nsCOMPtr<nsISVGEnum> mZoomAndPan;
nsCOMPtr<nsIDOMSVGPoint> mCurrentTranslate;
nsCOMPtr<nsIDOMSVGNumber> mCurrentScale;
};
//----------------------------------------------------------------------
@ -302,6 +313,14 @@ nsSVGOuterSVGFrame::~nsSVGOuterSVGFrame()
#ifdef DEBUG
// printf("~nsSVGOuterSVGFrame %p\n", this);
#endif
if (mZoomAndPan)
NS_REMOVE_SVGVALUE_OBSERVER(mZoomAndPan);
if (mCurrentTranslate)
NS_REMOVE_SVGVALUE_OBSERVER(mCurrentTranslate);
if (mCurrentScale)
NS_REMOVE_SVGVALUE_OBSERVER(mCurrentScale);
RemoveAsWidthHeightObserver();
}
@ -331,6 +350,12 @@ nsresult nsSVGOuterSVGFrame::Init()
NS_ASSERTION(SVGElement, "wrong content element");
SVGElement->SetParentCoordCtxProvider(this);
SVGElement->GetZoomAndPanEnum(getter_AddRefs(mZoomAndPan));
NS_ADD_SVGVALUE_OBSERVER(mZoomAndPan);
SVGElement->GetCurrentTranslate(getter_AddRefs(mCurrentTranslate));
NS_ADD_SVGVALUE_OBSERVER(mCurrentTranslate);
SVGElement->GetCurrentScaleNumber(getter_AddRefs(mCurrentScale));
NS_ADD_SVGVALUE_OBSERVER(mCurrentScale);
AddAsWidthHeightObserver();
SuspendRedraw();
@ -1022,6 +1047,19 @@ nsSVGOuterSVGFrame::GetCanvasTM()
nsCOMPtr<nsIDOMSVGSVGElement> svgElement = do_QueryInterface(mContent);
NS_ASSERTION(svgElement, "wrong content element");
svgElement->GetViewboxToViewportTransform(getter_AddRefs(mCanvasTM));
PRUint16 val;
mZoomAndPan->GetIntegerValue(val);
if (val == nsIDOMSVGZoomAndPan::SVG_ZOOMANDPAN_MAGNIFY) {
float scale, x, y;
mCurrentScale->GetValue(&scale);
mCurrentTranslate->GetX(&x);
mCurrentTranslate->GetY(&y);
nsCOMPtr<nsIDOMSVGMatrix> tmp;
mCanvasTM->Translate(x, y, getter_AddRefs(tmp));
tmp->Scale(scale, getter_AddRefs(mCanvasTM));
}
}
nsIDOMSVGMatrix* retval = mCanvasTM.get();
NS_IF_ADDREF(retval);