Bug 238450: Implement nsIDOMSVGStylable and make class-selectors work for svg-elements.

r/sr=jst for classinfo changes
r=afri for the rest  (not part of build)
This commit is contained in:
sicking%bigfoot.com 2004-04-12 23:48:42 +00:00
Родитель 3b31eab500
Коммит 752f5d34fd
9 изменённых файлов: 71 добавлений и 26 удалений

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

@ -62,6 +62,7 @@ SVG_ATOM(tspan, "tspan")
// properties
SVG_ATOM(alignment_baseline, "alignment-baseline")
SVG_ATOM(baseline_shift, "baseline-shift")
SVG_ATOM(_class, "class")
SVG_ATOM(clip_path, "clip-path")
SVG_ATOM(clip_rule, "clip-rule")
SVG_ATOM(cursor, "cursor")

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

@ -49,6 +49,7 @@ CPPSRCS = \
nsSVGAnimatedString.cpp \
nsSVGAnimatedTransformList.cpp \
nsSVGCircleElement.cpp \
nsSVGClassValue.cpp \
nsSVGElement.cpp \
nsSVGElementFactory.cpp \
nsSVGEllipseElement.cpp \
@ -71,11 +72,11 @@ CPPSRCS = \
nsSVGPolygonElement.cpp \
nsSVGPolylineElement.cpp \
nsSVGStringProxyValue.cpp \
nsSVGStylableElement.cpp \
nsSVGRect.cpp \
nsSVGRectElement.cpp \
nsSVGSVGElement.cpp \
nsSVGStyleElement.cpp \
nsSVGStyleValue.cpp \
nsSVGTSpanElement.cpp \
nsSVGTextElement.cpp \
nsSVGTransform.cpp \
@ -110,6 +111,7 @@ INCLUDES += \
-I$(srcdir)/../../../base/src \
-I$(srcdir)/../../../../layout/svg/base/src \
-I$(srcdir)/../../../html/style/src \
-I$(srcdir)/../../../html/content/src \
$(NULL)
DEFINES += -D_IMPL_NS_LAYOUT

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

@ -132,7 +132,7 @@ nsSVGAnimatedString::GetBaseVal(nsAString & aBaseVal)
NS_IMETHODIMP
nsSVGAnimatedString::SetBaseVal(const nsAString & aBaseVal)
{
mBaseVal = aBaseVal;
SetValueString(aBaseVal);
return NS_OK;
}

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

@ -62,6 +62,7 @@ SVG_ATOM(tspan, "tspan")
// properties
SVG_ATOM(alignment_baseline, "alignment-baseline")
SVG_ATOM(baseline_shift, "baseline-shift")
SVG_ATOM(_class, "class")
SVG_ATOM(clip_path, "clip-path")
SVG_ATOM(clip_rule, "clip-rule")
SVG_ATOM(cursor, "cursor")

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

@ -55,9 +55,9 @@
#include "nsICSSStyleRule.h"
#include "nsISVGSVGElement.h"
#include "nsRuleWalker.h"
#include "nsSVGStyleValue.h"
#include "nsCSSDeclaration.h"
#include "nsICSSParser.h"
#include "nsGenericHTMLElement.h"
nsSVGElement::nsSVGElement()
{
@ -99,12 +99,6 @@ nsSVGElement::Init(nsINodeInfo* aNodeInfo)
// Create mapped properties:
// style #IMPLIED
rv = NS_NewSVGStyleValue(getter_AddRefs(mStyle));
NS_ENSURE_SUCCESS(rv,rv);
rv = AddMappedSVGValue(nsSVGAtoms::style, mStyle);
NS_ENSURE_SUCCESS(rv,rv);
return NS_OK;
}
@ -204,6 +198,9 @@ nsSVGElement::SetAttr(PRInt32 aNamespaceID, nsIAtom* aName, nsIAtom* aPrefix,
attrValue.SetTo(svg_value);
}
}
else if (aName == nsSVGAtoms::style && aNamespaceID == kNameSpaceID_None) {
nsGenericHTMLElement::ParseStyleAttribute(this, PR_TRUE, aValue, attrValue);
}
else {
// We don't have an nsISVGValue attribute.
attrValue.SetTo(aValue);
@ -257,10 +254,52 @@ nsSVGElement::WalkContentStyleRules(nsRuleWalker* aRuleWalker)
return NS_OK;
}
NS_IMETHODIMP
nsSVGElement::SetInlineStyleRule(nsICSSStyleRule* aStyleRule, PRBool aNotify)
{
PRBool hasListeners = PR_FALSE;
PRBool modification = PR_FALSE;
nsAutoString oldValueStr;
if (mDocument) {
hasListeners = nsGenericElement::HasMutationListeners(this,
NS_EVENT_BITS_MUTATION_ATTRMODIFIED);
// There's no point in comparing the stylerule pointers since we're always
// getting a new stylerule here. And we can't compare the stringvalues of
// the old and the new rules since both will point to the same declaration
// and thus will be the same.
if (hasListeners || aNotify) {
// save the old attribute so we can set up the mutation event properly
const nsAttrValue* value = mAttrsAndChildren.GetAttr(nsSVGAtoms::style);
if (value) {
modification = PR_TRUE;
if (hasListeners) {
value->ToString(oldValueStr);
}
}
}
}
nsAttrValue attrValue(aStyleRule);
return SetAttrAndNotify(kNameSpaceID_None, nsSVGAtoms::style, nsnull,
oldValueStr, attrValue, modification, hasListeners,
aNotify);
}
NS_IMETHODIMP
nsSVGElement::GetInlineStyleRule(nsICSSStyleRule** aStyleRule)
{
return mStyle->GetStyleRule(this, aStyleRule);
*aStyleRule = nsnull;
const nsAttrValue* attrVal = mAttrsAndChildren.GetAttr(nsSVGAtoms::style);
if (attrVal && attrVal->Type() == nsAttrValue::eCSSStyleRule) {
NS_ADDREF(*aStyleRule = attrVal->GetCSSStyleRuleValue());
}
return NS_OK;
}
// PresentationAttributes-FillStroke

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

@ -51,7 +51,6 @@
#include "nsISVGValue.h"
#include "nsISVGValueObserver.h"
#include "nsWeakReference.h"
#include "nsISVGStyleValue.h"
#include "nsISVGContent.h"
class nsSVGElement : public nsGenericElement, // :nsIHTMLContent:nsIXMLContent:nsIStyledContent:nsIContent
@ -86,10 +85,9 @@ public:
// nsIStyledContent
NS_IMETHOD GetID(nsIAtom** aResult) const;
// virtual const nsAttrValue* GetClasses() const;
// NS_IMETHOD HasClass(nsIAtom* aClass) const;
NS_IMETHOD WalkContentStyleRules(nsRuleWalker* aRuleWalker);
NS_IMETHOD SetInlineStyleRule(nsICSSStyleRule* aStyleRule, PRBool aNotify);
NS_IMETHOD GetInlineStyleRule(nsICSSStyleRule** aStyleRule);
static const MappedAttributeEntry sFillStrokeMap[];
@ -149,7 +147,6 @@ protected:
nsCOMPtr<nsICSSStyleRule> mContentStyleRule;
nsAttrAndChildArray mMappedAttributes;
nsCOMPtr<nsISVGStyleValue> mStyle;
};
#endif // __NS_SVGELEMENT_H__

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

@ -39,12 +39,12 @@
#ifndef __NS_SVGGRAPHICELEMENT_H__
#define __NS_SVGGRAPHICELEMENT_H__
#include "nsSVGElement.h"
#include "nsSVGStylableElement.h"
#include "nsIDOMSVGLocatable.h"
#include "nsIDOMSVGTransformable.h"
#include "nsIDOMSVGAnimTransformList.h"
typedef nsSVGElement nsSVGGraphicElementBase;
typedef nsSVGStylableElement nsSVGGraphicElementBase;
class nsSVGGraphicElement : public nsSVGGraphicElementBase,
public nsIDOMSVGTransformable // : nsIDOMSVGLocatable

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

@ -36,7 +36,7 @@
*
* ----- END LICENSE BLOCK ----- */
#include "nsSVGElement.h"
#include "nsSVGStylableElement.h"
#include "nsSVGAtoms.h"
#include "nsIDOMSVGFitToViewBox.h"
#include "nsIDOMSVGLocatable.h"
@ -64,7 +64,9 @@
#include "nsSVGRect.h"
#include "nsISVGValueUtils.h"
class nsSVGSVGElement : public nsSVGElement,
typedef nsSVGStylableElement nsSVGSVGElementBase;
class nsSVGSVGElement : public nsSVGSVGElementBase,
public nsISVGSVGElement, // : nsIDOMSVGSVGElement
public nsIDOMSVGFitToViewBox,
public nsIDOMSVGLocatable
@ -85,9 +87,9 @@ public:
NS_DECL_NSIDOMSVGLOCATABLE
// xxx I wish we could use virtual inheritance
NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsSVGElement::)
NS_FORWARD_NSIDOMELEMENT(nsSVGElement::)
NS_FORWARD_NSIDOMSVGELEMENT(nsSVGElement::)
NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsSVGSVGElementBase::)
NS_FORWARD_NSIDOMELEMENT(nsSVGSVGElementBase::)
NS_FORWARD_NSIDOMSVGELEMENT(nsSVGSVGElementBase::)
// nsISVGSVGElement interface:
NS_IMETHOD GetParentViewportRect(nsISVGViewportRect **parentViewport);
@ -140,8 +142,8 @@ nsresult NS_NewSVGSVGElement(nsIContent **aResult, nsINodeInfo *aNodeInfo)
//----------------------------------------------------------------------
// nsISupports methods
NS_IMPL_ADDREF_INHERITED(nsSVGSVGElement,nsSVGElement)
NS_IMPL_RELEASE_INHERITED(nsSVGSVGElement,nsSVGElement)
NS_IMPL_ADDREF_INHERITED(nsSVGSVGElement,nsSVGSVGElementBase)
NS_IMPL_RELEASE_INHERITED(nsSVGSVGElement,nsSVGSVGElementBase)
NS_INTERFACE_MAP_BEGIN(nsSVGSVGElement)
NS_INTERFACE_MAP_ENTRY(nsIDOMNode)
@ -152,7 +154,7 @@ NS_INTERFACE_MAP_BEGIN(nsSVGSVGElement)
NS_INTERFACE_MAP_ENTRY(nsIDOMSVGLocatable)
NS_INTERFACE_MAP_ENTRY(nsISVGSVGElement)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(SVGSVGElement)
NS_INTERFACE_MAP_END_INHERITING(nsSVGElement)
NS_INTERFACE_MAP_END_INHERITING(nsSVGSVGElementBase)
//----------------------------------------------------------------------
// Implementation
@ -176,7 +178,7 @@ nsSVGSVGElement::~nsSVGSVGElement()
nsresult
nsSVGSVGElement::Init(nsINodeInfo* aNodeInfo)
{
nsresult rv = nsSVGElement::Init(aNodeInfo);
nsresult rv = nsSVGSVGElementBase::Init(aNodeInfo);
NS_ENSURE_SUCCESS(rv,rv);
// parent viewport. this will be initialized properly by our frame.
@ -1084,7 +1086,7 @@ nsSVGSVGElement::IsAttributeMapped(const nsIAtom* name) const
};
return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
nsSVGElement::IsAttributeMapped(name);
nsSVGSVGElementBase::IsAttributeMapped(name);
}
//----------------------------------------------------------------------

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

@ -332,6 +332,7 @@
#include "nsIDOMSVGImageElement.h"
#include "nsIDOMSVGURIReference.h"
#include "nsIDOMSVGStyleElement.h"
#include "nsIDOMSVGStylable.h"
#endif
#include "nsIImageDocument.h"
@ -2094,6 +2095,7 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget) \
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGLocatable) \
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGTransformable) \
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGStylable) \
DOM_CLASSINFO_SVG_ELEMENT_MAP_ENTRIES
// XXX - the proto chain stuff is sort of hackish, because of the MI in
@ -2120,6 +2122,7 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGSVGElement)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGFitToViewBox)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGLocatable)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGStylable)
DOM_CLASSINFO_SVG_ELEMENT_MAP_ENTRIES
DOM_CLASSINFO_MAP_END