Bug 508725 - Part 10: Implement scoped style sheets for SVG. r=bz

This commit is contained in:
Cameron McCormack 2013-01-08 19:09:24 +11:00
parent 89014f940c
commit 8a01478510
7 changed files with 76 additions and 118 deletions

View File

@ -873,6 +873,29 @@ public:
*/
nsIEditor* GetEditorInternal();
/**
* Helper method for NS_IMPL_BOOL_ATTR macro.
* Gets value of boolean attribute. Only works for attributes in null
* namespace.
*
* @param aAttr name of attribute.
* @param aValue Boolean value of attribute.
*/
NS_HIDDEN_(bool) GetBoolAttr(nsIAtom* aAttr) const
{
return HasAttr(kNameSpaceID_None, aAttr);
}
/**
* Helper method for NS_IMPL_BOOL_ATTR macro.
* Sets value of boolean attribute by removing attribute or setting it to
* the empty string. Only works for attributes in null namespace.
*
* @param aAttr name of attribute.
* @param aValue Boolean value of attribute.
*/
NS_HIDDEN_(nsresult) SetBoolAttr(nsIAtom* aAttr, bool aValue);
protected:
/*
* Named-bools for use with SetAttrAndNotify to make call sites easier to
@ -1215,6 +1238,24 @@ _elementName::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const \
return SetAttr(kNameSpaceID_None, nsGkAtoms::_atom, nullptr, aValue, true); \
}
/**
* A macro to implement the getter and setter for a given boolean
* valued content property. The method uses the GetBoolAttr and
* SetBoolAttr methods.
*/
#define NS_IMPL_BOOL_ATTR(_class, _method, _atom) \
NS_IMETHODIMP \
_class::Get##_method(bool* aValue) \
{ \
*aValue = GetBoolAttr(nsGkAtoms::_atom); \
return NS_OK; \
} \
NS_IMETHODIMP \
_class::Set##_method(bool aValue) \
{ \
return SetBoolAttr(nsGkAtoms::_atom, aValue); \
}
#define NS_FORWARD_NSIDOMELEMENT_TO_GENERIC \
typedef mozilla::dom::Element Element; \
NS_IMETHOD GetTagName(nsAString& aTagName) MOZ_FINAL \

View File

@ -3598,3 +3598,13 @@ Element::GetEditorInternal()
nsCOMPtr<nsITextControlElement> textCtrl = do_QueryInterface(this);
return textCtrl ? textCtrl->GetTextEditor() : nullptr;
}
nsresult
Element::SetBoolAttr(nsIAtom* aAttr, bool aValue)
{
if (aValue) {
return SetAttr(kNameSpaceID_None, aAttr, EmptyString(), true);
}
return UnsetAttr(kNameSpaceID_None, aAttr, true);
}

View File

@ -1870,16 +1870,6 @@ nsGenericHTMLElement::SetAttrHelper(nsIAtom* aAttr, const nsAString& aValue)
return SetAttr(kNameSpaceID_None, aAttr, aValue, true);
}
nsresult
nsGenericHTMLElement::SetBoolAttr(nsIAtom* aAttr, bool aValue)
{
if (aValue) {
return SetAttr(kNameSpaceID_None, aAttr, EmptyString(), true);
}
return UnsetAttr(kNameSpaceID_None, aAttr, true);
}
int32_t
nsGenericHTMLElement::GetIntAttr(nsIAtom* aAttr, int32_t aDefault) const
{

View File

@ -849,29 +849,6 @@ protected:
*/
NS_HIDDEN_(nsresult) SetAttrHelper(nsIAtom* aAttr, const nsAString& aValue);
/**
* Helper method for NS_IMPL_BOOL_ATTR macro.
* Gets value of boolean attribute. Only works for attributes in null
* namespace.
*
* @param aAttr name of attribute.
* @param aValue Boolean value of attribute.
*/
NS_HIDDEN_(bool) GetBoolAttr(nsIAtom* aAttr) const
{
return HasAttr(kNameSpaceID_None, aAttr);
}
/**
* Helper method for NS_IMPL_BOOL_ATTR macro.
* Sets value of boolean attribute by removing attribute or setting it to
* the empty string. Only works for attributes in null namespace.
*
* @param aAttr name of attribute.
* @param aValue Boolean value of attribute.
*/
NS_HIDDEN_(nsresult) SetBoolAttr(nsIAtom* aAttr, bool aValue);
/**
* Helper method for NS_IMPL_INT_ATTR macro.
* Gets the integer-value of an attribute, returns specified default value
@ -1234,24 +1211,6 @@ protected:
return SetAttrHelper(nsGkAtoms::_atom, aValue); \
}
/**
* A macro to implement the getter and setter for a given boolean
* valued content property. The method uses the generic GetAttr and
* SetAttr methods.
*/
#define NS_IMPL_BOOL_ATTR(_class, _method, _atom) \
NS_IMETHODIMP \
_class::Get##_method(bool* aValue) \
{ \
*aValue = GetBoolAttr(nsGkAtoms::_atom); \
return NS_OK; \
} \
NS_IMETHODIMP \
_class::Set##_method(bool aValue) \
{ \
return SetBoolAttr(nsGkAtoms::_atom, aValue); \
}
/**
* A macro to implement the getter and setter for a given integer
* valued content property. The method uses the generic GetAttr and

View File

@ -99,12 +99,14 @@ SVGStyleElement::SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
{
nsresult rv = SVGStyleElementBase::SetAttr(aNameSpaceID, aName, aPrefix,
aValue, aNotify);
if (NS_SUCCEEDED(rv)) {
UpdateStyleSheetInternal(nullptr,
aNameSpaceID == kNameSpaceID_None &&
(aName == nsGkAtoms::title ||
aName == nsGkAtoms::media ||
aName == nsGkAtoms::type));
if (NS_SUCCEEDED(rv) && aNameSpaceID == kNameSpaceID_None) {
if (aName == nsGkAtoms::title ||
aName == nsGkAtoms::media ||
aName == nsGkAtoms::type) {
UpdateStyleSheetInternal(nullptr, true);
} else if (aName == nsGkAtoms::scoped) {
UpdateStyleSheetScopedness(true);
}
}
return rv;
@ -116,12 +118,14 @@ SVGStyleElement::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
{
nsresult rv = SVGStyleElementBase::UnsetAttr(aNameSpaceID, aAttribute,
aNotify);
if (NS_SUCCEEDED(rv)) {
UpdateStyleSheetInternal(nullptr,
aNameSpaceID == kNameSpaceID_None &&
(aAttribute == nsGkAtoms::title ||
aAttribute == nsGkAtoms::media ||
aAttribute == nsGkAtoms::type));
if (NS_SUCCEEDED(rv) && aNameSpaceID == kNameSpaceID_None) {
if (aAttribute == nsGkAtoms::title ||
aAttribute == nsGkAtoms::media ||
aAttribute == nsGkAtoms::type) {
UpdateStyleSheetInternal(nullptr, true);
} else if (aAttribute == nsGkAtoms::scoped) {
UpdateStyleSheetScopedness(false);
}
}
return rv;
@ -210,56 +214,10 @@ SVGStyleElement::SetXmlspace(const nsAString & aXmlspace, ErrorResult& rv)
rv = SetAttr(kNameSpaceID_XML, nsGkAtoms::space, aXmlspace, true);
}
/* attribute DOMString type; */
NS_IMETHODIMP SVGStyleElement::GetType(nsAString & aType)
{
GetAttr(kNameSpaceID_None, nsGkAtoms::type, aType);
return NS_OK;
}
NS_IMETHODIMP SVGStyleElement::SetType(const nsAString & aType)
{
return SetAttr(kNameSpaceID_None, nsGkAtoms::type, aType, true);
}
void
SVGStyleElement::SetType(const nsAString & aType, ErrorResult& rv)
{
rv = SetAttr(kNameSpaceID_None, nsGkAtoms::type, aType, true);
}
/* attribute DOMString media; */
NS_IMETHODIMP SVGStyleElement::GetMedia(nsAString & aMedia)
{
GetAttr(kNameSpaceID_None, nsGkAtoms::media, aMedia);
return NS_OK;
}
NS_IMETHODIMP SVGStyleElement::SetMedia(const nsAString & aMedia)
{
return SetAttr(kNameSpaceID_None, nsGkAtoms::media, aMedia, true);
}
void
SVGStyleElement::SetMedia(const nsAString & aMedia, ErrorResult& rv)
{
rv = SetAttr(kNameSpaceID_None, nsGkAtoms::media, aMedia, true);
}
/* attribute DOMString title; */
NS_IMETHODIMP SVGStyleElement::GetTitle(nsAString & aTitle)
{
GetAttr(kNameSpaceID_None, nsGkAtoms::title, aTitle);
return NS_OK;
}
NS_IMETHODIMP SVGStyleElement::SetTitle(const nsAString & aTitle)
{
return SetAttr(kNameSpaceID_None, nsGkAtoms::title, aTitle, true);
}
void
SVGStyleElement::SetTitle(const nsAString & aTitle, ErrorResult& rv)
{
rv = SetAttr(kNameSpaceID_None, nsGkAtoms::title, aTitle, true);
}
NS_IMPL_STRING_ATTR(SVGStyleElement, Media, media)
NS_IMPL_BOOL_ATTR(SVGStyleElement, Scoped, scoped)
NS_IMPL_STRING_ATTR(SVGStyleElement, Title, title)
NS_IMPL_STRING_ATTR(SVGStyleElement, Type, type)
//----------------------------------------------------------------------
// nsStyleLinkElement methods
@ -278,7 +236,6 @@ SVGStyleElement::GetStyleSheetInfo(nsAString& aTitle,
bool* aIsScoped,
bool* aIsAlternate)
{
*aIsScoped = false;
*aIsAlternate = false;
nsAutoString title;
@ -296,6 +253,8 @@ SVGStyleElement::GetStyleSheetInfo(nsAString& aTitle,
aType.AssignLiteral("text/css");
}
*aIsScoped = HasAttr(kNameSpaceID_None, nsGkAtoms::scoped);
return;
}

View File

@ -5,7 +5,7 @@
#include "nsIDOMSVGElement.idl"
[scriptable, uuid(53DA8F96-E2F0-45AC-B8AE-3CACC5981383)]
[scriptable, uuid(2fecabb2-4671-4553-9e99-1b8167e3c131)]
interface nsIDOMSVGStyleElement
: nsIDOMSVGElement
{
@ -17,4 +17,5 @@ interface nsIDOMSVGStyleElement
// raises DOMException on setting
attribute DOMString title;
// raises DOMException on setting
attribute boolean scoped;
};

View File

@ -13,11 +13,9 @@
interface SVGStyleElement : SVGElement {
[SetterThrows]
attribute DOMString xmlspace; // Spec claims this should be on SVGElement
[SetterThrows]
attribute DOMString type;
[SetterThrows]
attribute DOMString media;
[SetterThrows]
attribute DOMString title;
attribute bool scoped;
};