mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-27 07:34:20 +00:00
Bug 508725 - Part 10: Implement scoped style sheets for SVG. r=bz
This commit is contained in:
parent
453303213d
commit
ad6a513fbc
@ -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 \
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -848,29 +848,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
|
||||
@ -1233,24 +1210,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
|
||||
|
@ -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,53 +214,39 @@ 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);
|
||||
}
|
||||
NS_IMPL_STRING_ATTR(SVGStyleElement, Media, media)
|
||||
void
|
||||
SVGStyleElement::SetMedia(const nsAString & aMedia, ErrorResult& rv)
|
||||
SVGStyleElement::SetMedia(const nsAString& aMedia, ErrorResult& rv)
|
||||
{
|
||||
rv = SetAttr(kNameSpaceID_None, nsGkAtoms::media, aMedia, true);
|
||||
}
|
||||
|
||||
/* attribute DOMString title; */
|
||||
NS_IMETHODIMP SVGStyleElement::GetTitle(nsAString & aTitle)
|
||||
/* attribute boolean scoped; */
|
||||
NS_IMPL_BOOL_ATTR(SVGStyleElement, Scoped, scoped)
|
||||
bool
|
||||
SVGStyleElement::Scoped() const
|
||||
{
|
||||
GetAttr(kNameSpaceID_None, nsGkAtoms::title, aTitle);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP SVGStyleElement::SetTitle(const nsAString & aTitle)
|
||||
{
|
||||
return SetAttr(kNameSpaceID_None, nsGkAtoms::title, aTitle, true);
|
||||
return GetBoolAttr(nsGkAtoms::scoped);
|
||||
}
|
||||
void
|
||||
SVGStyleElement::SetTitle(const nsAString & aTitle, ErrorResult& rv)
|
||||
SVGStyleElement::SetScoped(bool aScoped, ErrorResult& rv)
|
||||
{
|
||||
rv = SetBoolAttr(nsGkAtoms::scoped, aScoped);
|
||||
}
|
||||
|
||||
/* attribute DOMString type; */
|
||||
NS_IMPL_STRING_ATTR(SVGStyleElement, Type, type)
|
||||
void
|
||||
SVGStyleElement::SetType(const nsAString& aType, ErrorResult& rv)
|
||||
{
|
||||
rv = SetAttr(kNameSpaceID_None, nsGkAtoms::type, aType, true);
|
||||
}
|
||||
|
||||
/* attribute DOMString title; */
|
||||
NS_IMPL_STRING_ATTR(SVGStyleElement, Title, title)
|
||||
void
|
||||
SVGStyleElement::SetTitle(const nsAString& aTitle, ErrorResult& rv)
|
||||
{
|
||||
rv = SetAttr(kNameSpaceID_None, nsGkAtoms::title, aTitle, true);
|
||||
}
|
||||
@ -278,7 +268,6 @@ SVGStyleElement::GetStyleSheetInfo(nsAString& aTitle,
|
||||
bool* aIsScoped,
|
||||
bool* aIsAlternate)
|
||||
{
|
||||
*aIsScoped = false;
|
||||
*aIsAlternate = false;
|
||||
|
||||
nsAutoString title;
|
||||
@ -296,6 +285,8 @@ SVGStyleElement::GetStyleSheetInfo(nsAString& aTitle,
|
||||
aType.AssignLiteral("text/css");
|
||||
}
|
||||
|
||||
*aIsScoped = HasAttr(kNameSpaceID_None, nsGkAtoms::scoped);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -81,6 +81,8 @@ public:
|
||||
void SetType(const nsAString & aType, ErrorResult& rv);
|
||||
void SetMedia(const nsAString & aMedia, ErrorResult& rv);
|
||||
void SetTitle(const nsAString & aTitle, ErrorResult& rv);
|
||||
bool Scoped() const;
|
||||
void SetScoped(bool aScoped, ErrorResult& rv);
|
||||
|
||||
protected:
|
||||
// Dummy init method to make the NS_IMPL_NS_NEW_SVG_ELEMENT and
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -19,5 +19,7 @@ interface SVGStyleElement : SVGElement {
|
||||
attribute DOMString media;
|
||||
[SetterThrows]
|
||||
attribute DOMString title;
|
||||
[SetterThrows]
|
||||
attribute boolean scoped;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user