Discussion:
How can I call GetStyle() of nsIDOMNSHTMLElement
hap497
2010-05-21 05:41:46 UTC
Permalink
Hi,

If I have a pointer to nsIDOMNSHTMLElement* element, how can I call
the GetStyle()?

In nsGenericHTMLElement.h, it said
// nsIDOMNSHTMLElement methods. Note that these are non-virtual
// methods, implementations are expected to forward calls to these
// methods.
// Forward to GetStyle which is protected in the super-class
inline nsresult GetStyle(nsIDOMCSSStyleDeclaration** aStyle)

But when I do
nsIDOMNSHTMLElement* element;
nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;

nsresult result = element->GetStyle(getter_AddRefs(cssDecl));

My code will not compile.

So can I safely cast my nsIDOMNSHTMLElement* to nsGenericHTMLElement*
and call GetStyle() that way?

Thank you.
Boris Zbarsky
2010-05-21 12:02:44 UTC
Permalink
Post by hap497
If I have a pointer to nsIDOMNSHTMLElement* element, how can I call
the GetStyle()?
http://mxr.mozilla.org/mozilla-central/source/dom/interfaces/css/nsIDOMElementCSSInlineStyle.idl#42

-Boris
Jens Sorensen
2010-05-22 17:46:15 UTC
Permalink
I assume you have a valid nsIDOMElement pointer ..

nsCOMPtr<nsIDOMElement> domElement; // valid pointer to a DOM element

// QI nsIDOMElementCSSInlineStyle
nsCOMPtr<nsIDOMElementCSSInlineStyle> elementCSSInlineStyle =
do_QueryInterface(domElement);

// And get the style...
nsCOMPtr<nsIDOMCSSStyleDeclaration> domCSSStyleDecl;
domCSSStyleDecl->GetStyle( getter_AddRefs(domCSSStyleDecl));

-Jens
Post by hap497
Hi,
If I have a pointer to nsIDOMNSHTMLElement* element, how can I call
the GetStyle()?
In nsGenericHTMLElement.h, it said
// nsIDOMNSHTMLElement methods. Note that these are non-virtual
 // methods, implementations are expected to forward calls to these
 // methods.
 // Forward to GetStyle which is protected in the super-class
 inline nsresult GetStyle(nsIDOMCSSStyleDeclaration** aStyle)
But when I do
nsIDOMNSHTMLElement* element;
 nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
 nsresult result  = element->GetStyle(getter_AddRefs(cssDecl));
My code will not compile.
So can I safely cast my nsIDOMNSHTMLElement* to nsGenericHTMLElement*
and call GetStyle() that way?
Thank you.
_______________________________________________
dev-tech-dom mailing list
https://lists.mozilla.org/listinfo/dev-tech-dom
Loading...