diff --git a/content/xul/content/src/nsXULElement.cpp b/content/xul/content/src/nsXULElement.cpp index ebd54d3d136e..f3549dc51fcc 100644 --- a/content/xul/content/src/nsXULElement.cpp +++ b/content/xul/content/src/nsXULElement.cpp @@ -2806,3 +2806,39 @@ RDFElementImpl::SetController(nsIController* aController) NS_IF_ADDREF(mController); return NS_OK; } + +// Methods for setting/getting attributes from nsIDOMXULElement +nsresult +RDFElementImpl::GetId(nsString& aId) +{ + GetAttribute("id", aId); + return NS_OK; +} + +nsresult +RDFElementImpl::SetId(const nsString& aId) +{ + SetAttribute("id", aId); + return NS_OK; +} + +nsresult +RDFElementImpl::GetClassName(nsString& aClassName) +{ + GetAttribute("class", aClassName); + return NS_OK; +} + +nsresult +RDFElementImpl::SetClassName(const nsString& aClassName) +{ + SetAttribute("class", aClassName); + return NS_OK; +} + +nsresult +RDFElementImpl::GetStyle(nsIDOMCSSStyleDeclaration** aStyle) +{ + NS_NOTYETIMPLEMENTED("write me!"); + return NS_ERROR_NOT_IMPLEMENTED; +} diff --git a/dom/public/idl/xul/XULElement.idl b/dom/public/idl/xul/XULElement.idl index dadc53d16498..3e929fb0e9aa 100644 --- a/dom/public/idl/xul/XULElement.idl +++ b/dom/public/idl/xul/XULElement.idl @@ -5,6 +5,10 @@ interface XULElement : Element { readonly attribute xpidl nsIRDFResource resource; attribute xpidl nsIController controller; + attribute DOMString id; + attribute DOMString className; + readonly attribute CSSStyleDeclaration style; + void addBroadcastListener(in DOMString attr, in Element element); void removeBroadcastListener(in DOMString attr, in Element element); void doCommand(); diff --git a/dom/public/xul/nsIDOMXULElement.h b/dom/public/xul/nsIDOMXULElement.h index 5e84f812f4ef..e63e7e6cb8c7 100644 --- a/dom/public/xul/nsIDOMXULElement.h +++ b/dom/public/xul/nsIDOMXULElement.h @@ -27,6 +27,7 @@ class nsIController; class nsIDOMElement; +class nsIDOMCSSStyleDeclaration; class nsIRDFResource; class nsIDOMNodeList; @@ -43,6 +44,14 @@ public: NS_IMETHOD GetController(nsIController** aController)=0; NS_IMETHOD SetController(nsIController* aController)=0; + NS_IMETHOD GetId(nsString& aId)=0; + NS_IMETHOD SetId(const nsString& aId)=0; + + NS_IMETHOD GetClassName(nsString& aClassName)=0; + NS_IMETHOD SetClassName(const nsString& aClassName)=0; + + NS_IMETHOD GetStyle(nsIDOMCSSStyleDeclaration** aStyle)=0; + NS_IMETHOD AddBroadcastListener(const nsString& aAttr, nsIDOMElement* aElement)=0; NS_IMETHOD RemoveBroadcastListener(const nsString& aAttr, nsIDOMElement* aElement)=0; @@ -57,6 +66,11 @@ public: NS_IMETHOD GetResource(nsIRDFResource** aResource); \ NS_IMETHOD GetController(nsIController** aController); \ NS_IMETHOD SetController(nsIController* aController); \ + NS_IMETHOD GetId(nsString& aId); \ + NS_IMETHOD SetId(const nsString& aId); \ + NS_IMETHOD GetClassName(nsString& aClassName); \ + NS_IMETHOD SetClassName(const nsString& aClassName); \ + NS_IMETHOD GetStyle(nsIDOMCSSStyleDeclaration** aStyle); \ NS_IMETHOD AddBroadcastListener(const nsString& aAttr, nsIDOMElement* aElement); \ NS_IMETHOD RemoveBroadcastListener(const nsString& aAttr, nsIDOMElement* aElement); \ NS_IMETHOD DoCommand(); \ @@ -68,6 +82,11 @@ public: NS_IMETHOD GetResource(nsIRDFResource** aResource) { return _to GetResource(aResource); } \ NS_IMETHOD GetController(nsIController** aController) { return _to GetController(aController); } \ NS_IMETHOD SetController(nsIController* aController) { return _to SetController(aController); } \ + NS_IMETHOD GetId(nsString& aId) { return _to GetId(aId); } \ + NS_IMETHOD SetId(const nsString& aId) { return _to SetId(aId); } \ + NS_IMETHOD GetClassName(nsString& aClassName) { return _to GetClassName(aClassName); } \ + NS_IMETHOD SetClassName(const nsString& aClassName) { return _to SetClassName(aClassName); } \ + NS_IMETHOD GetStyle(nsIDOMCSSStyleDeclaration** aStyle) { return _to GetStyle(aStyle); } \ NS_IMETHOD AddBroadcastListener(const nsString& aAttr, nsIDOMElement* aElement) { return _to AddBroadcastListener(aAttr, aElement); } \ NS_IMETHOD RemoveBroadcastListener(const nsString& aAttr, nsIDOMElement* aElement) { return _to RemoveBroadcastListener(aAttr, aElement); } \ NS_IMETHOD DoCommand() { return _to DoCommand(); } \ diff --git a/dom/src/xul/nsJSXULElement.cpp b/dom/src/xul/nsJSXULElement.cpp index 895774ef2b57..7f5b0423eb99 100644 --- a/dom/src/xul/nsJSXULElement.cpp +++ b/dom/src/xul/nsJSXULElement.cpp @@ -29,6 +29,7 @@ #include "nsString.h" #include "nsIController.h" #include "nsIDOMElement.h" +#include "nsIDOMCSSStyleDeclaration.h" #include "nsIDOMXULElement.h" #include "nsIRDFResource.h" #include "nsIDOMNodeList.h" @@ -39,12 +40,14 @@ static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID); static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID); static NS_DEFINE_IID(kIControllerIID, NS_ICONTROLLER_IID); static NS_DEFINE_IID(kIElementIID, NS_IDOMELEMENT_IID); +static NS_DEFINE_IID(kICSSStyleDeclarationIID, NS_IDOMCSSSTYLEDECLARATION_IID); static NS_DEFINE_IID(kIXULElementIID, NS_IDOMXULELEMENT_IID); static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID); static NS_DEFINE_IID(kINodeListIID, NS_IDOMNODELIST_IID); NS_DEF_PTR(nsIController); NS_DEF_PTR(nsIDOMElement); +NS_DEF_PTR(nsIDOMCSSStyleDeclaration); NS_DEF_PTR(nsIDOMXULElement); NS_DEF_PTR(nsIRDFResource); NS_DEF_PTR(nsIDOMNodeList); @@ -54,7 +57,10 @@ NS_DEF_PTR(nsIDOMNodeList); // enum XULElement_slots { XULELEMENT_RESOURCE = -1, - XULELEMENT_CONTROLLER = -2 + XULELEMENT_CONTROLLER = -2, + XULELEMENT_ID = -3, + XULELEMENT_CLASSNAME = -4, + XULELEMENT_STYLE = -5 }; /***********************************************************************/ @@ -113,6 +119,55 @@ GetXULElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) } break; } + case XULELEMENT_ID: + { + secMan->CheckScriptAccess(scriptCX, obj, "xulelement.id", &ok); + if (!ok) { + //Need to throw error here + return JS_FALSE; + } + nsAutoString prop; + if (NS_OK == a->GetId(prop)) { + nsJSUtils::nsConvertStringToJSVal(prop, cx, vp); + } + else { + return JS_FALSE; + } + break; + } + case XULELEMENT_CLASSNAME: + { + secMan->CheckScriptAccess(scriptCX, obj, "xulelement.classname", &ok); + if (!ok) { + //Need to throw error here + return JS_FALSE; + } + nsAutoString prop; + if (NS_OK == a->GetClassName(prop)) { + nsJSUtils::nsConvertStringToJSVal(prop, cx, vp); + } + else { + return JS_FALSE; + } + break; + } + case XULELEMENT_STYLE: + { + secMan->CheckScriptAccess(scriptCX, obj, "xulelement.style", &ok); + if (!ok) { + //Need to throw error here + return JS_FALSE; + } + nsIDOMCSSStyleDeclaration* prop; + if (NS_OK == a->GetStyle(&prop)) { + // get the js object + nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, vp); + } + else { + return JS_FALSE; + } + break; + } default: return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp); } @@ -164,6 +219,34 @@ SetXULElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) NS_IF_RELEASE(prop); break; } + case XULELEMENT_ID: + { + secMan->CheckScriptAccess(scriptCX, obj, "xulelement.id", &ok); + if (!ok) { + //Need to throw error here + return JS_FALSE; + } + nsAutoString prop; + nsJSUtils::nsConvertJSValToString(prop, cx, *vp); + + a->SetId(prop); + + break; + } + case XULELEMENT_CLASSNAME: + { + secMan->CheckScriptAccess(scriptCX, obj, "xulelement.classname", &ok); + if (!ok) { + //Need to throw error here + return JS_FALSE; + } + nsAutoString prop; + nsJSUtils::nsConvertJSValToString(prop, cx, *vp); + + a->SetClassName(prop); + + break; + } default: return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp); } @@ -455,6 +538,9 @@ static JSPropertySpec XULElementProperties[] = { {"resource", XULELEMENT_RESOURCE, JSPROP_ENUMERATE | JSPROP_READONLY}, {"controller", XULELEMENT_CONTROLLER, JSPROP_ENUMERATE}, + {"id", XULELEMENT_ID, JSPROP_ENUMERATE}, + {"className", XULELEMENT_CLASSNAME, JSPROP_ENUMERATE}, + {"style", XULELEMENT_STYLE, JSPROP_ENUMERATE | JSPROP_READONLY}, {0} }; diff --git a/rdf/content/public/idl/XULElement.idl b/rdf/content/public/idl/XULElement.idl index dadc53d16498..3e929fb0e9aa 100644 --- a/rdf/content/public/idl/XULElement.idl +++ b/rdf/content/public/idl/XULElement.idl @@ -5,6 +5,10 @@ interface XULElement : Element { readonly attribute xpidl nsIRDFResource resource; attribute xpidl nsIController controller; + attribute DOMString id; + attribute DOMString className; + readonly attribute CSSStyleDeclaration style; + void addBroadcastListener(in DOMString attr, in Element element); void removeBroadcastListener(in DOMString attr, in Element element); void doCommand(); diff --git a/rdf/content/public/nsIDOMXULElement.h b/rdf/content/public/nsIDOMXULElement.h index 5e84f812f4ef..e63e7e6cb8c7 100644 --- a/rdf/content/public/nsIDOMXULElement.h +++ b/rdf/content/public/nsIDOMXULElement.h @@ -27,6 +27,7 @@ class nsIController; class nsIDOMElement; +class nsIDOMCSSStyleDeclaration; class nsIRDFResource; class nsIDOMNodeList; @@ -43,6 +44,14 @@ public: NS_IMETHOD GetController(nsIController** aController)=0; NS_IMETHOD SetController(nsIController* aController)=0; + NS_IMETHOD GetId(nsString& aId)=0; + NS_IMETHOD SetId(const nsString& aId)=0; + + NS_IMETHOD GetClassName(nsString& aClassName)=0; + NS_IMETHOD SetClassName(const nsString& aClassName)=0; + + NS_IMETHOD GetStyle(nsIDOMCSSStyleDeclaration** aStyle)=0; + NS_IMETHOD AddBroadcastListener(const nsString& aAttr, nsIDOMElement* aElement)=0; NS_IMETHOD RemoveBroadcastListener(const nsString& aAttr, nsIDOMElement* aElement)=0; @@ -57,6 +66,11 @@ public: NS_IMETHOD GetResource(nsIRDFResource** aResource); \ NS_IMETHOD GetController(nsIController** aController); \ NS_IMETHOD SetController(nsIController* aController); \ + NS_IMETHOD GetId(nsString& aId); \ + NS_IMETHOD SetId(const nsString& aId); \ + NS_IMETHOD GetClassName(nsString& aClassName); \ + NS_IMETHOD SetClassName(const nsString& aClassName); \ + NS_IMETHOD GetStyle(nsIDOMCSSStyleDeclaration** aStyle); \ NS_IMETHOD AddBroadcastListener(const nsString& aAttr, nsIDOMElement* aElement); \ NS_IMETHOD RemoveBroadcastListener(const nsString& aAttr, nsIDOMElement* aElement); \ NS_IMETHOD DoCommand(); \ @@ -68,6 +82,11 @@ public: NS_IMETHOD GetResource(nsIRDFResource** aResource) { return _to GetResource(aResource); } \ NS_IMETHOD GetController(nsIController** aController) { return _to GetController(aController); } \ NS_IMETHOD SetController(nsIController* aController) { return _to SetController(aController); } \ + NS_IMETHOD GetId(nsString& aId) { return _to GetId(aId); } \ + NS_IMETHOD SetId(const nsString& aId) { return _to SetId(aId); } \ + NS_IMETHOD GetClassName(nsString& aClassName) { return _to GetClassName(aClassName); } \ + NS_IMETHOD SetClassName(const nsString& aClassName) { return _to SetClassName(aClassName); } \ + NS_IMETHOD GetStyle(nsIDOMCSSStyleDeclaration** aStyle) { return _to GetStyle(aStyle); } \ NS_IMETHOD AddBroadcastListener(const nsString& aAttr, nsIDOMElement* aElement) { return _to AddBroadcastListener(aAttr, aElement); } \ NS_IMETHOD RemoveBroadcastListener(const nsString& aAttr, nsIDOMElement* aElement) { return _to RemoveBroadcastListener(aAttr, aElement); } \ NS_IMETHOD DoCommand() { return _to DoCommand(); } \ diff --git a/rdf/content/src/nsJSXULElement.cpp b/rdf/content/src/nsJSXULElement.cpp index 895774ef2b57..7f5b0423eb99 100644 --- a/rdf/content/src/nsJSXULElement.cpp +++ b/rdf/content/src/nsJSXULElement.cpp @@ -29,6 +29,7 @@ #include "nsString.h" #include "nsIController.h" #include "nsIDOMElement.h" +#include "nsIDOMCSSStyleDeclaration.h" #include "nsIDOMXULElement.h" #include "nsIRDFResource.h" #include "nsIDOMNodeList.h" @@ -39,12 +40,14 @@ static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID); static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID); static NS_DEFINE_IID(kIControllerIID, NS_ICONTROLLER_IID); static NS_DEFINE_IID(kIElementIID, NS_IDOMELEMENT_IID); +static NS_DEFINE_IID(kICSSStyleDeclarationIID, NS_IDOMCSSSTYLEDECLARATION_IID); static NS_DEFINE_IID(kIXULElementIID, NS_IDOMXULELEMENT_IID); static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID); static NS_DEFINE_IID(kINodeListIID, NS_IDOMNODELIST_IID); NS_DEF_PTR(nsIController); NS_DEF_PTR(nsIDOMElement); +NS_DEF_PTR(nsIDOMCSSStyleDeclaration); NS_DEF_PTR(nsIDOMXULElement); NS_DEF_PTR(nsIRDFResource); NS_DEF_PTR(nsIDOMNodeList); @@ -54,7 +57,10 @@ NS_DEF_PTR(nsIDOMNodeList); // enum XULElement_slots { XULELEMENT_RESOURCE = -1, - XULELEMENT_CONTROLLER = -2 + XULELEMENT_CONTROLLER = -2, + XULELEMENT_ID = -3, + XULELEMENT_CLASSNAME = -4, + XULELEMENT_STYLE = -5 }; /***********************************************************************/ @@ -113,6 +119,55 @@ GetXULElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) } break; } + case XULELEMENT_ID: + { + secMan->CheckScriptAccess(scriptCX, obj, "xulelement.id", &ok); + if (!ok) { + //Need to throw error here + return JS_FALSE; + } + nsAutoString prop; + if (NS_OK == a->GetId(prop)) { + nsJSUtils::nsConvertStringToJSVal(prop, cx, vp); + } + else { + return JS_FALSE; + } + break; + } + case XULELEMENT_CLASSNAME: + { + secMan->CheckScriptAccess(scriptCX, obj, "xulelement.classname", &ok); + if (!ok) { + //Need to throw error here + return JS_FALSE; + } + nsAutoString prop; + if (NS_OK == a->GetClassName(prop)) { + nsJSUtils::nsConvertStringToJSVal(prop, cx, vp); + } + else { + return JS_FALSE; + } + break; + } + case XULELEMENT_STYLE: + { + secMan->CheckScriptAccess(scriptCX, obj, "xulelement.style", &ok); + if (!ok) { + //Need to throw error here + return JS_FALSE; + } + nsIDOMCSSStyleDeclaration* prop; + if (NS_OK == a->GetStyle(&prop)) { + // get the js object + nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, vp); + } + else { + return JS_FALSE; + } + break; + } default: return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp); } @@ -164,6 +219,34 @@ SetXULElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) NS_IF_RELEASE(prop); break; } + case XULELEMENT_ID: + { + secMan->CheckScriptAccess(scriptCX, obj, "xulelement.id", &ok); + if (!ok) { + //Need to throw error here + return JS_FALSE; + } + nsAutoString prop; + nsJSUtils::nsConvertJSValToString(prop, cx, *vp); + + a->SetId(prop); + + break; + } + case XULELEMENT_CLASSNAME: + { + secMan->CheckScriptAccess(scriptCX, obj, "xulelement.classname", &ok); + if (!ok) { + //Need to throw error here + return JS_FALSE; + } + nsAutoString prop; + nsJSUtils::nsConvertJSValToString(prop, cx, *vp); + + a->SetClassName(prop); + + break; + } default: return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp); } @@ -455,6 +538,9 @@ static JSPropertySpec XULElementProperties[] = { {"resource", XULELEMENT_RESOURCE, JSPROP_ENUMERATE | JSPROP_READONLY}, {"controller", XULELEMENT_CONTROLLER, JSPROP_ENUMERATE}, + {"id", XULELEMENT_ID, JSPROP_ENUMERATE}, + {"className", XULELEMENT_CLASSNAME, JSPROP_ENUMERATE}, + {"style", XULELEMENT_STYLE, JSPROP_ENUMERATE | JSPROP_READONLY}, {0} }; diff --git a/rdf/content/src/nsRDFElement.cpp b/rdf/content/src/nsRDFElement.cpp index ebd54d3d136e..f3549dc51fcc 100644 --- a/rdf/content/src/nsRDFElement.cpp +++ b/rdf/content/src/nsRDFElement.cpp @@ -2806,3 +2806,39 @@ RDFElementImpl::SetController(nsIController* aController) NS_IF_ADDREF(mController); return NS_OK; } + +// Methods for setting/getting attributes from nsIDOMXULElement +nsresult +RDFElementImpl::GetId(nsString& aId) +{ + GetAttribute("id", aId); + return NS_OK; +} + +nsresult +RDFElementImpl::SetId(const nsString& aId) +{ + SetAttribute("id", aId); + return NS_OK; +} + +nsresult +RDFElementImpl::GetClassName(nsString& aClassName) +{ + GetAttribute("class", aClassName); + return NS_OK; +} + +nsresult +RDFElementImpl::SetClassName(const nsString& aClassName) +{ + SetAttribute("class", aClassName); + return NS_OK; +} + +nsresult +RDFElementImpl::GetStyle(nsIDOMCSSStyleDeclaration** aStyle) +{ + NS_NOTYETIMPLEMENTED("write me!"); + return NS_ERROR_NOT_IMPLEMENTED; +} diff --git a/rdf/content/src/nsXULElement.cpp b/rdf/content/src/nsXULElement.cpp index ebd54d3d136e..f3549dc51fcc 100644 --- a/rdf/content/src/nsXULElement.cpp +++ b/rdf/content/src/nsXULElement.cpp @@ -2806,3 +2806,39 @@ RDFElementImpl::SetController(nsIController* aController) NS_IF_ADDREF(mController); return NS_OK; } + +// Methods for setting/getting attributes from nsIDOMXULElement +nsresult +RDFElementImpl::GetId(nsString& aId) +{ + GetAttribute("id", aId); + return NS_OK; +} + +nsresult +RDFElementImpl::SetId(const nsString& aId) +{ + SetAttribute("id", aId); + return NS_OK; +} + +nsresult +RDFElementImpl::GetClassName(nsString& aClassName) +{ + GetAttribute("class", aClassName); + return NS_OK; +} + +nsresult +RDFElementImpl::SetClassName(const nsString& aClassName) +{ + SetAttribute("class", aClassName); + return NS_OK; +} + +nsresult +RDFElementImpl::GetStyle(nsIDOMCSSStyleDeclaration** aStyle) +{ + NS_NOTYETIMPLEMENTED("write me!"); + return NS_ERROR_NOT_IMPLEMENTED; +}