From 5bbc610a608f4748827a1fe057ea5ec50023fbdd Mon Sep 17 00:00:00 2001 From: "tor%cs.brown.edu" Date: Fri, 9 Mar 2007 16:27:01 +0000 Subject: [PATCH] Bug 353172 - remove nsSVGCoordCtxProvider. Patch by malex@cs.utexas.edu and tor, r=jwatt+roc, sr=roc git-svn-id: svn://10.0.0.236/trunk@221611 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/svg/content/src/Makefile.in | 3 - .../content/svg/content/src/nsISVGLength.h | 9 +- .../svg/content/src/nsISVGLengthList.h | 64 ----- .../svg/content/src/nsISVGSVGElement.h | 10 +- .../content/svg/content/src/nsSVGCoordCtx.h | 85 ------- .../svg/content/src/nsSVGCoordCtxProvider.cpp | 163 ------------- .../svg/content/src/nsSVGCoordCtxProvider.h | 122 ---------- .../content/svg/content/src/nsSVGElement.cpp | 72 +----- .../content/svg/content/src/nsSVGElement.h | 10 +- .../svg/content/src/nsSVGFilterElement.cpp | 1 - .../content/src/nsSVGForeignObjectElement.cpp | 1 - .../svg/content/src/nsSVGGradientElement.cpp | 12 - .../svg/content/src/nsSVGGradientElement.h | 3 - .../svg/content/src/nsSVGImageElement.cpp | 1 - .../content/svg/content/src/nsSVGLength.cpp | 76 +++--- .../content/svg/content/src/nsSVGLength2.cpp | 49 ++-- .../content/svg/content/src/nsSVGLength2.h | 10 +- .../svg/content/src/nsSVGLengthList.cpp | 46 ++-- .../content/svg/content/src/nsSVGLengthList.h | 6 +- .../svg/content/src/nsSVGMarkerElement.cpp | 2 +- .../svg/content/src/nsSVGMarkerElement.h | 4 +- .../svg/content/src/nsSVGSVGElement.cpp | 229 +++++++++++------- .../content/svg/content/src/nsSVGSVGElement.h | 23 +- .../svg/content/src/nsSVGTSpanElement.cpp | 79 +----- .../svg/content/src/nsSVGTextElement.cpp | 79 +----- .../svg/content/src/nsSVGUseElement.cpp | 2 +- mozilla/layout/base/Makefile.in | 1 + .../svg/base/src/nsSVGClipPathFrame.cpp | 1 + .../svg/base/src/nsSVGContainerFrame.cpp | 9 - .../layout/svg/base/src/nsSVGContainerFrame.h | 3 +- .../svg/base/src/nsSVGGeometryFrame.cpp | 15 +- .../svg/base/src/nsSVGGradientFrame.cpp | 5 +- .../svg/base/src/nsSVGInnerSVGFrame.cpp | 36 --- .../layout/svg/base/src/nsSVGMarkerFrame.cpp | 7 +- .../layout/svg/base/src/nsSVGMarkerFrame.h | 2 +- .../layout/svg/base/src/nsSVGMaskFrame.cpp | 1 + .../svg/base/src/nsSVGOuterSVGFrame.cpp | 54 ++--- .../layout/svg/base/src/nsSVGOuterSVGFrame.h | 13 +- .../layout/svg/base/src/nsSVGPatternFrame.cpp | 2 +- .../svg/base/src/nsSVGTextPathFrame.cpp | 5 +- .../layout/svg/base/src/nsSVGTextPathFrame.h | 2 +- mozilla/layout/svg/base/src/nsSVGUtils.cpp | 41 +--- mozilla/layout/svg/base/src/nsSVGUtils.h | 11 +- 43 files changed, 359 insertions(+), 1010 deletions(-) delete mode 100644 mozilla/content/svg/content/src/nsISVGLengthList.h delete mode 100644 mozilla/content/svg/content/src/nsSVGCoordCtx.h delete mode 100644 mozilla/content/svg/content/src/nsSVGCoordCtxProvider.cpp delete mode 100644 mozilla/content/svg/content/src/nsSVGCoordCtxProvider.h diff --git a/mozilla/content/svg/content/src/Makefile.in b/mozilla/content/svg/content/src/Makefile.in index 17dcc8c3d33..ef1e3fdaab2 100644 --- a/mozilla/content/svg/content/src/Makefile.in +++ b/mozilla/content/svg/content/src/Makefile.in @@ -83,7 +83,6 @@ CPPSRCS = \ nsSVGCircleElement.cpp \ nsSVGClassValue.cpp \ nsSVGClipPathElement.cpp \ - nsSVGCoordCtxProvider.cpp \ nsSVGDataParser.cpp \ nsSVGDefsElement.cpp \ nsSVGDescElement.cpp \ @@ -159,8 +158,6 @@ EXPORTS = \ nsISVGValue.h \ nsISVGValueObserver.h \ nsISVGValueUtils.h \ - nsSVGCoordCtxProvider.h \ - nsSVGCoordCtx.h \ nsSVGNumber.h \ nsSVGRect.h \ nsSVGPoint.h \ diff --git a/mozilla/content/svg/content/src/nsISVGLength.h b/mozilla/content/svg/content/src/nsISVGLength.h index b224392b527..cd7648c6e1f 100644 --- a/mozilla/content/svg/content/src/nsISVGLength.h +++ b/mozilla/content/svg/content/src/nsISVGLength.h @@ -40,22 +40,21 @@ #define __NS_ISVGLENGTH_H__ #include "nsIDOMSVGLength.h" - -class nsSVGCoordCtx; +#include "nsWeakPtr.h" //////////////////////////////////////////////////////////////////////// // nsISVGLength: private interface for svg lengths -// {ADFA6DD4-7E59-4FA2-BF55-BCE7D40C9F88} +// {DB02FD38-3C77-4c52-8DBD-C0A47F9DEDAD} #define NS_ISVGLENGTH_IID \ -{ 0xadfa6dd4, 0x7e59, 0x4fa2, { 0xbf, 0x55, 0xbc, 0xe7, 0xd4, 0x0c, 0x9f, 0x88 } } +{ 0xdb02fd38, 0x3c77, 0x4c52, { 0x8d, 0xbd, 0xc0, 0xa4, 0x7f, 0x9d, 0xed, 0xad } } class nsISVGLength : public nsIDOMSVGLength { public: NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISVGLENGTH_IID) - NS_IMETHOD SetContext(nsSVGCoordCtx* ctx)=0; + NS_IMETHOD SetContext(nsIWeakReference *aContext, PRUint8 aCtxType)=0; }; NS_DEFINE_STATIC_IID_ACCESSOR(nsISVGLength, NS_ISVGLENGTH_IID) diff --git a/mozilla/content/svg/content/src/nsISVGLengthList.h b/mozilla/content/svg/content/src/nsISVGLengthList.h deleted file mode 100644 index d10028e2dfc..00000000000 --- a/mozilla/content/svg/content/src/nsISVGLengthList.h +++ /dev/null @@ -1,64 +0,0 @@ -/* -*- 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) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Alex Fritze (original author) - * - * 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_ISVGLENGTHLIST_H__ -#define __NS_ISVGLENGTHLIST_H__ - -#include "nsIDOMSVGLengthList.h" - -class nsSVGCoordCtx; - -//////////////////////////////////////////////////////////////////////// -// nsISVGLengthList: private interface for svg lengthlists - -// {0857CC15-896D-4E3B-A985-125B398C7867} -#define NS_ISVGLENGTHLIST_IID \ -{ 0x0857cc15, 0x896d, 0x4e3b, { 0xa9, 0x85, 0x12, 0x5b, 0x39, 0x8c, 0x78, 0x67 } } - - -class nsISVGLengthList : public nsIDOMSVGLengthList -{ -public: - NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISVGLENGTHLIST_IID) - - NS_IMETHOD SetContext(nsSVGCoordCtx* ctx)=0; -}; - -NS_DEFINE_STATIC_IID_ACCESSOR(nsISVGLengthList, NS_ISVGLENGTHLIST_IID) - -#endif // __NS_ISVGLENGTHLIST_H__ diff --git a/mozilla/content/svg/content/src/nsISVGSVGElement.h b/mozilla/content/svg/content/src/nsISVGSVGElement.h index 0bf3765b293..b6e1e121e53 100644 --- a/mozilla/content/svg/content/src/nsISVGSVGElement.h +++ b/mozilla/content/svg/content/src/nsISVGSVGElement.h @@ -43,7 +43,7 @@ #include "nsISupports.h" #include "nsIDOMSVGSVGElement.h" -class nsSVGCoordCtxProvider; +class nsSVGSVGElement; class nsIDOMSVGNumber; class nsISVGEnum; @@ -51,14 +51,13 @@ class nsISVGEnum; // nsISVGSVGElement: private interface implemented by -elements #define NS_ISVGSVGELEMENT_IID \ -{ 0x7f22b121, 0x9522, 0x4840, { 0xb1, 0x0e, 0x07, 0x48, 0xfa, 0xe1, 0xb3, 0xf8 } } +{ 0x65195064, 0x9a5f, 0x42df, { 0xa1, 0x1f, 0x4c, 0x05, 0xbc, 0xa4, 0xe7, 0x28 } } class nsISVGSVGElement : public nsIDOMSVGSVGElement { public: NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISVGSVGELEMENT_IID) - NS_IMETHOD SetParentCoordCtxProvider(nsSVGCoordCtxProvider *parentCtx)=0; NS_IMETHOD GetCurrentScaleNumber(nsIDOMSVGNumber **aResult)=0; NS_IMETHOD GetZoomAndPanEnum(nsISVGEnum **aResult)=0; @@ -89,11 +88,6 @@ public: NS_IMETHOD_(float) GetPreviousScale()=0; NS_IMETHOD_(float) GetPreviousTranslate_x()=0; NS_IMETHOD_(float) GetPreviousTranslate_y()=0; - - /** - * Our viewport or viewbox is changing - throw away the cached value. - */ - NS_IMETHOD_(void) InvalidateViewBoxToViewport()=0; }; NS_DEFINE_STATIC_IID_ACCESSOR(nsISVGSVGElement, NS_ISVGSVGELEMENT_IID) diff --git a/mozilla/content/svg/content/src/nsSVGCoordCtx.h b/mozilla/content/svg/content/src/nsSVGCoordCtx.h deleted file mode 100644 index 7e598619b7c..00000000000 --- a/mozilla/content/svg/content/src/nsSVGCoordCtx.h +++ /dev/null @@ -1,85 +0,0 @@ -/* -*- 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) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Alex Fritze (original author) - * - * 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_NSSVGCOORDCTX_H__ -#define __NS_NSSVGCOORDCTX_H__ - -#include "nsCOMPtr.h" -#include "nsIDOMSVGNumber.h" -#include "nsSVGNumber.h" - -//////////////////////////////////////////////////////////////////////// -// nsSVGCoordCtx: ref-counted class used as a context for -// percentage/unit-based calculation on svg lengths - -class nsSVGCoordCtx -{ -public: - float GetMillimeterPerPixel() { return mmPerPx; } - - already_AddRefed GetLength() { - nsIDOMSVGNumber *rv = mLength.get(); - NS_IF_ADDREF(rv); - return rv; - } - - - nsrefcnt AddRef() { return ++mRefCnt; } - nsrefcnt Release() { - --mRefCnt; - if (mRefCnt == 0) { - mRefCnt = 1; // stabilize - delete this; - return 0; - } - return mRefCnt; - } - -protected: - friend class nsSVGCoordCtxHolder; - - nsSVGCoordCtx() : mRefCnt(1) { // addrefs - NS_NewSVGNumber(getter_AddRefs(mLength)); - } - - PRUint32 mRefCnt; - float mmPerPx; - nsCOMPtr mLength; -}; - -#endif // __NS_NSSVGCOORDCTX_H__ diff --git a/mozilla/content/svg/content/src/nsSVGCoordCtxProvider.cpp b/mozilla/content/svg/content/src/nsSVGCoordCtxProvider.cpp deleted file mode 100644 index dc74f501fcd..00000000000 --- a/mozilla/content/svg/content/src/nsSVGCoordCtxProvider.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* -*- 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) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Alex Fritze (original author) - * - * 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 "nsSVGCoordCtxProvider.h" -#include "nsISVGValue.h" -#include "nsISVGValueUtils.h" -#include "nsSVGUtils.h" -#include - -//////////////////////////////////////////////////////////////////////// -// nsSVGCoordCtxHolder implementation - -nsSVGCoordCtxHolder::nsSVGCoordCtxHolder() - : mCtxX(dont_AddRef(new nsSVGCoordCtx)), - mCtxY(dont_AddRef(new nsSVGCoordCtx)), - mCtxUnspec(dont_AddRef(new nsSVGCoordCtx)) -{} - -nsSVGCoordCtxHolder::~nsSVGCoordCtxHolder() -{ - if (mCtxRect) - NS_REMOVE_SVGVALUE_OBSERVER(mCtxRect); -} - -//---------------------------------------------------------------------- -// nsISupports methods: - -NS_IMPL_ADDREF(nsSVGCoordCtxHolder) -NS_IMPL_RELEASE(nsSVGCoordCtxHolder) - -NS_INTERFACE_MAP_BEGIN(nsSVGCoordCtxHolder) - NS_INTERFACE_MAP_ENTRY(nsISVGValueObserver) - NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsISVGValueObserver) -NS_INTERFACE_MAP_END - -//---------------------------------------------------------------------- -// nsISVGValueObserver methods: - -NS_IMETHODIMP -nsSVGCoordCtxHolder::WillModifySVGObservable(nsISVGValue* observable, - nsISVGValue::modificationType aModType) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsSVGCoordCtxHolder::DidModifySVGObservable(nsISVGValue* observable, - nsISVGValue::modificationType aModType) -{ - Update(); - return NS_OK; -} - -//---------------------------------------------------------------------- - -void -nsSVGCoordCtxHolder::SetContextRect(nsIDOMSVGRect* ctxRect) -{ - if (mCtxRect) - NS_REMOVE_SVGVALUE_OBSERVER(mCtxRect); - mCtxRect = ctxRect; - if (mCtxRect) { - NS_ADD_SVGVALUE_OBSERVER(mCtxRect); - Update(); - } -} - -void -nsSVGCoordCtxHolder::SetMMPerPx(float mmPerPxX, float mmPerPxY) -{ - mCtxX->mmPerPx = mmPerPxX; - mCtxY->mmPerPx = mmPerPxY; - mCtxUnspec->mmPerPx = (float)sqrt((mmPerPxX*mmPerPxX + mmPerPxY*mmPerPxY)/2.0); -} - -void -nsSVGCoordCtxHolder::Update() -{ - float w,h; - mCtxRect->GetWidth(&w); - mCtxRect->GetHeight(&h); - mCtxX->mLength->SetValue(w); - mCtxY->mLength->SetValue(h); - mCtxUnspec->mLength->SetValue((float)sqrt((w*w+h*h)/2.0)); -} - -already_AddRefed -nsSVGCoordCtxHolder::GetContextX() -{ - nsSVGCoordCtx *rv = mCtxX.get(); - NS_IF_ADDREF(rv); - return rv; -} - -already_AddRefed -nsSVGCoordCtxHolder::GetContextY() -{ - nsSVGCoordCtx *rv = mCtxY.get(); - NS_IF_ADDREF(rv); - return rv; -} - -already_AddRefed -nsSVGCoordCtxHolder::GetContextUnspecified() -{ - nsSVGCoordCtx *rv = mCtxUnspec.get(); - NS_IF_ADDREF(rv); - return rv; -} - -already_AddRefed -nsSVGCoordCtxProvider::GetCtxByType(PRUint16 aCtxType) -{ - if (!mInner) - return nsnull; - - switch (aCtxType) { - case nsSVGUtils::X: - return mInner->GetContextX(); - case nsSVGUtils::Y: - return mInner->GetContextY(); - case nsSVGUtils::XY: - return mInner->GetContextUnspecified(); - } - - return nsnull; -} diff --git a/mozilla/content/svg/content/src/nsSVGCoordCtxProvider.h b/mozilla/content/svg/content/src/nsSVGCoordCtxProvider.h deleted file mode 100644 index b842cb6154b..00000000000 --- a/mozilla/content/svg/content/src/nsSVGCoordCtxProvider.h +++ /dev/null @@ -1,122 +0,0 @@ -/* -*- 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) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Alex Fritze (original author) - * - * 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_SVGCOORDCTXPROVIDER_H__ -#define __NS_SVGCOORDCTXPROVIDER_H__ - -#include "nsCOMPtr.h" -#include "nsAutoPtr.h" -#include "nsSVGCoordCtx.h" -#include "nsIDOMSVGRect.h" -#include "nsISVGValueObserver.h" -#include "nsWeakReference.h" - -//////////////////////////////////////////////////////////////////////// -// nsSVGCoordCtxHolder: This is a private inner helper class for -// nsSVGCoordCtxProvider. It holds the actual coordinate contexts; the -// accessors (GetContextX,etc.) on nsSVGCoordCtxProvider are delegated -// to it. The sole purpose for having this separate inner class is to -// hide the nsISVGValueObserver interface which we require to listen -// in on viewbox (mCtxRect) size changes. - -class nsSVGCoordCtxHolder : nsISVGValueObserver -{ -private: - friend class nsSVGCoordCtxProvider; - nsSVGCoordCtxHolder(); // addrefs - ~nsSVGCoordCtxHolder(); - - // nsISupports interface: - NS_DECL_ISUPPORTS - - // nsISVGValueObserver interface: - NS_IMETHOD WillModifySVGObservable(nsISVGValue* observable, - nsISVGValue::modificationType aModType); - NS_IMETHOD DidModifySVGObservable (nsISVGValue* observable, - nsISVGValue::modificationType aModType); - - void SetContextRect(nsIDOMSVGRect* ctxRect); - void SetMMPerPx(float mmPerPxX, float mmPerPxY); - - void Update(); - - already_AddRefed GetContextX(); - already_AddRefed GetContextY(); - already_AddRefed GetContextUnspecified(); - - nsCOMPtr mCtxRect; - nsRefPtr mCtxX; - nsRefPtr mCtxY; - nsRefPtr mCtxUnspec; -}; - -//////////////////////////////////////////////////////////////////////// -// pseudo interface nsSVGCoordCtxProvider - -// {0C083184-4462-4B5D-B925-0BEC5A7E6779} -#define NS_SVGCOORDCTXPROVIDER_IID \ -{ 0x0c083184, 0x4462, 0x4b5d, { 0xb9, 0x25, 0x0b, 0xec, 0x5a, 0x7e, 0x67, 0x79 } } - -class nsSVGCoordCtxProvider : public nsISupports -{ -public: - NS_DECLARE_STATIC_IID_ACCESSOR(NS_SVGCOORDCTXPROVIDER_IID) - - nsSVGCoordCtxProvider() : mInner(new nsSVGCoordCtxHolder) {} - - already_AddRefed GetContextX() { return mInner ? mInner->GetContextX() : nsnull; } - already_AddRefed GetContextY() { return mInner ? mInner->GetContextY() : nsnull; } - already_AddRefed GetContextUnspecified() { return mInner ? mInner->GetContextUnspecified() : nsnull; } - - already_AddRefed GetCtxByType(PRUint16 aCtxType); - -protected: - void SetCoordCtxRect(nsIDOMSVGRect* ctxRect) { if(mInner) mInner->SetContextRect(ctxRect); } - void SetCoordCtxMMPerPx(float mmPerPxX, float mmPerPxY) { - if(mInner) - mInner->SetMMPerPx(mmPerPxX, mmPerPxY); - } - -private: - nsRefPtr mInner; -}; - -NS_DEFINE_STATIC_IID_ACCESSOR(nsSVGCoordCtxProvider, - NS_SVGCOORDCTXPROVIDER_IID) - -#endif // __NS_SVGCOORDCTXPROVIDER_H__ diff --git a/mozilla/content/svg/content/src/nsSVGElement.cpp b/mozilla/content/svg/content/src/nsSVGElement.cpp index 5e70a41b13d..749b5cf1a03 100644 --- a/mozilla/content/svg/content/src/nsSVGElement.cpp +++ b/mozilla/content/svg/content/src/nsSVGElement.cpp @@ -37,6 +37,7 @@ * ***** END LICENSE BLOCK ***** */ #include "nsSVGElement.h" +#include "nsSVGSVGElement.h" #include "nsIDocument.h" #include "nsRange.h" #include "nsIDOMAttr.h" @@ -65,8 +66,6 @@ #include "nsIScriptGlobalObject.h" #include "nsIEventListenerManager.h" #include "nsSVGUtils.h" -#include "nsSVGCoordCtxProvider.h" -#include "nsSVGCoordCtx.h" #include "nsSVGLength2.h" #include "nsSVGNumber2.h" #include @@ -128,28 +127,6 @@ NS_INTERFACE_MAP_END_INHERITING(nsGenericElement) //---------------------------------------------------------------------- // nsIContent methods -nsresult -nsSVGElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, - nsIContent* aBindingParent, - PRBool aCompileEventHandlers) -{ - nsresult rv = nsGenericElement::BindToTree(aDocument, aParent, - aBindingParent, - aCompileEventHandlers); - NS_ENSURE_SUCCESS(rv, rv); - - ParentChainChanged(); - - return rv; -} - -void -nsSVGElement::UnbindFromTree(PRBool aDeep, PRBool aNullParent) -{ - nsGenericElement::UnbindFromTree(aDeep, aNullParent); - ParentChainChanged(); -} - nsIAtom * nsSVGElement::GetIDAttributeName() const { @@ -678,33 +655,6 @@ nsSVGElement::DidModifySVGObservable(nsISVGValue* aObservable, modification, hasListeners, PR_TRUE); } -//---------------------------------------------------------------------- - -// recursive helper to call ParentChainChanged across non-SVG elements -static void CallParentChainChanged(nsIContent*elem) -{ - NS_ASSERTION(elem, "null element"); - - PRUint32 count = elem->GetChildCount(); - for (PRUint32 i=0; iGetChildAt(i); - if (child && child->IsNodeOfType(nsINode::eSVG)) { - NS_STATIC_CAST(nsSVGElement*, child)->ParentChainChanged(); - } - else { - // non-svg element might have an svg child, so recurse - CallParentChainChanged(child); - } - } -} - -void -nsSVGElement::ParentChainChanged() -{ - CallParentChainChanged(this); -} - - //---------------------------------------------------------------------- // Implementation Helpers: @@ -877,22 +827,12 @@ nsIAtom* nsSVGElement::GetEventNameForAttr(nsIAtom* aAttr) return aAttr; } -nsSVGCoordCtx * -nsSVGElement::GetCtxByType(PRUint16 aCtxType) +nsSVGSVGElement * +nsSVGElement::GetCtx() { nsCOMPtr svg; GetOwnerSVGElement(getter_AddRefs(svg)); - - // outermost svg? - if (!svg) - return nsnull; - - nsCOMPtr ctx = do_QueryInterface(svg); - - nsRefPtr rv = ctx->GetCtxByType(aCtxType); - - // ugh... - return rv.get(); + return NS_STATIC_CAST(nsSVGSVGElement*, svg.get()); } nsSVGElement::LengthAttributesInfo @@ -929,7 +869,7 @@ nsSVGElement::GetAnimatedLengthValues(float *aFirst, ...) NS_ASSERTION(info.mLengthCount > 0, "GetAnimatedLengthValues on element with no length attribs"); - nsCOMPtr ctx; + nsSVGSVGElement *ctx = nsnull; float *f = aFirst; PRUint32 i = 0; @@ -942,7 +882,7 @@ nsSVGElement::GetAnimatedLengthValues(float *aFirst, ...) PRUint8 type = info.mLengths[i].GetSpecifiedUnitType(); if (type != nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER && type != nsIDOMSVGLength::SVG_LENGTHTYPE_PX) - ctx = nsSVGUtils::GetCoordContextProvider(this); + ctx = GetCtx(); } *f = info.mLengths[i++].GetAnimValue(ctx); f = va_arg(args, float*); diff --git a/mozilla/content/svg/content/src/nsSVGElement.h b/mozilla/content/svg/content/src/nsSVGElement.h index e4d0bcd11ca..c5a6795d96d 100644 --- a/mozilla/content/svg/content/src/nsSVGElement.h +++ b/mozilla/content/svg/content/src/nsSVGElement.h @@ -53,7 +53,7 @@ #include "nsWeakReference.h" #include "nsICSSStyleRule.h" -class nsSVGCoordCtx; +class nsSVGSVGElement; class nsSVGLength2; class nsSVGNumber2; @@ -71,11 +71,6 @@ public: // nsIContent interface methods - virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent, - nsIContent* aBindingParent, - PRBool aCompileEventHandlers); - virtual void UnbindFromTree(PRBool aDeep = PR_TRUE, - PRBool aNullParent = PR_TRUE); virtual nsIAtom *GetIDAttributeName() const; virtual nsIAtom *GetClassAttributeName() const; virtual nsresult UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute, @@ -116,9 +111,8 @@ public: // nsISupportsWeakReference // implementation inherited from nsSupportsWeakReference - nsSVGCoordCtx *GetCtxByType(PRUint16 aCtxType); + nsSVGSVGElement* GetCtx(); - virtual void ParentChainChanged(); virtual void DidChangeLength(PRUint8 aAttrEnum, PRBool aDoSetAttr); virtual void DidChangeNumber(PRUint8 aAttrEnum, PRBool aDoSetAttr); diff --git a/mozilla/content/svg/content/src/nsSVGFilterElement.cpp b/mozilla/content/svg/content/src/nsSVGFilterElement.cpp index bf184e5dba8..b04f846ca5c 100644 --- a/mozilla/content/svg/content/src/nsSVGFilterElement.cpp +++ b/mozilla/content/svg/content/src/nsSVGFilterElement.cpp @@ -38,7 +38,6 @@ #include "nsSVGLength.h" #include "nsCOMPtr.h" #include "nsISVGSVGElement.h" -#include "nsSVGCoordCtxProvider.h" #include "nsSVGAnimatedEnumeration.h" #include "nsSVGAnimatedInteger.h" #include "nsSVGAnimatedString.h" diff --git a/mozilla/content/svg/content/src/nsSVGForeignObjectElement.cpp b/mozilla/content/svg/content/src/nsSVGForeignObjectElement.cpp index 6c2c4d02daf..b222d43eeef 100644 --- a/mozilla/content/svg/content/src/nsSVGForeignObjectElement.cpp +++ b/mozilla/content/svg/content/src/nsSVGForeignObjectElement.cpp @@ -39,7 +39,6 @@ #include "nsSVGLength.h" #include "nsCOMPtr.h" #include "nsISVGSVGElement.h" -#include "nsSVGCoordCtxProvider.h" #include "nsSVGForeignObjectElement.h" nsSVGElement::LengthInfo nsSVGForeignObjectElement::sLengthInfo[4] = diff --git a/mozilla/content/svg/content/src/nsSVGGradientElement.cpp b/mozilla/content/svg/content/src/nsSVGGradientElement.cpp index 54e214ad41d..cdf8f515f94 100644 --- a/mozilla/content/svg/content/src/nsSVGGradientElement.cpp +++ b/mozilla/content/svg/content/src/nsSVGGradientElement.cpp @@ -180,18 +180,6 @@ nsSVGGradientElement::GetHref(nsIDOMSVGAnimatedString * *aHref) return NS_OK; } -//---------------------------------------------------------------------- -// nsSVGElement methods - -void nsSVGGradientElement::ParentChainChanged() -{ - // Gradient length properties are relative to the target element - // (the one calling the gradient), so we don't set their - // contexts here. - // Also, gradient child elements (stops) don't have any length - // properties, so no need to recurse into children here. -} - //---------------------------------------------------------------------- // nsIContent methods diff --git a/mozilla/content/svg/content/src/nsSVGGradientElement.h b/mozilla/content/svg/content/src/nsSVGGradientElement.h index bb75fb26018..6946977256f 100644 --- a/mozilla/content/svg/content/src/nsSVGGradientElement.h +++ b/mozilla/content/svg/content/src/nsSVGGradientElement.h @@ -66,9 +66,6 @@ public: // URI Reference NS_DECL_NSIDOMSVGURIREFERENCE - // nsSVGElement specializations: - virtual void ParentChainChanged(); - // nsIContent NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const; diff --git a/mozilla/content/svg/content/src/nsSVGImageElement.cpp b/mozilla/content/svg/content/src/nsSVGImageElement.cpp index 0d1f7c2f691..9365698f41a 100644 --- a/mozilla/content/svg/content/src/nsSVGImageElement.cpp +++ b/mozilla/content/svg/content/src/nsSVGImageElement.cpp @@ -41,7 +41,6 @@ #include "nsSVGAnimatedString.h" #include "nsCOMPtr.h" #include "nsISVGSVGElement.h" -#include "nsSVGCoordCtxProvider.h" #include "nsIURI.h" #include "nsNetUtil.h" #include "nsSVGAnimatedPreserveAspectRatio.h" diff --git a/mozilla/content/svg/content/src/nsSVGLength.cpp b/mozilla/content/svg/content/src/nsSVGLength.cpp index b59b5e70d56..fa0895ac11a 100644 --- a/mozilla/content/svg/content/src/nsSVGLength.cpp +++ b/mozilla/content/svg/content/src/nsSVGLength.cpp @@ -39,16 +39,18 @@ #include "nsSVGLength.h" #include "nsIDOMSVGMatrix.h" +#include "nsIDOMSVGRect.h" #include "nsGkAtoms.h" #include "nsSVGValue.h" #include "nsTextFormatter.h" #include "prdtoa.h" #include "nsCRT.h" -#include "nsSVGCoordCtx.h" +#include "nsSVGSVGElement.h" #include "nsIDOMSVGNumber.h" #include "nsISVGValueUtils.h" #include "nsWeakReference.h" #include "nsContentUtils.h" +#include "nsIDOMSVGAnimatedRect.h" //////////////////////////////////////////////////////////////////////// // nsSVGLength class @@ -77,8 +79,8 @@ public: NS_DECL_NSIDOMSVGLENGTH // nsISVGLength interface: - NS_IMETHOD SetContext(nsSVGCoordCtx* context); - + NS_IMETHOD SetContext(nsIWeakReference *aContext, PRUint8 aCtxType); + // nsISVGValue interface: NS_IMETHOD SetValueString(const nsAString& aValue); NS_IMETHOD GetValueString(nsAString& aValue); @@ -99,10 +101,14 @@ protected: PRBool IsValidUnitType(PRUint16 unit); void MaybeAddAsObserver(); void MaybeRemoveAsObserver(); - + + // helper - returns a rect if we need to observe it (percentage length) + already_AddRefed MaybeGetCtxRect(); + + nsWeakPtr mElement; // owning element - weakptr to avoid reference loop float mValueInSpecifiedUnits; PRUint16 mSpecifiedUnitType; - nsRefPtr mContext; + PRUint8 mCtxType; }; @@ -143,7 +149,8 @@ NS_NewSVGLength(nsISVGLength** result, nsSVGLength::nsSVGLength(float value, PRUint16 unit) : mValueInSpecifiedUnits(value), - mSpecifiedUnitType(unit) + mSpecifiedUnitType(unit), + mCtxType(0) { // we don't have a context yet, so we don't call MaybeAddAsObserver() } @@ -486,7 +493,7 @@ nsSVGLength::ConvertToSpecifiedUnits(PRUint16 unitType) //---------------------------------------------------------------------- // nsISVGLength methods: NS_IMETHODIMP -nsSVGLength::SetContext(nsSVGCoordCtx* context) +nsSVGLength::SetContext(nsIWeakReference *aContext, PRUint8 aCtxType) { /* Unless our unit type is SVG_LENGTHTYPE_NUMBER or SVG_LENGTHTYPE_PX, our user unit value is determined by our context and we must notify our @@ -498,7 +505,8 @@ nsSVGLength::SetContext(nsSVGCoordCtx* context) MaybeRemoveAsObserver(); } - mContext = context; + mElement = aContext; + mCtxType = aCtxType; if (mSpecifiedUnitType != SVG_LENGTHTYPE_NUMBER && mSpecifiedUnitType != SVG_LENGTHTYPE_PX) { @@ -514,32 +522,35 @@ nsSVGLength::SetContext(nsSVGCoordCtx* context) float nsSVGLength::mmPerPixel() { - if (!mContext) { + nsCOMPtr element = do_QueryReferent(mElement); + if (!element) { NS_WARNING("no context in mmPerPixel()"); return 1.0f; } - - float mmPerPx = mContext->GetMillimeterPerPixel(); + + nsSVGSVGElement *ctx = + NS_STATIC_CAST(nsSVGElement*, element.get())->GetCtx(); + float mmPerPx = ctx->GetMMPerPx(mCtxType); if (mmPerPx == 0.0f) { NS_ASSERTION(mmPerPx != 0.0f, "invalid mm/pixels"); mmPerPx = 1e-4f; // some small value } - + return mmPerPx; } float nsSVGLength::AxisLength() { - if (!mContext) { + nsCOMPtr element = do_QueryReferent(mElement); + if (!element) { NS_WARNING("no context in AxisLength()"); return 1.0f; } - nsCOMPtr num = mContext->GetLength(); - NS_ASSERTION(num != nsnull, "null interface"); - float d; - num->GetValue(&d); + nsSVGSVGElement *ctx = + NS_STATIC_CAST(nsSVGElement*, element.get())->GetCtx(); + float d = ctx->GetLength(mCtxType); if (d == 0.0f) { NS_WARNING("zero axis length"); @@ -557,21 +568,32 @@ PRBool nsSVGLength::IsValidUnitType(PRUint16 unit) return PR_FALSE; } +already_AddRefed nsSVGLength::MaybeGetCtxRect() +{ + if ((mSpecifiedUnitType == SVG_LENGTHTYPE_PERCENTAGE) && mElement) { + nsCOMPtr element = do_QueryReferent(mElement); + if (element) { + nsSVGSVGElement *ctx = + NS_STATIC_CAST(nsSVGElement*, element.get())->GetCtx(); + if (ctx) + return ctx->GetCtxRect(); + } + } + + return nsnull; +} + void nsSVGLength::MaybeAddAsObserver() { - if ((mSpecifiedUnitType==SVG_LENGTHTYPE_PERCENTAGE) && - mContext) { - nsCOMPtr num = mContext->GetLength(); - NS_ADD_SVGVALUE_OBSERVER(num); - } + nsCOMPtr rect = MaybeGetCtxRect(); + if (rect) + NS_ADD_SVGVALUE_OBSERVER(rect); } void nsSVGLength::MaybeRemoveAsObserver() { - if ((mSpecifiedUnitType==SVG_LENGTHTYPE_PERCENTAGE) && - mContext) { - nsCOMPtr num = mContext->GetLength(); - NS_REMOVE_SVGVALUE_OBSERVER(num); - } + nsCOMPtr rect = MaybeGetCtxRect(); + if (rect) + NS_REMOVE_SVGVALUE_OBSERVER(rect); } diff --git a/mozilla/content/svg/content/src/nsSVGLength2.cpp b/mozilla/content/svg/content/src/nsSVGLength2.cpp index 6f795e11fb6..8f32f154c17 100644 --- a/mozilla/content/svg/content/src/nsSVGLength2.cpp +++ b/mozilla/content/svg/content/src/nsSVGLength2.cpp @@ -42,7 +42,8 @@ #include "prdtoa.h" #include "nsCRT.h" #include "nsTextFormatter.h" -#include "nsSVGCoordCtx.h" +#include "nsIDOMSVGNumber.h" +#include "nsSVGSVGElement.h" NS_IMPL_ADDREF(nsSVGLength2::DOMBaseVal) NS_IMPL_RELEASE(nsSVGLength2::DOMBaseVal) @@ -135,32 +136,29 @@ GetValueString(nsAString &aValueAsString, float aValue, PRUint16 aUnitType) aValueAsString.Append(unitString); } -static float -GetMMPerPixel(nsSVGCoordCtx *aCtx) +float +nsSVGLength2::GetMMPerPixel(nsSVGSVGElement *aCtx) { if (!aCtx) return 1; - float mmPerPx = aCtx->GetMillimeterPerPixel(); + float mmPerPx = aCtx->GetMMPerPx(mCtxType); if (mmPerPx == 0.0f) { NS_ASSERTION(mmPerPx != 0.0f, "invalid mm/pixels"); mmPerPx = 1e-4f; // some small value } - + return mmPerPx; } -static float -GetAxisLength(nsSVGCoordCtx *aCtx) +float +nsSVGLength2::GetAxisLength(nsSVGSVGElement *aCtx) { if (!aCtx) return 1; - nsCOMPtr num = aCtx->GetLength(); - NS_ASSERTION(num != nsnull, "null interface"); - float d; - num->GetValue(&d); + float d = aCtx->GetLength(mCtxType); if (d == 0.0f) { NS_WARNING("zero axis length"); @@ -254,30 +252,15 @@ nsSVGLength2::GetAnimValueString(nsAString & aValueAsString) float nsSVGLength2::ConvertToUserUnits(float aVal, nsSVGElement *aSVGElement) { - nsSVGCoordCtx *ctx = nsnull; + if (mSpecifiedUnitType == nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER || + mSpecifiedUnitType == nsIDOMSVGLength::SVG_LENGTHTYPE_PX) + return aVal; - if (mSpecifiedUnitType != nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER && - mSpecifiedUnitType != nsIDOMSVGLength::SVG_LENGTHTYPE_PX) - ctx = aSVGElement->GetCtxByType(mCtxType); - - return ConvertToUserUnits(aVal, ctx); + return ConvertToUserUnits(aVal, aSVGElement->GetCtx()); } float -nsSVGLength2::ConvertToUserUnits(float aVal, nsSVGCoordCtxProvider *aProvider) -{ - nsSVGCoordCtx *ctx = nsnull; - - if (aProvider && - mSpecifiedUnitType != nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER && - mSpecifiedUnitType != nsIDOMSVGLength::SVG_LENGTHTYPE_PX) - ctx = aProvider->GetCtxByType(mCtxType).get(); - - return ConvertToUserUnits(aVal, ctx); -} - -float -nsSVGLength2::ConvertToUserUnits(float aVal, nsSVGCoordCtx *aCtx) +nsSVGLength2::ConvertToUserUnits(float aVal, nsSVGSVGElement *aCtx) { switch (mSpecifiedUnitType) { case nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER: @@ -308,11 +291,11 @@ nsSVGLength2::ConvertToUserUnits(float aVal, nsSVGCoordCtx *aCtx) void nsSVGLength2::SetBaseValue(float aValue, nsSVGElement *aSVGElement) { - nsSVGCoordCtx *ctx = nsnull; + nsSVGSVGElement *ctx = nsnull; if (mSpecifiedUnitType != nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER && mSpecifiedUnitType != nsIDOMSVGLength::SVG_LENGTHTYPE_PX) - ctx = aSVGElement->GetCtxByType(mCtxType); + ctx = aSVGElement->GetCtx(); switch (mSpecifiedUnitType) { case nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER: diff --git a/mozilla/content/svg/content/src/nsSVGLength2.h b/mozilla/content/svg/content/src/nsSVGLength2.h index 8b0a4741c27..5ea600c65c6 100644 --- a/mozilla/content/svg/content/src/nsSVGLength2.h +++ b/mozilla/content/svg/content/src/nsSVGLength2.h @@ -42,7 +42,6 @@ #include "nsSVGUtils.h" #include "nsSVGElement.h" #include "nsDOMError.h" -#include "nsSVGCoordCtxProvider.h" class nsSVGLength2 { @@ -81,9 +80,9 @@ public: float GetAnimValInSpecifiedUnits() { return mAnimVal; } float GetBaseValInSpecifiedUnits() { return mBaseVal; } - float GetBaseValue(nsSVGCoordCtxProvider* aProvider) + float GetBaseValue(nsSVGSVGElement* aProvider) { return ConvertToUserUnits(mBaseVal, aProvider); } - float GetAnimValue(nsSVGCoordCtxProvider* aProvider) + float GetAnimValue(nsSVGSVGElement* aProvider) { return ConvertToUserUnits(mAnimVal, aProvider); } nsresult ToDOMBaseVal(nsIDOMSVGLength **aResult, nsSVGElement* aSVGElement); @@ -100,9 +99,10 @@ private: PRUint8 mCtxType; // X, Y or Unspecified PRPackedBool mIsAnimated; - float ConvertToUserUnits(float aValue, nsSVGCoordCtx *aCtx); + float GetMMPerPixel(nsSVGSVGElement *aCtx); + float GetAxisLength(nsSVGSVGElement *aCtx); float ConvertToUserUnits(float aValue, nsSVGElement *aSVGElement); - float ConvertToUserUnits(float aValue, nsSVGCoordCtxProvider *aProvider); + float ConvertToUserUnits(float aValue, nsSVGSVGElement *aProvider); void SetBaseValue(float aValue, nsSVGElement *aSVGElement); void SetBaseValueInSpecifiedUnits(float aValue, nsSVGElement *aSVGElement); void NewValueSpecifiedUnits(PRUint16 aUnitType, float aValue, diff --git a/mozilla/content/svg/content/src/nsSVGLengthList.cpp b/mozilla/content/svg/content/src/nsSVGLengthList.cpp index e5f1128ec40..0159d1d3056 100644 --- a/mozilla/content/svg/content/src/nsSVGLengthList.cpp +++ b/mozilla/content/svg/content/src/nsSVGLengthList.cpp @@ -43,7 +43,7 @@ #include "nsVoidArray.h" #include "nsDOMError.h" #include "nsReadableUtils.h" -#include "nsSVGCoordCtx.h" +#include "nsSVGSVGElement.h" #include "nsCRT.h" #include "nsISVGValueUtils.h" #include "nsContentUtils.h" @@ -51,14 +51,15 @@ //////////////////////////////////////////////////////////////////////// // nsSVGLengthList -class nsSVGLengthList : public nsISVGLengthList, +class nsSVGLengthList : public nsIDOMSVGLengthList, public nsSVGValue, public nsISVGValueObserver { protected: - friend nsresult NS_NewSVGLengthList(nsISVGLengthList** result); + friend nsresult NS_NewSVGLengthList(nsIDOMSVGLengthList** result, + nsSVGElement *aContext); - nsSVGLengthList(); + nsSVGLengthList(nsSVGElement *aContext); ~nsSVGLengthList(); // void Init(); @@ -69,9 +70,6 @@ public: // nsIDOMSVGLengthList interface: NS_DECL_NSIDOMSVGLENGTHLIST - // nsISVGLengthList interface: - NS_IMETHOD SetContext(nsSVGCoordCtx* context); - // remainder of nsISVGValue interface: NS_IMETHOD SetValueString(const nsAString& aValue); NS_IMETHOD GetValueString(nsAString& aValue); @@ -95,15 +93,18 @@ protected: void ReleaseLengths(); nsAutoVoidArray mLengths; - nsRefPtr mContext; + nsWeakPtr mContext; // needs to be weak to avoid reference loop + PRUint8 mCtxType; }; //---------------------------------------------------------------------- // Implementation -nsSVGLengthList::nsSVGLengthList() +nsSVGLengthList::nsSVGLengthList(nsSVGElement *aContext) + : mCtxType(0) { + mContext = do_GetWeakReference(NS_STATIC_CAST(nsGenericElement*, aContext)); } nsSVGLengthList::~nsSVGLengthList() @@ -120,7 +121,6 @@ NS_IMPL_RELEASE(nsSVGLengthList) NS_INTERFACE_MAP_BEGIN(nsSVGLengthList) NS_INTERFACE_MAP_ENTRY(nsISVGValue) NS_INTERFACE_MAP_ENTRY(nsIDOMSVGLengthList) - NS_INTERFACE_MAP_ENTRY(nsISVGLengthList) NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) NS_INTERFACE_MAP_ENTRY(nsISVGValueObserver) NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(SVGLengthList) @@ -294,22 +294,6 @@ nsSVGLengthList::AppendItem(nsIDOMSVGLength *newItem, nsIDOMSVGLength **_retval) return NS_OK; } -//---------------------------------------------------------------------- -// nsISVGLengthList methods: - -NS_IMETHODIMP -nsSVGLengthList::SetContext(nsSVGCoordCtx *context) -{ - mContext = context; - - PRInt32 count = mLengths.Count(); - for (PRInt32 i = 0; i < count; ++i) { - nsISVGLength* length = ElementAt(i); - length->SetContext(mContext); - } - return NS_OK; -} - //---------------------------------------------------------------------- // nsISVGValueObserver methods @@ -339,7 +323,7 @@ nsSVGLengthList::ReleaseLengths() PRInt32 count = mLengths.Count(); for (PRInt32 i = 0; i < count; ++i) { nsISVGLength* length = ElementAt(i); - length->SetContext(nsnull); + length->SetContext(nsnull, 0); NS_REMOVE_SVGVALUE_OBSERVER(length); NS_RELEASE(length); } @@ -364,7 +348,7 @@ nsSVGLengthList::AppendElement(nsISVGLength* aElement) // list': // aElement->SetListOwner(this); - aElement->SetContext(mContext); + aElement->SetContext(mContext, mCtxType); mLengths.AppendElement((void*)aElement); NS_ADD_SVGVALUE_OBSERVER(aElement); DidModify(); @@ -393,7 +377,7 @@ nsSVGLengthList::InsertElementAt(nsISVGLength* aElement, PRInt32 index) // list': // aElement->SetListOwner(this); - aElement->SetContext(mContext); + aElement->SetContext(mContext, mCtxType); mLengths.InsertElementAt((void*)aElement, index); NS_ADD_SVGVALUE_OBSERVER(aElement); @@ -405,11 +389,11 @@ nsSVGLengthList::InsertElementAt(nsISVGLength* aElement, PRInt32 index) // Exported creation functions: nsresult -NS_NewSVGLengthList(nsISVGLengthList** result) +NS_NewSVGLengthList(nsIDOMSVGLengthList** result, nsSVGElement *aContext) { *result = nsnull; - nsSVGLengthList* lengthList = new nsSVGLengthList(); + nsSVGLengthList* lengthList = new nsSVGLengthList(aContext); if (!lengthList) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(lengthList); diff --git a/mozilla/content/svg/content/src/nsSVGLengthList.h b/mozilla/content/svg/content/src/nsSVGLengthList.h index 188756e8e63..e2d1c13a9cf 100644 --- a/mozilla/content/svg/content/src/nsSVGLengthList.h +++ b/mozilla/content/svg/content/src/nsSVGLengthList.h @@ -39,9 +39,11 @@ #ifndef __NS_SVGLENGTHLIST_H__ #define __NS_SVGLENGTHLIST_H__ -#include "nsISVGLengthList.h" +#include "nsIDOMSVGLengthList.h" + +class nsSVGElement; nsresult -NS_NewSVGLengthList(nsISVGLengthList** result); +NS_NewSVGLengthList(nsIDOMSVGLengthList** result, nsSVGElement *aContext); #endif //__NS_SVGLENGTHLIST_H__ diff --git a/mozilla/content/svg/content/src/nsSVGMarkerElement.cpp b/mozilla/content/svg/content/src/nsSVGMarkerElement.cpp index 2c8f6ee365c..5388b71899f 100644 --- a/mozilla/content/svg/content/src/nsSVGMarkerElement.cpp +++ b/mozilla/content/svg/content/src/nsSVGMarkerElement.cpp @@ -342,7 +342,7 @@ nsSVGMarkerElement::DidChangeLength(PRUint8 aAttrEnum, PRBool aDoSetAttr) } void -nsSVGMarkerElement::SetParentCoordCtxProvider(nsSVGCoordCtxProvider *aContext) +nsSVGMarkerElement::SetParentCoordCtxProvider(nsSVGSVGElement *aContext) { mCoordCtx = aContext; mViewBoxToViewportTransform = nsnull; diff --git a/mozilla/content/svg/content/src/nsSVGMarkerElement.h b/mozilla/content/svg/content/src/nsSVGMarkerElement.h index bb32167aebb..a979a792f6e 100644 --- a/mozilla/content/svg/content/src/nsSVGMarkerElement.h +++ b/mozilla/content/svg/content/src/nsSVGMarkerElement.h @@ -91,7 +91,7 @@ public: protected: - void SetParentCoordCtxProvider(nsSVGCoordCtxProvider *aContext); + void SetParentCoordCtxProvider(nsSVGSVGElement *aContext); virtual LengthAttributesInfo GetLengthInfo(); @@ -99,7 +99,7 @@ protected: nsSVGLength2 mLengthAttributes[4]; static LengthInfo sLengthInfo[4]; - nsSVGCoordCtxProvider *mCoordCtx; + nsSVGSVGElement *mCoordCtx; nsCOMPtr mMarkerUnits; nsCOMPtr mOrient; diff --git a/mozilla/content/svg/content/src/nsSVGSVGElement.cpp b/mozilla/content/svg/content/src/nsSVGSVGElement.cpp index 05828df0102..57c9a87adcd 100644 --- a/mozilla/content/svg/content/src/nsSVGSVGElement.cpp +++ b/mozilla/content/svg/content/src/nsSVGSVGElement.cpp @@ -89,7 +89,6 @@ NS_INTERFACE_MAP_BEGIN(nsSVGSVGElement) 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) NS_INTERFACE_MAP_END_INHERITING(nsSVGSVGElementBase) @@ -97,7 +96,10 @@ NS_INTERFACE_MAP_END_INHERITING(nsSVGSVGElementBase) // Implementation nsSVGSVGElement::nsSVGSVGElement(nsINodeInfo* aNodeInfo) - : nsSVGSVGElementBase(aNodeInfo), mCoordCtx(nsnull), mRedrawSuspendCount(0) + : nsSVGSVGElementBase(aNodeInfo), + mCoordCtx(nsnull), + mCoordCtxMmPerPx(0), + mRedrawSuspendCount(0) { } @@ -129,8 +131,6 @@ nsSVGSVGElement::Init() NS_ENSURE_SUCCESS(rv,rv); rv = AddMappedSVGValue(nsGkAtoms::viewBox, mViewBox); NS_ENSURE_SUCCESS(rv,rv); - // initialize coordinate context with viewbox: - SetCoordCtxRect(viewbox); } // DOM property: preserveAspectRatio , #IMPLIED attrib: preserveAspectRatio @@ -788,9 +788,12 @@ nsSVGSVGElement::GetCTM(nsIDOMSVGMatrix **_retval) float x=0, y=0; nsCOMPtr tmp; if (ancestorCount == 0) { - // our immediate parent is an SVG element. get our 'x' and 'y' attribs - x = mLengthAttributes[X].GetAnimValue(mCoordCtx); - y = mLengthAttributes[Y].GetAnimValue(mCoordCtx); + // our immediate parent is an SVG element. get our 'x' and 'y' attribs. + // cast to nsSVGElement so we get our ancestor coord context. + x = mLengthAttributes[X].GetAnimValue(NS_STATIC_CAST(nsSVGElement*, + this)); + y = mLengthAttributes[Y].GetAnimValue(NS_STATIC_CAST(nsSVGElement*, + this)); } else { // We have an SVG ancestor, but with non-SVG content between us @@ -896,8 +899,11 @@ nsSVGSVGElement::GetScreenCTM(nsIDOMSVGMatrix **_retval) nsCOMPtr tmp; if (ancestorCount == 0) { // our immediate parent is an SVG element. get our 'x' and 'y' attribs - x = mLengthAttributes[X].GetAnimValue(mCoordCtx); - y = mLengthAttributes[Y].GetAnimValue(mCoordCtx); + // cast to nsSVGElement so we get our ancestor coord context. + x = mLengthAttributes[X].GetAnimValue(NS_STATIC_CAST(nsSVGElement*, + this)); + y = mLengthAttributes[Y].GetAnimValue(NS_STATIC_CAST(nsSVGElement*, + this)); } else { // We have an SVG ancestor, but with non-SVG content between us @@ -976,31 +982,6 @@ nsSVGSVGElement::SetZoomAndPan(PRUint16 aZoomAndPan) //---------------------------------------------------------------------- // nsISVGSVGElement methods: -NS_IMETHODIMP -nsSVGSVGElement::SetParentCoordCtxProvider(nsSVGCoordCtxProvider *parentCtx) -{ - if (!parentCtx) { - NS_ERROR("null parent context"); - return NS_ERROR_FAILURE; - } - - mCoordCtx = parentCtx; - - // set parent's mmPerPx on our coord contexts: - float mmPerPxX = nsRefPtr(parentCtx->GetContextX())->GetMillimeterPerPixel(); - float mmPerPxY = nsRefPtr(parentCtx->GetContextY())->GetMillimeterPerPixel(); - SetCoordCtxMMPerPx(mmPerPxX, mmPerPxY); - - if (!HasAttr(kNameSpaceID_None, nsGkAtoms::viewBox)) { - nsCOMPtr vb; - mViewBox->GetAnimVal(getter_AddRefs(vb)); - vb->SetWidth(mLengthAttributes[WIDTH].GetAnimValue(mCoordCtx)); - vb->SetHeight(mLengthAttributes[HEIGHT].GetAnimValue(mCoordCtx)); - } - - return NS_OK; -} - NS_IMETHODIMP nsSVGSVGElement::GetCurrentScaleNumber(nsIDOMSVGNumber **aResult) { @@ -1129,17 +1110,13 @@ nsresult nsSVGSVGElement::UnsetAttr(PRInt32 aNamespaceID, nsIAtom* aName, PRBool aNotify) { - if (aNamespaceID == kNameSpaceID_None && - aName == nsGkAtoms::viewBox && mCoordCtx) { - nsCOMPtr vb; - mViewBox->GetAnimVal(getter_AddRefs(vb)); - vb->SetX(0); - vb->SetY(0); - vb->SetWidth(mLengthAttributes[WIDTH].GetAnimValue(mCoordCtx)); - vb->SetHeight(mLengthAttributes[HEIGHT].GetAnimValue(mCoordCtx)); + nsSVGSVGElementBase::UnsetAttr(aNamespaceID, aName, aNotify); + + if (aNamespaceID == kNameSpaceID_None && aName == nsGkAtoms::viewBox) { + InvalidateTransformNotifyFrame(); } - return nsSVGSVGElementBase::UnsetAttr(aNamespaceID, aName, aNotify); + return NS_OK; } //---------------------------------------------------------------------- @@ -1241,37 +1218,45 @@ nsSVGSVGElement::GetViewboxToViewportTransform(nsIDOMSVGMatrix **_retval) { nsresult rv = NS_OK; - if (!mViewBoxToViewportTransform) { - float viewportWidth = - mLengthAttributes[WIDTH].GetAnimValue(mCoordCtx); - float viewportHeight = - mLengthAttributes[HEIGHT].GetAnimValue(mCoordCtx); - - float viewboxX, viewboxY, viewboxWidth, viewboxHeight; - { - nsCOMPtr vb; - mViewBox->GetAnimVal(getter_AddRefs(vb)); - NS_ASSERTION(vb, "could not get viewbox"); - vb->GetX(&viewboxX); - vb->GetY(&viewboxY); - vb->GetWidth(&viewboxWidth); - vb->GetHeight(&viewboxHeight); - } - if (viewboxWidth==0.0f || viewboxHeight==0.0f) { - NS_ERROR("XXX. We shouldn't get here. Viewbox width/height is set to 0. Need to disable display of element as per specs."); - viewboxWidth = 1.0f; - viewboxHeight = 1.0f; - } - - mViewBoxToViewportTransform = - nsSVGUtils::GetViewBoxTransform(viewportWidth, viewportHeight, - viewboxX, viewboxY, - viewboxWidth, viewboxHeight, - mPreserveAspectRatio); + float viewportWidth, viewportHeight; + nsSVGSVGElement *ctx = GetCtx(); + if (!ctx) { + // outer svg + viewportWidth = mViewportWidth; + viewportHeight = mViewportHeight; + } else { + viewportWidth = mLengthAttributes[WIDTH].GetAnimValue(ctx); + viewportHeight = mLengthAttributes[HEIGHT].GetAnimValue(ctx); } - *_retval = mViewBoxToViewportTransform; - NS_IF_ADDREF(*_retval); + float viewboxX, viewboxY, viewboxWidth, viewboxHeight; + if (HasAttr(kNameSpaceID_None, nsGkAtoms::viewBox)) { + nsCOMPtr vb; + mViewBox->GetAnimVal(getter_AddRefs(vb)); + NS_ASSERTION(vb, "could not get viewbox"); + vb->GetX(&viewboxX); + vb->GetY(&viewboxY); + vb->GetWidth(&viewboxWidth); + vb->GetHeight(&viewboxHeight); + } else { + viewboxX = viewboxY = 0.0f; + viewboxWidth = viewportWidth; + viewboxHeight = viewportHeight; + } + + if (viewboxWidth==0.0f || viewboxHeight==0.0f) { + NS_ERROR("XXX. We shouldn't get here. Viewbox width/height is set to 0. Need to disable display of element as per specs."); + viewboxWidth = 1.0f; + viewboxHeight = 1.0f; + } + + nsCOMPtr xform = + nsSVGUtils::GetViewBoxTransform(viewportWidth, viewportHeight, + viewboxX, viewboxY, + viewboxWidth, viewboxHeight, + mPreserveAspectRatio); + xform.swap(*_retval); + return rv; } @@ -1323,8 +1308,6 @@ nsSVGSVGElement::InvalidateTransformNotifyFrame() nsIPresShell* presShell = doc->GetShellAt(0); if (!presShell) return; - mViewBoxToViewportTransform = nsnull; - nsIFrame* frame = presShell->GetPrimaryFrameFor(this); if (frame) { nsISVGSVGFrame* svgframe; @@ -1343,6 +1326,94 @@ nsSVGSVGElement::InvalidateTransformNotifyFrame() } } +//---------------------------------------------------------------------- +// nsSVGSVGElement + +void +nsSVGSVGElement::SetCoordCtxRect(nsIDOMSVGRect* aCtxRect) +{ + if (mLengthAttributes[WIDTH].GetSpecifiedUnitType() == + nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE) { + aCtxRect->GetWidth(&mViewportWidth); + mViewportWidth *= + mLengthAttributes[WIDTH].GetAnimValInSpecifiedUnits() / 100.0f; + } else { + mViewportWidth = mLengthAttributes[WIDTH].GetAnimValue(this); + } + + if (mLengthAttributes[HEIGHT].GetSpecifiedUnitType() == + nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE) { + aCtxRect->GetHeight(&mViewportHeight); + mViewportHeight *= + mLengthAttributes[HEIGHT].GetAnimValInSpecifiedUnits() / 100.0f; + } else { + mViewportHeight = mLengthAttributes[HEIGHT].GetAnimValue(this); + } +} + +already_AddRefed +nsSVGSVGElement::GetCtxRect() { + nsCOMPtr vb; + if (HasAttr(kNameSpaceID_None, nsGkAtoms::viewBox)) { + mViewBox->GetAnimVal(getter_AddRefs(vb)); + } else { + nsSVGSVGElement *ctx = GetCtx(); + float w, h; + if (ctx) { + w = mLengthAttributes[WIDTH].GetAnimValue(ctx); + h = mLengthAttributes[HEIGHT].GetAnimValue(ctx); + } else { + w = mViewportWidth; + h = mViewportHeight; + } + NS_NewSVGRect(getter_AddRefs(vb), 0, 0, w, h); + } + + nsIDOMSVGRect *retval = nsnull; + vb.swap(retval); + return retval; +} + +float +nsSVGSVGElement::GetLength(PRUint8 aCtxType) { + float h, w; + + if (HasAttr(kNameSpaceID_None, nsGkAtoms::viewBox)) { + nsCOMPtr vb; + mViewBox->GetAnimVal(getter_AddRefs(vb)); + vb->GetHeight(&h); + vb->GetWidth(&w); + } else { + nsSVGSVGElement *ctx = GetCtx(); + if (ctx) { + w = mLengthAttributes[WIDTH].GetAnimValue(ctx); + h = mLengthAttributes[HEIGHT].GetAnimValue(ctx); + } else { + w = mViewportWidth; + h = mViewportHeight; + } + } + + switch (aCtxType) { + case nsSVGUtils::X: + return w; + case nsSVGUtils::Y: + return h; + case nsSVGUtils::XY: + return (float)sqrt((w*w+h*h)/2.0); + } + return 0; +} + +float +nsSVGSVGElement::GetMMPerPx(PRUint8 aCtxType) +{ + if (mCoordCtxMmPerPx == 0.0f) { + GetScreenPixelToMillimeterX(&mCoordCtxMmPerPx); + } + return mCoordCtxMmPerPx; +} + //---------------------------------------------------------------------- // nsSVGElement methods @@ -1351,15 +1422,7 @@ nsSVGSVGElement::DidChangeLength(PRUint8 aAttrEnum, PRBool aDoSetAttr) { nsSVGSVGElementBase::DidChangeLength(aAttrEnum, aDoSetAttr); - if (mCoordCtx && !HasAttr(kNameSpaceID_None, nsGkAtoms::viewBox) && - (aAttrEnum == WIDTH || aAttrEnum == HEIGHT)) { - nsCOMPtr vb; - mViewBox->GetAnimVal(getter_AddRefs(vb)); - vb->SetWidth(mLengthAttributes[WIDTH].GetAnimValue(mCoordCtx)); - vb->SetHeight(mLengthAttributes[HEIGHT].GetAnimValue(mCoordCtx)); - } else { - InvalidateTransformNotifyFrame(); - } + InvalidateTransformNotifyFrame(); } nsSVGElement::LengthAttributesInfo diff --git a/mozilla/content/svg/content/src/nsSVGSVGElement.h b/mozilla/content/svg/content/src/nsSVGSVGElement.h index 60585e9695a..fe2ed178e07 100644 --- a/mozilla/content/svg/content/src/nsSVGSVGElement.h +++ b/mozilla/content/svg/content/src/nsSVGSVGElement.h @@ -45,7 +45,7 @@ #include "nsIDOMSVGFitToViewBox.h" #include "nsIDOMSVGLocatable.h" #include "nsIDOMSVGZoomAndPan.h" -#include "nsSVGCoordCtxProvider.h" +#include "nsIDOMSVGMatrix.h" #include "nsSVGLength2.h" #define QI_TO_NSSVGSVGELEMENT(base) \ @@ -59,8 +59,7 @@ class nsSVGSVGElement : public nsSVGSVGElementBase, public nsISVGSVGElement, // : nsIDOMSVGSVGElement public nsIDOMSVGFitToViewBox, public nsIDOMSVGLocatable, - public nsIDOMSVGZoomAndPan, - public nsSVGCoordCtxProvider + public nsIDOMSVGZoomAndPan { friend class nsSVGOuterSVGFrame; friend class nsSVGInnerSVGFrame; @@ -72,7 +71,12 @@ protected: virtual ~nsSVGSVGElement(); nsresult Init(); + // nsSVGSVGElement methods: + void SetCoordCtxRect(nsIDOMSVGRect* aCtxRect); + public: + NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISVGSVGELEMENT_IID) + // interfaces: NS_DECL_ISUPPORTS_INHERITED NS_DECL_NSIDOMSVGSVGELEMENT @@ -86,7 +90,6 @@ public: NS_FORWARD_NSIDOMSVGELEMENT(nsSVGSVGElementBase::) // nsISVGSVGElement interface: - NS_IMETHOD SetParentCoordCtxProvider(nsSVGCoordCtxProvider *parentCtx); NS_IMETHOD GetCurrentScaleNumber(nsIDOMSVGNumber **aResult); NS_IMETHOD GetZoomAndPanEnum(nsISVGEnum **aResult); NS_IMETHOD SetCurrentScaleTranslate(float s, float x, float y); @@ -95,7 +98,6 @@ public: NS_IMETHOD_(float) GetPreviousTranslate_x(); NS_IMETHOD_(float) GetPreviousTranslate_y(); NS_IMETHOD_(float) GetPreviousScale(); - NS_IMETHOD_(void) InvalidateViewBoxToViewport() { mViewBoxToViewportTransform = nsnull; } // nsIContent interface NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const; @@ -112,6 +114,11 @@ public: // nsSVGElement specializations: virtual void DidChangeLength(PRUint8 aAttrEnum, PRBool aDoSetAttr); + // nsSVGSVGElement methods: + float GetLength(PRUint8 mCtxType); + float GetMMPerPx(PRUint8 mCtxType = 0); + already_AddRefed GetCtxRect(); + // public helpers: nsresult GetViewboxToViewportTransform(nsIDOMSVGMatrix **_retval); @@ -133,11 +140,13 @@ protected: nsSVGLength2 mLengthAttributes[4]; static LengthInfo sLengthInfo[4]; - nsSVGCoordCtxProvider *mCoordCtx; + nsSVGSVGElement *mCoordCtx; nsCOMPtr mViewBox; - nsCOMPtr mViewBoxToViewportTransform; nsCOMPtr mPreserveAspectRatio; + float mViewportWidth, mViewportHeight; // valid only for outersvg + float mCoordCtxMmPerPx; + // zoom and pan // IMPORTANT: only RecordCurrentScaleTranslate should change the "mPreviousX" // members below - see the comment in RecordCurrentScaleTranslate diff --git a/mozilla/content/svg/content/src/nsSVGTSpanElement.cpp b/mozilla/content/svg/content/src/nsSVGTSpanElement.cpp index 785025659f8..ed7cf3818e9 100644 --- a/mozilla/content/svg/content/src/nsSVGTSpanElement.cpp +++ b/mozilla/content/svg/content/src/nsSVGTSpanElement.cpp @@ -43,7 +43,7 @@ #include "nsSVGAnimatedLengthList.h" #include "nsSVGLengthList.h" #include "nsISVGSVGElement.h" -#include "nsSVGCoordCtxProvider.h" +#include "nsSVGSVGElement.h" #include "nsISVGTextContentMetrics.h" #include "nsIFrame.h" #include "nsDOMError.h" @@ -77,9 +77,6 @@ public: // nsIContent interface NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const; - // nsSVGElement specializations: - virtual void ParentChainChanged(); - virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const; protected: @@ -136,8 +133,8 @@ nsSVGTSpanElement::Init() // DOM property: nsIDOMSVGTextPositioningElement::x, #IMPLIED attrib: x { - nsCOMPtr lengthList; - rv = NS_NewSVGLengthList(getter_AddRefs(lengthList)); + nsCOMPtr lengthList; + rv = NS_NewSVGLengthList(getter_AddRefs(lengthList), this); NS_ENSURE_SUCCESS(rv,rv); rv = NS_NewSVGAnimatedLengthList(getter_AddRefs(mX), lengthList); @@ -148,8 +145,8 @@ nsSVGTSpanElement::Init() // DOM property: nsIDOMSVGTextPositioningElement::y, #IMPLIED attrib: y { - nsCOMPtr lengthList; - rv = NS_NewSVGLengthList(getter_AddRefs(lengthList)); + nsCOMPtr lengthList; + rv = NS_NewSVGLengthList(getter_AddRefs(lengthList), this); NS_ENSURE_SUCCESS(rv,rv); rv = NS_NewSVGAnimatedLengthList(getter_AddRefs(mY), lengthList); @@ -160,8 +157,8 @@ nsSVGTSpanElement::Init() // DOM property: nsIDOMSVGTextPositioningElement::dx, #IMPLIED attrib: dx { - nsCOMPtr lengthList; - rv = NS_NewSVGLengthList(getter_AddRefs(lengthList)); + nsCOMPtr lengthList; + rv = NS_NewSVGLengthList(getter_AddRefs(lengthList), this); NS_ENSURE_SUCCESS(rv,rv); rv = NS_NewSVGAnimatedLengthList(getter_AddRefs(mdX), lengthList); @@ -172,8 +169,8 @@ nsSVGTSpanElement::Init() // DOM property: nsIDOMSVGTextPositioningElement::dy, #IMPLIED attrib: dy { - nsCOMPtr lengthList; - rv = NS_NewSVGLengthList(getter_AddRefs(lengthList)); + nsCOMPtr lengthList; + rv = NS_NewSVGLengthList(getter_AddRefs(lengthList), this); NS_ENSURE_SUCCESS(rv,rv); rv = NS_NewSVGAnimatedLengthList(getter_AddRefs(mdY), lengthList); @@ -379,64 +376,6 @@ nsSVGTSpanElement::IsAttributeMapped(const nsIAtom* name) const nsSVGTSpanElementBase::IsAttributeMapped(name); } -//---------------------------------------------------------------------- -// nsSVGElement methods - -void nsSVGTSpanElement::ParentChainChanged() -{ - // set new context information on our length-properties: - - nsCOMPtr dom_elem; - GetOwnerSVGElement(getter_AddRefs(dom_elem)); - if (!dom_elem) return; - - nsCOMPtr ctx = do_QueryInterface(dom_elem); - NS_ASSERTION(ctx, " element missing interface"); - - // x: - { - nsCOMPtr dom_lengthlist; - mX->GetAnimVal(getter_AddRefs(dom_lengthlist)); - nsCOMPtr lengthlist = do_QueryInterface(dom_lengthlist); - NS_ASSERTION(lengthlist, "svg lengthlist missing interface"); - - lengthlist->SetContext(nsRefPtr(ctx->GetContextX())); - } - - // y: - { - nsCOMPtr dom_lengthlist; - mY->GetAnimVal(getter_AddRefs(dom_lengthlist)); - nsCOMPtr lengthlist = do_QueryInterface(dom_lengthlist); - NS_ASSERTION(lengthlist, "svg lengthlist missing interface"); - - lengthlist->SetContext(nsRefPtr(ctx->GetContextY())); - } - - // dx: - { - nsCOMPtr dom_lengthlist; - mdX->GetAnimVal(getter_AddRefs(dom_lengthlist)); - nsCOMPtr lengthlist = do_QueryInterface(dom_lengthlist); - NS_ASSERTION(lengthlist, "svg lengthlist missing interface"); - - lengthlist->SetContext(nsRefPtr(ctx->GetContextX())); - } - - // dy: - { - nsCOMPtr dom_lengthlist; - mdY->GetAnimVal(getter_AddRefs(dom_lengthlist)); - nsCOMPtr lengthlist = do_QueryInterface(dom_lengthlist); - NS_ASSERTION(lengthlist, "svg lengthlist missing interface"); - - lengthlist->SetContext(nsRefPtr(ctx->GetContextY())); - } - - // recurse into child content: - nsSVGTSpanElementBase::ParentChainChanged(); -} - //---------------------------------------------------------------------- // nsSVGElement overrides diff --git a/mozilla/content/svg/content/src/nsSVGTextElement.cpp b/mozilla/content/svg/content/src/nsSVGTextElement.cpp index 274892ff74b..dbd5a13ff36 100644 --- a/mozilla/content/svg/content/src/nsSVGTextElement.cpp +++ b/mozilla/content/svg/content/src/nsSVGTextElement.cpp @@ -43,7 +43,7 @@ #include "nsSVGAnimatedLengthList.h" #include "nsSVGLengthList.h" #include "nsISVGSVGElement.h" -#include "nsSVGCoordCtxProvider.h" +#include "nsSVGSVGElement.h" #include "nsISVGTextContentMetrics.h" #include "nsIFrame.h" #include "nsDOMError.h" @@ -76,9 +76,6 @@ public: // nsIContent interface NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const; - - // nsSVGElement specializations: - virtual void ParentChainChanged(); virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const; @@ -133,8 +130,8 @@ nsSVGTextElement::Init() // DOM property: nsIDOMSVGTextPositioningElement::x, #IMPLIED attrib: x { - nsCOMPtr lengthList; - rv = NS_NewSVGLengthList(getter_AddRefs(lengthList)); + nsCOMPtr lengthList; + rv = NS_NewSVGLengthList(getter_AddRefs(lengthList), this); NS_ENSURE_SUCCESS(rv,rv); rv = NS_NewSVGAnimatedLengthList(getter_AddRefs(mX), lengthList); @@ -145,8 +142,8 @@ nsSVGTextElement::Init() // DOM property: nsIDOMSVGTextPositioningElement::y, #IMPLIED attrib: y { - nsCOMPtr lengthList; - rv = NS_NewSVGLengthList(getter_AddRefs(lengthList)); + nsCOMPtr lengthList; + rv = NS_NewSVGLengthList(getter_AddRefs(lengthList), this); NS_ENSURE_SUCCESS(rv,rv); rv = NS_NewSVGAnimatedLengthList(getter_AddRefs(mY), lengthList); @@ -157,8 +154,8 @@ nsSVGTextElement::Init() // DOM property: nsIDOMSVGTextPositioningElement::dx, #IMPLIED attrib: dx { - nsCOMPtr lengthList; - rv = NS_NewSVGLengthList(getter_AddRefs(lengthList)); + nsCOMPtr lengthList; + rv = NS_NewSVGLengthList(getter_AddRefs(lengthList), this); NS_ENSURE_SUCCESS(rv,rv); rv = NS_NewSVGAnimatedLengthList(getter_AddRefs(mdX), lengthList); @@ -169,8 +166,8 @@ nsSVGTextElement::Init() // DOM property: nsIDOMSVGTextPositioningElement::dy, #IMPLIED attrib: dy { - nsCOMPtr lengthList; - rv = NS_NewSVGLengthList(getter_AddRefs(lengthList)); + nsCOMPtr lengthList; + rv = NS_NewSVGLengthList(getter_AddRefs(lengthList), this); NS_ENSURE_SUCCESS(rv,rv); rv = NS_NewSVGAnimatedLengthList(getter_AddRefs(mdY), lengthList); @@ -372,64 +369,6 @@ nsSVGTextElement::IsAttributeMapped(const nsIAtom* name) const nsSVGTextElementBase::IsAttributeMapped(name); } -//---------------------------------------------------------------------- -// nsSVGElement methods - -void nsSVGTextElement::ParentChainChanged() -{ - // set new context information on our length-properties: - - nsCOMPtr dom_elem; - GetOwnerSVGElement(getter_AddRefs(dom_elem)); - if (!dom_elem) return; - - nsCOMPtr ctx = do_QueryInterface(dom_elem); - NS_ASSERTION(ctx, " element missing interface"); - - // x: - { - nsCOMPtr dom_lengthlist; - mX->GetAnimVal(getter_AddRefs(dom_lengthlist)); - nsCOMPtr lengthlist = do_QueryInterface(dom_lengthlist); - NS_ASSERTION(lengthlist, "svg lengthlist missing interface"); - - lengthlist->SetContext(nsRefPtr(ctx->GetContextX())); - } - - // y: - { - nsCOMPtr dom_lengthlist; - mY->GetAnimVal(getter_AddRefs(dom_lengthlist)); - nsCOMPtr lengthlist = do_QueryInterface(dom_lengthlist); - NS_ASSERTION(lengthlist, "svg lengthlist missing interface"); - - lengthlist->SetContext(nsRefPtr(ctx->GetContextY())); - } - - // dx: - { - nsCOMPtr dom_lengthlist; - mdX->GetAnimVal(getter_AddRefs(dom_lengthlist)); - nsCOMPtr lengthlist = do_QueryInterface(dom_lengthlist); - NS_ASSERTION(lengthlist, "svg lengthlist missing interface"); - - lengthlist->SetContext(nsRefPtr(ctx->GetContextX())); - } - - // dy: - { - nsCOMPtr dom_lengthlist; - mdY->GetAnimVal(getter_AddRefs(dom_lengthlist)); - nsCOMPtr lengthlist = do_QueryInterface(dom_lengthlist); - NS_ASSERTION(lengthlist, "svg lengthlist missing interface"); - - lengthlist->SetContext(nsRefPtr(ctx->GetContextY())); - } - - // recurse into child content: - nsSVGTextElementBase::ParentChainChanged(); -} - //---------------------------------------------------------------------- // implementation helpers: diff --git a/mozilla/content/svg/content/src/nsSVGUseElement.cpp b/mozilla/content/svg/content/src/nsSVGUseElement.cpp index ed574107f66..5df10957bdd 100644 --- a/mozilla/content/svg/content/src/nsSVGUseElement.cpp +++ b/mozilla/content/svg/content/src/nsSVGUseElement.cpp @@ -39,7 +39,7 @@ #include "nsGkAtoms.h" #include "nsIDOMSVGAnimatedLength.h" #include "nsISVGSVGElement.h" -#include "nsSVGCoordCtxProvider.h" +#include "nsIDOMSVGAnimatedString.h" #include "nsSVGAnimatedString.h" #include "nsIDOMDocument.h" #include "nsIDOMSVGSVGElement.h" diff --git a/mozilla/layout/base/Makefile.in b/mozilla/layout/base/Makefile.in index 51de490803c..567f422ac7a 100644 --- a/mozilla/layout/base/Makefile.in +++ b/mozilla/layout/base/Makefile.in @@ -166,6 +166,7 @@ LOCAL_INCLUDES += \ -I$(srcdir)/../../content/xbl/src \ -I$(srcdir)/../../view/src \ -I$(srcdir)/../../dom/src/base \ + -I$(srcdir)/../../content/svg/content/src \ $(NULL) ifdef MOZ_MATHML diff --git a/mozilla/layout/svg/base/src/nsSVGClipPathFrame.cpp b/mozilla/layout/svg/base/src/nsSVGClipPathFrame.cpp index 425ee559366..8457a3e7886 100644 --- a/mozilla/layout/svg/base/src/nsSVGClipPathFrame.cpp +++ b/mozilla/layout/svg/base/src/nsSVGClipPathFrame.cpp @@ -43,6 +43,7 @@ #include "nsSVGUtils.h" #include "nsSVGGraphicElement.h" #include "gfxContext.h" +#include "nsIDOMSVGRect.h" //---------------------------------------------------------------------- // Implementation diff --git a/mozilla/layout/svg/base/src/nsSVGContainerFrame.cpp b/mozilla/layout/svg/base/src/nsSVGContainerFrame.cpp index 2e48971faf0..a0f5de396fa 100644 --- a/mozilla/layout/svg/base/src/nsSVGContainerFrame.cpp +++ b/mozilla/layout/svg/base/src/nsSVGContainerFrame.cpp @@ -100,15 +100,6 @@ nsSVGContainerFrame::Init(nsIContent* aContent, return rv; } -already_AddRefed -nsSVGContainerFrame::GetCoordContextProvider() -{ - NS_ASSERTION(mParent, "null parent"); - nsSVGContainerFrame *containerFrame = NS_STATIC_CAST(nsSVGContainerFrame*, - mParent); - return containerFrame->GetCoordContextProvider(); -} - NS_IMETHODIMP nsSVGDisplayContainerFrame::InitSVG() { diff --git a/mozilla/layout/svg/base/src/nsSVGContainerFrame.h b/mozilla/layout/svg/base/src/nsSVGContainerFrame.h index 39c46b7fa10..3c660f8449c 100644 --- a/mozilla/layout/svg/base/src/nsSVGContainerFrame.h +++ b/mozilla/layout/svg/base/src/nsSVGContainerFrame.h @@ -40,7 +40,7 @@ #include "nsContainerFrame.h" #include "nsISVGChildFrame.h" #include "nsIDOMSVGMatrix.h" -#include "nsSVGCoordCtxProvider.h" +#include "nsSVGSVGElement.h" typedef nsContainerFrame nsSVGContainerFrameBase; @@ -79,7 +79,6 @@ public: nsIFrame* aPrevInFlow); virtual already_AddRefed GetCanvasTM() { return nsnull; } - virtual already_AddRefed GetCoordContextProvider(); }; class nsSVGDisplayContainerFrame : public nsSVGContainerFrame, diff --git a/mozilla/layout/svg/base/src/nsSVGGeometryFrame.cpp b/mozilla/layout/svg/base/src/nsSVGGeometryFrame.cpp index e81816620f8..be79d6c3dcd 100644 --- a/mozilla/layout/svg/base/src/nsSVGGeometryFrame.cpp +++ b/mozilla/layout/svg/base/src/nsSVGGeometryFrame.cpp @@ -193,10 +193,14 @@ nsSVGGeometryFrame::DidModifySVGObservable(nsISVGValue* observable, float nsSVGGeometryFrame::GetStrokeWidth() { + nsSVGElement *ctx = NS_STATIC_CAST(nsSVGElement*, + GetType() == nsGkAtoms::svgGlyphFrame ? + mContent->GetParent() : mContent); + return nsSVGUtils::CoordToFloat(GetPresContext(), - GetType() == nsGkAtoms::svgGlyphFrame ? mContent->GetParent() : mContent, - GetStyleSVG()->mStrokeWidth); + ctx, + GetStyleSVG()->mStrokeWidth); } nsresult @@ -217,7 +221,9 @@ nsSVGGeometryFrame::GetStrokeDashArray(gfxFloat **aDashes, PRUint32 *aCount) if (dashes) { for (PRUint32 i = 0; i < count; i++) { dashes[i] = - nsSVGUtils::CoordToFloat(presContext, mContent, dasharray[i]); + nsSVGUtils::CoordToFloat(presContext, + NS_STATIC_CAST(nsSVGElement*, mContent), + dasharray[i]); if (dashes[i] < 0.0f) { delete [] dashes; return NS_OK; @@ -244,7 +250,8 @@ float nsSVGGeometryFrame::GetStrokeDashoffset() { return - nsSVGUtils::CoordToFloat(GetPresContext(), mContent, + nsSVGUtils::CoordToFloat(GetPresContext(), + NS_STATIC_CAST(nsSVGElement*, mContent), GetStyleSVG()->mStrokeDashoffset); } diff --git a/mozilla/layout/svg/base/src/nsSVGGradientFrame.cpp b/mozilla/layout/svg/base/src/nsSVGGradientFrame.cpp index e23dd4edb00..69b1aeb7177 100644 --- a/mozilla/layout/svg/base/src/nsSVGGradientFrame.cpp +++ b/mozilla/layout/svg/base/src/nsSVGGradientFrame.cpp @@ -47,6 +47,7 @@ #include "nsSVGGeometryFrame.h" #include "nsSVGGradientFrame.h" #include "gfxContext.h" +#include "nsIDOMSVGRect.h" //---------------------------------------------------------------------- // Implementation @@ -611,7 +612,7 @@ nsSVGLinearGradientFrame::GradientLookupAttribute(nsIAtom *aAtomName, "Unknown gradientUnits type"); return element->mLengthAttributes[aEnumName]. - GetAnimValue(NS_STATIC_CAST(nsSVGCoordCtxProvider*, nsnull)); + GetAnimValue(NS_STATIC_CAST(nsSVGSVGElement*, nsnull)); } cairo_pattern_t * @@ -691,7 +692,7 @@ nsSVGRadialGradientFrame::GradientLookupAttribute(nsIAtom *aAtomName, "Unknown gradientUnits type"); return element->mLengthAttributes[aEnumName]. - GetAnimValue(NS_STATIC_CAST(nsSVGCoordCtxProvider*, nsnull)); + GetAnimValue(NS_STATIC_CAST(nsSVGSVGElement*, nsnull)); } cairo_pattern_t * diff --git a/mozilla/layout/svg/base/src/nsSVGInnerSVGFrame.cpp b/mozilla/layout/svg/base/src/nsSVGInnerSVGFrame.cpp index d158fc93d6e..16b7e354ed7 100644 --- a/mozilla/layout/svg/base/src/nsSVGInnerSVGFrame.cpp +++ b/mozilla/layout/svg/base/src/nsSVGInnerSVGFrame.cpp @@ -87,14 +87,12 @@ public: // nsISVGChildFrame interface: NS_IMETHOD PaintSVG(nsSVGRenderState *aContext, nsRect *aDirtyRect); - NS_IMETHOD InitialUpdate(); NS_IMETHOD NotifyCanvasTMChanged(PRBool suppressInvalidation); NS_IMETHOD SetMatrixPropagation(PRBool aPropagate); NS_IMETHOD SetOverrideCTM(nsIDOMSVGMatrix *aCTM); NS_IMETHOD GetFrameForPointSVG(float x, float y, nsIFrame** hit); // nsSVGContainerFrame methods: - virtual already_AddRefed GetCoordContextProvider(); virtual already_AddRefed GetCanvasTM(); // nsISVGValueObserver @@ -113,8 +111,6 @@ public: protected: - void UpdateCoordCtx(); - nsCOMPtr mCanvasTM; nsCOMPtr mOverrideCTM; @@ -138,16 +134,6 @@ nsSVGInnerSVGFrame::nsSVGInnerSVGFrame(nsStyleContext* aContext) : #endif } -void -nsSVGInnerSVGFrame::UpdateCoordCtx() -{ - nsSVGContainerFrame *containerFrame = NS_STATIC_CAST(nsSVGContainerFrame*, - mParent); - nsSVGSVGElement *svgElement = NS_STATIC_CAST(nsSVGSVGElement*, mContent); - - svgElement->SetParentCoordCtxProvider(nsRefPtr(containerFrame->GetCoordContextProvider())); -} - //---------------------------------------------------------------------- // nsISupports methods @@ -210,20 +196,10 @@ nsSVGInnerSVGFrame::NotifyCanvasTMChanged(PRBool suppressInvalidation) { // make sure our cached transform matrix gets (lazily) updated mCanvasTM = nsnull; - nsSVGSVGElement *svg = NS_STATIC_CAST(nsSVGSVGElement*, mContent); - svg->InvalidateViewBoxToViewport(); return nsSVGInnerSVGFrameBase::NotifyCanvasTMChanged(suppressInvalidation); } -NS_IMETHODIMP -nsSVGInnerSVGFrame::InitialUpdate() -{ - UpdateCoordCtx(); - - return nsSVGInnerSVGFrameBase::InitialUpdate(); -} - NS_IMETHODIMP nsSVGInnerSVGFrame::SetMatrixPropagation(PRBool aPropagate) { @@ -311,18 +287,6 @@ nsSVGInnerSVGFrame::NotifyViewportChange() //---------------------------------------------------------------------- // nsSVGContainerFrame methods: -already_AddRefed -nsSVGInnerSVGFrame::GetCoordContextProvider() -{ - NS_ASSERTION(mContent, "null parent"); - - // Our content element is the CoordContextProvider for our children: - nsSVGCoordCtxProvider *provider; - CallQueryInterface(mContent, &provider); - - return provider; -} - already_AddRefed nsSVGInnerSVGFrame::GetCanvasTM() { diff --git a/mozilla/layout/svg/base/src/nsSVGMarkerFrame.cpp b/mozilla/layout/svg/base/src/nsSVGMarkerFrame.cpp index e529eba3606..9ceb1af4735 100644 --- a/mozilla/layout/svg/base/src/nsSVGMarkerFrame.cpp +++ b/mozilla/layout/svg/base/src/nsSVGMarkerFrame.cpp @@ -307,7 +307,7 @@ nsSVGMarkerFrame::GetType() const } void -nsSVGMarkerFrame::SetParentCoordCtxProvider(nsSVGCoordCtxProvider *aContext) +nsSVGMarkerFrame::SetParentCoordCtxProvider(nsSVGSVGElement *aContext) { nsSVGMarkerElement *marker = NS_STATIC_CAST(nsSVGMarkerElement*, mContent); marker->SetParentCoordCtxProvider(aContext); @@ -324,9 +324,8 @@ nsSVGMarkerFrame::AutoMarkerReferencer::AutoMarkerReferencer( mFrame->mInUse = PR_TRUE; mFrame->mMarkedFrame = aMarkedFrame; - nsRefPtr ctx = - nsSVGUtils::GetCoordContextProvider(NS_STATIC_CAST(nsSVGElement*, - aMarkedFrame->GetContent())); + nsSVGSVGElement *ctx = + NS_STATIC_CAST(nsSVGElement*, aMarkedFrame->GetContent())->GetCtx(); mFrame->SetParentCoordCtxProvider(ctx); } diff --git a/mozilla/layout/svg/base/src/nsSVGMarkerFrame.h b/mozilla/layout/svg/base/src/nsSVGMarkerFrame.h index ba29e036501..ab097c37a80 100644 --- a/mozilla/layout/svg/base/src/nsSVGMarkerFrame.h +++ b/mozilla/layout/svg/base/src/nsSVGMarkerFrame.h @@ -137,7 +137,7 @@ private: }; // nsSVGMarkerFrame methods: - void SetParentCoordCtxProvider(nsSVGCoordCtxProvider *aContext); + void SetParentCoordCtxProvider(nsSVGSVGElement *aContext); // recursion prevention flag PRPackedBool mInUse; diff --git a/mozilla/layout/svg/base/src/nsSVGMaskFrame.cpp b/mozilla/layout/svg/base/src/nsSVGMaskFrame.cpp index 49d08ad4875..4a7334a224c 100644 --- a/mozilla/layout/svg/base/src/nsSVGMaskFrame.cpp +++ b/mozilla/layout/svg/base/src/nsSVGMaskFrame.cpp @@ -41,6 +41,7 @@ #include "nsSVGMaskElement.h" #include "nsIDOMSVGMatrix.h" #include "gfxContext.h" +#include "nsIDOMSVGRect.h" //---------------------------------------------------------------------- // Implementation diff --git a/mozilla/layout/svg/base/src/nsSVGOuterSVGFrame.cpp b/mozilla/layout/svg/base/src/nsSVGOuterSVGFrame.cpp index 1c2f0808396..a747df2ecec 100644 --- a/mozilla/layout/svg/base/src/nsSVGOuterSVGFrame.cpp +++ b/mozilla/layout/svg/base/src/nsSVGOuterSVGFrame.cpp @@ -159,16 +159,8 @@ nsSVGOuterSVGFrame::nsSVGOuterSVGFrame(nsStyleContext* aContext) NS_IMETHODIMP nsSVGOuterSVGFrame::InitSVG() { - nsresult rv; - - // we are an *outer* svg element, so this frame will become the - // coordinate context for our content element: - float mmPerPx = 25.4f / GetPresContext()->AppUnitsToDevPixels(GetPresContext()->AppUnitsPerInch()); - SetCoordCtxMMPerPx(mmPerPx, mmPerPx); - nsCOMPtr SVGElement = do_QueryInterface(mContent); NS_ASSERTION(SVGElement, "wrong content element"); - SVGElement->SetParentCoordCtxProvider(this); nsIDocument* doc = mContent->GetCurrentDoc(); if (doc) { @@ -196,7 +188,6 @@ nsSVGOuterSVGFrame::InitSVG() NS_INTERFACE_MAP_BEGIN(nsSVGOuterSVGFrame) NS_INTERFACE_MAP_ENTRY(nsISVGSVGFrame) - NS_INTERFACE_MAP_ENTRY(nsSVGCoordCtxProvider) NS_INTERFACE_MAP_END_INHERITING(nsSVGOuterSVGFrameBase) //---------------------------------------------------------------------- @@ -253,7 +244,10 @@ nsSVGOuterSVGFrame::Reflow(nsPresContext* aPresContext, nsCOMPtr r; NS_NewSVGRect(getter_AddRefs(r), 0, 0, preferredWidth, preferredHeight); - SetCoordCtxRect(r); + + nsSVGSVGElement *svgElem = NS_STATIC_CAST(nsSVGSVGElement*, mContent); + NS_ENSURE_TRUE(svgElem, NS_ERROR_FAILURE); + svgElem->SetCoordCtxRect(r); #ifdef DEBUG // some debug stuff: @@ -287,14 +281,11 @@ nsSVGOuterSVGFrame::Reflow(nsPresContext* aPresContext, // Let's work out our desired dimensions. nsSVGSVGElement *svg = NS_STATIC_CAST(nsSVGSVGElement*, mContent); - svg->SetParentCoordCtxProvider(this); - float width = - svg->mLengthAttributes[nsSVGSVGElement::WIDTH].GetAnimValue(this); - float height = - svg->mLengthAttributes[nsSVGSVGElement::HEIGHT].GetAnimValue(this); - aDesiredSize.width = nsPresContext::CSSPixelsToAppUnits(width); - aDesiredSize.height = nsPresContext::CSSPixelsToAppUnits(height); + aDesiredSize.width = + nsPresContext::CSSPixelsToAppUnits(svg->mViewportWidth); + aDesiredSize.height = + nsPresContext::CSSPixelsToAppUnits(svg->mViewportHeight); // XXX add in CSS borders ?? @@ -303,7 +294,6 @@ nsSVGOuterSVGFrame::Reflow(nsPresContext* aPresContext, // tell our element that the viewbox to viewport transform needs refreshing, // and set us up to draw - svg->InvalidateViewBoxToViewport(); NotifyViewportChange(); UnsuspendRedraw(); @@ -386,6 +376,22 @@ nsDisplaySVG::Paint(nsDisplayListBuilder* aBuilder, nsIRenderingContext* aCtx, Paint(*aCtx, aDirtyRect, aBuilder->ToReferenceFrame(mFrame)); } +NS_IMETHODIMP +nsSVGOuterSVGFrame::AttributeChanged(PRInt32 aNameSpaceID, + nsIAtom* aAttribute, + PRInt32 aModType) +{ + if (aNameSpaceID == kNameSpaceID_None && + !(GetStateBits() & NS_FRAME_FIRST_REFLOW) && + (aAttribute == nsGkAtoms::width || aAttribute == nsGkAtoms::height)) { + AddStateBits(NS_FRAME_IS_DIRTY); + GetPresContext()->PresShell()-> + FrameNeedsReflow(this, nsIPresShell::eStyleChange); + } + + return NS_OK; +} + nsIFrame* nsSVGOuterSVGFrame::GetFrameForPoint(const nsPoint& aPoint) { @@ -628,18 +634,6 @@ nsSVGOuterSVGFrame::GetCanvasTM() return retval; } -already_AddRefed -nsSVGOuterSVGFrame::GetCoordContextProvider() -{ - NS_ASSERTION(mContent, "null parent"); - - // Our content element is the CoordContextProvider for our children: - nsSVGCoordCtxProvider *provider; - CallQueryInterface(mContent, &provider); - - return provider; -} - //---------------------------------------------------------------------- // Implementation helpers diff --git a/mozilla/layout/svg/base/src/nsSVGOuterSVGFrame.h b/mozilla/layout/svg/base/src/nsSVGOuterSVGFrame.h index 2685098c9e0..5da4332bc3f 100644 --- a/mozilla/layout/svg/base/src/nsSVGOuterSVGFrame.h +++ b/mozilla/layout/svg/base/src/nsSVGOuterSVGFrame.h @@ -41,7 +41,6 @@ #include "nsSVGContainerFrame.h" #include "nsISVGSVGFrame.h" -#include "nsSVGCoordCtxProvider.h" #include "nsISVGEnum.h" #include "nsIDOMSVGPoint.h" #include "nsIDOMSVGNumber.h" @@ -52,8 +51,7 @@ typedef nsSVGDisplayContainerFrame nsSVGOuterSVGFrameBase; class nsSVGOuterSVGFrame : public nsSVGOuterSVGFrameBase, - public nsISVGSVGFrame, - public nsSVGCoordCtxProvider + public nsISVGSVGFrame { friend nsIFrame* NS_NewSVGOuterSVGFrame(nsIPresShell* aPresShell, nsIContent* aContent, nsStyleContext* aContext); @@ -81,10 +79,6 @@ public: nsIFrame* aPrevFrame, nsIFrame* aFrameList); - // We don't define an AttributeChanged method since changes to the - // 'x', 'y', 'width' and 'height' attributes of our content object - // are handled in nsSVGSVGElement::DidModifySVGObservable - nsIFrame* GetFrameForPoint(const nsPoint& aPoint); NS_IMETHOD BuildDisplayList(nsDisplayListBuilder* aBuilder, @@ -108,6 +102,10 @@ public: } #endif + NS_IMETHOD AttributeChanged(PRInt32 aNameSpaceID, + nsIAtom* aAttribute, + PRInt32 aModType); + // nsSVGOuterSVGFrame methods: /* Invalidate takes a nsRect in screen pixel coordinates */ @@ -121,7 +119,6 @@ public: // nsSVGContainerFrame methods: virtual already_AddRefed GetCanvasTM(); - virtual already_AddRefed GetCoordContextProvider(); protected: // implementation helpers: diff --git a/mozilla/layout/svg/base/src/nsSVGPatternFrame.cpp b/mozilla/layout/svg/base/src/nsSVGPatternFrame.cpp index e4558428e5f..1140ee231f4 100644 --- a/mozilla/layout/svg/base/src/nsSVGPatternFrame.cpp +++ b/mozilla/layout/svg/base/src/nsSVGPatternFrame.cpp @@ -627,7 +627,7 @@ nsSVGPatternFrame::GetPatternRect(nsIDOMSVGRect **patternRect, static float GetLengthValue(nsSVGLength2 *aLength) { - return aLength->GetAnimValue(NS_STATIC_CAST(nsSVGCoordCtxProvider*, nsnull)); + return aLength->GetAnimValue(NS_STATIC_CAST(nsSVGSVGElement*, nsnull)); } nsresult diff --git a/mozilla/layout/svg/base/src/nsSVGTextPathFrame.cpp b/mozilla/layout/svg/base/src/nsSVGTextPathFrame.cpp index 361ef512017..e4e82361a50 100644 --- a/mozilla/layout/svg/base/src/nsSVGTextPathFrame.cpp +++ b/mozilla/layout/svg/base/src/nsSVGTextPathFrame.cpp @@ -113,7 +113,8 @@ nsSVGTextPathFrame::Init(nsIContent* aContent, if (!mStartOffset) return NS_ERROR_FAILURE; - NS_NewSVGLengthList(getter_AddRefs(mX)); + NS_NewSVGLengthList(getter_AddRefs(mX), + NS_STATIC_CAST(nsSVGElement*, mContent)); if (mX) { nsCOMPtr length; mX->AppendItem(mStartOffset, getter_AddRefs(length)); @@ -141,7 +142,7 @@ nsSVGTextPathFrame::GetType() const NS_IMETHODIMP_(already_AddRefed) nsSVGTextPathFrame::GetX() { - nsISVGLengthList *retval = mX; + nsIDOMSVGLengthList *retval = mX; NS_IF_ADDREF(retval); return retval; } diff --git a/mozilla/layout/svg/base/src/nsSVGTextPathFrame.h b/mozilla/layout/svg/base/src/nsSVGTextPathFrame.h index b64dc606d9a..6a1555cb376 100644 --- a/mozilla/layout/svg/base/src/nsSVGTextPathFrame.h +++ b/mozilla/layout/svg/base/src/nsSVGTextPathFrame.h @@ -107,7 +107,7 @@ private: nsCOMPtr mHref; nsCOMPtr mSegments; - nsCOMPtr mX; + nsCOMPtr mX; }; #endif diff --git a/mozilla/layout/svg/base/src/nsSVGUtils.cpp b/mozilla/layout/svg/base/src/nsSVGUtils.cpp index d3f59d24fbf..2ca9a5aeaf1 100644 --- a/mozilla/layout/svg/base/src/nsSVGUtils.cpp +++ b/mozilla/layout/svg/base/src/nsSVGUtils.cpp @@ -40,7 +40,7 @@ #include "nsIDOMSVGSVGElement.h" #include "nsStyleCoord.h" #include "nsPresContext.h" -#include "nsSVGCoordCtxProvider.h" +#include "nsSVGSVGElement.h" #include "nsIContent.h" #include "nsIDocument.h" #include "nsIFrame.h" @@ -403,8 +403,9 @@ nsSVGUtils::ReportToConsole(nsIDocument* doc, } float -nsSVGUtils::CoordToFloat(nsPresContext *aPresContext, nsIContent *aContent, - const nsStyleCoord &aCoord) +nsSVGUtils::CoordToFloat(nsPresContext *aPresContext, + nsSVGElement *aContent, + const nsStyleCoord &aCoord) { float val = 0.0f; @@ -419,19 +420,19 @@ nsSVGUtils::CoordToFloat(nsPresContext *aPresContext, nsIContent *aContent, break; case eStyleUnit_Percent: { - nsCOMPtr element = do_QueryInterface(aContent); - nsCOMPtr owner; - element->GetOwnerSVGElement(getter_AddRefs(owner)); - nsCOMPtr ctx = do_QueryInterface(owner); - + nsSVGSVGElement *ctx = aContent->GetCtx(); + nsCOMPtr length; - NS_NewSVGLength(getter_AddRefs(length), aCoord.GetPercentValue() * 100.0f, + NS_NewSVGLength(getter_AddRefs(length), + aCoord.GetPercentValue() * 100.0f, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE); - + if (!ctx || !length) break; - length->SetContext(nsRefPtr(ctx->GetContextUnspecified())); + nsWeakPtr weakCtx = + do_GetWeakReference(NS_STATIC_CAST(nsGenericElement*, ctx)); + length->SetContext(weakCtx, nsSVGUtils::XY); length->GetValue(&val); break; } @@ -559,7 +560,7 @@ nsSVGUtils::ObjectSpace(nsIDOMSVGRect *aRect, nsSVGLength2 *aLength) nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE) { fraction = aLength->GetAnimValInSpecifiedUnits() / 100; } else - fraction = aLength->GetAnimValue(NS_STATIC_CAST(nsSVGCoordCtxProvider*, + fraction = aLength->GetAnimValue(NS_STATIC_CAST(nsSVGSVGElement*, nsnull)); return fraction * axis; @@ -1084,22 +1085,6 @@ nsSVGUtils::HitTestChildren(nsIFrame *aFrame, float x, float y, *aResult = nsnull; } -already_AddRefed -nsSVGUtils::GetCoordContextProvider(nsSVGElement *aElement) -{ - nsCOMPtr owner; - nsresult rv = aElement->GetOwnerSVGElement(getter_AddRefs(owner)); - - // GetOwnerSVGElement can fail during teardown - if (NS_FAILED(rv) || !owner) - return nsnull; - - nsSVGCoordCtxProvider *ctx; - CallQueryInterface(owner, &ctx); - - return ctx; -} - nsRect nsSVGUtils::GetCoveredRegion(const nsFrameList &aFrames) { diff --git a/mozilla/layout/svg/base/src/nsSVGUtils.h b/mozilla/layout/svg/base/src/nsSVGUtils.h index b533f69cb79..53def5dfbbb 100644 --- a/mozilla/layout/svg/base/src/nsSVGUtils.h +++ b/mozilla/layout/svg/base/src/nsSVGUtils.h @@ -65,7 +65,7 @@ class nsISVGValueObserver; class nsIAtom; class nsSVGLength2; class nsSVGElement; -class nsSVGCoordCtxProvider; +class nsSVGSVGElement; class nsAttrValue; class gfxContext; class gfxASurface; @@ -182,7 +182,8 @@ public: * Factor (straight userspace), Coord (dimensioned), and Percent (of * the current SVG viewport) */ - static float CoordToFloat(nsPresContext *aPresContext, nsIContent *aContent, + static float CoordToFloat(nsPresContext *aPresContext, + nsSVGElement *aContent, const nsStyleCoord &aCoord); /* * Gets an internal frame for an element referenced by a URI. Note that this @@ -277,12 +278,6 @@ public: */ static already_AddRefed GetCanvasTM(nsIFrame *aFrame); - /* - * Get element's coordinate context provider. - */ - static already_AddRefed - GetCoordContextProvider(nsSVGElement *aElement); - /* * Get frame's covered region by walking the children and doing union. */