From a54443bcd623f179b6d33eac649287fe095cd656 Mon Sep 17 00:00:00 2001 From: "tor%cs.brown.edu" Date: Mon, 13 Sep 2004 22:55:43 +0000 Subject: [PATCH] Bug 257669 - respect x,y attributes of inner . p=tor,jonathan.watt@strath.ac.uk; r=afri,tor --- layout/svg/base/src/nsSVGInnerSVGFrame.cpp | 81 ++++++++++++++++++++-- 1 file changed, 74 insertions(+), 7 deletions(-) diff --git a/layout/svg/base/src/nsSVGInnerSVGFrame.cpp b/layout/svg/base/src/nsSVGInnerSVGFrame.cpp index 70392f47de10..0aac84ab0bfa 100644 --- a/layout/svg/base/src/nsSVGInnerSVGFrame.cpp +++ b/layout/svg/base/src/nsSVGInnerSVGFrame.cpp @@ -45,13 +45,20 @@ #include "nsISVGOuterSVGFrame.h" #include "nsIDOMSVGSVGElement.h" #include "nsISVGSVGElement.h" +#include "nsIDOMSVGAnimatedLength.h" +#include "nsSVGLength.h" +#include "nsISVGValue.h" +#include "nsISVGValueObserver.h" +#include "nsWeakReference.h" typedef nsContainerFrame nsSVGInnerSVGFrameBase; class nsSVGInnerSVGFrame : public nsSVGInnerSVGFrameBase, - public nsISVGChildFrame, - public nsISVGContainerFrame, - public nsISVGSVGFrame + public nsISVGChildFrame, + public nsISVGContainerFrame, + public nsISVGValueObserver, + public nsSupportsWeakReference, + public nsISVGSVGFrame { friend nsresult NS_NewSVGInnerSVGFrame(nsIPresShell* aPresShell, nsIContent* aContent, nsIFrame** aNewFrame); @@ -114,6 +121,13 @@ public: already_AddRefed GetCanvasTM(); already_AddRefed GetCoordContextProvider(); + // nsISVGValueObserver + NS_IMETHOD WillModifySVGObservable(nsISVGValue* observable); + NS_IMETHOD DidModifySVGObservable (nsISVGValue* observable); + + // nsISupportsWeakReference + // implementation inherited from nsSupportsWeakReference + // nsISVGSVGFrame interface: NS_IMETHOD SuspendRedraw(); NS_IMETHOD UnsuspendRedraw(); @@ -121,6 +135,9 @@ public: protected: nsCOMPtr mCanvasTM; + + nsCOMPtr mX; + nsCOMPtr mY; }; //---------------------------------------------------------------------- @@ -164,11 +181,33 @@ nsresult nsSVGInnerSVGFrame::Init() NS_ERROR("invalid container"); return NS_ERROR_FAILURE; } - + nsCOMPtr SVGElement = do_QueryInterface(mContent); NS_ASSERTION(SVGElement, "wrong content element"); SVGElement->SetParentCoordCtxProvider(nsRefPtr(containerFrame->GetCoordContextProvider())); - + + { + nsCOMPtr length; + SVGElement->GetX(getter_AddRefs(length)); + length->GetAnimVal(getter_AddRefs(mX)); + NS_ASSERTION(mX, "no x"); + if (!mX) return NS_ERROR_FAILURE; + nsCOMPtr value = do_QueryInterface(mX); + if (value) + value->AddObserver(this); // nsISVGValueObserver + } + + { + nsCOMPtr length; + SVGElement->GetY(getter_AddRefs(length)); + length->GetAnimVal(getter_AddRefs(mY)); + NS_ASSERTION(mY, "no y"); + if (!mY) return NS_ERROR_FAILURE; + nsCOMPtr value = do_QueryInterface(mY); + if (value) + value->AddObserver(this); + } + return NS_OK; } @@ -178,12 +217,15 @@ nsresult nsSVGInnerSVGFrame::Init() NS_INTERFACE_MAP_BEGIN(nsSVGInnerSVGFrame) NS_INTERFACE_MAP_ENTRY(nsISVGChildFrame) NS_INTERFACE_MAP_ENTRY(nsISVGContainerFrame) + NS_INTERFACE_MAP_ENTRY(nsISVGValueObserver) + NS_INTERFACE_MAP_ENTRY(nsSupportsWeakReference) NS_INTERFACE_MAP_ENTRY(nsISVGSVGFrame) NS_INTERFACE_MAP_END_INHERITING(nsSVGInnerSVGFrameBase) //---------------------------------------------------------------------- // nsIFrame methods + NS_IMETHODIMP nsSVGInnerSVGFrame::Init(nsPresContext* aPresContext, nsIContent* aContent, @@ -526,6 +568,14 @@ nsSVGInnerSVGFrame::GetCanvasTM() svgElement->GetViewboxToViewportTransform(getter_AddRefs(viewBoxToViewportTM)); parentTM->Multiply(viewBoxToViewportTM, getter_AddRefs(mCanvasTM)); + + // x and y: + float x, y; + mX->GetValue(&x); + mY->GetValue(&y); + nsCOMPtr fini; + mCanvasTM->Translate(x, y, getter_AddRefs(fini)); + mCanvasTM = fini; } nsIDOMSVGMatrix* retval = mCanvasTM.get(); @@ -543,6 +593,23 @@ nsSVGInnerSVGFrame::GetCoordContextProvider() mContent->QueryInterface(NS_GET_IID(nsSVGCoordCtxProvider), (void**)&provider); NS_IF_ADDREF(provider); - - return provider; + + return provider; +} + +//---------------------------------------------------------------------- +// nsISVGValueObserver methods: + +NS_IMETHODIMP +nsSVGInnerSVGFrame::WillModifySVGObservable(nsISVGValue* observable) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsSVGInnerSVGFrame::DidModifySVGObservable (nsISVGValue* observable) +{ + NotifyViewportChange(); + + return NS_OK; }