Fix for bug #233419: Communicate parent chain changes on svg element to full child tree; use appropriate default values for missing context in nsSVGLength. Not part of default builds - SVG only.

This commit is contained in:
alex.fritze%crocodile-clips.com 2004-02-27 01:00:33 +00:00
Родитель 38156c069e
Коммит 234b03e787
12 изменённых файлов: 152 добавлений и 25 удалений

Просмотреть файл

@ -0,0 +1,61 @@
/* -*- 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 <alex@croczilla.com> (original author)
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 NPL, 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_ISVGCONTENT_H__
#define __NS_ISVGCONTENT_H__
#include "nsISupports.h"
////////////////////////////////////////////////////////////////////////
// nsISVGContent: SVG extensions to nsIContent
// {B1098F79-4158-4A9A-9B82-DA4001FEBDF2}
#define NS_ISVGCONTENT_IID \
{ 0xb1098f79, 0x4158, 0x4a9a, { 0x9b, 0x82, 0xda, 0x40, 0x01, 0xfe, 0xbd, 0xf2 } }
class nsISVGContent : public nsISupports
{
public:
static const nsIID& GetIID() { static nsIID iid = NS_ISVGCONTENT_IID; return iid; }
virtual void ParentChainChanged()=0;
};
#endif // __NS_ISVGCONTENT_H__

Просмотреть файл

@ -67,8 +67,10 @@ public:
NS_FORWARD_NSIDOMELEMENT(nsSVGCircleElementBase::) NS_FORWARD_NSIDOMELEMENT(nsSVGCircleElementBase::)
NS_FORWARD_NSIDOMSVGELEMENT(nsSVGCircleElementBase::) NS_FORWARD_NSIDOMSVGELEMENT(nsSVGCircleElementBase::)
protected: // nsISVGContent specializations:
virtual void ParentChainChanged(); virtual void ParentChainChanged();
protected:
nsCOMPtr<nsIDOMSVGAnimatedLength> mCx; nsCOMPtr<nsIDOMSVGAnimatedLength> mCx;
nsCOMPtr<nsIDOMSVGAnimatedLength> mCy; nsCOMPtr<nsIDOMSVGAnimatedLength> mCy;
@ -255,7 +257,7 @@ NS_IMETHODIMP nsSVGCircleElement::GetR(nsIDOMSVGAnimatedLength * *aR)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// // nsISVGContent methods
void nsSVGCircleElement::ParentChainChanged() void nsSVGCircleElement::ParentChainChanged()
{ {
@ -315,4 +317,6 @@ void nsSVGCircleElement::ParentChainChanged()
length->SetContext(ctx); length->SetContext(ctx);
} }
// XXX call baseclass version to recurse into children?
} }

Просмотреть файл

@ -82,6 +82,7 @@ NS_INTERFACE_MAP_BEGIN(nsSVGElement)
NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOM3Node, new nsNode3Tearoff(this)) NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOM3Node, new nsNode3Tearoff(this))
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_ENTRY(nsISVGValueObserver) NS_INTERFACE_MAP_ENTRY(nsISVGValueObserver)
NS_INTERFACE_MAP_ENTRY(nsISVGContent)
// provided by nsGenericElement: // provided by nsGenericElement:
// NS_INTERFACE_MAP_ENTRY(nsIStyledContent) // NS_INTERFACE_MAP_ENTRY(nsIStyledContent)
// NS_INTERFACE_MAP_ENTRY(nsIContent) // NS_INTERFACE_MAP_ENTRY(nsIContent)
@ -619,6 +620,36 @@ nsSVGElement::DidModifySVGObservable (nsISVGValue* observable)
return NS_ERROR_NOT_IMPLEMENTED; return NS_ERROR_NOT_IMPLEMENTED;
} }
//----------------------------------------------------------------------
// nsISVGContent methods:
// 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; i<count; ++i) {
nsIContent* child = elem->GetChildAt(i);
nsCOMPtr<nsISVGContent> svgChild = do_QueryInterface(child);
if (svgChild) {
svgChild->ParentChainChanged();
}
else {
// non-svg element might have an svg child, so recurse
CallParentChainChanged(child);
}
}
}
void
nsSVGElement::ParentChainChanged()
{
CallParentChainChanged(this);
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// Implementation Helpers: // Implementation Helpers:

Просмотреть файл

@ -53,11 +53,13 @@
#include "nsISVGValueObserver.h" #include "nsISVGValueObserver.h"
#include "nsWeakReference.h" #include "nsWeakReference.h"
#include "nsISVGStyleValue.h" #include "nsISVGStyleValue.h"
#include "nsISVGContent.h"
class nsSVGElement : public nsGenericElement, // :nsIHTMLContent:nsIXMLContent:nsIStyledContent:nsIContent class nsSVGElement : public nsGenericElement, // :nsIHTMLContent:nsIXMLContent:nsIStyledContent:nsIContent
public nsIDOMSVGElement, // :nsIDOMElement:nsIDOMNode public nsIDOMSVGElement, // :nsIDOMElement:nsIDOMNode
public nsISVGValueObserver, public nsISVGValueObserver,
public nsSupportsWeakReference // :nsISupportsWeakReference public nsSupportsWeakReference, // :nsISupportsWeakReference
public nsISVGContent
{ {
protected: protected:
nsSVGElement(); nsSVGElement();
@ -132,11 +134,13 @@ public:
// nsISupportsWeakReference // nsISupportsWeakReference
// implementation inherited from nsSupportsWeakReference // implementation inherited from nsSupportsWeakReference
// nsISVGContent
virtual void ParentChainChanged();
protected: protected:
nsresult CopyNode(nsSVGElement* dest, PRBool deep); nsresult CopyNode(nsSVGElement* dest, PRBool deep);
virtual void ParentChainChanged(){};
nsSVGAttributes* mAttributes; nsSVGAttributes* mAttributes;
nsCOMPtr<nsISVGStyleValue> mStyle; nsCOMPtr<nsISVGStyleValue> mStyle;

Просмотреть файл

@ -70,9 +70,11 @@ public:
NS_FORWARD_NSIDOMELEMENT(nsSVGEllipseElementBase::) NS_FORWARD_NSIDOMELEMENT(nsSVGEllipseElementBase::)
NS_FORWARD_NSIDOMSVGELEMENT(nsSVGEllipseElementBase::) NS_FORWARD_NSIDOMSVGELEMENT(nsSVGEllipseElementBase::)
protected: // nsISVGContent specializations:
virtual void ParentChainChanged(); virtual void ParentChainChanged();
protected:
nsCOMPtr<nsIDOMSVGAnimatedLength> mCx; nsCOMPtr<nsIDOMSVGAnimatedLength> mCx;
nsCOMPtr<nsIDOMSVGAnimatedLength> mCy; nsCOMPtr<nsIDOMSVGAnimatedLength> mCy;
nsCOMPtr<nsIDOMSVGAnimatedLength> mRx; nsCOMPtr<nsIDOMSVGAnimatedLength> mRx;
@ -287,7 +289,7 @@ NS_IMETHODIMP nsSVGEllipseElement::GetRy(nsIDOMSVGAnimatedLength * *aRy)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// // nsISVGContent methods
void nsSVGEllipseElement::ParentChainChanged() void nsSVGEllipseElement::ParentChainChanged()
@ -364,4 +366,6 @@ void nsSVGEllipseElement::ParentChainChanged()
length->SetContext(ctx); length->SetContext(ctx);
} }
// XXX call baseclass version to recurse into children?
} }

Просмотреть файл

@ -69,8 +69,10 @@ public:
NS_FORWARD_NSIDOMELEMENT(nsSVGForeignObjectElementBase::) NS_FORWARD_NSIDOMELEMENT(nsSVGForeignObjectElementBase::)
NS_FORWARD_NSIDOMSVGELEMENT(nsSVGForeignObjectElementBase::) NS_FORWARD_NSIDOMSVGELEMENT(nsSVGForeignObjectElementBase::)
protected: // nsISVGContent specializations:
virtual void ParentChainChanged(); virtual void ParentChainChanged();
protected:
nsCOMPtr<nsIDOMSVGAnimatedLength> mX; nsCOMPtr<nsIDOMSVGAnimatedLength> mX;
nsCOMPtr<nsIDOMSVGAnimatedLength> mY; nsCOMPtr<nsIDOMSVGAnimatedLength> mY;
@ -284,7 +286,7 @@ NS_IMETHODIMP nsSVGForeignObjectElement::GetHeight(nsIDOMSVGAnimatedLength * *aH
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// // nsISVGContent methods
void nsSVGForeignObjectElement::ParentChainChanged() void nsSVGForeignObjectElement::ParentChainChanged()
{ {

Просмотреть файл

@ -75,11 +75,12 @@ public:
NS_FORWARD_NSIDOMELEMENT(nsSVGImageElementBase::) NS_FORWARD_NSIDOMELEMENT(nsSVGImageElementBase::)
NS_FORWARD_NSIDOMSVGELEMENT(nsSVGImageElementBase::) NS_FORWARD_NSIDOMSVGELEMENT(nsSVGImageElementBase::)
// nsISVGContent specializations:
virtual void ParentChainChanged();
protected: protected:
void GetSrc(nsAString& src); void GetSrc(nsAString& src);
virtual void ParentChainChanged();
nsCOMPtr<nsIDOMSVGAnimatedLength> mX; nsCOMPtr<nsIDOMSVGAnimatedLength> mX;
nsCOMPtr<nsIDOMSVGAnimatedLength> mY; nsCOMPtr<nsIDOMSVGAnimatedLength> mY;
nsCOMPtr<nsIDOMSVGAnimatedLength> mWidth; nsCOMPtr<nsIDOMSVGAnimatedLength> mWidth;
@ -329,7 +330,7 @@ nsSVGImageElement::GetHref(nsIDOMSVGAnimatedString * *aHref)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// // nsISVGContent methods
void nsSVGImageElement::ParentChainChanged() void nsSVGImageElement::ParentChainChanged()
{ {

Просмотреть файл

@ -504,8 +504,8 @@ float nsSVGLength::UserUnitsPerPixel()
float nsSVGLength::mmPerPixel() float nsSVGLength::mmPerPixel()
{ {
if (!mContext) { if (!mContext) {
NS_WARNING("no context in mmPerPixel()"); NS_ERROR("no context in mmPerPixel()");
return 1e-20f; return 1.0f;
} }
nsCOMPtr<nsIDOMSVGNumber> num; nsCOMPtr<nsIDOMSVGNumber> num;
@ -516,7 +516,7 @@ float nsSVGLength::mmPerPixel()
if (mmPerPx == 0.0f) { if (mmPerPx == 0.0f) {
NS_ASSERTION(PR_FALSE, "invalid mm/pixels"); NS_ASSERTION(PR_FALSE, "invalid mm/pixels");
mmPerPx = 1e-20f; // some small value mmPerPx = 1e-4f; // some small value
} }
return mmPerPx; return mmPerPx;
@ -525,8 +525,8 @@ float nsSVGLength::mmPerPixel()
float nsSVGLength::AxisLength() float nsSVGLength::AxisLength()
{ {
if (!mContext) { if (!mContext) {
NS_WARNING("no context in AxisLength()"); NS_ERROR("no context in AxisLength()");
return 1e-20f; return 1.0f;
} }
nsCOMPtr<nsIDOMSVGNumber> num; nsCOMPtr<nsIDOMSVGNumber> num;

Просмотреть файл

@ -70,8 +70,10 @@ public:
NS_FORWARD_NSIDOMELEMENT(nsSVGLineElementBase::) NS_FORWARD_NSIDOMELEMENT(nsSVGLineElementBase::)
NS_FORWARD_NSIDOMSVGELEMENT(nsSVGLineElementBase::) NS_FORWARD_NSIDOMSVGELEMENT(nsSVGLineElementBase::)
protected: // nsISVGContent specializations:
virtual void ParentChainChanged(); virtual void ParentChainChanged();
protected:
nsCOMPtr<nsIDOMSVGAnimatedLength> mX1; nsCOMPtr<nsIDOMSVGAnimatedLength> mX1;
nsCOMPtr<nsIDOMSVGAnimatedLength> mY1; nsCOMPtr<nsIDOMSVGAnimatedLength> mY1;
@ -283,7 +285,7 @@ NS_IMETHODIMP nsSVGLineElement::GetY2(nsIDOMSVGAnimatedLength * *aY2)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// // nsISVGContent methods
void nsSVGLineElement::ParentChainChanged() void nsSVGLineElement::ParentChainChanged()
{ {
@ -359,4 +361,6 @@ void nsSVGLineElement::ParentChainChanged()
length->SetContext(ctx); length->SetContext(ctx);
} }
// XXX call baseclass version to recurse into children?
} }

Просмотреть файл

@ -70,8 +70,10 @@ public:
NS_FORWARD_NSIDOMELEMENT(nsSVGRectElementBase::) NS_FORWARD_NSIDOMELEMENT(nsSVGRectElementBase::)
NS_FORWARD_NSIDOMSVGELEMENT(nsSVGRectElementBase::) NS_FORWARD_NSIDOMSVGELEMENT(nsSVGRectElementBase::)
protected: // nsISVGContent specializations:
virtual void ParentChainChanged(); virtual void ParentChainChanged();
protected:
nsCOMPtr<nsIDOMSVGAnimatedLength> mX; nsCOMPtr<nsIDOMSVGAnimatedLength> mX;
nsCOMPtr<nsIDOMSVGAnimatedLength> mY; nsCOMPtr<nsIDOMSVGAnimatedLength> mY;
@ -336,7 +338,7 @@ NS_IMETHODIMP nsSVGRectElement::GetRy(nsIDOMSVGAnimatedLength * *aRy)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// // nsISVGContent methods
void nsSVGRectElement::ParentChainChanged() void nsSVGRectElement::ParentChainChanged()
{ {
@ -444,4 +446,6 @@ void nsSVGRectElement::ParentChainChanged()
length->SetContext(ctx); length->SetContext(ctx);
} }
// XXX call baseclass version to recurse into children?
} }

Просмотреть файл

@ -76,10 +76,11 @@ public:
// nsIStyledContent interface // nsIStyledContent interface
NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const; NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
// nsISVGContent specializations:
virtual void ParentChainChanged();
protected: protected:
virtual void ParentChainChanged();
// nsIDOMSVGTextPositioning properties: // nsIDOMSVGTextPositioning properties:
nsCOMPtr<nsIDOMSVGAnimatedLengthList> mX; nsCOMPtr<nsIDOMSVGAnimatedLengthList> mX;
nsCOMPtr<nsIDOMSVGAnimatedLengthList> mY; nsCOMPtr<nsIDOMSVGAnimatedLengthList> mY;
@ -358,7 +359,7 @@ nsSVGTSpanElement::IsAttributeMapped(const nsIAtom* name) const
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// // nsISVGContent methods
void nsSVGTSpanElement::ParentChainChanged() void nsSVGTSpanElement::ParentChainChanged()
{ {
@ -402,4 +403,7 @@ void nsSVGTSpanElement::ParentChainChanged()
lengthlist->SetContext(ctx); lengthlist->SetContext(ctx);
} }
// recurse into child content:
nsSVGTSpanElementBase::ParentChainChanged();
} }

Просмотреть файл

@ -80,9 +80,11 @@ public:
// nsIStyledContent interface // nsIStyledContent interface
NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const; NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
protected: // nsISVGContent specializations:
virtual void ParentChainChanged(); virtual void ParentChainChanged();
protected:
already_AddRefed<nsISVGTextContentMetrics> GetTextContentMetrics(); already_AddRefed<nsISVGTextContentMetrics> GetTextContentMetrics();
// nsIDOMSVGTextPositioning properties: // nsIDOMSVGTextPositioning properties:
@ -365,7 +367,7 @@ nsSVGTextElement::IsAttributeMapped(const nsIAtom* name) const
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// // nsISVGContent methods
void nsSVGTextElement::ParentChainChanged() void nsSVGTextElement::ParentChainChanged()
{ {
@ -409,8 +411,14 @@ void nsSVGTextElement::ParentChainChanged()
lengthlist->SetContext(ctx); lengthlist->SetContext(ctx);
} }
// recurse into child content:
nsSVGTextElementBase::ParentChainChanged();
} }
//----------------------------------------------------------------------
// implementation helpers:
already_AddRefed<nsISVGTextContentMetrics> already_AddRefed<nsISVGTextContentMetrics>
nsSVGTextElement::GetTextContentMetrics() nsSVGTextElement::GetTextContentMetrics()
{ {